Matlab-如何使用fft2和fftshift应用低通和高通滤波器?

问题描述

我不确定如何在jpg图像上应用低通和高通滤镜。

过滤器的计算公式为:

function [cL,cH] = getfilters(radius)
    [x,y] = meshgrid(-128:127,-128:127);
    z = sqrt(x.^2+y.^2);
    cL = z < radius;
    cH = ~cL;
end

所以要过滤图像,我有:

img = imread('a jpg image')
ft = fftshift(fft2(img));
[cL,cH] = getfilters(40);
l_ft = ft .* cL;
h_ft = ft .* cH;
low_filtered_image = ifft2(ifftshift(l_ft),'symmetric');
high_filtered_image = ifft2(ifftshift(h_ft),'symmetric');

显示滤波后的傅立叶逆变换:

low_f = uint8(abs(low_filtered_image));
high_f = uint8(abs(high_filtered_image));
figure,imshow(low_f); figure,imshow(high_f);

这是输出:

enter image description here

enter image description here

如果该代码是错误的,我应该怎么做来解决它?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)