8.1. Image Compression
8.1. Image Compression
8.1. Image Compression
Contact: kalpoma@aust.com
Google Class code: o5sjihh
❑ Data storage
❑ Data transmission
Applications that require image compression
are many and varied such as:
1. Internet,
2. Businesses,
3. Multimedia,
4. Satellite imaging,
5. Medical imaging
Why Images Are Compressed?
bytes 2 sec
31,104,000 (60) 2 hours
sec hour
2.24 1011 bytes
= 224 GB
• Web Images
– color images of size 128 X 128 through 56Kbps to
12Mbps connections
Requires 7.0 to 0.03 seconds to download
Why Images Are Compressed?
• High Definition (HD) TV color sequence
– each of size 1920X1080 pixels
Compression must be higher
• Web Images
– color images of size 128 X 128 through 56Kbps to
12Mbps connections
Requires 7.0 to 0.03 seconds to download
• 1 GB Flash memory and 8 Megapixel Digital
camera
Can store at most ~41 uncompressed images
Data Redundancy
❑ Let n1 and n2 denote the number of information carrying units in two
data sets that represent the same information
• Coding redundancy
Most 2-D intensity arrays contain more bits than are
needed to represent the intensities
• Irrelevant information
Most 2-D intensity arrays contain information that is
ignored by the human visual system
Coding Redundancy
Total Bit
required is
Computer generated
256x256x8 bit image with
coding redundancy =256X256X8
Coding Redundancy: Example
Total
=256X256X1.81 bits
C =8/1.81=~4.42
Computer generated
256x256x8 bit image with
coding redundancy R=1-1/C=.774
77.4 %
Lavg =.25X2+.47X1+.25X3+.03X3=1.81 bits
Coding Redundancy
Variable-Length Coding
2nd Example:
7
Lav = l (rk )( p (rk )
k =0
• Histogram is equiprobable
• Vertically, pixels are independent
• Horizontally, they are maximally correlated
• The image cannot be compressed using variable length
coding
Spatial and Temporal Redundancy
Example
Original Bit required
=256X256X8
In Run length
=(256+256)X8
C =(256X256X8)/(256+256)X8
Computer generated 256x256x8 bit =128:1
image with spatial redundancy
• Coding redundancy
• Spatial redundancy
• Irrelevant information
How many bits do we really need
to represent image-information?
1
I ( E ) = log = − log P( E )
P( E )
J
H = − P(a j ) log P(a j )
j =1
Calculating Image Entropy
~ L −1
H = − Pr (rk ) log P(rk )
k =1
Compression
Error-Free Compression
Lossy Compression
(Loss-less)
Different Error Free Compression
Techniques
❑ LZW coding
❑ Bit plane coding
❖ Constant area coding
❖ Run length coding
Huffman Coding
0.1
0.4
0.06
0.1
0.04
0.3
Huffman Coding: Example
Consider a 3 bit image with the following probabilities:
Huffman Coding: Example
Source Reduction
Huffman Coding: Example
Source Reduction
Huffman Coding: Example
Consider a 3 bit image with the following probabilities:
Huffman Coding: Example
0
0 1
0 1
0
1
0
1 Symbol Codeword
1
a2 0
a6 10
a1 110
a4 1110
a3 11110
a5 11111
Huffman Coding Results
H = -[(0.4)log2(0.4)+(0.3)log2(0.3)+(0.1)log2(0.1)
+(0.1)log2(0.1)+(0.06)log2(0.06)+(0.04)log2(0.04) C = 3/2.2 = 1.364
= 0.53+0.52+0.33+0.33+0.24+0.19 RD = (1- 1/1.364) = 0.267
= 2.14 bits/pixel Log2(x) = log10(x)x3.322
Huffman Coding Example 2
Example 2:
Huffman Coding Example – Results
Properties :
0.16
0.08
0.04
Arithmetic Coding
Symbol a2, associated with
subinterval [0.04, 0.08) is expanded
the full height in narrow range again
0.16
0.08
0.04
Arithmetic Coding
Symbol a2, associated with
subinterval [0.04, 0.08) is expanded
the full height in narrow range again
0.16 0.072
0.08 0.056
0.04 0.048
Arithmetic Coding
Symbol a3, associated with
subinterval [0.056, 0.072) is
expanded the full height in narrow
range again
0.16 0.072
0.08 0.056
0.04 0.048
Arithmetic Coding
Symbol a3, associated with
subinterval [0.056, 0.072) is
expanded the full height in narrow
range again
a1a2 a3a3a4
is 0.068
• Example
Consider the following 4 x 4 8 bit image Dictionary Location Entry
39 39 126 126 0 0
1 1
39 39 126 126 . .
255 255
39 39 126 126 256 -
39 39 126 126 511 -
Initial Dictionary
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1 Sequence= Concatenate(‘ ’, ‘39’) = 39
. .
255 255
256 -
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1 Sequence= Concatenate(‘ ’, ‘39’) = 39
. .
255 255
256 -
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1 Sequence= Concatenate(‘39’, ‘39’) = 39-39
. .
255 255
256 -
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location Address of ‘39’
0 0
1 1 Sequence= Concatenate(‘39’, ‘39’) = 39-39
. .
255 255
256 39-39
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1
. .
255 255
256 39-39
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1 Sequence= Concatenate(‘39’, ‘126’) = 39-126
. .
255 255
256 39-39
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location Address of ‘39’
0 0
1 1 Sequence= Concatenate(‘39’, ‘126’) = 39-126
. .
255 255
256 39-39
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1 Sequence= Concatenate(‘39’, ‘126’) = 39-126
. .
255 255
256 39-39
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1 Sequence= Concatenate(‘126’, ‘126’) = 126-126
. .
255 255
256 39-39
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1
. .
255 255
256 39-39
Sequence= Concatenate(‘126’, ‘39’) = 126-39
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1
. .
255 255
256 39-39
Sequence= Concatenate(‘39’, ‘39’) = 39-39
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1
. .
255 255
256 39-39
Sequence= Concatenate(‘39’, ‘39’) = 39-39
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1
. .
255 255
256 39-39
Sequence= Concatenate(‘39’, ‘39’) = 39-39
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1
. .
255 255
256 39-39
Sequence= Concatenate(’39-39’, ‘126’) = 39-39-126
511 -
Lempel-Ziv-Welch (LZW) Coding
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
Dictionary Entry
Location
0 0
1 1
. .
255 255
256 39-39
511 -
511 -
511 -
Lempel-Ziv-Welch (LZW) Coding
Encoding of
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
is
39 39 126 126
256 258 260 259 257 126
How to decode?
LZW Decoding Dictionary Dictionary
Code word entry
0 0
Decoding of 1 1
| |
39 39 126 126 256 258 260 259 257 126 39 39
| |
is 126 126
39 | |
255 255
256 39-39
257 39-126
258 126-126
259 126-39
260 39-39-126
261 126-126-39
262 39-39-126-126
263 126-39-39
264 39-126-126
LZW Decoding Dictionary Dictionary
Code word entry
0 0
Decoding of 1 1
| |
39 39 126 126 256 258 260 259 257 126 39 39
| |
is 126 126
39 39 | |
255 255
256 39-39
257 39-126
258 126-126
259 126-39
260 39-39-126
261 126-126-39
262 39-39-126-126
263 126-39-39
264 39-126-126
LZW Decoding Dictionary Dictionary
Code word entry
0 0
Decoding of 1 1
| |
39 39 126 126 256 258 260 259 257 126 39 39
| |
is 126 126
39 39 126 | |
255 255
256 39-39
257 39-126
258 126-126
259 126-39
260 39-39-126
261 126-126-39
262 39-39-126-126
263 126-39-39
264 39-126-126
LZW Decoding Dictionary Dictionary
Code word entry
0 0
Decoding of 1 1
| |
39 39 126 126 256 258 260 259 257 126 39 39
| |
is 126 126
39 39 126 126 | |
255 255
256 39-39
257 39-126
258 126-126
259 126-39
260 39-39-126
261 126-126-39
262 39-39-126-126
263 126-39-39
264 39-126-126
LZW Decoding Dictionary Dictionary
Code word entry
0 0
Decoding of 1 1
| |
39 39 126 126 256 258 260 259 257 126 39 39
| |
is 126 126
39 39 126 126 | |
39 39 255 255
256 39-39
257 39-126
258 126-126
259 126-39
260 39-39-126
261 126-126-39
262 39-39-126-126
263 126-39-39
264 39-126-126
LZW Decoding Dictionary Dictionary
Code word entry
0 0
Decoding of 1 1
| |
39 39 126 126 256 258 260 259 257 126 39 39
| |
is 126 126
39 39 126 126 | |
39 39 126 126 255 255
256 39-39
257 39-126
258 126-126
259 126-39
260 39-39-126
261 126-126-39
262 39-39-126-126
263 126-39-39
264 39-126-126
LZW Decoding Dictionary Dictionary
Code word entry
0 0
Decoding of 1 1
| |
39 39 126 126 256 258 260 259 257 126 39 39
| |
is 126 126
39 39 126 126 | |
39 39 126 126 255 255
39 39 126 256 39-39
257 39-126
258 126-126
259 126-39
260 39-39-126
261 126-126-39
262 39-39-126-126
263 126-39-39
264 39-126-126
LZW Decoding Dictionary Dictionary
Code word entry
0 0
1 1
Decoding of | |
39 39 126 126 256 258 260 259 257 126 39 39
| |
is 126 126
39 39 126 126 | |
39 39 126 126 255 255
256 39-39
39 39 126 126
257 39-126
39 258 126-126
259 126-39
260 39-39-126
261 126-126-39
262 39-39-126-126
263 126-39-39
264 39-126-126
LZW Decoding Dictionary Dictionary
Code word entry
0 0
1 1
Decoding of | |
39 39 126 126 256 258 260 259 257 126 39 39
| |
is 126 126
39 39 126 126 | |
39 39 126 126 255 255
256 39-39
39 39 126 126
257 39-126
39 39 126 258 126-126
259 126-39
260 39-39-126
261 126-126-39
262 39-39-126-126
263 126-39-39
264 39-126-126
LZW Decoding Dictionary Dictionary
Code word entry
0 0
1 1
Decoding of | |
39 39 126 126 256 258 260 259 257 126 39 39
| |
is 126 126
39 39 126 126 | |
39 39 126 126 255 255
256 39-39
39 39 126 126
257 39-126
39 39 126 126 258 126-126
259 126-39
260 39-39-126
261 126-126-39
262 39-39-126-126
263 126-39-39
264 39-126-126
Compression Ratio using LZW Coding
Spatial redundancy
110
Recall
Run Length Encoding
256 x 256 x 8
– Compression Ratio = = 128
[256 + 256] x 8
Run Length Encoding (RLC)
1b 2w 1b 3w 4b 1w
1b 2w 1b 3w 4b 1w
❑ Example: