用法:
skimage.segmentation.find_boundaries(label_img, connectivity=1, mode='thick', background=0)
返回標記區域之間的邊界為 True 的布爾數組。
- label_img:int 或布爾數組
一個數組,其中不同的區域用不同的整數或布爾值標記。
- connectivity:int 在 {1, ...,label_img.ndim}, 可選的
如果一個像素的任何相鄰像素具有不同的標簽,則該像素被視為邊界像素。連通性控製哪些像素被認為是鄰居。連接性為 1(默認)意味著共享邊(2D)或麵(3D)的像素將被視為鄰居。 label_img.ndim 的連通性意味著共享一個角的像素將被視為鄰居。
- mode:{‘thick’, ‘inner’, ‘outer’, ‘subpixel’} 中的字符串
如何標記邊界:
- 厚:任何未完全被相同標簽的像素包圍的像素(定義為連通性) 被標記為邊界。這會產生 2 個像素厚的邊界。
- 內部:勾勒像素就在裏麵對象,保持背景像素不變。
- 外部:對象邊界周圍背景中的輪廓像素。當兩個物體接觸時,它們的邊界也會被標記。
- subpixel:返回一個加倍的圖像,帶有像素之間在適當的地方標記為邊界的原始像素。
- background:int 可選
對於模式‘inner’ and ‘outer’,需要定義背景標簽。有關這兩者的說明,請參見模式。
- boundaries:布爾數組,形狀與label_img
一個布爾圖像,其中
True
表示邊界像素。為了模式等於‘subpixel’,boundaries.shape[i]
等於2 * label_img.shape[i] - 1
對所有人i
(在所有其他像素對之間插入一個像素)。
參數:
返回:
例子:
>>> labels = np.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, 0, 5, 5, 5, 0, 0], ... [0, 0, 1, 1, 1, 5, 5, 5, 0, 0], ... [0, 0, 1, 1, 1, 5, 5, 5, 0, 0], ... [0, 0, 1, 1, 1, 5, 5, 5, 0, 0], ... [0, 0, 0, 0, 0, 5, 5, 5, 0, 0], ... [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=np.uint8) >>> find_boundaries(labels, mode='thick').astype(np.uint8) array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 1, 1, 1, 0, 1, 1, 0], [0, 0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8) >>> find_boundaries(labels, mode='inner').astype(np.uint8) 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, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 1, 0, 1, 0, 0], [0, 0, 1, 1, 1, 1, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8) >>> find_boundaries(labels, mode='outer').astype(np.uint8) array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 1, 0, 0, 1, 0], [0, 0, 1, 1, 1, 1, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8) >>> labels_small = labels[::2, ::3] >>> labels_small array([[0, 0, 0, 0], [0, 0, 5, 0], [0, 1, 5, 0], [0, 0, 5, 0], [0, 0, 0, 0]], dtype=uint8) >>> find_boundaries(labels_small, mode='subpixel').astype(np.uint8) array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0], [0, 0, 0, 1, 0, 1, 0], [0, 1, 1, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0], [0, 1, 1, 1, 0, 1, 0], [0, 0, 0, 1, 0, 1, 0], [0, 0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]], dtype=uint8) >>> bool_image = np.array([[False, False, False, False, False], ... [False, False, False, False, False], ... [False, False, True, True, True], ... [False, False, True, True, True], ... [False, False, True, True, True]], ... dtype=bool) >>> find_boundaries(bool_image) array([[False, False, False, False, False], [False, False, True, True, True], [False, True, True, True, True], [False, True, True, False, False], [False, True, True, False, False]])
相關用法
- Python skimage.segmentation.flood_fill用法及代碼示例
- Python skimage.segmentation.felzenszwalb用法及代碼示例
- Python skimage.segmentation.flood用法及代碼示例
- Python skimage.segmentation.active_contour用法及代碼示例
- Python skimage.segmentation.relabel_sequential用法及代碼示例
- Python skimage.segmentation.clear_border用法及代碼示例
- Python skimage.segmentation.watershed用法及代碼示例
- Python skimage.segmentation.expand_labels用法及代碼示例
- Python skimage.segmentation.random_walker用法及代碼示例
- Python skimage.segmentation.slic用法及代碼示例
- Python skimage.segmentation.join_segmentations用法及代碼示例
- Python skimage.feature.graycomatrix用法及代碼示例
- Python skimage.color.lab2lch用法及代碼示例
- Python skimage.draw.random_shapes用法及代碼示例
- Python skimage.feature.blob_doh用法及代碼示例
- Python skimage.feature.blob_dog用法及代碼示例
- Python skimage.filters.unsharp_mask用法及代碼示例
- Python skimage.registration.optical_flow_tvl1用法及代碼示例
- Python skimage.filters.rank.noise_filter用法及代碼示例
- Python skimage.exposure.histogram用法及代碼示例
注:本文由純淨天空篩選整理自scikit-image.org大神的英文原創作品 skimage.segmentation.find_boundaries。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。