数字图像的变换

傅里叶变换

傅里叶变换是最简单的正交变换,它是理解其他变换的基础,同时也是应用最广泛的一种正交变换。傅里叶变换建立了从时间域到频率域的桥梁。   

傅里叶变换的实现

%实现图像的傅里叶变换
I=imread('cameraman.tif');
subplot(131);imshow(I);
title('原始图像');
J=fft2(I);%傅里叶变换
subplot(132);imshow(J);
title('傅里叶变换后的图像');
K=ifft2(J)/255;%傅里叶逆变换
subplot(133);imshow(K);
title('傅里叶逆变换后图像');

结果:

%图像变亮后进行傅里叶变换
I=imread('peppers.png');
J=rgb2gray(I);
J=J*exp(1);
J(find(J>255))=255;
K=fft2(J);
K=fftshift(K);
L=abs(K/256);
figure;
subplot(121);imshow(J);
title('变亮后的图像');
subplot(122);imshow(uint8(L));%频谱图
title('频谱图');

结果:

 

%在图像text.tif中定位字母“a”
bw=imread('text.png');
a=bw(32:45,88:98);
subplot(1,2,1);imshow(bw);
title('原始图像');
subplot(1,2,2);imshow(a);
title('模板图像');

结果:

 

%将模板“a”和“text.png”图进行相关运算,就是先分别对其作快速傅里叶变换,然后利用快速卷积的方法,计算模板和text.png的卷积。
bw=imread('text.png');
a=bw(32:45,88:98);%从图像中提取字母“a”。
C=real(ifft2(fft2(bw).*fft2(rot90(a,2),256,256)));
subplot(121),imshow(C,[]);
title('模板与卷积')
max(C(:))
thresh=60  %设定门限
subplot(122),imshow(C>thresh)
title('a字母定位')

 结果:

滤波器的应用

%对图像进行巴特沃斯低通滤波器
I=imread('cameraman.tif');
I=im2double(I);
J=fftshift(fft2(I));%傅里叶变换和平移
[x,y]=meshgrid(-128:127,-128:127);%产生离散数据
z=sqrt(x.^2+y.^2);
D1=10;D2=35;
n=6;%滤波器的阶数
H1=1./(1+(z/D1).^(2*n));%滤波器
H2=1./(1+(z/D2).^(2*n));
K1=J.*H1;
K2=J.*H2;
L1=ifft2(ifftshift(K1));%傅里叶反变换
L2=ifft2(ifftshift(K2));
subplot(131);imshow(I);
title('原始图像');
subplot(132);imshow(L1);%显示载频频率为10hz
title('巴特沃斯低通滤波器');
subplot(133);imshow(L2);%显示载频频率为35hz
title('巴特沃斯低通滤波器');

结果:

 

%对图像进行巴特沃斯高通滤波器
I=imread('cameraman.tif');
I=im2double(I);
J=fftshift(fft2(I));%傅里叶变换和平移
[x,y]=meshgrid(-128:127,-128:127);%产生离散数据
z=sqrt(x.^2+y.^2);
D1=10;D2=35;
n1=4;n2=8;%滤波器的阶数
H1=1./(1+(z/D1).^(2*n1));%滤波器
H2=1./(1+(z/D2).^(2*n2));
K1=J.*H1;
K2=J.*H2;
L1=ifft2(ifftshift(K1));%傅里叶反变换
L2=ifft2(ifftshift(K2));
subplot(131);imshow(I);
title('原始图像');
subplot(132);imshow(L1);%显示载频频率为10hz
title('巴特沃斯低通滤波器');
subplot(133);imshow(L2);%显示载频频率为35hz
title('巴特沃斯低通滤波器');

结果:

 

       

猜你喜欢

转载自blog.csdn.net/qq_35654080/article/details/82841526