Lecture 10-Print
Lecture 10-Print
Dictionary Techniques
• In many applications, the output of the source consists of recurring
patterns e.g. text source in which certain patterns or words recur
constantly.
• Also, there are certain patterns that simply do not occur, or if they do,
occur with great rarity e.g. we can be reasonably sure that the word
Limpopo1 occurs in a very small fraction of the text sources in
existence.
• A very reasonable approach to encoding such sources is to keep a list,
or dictionary, of frequently occurring patterns.
• When these patterns appear in the source output, they are encoded
with a reference to the dictionary.
• If the pattern does not appear in the dictionary, then it can be
encoded using some other, less efficient, method.
• For this technique to be effective, the class of frequently occurring
patterns, and hence the size of the dictionary, must be much smaller
than the number of all possible patterns.
• Suppose we have a particular text that consists of
four-character words, three characters from the
26 lowercase letters of the English alphabet
followed by a punctuation mark of total 32
alphabets.
• If we were to encode the text source one
character at a time, treating each character as an
equally likely event, we would need 5 bits per
character.
• Treating all 324 ( = 220 = 1,048,576) four-character
patterns as equally likely, we have a code that
assigns 20 bits to each four-character pattern.
• Let us now put the 256 most likely four-character
patterns into a dictionary.
• The transmission scheme works as follows:
– Whenever we want to send a pattern that exists in the
dictionary, we will send a 1-bit flag, say, a 0, followed
by an 8-bit index corresponding to the entry in the
dictionary.
– If the pattern is not in the dictionary, we will send a 1
followed by the 20-bit encoding of the pattern.
– If the pattern we encounter is not in the dictionary,
we will actually use more bits than in the original
scheme, 21 instead of 20.
– But if it is in the dictionary, we will send only 9 bits.
– If the probability of encountering a pattern from the
dictionary is p, then the average number of bits per
pattern R is given by
• For scheme to be useful, R should have a value
less than 20.
• This happens when p ≥ 0.084.
• This does not seem like a very large number.
• For better performance, p should be as large
as possible.
Static Dictionary
• Choosing a static dictionary technique is most
appropriate when considerable prior
knowledge about the source is available.
• This technique is especially suitable for use in
specific applications.
• In such applications, it is highly efficient to
design a compression scheme based on a
static dictionary containing the recurring
patterns.
Adaptive Dictionary-The LZ77 Approach
• In this approach, the dictionary is simply a portion
of the previously encoded sequence.
• The encoder examines the input sequence through
a sliding window
• The window consists of two parts, a search buffer
that contains a portion of the recently encoded
sequence, and a look-ahead buffer that contains the
next portion of the sequence to be encoded.
• To encode the sequence in the look-ahead buffer,
the encoder moves a search pointer back through
the search buffer until it encounters a match to
the first symbol in the look-ahead buffer.
• The distance of the pointer from the look-ahead
buffer is called the offset.
• The encoder then examines the symbols following
the symbol at the pointer location to see if they
match consecutive symbols in the look-ahead
buffer.
• The number of consecutive symbols in the search
buffer that match consecutive symbols in the look
-ahead buffer, starting with the first symbol, is
called the length of the match.
• The encoder searches the search buffer for the
longest match.
• Once the longest match has been found, the encoder encodes it with
a triple <o, l, c>, where o is the offset, l is the length of the match,
and c is the codeword corresponding to the symbol in the look-ahead
buffer that follows the match.
• The pointer in the example below is pointing to the beginning of the
longest match.
• The offset o in this case is 7, the length of the match l is 4, and the
symbol in the look-ahead buffer following the match is r.
• The reason for sending the third element in the triple is to take care
of the situation where no match for the symbol in the look-ahead
buffer can be found in the search buffer.
• In this case, the offset and match-length values are set to 0, and the
third element of the triple is the code for the symbol itself.
• If the size of the search buffer is S, the size of
the window (search and look-ahead buffers) is
W, and the size of the source alphabet is A,
then the number of bits needed to code the
triple using fixed-length codes is
LZ77: Example
• Suppose the sequence to be encoded is
38
Old JPEG-LS
39
CALIC
• CALIC: Context Adaptive Lossless Image Compression
• Uses both context and prediction of the pixel values
• Context: to obtain the distribution of the symbol being
encoded
• Prediction: use previous values of the sequence to obtain a
prediction of the value of the symbol being encoded
• In an image, a given pixel generally has a value close to
one of its neighbors
• Which neighbor has the closest value depends on the local
structure of the image
40
CALIC
• We can get an idea of what kinds of structure may
or may not be in the neighborhood of X by NN N NE
computing NW
N
NE
W X
WW
41
CALIC: Initial Prediction
CALIC
• We refine this initial prediction using information about the
inter-relationship of the pixels in the neighborhood
• We quantify the information about the neighborhood by
first forming the vector [N, W, NW, NE, NN, WW, 2N-NN,
2W -WW]
• We then compare each component of this vector with our
initial prediction
• If the value of the component is less than the prediction, we
replace the value with a one, otherwise we replace it with a
zero.
43
CALIC
• We also compute where is
the predicted value of N.
• The range of values for is divided into 4 intervals (the
combination of two consecutive interval in 8 context intervals
explained in the next slide)
• These 4 intervals along with 144 possibilities for the vector
described above, 144x4=576 contexts for X.
• Based on the context for the pixel, we find a value named
offset and add it to the initial prediction of X.
• The residual (difference between pixel value and the
prediction) has to be encoded using its context.
44
CALIC
• The residual is mapped to [0,M-1] interval (original pixel
values are assumed to be between 0 and M-1.
• Context for encoding of residual is based on the range that
fall in:
context 1
context 2
context 8
45
CALIC: Encoding
• If a pixel takes on
values between 0
and M −1, then given
a predicted value ˆX ,
the difference X− ˆX
will take on values in
the range −ˆX to M
−1− ˆX .
• We can use this fact
to map the difference
values into the range
0-M −1, using the
following mapping:
JPEG-LS
• The new JPEG-LS is based on an algorithm named LOCO-
1 developed by HP (similar to CALIC)
• It has both a lossless and lossy (called near lossless) modes
• Initial prediction:
47
JPEG-LS
• Context:
D1=NE-N D2=N-NW D3=NW-W
• D1, D2 and D3 are mapped to Q1, Q2 and
Q3:
48
JPEG-LS
• Q1 and Q2 and Q3 define a context vector Q=(Q1, Q2 ,
Q3)
• Given 9 different values for each component, the context
vector can have 9x9x9=729 possible values
• The number of contexts is reduced by replacing any
context vector Q whose fist nonzero element is negative
with –Q
• Whenever this happens a variable SIGN is set to -1,
otherwise it is set to 1
• This reduces the number of context to 365
• Q is then mapped to a number between 0 and 364.
• This number is used to find a correction value c[Q]
• c[Q] is multiplied by SIGN and added to initial prediction
error
49
JPEG-LS
• The prediction error rn is mapped into an interval that is the
same size as the range occupied by the original pixel
values