Ch5 Dictionary Coding
Ch5 Dictionary Coding
CODING
Dictionary Coding
Dictionary coding is different from Huffman
coding and arithmetic coding.
Both Huffman and arithmetic coding techniques
are based on a statistical model (e.g.,
occurrence probabilities).
In dictionary-based data compression
techniques, a symbol or a string of symbols
generated from a source alphabet is
represented by an index to a dictionary
constructed from the source alphabet.
Dictionary Coding
A dictionary is a list of symbols and strings
of symbols.
There are many examples of this in our daily
lives.
the string September vs. 9,
a social security number vs. a person in the U.S.
Dictionary Coding
Consider English text coding.
The source alphabet includes 26 English letters in both
lower and upper cases, numbers, various punctuation
marks and the space bar.
Huffman or arithmetic coding treats each symbol based
on its occurrence probability. That is, the source is
modeled as a memoryless source.
It is well known, however, that this is not true in many
applications.
In text coding, structure or context plays a significant
role.
Very likely that the letter u appears after the letter q.
Likewise, it is likely that the word concerned will appear after
As far as the weather is.
Dictionary Coding
The strategy of the dictionary coding is to
build a dictionary that contains frequently
occurring symbols and string of symbols.
When a symbol or a string is encountered and it
is contained in the dictionary, it is encoded with
an index to the dictionary.
Otherwise, if not in the dictionary, the symbol or
the string of symbols is encoded in a less
efficient manner.
Dictionary Coding
All the dictionary schemes have an equivalent
statistical scheme, which achieves exactly the
same compression.
Statistical scheme using high-order context
models may outperform dictionary coding (with
high computational complexity).
But, dictionary coding is now superior for fast
speed and economy of memory.
In future, however, statistical scheme may be
preferred [bell 1990].
A fixed dictionary,
If not, then the index of the first symbol is used to encode the
first symbol. The second symbol is combined with the third
symbol to form a new pair, which is encoded in the next step.
Parsing Strategy
Once have a dictionary,
Need to examine the input text and find a string of
symbols that matches an item in the dictionary.
Then the index of the item to the dictionary is encoded.
Parsing Strategy
In terms of the highest coding efficiency, optimal
parsing is essentially a shortest-path problem
[bell 1990].
In practice, however, a method called greedy
parsing is used in all the LZ77 and LZ78
algorithms.
With greedy parsing, the encoder searches for the
longest string of symbols in the input that matches an
item in the dictionary at each coding step.
Greedy parsing may not be optimal, but it is simple in
implementation.
Parsing Strategy
Example 6.1
Consider a dictionary, D, whose phrase set
P {a, b, ab, ba, bb, aab, bbb} . The codewords assigned to
these strings are C(a) 10 , C (b) 011 , C (ab) 010 , C (ba) 0101 ,
C (bb) 01 , C (aab) 11 , and C (bbb) 0110.
Now the input text: abbaab.
Using greedy parsing, we then encode the text as
C (ab).C (ba).C (ab) , which is a 10-bit string: 010.0101.010.
In above representations, the periods are used to
indicate the division of segments in the parsing.
This, however, is not an optimum solution. Obviously,
the following parsing will be more efficient, i.e.,
C (a).C (bb).C (aab) , which is a 6- bit string: 10.01.11.
Introduction
There is a sliding window in the LZ77 algorithms. The
window consists of two parts: a search buffer and a lookahead buffer.
The search buffer contains: the portion of the text stream that has
recently been encoded --- the dictionary.
The look-ahead buffer contains: the text to be encoded next.
LZ78 Algorithms
Introduction
Limitations with LZ77:
If the distance between two repeated patterns is larger than the
size of the search buffer, the LZ77 algorithms cannot work
efficiently.
The fixed size of the both buffers implies that the matched string
cannot be longer than the sum of the sizes of the two buffers,
meaning another limitation on coding efficiency.
Increasing the sizes of the search buffer and the look-ahead
buffer seemingly will resolve the problems. A close look,
however, reveals that it also leads to increases in the number of
bits required to encode the offset and matched string length as
well as an increase in processing complexity.
Introduction
LZ78:
No use of the sliding window.
Use encoded text as a dictionary which, potentially, does not
have a fixed size.
Each time a pointer (token) is issued, the encoded string is
included in the dictionary.
Once a preset limit to the dictionary size has been reached,
either the dictionary is fixed for the future (if the coding
efficiency is good), or it is reset to zero, i.e., it must be restarted.
Instead of the triples used in the LZ77, only pairs are used in
the LZ78.
Specifically, only the position of the pointer to the matched
string and the symbol following the matched string need to be
encoded.
Decoding:
Since the decoder knows the rule applied in the encoding, it can
reconstruct the dictionary and decode the input text stream from
the received doubles.
Doubles
Encoded symbols
< 3, 1 >
cb
< 2, 3 >
ac
< 3, 2 >
ca
< 4, 3 >
cbc
< 2, 1 >
ab
< 3, 3 >
cc
10
< 1, 1 >
bb
11
< 5, 3 >
acc
LZW Algorithm
Both the LZ77 and LZ78 approaches, when published in
1977 and 1978, respectively, were theory-oriented.
The effective and practical improvement over the LZ78 in
[welch 1984] brought much attention to the LZ dictionary
coding techniques. The resulting algorithm is referred to
the LZW algorithm.
It removed the second item in the double (the index of the
symbol following the longest matched string) and hence, it
enhanced coding efficiency.
In other words, the LZW only sends the indexes of the
dictionary to the decoder.
LZW Algorithm
Example 6.4
Consider the following input text stream:
accbadaccbaccbacc. We see that the source
alphabet is S={a,b,c,d,}.
Encoding:
LZW Algorithm
Table 6.5 An example of the dictionary coding using the
LZW algorithm
Index
Entry
1
2
3
4
a
b
c
d
5
6
7
8
9
10
11
12
13
14
15
ac
cc
cb
ba
ad
da
acc
cba
accb
bac
cc
Input Smbols
Encoded Index
Initial dictionary
a
C
C
b
a
d
a,c
c,b
a,c,c
b,a,
c,c,
1
3
3
2
1
4
5
7
11
8
LZW Algorithm
Decoding:
Initially, the decoder has the same dictionary (the top four rows
in Table 6.5) as that in the encoder.
Once the first index 1 comes, the decoder decodes a symbol a.
The second index is 3, which indicates that the next symbol is c.
From the rule applied in encoding, the decoder knows further that
a new entry ac has been added to the dictionary with an index 5.
Exercises
1. Encode (i.e., compress) the following strings
using the LZ77 algorithm.
Window size : 5
ABBABCABBBBC
LZ77 - Example
Window size : 5
ABBABCABBBBC
NextSeq Code
A
B
BA
BC
ABB
BBC
(0,0,A)
(0,0,B)
(1,1,A)
(3,1,C)
(3,2,B)
(2,2,C)
Alternatively number of bits required to represent the integer part of the codeword
with index i is the number of significant bits required to represent the integer i 1
Codeword
index
Bits:
(0, A)
(0, B) (2, C) (3, A) (2, A) (4, A) (6, B)
1
2
3
4
5
6
7
(1 + 8) + (1 + 8) + (2 + 8) + (2 + 8) + (3 + 8) + (3 + 8) + (3 + 8) = 71 bits
Summary:
if(CW == 0)
output: currentCharacter
else
output: stringAtIndex CW + currentCharacter
Insert: current output in dictionary
Applications
The CCITT Recommendation V.42 bis is a data
compression standard used in modems that connect
computers with remote users via the GSTN. In the
compressed mode, the LZW algorithm is recommended for
data compression.
In image compression, the LZW finds its application as
well. Specifically, it is utilized in the graphic interchange
format (GIF) which was created to encode graphical
images. GIF is now also used to encode natural images,
though it is not very efficient in this regard. For more
information, readers are referred to [sayood 1996].
The LZW algorithm is also used in the Unix Compress
command.
Algorithms
MR (Modified READ (Relative Element Address Designate)
coding): Defined in CCITT Recommendation T.4 for
facsimile coding. It uses the 2-D RLC technique followed by
the modified Huffman coding technique.
MMR (Modified Modified READ coding): Defined in CCITT
Recommendation T.6. It is based on MR, but is modified to
maximize compression.
JBIG (Joint Bilevel Image experts Group coding): Defined in
CCITT Recommendation T.82. It uses an adaptive 2-D
coding model, followed by an adaptive arithmetic coding
technique.
Performance Comparison
The JBIG test image set was used to compare the
performance of the above-mentioned algorithms. The set
contains scanned business documents with different
densities, graphic images, digital halftones, and mixed
(document and halftone) images.
Note that digital halftones, also named (digital) halftone
images, are generated by using only binary devices.
Some small black units are imposed on a white background.
The units may assume different shapes: a circle, a square and so
on.
The more dense the black units in a spot of an image, the darker
the spot appears.
The digital halftoning method has been used for printing gray-level
images in newspapers and books.
Performance Comparison
For bilevel images excluding digital halftones, the
compression ratio achieved by these techniques ranges
from 3 to 100.
The compression ratio increases monotonically in the order
of the following standard algorithms: MH, MR, MMR, JBIG.
For digital halftones, MH, MR, and MMR result in data
expansion, while JBIG achieves compression ratios in the
range of 5 to 20.
This demonstrates that among the techniques, JBIG is the
only one suitable for the compression of digital halftones.
Algorithms
JPEG (Joint Photographic (image) Experts Group
coding): Defined in CCITT Recommendation T. 81.
For lossless coding (Lossless JPEG), it uses
differential coding technique. The predictive error is
encoded using either Huffman coding or adaptive
arithmetic coding techniques.
Performance Comparison
A set of color test images from the JPEG
standards committee was used for
performance comparison.
The luminance component (Y) is of resolution
720 576 pixels, while the chrominance
components (U and V) are of 360 576 pixels.
The compression ratios calculated are the
combined results for all the three components.
The following observations have been reported.
Performance Comparison
When quantized in 8 bits/pixel, the compression ratios vary
much less for multilevel images than for bilevel images,
and are roughly equal to 2.
When quantized with 5 bits/pixel down to 2 bits/pixel,
compared with the lossless JPEG, the JBIG achieves an
increasingly higher compression ratio, up to a maximum of
29%.
When quantized with 6 bits/pixel, JBIG and lossless JPEG
achieve similar compression ratios.
When quantized with 7 bits/pixel to 8 bits/pixel, the lossless
JPEG achieves a 2.4 % to 2.6 % higher compression ratio
than JBIG.