【发布时间】:2023-03-14 19:09:01
【问题描述】:
简单的问题:
我在 Matlab 中绘制了一个具有一定分辨率的二维高斯函数。我用方差或 sigma = 1.0 进行测试。我想将它与 FFT(Gaussian) 的结果进行比较,这应该会产生另一个方差为 (1./sigma) 的高斯。由于我使用 sigma = 1.0 进行测试,我认为我应该获得两个等效的 2D 内核。
即
g1FFT = buildKernel(rows, cols, mu, sigma) % uses normpdf over arbitrary resolution (rows, cols, 3) with the peak in the center
构建内核:
function result = buildKernel(rows, cols, mu, sigma)
result = zeros(rows, cols, 3);
center_w = floor(cols / 2);
center_h = floor(rows / 2);
for i = 1:rows
for j = 1:cols
distance = sqrt((center_w - j).^2 + (center_h - i).^2);
g_val = normpdf(distance, mu, sigma);
result(i, j, :) = g_val;
end
end
% normalize so that kernel sums to 1
sumKernel = sum(result(:));
result = result ./ sumKernel;
end
我正在使用 mu = 0.0(始终)和方差或 sigma = 1.0 进行测试。我想将它与 FFT(Gaussian) 的结果进行比较,这应该会产生另一个方差为 (1./sigma) 的高斯。
即
g1FFT = circshift(g1FFT, [rows/2, cols/2, 0]); % fft2 expects center to be in corners
freq_G1 = fft2(g1FFT);
freq_G1 = circshift(freq_G1, [-rows/2, -cols/2, 0]); % shift back to center, for comparison's sake
由于我使用 sigma = 1.0 进行测试,我认为我应该得到两个等效的 2D 内核,因为如果 sigma = 1.0,那么 1.0/sigma = 1.0。因此,g1FFT 将等于 freq_G1。
但是,我没有。即使在归一化之后,它们也有不同的大小。有什么我遗漏的吗?
【问题讨论】:
-
请提供您的所有代码以重现您的错误。您是正确的,因为高斯的 FFT 是另一个高斯,但是没有代码可以向我们展示您所做的事情,我们无法判断您是否正确执行。
-
你的
buildKernel函数是什么样的? -
真的很简单,但添加了代码。
-
为什么你的内核是 3D 矩阵?你说它是一个二维高斯函数,但是有三个通道。
-
您可能已经发现了这一点,但您不能直接将连续时间傅里叶变换对应用于离散时间/DFT。 users.ece.gatech.edu/mrichard/… 显示离散情况的等价性取决于标准偏差,即 samples。