MATLAB Answers


how can i do huffman encoding in image compression

Asked by omar
on 8 Dec 2012

hi,i am doing lossy image compression using discrete cosine transform i had done all the steps of the compression(dct then quantization then zigzag scan) now i have a vector and i want to do huffman encoding i know that the code as follows

 [dict,avglen] = huffmandict(symbols,p) 
 comp = huffmanenco(sig,dict)

i am asking now how to get the symbol and p(probability) from the large vector that i have to do the encoding




1 Answer

Answer by Walter Roberson
on 8 Dec 2012
 Accepted answer

If your vector is uint8() then one way of doing it is

symbols = unique(YourVector(:));
counts = hist(YourVector(:), symbols);
p = double(counts) ./ sum(counts);

This is not the only way.


Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!