
    hh5                         d dl Zd dlZd dlmZmZ d dlmZmZm	Z	m
Z
 d dlmZ  G d d      Z G d d      Z G d	 d
      Zy)    N)expected_warningsrun_in_parallel)graycomatrixgraycopropslocal_binary_patternmultiblock_lbp)integral_imagec                       e Zd Zd Z e       d        Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestGLCMc                 p    t        j                  g dg dg dg dgt         j                        | _        y )N)r   r      r   )r      r   r   )r   r      r   dtypenparrayuint8imageselfs    `/var/www/html/dev/engine/venv/lib/python3.12/site-packages/skimage/feature/tests/test_texture.pysetup_methodzTestGLCM.setup_method   s$    XX<|DBHH

    c           	         t        | j                  dgdt        j                  dz  t        j                  dz  dt        j                  z  dz  gd      }|j                  dk(  sJ t        j
                  g dg dg d	g d
gt        j                        }t        j                  j                  |d d d d ddf   |       t        j
                  g dg dg dg dgt        j                        }t        j                  j                  |d d d d ddf   |       t        j
                  g dg dg dg dgt        j                        }t        j                  j                  |d d d d ddf   |       t        j
                  g dg dg dg dgt        j                        }t        j                  j                  |d d d d ddf   |       y )Nr   r      r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   	r   r   r   pishaper   uint32testingassert_array_equal)r   result	expected1	expected2	expected3	expected4s         r   test_output_angleszTestGLCM.test_output_angles   s`   JJaBEEAIq255y1}Eq
 |||+++HH<|DBII
	 	

%%fQ1aZ&8)DHH<|DBII
	 	

%%fQ1aZ&8)DHH<|DBII
	 	

%%fQ1aZ&8)DHH<|DBII
	 	

%%fQ1aZ&8)Dr   c                 8   t        | j                  dgt        j                  dz  gdd      }|j                  dk(  sJ t        j
                  g dg dg d	g d
gt        j                        }t        j                  j                  |d d d d ddf   |       y Nr   r   r   T	symmetric)r   r   r   r   )   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r    )r   r&   expecteds      r   test_output_symmetric_1z TestGLCM.test_output_symmetric_1+   sy    djj1#	{AN|||+++88<|DBII
 	

%%fQ1aZ&8(Cr   c                 ^   t         t        j                  t        j                  t        j                  t        j
                  fD ][  }t        j                  t              5  t        | j                  j                  |      dgt        j                  gd       d d d        ] y # 1 sw Y   hxY wNr   r   )floatr   doublefloat16float32float64pytestraises
ValueErrorr   r   astyper!   r   r   s     r   test_error_raise_floatzTestGLCM.test_error_raise_float3   s~    RYY

BJJ

K 	HEz* HTZZ..u5sRUUGQGH H	HH Hs    8B##B,	c                    t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  fD ]Z  }t        j                  t              5  t        | j                  j                  |      dgt         j                  g       d d d        \ y # 1 sw Y   gxY w)Nr   )r   int16int32int64uint16r#   uint64r:   r;   r<   r   r   r=   r!   r>   s     r   test_error_raise_int_typesz#TestGLCM.test_error_raise_int_types8   s    hh"((BIIryy"))T 	EEz* ETZZ..u5sRUUGDE E	EE Es   97B;;C	c                     t        j                  t              5  t        | j                  j                  t        j                        dz
  dgt        j                  gd       d d d        y # 1 sw Y   y xY wr4   )	r:   r;   r<   r   r   r=   r   rA   r!   r   s    r   test_error_raise_negativez"TestGLCM.test_error_raise_negative=   sU    ]]:& 	K**2884q81#wJ	K 	K 	Ks   A	A,,A5c                     t        j                  t              5  t        | j                  dz
  dgt
        j                  gd       d d d        y # 1 sw Y   y xY w)Nr   r   )r:   r;   r<   r   r   r   r!   r   s    r   #test_error_raise_levels_smaller_maxz,TestGLCM.test_error_raise_levels_smaller_maxA   sA    ]]:& 	:a!ruugq9	: 	: 	:s   ,AAc                    t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  fD ]  }| j                  j                  |      }t        |dgt         j                  dz  gdd      }|j                  dk(  sJ t        j                  g dg dg d	g d
gt         j                        }t         j                  j                  |d d d d ddf   |        y r-   )r   rD   r#   rE   rA   rB   rC   r   r=   r   r!   r"   r   r$   r%   )r   r   imgr&   r1   s        r   test_image_data_typeszTestGLCM.test_image_data_typesE   s    iiBIIrxx288T 	HE**##E*C!#sRUUQYKdKF<<<///xx|\<HiiH JJ))&Aq!*<hG	H 	r   c                 B   t        j                  g dg dg dg dgt         j                        }t        |dgdgdd	
      }t        j                  g dg dg dg dgt         j                        }t         j
                  j                  |d d d d ddf   |       y )Nr   )r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   r   Fr.   )r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r#   r$   r%   )r   imr&   r1   s       r   test_output_distancezTestGLCM.test_output_distanceR   s}    XX<|DBHH
 b1#sA?88<|DBII
 	

%%fQ1aZ&8(Cr   c                 ,   t        j                  dgdgdgdggt         j                        }t        |ddgdt         j                  dz  gd      }|j
                  dk(  sJ t        j                  dt         j                        }t        j                  g d	g d
g dg dgt         j                        }t        j                  g d
g dg dg dgt         j                        }t         j                  j                  |d d d d ddf   |       t         j                  j                  |d d d d ddf   |       t         j                  j                  |d d d d ddf   |       t         j                  j                  |d d d d ddf   |       y )Nr   r   r   r   r   r   )r   r   r   r   r   r   rO   rP   r   r   )
r   r   r   r   r!   r"   zerosr#   r$   r%   )r   rQ   r&   ze1e2s         r   test_output_combozTestGLCM.test_output_combo\   s5   XXsQC!qc*"((;b1a&1beeai.!<|||+++HHV299-XX<|DBII
 XX<|DBII
 	

%%fQ1aZ&8!<


%%fQ1aZ&8!<


%%fQ1aZ&8"=


%%fQ1aZ&8"=r   c                    t        | j                  dgdgd      }t        j                  j	                  |d d d d ddf   t        j
                  dt        j                               t        | j                  dgdgdd      }t        j                  j	                  |d d d d ddf   t        j
                  dt        j                               y )N
   r   r   rT   r   T)normed)r   r   r   r$   r%   rU   r#   r   r&   s     r   test_output_emptyzTestGLCM.test_output_emptyn   s    djj2$Q7


%%1aA:ryy A	
 djj2$QtD


%%1aA:ryy A	
r   c           
         t        | j                  g ddt        j                  dz  t        j                  gddd      }t	        |j
                  d         D ]  }t	        |j
                  d         D ]  }t        j                  j                  |d d d d ||f   j                         d       t        j                  j                  |d d d d ||f   |d d d d ||f   j                                  y )	N)r   r   r   r   r   r   Tr\   r/   r         ?)r   r   r   r!   ranger"   r$   assert_almost_equalsumr%   	transpose)r   r&   das       r   test_normed_symmetriczTestGLCM.test_normed_symmetricx   s    JJ	Aruuqy"%%#8!DTX
 v||A' 	A6<<?+ 

..vaAqj/A/E/E/GM

--1aA:&q!Qz(:(D(D(F	r   c                     t        | j                  ddgdgddd      }t        j                  |d      }t	        |d      }t        j
                  j                  |d	   d
d       y )Nr   r   r   r   Tr`   r   contrastr   r   gQ?decimal)r   r   r   roundr   r$   rc   )r   r&   rj   s      r   test_contrastzTestGLCM.test_contrast   sZ    djj1a&1#qQUV&!$vz2


&&x~ua&Hr   c                     t        | j                  dgdt        j                  dz  gddd      }t        j                  |d      }t        |d      }t        j                  j                  |d	   d
d       y )Nr   r   r   r   Tr`   r   dissimilarityrk   gn?rl   r   r   r   r!   rn   r   r$   rc   r   r&   rq   s      r   test_dissimilarityzTestGLCM.test_dissimilarity   sg    JJa^Qtt
 &!$#FO<


&&}T':E1&Mr   c                     t        | j                  ddgt        j                  dz  gddd      }t        j                  |d      }t        |d      d   }t        j                  j                  |d	d
       y )Nr   r   r   r   Tr`   rq   rk   gHzG?rl   rr   rs   s      r   test_dissimilarity_2zTestGLCM.test_dissimilarity_2   sg    JJAQtt
 &!$#FO<TB


&&}eQ&Gr   c                 &   t         j                  j                  d      dz  j                  t         j                        }t	        |g dg dd      }t         j
                  j                  t        j                  t        |d            dk         y )N)d   rx      )r   r   r      )r   g      ?r   g      ?)levelscorrelationra   )	r   randomr=   r   r   r$   assert_maxr   )r   rL   ps      r   test_non_normalized_glcmz!TestGLCM.test_non_normalized_glcm   sb    yy
+a/77Al,=aH


266+a"?@3FGr   c                     t        | j                  dgdgd      }t        j                  t              5  t        |d       d d d        y # 1 sw Y   y xY w)Nr   r   r   ABC)r   r   r:   r;   r<   r   r]   s     r   test_invalid_propertyzTestGLCM.test_invalid_property   sE    djj1#sA6]]:& 	'&	' 	' 	's   A

Ac                     t        | j                  dgddgddd      }t        |d      d   }t        j                  j                  |d	       y )
Nr   r   r0   r   Tr`   homogeneityrk   g?r   r   r   r   r$   rc   )r   r&   r   s      r   test_homogeneityzTestGLCM.test_homogeneity   sF    djj1#1vqQUV!&-8>


&&{J?r   c                     t        | j                  dgddgddd      }t        |d      d   }t        j                  j                  |d       y )	Nr   r   r   Tr`   energyrk   g3YNp?r   r   r&   r   s      r   test_energyzTestGLCM.test_energy   sF    djj1#1vqQUVVX.t4


&&vz:r   c                     t        | j                  ddgdgddd      }t        |d      }t        j                  j                  |d   d	       t        j                  j                  |d
   d       y )Nr   r   r   r   Tr`   r|   rk   g
U i?)r   r   gl	TZZ?r   r   s      r   test_correlationzTestGLCM.test_correlation   s]    djj1a&1#qQUVV]3


&&vd|Z@


&&vd|Z@r   c                     t        | j                  dgdt        j                  dz  gddd      }t	        |d      d   }t        j
                  j                  |d	       y )
Nr   r   r   r   Tr`   meanrk   gI?r   r   r   r!   r   r$   rc   )r   r&   r   s      r   	test_meanzTestGLCM.test_mean   sT    JJa^Qtt
 66*40 	

&&tZ8r   c                     t        | j                  dgdt        j                  dz  gddd      }t	        |d      d   }t        j
                  j                  |d	       y )
Nr   r   r   r   Tr`   variancerk   ge7?r   )r   r&   r   s      r   test_variancezTestGLCM.test_variance   sT    JJa^Qtt
 vz248 	

&&x<r   c                     t        | j                  dgdt        j                  dz  gddd      }t	        |d      d   }t        j
                  j                  |d	       y )
Nr   r   r   r   Tr`   stdrk   g3&0P?r   )r   r&   r   s      r   test_stdzTestGLCM.test_std   sT    JJa^Qtt
 &%(. 	

&&sJ7r   c                     t        | j                  dgdt        j                  dz  gddd      }t	        |d      d   }t        j
                  j                  |d	       y )
Nr   r   r   r   Tr`   entropyrk   gv@L @r   )r   r&   r   s      r   test_entropyzTestGLCM.test_entropy   sT    JJa^Qtt
 fi06 	

&&w
;r   c                     t        j                  dt         j                        }t        |g ddt         j                  dz  gddd      }d	D ]  }t        ||        y )
NrT   r   )r   r   ry   r   r   r   Tr`   )
rj   rq   r   r   r|   ASMr   r   r   r   )r   onesr   r   r!   r   )r   rQ   r&   props       r   test_uniform_propertiesz TestGLCM.test_uniform_properties   sV    WWV288,	Aruuqy>1TT

 	&D %	&r   N)__name__
__module____qualname__r   r   r+   r2   r?   rF   rH   rJ   rM   rR   rY   r^   rh   ro   rt   rv   r   r   r   r   r   r   r   r   r   r    r   r   r   r      s    

 E E,DH
E
K:D>$
	INHH
'
@
;
A9=8<&r   r   c                       e Zd Zd Z e       d        Zd Zej                  j                  de
j                  e
j                  e
j                  g      d        Zd Zd Zd Zy	)
TestLBPc           	      |    t        j                  g dg dg dg dg dg dgt         j                        | _        y )N)   r0   r   r      r   )0               ?   )ry   r      2   r      )   r   r   (      r   )r   r   r   "   r      )      r   r      ~   r   r   r   s    r   r   zTestLBP.setup_method   s2    XX(,(,), ((


r   c           	          t        | j                  ddd      }t        j                  g dg dg dg dg dg d	g      }t        j                  j                  ||       y )
Nry   r   default)r      r   r   `   r   )   r         @   8   )   r         r      )   g      P@>   r      r   )r   r   r      r      )r   rz   r   r   r   r   r   r   r   r   r$   r%   r   lbprefs      r   test_defaultzTestLBP.test_default   sQ    "4::q!Y?hh))+,*%	
 	

%%c3/r   c           	          t        | j                  ddd      }t        j                  g dg dg dg dg dg d	g      }t        j                  j                  ||       y )
Nry   r   rorr      r   r   r   r      r   rz   3   r      w   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _   r   r   r   rz   r   r   r   r   r   r   s      r   test_rorzTestLBP.test_ror  sQ    "4::q!U;hh($)%)$	
 	

%%c3/r   r   c           	      *   | j                   j                  |      }d}t        |g      5  t        |ddd      }d d d        t	        j
                  g dg dg dg dg d	g d
g      }t        j                  j                  |       y # 1 sw Y   QxY w)N8Applying `local_binary_pattern` to floating-point imagesry   r   r   r   r   r   r   r   r   )r   r=   r   r   r   r   r$   r%   )r   r   r   msgr   r   s         r   test_float_warningzTestLBP.test_float_warning  s    

!!%(Hu% 	;&uaE:C	;hh($)%)$	
 	

%%c3/	; 	;s   B		Bc           	          t        | j                  ddd      }t        j                  g dg dg dg dg dg d	g      }t        j                  j                  ||       y )
Nry   r   uniform)r   r   r   ry   r   ry   )rz   r   	   r   r   r   )r   ry   r   r   r   r0   )r   r   rz   r0   rz   r   )ry   r   ry   r   r   r   )r   r   r   ry   r   r   r   r   s      r   test_uniformzTestLBP.test_uniform(  sQ    "4::q!Y?hh""""""	
 	

%%c3/r   c                    t         j                  j                  d       t         j                  j                  dd      }d}||j	                         z  |z  }d\  }}d}t        |g      5  t        |||d      }d d d        ddddf   }|d	z  |d
z
  z  |z  }t         j                  j                  |j                         |d       y # 1 sw Y   RxY w)Ni i  g333333?)r   r   r   varrz   r   r   r   )
r   r}   seedrandr   r   r   r$   rc   r   )r   r   
target_stdPRr   r   r1   s           r   test_varzTestLBP.test_var6  s     			x  		sC(
		#j0 1Hu% 	;&uaE:C	; !B$"*o q=AE*Q.


&&sxxz8Q?	; 	;s   +CCc           	          t        | j                  ddd      }t        j                  g dg dg dg dg dg d	g      }t        j                  j                  ||       y )
Nry   r   nri_uniform)r   6   r   9   r   r   )r   r   :   r   r      )r   r      r   r   /   )r[   r   r   *   #   r   )r   r   r   r   r   r   )r   r   r   r   r      )r   r   r   r   r$   assert_array_almost_equalr   s      r   test_nri_uniformzTestLBP.test_nri_uniformO  sQ    "4::q!]Chh&&'&&%	
 	

,,S#6r   N)r   r   r   r   r   r   r   r:   markparametrizer   r7   r8   r9   r   r   r   r   r   r   r   r   r      sl    
 0 00 [[Wrzz2::rzz&JK0 L0"0@27r   r   c                       e Zd Zd Zy)	TestMBLBPc                     t        j                  dd      }d|ddddf<   d|d dd df<   d|dd dd f<   d}t        |      }t        |d	d	dd      }t         j                  j                  ||       y )
N)r   r   r   r   r   r   r0   r      r   )r   rU   r	   r   r$   assert_equal)r   test_imgcorrect_answerint_imglbp_codes        r   test_single_mblbpzTestMBLBP.test_single_mblbp_  s     88F'21ac!RaRQR $ *!'1aA6


.9r   N)r   r   r   r  r   r   r   r  r  ^  s    :r   r  )numpyr   r:   skimage._shared.testingr   r   skimage.featurer   r   r   r   skimage.transformr	   r   r   r  r   r   r   <module>r     sA      F  -Z& Z&zp7 p7f: :r   