o
    ðËh  ã                   @   s¸   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 dejejg¡dd	„ ƒZd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )é    N)Úassert_almost_equalÚassert_equal)ÚdataÚimg_as_float)Údiamond)Úmatch_templateÚpeak_local_max)ÚtestingÚdtypec                 C   sD  d}t jdd| d}dt  |¡t  |¡d d d…   }|j| dd}d	d
g}|D ]\}}||||| …||| …f< q(t j d¡ |dt jjddj| dd 7 }t||ƒ}|j| ks]J ‚d}t	||d}	t
|	ƒdkr„|t|	jƒ }
t  |
¡d d d… }|	| d d… }	|	t  |	d d …df ¡ }	t||	ƒD ]	\}}t||ƒ q–d S )Néd   )é  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Úxy© r0   ú^/var/www/html/scripts/venv/lib/python3.10/site-packages/skimage/feature/tests/test_template.pyÚtest_template
   s*   " 
ÿr2   c                  C   sD  d} d}d\}}d\}}t  ||fd¡}d||||  …|||  …f< d||||  …|||  …f< t  | d | d f¡}d|dd|  …dd|  …f< t||ƒ}t  |j¡}	|	d }
|	d	 }t  |
|j¡}t  ||j¡}t  t  	|¡d ||fk¡szJ ‚t  t  	|¡d ||fk¡sŠJ ‚t  
|j|
 d	¡s•J ‚t  
|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_resultr0   r0   r1   Útest_normalization*   s&   
  rJ   c                  C   sb   t j d¡ ddt jjdd  } t  d¡}d|dd	…dd…f< t| |ƒ}t  t  |¡¡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•Ö&è.>)r3   r3   r   )é   rK   r   Nr4   )r   r   r   ÚnormalÚonesr   ÚanyÚisnan©r$   rD   r)   r0   r0   r1   Útest_no_nansN   s   

rQ   c                  C   sN   t  d¡} t  d¡}t t¡ t|| ƒ W d   ƒ d S 1 s w   Y  d S )N©r   r   ©r4   r4   ©r   rM   r	   ÚraisesÚ
ValueErrorr   ©r$   rD   r0   r0   r1   Útest_switched_arguments]   s
   

"ÿrX   c                  C   s  dt dƒ } dt d¡ }tddƒ}||dd…f  | dd…dd…f 8  < ||dd	…f  | 7  < ||d
d…f  | 8  < ||dd…f  | dd…dd…f 7  < t|| d| ¡ d}t |j¡}t |dd… |j	¡\}}t
|dƒ t |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   )é	   é   é   Nr4   éýÿÿÿé   rY   i÷ÿÿÿéüÿÿÿT)Ú	pad_inputÚconstant_values)r5   r   éþÿÿÿ)é   rK   )r   r   rM   Úslicer   Úmeanr"   r8   r9   r:   r   )rD   r$   Úmidr)   rE   ÚiÚjr0   r0   r1   Útest_pad_inputd   s   	
((ÿ
rh   c                  C   sr   t j d¡ t j ddd¡} t  d¡}| |dd…dd…dd…f< t|| ƒ}t|jd	ƒ tt  | 	¡ |j¡d
ƒ d S )Nr   r4   ©r5   r5   r5   rK   r   é   r]   r[   )é
   rk   rk   )r4   r   r]   ©
r   r   r   Úrandr7   r   r   r:   r9   Úargmax©rD   r$   r)   r0   r0   r1   Útest_3d€   s   

rp   c                  C   sv   t j d¡ t j ddd¡} t  d¡}| |dd…dd…dd…f< t|| d	d
}t|jdƒ tt  | 	¡ |j¡dƒ d S )Nr   r4   ri   rK   r   rj   r]   r[   T)r_   )r]   rK   r   rl   ro   r0   r0   r1   Útest_3d_pad_input   s   
rq   c                  C   sb   t dƒ} t d¡}| d d …dd …f |dd…d d…f< t|| ddd}tt | ¡ |j¡d	ƒ d S )
Nr   )rk   rk   r\   r[   r4   TÚreflect)r_   Úmode)r]   r   )r   r   r7   r   r   r9   rn   r:   ro   r0   r0   r1   Útest_padding_reflectš   s   
$ÿrt   c                  C   sÞ   t  d¡} t  d¡}t t¡ t|| ƒ W d   ƒ n1 sw   Y  t  d¡} t  d¡}t t¡ t|| ƒ W d   ƒ n1 sCw   Y  t  d¡} t  d¡}t t¡ t|| ƒ W d   ƒ d S 1 shw   Y  d S )N)r   r   r   rS   rR   )r4   r4   r   )r   r   r4   r4   rT   rW   r0   r0   r1   Útest_wrong_input¥   s   

ÿ

ÿ

"ÿru   c                  C   sX   t t ¡ ƒ} t d¡}d|d< t| |ƒ}t| ¡ ƒ | ¡ dk s"J ‚| ¡ dks*J ‚d S )NrS   r   )r   r   g›ò×  ð?g›ò×  ð¿)	r   r   Úpager   r7   r   ÚprintÚmaxÚminrP   r0   r0   r1   Útest_bounding_values¶   s   

rz   )Únumpyr   Úskimage._shared.testingr   r   Úskimager   r   Úskimage.morphologyr   Úskimage.featurer   r   Úskimage._sharedr	   ÚparametrizeÚfloat32Úfloat64r2   rJ   rQ   rX   rh   rp   rq   rt   ru   rz   r0   r0   r0   r1   Ú<module>   s"    
$