形态学算子在枕木图像和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)如何在科学图像形态学算子中设置边界条件?
诚挚的问候
发布于 2014-07-25 16:43:10
好的,它不是关于"border_value“参数的。我在skimage/形态学/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.ndimage.filters.convolve(输入、权重、output=None、模式=‘反射’、cval=0.0、origin=0):
模式:{“反射”、“常量”、“最近”、“镜像”、“包装”},可选模式参数决定数组边框的处理方式。对于“常量”模式,超出边界的值设置为cval。默认情况是“反映”。cval :标量,可选的值,如果输入模式是“常数”,则填充输入的过去边。缺省值为0.0 <-这里!
谜团解开了!
https://stackoverflow.com/questions/24956179
复制相似问题