ardavis
ardavis

Reputation: 9895

Shannon-Fano Encoding with Images

I have been assigned to encode and decode images using the Shannon-Fano technique. I'll be writing in Matlab.

I am able to access the data array of the image in Matlab, so I can see the value of each pixel. I understand the basics of using the Shannon-Fano technique for text, but not images.

Would I need to loop through each pixel and count the number of occurrences for each pixel value?

Thanks for pointing me in the right direction.

Upvotes: 1

Views: 1636

Answers (2)

Robert Kolner
Robert Kolner

Reputation: 1572

Imagine that this picture is actually a text and every pixel is a letter. If you have 8-bit picture, then you might have 256 different letters. How would you encode a text with 256 different letters? Yes, exactly the same way you encode text with 26 different letters, or 5 different letters, for that matter.

What you want to do in each case, is to make a histogram, sort it, based on frequency of each value, and then encode the image/text. So yes, you have to count each pixel value. Good luck!

Upvotes: 4

Jems
Jems

Reputation: 11620

Yes, since you want the frequencies of each possible pixel value. You could also try taking a smaller sample and estimating the frequencies if you need to be quick. The simplest method here would be to just make an array of ints that has the same size as the number of possible values. Whereas for text the symbols would be words or letters, for the image the symbols are the values of each pixel.

Upvotes: 1

Related Questions