3

Question 1: An image is coded with 3 bits per pixel and the probabilities associated with each of the grey levels are P = [0.2 0.15 0.13 0.13 0.12 0.10 0.09 0.08].

(i) Using Huffman coding, derive the variable length codes for representing this image.

(ii) Compute the expected length of the coding scheme from (i) and the corresponding compression ratio.

Hi guys. I have spent nearly two hours poring over all the research results that I could get from Google but I'm still unable to find a solution for the question mentioned above.

Can you guys help me or give me some hints of how to solve this question please? Thanks in advance!

1 Answers1

1

There are several straightforward implementations of Huffman coding at this MSE link. Brian M. Scott explains the details of constructing such a code, I highly recommend that you read his remarks. Using the implementation that was posted there I get the following Huffman code for your data:

$ ./huffman-tree.pl 0.2 0.15 0.13 0.13 0.12 0.10 0.09 0.08
+-0--+-0--X001 0.200000 00
|    |
|    +-1--+-0--X006 0.100000 010
|         |
|         +-1--X005 0.120000 011
|
+-1--+-0--+-0--X003 0.130000 100
     |    |
     |    +-1--X004 0.130000 101
     |
     +-1--+-0--X002 0.150000 110
          |
          +-1--+-0--X008 0.080000 1110
               |
               +-1--X007 0.090000 1111

The expected length can be obtained by summing over the product of the number of bits times the probability and gives $$ 0.09*4+0.08*4+0.15*3+0.13*3+0.13*3+0.12*3+0.1*3+0.2*2 = 2.97$$

Marko Riedel
  • 61,317