高斯模糊和FFT [英] Gaussian blur and FFT

查看:165
本文介绍了高斯模糊和FFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为学校项目实施高斯模糊。
我需要同时制作CPU和GPU实现来比较性能。

I´m trying to make an implementation of Gaussian blur for a school project. I need to make both a CPU and a GPU implementation to compare performance.

我不太清楚我是否理解高斯模糊是如何工作的。所以我的一个问题是
,如果我理解正确的话?

I am not quite sure that I understand how Gaussian blur works. So one of my questions is if I have understood it correctly?

继续我现在所做的事:
我使用维基百科中的等式 http://en.wikipedia.org/wiki/Gaussian_blur 计算过滤器的

对于2d,我对图像中的每个像素采用RGB,并通过
将滤波器应用于它,将像素的RGB和周围像素与相关的滤波器位置相乘。
然后将它们相加为新的像素RGB值。
对于1d我首先水平应用过滤器,然后是veteically,如果我理解正确的话,这应该给
相同的结果。
这个结果与应用2d滤波器的结果完全相同吗?

Heres what I do now: I use the equation from wikipedia http://en.wikipedia.org/wiki/Gaussian_blur to calculate the filter. For 2d I take RGB of each pixel in the image and apply the filter to it by multiplying RGB of the pixel and the surrounding pixels with the associated filter position. These are then summed to be the new pixel RGB values. For 1d I apply the filter first horizontally and then vetically, which should give the same result if I understand things correctly. Is this result exactly the same result as when the 2d filter is applied?

我的另一个问题是如何优化算法。
我读过快速傅立叶变换适用于高斯模糊。
但我无法弄清楚如何联系它。
有人可以给我一个正确方向的提示吗?

Another question I have is about how the algorithm can be optimized. I have read that the Fast Fourier Transform is applicable to Gaussian blur. But I can't figure out how to relate it. Can someone give me a hint in the right direction?

谢谢。

推荐答案

是的,2D高斯内核是可分离的,所以你可以将它作为两个1D内核应用。请注意,您不能就地应用这些操作 - 但是您需要至少一个临时缓冲区来存储第一个1D传递的结果。

Yes, the 2D Gaussian kernel is separable so you can just apply it as two 1D kernels. Note that you can't apply these operations "in place" however - you need at least one temporary buffer to store the result of the first 1D pass.

基于FFT当你有大内核时,卷积是一个有用的优化 - 这适用于任何类型的过滤器,而不仅仅是高斯过滤器。 大的大小取决于您的体系结构,但您可能不想担心使用基于FFT的方法来处理比49x49内核更小的方法。一般方法是:

FFT-based convolution is a useful optimisation when you have large kernels - this applies to any kind of filter, not just Gaussian. Just how big "large" is depends on your architecture, but you probably don't want to worry about using an FFT-based approach for anything smaller than, say, a 49x49 kernel. The general approach is:


  • FFT图像

  • FFT内核,填充到大小图像

  • 将频域中的两个相乘(相当于空间域中的卷积)

  • IFFT(逆FFT)结果

  • FFT the image
  • FFT the kernel, padded to the size of the image
  • multiply the two in the frequency domain (equivalent to convolution in the spatial domain)
  • IFFT (inverse FFT) the result

请注意,如果您将过滤器应用于多个图像,则只需要填充内核一次FFT。您仍然至少有两个FFT可以执行每个图像(一个正向和一个反向),这就是为什么这种技术只会成为大型内核的计算胜利。

Note that if you're apply a filter to more than one image that you only need FFT the padded kernel once. You still have at least two FFTs to perform per image though (one forward and one inverse), which is why this technique only becomes a computational win for large-ish kernels.

这篇关于高斯模糊和FFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆