2

在具有静态 sigma 值的图像上运行高斯滤波器很容易:

scipy.ndimage.gaussian_filter(input, sigma)

但是如何使用sigma每个像素不同的值来做到这一点?例如,我可能有另一个相同大小的 NumPy 数组,它指示每个像素使用什么 sigma。

4

1 回答 1

0

我不知道 OpenCV、scipy.ndimage 或 scikit-image 中的自适应高斯滤波器实现。DIPlib确实有这样的过滤器(披露:我是作者)。您可以使用pip install diplib.

这就是你将如何使用自适应高斯滤波器,其中只有内核的大小会发生变化(这个函数也可以旋转一个拉长的高斯滤波器,它非常简洁,我建议你尝试一下!)。

import diplib as dip

img = dip.ImageRead('examples/trui.ics')

# We need an image that indicates the kernel orientation for each pixel,
# we just set this to 0
orientation = img.Similar('SFLOAT')
orientation.Fill(0)
# We need an image that indicates the kernel size for each pixel,
# this is your NumPy array
scale = dip.CreateRadiusCoordinate(img.Sizes()) / 200
# This is the function. Kernel sizes in the `scale` image are multiplied
# by the sigmas given here
out = dip.AdaptiveGauss(img, [orientation, scale], sigmas=[5,5])

dip.ImageWrite(img,'so_in.jpg')
dip.ImageWrite(out,'so_out.jpg')

请注意,Python 绑定到 DIPlib 的图像对象与 NumPy 数组兼容。

于 2020-07-28T15:03:33.063 回答