JPEG Compression Standard
JPEG Compression Standard
Mitul Modi
ME II MSA
Roll No: 199
22-Mar-13 JPEG Compression Standard 1
22-Mar-13 JPEG Compression Standard 2
Outlines:
JPEG Compression Overview
YC
b
C
r
Color Mode
Discrete Cosine Transform
Block diagram of JPEG Compression
Steps For JPEG Compression
Matlab code for JPEG Compression using DCT
Examples
JPEG Compression Overview
JPEG stands for Joint Photographic Experts Group
Used on 24-bit color files.
It is a lossy compression technique, But excellent quality image
with high compression rates.
22-Mar-13 JPEG Compression Standard 3
YC
b
C
r
Color Mode:
22-Mar-13 JPEG Compression Standard 4
YC
b
C
r
color mode stores color in terms of its luminance
(brightness) and blue and red chrominance (hue).
The human eye is less sensitive to chrominance than luminance.
YC
b
C
r
is not required for JPEG compression, but it gives a
better compression rate.
22-Mar-13 JPEG Compression Standard 5
Discrete Cosine Transform:
The DCT transforms the data from the spatial domain to the
frequency domain.
The spatial domain shows the amplitude of the color as you
move through space`
The frequency domain shows how quickly the amplitude of the
color is changing from one pixel to the next in an image file.
The frequency domain is better representation for data because
it makes it possible for you to separate out and throw away
information that isnt very important to human perception.
The human eye is not very sensitive to high frequency changes
especially in photographic images, so the high frequency data
can, to some extent, be discarded.
22-Mar-13 JPEG Compression Standard 6
Block diagram of JPEG Compression
Steps in JPEG Compression
1. (Optionally) If the color is represented in RGB mode,
translate it to YC
b
C
r
.
2. Divide the file into 8 X 8 blocks.
3. Transform the pixel information from the spatial domain
to the frequency domain with the Discrete Cosine
Transform.
4. Quantize the resulting values by dividing each coefficient
by an integer value and rounding off to the nearest integer.
5. Look at the resulting coefficients in a zigzag order.
6. Do the Entropy Encoding Using Entropy Encoder like
Huffman Encoder and Run-Length Encoder.
22-Mar-13 JPEG Compression Standard 7
Step 1: Converting RGB to YC
b
C
r
.
22-Mar-13 JPEG Compression Standard 8
Optional But gives better Compression rate.
For converting RGB to YC
b
C
r
. Take downsampling
The notation 4:1:1 means that for each block of four pixels,
you have 4 samples of luminance information (Y), and 1
each of the two chrominance components (U and V).
MCU minimum coded unit
U, V
Y
Y
Y
Y
Step 2: Divide into 8 X 8 blocks
Note that with YC
b
C
r
color, you have 16 pixels of
information in each block for the Y component (though
only 8 in each direction for the U and V components).
If the file doesnt divide evenly into 8 X 8 blocks, extra
pixels are added to the end and discarded after the
compression.
The values are shifted left by subtracting 128.
22-Mar-13 JPEG Compression Standard 9
Step 3: DCT (1D)
Transform the pixel information from the spatial domain to
the frequency domain with the Discrete Cosine Transform.
The DCT is an array of coefficients (for 1D sequence length
N)
22-Mar-13 JPEG Compression Standard 10
where
Step 3: DCT (2D)
For N X N pixel image
the DCT is an array of coefficients
where
22-Mar-13 JPEG Compression Standard 11
(
+
(
+
=
=
=
N
v y
N
u x
p C C
N
DCT
N
y
xy
N
x
v u uv
2
) 1 2 (
cos
2
) 1 2 (
cos
2
1 1
0
1
0
t t
where
otherwise C C
v u for C C
v u
v u
1
0 ,
2
1
=
= =
| | N v N u p
uv
< s < s 0 , 0 ,
| | N v N u DCT
uv
< s < s 0 , 0 ,
Continue
For the 8 X 8 matrix of color data, youre getting an 8 X 8
matrix of coefficients for the frequency components.
22-Mar-13 JPEG Compression Standard 12
Continue
DCT is designed to work on pixel values ranging from -128 to
127, the original block is leveled off by subtracting 128 from
each entry. Finally D = TMT
22-Mar-13 JPEG Compression Standard 13
Step 4: Quantization
The DCT is lossless in that the reverse DCT will give you
back exactly your initial information (ignoring the rounding
error that results from using floating point numbers.)
The values from the DCT are initially floating-point.
Common Quantization Matrix is given by
22-Mar-13 JPEG Compression Standard 14
Q
(i,j)
=
Continue..
Quantization involves dividing each coefficient by an integer
between 1 and 255 and rounding off.
The quantization table is chosen to reduce the precision of
each coefficient to no more than necessary.
The quantization table is carried along with the compressed
file.
22-Mar-13 JPEG Compression Standard 15
Step 5: Arrange in zigzag order
This is done so that the coefficients are in order of increasing
frequency.
After quantization, most of the coefficients to equal zero.
JPEG takes advantage of this by encoding quantized
coefficients in the zig-zag sequence.
The advantage lies in the
consolidation of relatively
large runs of zeros, which
compress very well.
22-Mar-13 JPEG Compression Standard 16
22-Mar-13 JPEG Compression Standard 17
An entropy encoder supplementary compresses the
quantized values losslessly to provide a better overall
compression.
It uses a model to perfectly determine the probabilities for
each quantized value and produces an appropriate code
based on these probabilities so that the resultant output
code stream is smaller than the input stream.
The most commonly used entropy encoders are the
Huffman encoder and the arithmetic encoder, although for
applications requiring fast execution, simple Run Length
Encoding (RLE) is very effective. This improves the
compression of run-length encoding.
Step 6: Entropy Encoder
22-Mar-13 JPEG Compression Standard 18
Matlab code :
22-Mar-13 JPEG Compression Standard 19
Examples :
DCT to rows only:
22-Mar-13 JPEG Compression Standard 20
Examples :
DCT to rows*Column :
Reference:
Digital Image Processing by Rafael Gonzalez and Richard Woods
M.Mohamed Sathik , K.Senthamarai Kannan and Y.Jacob Vetha Raj,
Hybrid JPEG Compression Using Histogram Based Segmentation.
International Journal of Computer Science and Information Security, Vol.
8, No. 8, November 2010
Leger, A., T. Omachi, and T.K. Wallace, "JPEG Still Picture Compression
Algorithm," Optical Engineering, vol. 30, no. 7, July 1991, pp. 947-954.
Kiran Bindu, Anita Ganpati, Aman Kumar Sharma, A Comparative
Study Of Image Compression Algorithms. International Journal of
Research in Computer Science eISSN 2249-8265 Volume 2 Issue 5 (2012)
http://www.jpeg.org,
http://cnx.rice.edu,
http://www.datacompression.info
22-Mar-13 JPEG Compression Standard 21
22-Mar-13 JPEG Compression Standard 22
22-Mar-13 JPEG Compression Standard 23
Lossy Compression Model