资源描述:
《图像压缩的matlab代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
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('原图像的灰度图
2、');%显示workplace的变量的详细信息whos('G');%转换成为灰度级索引图像%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);%第
3、二幅图像%显示近似和细节figure(2);colormap(map2);subplot(2,2,1);%对矩阵进行量化编码image(wcodemat(A1,192));title('近似A1');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('对角细节
4、D1');%对图像进行多尺度分解[C,S]=wavedec2(G,2,'bior3.7');%提取分解后的近似和细节系数%提取一维小波变换低频系数CA2=appcoef2(C,S,'bior3.7',2);%提取小波变换高频系数[CH2,CV2,CD2]=detcoef2('all',C,S,2);[CH1,CV1,CD1]=detcoef2('all',C,S,1);%从系数C重构第二层近似A2=wrcoef2('a',C,S,'bior3.7',2);H1=wrcoef2('h',C,S,'bior3.7',1
5、);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);image(wcodemat(A1,192));title('近似A1');sub
6、plot(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(
7、'水平细节H2');subplot(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')(
8、2)file_name=('bab.bmp');H=imread(file_name);H=double(H);ca=0.2990*H(:,:,1)+0.5870*H(:,:,2)+0.1140*H(:,:,3);NbColors=255;G=wcodemat(ca,NbColors);map2=gray(NbColors);figure(1);image(