
    a6d+                        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 Zej                            dej        ej        g          d	             Zej                            dej        ej        g          d
             Zd Zd Zd Zd Zd Zd Zej                            dg d          d             Zd Zej                            dg d          d             Z dS )    N)assert_almost_equal)colordatadrawfeatureimg_as_float)filters)fetch)_supported_float_typec                      t          t          j                    d dd d f                             d                    } t	          j        | 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fds     >lib/python3.11/site-packages/skimage/feature/tests/test_hog.pytest_hog_output_sizer#      sz    
t~''aaa05515==
>
>C	Sq&%+
> 
> 
>B r771111111    dtypec           
      x   t          j        t          j                                                  | d          }t          j        t          d                    }t          j	        |ddddddd	          }t          |           }|j        |k    sJ |t
          j        k    rd
nd}t          |||           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_dtyper2   s         r"   #test_hog_output_correctness_l1_normr=      s    
.))
*
*
1
1E
1
J
JCWU#CDDEEN[1f)/D(,U#(* * *F (..K<;&&&&"*,,aa!G@@@@@@r$   c           
      x   t          j        t          j                                                  | d          }t          j        t          d                    }t          j	        |ddddddd	          }t          |           }|j        |k    sJ |t
          j        k    rd
nd}t          |||           d S )NFr'   z"data/astronaut_GRAY_hog_L2-Hys.npyr   r   r)   zL2-HysTr+   r/   r0   r1   r3   r9   s         r"   &test_hog_output_correctness_l2hys_normr?   #   s    
.))
*
*
1
1E
1
J
JCWU#GHHIIN[1f)/H(,U#(* * *F (..K<;&&&&"*,,aa!G@@@@@@r$   c                      t          j                    d dd df         } t          j        | dddd          }t	          |          dk    sJ d S )	N      r   r   r   r   r   i  )r   camerar   r   r   )imager!   s     r"   &test_hog_image_size_cell_size_mismatchrE   2   s]    KMM$3$*%E	UF%+
> 
> 
>Br771111111r$   c                      t          j        d          } d| d<   t          j        d          }d|d<   d|d<   t          j        | ddd	
          }t	          ||d           d S )Nr)   r   )r   r   )r   g      ?r      r   r   )r   r   r   r1   )r6   zerosr   r   r   )r    r:   r;   s      r"   test_hog_odd_cell_sizerI   9   sz    
(6

CCIXe__NN1N1[f)/DB B BF ::::::r$   c            
         dx} }t          j        || fd          }d||dz  d <   t          d          D ]G}t          j        ||          }|                    d          }t          j        |ddd	d
dd          \  }}t          j        |ddd	d
dd          \  }}	t          j        |ddd	d
d
d          \  }
}t          j        |ddd	d
d
d          \  }}	 t          ||           t          ||	           t          ||
d           t          ||d           t          j        |                    dd          d          }|dv rg d}n|dv rg d}nt%          d          t          ||d           Id S ) N#   floatr%   d   r   rG   uint8r   r   TFr   r   r   r   r.   r-   r   r   r*   r   rD   z$HOG result visualisation (float img)r0   z$HOG result visualisation (uint8 img)z5HOG result (transform_sqrt) visualisation (float img)   z5HOG result (transform_sqrt) visualisation (uint8 img)r1   r   )r   r   )r   r   r   r   )r   r*   )r   r   r   r   z+Result is not determined for this rotation.)r6   rH   rangerot90r5   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desireds                    r"   *test_hog_basic_orientations_and_data_typesrq   G   s    EFXvuoW555FF6Q;<<Qxx M8 M8hvs++ "((11%,[a"d5& & &"M &-[a"d5& & &"M 07{a"d40 0 0,+ 07{a"d40 0 0,+	6 	Iy111M=999
 	I~qAAAAI~qAAAA 	))"a00q999&=="llGGF]]"llGGIJJJFGQ77777[M8 M8r$   c            
         dx} }t          j        || f          }t          j        t	          |dz            t	          | dz            ft	          | dz                      \  }}d|||f<   t          j        |dd          }t          dd          D ]s}t          j	        ||ddd	d
d          \  }}	 |                    d|          }	t          j        |	d          }
t          j        |	          }t)          |
|d           td S )NrN   r   r*   reflect)mode   r   r   TFr   rP   r   r   rd   z'HOG result visualisation, orientations=rR   r   r1   )r6   rH   r   diskintr	   gaussianrS   r   r   rU   rV   rW   rX   rY   rZ   r[   r\   r^   r   r   )r`   ra   rD   rrccr   r   hog_imgrn   
hog_matrixro   rp   s               r"   test_hog_orientations_circler}      s"    EFHfe_%%EYFQJUQY8#eai..IIFBE"b&MUAI666Ea !8 !8 U5;5;t4904	6 6 6g	  [[\22
 !,,,'*%%FGQ77777C!8 !8r$   c                  b   dx} }t          j        || fd          }d||dz  d<   t          j        |d| |fdd	d
          \  }}|dz  fdt	          |          D             }||ddf         dk                                    sJ |ddf         dk                                    sJ 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.
       rL   rM   r   r   Nr*   r   Tr   )r   r   r   r.   r   c                      g | ]
}|k    |S  r   ).0xmiddle_indexs     r"   
<listcomp>z6test_hog_visualization_orientation.<locals>.<listcomp>   s#    NNNaA<M<M<M<M<Mr$   r   rR   )r6   rH   r   r   rS   all)r`   ra   rD   _	hog_imageindices_excluding_middler   s         @r"   "test_hog_visualization_orientationr      s     EFHfe_G444EE&A+,,;  LAy Q;LNNNN5==NNN.12a7<<>>>>>lAbD()A-224444444r$   c                      t          j        d          } t          j        t                    5  t          j        | d           d d d            d S # 1 swxY w Y   d S )NrG   Linf)r   )r6   eyepytestraises
ValueErrorr   r   )r    s    r"   ,test_hog_block_normalization_incorrect_errorr      s    
&))C	z	"	" , ,CF++++, , , , , , , , , , , , , , , , , ,s   AAAzshape,channel_axis)))r*   r*   r*   N)r)   rR   ))r*   r*   r*   r*   rR   c                     t          j        |           }t          j        t                    5  t          j        ||d           d d d            d S # 1 swxY w Y   d S )Nr   channel_axisr   )r6   rH   r   r   r   r   r   )shaper   r    s      r"   test_hog_incorrect_dimensionsr     s     (5//C	z	"	" E ECltDDDDE E E E E E E E E E E E E E E E E Es   AAAc                      t          j                    } d| d d d d df<   t          j        | dd          }dD ]>}t          j        t	          j        | |d          dd          }t          ||           ?d S )Nr   r   r   rR   r   r   r   r   )r   r   r   r   r6   rollr   )r    hog_refnhog_facts       r"   4test_hog_output_equivariance_deprecated_multichannelr     s    
.

CC111fk#B4@@@G / /;rwsAA666R*.0 0 0GX..../ /r$   r   )r   r   rR   c                 8   t          j                    d dd df         }d|d d d d df<   t          j        |d|           }t	          j        || d          }dD ]>}t	          j        t          j        |||           | d          }t          ||           ?d S )	N@       r   r   rR   r   r   r   )r   r   r6   moveaxisr   r   r   r   )r   r    r   r   r   s        r"   )test_hog_output_equivariance_channel_axisr     s    
.

3B38
$CC111f
+c2|
,
,Ck#LTJJJG / /;rwsALAAA,8TK K KGX..../ /r$   )!numpyr6   r   numpy.testingr   skimager   r   r   r   r   skimage._sharedr	   skimage._shared.testingr
   skimage._shared.utilsr   r#   markparametrizefloat32r8   r=   r?   rE   rI   rq   r}   r   r   r   r   r   r   r$   r"   <module>r      s        - - - - - - < < < < < < < < < < < < < < # # # # # # ) ) ) ) ) ) 7 7 7 7 7 72 2 2 2:rz":;;A A <;A 2:rz":;;A A <;A2 2 2; ; ;^8 ^8 ^8B28 28 28j5 5 5<, , , - 0 0 0  
E E 
E/ / / 88	/ 	/ 98	/ 	/ 	/r$   