ó
 ‰\c           @   s9  d  d l  Z  d  d l 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 l m Z d  d l m Z d  d l m Z d  d	 l m Z d  d
 l m Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e j d d e f d e f d e f g ƒ d „  ƒ Z d „  Z d S(   iÿÿÿÿN(   t   ndimage(   t   color(   t   datat   data_dir(   t   feature(   t   img_as_float(   t   draw(   t   assert_almost_equal(   t   testing(   t   expected_warningsc       
   C   s   t  t j ƒ  d  d … d  d  … f j d d ƒ ƒ }  t j |  d d d d d d d
 d ƒ} t | ƒ d d d k s{ t ‚ d  S(   Ni   t   axisi   t   orientationsi	   t   pixels_per_celli   t   cells_per_blocki   t
   block_normt   L1i   (   i   i   (   i   i   i    i@   (   R   R   t	   astronautt   meanR   t   hogt   lent   AssertionError(   t   imgt   fd(    (    s=   lib/python2.7/site-packages/skimage/feature/tests/test_hog.pyt   test_hog_output_size   s    4c          C   s}   t  j t j ƒ  ƒ }  t j t j j t	 d ƒ ƒ } t
 j |  d d d d d d d d	 d
 t d t d t ƒ} t | | ƒ d  S(   Ns   astronaut_GRAY_hog_L1.npyR   i	   R   i   R   i   R   R   t   feature_vectort   transform_sqrtt	   visualize(   i   i   (   i   i   (   R   t   rgb2grayR   R   t   npt   loadt   ost   patht   joinR   R   R   t   Truet   FalseR   (   R   t   correct_outputt   output(    (    s=   lib/python2.7/site-packages/skimage/feature/tests/test_hog.pyt#   test_hog_output_correctness_l1_norm   s    	c          C   s}   t  j t j ƒ  ƒ }  t j t j j t	 d ƒ ƒ } t
 j |  d d d d d d d d	 d
 t d t d t ƒ} t | | ƒ d  S(   Ns   astronaut_GRAY_hog_L2-Hys.npyR   i	   R   i   R   i   R   s   L2-HysR   R   R   (   i   i   (   i   i   (   R   R   R   R   R   R   R   R   R    R   R   R   R!   R"   R   (   R   R#   R$   (    (    s=   lib/python2.7/site-packages/skimage/feature/tests/test_hog.pyt&   test_hog_output_correctness_l2hys_norm#   s    	c       
   C   sm   t  j ƒ  d  d … d  d … f }  t j |  d d d d d d d	 d
 ƒ} t | ƒ d d d k si t ‚ d  S(   Ni–   iÈ   R   i	   R   i   R   i   R   R   (   i   i   (   i   i   i   i   (   R   t   cameraR   R   R   R   (   t   imageR   (    (    s=   lib/python2.7/site-packages/skimage/feature/tests/test_hog.pyt&   test_hog_image_size_cell_size_mismatch/   s    "c          C   sT  d }  } t  j | |  f d d ƒ} d | | d )xt d ƒ D]} t  j | | ƒ } | j d ƒ } t j | d d d	 d d d d t d t d d ƒ\ } } t j | d d d	 d  d d! d t d t d d ƒ\ } }	 t j | d d d	 d" d d# d t d t d d ƒ\ }
 } t j | d d d	 d$ d d% d t d t d d ƒ\ } } t rŠd d  l	 j
 } | j ƒ  | j d d d ƒ | j | ƒ | j ƒ  | j d ƒ | j d d d ƒ | j | ƒ | j ƒ  | j d ƒ | j d d d ƒ | j |	 ƒ | j ƒ  | j d ƒ | j d d d ƒ | j | ƒ | j ƒ  | j d ƒ | j d d d ƒ | j | ƒ | j ƒ  | j d ƒ | j ƒ  n  t | | ƒ t | |	 ƒ t | |
 d d ƒt | | d d ƒt  j | j d d ƒ d d ƒ} | d& k rd d d d g } n- | d' k r-d d d d g } n t d ƒ ‚ t | | d d ƒq@ Wd  S((   Ni#   t   dtypet   floatid   i   i   t   uint8R   R   i   R   i   R   R   R   R   iÿÿÿÿi   R(   s$   HOG result visualisation (float img)i   s$   HOG result visualisation (uint8 img)s5   HOG result (transform_sqrt) visualisation (float img)i   s5   HOG result (transform_sqrt) visualisation (uint8 img)t   decimalR
   i    s+   Result is not determined for this rotation.(   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i    i   (   i   i   (   R   t   zerost   ranget   rot90t   astypeR   R   R!   R"   t   matplotlib.pyplott   pyplott   figuret   subplott   imshowt   colorbart   titlet   showR   t   maxt   reshapet	   Exception(   t   widtht   heightt   image0t   rott   image_floatt   image_uint8t	   hog_floatt   hog_img_floatt	   hog_uint8t   hog_img_uint8t   hog_float_normt   hog_img_float_normt   hog_uint8_normt   hog_img_uint8_normt   pltt   actualt   desired(    (    s=   lib/python2.7/site-packages/skimage/feature/tests/test_hog.pyt*   test_hog_basic_orientations_and_data_types6   sr    






!c          C   s¸  d }  } t  j | |  f ƒ } t j t | d ƒ t |  d ƒ t |  d ƒ ƒ \ } } d | | | f <t j | d ƒ } x7t d d ƒ D]&} t j	 | d | d d d d d
 t
 d t d d ƒ\ } } t rgd d  l j } | j ƒ  | j d	 d d	 ƒ | j | ƒ | j ƒ  | j d ƒ | j d	 d d ƒ | j | ƒ | j ƒ  | j d | ƒ | j ƒ  n  | j d | ƒ }	 t  j |	 d d ƒ}
 t  j |	 ƒ } t |
 | d d	 ƒqŠ Wd  S(   Nid   i   i   i   R   R   i   R   i   R   R   R   R   iÿÿÿÿRA   s)   HOG result visualisation, orientations=%dR
   i    R-   (   i   i   (   i   i   (   R   R.   R   t   circlet   intt   ndit   gaussian_filterR/   R   R   R!   R"   R2   R3   R4   R5   R6   R7   R8   R9   R;   R   R   (   R=   R>   R(   t   rrt   ccR   R   t   hog_imgRK   t
   hog_matrixRL   RM   (    (    s=   lib/python2.7/site-packages/skimage/feature/tests/test_hog.pyt   test_hog_orientations_circle—   s8    

9


	c          C   sõ   d }  } t  j | |  f d d ƒ} d | | d )t j | d d d |  | f d	 d d
 t d d ƒ\ } } | d } g  t | ƒ D] } | | k rƒ | ^ qƒ } | | d d … f d k j ƒ  sÉ t ‚ | | d d … f d k j ƒ  sñ t ‚ d S(   sz  Test that the visualization produces a line with correct orientation

    The hog visualization is expected to draw line segments perpendicular to
    the midpoints of orientation bins.  This example verifies that when
    orientations=3 and the gradient is entirely in the middle bin (bisected
    by the y-axis), the line segment drawn by the visualization is horizontal.
    i   R*   R+   i   i   R   i   R   R   R   R   R   Ni    iÿÿÿÿ(   i   i   (   R   R.   R   R   R!   R/   t   allR   (   R=   R>   R(   t   _t	   hog_imaget   middle_indext   xt   indices_excluding_middle(    (    s=   lib/python2.7/site-packages/skimage/feature/tests/test_hog.pyt"   test_hog_visualization_orientationÌ   s    	

+(c          C   s<   t  j d ƒ }  t j t ƒ  t j |  d d ƒWd  QXd  S(   Ni   R   t   Linf(   R   t   eyeR   t   raisest
   ValueErrorR   R   (   R   (    (    s=   lib/python2.7/site-packages/skimage/feature/tests/test_hog.pyt,   test_hog_block_normalization_incorrect_errorê   s    s   shape,multichanneli   c      
   C   sB   t  j |  ƒ } t j t ƒ  t j | d | d d ƒWd  QXd  S(   Nt   multichannelR   R   (   R   R.   R   Ra   Rb   R   R   (   t   shapeRd   R   (    (    s=   lib/python2.7/site-packages/skimage/feature/tests/test_hog.pyt   test_hog_incorrect_dimensionsð   s    c          C   s•   t  j ƒ  }  d |  d  d  … d  d  … d f <t j |  d t d d ƒ} xH d	 D]@ } t j t j |  | d d ƒd t d d ƒ} t | | ƒ qM Wd  S(
   Ni    i   i   Rd   R   R   R
   (   i   i   (   i   i   (   R   R   R   R   R!   R   t   rollR   (   R   t   hog_reft   nt   hog_fact(    (    s=   lib/python2.7/site-packages/skimage/feature/tests/test_hog.pyt)   test_hog_output_equivariance_multichannelû   s    $	(   i   i   i   (   i   i   (   i   i   i   i   (   R   t   numpyR   t   scipyR    RQ   t   skimageR   R   R   R   R   R   t   skimage._shared.testingR   t   skimage._sharedR   R	   R   R%   R&   R)   RN   RW   R^   Rc   t   parametrizeR"   R!   Rf   Rk   (    (    (    s=   lib/python2.7/site-packages/skimage/feature/tests/test_hog.pyt   <module>   s.   						a	5					