Apply 1D FFT along specified dimension (row or column) using SimpleITK is SLOW

Hello,

I am using sitk::ForwardFFT in C++ to apply 1D FFT on each row or column on a 2D image. However, I found the processing speed is quite slow even using buffer operations.

Is there any built-in function in SimpleITK to apply 1D FFT or can anyone advise to speed up the 1D FFD procedure?

Thanks!
Elliot

Have you considered this class?
https://itk.org/Doxygen/html/classitk_1_1ForwardFFTImageFilter.html

Hello @SuperTXUH,

Not specific to FFT, is your build in release mode or could it be that it is in debug mode? The issue with speed and build type has happened to others in the past.

Thanks for pointing this out. I try to use “Forward1DFFTImageFilter”. However, the image seems not changed after apply fft then modulus. Where the input (imageIn) is sitk 2D image (float32).

    using PixelType = float;
    constexpr unsigned int Dimension = 2;
    using ImageType = itk::Image<PixelType, Dimension>;
    using ComplexImageType = itk::Image<std::complex<float>, Dimension>;

    ImageType::Pointer itkImage = dynamic_cast<ImageType*>(imageIn.GetITKBase());

    using FFTFilterType = itk::Forward1DFFTImageFilter<ImageType, ComplexImageType>;
    FFTFilterType::Pointer fftFilter = FFTFilterType::New();
    fftFilter->SetInput(itkImage);
    fftFilter->SetDirection(1);  
    fftFilter->Update();

    using ModulusFilterType = itk::ComplexToModulusImageFilter<ComplexImageType, ImageType>;
    ModulusFilterType::Pointer modulusFilter = ModulusFilterType::New();
    modulusFilter->SetInput(fftFilter->GetOutput());
    modulusFilter->Update();
    sitk::Image modulusImage = sitk::Image(modulusFilter->GetOutput());

I am using the debug mode. The speed is fairly slow.

That is a base class. You need to use either VNL or FFTW variant.

You want RelWithDebInfo or Release mode for performance testing. Debug can be very slow.

If you compiled SimpleITK and ITK in debug mode, first compile in release mode to determine if the performance is reasonable.

2 Likes

Thanks. The Release mode is significant faster than debug mode using my old codes. But using built-in method “Forward1DFFTImageFilter” from ITK probably can further speed it up. Do you have any idea why the example codes posted here does not working (the output modulusImage is still the original image)?

Thanks for the reply. The release mode is much faster.

1 Like

Got the stupid error. I cast the wrong image at testing main. Thanks for all helps!

1 Like

For posterity, can you share the approximate speedup you got from using Release mode instead of Debug, and from Forward1DFFTImageFilter over regular ForwardFFT?