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;
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);
I'm curious if there is some flaw in my thinking here.