
\c           @   s   d  Z  d d l Z d d l m Z d d l m Z e d d d   Z	 e d d d   Z
 e d d d   Z e d d d	   Z d S(
   s!   
Binary morphological operations
iN(   t   ndimagei   (   t   default_selemc         C   sM   | d k r* t j |  j d t j } n  t j |  d | d | d t | S(   s  Return fast binary morphological erosion of an image.

    This function returns the same result as greyscale erosion but performs
    faster for binary images.

    Morphological erosion sets a pixel at ``(i,j)`` to the minimum over all
    pixels in the neighborhood centered at ``(i,j)``. Erosion shrinks bright
    regions and enlarges dark regions.

    Parameters
    ----------
    image : ndarray
        Binary input image.
    selem : ndarray, optional
        The neighborhood expressed as a 2-D array of 1's and 0's.
        If None, use cross-shaped structuring element (connectivity=1).
    out : ndarray of bool, optional
        The array to store the result of the morphology. If None is
        passed, a new array will be allocated.

    Returns
    -------
    eroded : ndarray of bool or uint
        The result of the morphological erosion taking values in
        ``[False, True]``.

    t   dtypet	   structuret   outputt   border_valueN(   t   Nonet   npt   emptyt   shapet   boolt   ndit   binary_erosiont   True(   t   imaget   selemt   out(    (    s8   lib/python2.7/site-packages/skimage/morphology/binary.pyR      s    c         C   sG   | d k r* t j |  j d t j } n  t j |  d | d | | S(   s  Return fast binary morphological dilation of an image.

    This function returns the same result as greyscale dilation but performs
    faster for binary images.

    Morphological dilation sets a pixel at ``(i,j)`` to the maximum over all
    pixels in the neighborhood centered at ``(i,j)``. Dilation enlarges bright
    regions and shrinks dark regions.

    Parameters
    ----------

    image : ndarray
        Binary input image.
    selem : ndarray, optional
        The neighborhood expressed as a 2-D array of 1's and 0's.
        If None, use cross-shaped structuring element (connectivity=1).
    out : ndarray of bool, optional
        The array to store the result of the morphology. If None, is
        passed, a new array will be allocated.

    Returns
    -------
    dilated : ndarray of bool or uint
        The result of the morphological dilation with values in
        ``[False, True]``.
    R   R   R   N(   R   R   R   R	   R
   R   t   binary_dilation(   R   R   R   (    (    s8   lib/python2.7/site-packages/skimage/morphology/binary.pyR   .   s    c         C   s(   t  |  |  } t | | d | } | S(   s  Return fast binary morphological opening of an image.

    This function returns the same result as greyscale opening but performs
    faster for binary images.

    The morphological opening on an image is defined as an erosion followed by
    a dilation. Opening can remove small bright spots (i.e. "salt") and connect
    small dark cracks. This tends to "open" up (dark) gaps between (bright)
    features.

    Parameters
    ----------
    image : ndarray
        Binary input image.
    selem : ndarray, optional
        The neighborhood expressed as a 2-D array of 1's and 0's.
        If None, use cross-shaped structuring element (connectivity=1).
    out : ndarray of bool, optional
        The array to store the result of the morphology. If None
        is passed, a new array will be allocated.

    Returns
    -------
    opening : ndarray of bool
        The result of the morphological opening.

    R   (   R   R   (   R   R   R   t   eroded(    (    s8   lib/python2.7/site-packages/skimage/morphology/binary.pyt   binary_openingQ   s    c         C   s(   t  |  |  } t | | d | } | S(   s  Return fast binary morphological closing of an image.

    This function returns the same result as greyscale closing but performs
    faster for binary images.

    The morphological closing on an image is defined as a dilation followed by
    an erosion. Closing can remove small dark spots (i.e. "pepper") and connect
    small bright cracks. This tends to "close" up (dark) gaps between (bright)
    features.

    Parameters
    ----------
    image : ndarray
        Binary input image.
    selem : ndarray, optional
        The neighborhood expressed as a 2-D array of 1's and 0's.
        If None, use cross-shaped structuring element (connectivity=1).
    out : ndarray of bool, optional
        The array to store the result of the morphology. If None,
        is passed, a new array will be allocated.

    Returns
    -------
    closing : ndarray of bool
        The result of the morphological closing.

    R   (   R   R   (   R   R   R   t   dilated(    (    s8   lib/python2.7/site-packages/skimage/morphology/binary.pyt   binary_closings   s    (   t   __doc__t   numpyR   t   scipyR    R   t   miscR   R   R   R   R   R   (    (    (    s8   lib/python2.7/site-packages/skimage/morphology/binary.pyt   <module>   s   ""!