
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
SciPy - fft2() Function
The scipy.fft.fft2() function gives you the 2D Fast Fourier Transform (FFT) of a 2D array. It changes spatial or time-domain signals into frequency domain data showing the data as a sum of sinusoidal components.
People often use the scipy.fft.fft2() function to look at frequency parts of 2D signals in image processing, pattern recognition, and signal analysis. This method also helps with things like filtering images finding features, and changing frequencies.
The plan parameter in scipy.fft.fft2 allows users to use the precomputed FFT plans to realize better performance for repeating transforms of big datasets, significantly cutting down computation time.
The fft() function calculates the FFT for one-dimensional signals like audio or time-series data, transforming them into the frequency domain. The fft2() approach works with 2D signals like pictures or matrices, examining frequency patterns in two dimensions.
Syntax
The syntax for the SciPy fft2() method is as follows −
.fft2(x, s=None, axes=(-2, -1), norm=None, overwrite_x=False, workers=None, *, plan=None)
Parameters
This method accepts the following parameters −
x (array_like) − Input 2D array to be transformed. It can be real or complex.
s − Shape of the FFT to compute along each axis. If given, the input is either zero-padded or truncated to match the specified shape. Default is the shape of the input array.
axes − Axes over which the FFT is computed. Default is the last two axes (-2, -1) of the input array.
norm − The normalization mode allows control over scaling: "backward" (default, no scaling), "ortho" (unitary scaling for energy preservation), and "forward" (scales the output by 1/n, where n is the transform length).
overwrite_x − If True, allows the input array x to be overwritten for better performance. Default is False.
workers − Number of parallel workers to use for computation. Default is None, meaning a single thread is used.
plan − Precomputed plan for FFT optimization (advanced use). Default is None.
Return Value
y (ndarray) − The transformed 2D array in the frequency domain. The output is complex, containing the amplitude and phase information of the frequency components.
Example 1
This is a basic example of calculating the 2D FFT of a basic 2x2 array using fft2() method and then transforming this array into the frequency domain for evaluating the frequency components of the signal.
import numpy as np from scipy.fft import fft2 # Define a 2D input array x = np.array([[1, 2], [3, 4]]) # Compute the 2D FFT result = fft2(x) print("2D FFT Result:\n", result)
When we run above program, it produces following result
2D FFT Result: [[10.-0.j -2.-0.j] [-4.-0.j 0.-0.j]]
Example 2
This is an example of using zero padding with the 2D FFT to expand the input array to 4x4 form, giving increased frequency resolution and greater extents of frequency analysis in the output.
import numpy as np from scipy.fft import fft2 # Compute 2D FFT with a different shape fft_padded = fft2(x, s=(4, 4)) print("2D FFT with zero-padding:\n", fft_padded)
Following is an output of the above code
2D FFT with zero-padding: [[10.-0.j 4.-6.j -2.-0.j 4.+6.j] [ 3.-7.j -3.-5.j -1.+1.j 5.-1.j] [-4.-0.j -2.+2.j 0.-0.j -2.-2.j] [ 3.+7.j 5.+1.j -1.-1.j -3.+5.j]]
Example 3
The norm parameter controls the scaling of the FFT result, so that the amplitude is represented correctly.
The ortho normalization ensures that the FFT and the inverse FFT scale consistently. This is useful in image processing applications where changes in frequency space need to be reversed to the original spatial domain without distortion.
The below code, first does a 2D FFT with normalization using fft2() method on a sample matrix and then reconstructs the original image with the inverse FFT ifft2() method using the same normalization.
import numpy as np from scipy.fft import fft2, ifft2 a = np.array([[10, 20], [30, 40]]) # Perform FFT with normalization fft_result = fft2(a, norm="ortho") # Inverse FFT with the same normalization reconstructed_image = ifft2(fft_result, norm="ortho") print("Reconstructed Image:\n", reconstructed_image)
Output of the above code is as follows
Reconstructed Image: [[10.-0.j 20.+0.j] [30.+0.j 40.+0.j]]