python - 二维高斯核的傅里叶变换与空间域中的对应物不匹配

标签 python image-processing signal-processing fft convolution

我们知道高斯滤波器的傅立叶变换在频域中又是高斯的,我编写了以下方法来构建高斯核:

def get_gaussian(size, sigma):
  g_kernel = np.zeros((size,size))
  x_center = size // 2
  y_center = size // 2
  for i in range(size):
    for j in range(size):
      g_kernel[i,j] = np.exp(-((i - x_center)**2 + (j - y_center)**2) / (2*sigma**2))
  return 1/(2*np.pi * sigma**2)* g_kernel

plt.figure(figsize=(8, 10))
sigma = 20
g_spatial = get_gaussian(img2.shape[0],sigma)
plt.imshow(g_spatial)

plt.figure(figsize=(8, 10))
g_frequnecy = fft.fftshift(fft.fft2(g_spatial))
plt.imshow(np.abs(g_frequnecy))

plt.figure(figsize=(8, 10))
g_spatial = get_gaussian(img2.shape[0],sigma / (np.sqrt(2) * np.pi))
plt.imshow(g_spatial)

第二个和第三个高斯函数似乎根本不匹配。我将在下面附上所有三个高斯核的图片。我很确定我已经计算了每个高斯核的方差,以便它们根据高斯核的二维傅里叶变换进行匹配。我哪里出错了?

enter image description here

enter image description here

enter image description here

最佳答案

在频域中,高斯的西格玛为 size/(2 * pi * sigma),其中 size 为图像的大小, sigma 空间域西格玛。是的,对于非正方形图像,空间域中各向同性高斯分布在频域中不是各向同性。

您的计算sigma/(np.sqrt(2) * np.pi)是错误的。判断其不正确的一种快速方法是,使用您的计算,空间域中较大的西格玛也会在频域中产生更大的西格玛。但我们知道,在空间域中放大(==变大)会缩小频域,因为较大的波长具有较小的频率。

关于python - 二维高斯核的傅里叶变换与空间域中的对应物不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74539485/

相关文章:

python - 将 QGroupBox 复选框视觉效果更改为扩展器

image-processing - 结合多特征提取器

python - 运行时错误: _thnn_mse_loss_forward is not implemented for type torch. cuda.LongTensor

swift - 使用 Swift 对增长的时间序列进行峰值检测

python - 如何使用文件路径作为函数参数

python - 在 AudioLazy 库中从 python 中的 zfilter 对象中提取数值

python - 使用来自 Homebrew 的 python 2.7.6 在 OS X 10.9.1 上运行 virtualenv 时遇到问题

python - 直接打开Spyder还是通过Pythonxy打开?

python - 如何知道 nquad 调用的 C 函数中的维数?

python - 使用 Python 查找线外的点