我在使用huffman编码和解码的jpeg压缩工作,我不想使用内置函数,如(huffmandict,huffmanencdo,huffmandeco)而不是这个内置函数,我可以使用什么编码。这里编码的是游程长度编码
HEAD=0;
POS=0;
S_=size(encoded);
for i=1:S_(2)
if (POS~=0)
S=size(HEAD); F=0;
k=1;
while (F==0 && k<=S(2))
if (encoded(i)==HEAD(k)) F=1; end;
k=k+1;
end;
else F=0;
end;
if (F==0)
POS=POS+1;
HEAD(POS)=encoded(i);
end;
end;
%Compute probability for symbols%
S_H=size(HEAD);
Count(1:S_H(2))=0;
for i=1:S_H(2)
for j=1:S_(2)
if (encoded(j)==HEAD(i))
Count(i)=Count(i)+1;
end;
end;
end;
Count=Count./S_(2);
%Sort accordng to maximum number%
for i=1:S_H(2)-1
for j=i+1:S_H(2)
if (Count(j)>Count(i))
T1=Count(i); Count(i)=Count(j); Count(j)=T1;
T1=HEAD(i); HEAD(i)=HEAD(j); HEAD(j)=T1;
end;
end;
end;
[dict,avglen] = huffmandict(HEAD,Count); % Create dictionary.
comp = huffmanenco(encoded,dict); % Encode the data.
end
end
decode=huffmandeco(comp,dict);