scipy.ndimage.binary_hit_or_miss¶
- scipy.ndimage.binary_hit_or_miss(input, structure1=None, structure2=None, output=None, origin1=0, origin2=None)[源代码]¶
多维二进制命中或未命中变换。
命中或未命中转换查找输入图像内给定图案的位置。
- 参数
- inputARRAY_LIKE(强制转换为布尔值)
要检测模式的二进制图像。
- structure1ARRAY_LIKE(强制转换为布尔值),可选
要适配到的前景(非零元素)的结构元素的一部分 input 。如果没有提供值,则选择方形连通性1的结构。
- structure2ARRAY_LIKE(强制转换为布尔值),可选
必须完全错过前景的结构化元素的第二部分。如果未提供任何值,则 structure1 已经有人了。
- outputndarray,可选
与输入形状相同的数组,输出将放置到该数组中。默认情况下,将创建一个新阵列。
- origin1整型或整型元组,可选
结构元素的第一部分的放置 structure1 ,对于居中结构,默认情况下为0。
- origin2整型或整型元组,可选
结构元素的第二部分的放置 structure2 ,对于居中结构,默认情况下为0。如果为提供了值 origin1 而不是为了 origin2 ,那么 origin2 设置为 origin1 。
- 退货
- binary_hit_or_missndarray
命中或未命中的变换 input 使用给定的结构元素 (structure1 , structure2 )。
参考文献
示例
>>> from scipy import ndimage >>> a = np.zeros((7,7), dtype=int) >>> a[1, 1] = 1; a[2:4, 2:4] = 1; a[4:6, 4:6] = 1 >>> a array([[0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]) >>> structure1 = np.array([[1, 0, 0], [0, 1, 1], [0, 1, 1]]) >>> structure1 array([[1, 0, 0], [0, 1, 1], [0, 1, 1]]) >>> # Find the matches of structure1 in the array a >>> ndimage.binary_hit_or_miss(a, structure1=structure1).astype(int) array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) >>> # Change the origin of the filter >>> # origin1=1 is equivalent to origin1=(1,1) here >>> ndimage.binary_hit_or_miss(a, structure1=structure1,\ ... origin1=1).astype(int) array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0]])