Matlab图像做图像小波变换,还有不同阈值滤波器的使用。
1.对一幅给定的灰度图像(有条件的可考虑彩色图像)进行一次小波变换并显示;
2.进行小波逆变换并通过显示与原图比较;
3.观察变换前后图像数据的差异;
4.设置不同的阈值观察其对图像的影响。(选作内容)
这里的灰度图像和彩色图像,我们以下图为例演示。
灰度图像的变换
x1=imread('lena256.bmp');
n1=20;
n2=50;
n3=100;
subplot(2,3,1)
imshow(x1)
title('原图')
N=256;
for i=1:N
if(mod(i,2)==0)
w1(i,fix(i/2))=0.5;
w1(i,fix(i/2)+N/2)=-0.5;
else
w1(i,fix(i/2)+1)=0.5;
w1(i,fix(i/2)+N/2+1)=0.5;
end
end
x2=double(x1);
y3=w1'*x2*w1;
subplot(2,3,2)
imshow(uint8(abs(y3)))
title('小波变换后')
subplot(2,3,3)
w11=inv(w1);
x3=w11'*y3*w11;
imshow(uint8(x3))
title('小波逆变换后')
for m=1:256
for n=1:256
if(abs(y3(m,n))<n1)
y4(m,n)=0;
else
y4(m,n)=y3(m,n);
end
end
end
x4=w11'*y4*w11;
subplot(2,3,4)
imshow(uint8(x4))
title('阈值为20')
for m=1:256
for n=1:256
if(abs(y3(m,n))<n2)
y5(m,n)=0;
else
y5(m,n)=y3(m,n);
end
end
end
x5=w11'*y5*w11;
subplot(2,3,5)
imshow(uint8(x5))
title('阈值为50')
for m=1:256
for n=1:256
if(abs(y3(m,n))<n3)
y6(m,n)=0;
else
y6(m,n)=y3(m,n);
end
end
end
x6=w11'*y6*w11;
subplot(2,3,6)
imshow(uint8(x6))
title('阈值为100')
彩色图片变换
x1=imread('tiger.bmp');
n1=20;
n2=50;
n3=100;
subplot(2,3,1)
imshow(x1)
title('原图')
N=256;
for i=1:N
if(mod(i,2)==0)
w1(i,fix(i/2))=0.5;
w1(i,fix(i/2)+N/2)=-0.5;
else
w1(i,fix(i/2)+1)=0.5;
w1(i,fix(i/2)+N/2+1)=0.5;
end
end
x2=double(x1);
y3(:,:,1)=w1'*x2(:,:,1)*w1;
y3(:,:,2)=w1'*x2(:,:,2)*w1;
y3(:,:,3)=w1'*x2(:,:,3)*w1;
subplot(2,3,2)
imshow(uint8(abs(y3)))
title('小波变换后')
subplot(2,3,3)
w11=inv(w1);
x3(:,:,1)=w11'*y3(:,:,1)*w11;
x3(:,:,2)=w11'*y3(:,:,2)*w11;
x3(:,:,3)=w11'*y3(:,:,3)*w11;
imshow(uint8(x3))
title('小波逆变换后')
for m=1:256
for n=1:256
for p=1:3
if(abs(y3(m,n,p))<n1)
y4(m,n,p)=0;
else
y4(m,n,p)=y3(m,n,p);
end
end
end
end
x4(:,:,1)=w11'*y4(:,:,1)*w11;
x4(:,:,2)=w11'*y4(:,:,2)*w11;
x4(:,:,3)=w11'*y4(:,:,3)*w11;
subplot(2,3,4)
imshow(uint8(x4))
title('阈值为20')
for m=1:256
for n=1:256
for p=1:3
if(abs(y3(m,n,p))<n2)
y5(m,n,p)=0;
else
y5(m,n,p)=y3(m,n,p);
end
end
end
end
x5(:,:,1)=w11'*y5(:,:,1)*w11;
x5(:,:,2)=w11'*y5(:,:,2)*w11;
x5(:,:,3)=w11'*y5(:,:,3)*w11;
subplot(2,3,5)
imshow(uint8(x5))
title('阈值为50')
for m=1:256
for n=1:256
for p=1:3
if(abs(y3(m,n,p))<n3)
y6(m,n,p)=0;
else
y6(m,n,p)=y3(m,n,p);
end
end
end
end
x6(:,:,1)=w11'*y6(:,:,1)*w11;
x6(:,:,2)=w11'*y6(:,:,2)*w11;
x6(:,:,3)=w11'*y6(:,:,3)*w11;
subplot(2,3,6)
imshow(uint8(x6))
title('阈值为100')
运行结果为