
    1-Ph                         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dS )    N)assert_almost_equalassert_equal)dataimg_as_float)diamond)match_templatepeak_local_max)testingdtypec                 f   d}t          j        dd|           }dt          j        |          t          j        |          d d d         z   z  }|                    | d          }d	d
g}|D ]\  }}|||||z   |||z   f<   t           j                            d           |dt           j                            d                              | d          z  z  }t          ||          }|j        | k    sJ d}t          ||          }	t          |	          dk    rG|t          |	j                           }
t          j        |
          d d d         }|	|         d d         }	|	t          j        |	d d df                            }	t          ||	          D ]\  }}t          ||           d S )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/test/jupyter/venv/lib/python3.11/site-packages/skimage/feature/tests/test_template.pytest_templater3   
   s   DGJ5111EBF4LL26$<<"#556F]]5u]--F *-  3 31,2a!d(lADL())INN1	S29$$*$55<<U<OOOOEE6**F<5    EvE:::I
9~~U9;//0J{++DDbD1	i(!,	 "*Yqqq!t_556I-y99 + +	2B	****+ +    c                     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 d
S )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$GQFC  E./E$/4$(?
*+./E$/4$(?
*+ xQA''H%&HQQYAE	!"E8,,F Jv{++Ma Ib!I!)V\::J!)V\::J 628J''!+t<=====628J''!+t<=====;v{9-r22222;v{9-q1111111r4   c                  >   t           j                            d           ddt           j                            d          z  z   } t          j        d          }d|dd	ddf<   t          | |          }t          j        t          j        |                    rJ dS )
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     INN1$))x)8888EwvHHRaRUOE8,,Fvbhv&&'''''''r4   c                      t          j        d          } t          j        d          }t          j        t                    5  t          ||            d d d            d S # 1 swxY w Y   d S )Nr   r   r7   r7   r   rQ   r
   raises
ValueErrorr   r&   rG   s     r2   test_switched_argumentsr]   ]   s    GFOOEwvH	
	#	# ( (x'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   A  A$'A$c                     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|                                          }t          j        |j                  }t          j        |dd         |j	                  \  }}t          |d           t          j        |dd         |j	                  \  }}t          |d           dS )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   st    WQZZH"''"""E
1++C	#rr'NNNhqqq"##v&&NNN	#qs(OOOxOOO	#r"u*!	#rss(OOOx2A2&OOOx4  F
 Jv{++MM"1"-v|<<DAqGM"##.==DAqGr4   c                     t           j                            d           t           j                            ddd          } t          j        d          }| |ddddddf<   t          ||           }t          |j        d	           t          t          j        |	                                |j                  d
           d S )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    INN1y~~aA&&HH\""E#E!A#qsAaC-E8,,F|,,,!&--//6<@@)LLLLLr4   c                     t           j                            d           t           j                            ddd          } t          j        d          }| |ddddddf<   t          || d	
          }t          |j        d           t          t          j        |	                                |j                  d           d S )Nr   r7   rp   rO   r   rq   rc   ra   T)re   )rc   rO   r   rs   rv   s      r2   test_3d_pad_inputry      s    INN1y~~aA&&HH\""E#E!A#qsAaC-E8t<<<F|,,,!&--//6<@@)LLLLLr4   c                     t          d          } t          j        d          }| d d dd f         |ddd df<   t          || dd          }t	          t          j        |                                |j                  d	           d S )
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}      s    qzzHHXEaaaf%E!A#rr'NE8t)LLLF!&--//6<@@&IIIIIr4   c                  ~   t          j        d          } t          j        d          }t          j        t                    5  t          ||            d d d            n# 1 swxY w Y   t          j        d          } t          j        d          }t          j        t                    5  t          ||            d d d            n# 1 swxY w Y   t          j        d          } t          j        d          }t          j        t                    5  t          ||            d d d            d S # 1 swxY w Y   d S )N)r   r   r   rX   rW   )r7   r7   r   )r   r   r7   r7   rY   r\   s     r2   test_wrong_inputr      s   GIEwvH	
	#	# ( (x'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( GFOOEwy!!H	
	#	# ( (x'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( GL!!Ewy!!H	
	#	# ( (x'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s6   AA#&A#+CCCD22D69D6c                  B   t          t          j                              } t          j        d          }d|d<   t          | |          }t          |                                           |                                dk     sJ |                                dk    sJ d S )NrX   r   )r   r   g  ?g  )	r   r   pager   r:   r   printmaxminrT   s      r2   test_bounding_valuesr      s    %%Ex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      sL       E E E E E E E E & & & & & & & & & & & & & & : : : : : : : : # # # # # # Wrz2:677+ + 87+>!2 !2 !2H( ( (( ( (  :
M 
M 
M
M 
M 
MJ J J( ( ("$ $ $ $ $r4   