Error using huffman code

I get error
Error using ==> huffmandict at 72
The symbol input must be a vector
Error in ==> Untitled3 at 5
[dict,avglen]=huffmandict(symbols,p)
wen using the code
A=imread('lena.jpg');
A=rgb2gray(A);
[symbols,p]=hist(A,double(unique(A)));
p=p/sum(p)
[dict,avglen]=huffmandict(symbols,p)
comp=huffmanenco(A,dict)
please help

Respuestas (1)

Walter Roberson
Walter Roberson el 11 de Dic. de 2012

1 voto

Remember that hist() applied to an array (rather than a vector) histograms by column. This behavior is not documented, though: what is documented is that you must hist() a vector.

12 comentarios

kash
kash el 11 de Dic. de 2012
id i use A(:),will it be correct
kash
kash el 11 de Dic. de 2012
if i use A(:) i get error as
Error using ==> huffmandict at 174 Source symbols repeat
Error in ==> Untitled3 at 6 [dict,avglen]=huffmandict(symbols,p)
Walter Roberson
Walter Roberson el 11 de Dic. de 2012
Yes, but your problem with symbols needing to be a vector is solved.
I am not surprised that your symbols repeat. I would rather expect that when you use counts as the symbols.
kash
kash el 11 de Dic. de 2012
can u please correct the code above
Walter Roberson
Walter Roberson el 11 de Dic. de 2012
You should be passing a vector of symbols at that point. And the p vector should be the vector of the probabilities of each symbol.
I cannot correct the code for you because you need to decide which symbols you are going to use. Symbols can be intended to represent different numbers of bits. For example if you often had 10 consecutive 0 bits, then it might be worth creating a symbol for that.
kash
kash el 11 de Dic. de 2012
ok walter is there any solution for encoding using huffman encoding
kash
kash el 11 de Dic. de 2012
i used a code in
http://www.mathworks.in/matlabcentral/answers/2158
but i get error
In an assignment A(I) = B, the number of elements in B and
I must be the same.
Error in ==> Untitled4567 at 18
count(j) = c;
Walter Roberson
Walter Roberson el 11 de Dic. de 2012
The "solution" is for you to decide which symbols you are going to use, and calculate the appropriate probabilities. Just like I could tell you that there is a special on "Liver and Brussel Sprouts", but you need to decide for yourself what you want to order off the menu.
kash
kash el 11 de Dic. de 2012
Acutually walter its image copmresiion,i have performed dwt2,want to compress cA,cH bands
Walter Roberson
Walter Roberson el 11 de Dic. de 2012
So you are indicating to me that you want to have exactly two symbols, 'cA' and 'cH' ?
huffmandict({'cA', 'cH'}, p)
kash
kash el 11 de Dic. de 2012
i get same eerror
Error using ==> huffmandict at 97 The symbol and probability vector must have the same length
Error in ==> Untitled28 at 13 [dict,avglen]=huffmandict({'cA', 'cH'}, p);
Walter Roberson
Walter Roberson el 11 de Dic. de 2012
I think you should go back and study the theory about what a "symbol" is for the purposes of huffman encoding.

Iniciar sesión para comentar.

Categorías

Más información sobre Large Files and Big Data en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 11 de Dic. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by