形态运算符在Scipy ndimage和Scikit图像上有所不同.我想,边界条件以不同的方式处理:
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形态运算符中设置边界条件?
最好的祝福
最佳答案 好的,它不是关于“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)
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.默认为’reflect’. cval:标量,可选填写值
如果模式为“常量”,则输入的过去边缘.默认值为0.0< —–在这里! 谜团已揭开!