-1

So, I have been breaking my head over huffman coding compression for "IMAGES".

I know the working of huffman and am able to implement on text, however, I do not understand how do I proceed further with images.

I have a grayscale image, which I converted into binary string i.e 1's and 0's now I can perform huffman coding on the string, but how do I compress the image?

can some one please help me with steps?

Say convert image into bytearray and then into binary string and perform huffman coding and then convert back to byte and into image, but I dont know how do I proceed with that.

All over internet, I can find huffman coding on text and they are making a huffman tree out of that, but I do not want a tree, I want to compress image. :(

Any help related to algorithm would be highly appreciated.

Thanks (Let me know, if you need more info)

Polynomial Proton
  • 5,020
  • 20
  • 37
  • Do you have code to go with this? What have you tried so far and what problems are you running into specifically? – Philip Liberato Dec 02 '13 at 04:13
  • So, I converted image into `byte array` and then that into `binary string` so I have the image data as 0's and 1's and I'm stuck. I'm not sure how to perform compression on the binary string and convert it back to image – Polynomial Proton Dec 02 '13 at 04:16
  • So you've compressed the file, you're asking how to decode it then? – Philip Liberato Dec 02 '13 at 04:18
  • I have successfully converted the file into a binary string until now, its not compressed. I want to learn, how to compress the binary string that I have for e.g. 1111000110 and then convert it back to an image. PS: I'm not sure if I'm doing it right by converting image into Binary String – Polynomial Proton Dec 02 '13 at 04:29
  • It would really be helpful if you could add the code you have right now to your post. The method I've used in the past for huffman encoding involved creating a binary heap to represent the frequency of each respective value. This way the binary code would be the pattern used to traverse the heap and find the appropriate value. – Philip Liberato Dec 02 '13 at 04:36

1 Answers1

0

How many bits per pixel? I'm guessing eight. Just put each pixel in a byte, and then compress as you have already compressed text using Huffman coding, where the text is also just a series of bytes.

This won't give very good compression, unless there are large swaths of identical pixels. The next step to improve that is to do difference coding. Replace each pixel (except for the first one) with the difference of it and the last pixel. Now if the image is relatively smooth, you should get much better compression.

You can then try improved predictors. See the PNG filters, where the above filter is called "sub".

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • Each pixel has a hex value of 8 bits in grey scale. After applying Huffman encoding, how do I save the new array of values? Because if we take integer values, the values will be small, but still each of them will take 8 bits isn't it? – Bugs Buggy Dec 29 '17 at 16:44