Jpeg Compression
Jpeg Compression
Jpeg Compression
Presented by
Krishan Singh (EE22M304) Presented to
Kunchakara Shashank (EE22M305) Dr. Vikramkumar Pudi
Manvi Chaudhary (EE22M306)
Shubham Pandey (EE22M311)
Table of Contents
▪ What is JPEG Image Compression?
▪ Project Overview
▪ Compression Steps
▪Color Space Conversion
▪Chrominance Downsampling
▪Discrete Cosine Transform
▪Quantization
▪Huffman Encoding
▪Decoding
▪Dequantization
▪Inverse Discrete Cosine Transform
What is JPEG Compression?
▪ JPEG, which stands for Joint Photographic Experts Group is a lossy compression
algorithm for images.
▪ A lossy compression scheme is a way to inexactly represent the data in the
image, such that less memory is used yet the data appears to be very similar.
This is why JPEG images look almost the same as the original images.
▪ The JPEG algorithm takes advantage of the fact that humans can’t see colors at
high frequencies. These high frequencies are the data points in the image that
are eliminated during the compression. JPEG compression also works best on
images with smooth color transitions.
Project Overview
▪ In this project we take YCbCr color space image and apply JPEGcompression
algorithm to the chrominance components Cb and Cr
▪ In compression stage we downsample the pixel values by a factor of 4. Then by
performing DCT we convert the pixel info from spatial domain to frequency
domain for data compression at high frequencies.
▪ Quantization is the process of reducing the number of bits needed to store an
integer value by reducing the precision of the integer.
▪ Huffman encoding converts 2D matrix into 1D array reducing the data by run
length encoding hence resulting the lossless compression at this stage.
Project Overview
▪ In the second stage we take the encoded string from memory and apply the
decoding algorithms.
▪ Dequantization is the exact reverse of quantization process that results in an
output similar to DCT matrix output.
▪ Inverse DCT matrix converts the frequency domain data to spatial domain.
▪ This can be used to extract the chrominance component with the help of
resampling.
Compression Steps
▪ Color Space Conversion
▪ Firstly the input image is in the form of RGB format representing the amount of red,
green and blue color through the variation of these colors from 0 to 255 rest all the
colors can be obtained where if all the 3 are 255 represent white color. This RGB image
is converted into YCbCr format for image compression where Y represents Luminance
or brightness and Cb and Cr represents Chrominance i.e. the colors of the image.
Compression Steps
▪ Chrominance Downsampling
▪ In chrominance downsampling, the pixel values of two blocks in horizontal and two blocks in vertical
are taken i.e. 2x2 matrix and their values are replaced by their average values. Thus the amount of
data reduces by a factor of 4.
Compression Steps
▪ Discrete Cosine Transform
▪ While performing Discrete Cosine Transformation(DCT), we subtract 128 from each pixel value so
that the range of the pixel values change from 0 - 255 to (-128) - 128 creating negative pixel values
as well. Now this converted matrix is manipulated through matrix multiplication. This manipulation is
done by multiplying a cosine coefficient orthogonal matrix with the above converted matrix which is
further multiplied by the transpose of the cosine coefficient matrix.
Compression Steps
▪ Discrete Cosine Transform
▪ This coefficient matrix is fixed for a particular image and calculated by calculating the contribution of
each pixel as mentioned in the above images where the frequency of image increases diagonally
from top left to bottom right. This contribution is calculated as follows,
▪ This contribution is calculated for each pixel and a coefficient matrix is created called cosine
coefficient matrix.
▪ The matrix multiplication is done as :
▪ Where, T is the coefficient matrix , M is the converted matrix and T’ is the transpose of the
coefficient matrix. Here D is the output DCT matrix.
Compression Steps
▪ Quantization
▪ This is one of the important steps which decides the compression quality and quantity. Higher the
compression percentage lesser the quality.
▪ Quantization matrix is obtained by multiplying each individual pixel value of a standard quantization
matrix of 50% quality factor by (100 - quality level)/50 for quality level greater than 50 and by
50/(quality level) for quality level less than 50.
▪ The matrix with 50% quality factor is as follows:
Compression Steps
▪ Quantization
▪ After getting this Quantization matrix, each value of the DCT matrix is divided by the corresponding
values of the Quantization matrix and rounded off to the nearest integer.
▪ Thus bottom left values of the matrix are zero and thus high frequency data is removed as it is not
that sensitive to our eyes
▪ Thus the output matrix contains a lot of zeros and this data is further stored at a single place thus
reducing its size.
Compression Steps
▪ Huffman Encoding
▪ Once the data is reduced, the reduced data needs to be removed or discarded and the data needs
to be stored in the storage.
▪ Huffman encoding is the step where actual data compression takes place and is the final step for
JPEG image compression.
▪ In this step the 2D matrix is converted into a 1D array or more precisely bitstream to be stored in
the storage.
Compression Steps
▪ Huffman Encoding
▪ The values of the 2D matrix are stored as 8 bit integers in one dimension wherein the first bit
represents the flag where if the number is positive the flag is 0 and if the number is 0 then the flag
is 1.
▪ If the flag is 1 i.e. the number is 0 then the next 7 bits store the number of continuous zeroes and if
the flag is 0 then the next 7 bits store the positive number encountered.
▪ The conversion takes place in the order as shown above to get maximum compression of data.
Compression Steps
▪ Decoding
▪ In this Step we start retracing the steps we performed while encoding but in reverse order.
▪ Thus the last step in encoding is the first step in decoding that is Huffman decoding where we
create a 2D matrix and start storing the values as we did during encoding but instead of 2D to 1D,
we are now converting the 1D array to 2D array by recognizing the first bit as flag and the next 7
bits as counter or the number depending upon the value of the flag.
Compression Steps
▪ Dequantization
▪ Dequantization is the exact reverse of the quantization process where instead of division,
multiplication takes place. Here each individual element of the matrix is multiplied by the respective
element of the quantization or dequantization matrix which will be fixed and known. Thus, the output
will be similar to that of the DCT matrix output wherein the bottom right values or lesser values will
be replaced by zero.
Compression Steps
▪ Inverse DCT
▪ In inverse DCT the DCT matrix or the output of dequantization say matrix R is taken. The transpose
of the coefficient matrix used during encoding is used and multiplied with the matrix R which is
further multiplied by the coefficient matrix. To get the required output in the range of 0 to 255 which
is the pixel range, 128 is added to each element of the matrix to get the desired output which can
be shown by its pixel values.
▪ This calculation is represented as follows:
▪ Here, N is the desired output for Y while Cb and Cr needs to go through one more process of
Chrominance resampling.
THANK YOU