gpt4 book ai didi

python - 仅幅度重建看起来不正确,我的解释正确吗?

转载 作者:太空宇宙 更新时间:2023-11-03 14:11:09 25 4
gpt4 key购买 nike

我已经实现了“从非周期对象的傅立叶变换幅度进行相位检索”论文中的方法,可在:https://pdfs.semanticscholar.org/4796/592751aaa5b316aaefbd5eab09ca51fad580.pdf

作者通过过采样重建对象,然后使用 HIO 迭代过程后的幅度。

阅读论文的图形部分指出:“通过过采样从复值对象的傅立叶变换幅度进行图像重建的示例;”

当我仅使用幅度进行重建时,我得到的看起来像空白图像。我这样做正确吗?我是否误解了论文的含义?

import matplotlib.pyplot as plt
import numpy as np
import scipy.ndimage as nd

img = nd.imread("einstein.bmp", flatten=True)

numIters = 500

# Pad image to simulate oversampling
initSize = img.shape
pad_len = 64
padded = np.pad(img, ((pad_len, pad_len), (pad_len, pad_len)), 'constant')

# Get initial magnitude
targetImg = np.fft.fftshift(np.fft.fft2(padded))
F_mag = np.abs(targetImg)
# Save for plotting later
startMag = np.abs(np.fft.ifft2(np.fft.ifftshift(F_mag)))
startPhase = np.angle(targetImg)

# keep track of where the image is vs the padding
mask = np.ones((initSize[0], initSize[1]))
mask = np.pad(mask, ((pad_len, pad_len), (pad_len, pad_len)), 'constant')

# Paper uses random phase for phase, adding noise here
noise = np.random.normal(0,1.5,(initSize[0], initSize[1]))
noise = np.pad(noise, ((pad_len, pad_len), (pad_len, pad_len)), 'constant')
source = F_mag * np.exp(1j * (startPhase + noise))

# Shift first then transform for inverse
imgWithNoise = np.abs(np.fft.ifft2(np.fft.ifftshift(source))) * mask
sourceImg = np.abs(np.fft.ifft2(np.fft.ifftshift(source))) * mask

# Test for proper image
# imgplot = plt.imshow(sourceImg)
# plt.show()

beta=0.8
for i in range(numIters):
print "Progress on: " + str(i) + " Of " + str(numIters)
G_k = np.fft.fftshift(np.fft.fft2(sourceImg))
G_k_phase = np.angle(G_k)
G_k_prime = F_mag * np.exp(1j*G_k_phase)
g_k_prime = np.fft.ifft2(np.fft.ifftshift(G_k_prime))

# In support i.e non negative real and imaginary
real_g_k = np.real(g_k_prime)
imag_g_k = np.imag(g_k_prime)
# x_e_S = np.where(((real_g_k > 0) & (imag_g_k > 0)))
x_e_notS = np.where(((real_g_k <= 0) & (imag_g_k <= 0) & (mask == 1)) | (mask == 0))

tmp = g_k_prime
beta_g_k_prime = beta * g_k_prime[x_e_notS]
tmp[x_e_notS] = sourceImg[x_e_notS] - beta_g_k_prime
sourceImg = tmp

G_k = np.fft.fftshift(np.fft.fft2(sourceImg))
finalMag = np.abs(G_k)
finalMagImg = np.abs(np.fft.ifft2(np.fft.ifftshift(finalMag)))

# Show magnitude plot
plt.subplot(231),plt.imshow(padded)
plt.title('Input Image'), plt.xticks([]), plt.yticks([])
plt.subplot(232),plt.imshow(np.abs(imgWithNoise))
plt.title('Image with Noise'), plt.xticks([]), plt.yticks([])
plt.subplot(233),plt.imshow(np.abs(sourceImg))
plt.title('Image after HIO'), plt.xticks([]), plt.yticks([])
plt.subplot(234),plt.imshow(startMag)
plt.title('Start Magnitude Spectrum'), plt.xticks([]), plt.yticks([])
plt.subplot(235),plt.imshow(finalMagImg)
plt.title('End Magnitude Spectrum Img'), plt.xticks([]), plt.yticks([])
plt.subplot(236),plt.imshow(finalMag)
plt.title('End Magnitude Spectrum'), plt.xticks([]), plt.yticks([])
plt.show()

enter image description here

最佳答案

你确实误解了这篇论文。它们仅使用幅度信息来检索相位,这与仅使用幅度信息应用​​ IDFT 不同。

您的 FinalMagImg 不是空的,它在左上角有一个峰值。应用 fftshift 将其移动到中心,并应用对数映射来查看其余数据。如果相位全部为零,这就是逆 DFT 的样子。

关于python - 仅幅度重建看起来不正确,我的解释正确吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48486082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com