+
    Ai8                         R t ^ RIHt ^ RIHt ^ RIt^ RIHt	 ^RI
Ht ^RIHt ^RIHt ^RIHtHt R	 tR
^RRR^R^
RRRRR]P*                  /R ltR tR^R^
RRRRR]P*                  /R ltR# )z,TV-L1 optical flow algorithm implementation.)partial)combinations_with_replacementN)ndimage)gaussian)_supported_float_type)warp)_coarse_to_fine_get_warp_pointsc	                
   V P                   p	\        P                  ! V P                   U
u. uF  p
\        P                  ! WR7      NK  	  up
RRRR/ pRV P
                  ,          p^pW4,          pW,          pWpP                  ,          pT;pp\        P                  ! V P
                  3V P                  ,           V	R7      p\        P                  ! V P
                  V P
                  3V P                  ,           V	R7      p\        R4      .VP
                  ,          p\        R4      .VP
                  ,          p\        R4      .VP
                  ^,
          ,          p\        V4       EF  pV'       d2   \        P                  ! V^.V P
                  ^.,          ,           4      p\        V\        VV4      RR	7      p\        P                  ! \        P                  ! V4      4      pVV,          P!                  ^ 4      p^VV^ 8H  &   VV ,
          VV,          P!                  ^ 4      ,
          p\        V4       EF  pVVV,          P!                  ^ 4      ,           p\#        V4      VV,          8*  pTpVR
V3;;,          VV,          VR
V3,          ,          VV,          ,          ,          uu&   V( pV\        P$                  ! VV,          4      ,          pVR
V3;;,          VVR
V3,          ,          ,          uu&   VP'                  4       p\        V P
                  4       EF  pVV^ &   \        V4       EF  p\        V P
                  4       F^  p V V^ &   \        ^ R4      VV ^,           &   \        P(                  ! VV,          V R7      V\+        V4      &   \        R4      VV ^,           &   K`  	  \        P,                  ! V^,          P!                  ^ 4      4      \        P.                  R3,          p!V!V,          p!V!R,          p!VV;;,          VV,          ,          uu&   VV;;,          V!,          uu&   VV,          P!                  ^ 4      ) p"\        V P
                  4       F~  p V V^&   \        ^ R4      VV ^,           &   \        ^R4      VV &   V"\+        V4      ;;,          V\+        V4      ,          ,          uu&   \        R4      VV ^,           &   \        R4      VV &   K  	  VV,          V",           VV&   EK  	  EK  	  EK  	  VV,          pVV,          P!                  4       V8  d    V# TpEK  	  V# u up
i )u>  TV-L1 solver for optical flow estimation.

Parameters
----------
reference_image : ndarray, shape (M, N[, P[, ...]])
    The first grayscale image of the sequence.
moving_image : ndarray, shape (M, N[, P[, ...]])
    The second grayscale image of the sequence.
flow0 : ndarray, shape (image0.ndim, M, N[, P[, ...]])
    Initialization for the vector field.
attachment : float
    Attachment parameter. The smaller this parameter is,
    the smoother is the solutions.
tightness : float
    Tightness parameter. It should have a small value in order to
    maintain attachment and regularization parts in
    correspondence.
num_warp : int
    Number of times moving_image is warped.
num_iter : int
    Number of fixed point iteration.
tol : float
    Tolerance used as stopping criterion based on the L² distance
    between two consecutive values of (u, v).
prefilter : bool
    Whether to prefilter the estimated optical flow before each
    image warp.

Returns
-------
flow : ndarray, shape (image0.ndim, M, N[, P[, ...]])
    The estimated optical flow components for each axis.

dtypeindexingijsparseTg      ?Nedgemode:NNNaxis.g      ?)r   npmeshgridshapearangendimsizezerosslicerangendimedian_filterr   r	   arraygradientsumabssigncopydifftuplesqrtnewaxis)#reference_imagemoving_imageflow0
attachment	tightnessnum_warpnum_itertol	prefilterr   ngriddtreg_num_iterf0f1flow_currentflow_previousgprojs_gs_ps_d_image1_warpgradNIrho_0rhoidxflow_auxiliarysrhoaxnormds#   &&&&&&&&&                          `/var/www/html/photoedit/myenv/lib/python3.14/site-packages/skimage/registration/_optical_flow.py_tvl1rN      s   \ !!E;;-<-B-B	C-B"))A
#-B	C D 
##	#BL		B	BC#((L=
/&&(?+@+@@NA88    	
 

		 
 D 	d	C 	d		C 	d	QC 8_,,qcO$8$8A3$>>L *4>V
 xxK01Tkq!27o-1D0I0I!0LLxA 4,.33A66Cc(b2g%C)N1c6"c#haf&=3&GG"$CC))D1c6"dT!S&\&99" *..0L_112A|,A#O$8$89!#A&+ArlBF(*S0A(K%*&+DkBF	 : 77AqD::a=1"**c/BDBJDCKDIa'II%I cq))A#O$8$89!#A&+ArlBF"'4.B%*eCj)99&+DkBF"'+B : )7s(;a(?L%/ - 3% !Z 	%M)..036  %A D I 
Ds    T<r.   r/   g333333?r0   r1   r2   g-C6?r3   Fr   c          
         \        \        VVVVVVR7      p	\        P                  ! V4      \	        V4      8w  d   RV R2p
\        V
4      h\        WWR7      # )u
  Coarse to fine optical flow estimator.

The TV-L1 solver is applied at each level of the image
pyramid. TV-L1 is a popular algorithm for optical flow estimation
introduced by Zack et al. [1]_, improved in [2]_ and detailed in [3]_.

Parameters
----------
reference_image : ndarray, shape (M, N[, P[, ...]])
    The first grayscale image of the sequence.
moving_image : ndarray, shape (M, N[, P[, ...]])
    The second grayscale image of the sequence.
attachment : float, optional
    Attachment parameter (:math:`\lambda` in [1]_). The smaller
    this parameter is, the smoother the returned result will be.
tightness : float, optional
    Tightness parameter (:math:`\theta` in [1]_). It should have
    a small value in order to maintain attachment and
    regularization parts in correspondence.
num_warp : int, optional
    Number of times moving_image is warped.
num_iter : int, optional
    Number of fixed point iteration.
tol : float, optional
    Tolerance used as stopping criterion based on the L² distance
    between two consecutive values of (u, v).
prefilter : bool, optional
    Whether to prefilter the estimated optical flow before each
    image warp. When True, a median filter with window size 3
    along each axis is applied. This helps to remove potential
    outliers.
dtype : dtype, optional
    Output data type: must be floating point. Single precision
    provides good results and saves memory usage and computation
    time compared to double precision.

Returns
-------
flow : ndarray, shape (image0.ndim, M, N[, P[, ...]])
    The estimated optical flow components for each axis.

Notes
-----
Color images are not supported.

References
----------
.. [1] Zach, C., Pock, T., & Bischof, H. (2007, September). A
   duality based approach for realtime TV-L 1 optical flow. In Joint
   pattern recognition symposium (pp. 214-223). Springer, Berlin,
   Heidelberg. :DOI:`10.1007/978-3-540-74936-3_22`
.. [2] Wedel, A., Pock, T., Zach, C., Bischof, H., & Cremers,
   D. (2009). An improved algorithm for TV-L 1 optical flow. In
   Statistical and geometrical approaches to visual motion analysis
   (pp. 23-45). Springer, Berlin, Heidelberg.
   :DOI:`10.1007/978-3-642-03061-1_2`
.. [3] Pérez, J. S., Meinhardt-Llopis, E., & Facciolo,
   G. (2013). TV-L1 optical flow estimation. Image Processing On
   Line, 2013, 137-150. :DOI:`10.5201/ipol.2013.26`

Examples
--------
>>> from skimage.color import rgb2gray
>>> from skimage.data import stereo_motorcycle
>>> from skimage.registration import optical_flow_tvl1
>>> image0, image1, disp = stereo_motorcycle()
>>> # --- Convert the images to gray level: color is not supported.
>>> image0 = rgb2gray(image0)
>>> image1 = rgb2gray(image1)
>>> flow = optical_flow_tvl1(image1, image0)

)r.   r/   r0   r1   r2   r3   dtype=. is not supported. Try 'float32' or 'float64.'r   )r   rN   r   r   r   
ValueErrorr   )r+   r,   r.   r/   r0   r1   r2   r3   r   solvermsgs   &&$$$$$$$  rM   optical_flow_tvl1rU      sb    j F 
xx/66ugKLo?&NN    c           
        V P                   pV P                  p^V,          ^,           p	V'       d$   W^,          3,          p
\        \        V
RR7      pM#\        \        P
                  W3,          RR7      pTp\        P                  ! V P                  W3,           VR7      p\        P                  ! V P                  V^3,           VR7      p\        P                  ! V P                   Uu. uF  p\        P                  ! WR7      NK  	  upRRRR/ p\        V4       EF  pV'       d&   \        P                  ! VRVR,          ,           4      p\        V\        VV4      R	R
7      p\        P                  ! \        P                   ! V4      ^ R7      pVV,          P#                  ^ R7      V ,           V,
          p\%        \        V4      ^4       F1  w  ppV! VV,          VV,          ,          4      ;VRVV3&   VRVV3&   K3  	  \        V4       F  pV! VV,          V,          4      VRV^ 3&   K!  	  \'        \        P(                  P+                  V4      4      R8  p\        P,                  ! WR7      VV&   ^ VV&   \        P.                  ! \        P(                  P1                  W4      R,          V^ 4      pEK  	  V# u upi )a  Iterative Lucas-Kanade (iLK) solver for optical flow estimation.

Parameters
----------
reference_image : ndarray, shape (M, N[, P[, ...]])
    The first grayscale image of the sequence.
moving_image : ndarray, shape (M, N[, P[, ...]])
    The second grayscale image of the sequence.
flow0 : ndarray, shape (reference_image.ndim, M, N[, P[, ...]])
    Initialization for the vector field.
radius : int
    Radius of the window considered around each pixel.
num_warp : int
    Number of times moving_image is warped.
gaussian : bool
    if True, a gaussian kernel is used for the local
    integration. Otherwise, a uniform kernel is used.
prefilter : bool
    Whether to prefilter the estimated optical flow before each
    image warp. This helps to remove potential outliers.

Returns
-------
flow : ndarray, shape (reference_image.ndim, M, N[, P[, ...]])
    The estimated optical flow components for each axis.

mirror)sigmar   )r   r   r   r   r   r   Tr   r   r   .g+=)   )   ).    )r   r   r   gaussian_filterr   uniform_filterr   r   r   r   r   r   r    r   r	   stackr"   r#   r   r$   linalgdeteyemoveaxissolve)r+   r,   r-   radiusr0   r   r3   r   r   r   rY   filter_funcflowAbr4   r5   rA   moving_image_warprC   error_imageijrG   s   &&&&&&&                 rM   _ilkrn     sO   8 !!EDv:>Dq{"oUJc00tg~HUD 	&&$5UCA
&&$2%@A;;-<-B-B	C-B"))A
#-B	C D 8_$$T4$++=>D *46V
 xx$56Q?d{''Q'//ADUU 2%+qADAq*5d1gQ6G*HHAc1aiL1S!QY< B tA&tAw'<=Ac1aiL  "))--"#e+*## {{299??108$B/ 2 K= 
Ds   , Kre   r   c                   \        \        W#WER7      p\        P                  ! V4      \	        V4      8w  d   RV R2p\        V4      h\        WWvR7      # )a]	  Coarse to fine optical flow estimator.

The iterative Lucas-Kanade (iLK) solver is applied at each level
of the image pyramid. iLK [1]_ is a fast and robust alternative to
TVL1 algorithm although less accurate for rendering flat surfaces
and object boundaries (see [2]_).

Parameters
----------
reference_image : ndarray, shape (M, N[, P[, ...]])
    The first grayscale image of the sequence.
moving_image : ndarray, shape (M, N[, P[, ...]])
    The second grayscale image of the sequence.
radius : int, optional
    Radius of the window considered around each pixel.
num_warp : int, optional
    Number of times moving_image is warped.
gaussian : bool, optional
    If True, a Gaussian kernel is used for the local
    integration. Otherwise, a uniform kernel is used.
prefilter : bool, optional
    Whether to prefilter the estimated optical flow before each
    image warp. When True, a median filter with window size 3
    along each axis is applied. This helps to remove potential
    outliers.
dtype : dtype, optional
    Output data type: must be floating point. Single precision
    provides good results and saves memory usage and computation
    time compared to double precision.

Returns
-------
flow : ndarray, shape (reference_image.ndim, M, N[, P[, ...]])
    The estimated optical flow components for each axis.

Notes
-----
- The implemented algorithm is described in **Table2** of [1]_.
- Color images are not supported.

References
----------
.. [1] Le Besnerais, G., & Champagnat, F. (2005, September). Dense
   optical flow by iterative local window registration. In IEEE
   International Conference on Image Processing 2005 (Vol. 1,
   pp. I-137). IEEE. :DOI:`10.1109/ICIP.2005.1529706`
.. [2] Plyer, A., Le Besnerais, G., & Champagnat,
   F. (2016). Massively parallel Lucas Kanade optical flow for
   real-time video processing applications. Journal of Real-Time
   Image Processing, 11(4), 713-730. :DOI:`10.1007/s11554-014-0423-0`

Examples
--------
>>> from skimage.color import rgb2gray
>>> from skimage.data import stereo_motorcycle
>>> from skimage.registration import optical_flow_ilk
>>> reference_image, moving_image, disp = stereo_motorcycle()
>>> # --- Convert the images to gray level: color is not supported.
>>> reference_image = rgb2gray(reference_image)
>>> moving_image = rgb2gray(moving_image)
>>> flow = optical_flow_ilk(moving_image, reference_image)

)re   r0   r   r3   rP   rQ   r   )r   rn   r   r   r   rR   r   )	r+   r,   re   r0   r   r3   r   rS   rT   s	   &&$$$$$  rM   optical_flow_ilkrp   [  sT    T VF 
xx/66ugKLo?&NNrV   )__doc__	functoolsr   	itertoolsr   numpyr   scipyr   r   _shared.filtersr   r]   _shared.utilsr   	transformr   _optical_flow_utilsr   r	   rN   float32rU   rn   rp    rV   rM   <module>r|      s    2  3    9 1  BTncO 	cO
 cO cO cO 	cO cO **cOLL^RO 	RO
 RO RO RO **ROrV   