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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

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

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.

## 0 Comments