Size increases after encoding
Show older comments
Finally i got through the problem in huffman encoding,but the size after encoding increases,please help
A=imread('imagcp.bmp');
A=A(:);
YourVector=double(A);
symbols = unique(YourVector(:));
counts = hist(YourVector(:), symbols);
p = double(counts) ./ sum(counts)
[dict,avglen]=huffmandict(symbols,p);
comp=huffmanenco(A,dict);
numel(comp)
ans =
167343
>> numel(A)
ans =
65536
Answers (1)
Walter Roberson
on 25 Dec 2012
0 votes
Remember, comp is representing binary, and so is 1 bit per element, whereas your original data is at least 8 bits per element.
6 Comments
FIR
on 26 Dec 2012
Walter Roberson
on 26 Dec 2012
First calculate the amount of storage required to represent the list of symbols and corresponding bit codes (you should not include any space for the probabilities.) This is the dictionary overhead, which I will call OVER. OVER should be in bytes.
Then,
compression_ratio = (numel(comp) + OVER * 8) ./ (numel(A) * 8)
FIR
on 26 Dec 2012
Walter Roberson
on 26 Dec 2012
You cannot reconstruct the compressed image unless you have the table of prefixes and corresponding symbols. So when you save the compressed image, you need to also save the table of prefixes and symbols, and you need to include the size of that saved table when you are calculating the storage space required for the compressed image. The variable I named as "OVER" is the size of that saved table, in bytes.
To calculate the size of that table, you need to figure out the minimum amount of disk storage that you can use to save the table. How to store the table efficiently is going to require some thought on your part.
I would also recommend that you store the dimensions and number of bit planes of the image; if you do not know those, then although you might be able to restore the image contents, you would not be able to figure out the shape the image should be. The size required to store the dimensions and bit planes should be included in the value of OVER.
FIR
on 26 Dec 2012
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!