Asked by FIR
on 25 Dec 2012

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

*No products are associated with this question.*

Answer by Walter Roberson
on 25 Dec 2012

Remember, comp is representing binary, and so is 1 bit per element, whereas your original data is at least 8 bits per element.

Show 3 older comments

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

walter can you please help me in giving the code for restoring image content

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments