# How do I convert a filter from Spatial to Fourier domain?

I have a small 2D Gaussian image filter that I am currently applying as a window by convolution. I would like to do this in the Fourier domain as a single multiplication. I would like to convert my current small filter to the Fourier domain as it is with maximum possible fidelity.

I do not know the size of the image that I shall be applying it on and want to be able to dynamically change it for any image size. How do I go about doing this?

Can I scale my filter to the image size (square to rectangle), FFT the scaled and now distorted and multiply in the Fourier domain?

or

Should I FFT it first, scale up (square to rectangle) and distort the FFT and then multiply it?

I am not convinced that either is a correct approach. Are there any alternative ways?

I am working with this in MATLAB

• Do you know the spatial expression for the filter? Gaussian filters have an analytic form in the Fourier domain as well. – geometrikal May 3 '13 at 23:16

Second, the Fourier transform of a Gaussian is a Gaussian. So we can work in one dimension at a time, we know what we're going to get, and multiplying a Gaussian in the Fourier domain is also separable since $e^{-(x^2+y^2)}=e^{-x^2}e^{-y^2}$. The only question is what the standard deviation ($\sigma$) of the transformed Gaussian is going to be. The derivation is worked out on Mathworld as: $$\mathcal{F}[e^{-ax^2}](k)=\sqrt{\frac{\pi}{a}}e^{-\pi^2k^2/a}.$$
• The only trouble with doing this is that the image resulting may have circular (spatial) aliasing. If the image is $N\times N$ and the filter is $N \times N$ then the resulting (convolved) image needs to be $2N -1 \times 2N - 1$ to avoid such aliasing. – Peter K. May 4 '13 at 13:54