U
    ?h+                     @   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 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dddgdd Zd d! Zejd"d d#d$d%gd&d' Z dS )(    N)assert_almost_equal)colordatadrawfeatureimg_as_float)filters)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sHtd S )
N      Zaxis	      r      r   L1orientationspixels_per_cellcells_per_block
block_normi H  )r   r   	astronautmeanr   hoglenAssertionError)imgfd r    P/var/www/html/venv/lib/python3.8/site-packages/skimage/feature/tests/test_hog.pytest_hog_output_size   s    $
 r"   dtypec              
   C   sz   t t j| dd}ttd}tj	|dddddddd	}t
| }|j|ksVt|tjkrdd
nd}t|||d d S )NFr#   copyzdata/astronaut_GRAY_hog_L1.npyr   r      r'   r   Tr   r   r   r   Zfeature_vectortransform_sqrt	visualize      decimalr   Zrgb2grayr   r   astypenploadr	   r   r   r
   r#   r   float64r   r#   r   correct_outputoutputZfloat_dtyper.   r    r    r!   #test_hog_output_correctness_l1_norm   s    
  r7   c              
   C   sz   t t j| dd}ttd}tj	|dddddddd	}t
| }|j|ksVt|tjkrdd
nd}t|||d d S )NFr$   z"data/astronaut_GRAY_hog_L2-Hys.npyr   r   r&   zL2-HysTr(   r+   r,   r-   r/   r4   r    r    r!   &test_hog_output_correctness_l2hys_norm#   s    
  r8   c                  C   s@   t  d dd df } tj| ddddd}t|dks<td S )	N      r   r   r   r   r   i  )r   camerar   r   r   r   )imager   r    r    r!   &test_hog_image_size_cell_size_mismatch2   s    
 r=   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   r-   )r1   zerosr   r   r   )r   r5   r6   r    r    r!   test_hog_odd_cell_size9   s    

 r@   c               
   C   sP  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krddddg}n |dkr4ddddg}nt
dt||dd q2d S )N#   floatr#   d   r   r>   Zuint8r   r   TFr   r   r   r   r*   r)   r   r-   r   r   )r   r   r   )r   r'   z+Result is not determined for this rotation.)r1   r?   rangeZrot90r0   r   r   r   maxreshape	Exception)widthheightZimage0ZrotZimage_floatZimage_uint8Z	hog_floatZhog_img_floatZ	hog_uint8Zhog_img_uint8Zhog_float_normZhog_img_float_normZhog_uint8_normZhog_img_uint8_normactualdesiredr    r    r!   *test_hog_basic_orientations_and_data_typesG   sj    
    
    
    
    
"



rO   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 ]R}tj	||ddd	d
dd\}}|
d|}t j|dd}	t |}
t|	|
dd qhd S )NrD   r   r'   Zreflect)mode   r   r   TFr   rE   rF   r   r   r   r-   )r1   r?   r   Zdiskintr   ZgaussianrG   r   r   rI   r   r   )rK   rL   r<   Zrrccr   r   Zhog_imgZ
hog_matrixrM   rN   r    r    r!   test_hog_orientations_circle   s"    
, 

rT   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 st| ddf dk st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.
       rB   rC   r   r   Nr'   r   Tr   )r   r   r   r*   r   c                    s   g | ]}| kr|qS r    r    ).0xZmiddle_indexr    r!   
<listcomp>   s      z6test_hog_visualization_orientation.<locals>.<listcomp>r   rF   )r1   r?   r   r   rG   allr   )rK   rL   r<   _Z	hog_imageZindices_excluding_middler    rX   r!   "test_hog_visualization_orientation   s    	
	r\   c               	   C   s2   t d} tt tj| dd W 5 Q R X d S )Nr>   ZLinf)r   )r1   eyepytestraises
ValueErrorr   r   )r   r    r    r!   ,test_hog_block_normalization_incorrect_error   s    
ra   zshape,channel_axis))r'   r'   r'   N)r&   rF   ))r'   r'   r'   r'   rF   c              	   C   s4   t | }tt tj||dd W 5 Q R X d S )Nr   channel_axisr   )r1   r?   r^   r_   r`   r   r   )shaperc   r   r    r    r!   test_hog_incorrect_dimensions  s    
re   c                  C   sb   t  } d| d d d d df< tj| ddd}dD ]*}tjtj| |ddddd}t|| q2d S )Nr   r   r   rF   r   rb   r   r   )r   r   r   r   r1   rollr   )r   hog_refnhog_factr    r    r!   4test_hog_output_equivariance_deprecated_multichannel  s    rk   rc   r   rF   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|| qPd S )	N@       r   rf   rF   r   rb   r   )r   r   r1   Zmoveaxisr   r   rg   r   )rc   r   rh   ri   rj   r    r    r!   )test_hog_output_equivariance_channel_axis  s     ro   )!numpyr1   r^   Znumpy.testingr   Zskimager   r   r   r   r   Zskimage._sharedr   Zskimage._shared.testingr	   Zskimage._shared.utilsr
   r"   markZparametrizeZfloat32r3   r7   r8   r=   r@   rO   rT   r\   ra   re   rk   ro   r    r    r    r!   <module>   s4   	

a5
