clear;
I = imread('cameraman.tif');
figure;
colormap(gray);
subplot(2,2,1);imshow(I);title('原图');
disp('压缩前图像大小');
whos('I');
[c,s] = wavedec2(I,2,'bior3.7');%小波分解
cal = appcoef2(c,s,'bior3.7',1);
ch1 = detcoef2('h',c,s,1);
cv1 = detcoef2('v',c,s,1);
cd1 = 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),imshow(c1,[]),title('分解后低频和高频信息');
ca1 = appcoef2(c,s,'bior3.7',1);
ca1 = wcodemat(ca1,440,'mat',0);
ca1 = 0.5*ca1;
subplot(2,2,3),imshow(ca1,[]),title('第一次压缩图像');
disp('第一次压缩的大小为:');
whos('ca1');
ca2 = appcoef2(c,s,'bior3.7',2);
ca2 = wcodemat(ca2,440,'mat',0);
ca2 = 0.25 * ca2;
subplot(2,2,4),imshow(ca2,[]),title('第二次压缩图像');
disp('第二次压缩大小为:');
whos('ca2');
init = 2055615866;%去噪
rand('seed',init);
I = double(I);
x = I + 18*randn(size(I));
wname = 'sym4';lev=3;
[c,s] = wavedec2(I,lev,wname);
alpha = 1.5;m = 2.7*prod(s(1,:));
[thr,nkeep] = wdcbm2(c,s,alpha,m);
[xd,cxd,sxd,perf0,perfl2]=wdencmp('lvd',c,s,wname,lev,thr,'h');
colormap(gray);
figure;
subplot(2,2,1),imshow(wcodemat(I),[]),xlabel('原图');
subplot(2,2,2),imshow(wcodemat(x),[]),xlabel('含噪声');
subplot(2,2,3),imshow(wcodemat(xd),[]),xlabel('滤除噪声后');
评论1