+
    Ai '                     p    ^ RI t^ RIHt ^RIHt ^RIHtH	t	H
t
 ^RIHtHt ^RIHt R tR
R ltRR	 ltR# )    N)ndimage)_supported_float_type)dilationerosionfootprint_rectangle)img_as_floatview_as_windows)gray2rgbc                
   V P                   p\        P                  ! V P                  4      P                  p\        P
                  ! V P                   Uu. uF  p^V,          ^,
          NK  	  upV P                  4      p\        RR^4      3V,          pWV&   \        P                  ! VP                  \        R7      pRWe&   W$V&   \        \        P                  ! V^RR7      RV,          4      p\        P                  ! V4      p\        P                  ! VP                  4       FS  p	Wi,          '       g   K  \        P                  ! Wy,          P                  4       4      p
\!        V
4      ^8  g   KO  RW&   KU  	  V# u upi )a  See ``find_boundaries(..., mode='subpixel')``.

Notes
-----
This function puts in an empty row and column between each *actual*
row and column of the image, for a corresponding shape of ``2s - 1``
for every image dimension of size ``s``. These "interstitial" rows
and columns are filled as ``True`` if they separate two labels in
`label_img`, ``False`` otherwise.

I used ``view_as_windows`` to get the neighborhood of each pixel.
Then I check whether there are two labels or more in that
neighborhood.
N)dtypeFedgemodeT)   )ndimnpiinfor   maxzerosshapesliceonesboolr	   pad
zeros_likendindexuniqueravellen)	label_imgr   	max_labelslabel_img_expandedpixelsedgeswindows
boundariesindexvaluess   &          ]/var/www/html/photoedit/myenv/lib/python3.14/site-packages/skimage/segmentation/boundaries.py_find_boundaries_subpixelr+   
   s'    >>D)--I'oo.o!a%!))o.	 D$"$t+F!*vGG&,,D9EEM )ubff%7H$QU+VGu%J.445<<YYw~3356F6{Q$(
!	 6
 ! 	/s   F c                T   V P                   R8X  d    V P                  \        P                  4      p V P                  p\
        P                  ! WA4      pVR8w  d   \        W4      \        W4      8g  pVR8X  d   W8g  pWg,          pV# VR8X  d   \        P                  ! V P                   4      P                  pW8H  p	\
        P                  ! WD4      p\        P                  ! V RR7      p
WV	&   \        W4      \        W4      8g  V	( ,          pWiV,          ,          pV# \        V 4      pV# )a  Return bool array where boundaries between labeled regions are True.

Parameters
----------
label_img : array of int or bool
    An array in which different regions are labeled with either different
    integers or boolean values.
connectivity : int in {1, ..., `label_img.ndim`}, optional
    A pixel is considered a boundary pixel if any of its neighbors
    has a different label. `connectivity` controls which pixels are
    considered neighbors. A connectivity of 1 (default) means
    pixels sharing an edge (in 2D) or a face (in 3D) will be
    considered neighbors. A connectivity of `label_img.ndim` means
    pixels sharing a corner will be considered neighbors.
mode : string in {'thick', 'inner', 'outer', 'subpixel'}
    How to mark the boundaries:

    - thick: any pixel not completely surrounded by pixels of the
      same label (defined by `connectivity`) is marked as a boundary.
      This results in boundaries that are 2 pixels thick.
    - inner: outline the pixels *just inside* of objects, leaving
      background pixels untouched.
    - outer: outline pixels in the background around object
      boundaries. When two objects touch, their boundary is also
      marked.
    - subpixel: return a doubled image, with pixels *between* the
      original pixels marked as boundary where appropriate.
background : int, optional
    For modes 'inner' and 'outer', a definition of a background
    label is required. See `mode` for descriptions of these two.

Returns
-------
boundaries : array of bool, same shape as `label_img`
    A bool image where ``True`` represents a boundary pixel. For
    `mode` equal to 'subpixel', ``boundaries.shape[i]`` is equal
    to ``2 * label_img.shape[i] - 1`` for all ``i`` (a pixel is
    inserted in between all other pairs of pixels).

Examples
--------
>>> 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]])
r   subpixelinnerouterTcopy)r   astyper   uint8r   ndigenerate_binary_structurer   r   r   r   arrayr+   )r    connectivityr   
backgroundr   	footprintr'   foreground_imager!   background_imageinverted_backgroundadjacent_objectss   &&&&        r*   find_boundariesr>   0   s   ^ & $$RXX.	>>D--dAIzi3wy7TT
7?(6*J  W_155I(655dAI"$((94"@4= 01..:;!! " -===J.y9
    c           	        \        V P                  4      p\        V RR7      pVP                  VRR7      pVP                  ^8X  d   \        V4      pVR8X  dL   \        P                  ! YwP                  RR
  Uu. uF  p^^V,          ,
          NK  	  up^.,           RR7      p\        WVR	7      p	Ve   \        V	\        R4      4      p
W7V
&   W'V	&   V# u upi )au  Return image with boundaries between labeled regions highlighted.

Parameters
----------
image : (M, N[, 3]) array
    Grayscale or RGB image.
label_img : (M, N) array of int
    Label array where regions are marked by different integer values.
color : length-3 sequence, optional
    RGB color of boundaries in the output image.
outline_color : length-3 sequence, optional
    RGB color surrounding boundaries in the output image. If None, no
    outline is drawn.
mode : string in {'thick', 'inner', 'outer', 'subpixel'}, optional
    The mode for finding boundaries.
background_label : int, optional
    Which label to consider background (this is only useful for
    modes ``inner`` and ``outer``).

Returns
-------
marked : (M, N, 3) array of float
    An image in which the boundaries between labels are
    superimposed on the original image.

See Also
--------
find_boundaries
T)
force_copyFr0   r-   Nmirrorr   )r   r8   )r   r   )r   r   r   r2   r   r
   r4   zoomr   r>   r   r   )imager    coloroutline_colorr   background_labelfloat_dtypemarkedr"   r'   outliness   &&&&&&     r*   mark_boundariesrL      s    J (4K%D1F]];U]3F{{a&!z
 Sb(9:(91QQYY(9:aS@x
 !BRSJ J(;F(CD(x:M ;s   :C
)   thickr   ))rM   rM   r   Nr/   r   )numpyr   scipyr   r4   _shared.utilsr   
morphologyr   r   r   utilr   r	   rF   r
   r+   r>   rL    r?   r*   <module>rU      s,       1 ? ? 0 #LFR7r?   