只有震级的重建看起来不正确,我正确地解释了吗?

2024-07-02 12:55:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经实现了一个方法从“相位从非周期物体的傅里叶变换的幅度检索”的论文在: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


Tags: fftlentitlenppltmaskabsprime
1条回答
网友
1楼 · 发布于 2024-07-02 12:55:42

你确实误解了报纸。它们仅使用幅值信息检索相位,这与仅使用幅值信息应用IDFT不同。在

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

相关问题 更多 >