2D Discrete Fourier Transform of Images

The following nodes are provided to compute a 2D Discrete Fourier Transform (2D DFT) of an image and its inverse:
  • ImageProcessing.Compute.Transform.Fourier
  • ImageProcessing.Compute.Transform.FourierInverse
The example Fourier2D demonstrates the basic usage of these nodes.

ImageProcessing.Compute.Transform.Fourier

This node computes the 2D Fast Fourier Transform (2D FFT) of an image $\mathrm{f}[x,y]$ with width $S_x$ and height $S_y$ by:

$\mathrm{F}[u, v] = \sum\limits_{y=0}^{S_y-1} \left( \sum\limits_{x=0}^{S_x-1} \mathrm{f}[x,y] \, e^{-2 \pi i \frac{x\, u}{S_x} } \,\right) \, e^{-2 \pi i \frac{y\, v}{S_y} } \quad \quad \forall \, \, u \times v \in [0;S_x-1] \times [0;S_y-1] \quad.$
The resulting complex 2D FFT function $\mathrm{F}[u, v]$ has the same size as the input image and its real and imaginary parts are stored in the red and green channel of the output image.
For convinience, the FFT image is shifted such that $\mathrm{F}[0, 0]$ is afterwards located at the middle of the output image, which makes applying a filtering function easier. The shifting operation is achieved by:
$\mathrm{F}'[u, v] = \mathrm{F}[(u + \frac{S_x}{2}) \bmod S_x, (v + \frac{S_y}{2}) \bmod S_y] \quad.$
The shifted FFT image $\mathrm{F}'[u, v]$ is available at the FFT output slot.
The floating point output of the 2D FFT is typically not in the range of RGBA color values, which is [0.0, 1.0]. To obtain a suitable visualization, it is often necessary to scale the FFT values such that they populate the displayable range of [0.0, 1.0] (see also MagnitudePhase).
The 2D Fast Fourier Transform can only be computed if the width and height of the image are both a power of two (e.g., 2, 4, 8, 16, 32, 64, etc.).

ImageProcessing.Compute.Transform.FourierInverse

This node computes the 2D Inverse Fast Fourier Transform (2D IFFT) by:

$\mathrm{f}[x,y] = \frac{1}{S_x \, S_y} \sum\limits_{u=0}^{S_x-1} \left( \sum\limits_{v=0}^{S_y-1} \mathrm{F}[u, v] \, e^{2 \pi i \, \frac{n\, v}{S_y}} \right) \, e^{2 \pi i \, \frac{n\, u}{S_x} } \quad \quad \forall \, \, x \times y \in [0;S_x-1] \times [0;S_y-1] \quad.$
The complex 2D FFT function $\mathrm{F}[u, v]$ must be provided as an image with width $S_x$ and height $S_y$. Thereby the real parts must be stored in the red channel and the imaginary parts in the green channel of the image.
The FFT input slot expects an shifted FFT $\mathrm{F}'[u, v]$ as generated by the forwards 2D FFT above. Therefore, before applying the inverse 2D FFT the values are shifted back with
$\mathrm{F}[u, v] = \mathrm{F}'[(u + \frac{S_x}{2}) \bmod S_x, (v + \frac{S_y}{2}) \bmod S_y] \quad.$
The inverse 2D Fast Fourier Transform can only be computed if the width $S_x$ and height $S_y$ of the input image are both a power of two (e.g., 2, 4, 8, 16, 32, 64, etc.).

ImageProcessing.Compute.Transform.MagnitudePhase

This node converts the complex output of a 2D Fast Fourier Transform (2D FFT) with a real and imaginary part to a magnitude and phase representation.
The complex 2D FFT function $\mathrm{F}[u, v]$ must be provided as in image at the FFT input slot. Thereby the real part $\mathrm{r}[x,y]$ of the function must be stored in the red channel and the imaginary part $\mathrm{i}[x,y]$ in the green channel of the image.
The magnitude values are typically not in the range of RGBA color values, which is [0.0, 1.0]. To obtain a suitable visualisation it is often necessary to scale the magnitude values such that they populate the displayable range of [0.0, 1.0]. This can be achieved with a scaling value $s$ that can be set via the magnitude scale input slot.
The format of the magnitude signal $\mathrm{m}[x,y]$ can be selected via the format input slot:
  • Format = 0: (standard)
    $\mathrm{m}[x,y] = s \, \sqrt{\mathrm{r}[x,y]^2 + \mathrm{i}[x,y]^2} $
  • Format = 1: (dB)
    $\mathrm{m}[x,y] = 20.0 \, s \, \log \left(\sqrt{\mathrm{r}[n]^2 + \mathrm{i}[n]^2}\right) $
  • Format = 2: (normalized)
    $\mathrm{m}[x,y] = \frac{s}{S_x \, S_y} \,\sqrt{\mathrm{r}[n]^2 + \mathrm{i}[n]^2} $
    where $S_x$ and $S_y$ are the width and height of the input image.

The phase signal $\mathrm{p}[x,y]$ is computed by:

$\mathrm{p}[x,y] = \begin{cases} \operatorname{atan2}(\mathrm{i}[x,y], \mathrm{r}[x,y]) & : |\mathrm{r}[x,y]| \ge t \, \lor \, |\mathrm{i}[x,y]| \ge t \\ 0 & : |\mathrm{r}[x,y]| < t \, \land \, |\mathrm{i}[x,y]| < t\\ \end{cases}$
The threshold $t$ can be set via the phase threshold input slot. If the absolute values of the real and imaginary part are below this threshold, the phase is set to zero.
Furthermore, the phase values $\mathrm{p}[x,y]$, which are in range [-$\pi$/2, $\pi$/2], are modified such that they are in the displayable range [0.0, 1.0] of an image by
$\mathrm{p}'[x,y] = \frac{ \mathrm{p}[x,y]}{\pi} + 0.5 $