0% found this document useful (0 votes)
44 views34 pages

Major Report Pandey Final

The document discusses image compression using discrete cosine transform (DCT) via MATLAB. It presents the implementation of a JPEG image compression algorithm in MATLAB. The algorithm involves five main steps - RGB to YCbCr color space conversion, downsampling of chrominance components, 2D DCT, quantization, and entropy coding using Huffman encoding. The algorithm exploits human visual perception by storing luminance components with more detail than chrominance. Compression ratio, PSNR, and MSE are used to analyze image quality at different compression levels.

Uploaded by

Rohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views34 pages

Major Report Pandey Final

The document discusses image compression using discrete cosine transform (DCT) via MATLAB. It presents the implementation of a JPEG image compression algorithm in MATLAB. The algorithm involves five main steps - RGB to YCbCr color space conversion, downsampling of chrominance components, 2D DCT, quantization, and entropy coding using Huffman encoding. The algorithm exploits human visual perception by storing luminance components with more detail than chrominance. Compression ratio, PSNR, and MSE are used to analyze image quality at different compression levels.

Uploaded by

Rohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Image Compression Using FPGA via MATLAB

​Enrollment Numbers: 16102173, 16102029


Name of Students: Manik Chauhan, Rohit Pandey
Name of Supervisor: Dr. Rachna Singh

DECEMBER, 2019

Submitted in partial fulfilment of the Degree of Bachelor of Technology


DEPARTMENT OF ELECTRONICS AND COMMUNICATION
JAYPEE INSTITUTE OF INFORMATION TECHNOLOGY, NOIDA

1
CERTIFICATE

This is to certify that the work titled “​IMAGE COMPRESSION ​” submitted by “​Manik
Chauhan &Rohit Pandey​” in partial fulfilment for the award of degree of B.Tech of Jaypee
Institute of Information Technology, Noida has been carried out under my supervision. This
work has not been submitted partially or wholly to any other University or Institute for the award
of this or any other degree or diploma.

Signature of Supervisor ……………………..


Name of Supervisor:Dr. Rachna Singh
Designation ……………………..
Date

2
ACKNOWLEDGMENT

We express our deep sense of gratitude to Dr. Rachna Singh, Associate Professor in the
Electronics Department for encouraging us to take this project namely “Image compression using
Matlab”. We are highly indebted to our project mentor, Dr. Rachna Singh for her continuous
support, supervision, motivation and guidance throughout the tenure of our project in spite of
their hectic schedule and their experience gave us the light in handling this project and helped us
in clarifying the abstruse concepts, requiring knowledge and perception, handling critical
situations and in understanding the objective of our work.
Lastly, we would like to thank our colleagues and friends without whose support and constant
help this project wouldn‟t have been a reality.

Signature of the Student: ......................... .........................


Name of Student: Manik Chauhan Rohit Pandey
Date:

3
DECLARATION

We hereby declare that the work presented in this report entitled “IMAGE COMPRESSION”, in
partial fulfilment of the requirements for the award of the Degree of Bachelor of Technology in
Electronics and Communication Engineering, submitted in ECE Department of Jaypee Institute
of Information Technology, Noida, is an authentic record of the work carried out by us during
our degree under the guidance of Dr. Rachna Singh. The work reported in this has not been
submitted by us for award of any other degree or diploma.

MANIK CHAUHAN(16102173) …………………


ROHIT PANDEY(16102029) ............................

4
TABLE OF CONTENTS

Chapter No. Topics Page No​.


Certificate from Supervisor 2
Acknowledgement 3
Abstract 8
Chapter 1 ​ Introduction 9
​ ​
1.1 Types of Compression 11
1.1(a) Lossless Techniques
1.1(b) Lossy Techniques

1.2 Principles behind Image compression Image


Compression 14
1.3
Advantage of Image Compression 14
1.3(a)
1.3(b) Disadvantage of Image Compression Image

1.4 Decompression
Advantage of Image Decompression 15
1.4(a)
1.4(b) Disadvantage of Image Decompression
​Theory
Chapter 2​
Discrete Cosine Transform (DCT) 16
2.1
Quantization 16
2.2
ZigZag Sequencing 19
2.3
Huffman Encoding 20
2.4
Reconstruction of Image 21
2.5
Image Quality 24
2.6
25
Chapter-3 ​ lgorithms and Workings
A

3.1 System Implementation and Working 26


3.2 MATLAB Code 27

3.3 Working of Code 28

5
Chapter-4 SNAPSHOTS ​29
4.1 Code Snippets 30
4.2 Observations 32
Chapter 6 CONCLUSION ​33
References
References link ​34

6
LIST OF FIGURES

Figure No Title Page No

Fig1 Types of Lossless Techniques 11

Fig2 Types of lossy Techniques 12

Fig3 Discrete cosine transform 18

Fig4 Conversion from spatial domain to

frequency domain 18

Fig5 Quantization 20

Fig6 Zig-Zag pattern 21

Fig7 Huffman encoding tree 23

Fig8 Compression algorithm scheme 26

Fig9 RGB to YCbCr Conversion 29

Fig10 DCT & Quantisation 29

Fig11 Huffman Encoding 30

Fig12 Downsampling of Illuminance 30

Fig13 Observed YCbCr 30

Fig14 Downsampling of Image 31

Fig15 Final Compression 31

7
ABSTRACT
Due to increment in transmission of image,video over multimedia devices and different
applications,the use of image compression techniques in image processing evolved over the
years.Image compression is the reduction or elimination of redundancy in image representation
in order to achieve savings in storage and communication costs. Image compression techniques
can be broadly classified into two categories: Lossless, Lossy schemes. Digital images require an
enormous amount of space for storage.
In this project we have implemented image compression in Matlab using DCT
techniques.Discrete cosine transform(DCT) is computationally intensive algorithm it has a lot of
electronics application. DCT transforms the information time or space domain into frequency
domain to provide compact representation, fast transmission, memory saving. DCT is very
effective due to symmetry and simplicity.We have calculated image quality using different
metrics like Compression Ratio,PSNR and MSE.

8
CHAPTER 1
INTRODUCTION
Nowadays there is increased use of image in every part of our life.The development and demand
of multimedia product grows increasingly fast, contributing to insufficient bandwidth of network
and storage of memory device. Therefore, the theory of data compression becomes more and
more significant for reducing the data redundancy to save more hardware space and transmission
bandwidth. In computer science and information theory, data compression or source coding is
the process of encoding information using fewer bits or other information-bearing units than an
unencoded representation. Compression is useful because it helps reduce the consumption of
expensive resources such as hard disk space or transmission bandwidth.
JPEG is the most commonly used method of lossy compression for digital photography. In this
paper, we elaborate on the entire JPEG compression flow design and implementation in Matlab.
We also provide the Matlab implementation which is used to justify the result of our hardware
implementation.One of the most popular lossy compression methods is JPEG.JPEG stands for
joint photographic Expert Group. The JPEG compression can be divided into five main steps as
color space conversion, down-sampling, 2-D DCT, quantization and entropy coding .The first
two operations are used only for color images for gray scale image we use only last three steps.
The process of the JPEG starts with color space conversion this process is not applicable to
grey.scale image, where there is only one luminance component for gray scale image. Color
image data in computers is usually represented in RGB format. Each color component uses 8bits
to store ,thus ,a full color pixel would require 24 bits .

The human eyes are more sensitive to intensity change rather than color change, the JPEG
algorithm exploits this by converting the RGB format to another color space called YCbCr.Y is
luminance component ,Cb and Cr are chrominance components After converting the color space,
the encoder stores the luminance Y in more detail than the other two chrominance components.
The Y components represents the brightness of a pixel, the Cb and Cr components represent the
chrominance .this is the same color space as used by digital color television as well as digital
video including video DVDs, and is similar to the way color is represented in analog PAL video
space. Data compression is a technique to reduce redundancies in data representation in order to
decrease data storage requirements and hence communication costs. Reducing the storage
requirement is equivalent to increasing the capacity of the storage medium and hence
communication bandwidth. Thus the development of efficient compression techniques will
continue to be a design challenge for future communication systems and advanced multimedia
applications.

9
MATLAB (matrix laboratory) is a fourth generation programming language developed by
MathWorks. Matlab is an interpreted language for numerical computation. It allows one to
perform numerical calculations, and visualize the results without the need for complicated and
time consuming programming. Matlab allows its users to accurately solve problems, produce
graphics easily and produce code efficiently. This is extremely helpful in image processing as
images can be easily represented as a matrix and thus mathematically manipulated. Data
compression, also known as source coding and bit rate reduction involves encoding a given
information using fewer bits than the original representation.

1.1.Types of Compression:
I) Lossless Compression which reduces bits by identifying and eliminating statistically
redundant data while not losing any data.
II) Lossy Compression instead finds unnecessary information and ends up removing it.
Thus some data is lost. We will be using Lossy Compression as we will be concentrating on
compressing and watermarking photographs.
1.1(a) Lossless Technique​:

a. Entropy b. Run time c. LZW d. Huffman e. Arithmetic


A)Run Length Encoding (RLE) : It goes under the class of 'lossless information compression'.
‘RLE’ is a least difficult kind of information compression strategy. Runs term is utilized to store
information which additionally contains types of arrangement. RLE can be utilized as a design
document and ‘graphics file format’. It isn't reasonable for work uninterrupted tone pictures, for
example, photos, despite that fact that for JPEG it very fruitful.

Fig1:Types of Lossless Techniques​[9]

10
Entropy Encoding​:
Entropy encoders are utilized to minimize information by with the assistance of
cryptogram which constitute to a similar length codes by methods for images. Thus, the
most widely recognized images utilize the briefest codes.
Huffman coding​:
This is most effective coding system and is accustomed to produce least excess codes
contrasted with diverse calculations. This coding has effectively surmised as a part of content,
picture, video pressure, and also conferencing framework.
Arithmetic Encoding (AC)​:
It is a technique utilized for static lossless encoding. It gives extra adaptability and more
proficient capability than the Huffman coding. ‘AC’ for the most part conveys code words
with idea length. ‘AC’ is valuable strategy to code images compared to the likelihood of their
event. Every image is allotted an interval by the ‘AC’, whose size shows the likelihood for the
image's appearance. A normal number which has a place in the interval is the code expression
of the image.
‘LZW Coding’​:
The operation based algorithm, which is the’ LZW’ algorithm depends on the numerous events of
character arrangements in the string to be encoded. Amid the procedure the calculation goes over
the stream of data, codes it; if a string isn't minor or slight than the longest word in the dictionary
then it transmits. Through deciphering process, the calculation constructs the word reference
again the other way; in this manner, there is no compelling reason to store it.
1.1(b).Lossy technique​ :

Fig2:Types of lossy techniques[10]

11
Block Truncation coding​:

This is mainly used for grayscale images and come under the category of lossy image
compression. BTC usually divides the images in form of various blocks after which it sends them to
the quantizer for further process. In further process, it reduces it to grayscale levels. The main
purpose of each block is to maintain mean and deviation at each
point. BTC has also been adapted to color and video compression also. After BTC, AMBTC
come into existence in this, instead of standard deviation, it preserves the absolute value of image
along with the mean.
Transform Coding​:
In this old picture , it is separated into sub parts and coefficients of each piece are computed,
effectively changing over the first 8 x 8 array of pixel value into a coefficients arrays. Subsequent to
computing coefficients the following stage is to quantize the picture and the yield of the quantizer
is utilized by an image encoding system to deliver the yield bit stream which renders the encoded
picture. At the beneficiary side (receiver), the reverse of this process happens which is
dequantizing.
Discrete Cosine Transform (DCT)​:
This type of technique usually applies on blocks of ‘8 * 8’ or ‘16 * 16’ pixels. Following, it
changes it into arrangement of coefficients which comprises of spectral synthesis of ‘blocks’.
The transformer in DCT changes picture such information has lesser pixel redundancies in the
given picture. This is reversible and used to outline pixel onto an arrangement of
coefficients, which are encoded and also quantized . The primary favorable position of this system
is that the subsequent pictures have little sizes and can be quantized without causing decoded
picture to be crooked.
Discrete Wavelet Transform (DWT)​:
In this sort of system technique, picture is taken as a total of wavelet capacities/functions, known as
wavelets, with various area and scale. The picture produces the information into an arrangement of
detail and surmised coefficients. Right off the bat, the picture is separated into squares of 32×32.
Each piece or block is then gone through the filters : the principle undertaking of first filter is to
decompress the information into an estimated and detailed coefficients. In the wake of getting the
new transforming matrix, the detail and comparative coefficients which are isolated as ‘LL’, ‘HL’,
‘LH’, and ‘HH’ ‘coefficients’. Every one of the coefficients are disposed of aside from the ‘LL
coefficients’ that are changed into the second level. The coefficients are then gone through a steady
scaling component to accomplish the coveted ‘compression ratio’.

12
1.2 Principles Behind Compression​[1]
Image Compression addresses the problem of reducing the amount of data required to
represent the digital image. We can achieve compression by removing of one or more of three
basic data redundancies:

(1) Spatial Redundancy or correlation between neighboring pixels.


(2) Due to the correlation between different colour planes or spectral bands, the Spectral
redundancy is founded.
(3) Due to the properties of the human visual system ,the Psycho-visual redundancy is founded. 1.

1.3.ImageCompression:
Image compression is an application of data compression that encodes the original image
with few bits. The objective of image compression is to reduce redundancy of the image and
to store or transmit data in an efficient form. Image compression is minimizing the size in
bytes of a graphics file without degrading the quality of the image to an unacceptable
level. It involves minimization of the number of information carrying units, pixels. This
means that an image where adjacent pixels have almost the same values leads to spatial
redundancy. The reduction in file size allows more images to be stored in a given amount
of disk or memory space. It also reduces the time required for images to be sent over the
Internet or downloaded from Web pages. ​

1.3(a).Advantages of Image Compression:


● Less disk space(more data in reality).
● The quantity of bits used to store the data is reduced.
● Faster insertion and deletion.
● Faster file transfer.

● Can zip up several small files into a single file

1.3(b).Disadvantages of Image Compression :

● Added complication.
● Effect of errors in transmission.
● Slower for sophisticated methods
● Need to decompress all previous data

13
1.4.Image De-Compression :
The major goal of Image decompression is to image decompression is to decode and reconstruct
the original image. It is an application to get a much better image in terms of quality or size and
also we can get original images from their compressed form where we need that the quality of
the image is high whether it may be of higher size.

1.4(a)Advantages of Image De-Compression :

● Quality of the picture is maintained.

● More advantageous where HD pictures are required.

● Need not to decompress further.


1.4(b)Disadvantages of Image De-Compression :

● Requires more disk space.

● The quantity of bits used to store the data is increased.

● Slower insertion and deletion .

● Slower file transfer.

14
CHAPTER 2
THEORY

2.1.​Discrete Cosine Transform​[2]
The DCT is a special case of the well known Fourier transform.The Fourier transform in theory
can represent a given input signal with a series of sine and cosine terms. The discrete
cosine transform is a special case of the Fourier transform in which the sine components are
eliminated. For JPEG, a two-dimensional DCT algorithm is used, which is essentially the one-
dimensional version evaluated twice. By this property there are numerous ways to efficiently
implement a software or hardware based DCT module.The DCT is operated two
dimensionally taking into account an 8 by 8 block of pixels. The resulting data set is an 8 by
8 block of frequency space components, the coefficients scaling the series cosine terms, known
as basis functions.
The first element at row 0 and column 0, is known as the DC term, the average frequency
value of the entire block. The other 63 terms are AC components which represent the spatial
frequencies that compose the input pixel block, by scaling the cosine terms with in the
series. .
Formula for implementing 2-D DCT:

EqEn.1​[7]

There are two useful products of the DCT algorithm:

● It has the ability to concentrate image energy into a small number of coefficients.

● It minimizes the interdependencies between coefficients.

15
These two points essentially state why this form of transform is used for the standard JPEG
compression technique. By compacting the energy within an image, more coefficients are left to
be quantized coarsely, impacting compression positively, but not losing quality in the resulting
image after decompression. Taking away inter-pixel relations allows quantization to be

non-linear, also affecting quantization positively. DCT has been effective in producing great
pictures at low bit rates and is fairly easy to implement with fast hardware based
algorithms . Quantization, involved in image processing, is a lossy compression technique
achieved by compressing a range of values to a single quantum value. For example, reducing
the number of colors required to represent a digital image makes it possible to reduce its file
size.Quantization is opposite to sampling. It is done on y axis. When you are quantizing an
image, you are actually dividing a signal into quanta(partitions).The quantized below shown
above has 5 different levels of gray. It means that the image formed from this signal, would
only have 5 different colors. It would be a black and white image more or less with some
colors of gray. Now if you were to make the quality of the image more better, there is one
thing you can do here. Which is, to increase the levels, or gray level resolution up. If we
increase this level to 256, it means we have a grayscale image. Which is far better then simple
black and white image. Now 256, or 5 or whatever level you choose is called gray level.
Remember the formula that we discussed in the previous tutorial of gray level resolution
which is L=2^k On the x axis of the signal, are the coordinate values, and on the y axis, we
have amplitudes. So digitizing the amplitudes is known as Quantization. Quantization is an
extremely important step in the JPEG compression algorithm, as it removes a considerable
amount of information, thus reducing the entropy in the input data stream. Quantization alone,
is essentially a lossy compression technique. However, quantization does benefit the
compression process, regardless of the lossy artifacts that are produced. The high frequency
AC coefficients typically will become zero, which aids in entropy coding. Quantization is
intended to remove the less important components to the visual reproduction of the image.
However, quantization is most effective when less important elements are quantized more
coarsely. Larger quantization values will result in visual artifacts. Nonzero AC coefficients after
quantization are worse for compression, but will suppress blocking artifacts in the
reconstructed image. Blocking artifacts indicate high spatial frequencies caused by an absence of
AC coefficients. Essentially, quantization, when used effectively, will result in
high compression, with minimal loss in quality.
The spatial frequency representation is shown in the figure below.

Fig3:Discrete cosine transform​[14]

Fig4 : Conversion from spatial domain to frequency domain using DCT​[14]

17
2.2. Quantisation
Quantization, involved in image processing, is a lossy compression technique achieved by
compressing a range of values to a single quantum value. ... For example, reducing the number
of colors required to represent a digital image makes it possible to reduce its file
size.Quantization is opposite to sampling. It is done on y axis. When you are quantizing an
image, you are actually dividing a signal into quanta(partitions).The quantized below shown
above has 5 different levels of gray. It means that the image formed from this signal, would only
have 5 different colors. It would be a black and white image more or less with some colors of
gray. Now if you were to make the quality of the image better, there is one thing you can do
here. Which is, to increase the levels, or gray level resolution up. If you increase this level
to 256, it means you have a grayscale image. Which is far better than simple black and white
image.Now 256, or 5 or whatever level you choose is called gray level.
Remember the formula that we discussed in the previous tutorial of gray level resolution which
is L=2^k On the x axis of the signal, are the coordinate values, and on the y axis, we have
amplitudes.
So digitizing the amplitudes is known as Quantization.
Quantization is an extremely important step in the JPEG compression algorithm, as it removes a
considerable amount of information, thus reducing the entropy in the input data stream.
Quantization alone,is essentially a lossy compression technique. However, quantization does
benefit the compression process,regardless of the lossy artifacts that are produced. The high
frequency AC coefficients typically will become zero, which aids in entropy coding.
Quantization is intended to remove the less important components to the visual reproduction of
the image. However, quantization is most effective when less important elements are quantized
more coarsely. Larger quantization values will result in visual artifacts.Nonzero AC coefficients
after quantization are worse for compression, but will suppress blocking artifacts in the
reconstructed image. Blocking artifacts indicate high spatial frequencies caused by an absence of
AC coefficients. Essentially, quantization, when used effectively, will result in high
compression, with minimal loss in quality.

18
Fig5:Quantization[12]

2.3.Zig zag
First of all, zig-zag scanning is not a property of DCT itself but rather a part of the transform
based image coding process. Zig-zag scanning is employed after the quantization of DCT
coefficients per N x N image block, and before the Category / Run length coding of the
quantized coefficients. Typical natural images of N x N (N=8 most typical) blocks are low pass
which are reflected in their DCT coefficients as packing most of the signal energy in the lower
index coefficients and further distributing them circularly about the origin.
Zig-zag scanning of those coefficients therefore begins from low order coefficients and moves
through a circular pattern from inside to outside. The resulting 1D sequence, after a certain
number of initial non-zero coefficients (whose number is based on the quality setting) most of
the remaining quantized and ZZ scanned coefficients will be zero requiring no bits to encode;
hence compression. The Category / Run length encoding (RLE) is such that it counts the number
of "consecutive zeros" in the scanned sequence before coding a non-zero coefficient into a two
part symbol: sym1-sym2. Sym1 (category) is based on the magnitude of the coefficient being
coded and sym-2 (run length) is based on the number of zeros before that nonzero coefficient.
zig-zag scanning, therefore, orders the DCT coefficients into an efficient manner for
this category/run length coding phase to take advantage of their structure.

19
Quantized output is sent sequentially byte-by-byte in zig-zag pattern. Zig-zag operation is done
for every 8X8 block..The Run-length encoding for a data sequence having frequent runs of zeros.
Each time a zero is encountered in the input data, two values are written to the output file. The
first of these values is a zero, a flag to indicate that run length compression is beginning.
The second value is the number of zeros in the run. If the average run-length is longer than
two, compression will take place. On the other hand, many single zeros in the data can
make the encoded file larger than the original.

Fig6:Zig-Zag pattern​[11]

2.4.Huffman Coding
Huffman codes are widely used and very effective technique for compression data; saving
of 20% to 90% are typical, depending on the characteristics of the data being compressed. The
data to be considered here is the sequence of characters. Huffman’s greedy algorithm uses a
table of the frequencies of occurrence of characters to build up an optimal way of
representing each character as a binary string. Given a 100,000-character data file that
needs to be stored compactly.The data file contains only the characters a-f, with the
frequencies indicated. If each character is assigned as three bit codeword, the file can be
encoded in 300,000 bits. Using the variable length code shown, the file can be encoded in
224,000 bits, which saves approximately 25%. In fact,this is an optimal character code for this
file. Once the alphabet symbols have been defined, the compression efficiency can be
improved by using shorter code words for more probable symbols and longer codewords for
the less probable symbol.

20
This variable-length codewords belong to entropy coding scheme. Huffman coding is
one of the entropy coding techniques that JPEG uses in its compression
standard. We see here only codes in which no codeword is also a prefix of some other
codeword. Such codes are called prefix codes. It is possible to show that
the optimal data compression achievable by a character code can always be
achieved with a prefix code. Encoding is always simple for any binary character
code;
The codewords representing each character of the file are just concatenated. For
example, with a variable length prefix code of Table 1, the 3 characters abc
are coded as 0.101.100=0101100, where “.” is used to denote concatenation.
The decoding process needs a convenient representation for the prefix code so that the
initial codeword can be easily picked off. A binary tree, whose leaves are the given
characters provides one such presentation. We interpret the binary codeword for a
character as the path from the root to that character, where 0 means “go to the
left child”, and 1 means “go to the right child”. Figure 7 shows the tree for the
fixed length codes of the above example. Each leaf is labelled with a
character and its frequency of occurrence. Each internal node is labelled with
a sum of the frequencies of the leaves in its subtree. An optimal code
for a file is always represented by a full binary tree, in which every non-leaf
node has two children. If the tree is restricted to the full binary tree, then if C is the
alphabet from which the characters are drawn, then the tree for the optimal prefix code
has exactly |C| leaves, one for each letter of the alphabet, and exactly |C|-1
internal nodes. Figure 8 demonstrates a full binary tree, which realizes the
optimal prefix code for the above example. The problem with tree structures is that
they are very sensitive to memory errors, lacking exploitable redundancy. Trees
are constructed by using pointers to link nodes together and each node carries information
about itself, its parent and children. Therefore, if one internal node disappears as a
result of a memory error, then all its child nodes are lost. Coding by using
Huffman code tables is applied in the JPEG image compression
standard. The row and column indices indicate the code size as well as the zero run length
of the nonzero DCT coefficients in a block. The using of code table is described
more in the fault tolerance design for Huffman coding in JPEG compression systems.

21
Fig7:Huffman encoding tree​[10]

Huffman Algorithm Steps:

1) Reading the image in MATLAB

2) Calling functions which will discover the images .

3) Calling functions which will evaluate the symbol’s individual prospect.


4) Chances of symbols to crop up is to be orchestrated in decreasing order and lesser
probabilities are combined. This progression is proceeded until just two probabilities are
remaining, as per to these codes are appointed; the most highly apparent symbol will have a
diminished code length.
5) Thereafter, ‘Huffman encoding’ is operated i.e. aligning of code words to the complementary
‘symbols’.

6) Now, reconstruction of the old image i.e. decompression is executed applying’ Huffman

decoding’.

22
7) Code dictionary and code words are matched with each other to get the reconstructed image.
8) Then yield a tree comparable to the ‘encoding tree’.

9) Keep checking till the last element is read.


10) Continue with the process, till all codes of corresponding symbols are known.
2.5.Reconstruction method
Image reconstruction techniques are used to create 2-D and 3-D images from sets of 1-D
projections. These reconstruction techniques form the basis for common imaging modalities such
as CT, MRI, and PET, and they are useful in medicine, biology, earth science, archaeology,
materials science, and nondestructive testing. The mathematical foundation for these
reconstruction methods are the Radon transform, the inverse Radon transform, and the projection
slice theorem. Computational techniques include filtered backprojection and a variety of iterative
methods. Several projection geometries are commonly used, including parallel beam, fan beam,
and cone beam. The Shepp-Logan phantom image is often used to evaluate different
reconstruction algorithms. Image reconstruction plays a critical role in the clinical use of
magnetic resonance imaging. The MRI raw data is not acquired in image space and the role of
the image reconstruction process is to transform the acquired raw data into images that can be
interpreted clinically. This process involves multiple signal processing steps that each have an
impact on the image quality. This review explains the basic terminology used for describing and

quantifying image quality in terms of signal to noise ratio and point spread function. In this
context, several commonly used image reconstruction components are discussed. The image
reconstruction components covered include noise pre-whitening for phased array data
acquisition, interpolation needed to reconstruct square pixels, raw data filtering to reduce Gibbs
ringing artifacts,
Fourier transforms connecting the raw data with image space, and phased array coil combination.
The treatment of phased array coils includes a general explanation of parallel imaging as a coil
combination technique. The review is aimed at readers with no signal processing experience and
should enable them to understand what role basic image reconstruction steps play in the
formation of clinical images and how the resulting image quality is described.

23
2.6.Image Quality
Specific image reconstruction algorithms and signal processing steps they employ, it is important
to establish basic tools and terminology for characterizing the quality of the reconstructed image.
The term image quality is not meant to signify that one image is better than another. It is used
broadly here to mean any characteristics that discriminate one image reconstruction results from
another. There are many ways to characterize image reconstruction results. In this paper we will
adopt the somewhat simplified view that there are three different categories of images.
characteristics: a) signal-to-noise ratio (SNR) .
Compression ratio:​It can be described or interpreted as ratio of ‘given image’ size and size of
reconstructed image .

CR=𝑛1 /𝑛2
Eqn.2
n1=original image size
n2=reconstructed image size
Quality measure​:
Distortion-measure:’
Mean Square Error- MSE’ is a measure of distortion rate in the new compressed picture.

Eqn.3

‘PSNR​’: is for the most part used to gauge the nature of compacted picture which is given by

PSNR=10 log 255^2 /𝑀𝑆E Eqn.4

24
CHAPTER 3
ALGORITHM & WORKINGS

3.1.System Implementation and Working:

​Fig.8​:Compression algorithm scheme: (a) compression step and (b) decompression step JPEG
Process Steps for color images

● This section presents jpeg compression steps

● An RGB to YCbCr color space conversion ( color specification )

● Original image is divided into blocks of 8 x 8.


● The pixel values within each block range from[-128 to 127] but pixel values of a
black and white image range from [0-255] so, each block is shifted from[0-255] to
[-128 to 127].
● The DCT works from left to right, top to bottom thereby it is applied to each
block.

● Each block is compressed through quantization.

● Quantized matrix is entropy encoded.


● Compressed image is reconstructed through reverse process. This process uses the
inverse Discrete Cosine Transform (IDCT).

25
3.2.MATLAB CODE

I = imread(IMAGE');

Y_d = rgb2ycbcr( I );

% Downsample:

Y_d(:,:,2) = 2*round(Y_d(:,:,2)/2);

Y_d(:,:,3) = 2*round(Y_d(:,:,3)/2);

% DCT compress:

A = zeros(size(Y_d));

B = A;

for channel = 1:3

for j = 1:8:size(Y_d,1)-7

for k = 1:8:size(Y_d,2)

II = Y_d(j:j+7,k:k+7,channel);

freq = dct2(II);

freq = Q.*round(freq./Q);

A(j:j+7,k:k+7,channel) = freq;

B(j:j+7,k:k+7,channel) = idct2(freq);

end

end

end

26
3.3.Working of Code​[8]
Main Functions Explained
imread()
A = IMREAD(FILENAME,FMT) reads a grayscale or color image from the file specified
by the string FILENAME. The return value A is an array containing the image data.
If the file contains a grayscale image, A is an M-by-N array. If the file contains a true color
image, A is an M-by-N-by-3 array.

rgb2gray()
I = RGB2GRAY(RGB) converts the truecolor image RGB to grayscale intensity image.

dct2()
B = DCT2(A) returns the discrete cosine transform of A. The matrix B is the same size as A
and contains the discrete cosine transform coefficients.

flipud()
It flips matrix in up/down direction. FLIPUD(X) returns X with columns preserved and rows
flipped in the up/down direction.

idct()
B = IDCT2(A) returns the two-dimensional inverse discrete cosine transform of A.

27
CHAPTER 4
SNAPSHOTS

4.1.Code Snippets:

Fig.9:.RGB to YCbCr Conversion

​Fig.10.DCT & Quantisation

28
Fig.11.Huffman Encoding

4.2.OBSERVATIONS:

Fig.12.Downsampling of Illuminance

Fig.13.Observed YCbCr

29
Fig.14.Downsampling of Image

Fig.15.Final Compression

30
CHAPTER 5
CONCLUSION
This project successfully implemented the DCT for image compression. The system is designed
by using MATLAB software. This project has been tested for all possible situations on
MATLAB environment on Windows 10 and finally produced an 8x8 Compressed DCT image.
One of the main problems and the criticism of the DCT is the blocking effect. In DCT, images
are broken into blocks of 8x8 or 16x16 or bigger. The problem with these blocks is that when the
image is reduced to higher compression ratios, these blocks become visible. This has been
termed as the blocking effect. This image is compressed using 8x8 blocks and only 4 coefficients
are retained .and does so in nlogn time, or better.It also inspired many other algorithms that
compress images and video, and do so in a fashion very similar to JPEG.
Most of the variants of JPEG take the basic concepts of the JPEG algorithm and apply
them to more specific problems.Due to the immense number of JPEG images that exist, this
algorithm will probably be in use for at least 10 more years. This is despite the fact that better
algorithms for compressing images exist, and even better ones than those will be ready in the near
future.

RESULTS
Compression ratio: 6.72
Highest Compression ratio: 31.3
Lowest Compression ratio: 1

REFERENCE PAPERS RESULTS

Compression ratio =1.0033


PSNR= 37.86 dB

Compression ratio= 0.637963


PSNR= 25.506879

Compression ratio =0.642711


PSNR= 24.986462

31
32
REFERENCES

[1] ​Amit D. Landge, M.M. Deshmukh, B. P. Pardhi, S. A. Bagal,"Design and


Implementation of 8*8 DCT for Grayscale Image Compression​" IJCSN 2014 .
Ahmed N, Natarajan T, Rao KR ,​ Discrete Cosine Transform​. IEEE 1974.

[2] A.M.Raid, W.M.Khedr, M. A. El-dosuky and Wesam Ahmed1,"​Jpeg Image Compression


Using the Discrete Cosine Transform - A Survey​" .

[3] B.Raghu Kanth, S R Sastry Kalavakolanu, M.Aravind Kumar, D.N.Bhushan Babu,"JPEG


IMAGE COMPRESSION USING VERILOG​".

[4] ​A. K Jain, "​Fundamentals of digital image processing​" , Prentice Hall , Englewood Cliffs,
NJ, 1989 .

[5] Gopal Lakhani,"​Modified JPEG Huffman Coding IEEE transactions on Image Processing​
",VOL.12,NO.2,February 2003.

[6] A. S. Lewis and G. Knowles, "​Image Compression Using the 2-D Wavelet Transform"
IEEE Trans. on Image Processing​, Vol. I . NO. 2, PP. 244 - 250, APRIL 1992 .

[7] Giridhar Mandyam, Nasir Ahmed, Neeraj Magotra, “Lossless Image compression using
Discrete Cosine Transform”, Journal of Visual Communication and Image Representation ,Vol.8,
No.1, March, pp.21- 26, 1997, Article no. VC970323.

[8] https://www.researchgate.net/figure/Lossy-and-lossless-image-compression-
methods_fig1_25

[9] http://bhrigu.me/blog/2017/01/17/huffman-coding-python-implementation.

[10] https://www.ece.ucdavis.edu/cerl/reliablejpeg/compression.

[11] https://buzztech.in/sampling-and-quantization-in-digital-image-processing.

[12] https://www.securitylinkindia.com/technology-paper/2019/07/15/video-
compression-its-significance.

[13] https://people.ece.cornell.edu/land/courses/ece5760/FinalProjects/f2009/
jl589_jbw48/jl589_jb w48/index.html.

32
34

You might also like