1、(1) file_name=baboon.bmp;H=imread(file_name);H=double(H);Grgb=0.2990*H(:,:,1)+0.5870*H(:,:,2)+0.1140*H(:,:,3);NbColors=255;%对矩阵进行量化编码G=wcodemat(Grgb,NbColors); %gray 线性的灰阶色调map2=gray(NbColors);%建立图形窗口 1figure(1);%建立图像 Gimage(G);%应用调色板colormap(map2);title(原图像的灰度图);%显示 workplace 的变量的详细信息whos(G);%转换成为灰
2、度级索引图像%dwt2 单尺度二维离散小波变换CA1,CH1,CV1,CD1=dwt2(G,bior3.7);%从分解系数中提取近似和细节% upcoef2 二维系数的直接小波重构A1=upcoef2(a,CA1,bior3.7,1);H1=upcoef2(h,CH1,bior3.7,1);V1=upcoef2(v,CV1,bior3.7,1);D1=upcoef2(d,CD1,bior3.7,1);%第二幅图像%显示近似和细节figure (2);colormap(map2);subplot(2,2,1);%对矩阵进行量化编码image(wcodemat(A1,192);title(近似 A
3、1);subplot(2,2,2);image(wcodemat(H1,192);title(水平细节 H1);subplot(2,2,3);image(wcodemat(V1,192);title(垂直细节 V1);subplot(2,2,4);image(wcodemat(D1,192);title(对角细节 D1);%对图像进行多尺度分解C,S=wavedec2(G,2,bior3.7);%提取分解后的近似和细节系数%提取一维小波变换低频系数CA2=appcoef2(C,S,bior3.7,2);%提取小波变换高频系数CH2,CV2,CD2=detcoef2(all,C,S,2);CH1
4、,CV1,CD1=detcoef2(all,C,S,1);%从系数 C 重构第二层近似A2=wrcoef2(a,C,S,bior3.7,2);H1=wrcoef2(h,C,S,bior3.7,1);V1=wrcoef2(v,C,S,bior3.7,1);D1=wrcoef2(d,C,S,bior3.7,1);H2=wrcoef2(h,C,S,bior3.7,2);V2=wrcoef2(v,C,S,bior3.7,2);D2=wrcoef2(d,C,S,bior3.7,2);%第三幅图像%显示多尺度分解的结果figure (3);colormap(map2);subplot(2,4,1);ima
5、ge(wcodemat(A1,192);title(近似 A1);subplot(2,4,2);image(wcodemat(H1,192);title(水平细节 H1);subplot(2,4,3);image(wcodemat(V1,192);title(垂直细节 V1);subplot(2,4,4);image(wcodemat(D1,192);title(对角细节 D1);subplot(2,4,5);image(wcodemat(A2,192);title(近似 A2);subplot(2,4,6);image(wcodemat(H2,192);title(水平细节 H2);subp
6、lot(2,4,7);image(wcodemat(V2,192);title(垂直细节 V2);subplot(2,4,8);image(wcodemat(D2,192);title(对角细节 D2);%第四幅图像%从多尺度分解后的系数重构原始图像并显示结果G0=waverec2(C,S,bior3.7);%建立图形窗口 4figure (4);%建立图像 G0image(G0);%应用调色板colormap(map2);%绘制调色板的内容colorbar;whos(G0)(2) file_name=(bab.bmp);H=imread(file_name);H=double(H);ca=0
7、.2990*H(:,:,1)+0.5870*H(:,:,2)+0.1140*H(:,:,3);NbColors=255;G=wcodemat(ca,NbColors);map2=gray(NbColors);figure(1);image(G);colormap(map2);title(原图像的灰度图);whos(G);%对图像进行多尺度二维小波分解c,s=wavedec2(G,2,bior3.7);ca1=appcoef2(c,s,bior3.7,1);ch1=detcoef2(h,c,s,1);cv1=detcoef2(v,c,s,1);cd1=detcoef2(d,c,s,1);%对各频
8、率进行小波重构a1=wrcoef2(a,c,s,bior3.7,1);h1=wrcoef2(h,c,s,bior3.7,1);v1=wrcoef2(v,c,s,bior3.7,1);d1=wrcoef2(d,c,s,bior3.7,1);G1=a1,h1;v1,d1;figure(2);image(G1);colormap(map2);axis square;title(分解后低频和高频信息)whos(G1);ca1=appcoef2(c,s,bior3.7,1);ca1=wcodemat(ca1,440,mat,1);ca2=0.6*ca1;figure(3);image(ca2);colormap(map2);title(低频压缩图像);whos(ca2);ca3=appcoef2(c,s,bior3.7,2);ca3=wcodemat(ca3,440,mat,0);ca4=0.5*ca3;figure(4);image(ca4);title(二层分解后低频压缩图像);colormap(map2);whos(ca4);