使用NumPy进行自适应高斯滤波

3

对于静态sigma值,可以轻松地在图像上运行高斯滤波器:

scipy.ndimage.gaussian_filter(input, sigma)

对于每个像素值不同的sigma值,如何实现呢?例如,我可能有一个与该大小相同的另一个NumPy数组,指示每个像素使用什么sigma。


你可能没有ndimage中的这个实现。DIPlib有一个实现,或者你可以自己编写一个。你有几个不同的sigma值,还是有很多不同的值?我问这个是因为对于少数sigma的情况有一种快捷方式。 - undefined
请求是对每个像素进行不同的模糊处理。还有另一张“图像”,它说明了每个像素应该被模糊多少。我会尝试使用DIPlib - 谢谢@CrisLuengo - undefined
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数组兼容。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接