【问题标题】:Adaptive Gaussian filtering with NumPy使用 NumPy 进行自适应高斯滤波
【发布时间】:2020-11-17 23:46:03
【问题描述】:

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

scipy.ndimage.gaussian_filter(input, sigma)

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

【问题讨论】:

  • 你可能在 ndimage 中没有这个实现。 DIPlib 确实有一个实现,或者你可以自己动手。你有几个不同的 sigma 值,还是有很多不同的?我问是因为对于几个 sigma 的情况有一条捷径。
  • 请求是对每个像素进行不同的模糊处理。还有另一个“图像”说,每个像素应该模糊多少。将尝试 DIPlib - 谢谢@CrisLuengo

标签: python numpy image-processing filtering ndimage


【解决方案1】:

我不知道 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')

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

【讨论】:

    猜你喜欢
    • 2021-05-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2017-12-28
    • 2013-03-29
    • 1970-01-01
    • 2013-09-12
    • 2014-05-22
    相关资源
    最近更新 更多