
    9i`                     p    S r SSKrSSKJr  SSKJr  SSKJ	r	  S r
S rSS jrSS	S
\R                  4S jrg)z(Common tools to optical flow algorithms.    N)ndimage   )pyramid_reduce)_convertc                 j    UR                  5       n[        U 5       H  u  p4X#S4==   U-  ss'   M     U$ )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/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/registration/_optical_flow_utils.py_get_warp_pointsr   
   s4    " ))+CD/H "J    c           	      $   [        XR                  SS 5       VVs/ s H	  u  p#X#-  PM     nnn[        R                  " X@R                  S9nU H  nUS[        R
                  4   nM     U[        R                  " U S/U-   SSSS9-  nU$ s  snnf )	am  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.

   Ndtype.r   nearestF)ordermode	prefilter)zipshapenparrayr   newaxisndizoom)r   r   noscalescale_factor_rflows           r   _resize_flowr'   !   s    (  #5**QR.9:9tqQU9E:88E4L#CO4  388qcEke E L ;s   B
      c                     U /n[        U R                  5      nSnXb:  aP  XQU-  :  aH  [        US   USS9nUR                  U5        [        UR                  5      nUS-  nXb:  a
  XQU-  :  a  MH  USSS2   $ )az  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_pyramidr7   B   s    * cGqww<DE>8'; ;72;	Eq177|
	 >8'; ; 4R4=r   c                    U R                   UR                   :w  a  [        S5      e[        R                  " U5      R                  S;  a  [        S5      e[        [        [        [        X5      X4U5      [        [        X5      X4U5      5      5      n[        R                  " US   S   R                  4US   S   R                   -   US9nU" US   S   US   S   U5      nUSS  H!  u  pU" X[        XR                   5      5      nM#     U$ )a%  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   r7   r   zerosndimr'   )I0I1solverr0   r1   r2   r   r3   r   J0J1s              r   _coarse_to_finerD   d   s    : 
xx288BCC	xx6)VWW",iJ",iJ	
G 88WQZ]'')GAJqM,?,??uMD'!*Q-A5D!"+bl4:;  Kr   )g       @r(   r)   )__doc__numpyr   scipyr   r   	transformr   
util.dtyper   r   r'   r7   float32rD    r   r   <module>rL      s9    .    & !.BF  Rrzz2r   