DCT Based Coding
DCT Based Coding
DR TANIA STATHAKI
READER (ASSOCIATE PROFFESOR) IN SIGNAL PROCESSING
IMPERIAL COLLEGE LONDON
Elements from Information Theory
𝐻 𝑆 = 𝑝𝑖 𝐼 𝑠𝑖 = − 𝑝𝑖 log 2 𝑝𝑖
𝑖=1 𝑖=1
• In Physics
what "disorder” above refers to, is really the number of different
microscopic states a system can be in, given that the system has a
particular fixed composition, volume, energy, pressure, and
temperature. By "microscopic states", we mean the exact states of
all the molecules making up the system.
𝐻 𝑆 ≤ 𝑙𝑎𝑣𝑔 < 𝐻 𝑠 + 𝛿
• We observe that for 𝛿 small enough, the average number of bits per
symbols converges to the entropy of the source. This is the best coding
we can achieve.
• The above is not realistic since the alphabet size increases too much
with 𝑁!
Examples of possible codes for a 4-symbol source
1/20
1/20
0.05 0.1
0.05
Properties of Huffman Codes
• 𝐻 𝑆 ≤ 𝑙𝑎𝑣𝑔 ≤ 𝐻 𝑆 + 1
• If 𝑝𝑚𝑎𝑥 < 0.5 then 𝑙𝑎𝑣𝑔 ≤ 𝐻 𝑆 + 𝑝𝑚𝑎𝑥
• If 𝑝𝑚𝑎𝑥 ≥ 0.5 then 𝑙𝑎𝑣𝑔 ≤ 𝐻 𝑆 + 𝑝𝑚𝑎𝑥 + 0.086
• 𝐻 𝑆 = 𝑙𝑎𝑣𝑔 if the probabilities of the symbols are of the form 2𝑘 , with 𝑘
a negative integer.
1
• For an 𝑁 −th extension of a DMS we have 𝐻 𝑆 ≤ 𝑙𝑎𝑣𝑔 ≤ 𝐻 𝑆 +
𝑁
• The complement of a Huffman code is also a valid Huffman code.
• A minimum variance Huffman code is obtained by placing the
combined letter in the sorted list as high as possible.
• The code efficiency is defined as 𝐻(𝑆)/𝑙𝑎𝑣𝑔
• The code redundancy is defined as 𝑙𝑎𝑣𝑔 − 𝐻(𝑆)
Huffman Decoding: Bit-Serial Decoding
• We repeat these steps until all of the input is consumed. Since the
codewords are not of the same length, the decoding bit rate is not the
same for all symbols. Hence, this scheme has a fixed input bit rate but a
variable output symbol rate.
Huffman Decoding: Lookup-Table-Based Decoding
• When we receive the bit stream for decoding we read the first 𝐿 bits.
• By checking the Lookup Table we find the symbol 𝑠𝑖 which has the read
𝐿-bit word as one if its possible codewords.
• When we find this symbol we know that the “true” codeword for that
symbol is formed by the first 𝑙𝑖 bits only of the read 𝐿-bit word.
• The first 𝑙𝑖 bits are discarded from the buffer.
• The next 𝑙𝑖 bits are appended to the buffer so that the next 𝐿-bit word for
investigation is formed.
• We carry on this procedure until the entire bit stream is examined.
Example of Huffman coding with poor performance
• The magnitude is expressed in binary form with the Most Significant Bit
(MSB) always 1 if it is positive.
• If the residual is negative, then the code for the magnitude is the one's
complement of its absolute value.
𝑎 = 100,
𝑏 = 191 𝑐 𝑏
𝑐 = 100
𝑥 = 180 𝑎 𝑥
𝑎+𝑏
𝑦= = 145
2
𝑟 = 𝑦 − 𝑥 = −35
• Suppose Huffman code for six is 1110 then is coded by the 10 −bit
codeword 1110011100.
• Regardless of the compression method that being used, given the level
of image loss (or distortion), there is always a bound on the
minimum bit rate of the compressed bit stream.
• The analysis that relates signal distortion and minimum bit rate falls within
the so called Rate-Distortion theory.
Lossy Compression
• The input block (labeled original) is taken from a low activity region; that
is, there are very small differences among pixel values in that area.
DCT Based Coding Examples
• Observe that 𝑋 ≠ 𝑋.
DCT Based Coding Example – High activity region
• The input block (labeled original) is taken from a high activity region;
that is, there are essential differences among pixel values in that area.
DCT Based Coding Example – High activity region
Huffman Coding of DC Coefficients
• From this pair of values, only the first (size) is Huffman coded.
Example
• size= 8.
• After quantization, most of the AC coefficients will be zero; thus, only the
nonzero AC coefficients need to be coded.
• From this pair of values, only the first (run/size) is Huffman coded.
• The pair (6/5) is Huffman coded, and the 5 −bit value of −18 is
appended to that code.
• If the Huffman codeword for (6/5) is 1101, then the codeword for 6 zeros
followed by −18 is 110101101.
Special cases
• If after a nonzero AC value all the remaining coefficients are zero, then
the special symbol 0/0 denotes an end of block (EOB).
Conventional and zig-zag ordering
• Assume that the values of a quantized DCT matrix are given by:
• Values for the DC differentials range between −2047 and 2047, and for
the AC coefficients range between −1023 and 1023.
• By Huffman coding only the size or the (run/size) information, the size of
these tables is reduced to 12 and 162 entries, respectively!