From 53077c9f227dac53a93edd50176ea2e6ce44ab3d Mon Sep 17 00:00:00 2001 From: Vighnesh Birodkar Date: Mon, 16 Jun 2014 03:30:01 +0530 Subject: [PATCH] Added edge threshold cut --- skimage/graph/graph_cut.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 skimage/graph/graph_cut.py diff --git a/skimage/graph/graph_cut.py b/skimage/graph/graph_cut.py new file mode 100644 index 00000000..bf55db84 --- /dev/null +++ b/skimage/graph/graph_cut.py @@ -0,0 +1,25 @@ +import networkx as nx +import numpy as np + +def threshold_cut(label, rag, thresh): + + #print [rag.edges_iter(data = True)] + to_remove = [(x,y) for x,y,d in rag.edges_iter(data = True) if d['weight'] >= thresh] + print "edges to remove",len(to_remove) + + rag.remove_edges_from(to_remove) + + + comps = nx.connected_components(rag) + out = np.copy(label) + print "comps",len(comps) + + for i, nodes in enumerate(comps) : + + for node in nodes : + for l in rag.node[node]['labels'] : + out[label == l] = i + + #print out + #print label + return out