fft2
→Tensorfft2(input: Tensor, s: Sequence[int] | None = None, dim: Sequence[int] = (-2, -1), norm: str | None = None)2-D discrete Fourier transform over a pair of axes.
Computes the two-dimensional DFT of the input tensor by applying
fft along the two axes specified by dim (default: the
last two axes). For an input array, the 2-D DFT
is:
where and .
This is equivalent to calling fftn(input, s=s, dim=dim, norm=norm)
with a two-element dim — it is provided as a convenience for the
common case of 2-D signals such as images or spatial fields.
Parameters
inputTensorssequence of int= None(M_out, N_out) along each transformed axis.
The input is zero-padded or truncated to this size before the
transform. len(s) must be 2 when given. If None, the
axes are transformed at their current sizes.dimsequence of int= (-2, -1)(-2, -1) (the last two axes).normstr or None= None"backward" (default), "forward", or
"ortho". in the scaling formula is the product
.Returns
TensorComplex tensor (complex64) with the same shape as input
except that the two transformed axes have lengths s[0] and
s[1] (or the original axis sizes when s is None).
Notes
Spatial frequency interpretation — in image processing, the
2-D DFT maps a spatial image to its spatial-frequency
content . The bin is the
DC component (average pixel value times ). Radial distance
from the origin in the frequency plane corresponds to spatial frequency
magnitude; fftshift is typically applied before displaying the
spectrum so that low frequencies sit at the centre.
Separability — the 2-D DFT is separable: the row-wise 1-D DFTs followed by the column-wise 1-D DFTs yield the same result as a single 2-D DFT. The engine exploits this to run two passes of the 1-D algorithm.
Examples
2-D DFT of a real image-like tensor:
>>> x = lucid.randn(64, 64)
>>> X = lucid.fft.fft2(x)
>>> X.shape
(64, 64)
Zero-pad to a larger grid for spectral interpolation:
>>> X_padded = lucid.fft.fft2(x, s=[128, 128])
>>> X_padded.shape
(128, 128)
Centre the spectrum for visualisation:
>>> X_shifted = lucid.fft.fftshift(lucid.fft.fft2(x))