ó
 ‰\c        	   @   sí  d  d l  m Z d  d l Z d  d l m Z d  d l m Z d d l m	 Z	 d d l
 m Z d d l m Z d d	 l m Z d
 d l m Z d d l m Z d d l m Z d
 d l m Z m Z d  d l m Z d d d „ Z d
 d d d „ Z d
 d d d d „ Z d „  Z d
 e  d „ Z! d „  Z" d „  Z# d d d d „ Z$ d
 d d d „ Z% d d d „ Z& d d d d
 d „ Z' d
 d  „ Z( d
 d! „ Z) d" d# d$ „ Z* d% d& d' „ Z+ d
 d d( e  e  e j, d d d) „ Z- d
 d* „ Z. d+ „  Z/ d S(,   iÿÿÿÿ(   t   combinations_with_replacementN(   t   ndimage(   t   statsi   (   t   img_as_float(   t   peak_local_max(   t   _prepare_grayscale_input_2D(   t   _corner_fasti   (   t   _hessian_matrix_det(   t   integral_image(   t   safe_as_int(   t   _corner_moravect   _corner_orientations(   t   warnt   constanti    c         C   sL   t  j |  d d d | d | ƒ} t  j |  d d d | d | ƒ} | | f S(   s  Compute derivatives in x and y direction using the Sobel operator.

    Parameters
    ----------
    image : ndarray
        Input image.
    mode : {'constant', 'reflect', 'wrap', 'nearest', 'mirror'}, optional
        How to handle values outside the image borders.
    cval : float, optional
        Used in conjunction with mode 'constant', the value outside
        the image boundaries.

    Returns
    -------
    imx : ndarray
        Derivative in x-direction.
    imy : ndarray
        Derivative in y-direction.

    t   axisi    t   modet   cvali   (   t   ndit   sobel(   t   imageR   R   t   imyt   imx(    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   _compute_derivatives   s    !!c   	      C   s   t  |  ƒ }  t |  d | d | ƒ\ } } t j | | | d | d | ƒ} t j | | | d | d | ƒ} t j | | | d | d | ƒ} | | | f S(   sÑ  Compute structure tensor using sum of squared differences.

    The structure tensor A is defined as::

        A = [Axx Axy]
            [Axy Ayy]

    which is approximated by the weighted sum of squared differences in a local
    window around each pixel in the image.

    Parameters
    ----------
    image : ndarray
        Input image.
    sigma : float, optional
        Standard deviation used for the Gaussian kernel, which is used as a
        weighting function for the local summation of squared differences.
    mode : {'constant', 'reflect', 'wrap', 'nearest', 'mirror'}, optional
        How to handle values outside the image borders.
    cval : float, optional
        Used in conjunction with mode 'constant', the value outside
        the image boundaries.

    Returns
    -------
    Axx : ndarray
        Element of the structure tensor for each pixel in the input image.
    Axy : ndarray
        Element of the structure tensor for each pixel in the input image.
    Ayy : ndarray
        Element of the structure tensor for each pixel in the input image.

    Examples
    --------
    >>> from skimage.feature import structure_tensor
    >>> square = np.zeros((5, 5))
    >>> square[2, 2] = 1
    >>> Axx, Axy, Ayy = structure_tensor(square, sigma=0.1)
    >>> Axx
    array([[ 0.,  0.,  0.,  0.,  0.],
           [ 0.,  1.,  0.,  1.,  0.],
           [ 0.,  4.,  0.,  4.,  0.],
           [ 0.,  1.,  0.,  1.,  0.],
           [ 0.,  0.,  0.,  0.,  0.]])

    R   R   (   R   R   R   t   gaussian_filter(	   R   t   sigmaR   R   R   R   t   Axxt   Axyt   Ayy(    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   structure_tensor.   s    0"""c         C   sÜ   t  |  ƒ }  t j |  d | d | d | ƒ} | d	 k rd |  j d k r[ t d ƒ d } qd d } n  t j | ƒ } t |  j ƒ } | d k r t	 | ƒ } n  g  t
 | d ƒ D]% \ } }	 t j | | d |	 ƒ^ q­ }
 |
 S(
   sß  Compute Hessian matrix.

    The Hessian matrix is defined as::

        H = [Hrr Hrc]
            [Hrc Hcc]

    which is computed by convolving the image with the second derivatives
    of the Gaussian kernel in the respective x- and y-directions.

    Parameters
    ----------
    image : ndarray
        Input image.
    sigma : float
        Standard deviation used for the Gaussian kernel, which is used as
        weighting function for the auto-correlation matrix.
    mode : {'constant', 'reflect', 'wrap', 'nearest', 'mirror'}, optional
        How to handle values outside the image borders.
    cval : float, optional
        Used in conjunction with mode 'constant', the value outside
        the image boundaries.
    order : {'xy', 'rc'}, optional
        This parameter allows for the use of reverse or forward order of
        the image axes in gradient computation. 'xy' indicates the usage
        of the last axis initially (Hxx, Hxy, Hyy), whilst 'rc' indicates
        the use of the first axis initially (Hrr, Hrc, Hcc).

    Returns
    -------
    Hrr : ndarray
        Element of the Hessian matrix for each pixel in the input image.
    Hrc : ndarray
        Element of the Hessian matrix for each pixel in the input image.
    Hcc : ndarray
        Element of the Hessian matrix for each pixel in the input image.

    Examples
    --------
    >>> from skimage.feature import hessian_matrix
    >>> square = np.zeros((5, 5))
    >>> square[2, 2] = 4
    >>> Hrr, Hrc, Hcc = hessian_matrix(square, sigma=0.1, order = 'rc')
    >>> Hrc
    array([[ 0.,  0.,  0.,  0.,  0.],
           [ 0.,  1.,  0., -1.,  0.],
           [ 0.,  0.,  0.,  0.,  0.],
           [ 0., -1.,  0.,  1.,  0.],
           [ 0.,  0.,  0.,  0.,  0.]])
    R   R   R   i   s¾   deprecation warning: the default order of the hessian matrix values will be "row-column" instead of "xy" starting in skimage version 0.15. Use order="rc" or order="xy" to set this explicitlyt   xyt   rcR   N(   R   R   R   t   Nonet   ndimR   t   npt   gradientt   ranget   reversedR    (   R   R   R   R   t   ordert   gaussian_filteredt	   gradientst   axest   ax0t   ax1t   H_elems(    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   hessian_matrixj   s    4
		8c         C   s“   |  d } t  j | j | j | j f ƒ } x` t t t | j ƒ d ƒ ƒ D]@ \ } \ } } |  | | d | | f <|  | | d | | f <qK W| S(   sª  Convert the upper-diagonal elements of the Hessian matrix to a matrix.

    Parameters
    ----------
    H_elems : list of array
        The upper-diagonal elements of the Hessian matrix, as returned by
        `hessian_matrix`.

    Returns
    -------
    hessian_image : array
        An array of shape ``(M, N[, ...], image.ndim, image.ndim)``,
        containing the Hessian matrix corresponding to each coordinate.
    i    i   .(   R!   t   zerost   shapeR    t	   enumerateR    R#   (   R+   R   t   hessian_imaget   idxt   rowt   col(    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   _hessian_matrix_image»   s    
".c         C   sl   t  |  ƒ }  |  j d k rC | rC t |  ƒ } t j t | | ƒ ƒ St t |  | ƒ ƒ } t j j	 | ƒ Sd S(   s  Compute the approximate Hessian Determinant over an image.

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

    Parameters
    ----------
    image : array
        The image over which to compute Hessian Determinant.
    sigma : float, optional
        Standard deviation used for the Gaussian kernel, used for the Hessian
        matrix.
    approximate : bool, optional
        If ``True`` and the image is 2D, use a much faster approximate
        computation. This argument has no effect on 3D and higher images.

    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
    -----
    For 2D images when ``approximate=True``, 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.
    i   N(
   R   R    R   R!   t   arrayR   R4   R,   t   linalgt   det(   R   R   t   approximatet   integralt   hessian_mat_array(    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   hessian_matrix_detÓ   s    $c         C   sp   |  | d t  j d | d |  | d ƒ d } |  | d t  j d | d |  | d ƒ d } | | f S(   Ni   i   (   R!   t   sqrt(   t   M00t   M01t   M11t   l1t   l2(    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt"   _image_orthogonal_matrix22_eigvals   s    33c         C   s   t  |  | | ƒ S(   sØ  Compute Eigen values of structure tensor.

    Parameters
    ----------
    Axx : ndarray
        Element of the structure tensor for each pixel in the input image.
    Axy : ndarray
        Element of the structure tensor for each pixel in the input image.
    Ayy : ndarray
        Element of the structure tensor for each pixel in the input image.

    Returns
    -------
    l1 : ndarray
        Larger eigen value for each input matrix.
    l2 : ndarray
        Smaller eigen value for each input matrix.

    Examples
    --------
    >>> from skimage.feature import structure_tensor, structure_tensor_eigvals
    >>> square = np.zeros((5, 5))
    >>> square[2, 2] = 1
    >>> Axx, Axy, Ayy = structure_tensor(square, sigma=0.1)
    >>> structure_tensor_eigvals(Axx, Axy, Ayy)[0]
    array([[ 0.,  0.,  0.,  0.,  0.],
           [ 0.,  2.,  4.,  2.,  0.],
           [ 0.,  4.,  0.,  4.,  0.],
           [ 0.,  2.,  4.,  2.,  0.],
           [ 0.,  0.,  0.,  0.,  0.]])

    (   RB   (   R   R   R   (    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   structure_tensor_eigvals  s    "c         C   sÕ   | d k	 r= | d k r! |  } n  | | | g }  t d ƒ n  t |  ƒ d k rg t j t |  Œ  ƒ } nj t |  ƒ } t j j | ƒ d d d d … f } t	 t
 | j d ƒ ƒ } t j | | j d f | ƒ } | S(   sÊ  Compute Eigenvalues of Hessian matrix.

    Parameters
    ----------
    H_elems : list of ndarray
        The upper-diagonal elements of the Hessian matrix, as returned
        by `hessian_matrix`.
    Hxy : ndarray, deprecated
        Element of the Hessian matrix for each pixel in the input image.
    Hyy : ndarray, deprecated
        Element of the Hessian matrix for each pixel in the input image.
    Hxx : ndarray, deprecated
        Element of the Hessian matrix for each pixel in the input image.

    Returns
    -------
    eigs : ndarray
        The eigenvalues of the Hessian matrix, in decreasing order. The
        eigenvalues are the leading dimension. That is, ``eigs[i, j, k]``
        contains the ith-largest eigenvalue at position (j, k).

    Examples
    --------
    >>> from skimage.feature import hessian_matrix, hessian_matrix_eigvals
    >>> square = np.zeros((5, 5))
    >>> square[2, 2] = 4
    >>> H_elems = hessian_matrix(square, sigma=0.1, order='rc')
    >>> hessian_matrix_eigvals(H_elems)[0]
    array([[ 0.,  0.,  2.,  0.,  0.],
           [ 0.,  1.,  0.,  1.,  0.],
           [ 2.,  0., -2.,  0.,  2.],
           [ 0.,  1.,  0.,  1.,  0.],
           [ 0.,  0.,  2.,  0.,  0.]])
    s¢   The API of `hessian_matrix_eigvals` has changed. Use a list of elements instead of separate arguments. The old version of the API will be removed in version 0.16.i   .Niÿÿÿÿi   (   R   R   t   lenR!   R5   RB   R4   R6   t   eigvalsht   tupleR#   R    t	   transpose(   R+   t   Hxyt   Hyyt   Hxxt   eigvalst   matricest   leading_axes(    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   hessian_matrix_eigvals+  s    #	% c      
   C   sZ   t  |  d | d | d | d d ƒ} t | ƒ \ } } d t j t j | | | | ƒ S(   su  Compute the shape index.

    The shape index, as defined by Koenderink & van Doorn [1]_, is a
    single valued measure of local curvature, assuming the image as a 3D plane
    with intensities representing heights.

    It is derived from the eigen values of the Hessian, and its
    value ranges from -1 to 1 (and is undefined (=NaN) in *flat* regions),
    with following ranges representing following shapes:

    .. table:: Ranges of the shape index and corresponding shapes.

      ===================  =============
      Interval (s in ...)  Shape
      ===================  =============
      [  -1, -7/8)         Spherical cup
      [-7/8, -5/8)         Through
      [-5/8, -3/8)         Rut
      [-3/8, -1/8)         Saddle rut
      [-1/8, +1/8)         Saddle
      [+1/8, +3/8)         Saddle ridge
      [+3/8, +5/8)         Ridge
      [+5/8, +7/8)         Dome
      [+7/8,   +1]         Spherical cap
      ===================  =============

    Parameters
    ----------
    image : ndarray
        Input image.
    sigma : float, optional
        Standard deviation used for the Gaussian kernel, which is used for
        smoothing the input data before Hessian eigen value calculation.
    mode : {'constant', 'reflect', 'wrap', 'nearest', 'mirror'}, optional
        How to handle values outside the image borders
    cval : float, optional
        Used in conjunction with mode 'constant', the value outside
        the image boundaries.

    Returns
    -------
    s : ndarray
        Shape index

    References
    ----------
    .. [1] Koenderink, J. J. & van Doorn, A. J.,
           "Surface shape and curvature scales",
           Image and Vision Computing, 1992, 10, 557-564.
           DOI:10.1016/0262-8856(92)90076-F

    Examples
    --------
    >>> from skimage.feature import shape_index
    >>> square = np.zeros((5, 5))
    >>> square[2, 2] = 4
    >>> s = shape_index(square, sigma=0.1)
    >>> s
    array([[ nan,  nan, -0.5,  nan,  nan],
           [ nan, -0. ,  nan, -0. ,  nan],
           [-0.5,  nan, -1. ,  nan, -0.5],
           [ nan, -0. ,  nan, -0. ,  nan],
           [ nan,  nan, -0.5,  nan,  nan]])
    R   R   R   R%   R   g       @(   R,   RN   R!   t   pit   arctan(   R   R   R   R   t   HR@   RA   (    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   shape_index`  s    B$c         C   sÔ   t  |  d | d | ƒ\ } } t  | d | d | ƒ\ } } t  | d | d | ƒ\ } } | | d | | d d | | | }	 | d | d }
 t j |  d t j ƒ} |
 d k } |	 | |
 | | | <| S(   sÐ  Compute Kitchen and Rosenfeld corner measure response image.

    The corner measure is calculated as follows::

        (imxx * imy**2 + imyy * imx**2 - 2 * imxy * imx * imy)
            / (imx**2 + imy**2)

    Where imx and imy are the first and imxx, imxy, imyy the second
    derivatives.

    Parameters
    ----------
    image : ndarray
        Input image.
    mode : {'constant', 'reflect', 'wrap', 'nearest', 'mirror'}, optional
        How to handle values outside the image borders.
    cval : float, optional
        Used in conjunction with mode 'constant', the value outside
        the image boundaries.

    Returns
    -------
    response : ndarray
        Kitchen and Rosenfeld response image.

    R   R   i   t   dtypei    (   R   R!   t
   zeros_liket   double(   R   R   R   R   R   t   imxxt   imxyt   imyxt   imyyt	   numeratort   denominatort   responset   mask(    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   corner_kitchen_rosenfeld¨  s    *t   kgš™™™™™©?gíµ ÷Æ°>c         C   sk   t  |  | ƒ \ } } } | | | d } | | }	 | d k rU | | |	 d }
 n d | |	 | }
 |
 S(   sê  Compute Harris corner measure response image.

    This corner detector uses information from the auto-correlation matrix A::

        A = [(imx**2)   (imx*imy)] = [Axx Axy]
            [(imx*imy)   (imy**2)]   [Axy Ayy]

    Where imx and imy are first derivatives, averaged with a gaussian filter.
    The corner measure is then defined as::

        det(A) - k * trace(A)**2

    or::

        2 * det(A) / (trace(A) + eps)

    Parameters
    ----------
    image : ndarray
        Input image.
    method : {'k', 'eps'}, optional
        Method to compute the response image from the auto-correlation matrix.
    k : float, optional
        Sensitivity factor to separate corners from edges, typically in range
        `[0, 0.2]`. Small values of k result in detection of sharp corners.
    eps : float, optional
        Normalisation factor (Noble's corner measure).
    sigma : float, optional
        Standard deviation used for the Gaussian kernel, which is used as
        weighting function for the auto-correlation matrix.

    Returns
    -------
    response : ndarray
        Harris response image.

    References
    ----------
    .. [1] http://kiwi.cs.dal.ca/~dparks/CornerDetection/harris.htm
    .. [2] http://en.wikipedia.org/wiki/Corner_detection

    Examples
    --------
    >>> from skimage.feature import corner_harris, corner_peaks
    >>> square = np.zeros([10, 10])
    >>> square[2:8, 2:8] = 1
    >>> square.astype(int)
    array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
    >>> corner_peaks(corner_harris(square), min_distance=1)
    array([[2, 2],
           [2, 7],
           [7, 2],
           [7, 7]])

    i   R_   (   R   (   R   t   methodR_   t   epsR   R   R   R   t   detAt   traceAR\   (    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   corner_harrisÓ  s    B
c         C   sK   t  |  | ƒ \ } } } | | t j | | d d | d ƒ d } | S(   sœ  Compute Shi-Tomasi (Kanade-Tomasi) corner measure response image.

    This corner detector uses information from the auto-correlation matrix A::

        A = [(imx**2)   (imx*imy)] = [Axx Axy]
            [(imx*imy)   (imy**2)]   [Axy Ayy]

    Where imx and imy are first derivatives, averaged with a gaussian filter.
    The corner measure is then defined as the smaller eigenvalue of A::

        ((Axx + Ayy) - sqrt((Axx - Ayy)**2 + 4 * Axy**2)) / 2

    Parameters
    ----------
    image : ndarray
        Input image.
    sigma : float, optional
        Standard deviation used for the Gaussian kernel, which is used as
        weighting function for the auto-correlation matrix.

    Returns
    -------
    response : ndarray
        Shi-Tomasi response image.

    References
    ----------
    .. [1] http://kiwi.cs.dal.ca/~dparks/CornerDetection/harris.htm
    .. [2] http://en.wikipedia.org/wiki/Corner_detection

    Examples
    --------
    >>> from skimage.feature import corner_shi_tomasi, corner_peaks
    >>> square = np.zeros([10, 10])
    >>> square[2:8, 2:8] = 1
    >>> square.astype(int)
    array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
    >>> corner_peaks(corner_shi_tomasi(square), min_distance=1)
    array([[2, 2],
           [2, 7],
           [7, 2],
           [7, 7]])

    i   i   (   R   R!   R<   (   R   R   R   R   R   R\   (    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   corner_shi_tomasi$  s    7/c   
      C   s®   t  |  | ƒ \ } } } | | | d } | | } t j |  d t j ƒ} t j |  d t j ƒ} | d k }	 | |	 | |	 | |	 <d | |	 | |	 d | |	 <| | f S(   s‰  Compute Foerstner corner measure response image.

    This corner detector uses information from the auto-correlation matrix A::

        A = [(imx**2)   (imx*imy)] = [Axx Axy]
            [(imx*imy)   (imy**2)]   [Axy Ayy]

    Where imx and imy are first derivatives, averaged with a gaussian filter.
    The corner measure is then defined as::

        w = det(A) / trace(A)           (size of error ellipse)
        q = 4 * det(A) / trace(A)**2    (roundness of error ellipse)

    Parameters
    ----------
    image : ndarray
        Input image.
    sigma : float, optional
        Standard deviation used for the Gaussian kernel, which is used as
        weighting function for the auto-correlation matrix.

    Returns
    -------
    w : ndarray
        Error ellipse sizes.
    q : ndarray
        Roundness of error ellipse.

    References
    ----------
    .. [1] http://www.ipb.uni-bonn.de/uploads/tx_ikgpublication/foerstner87.fast.pdf
    .. [2] http://en.wikipedia.org/wiki/Corner_detection

    Examples
    --------
    >>> from skimage.feature import corner_foerstner, corner_peaks
    >>> square = np.zeros([10, 10])
    >>> square[2:8, 2:8] = 1
    >>> square.astype(int)
    array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
    >>> w, q = corner_foerstner(square)
    >>> accuracy_thresh = 0.5
    >>> roundness_thresh = 0.3
    >>> foerstner = (q > roundness_thresh) * (w > accuracy_thresh) * w
    >>> corner_peaks(foerstner, min_distance=1)
    array([[2, 2],
           [2, 7],
           [7, 2],
           [7, 7]])

    i   RS   i    i   (   R   R!   RT   RU   (
   R   R   R   R   R   Rb   Rc   t   wt   qR]   (    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   corner_foerstnerc  s    >
i   g333333Ã?c         C   s1   t  |  ƒ }  t j |  ƒ }  t |  | | ƒ } | S(   sø  Extract FAST corners for a given image.

    Parameters
    ----------
    image : 2D ndarray
        Input image.
    n : int
        Minimum number of consecutive pixels out of 16 pixels on the circle
        that should all be either brighter or darker w.r.t testpixel.
        A point c on the circle is darker w.r.t test pixel p if
        `Ic < Ip - threshold` and brighter if `Ic > Ip + threshold`. Also
        stands for the n in `FAST-n` corner detector.
    threshold : float
        Threshold used in deciding whether the pixels on the circle are
        brighter, darker or similar w.r.t. the test pixel. Decrease the
        threshold when more corners are desired and vice-versa.

    Returns
    -------
    response : ndarray
        FAST corner response image.

    References
    ----------
    .. [1] Edward Rosten and Tom Drummond
           "Machine Learning for high-speed corner detection",
           http://www.edwardrosten.com/work/rosten_2006_machine.pdf
    .. [2] Wikipedia, "Features from accelerated segment test",
           https://en.wikipedia.org/wiki/Features_from_accelerated_segment_test

    Examples
    --------
    >>> from skimage.feature import corner_fast, corner_peaks
    >>> square = np.zeros((12, 12))
    >>> square[3:9, 3:9] = 1
    >>> square.astype(int)
    array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
           [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
           [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
           [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
           [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
           [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
    >>> corner_peaks(corner_fast(square, 9), min_distance=1)
    array([[3, 3],
           [3, 8],
           [8, 3],
           [8, 8]])

    (   R   R!   t   ascontiguousarrayR   (   R   t   nt	   thresholdR\   (    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   corner_fast³  s    8i   g®Gáz®ï?c   5      C   s‘  | d d } t  j |  d | d d d d ƒ}  t | | ƒ } t  j d d t  j ƒ} t  j d d t  j ƒ} t  j d d t  j ƒ} t  j d d t  j ƒ} | d d }	 t j j d | |	 |	 ƒ }
 t j j | |	 |	 ƒ } t  j | | d … | | d … f \ } } t  j	 | d t  j ƒ} xXt
 | ƒ D]J\ } \ } } | | d } | | d } | | d } | | d } |  | | … | | … f } t | d d d	 d ƒ\ } } | | d d
 … d d
 … f } | | d d
 … d d
 … f } | | d d
 … d d
 … f } t  j | ƒ } t  j | ƒ } t  j | ƒ } t  j | | ƒ } t  j | | ƒ }  t  j | | ƒ }! t  j | | ƒ }" t  j | | ƒ }# t  j | | ƒ }$ | | d <| | d <| d <| | d <| | d <| | d <| d <| | d <|  |! |# |" f | (|$ |! | |" f | (y. t  j j | | ƒ }% t  j j | | ƒ }& Wn< t  j j k
 r›t  j t  j f | | d d … f <q5n X| |% d }' | |% d }( | |& d }) | |& d }* |( |( }+ |( |' }, |' |' }- |* |* }. |* |) }/ |) |) }0 t  j | |- d | |, | |+ ƒ }1 t  j | |0 d | |/ | |. ƒ }2 |1 t  j d ƒ k  r”|2 t  j d ƒ k  r”t  j }3 n" |1 d k r¬t  j }3 n
 |2 |1 }3 t |3 | k  ƒ t |3 |
 k ƒ }4 |4 d
 k r| |% d | |% d f | | d d … f <q5|4 d k rDt  j t  j f | | d d … f <q5|4 d k r5| |& d | |& d f | | d d … f <q5q5W| | 8} | S(   sp  Determine subpixel position of corners.

    A statistical test decides whether the corner is defined as the
    intersection of two edges or a single peak. Depending on the classification
    result, the subpixel corner location is determined based on the local
    covariance of the grey-values. If the significance level for either
    statistical test is not sufficient, the corner cannot be classified, and
    the output subpixel position is set to NaN.

    Parameters
    ----------
    image : ndarray
        Input image.
    corners : (N, 2) ndarray
        Corner coordinates `(row, col)`.
    window_size : int, optional
        Search window size for subpixel estimation.
    alpha : float, optional
        Significance level for corner classification.

    Returns
    -------
    positions : (N, 2) ndarray
        Subpixel corner positions. NaN for "not classified" corners.

    References
    ----------
    .. [1] http://www.ipb.uni-bonn.de/uploads/tx_ikgpublication/           foerstner87.fast.pdf
    .. [2] http://en.wikipedia.org/wiki/Corner_detection

    Examples
    --------
    >>> from skimage.feature import corner_harris, corner_peaks, corner_subpix
    >>> img = np.zeros((10, 10))
    >>> img[:5, :5] = 1
    >>> img[5:, 5:] = 1
    >>> img.astype(int)
    array([[1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
           [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
           [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
           [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
           [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
           [0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
           [0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
           [0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
           [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]])
    >>> coords = corner_peaks(corner_harris(img), min_distance=2)
    >>> coords_subpix = corner_subpix(img, coords, window_size=7)
    >>> coords_subpix
    array([[ 4.5,  4.5]])

    i   i   t	   pad_widthR   R   t   constant_valuesi    RS   R   iÿÿÿÿN(   i   i   (   i   i   (   i   (   i   (   i    i    (   i    i   (   i   i    (   i   i   (   i    i    (   i    i   (   i   i    (   i   i   (   R!   t   padR	   R-   RU   R   t   ft   isft   mgridRT   R/   R   t   sumR6   t   solvet   LinAlgErrort   nant   spacingt   inft   int(5   R   t   cornerst   window_sizet   alphat   wextt   N_dott   N_edget   b_dott   b_edget
   redundancyt
   t_crit_dott   t_crit_edget   yt   xt   corners_subpixt   it   y0t   x0t   minyt   maxyt   minxt   maxxt   windowt   winxt   winyt	   winx_winxt	   winx_winyt	   winy_winyR   R   R   t   bxx_xt   bxx_yt   bxy_xt   bxy_yt   byy_xt   byy_yt   est_dott   est_edget   ry_dott   rx_dott   ry_edget   rx_edget   rxx_dott   rxy_dott   ryy_dott   rxx_edget   rxy_edget   ryy_edget   var_dott   var_edget   tt   corner_class(    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   corner_subpixò  s’    9!/   



"





!!*
"/%3
gš™™™™™¹?c	         C   sõ   t  |  d | d | d | d | d t d | d | d | ƒ}	 | d	 k rÎ t j |	 j ƒ  ƒ }
 xn |
 D]c \ } } |	 | | f rd t |	 | | | | d
 … | | | | d
 … f <t |	 | | f <qd qd Wn  | t k rí t j |	 j ƒ  ƒ S|	 Sd S(   s"  Find corners in corner measure response image.

    This differs from `skimage.feature.peak_local_max` in that it suppresses
    multiple connected peaks with the same accumulator value.

    Parameters
    ----------
    * : *
        See :py:meth:`skimage.feature.peak_local_max`.

    Examples
    --------
    >>> from skimage.feature import peak_local_max
    >>> response = np.zeros((5, 5))
    >>> response[2:4, 2:4] = 1
    >>> response
    array([[ 0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  1.,  1.,  0.],
           [ 0.,  0.,  1.,  1.,  0.],
           [ 0.,  0.,  0.,  0.,  0.]])
    >>> peak_local_max(response)
    array([[3, 3],
           [3, 2],
           [2, 3],
           [2, 2]])
    >>> corner_peaks(response)
    array([[2, 2]])

    t   min_distancet   threshold_abst   threshold_relt   exclude_bordert   indicest	   num_peakst	   footprintt   labelsi    i   N(   R   t   FalseR!   RG   t   nonzerot   True(   R   R¬   R­   R®   R¯   R°   R±   R²   R³   t   peakst   coordst   rt   c(    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   corner_peaks¡  s    "4c         C   s   t  |  | ƒ S(   sÕ  Compute Moravec corner measure response image.

    This is one of the simplest corner detectors and is comparatively fast but
    has several limitations (e.g. not rotation invariant).

    Parameters
    ----------
    image : ndarray
        Input image.
    window_size : int, optional
        Window size.

    Returns
    -------
    response : ndarray
        Moravec response image.

    References
    ----------
    .. [1] http://kiwi.cs.dal.ca/~dparks/CornerDetection/moravec.htm
    .. [2] http://en.wikipedia.org/wiki/Corner_detection

    Examples
    --------
    >>> from skimage.feature import corner_moravec
    >>> square = np.zeros([7, 7])
    >>> square[3, 3] = 1
    >>> square.astype(int)
    array([[0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0]])
    >>> corner_moravec(square).astype(int)
    array([[0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0],
           [0, 0, 1, 1, 1, 0, 0],
           [0, 0, 1, 2, 1, 0, 0],
           [0, 0, 1, 1, 1, 0, 0],
           [0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0]])
    (   R
   (   R   R{   (    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   corner_moravec×  s    -c         C   s   t  |  | | ƒ S(   s	  Compute the orientation of corners.

    The orientation of corners is computed using the first order central moment
    i.e. the center of mass approach. The corner orientation is the angle of
    the vector from the corner coordinate to the intensity centroid in the
    local neighborhood around the corner calculated using first order central
    moment.

    Parameters
    ----------
    image : 2D array
        Input grayscale image.
    corners : (N, 2) array
        Corner coordinates as ``(row, col)``.
    mask : 2D array
        Mask defining the local neighborhood of the corner used for the
        calculation of the central moment.

    Returns
    -------
    orientations : (N, 1) array
        Orientations of corners in the range [-pi, pi].

    References
    ----------
    .. [1] Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski
          "ORB : An efficient alternative to SIFT and SURF"
          http://www.vision.cs.chubu.ac.jp/CV-R/pdf/Rublee_iccv2011.pdf
    .. [2] Paul L. Rosin, "Measuring Corner Properties"
          http://users.cs.cf.ac.uk/Paul.Rosin/corner2.pdf

    Examples
    --------
    >>> from skimage.morphology import octagon
    >>> from skimage.feature import (corner_fast, corner_peaks,
    ...                              corner_orientations)
    >>> square = np.zeros((12, 12))
    >>> square[3:9, 3:9] = 1
    >>> square.astype(int)
    array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
           [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
           [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
           [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
           [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
           [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
    >>> corners = corner_peaks(corner_fast(square, 9), min_distance=1)
    >>> corners
    array([[3, 3],
           [3, 8],
           [8, 3],
           [8, 8]])
    >>> orientations = corner_orientations(square, corners, octagon(3, 2))
    >>> np.rad2deg(orientations)
    array([  45.,  135.,  -45., -135.])

    (   R   (   R   Rz   R]   (    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   corner_orientations  s    ?(0   t	   itertoolsR    t   numpyR!   t   scipyR   R   R   t   utilR   t   featureR   t   feature.utilR   t   feature.corner_cyR   t   _hessian_det_appxR   t	   transformR   t   _shared.utilsR	   t	   corner_cyR
   R   t   warningsR   R   R   R   R,   R4   R¶   R;   RB   RC   RN   RR   R^   Rd   Re   Rh   Rl   R«   Rx   R»   R¼   R½   (    (    (    s5   lib/python2.7/site-packages/skimage/feature/corner.pyt   <module>   s@   <Q	-		%5H+Q?P?¯	40