Size increases after encoding

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

Réponses (1)

Walter Roberson
Walter Roberson le 25 Déc 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 commentaires

FIR
FIR le 26 Déc 2012
ok walter then how to calculate compression ration and display compressed image
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
FIR le 26 Déc 2012
walter i could not get what is OVER in your code,plz can u tell how to calculate it for my above code
Walter Roberson
Walter Roberson le 26 Déc 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
FIR le 26 Déc 2012
walter can you please help me in giving the code for restoring image content

Connectez-vous pour commenter.

Catégories

En savoir plus sur Large Files and Big Data dans Centre d'aide et File Exchange

Tags

Question posée :

FIR
le 25 Déc 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by