o
    eW  ã                   @   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   úTD:\Projects\ConvertPro\env\Lib\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_motion7   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_2dB   ó   
r7   c                  C   r2   )Nr   )é@   r9   r9   r   r3   r5   r   r   r   Útest_no_motion_3dK   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!   gü©ñÒMbP?)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   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_shapesi   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_dtypeq   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    

		