0
votes

again I am still trying to get my lowpass filter running, but I am at a point where I do not know why this is still not running. I oriented my code according to FFT Filters and my previous question FFT Question in order to apply an ideal low pass filter to the image. The code below just makes the image darker and places some white pixels in the resulting image.

// forward fft the result is in freqBuffer
fftw_execute(forward);

for (int y = 0; y < h; y++)
{
    for (int x = 0; x < w; x++)
    {
        uint gid = y * w + x;

        // shifting coordinates normalized to [-0.5 ... 0.5]
        double xN = (x - (w / 2)) / (double)w;
        double yN = (y - (h / 2)) / (double)h;

        // max radius
        double maxR = sqrt(0.5f * 0.5f + 0.5f * 0.5f);

        // current radius normalized to [0 .. 1]
        double r = sqrt(xN * xN + yN * yN) / maxR ;

        // filter response
        double filter = r > 0.7f ? 0.0f : 1.0f;

        // applying filter response
        freqBuffer[gid][0] *= filter;
        freqBuffer[gid][1] *= filter;
    }
}

// normlization (see fftw scaling)
for (uint i = 0; i < size; i++)
{
    freqBuffer[i][0] /= (float)size;
    freqBuffer[i][1] /= (float)size;
}

// backward fft
fftw_execute(backward);

Some help would be appreciated.

Wolf

1
For arbitrary content, a brick-wall filter (zeroing FFT bins) is far from ideal.hotpaw2
As far as I see it this behavior is called "ideal" see Ideal Low PassDerHandwerk
Note that this filter is continuous, which can behave very differently from FFT bins (where the response can have huge overshoots between bin centers instead of being flat, as per the diagram).hotpaw2
That's exactly what I experienced. So I replaced it by a filter with cosine transition, which is much smoother. The result is much more ideal than the result of the ideal filter. :-DDerHandwerk

1 Answers

1
votes

If you have a filter with a step response in the frequency domain then you will see significant sin(x)/x ringing in the spatial domain. This is known as the Gibbs Phenomenon. You need to apply a window function to the desired frequency response to mitigate this.