def MRF_modelling(superpixels, labels, unaries, data, p=0.2): edges, surfaces = adjGraph(superpixels, data, False) # p : smoothing parameter # Labels : is supposed to be an array: length = #SP, width= #Labels with the probaility for each label and each SP nLabels = labels.shape[1] # The width of the labels array is the number of different labels nVariables = superpixels.max() # The max number of the sp ID is the total number of SPs nEdges = edges.shape[0] # Number of edges = lenght of edges-array edgeVis = edges[:,0:2] # Vertice-Tuples in Edges list unaryValues= labels sameLabel = np.zeros((nVariables,1)) diffLabel = np.ones((nVariables,1)) * p edgeValues = np.concatenate((sameLabel, diffLabel), axis=1) gm = getGraphicalModel( nLabels = nLabels, nVariables = nVariables, nEdges = nEdges, edgeVis = edgeVis, unaryValues = unaryValues, edgeValues = edgeValues, gmOperator = 'adder') gm return gm
def MRF_modelling(superpixels, labels, edges, data, p=0.2): # p : smoothing parameter # Labels : is supposed to be an array: length = #SP, width= #Labels with the probaility for each label and each SP labels = l["labels"].value import pdb pdb.set_trace() labels = labels/labels.sum(axis=1) nVariables = superpixels.max() sameLabel = np.zeros((nVariables,1)) diffLabel = np.ones((nVariables,1)) * p edgeValues = np.concatenate((sameLabel, diffLabel), axis=1) gm = getGraphicalModel( nLabels = labels.shape[1], # The width of the labels array is the number of different labels nVariables = superpixels.max(), # The max number of the sp ID is the total number of SPs nEdges = edges.shape[0], # Number of edges = lenght of edges-array edgeVis = edges[:,0:2], # Vertice-Tuples in Edges list unaryValues = labels, edgeValues = edgeValues, gmOperator = 'adder') infer = opengm.inference.AlphaBetaSwap(gm) infer.infer() result = infer.arg() return result
def MRF_modelling(superpixels, labels, unaries, data): edges, surfaces = adjGraph(superpixels, data) nLabels = labels.shape[0]################################################# nVariables = superpixels.max()############################################### nEdges = edges.shape[0] edgeVis = edges[:,0:2] unaryValues= unaries######################################################### edgeValues = binaryClassifier(edges)######################################### gm = getGraphicalModel( nLabels = nLabels, nVariables = nVariables, nEdges = nEdges, edgeVis = edgeVis, unaryValues = unaryValues, edgeValues = edgeValues, gmOperator = 'adder') gm return gm