
    #
3j                     F    S SK rS SKrS SKJr  \" SSSS9S 5       rSS jrg)	    N)njitz>void(f8[:, :, :], f8, i8, f8[:, :, :], i8[:], i8[:], b1[:, :])T)cachenogilc                 	   U R                   u  pxn	U	S:X  d   eSU-  S-   n
X-  n[        U5       H  n[        U5       H  nXU-  -   nUSU-  S-   S-  -  n[        USU-  -
  USU-  -   S-   5       HV  n[        USU-  -
  USU-  -   S-   5       H4  nUUU-  -   nSUs=::  a  U:  a  O  OSUs=::  a  U:  a  O  OUXO'   US-  nM6     MX     XUS-   '   M     M     [        R                  " SU-  S-   SU-  S-   S45      n[        X'U-
  5       GHy  n[        X(U-
  5       GHb  n[        R                  " UUU-
  UU-   S-   2UU-
  UU-   S-   24   5      (       a  M<  [        S5       H  nSn[        U
5       H,  n[        U
5       H  nUU UU-   U-
  UU-   U-
  U4   -  nM     M.     [        SU-  S-   5       H;  n[        SU-  S-   5       H#  nU UU-   U-
  UU-   U-
  U4   UU-  -
  UUUU4'   M%     M=     M     UnSnSnUnSnUn[        U
5       H  n[        U
5       H{  nUUUUS4   UUUS4   -  -  nUUUUS4   UUUS4   -  -  nUUUUS4   UUUS4   -  -  nUUUUS4   UUUS4   -  -  nUUUUS4   UUUS4   -  -  nUUUUS4   UUUS4   -  -  nM}     M     UU-  nUU-  nUU-  nUU-  nUU-  nUU-  nUU-  U-  UU-  U-  -   UU-  U-  -   UU-  U-  -
  SU-  U-  U-  -
  n SU -  n!UU-  UU-  -
  U!-  n"UU-  UU-  -
  U!-  n#UU-  UU-  -
  U!-  n$UU-  UU-  -
  U!-  n%UU-  UU-  -
  U!-  n&UU-  UU-  -
  U!-  n'[        SU-  S-   5       GH#  n([        SU-  S-   5       GH	  n)UU(U)S4   nUU(U)S4   n*UU(U)S4   n+U"U-  U#U*-  -   U$U+-  -   n,U#U-  U%U*-  -   U&U+-  -   n-U$U-  U&U*-  -   U'U+-  -   n.[        SU-  S-   5       H  n/[        SU-  S-   5       H  n0UU)-   U-
  nUU(-   U-
  nUU0-   U-
  nUU/-   U-
  nXU-  -   nUUU-  -   nU,UU/U0S4   -  U-UU/U0S4   -  -   U.UU/U0S4   -  -   n1UU:X  a  SOSSU1-   U-  -
  n2UU-
  SU-  -   nUU-
  SU-  -   nX>UU4==   U2-  ss'   M     M     GM     GM&     GMe     GM|     g )N            r   g        g      ?)shaperangenpzerosall)3imageepsilonrvaluesindicesindptris_knownhwdsizewindow_areayixiikyjxjjcyxdcsdydxa00a01a02a11a12a22detinv_detm00m01m02m11m12m22dyidxituc0c1c2dyjdxjtempvalues3                                                      Z/home/wildlama/miniconda3/lib/python3.13/site-packages/pymatting/laplacian/cf_laplacian.py_cf_laplacianrD      sH   kkGA!6M6q519D+KAh(B!VAQUQY1$$ABQJQU
Q7QU
BQJN;BR!VAB{{qB{{%&
FA < 8 1q5M    	!a%!)QUQY*+A 1!e_qa%Avvhq1uq1uqy0!a%!a%!)2CCDEE Ah+B#DkU1r6A:q2vz2#=>> * &
  A	*B#AEAI.!!b&1*a"fqj""<=KO "b"* / +  CCCCCCDk+B1RQY<!BAI,66C1RQY<!BAI,66C1RQY<!BAI,66C1RQY<!BAI,66C1RQY<!BAI,66C1RQY<!BAI,66C & " ;C;C;C;C;C;C c	C)c/")c/" )c/" c'C-#%	&  CiG 9sSy(G3C9sSy(G3C9sSy(G3C9sSy(G3C9sSy(G3C9sSy(G3C QUQY' Q+C#sA+A#sA+A#sA+Aq37*S1W4Bq37*S1W4Bq37*S1W4B$QUQY/#(Q#3C!"S1B!"S1B!"S1B!"S1B "!VA "R!VA !#QsC{^ 3"$qc1~"5!6"$qc1~"5!6 ! ./!VS# !D +B, %,E "$b1q5B!#b1q5B"b"9-6-/ $4  0 , ( !     c           	      (   U R                   u  pEnXE-  nUc$  [        R                  " XE4[        R                  S9nUR	                  XE5      n[        R                  " US-   [        R
                  S9n[        R                  " USU-  S-   S-  -  [        R
                  S9n	[        R                  " USU-  S-   SU-  S-   4[        R                  S9n
[        XX*XU5        [        R                  R                  U
R                  5       X4Xw45      nU$ )a  
This function implements the alpha estimator for closed-form alpha matting
as proposed by :cite:`levin2007closed`.

Parameters
----------
image: numpy.ndarray
   Image with shape :math:`h\times w \times 3`
epsilon: float
   Regularization strength, defaults to :math:`10^{-7}`. Strong
   regularization improves convergence but results in smoother alpha mattes.
radius: int
   Radius of local window size, defaults to :math:`1`, i.e. only adjacent
   pixels are considered.
   The size of the local window is given as :math:`(2 r + 1)^2`, where
   :math:`r` denotes         the radius. A larger radius might lead to
   violated color line constraints, but also
   favors further propagation of information within the image.
is_known: numpy.ndarray
    Binary mask of pixels for which to compute the laplacian matrix.
    Laplacian entries for known pixels will have undefined values.

Returns
-------
L: scipy.sparse.spmatrix
    Matting Laplacian
)dtyper	   r
   r   )r   r   r   bool_reshapeint64float64rD   scipysparse
csr_matrixravel)r   r   radiusr   r   r   r   nr   r   r   Ls               rC   cf_laplacianrS      s    8 kkGA!	A88QF"((3%H XXa!e288,FhhqAJNq00AGXXq!f*q.!f*q.9LF%&'8L AA6JAHrE   )gHz>r	   N)numpyr   scipy.sparserL   numbar   rD   rS    rE   rC   <module>rX      s4      FdZ^_{7 `{7|-rE   