VPI - Vision Programming Interface

0.3.7 Release

Image Inverse FFT

Overview

Image Inverse FFT implements the inverse Fourier Transform for 2D images, supporting real- and complex-valued outputs. Given a 2D spectrum (frequency domain), it returns the image representation on the spatial domain. It is the exact inverse of Image FFT algorithm.

Input as a magnitude spectrum Output in spatial domain

Implementation

The inverse Fast Fourier Transform follows closely forward FFT's implementation, except for the sign of the exponent, which is positive here.

\[ I[m,n] = \frac{1}{MN} \sum^{M-1}_{u=0} \sum^{N-1}_{v=0} I'[u,v] e^{+2\pi i (\frac{um}{M}+\frac{vn}{N})} \]

Where:

  • \(I'\) is the input image in frequency domain
  • \(I\) is its spatial domain representation
  • \(M\times N\) is input's dimensions

The normalization factor \(\frac{1}{MN}\) is applied by default to make IFFT an exact inverse of FFT. As this incurs in a performance hit and normalization might not be needed, user can pass the flag VPI_IFFT_DENORMALIZED to vpiSubmitImageIFFT to indicate that output must be left denormalized.

As with direct FFT, depending on \(N\), different techniques are employed for best performance:

  • CPU backend
    • Fast paths when \(N\) can be factored into \(2^a \times 3^b \times 5^c\)
  • CUDA backend
    • Fast paths when \(N\) can be factored into \(2^a \times 3^b \times 5^c \times 7^d\)

In general the smaller the prime factor is, the better the performance, i.e., powers of two are fastest.

Image IFFT supports the following transform types:

  • complex-to-complex, C2C
  • complex-to-real, C2R.

Data Layout

Data layout depends strictly on the transform type. In case of general C2C transform, both input and output data shall be of type VPI_IMAGE_TYPE_2F32 and have the same size. In C2R mode, each input image row \((X_1,X_2,\dots,X_{\lfloor\frac{N}{2}\rfloor+1})\) of type VPI_IMAGE_TYPE_2F32 containing only non-redundant values results in row \((x_1,x_2,\dots,x_N)\) with type VPI_IMAGE_TYPE_F32 representing the whole image. In both cases, input and output image heights are the same.

Usage

  1. Initialization phase
    1. Include the header that defines the inverse FFT functions.
    2. Define the stream on which the algorithm will be executed and the input spectrum image. Since we're performing a C2R IFFT, the input width must be \(\lfloor \frac{w}{2} \rfloor+1\), where \(w\) is the output image width. Input and output heights must match.
      VPIStream stream = /*...*/;
      VPIImage input = /*...*/;
    3. Create the output image. Again, because of C2F IFFT, the output type must be VPI_IMAGE_TYPE_F32. We're passing 0 as flags to make the function return a normalized output.
      VPIImage output;
      vpiImageCreate(w, h, VPI_IMAGE_TYPE_F32, 0, &output);
    4. Create the ImageIFFT payload. Input is complex and output is real. Problem size refers to output size.
  2. Processing phase
    1. Submit the IFFT algorithm to the stream, passing the input spectrum and the output buffer.
      vpiSubmitImageIFFT(ifft, input, output, 0);
    2. Wait until the processing is done.
      vpiStreamSync(stream);
    3. Now display output using your preferred method.

For more details, consult the API reference.

Limitations and Constraints

Constraints for specific backends supersede the ones specified for all backends.

All Backends

CPU

  • If output has type VPI_IMAGE_TYPE_F32, its width must be even.
  • Input and output rows must be aligned to 4 bytes.

CUDA

  • There can be memory allocation in first call to vpiSubmitImageIFFT and every time the input or output row stride changes with respect to previous call.

PVA

  • Not implemented.

Performance

For further information on how performance was benchmarked, see Performance Measurement.

Jetson AGX Xavier
sizetypenorm.CPUCUDAPVA
1920x1080C2Ryes 6.3 ms0.9757 msn/a
1920x1080C2Rno 6.15 ms0.8162 msn/a
1920x1080C2Cyes 16.4 ms1.5193 msn/a
1920x1080C2Cno 14.5 ms1.2645 msn/a
1024x1024C2Ryes 5.2 ms0.2779 msn/a
1024x1024C2Rno 4.57 ms0.1977 msn/a
1024x1024C2Cyes 8.5 ms0.6150 msn/a
1024x1024C2Cno 7.4 ms0.4587 msn/a
626x626C2Ryes 34.1 ms0.466 msn/a
626x626C2Rno 34.1 ms0.4295 msn/a
626x626C2Cyes 67.5 ms0.8276 msn/a
626x626C2Cno 66.7 ms0.774 msn/a
Jetson TX2
sizetypenorm.CPUCUDAPVA
1920x1080C2Ryes 17.07 ms3.05 msn/a
1920x1080C2Rno 16.93 ms2.485 msn/a
1920x1080C2Cyes 55.8 ms5.065 msn/a
1920x1080C2Cno 51.9 ms4.21 msn/a
1024x1024C2Ryes 11.99 ms1.178 msn/a
1024x1024C2Rno 11.85 ms0.907 msn/a
1024x1024C2Cyes 41.5 ms1.888 msn/a
1024x1024C2Cno 39.59 ms1.51 msn/a
626x626C2Ryes 74.5 ms1.589 msn/a
626x626C2Rno 74.4 ms1.454 msn/a
626x626C2Cyes 148.1 ms3.065 msn/a
626x626C2Cno 147.1 ms2.89 msn/a
Jetson Nano
sizetypenorm.CPUCUDAPVA
1920x1080C2Ryes 34.31 ms6.964 msn/a
1920x1080C2Rno 34.04 ms5.723 msn/a
1920x1080C2Cyes 85.5 ms12.26 msn/a
1920x1080C2Cno 87.5 ms10.456 msn/a
1024x1024C2Ryes 21.4 ms2.491 msn/a
1024x1024C2Rno 21.29 ms1.916 msn/a
1024x1024C2Cyes 70.4 ms4.068 msn/a
1024x1024C2Cno 63.8 ms3.062 msn/a
626x626C2Ryes 171 ms3.602 msn/a
626x626C2Rno 171 ms3.352 msn/a
626x626C2Cyes 343 ms6.659 msn/a
626x626C2Cno 342 ms6.292 msn/a
VPI_IMAGE_TYPE_2F32
@ VPI_IMAGE_TYPE_2F32
2 interleaved channels of 32-bit floats.
Definition: Types.h:216
ImageIFFT.h
vpiStreamSync
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
VPIStream
struct VPIStreamImpl * VPIStream
A handle to a stream.
Definition: Types.h:177
vpiSubmitImageIFFT
VPIStatus vpiSubmitImageIFFT(VPIPayload payload, VPIImage input, VPIImage output, uint32_t flags)
Runs IFFT on single image.
VPIImage
struct VPIImageImpl * VPIImage
A handle to an image.
Definition: Types.h:183
VPIPayload
struct VPIPayloadImpl * VPIPayload
A handle to an algorithm payload.
Definition: Types.h:195
vpiImageCreate
VPIStatus vpiImageCreate(uint32_t width, uint32_t height, VPIImageType type, uint32_t flags, VPIImage *img)
Create an empty image instance with the specified flags.
vpiCreateImageIFFT
VPIStatus vpiCreateImageIFFT(VPIStream stream, uint32_t outputWidth, uint32_t outputHeight, const VPIImageType inType, const VPIImageType outType, VPIPayload *payload)
Creates payload for vpiSubmitImageIFFT.
VPI_IMAGE_TYPE_F32
@ VPI_IMAGE_TYPE_F32
1 channel of 32-bit float.
Definition: Types.h:215