![](http://images-20200215.ebookreading.net/23/1/1/9781482247336/9781482247336__a-computational-introduction__9781482247336__bg1bf.png)
Image Coding and Compression 429
Exercises
1. Construct a Huffman code f or each of the probability tables given:
Grayscale
0 1 2 3 4 5 6 7
Probability (a) .07 .11 .08 .04 .5 .05 .06 .09
(b)
.13 .12 .13 .13 .12 .12 .12 .13
(c)
.09 .13 .15 .1 .14 .12 .11 .16
In each case, determine the average bits/pixel given by your code.
2. From your results of the previous question, what do you think are the conditions of
the probability distribution which give rise to a high compression rate using Huffman
coding?
3. Download a Huffman code program (or write one of your own), and test it on the
examples given.
Then try it on different images. What sort of compres sion rates do you obtain? What
sorts of images seem to have the best compression rates?
Note: Both Octave and MATLAB have Huffman routines in their Communications
toolboxes; a Python routine can be found at
http://rosettacode.org/wiki/Huffman
_
coding#Python
.
4. Encode each of the following binary images using run length encoding:
(a)
1 0 0 1 1 1
0 1 0 1 1 1
1 0 0 1 1 1
0 1 1 1 0 1
1 0 1 0 1 1
0 1 1 1 1 0
(b)
1 0 1 0 0 0
0 0 1 1 0 1
1 1 0 0 0 0
0 0 0 0 1 1
1 1 1 1 0 0
1 1 1 0 0 0
5. Using run length encoding, encode each of the following 4-bit images:
(a)
1 1 3 3 1 1
1 7 10 10 7 1
6 13 15 15 13 6
6 13 15 15 13 6
1 7 10 10 7 1
1 1 3 3 1 1
(b)
0 0 0 6 12 12 1 9
1 1 1 6 12 11 9 13
2 2 2 6 11 9 13 13
8 10 15 15 7 5 5 5
14 8 10 15 7 4 4 4
14 14 5 10 7 3 3 3
6. Check your answers to the previous two questions with the techniques discussed in this
chapter. You can isolate the bit planes by using the technique discussed in Section 3.3.
7. Encode the preceding images using the 4-bit Gray code, and apply run length encoding
to the bit planes of the result.
Compare the results obtained using Gray codes, and standard binary codes.
8. Write a func tion for restoring a binary image from a run length code. Test it on the
images and codes from the previous questions.
9. The following are the run-length encodings for a 4 ×4 4-bit image from most to least
important bit-planes: