赞
踩
未整理完!
在滤波器之前,先讲解傅里叶变换
f = imread('Fig0441.tif'); f = im2double(f); % 计算填充图像大小 [M,N] = size(f); M2 = 2*M; N2 = 2*N; % 傅里叶变换 F = fftshift(fft2(f,M2,N2)); figure;imshow(mat2gray(log(1+abs(F))));title('傅里叶频谱'); % 设计滤波器 % 生成网格坐标 u = -N:N-1; v = -M:M-1; [U,V] = meshgrid(u,v); % 设计滤波器 D = hypot(U,V); D0 = 30; % 截止频率[10 30 60 160 460] H = mat2gray( D <= D0 );% 理想低通滤波器 figure;imshow(H);title('理想低通滤波器'); % 频域滤波 G = F.*H; figure;imshow(mat2gray(log(1+abs(G))));title('频域滤波'); 1-sum(sum(abs(G).^2))/sum(sum(abs(F).^2)) g0 = ifft2(fftshift(G)); g = g0(1:M,1:N); g = real(g); figure;imshow(g);title('滤波后的图像'); figure; subplot(121);imshow(f);title('原图'); subplot(122);imshow(g);title('滤波后的图像');
结果:
原图:
f = imread('Fig0441.tif'); f = im2double(f); % 计算填充图像大小 [M,N] = size(f); M2 = 2*M; N2 = 2*N; % 傅里叶变换 F = fftshift(fft2(f,M2,N2)); figure;imshow(mat2gray(log(1+abs(F))));title('傅里叶频谱'); % 设计滤波器 % 生成网格坐标 u = -N:N-1; v = -M:M-1; [U,V] = meshgrid(u,v); % 设计滤波器 D = hypot(U,V); D0 = 30; % 截止频率[10 30 60 160 460] H = mat2gray(1./(1+((D./D0).^4))); figure;imshow(H);title('布特沃斯低通滤波器(n=2)'); % 频域滤波 G = F.*H; figure;imshow(mat2gray(log(1+abs(G))));title('频域滤波'); 1-sum(sum(abs(G).^2))/sum(sum(abs(F).^2)) g0 = ifft2(fftshift(G)); g = g0(1:M,1:N); g = real(g); figure;imshow(g);title('滤波后的图像'); figure; subplot(121);imshow(f);title('原图'); subplot(122);imshow(g);title('滤波后的图像');
matlab结果:
高斯低通滤波器代码:
H = exp((-D.^2)/(2*(D0).^2));
figure;imshow(H);title('滤波器(D0=100)');
结果:
理想高通滤波器代码:
H = mat2gray( D >= D0 );%理想高通滤波器
figure;imshow(H);title('滤波器()');
结果:
布特沃斯高通滤波器代码:
H = 1./(1+((D0./D).^4));%布特沃斯高通滤波器
figure;imshow(H);title('滤波器(n=2)');
结果:
高斯高通滤波器代码:
H = 1-exp((-D.^2)/(2*(D0).^2));%高斯高通滤波器
figure;imshow(H);title('滤波器');
matlab结果:
[file,path] = uigetfile({'*.png';'*.jpg';},'选择图片'); f = imread([path,file]); f = im2double(f); %计算填充图像大小 [M,N] = size(f); M2 = 2*M; N2 = 2*N; % 傅里叶变换 F = fftshift(fft2(f,M2,N2)); figure;imshow(mat2gray(log(1+abs(F))));title('傅里叶频谱'); % 设计滤波器 % 生成网格坐标 u = -N:N-1; v = -M:M-1; [U,V] = meshgrid(u,v); % 设计滤波器 D = hypot(U,V); D0 = 40; %截至频率[10 30 60 160 460] H = 1-exp((-D.^2)/(2*(D0).^2));%¸高斯高通滤波 G = (F.^(-1)).*((0.5+0.75.*H).*F);% figure;imshow(H);title('滤波器'); figure;imshow(mat2gray(log(1+abs(G))));title('频率滤波'); % 傅里叶逆变换 g0 = ifft2(fftshift(G)); g = g0(1:M,1:N); g = real(g); i=histeq(g); figure;imshow(g);title('滤波后的图像'); figure;imshow(i);title('直方图均衡');
结果:
原图:
reference:
李卫军,肖宛昂,董肖莉,覃鸿老师《视觉信息处理及FPGA实现》课程等
越是憧憬,越要风雨兼程。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。