ó
    #
3jc  ã                   óV   • S SK Jr  S SKJr  S SKJr  S SKrS SKr	SS/ SQSSS0 0 4S jr
g)	é    )Úichol)Úsparse_conv_matrix_with_offsets)ÚcgNgñhãˆµøä>))éÿÿÿÿr   )é   r   )r   r   )r   r   Fc
                 ó²  • U R                   u  p«nUR                   X«4:X  d   eXº-  nUR                  5       nSnU H“  u  nn[        XºSS/SU/SU/5      nUR                  R	                  [
        R                  R                  U[        R                  " UR	                  U5      5      -   5      5      R	                  U5      nUc  UOUU-   nAAM•     [
        R                  R                  US/SU//5      nA[
        R                  R                  [
        R                  R                  U5      [
        R                  R                  SU-
  5      //5      nUR                  R	                  U5      U-   nUR                  5         A[        U40 UD6nUc  U OUR                  5       nUc  U OUR                  5       n[        U5       HÑ  nU SS2SS2U4   R                  5       nUR                  R	                  U5      nUSS2SS2U4   R                  5       nUSS2SS2U4   R                  5       n[        R                  " UU/5      n[!        UU4UUUS.U	D6nUSU R#                  X«5      USS2SS2U4'   UUS R#                  X«5      USS2SS2U4'   MÓ     [        R$                  " USS5      n[        R$                  " USS5      nU(       a  UU4$ U$ )a+  Estimates the foreground of an image given alpha matte and image.

This method is based on the publication :cite:`levin2007closed`.

Parameters
----------
image: numpy.ndarray
    Input image with shape :math:`h \times  w \times d`
alpha: numpy.ndarray
    Input alpha matte with shape :math:`h \times  w`
regularization: float
    Regularization strength :math:`\epsilon`, defaults to :math:`10^{-5}`
neighbors: list of tuples of ints
    List of relative positions that define the neighborhood of a pixel
return_background: bool
    Whether to return the estimated background in addition to the foreground
foreground_guess: numpy.ndarray
    An initial guess for the foreground image in order to accelerate convergence.
    Using input image by default.
background_guess: numpy.ndarray
    An initial guess for the background image.
    Using input image by default.
ichol_kwargs: dictionary
    Keyword arguments for the incomplete Cholesky preconditioner
cg_kwargs: dictionary
    Keyword arguments for the conjugate gradient descent solver

Returns
-------
F: numpy.ndarray
    Extracted foreground
B: numpy.ndarray
    Extracted background (not returned by default)

Example
-------
>>> from pymatting import *
>>> image = load_image("data/lemur/lemur.png", "RGB")
>>> alpha = load_image("data/lemur/lemur_alpha.png", "GRAY")
>>> F = estimate_foreground_cf(image, alpha, return_background=False)
>>> F, B = estimate_foreground_cf(image, alpha, return_background=True)


See Also
--------
stack_images: This function can be used to place the foreground on a new background.
Ng      ð?g      ð¿r   r   )Úx0ÚMÚrtol)ÚshapeÚflattenr   ÚTÚdotÚscipyÚsparseÚdiagsÚnpÚabsÚbmatÚsum_duplicatesr   ÚcopyÚrangeÚconcatenater   ÚreshapeÚclip) ÚimageÚalphaÚregularizationr   Ú	neighborsÚreturn_backgroundÚforeground_guessÚbackground_guessÚichol_kwargsÚ	cg_kwargsÚhÚwÚdÚnÚaÚSÚdxÚdyÚDÚS2ÚVÚUÚAÚpreconditionÚ
foregroundÚ
backgroundÚchannelÚimage_channelÚbÚf0Úb0Úfbs                                    Úe/home/wildlama/miniconda3/lib/python3.13/site-packages/pymatting/foreground/estimate_foreground_cf.pyÚestimate_foreground_cfr<      sš  € ðv k‰kG€Aˆ!à;‰;˜1˜&Ó Ð Ð à	‰€Aà‰‹€Aà€AÛ‰ˆˆBä+¨A°3¸°+ÀÀ2¸wÈÈBÈÓPˆàS‰SW‰W”U—\‘\×'Ñ'¨¼¿ºÀÇÁÀaÃÓ9IÑ(IÓJÓK×OÑOÐPQÓRˆà‘)‰B  R¡ˆàŠrñ ô 	‰×Ñ˜A˜t˜9 t¨Q iÐ0Ó1€Aà	ä‰×ÑœEŸL™L×.Ñ.¨qÓ1´5·<±<×3EÑ3EÀaÈ!ÁeÓ3LÐMÐNÓO€Aà	‰‰‹
Q‰€Aà×ÑÔà	ô ˜Ñ+˜lÑ+€Lð ,Ñ3‘%Ð9I×OÑOÓQ€JØ+Ñ3‘%Ð9I×OÑOÓQ€Jô ˜–8ˆØša¢ G˜mÑ,×4Ñ4Ó6ˆàC‰CG‰GMÓ"ˆð šš1˜g˜Ñ&×.Ñ.Ó0ˆØšš1˜g˜Ñ&×.Ñ.Ó0ˆÜ^Š^˜R ˜HÓ%ˆô
 1ÐD˜˜|°$ÑD¸)ÑDˆà$& r¨ F§N¡N°1Ó$8ˆ
’1’a˜=Ñ!Ø$& q r F§N¡N°1Ó$8ˆ
’1’a˜=Ó!ñ! ô$ —’˜ Q¨Ó*€JÜ—’˜ Q¨Ó*€JæØ˜:Ð%Ð%àÐó    )Úpymatting.preconditioner.icholr   Úpymatting.util.utilr   Úpymatting.solver.cgr   Úscipy.sparser   Únumpyr   r<   © r=   r;   Ú<module>rD      s4   ðÝ 0Ý ?Ý "Û Û ð Ø	Ú0ØØØØØõzr=   