【图像处理】MATLAB:频域高低通滤波器
2017-10-08 16:44
525 查看
建立网格数组
M函数dftuv,提供了距离计算及其他类似应用所需要的网格数组。function [U, V] = dftuv(M, N) %DFTUV Computes meshgrid frequency matrices. % [U, V] = DFTUV(M, N) computes meshgrid frequency matrices U and % V. U and V are useful for computing frequency-domain filter % functions that can be used with DFTFILT. U and V are both % M-by-N. % Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins % Digital Image Processing Using MATLAB, Prentice-Hall, 2004 % $Revision: 1.3 $ $Date: 2003/04/16 22:30:34 $ % Set up range of variables. u = 0:(M - 1); v = 0:(N - 1); % Compute the indices for use in meshgrid. idx = find(u > M/2); u(idx) = u(idx) - M; idy = find(v > N/2); v(idy) = v(idy) - N; % Compute the meshgrid arrays. [V, U] = meshgrid(v, u);
低通频域滤波器
代码示例
f = imread('pattern.tif'); PQ = paddedsize(size(f)); [U,V] = dftuv(PQ(1),PQ(2)); D0 = 0.05*PQ(2); F = fft2(f,PQ(1),PQ(2)); H = exp(-(U.^2+V.^2)/(2*(D0^2))); %低通高斯滤波器 g = dftfilt(f,H); subplot(2,2,1);imshow(f);title('原图像'); subplot(2,2,2);imshow(fftshift(H),[ ]);title('高斯低通滤波器'); subplot(2,2,3);imshow(log(1+abs(fftshift(F))),[ ]);title('原图像的频谱'); subplot(2,2,4);imshow(g,[ ]);title('处理后图像(比原图像模糊)');
运行结果
函数lpfilter用于生成低通滤波器的传递函数:
function H = lpfilter(type, M, N, D0, n) %LPFILTER Computes frequency domain lowpass filters. % H = LPFILTER(TYPE, M, N, D0, n) creates the transfer function of % a lowpass filter, H, of the specified TYPE and size (M-by-N). To % view the filter as an image or mesh plot, it should be centered % using H = fftshift(H). % % Valid values for TYPE, D0, and n are: % % 'ideal' Ideal lowpass filter with cutoff frequency D0. n need % not be supplied. D0 must be positive. % % 'btw' Butterworth lowpass filter of order n, and cutoff % D0. The default value for n is 1.0. D0 must be % positive. % % 'gaussian' Gaussian lowpass filter with cutoff (standard % deviation) D0. n need not be supplied. D0 must be % positive. % Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins % Digital Image Processing Using MATLAB, Prentice-Hall, 2004 % $Revision: 1.8 $ $Date: 2004/11/04 22:33:16 $ % Use function dftuv to set up the meshgrid arrays needed for % computing the required distances. [U, V] = dftuv(M, N); % Compute the distances D(U, V). D = sqrt(U.^2 + V.^2); % Begin filter computations. switch type case 'ideal' %理想低通滤波器 H = double(D <= D0); case 'btw' %巴特沃兹低通滤波器 if nargin == 4 n = 1; end H = 1./(1 + (D./D0).^(2*n)); case 'gaussian' %高斯低通滤波器 H = exp(-(D.^2)./(2*(D0^2))); otherwise error('Unknown filter type.') end
绘制低通滤波器的线框图及表面图
% 绘制线框图 H = fftshift(lpfilter('gaussian',500,500,50)); % 高斯低通滤波器 mesh(H(1:10:500,1:10:500)); % 绘制线框图 axis([0 50 0 50 0 1]); % 坐标轴 colormap([0 0 0]); % 通过彩色绘制网线 axis on; % 打开网格,axis off关闭 grid on; % 打开坐标轴,grid off关闭 view(-25,30); % 查看点(观察者)位置
% 绘制表面图 H = fftshift(lpfilter('gaussian',500,500,50)); % 高斯低通滤波器 surf(H(1:10:500,1:10:500)); % 绘制表面图 axis([0 50 0 50 0 1]); % 坐标轴 colormap(gray); % 通过彩色绘制网线 axis pff; % 关闭网格 grid off; % 关闭坐标轴
高通频域滤波器
高通滤波通过削弱傅里叶变换的低频而保持高频相对不变,会使图像变得更加清晰(锐化)。函数hpfilter用于生成低通滤波器的传递函数:
function H = hpfilter(type, M, N, D0, n) %HPFILTER Computes frequency domain highpass filters. if nargin == 4 n = 1; % Default value of n. end % Generate highpass filter. Hlp = lpfilter(type, M, N, D0, n); H = 1 - Hlp;
代码示例
H = fftshift(hpfilter('ideal',500,500,50)); mesh(H(1:10:500,1:10:500)); axis([0 50 0 50 0 1]); colormap([0 0 0]); axis off; grid off; title('理想高通滤波器的透视图'); figure,imshow(H,[ ]); title('理想高通滤波器相应图像');
运行结果
代码示例
f = imread('pattern.tif'); PQ = paddedsize(size(f)); D0 = 0.05* PQ(1); H = hpfilter('gaussian',PQ(1),PQ(2),D0); g = dftfilt(f,H); subplot(1,2,1);imshow(f);title('原图像'); subplot(1,2,2);imshow(g,[ ]);title('高斯高通滤波后的结果');
运行结果
高频强调滤波
代码示例
PQ = paddedsize(size(f)); D0 = 0.05*PQ(1); HBW = hpfilter('btw',PQ(1),PQ(2),D0,2); H = 0.5 + 2 * HBW; gbw = dftfilt(f,HBW); gbw = gscale(gbw); ghf = dftfilt(f,H); ghf = gscale(ghf); ghe = histeq(ghf,256); subplot(2,2,1);imshow(f);title('原图像'); subplot(2,2,2);imshow(gbw);title('巴特沃兹高通滤波'); subplot(2,2,3);imshow(ghf);title('高频强调滤波'); subplot(2,2,4);imshow(ghe);title('高频强调滤波与直方图均衡化结合');
运行结果
相关文章推荐
- Matlab 图像处理 冈萨雷斯 第四章 频域处理 4.1 && 4.2
- 图像matlab 频域处理
- [数字图像处理]频域滤波(1)--基础与低通滤波器
- Matlab中图像处理实例:灰度变换,空域滤波,频域滤波,傅里叶变换的实现
- Matlab图像频域处理
- 【图像处理】MATLAB:频域处理
- Matlab中图像处理实例:灰度变换,空域滤波,频域滤波,傅里叶变换的实现
- [数字图像处理]频域滤波(1)--基础与低通滤波器
- [数字图像处理]频域滤波(1)--基础与低通滤波器
- Atitit MATLAB 图像处理 经典书籍attilax总结
- 【图像处理】MATLAB图像处理_IPC图像处理流程
- 【MATLAB图像处理】在MATLAB中图像的坐标以及rectangle的坐标
- Matlab图像处理:误拒率、误识率意义,计算等错误率的Matlab源码(网络首发)
- MATLAB图像处理基础知识
- MATLAB图像处理命令
- Matlab数字数字图像处理函数汇总
- matlab图像处理(一)--图片读写
- MATLAB处理RGB图像时如何获得单通道,以及如何根据各单通道恢复彩色图像
- 图像分割 处理 matlab源码
- matlab中fread函数的用法-在视频图像处理中