o
    e-,                     @   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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)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      Zaxis	      r      r   L1orientationspixels_per_cellcells_per_block
block_normi H  )r   r   	astronautmeanr   hoglen)imgfd r   ND:\Projects\ConvertPro\env\Lib\site-packages\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   Zfeature_vectortransform_sqrt	visualize      decimalr   Zrgb2grayr   r   astypenploadr	   r   r   r
   r"   float64r   r"   r   correct_outputoutputZfloat_dtyper.   r   r   r    #test_hog_output_correctness_l1_norm      
r7   c              
   C   r#   )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#   r8   r9   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_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   

rA   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   r?   Zuint8r   r   TFr   r   r   r   r*   r)   r   r   r'   r   r=   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)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   matplotlib.pyplotpyplotfiguresubplotimshowcolorbartitleshowr   maxreshape	Exception)widthheightZimage0Zrot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pltactualdesiredr   r   r    *test_hog_basic_orientations_and_data_typesG   sN   








r[   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 )NrE   r   r'   Zreflect)mode   r   r   TFr   rF   r   r   rW   z'HOG result visualisation, orientations=rH   r   r-   )r1   r@   r   Zdiskintr   ZgaussianrI   r   r   rJ   rK   rL   rM   rN   rO   rP   rQ   rS   r   r   )rU   rV   r=   rrccr   r   Zhog_imgrX   Z
hog_matrixrY   rZ   r   r   r    test_hog_orientations_circle   s$   
,

ra   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.
       rC   rD   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   rH   )r1   r@   r   r   rI   all)rU   rV   r=   _Z	hog_imageZindices_excluding_middler   re   r    "test_hog_visualization_orientation   s   	
	 ri   c                  C   sH   t d} tt tj| dd W d    d S 1 sw   Y  d S )Nr?   ZLinf)r   )r1   eyepytestraises
ValueErrorr   r   )r   r   r   r    ,test_hog_block_normalization_incorrect_error   s   
"rn   zshape,channel_axis)))r'   r'   r'   N)r&   rH   ))r'   r'   r'   r'   rH   c                 C   sJ   t | }tt tj||dd W d    d S 1 sw   Y  d S )Nr   channel_axisr   )r1   r@   rk   rl   rm   r   r   )shaperp   r   r   r   r    test_hog_incorrect_dimensions  s   
"rr   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|| qd S )Nr   r   r   rH   r   ro   r   r   )r   r   r   r   r1   rollr   )r   hog_refnhog_factr   r   r    4test_hog_output_equivariance_deprecated_multichannel  s   rx   rp   )r   r   rH   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   rs   rH   r   ro   r   )r   r   r1   Zmoveaxisr   r   rt   r   )rp   r   ru   rv   rw   r   r   r    )test_hog_output_equivariance_channel_axis  s   r|   )!numpyr1   rk   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   r9   r>   rA   r[   ra   ri   rn   rr   rx   r|   r   r   r   r    <module>   s.    	

a5
