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

**URL:** <https://discourse.itk.org/t/it-is-impossible-to-perform-the-fast-fourier-transform-on-the-image/6717>\
**Category:** Beginner Questions\
**Tags:** itk\
**Created:** [June 24, 2024, 10:10am UTC](https://discourse.itk.org/t/it-is-impossible-to-perform-the-fast-fourier-transform-on-the-image/6717 "2024-06-24T10:10:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![xem123](https://discourse.itk.org/user_avatar/discourse.itk.org/xem123/32/4080_2.png) [@xem123](https://discourse.itk.org/u/xem123)\
**Post date:** [June 24, 2024, 10:10am UTC](https://discourse.itk.org/t/it-is-impossible-to-perform-the-fast-fourier-transform-on-the-image/6717/1 "2024-06-24T10:10:09Z")

</div>

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.

 ![image](https://discourse.itk.org/uploads/default/original/2X/1/1155d56b9b74608e4155e6c8cbc2d5c184002f92.png)

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [June 24, 2024, 11:00am UTC](https://discourse.itk.org/t/it-is-impossible-to-perform-the-fast-fourier-transform-on-the-image/6717/2 "2024-06-24T11:00:36Z")

</div>

The [FFTPadImageFilter](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1FFTPadImageFilter.html) Is what you are looking for:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [June 24, 2024, 11:05am UTC](https://discourse.itk.org/t/it-is-impossible-to-perform-the-fast-fourier-transform-on-the-image/6717/3 "2024-06-24T11:05:44Z")

</div>

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](https://github.com/InsightSoftwareConsortium/ITK/pull/4749))

---

<div class="post-metadata">

**Author:** ![xem123](https://discourse.itk.org/user_avatar/discourse.itk.org/xem123/32/4080_2.png) [@xem123](https://discourse.itk.org/u/xem123)\
**Post date:** [June 25, 2024, 5:21am UTC](https://discourse.itk.org/t/it-is-impossible-to-perform-the-fast-fourier-transform-on-the-image/6717/4 "2024-06-25T05:21:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [June 25, 2024, 12:47pm UTC](https://discourse.itk.org/t/it-is-impossible-to-perform-the-fast-fourier-transform-on-the-image/6717/5 "2024-06-25T12:47:04Z")

</div>

You can use [SetDecayBase()](https://itk.org/Doxygen/html/classitk_1_1MirrorPadImageFilter.html#a523aad81a5afc1ebd20b056ca6d25974) to enable exponential fall-off in the padded region. This reduces the edge effect.

---

<div class="post-metadata">

**Author:** ![xem123](https://discourse.itk.org/user_avatar/discourse.itk.org/xem123/32/4080_2.png) [@xem123](https://discourse.itk.org/u/xem123)\
**Post date:** [June 26, 2024, 1:28am UTC](https://discourse.itk.org/t/it-is-impossible-to-perform-the-fast-fourier-transform-on-the-image/6717/6 "2024-06-26T01:28:51Z")

</div>

Thank you very mach

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [June 27, 2024, 12:04pm UTC](https://discourse.itk.org/t/it-is-impossible-to-perform-the-fast-fourier-transform-on-the-image/6717/7 "2024-06-27T12:04:50Z")

</div>

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?
