
    9i                         S SK rS SKJrJr  S SKJrJr  S SKJ	r	  S SK
JrJr  S SKJr  \R                  " S\R                   \R"                  /5      S 5       rS	 rS
 rS rS rS rS rS rS rS rg)    N)assert_almost_equalassert_equal)dataimg_as_float)diamond)match_templatepeak_local_max)testingdtypec                    Sn[         R                  " SSU S9nS[         R                  " U5      [         R                  " U5      S S S2   -   -  nUR                  U SS9nS	S
/nU H  u  pVX2XUU-   2XfU-   24'   M     [         R                  R                  S5        US[         R                  R                  SS9R                  U SS9-  -  n[        X#5      nUR                  U :X  d   eSn[        XxS9n	[        U	5      S:  a;  U[        U	R                  5         n
[         R                  " U
5      S S S2   nX   S S n	U	[         R                  " U	S S 2S4   5         n	[        XI5       H  u  p[        X5        M     g )Nd   )  r         ?)r   g?F)copy)2   r   )   r      size   )min_distance   r   )npfulltriastyperandomseeduniformr   r   r	   lentupleTargsortzipr   )r   r   imagetargettarget_positionsxyresultdelta	positionsintensities	i_maxsort	xy_targetxys                 c/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/feature/tests/test_template.pytest_templater3   
   sk   DGGJ51EBFF4L266$<"#556F]]5u]-F *- ,2ad(lADL() !IINN1	S299$$*$5<<U<OOOEE*F<<5   Ev:I
9~U9;;/0JJ{+DbD1	(!,	 "**Yq!t_56I-9	B* :    c                  X   Sn SnSu  p#Su  pE[         R                  " X4S5      nSXbX -   2X3U -   24'   SXdX@-   2XUU -   24'   [         R                  " U S-   U S-   45      nSUSSU -   2SSU -   24'   [        Xg5      n[         R                  " UR
                  5      n	U	S   n
U	S	   n[         R                  " XR                  5      n[         R                  " XR                  5      n[         R                  " [         R                  " U5      S-   XE4:H  5      (       d   e[         R                  " [         R                  " U5      S-   X#4:H  5      (       d   e[         R                  " UR
                  U
   S	5      (       d   e[         R                  " UR
                  U   S5      (       d   eg
)zTest that `match_template` gives the correct normalization.

Normalization gives 1 for a perfect match and -1 for an inverted-match.
This test adds positive and negative squares to a zero-array and matches
the array with a positive template.
r      )r      )      r   r   r   r   r   N)r   r   zerosr   r$   flatunravel_indexshapeallarrayallclose)nNiposjposinegjnegr&   templater+   sorted_result	iflat_min	iflat_max
min_result
max_results                 r2   test_normalizationrM   *   s    	
A
AJDJDGGQFC E./E/4(?
*+./E/4(?
*+ xxQA'H%&HQQYAE	!"E,F JJv{{+Ma Ib!I!!)\\:J!!)\\:J 66288J'!+<====66288J'!+<====;;v{{9-r2222;;v{{9-q1111r4   c                  B   [         R                  R                  S5        SS[         R                  R                  SS9-  -   n [         R                  " S5      nSUSS	2SS24'   [        X5      n[         R                  " [         R                  " U5      5      (       a   eg)
zTest that `match_template` doesn't return NaN values.

When image values are only slightly different, floating-point errors can
cause a subtraction inside of a square root to go negative (without an
explicit check that was added to `match_template`).
r   r   g&.>)r6   r6   r   )   rO   r   Nr7   )r   r   r   normalonesr   anyisnanr&   rG   r+   s      r2   test_no_nansrU   N   s~     IINN1$))x)888EwwvHHRaRUOE,Fvvbhhv&'''''r4   c                      [         R                  " S5      n [         R                  " S5      n[        R                  " [        5         [        X5        S S S 5        g ! , (       d  f       g = f)Nr   r   r7   r7   r   rQ   r
   raises
ValueErrorr   r&   rG   s     r2   test_switched_argumentsr]   ]   s<    GGFOEwwvH	
	#x' 
$	#	#s   A
A*c                  H   S[        S5      -  n S[        R                  " S5      -  n[        SS5      nXSS24==   U SS2SS24   -  ss'   XSS	24==   U -  ss'   XS
S24==   U -  ss'   XSS24==   U SS2SS24   -  ss'   [	        XSUR                  5       S9n[        R                  " UR                  5      n[        R                  " USS UR                  5      u  pV[        US5        [        R                  " USS UR                  5      u  pV[        US5        g)aQ  Test `match_template` when `pad_input=True`.

This test places two full templates (one with values lower than the image
mean, the other higher) and two half templates, which are on the edges of
the image. The two full templates should score the top (positive and
negative) matches and the centers of the half templates should score 2nd.
r   r   )	         Nr7      r_   iT)	pad_inputconstant_values)r8   r   )   rO   )r   r   rQ   slicer   meanr$   r;   r<   r=   r   )rG   r&   midr+   rH   ijs          r2   test_pad_inputrn   d   s    WQZH"'''""E
1+C	rr'Nhq"#v&&N	qs(OxO	r"u*!	rs(Ox2A2&O4F
 JJv{{+MM"1-v||<DAGM"#.=DAGr4   c                  ~   [         R                  R                  S5        [         R                  R                  SSS5      n [         R                  " S5      nXSS2SS2SS24'   [        X5      n[        UR                  S	5        [        [         R                  " UR                  5       UR                  5      S
5        g )Nr   r7   r8   r8   r8   rO   r      rc   ra   )
   rr   rr   )r7   r   rc   
r   r   r   randr:   r   r   r=   r<   argmaxrG   r&   r+   s      r2   test_3drw      s    IINN1yy~~aA&HHH\"E#!A#qsAaC-E,F|,!!&--/6<<@)Lr4   c                  |   [         R                  R                  S5        [         R                  R                  SSS5      n [         R                  " S5      nXSS2SS2SS24'   [        XS	S
9n[        UR                  S5        [        [         R                  " UR                  5       UR                  5      S5        g )Nr   r7   rp   rO   r   rq   rc   ra   T)re   )rc   rO   r   rs   rv   s      r2   test_3d_pad_inputry      s    IINN1yy~~aA&HHH\"E#!A#qsAaC-Et<F|,!!&--/6<<@)Lr4   c                      [        S5      n [        R                  " S5      nU S S 2SS 24   USS2S S24'   [        XSSS9n[	        [        R
                  " UR                  5       UR                  5      S	5        g )
Nr   )rr   rr   rb   ra   r7   Treflect)re   mode)rc   r   )r   r   r:   r   r   r<   ru   r=   rv   s      r2   test_padding_reflectr}      sh    qzHHHXEaf%E!A#rr'NEt)LF!!&--/6<<@&Ir4   c                     [         R                  " S5      n [         R                  " S5      n[        R                  " [        5         [        X5        S S S 5        [         R                  " S5      n [         R                  " S5      n[        R                  " [        5         [        X5        S S S 5        [         R                  " S5      n [         R                  " S5      n[        R                  " [        5         [        X5        S S S 5        g ! , (       d  f       N= f! , (       d  f       Nz= f! , (       d  f       g = f)N)r   r   r   rX   rW   )r7   r7   r   )r   r   r7   r7   rY   r\   s     r2   test_wrong_inputr      s    GGIEwwvH	
	#x' 
$ GGFOEwwy!H	
	#x' 
$ GGL!Ewwy!H	
	#x' 
$	# 
$	#
 
$	#
 
$	#s$   D!D!;D2
D!
D/2
E c                     [        [        R                  " 5       5      n [        R                  " S5      nSUS'   [        X5      n[        UR                  5       5        UR                  5       S:  d   eUR                  5       S:  d   eg )NrX   r   )r   r   g  ?g  )	r   r   pager   r:   r   printmaxminrT   s      r2   test_bounding_valuesr      si    %ExxHHTNE,F	&**,::<("""::<)###r4   )numpyr   skimage._shared.testingr   r   skimager   r   skimage.morphologyr   skimage.featurer   r	   skimage._sharedr
   parametrizefloat32float64r3   rM   rU   r]   rn   rw   ry   r}   r   r    r4   r2   <module>r      sv     E & & : # 	Wrzz2::67+ 8+>!2H((:
M
MJ("$r4   