ó
 ‰\c           @   s2   d  d l  Z d d l m Z d d e d „ Z d S(   iÿÿÿÿNi   (   t   labeli    c            sŠ  |  } t  ‡  f d †  | j Dƒ ƒ r4 t d ƒ ‚ n  t j | d t j ƒ} ˆ  d } t | ƒ } t | d ƒ } g  | j D] }	 t |	 ƒ ^ q| }
 xW t | j	 ƒ D]F } t
 |
 ƒ } | | | <t | t | ƒ <| | | <t | t | ƒ <q¤ Wt | d d ƒ}  t j |  ƒ d } t j |  | ƒ } t j | d ƒ } t j | | ƒ } | |  j ƒ  j |  j ƒ } | s|| j ƒ  } n  | | | <| S(   s.  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.
    in_place : bool, optional
        Whether or not to manipulate the labels array in-place.

    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],
    ...                    [0, 0, 0, 0, 1, 0, 0, 0, 0],
    ...                    [1, 0, 0, 1, 0, 1, 0, 0, 0],
    ...                    [0, 0, 1, 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, 1, 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   s   |  ] } ˆ  | k Vq d  S(   N(    (   t   .0t   s(   t   buffer_size(    sA   lib/python2.7/site-packages/skimage/segmentation/_clear_border.pys	   <genexpr>.   s    s.   buffer size may not be greater than image sizet   dtypei   t
   backgroundi    N(   t   anyt   shapet
   ValueErrort   npt
   zeros_liket   bool_t   slicet   Nonet   ranget   ndimt   listt   Truet   tupleR    t   maxt   uniquet   aranget   in1dt   ravelt   reshapet   copy(   t   labelsR   t   bgvalt   in_placet   imaget   borderst   extt   slstartt   slendR   t   slicest   dt   slicedimt   numbert   borders_indicest   indicest
   label_maskt   mask(    (   R   sA   lib/python2.7/site-packages/skimage/segmentation/_clear_border.pyt   clear_border   s0    '
"


(   t   numpyR	   t   measureR    t   FalseR*   (    (    (    sA   lib/python2.7/site-packages/skimage/segmentation/_clear_border.pyt   <module>   s   