a
    
d                     @   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   m/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/skimage/registration/tests/test_tvl1.py
<listcomp>       z!_sin_flow_gen.<locals>.<listcomp>ZindexingZijdtyper   )r   .Zedge)mode)
r   ZmeshgridshapestackZ
zeros_likefloatsinmaxpir   )image0Z
max_motionZnpicsZ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sXJ t	|| 
 dk spJ | |krtt  t||d| d W d    n1 s0    Y  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 sJJ 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_motion7   s
    r0   c                  C   s8   t jd} | jdd}t||}t |dks4J d S )Nr   r   r   r   r#   r$   r%   r   allr+   imgr,   r   r   r   test_no_motion_2dB   s    
r5   c                  C   s8   t jd} | jdd}t||}t |dks4J d S )Nr   )@   r6   r6   r   r1   r3   r   r   r   test_no_motion_3dK   s    
r7   c                  C   s   t jd} | jdd}t|\}}t||dt jd}|jt jksFJ t||dt jd}|jt jkshJ t 	|| 
 dk sJ 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_dtypeT   s    r:   c                  C   s`   t jd} | jdd}| jdd}tt t||\}}W d    n1 sR0    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_shapesi   s
    r>   c                  C   sZ   t jd} | jdd}tt$ t||t jd\}}W d    n1 sL0    Y  d S )Nr   r   r   r   )	r   r#   r$   r%   r(   r)   r*   r   int64)r+   r4   r<   r=   r   r   r   test_wrong_dtypeq   s    r@   )r   r   )numpyr   r(   Zskimage._shared.utilsr   Zskimage.registrationr   Zskimage.transformr   r   markZparametrizefloat16r9   r8   r-   r0   r5   r7   r:   r>   r@   r   r   r   r   <module>   s   

		