It is impossible to perform the fast Fourier transform on the image.

Hi all:
question:I want to use the functions “itk::RealToHalfHermitianForwardFFTImageFilter” in ITK version 5.3 to perform fast Fourier transform and filtering on the image. However, an error occurred after I input an image of size [796, 768], because this function now requires the input image size to be a power of 2, 3, or 5. So which function should I use to perform Fourier transform on this image? Tanks for you help!
error:itk::ERROR: itk::ERROR: VnlRealToHalfHermitianForwardFFTImageFilter(0000021E3C96B690): Cannot compute FFT of image with size [796, 768]. VnlRealToHalfHermitianForwardFFTImageFilter operates only on images whose size in each dimension has a prime factorization consisting of only 2s, 3s, or 5s.
ps: This problem still occurs when using this function in simpleitk-2.0.0 in Python.

The FFTPadImageFilter Is what you are looking for:

In [1]: import SimpleITK as sitk

In [2]: img = sitk.Image([796, 768], sitk.sitkFloat32)

In [3]: pad_img = sitk.FFTPad(img)

In [4]: pad_img.GetSize()
Out[4]: (800, 768)

In [5]: fft_output = sitk.RealToHalfHermitianForwardFFT(pad_img)

Also the ITK Documentation for the PadImageFilter::SizeGreatestPrimeFactor parameter is not correct. In SimpleITK it defaults to 5, in ITK it is automatically selected to a value that is compatible with the underlying FFT engine (5 for VNL, and 14 for FFTW).

(EDIT: PR to update the documentation DOC: Correct Documentation for PadImageFilter::SizeGreatestPrimeFactor by blowekamp · Pull Request #4749 · InsightSoftwareConsortium/ITK · GitHub)

1 Like

Thank you for your reply. However, after padding the edges and then performing FFT, if Hanning window filtering or cosine filtering is carried out in the frequency domain, will the edge information filled by padding affect the filtering effect?

You can use SetDecayBase() to enable exponential fall-off in the padded region. This reduces the edge effect.

Thank you very mach

Unfortunately, that is not available for the converted FFTPadImageFilter, but only the MirrorPadImageFilter. And the “Mirror” option is not even available as a boundary condition for the FFTPadImageFilter. Is it just me or are these filters a little awkward?