
    1-Ph                     (    d dl ZddlmZ ddddZdS )    N   )label)outc                   t          fd| j        D                       r|t          d          ||                                 }|Nd|j         d|j         }|j        |j        k    r	t          |f|j        t
          k    rt          d          | }nt          j        |t
                    }dz   }t          |          }t          | d          }	d	 |j        D             }
t          |j                  D ]B}||
|<   d
|t          |
          <   |	|
|<   d
|t          |
          <   t          d          |
|<   Ct          |dd
          \  } }t          j        | |                   }t          j        |dz             }t          j        ||          }||                     d                                       | j                  }|||<   |S )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   $   K   | ]
}|k    V  d S N ).0sbuffer_sizes     b/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/segmentation/_clear_border.py	<genexpr>zclear_border.<locals>.<genexpr>?   s(      
2
2;!
2
2
2
2
2
2    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   c                 ,    g | ]}t          d           S r   )slice)r
   _s     r   
<listcomp>z clear_border.<locals>.<listcomp>V   s    111!%++111r   Tr   )
background
return_num)anyshape
ValueErrorcopyr   bool	TypeErrornp
zeros_liker   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_borderr6      s   r 
2
2
2
2V\
2
2
222 Lt|JKKK
{kkmm090 0#':0 0 	 9
""w''::;;;% -4000Ao**sdD!!11sy111sx 	$ 	$AF1I%)GE&MM"F1I%)GE&MM"dF1II 31>>>NFF iw00Oi
##G/22JfnnR(()11&,??D CIJr   )r   r   N)numpyr   measurer   r6   r	   r   r   <module>r9      sU             g4 g g g g g g gr   