2. What is JPEG?
JPEG is sophisticated lossy/lossless
compression method for color or greyscale
still images. It works best on continuous tone
images where adjacent pixels have similar
colors. One advantage of JPEG is the use of
many parameters, allowing the use to adjust
the amount of data lost over a wide variety
range.
3. Main Goals of JPEG
High Compression Ratio in such cases where
images quality is judged as very good to
excellent.
The use of many parameters allowing user to
experiment and achieve the desired level of
compression.
Obtaining good results any kind of continuous
tone images.
Sophisticated but not too complex compression
method, allowing software and hardware
implementation on many platform.
Several modes of operations.
4. Modes of JPEG
Sequential Mode: each image component is
compressed in a single left to right, top to bottom
scan.
Progressive Mode: the images is compressed in
multiple blocks to be viewed from coarse to final
detail.
Lossless Mode: important for cases where the
user decides no pixel should be lost.
Hierarchical Mode: the image is compressed at
multiple resolution allowing lower resolution blocks
to be viewed without first having to decompressed
the following higher-resolution blocks.
5. Basic JPEG Compression
JPEG compression involves the following:
Color Space Transform and subsampling (YIQ)
DCT (Discrete Cosine Transformation)
Quantization
Zigzag Scan
DPCM on DC component & RLE on AC Components
Entropy Coding — Huffman or Arithmetic
7. 1.Colour Space Transform and sub-sampling(YIQ)
The images values are transformed from RGB to
luminance/chrominance color space.
The eye is sensitive to small changes in luminance
but not in chrominance. So chrominance values
can be used to compress the data.
This step is optional but important since the
remainder of the algorithm works on each color
component separately.
8. Color Space Transformation
RGB to YCbCr
Y is Luminance (Brightness).
CbCr is the Chrominance.
Sampling:
RGB
RGB
Y
Cb Cr
+ (Down Sampling)
9. RGB to YCbCr
First the image is divided into 8x8 blocks.
RGB RGB
RGB RGB
Y Y
Y Y
Cb
Cr
+
8
8
8 8
8
8
8 8
8
8
8
4 x 64 x 3 byte 4 x 64 x 1 byte 2 x 64 x 1 byte
Y = 0.299 R + 0.587 G + 0.114 B
Cb = - 0.169 R - 0.331 G + 0.500 B
Cr = 0.500 R - 0.419 G - 0.081 B
10. The mathematical representation of FDCT (2-D):
7
0
7
0
)
16
/
)
1
(
2
cos(
)
16
/
)
1
(
2
cos(
)
,
(
)
(
)
(
4
1
)
,
(
x y
v
j
u
i
y
x
f
v
C
u
C
v
u
F
Where
otherwise
x
x
C
1
0
2
/
1
)
(
f(x,y): 2-D sample value
F(u,v): 2-D DCT coefficient
2.Discrete Cosine Transform (DCT)
The Discrete Cosine Transform (DCT) separates the frequencies
contained in an image.
The original data could be reconstructed by Inverse DCT.
11. DCT (cont’d)
DCT
Coefficients
sxy DCT
8
8 8
8
DC coefficient
The DCT coefficient values can be regarded as the
relative amounts of the 2-D spatial frequencies
contained in the 88 block
the upper-left corner coefficient is called the DC
coefficient, which is a measure of the average of
the energy of the block
Other coefficients are called AC coefficients,
coefficients correspond to high frequencies tend to
be zero or near zero for most natural images
12. DCT (cont’d)
Why we apply DCT?
To move from Spatial Domain to Frequency
Domain.
Why not FFT?
DCT is like FFT, but can approximate linear
signals well with few [real] coefficients.
DCT is slow
1024 multiplications and 896 additions.
JPEG 2000: Wavelet Transforms.
14. Quantization (cont’d)
Why do we need to quantise:
To throw out bits from DCT.
Example: 101101 = 45 (6 bits).
Truncate to 4 bits: 1011 = 11.
Truncate to 3 bits: 101 = 5.
Quantization error is the main source of Lossy
Compression.
• DCT itself is not Lossy
• How we throw away bits in Quantization
Step is Lossy
19. 5.DPCM & RLE
1. DPCM on DC Component
Differential Pulse Code Modulation.
DC component is large and varied, but often
close to previous value.
2. RLE on AC Components
Zero Run Length Encoding.
1 x 64 vector has lots of zeros in it.
57,45,0,0,0,0,23,0,-30,-16,0,0,1,0,0,0, 0 , 0 ,0 , only 0,..,0
RLC: (0,57); (0,45); (4,23); (1,-30); (0,-16); (2,1); EOB
EOB = (0,0)
21. 6.Huffman (Entropy) Coding
DC and AC components finally need to be
represented by a
smaller number of bits (Arithmetic coding also
supported in place of Huffman coding):
(Variant of) Huffman coding: Each DPCM-coded DC
coefficient is represented by a pair of symbols : (Size,
Amplitude) where Size indicates number of bits needed
to represent coefficient and Amplitude contains actual
bits.
22. Huffman Coding (Table of values and bits for the
values)
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 ...
25. 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)
The difference of DC coefficience :
-511
Encode the value as category and bits for the value :
9, 000000000
26. Huffman Coding (Example) (cont’d)
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