o
    ci                     @   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|| qd 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xy r0   m/var/www/addictedbytheproject.nl/epg/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sJ t 
|j|
 d	sJ t 
|j| dsJ 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   iT)	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"    
$
