Image Compression
Content
Redundancies
Coding
Interpixel
Psychovisual
Fidelity Criteria
Image Compression models
Error free compression
Lossy compression
Image compression standards
Compression..??
What is compression.?
A technique by which the data is stored as information.
Representation of data in such a way that it makes the
use of less resources to store and transmit it.
How it is done..??
By reducing the redundancy present in the data.
Redundancy = Data – Information
Redundancy = Irrelevant or symmetric data.
R= 1- 1/C
Where
c= b/b’
R = relative redundancy
b= bits used to represent data
b’ = bits used to represent the information from that data
Redundancies
Coding Redundancies
Interpixel Redundancies
Psychovisual Redundancies
Coding Redundancies
Code: system of letters, numbers, bits (symbols)
Codeword: Meaningful sequence of symbols
Code Length: Number of symbols used to form codeword
Often Coding techniques makes the use of more number of bits than
that required to store the intensity.
Example
In 8 bit gray scale representation intensity level ‘6’ is represented by
‘00000110’
where only 3 last bits are significant and rest 5 are redundant.
In this example
Code = {1,0}, Codeword = 00000110 and Code Length = 8
Other way to exploit redundancy
Suppose we are making use of 8 bits to represent the gray levels in the
image.
But suppose image is having only ’64’ different intensity levels in it out
of possible ‘256’ gray levels.
Now if we assign new code to those ’64’ intensities, ‘6’ bits are sufficient
to store the pixel information
Interpixel Redundancy (based
on planes)
Spetial (Intra plane) Redundancy:
The correlated pixels in a still image
Temporal (Interplane) Redundancy:
The correlated pixels in two consecutive
frames (two still images)
Psychovisual Redundancies
The information coded, that is not
interpreted by human visual system.
The information coded, that is not
detected by human visual system.
Detected = Interpreted..??
Fidelity Criteria
How to specify Information loss.?
Objective fidelity (mathematical)
Subjective fidelity (human opinion)
Objective Fidelity
Let f(x,y) is original image and f’(x,y) be the
approximation of f(x,y)
Error e(x,y) = f’(x,y) – f(x,y)
So the total error between original and
decompressed image
∑∑[f’(x,y) – f(x,y)]
Where summation is taken along the rows and
columns
Fidelity Criteria (cntd…)
Root Mean Square Error
Where MSE is mean square error.
MSE =1/MN ( ∑∑[f’(x,y) – f(x,y)] )2
Where summation is taken along the rows
(M) and columns (N)
Fidelity Criteria (cntd…)
Signal to Noise Ratio (SNR)
∑∑f’(x,y)2 / ∑∑[f’(x,y) – f(x,y)] )2
Where summation is taken along the rows
(M) and columns (N)
i.e. Approximated Signal / Square Error
Fidelity Criteria (cntd…)
Subjective Fidelity
Human opinion about the perceived image
Excellent (much better)
Fine (better)
Passable (slightly better)
Marginal (slightly worse)
Inferior (worse)
Unusable (much worse)
These comments can be ranged from -3 to 3
numeric from ‘much better’ to ‘much ‘worse’
respectively
Image Compression Model
General Compression Model
Generic Image Compression Model
Special about Image Compression
Compressing an image is significantly different than compressing raw
binary data.
Of course, general purpose compression programs can be used to
compress images, but the result is less than optimal.
This is because images have certain statistical properties which can be
exploited by encoders specifically designed for them.
Also, some of the finer details in the image can be sacrificed for the
sake of saving a little more bandwidth or storage space.
This also means that lossy compression techniques can be used in this
area.
Lossless compression involves with compressing data which, when
decompressed, will be an exact replica of the original data.
This is the case when binary data such as executables, documents etc.
are compressed.
On the other hand, images (and music too) need not be reproduced
'exactly'.
An approximation of the original image is enough for most purposes, as
long as the error between the original and the compressed image is
tolerable.
Image Compression Model (cntd..)
Mapper : Reduces inter-pixel redundancy
Run length coding: reversible
Calculation of DCT: reversible
Quantizer: reduces psyco-visual redundancy
Reduction of grey scales: not reversible
Removal of high frequency content: not reversible
Reduces the accuracy of Mapper’s output
Symbol Enoder:reduces coding redundancy
Generates the fixed length or variable length symbols
to represent the output of quantizer.
Variable length coding: reversible
Channel transmits the compressed data.
Error Free Compression
Variable length coding
Huffman coding
Most probable symbol is assigned the shortest code
word
Some Properties of Huffman Code
Instantaneous:
do not refer|ence s{uz cceed}ing symbols
Uniquely decodable
symbols can be decoded in only one way
Block code
for each symbol: only one code
Example
Symbol Frequency
A 24
B 12
C 10
D 08
E 08
Total 186 bit (with 3 bit per code word)
Steps
The two rarest symbols 'E' and 'D' are connected first,
followed by 'C' and 'D'.
The new parent nodes have the frequency 16 and 22
respectively and are brought together in the next step.
The resulting node and the remaining symbol 'A' are
subordinated to the root node that is created in a final
step.
Example Continued
Example Continued
S F C CL TL
A 24 0 1 24
B 12 100 3 36
C 10 101 3 30
D 8 110 3 24
E 8 111 3 24
-------------------------------------
186 138 bits
Lavg = (0.4)(1) + (0.3)(2) + (0.1)(3) + (0.1)(4) + (0.06)(5) +
(0.04)(5) = 2.2 bits/pixel
Arithmetic Coding
Huffman uses a static table for the whole
coding process, so it is rather fast, but
does not produce an efficient
compression ratio.
Arithmetic coding, on the other hand,
has different features.
It can generate a high compression ratio (3
bits per character on avarage), but all the
complex calculation takes much more time,
resulting in a slower implementation.
AAA: 0, 0.0996
AA: 0, 0.166 AAB: 0.0996, 0.1328
AAC: 0.1328, 0.166
ABA: 0.166, 0.1869375
: 0, 0.333 AB: 0.166, 0.24975 ABB: 0.1869375, 0.2288125
ABC: 0.2288125, 0.24975
ACA: 0.24975, 0.2705625
AC: 0.24975, 0.333 ACB: 0.2705625, 0.291375
ACC: 0.291375, 0.333
BAA: 0.333, 0.34965
BA: 0.333, 0.41625 BAB: 0.34965, 0.3996
BAC: 0.3996, 0.41625
BBA: 0.41625, 0.457875
B: 0.333, 0.666 BB: 0.41625, 0.58275 BBB: 0.457875, 0.541125
BBC: 0.541125, 0.58275
BCA: 0.58275, 0.5994
BC: 0.58275, 0.666 BCB: 0.5994, 0.6327
BCC: 0.6327, 0.666
CAA: 0.666, 0.68265
CA: 0.666, 0.74925 CAB: 0.68265, 0.6993
CAC: 0.6993, 0.74925
CBA: 0.74925, 0.7700625
C: 0.666, 1.0 CB: 0.74925, 0.8325 CBB: 0.7700625, 0.790875
CBC: 0.790875, 0.8325
CCA: 0.8325, 0.874375
CC: 0.8325, 1.0 CCB: 0.874375, 0.91625
Initial:
D
i
v
i
d
e
a
r
e
a
i
n
2nd
t
1st Iteration: Iteratio
o
After n: 3rd Iteration: After
5 4th Iteration: After
A After ABA 5th Iteration: After
( ABAC
Divide AB Divide ABACU
# Divide
previo Divide previous Divide previous
o previous area
us area previo area by 8 (# area by 10 (#
f by 9 (#
by 6 (# us area unique unique characters
u unique
unique by 7 (# characters +5)
n characters +4)
charact unique +3)
i
ers +1) charact
q
ers +2)
u
e
c
h
Comparison
Lampel-Zev-Welch
Huffman coding and Arithmetic coding
Coding redundancy
LZW emphasizes on Spatial Redundancy
Error free compression technique that makes the use of
fixed length codes.
It assigns fixed length-length to variable length code words.
It is a patent technique
Technique is used in GIF, TIFF and PDF
So PNG was designed to overcome the difficulties of patent .
LZW gives the better compression ratio than that of HC or
AC as it exploits both coding as well as spetial
redundancies.
How LZW works.?
A dictionary is constructed which contains
Source symbols to be encoded.
For 8 bit image, intensities [0,255] are put in
dictionary
Encoder examines the pixel intensities
Intensity that are not in the dictionary are put in
next unused (algorithmically determined)
locations.
Suppose we encountered two consecutive
pixels of value 255 then a new code word ‘256’
is used to represent it.
Number of bits saved = (8+8) – 9 = 7 bits
Introduction to LZW (cont'd)
Codes 0-255 in the code table are always assigned to represent single
bytes from the input file.
When encoding begins the code table contains only the first 256
entries, with the remainder of the table being blanks.
Compression is achieved by using codes 256 through 4095 to represent
sequences of bytes.
As the encoding continues, LZW identifies repeated sequences in the
data, and adds them to the code table.
Decoding is achieved by taking each code from the compressed file,
and translating it through the code table to find what character or
characters it represents.
Example 1: Compression using LZW
Example 1: Use the LZW algorithm to compress the string
BABAABAAA
Example 1: LZW Compression Step 1
BABAABAAA P=A
STRING TABLE
C=empty
ENCODER OUTPUT
string codeword representing output code
BA 256 B 66
Example 1: LZW Compression Step 2
BABAABAAA P=B
STRING TABLE
C=empty
ENCODER OUTPUT
string codeword representing output code
BA 256 B 66
AB 257 A 65
Example 1: LZW Compression Step 3
BABAABAAA P=A
STRING TABLE
C=empty
ENCODER OUTPUT
string codeword representing output code
BA 256 B 66
AB 257 A 65
BAA 258 BA 256
Example 1: LZW Compression Step 4
BABAABAAA P=A
STRING TABLE
C=empty
ENCODER OUTPUT
string codeword representing output code
BA 256 B 66
AB 257 A 65
BAA 258 BA 256
ABA 259 AB 257
Example 1: LZW Compression Step 5
BABAABAAA P=A
STRING TABLE
C=A
ENCODER OUTPUT
string codeword representing output code
BA 256 B 66
AB 257 A 65
BAA 258 BA 256
ABA 259 AB 257
AA 260 A 65
Example 1: LZW Compression Step 6
BABAABAAA P=AA
STRING TABLE
C=empty
ENCODER OUTPUT
string codeword representing output code
BA 256 B 66
AB 257 A 65
BAA 258 BA 256
ABA 259 AB 257
AA 260 A 65
AA 260
LZW Decompression
The LZW decompressor creates the same string table during
decompression.
It starts with the first 256 table entries initialized to single characters.
The string table is updated for each character in the input stream,
except the first one.
Decoding achieved by reading codes and translating them through the
code table being built.
LZW Decompression Algorithm
1 Initialize table with single character strings
2 OLD = first input code
3 output translation of OLD
4 WHILE not end of input stream
5 NEW = next input code
6 IF NEW is not in the string table
7 S = translation of OLD
8 S=S+C
9 ELSE
10 S = translation of NEW
11 output S
12 C = first character of S
13 OLD + C to the string table
14 OLD = NEW
15 END WHILE
Run length Encoding
It specifies two values
New intensity value
Number of consecutive pixels having that intensity.
The technique was explored for two dimensions
It became standard in facsimile (FAX)
It exploits the ------------ redundancy..??
It exploits spetial redundancy by grouping
consecutive pixels having same intensity value.
RLE Example
Standards that use RLE
CCITT
JPEG
M-JPEG
BMP
Symbol Based Coding
It exploits coding as well as spetial
redundancies
It assign a unique value to each symbol.
For compression it stores location and
corresponding code of that symbol.
Bit Plane Coding
First make the use of bit slice of the image
Then use one of the available techniques to compress the file.
Generally
Image is broken up into bit planes and then RLE is applied to each
plane.
Let the image is represented as
am-12m-1 + am-2 2m-2 + a1 21 + a0 20
So here we will get ‘m’ planes (0,1,2...m-1)
Problem:
Small change in intensities can cause lots of variation in code i.e. 127
(01111111) and 128(10000000)
Solution
Make the use of gray code
gi = ai EXOR ai+1 where 0<=i<=m-2 and gm-1 = am-1
Block Transform Coding
I/P Block Symbol Compressed
FT Quantizer Image
Preparation Encoder
Merge all Inverse Symbol
blocks Transform Decoder
Block Preparation
Y = 0.30R+0.59G+0.11B
I = 0.60R-0.28G-0.32B
Q = 0.21R-0.52G+0.31B
4800 blocks
Block ‘Y’ matrix to DCT
Computation of the quantized DCT coefficients
Transmission order
Image Compression
Standards
JPEG
CCITT
BMP