ó
 ‰\c           @   s0   d  d l  m Z d  d l m Z d d „ Z d S(   iÿÿÿÿ(   t   unique(   t   entropyi   c         C   s(   t  |  d t ƒ\ } } t | d | ƒS(   s+  Calculate the Shannon entropy of an image.

    The Shannon entropy is defined as S = -sum(pk * log(pk)),
    where pk are frequency/probability of pixels of value k.

    Parameters
    ----------
    image : (N, M) ndarray
        Grayscale input image.
    base : float, optional
        The logarithmic base to use.

    Returns
    -------
    entropy : float

    Notes
    -----
    The returned value is measured in bits or shannon (Sh) for base=2, natural
    unit (nat) for base=np.e and hartley (Hart) for base=10.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Entropy_(information_theory)
    .. [2] https://en.wiktionary.org/wiki/Shannon_entropy

    Examples
    --------
    >>> from skimage import data
    >>> shannon_entropy(data.camera())
    7.0479552324230861
    t   return_countst   base(   R    t   Truet   scipy_entropy(   t   imageR   t   _t   counts(    (    s6   lib/python2.7/site-packages/skimage/measure/entropy.pyt   shannon_entropy   s    "N(   t   numpyR    t   scipy.statsR   R   R	   (    (    (    s6   lib/python2.7/site-packages/skimage/measure/entropy.pyt   <module>   s   