近期在编写一个小波图像压缩的程序。遇到的问题如下:当我照抄书上的例子时,运行就没有问题;当我改用我自己的图片时(原程序中load tire;换为[X,map]=imread('girl.bmp');),就出现很多问题。有.tif和.bmp文件,是不是一定要有.mat文件?
程序清单如下,请高手多多指教:
load tire;
subplot(2,2,1);image(X);colormap(map);
title('原始图像');
axis square
%%进行图像压缩
%%用db3小波对图像进行二次分解
[c,s]=wavedec2(X,2,'db3');
%使用wdencmp函数压缩图像
[thr,sorh,keepapp]=ddencmp('cmp','wv',X);
%输入参数中选择了全局域值选项gb1,用来对所有的高频系数进行相同的域值量化处理
[Xcomp,cxc,lxc,perf0,perfl2]=wdencmp('gbl',c,s,'db3',2,thr,sorh,keepapp);
%显示压缩图像并比较
subplot(2,2,2);image(Xcomp);colormap(map);
title('compass ed');
axis square
disp('小波分解系数中置0系数百分比');
perf0
disp('压缩后图像剩余能量百分比');
perfl2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%二维小波分析图像压缩 去掉高频部分,保留低频
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load wbarb;
subplot(2,2,1);
image(X);
colormap(map);
title('原始图像');
axis square
disp('原始图像大小');
whos('X')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%提取小波分解结构中的第一层低频系数和高频系数
[c,s]=wavedec2(X,2,'bior3.7');
ca1=appcoef2(c,s,'bior3.7',1);
ca2=detcoef2('h',c,s,1);
ca3=detcoef2('v',c,s,1);
ca4=detcoef2('d',c,s,1);
%%%%%%%%%对各个频率成分重构
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);
c1=[a1,h1;v1,d1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%显示分解后各频率成分信息
subplot(2,2,2);
image(c1);
axis square
title('分解后低频和高频信息');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%图像压缩, 保留一层分解的低频信息ca1,显示
%对第一层信息进行量化
ca1=appcoef2(c,s,'bior3.7',1);
ca1=wcodemat(ca1,440,'mat',0);%量化编码
ca1=0.5*ca1;%改变图像高度
subplot(2,2,3);
image(ca1);
colormap(map);
axis square
title('一次压缩');
disp('第一次压缩后的大小为');
whos('ca1')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%保留第二层分解低频信息
ca2=appcoef2(c,s,'bior3.7',2);
ca2=wcodemat(ca2,440,'mat',0);
ca2=ca2*0.25;
subplot(2,2,4);
image(ca2);
colormap(map);
axis square
title('二次压缩');
disp('第二次压缩后的大小为');
whos('ca2')
小波分解系数中置0系数百分比
perf0
压缩后图像剩余能量百分比
perfl2