o
    :ήc
                     @   s6   d dl Zd dlmZmZmZ d dlmZ d	ddZdS )
    N)vec_vec_dotmat_vec_dotvec_vec_outer)	boxfilterHz>
   Tc                    sB   tjd d }|| }j\}tdd| }ttdd| }|t||8 }tj||| t|  |  t	 |d| t
| ttd  d  fdd fdd}	|rtd dd}
dtdd }|t	t dd8 }|
t
|7 }
|	|
 fS |	S )	a  Calculates the Laplacian for large kernel matting :cite:`he2010fast`

    Parameters
    ---------
    image: numpy.ndarray
        Image of shape :math:`h\times w \times 3`
    epsilons: float
        Regularization strength, defaults to :math:`10^{-7}`
    radius: int
        Radius of local window size, defaults to :math:`10`, i.e. only adjacent pixels are considered. The size of the local window is given as :math:`(2 r + 1)^2`, where :math:`r` denotes the radius. A larger radius might lead to violated color line constraints, but also favors further propagation of information within the image.
    return_diagonal: bool
        Whether to also return the diagonal of the laplacian, defaults to True

    Returns
    -------
    L_matvec: function
        Function that applies the Laplacian matrix to a vector
    diag_L: numpy.ndarray
        Diagonal entries of the matting Laplacian, only returnes if `return_diagonal` is True
          validmodefullc                    s   |  } t| dd}t| d d d d tjf  dd}|  }|d d d d tjf  t | }|tt|dd7 }| t| }|t|dd8 }| S )Nr
   r   r   )reshaper   npnewaxisr   r   flatten)pp_sumspI_sumsp_LtempVVmchimagemVmradiusw H/tmp/pip-target-vg8gfxp4/lib/python/pymatting/laplacian/lkm_laplacian.pyL_matvec.   s   &&zlkm_laplacian.<locals>.L_matvecg      ?)astyper   float64shaper   r   linalginveyer   r   onesr   )r   epsilonr   return_diagonalwindow_sizewindow_areadepthmeanscovsr"   diag_Lr   r    r   r!   lkm_laplacian   s&   "
(r2   )r   r   T)	numpyr   pymatting.util.utilr   r   r   pymatting.util.boxfilterr   r2   r    r    r    r!   <module>   s    