ó
 ‰\c           @` s[   d  d l  m Z m Z m Z d  d l Z d d l m Z m Z d d l	 m
 Z
 d „  Z d S(   i    (   t   divisiont   print_functiont   absolute_importNi   (   t   img_as_ubytet   cropi   (   t   _compute_thin_imagec         C` s  |  j  d k  s |  j  d k r4 t d |  j  ƒ ‚ n  t j |  ƒ }  t |  d t ƒ}  |  } |  j  d k r€ |  t j d f } n  t j | d d d d	 ƒ} | j ƒ  } d | | d
 k <t j	 t
 | ƒ ƒ } t | d d ƒ} |  j  d k rú | d
 } n  | | 9} | S(   s…  Compute the skeleton of a binary image.

    Thinning is used to reduce each connected component in a binary image
    to a single-pixel wide skeleton.

    Parameters
    ----------
    img : ndarray, 2D or 3D
        A binary image containing the objects to be skeletonized. Zeros
        represent background, nonzero values are foreground.

    Returns
    -------
    skeleton : ndarray
        The thinned image.

    See also
    --------
    skeletonize, medial_axis

    Notes
    -----
    The method of [Lee94]_ uses an octree data structure to examine a 3x3x3
    neighborhood of a pixel. The algorithm proceeds by iteratively sweeping
    over the image, and removing pixels at each iteration until the image
    stops changing. Each iteration consists of two steps: first, a list of
    candidates for removal is assembled; then pixels from this list are
    rechecked sequentially, to better preserve connectivity of the image.

    The algorithm this function implements is different from the algorithms
    used by either `skeletonize` or `medial_axis`, thus for 2D images the
    results produced by this function are generally different.

    References
    ----------
    .. [Lee94] T.-C. Lee, R.L. Kashyap and C.-N. Chu, Building skeleton models
           via 3-D medial surface/axis thinning algorithms.
           Computer Vision, Graphics, and Image Processing, 56(6):462-478, 1994.

    i   i   sJ   skeletonize_3d can only handle 2D or 3D images; got img.ndim = %s instead.t
   force_copy.t	   pad_widthi   t   modet   constanti    t
   crop_width(   t   ndimt
   ValueErrort   npt   ascontiguousarrayR   t   Falset   newaxist   padt   maxt   asarrayR   R   (   t   imgt   img_ot   maxval(    (    sA   lib/python2.7/site-packages/skimage/morphology/_skeletonize_3d.pyt   skeletonize_3d   s"    *
(   t
   __future__R    R   R   t   numpyR   t   utilR   R   t   _skeletonize_3d_cyR   R   (    (    (    sA   lib/python2.7/site-packages/skimage/morphology/_skeletonize_3d.pyt   <module>   s   