python - 相移后进行傅里叶变换

标签 python numpy fft scientific-computing

我正在尝试改变图像的相位并对它进行傅立叶变换。但是这种相位变化会导致沿 x 轴和 y 轴的功率泄漏。

假设我的图像是一个全一矩阵。如果我进行傅里叶变换,我会得到 Spectrum of all ones .看到所有的力量都在中心。事实上,除非你放大,否则我们无法看到全部。

现在假设我将矩阵乘以复数正弦曲线。理想情况下,功率应该正好转移到正弦波的频率。但这就是我得到的 Spectra of phase multiplied image .请注意沿 x 轴和 y 轴泄漏的功率。

为什么会出现这种情况?是因为信号的非连续性吗?

请看下面的python代码

import numpy as np
from matplotlib import pyplot as plt

# Init a all one array
base_image = np.ones([1024,1024])

#Generate a array so that we can make a sinusoid using it
x_cords = np.arange(base_image.shape[1]) - base_image.shape[1]/2
x_cords = np.transpose(x_cords)/512
x_cords = x_cords.astype(float)
x_cords = np.tile(x_cords, [base_image.shape[0], 1])
y_cords = np.transpose(x_cords)

#Generate the sinusoid
phase = np.exp(x_cords + y_cords)

#Apply this shift
new_image = base_image * phase

spec_base = np.fft.fftshift(np.fft.fft2(base_image))
spec_new = np.fft.fftshift(np.fft.fft2(new_image))

plt.imshow(np.log(np.abs(spec_base)))
plt.show()

plt.imshow(np.log(np.abs(spec_new)))
plt.show()

提前感谢任何答案

最佳答案

如果绘制 new_image,您会发现它不是正弦曲线:enter image description here

这是一种无需使用复数即可创建正弦波模式的蛮力方法:

# create a sinusoid
F=4 ## select the frequency -- use an even integer to minimize spectral "leakage"
new_image = np.ones([X,Y])
for y in xrange(Y):
   for x in xrange(X):
      new_image[y][x] = sin(x/float(X)*pi*F)*sin(y/float(Y)*pi*F)

enter image description here

功率谱具有最小的泄漏,如果放大,您可以看到峰值功率偏离原点,并且由于 DC 周围的镜像,实际上有 4 个峰值。

enter image description here

关于python - 相移后进行傅里叶变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32740592/

相关文章:

python - 当我将 displacy.render(doc, style ="dep") 的输出保存到 svg 文件时,出现 TypeError : write() argument must be str, not None

python - 选择NUKE节点,其中节点的类以字符串 "OFXuk"开头

python - 值错误 : operands could not be broadcast together with shapes (1, 2) (20,100)

c - kiss_fftr 的 KissFFT 输出

python - 使用重复元素创建元组

java - 从 java 编写 .npy(numpy 二进制格式)

python - 将元组列表转换为切片列表以与 np.r_ 一起使用

java - Android whiSTLe 检测与麦克风

matlab - 快速移位/快速移位

python - Python 中的链式比较实际上是如何工作的?