傅立叶变换逆傅立叶变换python

时间:2020-01-19 17:20:13

标签: python opencv signal-processing fft

我已经将狗的图片解构成其大小和相位分量。但是,当我将它们放回去并尝试进行傅立叶逆变换时,我没有得到原始图像吗?

img1 = img1[:,:,2] 

plt.imshow(img1, cmap='gray')

plt.show()

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

print(dft)

dft_shift = np.fft.fftshift(dft)

print(dft_shift)

mag, ang = cv2.cartToPolar(dft_shift[:,:,0],dft_shift[:,:,1])

plt.imshow(20*np.log(mag), cmap='gray')

plt.show()

plt.imshow(ang, cmap='gray')

plt.show()

combined = np.multiply(mag, np.exp(1j*ang))

imgCombined = np.real(np.fft.ifft2(np.fft.ifftshift(combined)))

plt.imshow(imgCombined, cmap='gray')

plt.show()

固定!

def compute_mag_phase(toBeTransfromed):
    dft = np.fft.fft2(toBeTransfromed)
    dft_shift = np.fft.fftshift(dft)
    mag = np.abs(dft_shift)
    ang = np.angle(dft_shift)
    return mag, ang

def reconstruct(mag,ang):
    combined = np.multiply(mag, np.exp(1j*ang))
    fftx = np.fft.ifftshift(combined)
    ffty = np.fft.ifft2(fftx)
    imgCombined = np.abs(ffty)
    return imgCombined

幅度:

magnitude

角度:

angle

重建:

reconstructed

0 个答案:

没有答案