
- 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 - ifft2() Function
The scipy.fft.ifft2() method performs 2D inverse discrete Fourier transform (IDFT) for any given 2D array, using the FFT method. It transforms data from the frequency domain to a spatial or time domain.
The following is an example that uses any input array, x. ifft2(fft2(x)) restores the original array and in numerical accuracy. In other words, this is multidimensional data, maximized in performance and accuracy.
The ifft2 function is widely used in any application that requires the analysis and reconstruction of 2D signals such as image processing, filtering, and audio spectrograms.
The ifft2() method returns the inverse FFT for 2D arrays, making it appropriate for images and 2D signals. In contrast, the ifft() method can use 1D arrays, for example time series or audio signals, to carry out analogous transformations in one dimension.
In the real-world scenario, this method proved to be effective in getting rid of high-frequency noises by using FFT for analysis, and IFFT for the reconstruction process, as well as compressing images that reject less relevant frequencies in frequency domain and restore the data using IFFT.
Syntax
The syntax for the SciPy ifft2() method is as follows −
.ifft2(x, s=None, axes=(-2, -1), norm=None, overwrite_x=False, workers=None, *, plan=None)
Parameters
This method accepts the following parameters −
x − Input 2D array (can be complex) representing frequency domain data.Shape of the output along each axis. Pads with zeros or truncates the input. If not specified, the input shape is used.
s − Shape of the output along each axis. Pads with zeros or truncates the input. If not specified, the input shape is used.
axes − Axes over which to compute the inverse FFT. Defaults to the last two axes.
norm − The normalization mode for IFFT 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 modifying the input array for memory efficiency. Default is False.
workers − Number of workers for parallel computation. Defaults to using all available cores.
plan − A precomputed plan for FFT, used to optimize repetitive computations. Not actively used in standard SciPy FFT.
Return Value
out(complex ndarray) The reconstructed 2D array in the spatial domain (real values represent the signal).
Example 1
This is the basic example of ifft2() method where we compute the inverse FFT for identity matrix. Following is the code −
import numpy as np import scipy.fft from scipy.fft import ifft2 # Create a 2D identity matrix x = 4 * np.eye(4) # Compute the 2D Inverse FFT result = scipy.fft.ifft2(x) print("Inverse FFT Result:\n", result)
When we run above program, it produces following result
Inverse FFT Result: [[1.-0.j 0.+0.j 0.-0.j 0.-0.j] [0.+0.j 0.+0.j 0.+0.j 1.-0.j] [0.-0.j 0.-0.j 1.-0.j 0.+0.j] [0.-0.j 1.+0.j 0.-0.j 0.-0.j]]
Example 2
This code demonstrates the application of a low-pass filter to a 2D signal, retaining only the low-frequency components and setting the rest to zero.
In below code, freq_signal[1:, 1:] = 0. ensures that only the first frequency (low-frequency corner) is retained and higher frequencies are deleted. The filtered signal is then reconstructed by the inverse FFT ifft2, showing how removing high frequencies smooths down the data.
import numpy as np from scipy.fft import fft2, ifft2 # Create a simple 2D signal signal = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) # Transform to frequency domain freq_signal = fft2(signal) # Apply a low-pass filter (keep only low frequencies) freq_signal[1:, 1:] = 0 # Reconstruct the filtered signal reconstructed = ifft2(freq_signal).real print("Filtered Signal:\n", reconstructed)
Following is an output of the above code −
Filtered Signal: [[ 1. 2. 3. 4.] [ 5. 6. 7. 8.] [ 9. 10. 11. 12.] [13. 14. 15. 16.]]
Example 3
This code shows the compression of an image by retaining only the low-frequency components of a two-dimensional image in the frequency domain. It sets the higher frequency components (responsible for finer details) to zero.
The image is then reconstituted using ifft2(), which displays how much of the original image can be represented by only the low frequencies.
import numpy as np from scipy.fft import fft2, ifft2 # Create a small 2D image image = np.random.rand(4,4) # Transform to frequency domain freq_image = fft2(image) # Keep only low frequencies (compress) compressed_freq = np.zeros_like(freq_image) compressed_freq[:4, :4] = freq_image[:4, :4] # Reconstruct the compressed image compressed_image = ifft2(compressed_freq).real print("Compressed Image:\n", compressed_image)
Output of the above code is as follows
Compressed Image: [[0.90369036 0.12522491 0.31535467 0.98059885] [0.28058477 0.74990898 0.79490161 0.35299132] [0.47120366 0.35896801 0.21072606 0.08047562] [0.18525763 0.72736845 0.68369767 0.47155035]]