Decompressing an image with a Huffman tree?

First, an image was compressed using run-length encoding, then a Huffman tree was created for the run-lengths (image below). The Huffman tree is included in the image header and looks like this:

The binary sequence consists of alternating run length and color. According to the task, I was supposed to draw an image, which is shown above. I tried several times, but I could only determine the width (7), height (5), and color depth (3). How do I do it?

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
4 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
aperfect10
7 months ago

In the coded image data there is always alternately a Huffman code which encodes the running length, and a color whose value is three bits long (color depth 3 bit).

So let’s see what Huffman code is at the beginning. For this we begin in the root of the tree. When we read a zero, we go to the left child node when we read one, to the right.

The first bit is a zero, so we go to the left and land at a blade node, so the code is over here. The running length 1 is stored in the blade node. We read the next 3 bits (color depth), which are 000. So we color the next 1 pixels with the color 000.

And now the whole thing from the front: we start again at the root. We read one and go right. We read another one and go right. We read again a 1 and arrived at a blade node that stores the running length 20 . We read the color: 001. So we color the next 20 pixels with the color 001.

Do you have the rest?

aperfect10
7 months ago
Reply to  Anonymous573

That’s right. Thanks for the star!