+
    Ai                     F    ^ RI t^ RIt^ RIHt ^ RIHt ^^
.RR.R3R ltR# )    N)knn)normalize_rowsg       @g?binaryc           
        V P                   R,          w  rEV P                  R	^4      P                  w  rgpWT,          p	VR
9  d   \        RV,           R,           4      h\        P
                  ! \        P                  ! ^ ^V4      V4      p
\        P                  ! \        P                  ! ^ ^V4      V4      p. . . rp\        W4       EF^  w  pp\        P                  ! WgVVV
,          VV,          .^\        P                  ! V	^3\        P                  R7      R7      p\        VVVR7      w  ppVP                  \        P                  ! \        P                  ! V	4      V4      4       VP                  VP                  4       4       \        P                   ! W,          4      pVR8X  di   V\        P"                  ! VVR	,          ,          VVR	,          ,          ,
          4      P%                  ^R7      VP                   ^,          ,          ,          pVP                  V4       EKa  	  \        P&                  ! W,           4      p\        P&                  ! W,           4      p\        P&                  ! W,           4      p\(        P*                  P-                  VVV33W34      p\/        V4      p\(        P*                  P1                  V	4      pVV,
          pV# )a  
This function calculates the KNN matting Laplacian matrix similar to
:cite:`chen2013knn`.
We use a kernel of 1 instead of a soft kernel by default since the former is
faster to compute and both produce almost identical results in all our
experiments, which is to be expected as the soft kernel is very close to 1
in most cases.

Parameters
----------
image: numpy.ndarray
    Image with shape :math:`h\times w \times 3`
n_neighbors: list of ints
    Number of neighbors to consider. If :code:`len(n_neighbors)>1` multiple
    nearest neighbor calculations are done and merged, defaults to
    `[20, 10]`, i.e. first 20 neighbors are considered and in the second run
    :math:`10` neighbors. The pixel distances are then weighted by the
    :code:`distance_weights`.
distance_weights: list of floats
    Weight of distance in feature vector, defaults to `[2.0, 0.1]`.
kernel: str
    Must be either "binary" or "soft". Default is "binary".

Returns
-------
L: scipy.sparse.spmatrix
    Matting Laplacian matrix
:N   Nsoftz$kernel must be binary/soft, but not .)dtype)axisout)k)r   )r   r   )shapereshapeT
ValueErrornptilelinspacerepeatzipstackzerosfloat32r   appendarangeravelonesabssumconcatenatescipysparse
csr_matrixr   identity)imagen_neighborsdistance_weightskernelhwrgbnxyijcoo_datar   distance_weightf_neighbor_indicesW_ijijjiWILs   &&&&                      _/var/www/html/photoedit/myenv/lib/python3.14/site-packages/pymatting/laplacian/knn_laplacian.pyknn_laplacianr@      s!   D ;;r?DAmmB"$$GA!	A''?&H3NOO
Aq!$a(A
		"++aA&*A R(A!+@?HH1o)?Q+>?!Qrzz2
 "!Q!n 	
299Q<+,	!'')*wwqu~VBFF1QrU8a"h./333;aggajHHD) A2 
	B		B~~h12H 	B8 4qf=AqAa A	AAH    )	numpyr   scipy.sparser"   pymatting.util.kdtreer   pymatting.util.utilr   r@    rA   r?   <module>rG      s*      % .
 R3Z	UrA   