
    9i-                        S SK rS SKrS SKJr  S SKJrJrJrJ	r	J
r
  S SKJr  S SKJr  S SKJr  S r\R$                  R'                  S\R(                  \R*                  /5      S	 5       r\R$                  R'                  S\R(                  \R*                  /5      S
 5       rS rS rS rS rS rS r\R$                  R'                  S/ SQ5      S 5       rS r\R$                  R'                  S/ SQ5      S 5       r S r!g)    N)assert_almost_equal)colordatadrawfeatureimg_as_float)filters)fetch)_supported_float_typec                      [        [        R                  " 5       S S2S S 24   R                  SS95      n [        R
                  " U SSSSS9n[        U5      S	:X  d   eg )
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/land-doc-ocr/venv/lib/python3.13/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                 d   [         R                  " [        R                  " 5       5      R	                  U SS9n[
        R                  " [        S5      5      n[        R                  " USSSSSSSS	9n[        U 5      nUR                  U:X  d   eU[
        R                  :X  a  S
OSn[        X2US9  g )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                 d   [         R                  " [        R                  " 5       5      R	                  U SS9n[
        R                  " [        S5      5      n[        R                  " USSSSSSSS	9n[        U 5      nUR                  U:X  d   eU[
        R                  :X  a  S
OSn[        X2US9  g )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                      [         R                  " 5       S S2S S24   n [        R                  " U SSSSS9n[	        U5      S:X  d   eg )	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                      [         R                  " S5      n SU S'   [         R                  " S5      nSUS'   SUS'   [        R                  " U SSS	S
9n[	        X!SS9  g )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                     S=p[         R                  " X4SS9nSX!S-  S & [        S5       GH  n[         R                  " X#5      nUR	                  S5      n[
        R                  " USSS	S
SSS9u  pg[
        R                  " USSS	S
SSS9u  p[
        R                  " USSS	S
S
SS9u  p[
        R                  " USSS	S
S
SS9u  p [        Xh5        [        Xy5        [        XjSS9  [        XlSS9  [         R                   " UR#                  SS5      SS9nUS;   a  / SQnOUS;   a  / SQnO[%        S5      e[        UUSS9  GM     g )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   ^   su    EXXvoW5FFQ;=Qxhhv+ "((1%,[["" &
" &-[["" &
" 07{{""0
, 07{{""0
, 8 	I1M9
 	IqAIqA 	))"a0q9&="GF]"GIJJFGQ7E r$   c                     S=p[         R                  " X45      n[        R                  " [	        US-  5      [	        U S-  5      4[	        U S-  5      5      u  p4SX#U4'   [
        R                  " USSS9n[        SS5       Hg  n[        R                  " UUSSS	S
SS9u  pg UR%                  SU5      n	[         R&                  " U	SS9n
[         R&                  " U	5      n[)        XSS9  Mi     g )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     EHHf_%EYYFQJUQY8#eai.IFBEb&MU!)<Ea %"" 
   [[\2
 !,''*%FQ7K %r$   c            	      T   S=p[         R                  " X4SS9nSX!S-  S& [        R                  " USX4SS	S
S9u  p4US-  n[	        U5       Vs/ s H  ofU:w  d  M
  UPM     nnXGSS24   S:H  R                  5       (       d   eXESS24   S:  R                  5       (       d   egs  snf )af  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     EHHf_G4EEA+-;;LA Q;L+0=N=a<M=N12a7<<>>>>AbD()A-224444  Os   	B%B%c                      [         R                  " S5      n [        R                  " [        5         [
        R                  " U SS9  S S S 5        g ! , (       d  f       g = f)NrG   Linf)r   )r6   eyepytestraises
ValueErrorr   r   r    s    r"   ,test_hog_block_normalization_incorrect_errorr   +  s5    
&&)C	z	"CF+ 
#	"	"   A
Azshape,channel_axis)))r*   r*   r*   N)r)   rQ   ))r*   r*   r*   r*   rQ   c                     [         R                  " U 5      n[        R                  " [        5         [
        R                  " X!SS9  S S S 5        g ! , (       d  f       g = f)Nr   channel_axisr   )r6   rH   r   r   r   r   r   )shaper   r    s      r"   test_hog_incorrect_dimensionsr   1  s7     ((5/C	z	"CtD 
#	"	"r   c            	          [         R                  " 5       n SU S S 2S S 2S4'   [        R                  " U SSS9nS H7  n[        R                  " [        R
                  " XSS9SSS9n[        X5        M9     g )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   ?  sd    
..
CC1fkk#B4@G;;GGC#"
 	G.	 r$   r   )r   r   rQ   c           	      ,   [         R                  " 5       S S2S S24   nSUS S 2S S 2S4'   [        R                  " USU 5      n[        R
                  " XSS9nS H7  n[        R
                  " [        R                  " XU S9U SS9n[        X$5        M9     g )	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#TJG;;GGC.%

 	G. r$   c                     [         R                  " S5      n [        R                  " U SSS9  [         R                  " S5      n [        R
                  " [        SS9   [        R                  " U SSS9  SSS5        g! , (       d  f       g= f)	zaTest 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   [  sa     ((8
CKKVVD
((8
C	z)E	F""	
 
G	F	Fs   A<<
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$   