Compression:: Source Image Data FDCT Quantizer Compressed Image Data
Compression:: Source Image Data FDCT Quantizer Compressed Image Data
JPEG (Joint photographic experts group) is joint result by:
o International organization for standardization (ISO)
o International Telegraph and Telephone Consultative Committee (CCITT)
o International Electrotechnical Committee (IEC)
The JPEG standard includes the following modes of operation:
o Lossless coding
o Sequential coding
o Progressive coding
o Hierarchical coding
Compression:
Source FDCT Q u a n tiz e r E n tro p y Compressed
Image Data E ncoder Image Data
8x8 blocks
T a b le T a b l e
S p e c if ic a t io n s S p e c if ic a t io n s
Decompression:
Compressed Entropy
D e q u a n tiz e r IDCT Reconstructed
Image Data Decoder Image Data
Table Table
Specifications Specifications
Discrete cosine transform
1-dimensional
DCT transform:
N 1
2 x 1 u
C u u f x cos
x 0 2N
Inverse transform:
N 1
2 x 1 u
f x u C u cos
u 0 2N
Scaling factor:
1 for u 0
N
u
2 for u 1,2,..., N 1
N
Discrete cosine transform
2-dimensional
DCT transform:
N 1 N 1
2 x 1 u 2 y 1 v
C u , v u v f x, y cos cos
x 0 y 0 2N 2N
Inverse transform:
N 1 N 1
2 x 1 u 2 y 1 v
f x, y u v C u , v cos cos
u 0 v 0 2N 2N
DCT basis functions for N=8:
v
0 1 2 3
3
Examples of DCT for sample 44 blocks
ORIGINAL TRANSFORMED
IMAGE IMAGE
FLAT
10 10 10 10 40.0 0.0 0.0 0.0
10 10 10 10 0.0 0.0 0.0 0.0
10 10 10 10 0.0 0.0 0.0 0.0
10 10 10 10 0.0 0.0 0.0 0.0
RANDOM TEXTURE
11 15 18 14 58.8 0.3 1.8 1.3
14 11 13 12 3.9 2.8 3.5 2.6
15 16 19 12 2.7 1.7 1.2 3.4
18 17 12 18 3.0 0.9 5.3 1.8
IMPULSE
10 10 10 10 42.5 1.4 2.5 3.2
10 20 10 10 1.4 0.7 1.4 1.8
10 10 10 10 2.5 1.4 2.5 3.3
10 10 10 10 3.2 1.8 3.3 4.3
LINE (horizontal)
10 10 10 10 50.0 0.0 0.0 0.0
10 10 10 10 5.4 0.0 0.0 0.0
20 20 20 20 10.1 0.0 0.0 0.0
10 10 10 10 13.1 0.0 0.0 0.0
EDGE (vertical)
10 10 20 20 60.0 18.4 0.0 7.7
10 10 20 20 0.0 0.0 0.0 0.0
10 10 20 20 0.0 0.0 0.0 0.0
10 10 20 20 0.0 0.0 0.0 0.0
EDGE (horizontal)
10 10 10 10 60.0 0.0 0.0 0.0
10 10 10 10 18.4 0.0 0.0 0.0
20 20 20 20 0.0 0.0 0.0 0.0
20 20 20 20 7.7 0.0 0.0 0.0
EDGE (diagonal)
10 10 10 10 55.0 11.1 0.0 0.7
10 10 10 20 11.1 5.0 4.6 0.0
10 10 20 20 0.0 4.6 5.0 1.9
10 20 20 20 0.7 0.0 1.9 5.0
SLOPE (horizontal)
10 12 14 16 52.0 8.9 0.0 0.6
10 12 14 16 0.0 0.0 0.0 0.0
10 12 14 16 0.0 0.0 0.0 0.0
10 12 14 16 0.0 0.0 0.0 0.0
Quantization in JPEG
Quantization equation:
c
ĉi round i
qi
- ci is the original transform coefficient (real number)
- q is the quantization factor (ingeteger between 1..255)
- The result is rounded to the nearest integer
Example of quantization by factor of 2:
10
9
8
7
6
5 5
4 4
3 3
2 2
1 1
0 0
Dequantization:
ri cˆi qi
Possible quantization tables:
Quantization tables in JPEG:
Luminance Chrominance
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
Entropy coding:
- Huffman or arithmetic coding.
- The first coefficient (denoted by DCcoefficient) is separately coded from the rest of
the coefficients (ACcoefficients).
- The DCcoefficient is by predicting from the DCcoefficient of the previous block.
- The prediction error is coded using as in lossless JPEG
- The ACcoefficients are coded one in the order given by zigzag scanning
- Simple runlength coding is applied:
o All subsequent zerovalue coefficients are coded by the runlength
o Huffman coding is then applied to the nonzero coefficients.
JPEG for color images:
RGB color images are compressed in JPEG by transforming the image first into YUV (or
YIQ in the case of North America) and then compressing the three color components
separately. The chrominance components are often subsampled so that 22 block of the
original pixels forms a new pixel in the subsampled image. The color component images are
then upsampled to their original resolution in the decompression phase.
Progressive mode:
Progressive JPEG is rather trivial. Instead of coding the image block after block, the coding is
divided into several stages. At the first stages the DCcoefficients are coded from each block.
The decoder can get rather good approximation of the image on the basis on the
DCcoefficients alone, since they contain the information of the average value of the blocks.
At the second stage, the first significant ACcoefficients (determined by the zigzag order) are
coded. At the third phase the next significant ACcoefficients are coded, and so on. In total,
there are 64 coefficients in each block, so the progressive coding can have at most 64 stages.
In practice, the progressive coding can be changed back to the sequential order for example
already after the first stage. This is because the DCcoefficients are usually enough for the
decoder to decide whether the image is worth retrieving.
Hierarchical mode:
- A reduced resolution version of the image is compressed
- followed by the higher resolution versions in increasing order.
- In each case the resolution is doubled
Example of a block compressed by JPEG:
Original block Transformed block
139 144 149 153 155 155 155 155 235.6 1.0 12.1 5.2 2.1 1.7 2.7 1.3
144 151 153 156 159 156 156 156 22.6 17.5 6.2 3.2 2.9 0.1 0.4 1.2
150 155 160 163 158 156 156 156 10.9 9.3 1.6 1.5 0.2 0.9 0.6 0.1
159 161 162 160 160 159 159 159 7.1 1.9 0.2 1.5 0.9 0.1 0.0 0.3
159 160 161 162 162 155 155 155 0.6 0.8 1.5 1.6 0.1 0.7 0.6 1.3
161 161 161 161 160 157 157 157 1.8 0.2 1.6 0.3 0.8 1.5 1.0 1.0
162 162 161 163 162 157 157 157 1.3 0.4 0.3 1.5 0.5 1.7 1.1 0.8
162 162 161 161 163 158 158 158 2.6 1.6 3.8 1.8 1.9 1.2 0.6 0.4
Quantization matrix Quantized coefficients
16 11 10 16 24 40 51 61 15 0 1 0 0 0 0 0
12 12 14 19 26 58 60 55 2 1 0 0 0 0 0 0
14 13 16 24 40 57 69 56 1 1 0 0 0 0 0 0
14 17 22 29 51 87 80 62 1 0 0 0 0 0 0 0
18 22 37 56 68 109 103 77 0 0 0 0 0 0 0 0
24 35 55 64 81 104 113 92 0 0 0 0 0 0 0 0
49 64 78 87 103 121 120 101 0 0 0 0 0 0 0 0
72 92 95 98 112 100 103 99 0 0 0 0 0 0 0 0
Dequantized coefficients Decompressed block
240 0 10 0 0 0 0 0 144 146 149 152 154 156 156 156
24 12 0 0 0 0 0 0 148 150 152 154 156 156 156 156
14 13 0 0 0 0 0 0 155 156 157 158 158 157 156 156
0 0 0 0 0 0 0 0 160 161 161 162 161 159 157 155
0 0 0 0 0 0 0 0 163 163 164 163 162 160 158 156
0 0 0 0 0 0 0 0 163 164 164 164 162 160 158 157
0 0 0 0 0 0 0 0 160 161 162 162 162 161 159 158
0 0 0 0 0 0 0 0 158 159 161 161 162 161 159 158
Original JPEG
bpp = 8.00 mse = 0.00 bpp = 1.00 mse = 17.26
JPEG JPEG
bpp = 0.50 mse = 33.08 bpp = 0.25 mse = 79.11
Figure 4.26: Magnifications of Lena compressed by JPEG.