0% found this document useful (0 votes)
36 views

SisMul - Image Coding (Compression) - 07 - 2

The document discusses JPEG, a lossy image compression method and standard. JPEG consists of several steps including converting RGB to YCbCr color space, downsampling color channels, applying the discrete cosine transform (DCT) to blocks of the image, quantizing the DCT coefficients, and entropy coding the results using Huffman coding. Quantization is a key step that results in lossy compression by dividing DCT coefficients by values in a quantization matrix and rounding the results, effectively removing some high-frequency detail information from the image. Typical JPEG compression yields file sizes that are 30% of the original image size with slightly noticeable quality reduction.

Uploaded by

Ekik Vikny
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

SisMul - Image Coding (Compression) - 07 - 2

The document discusses JPEG, a lossy image compression method and standard. JPEG consists of several steps including converting RGB to YCbCr color space, downsampling color channels, applying the discrete cosine transform (DCT) to blocks of the image, quantizing the DCT coefficients, and entropy coding the results using Huffman coding. Quantization is a key step that results in lossy compression by dividing DCT coefficients by values in a quantization matrix and rounding the results, effectively removing some high-frequency detail information from the image. Typical JPEG compression yields file sizes that are 30% of the original image size with slightly noticeable quality reduction.

Uploaded by

Ekik Vikny
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Sistem

Multimedia
K Candra Brata
[email protected]

Tim Ajar Mata kuliah Sitem Multimedia 2017-2018


Image Coding
(Compression)
Definitions
JPEG

• JPEG is a lossy image compression method.


• JPEG is an image compression standard developed by the
Joint Photographic Experts Group. It was formally
accepted as an international standard in 1992
• JPEG consists of a number of steps, each of which
contributes to compression.

Disusun oleh Tim Ajar Mata Kuliah Sistem Multimedia 2016/2017


JPEG

• The eye–brain system cannot see extremely fine detail.


• Color information in JPEG is decimated (partially dropped, or
averaged) and then small blocks of an image are represented in
the spatial frequency domain (u, v), rather than in (x, y) and a new
“image” is formed by grouping the coefficients.

DCT

Disusun oleh Tim Ajar Mata Kuliah Sistem Multimedia 2016/2017


JPEG

• image with a quality factor Q = 10. (The usual default quality


factor is Q = 75).
• This image is a mere 1.5 % of the original size. In comparison, a
JPEG image with Q = 75 yields an image size 7 % of the original,
whereas a GIF version of this image compresses down to 23.0 % of
the uncompressed image size.

Disusun oleh Tim Ajar Mata Kuliah Sistem Multimedia 2016/2017


Compression Techniques

Algorithm BMP GIF PNG JPEG


RLE v v
LZW v v
Huffman v v
DCT v

Note:
RLE (Run Length Encoding)
LZW (Lempel, Ziv, Welch)
DCT (Discrete Cosine Transform)

Disusun oleh Tim Ajar Mata Kuliah Sistem Multimedia 2016/2017


Compression Ratios Comparison

For Photos
• GIF: 5:1 (1/5 the storage)
• JPEG: 10:1 at lowest level
200:1 at highest level
• Typical: 30:1 slightly noticeable reduction
in quality

7
JPEG Compression
JPEG Compression

f(x,y)

Disusun oleh Tim Ajar Mata Kuliah Sistem Multimedia 2016/2017


Main Steps of JPEG Compression

1. Transform RGB to YCbCr


2. subsample color
3. Perform DCT on image blocks
4. Apply Quantization
5. Perform Zigzag ordering
6. Run-length encoding (For AC coefficients)
7. DPCM for DC Coefficients (For DC coefficients)
8. Perform Entropy coding using Huffman Coding

Disusun oleh Tim Ajar Mata Kuliah Sistem Multimedia 2016/2017


1. Color Space Conversion

 Y   0.299000 0.587000 0.114000   R   0 


C    0.168736 0.331264 0.500002  G   128
 b     
Cr   0.500000 0.418688 0.081312   B  128
(a) translate from RGB to YCbCr

 R  1.0 0.0 1.40210   Y 


G   1.0 0.34414 0.71414 C  128
    b 
 B  1.0 1.77180 0.0  Cr  128
(b) translate from YCbCr to RGB

Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC
2. Downsampling

W W W
Y H Y H Y H
W W W
Cb Cb Cb H
H H

W W W
Cr Cr Cr H
H H

(a) 4:4:4 (b) 4:2:2 (c) 4:2:0

Figure 2. Three color format in the baseline system


2. Downsampling
3. Discrete Cosine Transform
(DCT)
• Forward 2-D Discrete Cosine Transform
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

• Inverse 2-D Discrete Cosine Transform


2 N 1 N 1   (2 x  1)u    (2 y  1)v 
f ( x, y )  
MN u 0 v 0
C (u )C (v) F (u, v) cos 
 2 M 

cos 
 2N 
for x  0,..., M  1 and y  0,..., N  1
f(x,y) : the element in spatial domain
F(u,v) : the DCT coefficient in the frequency domain
Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC
Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC
3. Discrete Cosine Transform
u
0 1 2 3 4 5 6 7
0
1

v
2
3
4
5
6
7

The 8x8 DCT basis


Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC
3. Discrete Cosine Transform
Example : 48 39 40 68 60 38 50 121

W 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
H 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 coefficiences


Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC
4. Quantization
The default values in the 8×8 quantization matrix Q(u,v) are listed in
Figure 3 for luminance and chrominance images

 F (u, v) 
Fq (u, v)  Round  
 Q(u, v) 
16 11 10 16 24 40 51 61 17 18 24 47 99 99 99 99
12 12 14 19 26 58 60 55 18 21 26 66 99 99 99 99
14 13 16 24 40 57 69 56 24 26 56 99 99 99 99 99
14 17 22 29 51 87 80 62 47 66 99 99 99 99 99 99
18 22 37 56 68 109 103 77 99 99 99 99 99 99 99 99
24 35 55 64 81 104 113 92 99 99 99 99 99 99 99 99
49 64 78 87 103 121 120 101 99 99 99 99 99 99 99 99
72 92 95 98 112 100 103 99 99 99 99 99 99 99 99 99

Figure 3. Luminance and Chrominance quantization matrix

Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC19
4. Quantization
Example :
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
F(u,v)
85.71 30.32 61.78 44.87 14.84 17.35 15.51 -13.19
8x8 DCT coefficiences
-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

16 11 10 16 24 40 51 61 Q(u,v)
12 12 14 19 26 58 60 55
Luminance
14 13 16 24 40 57 69 56
Quantization matrix
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99

Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC20
4. Quantization
Example :
43.70 3.93
-10.82 -5.96
5.52
-5.02
4.51
-3.86
1.00
2.29
-0.64
-0.41
0.22
0.38
-0.07
-0.04
F (u , v)
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
Q(u, v)
-8.75 -2.25 0.36 -0.03 -0.13 0.21 -0.08 -0.12
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

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

Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC 21
5. Zig-Zag Reordering
Matrix

0 1 5 6 14 15 27 28

2 4 7 13 16 26 29 42

3 8 12 17 25 30 41 43

9 11 18 24 31 40 44 53

10 19 23 32 39 45 52 54

20 22 33 38 46 51 55 60

21 34 37 47 50 56 59 61

35 36 48 49 57 58 62 63

Figure 4. Zig-Zag reordering matrix

Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC
5. Zig-Zag Reordering Matrix
Zig-Zag Reordering :
Example : 44,
4,-11,
6,-6,6,
Fq (u , v) 5,-5,2,-3,
-9,1,4,-4,1,
44 4 6 5 1 -1 0 0 -1,2,2,-1,-2,4,
-11 -6 -5 -4 2 0 0 0 -1,0,0,-2,0,0,0,
6 2 4 2 0 0 0 0 0,0,0,1,0,1,-1,0,
-3 1 -1 -2 1 0 0 0
-1,0,-1,0,0,0,0,
-9 -2 0 0 0 0 0 0
0,0,0,-1,0,0,
4 0 1 -1 -1 0 0 0
0,1,0,0,0,
-1 -1 0 0 1 0 0 0
0,0,0,0,
0 -1 0 0 0 0 0 0
0,0,0,
0,0,
0
Zig-Zag Reordering :
44,4,-11,6,-6,6,5,-5,2,-3,-9,1,4,-4,1,-1,2,2,-1,-2,4,-1,0,0,-2,0,0,0,0,0,0,1,0,1,-1,0, -1,0,
-1,0,0,0,0,0,0,0,-1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0
Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC
6. Zero Run Length Coding
of AC Coefficients
 Example 1
64 pixel
1 DC and 63 AC coefficience:
65,57, 45, 0, 0, 0, 0, 23, 0, -30, -16, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,..., 0
50 zeros
Run Length Coding :
(0,57) ; (0,45) ; (4,23) ; (1,-30) ; (0,-16) ; (2,1) ; EOB
(0,0)
 Example 2

1 DC and 63 AC coefficience. Assume that the first value is DC:


(32,6,−1,−1,0,−1,0,0,0,−1,0,0,1,0,0,...,0)

Run Length Coding :


(0, 6);(0, −1);(0, −1);(1, −1);(3, −1);(2, 1);(0, 0)

Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC
Example(2): Zero Run Length Coding
(AC Coefficients)

−26, −3, 0, −3, −2, −6, 2, −4, 1, −4, 1, 1, 5, 1, 2, −1, 1, −1, 2, 0, 0, 0, 0, 0, −1,
−1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,

Run-length encode:
(0,-3);(1,-3);(0,-2);(0,-6);(0,2);(0,-4);(0,1);(0,1);…………………..
Encoding is complete.
7. DPCM for DC Coefficients
Differential Pulse Code Modulation on DC Coefficients

• large correlation still exists between the DC


components in the neighboring macroblocks

DCi-1 DCi

… Blocki-1 Blocki …

Diffi = DCi - DCi-1


Different Coding on DC Coefficients

Encode : Decode :
Diffi = DCi  DCi1 DCi = DCi1 + Diffi

Diffi1= Diffi=
Diff1=DC1
DCi1 DCi2 DCi DCi1

DC0 DC1 … DCi1 DCi …

0
… …

block 1 block i1 block i

Figure 5. DCs of 88 blocks


Example DPCM on DC Coefficients

• If the DC coefficients for the first five image blocks


are 150, 155, 149, 152, 144, DPCM would produce
150, 5, −6, 3, −8, assuming the predictor for the ith
block is simply di = DCi − DCi−1, and d0 = DC0.

• We expect DPCM codes to generally have smaller


magnitude and variance, which is beneficial for the
next entropy coding step.

• DPCM for the DC coefficients in JPEG is carried out


on the entire image at once.
8. Huffman Coding of DC coefficients

Category Values Bits for the value


1 -1,1 0,1
2 -3,-2,2,3 00,01,10,11
3 -7,-6,-5,-4,4,5,6,7 000,001,010,011,100,101,110,111
4 -15,...,-8,8,...,15 0000,...,0111,1000,...,1111
5 -31,...,-16,16,...31 00000,...,01111,10000,...,11111
6 -63,...,-32,32,...63 000000,...,011111,100000,...,111111
7 -127,...,-64,64,...,127 0000000,...,0111111,1000000,...,1111111
8 -255,..,-128,128,..,255 ...
9 -511,..,-256,256,..,511 ...
10 -1023,..,-512,512,..,1023 ...
11 -2047,..,-1024,1024,..,2047 ...

Figure 6. Table of values and bits for the value


Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC
8. Huffman Coding

 Example
Run length coding of 63 AC coefficiences :
(0,57) ; (0,45) ; (4,23) ; (1,-30) ; (0,-8) ; (2,1) ; (0,0)

Encode the right value of these pair as category and bits for the value,
except the special markers like (0,0) or (15,0) :
(0,6,111001) ; (0,6,101101) ; (4,5,10111);
(1,5,00001) ; (0,4,0111) ; (2,1,1) ; (0,0)

For example, if the difference of DC coefficience :


-511

Encode the value as category and bits for the value : (see Grouping table
in the Figure 6)
9, 000000000

Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC
8. Huffman Coding (AC Coefficients)

run/category code length code word


0/0 4 1010
...
0/6 7 1111000
...
0/10 16 1111111110000011
1/1 4 1100
...
1/5 11 11111110110
...
4/5 16 1111111110011000
...
15/10 16 1111111111111110
Figure 7. Huffman table of luminance AC coefficience
Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC
8. Huffman Coding (DC Coefficients)

category code length code word


0 2 00
1 3 010
2 3 011
3 3 100
4 3 101
5 3 110
6 4 1110
7 5 11110
8 6 111110
9 7 1111110
10 8 11111110
11 9 111111110
Figure 8. Huffman table of luminance DC coefficience
8. Huffman Coding

 Example

The AC coefficiences :
(0,6,111001) ; (0,6,101101) ; (4,5,10111);
(1,5,00001) ; (0,4,0111) ; (2,1,1) ; (0,0)

Encode the left two value in () using Huffman encoding :


1111000 111001 , 1111000 101101 , 1111111110011000 10111 ,
11111110110 00001 , 1011 0111 , 11100 1 , 1010

The DC coefficience :
9, 000000000

Encode the category using Huffman encoding :


1111110 000000000

Graduate Institute of Communication Engineering, National Taiwan University, Taipei, Taiwan, ROC
Original and JPEG Compressed Image

ORIGINAL

COMPRESSED
Issues and Problems

Compressed image
Original image

• The quantization step makes the JPEG Image Compression Standard


an example of lossy compression.
• For some applications, such as web browsing, the loss of resolution is
acceptable.
• For other applications, such as high resolution photographs for
magazine advertisements, the loss of resolution is unacceptable.
Thanks
We are
..moving..

http://j.gs/18164083/sismul

You might also like