scipy.ndimage.
binary_fill_holes#
- scipy.ndimage.binary_fill_holes(input, structure=None, output=None, origin=0, *, axes=None)[原始碼]#
填滿二元物件中的孔洞。
- 參數:
- inputarray_like
具有要填滿孔洞的 N 維二元陣列
- structurearray_like, optional
用於計算的結構元素;大型元素可以加快計算速度,但可能會遺漏被薄區域與背景分離的孔洞。預設元素(具有等於 1 的方形連通性)會產生直觀的結果,其中輸入中的所有孔洞都已被填滿。
- outputndarray, optional
與輸入形狀相同的陣列,輸出將放置於其中。預設情況下,會建立一個新陣列。
- originint, tuple of ints, optional
結構元素的位置。
- axestuple of int or None
要套用濾波器的軸。如果為 None,則沿所有軸對 input 進行濾波。如果提供了 origin 元組,則其長度必須與軸數相符。
- 返回:
- outndarray
初始影像 input 的轉換,其中孔洞已被填滿。
註解
此函數中使用的演算法包括從影像的外邊界入侵 input 中形狀的互補集,使用二元膨脹。孔洞未連接到邊界,因此不會被入侵。結果是被入侵區域的互補子集。
參考文獻
範例
>>> from scipy import ndimage >>> import numpy as np >>> a = np.zeros((5, 5), dtype=int) >>> a[1:4, 1:4] = 1 >>> a[2,2] = 0 >>> a array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]) >>> ndimage.binary_fill_holes(a).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]]) >>> # Too big structuring element >>> ndimage.binary_fill_holes(a, structure=np.ones((5,5))).astype(int) array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]])