Day 20
Day 20
character Frequency
a 5
b 9
c 12
d 13
e 16
f 45
Huffman coding- Example(contd.)
Extract two minimum frequency nodes from min
heap. Add a new internal node with frequency 5 + 9 =
14.
character Frequency
c 12
d 13
Internal Node 14
e 16
f 45
Huffman coding- Example(contd.)
Extract two minimum frequency nodes from heap.
Add a new internal node with frequency 12 + 13 = 25
character Frequency
Internal Node 14
e 16
Internal Node 25
f 45
Huffman coding- Example(contd.)
Extract two minimum frequency nodes. Add a new
internal node with frequency 14 + 16 = 30
character Frequency
Internal Node 25
Internal Node 30
f 45
Huffman coding- Example(contd.)
Extract two minimum frequency nodes. Add a new internal
node with frequency 25 + 30 = 55
character Frequency
f 45
Internal Node 55
Huffman coding- Example(contd.)
Extract two minimum frequency nodes. Add a new
internal node with frequency 45 + 55 = 100
character Frequency
Internal Node 100
Huffman coding- Generating the
code
Traverse the tree formed starting from the root. While
moving to the left child, write 0 . While moving to the
right child, write 1
Huffman coding- Generating the
codes
character code-word
f 0
e 111
d 101
c 100
b 1101
a 1100
LZW (Lempel–Ziv–Welch)
• It is lossless, meaning no data is lost when
compressing
• is typically used in GIF and Unix file compression
utility compress
• works by reading a sequence of symbols, grouping
the symbols into strings, and converting the strings
into codes
• The strings are replaced by their corresponding
codes and so the input file is compressed.
• The efficiency of the algorithm increases as the
number of long, repetitive words in the input data
increases.
LZW ENCODING
1 Initialize table with single character strings
2 P = first input character
3 WHILE not end of input stream
4 C = next input character
5 IF P + C is in the string table
6 P=P+C
7 ELSE
8 output the code for P
9 add P + C to the string table
10 P=C
11 END WHILE
12 output code for P
LZW Encoding Example
Data word : a b a b a b a b a
Dictionary
1 a
2 b
ababababa
Dictionary
1a Encoded word : 1
2b
3 ab
LZW Encoding Example(cont.)
ababababa
Dictionary
1a Encoded word : 1 2
2b
3 ab
4 ba
ababababa
ab already available in the dictionary, append next character
LZW Encoding Example(cont.)
ababababa
Dictionary
1a Encoded word : 1 2 3
2b
3 ab
4 ba
5 aba
ababababa
ab already available in the dictionary, append next character
ababababa
aba already available in the dictionary, append next character
LZW Encoding Example(cont.)
ababababa
Dictionary
1a Encoded word : 1 2 3 5
2b
3 ab
4 ba
5 aba
6 abab
ababababa
ba already available in the dictionary. Since, end of loop,
output code for ba
Encoded word: 1 2 3 5 4
LZW DECODING
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
LZW Decoding Example
Code word : 1 2 3 5 4 7
Dictionary
1a
2b
123547 Decoded word : a
123547 Decoded word : a b
123547
Dictionary
1a
2b
3 ab Decoded word : a b ab
LZW Decoding Example(contd.)
123547
Dictionary
1a
2b
3 ab
4 ba
5 aba
6 abab
7 bab Decoded word : a b ab aba ba bab
Image Compression Standards
Image Compression Standards
• Tagged image file format (TIFF) : used widely in
printing business as photograph file standard and not
used in browsers
• Portable network graphics (PNG) :created as an
open-source alternative to GIF. Designed to transfer
images over the internet.
• Joint Photographic Experts Group (JPEG): working
group which creates the standard for still image
compression.
• JPEG 2000 : image compression standard compatible
with multimedia technologies with the features such as
superior bit rate performance progressive transmission
by pixel and by accuracy, coding of interested region,
and not error prone to bit errors
JPEG vs JPEG 2000
JPEG JPEG2000
Created for natural images Created for computer generated images
Discrete Cosine Transform Discrete Wavelet Transform
Video Compression Standards
Standard Application
H.261 Video conferencing over ISDN
MPEG-1 Video on digital storage media
(CD-ROM)