对于静态sigma值,可以轻松地在图像上运行高斯滤波器:
scipy.ndimage.gaussian_filter(input, sigma)
对于每个像素值不同的sigma
值,如何实现呢?例如,我可能有一个与该大小相同的另一个NumPy数组,指示每个像素使用什么sigma。
对于静态sigma值,可以轻松地在图像上运行高斯滤波器:
scipy.ndimage.gaussian_filter(input, sigma)
对于每个像素值不同的sigma
值,如何实现呢?例如,我可能有一个与该大小相同的另一个NumPy数组,指示每个像素使用什么sigma。
我不知道在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')