clear all
I=imread('CIMG1037.JPG');
I=rgb2gray(I);
%二级小波
[c,s]=wavedec2(I,2,'db2');
ca2=appcoef2(c,s,'db2',2);
ch2=detcoef2('h',c,s,2);
cv2=detcoef2('v',c,s,2);
cd2=detcoef2('d',c,s,2);
ch1=detcoef2('h',c,s,1);
cv1=detcoef2('v',c,s,1);
cd1=detcoef2('d',c,s,1);
A1=[ca2*4,ch2*4;cv2*4,cd2*4];
k=s(2,1)*2-s(3,1);
ch1=padarray(ch1,[k k],1,'post');
cv1=padarray(cv1,[k k],1,'post');
cd1=padarray(cd1,[k k],1,'post');
A=[A1,ch1*4;cv1*4,cd1*4];
min=min(A(:));
max=max(A(:));
subplot(121);imshow(A,[min,max]);
%三级小波
[c,s]=wavedec2(I,3,'db2');
ca3=appcoef2(c,s,'db2',3);
ch3=detcoef2('h',c,s,3);
cv3=detcoef2('v',c,s,3);
cd3=detcoef2('d',c,s,3);
ch2=detcoef2('h',c,s,2);
cv2=detcoef2('v',c,s,2);
cd2=detcoef2('d',c,s,2);
ch1=detcoef2('h',c,s,1);
cv1=detcoef2('v',c,s,1);
cd1=detcoef2('d',c,s,1);
A2=[ca3*4,ch3*4;cv3*4,cd3*4];
%显示分解结果
k=s(2,1)*2-s(3,1);
ch2=padarray(ch2,[k k],1,'post');
cv2=padarray(cv2,[k k],1,'post');
cd2=padarray(cd2,[k k],1,'post');
A1=[A2,ch2*4;cv2*4,cd2*4];
k=s(2,1)*4-s(4,1);
ch1=padarray(ch1,[k k],1,'post');
cv1=padarray(cv1,[k k],1,'post');
cd1=padarray(cd1,[k k],1,'post');
A=[A1,ch1*4;cv1*4,cd1*4];
myMin = min(A(:));
myMax = max(A(:));
subplot(122);imshow(A,[myMin,myMax]); |