Matlab自写高通滤波器函数:
function H=hpfilter(type,f,D0,n)
[M,N]=size(f);
n1=floor(M/2); n2=floor(N/2);
for i=1:M
for j=1:N
D(i,j)=[(i-n1)^2+(j-n2)^2]^0.5;
end
end
switch type
case 'ideal'
H = double(D >= D0);
case 'btw'
if nargin == 3
n = 1;
end
H = 1./(1+(D0./D).^(2*n));
case 'gaussian'
H = 1-exp(-(D.^2)./(2*(D0^2)));
otherwise
error('Unkown filter type');
end
(1) (2) (3)
clear all;close all;clc;
f=imread('实验3_测试图像\6.胸部X射线图像.tif');
f1=im2double(f);[R, C]=size(f1);
f1=padarray(f1,[R C],'symmetric','post');
F1=fft2(f1);F=fftshift(F1);
D0=40;
H1=hpfilter('gaussian',f1,D0);
G1=H1.*F;G2=(0.5+0.75*H1).*F;
g1=real(ifft2(ifftshift(G1)));
g2=real(ifft2(ifftshift(G2)));
g1=g1(1:size(f,1),1:size(f,2));
g2=g2(1:size(f,1),1:size(f,2));
g3=histeq(g2);
subplot(221);imshow(f,[]);title('原图像');
subplot(222);imshow(g1,[]);title('高斯高通滤波结果');
subplot(223);imshow(g2,[]);title('高频强调滤波结果');
subplot(224);imshow(g3,[]);title('直方图均衡后结果');
实验结果如图所示: