我想把一幅图像的相位谱和不同图像的幅值谱组合成一幅图像。
我得到了图像A和图像B的相位谱和幅值谱。
这是密码。
f = np.fft.fft2(grayA)
fshift1 = np.fft.fftshift(f)
phase_spectrumA = np.angle(fshift1)
magnitude_spectrumB = 20*np.log(np.abs(fshift1))
f2 = np.fft.fft2(grayB)
fshift2 = np.fft.fftshift(f2)
phase_spectrumB = np.angle(fshift2)
magnitude_spectrumB = 20*np.log(np.abs(fshift2))我想弄清楚,但我还是不知道该怎么做。
下面是我的测试代码。
imgCombined = abs(f) * math.exp(1j*np.angle(f2))我真希望我能这样出来

发布于 2018-09-14 18:21:35
为了使代码按预期工作,您需要修复以下几点:
math.exp函数支持标量指数。对于按元素计算的矩阵指数,您应该使用numpy.exp代替。*算子将尝试执行矩阵乘法。在您的例子中,您希望执行按元素方向的乘法,这可以用np.multiply来完成。通过这些修复,您应该得到频域组合矩阵如下:
combined = np.multiply(np.abs(f), np.exp(1j*np.angle(f2)))要获得相应的空域图像,则需要计算反变换(并取实数部分,因为存在数值误差导致的残差小虚部):
imgCombined = np.real(np.fft.ifft2(combined))最后,可以用以下方法显示结果:
import matplotlib.pyplot as plt
plt.imshow(imgCombined, cmap='gray')

请注意,imgCombined可能包含[0,1]范围以外的值。然后,您需要决定如何重新分配这些值,以适应预期的[0,1]范围。
imgCombined = np.abs(imgCombined)获取绝对值。

https://stackoverflow.com/questions/52312053
复制相似问题