Image Compression using Huffman Coding
7
3
3
3
3
3
3
3
1
1
9
9
5
6
9
9
To build the Huffman tree, keep taking the two smallest-weight subtrees and merge them. To code a pixel, trace the path from the root to that leaf, writing a 0 whenever going left and 1 whenever going right.
Frequency
table:
1: 2
3: 7
5: 1
6: 1
7: 1
9: 4
Sorted
table:
5: 1
6: 1
7: 1
1: 2
9: 4
3: 7
Huffman Tree:
5
6
7
2
3
1
5
9
9
3
16
1
1
1
2
4
7
Code
3: 1
9: 01
1: 001
5: 00000
6: 00001
7: 0001
Previous slide
Next slide
Back to first slide
View graphic version