在读了一个关于scipy.ndimage.label(Variable area threshold for identifying objects - python),我想在标签中包含一个“误差范围”。在
在上述链接讨论中: 上面的蓝色圆点怎么也包括在内(假设它错误地与橙色最大的对象断开连接)?在
我找到了structure属性,通过改变数组(从np.ones公司(3,3,3)比这更重要(我希望它是3D的)。然而,不幸的是,将“structure”属性调整为更大的数组似乎不起作用。它要么给出维度的错误(RuntimeError:结构和输入必须具有相等的秩 )或者它不会改变任何东西。。在
谢谢!在
代码如下:
labels, nshapes = ndimage.label(a, structure=np.ones((3,3,3)))
其中a是一个3D数组。在
这里有一个使用^{} 的可能方法。在2D示例中更容易看到发生了什么,但最后我将演示如何将其推广到3D。在
将每个“形状”向下和向右延伸一个像素:
^{pr2}$将
label
应用于填充数组:通过将
a
乘以labels
,我们得到了a
所需的标签数组:(这假定
a
中的值为0或1。如果不是,可以使用alab = labels * (a > 0)
。)对于三维输入,必须将
structure
参数改为binary_dilation
:相关问题 更多 >
编程相关推荐