Example #1
0
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

       
Example #2
0
def getData():
  l = h5py.File("data/labels.h5", "r")
  labels = l["labels"].value
  labels = labels/labels.sum(axis=1)
  
  f = h5py.File('data/block00.h5', 'r')
  data = f['volume/data'].value
  
  d = h5py.File("data/ws.h5",'r')
  sp = d['ws'].value
  edges = adjGraph(sp, data, False)

  return data, sp, edges, labels
Example #3
0
def testAdjGraph():
  f = h5py.File("data/block00.h5", 'r') # load image data
  d = f["volume/data"].value
  ws = h5py.File("data/ws.h5", 'r') # load watershed segmentation / superpixels
  sp = ws["ws"].value
  
  edges, surfaces = adjGraph(sp, d.astype(np.float32), True) # compute region adjecency graph
  
  g = h5py.File("data/edges.h5", 'w')
  g.create_dataset("edges", data=edges)
  g.close()
  # e = h5py.File("data/edges.h5", 'r')
  # edges = e["edges"].value
  
  pickle.dump(surfaces, open("data/surfaces.p", "wb"))
Example #4
0
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
Example #5
0
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 29 14:00:29 2013

@author: mfk
"""

import numpy as np
import _adjGraph as gm
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt

test1 = np.zeros((3,3,3),dtype=np.uint32)
test1[:,:,0] = 1
result = gm.adjGraph(test1, test1.astype(np.float32), False)

points = result[1][0]
fig = plt.figure("EdgePoints", figsize=(10,10)) # create a figure
ax = fig.add_subplot(111, projection="3d") # create subplot 3d in figure
ax.scatter(points[:,0], points[:,1], points[:,2])
print result


# Test functions for the adjGraph-search algorithm #
test1 = np.zeros((3,3,3),dtype=np.uint32)
result = gm.adjGraph(test1, test1.astype(np.float32), True) # should return empty edges and #edges=0
print result

test1[:,:,0] = 1
result = gm.adjGraph(test1, test1.astype(np.float32), True)  # should return edge (0,1) and #edges=1
print result