Search code examples
pythonimagecompressionhuffman-codeimage-compression

Are there any modern image formats that use plain Huffman coding?


I have some images that are very noisy, but the values are all in a narrow range of near-zero uint8 values. I think Huffman coding might be optimal for compressing them, since there is a lot of bit-wise redundancy but not a lot of sequence redundancy. However I can't find any image formats that use the plain bit-wise algorithm without encoding sequences (like PNG or Deflate do). The closest I found was an obsolete Unix command line tool called "pack". Is there an image format that uses plain old Huffman compression?

Bonus points if there's a Python encoder for it.

noise image and histogram


Solution

  • Yes, the PNG image format. You can request that zlib use the Z_HUFFMAN_ONLY strategy for a PNG image. You can also try Z_FILTERED which is not Huffman-only, but is tuned for the filtered image data in PNG files, and does less string matching. Try those along with Z_DEFAULT_STRATEGY on your images, to see how they compare. All of them will take advantage of the small range of your pixel values with Huffman coding.