Compute Forward FFT In One Dimension#

Synopsis#

Compute forward FFT of an image in one dimension.

Results#

Input image

Input RF Ultrasound Image#

Modulus Image

Output Modulus Image#

Phase Image

Output Phase Image#

Output:

Read real input image of type <class 'itk.itkImagePython.itkImageF2'> and size itkSize2 ([1536, 128])
Padded input image to size itkSize2 ([1536, 128])
Performing FFT along axis 0
Generated complex frequency image of type <class 'itk.itkImagePython.itkImageCF2'> and size itkSize2 ([1536, 128])

Code#

Python#

#!/usr/bin/env python

import itk
import argparse

parser = argparse.ArgumentParser(description="Compute Inverse FFT Of Image.")
parser.add_argument("input_path", nargs=1, type=str)
parser.add_argument("modulus_output_path", nargs=1, type=str)
parser.add_argument("phase_output_path", nargs=1, type=str)
parser.add_argument("fft_direction", nargs="?", default=0, type=int)
args = parser.parse_args()

# Read input image
pixel_type = itk.F
image = itk.imread(args.input_path[0], pixel_type=pixel_type)
print(f"Read real input image of type {type(image)} and size {itk.size(image)}")

assert (
    args.fft_direction < image.GetImageDimension()
), "FFT direction must be an image dimension"

# Perform FFT in given direction
padded_image = itk.fft_pad_image_filter(image)
print(f"Padded input image to size {itk.size(image)}")
print(f"Performing FFT along axis {args.fft_direction}")
complex_image = itk.forward1_dfft_image_filter(image, direction=args.fft_direction)
print(
    f"Generated complex frequency image of type {type(complex_image)} and size {itk.size(complex_image)}"
)

# Shift image along FFT dimension to represent complex range (-f_B, +f_B]
shift = [0] * complex_image.GetImageDimension()
shift[args.fft_direction] = int(itk.size(complex_image)[args.fft_direction] / 2)
shift = [int(itk.size(complex_image)[args.fft_direction] / 2), 0]
shifted_image = itk.cyclic_shift_image_filter(complex_image, shift=shift)

# Write out modulus and phase images for visualization in PNG format
modulus_image = itk.complex_to_modulus_image_filter(shifted_image)
itk.imwrite(modulus_image, args.modulus_output_path[0])

phase_image = itk.complex_to_phase_image_filter(shifted_image)
itk.imwrite(phase_image, args.phase_output_path[0])

Classes demonstrated#

template<typename TInputImage, typename TOutputImage = TInputImage>
class FFTPadImageFilter : public itk::PadImageFilterBase<TInputImage, TInputImage>

Pad an image to make it suitable for an FFT transformation.

FFT filters usually requires a specific image size. The size is decomposed in several prime factors, and the filter only supports prime factors up to a maximum value. This filter automatically finds the greatest prime factor required by the available implementation and pads the input appropriately.

This code was adapted from the Insight Journal contribution [66].

Author

Gaetan Lehmann

See

FFTShiftImageFilter

See itk::FFTPadImageFilter for additional documentation.
template<typename TInputImage, typename TOutputImage = Image<std::complex<typename TInputImage::PixelType>, TInputImage::ImageDimension>>
class Forward1DFFTImageFilter : public itk::ImageToImageFilter<TInputImage, Image<std::complex<typename TInputImage::PixelType>, TInputImage::ImageDimension>>

Perform the Fast Fourier Transform, in the forward direction, with real inputs, but only along one dimension.

Forward1DFFTImageFilter implements methods for generating output information and relies on the ITK object factory to select a viable backend to generate data. Forward1DFFTImageFilter does not itself implement FFT.

See

itkVnlForward1DFFTImageFilter

See

itkFFTWForward1DFFTImageFilter

Subclassed by itk::FFTWForward1DFFTImageFilter< TInputImage, TOutputImage >, itk::VnlForward1DFFTImageFilter< TInputImage, TOutputImage >

See itk::Forward1DFFTImageFilter for additional documentation.
template<typename TInputImage, typename TOutputImage = TInputImage>
class CyclicShiftImageFilter : public itk::ImageToImageFilter<TInputImage, TInputImage>

Perform a cyclic spatial shift of image intensities on the image grid.

This filter supports arbitrary cyclic shifts of pixel values on the image grid. If the Shift is set to [xOff, yOff], the value of the pixel at [0, 0] in the input image will be the value of the pixel in the output image at index [xOff modulo xSize, yOff modulo ySize] where xSize and ySize are the sizes of the image in the x and y dimensions, respectively. If a pixel value is moved across a boundary, the pixel value is wrapped around that boundary. For example, if the image is 40-by-40 and the Shift is [13, 47], then the value of the pixel at [0, 0] in the input image will be the value of the pixel in the output image at index [13, 7].

Negative Shifts are supported. This filter also works with images whose largest possible region starts at a non-zero index.

See itk::CyclicShiftImageFilter for additional documentation.
template<typename TInputImage, typename TOutputImage>
class ComplexToModulusImageFilter : public itk::UnaryGeneratorImageFilter<TInputImage, TOutputImage>

Computes pixel-wise the Modulus of a complex image.

See itk::ComplexToModulusImageFilter for additional documentation.
template<typename TInputImage, typename TOutputImage>
class ComplexToPhaseImageFilter : public itk::UnaryGeneratorImageFilter<TInputImage, TOutputImage>

Computes pixel-wise the modulus of a complex image.

See itk::ComplexToPhaseImageFilter for additional documentation.