Reputation: 1
I am writing a program in java in which takes the input from the user as to how many times a given image needs to be compressed, based on which it should compress the image.
Initially we convert image into pixel matrix, find the probabilities of each pixel appearing in that matrix and apply huffman code to obtain code in the form of 0's n 1's.
Now if we try to compress it 2nd time we will have only 2 probabilities i.e of 0 n 1.Hence we cant apply the huffman code now.
so what can be done in this situation?
Upvotes: 0
Views: 448
Reputation: 112627
You could apply an arithmetic code on two symbols. If, for example, there are many more zeros than ones then an arithmetic code would reduce the total number of bits by encoding the zeros each with less than one bit, and the ones with more than one bit. (This is done by considering the output bits to be a binary fraction, and each new input bit reducing the range of the binary fraction.)
However you will find after compressing using Huffman codes, that you will have very close to the same number of ones as zeros. It will not be compressible this way. Or really any way.
Upvotes: 2