RTUComputer ScienceYr 2023 · Sem 62023

Q16Digital Image Processing

Question

4 marks

Explain the Huffman coding technique for image compression with an example.

Answer

Huffman coding assigns shorter binary codewords to more probable gray levels by iteratively merging the two lowest-probability nodes into a binary tree, achieving optimal prefix-free lossless compression.

Huffman coding is a lossless, variable-length coding technique that removes coding redundancy by assigning shorter codewords to intensity levels that occur more frequently, and longer codewords to rare ones, while guaranteeing that no codeword is a prefix of another (instantaneously decodable).

Algorithm

  • Compute the probability (relative frequency) of each gray level from the image histogram.
  • List the symbols in decreasing order of probability as leaf nodes.
  • Repeatedly combine the two nodes with the lowest probabilities into a new node whose probability is their sum, until a single root node remains, forming a binary tree.
  • Assign 0 and 1 to the two branches at every merge point; the codeword for each symbol is the sequence of bits read from the root to that leaf.

Worked Example

Consider four gray levels with probabilities . Merging the two lowest () gives a node of probability 0.3; merging that with (0.3) gives 0.6; merging with (0.4) gives the root (1.0). Backtracking assigns codes: (1 bit), , , (each 2-3 bits), giving an average length of bits/pixel versus 2 bits/pixel for fixed-length coding, close to the entropy of about 1.85 bits, demonstrating near-optimal compression.

In real images, the Huffman table itself must be transmitted alongside the compressed data (or a standard table, as in baseline JPEG, must be agreed upon in advance), since the decoder needs the same code assignments to reconstruct the original symbols. This overhead is negligible for large images but can be significant for small images with many distinct symbols. Huffman coding is also the entropy-coding stage that follows quantization in JPEG compression, where it losslessly compresses the already-quantized DCT coefficients, showing how Huffman coding functions as a general-purpose final stage layered on top of other, lossy compression techniques rather than a compression method used in isolation.

Back to Paper