
    #
3j@                     X    S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
rS0 0 4S jrg)    )sanity_check_image)make_linear_system)knn_laplacian)jacobi)cgNc                     Uc  [         n[        U 5        [        [        U 40 UD6U5      u  pV[	        XV4SU" U5      0UD6n[
        R                  " USS5      R                  UR                  5      nU$ )a  
Estimate alpha from an input image and an input trimap using KNN Matting similar to :cite:`chen2013knn`.
See `knn_laplacian` for more details.

Parameters
----------
image: numpy.ndarray
    Image with shape :math:`h \times  w \times d` for which the alpha matte should be estimated
trimap: numpy.ndarray
    Trimap with shape :math:`h \times  w` of the image
preconditioner: function or scipy.sparse.linalg.LinearOperator
    Function or sparse matrix that applies the preconditioner to a vector (default: jacobi)
laplacian_kwargs: dictionary
    Arguments passed to the :code:`knn_laplacian` function
cg_kwargs: dictionary
    Arguments passed to the :code:`cg` solver

Returns
-------
alpha: numpy.ndarray
    Estimated alpha matte

Example
-------
>>> from pymatting import *
>>> image = load_image("data/lemur/lemur.png", "RGB")
>>> trimap = load_image("data/lemur/lemur_trimap.png", "GRAY")
>>> alpha = estimate_alpha_knn(
...     image,
...     trimap,
...     laplacian_kwargs={"n_neighbors": [15, 10]},
...     cg_kwargs={"maxiter":2000})
Mr      )	r   r   r   r   r   npclipreshapeshape)	imagetrimappreconditionerlaplacian_kwargs	cg_kwargsAbxalphas	            \/home/wildlama/miniconda3/lib/python3.13/site-packages/pymatting/alpha/estimate_alpha_knn.pyestimate_alpha_knnr   	   sp    H umEF5EFODA
12>!$2	2AGGAq!$$V\\2EL    )pymatting.util.utilr   pymatting.laplacian.laplacianr   !pymatting.laplacian.knn_laplacianr   pymatting.preconditioner.jacobir   pymatting.solver.cgr   numpyr   r    r   r   <module>r"      s%    2 < ; 2 "  #'r/r   