Ë
    ÿ[;ja  ã                   ó8   — d dl Zd dlZd dlmZ ddlmZ d„ Zd„ Z	y)é    N)Úsparseé   )Ú_ncut_cyc                 ó¾   — t        j                  | d¬«      }|j                  d¬«      }t        j                  |df|j
                  ¬«      j                  «       }||fS )a¾  Returns the diagonal and weight matrices of a graph.

    Parameters
    ----------
    graph : RAG
        A Region Adjacency Graph.

    Returns
    -------
    D : csc_array
        The diagonal matrix of the graph. ``D[i, i]`` is the sum of weights of
        all edges incident on `i`. All other entries are `0`.
    W : csc_array
        The weight matrix of the graph. ``W[i, j]`` is the weight of the edge
        joining `i` to `j`.
    Úcsc)Úformatr   )Úaxis)Úshape)ÚnxÚto_scipy_sparse_arrayÚsumr   Ú	dia_arrayr
   Útocsc)ÚgraphÚWÚentriesÚDs       ú\G:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\skimage/graph/_ncut.pyÚDW_matricesr      sQ   € ô$ 	× Ñ  ¨uÔ5€AØ�e‰e˜ˆe‹m€GÜ×Ñ˜' 1˜¨Q¯W©WÔ5×;Ñ;Ó=€Aàˆaˆ4€Kó    c                 óB  — t        j                  | «      } t        j                  | |j                  |j
                  |j                  |j                  d   ¬«      }|j                  |    j                  «       }|j                  |     j                  «       }||z  ||z  z   S )a|  Returns the N-cut cost of a bi-partition of a graph.

    Parameters
    ----------
    cut : ndarray
        The mask for the nodes in the graph. Nodes corresponding to a `True`
        value are in one set.
    D : csc_array
        The diagonal matrix of the graph.
    W : csc_array
        The weight matrix of the graph.

    Returns
    -------
    cost : float
        The cost of performing the N-cut.

    References
    ----------
    .. [1] Normalized Cuts and Image Segmentation, Jianbo Shi and
           Jitendra Malik, IEEE Transactions on Pattern Analysis and Machine
           Intelligence, Page 889, Equation 2.
    r   )Únum_cols)	ÚnpÚarrayr   Úcut_costÚdataÚindicesÚindptrr
   r   )Úcutr   r   r   Úassoc_aÚassoc_bs         r   Ú	ncut_costr"       s�   € ô0 �(‰(�3‹-€CÜ× Ñ   a§f¡f¨a¯i©i¸¿¹ÈAÏGÉGÐTUÉJÔW€Hð �f‰f�S‰k�o‰oÓ€GØ�f‰f�c�T‰l×ÑÓ €Gà�wÑ 8¨gÑ#5Ñ6Ð6r   )
Únetworkxr   Únumpyr   Úscipyr   Ú r   r   r"   © r   r   Ú<module>r(      s   ðÛ Û Ý Ý òó2 7r   