Considering image compression, is Run length encoding always better than Huffman coding?
-
04-06-2021 - |
Question
We found out that run length is much better than huffman coding (JAVA) considering compression ratio. Is it true for all cases?
Solution
Of course not. Consider ABABABAB
, it will compress better with huffman than run-length encoding.
Run length will only work for data that have repeated values; that's not guaranteed in images.
OTHER TIPS
RLE generally works well for things like charts and graphs that have large areas of identical colors.
It tends to work poorly (often causes expansion) for things like photographs that almost always exhibit at least minor differences between pixels, even in areas that look like a solid color.
Although the same general idea tends to apply to Huffman as well, it tends to work better across a wider variety of inputs. In theory it can cause expansion as well, but about the only times I've seen that happen was trying to use it on data that was already compressed.