
    |h                         d dl Zd dlmZmZ d dlmZmZ d dlm	Z	 d dl
mZmZ d dlmZ  ej                  dej                   ej"                  g      d        Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zy)    N)assert_almost_equalassert_equal)dataimg_as_float)diamond)match_templatepeak_local_max)testingdtypec                    d}t        j                  dd|       }dt        j                  |      t        j                  |      d d d   z   z  }|j                  | d      }d	d
g}|D ]  \  }}|||||z   |||z   f<    t         j                  j                  d       |dt         j                  j                  d      j                  | d      z  z  }t        ||      }|j                  | k(  sJ d}t        ||      }	t        |	      dkD  r;|t        |	j                           }
t        j                  |
      d d d   }|	|   d d }	|	t        j                  |	d d df            }	t        ||	      D ]  \  }}t        ||        y )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                 b/var/www/html/test/engine/venv/lib/python3.12/site-packages/skimage/feature/tests/test_template.pytest_templater3   
   s   DGGJ51EBFF4L266$<"#556F]]5u]-F *-  31,2a!d(lADL()3IINN1	S299$$*$5<<U<OOOEE6*F<<5   EvE:I
9~U9;;/0JJ{+DbD1	i(!,	 "**Yq!t_56I-y9 +	2B	*+    c                  6   d} d}d\  }}d\  }}t        j                  ||fd      }d|||| z   ||| z   f<   d|||| z   ||| z   f<   t        j                  | dz   | dz   f      }d|dd| z   dd| z   f<   t        ||      }t        j                  |j
                        }	|	d   }
|	d	   }t        j                  |
|j                        }t        j                  ||j                        }t        j                  t        j                  |      dz   ||fk(        sJ t        j                  t        j                  |      dz   ||fk(        sJ t        j                  |j
                  |
   d	      sJ t        j                  |j
                  |   d      sJ y
)a  Test 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$GGQFC E./E$/4$(?
*+./E$/4$(?
*+ xxQA'H%&HQQYAE	!"E8,F JJv{{+Ma Ib!I!!)V\\:J!!)V\\:J 66288J'!+t<===66288J'!+t<===;;v{{9-r222;;v{{9-q111r4   c                  :   t         j                  j                  d       ddt         j                  j                  d      z  z   } t        j                  d      }d|dd	ddf<   t        | |      }t        j                  t        j                  |            rJ y)
a  Test 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E8,Fvvbhhv&''''r4   c                      t        j                  d      } t        j                  d      }t        j                  t              5  t        ||        d d d        y # 1 sw Y   y xY w)Nr   r   r7   r7   r   rQ   r
   raises
ValueErrorr   r&   rG   s     r2   test_switched_argumentsr]   ]   sG    GGFOEwwvH	
	# (x'( ( (s   AA#c                  T   dt        d      z  } dt        j                  d      z  }t        dd      }||ddfxx   | ddddf   z  cc<   ||dd	fxx   | z  cc<   ||d
dfxx   | z  cc<   ||ddfxx   | ddddf   z  cc<   t	        || d|j                               }t        j                  |j                        }t        j                  |dd |j                        \  }}t        |d       t        j                  |dd |j                        \  }}t        |d       y)ae  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x4F
 JJv{{+MM"1-v||<DAqGM"#.=DAqGr4   c                  ~   t         j                  j                  d       t         j                  j                  ddd      } t        j                  d      }| |ddddddf<   t        ||       }t        |j                  d	       t        t        j                  |j                         |j                        d
       y )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#E!A#qsAaC-E8,F|,!!&--/6<<@)Lr4   c                     t         j                  j                  d       t         j                  j                  ddd      } t        j                  d      }| |ddddddf<   t        || d	
      }t        |j                  d       t        t        j                  |j                         |j                        d       y )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#E!A#qsAaC-E8t<F|,!!&--/6<<@)Lr4   c                      t        d      } t        j                  d      }| d d dd f   |ddd df<   t        || dd      }t	        t        j
                  |j                         |j                        d	       y )
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}      sj    qzHHHXEaf%E!A#rr'NE8t)LF!!&--/6<<@&Ir4   c                  \   t        j                  d      } t        j                  d      }t        j                  t              5  t        ||        d d d        t        j                  d      } t        j                  d      }t        j                  t              5  t        ||        d d d        t        j                  d      } t        j                  d      }t        j                  t              5  t        ||        d d d        y # 1 sw Y   xY w# 1 sw Y   nxY w# 1 sw Y   y xY w)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4D"
DD"D+c                     t        t        j                               } t        j                  d      }d|d<   t        | |      }t        |j                                |j                         dk  sJ |j                         dkD  sJ y )NrX   r   )r   r   g  ?g  )	r   r   pager   r:   r   printmaxminrT   s      r2   test_bounding_valuesr      sk    %ExxHHTNE8,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      sx     E & & : # Wrzz2::67+ 8+>!2H((:
M
MJ("$r4   