Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

UNIVERSITY OF GONDAR

INSTITUTE OF TECHNOLOGY
DEPARTMENT OF ELECTRICAL AND COMPUTER
ENGINEERING

Project Title: Image compression using discrete cosine


transform
3rd YEAR SECTION #3
PROJECT REPORT

PREPARED BY: NAME ID


 SELAMAWIT BAYE 00468/10
 SAMRAWIT ASRAT 05056/11
 DAGNACHEW AYELE 00976/10
 BAHIRU MELESE 00366/10

SUBMITE TO: INSTRUCTOR BELAYNEH SUBMISSION DATE February 24th,2021

ACKNOWLEDGEMENT
1

University of gondar institute of technology


we would like to express our special thanks of gratitude to our instructor belayneh as who gave
us the golden opportunity to do this wonderful project on the topic Image compression and
decompression using DCT which also helped US in doing a lot of Research and we came to
know about so many things. 

ABSTRACT
Due to the increasing requirements for transmission of images in computer, mobile
environments, the research in the field of image compression has increased significantly. Image
compression plays a crucial role in digital image processing, it is also very important for efficient
2

University of gondar institute of technology


transmission and storage of images. When we compute the number of bits per image resulting
from typical sampling rates and quantization methods, we find that Image compression is
needed. Therefore, development of efficient techniques for image compression has become
necessary. This paper describes for lossy image compression, decompression using Discrete
Cosine Transform.

Contents page

University of gondar institute of technology


1. Introduction…………………………………………………………………..5

1.1 Atypical image coder……………………………………………………..6

1.2 Color specification……………………………………………………….6

2. objective………………………………………………………………..…..9

3. System model and result analysis……………………………………….…10

4. Conclusion……………………………………………………………..…12

5. Reference and appendix………………………………………………… 13

1. INTRODUCTION
Image compression is minimizing the size in bytes of a graphics file without degrading the
quality of image. Many applications need large number of images for solving problems. Image
Compression means reducing the amount of data required to represent a digital image. One of the
4

University of gondar institute of technology


most popular compression methods is Joint Photographic Expert Group (JPEG). JPEG create a
web page with a picture can be accessed faster than a web page with an image without
compression. JPEG provides for lossy compression of images. Image compression may be lossy
or lossless. Lossless compression is preferred for archiving and often for medical imaging,
technical drawings, etc. Lossy methods are especially suitable for natural images such as
photographs in applications. . Color image JPEG compression consists of five steps. The steps
are: color space conversion, down sampling, 2-D DCT, quantization and entropy coding.
The discrete cosine transform is a fast transform. It is a widely used and robust method for image
compression. It has excellent compaction for highly correlated data. DCT has fixed basis images
DCT gives good compromise between information packing ability and computational
complexity. Image compression is very important for efficient transmission and storage of
images.
JPEG provides a compression method that is capable of compressing continuous-tone image
data with a pixel depth of 6 to 24 bits with reasonable speed and efficiency.JPEG may be
adjusted to produce very small, compressed images that are of relatively poor quality in
appearance but still suitable for many applications DCT separates images into parts of different
frequencies where less important frequencies are discarded through quantization and important
frequencies are used to retrieve the image during decompression. Compared to other input
dependent transforms.
DCT has many advantages, these are:
(1) It has been implemented in single integrated circuit;
(2) It has the ability to pack most information in fewest coefficients;
(3) It minimizes the block like appearance called blocking artifact that results when boundaries
between sub-images become visible.
Various techniques can be used to compress the images to reduce their storage sizes as well as
using a smaller space. We can use two ways to categorize compression techniques.
 Lossy Compression System
Lossy compression techniques are used in images where we can sacrifice some of the finer
details in the image to save a little more bandwidth or storage space.
 Lossless compression system
Lossless Compression System aims at reducing the bit rate of the compressed output without any
distortion of the image. The bit-stream after decompression is identical to the original bitstream.

1.1 Atypical Image Coder

Three closely connected components form a typical lossy image compression system, they are
(a) Source Encoder (b) Quantizer and (c) Entropy Encoder.
5

University of gondar institute of technology


(a) Source Encoder (or Linear Transformer)
It is aimed at decorrelating the input signal by transforming its representation in which the
set of data values is sparse, thereby compacting the information content of the signal into
smaller number of coefficients. a variety of linear transforms have been developed such as
Discrete Cosine Transform (DCT), Discrete wavelet Transform (DWT), Discrete Fourier
Transform (DFT).
(b) Quantizer
A quantizer aims at reducing the number of bits needed to store transformed coefficients by
reducing the precision of those values. Quantization performs on each individual coefficient
i.e., Scalar Quantization (SQ) or it performs on a group of coefficients together, Vector
Quantization (VQ).
(c) Entropy Coding
Entropy encoding removes redundancy by removing repeated bit patterns in the output of
the Quantizer. the most common entropy coders are the Huffman Coding, Arithmetic
Coding, Run Length Encoding (RLE) and Lempel-Ziv (LZ) algorithm.

Figure 1: represents the encoding of image compression system

1.2 Color Specification


The YUV color coordinate defines Y, Cb, and Cr components of one-color image, where Y is
commonly called the luminance and Cb, Cr are commonly called the chrominance. the RGB
primary uses color display to mix the luminance and chrominance attributes of a light.
Describing of a color in terms of its luminance and chrominance content separately enable more
efficient processing and transmission of color signals in many applications. To obtain this goal,
various three-component color coordinates have been developed, in which one component(Y)
reflects the luminance and the other two collectively (Cb, Cr) characterize and saturation.

JPEG IMAGE COMPRESSION


The JPEG image compression system is composed of four main steps: image acquisition,
preprocessing, image compression and image decompression.

University of gondar institute of technology


A. Image Acquisition
The images are acquired by two techniques: online and offline. This system uses the offline
technique. The input image is RGB and JPEG type. And then, the size of the image is arbitrary
size. Bilinear interpolation is used to resize the pixel values of the original image.
B. Image Preprocessing In the preprocessing step, it is necessary to perform changing color and
chrominance down-sampling.
1. RGB to YCbCr Conversion: Changing color is necessary to transform for image
quantization. The luminance component represents the intensity of the image and look like a
gray scale version. The chrominance components represent the color information in the
image. In the image compression step, luminance and chrominance quantization is done after
transforming using DCT. Converting from color into YCbCr color space consists of the
luminance and two chrominance components.

2. Chrominance Down-sampling: After changing YCbCr color space, the image is down-
sampled by the factor of 2. The format is 4:2:0. Down-sampling can cause reduction of
pixels in chrominance (CbCr) in image compression system. Chrominance down-sampling
format is shown in figure1.

C. Image Compression
In the image compression step, the DCT image transform, image quantization and entropy
encoding are performed

1. DCT Image Transform


For image compression, Discrete Cosine Transform (DCT) is used. An input image f(x, y) is a
two dimensional M by N matrix image with different intensity values. To transform spatial to
frequency domain for image compression, the system is needed to determine with the forward
2D-DCT transformation equation.The transform matrix is calculated as shown .

Where i,j=0,1,2,3……N-1
P(x,y)=input matrixes.
D(i,j)=transformed matrix

2. Image Quantization
Quantization is the step where most of the image compression takes place. DCT really does not
compress the image because it is almost lossless. For obtaining quantization matrices with other
quality levels, scalar multiplications of standard quantization matrix are used. JPEG standard has
two quantization tables for the luminance and chrominance coefficients. Values of resultant
7

University of gondar institute of technology


matrix are then rounded to be the nearest integer value. The transformed image matrix by using
DCT is divided into the quantization matrix.

Quantization=
Quantization:
FQ(i,j)=round(F(i,j)/Q(i,j))
The compression level of an image can be controlled by a constant, which is generally called the
quality factor (Q factor). The quality levels ranging from 1 to 100 are selected, where 1 gives
poorest image quality and highest compression, while 100 gives the best quality and lowest
compression. Different JPEG compression programs have different Q-factors.

3. Entropy Encoding
In the entropy coding stage, the 8x8 block of quantization indices of the DCT coefficients (or
shortly quantized DCT coefficients) is compressed. Entropy encoding stage has the following
steps:
Step-1: Zigzag Scan
After quantization, the zigzag scan orders 64 coefficients (1 DC and 63 AC coefficients) into the
one-dimensional vector format. Zigzag order rearranges the quantized coefficients of each 8x8
block for further encoding.
The DC coefficient is encoded by using Digital Pulse Code Modulation (DPCM).The AC
coefficients are coded by applying the run-length encoding

.
8

University of gondar institute of technology


Step-2: DPCM on DC component
Differential Pulse Code Modulation (DPCM) is the coding method.
Step-3: Run Length Encoding (RLE) on AC component
After quantization and zigzag scanning, the one-dimensional vectors with a lot of consecutive
zeros are obtained. Thus, the run length coding technique is applied which called variable length
coding. The 63 AC coefficients in the original 64 quantized vectors first. To be more efficient
to save the non-zero values and to skip the number of zeros, run-length encoding is used.
Step-4: Huffman Coding
The Huffman algorithm begins with a set of symbols each with its frequency of occurrence
(probability) constructing what we can call a frequency table. The Huffman algorithm then
builds the Huffman Tree using frequency table. The tree structure contains nodes, each contains
a symbol, its frequency, a pointer to a parent node, and pointers to the left and right child nodes.
Successive passes through the existing nodes allows the tree to grow. Each pass searches for two
nodes that have the two lowest frequency counts, provided that they have not grown a parent
node. Anew node is generated when the algorithm finds those two nodes.
A new node is assigned as the parent of the two nodes and is given a frequency count that equals
the sum of the two child nodes. Those two child nodes are ignored by the next iterations which
include the new parent node. The passes stop when only one node with no parent remains. Only
one node with no parent will be the root node of the tree. Compression involves traversing the
tree beginning at the leaf node for the symbol to be compressed and navigating to the root. The
parent of the current node is iteratively selected and seen by this navigation to determine
whether the current node is the "right" or "left" child of the parent, therefore determining if the
next bit is a (1) or a (0). The final bit string is now to be reversed, because we are proceeding
from leaf to root

D. Image Decompression
In the image decompression step, each of the above compression steps is reversed in reverse
order.
1. Use the run length decoding technique to decode strings of bits into a 64-element array;
2. Reform the 64-element array into an 8 × 8 block;
3. Multiply each element in the block by a corresponding quantization value;
4. Performs the IDCT on the de-quantized block;
5. Add 128 to each of the de-transformed pixels to recover an approximation of the original
image.

OBJECTIVE
the main objective of this project are…..

University of gondar institute of technology


 Reduce irrelevance and redundancy of the image data to able to store.
 It represent minimizing the number of bits of the image.
 Large images can be transmitted through a lower storage and band width.

SYSTEM MODEL AND RESULT ANALYSIS


A. Design Model of the Proposed System
In this paper, Discrete Cosine Transform (DCT) is applied to implement image compression
system. The overall block diagram of the proposed system is shown in figure 2

Original Image RGB to YCbCr Down-sampling

Entropy Encoding Quantization Forward DCT

Entropy Decoding Dequantization Inverse DCT

Output Image YCbCr to RGB Up-sampling

Figure 2. Overview of JPEG Compression and decompression process

In image preprocessing step, RGB and YCbCr conversion is included. This is explained in the
background theory. DCT transform, image quantization and entropy encoding are included in
image compression system. Image decompression step includes the reverse processes of image
compression.

B. Implementation of the Proposed System


There are two main steps in the image compression system. The first step is image compression
and the second step is image decompression.
the performance parameters are compression time MSE, compression ratio (CR) and PSNR are
not the same.

The result to compress the original image.

10

University of gondar institute of technology


Figure 3, over view of compressed image.

The result we can get to decompress the compressed image.

Figure 4, over view of the decompressed image.

Conclusion
Image compression is an extremely important part of modern computing. The JPEG image

11

University of gondar institute of technology


compression algorithm proves as a very effective way to compress images with minimal loss in
quality. Using the run length coding, the results may be compared with the above outputs which
are implemented by using MATLAB. The performance of this research is measured by
compression ratio. The performance of compression can be increased when the Q-factors are
increased. The performances of compression are not the same because of different Q-factors and
different images. In this paper, our work deals with deals with the JPEG Encode for image
compression upon comparing with Discrete cosine transform (DCT) is widely used in image
processing, especially for compression and decompression based on DCT

REFERENCE
[1] K. Deepthi: “Design and Implementation of JPEG Image Compression and Decompression”.
International Journal of Innovations in Engineering and Technology (IJIET) CVSR College of Engineering,
Hyderabad, Andhra Pradesh, India Vol. 2 Issue 1 February (2013)

[2] N. Ahmed, T. Natarajan, and K. R. Rao, "Discrete cosine transform," IEEE Trans. on Computers, vol. C-
23, pp. 90-93,1974

[3] A. B. Waston Mathematica Journal, vol. 4, no. 1, pp. 81-88, 1994. http://vision.arc.nasa.gov/ Image
Compression Using Discrete Cosine Transform, Andrew B. Waston publications/mathjournal94.pdf

[4] Bonnie L.Stephens, Student Thesis on “Image Compression algorithms”,California State University,
Sacramento, August 1996.

Appendix:
function varargout = selam(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @selam_OpeningFcn, ...
'gui_OutputFcn', @selam_OutputFcn, ...
'gui_LayoutFcn', [] , ...
12

University of gondar institute of technology


'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function selam_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = selam_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function p2_Callback(hObject, eventdata, handles)
imagename=get(handles.e1,'String');
handles.img = rgb2gray(imread(imagename));
axes(handles.a1);
imshow(handles.img);
imageinfo(handles.img)
get( handles.img,'Color')
title('orginal image');
guidata(hObject,handles);
function a2_CreateFcn(hObject, eventdata, handles)
function a1_CreateFcn(hObject, eventdata, handles)
function a3_CreateFcn(hObject, eventdata, handles)
function e1_Callback(hObject, eventdata, handles)
[filename ,pathname] = uigetfile({'*.jpg';'*.bmp'},'File Selector');
handles.myImage = strcat(pathname, filename);
axes(handles.a1);
imshow(handles.myImage)
set(handles.edit1,'string',filename);
set(handles.e1,'string',image);
guidata(hObject,handles);
function e1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in p5.
function p5_Callback(hObject, eventdata, handles)
imagename=get(handles.e1,'String');
handles.img = imread(imagename);
axes(handles.a3);
image(handles.img);
guidata(hObject,handles);
im=imread(imagename);
im=double(im)/225;
im=rgb2gray(im);
img_dct=dct2(im)
img_pow=(img_dct);
img_pow=img_pow(:);

13

University of gondar institute of technology


[B,index]=sort((img_pow).^2);
B=flipud(B);
g=10000000;
index=flipud(index);
compressed_dct=zeros(size(im));
f=1;
for k=1:f;
compressed_dct(index(k))=img_dct(index(k));
end
im_dct=idct2(compressed_dct);

imshow(im_dct)
title('compressed using dct at f=1500');
imwrite(im_dct,'compressed.JPG')
axes(handles.a3);
CR=f/g;
set(handles.edit2,'string',CR);
function p1_Callback(hObject, eventdata, handles)
[filename,pathname]=uigetfile(...
{'*.jpg;*.gif;*.png;*.bmp',...
'image file(*.jpg,*.gif,*.png,*.bmp)';'*.*','all files(*.*)'},...
'open the image file to be verified');

set(handles.e1,'string',filename);

function a4_CreateFcn(hObject, eventdata, handles)


function a3_ButtonDownFcn(hObject, eventdata, handles)
function p3_Callback(hObject, eventdata, handles)
imagename=get(handles.e1,'String');
handles.img = imread(imagename);
axes(handles.a2);
image(handles.img);
guidata(hObject,handles);
im=imread(imagename);
im=double(im)/255;
im=rgb2gray(im);
img_dct=dct2(im);
img_pow=(img_dct);
img_pow=img_pow(:);
[B,index]=sort((img_pow).^2);
B=flipud(B);
g=10000000;
index=flipud(index);
compressed_dct=zeros(size(im));
f=4000;
for k=1:f;
compressed_dct(index(k))=img_dct(index(k));
end
im_dct=idct2(compressed_dct);
plot (212)

14

University of gondar institute of technology


imshow(im_dct)
title('compressed dct at f=4000');
imwrite(im_dct,'compressed.JPG')
axes(handles.a2);
o=26.2;
c=9.1;
CR=c/o;
set(handles.edit2,'string',CR);
function p7_Callback(hObject, eventdata, handles)
imagename=get(handles.e1,'String');
handles.img = imread(imagename);
axes(handles.a4);
image(handles.img);
guidata(hObject,handles);
im=imread(imagename);
im=double(im)/255;
im=rgb2gray(im);
img_dct=dct2(im);
img_pow=(img_dct);
img_pow=img_pow(:);
[B,index]=sort((img_pow).^2);
B=flipud(B);
g=10000000;
index=flipud(index);
compressed_dct=zeros(size(im));
f=50;
for k=1:f;
compressed_dct(index(k))=img_dct(index(k));
end
im_dct=idct2(compressed_dct);
plot (212)
imshow(im_dct)
title('compressed dct at f=50');
imwrite(im_dct,'compressed.JPG')
axes(handles.a4);
% CR=f/g;
set(handles.edit2,'string',CR);
function figure1_CreateFcn(hObject, eventdata, handles)
function p8_Callback(hObject, eventdata, handles)
imagename=get(handles.e1,'String');
handles.img = imread(imagename);
axes(handles.a4);
image(handles.img);
guidata(hObject,handles);
title('orginal image');
im=imread(imagename);
im=double(im)/225;
im=rgb2gray(im);
img_idct=idct2(im);
img_pow=(img_idct);
15

University of gondar institute of technology


img_pow=img_pow(:);
[B,index]=sort((img_pow).^2);
B=flipud(B);
g=10000000;
index=flipud(index);
compressed_idct=zeros(size(im));
f=1000000;
for k=1:f;
compressed_idct(index(k))=img_idct(index(k));
end
im_dct=idct2(compressed_idct);
imshow(im_dct)
title('decompressed dct at f=1000');
DR=f/g;
set(handles.edit7,'string',DR);
function p6_Callback(hObject, eventdata, handles)
imagename=get(handles.e1,'String');
handles.img = imread(imagename);
axes(handles.a3);
image(handles.img);
guidata(hObject,handles);
title('orginal image');
im=imread(imagename);
im=double(im)/225;
im=rgb2gray(im);
img_idct=idct2(im);
img_pow=(img_idct);
img_pow=img_pow(:);
[B,index]=sort((img_pow).^2);
B=flipud(B);
g=10000000;
index=flipud(index);
compressed_idct=zeros(size(im));
f=1500000;
for k=1:f;
compressed_idct(index(k))=img_idct(index(k));
end
im_dct=idct2(compressed_idct);
imshow(im_dct)
title('decompressed dct at f=1500000');
cr=f/g;
set(handles.edit7,'string',DR);
function pd4_Callback(hObject, eventdata, handles)
imagename=get(handles.e1,'String');
handles.img = imread(imagename);
axes(handles.a2);
image(handles.img);
guidata(hObject,handles);
title('decompressed image');
im=imread(imagename);
im=double(im)/225;
im=rgb2gray(im);

16

University of gondar institute of technology


img_idct=idct2(im);
img_pow=(img_idct);
img_pow=img_pow(:);
[B,index]=sort((img_pow).^2);
B=flipud(B);
g=1000000;
index=flipud(index);
compressed_idct=zeros(size(im));
f=10000000;
for k=1:f;
compressed_idct(index(k))=img_idct(index(k));
end
im_dct=idct2(compressed_idct);
imshow(im_dct)
g=10000000;
DR=f/g;
set(handles.edit7,'string',DR);
function uipanel2_CreateFcn(hObject, eventdata, handles)
function edit2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function a3_DeleteFcn(hObject, eventdata, handles)
function p7_ButtonDownFcn(hObject, eventdata, handles)

17

University of gondar institute of technology

You might also like