gpt4 book ai didi

python - 形态侵 eclipse ——Scipy ndimage 和 Scikit image 的区别

转载 作者:太空宇宙 更新时间:2023-11-03 11:29:29 26 4
gpt4 key购买 nike

形态学运算符在 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) <---Here!
if conv is not None:
out = conv
return np.equal(out, np.sum(selem), out=out)

来自 Scipy 引用指南:

scipy.ndimage.filters.convolve(输入,权重,输出=无,模式='反射',cval=0.0,原点=0):

mode : {‘reflect’,’constant’,’nearest’,’mirror’, ‘wrap’},可选mode 参数确定如何处理数组边界。对于“常量”模式,值超越边界被设置为cval。默认为“反射(reflect)”。 cval :标量,可选要填充的值如果模式为“常数”,则过去输入的边缘。默认为 0.0 <-----此处!

谜底揭晓!

关于python - 形态侵 eclipse ——Scipy ndimage 和 Scikit image 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24956179/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com