Image Compression5
Image Compression5
3-2020-? Lecture 5
:
Data Compression o r BrooaaddCCaasstt:
FFor Br = 1 6 6
M Mbbitit//ss
te
bit raate=16 6
Withthe
With thegrowing
growingneed
needofofreal-time
real-timevideo
videoapplication,
application, TTVVbit r 85 Mbbititss//ss
TV =8885 M
thevideo
the videocompression
compressionplays
playsthe
theimportant
importantrole
roleof
ofBand
Band HHDDTV =
5
Widthefficiency
Width efficiencyfor
forboth
bothtransmission
transmissionand
andstorage.
storage.
4
3
1
6
JPEG Compression
JPEG is an image compression standard that was developed by the “Joint
Photographic Experts Group”. JPEG was formally accepted as an
international standard in 1992.
Gray
YCbCr
• Y : the luminance of the image which represents the brightness.
• Cb : the chrominance of the image which represents the difference between the
gray and blue.
• Cr : the chrominance of the image which represents the difference between the
gray and red.
Chrominance
(a) 4 : 4 : 4 (b) 4 : 2 : 2
Subsampling
(c) 4 : 2 : 0 (d) 4 : 1 : 1
W W W W
H Y H Y H Y H Y
t is n ot
e fo rma
h
e of t to the
W W/2 W/2 W/4
n a m
H/2 Cb The r e lated .
H C y s
alwa ratio
H Cb H Cb
b
mp l in g
subsa
W W/2 W/2 W/4
H/2 Cr
H Cr H Cr H Cr
5
Matlab
Rgb2ycbcr
Convert RGB color values to YCbCr color space
RGB = imread('board.tif');
YCBCR = rgb2ycbcr(RGB);
Y Cb Cr
ycbcr2 Rgb
Ea
ch
In B
de Cod loc
pe e k
nd
en
tly
Observation for JPEG Compression
• The effectiveness of the DCT transform coding method in JPEG relies
on 3 major observations:
• Observation 1:1 Useful image contents change relatively slowly across
the image, i.e., it is unusual for intensity values to vary widely several
times in a small area, for example, within an 8 x 8 image block.
– much of the information in an image is repeated, hence “spatial
redundancy”.
• Observation 2: 2 Psychophysical experiments suggest that humans are
much less likely to notice the loss of very high spatial frequency
components than the loss of lower frequency components.
– the spatial redundancy can be reduced by largely reducing the high
spatial frequency contents.
– JPEG uses DCT to reduce high-frequency contents and then
efficiently code the results into a string
• Observation 3:Visualacuity(accuracy
3 in distinguishing closely spaced
lines) is much greater for gray (“black and white”) than for color.
– chroma subsampling (4:2:0) is used in JPEG.
DCT Image Compression
DCT is the real part of the 2D Fourier Transform
• DCT
• Inverse DCT
2D-DCT A
2D-IDCT
DCT Properties:
Decorrelation
The principle advantage of image transformation is the removal of
redundancy between neighboring pixels.
This leads to uncorrelated transform coefficients which can be
encoded independently.
Energy Compaction
Efficiency of a transformation scheme can be directly measured by its
ability to pack input data into as few coefficients as possible.
This allows the quantizer to discard coefficients with relatively small
amplitudes without introducing visual distortion in the reconstructed
image.
DCT exhibits excellent energy compaction for highly correlated images.
Increasing frequency
Increasing frequency
Visualization of basis Functions
DC component
2D-DCT
low frequency High frequency
• Purpose of quantization
– reduce the total number of bits needed for a compressed image.
• Low-frequency coefficients usually have more energy than high-
frequency coefficients, The human visual system is more sensitive to
low frequencies and more sensitive to luminance to chrominance.
Code Category
010 0
011 1
100 2
00 3
101 4
110 5
1110 6
11110 7
111110 8
1111110 9
11111110 10
111111110 11
Huffman Coding
• The DC and AC coefficients finally undergo an entropy coding step to
gain a possible further compression.
• Use DC as an example: each DPCM coded DC coefficient is
represented by (SIZE, AMPLITUDE),
SIZE indicates how many bits are needed for representing the
coefficient,
AMPLITUDE contains the actual bits.
• In the example we're using, codes 150, 5, −6, 3, −8 will be turned into
(8, 10010110), (3, 101), (3, 001), (2, 11), (4, 0111) .
• SIZE is Huffman coded since smaller SIZEs occur much more often.
• AMPLITUDE is not Huffman coded, its value can change widely so
Huffman coding has no appreciable benefit.
.Entropy Coding-run Length Coding on Acs
• The zigzag scan order has a good chance of concatenating long runs of
zeros.
(32, 6, -1, -1, 0, -1, 0,0,0,-1, 0,0, 1, 0,0, …, 0)
• Replace values by a pair (RUNLENGTH, VALUE) for each run of zeros in
the AC coefficients.
– RUNLENGTH is the number of zeros in the run
– VALUE is the next nonzero coefficient.
– A special pair (0,0) indicates the end-of-block.
• Not considering the first (DC) component, we will have (0,6)(0,-1) (0,-1)
(1,-1)(3,-1)(2,1)(0,0)
Zero Run Length Coding
• Encode each value which is not 0, than add the number of consecutive
zeroes in front of it
• EOB (End of Block) = (0,0)
• Only 4-bit value
• [57,45,0,0,0,0,23,0,-30,-16,0,……,0]
⇒[(0,57)(0,45)(4,23)(1,-30)(0,16)EOB]
• “Eighteen zeroes, 3” ⇒(15,0) ; (2,3) where (15,0) is 16 consecutive zeroes
Huffman Coding
P(xi) Xi
0.55 00 0.45 00 0.3 00 0.3 1 0.3 X
01
0.45 01 0.3 01 0.25 01 0.25 00 0.25 X
12
11 0.25 11 0.25 10 0.2 01 0.2 X3
101 100 0.2 11 0.13 0.12 X4
1000 101 0.12 0.08 X5
1001 0.05 X6
H=2.36 b/symbol
L=2.38 b/symbol
0.991=
r =0.009
Huffman Coding
Image size(16*16)
P(xi) Xi
0.53 00 0.47 00 0.3 00 0.3 00 0.3 00 0.3 10.3 X01
000.23 1
0.47 01 0. 3 01 0.23 01 0.23 01 0.23 01 0.23 X2
1000.23 11
100 0.27 100 0.2 0.15 10 0.15 010.15 X3
101 101 0.2 101 0.15 0.12 11 0.12 0.08 X4
100
0.12 0.12 0.08 0.06 X5
1000 111 110 101
0.08 0.06 0.06 X6
1001 1000 111
1010 1001 0.06 0.06 X7
1011 0.06 X8
Huffman Coding
Image size(16*16)
Huffman
De-zigzag
Decoding
Bit-stream Dequantizer
De-DC Huffman
Quantization coding Decoding
Table
B
G
Chrominance R
8X8 YVU color
Upsampling Decoded
IDCT coordinate
(4:2:2 or 4:2:0) Image
Fidelity Criteria
• Resulting image is “close” to original image.
• Usually measure “closeness” with MSE (Mean Squared Error) and PSNR
(Peak Signal to Noise Ratio) – Want low MSE and high PSNR
255
Compression Ratio
JPEG Encoder
JPEG Encoder
JPEG Decoder
JPEG Decoder
JPEG
JPEG
.The proposed algorithm focus on Always , Most of image
reduce the processing time required blocks have this property
taking advantage of inter pixel
The pixels in this block
redundancy
have same value of
amplitude
88 88 88 88 88 88 88 88 704 0 0 0 0 0 0 0
88 88 88 88 88 88 88 88 0 0 00 0 00 0
88 88 88 88 88 88 88 88 0 0 00 0 00 0
88 88 88 88 88 88 88 88 0 0 00 0 00 0
88 88 88 88 88 88 88 88
2D-DCT 0 0 00 0 00 0
88 88 88 88 88 88 88 88
0 0 0 00 0 00
88 88 88 88 88 88 88 88
0 0 0 00 0 00
88 88 88 88 88 88 88 88
0 0 0 00 0 00
DCT for DC DCT for other
element only 63 elements
Quantization Quantization
for DC for other
element 63 elements
zigzag
Using DC AC Huffman
Huffman table table
JPEG
JPEG
C(u,v)=L(u,v)*Q(u,v)+ Δ
Modified JPEG
No. of
Processing Ratio No. of MJPEG CODEC JPEG CODEC Total
Time of Similar PSNR Compression PSNR Compression Blocks Dimensions Image
Ratio SB/T Blocks (dB) Ratio (dB) Ratio (TB)
MJPEG/ B (SB)
JPEG
0.43 0.6 1850 32.027 32.263 31.830 30.655 3072 256*256*3 House
0.42 0.62 745 37.80 25.65 38.51 24.519 1188 176*144*3 Table
0.61 0.39 1209 31.22 25.761 31.406 24.197 3072 256*256*3 Peppers
0.44 0.59 1820 29.587 22.548 29.513 21.215 3072 256*256*3 Boat
0.70 0.32 1009 26.477 15.745 26.19 15.355 3072 256*256*3 Sailboat
charts illustrated percents omitted operations in equality block contents
Performance of MJPEG scheme compared with JPEG
Arithmetic (or Range)Coding
Unlike the variable-length codes, arithmetic coding, generates non-
block codes. In arithmetic coding, a one-to-one correspondence between
source symbols and code words does not exist. Instead, an entire sequence
of source symbols (or message) is assigned a single arithmetic code word.
The code word itself defines an interval of real numbers between 0 and
1. As the number of symbols in the message increases, the interval used to
represent it becomes smaller and the number of information units (say,
bits) required to represent the interval becomes larger. Each symbol of
the message reduces the size of the interval in accordance with the
probability of occurrence.
Encode message: a1 a2 a3 a3 a4
1)Assume message occupies [0, 1)
2)Subdivide [0, 1) based on the probability of αi
3)Update interval by processing source symbols.
Encoding Sequence
a1 a2 a3 a3 a4
1 0.2 0.08 0.072 0.0688
a4 a4 a4 a4 a4
0.06752
a3 a3 a3 a3 a3
a2 a2 a2 a2 a2
a1 a1 a1 a1 a1
0 0 0.04 0.056 0.0624
Decode 0.572
Decode 0.572
a3
r y0 0
Consider a 4x4, 8 bit image na 1 1
126 126 39 39 tio . .
ic
126 126 39 39 l D 255 255
126 126 39 39 i tia - 256
126 126 39 39 In
LZW Coding
511 -
LZW Coding Concatenated Sequence: CS = CR + P
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
CR = empty
If CS is found:
(1) No Output
(2) CR=CS
:else
Output D(CR) )1(
Add CS to D )2(
CR=P )3(
• The dictionary which was used for encoding need not be sent with the
image.
• Can be built on the “fly” by the decoder as it reads the received code
words.
JPEG2000 JPEG