【问题标题】:Morphology erosion - difference betwen Scipy ndimage and Scikit image形态学侵蚀 - Scipy ndimage 和 Scikit 图像之间的区别
【发布时间】:2014-09-17 08:02:01
【问题描述】:

形态算子在 Scipy ndimage 和 Scikit image 中不同。我想,边界条件的处理方式不同:

import numpy as np
from scipy import ndimage
from skimage import morphology

scp = ndimage.binary_erosion(np.ones((10,10),dtype="uint8"),).astype("uint8")
sci = morphology.binary_erosion(np.ones((10,10),dtype="uint8"),morphology.disk(1))

scp 结果符合预期,但 sci 没有:

>>>> scp
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)

>>>> sci
array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=uint8)

如何在 scikit-image 形态学算子中设置边界条件?

最好的问候

【问题讨论】:

  • 你试过用morphology.square(10)代替.disk(1)吗?
  • morphology.suqare 和 .disk 只是结构元素,略有不同。结构元素的半径或形状对我上面描述的边框行为没有影响。
  • scikit-image 形态运算符中似乎缺少“border_value”参数。此参数控制边界外的像素值。

标签: python image-processing numpy scipy scikit-image


【解决方案1】:

好的,这与“border_value”参数无关。 我在 skimage/morphology/binary.py 中找到:

import numpy as np
from scipy import ndimage

def binary_erosion(image, selem, out=None):
    conv = ndimage.convolve(image > 0, selem, output=out,
                            mode='constant', cval=1) <---Here!
    if conv is not None:
        out = conv
    return np.equal(out, np.sum(selem), out=out)

来自 Scipy 参考指南:

scipy.ndimage.filters.convolve(input, weights, output=None, mode='reflect', cval=0.0, origin=0):

mode : {'reflect','constant','nearest','mirror','wrap'},可选 mode 参数确定如何处理数组边界。对于“恒定”模式,值 超出边界设置为 cval。默认为“反射”。 cval : 标量,可选要填充的值 如果模式是“恒定的”,则过去的输入边缘。默认值为 0.0

谜团解开!

【讨论】:

  • 我认为我们应该尽可能地以兼容性为目标。你能在 GitHub 上提交问题吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多