
- 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 - irfft2() Function
SciPy's irfft2() method is using 2-dimensional Inverse Real Fast Fourier Transform for turning frequency-domain data back to real-valued spatial or time domain. This method is designed exclusively for rfft2 data. It only deals with non-redundant positive frequency components for optimal efficiency.
This method is extensively utilized in image processing, reconstruction of 2D signals and scientific computing to convert the frequency-domain data into an interpretable spatial-domain result.
The workers argument supports parallel processing using multiple CPU threads during the transformation. For example, setting workers=4 will distribute the task over four CPU threads.
irfft2() method is often used in combination with rfft2 to perform round-trip transformations, which enable smooth frequency-domain analysis and real-domain reconstruction.
Syntax
The syntax for the SciPy irfft2() method is as follows −
.irfft2(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 array representing real-valued frequency-domain data.
s (sequence of ints, optional) − Shape of the output (number of rows and columns). If not specified, it defaults to the input shape.
axes sequence of ints, optional − Axes over which to compute the inverse FFT. Defaults to the last two axes ((-2, -1)).
norm (str, optional) − 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 (bool, optional) − If True, allows the input array x to be overwritten for better performance. Default is False.
workers (int, optional) − Number of parallel workers to use for computation. Default is None, meaning a single thread is used.
plan (plan, optional) − Reserved for precomputed FFT plans for performance optimization.
Return Value
out ndarray − The result of the inverse real 2-D FFT.
Example 1
The following code takes input frequency-domain data and reconstructs a 2D spatial-domain dataset, with an output shape s=(2, 2). This code demonstrates the basic functionality of irfft2, such as re-creating images or signals from their frequency representations.
import scipy.fft import numpy as np frequency_data = np.array([[8 + 0j, 0 + 0j], [0 + 0j, 0 + 0j]]) spatial_data = scipy.fft.irfft2(frequency_data, s=(2, 2)) print("Reconstructed Spatial Data:", spatial_data)
When we run above program, it produces following result
Reconstructed Spatial Data: [[2. 2.] [2. 2.]]
Example 2
The workers parameter of irfft2() allows to speed up the transformation, employing multiple CPU threads on larger datasets.
This example demonstrates how to use irfft2 to reconstruct a 2D spatial domain from frequency domain input. By specifying workers=2, it means the transformation will be speed up with two CPU threads. Instead of processing the whole dataset sequentially, threads work in parallel, significantly lowering computing time by utilizing several CPU cores.
import scipy.fft import numpy as np frequency_data = np.array([[8 + 0j, 0 + 0j], [0 + 0j, 0 + 0j]]) spatial_data = scipy.fft.irfft2(frequency_data, s=(2, 2), workers=2) print("Reconstructed Spatial Data:", spatial_data)
Following is an output of the above code −
Reconstructed Spatial Data: [[2. 2.] [2. 2.]]
Example 3
The irfft2() method is usually used along with rfft2() to carry out round-trip transforms, converting the data from spatial to the frequency domain and vice versa, maintaining accuracy.
In this code, we make a 2D array for defining a 2D dataset and use the rfft2() operation to convert the data from spatial space to frequency-space representation retaining only the unique positive frequency components. And then, the irfft2() function is used in order to reconstruct the exact original spatial data from a frequency domain representation, to ensure that the reconstructed data is just the same.
import scipy.fft import numpy as np # Define the original spatial domain data data = np.array([[1, 2], [3, 4]]) # Compute the 2D real FFT frequency_data = scipy.fft.rfft2(data) # Compute the inverse 2D real FFT, ensuring correct shape reconstructed_data = scipy.fft.irfft2(frequency_data, s=data.shape) # Use data.shape instead of (2,2) # Print results print("Original Spatial Data:\n", data) print("Reconstructed Spatial Data:\n", reconstructed_data)
Output of the above code is as follows −
Original Spatial Data: [[1 2] [3 4]] Reconstructed Spatial Data: [[1. 2.] [3. 4.]]