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


Python skimage.segmentation.expand_labels用法及代碼示例

用法:

skimage.segmentation.expand_labels(label_image, distance=1)

通過distance 像素展開標簽圖像中的標簽而不重疊。

給定一個標簽圖像,expand_labels 將標簽區域(連接的組件)向外增長最多 distance 個像素,而不會溢出到相鄰區域。更具體地說,每個在歐幾裏得距離 distance 像素的歐幾裏得距離內的每個背景像素都被分配了該連接分量的標簽。當多個連通分量在背景像素的distance 像素內時,將分配最近連通分量的標簽值(有關多個標簽等距離的情況,請參見注釋)。

參數

label_imagedtype int的ndarray

標簽圖像

distance浮點數

以像素為單位的歐幾裏得距離,用於增長標簽。默認為一。

返回

enlarged_labelsdtype int的ndarray

標記數組,其中所有連接區域都已放大

注意

在標簽間隔超過 distance 像素的情況下,這相當於使用半徑為 distance 的圓盤或超球進行形態膨脹。然而,與形態擴張相反,expand_labels 不會將標簽區域擴展到相鄰區域。

expand_labels 的這個實現是從 CellProfiler [1] 派生的,它被稱為模塊“IdentifySecondaryObjects (Distance-N)”[2]

當一個像素到多個區域的距離相同時,存在一個重要的邊情況,因為沒有定義哪個區域擴展到該空間。在這裏,確切的行為取決於 scipy.ndimage.distance_transform_edt 的上遊實現。

參考

1

https://cellprofiler.org

2

https://github.com/CellProfiler/CellProfiler/blob/082930ea95add7b72243a4fa3d39ae5145995e9c/cellprofiler/modules/identifysecondaryobjects.py#L559

例子

>>> labels = np.array([0, 1, 0, 0, 0, 0, 2])
>>> expand_labels(labels, distance=1)
array([1, 1, 1, 0, 0, 2, 2])

標簽不會相互覆蓋:

>>> expand_labels(labels, distance=3)
array([1, 1, 1, 1, 2, 2, 2])

在平局的情況下,行為未定義,但目前按字典順序解析為最接近 (0,) * ndim 的標簽。

>>> labels_tied = np.array([0, 1, 0, 2, 0])
>>> expand_labels(labels_tied, 1)
array([1, 1, 1, 2, 2])
>>> labels2d = np.array(
...     [[0, 1, 0, 0],
...      [2, 0, 0, 0],
...      [0, 3, 0, 0]]
... )
>>> expand_labels(labels2d, 1)
array([[2, 1, 1, 0],
       [2, 2, 0, 0],
       [2, 3, 3, 0]])

相關用法


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