用法:
skimage.morphology.label(label_image, background=None, return_num=False, connectivity=None)
標記整數數組的連接區域。
當兩個像素是相鄰的並且具有相同的值時,它們是連接的。在 2D 中,它們可以是 1 或 2 連接意義上的鄰居。該值是指將像素/體素視為鄰居的最大正交跳數:
1-connectivity 2-connectivity diagonal connection close-up [ ] [ ] [ ] [ ] [ ] | \ | / | <- hop 2 [ ]--[x]--[ ] [ ]--[x]--[ ] [x]--[ ] | / | \ hop 1 [ ] [ ] [ ] [ ]
- label_image:dtype int的ndarray
要標記的圖像。
- background:int 可選
將具有此值的所有像素視為背景像素,並將它們標記為 0。默認情況下,將 0 值像素視為背景像素。
- return_num:布爾型,可選
是否返回分配標簽的數量。
- connectivity:int 可選
將像素/體素視為鄰居的最大正交跳數。接受的值範圍從 1 到 input.ndim 如果
None
,則使用input.ndim
的完整連接。
- labels:dtype int的ndarray
標記數組,其中所有連接區域都分配有相同的整數值。
- num:int 可選
標簽數,等於最大標簽索引,僅在return_num 為 True 時返回。
- input:DEPRECATED
已棄用以支持label_image。
參數:
返回:
其他參數:
參考:
- 1
Christophe Fiorio and Jens Gustedt, “Two linear time Union-Find strategies for image processing”, Theoretical Computer Science 154 (1996), pp. 165-181.
- 2
Kensheng Wu, Ekow Otoo and Arie Shoshani, “Optimizing connected component labeling algorithms”, Paper LBNL-56864, 2005, Lawrence Berkeley National Laboratory (University of California), http://repositories.cdlib.org/lbnl/LBNL-56864
例子:
>>> import numpy as np >>> x = np.eye(3).astype(int) >>> print(x) [[1 0 0] [0 1 0] [0 0 1]] >>> print(label(x, connectivity=1)) [[1 0 0] [0 2 0] [0 0 3]] >>> print(label(x, connectivity=2)) [[1 0 0] [0 1 0] [0 0 1]] >>> print(label(x, background=-1)) [[1 2 2] [2 1 2] [2 2 1]] >>> x = np.array([[1, 0, 0], ... [1, 1, 5], ... [0, 0, 0]]) >>> print(label(x)) [[1 0 0] [1 1 2] [0 0 0]]
相關用法
- Python skimage.morphology.local_maxima用法及代碼示例
- Python skimage.morphology.local_minima用法及代碼示例
- Python skimage.morphology.h_minima用法及代碼示例
- Python skimage.morphology.dilation用法及代碼示例
- Python skimage.morphology.remove_small_holes用法及代碼示例
- Python skimage.morphology.flood_fill用法及代碼示例
- Python skimage.morphology.black_tophat用法及代碼示例
- Python skimage.morphology.h_maxima用法及代碼示例
- Python skimage.morphology.area_closing用法及代碼示例
- Python skimage.morphology.max_tree_local_maxima用法及代碼示例
- Python skimage.morphology.thin用法及代碼示例
- Python skimage.morphology.flood用法及代碼示例
- Python skimage.morphology.diameter_closing用法及代碼示例
- Python skimage.morphology.remove_small_objects用法及代碼示例
- Python skimage.morphology.reconstruction用法及代碼示例
- Python skimage.morphology.erosion用法及代碼示例
- Python skimage.morphology.diameter_opening用法及代碼示例
- Python skimage.morphology.max_tree用法及代碼示例
- Python skimage.morphology.medial_axis用法及代碼示例
- Python skimage.morphology.skeletonize用法及代碼示例
注:本文由純淨天空篩選整理自scikit-image.org大神的英文原創作品 skimage.morphology.label。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。