Lecture8 PDF
Lecture8 PDF
5 Dictionary-based Coding
LZW uses fixed-length code words to represent
variable-length strings of symbols/characters that
commonly occur together, e.g., words in English
text
LZW encoder and decoder build up the same dictionary
dynamically while receiving the data
1 A
2 B
3 C
A B 1 4 AB
B A 2 5 BA
A B
AB B 4 6 ABB
B A
BA B 5 7 BAB
B C 2 8 BC
C A 3 9 CA
A B
AB A 4 10 ABA
A B
AB B
ABB A 6 11 ABBA
A EOF 1
2
1/30/09 CSE 40373/60373: Multimedia Systems page 2
LZW decompression (1 2 4 5 2 3 4 6 1)
1 A
2 B
3 C
NIL 1 A
A 2 B 4 AB
B 4 AB 5 BA
AB 5 BA 6 ABB
BA 2 B 7 BAB
B 3 C 8 BC
C 4 AB 9 CA
AB 6 ABB 10 ABA
ABB 1 A 11 ABBA
A EOF
ABABBABCABABBA
3
1/30/09 CSE 40373/60373: Multimedia Systems page 3
LZW Coding (cont’d)
In real applications, the code length l is kept in the
range of [l0, lmax]. The dictionary initially has a size
of 2l0. When it is filled up, the code length will be
increased by 1; this is allowed to repeat until l = lmax
Predictor Prediction
P1 A
P2 B
P3 C
P4 A+B–C
P5 A + (B – C) / 2
P6 B + (A – C) / 2
P7 (A + B) / 2
1/30/09 CSE 40373/60373: Multimedia Systems page 7
2. Encoding: The encoder compares the prediction
with the actual pixel value at the position ‘X’ and
encodes the difference using Huffman coding