ó
 ‰\c           @   sÌ   d  d l  Z d  d l m Z m Z d  d l m Z m Z d  d l m	 Z	 d  d l
 m Z m Z d  d l m Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿN(   t   assert_almost_equalt   assert_equal(   t   datat   img_as_float(   t   diamond(   t   match_templatet   peak_local_max(   t   testingc          C   s‡  d }  d t  j d ƒ } d t  j |  ƒ t  j |  ƒ d  d  d … } d d g } x8 | D]0 \ } } | | | | |  … | | |  … f <qY Wt  j j d ƒ | d t  j j d	 d ƒ 7} t | | ƒ } d
 } t | d | ƒ} t | ƒ d k r3| t	 | j
 ƒ }	 t  j |	 ƒ d  d  d … }
 | |
 d  } n  | t  j | d  d  … d f ƒ } x* t | | ƒ D] \ } } t | | ƒ qfWd  S(   Nid   g      à?i  gš™™™™™¹?iÿÿÿÿi2   iÈ   i   t   sizei   t   min_distancei   i    (   i  i  (   i2   i2   (   iÈ   iÈ   (   i  i  (   t   npt   onest   trit   randomt   seedt   uniformR   R   t   lent   tuplet   Tt   argsortt   zipR    (   R   t   imaget   targett   target_positionst   xt   yt   resultt   deltat	   positionst   intensitiest	   i_maxsortt	   xy_targett   xy(    (    sB   lib/python2.7/site-packages/skimage/feature/tests/test_template.pyt   test_template
   s$    -(#c          C   sÃ  d }  d } d \ } } d \ } } d t  j | | f ƒ } d | | | |  … | | |  … f <d	 | | | |  … | | |  … f <t  j |  d |  d f ƒ } d | d d |  … d d |  … f <t | | ƒ } t  j | j ƒ }	 |	 d	 }
 |	 d
 } t  j |
 | j ƒ } t  j | | j ƒ } t  j t  j	 | ƒ d | | f k ƒ sSt
 ‚ t  j t  j	 | ƒ d | | f k ƒ st
 ‚ t  j | j |
 d
 ƒ s t
 ‚ t  j | j | d ƒ s¿t
 ‚ d S(   s  Test that `match_template` gives the correct normalization.

    Normalization gives 1 for a perfect match and -1 for an inverted-match.
    This test adds positive and negative squares to a zero-array and matches
    the array with a positive template.
    i   i   i   i   i   i   g      à?i   i    iÿÿÿÿN(   i   i   (   i   i   (   R
   R   t   zerosR   R   t   flatt   unravel_indext   shapet   allt   arrayt   AssertionErrort   allclose(   t   nt   Nt   ipost   jpost   inegt   jnegR   t   templateR   t   sorted_resultt	   iflat_mint	   iflat_maxt
   min_resultt
   max_result(    (    sB   lib/python2.7/site-packages/skimage/feature/tests/test_template.pyt   test_normalization'   s&    $$$

..c          C   sŠ   t  j j d ƒ d d t  j j d d
 ƒ }  t  j d ƒ } d | d d	 … d d … f <t |  | ƒ } t  j t  j | ƒ ƒ s† t ‚ d S(   s  Test that `match_template` doesn't return NaN values.

    When image values are only slightly different, floating-point errors can
    cause a subtraction inside of a square root to go negative (without an
    explicit check that was added to `match_template`).
    i   g      à?g•Ö&è.>R   i   i   i    Ni   (   i   i   (   i   i   (	   R
   R   R   t   normalR   R   t   anyt   isnanR(   (   R   R0   R   (    (    sB   lib/python2.7/site-packages/skimage/feature/tests/test_template.pyt   test_no_nansK   s    c          C   sE   t  j d ƒ }  t  j d ƒ } t j t ƒ  t | |  ƒ Wd  QXd  S(   Ni   i   (   i   i   (   i   i   (   R
   R   R   t   raisest
   ValueErrorR   (   R   R0   (    (    sB   lib/python2.7/site-packages/skimage/feature/tests/test_template.pyt   test_switched_argumentsZ   s    c          C   s]  d t  d ƒ }  d t j d ƒ } t d d ƒ } | | d d … f c |  d d … d d … f 8<| | d	 d … f c |  7<| | d
 d … f c |  8<| | d d … f c |  d d … d d … f 7<t | |  d t d | j ƒ  ƒ} t j | j ƒ } t j	 | d  | j
 ƒ \ } } t | d ƒ t j	 | d | j
 ƒ \ } } t | d ƒ d S(   se  Test `match_template` when `pad_input=True`.

    This test places two full templates (one with values lower than the image
    mean, the other higher) and two half templates, which are on the edges of
    the image. The two full templates should score the top (positive and
    negative) matches and the centers of the half templates should score 2nd.
    g      à?i   i	   i   i   Ni   iýÿÿÿi   i÷ÿÿÿiüÿÿÿt	   pad_inputt   constant_valuesi   i    iþÿÿÿi   i   (   i	   i   (   i   i    (   i   i   (   R   R
   R   t   sliceR   t   Truet   meanR   R#   R$   R%   R   (   R0   R   t   midR   R1   t   it   j(    (    sB   lib/python2.7/site-packages/skimage/feature/tests/test_template.pyt   test_pad_inputa   s    	22c          C   s¡   t  j j d ƒ t  j j d d d ƒ }  t  j d
 ƒ } |  | d d … d d … d d … f <t | |  ƒ } t | j d ƒ t t  j | j	 ƒ  | j ƒ d ƒ d  S(   Ni   i   i   i   i   i   i   i   i
   (   i   i   i   (   i
   i
   i
   (   i   i   i   (
   R
   R   R   t   randR"   R   R   R%   R$   t   argmax(   R0   R   R   (    (    sB   lib/python2.7/site-packages/skimage/feature/tests/test_template.pyt   test_3d}   s    %c          C   s§   t  j j d ƒ t  j j d d d ƒ }  t  j d
 ƒ } |  | d d … d d … d d … f <t | |  d	 t ƒ} t | j d ƒ t t  j	 | j
 ƒ  | j ƒ d ƒ d  S(   Ni   i   i   i   i   i   i   i   R>   (   i   i   i   (   i   i   i   (   i   i   i   (   R
   R   R   RG   R"   R   RA   R   R%   R$   RH   (   R0   R   R   (    (    sB   lib/python2.7/site-packages/skimage/feature/tests/test_template.pyt   test_3d_pad_inputŠ   s    %c          C   sŽ   t  d ƒ }  t j d ƒ } |  d  d  … d d  … f | d d … d  d … f <t | |  d t d d ƒ} t t j | j ƒ  | j ƒ d ƒ d  S(   Ni   i
   iýÿÿÿi   i   R>   t   modet   reflecti   i    (   i
   i
   (   i   i    (	   R   R
   R"   R   RA   R   R$   RH   R%   (   R0   R   R   (    (    sB   lib/python2.7/site-packages/skimage/feature/tests/test_template.pyt   test_padding_reflect—   s    2	c       	   C   sÇ   t  j d ƒ }  t  j d ƒ } t j t ƒ  t | |  ƒ Wd  QXt  j d ƒ }  t  j d ƒ } t j t ƒ  t | |  ƒ Wd  QXt  j d	 ƒ }  t  j d
 ƒ } t j t ƒ  t | |  ƒ Wd  QXd  S(   Ni   i   i   i   (   i   i   i   (   i   i   (   i   i   (   i   i   i   (   i   i   i   i   (   i   i   i   (   R
   R   R   R;   R<   R   (   R   R0   (    (    sB   lib/python2.7/site-packages/skimage/feature/tests/test_template.pyt   test_wrong_input¢   s    c          C   s…   t  t j ƒ  ƒ }  t j d ƒ } d | d <t t  t j ƒ  ƒ | ƒ } | j ƒ  GH| j ƒ  d k  si t ‚ | j ƒ  d k s t ‚ d  S(	   Ni   i   gH¯¼šò×z>iÿÿÿÿ(   i   i   (   i   i   g›ò×  ð?g›ò×  ð¿(	   R   R   t   pageR
   R"   R   t   maxR(   t   min(   R   R0   R   (    (    sB   lib/python2.7/site-packages/skimage/feature/tests/test_template.pyt   test_bounding_values³   s    
(   t   numpyR
   t   skimage._shared.testingR    R   t   skimageR   R   t   skimage.morphologyR   t   skimage.featureR   R   t   skimage._sharedR   R!   R6   R:   R=   RF   RI   RJ   RM   RN   RR   (    (    (    sB   lib/python2.7/site-packages/skimage/feature/tests/test_template.pyt   <module>   s   		$							