a
    
d+                     @   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sHJ 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   g/var/www/html/stable-diffusion-webui/venv/lib/python3.9/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sVJ |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"   float64r   r"   r   correct_outputoutputZfloat_dtyper-   r   r   r    #test_hog_output_correctness_l1_norm   s    
r6   c              
   C   sz   t t j| dd}ttd}tj	|dddddddd	}t
| }|j|ksVJ |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.   r3   r   r   r    &test_hog_output_correctness_l2hys_norm#   s    
r7   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   Z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,   )r0   zerosr   r   r   )r   r4   r5   r   r   r    test_hog_odd_cell_size9   s    

r>   c               
   C   sH  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 rg d}n|dv r,g d}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   r   )r   r&   )r   r   r   r   z+Result is not determined for this rotation.)r0   r=   rangeZrot90r/   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    




"





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 ]R}tj	||ddd	d
dd\}}|
d|}t j|dd}	t |}
t|	|
dd qhd S )NrB   r   r&   Zreflect)mode   r   r   TFr   rC   rD   r   r   r   r,   )r0   r=   r   Zdiskintr   ZgaussianrE   r   r   rG   r   r   )rI   rJ   r:   rrccr   r   Zhog_imgZ
hog_matrixrK   rL   r   r   r    test_hog_orientations_circle   s     
,

rS   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 sJ | ddf dk sJ 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.
       r@   rA   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>       z6test_hog_visualization_orientation.<locals>.<listcomp>r   rD   )r0   r=   r   r   rE   all)rI   rJ   r:   _Z	hog_imageZindices_excluding_middler   rW   r    "test_hog_visualization_orientation   s    	
	r\   c                  C   sF   t d} tt tj| dd W d    n1 s80    Y  d S )Nr<   ZLinf)r   )r0   Z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%   rD   ))r&   r&   r&   r&   rD   c                 C   sH   t | }tt  tj||dd W d    n1 s:0    Y  d S )Nr   channel_axisr   )r0   r=   r]   r^   r_   r   r   )shaperb   r   r   r   r    test_hog_incorrect_dimensions  s    
rd   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   rD   r   ra   r   r   )r   r   r   r   r0   rollr   )r   hog_refnhog_factr   r   r    4test_hog_output_equivariance_deprecated_multichannel  s    rj   rb   )r   r   rD   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   re   rD   r   ra   r   )r   r   r0   Zmoveaxisr   r   rf   r   )rb   r   rg   rh   ri   r   r   r    )test_hog_output_equivariance_channel_axis  s    rn   )!numpyr0   r]   Znumpy.testingr   Zskimager   r   r   r   r   Zskimage._sharedr   Zskimage._shared.testingr	   Zskimage._shared.utilsr
   r!   markZparametrizefloat32r2   r6   r7   r;   r>   rM   rS   r\   r`   rd   rj   rn   r   r   r   r    <module>   s,   	

a5
