【问题标题】:How to apply Gaussian blur on a polygon drawn inside a larger image如何在较大图像内绘制的多边形上应用高斯模糊
【发布时间】:2019-02-18 18:17:48
【问题描述】:

我想在较大图像内的多边形的像素坐标上应用高斯模糊,然后在相同坐标上对模糊的多边形做一些事情。 skimage 中的 draw polygon 函数直接为我提供了图像的坐标,而不是蒙版。理想情况下,我想在面具本身上应用过滤器,但 draw polygon 函数没有让我得到面具。

img = np.zeros((10, 10), dtype=np.uint8)
r = np.array([1, 2, 8, 1])
c = np.array([1, 7, 4, 1])
rr, cc = polygon(r, c)
# Apply Gaussian blur here on the locations specified by the polygon
img[rr, cc] = 1 # or do something else on the blurred positions.

我显然不能先在图像上运行高斯模糊,因为如果我在 rr, cc 上运行高斯模糊,我会得到十进制值,并且无法通过索引访问相同的多边形。我该如何解决这个问题?

【问题讨论】:

    标签: python gaussian scikit-image


    【解决方案1】:

    SciPy 的Gaussian blur 不接受掩码作为输入,因此您需要模糊整个图像,然后仅复制该多边形的值。在这种情况下,您可以使用索引:

    from skimage import filters
    
    img_blurred = filters.gaussian(img)
    img_poly_blurred = np.copy(img)  # don't modify img in-place unless you're sure!
    img_poly_blurred[rr, cc] = img_blurred[rr, cc]
    

    【讨论】:

      【解决方案2】:

      我是这样解决的。

      mask = np.zeros_like(img)
      mask[rr, cc] = 1  # or anything else on the blurred positions
      mask = filters.gaussian(mask, sigma=3)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-05
        • 1970-01-01
        • 2019-10-01
        • 1970-01-01
        • 2016-01-02
        • 1970-01-01
        相关资源
        最近更新 更多