您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > 二维小波变换MATLAB实现
二维小波变换MATLAB实现•dwt2函数•功能:二维离散小波变换•格式:[cA,cH,cV,cD]=dwt2(X,'wname')•[cA,cH,cV,cD]=dwt2(X,Lo_D,Hi_D)•说明:[cA,cH,cV,cD]=dwt2(X,'wname')使用指定的小波基函数'wname'对二维信号X进行二维离散小波变幻;cA,cH,cV,cD分别为近似分量、水平细节分量、垂直细节分量和对角细节分量;[cA,cH,cV,cD]=dwt2(X,Lo_D,Hi_D)使用指定的分解低通和高通滤波器Lo_D和Hi_D分解信号X。•loadwoman;•nbcol=size(map,1);%返回矩阵的行数和列数•[cA1,cH1,cV1,cD1]=dwt2(X,'db1');•cod_x=wcodemat(X,nbcol);%返回矩阵X的编码矩阵,nbcol为编码的最大值•cod_cA1=wcodemat(cA1,nbcol);•cod_cH1=wcodemat(cH1,nbcol);•cod_cV1=wcodemat(cV1,nbcol);•cod_cD1=wcodemat(cD1,nbcol);•dec2d=[cod_cA1,cod_cH1;cod_cV1,cod_cD1];•subplot(1,2,1),imshow(cod_x,[]);•title('量化后的图像');•subplot(1,2,2),imshow(dec2d,[]);•title('二维离散小波分解后的图像');•idwt2函数•功能:二维离散小波反变换•格式:X=idwt2(cA,cH,cV,cD,'wname')•X=idwt2(cA,cH,cV,cD,Lo_R,Hi_R)•X=idwt2(cA,cH,cV,cD,'wname',S)•X=idwt2(cA,cH,cV,cD,Lo_R,Hi_R,S)•说明:X=idwt2(cA,cH,cV,cD,'wname')由信号小波分解的近似信号cA和细节信号cH、cH、cV、cD经小波反变换重构原信号X;X=idwt2(cA,cH,cV,cD,Lo_R,Hi_R)使用指定的重构低通和高通滤波器Lo_R和Hi_R重构原信号X;X=idwt2(cA,cH,cV,cD,'wname',S)和X=idwt2(cA,cH,cV,cD,Lo_R,Hi_R,S)返回中心附近的S个数据点。•loadwoman;•sX=size(X);•[cA1,cH1,cV1,cD1]=dwt2(X,'db4');•A0=idwt2(cA1,cH1,cV1,cD1,'db4',sX);•subplot(1,2,1),imshow(X,[])•title('原始图像');•subplot(1,2,2),imshow(A0,[])•title('由二维小波分解重构后的图像');•wavedec2函数•功能:二维信号的多层小波分解•格式:[C,S]=wavedec2(X,N,'wname')•[C,S]=wavedec2(X,N,Lo_D,Hi_D)•说明:[C,S]=wavedec2(X,N,'wname')用小波基函数'wname'对二维信号X进行N层分解;[C,S]=wavedec2(X,N,Lo_D,Hi_D)用指定的分解低通和高通滤波器Lo_D和Hi_D分解信号X。•waverec2函数•说明:二维信号的多层小波重构•格式:X=waverec2(C,S,'wname')•X=waverec2(C,S,Lo_R,Hi_R)•说明:X=waverec2(C,S,'wname')由多层二维小波分解的结果C、S重构原始信号X,'wname'为使用的小波基函数;X=waverec2(C,S,Lo_R,Hi_R)使用重构低通和高通滤波器Lo_R和Hi_R重构原信号。•loadwoman;•[c,s]=wavedec2(X,2,'sym4');•a0=waverec2(c,s,'sym4');•subplot(1,2,1),imshow(X,[])•title('原始图像');•subplot(1,2,2),imshow(a0,[])•title('重构后的图像');appcoef2提取二维信号小波分解的近似分量•loadwoman;•[c,s]=wavedec2(X,3,'db1');%用db1小波进行三层分解•ca1=appcoef2(c,s,'db1',1);%提取一层近似分量•ca2=appcoef2(c,s,'db2',2);%提取二层近似分量•imshow(X,[]);•title('原始图像');•figure,imshow(ca1,[])•title('第一层近似分量');•figure,imshow(ca2,[])•title('第二层近似分量');•detcoef2提取二维信号小波分解的细节分量•loadwoman;•[c,s]=wavedec2(X,3,'db1');•chd2=detcoef2('h',c,s,1);•cvd2=detcoef2('v',c,s,1);•cdd2=detcoef2('d',c,s,1);•imshow(X,[])•title('原始图像');•figure•subplot(1,3,1),imshow(chd2,[])•title('第一层分解的水平细节');•subplot(1,3,2),imshow(cvd2,[])•title('第一层分解的垂直细节');•subplot(1,3,3),imshow(cdd2,[])•title('第一层分解的对角细节');•wrcoef2由多层小波分解重构某一层的分解信号•clearall•loadwbarb;image(X);colormap(map);colorbar;•I=ind2gray(X,map);figure;I=imadjust(I,stretchlim(I),[0,1]);imshow(I);•%j=imadjust(i,[low_in;high_in],[low_out,high_out])将i中的亮度值映射到j中的新值•wname='sym2';•[c,s]=wavedec2(I,2,wname);•cA1=appcoef2(c,s,wname,1);•[ch1,cv1,cd1]=detcoef2('all',c,s,1);•cA2=appcoef2(c,s,wname,2);•[ch2,cv2,cd2]=detcoef2('all',c,s,2);•a1=wrcoef2('a',c,s,wname,1);•h1=wrcoef2('h',c,s,wname,1);•v1=wrcoef2('v',c,s,wname,1);•d1=wrcoef2('d',c,s,wname,1);•a2=wrcoef2('a',c,s,wname,2);•h2=wrcoef2('h',c,s,wname,2);•v2=wrcoef2('v',c,s,wname,2);•d2=wrcoef2('d',c,s,wname,2);•figure;•subplot(2,2,1);a1=abs(a1);a1=imadjust(a1,stretchlim(a1),[0,1]);imshow(a1);•title('approximationa1')•subplot(2,2,2);h1=abs(h1);h1=imadjust(h1,stretchlim(h1),[0,1]);imshow(h1);•title('horizontaldetailh1')•subplot(2,2,3);v1=abs(v1);v1=imadjust(v1,stretchlim(v1),[0,1]);imshow(v1);•title('verticaldetailv1')•subplot(2,2,4);d1=abs(d1);d1=imadjust(d1,stretchlim(d1),[0,1]);imshow(d1);•title('diagonaldetaild1')•figure;•subplot(2,2,1);a2=abs(a2);a2=imadjust(a2,stretchlim(a2),[0,1]);imshow(a2);•title('approximationa2')•subplot(2,2,2);h2=abs(h2);h2=imadjust(h2,stretchlim(h2),[0,1]);imshow(h2);•title('horizontaldetailh2')•subplot(2,2,3);v2=abs(v2);v2=imadjust(v2,stretchlim(v2),[0,1]);imshow(v2);•title('verticaldetailv2')•subplot(2,2,4);d2=abs(d2);d2=imadjust(d2,stretchlim(d2),[0,1]);imshow(d2);•title('diagonaldetaild2')upcoef2由多层小波分解重构近似分量或细节分量•loadwoman;•[c,s]=wavedec2(X,2,'db4');•siz=s(size(s,1),:);•cal=appcoef2(c,s,'db4',1);•a1=upcoef2('a',cal,'db4',1,siz);•chd1=detcoef2('h',c,s,1);•hd1=upcoef2('h',chd1,'db4',1,siz);•cvd1=detcoef2('v',c,s,1);•vd1=upcoef2('h',cvd1,'db4',1,siz);•cdd1=detcoef2('d',c,s,1);•dd1=upcoef2('d',cdd1,'db4',1,siz);•subplot(2,2,1),imshow(a1,[])•title('重构近似信号');•subplot(2,2,2),imshow(hd1,[])•title('重构水平细节信号');•subplot(2,2,3),imshow(vd1,[])•title('重构垂直细节信号');•subplot(2,2,4),imshow(dd1,[])•title('重构对角细节信号');
本文标题:二维小波变换MATLAB实现
链接地址:https://www.777doc.com/doc-3228576 .html