You are on page 1of 6

Example of JPEG compression

In this example, the cameraman.tif image is taken. First, the image divides into 8x8 sub
images. One of the sub images is given below.

126 56 14 11 13 11 12 12
127 129 61 14 12 13 12 12
129 136 142 72 16 12 12 12
135 131 137 134 78 18 13 12
138 141 134 137 132 108 26 14
137 141 133 129 130 135 120 53
137 135 138 139 131 136 122 126
130 142 140 143 142 142 141 147

[1] For performing the level shifting, we subtract 128 from each pixel. As a result each pixel
value comes between -128 to 127 ranges which are shown below.

-2 -72 -114 -117 -115 -117 -116 -116

-1 1 -67 -114 -116 -115 -116 -116

1 8 14 -56 -112 -116 -116 -116

7 3 9 6 -50 -110 -115 -116

10 13 6 9 4 -20 -102 -114

9 13 5 1 2 7 -8 -75

9 7 10 11 3 8 -6 -2

2 14 12 15 14 14 13 19

[2] After level shifting, this sub image converts into frequency domain by applying Forward
Discrete Cosine Transform (FDCT) which mentioned in equation The sub image after
FDCT operation is shown below.
-296.125 233.7519 1.9482 11.1034 -7.875 -0.432 1.7637 -5.2196

-301.5572 116.254 80.551 1.6693 7.183 0.2253 -0.2099 5.1969

-21.7092 -104.5723 86.0362 24.2657 6.1233 -2.6698 -3.3865 1.1709

-10.1878 -34.1982 -18.0097 73.5436 6.4484 2.4243 -2.5882 -2.7868

-10.375 0.0732 -32.4555 8.4345 42.375 -0.6891 1.6725 -3.545

-7.746 -6.0793 3.415 -25.1143 23.3837 25.2995 2.9415 5.0275

3.445 -5.9337 -1.3865 -1.3323 -17.5545 20.4308 1.7138 7.7959

1.2232 5.1583 -7.8579 -0.9511 0.2968 -8.9646 23.9167 6.0972

Quantization Matrix:

[3] After FDCT stage, Quantization process performs by normalizing above coefficients
using the Quantization matrix. After Quantization process, the resultant matrix is shown
below.
-19 21 0 1 0 0 0 0

-25 10 6 0 0 0 0 0

-2 -8 5 1 0 0 0 0

-1 -2 -1 3 0 0 0 0

-1 0 -1 0 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

[4] After quantization above coefficients are rearranged in zigzag ordering which is shown
below

-19 21 -25 -2 10 0 1 6 -8 -1 -1 -2 5 0 0 0 0 1 -1 0 0 0 0 -1 3 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 EOB

From above zigzag ordering, efficient DC coefficient can be predicted by subtracting


previous DC coefficient value from the current DC coefficient value, consider previous
image block‘s DC coefficient is - 4.

(DC)PREDICTED = (DC) CURRENT – (DC) PREVIOUS

(-15) = (-19) - (-4)

For AC coefficient encoding, Run level generates from above zigzag ordering. In this run
level first digit indicate Run means number of levels. When all zeros are exist in the stream
special End of Bit (EOB) code word are inserted.

(0,21),(0,-25),(0.-2),(0,10),(1,1),(0,6),(0,-8),(0,-1),(0,-1),(0,-2),(0,5),(4,1),(0,-1),(4,1),(0,3),(14,1),EOB

For the coding of DC coefficient, we have to use JPEG Coefficients Coding Category table as
well as JPEG default DC code table which are shown in Table and Table A2.

For DC coefficient encoding, we need to encode (-15). For that we can find its DC difference
category from Table. It indicates its DC difference category is 4, for the same its Base code is
101 which shown in Table .
Final DC code can be achieved by combining the base code and its Huffman code. For our
coefficient (-15), its complete code word is 1010000.

Range DC Base Code


-15 ………. 15
Difference
Category
0000 …….. 1111
-15,…,-8,8,…,15 4 101

(a) Base code for DC coefficient (b) Huffman code for DC coefficient

For AC coefficient coding (0, 21) we can find AC category from TableA1. So, AC
category is 5 for 21 and its run is 0. We can find the base code for 0/5 (Run/Category)
from

TableA3. The base code is 11010 and Huffman code is 1101010101 for the same. Similarly,
we can encode all AC coefficients using this run length encoding method.

After encoding all DC coefficients and AC coefficient final encoded output for given sub
image is shown below.

1010000 1101010101 1101000110 0101 10111010 11001 100110 10110111 000 000 0101
100101 1110111 000 1110111 0111 1111111101101 1010.

Above bit streams are only for one sub image, using the similar procedure the entire image is
encoded using the same procedure and this bit stream is transmitted through channel. At the
decoder side same procedure can be done in reverse way to retrieve the original image.

Huffman Coding Tables


TableA1 JPEG Coefficients Coding Category

Table A2 JPEG default DC code (luminance)


Table A3 JPEG default AC code (luminance)

You might also like