0
$\begingroup$

I've been tasked with creating a 32 x 32 half-band low-pass image filter in MATLAB. My thinking is to generate the ideal filter mask in the frequency domain and compute the corresponding convolution mask using the inverse FFT. I first generate the filter in the frequency domain.

filter = zeros(32);
filter (1:8, 1:8) = 1;
filter (1:8, 24:32) = 1;
filter (24:32, 1:8) = 1;
filter (24:32, 24:32) = 1;

This filter turns out to be the following in the frequency domain. I've confirmed my MATLAB code produces this pattern which is symmetric. enter image description here

Note, I'm assuming I need to define the mask with the frequency ranges from 0 -> 2pi rad/sec, hence putting the "ones" in the corners.

I then generate the convolution mask using the "iift2" MATLAB function. However, this mask turns out to be complex which raises some red flags. I would expect it to be a real filter.

mask = ifft2(filter)

When I convolve this filter mask with my image however, I get some weird artifacts.

image_filtered = imfilter(image_orig, mask);

enter image description here

I'm curious if there is some flaw in my thinking here.

$\endgroup$
12
  • 2
    $\begingroup$ Does this answer your question? Why is it a bad idea to filter by zeroing out FFT bins? $\endgroup$ – Marcus Müller Feb 7 at 20:50
  • $\begingroup$ all the things said for 1D filters there 100% directly translate to 2D filters, plus you forgot the circular nature of DFT convolution. $\endgroup$ – Marcus Müller Feb 7 at 20:51
  • $\begingroup$ also "ideal low-pass filter" has a specific meaning, and that is a low-pass filter with infinitely steep transition, which would be infinite in size and hence can not be implemented. $\endgroup$ – Marcus Müller Feb 7 at 20:52
  • $\begingroup$ @MarcusMüller I'm more interested in whether or not the fourier mask I've defined is correct and why I would be getting a complex convolution mask when performing the IFFT. Ideally, I would like the IFFT to create a 2D signal that entirely real. $\endgroup$ – Izzo Feb 8 at 18:06
  • $\begingroup$ again, no, you didn't define that mask correctly for any practical filtering problem. $\endgroup$ – Marcus Müller Feb 8 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.