matlab 图片霍夫曼编码,用MATLAB仿真霍夫曼编码在jpg图像压缩中的应用

这是我从网上下载的一个huffman编码和解码的程序,哪位高手帮我解释一下是什么意思啊,我是个新手,看不懂代码,谢谢啊

%编码

clear;

f0=imread('lena.jpg');

subplot(121)

imshow(uint8(f0));

xlabel('\fontsize{16}原始图像');

f=abs(f0/4)-10;

[M,N]=size(f);

p=zeros(1,61);

for t=1:61

count=0;

for i=1:M

for j=1:N

if f(i,j)==t-1

count=count+1;

end

end

end

p(t)=count;p0=p;

end

core=cell(61,1);

sign=zeros(61);

for hh=1:60

re=M*N;

for t=1:61

if (p(t)0)

re=p(t);

end

end

t=1;

while (p(t)~=re)&(t<61)

t=t+1;

end

if sign(t,1)==0

core{t}='0';

else

core{t}=['0',core{t}];

i=1;

while (sign(t,i)~=0)&(i<61)

core{sign(t,i)}=['0',core{sign(t,i)}];

i=i+1;

end

end

p(t)=0;

cou=t;

re1=M*N;

for t=1:61

if (p(t)0)

re1=p(t);

end

end

t=1;

while (p(t)~=re1)&(t<61)

t=t+1;

end

if sign(t,1)==0

core{t}='1';

else

core{t}=['1',core{t}];

i=1;

while (sign(t,i)~=0)&(i<61)

core{sign(t,i)}=['1',core{sign(t,i)}];

i=i+1;

end

end

p(t)=p(t)+re;

cou1=t;

i=1;

while (sign(t,i)~=0)&(i<61)

i=i+1;

end

sign(t,i)=cou;

i=i+1;

j=1;

while (sign(cou,j)~=0)&(j<61)

sign(t,i)=sign(cou,j);

i=i+1;

j=j+1;

end

end

fc=cell(M,N);

for i=1:M

for j=1:N

if f(i,j)<61

fc{i,j}=core{f(i,j)+1};

else

fc{i,j}='0';

end

end

end

imcore=char();

for i=1:M

for j=1:N

imcore=[imcore,fc{i,j}];

end

end

save picture imcore core;

%解码

clear;

load  picture.mat %载入图片码流和编码对应表

Nc=size(core);

Nic=size(imcore);

flag=0;

i=1;

j=1;

n=1;

cz=char();

f=zeros(128);

for n=1:400930

if flag==0

cz=[cz,imcore(n)];

else

cz=imcore(n);

flag=0;

end

for t=1:61

if strcmp(cz,core{t})

f(j,i)=t;

flag=1;

if i>127;

i=1;

j=j+1;

else

i=i+1;

end

break;

end

end

end

f=uint8(f*4+35);

subplot(122)

imshow(f);xlabel('\fontsize{16}解码后的图像');

你可能感兴趣的:(matlab,图片霍夫曼编码)