U
    ?h                     @   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   V/var/www/html/venv/lib/python3.8/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sXt	t
||  dk spt	| |krtt t||d| d W 5 Q R X d S )	Nr      r   sizeF)copyr   
attachmentr         ?)r   randomdefault_rngnormalr   Zastyper   r   r   AssertionError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 sJtd S )Nr   )d   r0   r0   r   
   )r"   r#   )	r   r$   r%   r&   r   r   r(   r)   r'   )r-   r   r   r   r.   r   r   r   test_3d_motion7   s
    r2   c                  C   s8   t jd} | jdd}t||}t |dks4td S )Nr   r   r   r   r$   r%   r&   r   allr'   r-   imgr.   r   r   r   test_no_motion_2dB   s    
r7   c                  C   s8   t jd} | jdd}t||}t |dks4td S )Nr   )@   r8   r8   r   r3   r5   r   r   r   test_no_motion_3dK   s    
r9   c                  C   s   t jd} | jdd}t|\}}t||dt jd}|jt jksFtt||dt j	d}|jt j	kshtt 
||  dk std S )Nr   r   r   r   r!   gMbP?)r   r$   r%   r&   r   r   float64r   r'   float32r(   r)   )r-   r   r   r   Zflow_f64Zflow_f32r   r   r   test_optical_flow_dtypeT   s    r<   c               	   C   sL   t jd} | jdd}| jdd}tt t||\}}W 5 Q R X 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   sF   t jd} | jdd}tt t||t jd\}}W 5 Q R X 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_dtypeq   s    rA   )r   r   )numpyr   r*   Zskimage._shared.utilsr   Zskimage.registrationr   Zskimage.transformr   r   markZparametrizeZfloat16r;   r:   r/   r2   r7   r9   r<   r@   rA   r   r   r   r   <module>   s   

		