赞
踩
今天介绍四种低通滤波器对信号频率成分进行滤波,首先进行正傅里叶变换,设计一个滤波器用点操作的方法加工频谱数据,然后进行反傅里叶变换。关键是求出传递函数H(u,v)。
一.理想低通滤波器
matlab代码:
- clc;
- close all;
- clear all;
- I = rgb2gray(imread('plane.jfif'));
- subplot(131);imshow(I);title('原图');
- J = fftshift(fft2(I));
- subplot(132);imshow(log(abs(J)),[8,10]);title('傅里叶变换后');
- [M,N] = size(I);
- H = zeros(M,N);
- for u =1:M
- for v = 1:N
- if sqrt((u-M/2)^2+(v-N/2)^2)<=30
- H(u,v) = 1;
- else
- H(u,v) = 0;
-
- end;
- end;
- end;
- I1 = H.*J;
- I1 = ifftshift(I1);
- I2 = real(ifft2(I1));
- subplot(133);imshow(I2,[]);title('理想低通滤波器');
二.巴特沃斯低通滤波器
- clc;
- close all;
- clear all;
- I = rgb2gray(imread('plane.jfif'));
- subplot(131);imshow(I);title('原图');
- J = fftshift(fft2(I));
- subplot(132);imshow(log(abs(J)),[8,10]);title('傅里叶变换后');
- [M,N] = size(I);
- H = zeros(M,N);
- n1 = floor(M/2);n2 = floor(N/2);
- for i =1:M
- for j = 1:N
- d = sqrt((i-n1)^2+(j-n2)^2);
- H = 1/(1+(d/30)^(2*2));
- I1(i,j)=H*J(i,j);
- end;
- end;
- I1 = ifftshift(I1);
- I2 = real(ifft2(I1));
- subplot(133);imshow(I2,[]);title('巴特沃斯低通滤波器');
三.指数低通滤波器
- clc;
- close all;
- clear all;
- I = rgb2gray(imread('plane.jfif'));
- subplot(131);imshow(I);title('原图');
- J = fftshift(fft2(I));
- subplot(132);imshow(log(abs(J)),[8,10]);title('傅里叶变换后');
- [M,N] = size(I);
- H = zeros(M,N);
- n1 = floor(M/2);n2 = floor(N/2);
- for i =1:M
- for j = 1:N
- d = sqrt((i-n1)^2+(j-n2)^2);
- o = -(d/30)^2;
- H = exp(1)^o;
- I1(i,j)=H*J(i,j);
- end;
- end;
- I1 = ifftshift(I1);
- I2 = real(ifft2(I1));
- subplot(133);imshow(I2,[]);title('指数低通滤波器');
四.梯形低通滤波器
- clc;
- close all;
- clear all;
- I = rgb2gray(imread('plane.jfif'));
- subplot(131);imshow(I);title('原图');
- J = fftshift(fft2(I));
- subplot(132);imshow(log(abs(J)),[8,10]);title('傅里叶变换后');
- [M,N] = size(I);
- H = zeros(M,N);
- for u =1:M
- for v = 1:N
- if sqrt((u-M/2)^2+(v-N/2)^2)<30
- H(u,v) = 1;
- elseif 30<= sqrt((u-M/2)^2+(v-N/2)^2)<=180
- H(u,v) = (sqrt((u-M/2)^2+(v-N/2)^2)-180)/(30-180);
- else
- H(u,v)=0;
- end;
- end;
-
- end;
- I1 =H.*J;
- I1 = ifftshift(I1);
- I2 = real(ifft2(I1));
- subplot(133);imshow(I2,[]);title('梯形低通滤波器');
其中D0为截止频率,其值会影响最后图像平滑的效果,不同图像对应最佳的D0值也有所不同。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。