Pregunta

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

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top