a
    =b                     @   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   Clib/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floatZsinmaxZ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   rndr   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
    r.   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    
r3   c                  C   s8   t jd} | jdd}t||}t |dks4J d S )Nr   )@   r4   r4   r   r/   r1   r   r   r   test_no_motion_3dK   s    
r5   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    r8   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   Zint64)r)   r2   r:   r;   r   r   r   test_wrong_dtypeq   s    r=   )r   r   )Znumpyr   r&   Zskimage._shared.utilsr   Zskimage.registrationr   Zskimage.transformr   r   ZmarkZparametrizeZfloat16r7   r6   r+   r.   r3   r5   r8   r<   r=   r   r   r   r   <module>   s   

		