Ë
    îì�i`  ã                   ól   — 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y)z(Common tools to optical flow algorithms.é    N)Úndimageé   )Úpyramid_reduce)Ú_convertc                 ój   — |j                  «       }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        ú�/var/www/ITT-ServiceAPI-Services/ITT-Document-Scan/mrzscanner/mrzenv/lib/python3.12/site-packages/skimage/registration/_optical_flow_utils.pyÚ_get_warp_pointsr   
   s=   € ð" �)‰)‹+€CÜ˜D“/ò ‰ˆˆQØˆC�ˆH‹˜ÑŒðà€Jó    c                 ó*  — t        || j                  dd «      D ��cg c]
  \  }}||z  ‘Œ }}}t        j                  || j                  ¬«      }|D ]  }|dt        j
                  f   }Œ |t        j                  | dg|z   ddd¬«      z  }|S c c}}w )	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.

    é   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¨$¯*©*°Q°R¨.Ó9×:‘t�q˜!ˆQ�‹UÐ:€EÑ:Ü—8‘8˜E¨¯©Ô4€Làò 5ˆØ# C¬¯© OÑ4‰ð5ð œ3Ÿ8™8Øˆqˆc�E‰k ¨¸eôñ €Eð €Lùó ;s   �Bé
   é   c                 óô   — | g}t        | j                  «      }d}||k  rR|||z  kD  rJt        |d   |d¬«      }|j                  |«       t        |j                  «      }|dz  }||k  r	|||z  kD  rŒJ|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_pyramidr7   B   s‰   € ð* ˆc€GÜˆq�w‰w‹<€DØ€Eà�6Š>  y°8Ñ';Ò ;Ü˜7 2™;¨	ÀÔEˆØ�‰�qÔÜ�1—7‘7‹|ˆØ�‰
ˆð	 �6Š>  y°8Ñ';Ó ;ð ‘4�R�4‰=Ðr   c                 ó   — | j                   |j                   k7  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   r7   r   ÚzerosÚndimr'   )ÚI0ÚI1Úsolverr0   r1   r2   r   r3   r   ÚJ0ÚJ1s              r   Ú_coarse_to_finerD   d   s  € ð: 
‡x�x�2—8‘8ÒÜÐBÓCÐCä	‡x�x�ƒ×Ñ 6Ñ)ÜÐVÓWÐWäÜÜœ " eÓ,¨i¸ÀÓJÜœ " eÓ,¨i¸ÀÓJó	
ó€Gô �8‰8�W˜Q‘Z ‘]×'Ñ'Ð)¨G°A©J°q©M×,?Ñ,?Ñ?ÀuÔM€Dá�'˜!‘*˜Q‘- ¨¡¨A¡°Ó5€Dà˜!˜"�+ò <‰ˆˆBÙ�b˜"œl¨4°·±Ó:Ó;‰ð<ð €Kr   )g       @r(   r)   )Ú__doc__Únumpyr   Úscipyr   r   Ú	transformr   Ú
util.dtyper   r   r'   r7   Úfloat32rD   © r   r   ú<module>rL      s9   ðÙ .ã Ý  å &Ý !òò.óBðF  ¨°R¸r¿z¹zô2r   