o
    :ήc                     @   s$   d dl Zdd Zdd Zdd ZdS )    Nc                 C   s8   d|  kr|ksJ  J | |kr|S | |k r|S | S )a  Clip coordinate between low and high values.

    This method was created so that `hessian_det_appx` does not have to make
    a Python call.

    Parameters
    ----------
    x : int
        Coordinate to be clipped.
    low : int
        The lower bound.
    high : int
        The higher bound.

    Returns
    -------
    x : int
        `x` clipped between `high` and `low`.
    r    )xlowhighr   r   P/tmp/pip-target-vg8gfxp4/lib/python/skimage/feature/_hessian_det_appx_pythran.py_clip   s   r   c                 C   s   t |d| jd d }t |d| jd d }t || d| jd d }t || d| jd d }| ||f | ||f  | ||f  | ||f  }td|S )aS  Integrate over the 2D integral image in the given window.

    This method was created so that `hessian_det_appx` does not have to make
    a Python call.

    Parameters
    ----------
    img : array
        The integral image over which to integrate.
    r : int
        The row number of the top left corner.
    c : int
        The column number of the top left corner.
    rl : int
        The number of rows over which to integrate.
    cl : int
        The number of columns over which to integrate.

    Returns
    -------
    ans : int
        The integral over the given window.
    r      g        )r   shapemax)imgrcrlclr2c2ansr   r   r   _integ"   s   0
r   c              	   C   s  t d| }| j\}}|d d }|d }|d }|}|d d }	tj| tjd}
d| | }|d dkr9|d7 }t|D ]}t|D ]}t| || || ||}t| |d |d ||}t| || |d ||}t| |d || ||}|| | | }| | }t| || d || d| d |}t| || d ||d  d| d |}|d|  }| | }t| || || d |d| d }t| ||d  || d |d| d }|d|  }| | }|| d||   |
||f< qCq=|
S )a.  Compute the approximate Hessian Determinant over a 2D image.

    This method uses box filters over integral images to compute the
    approximate Hessian Determinant as described in [1]_.

    Parameters
    ----------
    img : array
        The integral image over which to compute Hessian Determinant.
    sigma : float
        Standard deviation used for the Gaussian kernel, used for the Hessian
        matrix

    Returns
    -------
    out : array
        The array of the Determinant of Hessians.

    References
    ----------
    .. [1] Herbert Bay, Andreas Ess, Tinne Tuytelaars, Luc Van Gool,
           "SURF: Speeded Up Robust Features"
           ftp://ftp.vision.ee.ethz.ch/publications/articles/eth_biwi_00517.pdf

    Notes
    -----
    The running time of this method only depends on size of the image. It is
    independent of `sigma` as one would expect. The downside is that the
    result for `sigma` less than `3` is not accurate, i.e., not similar to
    the result obtained if someone computed the Hessian and took its
    determinant.
       r      )dtypeg      ?r   gQ?)intr	   np
empty_likedoubleranger   )r   sigmasizeheightwidths2s3lwboutw_ir   r   tlbrbltrdxymidsidedxxdyyr   r   r   _hessian_matrix_detF   s<   "

$(
$(
r0   )numpyr   r   r   r0   r   r   r   r   <module>   s    $