U
    !?h.                     @   sX   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
Zdi i fddZdS )	    )sanity_check_image)make_linear_system)lbdm_laplacian)ichol)cgNc           	      C   s^   |dkrt }t|  tt| f||\}}t||fd||i|}t|dd|j}|S )az  
    Estimate alpha from an input image and an input trimap using Learning Based Digital Matting as proposed by :cite:`zheng2009learning`.

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

    NMr      )	r   r   r   r   r   npZclipZreshapeshape)	imageZtrimapZpreconditionerZlaplacian_kwargsZ	cg_kwargsAbxalpha r   U/var/www/html/venv/lib/python3.8/site-packages/pymatting/alpha/estimate_alpha_lbdm.pyestimate_alpha_lbdm	   s    $r   )Zpymatting.util.utilr   Zpymatting.laplacian.laplacianr   Z"pymatting.laplacian.lbdm_laplacianr   Zpymatting.preconditioner.icholr   Zpymatting.solver.cgr   numpyr	   r   r   r   r   r   <module>   s     