python ndimage_python – 形态侵蚀 – Scipy ndimage和Scikit图像之间的差异

形态运算符在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< —–在这里! 谜团已揭开!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值