o
    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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      axis	      r      r   L1orientationspixels_per_cellcells_per_block
block_normi H  )r   r   	astronautmeanr   hoglen)imgfd r    Y/var/www/html/scripts/venv/lib/python3.10/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   feature_vectortransform_sqrt	visualize      decimalr   rgb2grayr   r   astypenploadr	   r   r   r
   r#   float64r   r#   r   correct_outputoutputfloat_dtyper0   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.   r/   r1   r7   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_mismatch2   s
   
rB   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/   )r4   zerosr   r   r   )r   r8   r9   r    r    r!   test_hog_odd_cell_size9   s   

rE   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   rC   uint8r   r   TFr   r   r   r   r,   r+   r   r   r(   r   rA   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.)r4   rD   rangerot90r3   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_typesG   sN   








rl   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 )NrI   r   r(   reflect)mode   r   r   TFr   rK   r   r   r_   z'HOG result visualisation, orientations=rM   r   r/   )r4   rD   r   diskintr   gaussianrN   r   r   rP   rQ   rR   rS   rT   rU   rV   rW   rY   r   r   )r[   r\   rA   rrccr   r   hog_imgri   
hog_matrixrj   rk   r    r    r!   test_hog_orientations_circle   s$   
,

rw   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.
       rG   rH   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   rM   )r4   rD   r   r   rN   all)r[   r\   rA   _	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 )NrC   Linf)r   )r4   eyepytestraises
ValueErrorr   r   )r   r    r    r!   ,test_hog_block_normalization_incorrect_error   s   
"r   zshape,channel_axis)))r(   r(   r(   N)r'   rM   ))r(   r(   r(   r(   rM   c                 C   sJ   t | }tt tj||dd W d    d S 1 sw   Y  d S )Nr   channel_axisr   )r4   rD   r   r   r   r   r   )shaper   r   r    r    r!   test_hog_incorrect_dimensions  s   
"r   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   rM   r   r   r   r   )r   r   r   r   r4   rollr   )r   hog_refnhog_factr    r    r!   4test_hog_output_equivariance_deprecated_multichannel  s   r   r   )r   r   rM   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   rM   r   r   r   )r   r   r4   moveaxisr   r   r   r   )r   r   r   r   r   r    r    r!   )test_hog_output_equivariance_channel_axis  s   r   )!numpyr4   r   numpy.testingr   skimager   r   r   r   r   skimage._sharedr   skimage._shared.testingr	   skimage._shared.utilsr
   r"   markparametrizefloat32r6   r;   r=   rB   rE   rl   rw   r   r   r   r   r   r    r    r    r!   <module>   s.    	

a5
