how to apply low pass and high pass filters using fft2 and fftshift?

18 ビュー (過去 30 日間)
Hadi Ghahremannezhad
Hadi Ghahremannezhad 2020 年 9 月 23 日
回答済み: Soroush Vahidi 2022 年 2 月 11 日
I am trying to apply low-pass and high-pass filters on a jpg image.
The filters are calculated by:
function [cL,cH] = getfilters(radius)
[x,y] = meshgrid(-128:127,-128:127);
z = sqrt(x.^2+y.^2);
cL = z < radius;
cH = ~cL;
end
so to filter the image, I have:
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');
To display the filtered inverse Fourier transform:
low_f = uint8(abs(low_filtered_image));
high_f = uint8(abs(high_filtered_image));
figure, imshow(low_f); figure, imshow(high_f);
Which parts are wrong in this code?

回答 (1 件)

Soroush Vahidi
Soroush Vahidi 2022 年 2 月 11 日
It is exactly my question too.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by