为空间域中的给定掩模找到频域中的等效高斯滤波器掩模

发布于 2024-10-13 08:55:37 字数 881 浏览 8 评论 0原文

到目前为止,我已经完全在空间域中实现了高斯模糊滤波器,利用高斯的可分离性,即沿图像的行然后沿列应用一维高斯核。效果很好。

现在,仅给出空间域 NxN 卷积矩阵的大小 N,我想在频域上实现完全相同的模糊图像。这意味着我将把图像加载到一个矩阵中(numpy,我使用的是python),对其应用FFT(然后我有G(x,y)),然后我还必须有一个过滤器H( u,v) 在频域中也类似于某些 2d 高斯的形状,其中心值为 1.0,然后随着离中心越远,值就会下降到 0。然后我在频域中进行乘法(在我必须考虑进行 H 的中心移位之前),然后应用 iFFT。

我遇到的麻烦是找到将产生相应的 H(u,v) 的精确公式(即找到 sigma,标准偏差)。从空间域来看,如果给我一个掩码大小 N,我知道 std-dev sigma 可以近似为 sigma=(maskSize-1)/2/2.575,例如对于掩码大小 N=15 我得到对于 e^-(x²/2sigma²),std-dev=2.71845,目前仅考虑一维情况。

但是如何获得频域的西格玛呢?

有趣的是,理论上我知道如何使用 Mathematica 获得 sigma,但结果纯粹是假的,正如我可以在这里演示的:

gauss1d[x_, sigma_] := Exp[-(x^2)/(2 sigma^2)]
Simplify[FourierTransform[gauss1d[x, sigma], x, omega], sigma > 0]

结果是 E^(-(1/2) omega^2 sigma^2) * sigma

这是假的,因为它在 E 函数的指数中将 1/sigma² 转换为 sigma²。因此,如果你画这个,你会发现标准差变得小了很多,因为 H(u,v)-高斯分布“更薄”了很多。然而,它实际上在频域中应该比在空间域中宽得多!这没有任何意义...

So far I've implemented a gaussian blur filter entirely in the space domain, making use of the separability of the gaussian, that is, applying a 1D gaussian kernel along the rows and then along the columns of an image. That worked fine.

Now, given only with the size N of the NxN convolution matrix of the space domain, I want to achieve the exact same blurred image over the frequency domain. That means that I'll load the image into a matrix (numpy, I'm using python), apply the FFT on it (then I have G(x,y)), and then I have to have also a filter H(u,v) in the frequency domain that also resembles the shape of some 2d gaussian, with its center value being 1.0 and then having values falling off to 0 the further away from the center I am. I do then the multiplication in frequency domain (before I have to consider to do a center-shift of H) and then apply the iFFT.

The trouble I have is to find the exact formula (i.e. to find sigma, the std-deviation) that will result in the corresponding H(u,v). From the space domain, if I have been given a mask-size N, I know that the std-dev sigma can be approximated as sigma=(maskSize-1)/2/2.575, e.g. for a mask size N=15 I get std-dev=2.71845 for e^-(x²/2sigma²), just considering 1D cases for now.

But how do I get sigma for the frequency domain?

Funny thing is btw that in theory I know how to get sigma, using Mathematica, but the result is pure bogus, as I can demonstrate here:

gauss1d[x_, sigma_] := Exp[-(x^2)/(2 sigma^2)]
Simplify[FourierTransform[gauss1d[x, sigma], x, omega], sigma > 0]

The result is E^(-(1/2) omega^2 sigma^2) * sigma

This is bogus because it turns, in the exponent of the E function, the 1/sigma² into a sigma². Consequently, if you draw this, you will see that the standard deviation has become a lot smaller, since the H(u,v)-gaussian is a lot "thinner". However, it should actually be a lot wider in the frequency domain than in the space domain!! It doesn't make any sense...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神也荒唐 2024-10-20 08:55:37

高斯的傅里叶变换是高斯,正如您可以从

http://en.wikipedia.org/ 中看到的那样wiki/Fourier_transform

但请注意,std。开发人员。确实反转!!!!

你说那是假的,但事实并非如此。从某种意义上说,频域是时域的反演。

freq = 1/time

给出的标准差是及时的,当你变换它时它仍然是及时的(常数没有被变换)。

假设您使用一些时间形式的 s 找到了高斯的时间版本。您将数据转换为频率空间。您可以使用该 s,它的行为将完全按照预期的方式进行。例如,如果你有一个小 s 那么它会导致频率标准。开发人员。在频率版本上要大。

同样,这是因为频率是时间的反演(同样,在某种意义上)。

假设你的高斯函数的标准差非常小。开发人员。然后它近似狄拉克δ函数。我们知道这一点是因为它被转换成频域中的正弦曲线。即跨越整个频域的东西。 (即,具有无限的标准差。(如果它是高斯)。

这样想:您想要在频域中进行平滑。平滑什么?高频分量,对吧?通过与高斯进行卷积,您正在平滑如果标准差很小,则意味着您在频域中保持更多频率,但如果我们乘以频域中的薄高斯。域中,我们将留下一小组频率

G(t)*f(t) 。
G[w]*f[w]

第一个,卷积。对于平滑滤波器,我们希望 G(t) 为“大”(std.dev. 为大)。这意味着我们需要更少的高频分量(一种低通滤波器)。在频率中。我们乘以 G[w] 的域。这意味着 G[w] 必须很薄(并且以原点为中心),以便我们阻挡高点。

我认为基本上你没有意识到在时域中我们有一个卷积,而在频域中它是一个乘法。两者中的 G 不能相同。如果 G 在时域中较薄且在频域中较薄,则不会产生相同的效果。卷积中的 G Thin 几乎没有效果,但频率中的 G Thin 几乎没有效果。域几乎完全消除了所有频率(仅保留非常低的频率)。

The Fourier Transform of the a Gaussian is a Gaussian as you can see from

http://en.wikipedia.org/wiki/Fourier_transform

But note that the std. dev. DOES invert!!!!

You say that is bogus BUT it is not. The frequency domain is, in some sense, the inversion of the time domain.

freq = 1/time

The standard deviation given is in time, when you transform it is still in time(the constant does not get transformed).

Suppose your you found the time version of the Gaussian using some s in terms of time. You transform the data into freq space. You can use that s and it will behave exactly the way it is suppose to. e.g., if you have a small s then it will cause the freq std. dev. in the frequency version to be large.

Again, this is because frequency is the inversion of time(again, in a sense).

Suppose your Gaussian has very small std. dev. Then it approximates a dirac delta function. We know this because gets transformed into a sinusoid in the freq domain. i.e., something that spans the whole frequency domain. (i.e., has infinite std. dev.(if it were a Gaussian).

Think of it like this: You are wanting to smooth in the frequency domain. Smooth what? High frequency components, right? By convoluting with a gaussian you are smoothing near by data. If the std. dev. is small you are keeping higher frequencies. In the frequency domain this means you are KEEPING more frequencies. But the conv is a multiplication in frequency domain. If we mulitplied by a thin gaussian in the frequency domain we would be left with a small group of frequencies.

G(t)*f(t)
G[w]*f[w]

The first, a convolution. For a smooth filter we want G(t) to be "large"(std. dev. to be large). This means in we want less of the high frequency components(a sort of low pass filter). In the freq. domain we are multiplying by G[w]. This means that G[w] must be thin(and centered around the origin) so that we block out the highs.

I think basically you are not realizing that in the time domain we have a convolution and the frequency domain it is a multiplication. G cannot be the same in both. If G is thin in the time domain and thin in the frequency domain they will not result in the same effect. G thin in the convolution gives almost no effect but G thin in the freq. domain almost completely removes all the frequencies(just the very low are kept).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文