0% found this document useful (0 votes)
15 views7 pages

JPEG Image Compression with MATLAB

The document discusses JPEG image compression using MATLAB, detailing the encoding process of grayscale images and comparing compression ratios and encoding times between classic and fast DCT methods. It explains the JPEG standard, types of images, and the advantages and disadvantages of JPEG compression, along with a MATLAB code implementation for compressing images. The project concludes that JPEG compression effectively reduces image size while maintaining acceptable quality, utilizing techniques such as DCT and quantization.

Uploaded by

Rajorshi De
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)
15 views7 pages

JPEG Image Compression with MATLAB

The document discusses JPEG image compression using MATLAB, detailing the encoding process of grayscale images and comparing compression ratios and encoding times between classic and fast DCT methods. It explains the JPEG standard, types of images, and the advantages and disadvantages of JPEG compression, along with a MATLAB code implementation for compressing images. The project concludes that JPEG compression effectively reduces image size while maintaining acceptable quality, utilizing techniques such as DCT and quantization.

Uploaded by

Rajorshi De
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

e-ISSN: 2582-5208

International Research Journal of Modernization in Engineering Technology and Science


Volume:03/Issue:05/May-2021 Impact Factor- 5.354 [Link]

JPEG IMAGE COMPRESSION USING MATLAB


Sharan Reddy Ayiluri*1, Sampath Kumar Yelchuri*2, Vusa Laxumudu*3, Gorrepati
Praveen Sajan*4, Arvapalli Yaswanth Pavan Kumar*5, Kulraj Kaur*6
*1,2,3,4,5,6Electronics And Communication, Engineering Lovely Professional University,
Phagwara, Punjab, India.
ABSTRACT
In this project we have done JPEG compression using MATLAB. We have done the encoding of grayscale images
in JPEG. With this project we have also shown the differences between the compression ratios and time spent in
encoding the images with classic DCT and fast DCT. The Encoding starts with dividing he original image in 8^8
blocks of sub images. The DCT is performed separately on these sub images. And followed results are divided to
matrices by a Quantization Matrix. The final step in algorithm is to make data one dimensional by using zigzag
coding and compressed by Huffman coding and run level coding. To restore the original image the Inverse DCT
is performed.
I. INTRODUCTION
The Multimedia images plays a crucial role in storing the moments and memories of day to day life. The size of
the data that is encoded in each image is very large. Due to large size of the image we must compress them for
applications. So, to eliminate this problem the JPEG image compression has been introduced. The decrease in
the storage capacity and without losing out much information in the images makes this application usage faster.
The JPEG(Joint Photographic Experts Group) is first introduced in 1992, since introduction, it is most widely
used image compression standard in the world. JPEG is also termed as JPG, which is a commonly used method
of lossy and lossless compression for digital images. For this JPEG images, the degree of compression can be
adjusted by using a selectable trade-off in between the storage size and the image quality. The JPEG images
typically achieve 10:1 compression with a slight loss in image quality. It uses a lossy form of compression based
on the discrete cosine transform(DCT). The lossy image compression was first proposed by Nasir Ahmed in
1972. The JPEG compression is used in several image file formats. Whereas most common image format used
by digital cameras and other photographic images are JPEG/Exif. These formats are simply called JPEG. The
JPEG compression algorithm is mostly done on photographs and paintings with small variations in tone and
[Link] file format enables the bitstreams to be exchanged between a large variety of platforms and
applications.
II. TYPES OF IMAGES
IMAGE TYPE INTERPRETATION
Binary Logical arrays having only 0 and 1 are named as black and white

Indexed Array class logically called as unit8, unit16, single, or double, where pixel values
directly indicates colour map. The colour map is an m-by-3 array of class double.

Grayscale Array of class unit8, unit 16, int16,single, or double whose pixel values specify
intensity values. For single or double arrays, value ranges from (0,1). For unit8
value ranges from (0,255). For unit16, values range from (0,65535). For int16 ,
values from (-32768,32767).

TrueColor m-by-n-by-3 array of class unit8, unit16, single, or double whose pixel values
specify intensity values. For single or double arrays, value ranges from (0, 1). For
unit8 value ranges from (0, 255). For unit16, values range from (0, 65535).

III. IMAGE COMPRESSION


The images are generally compressed to decrease the space required to store the images without changing the
information present in the images. The compressed image will be of a lower quality with respect to the original
image and is easy to transmit or download.
[Link] @International Research Journal of Modernization in Engineering, Technology and Science
[663]
e-ISSN: 2582-5208
International Research Journal of Modernization in Engineering Technology and Science
Volume:03/Issue:05/May-2021 Impact Factor- 5.354 [Link]
Lossless Compression:
It is a data compression that uses an algorithm which converts the data from a compressed image into original
image. Lossless compression does not eliminate the data which is not noticeable. The file format can be
restored in its original form. The compression does not compromise the data quality. This compression holds
less data capacity compared to lossy compression. It is also termed as reversible compression.

Fig 1: Block diagram of Lossless compression method

Lossy Compression:
The Lossy compression is a data compression of the size of the file is reduced by removing the data in the file.
While compression makes the image quality to be decrease file size. It eliminates the data which is not
considered. While compression the file does not rebuild in its original form. It is used in Images, Audio, Video. It
is also termed as irreversible compression.

Fig 2: Block diagram of Lossy compression method


The serial process of compression of image starts with conversion of RGB image into YIQ if required. The
resulted image is then transformed by DCT transformation. In the quantization unnecessary data of the image is
eliminated from size and quality. Encoding of the image is done for protection by changing the names of the
values of the quantized image by passing the image into channel encoder. The decompression of the image can
be done by simply reversing the process image have gone through during the compression process. The image
is decoded by passing the image through the channel decoder followed by the entropy decoder. The image is
involved in inverse quantization retrieves the lost data of the image. Passing through the inverse
transformation phase forms the original image. The Image Compression is a method in which it reduces the

[Link] @International Research Journal of Modernization in Engineering, Technology and Science


[664]
e-ISSN: 2582-5208
International Research Journal of Modernization in Engineering Technology and Science
Volume:03/Issue:05/May-2021 Impact Factor- 5.354 [Link]
measure of information required to speak to an advanced image. And this can be obtained by expelling the
redundancies. Some of the important techniques used for redundancies are:
1. Spatial redundancy
2. Spectral redundancy
3. Psycho-visual redundancy
1. Spatial redundancy:
The redundancy in which there is a correlation between the neighbouring pixel values is known as spatial
redundancy.
[Link] redundancy:
The correlation between different spectral bands and different colour planes is known to be spectral
redundancy.
[Link]-visual redundancy:
The tendency of which the unimportant information of the human visual system is removed is known as
psychovisual redundancy.
IV. DISCREATE COSINE TRANSFORM
Discrete Cosine Transform is an algorithm which is used to develop fast Fourier transform. It is first introduced
in 1972 by Nasir Ahmed. It is used mostly in digital processing that makes us to find the patterns and to
implement the Wiener filtering. It is as similar as Discrete Fourier transform which transforms the image from
spatial domain to frequency domain. It does not reduce the number of bits required for the block. The DCT can
be considered as ratio of the performance versus computational cost that has been adopted for international
standards. It has areal transform with great advantages in energy compaction. There are many variants in the
DCT but mostly we must concern with the principles. When we compare the speed implementations the DCT is
fast than DFT. Due to cosine basis functions the DCT is a shift variant, with one important exception. It is not
proved possible to implement convolution with the DCT.
DCT expresses a finite sequence of the data points in terms of a sum of cosine functions oscillating at the
different frequencies. It is widely used for digital media in which are known to be digital audio and videos,
radios, and speech coding’s. This transform is mostly used in science and engineering applications.

Fig 3: DCT formed by Image compression


JPEG process:
 The first step in image compression is that to break the image into 8^8 blocks.
 While the breaking is done, we must apply the DCT to each image.
 Therefore, by quantization each block is get compressed.

[Link] @International Research Journal of Modernization in Engineering, Technology and Science


[665]
e-ISSN: 2582-5208
International Research Journal of Modernization in Engineering Technology and Science
Volume:03/Issue:05/May-2021 Impact Factor- 5.354 [Link]
 The array of compressed blocks that constitute the image gets stored by drastically reduced amount of
space.
The Compression of the Image starts with converting the original image which is in RGB colours into YIQ or
YUV. The letter Y in YIQ shows the brightness and IQ represents the chromeness. In YUV, Y represents the
brightness and UV represent the colour of the image. The colour transformed image is involved in sampling in
8x8 block extractor. Image formed after sampling contains values f (u, v) where u and v represent different
blocks of the image. The values are now passed through the Discrete Courier Transform as the next step. The
unwanted values are removed then quantization process reduces the size and quality. In encoding process zero
and non-zero values are aligned in zig zag form for representing the f (u, v) values as dc1 and ac1 respectively.
The values that are lost during the entire process results in the compressed image. The Discrete Cosine
Transform which is just like Discrete Fourier Transform is implemented by using only real numbers. The DCT is
mostly related to the Fourier transform series. The use of cosine and sine functions are critical for compression,
fewer cosine functions are needed to approximate a typical signal, the cosine express the discrete Fourier
transform. The DCT is mostly related to Fourier series coefficients of symmetrically and periodically sequence.
The DFT are mostly related to periodically sequence. There are eight standard DCT variants in which the most
used is the type- II DCT. The DCT is also called Block compression, which compresses the data to discreate DCT
blocks. The DCT blocks have several sizes, with 8x8 pixels for standard DCT and 4x4 and 32x32 pixels for
varied DCT. The DCT has a strong energy compaction property, which can achieve high quality at high data
compression ratios. The blocky compression artifacts can appear when heavy DCT compression is applied. The
DCT is widely used in many applications.
V. ADVANTAGES AND DISADVANTAGES
Advantages:
 This Image format has been using since long time and is extremely portable.
 The format is very easy to read so they can be understood easily by printers to print.
 JPEG format is used to store high resolution images where some of them are blur shows small in size
format.
 These format images are easy to share from devices to devices.
 The size in JPEG images can be reduced and compressed. In which the file format is suitable for
transferring images from internet to devices.
Disadvantages:
 Compression in JPEG format loses certain actual contents of the image.
 Quality of the image is reduced after compression owing to the loss of actual content of the image.
 This compression is not suitable for images which having sharp line sand edges.
 This type of format is not capable for handling animated graphic images.
 In JPEG format only 8bit images are supported. But modern high-resolution digital cameras support 10,
12, 14or16 bit images. The images that are stored in JPEG format, in which the extra information is
disabled, results to decreasing in image quality.
VI. ALGORITHM/MATLAB CODE
clc;
clear all;
close all;
%Reading and displaying of original image
P=100;
A=imread('[Link]');
subplot(3,2,1);
imshow(A);
title('original image');

[Link] @International Research Journal of Modernization in Engineering, Technology and Science


[666]
e-ISSN: 2582-5208
International Research Journal of Modernization in Engineering Technology and Science
Volume:03/Issue:05/May-2021 Impact Factor- 5.354 [Link]
%Converting original jpg image into gray image and plotting it
B=rgb2gray(A);
subplot(3,2,2);
imshow(B);
title('original to gray image');
%n1,n2 shows the resolution of image
b=double(B);
[n1,n2]=size(b);
% plotting of gray image
subplot(3,2,3);
imshow(B);
title('gray image');
%Converting Grayimage to original image and plotting it
C=gray2ind(B);
subplot(3,2,4);
imshow(C);
title(' gray to rgb image');
% plotting histogram of gray image
subplot(3,2,5);
imhist(B);
title('histogram of grayimage');
%plotting histogram of original image
subplot(3,2,6);
imhist(C);
title('histogram of rgbimage');
%Compression of jpg image
name=input('enter the image name: ','s');
rate=input('compression quality % (1<x<100): ');
original = imread(name);
original = double(original/255);
rate=1000*rate;
fori=1:3
im=original(:,:,i);
img_dct=dct2(im);
img_pow=(img_dct).^2;
img_pow=img_pow(:);
[B,index]=sort(img_pow);
B=flipud(B);
index=flipud(index);
compressed_dct=zeros(size(im));
for k=1:rate
compressed_dct(index(k))=img_dct(index(k));

[Link] @International Research Journal of Modernization in Engineering, Technology and Science


[667]
e-ISSN: 2582-5208
International Research Journal of Modernization in Engineering Technology and Science
Volume:03/Issue:05/May-2021 Impact Factor- 5.354 [Link]
end
img_dct=idct2(compressed_dct);
RGB(:,:,i)=img_dct;
end
%plotting original image
subplot(2,2,1);
imshow(A);
title('Original Image');
%plotting of Compressed jpg image
subplot(2,2,2);
imshow(RGB);
title('DCT compressed image');
imwrite(RGB,'[Link]');
VII. RESULTS

Fig 4: conversion of rgb to grey image, histogram of grayimage and rgb image

Fig 5: DCT compressed image

[Link] @International Research Journal of Modernization in Engineering, Technology and Science


[668]
e-ISSN: 2582-5208
International Research Journal of Modernization in Engineering Technology and Science
Volume:03/Issue:05/May-2021 Impact Factor- 5.354 [Link]
VIII. CONCLUSION
Thus, the JPEG image is converted into gray image and then into png image using MATLAB. The histograms
plotted for both the gray image as well as png image. The image compression also helps to save memory, as the
size of the compressed image is less than the actual size of the image. In this project we have taken several
images, in which original images are converted into compressed images using various compression methods.
The JPEG image is compressed using MATLAB [Link] reducing or removing redundant information
makes the images compressed. For achieving the compression more effectively,the patterns in the data must be
identified and utilized.
IX. REFERENCES
[1] Fabian Mentzer, Eirikur Agustsson, Michel Tschannen, Radu Timofte, and Luc Van Gool. Practical full
resolution learned lossless image compression. In Proceedings of the IEEE Conference on Computer
Vision and Pattern Recognition, pages 10689-10638, 2019.
[2] Chris Solomon and Toby Breckon. Fundamentals of Digital Image Processing: A practical approach with
examples in Matlab. John Wiley & Sons, 2011.
[3] Kenta Kurihara, Shoko Imaizumi, Sayaka Shiota, and Hitoshi Kiya. An encryption-then-compression
system for lossless image compression standards. IEICE transactions on information and systems,
100(1):52-56, 2017. Publisher: The Institute of Electronics, Information and Communication
Engineers.
[4] M. D. Manigandan and S. Deepa. Comprehensive study on the effect of entropy encoding algorithms on
medical image compression. International Research Journal of Engineering and Technology, 5(4):3460-
3468, 2018.
[5] Mohamed Uvaze Ahamed Ayoobkhan, Eswaran Chikkannnan, Kannan Ramakrishnan, and Sarvana
Balaji Balasubramanian. Prediction-based Lossless Image Compression. In International Conference on
ISMAC in Computational Vision and Bio-Engineering, pages 1749-1761. Springer, 2018.
[6] James Townsend, Thomos Bird, Julius Kunze, and David Barbar. Hilloc: Lossless Image Compression
with hierarchical Latent Variable Models. ArXiv preprint arXiv:1912.09953, 2019.
[7] Karam Lina J. Chapter 16 - Lossless Image Compression. In Al Bolvik, editor. The Essential Guide to
Image Processing, pages 385-419. Academic Press, Boston, 2009.
[8] Bin Xiao, Gang Lu, Yanhong Zhang, Weisheng Li, and Guoyin Wang. Lossless Image Compression based
on integer Discrete Tchebichef Transform. Neurocomputing, 214:587-593,2016. Publisher: Elseveir.
[9] Digital Image Processing (Pearson Education, Second Edition) By Rafael [Link] and Richard
[Link].
[10] Digital Image Processing by Athur [Link].
[11] Digital Image Processing using MATLAB (Pearson Education) By Rafael [Link], Richard [Link]
and Steven [Link].
[12] T Hong LIU, Lin-pei ZHAIV, Ying GAO, Wen-ming LI``,Jiu-fei ZHOU``,``Image Compression Based on
Biorthogonaln Wavelet Transform”, IEEE Proceedings of ISCIT2005
[13] De Vore, et al., n” Image Compression through Wavelet Transform Coding”, IEEE Transaction on
Information Theory.
[14] ``A Comparative Study of Image Compression Techniques Based on Svd, Dwd- Dct” ICSCI2008
proceedings pg 494-496.

[Link] @International Research Journal of Modernization in Engineering, Technology and Science


[669]

You might also like