ó
 ‰\c           @   s>   d  d l  Z d  d l Z d d l m Z d „  Z d „  Z d S(   iÿÿÿÿNi   (   t   warnc         C   s6   |  } x) t  |  j ƒ D] } | j d | ƒ } q W| S(   s0  Integral image / summed area table.

    The integral image contains the sum of all elements above and to the
    left of it, i.e.:

    .. math::

       S[m, n] = \sum_{i \leq m} \sum_{j \leq n} X[i, j]

    Parameters
    ----------
    image : ndarray
        Input image.

    Returns
    -------
    S : ndarray
        Integral image/summed area table of same shape as input image.

    References
    ----------
    .. [1] F.C. Crow, "Summed-area tables for texture mapping,"
           ACM SIGGRAPH Computer Graphics, vol. 18, 1984, pp. 207-212.

    t   axis(   t   ranget   ndimt   cumsum(   t   imaget   St   i(    (    s9   lib/python2.7/site-packages/skimage/transform/integral.pyt   integral_image   s    c      	   C   s  t  j t  j | ƒ ƒ } t  j t  j | ƒ ƒ } | j d } |  j } t  j | | d g ƒ } | d k  } | d k  } | | | | | } | | | | | } t  j | | d k  ƒ rÌ t d ƒ ‚ n  t  j | ƒ } d |  j } t	 t
 | d ƒ d ƒ }	 xú t | ƒ D]ì }
 t
 |
 ƒ d j |	 ƒ } g  | D] } | d k ^ q5} d t | ƒ } g  t | ƒ D]' } t  j | | d | d k  ƒ ^ qj} | t  j | ƒ | d | } | g  t | ƒ D]. } | | sî| |  t | | ƒ n d ^ qÆ7} qW| S(   sµ  Use an integral image to integrate over a given window.

    Parameters
    ----------
    ii : ndarray
        Integral image.
    start : List of tuples, each tuple of length equal to dimension of `ii`
        Coordinates of top left corner of window(s).
        Each tuple in the list contains the starting row, col, ... index
        i.e `[(row_win1, col_win1, ...), (row_win2, col_win2,...), ...]`.
    end : List of tuples, each tuple of length equal to dimension of `ii`
        Coordinates of bottom right corner of window(s).
        Each tuple in the list containing the end row, col, ... index i.e
        `[(row_win1, col_win1, ...), (row_win2, col_win2, ...), ...]`.

    Returns
    -------
    S : scalar or ndarray
        Integral (sum) over the given window(s).


    Examples
    --------
    >>> arr = np.ones((5, 6), dtype=np.float)
    >>> ii = integral_image(arr)
    >>> integrate(ii, (1, 0), (1, 2))  # sum from (1, 0) to (1, 2)
    array([ 3.])
    >>> integrate(ii, [(3, 3)], [(4, 5)])  # sum from (3, 3) to (4, 5)
    array([ 6.])
    >>> # sum from (1, 0) to (1, 2) and from (3, 3) to (4, 5)
    >>> integrate(ii, [(1, 0), (3, 3)], [(1, 2), (4, 5)])
    array([ 3.,  6.])
    i    i   s1   end coordinates must be greater or equal to starti   t   1iÿÿÿÿ(   t   npt
   atleast_2dt   arrayt   shapet   tilet   anyt
   IndexErrort   zerosR   t   lent   binR   t   zfillt   sumt   invertt   tuple(   t   iit   startt   endt   rowst   total_shapet   start_negativest   end_negativesR   t   bit_permt   widthR   t   binaryt   bitt	   bool_maskt   signt   rt   badt   corner_points(    (    s9   lib/python2.7/site-packages/skimage/transform/integral.pyt	   integrate'   s6    "	
7C(   t   numpyR
   t   collectionst   _shared.utilsR    R   R(   (    (    (    s9   lib/python2.7/site-packages/skimage/transform/integral.pyt   <module>   s   	 