
    #
3j                      J    S SK Jr  S SKJr  S SK Jr  S SKJr  S SKr0 0 4S jr	g)    )sanity_check_image)lkm_laplacian)trimap_split)cgNc                   ^^^ [        U 5        [        U 40 UD6u  mn[        U5      u  pVpxSn	X-  mX-  n
SUT-   -  mUU4S jnU4S jn[        X4SU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 as described in Fast Matting Using Large Kernel Matting Laplacian Matrices by :cite:`he2010fast`.

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
laplacian_kwargs: dictionary
    Arguments passed to the :code:`lkm_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_lkm(
...     image,
...     trimap,
...     laplacian_kwargs={"epsilon": 1e-6, "radius": 15},
...     cg_kwargs={"maxiter":2000})

g      Y@g      ?c                     > T" U 5      TU -  -   $ N )xL_matveccs    \/home/wildlama/miniconda3/lib/python3.13/site-packages/pymatting/alpha/estimate_alpha_lkm.pyA_matvec$estimate_alpha_lkm.<locals>.A_matvec6   s    {QU""    c                    > TU -  $ r	   r
   )r   
inv_diag_As    r   jacobi"estimate_alpha_lkm.<locals>.jacobi9   s    A~r   Mr      )r   r   r   r   npclipreshapeshape)imagetrimaplaplacian_kwargs	cg_kwargsdiag_Lis_fgis_bgis_known
is_unknownlambda_valuebr   r   r   alphar   r   r   s                  @@@r   estimate_alpha_lkmr(      s    B u$U?.>?Hf)5f)=&E(LAA
#J# 	8.&.I.AGGAq!$$V\\2ELr   )
pymatting.util.utilr   !pymatting.laplacian.lkm_laplacianr   r   pymatting.solver.cgr   numpyr   r(   r
   r   r   <module>r-      s     2 ; , "  8:R 8r   