Analyze 2-D spatial frequencies
Image and matrix frequency analysis
SciPy · Function
Computes a two-dimensional discrete Fourier transform with SciPy's FFT implementation. It can operate on selected axes of an M-D array and supports configurable sizes and normalization.
fft2 applies the Fast Fourier Transform across two selected axes of an array. By default, it operates on the final two axes; s can crop or zero-pad those axes, while norm selects the normalization convention.
scipy.fft.fft2(x, s=None, axes=(-2, -1), norm=None, overwrite_x=False, workers=None, *, plan=None)| Name | Type | Description |
|---|---|---|
x | array_like | Input array; complex values are allowed. |
s | sequence of ints, optional | Optional output lengths for the transformed axes. Smaller lengths crop the input; larger lengths pad it with zeros. |
axes | sequence of ints, optional | Axes over which to compute the FFT. If omitted, the last two axes are used. |
norm | {“backward”, “ortho”, “forward”}, optional | Normalization mode: backward, ortho, or forward. Defaults to backward. |
overwrite_x | bool, optional | If true, the input contents may be destroyed. Defaults to false. |
workers | int, optional | Maximum number of workers to use for parallel computation. |
plan | object, optional | Reserved for passing a backend-specific plan; currently unused. |
A complex ndarray containing the truncated or zero-padded input transformed along axes, or along the last two axes when axes is omitted.
import numpy as np
from scipy.fft import fft2, ifft2
image = np.eye(4)
spectrum = fft2(image)
reconstructed = ifft2(spectrum)
print(np.allclose(reconstructed, image))Computes a forward 2-D FFT and reconstructs the input with the inverse transform.
Image and matrix frequency analysis
Spectral filtering
Multidimensional arrays
fft2 computes a 2-D discrete Fourier transform using the Fast Fourier Transform. It can also transform any chosen axes of an M-D input array.
Follow-up: How can the transformed dimensions be controlled? Use s to provide the output length for each transformed axis and axes to identify those axes.
With no axes argument, fft2 transforms the last two axes. For an M-D array, this produces a 2-D transform independently across the remaining dimensions.
Follow-up: What happens if s is shorter than the input? The data is cropped along that transformed axis.
The default normalization is backward. The norm argument also accepts ortho and forward, matching the normalization choices documented for fft.
Follow-up: How do you recover the original array? Apply ifft2 with compatible s, axes, and norm settings.
scipy.fft.fftscipy.fft.ifft2scipy.fft.fftn