📄 lpfhpf.m
字号:
% ICLPF 理想低通滤波
Flpf1=Iclpf(F,0.4);
Flpf2=Iclpf(F,0.2);
Flpf3=Iclpf(F,0.06);
f1l=ifft2(ifftshift(Flpf1));f1l=uint8(real(f1l));
f2l=ifft2(ifftshift(Flpf2));f1l=uint8(real(f1l));
f3l=ifft2(ifftshift(Flpf3));f1l=uint8(real(f1l));
figure(2)
subplot(321);imshow(log(abs(Flpf1)),[]);title('ICLPF (r=0.4)');
subplot(323);imshow(log(abs(Flpf2)),[]);title('ICLPF (r=0.2)');
subplot(325);imshow(log(abs(Flpf3)),[]);title('ICLPF (r=0.06)');
subplot(322);imshow(f1l,[]);
subplot(324);imshow(f2l,[]);
subplot(326);imshow(f3l,[]);
% ICHPF 理想高通滤波
Fhpf1=Ichpf(F,0.4);
Fhpf2=Ichpf(F,0.2);
Fhpf3=Ichpf(F,0.06);
f1h=ifft2(ifftshift(Fhpf1));f1h=uint8(real(f1h));
f2h=ifft2(ifftshift(Fhpf2));f2h=uint8(real(f2h));
f3h=ifft2(ifftshift(Fhpf3));f2h=uint8(real(f2h));
figure(3)
subplot(321);imshow(log(abs(Fhpf1)),[]);title('ICHPF (r=0.4)');
subplot(323);imshow(log(abs(Fhpf2)),[]);title('ICHPF (r=0.2)');
subplot(325);imshow(log(abs(Fhpf3)),[]);title('ICHPF (r=0.06)');
subplot(322);imshow(f1h,[]);
subplot(324);imshow(f2h,[]);
subplot(326);imshow(f3h,[]);
%理想低通与高通滤波子程序编程如下:
function F1=Iclpf(F,r)
%ICLPF(Ideal Circular LowPass Filter)
% F is the FFT2 of an image;
% r is the radius of the filter,r ranges from 0 to 1
% F1 is the output of the transformed spectrum
[m,n]=size(F);
a=fix(m/2);
b=fix(n/2);
R=r*(m/2);
for i=1:m
for j=1:n
d1=sqrt((i-a)^2+(j-b)^2);
if (d1<=R)
F1(i,j)=F(i,j);
else F1(i,j)=0;
end
end
end
function F1=Ichpf(F,r)
%ICLPF(Ideal Circular HighPass Filter)
% F is the FFT2 of an image;
% r is the radius of the filter,r ranges from 0 to 1
% F1 is the output of the transformed spectrum
[m,n]=size(F);
a=fix(m/2);
b=fix(n/2);
R=r*(m/2);
for i=1:m
for j=1:n
d1=sqrt((i-a)^2+(j-b)^2);
if (d1>=R)
F1(i,j)=F(i,j);
else F1(i,j)=0;
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -