Saturday, April 28, 2018

fft - Applying Image Filtering (Circular Convolution) in Frequency Domain


To filter an image we can:



  1. Use a 3x3, 5x5, 7x7, etc. filter, that is convolve the image and the filter in the space domain.

  2. Use a FFT on both the image and the filter, multiply them together in the frequency domain, and then perform an IFFT on the image to get the filtered result.



These two approaches should produce equivalent result.


Questions:



  1. Are there any conditions placed on the filter so that the results are equal?

  2. Will there be any information loss in the second approach or will the images be exactly equal (neglecting floating point precision error)?

  3. As the kernel size increases, will the second approach start outperforming the first?



Answer



In my StackExchange Signal Processing Q38542 GitHub Repository you will be able to see a code which implements 2D Circular Convolution both in Spatial and Frequency Domain.



Pay attention to the function CircularExtension2D().
This function align the axis origin between the image and the kernel before working in the Frequency Domain.
Remember that for Discrete Signals the implicit assumption on signals, In frequency Domain analysis, is being periodic (Circular).


In the discrete case one could indeed apply Circular Convolution by element wise multiplication in the Frequency Domain.


With proper padding one could apply linear convolution using circular convolution hence Linear Convolution can also be achieved using multiplication in the Frequency Domain.


See:


enter image description here


In depth description can be found in FFT Based 2D Cyclic Convolution.


Regarding your questions:




  1. The filter is just an array of numbers. As long as you are after 2D Circular Convolution there is no constraints on the Filter. If it is valid for 2D Spatial Circular Convolution it is valid for Frequency Domain Circular Convolution.

  2. Up to Floating Point Quantization errors both are mathematically equivalent (See Convolution Theorem).

  3. If the Convolution Kernel is similar in its size to the image and both are large enough Frequency Domain Convolution becomes more efficient than Spatial Domain.


No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, $\ce{Mg^2+}$ is closest in radius to $\ce{Li+}$. Is this true, and if so, why would a whole larger shell ($\ce{...