2

I am trying to find the phase spectrum of an image after applying DFT in python, here is the code i have used. `

import numpy as np
import cv2
from matplotlib import pyplot as plt

img=cv2.imread('/content/drive/My Drive/IP assg2/im1.jpg')

img = cv2.cvtColor(sm1,cv2.COLOR_BGR2GRAY)

dft = cv2.dft(np.float32(img),flags = cv2.DFT_COMPLEX_OUTPUT)

`

I am not sure how to move on from here, as all the tutorials i have come across are related to MATLAB.

1 Answer 1

5

You can try this:

import numpy as np
import cv2
from matplotlib import pyplot as plt

img=cv2.imread('input.png')
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
dft = np.fft.fft2(img)
dft_shift = np.fft.fftshift(dft)
phase_spectrum = np.angle(dft_shift)

ax1 = plt.subplot(1,2,1)
ax1.imshow(img, cmap='gray')

ax2 = plt.subplot(1,2,2)
ax2.imshow(phase_spectrum, cmap='gray')

plt.show()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.