【问题标题】:Fourier transform inverse fourier transform python傅里叶变换 傅里叶逆变换 python
【发布时间】:2020-01-19 17:20:13
【问题描述】:

我已将狗的图片解构为其幅度和相位分量。但是,当我将它们重新组合在一起并尝试进行傅里叶逆变换时,我没有得到原始图像?

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

幅度:

角度:

重构:

【问题讨论】:

  • 我没有看到您在 Birol Kuyumcu 的文档链接中提到了您的 dft_scale。如果您发布您的输入狗图像,以便其他人可以测试您的代码并显示您的代码以读取您的图像,这也会很有帮助。请参阅此论坛帮助部分,了解如何提供最低限度的可重现和可验证的代码。

标签: python opencv signal-processing fft


【解决方案1】:

fftshift 反转了dft_shift 的第三维。 以下似乎有效

dft_real = np.fft.fftshift(dft[:, :, 0])
dft_imag = np.fft.fftshift(dft[:, :, 1])
mag, ang = cv2.cartToPolar(dft_real, dft_imag)

【讨论】:

  • @Jamie Thompson,如果这没有帮助,请告诉我...
  • 抱歉回复晚了,看来确实如此。我最终停止使用 carToPolar:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-12
  • 2021-05-25
  • 1970-01-01
  • 1970-01-01
  • 2021-05-18
相关资源
最近更新 更多