o
    j                     @   s   d dl Zd dlZd dlmZ d dlmZ d dlmZ dddZ	ej
d	ej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S )    N)_supported_float_type)optical_flow_tvl1)warp      @   c                 C   sz   t jdd | jD ddi}t |}t j|td}|t |d |d   | t j  |d< t	| || dd	}||fS )
a  Generate a synthetic ground truth optical flow with a sinusoid as
      first component.

    Parameters
    ----------
    image0: ndarray
        The base image to be warped.
    max_motion: float
        Maximum flow magnitude.
    npics: int
        Number of sinusoid pics.

    Returns
    -------
    flow, image1 : ndarray
        The synthetic ground truth optical flow with a sinusoid as
        first component and the corresponding warped image.

    c                 S   s   g | ]}t |qS  )npZarange).0nr   r   e/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/skimage/registration/tests/test_tvl1.py
<listcomp>   s    z!_sin_flow_gen.<locals>.<listcomp>ZindexingZijdtyper   )r   .edge)mode)
r   ZmeshgridshapestackZ
zeros_likefloatsinmaxpir   )image0Z
max_motionZnpicsgridgt_flowimage1r   r   r   _sin_flow_gen	   s   
,r   r   c                 C   s   t jd}|jdd}t|\}}|j| dd}t| }t||d|d}|j|ks,J t	|| 
 dk s8J | |kr\tt t||d| d W d    d S 1 sUw   Y  d S d S )	Nr      r   sizeF)copyr   
attachmentr         ?)r   randomdefault_rngnormalr   Zastyper   r   r   absmeanpytestraises
ValueError)r   rngr   r   r   Zfloat_dtypeflowr   r   r   test_2d_motion%   s   "r.   c                  C   sN   t jd} | jdd}t|\}}t||dd}t||  dk s%J d S )Nr   )d   r/   r/   r   
   )r"   r#   )r   r$   r%   r&   r   r   r'   r(   )r,   r   r   r   r-   r   r   r   test_3d_motion8   s
   r1   c                  C   8   t jd} | jdd}t||}t |dksJ d S )Nr   r   r   r   r$   r%   r&   r   allr,   imgr-   r   r   r   test_no_motion_2dC      
r7   c                  C   r2   )Nr   )@   r9   r9   r   r3   r5   r   r   r   test_no_motion_3dL   r8   r:   c                  C   s   t jd} | jdd}t|\}}t||dt jd}|jt jks#J t||dt jd}|jt jks4J t 	|| 
 dk sAJ d S )Nr   r   r   r   r!   gMbP?)r   r$   r%   r&   r   r   float64r   float32r'   r(   )r,   r   r   r   Zflow_f64Zflow_f32r   r   r   test_optical_flow_dtypeU   s   r=   c                  C   sb   t jd} | jdd}| jdd}tt t||\}}W d    d S 1 s*w   Y  d S )Nr   r   r   )   r   )r   r$   r%   r&   r)   r*   r+   r   )r,   ZI0ZI1uvr   r   r   test_incompatible_shapesj   s   "rA   c                  C   s\   t jd} | jdd}tt t||t jd\}}W d    d S 1 s'w   Y  d S )Nr   r   r   r   )	r   r$   r%   r&   r)   r*   r+   r   Zint64)r,   r6   r?   r@   r   r   r   test_wrong_dtyper   s
   "rB   )r   r   )numpyr   r)   Zskimage._shared.utilsr   Zskimage.registrationr   Zskimage.transformr   r   markZparametrizeZfloat16r<   r;   r.   r1   r7   r:   r=   rA   rB   r   r   r   r   <module>   s    

		