introduction - Information Services and Technology

INTRODUCTION
1
CHAPTER 1
INTRODUCTION
Image compression is minimizing the size of a graphics file without degrading the quality of the
image to an unacceptable level. The objective of image compression is to reduce irrelevance and
redundancy of the image data in order to be able to store or transmit data in an efficient form.
Depending on whether the reconstructed image has to be exactly same as the original or some
unidentified loss may be incurred, two techniques for compression exist. Lossless compression is
the term used for the former and lossy compression for the later mentioned method. Although
lossy compression techniques achieve very high compression ratios but the decompressed image
is not exactly same as the original one. These methods take advantage of the fact that to certain
extent the human eye cannot differentiate between the images although noise exists in the
decompressed image. Lossy methods are especially suitable for natural images such as
photographs in applications where minor (sometimes imperceptible) loss of fidelity is acceptable
to achieve a substantial reduction in bit rate. The lossy compression that produces imperceptible
differences may be called visually lossless. Methods for lossy compression are:
1.Adaptive Interpolation
2.JPEG Compression
3.Quantization
Lossless methods on the other hand, give very less compression ratios but exactly recover back
the original image. Lossless compression is preferred for archival purposes and often for medical
imaging, technical drawings, clip art, or comics. Methods for lossless image compression are:
1. Run Length Encoding
2. Huffman Encoding
3. LZW
2
The proposed system presents a simple algorithm incorporating the Huffman coding scheme and
adaptive interpolation.
1.1 PROBLEM DEFINITION
This project proposes a hybrid approach to compression. It incorporates lossy as well as lossless
compression. Although lossy compression techniques achieve very high compression ratios but
the decompressed image is not exactly same as the original one. Lossless methods on the other
hand, give very less compression ratios but exactly recover back the original image. Various
parts of image are compressed in either way, depending on the amount of information held in
that part and the importance of details required i.e region of interest is taken into consideration.
1.2 OBJECTIVE
Image compression literally means reducing the size of graphics file, without compromising on
its quality. Our objective is to compress images efficiently. We want good compression
ratio , MSE,PSNR and SSIM . In other words, the newly proposed algorithm provides an
efficient means for image compression. Compression ratio is of the size of the compressed file
compared to that of the uncompressed file. PSNR stands for Probabilistic Signal-to-Noise Ratio.
It is the ratio between the maximum possible power of a signal and the power of corrupting noise
that affects the quality of its representation. PSNR is measure of peak error.
Higher PSNR indicates that reconstructed image is of higher quality. SSIM measures similarity
between images. It is a reference metric which measures quality of image with respect to original
image.It is calculated on sections of image.
The objective of proposed system is to reduce the size of image, to get better compression ratios
with minimum loss of important information or error.
3
SYSTEM ANALYSIS
4
CHAPTER 2
SYSTEM ANALYSIS
2.1 EXISTING SYSTEM [4]
The existing system involves the following compression techniques applied on entire block of
image.
Various Compression Techniques are:
2. 1.1 LOSSLESS COMPRESSION TECHNIQUES
2. 1.1.1 Run Length Encoding
This technique replaces sequences of identical symbols (pixels) ,called runs by shorter symbols.
The run length code for a gray scale image is represented by a sequence{ Vi , Ri } where Vi is
the intensity of pixel and Ri refers to the number of consecutive pixels with the intensity Vi.
2. 1.1.2 Huffman Encoding
This is a general technique for coding symbols based on their statistical occurrence frequencies.
The pixels in the image are treated as symbols. The symbols that occur more frequently are
assigned a smaller number of bits, while the symbols that occur less frequently are assigned a
relatively larger number of bits. Huffman code is a prefix code.
2. 1.1.3 LZW (Lempel- Ziv – Welch ) Coding
The paper encodes sequences of 8-bit data as fixed-length 12-bit codes. The codes from 0 to 255
represent 1-character sequences consisting of the corresponding 8-bit character, and the codes
256 through 4095 are created in a dictionary for sequences encountered in the data as it is
encoded. At each stage in compression, input bytes are gathered into a sequence until the next
character would make a sequence for which there is no code yet in the dictionary.
5
2.1.2 LOSSY COMPRESSION TECHNIQUES
2.1.2.1 JPEG (Joint Photographic Experts Group )
In computing, JPEG is a commonly used method of lossy compression for digital photography.
The JPEG compression algorithm operates in the stages as shown. It consists of a encoder and a
decoder. It forms a powerful compressor capable of compressing images to less than 10 percent
of their original size while losing little, if any of their original fidelity. The block diagram for
encoder and decoder is shown in the figure.2.1 and figure 2.2.
Figure. 2.1 JPEG Encoder
Figure 2.2 JPEG Decoder
2.1.2.1.1 Discrete Cosine Transform
DCT (Discrete Cosine Transform) are used to change the pixels in the original image into
frequency domain coefficients (called transform coefficients).These coefficients have several
desirable properties. Only those few significant coefficients are selected and the remaining are
discarded. The selected coefficients are considered for further quantization and entropy
encoding. This is the first step in JPEG compression.
6
2.1.2.1.2 Quantization
The human eye is good at seeing small differences in brightness over a relatively large area, but
not so good at distinguishing the exact strength of a high frequency brightness variation. This
allows one to greatly reduce the amount of information in the high frequency components. This
is done by simply dividing each component in the frequency domain by a constant for that
component, and then rounding to the nearest integer. This rounding operation is the only lossy
operation in the whole process if the DCT computation is performed with sufficiently high
precision. As a result of this, it is typically the case that many of the higher frequency
components are rounded to zero, and many of the rest become small positive or negative
numbers, which take many fewer bits to represent.
2.1.2.1.3 Entropy coding
Entropy coding is a special form of lossless data compression. It involves arranging the image
components in a "zigzag" order employing run-length encoding (RLE) algorithm that groups
similar frequencies together, inserting length coding zeros, and then using Huffman coding on
what is left. Entropy Coding:Developing a code such that fewer bits are assigned to grey levels
having higher probabality of occurrence or vice versa, we could reduce the number of bits
required for transmission.
2.1.2.2 JPEG 2000
JPEG 2000 is an image compression standard and coding system. Superior compression
performance: at high bit rates, where artifacts become nearly imperceptible, JPEG 2000 has a
small machine-measured fidelity advantage over JPEG. At lower bit rates (e.g., less than 0.25
bits/pixel for grayscale images), JPEG 2000 has a much more significant advantage over certain
modes of JPEG: artifacts are less visible .The compression gains over JPEG are attributed to the
use of DWT and a more sophisticated entropy encoding scheme.
Multiple resolution representation: JPEG 2000 decomposes the image into a multiple resolution
representation in the course of its compression process. This representation can be put to use for
other image presentation purposes beyond compression as such.
7
Progressive transmission by pixel and resolution accuracy, commonly referred to as progressive
decoding and signal-to-noise ratio (SNR) scalability: JPEG 2000 provides efficient code-stream
organizations which are progressive by pixel accuracy and by image resolution (or by image
size). This way, after a smaller part of the whole file has been received, the viewer can see a
lower quality version of the final picture
Region of Interest (ROI): JPEG 2000 code streams offer several mechanisms to support spatial
random access or region of interest access at varying degrees of granularity. This way it is
possible to store different parts of the same picture using different quality.
Error resilience: Like JPEG 1992, JPEG 2000 is robust to bit errors introduced by noisy
communication channels, due to the coding of data in relatively small independent blocks.
Flexible file format: The JP2 and JPX file formats allow for handling of color-space information,
metadata, and for interactivity in networked applications as developed in the JPEG Part 9 JPIP
protocol.
The aim of JPEG 2000 is not only improving compression performance over JPEG but also
adding (or improving) features such as scalability and editability .JPEG 2000's improvement in
compression performance relative to the original JPEG standard is actually rather modest and
should not ordinarily be the primary consideration for evaluating the design. Very low and very
high compression rates are supported in JPEG 2000.
2.1.3 DRAWBACKS OF EXISTING SYSTEM
The above algorithms or techniques use only one approach to all the regions in the image and
does not consider the region of interest (the region in the image which contains more important
information).So many times, region with less details is encoded considering it as important and
vice versa .So there is a risk of losing important information or preserving not so useful
information resulting into inefficient compression. While in the proposed system different
regions in the image are compressed and decompressed considering the amount of information
8
containing in that region. Lossy compression methods mentioned use wavelet transforms .But
using wavelets proves to be computationally expensive and the problem of edge pixels also
persists.
2.2 PROPOSED SYSTEM
This proposed system uses a hybrid approach to compression. It incorporates lossy as well as
lossless compression. Various parts of image are compressed in either way, depending on the
amount of information held in that part. This scheme consists of two stages. In the first stage the
image is filtered by a high pass filter to find the areas that have details. In the second stage, an
effective scheme based on Huffman coding and adaptive interpolation is developed to encode the
original image. Regions in the image containing more information is encoded using Huffman
coding and regions with less information is encoded using adaptive interpolation. With this
algorithm, a good compression ratio is obtained, while, PSNR and SSIM are better to that of
other methods available mentioned earlier. In other words, the newly proposed algorithm
provides efficient compression. This method is relatively computationally inexpensive to
Wavelet Coding and and the problem of edge pixels is also solved.
2.3 FEASIBILITY STUDY
2.3.1 Economic Feasibility
The development tools and technologies to be used were identified by us through careful
research. The softwares required for the project are all open source. The softwares are available
for free.
The technologies can be easily upgrade for very less or no price at all as all the softwares are
free.
2.3.2 Technical Feasibility
There training and learning was required since the MATLAB language and Toolboxes in Matlab
were new to us.There are many alternatives available for developing this application, which
would fulfil the objective of the project like implementing it in C,C++ or Java.
The technologies to be should be easy to develop and use.
9
The technologies need to come with proper, efficient technical support.
They have to be easily available.
The technologies should be interoperable with other technologies.
There should be enough room for scalability.
In other words, technologies should be easily upgradable.
We chose Matlab over any other programming language because it is a very powerful software
which has inbuilt functions for complex operations like reading an image or converting RGB to
Grayscale images.
10
2.3.3 Timeline Chart
Activity
September
October
November
December
January
February
March
April
Identify
requirements
Study on
Matlab
Analyse Phase
Technical
diagrams
System
Design
Coding of
project
Testing
Documentation
Figure 2.3 Timeline Chart
11
SYSTEM
SPECIFICATION
12
CHAPTER 3
SYSTEM SPECIFICATION
Matlab 7 will require
3.1 HARDWARE REQUIREMENTS
1.Processors
Pentium III, IV, Xeon , Pentium M,AMD Athlon ,Athlon XP, Athlon MP
2.Disk Space Requirement
345 MB (MATLAB only with help)
2034 MB (MATLAB with documentation)
3.RAM
256 MB (Minimum)
512 MB (Recommended)
3.2 SOFTWARE REQUIREMENTS
1.Operating System
Windows XP,Windows 2000(Service Pack 3 or 4),Windows NT 4.0(Service Pack 5 or 6a)
2.Graphics
16-, 24-, or 32-bit OpenGL capable graphics adapter (strongly recommended)
3.3 MATLAB GUI
The proposed system is implemented in MATLAB .MATLAB® is a high-performance language
for technical computing. It integrates computation, visualization, and programming in an easy-touse environment where problems and solutions are expressed in familiar mathematical notation.
GUIDE, the MATLAB Graphical User Interface development environment, provides a set of
tools for creating graphical user interfaces (GUIs). These tools greatly simplify the process of
designing and building GUIs. GUIDE tools can be used to lay out the GUI Using the GUIDE
Layout Editor, GUI can be easily layed out by clicking and dragging GUI components -- such as
panels, buttons, text fields, sliders, menus, and so on -- into the layout area. Program the GUI
GUIDE automatically generates an M-file that controls how the GUI operates. The M-file
13
initializes the GUI and contains a framework for all the GUI callbacks -- the commands that are
executed when a user clicks a GUI component. Using the M-file editor, you can add code to the
callbacks to perform the functions you want them to. To start GUIDE, enter guide at the
MATLAB prompt. This displays the GUIDE Quick Start dialog, as shown in the following
figure. From the Quick Start dialog, you can Create a new GUI from one of the GUIDE
templates -- prebuilt GUIs that you can modify for your own purposes. Open an existing GUI.
Once you have selected one of these options, clicking OK opens the GUI in the Layout Editor.
The Layout Editor :When you open a GUI in GUIDE, it is displayed in the Layout Editor, which
is the control panel for all of the GUIDE tools. The following figure shows the Layout Editor
with a blank GUI template. You can lay out your GUI by dragging components, such as push
buttons, pop-up menus, or axes, from the component palette, at the left side of the Layout Editor,
into the layout area. For example, if you drag a push button into the layout area, it appears as in
the following figure. You can also use the Layout Editor to set basic properties of the GUI
components
3.4 MATLAB
The MATLAB system consists of five main parts:
1. Development Environment:
This is the set of tools and facilities that help us to use MATLAB functions and files. Many of
these tools are graphical user interfaces. It includes the MATLAB desktop and Command
Window, a command history, an editor and debugger, and browsers for viewing help, the
workspace ,files, and the search path.
2. The MATLAB Mathematical Function Library:
This is a vast collection of computational algorithms ranging from elementary functions like
sum, sine, cosine, and complex arithmetic, to more sophisticated functions like matrix inverse,
matrix eigen values, Bessel functions, and fast Fourier transforms.
3. The MATLAB Language:
This is a high-level matrix/array language with control flow statements, functions, data
structures, input/output, and object-oriented programming features.
14
4. Graphics:
MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as
annotating and printing these graphs. It includes high-level functions for two-dimensional and
three-dimensional data visualization, image processing, animation, and presentation graphics. It
also includes low-level functions that allow you to fully customize the appearance of graphics as
well as to build complete graphical user interfaces on your MATLAB applications.
5. The MATLAB Application Program Interface (API):
This is a library that allows us to write C and Fortran programs that interact with MATLAB. It
includes facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as a
computational engine, and for reading and writing MAT-files.
15
PROJECT
DESCRIPTION
16
CHAPTER 4
PROJECT DESCRIPTION
4.1 PROBLEM DEFINITION
This project proposes a hybrid approach to compression. It incorporates lossy as well as lossless
compression. Although lossy compression techniques achieve very high compression ratios but
the decompressed image is not exactly same as the original one. Lossless methods on the other
hand, give very less compression ratios but exactly recover back the original image. Various
parts of image are compressed in either way, depending on the amount of information held in
that part and the importance of details required i.e region of interest is taken into consideration.
4.2 OVERVIEW OF THE PROJECT
This proposed system employs a hybrid approach to compression.It incorporates lossy as well as
lossless compression.Various parts of image are compressed in either way, depending on the
amount of information held in that part. This scheme consists of two stages. In the first stage the
image is filtered by a high pass filter to find the areas that have details. In the second stage, an
effective scheme based on Huffman coding and adaptive interpolation is developed to encode the
original image. With this algorithm, a good compression ratio is obtained, while, PSNR and
SSIM are better. In other words, the newly proposed algorithm provides an efficient means for
image compression.
4.3 MODULE DESCRIPTION
4.3.1 ADAPTIVE COMPRESSION[2]
To compress the image we proceed in the following manner. We start from the first pixel of the
image and select other eight adjacent pixels such that a square is formed. The zoomed in pixels
in Figure 4.1 show how a set is formed.
17
Figure 4.1 Partially Magnified Image
To form such sets (squares) we first check whether m and n are divisible by 3. If this is not the
case, then zero padding is done so that m and n become divisible by 3. This padding may lead to
some error which will be removed when original image is acquired back after decompression.
The image is then divided into non-overlapping squares and no pixel is missed as shown by
original image in Figure 4.2.
Figure 4.2 Image Representation
18
The center pixel from each set is chosen and a new image is formed using these pixels.
Consider an Image in matrix form which is of size (1024, 1024). The starting pixel is at position
(1, 1). Figure 4.3 represents a part of this matrix.
Figure 4.3 Image (in matrix form)
To compress it by the described method we first check whether 1024 is divisible by 3. As it is
not, we pad the image by 2 rows and 2 columns. The squares (sets) are formed starting from the
first pixel. The center pixels (boundaries highlighted) in Figure 4.3 are selected and stored in a
new matrix, say N shown in Figure 4. 4. As can be seen in Figure 4.3 pixel values at position
(2,2), (2,5), (5,2) becomes pixel values at position (1,1), (1,2),(2,1) respectively in Figure 4.4.
Similarly, the whole image is compressed.
Figure 4.4 Compressed Matrix
19
4.3.2 ADAPTIVE DECOMPRESSION[2]
This method involves application of second order interpolation over the compressed image.
Any pixel in the image has two values. First is its position (x, y) in the image and second is its
gray value G at that position. Figure 4.5 shows how a nth pixel which is at position (xp, yq) and
has gray value Gn, can be plotted in this coordinate system. We plot xp or yq on the ξ − axis
depending on whether we are moving in x or y direction (in the image)
respectively and on G−axis we plot the gray value Gn.
Assuming that compressed image is of size (m′, n′) and starts from (1, 1), decompression method
is implemented considering image as matrix:
1. We acquire the first pixel, P1,which is at position (1, 1) in the compressed image.
2. The next pixels chosen are P2 and P3 which are at position (1, 2) and (1, 3) in the compressed
image, considering we are moving in x direction.
3. Obtain the gray values of P1, P2 and P3 which are G1, G2 and G3 respectively.
4. Figure 4.2 shows us that originally two pixels were present between any two given adjacent
pixels of compressed image. Interpolate two pixels between P1 and P2 and two between P2 and P3
as follows:
• Figure 4.6 depicts the position of P1, P2 and P3 on _ v/s G axis. P1 is at (1,G1) and P2 is at
((1+3),G2) (leaving positions of two pixels) on this coordinate system and similarly P3 is at
((1 +6),G3).
Figure 4.5 Derived Curve
20
• The second order curve passing through these three points is 18G = (G1 − 2G2 + G3) ξ
2+ (−11G1 + 16G2 − 5G3) ξ + 28G1 − 14G2 + 4G3 (1)
It is depicted in Figure 4.6.
• Use Equation (1) to calculate values of the four interpolated pixels, say IP1, IP2, IP3 and IP4
which are at position 2, 3, 5 and 6 respectively, on ξ − axis ( refer Figure 4.6).IG1, IG2, IG3 and
IG4 are the calculated gray values of IP1, IP2, IP3 and IP4 respectively.
• Store G1, IG1, IG2, G2, IG3, IG4 and G3 in a new matrix at positions corresponding to the pixel’s
position in the decompressed image, i.e., at (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6)
and (1, 7).
5. Acquire next two pixels in the compressed image, such that no pixel is missed, in the x
direction as in Step 1 and 2. Repeat Steps 3 to 5until the whole image is decompressed in this
direction.
6. Repeat Steps 1 to 5 to decompress the image in y direction.
7. When the complete compressed image is decompressed in both the directions,
render the reconstructed image. Consider the compressed matrix of Figure 4.4.
We begin with taking first three pixels (1, 1), (1, 2) and (1, 3). As we are moving horizontally
we mark 1, 4, 7 on ξ − axis and 176, 176 and 193 on G−axis respectively for the three
points. Using this the second order equation is derived. We find four new points on this
curve corresponding to values ξ 2 = 2, ξ 3 = 3, ξ 5 = 5 and ξ 6 = 6 on ξ − axis. The values
come out to be 174, 174, 180 and 185. These four values are put in a new matrix as shown
by dashed arrows in Figure 4.6.
21
Figure 4.6 Compressed to Decompressed
When this procedure is continued in this direction on the whole compressed matrix
the resultant matrix obtained is as shown in Figure 4.7.This is the final decompressed image.
Figure 4.7 Final Decompressed Image
4.3.3 HUFFMAN ENCODING[4]
1. In Huffman encoding, we take the two least probable symbols in the alphabet(longest
codewords, equal length, differing in last digit)
2. Combine these two symbols into a single symbol, and repeat.
22
3. Say we have a image matrix with various pixel gray values.A source generates 4 different
symbols {A1,A2,A3,A4} with probability {0.4,0.35,0.2,0.05}.A binary tree is generated
from left to right taking the two least probable symbols and putting them together to form
another equivalent symbol having a probability that equals the sum of the two symbols.
The process is repeated until there is just one symbol as in Figure 4.8.
Figure 4.8 Huffman Tree
The tree can then be read backwards, from right to left, assigning different bits to
different branches. The final Huffman code is:
Symbol
Code
A1
0
A2
10
A3
110
A4
111
Table 4.1: Huffman Codes
23
\
4.3.4 HUFFMAN DECODING[4]
the process of decompression is simply a matter of translating the stream of prefix codes to
individual byte values, usually by traversing the Huffman tree node by node as each bit is read
from the input stream (reaching a leaf node necessarily terminates the search for that particular
byte value)
4.4 DATA FLOW DIAGRAM
The Data Flow diagram for the proposed system:
Figure 4.9: Context level Diagram of the system
24
Figure 4.10 : Level-0 Diagram of the system
Figure 4.11: Level-1 Diagram For Compression
25
Figure 4.12: Level-1 Diagram For Decompression
26
SYSTEM TESTING
27
CHAPTER 5
SYSTEM TESTING
5.1 UNIT TESTING
Testing includes the various cases to which the software was subjected to inorder to verify the
correctness in different aspects. These aspects include:
1. Correctness of functionality
2. Satisfying the requirements of problem statement
3. Performance criteria
4. Load criteria
In unit testing we tested the basic functionality of the core modules. All the modules were
checked to verify whether they are performing the desired function and whether the objective
behind the development of module was satisfied. All the modules were tested in isolation and
provided the desired results.
5.2 INTEGRATION TESTING
Integration testing consists of testing the entire software upon integrating the core functions and
modules under GUI.
After the basic data acquiring capability of the software was achieved, each function was first
developed and tested separately. After successful testing of each function, they were added one
by one to core module.
Integration of modules was done step by step so that any problems, if encountered would be
easier to deal with. The integration process did not generate any new problem as the modules
were added one by one. The approach for integrating the functions was top down. The GUI was
developed first followed by the rest.
28
5.3 SYSTEM TESTING
System testing is actually a series of different test whose primary purpose is to fully exercise the
computer – based system.
Although each test has different purpose, all worked to verify that system elements have been
properly integrated and perform allocated functions. Test cases were developed in order to test
the system for adequate results. The system testing involved testing various images for their
compression ratios and comparison of compression ratio for our algorithm, only Huffman and
only adaptive
5.4 TEST CASES
Input Image
Output
Test Case
Our algorithm
Huffman
Adaptive
compression
compression
interpolation
ratio
ratio
compression
Result
ratio
1
88.27
86
11
Passed
2
101.8
97.287
13.6711
Passed
3
29.47
25.678
11.1546
Passed
4
63.85
59.97
15.0638
Passed
Table 5.1 :Test Case 1: Our algorithm CR>Huffman CR
Image
Output
Test Case
Our algorithm
Huffman
Adaptive
compression
compression
interpolation
ratio
ratio
compression
Result
ratio
1
88.27
86
11
Passed
2
101.8
97.287
13.6711
Passed
3
29.47
25.678
11.1546
Passed
4
63.85
59.97
15.0638
Passed
Table 5.2:Test Case 2: Our algorithm CR>Adaptive CR
29
Image
Output
Test Case
Our algorithm
Huffman
Adaptive
compression
compression
interpolation
ratio
ratio
compression
Result
ratio
1
88.27
86
11
Passed
2
101.8
97.287
13.6711
Passed
3
29.47
25.678
11.1546
Passed
4
63.85
59.97
15.0638
Passed
Table 5.3 Test Case 3: Our algorithm CR>Adaptive CR & Huffman CR
Result: The system passed the test cases.
30
SYSTEM
IMPLEMENTATION
31
CHAPTER 6
SYSTEM IMPLEMENTATION
6.1 ALGORITHM[1]
In the implemented system the algorithm requires inputs as RGB images. It gives output as
Grayscale Images. In Grayscale images, each pixel represents gray value which ranges from 0 to
2b-1. 0 represents black and 2b-1 represents white. Here b denotes value of bits used for
representation. Generally images are represented by 8 bits so 0 represents Black and 255
represents White color.
6.1.1 ALGORITHM FOR COMPRESSION:
Step 1: The RGB image to be processed is converted into Grayscale image.
Step 2: The Grayscale image is passed through a Compass high pass filter to find region of
interest i.e. high frequency region in an image.
Step 3: The resultant image is then divided into blocks of equal size say 9*9 or anything.
Step 4: For each block
1. The gray value for each pixel is determined.
2. If less than half of these values are 0 (42 if block size is 9)then the blocked is marked for
Huffman encoding else for Adaptive Interpolation.
Step 5: The original input image is also divided into blocks of equal size and numbered so as to
understand for which block which algorithm is to be applied. Computations, from now onwards,
are carried out on the original image and not on the filtered one.
Step 6: Each block, starting from block number 1, is checked for which method it is marked for
Huffman encoding or Adaptive Interpolation.
Step 7 : All the blocks marked for Huffman encoding are placed together rowwise in a new
image matrix, ImgHuff.
Step 8 :In ImgHuff
32
1) For each position, (x, y), grey value, Gn, is obtained.
2) Number of occurence of each Gn is calculated.
3) Encode ImgHuff using the above calculated values.
4) This encoded matrix is represented as Comhuff
Step 9 :All the blocks marked for Adaptive Interpolation are placed together rowwise in image
matrix ImgInt.
1) ImgInt is divided into 3 × 3 blocks.
2) Centre pixel from each block is chosen as in
3) The chosen pixels form compressed image
Hence, the two images, ComHuff and ComInt, are the resultant compressed images
corresponding to the original image.
6.1.2 ALGORITHM FOR DECOMPRESSION
To reconstruct the original image the two compressed images, ComHuff and ComInt, are
considered. The procedure is outlined below:
Step 1 :We start with block number 1 and check whether it belongs to ComHuff or ComInt
matrix
Step 2 :If the nth block belongs to ComHuff
1) It is stored in a new image matrix ImgHuf1.This is done until all blocks compressed
by the Huffman method are stored in ImgHuf1.
2) ImgHuf1 is decoded back to original pixel values using Huffman decoding algorithm.
3) The decoded blocks are placed in reconstructed image, say DecomImg, according
to their number.
33
Step 3: If the nth block belongs to ComInt
1) We consider 9 pixels in a block of 3×3 size.
2) 2 pixels are interpolated, as in [2], between every two adjacent pixels.
3) As can be observed from Figure 2 the above step will return a block of 7 × 7 instead of
9 × 9. For the time being values of adjacent row and column are copied to make it of 9 × 9 size.
4) This block is placed in reconstructed image, DecomImg, according to its number.
Step 4 :To make DecomImg more close to the original image, we consider all those blocks which
were decompressed using adaptive interpolation.This is done because image data conatins
large amount of local redundancy . To explain this let us consider an interpolated block
starting at position (p, q) in DecomImg
1) We take gray values of pixels from (p−1, q) to (p − 1, q + 9) and from (p + 1, q) to
(p + 1, q + 9). Obtain their average and put in positions (p, q) to (p, q + 9). Similarly
average of (p + 8, q) to (p + 11, q + 9) and from (p + 11, q + 9) is placed in positions
(p + 9, q) to (p + 9, q + 9).
2) Similarly, we take gray values of pixels from (p, q − 1) to (p + 9, q − 1) and from
(p, q + 1) to (p + 9, q). Obtain their average and put in positions (p, q) to (p + 9, q).
Similarly average of (p, q+8) to (p+9, q+11) and from (p+9, q+11) is placed in positions
(p, q + 9) to (p + 9, q + 9).
3) The above two steps are repeated for all interpolated blocks in DecomImg and the
resultant image, say FinDecomImg, is obtained.
Step 5 FinDecomImg is the final reconstructed image.
34
6.2 CALCULATION OF PERFORMANCE METRICS
6.2.1 MSE(Mean Square Error)
MSE=∑
∑
Equation 6.1:Mean Square Error
where O is the original image and D is the decompressed
6.2.2 PSNR(Peak Signal-to-Noise Ratio)
PSNR=10 log 10 (255*255 / MSE)
Equation .6.2:Peak signal to Noise Ratio
6.2.3 SSIM
It measures similarity between images. It is a reference metric which measures quality of image
with respect to original image. It is calculated on sections of image. If x and y are two sections
then it is calculated as:
SSIM(x, y) = (2μxμy + c1)(2covxy + c2) /(μ2x + μ2y + c1)(σ2x + σ2 y + c2)
Equation 6.3:Structural Similarity Index
where μx the average of x, μy the average of y, σ2x the variance of x, σ2 y the variance of y, covxy
the covariance of x and y, c1 = (k1, L)2, c2 = (k2, L)2 two variables to stabilize
the division with weak denominator, L the dynamic range of the pixel-values, k1 = 0.01 and k2 =
0.03 by default
6.2.4 Compression Ratio
CR=size of Compressed image/size of Original image*100
Equation 6.4:Compression Ratio
35
6.3 BLOCK DIAGRAM
6.3.1 BLOCK DIAGRAM FOR COMPRESSION
Figure 6.1 : Block diagram for Compression
36
6.3.2 BLOCK DIAGRAM FOR DECOMPRESSION
Insert Values of
adjacent rows and
columns in place of
zeroes
Figure 6.2 : Block diagram for decompression
37
CONCLUSION &
FUTURE
ENHANCEMENTS
38
CHAPTER 7
CONCLUSION & FUTURE ENHANCEMENTS
7.1 RESULT ANALYSIS
Image
Compression
Ratio(Impleme
nted System)
Crowd. 101.8
Compressio
Compressio
MSE
PSNR SSIM
n Ratio(only n Ratio(only
Huffman )
Adaptive)
97.27
16.89
2.4
44.17
0.99
69.2435
68.1775
14.6016
26.48
33.905 0.97
88.27
86.9
11.56
5
41
61.01
15.06
0.0427 61.817 0.99
jpg
Thesur
es.jpg
New.jp
0.996
g
Xray.jp 64.07
g
7.1 Table : Compression Ratios and Comparison
39
Crowd.jpg
Figure 7.1 Input Image of Crowd.jpg
Figure 7.2 Output Image of Crowd.jpg
40
Thesures.jpg
7.3 Input image of Thesures.jpg
7.4 Output Image for Thesures.jpg
41
New.jpg
7.5 Input Image of New.jpg
7.6 Output image for New.jpg
42
Xray.jpg
7.7 Input Image of Xray.jpg
7.8 Output image of Xray.jpg
43
7.2 CONCLUSION
We have proposed a new compression technique which is suited for both lossy and lossless
compressions. Common compression techniques focus on either lossless or lossy mechanism.
The proposed method is a combination of both. Block coding methods often stress on same
method for all the blocks. Here, how the block will be coded depends on details it carries.
Adaptive interpolation and Huffman coding were the two methods used to implement the same.
The proposed method can be used for any type of image. For example, if we have a medical
image, where no data loss can be tolerated, then Huffman code will be executed on almost all
blocks. In another case, where loss of data is not comprehensible, then interpolation will be
used more often.
The decompressed images with good compression ratio ,MSE,PSNR and SSIM were obtained.
Different types of images were tested Text image, Galaxy image, Face image, Xray image,
Satellite images.etc.
7.3 FUTURE ENHANCEMENTS
A neural network can be made to learn the threshold on which it has to decide whether the
block has to be compressed in lossy or lossless manner.
The algorithm can be made faster for large images
The algorithm can be modified to ask user to change the thresholds
The algorithm can be modified so that user can select own region of interest.
44
APPENDIX
45
CHAPTER 8
APPENDIX
8.1 SOURCE CODES
function [ipsize,compsize,opsize,ssim,psnr,compratio,mse]= godhelpme(abcd)
inputimage=imread(abcd);
figure(1);
imshow(inputimage);
a=rgb2gray(inputimage);
[row1 col1]=size(a);
%Implement Compass Operator****************************
I=double(a);
s=size(I);
xa=[-1 -1 -1 ; 0 0 0;1 1 1];
xb=[xa(1,2) xa(1,3) xa(2,3);xa(1,1) xa(2,2) xa(3,3);xa(2,1) xa(3,1) xa(3,2)];
xc=[xb(1,2) xb(1,3) xb(2,3);xb(1,1) xb(2,2) xb(3,3);xb(2,1) xb(3,1) xb(3,2)];
xd=[xc(1,2) xc(1,3) xc(2,3);xc(1,1) xc(2,2) xc(3,3);xc(2,1) xc(3,1) xc(3,2)];
xe=[xd(1,2) xd(1,3) xd(2,3);xd(1,1) xd(2,2) xd(3,3);xd(2,1) xd(3,1) xd(3,2)];
xf=[xe(1,2) xe(1,3) xe(2,3);xe(1,1) xe(2,2) xe(3,3);xe(2,1) xe(3,1) xe(3,2)];
xg=[xf(1,2) xf(1,3) xf(2,3);xf(1,1) xf(2,2) xf(3,3);xf(2,1) xf(3,1) xf(3,2)];
xh=[xg(1,2) xg(1,3) xg(2,3);xg(1,1) xg(2,2) xg(3,3);xg(2,1) xg(3,1) xg(3,2)];
for x=2:1:s(1)-1;
for y=2:1:s(2)-1;
A11(x,y)=[xa(1)*I(x-1,y-1)+xa(2)*I(x-1,y)+xa(3)*I(x-1,y+1)+xa(4)*I(x,y1)+xa(5)*I(x,y)+xa(6)*I(x,y+1)+xa(7)*I(x+1,y-1)+xa(8)*I(x+1,y)+xa(9)*I(x+1,y+1)];
B11(x,y)=[xb(1)*I(x-1,y-1)+xb(2)*I(x-1,y)+xb(3)*I(x-1,y+1)+xb(4)*I(x,y1)+xb(5)*I(x,y)+xb(6)*I(x,y+1)+xb(7)*I(x+1,y-1)+xb(8)*I(x+1,y)+xb(9)*I(x+1,y+1)];
C11(x,y)=[xc(1)*I(x-1,y-1)+xc(2)*I(x-1,y)+xc(3)*I(x-1,y+1)+xc(4)*I(x,y1)+xc(5)*I(x,y)+xc(6)*I(x,y+1)+xc(7)*I(x+1,y-1)+xc(8)*I(x+1,y)+xc(9)*I(x+1,y+1)];
46
D11(x,y)=[xd(1)*I(x-1,y-1)+xd(2)*I(x-1,y)+xd(3)*I(x-1,y+1)+xd(4)*I(x,y1)+xd(5)*I(x,y)+xd(6)*I(x,y+1)+xd(7)*I(x+1,y-1)+xd(8)*I(x+1,y)+xd(9)*I(x+1,y+1)];
E11(x,y)=[xe(1)*I(x-1,y-1)+xe(2)*I(x-1,y)+xe(3)*I(x-1,y+1)+xe(4)*I(x,y1)+xe(5)*I(x,y)+xe(6)*I(x,y+1)+xe(7)*I(x+1,y-1)+xe(8)*I(x+1,y)+xe(9)*I(x+1,y+1)];
F11(x,y)=[xf(1)*I(x-1,y-1)+xf(2)*I(x-1,y)+xf(3)*I(x-1,y+1)+xf(4)*I(x,y1)+xf(5)*I(x,y)+xf(6)*I(x,y+1)+xf(7)*I(x+1,y-1)+xf(8)*I(x+1,y)+xf(9)*I(x+1,y+1)];
G11(x,y)=[xg(1)*I(x-1,y-1)+xg(2)*I(x-1,y)+xg(3)*I(x-1,y+1)+xg(4)*I(x,y1)+xg(5)*I(x,y)+xg(6)*I(x,y+1)+xg(7)*I(x+1,y-1)+xg(8)*I(x+1,y)+xg(9)*I(x+1,y+1)];
H11(x,y)=[xh(1)*I(x-1,y-1)+xh(2)*I(x-1,y)+xh(3)*I(x-1,y+1)+xh(4)*I(x,y1)+xh(5)*I(x,y)+xh(6)*I(x,y+1)+xh(7)*I(x+1,y-1)+xh(8)*I(x+1,y)+xh(9)*I(x+1,y+1)];
end
end
a1=max(max(max(max(max(max(max(A11,B11),C11),D11),E11),F11),G11),H11);
[hrow hcol]=size(a1);
%Padding bits****************************************
newrow=0;newcol=0;
if( hrow > hcol);
if (mod(hrow,9)==0);
newrow=hrow;
newcol=hrow;
B = padarray(a1,[newrow-hrow newcol-hcol],0,'post');
end
no = mod(hrow,9);
newrow=hrow+(9-no);
newcol=newrow;
B = padarray(a1,[newrow-hrow newcol-hcol],0,'post');
else
if mod(hcol,9)==0;
newcol=hcol;
newrow=hcol;
47
B = padarray(a1,[newrow-hrow newcol-hcol],0,'post');
end
no = mod(hcol,9);
newcol=hcol+(9-no);
newrow=newcol;
B = padarray(a1,[newrow-hrow newcol-hcol],0,'post');
end
[newrow newcol]=size(B);
newrowa=0;newcola=0;
if( row1 > col1);
if (mod(row1,9)==0);
newrowa=row1;
newcola=row1;
BA = padarray(a,[newrowa-row1 newcola-col1],0,'post');
end
no = mod(row1,9);
newrowa=row1+(9-no);
newcola=newrowa;
BA = padarray(a,[newrowa-row1 newcola-col1],0,'post');
else
if (mod(col1,9)==0);
newcola=col1;
newrowa=col1;
BA = padarray(a,[newrowa-row newcola-col1],0,'post');
end
48
no = mod(col1,9);
newcola=col1+(9-no);
newrowa=newcola;
BA = padarray(a,[newrowa-row1 newcola-col1],0,'post')
;
end
[row col]=size(BA);
%Mark blocks for Huffman or adaptive*******************************
flag=[];
pt=1;
for m=1:9:newrow-8;
for n=1:9:newcol-8;
sum=0;
for i=m:1:m+8;
for j=n:1:n+8 ;
if(B(i,j)==0);
sum=sum+1;
end
end
end
if(sum>42);
flag(pt)=0;
pt=pt+1;
else
flag(pt)=1;
pt=pt+1;
end
end
49
end
flr=length(flag);
Cadap=[];
divisions=newrow/9;
cr=1;cc=1;
pr=1;pc=1;
counta=0;
for m=1:1:flr;
if(flag(m)==0);
counta=counta+1;
for x=pr:1:pr+8;
for y=pc:1:pc+8;
Cadap(cr,cc)=BA(x,y);
cc=cc+1;
end
cr=cr+1;
cc=cc-9;
end
cr=1;
cc=counta*9+1;
end
if(mod(m,divisions)==0);
pr=pr+9;
pc=1;
else
pc=pc+9;
pr=pr;
50
end;
end
[cadapr cadapc]=size(Cadap);
Chuff=[];
counthuff=0;
cr1=1;cc1=1;
pr1=1;pc1=1;
for m=1:1:flr;
if(flag(m)==1);
counthuff=counthuff+1;
for x=pr1:1:pr1+8;
for y=pc1:1:pc1+8;
Chuff(cr1,cc1)=BA(x,y);
cc1=cc1+1;
end
cr1=cr1+1;
cc1=cc1-9;
end
cc1=counthuff*9+1;
cr1=1;
end
if(mod(m,divisions)==0);
pr1=pr1+9;
pc1=1;
else
pc1=pc1+9;
pr1=pr1;
51
end;
end
[chuffr chuffc]=size(Chuff);
%ADAPTIVE STARTS**********************************************
[rowca colca]=size(Cadap);
ComAdap=[];
i=1;
j=0;
for r=2:3:rowca-1;
for c=2:3:colca-1;
j=j+1;
ComAdap(i,j)=Cadap(r,c);
% disp(ComAdap(i,j));
end;
i=i+1;
j=0;
end;
ComAdap=uint8(ComAdap);
%HUFFMAN STARTS******************************************
Chuff = uint8(Chuff);
fprintf('Compresing data ... ')
[zipped,info] = norm2huff(Chuff);
[packed,table]=norm2lzw1(uint8(zipped),1000);
[unpacked,table]=lzw2norm1(packed,1000);
Dehuff = huff2norm(unpacked,info);
[carow cacol]=size(ComAdap);
52
%ADAPTIVE INTERPOLATION DECOMPRESSION******************
ImgAdap1=[];
r1=1;c1=1;
for i=1:1:carow;
for j=1:1:cacol;
%disp(c1);
ImgAdap1(r1,c1)=ComAdap(i,j);
if(mod(c1,7)==0);
c1=c1+1;
else
c1=c1+3;
end
end
c1=1;
r1=r1+1;
end
darow=1;dacol=1;
for i=1:1:carow;
for j=1:3:cacol-2;
for l=1:1:2;
for k=1:1:2;
dacol=dacol+1;
e=dacol;
ImgAdap1(darow,dacol)=((ComAdap(i,j)2*ComAdap(i,j+1)+ComAdap(i,j+2))*(e*e))+((16*ComAdap(i,j+1)-11*ComAdap(i,j)5*ComAdap(i,j+2))*e)+(28*ComAdap(i,j))-(14*ComAdap(i,j+1))+(4*ComAdap(i,j+2));
53
ImgAdap1(darow,dacol)=round(ImgAdap1(darow,dacol)/18);
end
dacol= (dacol+1);
end
dacol=dacol+1;
end
dacol=1;
darow=darow+1;
end
[dar dac]=size(ImgAdap1);
ImgAdap11=[];
r11=1;c11=1;
for i=1:1:dar;
for j=1:1:dac;
ImgAdap11(r11,c11)=ImgAdap1(i,j);
c11=c11+1;
end
if(mod(r11,7)==0);
r11=r11+1;
else
r11=r11+3;
end
c11=1;
end
darow1=1;dacol1=1;
for i=1:1:dac;
for j=1:3:dar-2;
for l=1:1:2;
54
for k=1:1:2;
darow1=darow1+1;
e=darow1;
ImgAdap11(darow1,dacol1)=((ImgAdap1(j,i)2*ImgAdap1(j+1,i)+ImgAdap1(j+2,i))*(e*e))+((16*ImgAdap1(j+1,i)-11*ImgAdap1(j,i)5*ImgAdap1(j+2,i))*e)+(28*ImgAdap1(j,i))-(14*ImgAdap1(j+1,i))+(4*ImgAdap1(j+2,i));
ImgAdap11(darow1,dacol1)=round(ImgAdap11(darow1,dacol1)/18);
end
darow1= (darow1+1);
end
darow1=darow1+1;
end
darow1=1;
dacol1=dacol1+1;
end
[finalrowa finalcola]=size(ImgAdap11);
Deadap=[];
r111=2;c111=2;
for i=1:1:finalrowa
for j=1:1:finalcola
Deadap(r111,c111)=ImgAdap11(i,j);
if(mod(j,7)==0)
Deadap(r111,c111+1)=ImgAdap11(i,j);
if(j~=finalcola)
55
Deadap(r111,c111+2)=ImgAdap11(i,j+1);
end
c111=c111+3;
else
c111=c111+1;
end
end
if(mod(i,7)==0);
[tpr1 tpc1]=size(Deadap);
for g=1:1:tpc1;
Deadap(r111+1,g)=Deadap(r111,g);
end
r111=r111+3;
else
if(mod(i,8)==0);
[tpr1 tpc1]=size(Deadap);
for g=1:1:tpc1;
Deadap(r111-1,g)=Deadap(r111,g);
end
r111=r111+1;
else
r111=r111+1;
end
end
c111=2;
end
56
[tpr11 tpc11]=size(Deadap);
for i=1:1:tpr11
Deadap(i,1)=Deadap(i,2);
end
[tpr11 tpc11]=size(Deadap);
for i=1:1:tpc11
Deadap(1,i)=Deadap(2,i);
end
[tpr11 tpc11]=size(Deadap);
clear ImgAdap1;
clear ImgAdap11;
%Merge Blocks of Huffman and Adaptive to get Final Decompressed Image**************
rowno1=1;colno1=1;FinalImg=[];counterforhuff=1;counterforadap=1;
for f=1:1:length(flag);
%disp('flag');disp(f);
if(flag(f)==1);
for i=counterforhuff:1:counterforhuff+81-1;
FinalImg(rowno1,colno1)=Dehuff(i);
if(mod(rowno1,9)==0);
rowno1=rowno1-8;
colno1=colno1+1;
else
rowno1=rowno1+1;
end
end
colno1=colno1-9;
counterforhuff=counterforhuff+81;
57
else
for i=1:1:9;
for j=9*counterforadap-8:1:9*counterforadap;
FinalImg(rowno1,colno1)=Deadap(i,j);
colno1=colno1+1;
end
colno1=colno1-9;
rowno1=rowno1+1;
end
rowno1=rowno1-9;
counterforadap=counterforadap+1;
end
if(mod(f,divisions)==0);
rowno1=rowno1+9;
colno1=1;
else
colno1=colno1+9;
end
end
FinalImg=uint8(FinalImg);
FinalImg1=imcrop(FinalImg,[0 0 col1 row1]);
FinalImg1=uint8(FinalImg1);
figure(2);
imshow((FinalImg1));
ComAdap=uint8(ComAdap);
58
[car cac]=size(ComAdap);
[zr zc]=size(packed);
compsize=(carow*cacol)+(zr*zc);
[rii cii zii]=size(inputimage);
ipsize=row1*col1;
[rfi cfi]=size(FinalImg1);
opsize=rfi*cfi;
%Calculate performance metrics****************
mse=mean((a(:)- FinalImg1(:)).^2);
psnr = 10*log10(255*255/mse);
mx=mean(a(:));
my=mean(FinalImg1(:));
x = var(a(:));
y = var(FinalImg1(:));;
ssim=((2*mx*my + 0.3)*(2*sqrt(x)*sqrt(y) + 0.5))/((my*my+mx*mx + .3)*(x+y+ 0.5));
compratio=compsize/ipsize*100;
59
8.2 SCREENSHOTS
8.1 GUI when started
60
8. 2 User selecting the image.
61
8. 3 The decompressed image appears
62
8. 4 when the user clicks results
63
REFERENCES
64
CHAPTER 9
REFERENCES
[1] Bhooshan S. and Sharma S.(2009) ‘An Efficient and Selective Image Compression Scheme
using Huffman and Adaptive Interpolation’ ,24th International Conference Image and Vision
Computing New Zealand (IVCNZ 2009),pp 197-202
[2] Bhooshan S. and Sharma S ’Image Compression and Decompression using Adaptive
Interpolation ‘,Proceedings of the 8th WSEAS International Conference on signal processing,
robotics and automation,pp 256-261
[3] X. Li, Y. Shen, and J. Ma, ‘An efficient medical image compression’ in Engineering In
Medicine And Biology 27th Annual Conference, Shangai, China, September 1-4 2005 IEEE.
[4] Huffman D., “A method for the construction of minimum redundancy codes,” in IRE, I.R.E,
Ed., vol. 40, no. 1098-1102. IRE, Sept. 1952, pp. 1098–1011.
[5] Gonzalez R.and Woods R,,Digital Image Procesing (Second Edition), Prentice Hall
[6] Athanassios Skodras, Charilaos Christopoulos, and Touradj Ebrahimi, ‘The JPEG 2000 Still
Image Compression Standard,’,IEEE Signal Processing Magazine, September 2001.
[7] Gonzalez, Woods, Eddins, Digital Image Processing Using MATLAB, 2nd edition, Prentice
Hall
[8] (Online) http://www.mathworks.in
[9] (Online) http://www.jpeg.org/jpeg/index.html
[10] (Online) http://www.ux.uis.no/~karlsk/index.html
[11](Online) http://www.cs.nyu.edu/~melamed/courses/102/lectures/huffman.ppt
[12] (Online) http://www.matlabgui.com
/
65