Image Processing (RCS082) Unit V Huffman Coding
Image Processing (RCS082) Unit V Huffman Coding
Unit V
Huffman Coding
Prepared By:
Dr. Suveg Moudgil
Associate Professor, CSE Deptt
IMS Engineering College, Ghaziabad
DR. A. P. J. ABDUL KALAM TECHNICAL UNIVERSITY, Uttar Pradesh
Huffman Coding
• Huffman coding is named after David A. Huffman, who developed the code in
1952 at M.I.T, USA.
• It is a lossless data compression technique.
• It is a variable length coding technique.
• It assigns few bits code for symbols/intensity values with high probability of
occurrence and vice versa.
• In this way, no. of bits used to store the message/image is reduced.
• It eliminates coding redundancy.
Huffman Coding
• It is based on greedy approach which considers frequency/probability of
alphabets for generating codes.
• No code is prefix of another code due to which a sequence of code can be
unambiguously decoded to characters.
• The algorithm is based on a binary-tree frequency-sorting method that allows to
encode any message sequence into shorter encoded messages and a method to
reassemble into the original message without losing any data.
• When applying Huffman encoding technique on an Image, the source symbols
can be the pixel intensities of the Image.
• Two Steps of Huffman Coding
a) Source reduction
b) Code assignment
Huffman Coding
First Step : Source reduction
• It create a series of source reductions by ordering the probabilities of the
symbols under consideration.
• Combine the lowest probability symbols into a single symbol that replaces them
in the next source reduction.
• At the far left, a hypothetical set of source symbols and their probabilities are
ordered from top to bottom in terms of decreasing probability values.
• To form the first source reduction, the bottom two probabilities, 0.06 and 0.04
are combined to form a “compound symbol” with probability 0.1.
• This compound symbol and its associated probability are placed in the first source
reduction column so that the probabilities of the reduced source are also ordered
from the most to the least probable.
• This process is then repeated until a reduced source with two symbols (at the far
right) is reached.
Huffman Coding
Huffman Coding
Second Step : Code assignment
• The second step in Huffman’s procedure is to code each reduced
source, starting with the smallest source and working back to the
original source.
• The minimal length binary code for a two-symbol source is 0 and 1.
• These codes are assigned to the two symbols on the right (the
assignment is arbitrary; reversing the order of the 0 and 1 would work
just as well).
• As the reduced source symbol with probability 0.6 was generated by
combining two symbols in the reduced source to its left, the 0 used to
code it is now assigned to both of these symbols, and a 0 and 1 are
arbitrarily appended to each to distinguish them from each other.
Huffman Coding
Huffman Coding
• This operation is then repeated for each reduced source until the
original source is reached.
• The final code appears at the far left.
• The average length of this code is calculated by the sum of product of
probability and no. of bits for symbols.
Lavg = (0.4)(1) + (0.3)(2) + (0.1)(.3) + (0.1)(4) + (0.06)(5) + (0.04)(5)
= 2.2 bits/symbol.
Huffman Coding
Huffman Decoding :
• Any string of Huffman encoded symbols can be decoded by examining the
individual symbols of the string in a left-to-right manner.
• Decoding is done by scanning the Huffman encoded message from left to right
looking for the Huffman encoded symbol and replacing it with original symbol.
• For the binary code obtained in table, a left-to-right scan of the encoded string
010100111100
• reveals that the first valid code word is 01010, which is the code for symbol a3.
• The next valid code is 011, which corresponds to symbol a1.
• Repeating the same process decoded message for the above string is.
a3 a1 a2 a2 a6
Huffman Coding
• It is also called a block code because each source symbol is mapped into a fixed
sequence of code symbols.
• It is uniquely decodable because any string of code symbols can be decoded in
only one way.
For Any Query/Doubt You can mail at
[email protected]
Thank You