o
    :Î®c.  ã                   @   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   sb   |du rt }t| ƒ tt| fi |¤Ž|ƒ\}}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   ÚnpÚclipÚreshapeÚshape)	ÚimageÚtrimapÚpreconditionerÚlaplacian_kwargsÚ	cg_kwargsÚAÚbÚxÚalpha© r   úJ/tmp/pip-target-vg8gfxp4/lib/python/pymatting/alpha/estimate_alpha_lbdm.pyÚestimate_alpha_lbdm	   s   $r   )Úpymatting.util.utilr   Úpymatting.laplacian.laplacianr   Ú"pymatting.laplacian.lbdm_laplacianr   Úpymatting.preconditioner.icholr   Úpymatting.solver.cgr   Únumpyr	   r   r   r   r   r   Ú<module>   s    ÿ