Issue
So currently I'm trying to wrap my head around the fourier transform (in 2D). I wanted to fourier transform an image and return back in only the magnitude spectrum just like this topic on this site:
https://dsp.stackexchange.com/questions/16995/image-reconstructionphase-vs-magnitude
However my image (using spyder ide) comes out like this with some weird artificant in the middle, using the same image from the link above.
original image:
Magnitude spectrum:
The code that I'm using is in python using numpy (np), OpenCV and Matplotlib:
import numpy as np
import cv2
from matplotlib import pyplot as plt
from os import listdir
from os.path import isfile, join
image1 = cv2.imread("Images/test2.png", 0)
fourier = np.fft.fft2(image1)
magnitude = abs(fourier)
inverse = np.fft.ifftshift(np.fft.ifft2(magnitude))
plt.subplot(), plt.imshow(np.uint8(inverse), cmap='gray')
plt.title(''), plt.xticks([]), plt.yticks([])
plt.show()
What am I doing wrong?
Update: added imports
Solution
You can try changing the np.uint8
to np.abs
. Since you want clipping above 255 and not modulus you should do something like this:
inverse = np.fft.ifftshift(np.fft.ifft2(magnitude))
inv = np.abs(inverse)
inv[inv > 255] = 255
plt.subplot(), plt.imshow(inv, cmap='gray')
Answered By - Aguy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.