o
    :ήc-                     @   s  d dl Zd dlZd dlmZ d dlmZmZmZ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	 Zejd
ejejgdd Zejd
ejejgdd Zdd Zdd Zdd Zdd Zdd Zdd Zejdg ddd Z dd  Z!ejd!g d"d#d$ Z"dS )%    N)assert_almost_equal)colordatadrawfeatureimg_as_float)filters)expected_warnings)fetch)_supported_float_typec                  C   sL   t t d dd d f jdd} tj| ddddd}t|d	ks$J d S )
N      axis	      r      r   L1orientationspixels_per_cellcells_per_block
block_normi H  )r   r   	astronautmeanr   hoglen)imgfd r!   E/tmp/pip-target-vg8gfxp4/lib/python/skimage/feature/tests/test_hog.pytest_hog_output_size   s
   $
r#   dtypec              
   C   z   t t j| dd}ttd}tj	|dddddddd	}t
| }|j|ks+J |tjkr2d
nd}t|||d d S )NFr$   copyzdata/astronaut_GRAY_hog_L1.npyr   r      r)   r   Tr   r   r   r   feature_vectortransform_sqrt	visualize      decimalr   rgb2grayr   r   astypenploadr
   r   r   r   r$   float64r   r$   r   correct_outputoutputfloat_dtyper1   r!   r!   r"   #test_hog_output_correctness_l1_norm      
r<   c              
   C   r%   )NFr&   z"data/astronaut_GRAY_hog_L2-Hys.npyr   r   r(   zL2-HysTr*   r.   r/   r0   r2   r8   r!   r!   r"   &test_hog_output_correctness_l2hys_norm$   r=   r>   c                  C   s@   t  d dd df } tj| ddddd}t|dksJ d S )	N      r   r   r   r   r   i  )r   camerar   r   r   )imager    r!   r!   r"   &test_hog_image_size_cell_size_mismatch3   s
   
rC   c                  C   sP   t d} d| d< t d}d|d< d|d< tj| ddd	d
}t||dd d S )Nr(   r   )r   r   )r   g      ?r      r   r   )r   r   r   r0   )r5   zerosr   r   r   )r   r9   r:   r!   r!   r"   test_hog_odd_cell_size:   s   

rF   c               
   C   sD  d } }t j|| fdd}d||d d < tdD ]}t ||}|d}tj|ddd	d
ddd\}}tj|ddd	d
ddd\}}	tj|ddd	d
d
dd\}
}tj|ddd	d
d
dd\}}	 t|| t||	 t||
dd t||dd t j|dddd}|dv rg d}n|dv rg d}ntdt||dd qd S ) N#   floatr$   d   r   rD   uint8r   r   TFr   r   r   r   r-   r,   r   r   r)   r   rB   z$HOG result visualisation (float img)r/   z$HOG result visualisation (uint8 img)z5HOG result (transform_sqrt) visualisation (float img)   z5HOG result (transform_sqrt) visualisation (uint8 img)r0   r   )r   r   )r   r   r   r   )r   r)   )r   r   r   r   z+Result is not determined for this rotation.)r5   rE   rangerot90r4   r   r   matplotlib.pyplotpyplotfiguresubplotimshowcolorbartitleshowr   maxreshape	Exception)widthheightimage0rotimage_floatimage_uint8	hog_floathog_img_float	hog_uint8hog_img_uint8hog_float_normhog_img_float_normhog_uint8_normhog_img_uint8_normpltactualdesiredr!   r!   r"   *test_hog_basic_orientations_and_data_typesH   sN   








rm   c               
   C   s   d } }t || f}tt|d t| d ft| d \}}d|||f< tj|ddd}tddD ]*}tj	||ddd	d
dd\}}	 |d|}	t j|	dd}
t |	}t|
|dd q4d S )NrJ   r   r)   reflect)mode   r   r   TFr   rL   r   r   r`   z)HOG result visualisation, orientations=%drN   r   r0   )r5   rE   r   diskintr   gaussianrO   r   r   rQ   rR   rS   rT   rU   rV   rW   rX   rZ   r   r   )r\   r]   rB   rrccr   r   hog_imgrj   
hog_matrixrk   rl   r!   r!   r"   test_hog_orientations_circle   s$   
,

rx   c                     s   d } }t j|| fdd}d||d d< tj|d| |fdd	d
d\}}|d   fddt|D }||ddf dk sAJ | ddf dk sOJ dS )az  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.
       rH   rI   r   r   Nr)   r   Tr   )r   r   r   r-   r   c                    s   g | ]}| kr|qS r!   r!   ).0xmiddle_indexr!   r"   
<listcomp>   s    z6test_hog_visualization_orientation.<locals>.<listcomp>r   rN   )r5   rE   r   r   rO   all)r\   r]   rB   _	hog_imageindices_excluding_middler!   r|   r"   "test_hog_visualization_orientation   s   	
	 r   c                  C   sH   t d} tt tj| dd W d    d S 1 sw   Y  d S )NrD   Linf)r   )r5   eyepytestraises
ValueErrorr   r   )r   r!   r!   r"   ,test_hog_block_normalization_incorrect_error   s   
"r   zshape,multichannel)))r)   r)   r)   F)r(   T))r)   r)   r)   r)   Tc              	   C   s   t | }tt. tdg tj||dd W d    n1 s#w   Y  W d    d S W d    d S 1 s;w   Y  d S )N'`multichannel` is a deprecated argumentr   multichannelr   )r5   rE   r   r   r   r	   r   r   )shaper   r   r!   r!   r"   test_hog_incorrect_dimensions  s   
"r   c                  C   s  t  } d| d d d d df< tdg tj| ddd}W d    n1 s'w   Y  dD ]W}tdg tjtj| |ddddd}W d    n1 sNw   Y  t|| td	g ttj| |ddd
ddddddd	}W d    n1 s{w   Y  t|| q.d S )Nr   r   r   r   Tr   r   r   r   z%Providing the `multichannel` argumentr   r   r(   F)r   r   r	   r   r   r5   rollr   )r   hog_refnhog_factr!   r!   r"   4test_hog_output_equivariance_deprecated_multichannel  s&   

r   channel_axis)r   r   rN   c                 C   s   t  d dd df }d|d d d d df< t|d| }tj|| dd}dD ]}tjtj||| d| dd}t|| q(d S )	N@       r   r   rN   r   )r   r   r   )r   r   r5   moveaxisr   r   r   r   )r   r   r   r   r   r!   r!   r"   )test_hog_output_equivariance_channel_axis!  s   r   )#numpyr5   r   numpy.testingr   skimager   r   r   r   r   skimage._sharedr   skimage._shared._warningsr	   skimage._shared.testingr
   skimage._shared.utilsr   r#   markparametrizefloat32r7   r<   r>   rC   rF   rm   rx   r   r   r   r   r   r!   r!   r!   r"   <module>   s0    	

a5
