JPEG

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 21

JPEG Compression

Image Compression

• Reducing the amount of data


required to represent the given
image.

Image = Information +
Redundant data
Why do we need compression?

• To reduce the volume of data to


be transmitted (text, fax, images)
• To reduce the bandwidth
required for transmission
• To reduce storage
requirements (speech, audio,
video)
Compression Classification

• Lossless Compression
No information loss
Image can be reconstructed
exactly
• Lossy compression
Information loss is tolerable
Image cannot be reconstructed
exactly
Used where high compression
ratio is required
What is JPEG?

• “Joint Photographic Expert


Group". Voted as international
standard in 1992

• Works with color and gray scale


images.

• Lossy and lossless


Steps in JPEG Compression
• 1. (Optionally) If the color is
represented in RGB mode,
translate it to YUV.

• 2. Divide the image into 8 X 8


blocks.

• 3. Transform the pixel information


from the spatial domain to the
frequency domain with the
Discrete Cosine Transform.
Steps in JPEG (contd..)

• 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. Do
a run-length encoding of the
coefficients ordered in this
manner. Follow by Huffman
coding.
Steps in JPEG Image Compression
Discrete Cosine
Transform
• Image is divided into 88 blocks of pixels
• 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.

1 7 7
  (2 x  1)u    (2 y  1)v 
F (u , v)  C (u )C (v) f ( x, y ) cos   cos  
4 x 0 y 0  16 16
for u  0,..., 7 and v  0,..., 7
1/ 2 for k  0
where C (k )  
 1 otherwise
Discrete Cosine
Transform
Example : 48 39 40 68 60 38 50 121
149 82 79 101 113 106 27 62
58 63 77 69 124 107 74 125
80 97 74 54 59 71 91 66
18 34 33 46 64 61 32 37
Y
149 108 80 106 116 61 73 92
211 233 159 88 107 158 161 109
212 104 40 44 71 136 113 66
the luminance of an image 8x8 values of luminance
699.25 43.18 55.25 72.11 24.00 -25.51 11.21 -4.14
DCT
-129.78 -71.50 -70.26 -73.35 59.43 -24.02 22.61 -2.05
85.71 30.32 61.78 44.87 14.84 17.35 15.51 -13.19
-40.81 10.17 -17.53 -55.81 30.50 -2.28 -21.00 -1.26
-157.50 -49.39 13.27 -1.78 -8.75 22.47 -8.47 -9.23
92.49 -9.03 45.72 -48.13 -58.51 -9.01 -28.54 10.38
-53.09 -62.97 -3.49 -19.62 56.09 -2.25 -3.28 11.91
-20.54 -55.90 -20.59 -18.19 -26.58 -27.07 8.47 0.31

8x8 DCT coefficients


Quantization

• Used to reduce the amount of


information to be conveyed

• Each DCT coefficient is divided by


a constant and round it to the
nearest integer.

• The quantization table is carried


along with the compressed file.
Quantization (contd..)
• The quantizer output is: 16 11 10 16 24 40 51 61
Fq(u,v)=Round(F(u,v)/
Q(u,v)) 12 12 14 19 26 58 60 55
• This rounds to the
nearest integer 14 13 16 24 40 57 69 56
• Here, Q(u,v) is a
quantization table. 14 17 22 29 51 87 80 62
• The default luminance
table for JPEG is 18 22 37 56 68 10 10 77
presented on the right
9 3
• What to note:
– Smaller Q(u,v) means a 24 35 55 64 81 10 11 92
smaller step size and 4 3
hence more resolution
and vice-versa 49 64 78 87 10 12 12 10
– Q(u,v) may be scaled 3 1 0 1
by a quality factor
72 92 95 98 11 10 10 99
2 0 3
How Quantization is
Performed
Ex : 699.25 43.18 55.25 72.11 24.00 -25.51 11.21 -4.14
-129.78 -71.50 -70.26 -73.35 59.43 -24.02 22.61 -2.05
85.71 30.32 61.78 44.87 14.84 17.35 15.51 -13.19
-40.81 10.17 -17.53 -55.81 30.50 -2.28 -21.00 -1.26
-157.50 -49.39 13.27 -1.78 -8.75 22.47 -8.47 -9.23
92.49 -9.03 45.72 -48.13 -58.51 -9.01 -28.54 10.38 F(u,v)
-53.09 -62.97 -3.49 -19.62 56.09 -2.25 -3.28 11.91 8x8 DCT coefficiences
-20.54 -55.90 -20.59 -18.19 -26.58 -27.07 8.47 0.31

16 11 10 16 24 40 51 61

12 12 14 19 26 58 60 55

14 13 16 24 40 57 69 56

14 17 22 29 51 87 80 62 Q(u,v)
18 22 37 56 68 109 103 77 Quantization matrix
24 35 55 64 81 104 113 92

49 64 78 87 103 121 120 101

72 92 95 98 112 100 103 99


How Quantization is
Performed
Example :
43.70 3.93 5.52 4.51 1.00 -0.64 0.22 -0.07

-10.82 -5.96 -5.02 -3.86 2.29 -0.41 0.38 -0.04

6.12
-2.91
2.33
0.60
3.86
-0.80
1.87
-1.92
0.37
0.60
0.30
-0.03
0.22
-0.26
-0.24
-0.02
F (u , v)
-8.75 -2.25 0.36 -0.03 -0.13 0.21 -0.08 -0.12
Q(u , v)
3.85 -0.26 0.83 -0.75 -0.72 -0.09 -0.25 0.11
-1.08 -0.98 -0.04 -0.23 0.54 -0.02 -0.03 0.12
-0.29 -0.61 -0.22 -0.19 -0.24 -0.27 0.08 0.00

Fq (u, v) 
44 4 6 5 1 -1 0 0
-11 -6 -5 -4 2 0 0 0
6 2 4 2 0 0 0 0
-3 1 -1 -2 1 0 0 0  F (u, v) 
-9 -2 0 0 0 0 0 0 Round  
4 0 1 -1 -1 0 0 0  Q (u , v ) 
-1 -1 0 0 1 0 0 0
0 -1 0 0 0 0 0 0
Zig-Zag Ordering

• This is done so that the coefficients are


in order of increasing frequency.

• Conversion of 8X8 matrix to 1X64


matrix

• The higher frequency coefficients are


more likely to be 0 after quantization.
Zig-Zag Reordering
1 1 2 2
0 1 5 6
4 5 7 8
1 1 2 2 4
2 4 7
3 6 6 9 2
1 1 2 3 4 4
3 8
2 7 5 0 1 3
1 1 2 3 4 4 5
9
1 8 4 1 0 4 3
1 1 2 3 3 4 5 5
0 9 3 2 9 5 2 4
2 2 3 3 4 5 5 6
0 2 3 8 6 1 5 0
2 3 3 4 5 5 5 6
1 4 7 7 0 6 9 1
3 3 4 4 5 5 6 6
5 6 8 9 7 8 2 3

Zig-Zag reordering matrix


Zig-Zag Reordering
Zig-Zag Reordering :
Example : 44,
4,-11,
44 4 6 5 1 -1 0 0
6,-6,6,
- 5,-5,2,-3,
-6 -5 -4 2 0 0 0
11 -9,1,4,-4,1,
-1,2,2,-1,-2,4,
6 2 4 2 0 0 0 0
-1,0,0,-2,0,0,0,
-3 1 -1 -2 1 0 0 0 0,0,0,1,0,1,-1,0,

-9 -2 0 0 0 0 0 0
-1,0,-1,0,0,0,0,
0,0,0,-1,0,0,
4 0 1 -1 -1 0 0 0 0,1,0,0,0,
0,0,0,0,
-1 -1 0 0 1 0 0 0
0,0,0,
0 -1 0 0 0 0 0 0 0,0,
0
Run-length Encoding

• 63 values of the AC coefficients

• Long strings of zeros because of


the zig-zag scan

• Each AC coefficient encoded as a


pair of values -- (skip, value), skip
indicates the number of zeros in
the run and value is the next non-
zero coefficient
Zero Run Length Coding

Example

• 63 AC coefficients:
57, 45, 0, 0, 0, 0, 23, 0, -30, -16, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0,..., 0

• Run Length Coding :


(0,57) ; (0,45) ; (4,23) ; (1,-30) ;
(0,-16) ; (2,1) ; EOB
Huffman Encoding

• Long strings of binary digits


replaced by shorter codewords
• Prefix property of the huffman
codewords enable decoding the
encoded bitstream unambiguously
THANK YOU

You might also like