沈阳理工大学数字图像处理课程设计
visit(HufData(node).left,n,ocode1);.........................................................................................13
end............................................................................................................................................14
if(HufData(node).right>0)........................................................................................................14
%遍历右分支接点输出 0,这里采用子函数嵌套调用.......................................................14
ocode2=[ocode 0];....................................................................................................................14
visit(HufData(node).right,n,ocode2);.......................................................................................14
end............................................................................................................................................14
end.............................................................................................................................................14
end.............................................................................................................................................14
3.2 霍夫曼编码结果分析.........................................................................................................14
源程序:...................................................................................................................................17
clear all......................................................................................................................................17
I=imread('moon.tif');.................................................................................................................17
[m n]=size(I);.............................................................................................................................17
I=im2bw(I);...............................................................................................................................17
figure(1);....................................................................................................................................17
imshow(I);title('原始图像');......................................................................................................17
J=[];............................................................................................................................................17
I1=I';..........................................................................................................................................17
I1=I1(:);.....................................................................................................................................17
S=length(I1);.............................................................................................................................17
num=1;.......................................................................................................................................17
V1=double(I1(1));.....................................................................................................................17
J=[J V1];....................................................................................................................................17
for i=2:S.....................................................................................................................................17
V=I1(i);.....................................................................................................................................17
if V==V1..................................................................................................................................17
num=num+1;............................................................................................................................17
else............................................................................................................................................17
num=double(num);...................................................................................................................17
J=[J num];.................................................................................................................................17
num=1;......................................................................................................................................17
V1=I1(i);...................................................................................................................................18
end............................................................................................................................................18
end.............................................................................................................................................18
J=[J num];..................................................................................................................................18
L=length(J);...............................................................................................................................18
St=J(1);......................................................................................................................................18
I2=[];..........................................................................................................................................18
num0=1;.....................................................................................................................................18
for i=2:L.....................................................................................................................................18
num=J(i);..................................................................................................................................18
num1=num0+num;...................................................................................................................18
I2(num0:num1-1)=St;...............................................................................................................18