
    |h-                        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$                  j'                  dej(                  ej*                  g      d	        Zej$                  j'                  dej(                  ej*                  g      d
        Zd Zd Zd Zd Zd Zd Zej$                  j'                  dg d      d        Zd Zej$                  j'                  dg d      d        Z d Z!y)    N)assert_almost_equal)colordatadrawfeatureimg_as_float)filters)fetch)_supported_float_typec                      t        t        j                         d dd d f   j                  d            } t	        j
                  | dddd      }t        |      d	k(  sJ y )
N      axis	      r      r   L1orientationspixels_per_cellcells_per_block
block_normi H  )r   r   	astronautmeanr   hoglen)imgfds     ]/var/www/html/test/engine/venv/lib/python3.12/site-packages/skimage/feature/tests/test_hog.pytest_hog_output_sizer#      s`    
t~~'a05515=
>C	
B r71111    dtypec           
      l   t        j                  t        j                               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        |||       y )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
JCWWU#CDEN[[	F (.K<<;&&&"**,a!G@r$   c           
      l   t        j                  t        j                               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        |||       y )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
JCWWU#GHIN[[	F (.K<<;&&&"**,a!G@r$   c                      t        j                         d dd df   } t        j                  | dddd      }t	        |      dk(  sJ y )	N      r   r   r   r   r   i  )r   camerar   r   r   )imager!   s     r"   &test_hog_image_size_cell_size_mismatchrE   C   sP    KKM$3$*%E	
B r71111r$   c                      t        j                  d      } d| d<   t        j                  d      }d|d<   d|d<   t        j                  | ddd	
      }t	        ||d       y )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   O   s_    
((6
CCIXXd^NN1N1[[VVF :r$   c            
         dx} }t        j                  || fd      }d||dz  d  t        d      D ]-  }t        j                  ||      }|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                   |j#                  dd      d      }|dv rg d}n|dv rg d}nt%        d      t        ||d       0 y )N#   floatr%   d   r   rG   uint8r   r   TFr   r   r   r   r.   r-   r   r   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_typesrp   ^   s    EFXXvuoW5FF6Q;=Qx b8hhvs+ "((1%,[["" &
"M &-[["" &
"M 07{{""0
,+ 07{{""0
,+ 8 	Iy1M=9
 	I~qAI~qA 	))"a0q9&="GF]"GIJJFGQ7Eb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 ]n  }t        j                  ||ddd	d
d      \  }}	 |j%                  d|      }	t        j&                  |	d      }
t        j&                  |	      }t)        |
|d       p y )NrN   r   r*   reflect)sigmamode   r   r   TFr   rP   r   r   rQ   r   r1   )r6   rH   r   diskintr	   gaussianrR   r   r   rT   rU   rV   rW   rX   rY   rZ   r[   r]   r   r   )r_   r`   rD   rrccr   r   hog_imgrm   
hog_matrixrn   ro   s               r"   test_hog_orientations_circler}      s     EFHHfe_%EYYFQJUQY8#eai.IFBE"b&MU!)<Ea %8 %"" 
g   [[\2
 !,''*%FGQ7K%8r$   c                  N   dx} }t        j                  || fd      }d||dz  d t        j                  |d| |fdd	d
      \  }}|dz  }t	        |      D cg c]
  }||k7  s	| }}||ddf   dk(  j                         sJ ||ddf   dkD  j                         sJ yc c}w )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   r   rQ   )r6   rH   r   r   rR   all)r_   r`   rD   _	hog_imagemiddle_indexxindices_excluding_middles           r"   "test_hog_visualization_orientationr     s     EFHHfe_G4EE&A+-;;LAy Q;L+0=NaA<MNN.12a7<<>>>lAbD()A-22444  Os   
B"#B"c                      t        j                  d      } t        j                  t              5  t        j                  | d       d d d        y # 1 sw Y   y xY w)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zshape,channel_axis)))r*   r*   r*   N)r)   rQ   ))r*   r*   r*   r*   rQ   c                     t        j                  |       }t        j                  t              5  t        j                  ||d       d d d        y # 1 sw Y   y xY w)Nr   channel_axisr   )r6   rH   r   r   r   r   r   )shaper   r    s      r"   test_hog_incorrect_dimensionsr   1  sF     ((5/C	z	" ECltDE E Es   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        ||       > y )Nr   r   r   rQ   r   r   r   r   )r   r   r   r   r6   rollr   )r    hog_refnhog_facts       r"   4test_hog_output_equivariance_deprecated_multichannelr   ?  sm    
..
CC1fkk#B4@G /;;GGC#"
 	GX.	/r$   r   )r   r   rQ   c                 6   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        ||       > y )	N@       r   r   rQ   r   r   r   )r   r   r6   moveaxisr   r   r   r   )r   r    r   r   r   s        r"   )test_hog_output_equivariance_channel_axisr   K  s    
..
3B38
$CC1f
++c2|
,Ckk#LTJG /;;GGC.%

 	GX./r$   c                     t        j                  d      } t        j                  | dd       t        j                  d      } t	        j
                  t        d      5  t        j                  | dd       ddd       y# 1 sw Y   yxY w)	ziTest that an exception is thrown whenever the input image is
    too small for the given parameters.
    )   r   r   r)   )r   r   )   r   z.*image is too small given)matchN)r6   rH   r   r   r   r   r   r   s    r"   test_hog_small_imager   [  si     ((8
CKKVVD
((8
C	z)E	F 
""	

 
 
s   B  B	)"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   rp   r}   r   r   r   r   r   r    r$   r"   <module>r      s     - < < # ) 72 2::rzz":;A <A( 2::rzz":;A <A(	2;s8l68r5<, EE	/ 8/ 9/
r$   