I have a noisy image with a particular pattern and I want to remove the pattern. If I save the fft to a png image and do inverse FFT on it I get a blank image.
I have this python code that computes FFT:
import cv2
import numpy as np
import matplotlib.pyplot as plt
# Load the image
image_path = '/home/gras/Downloads/archive(1)/demo_2.jpg' # Update this with your image path
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# Perform Fourier Transform
f_transform = np.fft.fft2(image)
f_transform_shifted = np.fft.fftshift(f_transform)
magnitude_spectrum = 20 * np.log(np.abs(f_transform_shifted))
# Save the Fourier transform magnitude spectrum as an image
output_path = './fourier_transform_magnitude_spectrum.png'
cv2.imwrite(output_path, magnitude_spectrum)
And this code that does Inverse FFT:
# Load the Fourier transformed image
fourier_image_path = './fourier_transform_magnitude_spectrum.png' # Update this with your Fourier-transformed image path
fourier_image = cv2.imread(fourier_image_path, cv2.IMREAD_GRAYSCALE)
# Perform inverse Fourier Transform
f_transform_shifted = np.fft.ifftshift(fourier_image)
f_transform = np.fft.ifft2(f_transform_shifted)
reconstructed_image = np.abs(f_transform)
# Plot the reconstructed image
plt.figure(figsize=(8, 8))
plt.imshow(fourier_image, cmap='gray', vmin=0, vmax=255) # Specify vmin and vmax
plt.title('Reconstructed Image')
plt.axis('off')
plt.show()
The plotted image appears as blank, and the saved FFT image is much brighter than it is shown in the plot.
How do I fix this?