§
    1-Phi  ã                   ó"   — d dl Zd dlmZ dd„ZdS )é    N)Údistance_transform_edté   c                 ó¾   ‡— t          | dk    |d¬¦  «        \  }}t          j        | ¦  «        }||k    Šˆfd„|D ¦   «         }| t          |¦  «                 }||‰<   |S )as  Expand labels in label image by ``distance`` pixels without overlapping.

    Given a label image, ``expand_labels`` grows label regions (connected components)
    outwards by up to ``distance`` units without overflowing into neighboring regions.
    More specifically, each background pixel that is within Euclidean distance
    of <= ``distance`` pixels of a connected component is assigned the label of that
    connected component. The `spacing` parameter can be used to specify the spacing
    rate of the distance transform used to calculate the Euclidean distance for anisotropic
    images.
    Where multiple connected components are within ``distance`` pixels of a background
    pixel, the label value of the closest connected component will be assigned (see
    Notes for the case of multiple labels at equal distance).

    Parameters
    ----------
    label_image : ndarray of dtype int
        label image
    distance : float
        Euclidean distance in pixels by which to grow the labels. Default is one.
    spacing : float, or sequence of float, optional
        Spacing of elements along each dimension. If a sequence, must be of length
        equal to the input rank; if a single number, this is used for all axes. If
        not specified, a grid spacing of unity is implied.

    Returns
    -------
    enlarged_labels : ndarray of dtype int
        Labeled array, where all connected regions have been enlarged

    Notes
    -----
    Where labels are spaced more than ``distance`` pixels are apart, this is
    equivalent to a morphological dilation with a disc or hyperball of radius ``distance``.
    However, in contrast to a morphological dilation, ``expand_labels`` will
    not expand a label region into a neighboring region.

    This implementation of ``expand_labels`` is derived from CellProfiler [1]_, where
    it is known as module "IdentifySecondaryObjects (Distance-N)" [2]_.

    There is an important edge case when a pixel has the same distance to
    multiple regions, as it is not defined which region expands into that
    space. Here, the exact behavior depends on the upstream implementation
    of ``scipy.ndimage.distance_transform_edt``.

    See Also
    --------
    :func:`skimage.measure.label`, :func:`skimage.segmentation.watershed`, :func:`skimage.morphology.dilation`

    References
    ----------
    .. [1] https://cellprofiler.org
    .. [2] https://github.com/CellProfiler/CellProfiler/blob/082930ea95add7b72243a4fa3d39ae5145995e9c/cellprofiler/modules/identifysecondaryobjects.py#L559

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

    Labels will not overwrite each other:

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

    In case of ties, behavior is undefined, but currently resolves to the
    label closest to ``(0,) * ndim`` in lexicographical order.

    >>> 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]])
    >>> expand_labels(labels2d, 1, spacing=[1, 0.5])
    array([[1, 1, 1, 1],
           [2, 2, 2, 0],
           [3, 3, 3, 3]])
    r   T)ÚsamplingÚreturn_indicesc                 ó    •— g | ]
}|‰         ‘ŒS © r	   )Ú.0Údimension_indicesÚdilate_masks     €úc/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/segmentation/_expand_labels.pyú
<listcomp>z!expand_labels.<locals>.<listcomp>c   s,   ø€ ð #ð #ð #Ø+<Ð˜+Ô&ð#ð #ð #ó    )r   ÚnpÚ
zeros_likeÚtuple)	Úlabel_imageÚdistanceÚspacingÚ	distancesÚnearest_label_coordsÚ
labels_outÚmasked_nearest_label_coordsÚnearest_labelsr   s	           @r   Úexpand_labelsr      s•   ø€ õl '=ØqÒ 7¸4ð'ñ 'ô 'Ñ#€IÐ#õ ”˜{Ñ+Ô+€JØ˜xÒ'€Kð#ð #ð #ð #Ø@Tð#ñ #ô #Ðð !¥Ð'BÑ!CÔ!CÔD€NØ,€Jˆ{ÑØÐr   )r   r   )Únumpyr   Úscipy.ndimager   r   r	   r   r   ú<module>r      sG   ðØ Ð Ð Ð Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0ðcð cð cð cð cð cr   