用法:
cucim.skimage.segmentation.find_boundaries(label_img, connectivity=1, mode='thick', background=0)
返回標記區域之間的邊界為 True 的布爾數組。
- label_img:int 或 bool 數組
一個數組,其中不同的區域用不同的整數或布爾值標記。
- connectivity:int in {1, ...,
label_img.ndim
},可選 如果一個像素的任何相鄰像素具有不同的標簽,則該像素被視為邊界像素。
connectivity
控製哪些像素被視為鄰居。連接性為 1(默認)意味著共享邊(2D)或麵(3D)的像素將被視為鄰居。label_img.ndim
的連通性意味著共享一個角的像素將被視為鄰居。- mode:{‘thick’, ‘inner’, ‘outer’, ‘subpixel’} 中的字符串
如何標記邊界:
- 厚:任何未被相同標簽(由
connectivity
定義)的像素完全包圍的像素都被標記為邊界。這會產生 2 個像素厚的邊界。 - 內部:勾勒對象的像素
just inside
,保持背景像素不變。 - 外部:對象邊界周圍背景中的輪廓像素。當兩個物體接觸時,它們的邊界也會被標記。
- subpixel:返回一個加倍的圖像,像素
between
在適當的地方標記為邊界的原始像素。
- 厚:任何未被相同標簽(由
- background:整數,可選
對於模式‘inner’ and ‘outer’,需要定義背景標簽。有關這兩者的說明,請參見
mode
。
- boundaries:布爾數組,與
label_img
的形狀相同 True
表示邊界像素的布爾圖像。對於等於‘subpixel’的mode
,對於所有i
,boundaries.shape[i]
等於2 * label_img.shape[i] - 1
(在所有其他像素對之間插入一個像素)。
- boundaries:布爾數組,與
參數:
返回:
例子:
>>> labels = cp.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=cp.uint8) >>> find_boundaries(labels, mode='thick').astype(cp.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(cp.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(cp.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(cp.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 = cp.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 cucim.skimage.segmentation.random_walker用法及代碼示例
- Python cucim.skimage.segmentation.relabel_sequential用法及代碼示例
- Python cucim.skimage.segmentation.join_segmentations用法及代碼示例
- Python cucim.skimage.feature.shape_index用法及代碼示例
- Python cucim.skimage.restoration.richardson_lucy用法及代碼示例
- Python cucim.skimage.util.invert用法及代碼示例
- Python cucim.skimage.data.binary_blobs用法及代碼示例
- Python cucim.skimage.filters.roberts_neg_diag用法及代碼示例
- Python cucim.skimage.color.lch2lab用法及代碼示例
- Python cucim.skimage.measure.label用法及代碼示例
- Python cucim.skimage.color.rgb2gray用法及代碼示例
- Python cucim.skimage.filters.gabor用法及代碼示例
- Python cucim.skimage.transform.rescale用法及代碼示例
- Python cucim.skimage.filters.roberts_pos_diag用法及代碼示例
- Python cucim.skimage.filters.roberts用法及代碼示例
- Python cucim.skimage.morphology.dilation用法及代碼示例
- Python cucim.skimage.feature.corner_foerstner用法及代碼示例
- Python cucim.skimage.measure.moments_coords用法及代碼示例
- Python cucim.skimage.filters.gabor_kernel用法及代碼示例
- Python cucim.skimage.color.hsv2rgb用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cucim.skimage.segmentation.find_boundaries。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。