I have been trying different parameters, and methods of Fourier transform to remove wave pattern artifacts from my (.tiff) image but was unsuccessful in most instances. I read this wonderful stackoverflow answer but it didn’t help me much. at this point I am confused. How to remove repititve pattern from an image using FFT
image, i am working with Mouse Brain Scan montage
I have tried the code, posted on the aforementioned stackoverflow question including this below code, I had written earlier:
def fourier_masker(image):
dark_image_fourier = np.fft.fftshift(np.fft.fft2(image))
mask_vertical = np.ones_like(dark_image_fourier)
center_col = mask_vertical.shape[1] // 2
mask_vertical[:, center_col-1:center_col+2] = 0
mask_horizontal = np.ones_like(dark_image_fourier)
center_row = mask_horizontal.shape[0] // 2
mask_horizontal[center_row-1:center_row+2, :] = 0
dark_image_fourier *= mask_vertical * mask_horizontal
masked_log_spectrum = np.log(abs(dark_image_fourier) + 1) # Add 1 to avoid log(0)
masked_log_spectrum -= np.min(masked_log_spectrum) # Normalize the spectrum
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.imshow(masked_log_spectrum, cmap='gray')
plt.title('Masked Fourier')
plt.axis('off')
restored_image = np.abs(np.fft.ifft2(np.fft.ifftshift(dark_image_fourier)))
restored_image -= np.min(restored_image)
restored_image /= np.max(restored_image)
plt.subplot(1, 2, 2)
plt.imshow(restored_image, cmap='gray')
plt.title('Transformed Greyscale Image')
plt.axis('off')
plt.show()
I used a grayscale image and its a tiff image.
Absurd Cat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.