
    <YId                     :    d dl Zd dlZd dlmZ ddlmZ d Zd Z	dS )    N)sparse   )_ncut_cyc                     t          j        | d          }|                    d          }t          j        |df|j                                                  }||fS )a  Returns the diagonal and weight matrices of a graph.

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

    Returns
    -------
    D : csc_matrix
        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_matrix
        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_matrixr
   tocsc)graphWentriesDs       3lib/python3.11/site-packages/skimage/graph/_ncut.pyDW_matricesr      sZ    $ 	 u555AeeemmG7A,ag666<<>>Aa4K    c                     t          j        |           } t          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_matrix
        The diagonal matrix of the graph.
    W : csc_matrix
        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.
    )nparrayr   cut_costdatar   )cutr   r   r   assoc_aassoc_bs         r   	ncut_costr       sh    0 (3--C a((H fSkooGfcTl  Gw8g#566r   )
networkxr   numpyr   scipyr    r   r   r    r   r   <module>r%      si                         2 7  7  7  7  7r   