?? di3.9.m
字號:
function g=haffuman(data)
%haffuman() use to code the data
%the input data is the sign and their probability !
%進(jìn)行哈夫曼編碼,
%輸入data為二維灰度圖象數(shù)據(jù),輸出為g:2維元胞矩陣,里面第一列為符號(像素值),第二列為:輸出的哈夫曼編碼
sgailv=getsignpro(data);
paixu=paixuhuff(sgailv)
n=size(paixu);
n1=n(1);
paixu2=paixu;
for v=1:n1
paixu2(v,1)=v;
end
b=0;
n1=n1-1;
for k=n1:-1:1
paixu2(k,2)= paixu2(k,2)+ paixu2(k+1,2);
b=b+1;
dt(1,b)= paixu2(k,1);
dt(2,b)= paixu2(k+1,1);
paixu2(k+1,:)=[] ;
paixu2=paixuhuff( paixu2);
end
%下面對dt進(jìn)行編碼 dt矩陣的長為 n1 按上面的初始的排序順序,建立一個(gè)元胞矩陣返回。
ret(dt(1,n1),2)={0};
ret(dt(2,n1),2)={1};
for k=n1:-1:1
for t=1:2
if dt(t,k)~=-1
for k2=(k-1):-1:1
if dt(1,k2)~=-1 & dt(2,k2)~=-1
if dt(t,k)==dt(1,k2)
bn=ret{dt(t,k),2};
ret(dt(1,k2),2)={[0 bn]};
ret(dt(2,k2),2)={[1 bn]};
dt(1,k2)=-1;
elseif dt(t,k)==dt(2,k2)
bn=ret{dt(t,k),2};
ret(dt(1,k2),2)={[0 bn]};
ret(dt(2,k2),2)={[1 bn]};
dt(2,k2)=-1;
end
end
end
end
end
end
n1=n1+1;
for k=1:n1
ret(k,1)={paixu(k,1)};
sign=paixu(k,1);
mazi=ret{k,2}
end
g=ret;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -