Borda / pyGCO

A python wrapper for gco-v3.0 package, used for graph cuts based MRF optimization.
http://vision.csd.uwo.ca/code
58 stars 18 forks source link

segmentation on rgb image #26

Open foreverzzx opened 1 year ago

foreverzzx commented 1 year ago

Thanks for your contribution. I wonder what is the input for unary_cost in function cut_grid_graph_simple while performing classfication on rgb image. I cannot understand the shape of unary_cost. Could you show me a example of segmentation on rgb image?


def cut_grid_graph_simple(unary_cost, pairwise_cost, n_iter=-1, connect=4, algorithm='expansion'):
    """
    Apply multi-label graphcuts to grid graph. This is a simplified version of
    cut_grid_graph, with all edge weights set to 1.
    Parameters
    ----------
    unary_cost: ndarray, int32, shape=(height, width, n_labels)
        Unary potentials
    pairwise_cost: ndarray, int32, shape=(n_labels, n_labels)
        Pairwise potentials for label compatibility
    connect: int, number of connected components - 4 or 8
    n_iter: int, (default=-1)
        Number of iterations.
        Set it to -1 will run the algorithm until convergence
    algorithm: string, `expansion` or `swap`, default=expansion
        Whether to perform alpha-expansion or alpha-beta-swaps.
    Note all the node indices start from 0.`
Borda commented 1 year ago

Hi, you can have a look at my PhD project: https://github.com/Borda/pyImSegm it is using superpixels, but you ll get the point of how to build the unary terms for multiple features either raw RGB values or any other quazi features :otter: