
    9i                     *    S SK rSSKJr  SSS.S jjrg)    N   )label)outc                  ^ [        U4S jU R                   5       5      (       a  Uc  [        S5      eUc  U R                  5       nUba  SUR                   SUR                   3nUR                  UR                  :w  a  [        U4eUR                  [
        :w  a  [        S5      eU) nO[        R                  " U[
        S9nTS-   n[        U5      n[        U* S5      n	UR                   V
s/ s H  n
[        S5      PM     nn
[        UR                  5       H4  nXU'   S	U[        U5      '   XU'   S	U[        U5      '   [        S5      X'   M6     [        US
S	S9u  p[        R                  " X   5      n[        R                  " US-   5      n[        R                   " X5      nUU R#                  S5         R#                  U R                  5      nX$U'   U$ s  sn
f )a  Clear objects connected to the label image border.

Parameters
----------
labels : (M[, N[, ..., P]]) array of int or bool
    Imaging data labels.
buffer_size : int, optional
    The width of the border examined.  By default, only objects
    that touch the outside of the image are removed.
bgval : float or int, optional
    Cleared objects are set to this value.
mask : ndarray of bool, same shape as `image`, optional.
    Image data mask. Objects in labels image overlapping with
    False pixels of mask will be removed. If defined, the
    argument buffer_size will be ignored.
out : ndarray
    Array of the same shape as `labels`, into which the
    output is placed. By default, a new array is created.

Returns
-------
out : (M[, N[, ..., P]]) array
    Imaging data labels with cleared borders

Examples
--------
>>> import numpy as np
>>> from skimage.segmentation import clear_border
>>> labels = np.array([[0, 0, 0, 0, 0, 0, 0, 1, 0],
...                    [1, 1, 0, 0, 1, 0, 0, 1, 0],
...                    [1, 1, 0, 1, 0, 1, 0, 0, 0],
...                    [0, 0, 0, 1, 1, 1, 1, 0, 0],
...                    [0, 1, 1, 1, 1, 1, 1, 1, 0],
...                    [0, 0, 0, 0, 0, 0, 0, 0, 0]])
>>> clear_border(labels)
array([[0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 0, 0],
       [0, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0]])
>>> mask = np.array([[0, 0, 1, 1, 1, 1, 1, 1, 1],
...                  [0, 0, 1, 1, 1, 1, 1, 1, 1],
...                  [1, 1, 1, 1, 1, 1, 1, 1, 1],
...                  [1, 1, 1, 1, 1, 1, 1, 1, 1],
...                  [1, 1, 1, 1, 1, 1, 1, 1, 1],
...                  [1, 1, 1, 1, 1, 1, 1, 1, 1]]).astype(bool)
>>> clear_border(labels, mask=mask)
array([[0, 0, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 0, 0, 1, 0, 0, 1, 0],
       [0, 0, 0, 1, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 0, 0],
       [0, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0]])

c              3   .   >#    U  H
  nTU:  v   M     g 7f)N ).0sbuffer_sizes     b/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/segmentation/_clear_border.py	<genexpr>clear_border.<locals>.<genexpr>?   s     
2\;!\s   Nz/buffer size may not be greater than labels sizez3labels and mask should have the same shape but are z and zmask should be of type bool.)dtype   Tr   )
background
return_num)anyshape
ValueErrorcopyr   bool	TypeErrornp
zeros_likeslicerangendimtupler   uniquearangeisinreshape)labelsr   bgvalmaskr   err_msgbordersextslstartslend_slicesdnumberborders_indicesindices
label_masks    `               r   clear_borderr3      s   r 
2V\\
222t|JKK
{kkm99+U4::,0 	 99

"w'':::;;% --40Ao*sdD!'*yy1y!%+y1sxxA1I%)GE&M"1I%)GE&M"dFI ! 31>NF ii0Oii
#G2JfnnR()11&,,?D IJ/ 2s   /G)r   r   N)numpyr   measurer   r3   r       r   <module>r7      s     g4 gr6   