
    1-Ph`                     d    d Z ddlZddlmZ ddlmZ ddlm	Z	 d Z
d ZddZdd
dej        fdZdS )z(Common tools to optical flow algorithms.    N)ndimage   )pyramid_reduce)_convertc                 |    |                                 }t          |           D ]\  }}||dfxx         |z  cc<   |S )a>  Compute warp point coordinates.

    Parameters
    ----------
    grid : iterable
        The sparse grid to be warped (obtained using
        ``np.meshgrid(..., sparse=True)).``)
    flow : ndarray
        The warping motion field.

    Returns
    -------
    out : ndarray
        The warp point coordinates.

    .)copy	enumerate)gridflowoutidxgs        h/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/registration/_optical_flow_utils.py_get_warp_pointsr   
   sK    " ))++CD//  QCHJ    c                     d t          || j        dd                   D             }t          j        || j                  }|D ]}|dt          j        f         }|t          j        | dg|z   ddd	          z  }|S )
a  Rescale the values of the vector field (u, v) to the desired shape.

    The values of the output vector field are scaled to the new
    resolution.

    Parameters
    ----------
    flow : ndarray
        The motion field to be processed.
    shape : iterable
        Couple of integers representing the output shape.

    Returns
    -------
    rflow : ndarray
        The resized and rescaled motion field.

    c                     g | ]
\  }}||z  S  r   ).0nos      r   
<listcomp>z _resize_flow.<locals>.<listcomp>5   s     :::tq!QU:::r      Ndtype.r   nearestF)ordermode	prefilter)zipshapenparrayr   newaxisndizoom)r   r!   scalescale_factor_rflows         r   _resize_flowr+   !   s    ( ;:s5$*QRR.99:::E8E444L 5 5#CO438qcEke   E Lr          @
      c                    | g}t          | j                  }d}||k     r^|||z  k    rUt          |d         |d          }|                    |           t          |j                  }|dz  }||k     r	|||z  k    U|ddd         S )a  Construct image pyramid.

    Parameters
    ----------
    I : ndarray
        The image to be preprocessed (Grayscale or RGB).
    downscale : float
        The pyramid downscale factor.
    nlevel : int
        The maximum number of pyramid levels.
    min_size : int
        The minimum size for any dimension of the pyramid levels.

    Returns
    -------
    pyramid : list[ndarray]
        The coarse to fine images pyramid.

    r   N)channel_axis)minr!   r   append)I	downscalenlevelmin_sizepyramidsizecountJs           r   _get_pyramidr<   B   s    * cGqw<<DE6>>y8'; ; ;72;	EEEq17||
	 6>>y8'; ; ; 44R4=r   c                 l   | j         |j         k    rt          d          t          j        |          j        dvrt          d          t          t          t          t          | |          |||          t          t          ||          |||                              }t          j	        |d         d         j
        f|d         d         j         z   |          } ||d         d         |d         d         |          }|dd         D ]%\  }	}
 ||	|
t          ||	j                             }&|S )ay  Generic coarse to fine solver.

    Parameters
    ----------
    I0 : ndarray
        The first grayscale image of the sequence.
    I1 : ndarray
        The second grayscale image of the sequence.
    solver : callable
        The solver applied at each pyramid level.
    downscale : float
        The pyramid downscale factor.
    nlevel : int
        The maximum number of pyramid levels.
    min_size : int
        The minimum size for any dimension of the pyramid levels.
    dtype : dtype
        Output data type.

    Returns
    -------
    flow : ndarray
        The estimated optical flow components for each axis.

    z'Input images should have the same shapeefdgz8Only floating point data type are valid for optical flowr   r   r   N)r!   
ValueErrorr"   r   charlistr    r<   r   zerosndimr+   )I0I1solverr5   r6   r7   r   r8   r   J0J1s              r   _coarse_to_finerI   d   s1   : 
x28BCCC	x6))VWWW"e,,iJJ"e,,iJJ	
 	
 G 8WQZ]')GAJqM,??uMMMD6'!*Q-A55D!""+ < <Bvb"l4::;;Kr   )r,   r-   r.   )__doc__numpyr"   scipyr   r%   	transformr   
util.dtyper   r   r+   r<   float32rI   r   r   r   <module>rP      s    . .                 & & & & & & ! ! ! ! ! !  .  B   F  Rrz2 2 2 2 2 2r   