當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python skimage.morphology.remove_small_objects用法及代碼示例

用法:

skimage.morphology.remove_small_objects(ar, min_size=64, connectivity=1, in_place=False, *, out=None)

移除小於指定大小的對象。

期望 ar 是一個帶有標簽對象的數組,並刪除小於 min_size 的對象。如果 ar 是 bool,則首先標記圖像。這導致 bool 和 0 和 1 數組的行為可能不同。

參數

arndarray(任意形狀,int 或 bool 類型)

包含感興趣對象的數組。如果數組類型是int,則整數必須為非負數。

min_sizeint 可選(默認值:64)

允許的最小對象大小。

connectivityint {1, 2, ..., ar.ndim},可選(默認值:1)

定義像素鄰域的連通性。如果 ar 為 bool,則在標記期間使用。

in_place布爾值,可選(默認值:False)

如果True,刪除輸入數組本身中的對象。否則,請製作副本。自 0.19 版起已棄用。請用out反而。

outndarray

與 ar 形狀相同的數組,其中放置輸出。默認情況下,會創建一個新數組。

返回

outndarray,與輸入相同的形狀和類型阿爾

刪除了小連接組件的輸入數組。

拋出

TypeError

如果輸入數組的類型無效,例如浮點數或字符串。

ValueError

如果輸入數組包含負值。

例子

>>> from skimage import morphology
>>> a = np.array([[0, 0, 0, 1, 0],
...               [1, 1, 1, 0, 0],
...               [1, 1, 1, 0, 1]], bool)
>>> b = morphology.remove_small_objects(a, 6)
>>> b
array([[False, False, False, False, False],
       [ True,  True,  True, False, False],
       [ True,  True,  True, False, False]])
>>> c = morphology.remove_small_objects(a, 7, connectivity=2)
>>> c
array([[False, False, False,  True, False],
       [ True,  True,  True, False, False],
       [ True,  True,  True, False, False]])
>>> d = morphology.remove_small_objects(a, 6, out=a)
>>> d is a
True

相關用法


注:本文由純淨天空篩選整理自scikit-image.org大神的英文原創作品 skimage.morphology.remove_small_objects。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。