How to transform a FFT (Fast Fourier Transform) into a Polar Transformation with Python? How to transform a FFT (Fast Fourier Transform) into a Polar Transformation with Python? numpy numpy

How to transform a FFT (Fast Fourier Transform) into a Polar Transformation with Python?


This is roughly solution to you problem; It was tested on one sample image, and the result looks credible.

# your code goes here... def transform_data(m):    dpix, dpiy = m.shape    x_c, y_c = np.unravel_index(np.argmax(m), m.shape)    angles = np.linspace(0, np.pi*2, min(dpix, dpiy))    mrc = min(abs(x_c - dpix), abs(y_c - dpiy), x_c, y_c)    radiuses = np.linspace(0, mrc, max(dpix, dpiy))    A, R = np.meshgrid(angles, radiuses)    X = R * np.cos(A)    Y = R * np.sin(A)    return A, R, m[X.astype(int) + mrc - 1, Y.astype(int) + mrc - 1]    angles, radiuses, m = transform_data(magnitude_spectrum)    plt.contourf(angles, radiuses, m)

enter image description here

Finally, we can get the angle we want to turn the original image:

sample_angles = np.linspace(0,  2 * np.pi, len(c.sum(axis=0))) / np.pi*180turn_angle_in_degrees = 90 - sample_angles[np.argmax(c.sum(axis=0))]

For my sample image I got:

turn_angle_in_degrees = 3.2015810276679844 degrees.

Also, we can plot projected spectrum magnitude:

plt.plot(sample_angles, c.sum(axis=0))

enter image description here

Hope that helps...