scipy.ndimage.binary_opening¶
- scipy.ndimage.binary_opening(input, structure=None, iterations=1, output=None, origin=0, mask=None, border_value=0, brute_force=False)[源代码]¶
具有给定结构元素的多维二元开口。
这个 打开 结构元素对输入图像的 扩张 的 侵蚀 结构元素对图像的影响。
- 参数
- inputarray_like
要打开的二进制数组_LIKE。非零(True)元素构成要打开的子集。
- structureARRAY_LIKE,可选
用于洞口的结构图元。非零元素被认为是True。如果没有提供结构元素,则生成方形连通性等于1的元素(即,只有最近的邻居连接到中心,对角连接的元素不被视为邻居)。
- iterations整型,可选
开口的侵蚀步骤,然后每个膨胀步骤重复 iterations 次数(默认情况下为一次)。如果 iterations 小于1,则重复每个操作,直到结果不再更改。仅接受整数次迭代。
- outputndarray,可选
与输入形状相同的数组,输出将放置到该数组中。默认情况下,将创建一个新阵列。
- origin整型或整型元组,可选
过滤的位置,默认为0。
- maskARRAY_LIKE,可选
如果给定了掩码,则在每次迭代中只修改在相应掩码元素处具有True值的那些元素。
1.1.0 新版功能.
- border_valueint(强制转换为0或1),可选
输出数组中边框处的值。
1.1.0 新版功能.
- brute_force布尔值,可选
内存条件:如果为False,则仅跟踪其值在上一次迭代中更改的像素作为在当前迭代中更新的候选像素;如果为True,则将所有像素视为更新的候选像素,而不考虑上一次迭代中发生的情况。默认情况下为False。
1.1.0 新版功能.
- 退货
- binary_opening一群野猪
由结构化元素打开输入。
注意事项
打开 [1] 是一种数学形态学运算 [2] 这包括具有相同结构元素的输入的连续侵蚀和膨胀。因此,打开会移除比结构元素小的对象。
Together with closing (
binary_closing
), opening can be used for noise removal.参考文献
示例
>>> from scipy import ndimage >>> a = np.zeros((5,5), dtype=int) >>> a[1:4, 1:4] = 1; a[4, 4] = 1 >>> a array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 1]]) >>> # Opening removes small objects >>> ndimage.binary_opening(a, structure=np.ones((3,3))).astype(int) array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]) >>> # Opening can also smooth corners >>> ndimage.binary_opening(a).astype(int) array([[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]) >>> # Opening is the dilation of the erosion of the input >>> ndimage.binary_erosion(a).astype(int) array([[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]]) >>> ndimage.binary_dilation(ndimage.binary_erosion(a)).astype(int) array([[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]])