gpt4 book ai didi

c++ - 使用 fft 的高斯模糊

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:51:44 25 4
gpt4 key购买 nike

我实现了一种使用高斯模糊图像的方法,如下所示:

- image I , size = WxH
- kernel K , size = MxM
- padded the kernel PD to the size of the image
i.e for an image 5x5 and a kernel 3x3 after padding the kernel looks like:
0 0 0 0 0
0 x x x 0
0 x x x 0
0 x x x 0
0 0 0 0 0
where X is the value from the original kernel
- performed 2d fft on the padded kernel PD (FFT_K)
- performed 2d fft on the image I (FFT_I)
- multiplied FFT_I * FFT_K (FFT_RES)
- perfomed fft on FFT_RES
- shifted the FFT_RES (RESULT)

结果在边缘包含一些锯齿。

结果如下:

enter image description here

如果您注意到右边的图像,您会发现它在两个维度上都有别名。

以上算法是否正确?

使用 C++ 和 fftw3 实现。

最佳答案

您的上述算法是正确的,但有轻微的空化。

当您用 0 填充图像时,这些零实际上用于卷积。在 FFT 空间中,这将在图像边缘周围添加巨大的高频分量。在非 FFT 空间中,这意味着,直到 1-边缘上的内核大小,0 被卷入,这会给你带来奇怪的边缘结果。人们通常通过两种方式处理此问题:

  1. 简单地在卷积后在图像周围抛出 1 个内核大小的边界。
  2. 将边缘镜像到焊盘中,而不是用零填充它。

为了获得最佳结果,我通常会同时执行 1 和 2(以获得实际图像并消除傅立叶空间中的高频边缘)。

关于c++ - 使用 fft 的高斯模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27404355/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com