From 0e35c422b398f737f96264caa34e0543f60e3065 Mon Sep 17 00:00:00 2001 From: Vighnesh Birodkar Date: Sun, 22 Jun 2014 13:58:00 +0530 Subject: [PATCH] Graph can now merge non adjacent nodes --- skimage/graph/rag.py | 5 ----- skimage/graph/tests/test_rag.py | 12 ++++++------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/skimage/graph/rag.py b/skimage/graph/rag.py index 92f8c62e..8bcb06b9 100644 --- a/skimage/graph/rag.py +++ b/skimage/graph/rag.py @@ -28,10 +28,6 @@ class RAG(nx.Graph): Node to be merged. """ - - if not self.has_edge(i, j): - raise ValueError('Cant merge non adjacent nodes') - for x in self.neighbors(i): if x == j: continue @@ -41,7 +37,6 @@ class RAG(nx.Graph): w2 = self.get_edge_data(x, j)['weight'] w = max(w1, w2) - self.add_edge(x, j, weight=w) self.node[j]['labels'] += self.node[i]['labels'] diff --git a/skimage/graph/tests/test_rag.py b/skimage/graph/tests/test_rag.py index 6ac1c373..1225e774 100644 --- a/skimage/graph/tests/test_rag.py +++ b/skimage/graph/tests/test_rag.py @@ -11,13 +11,13 @@ def test_rag_merge(): for i in range(9): x = random.choice(g.nodes()) - y = random.choice(g.neighbors(x)) - g.merge_nodes(x, y) - - np.testing.assert_raises(ValueError, g.merge_nodes, 7, 9) - + y = random.choice(g.nodes()) + while x == y : + y = random.choice(g.nodes()) + g.merge_nodes(x,y) + idx = g.nodes()[0] - sorted(g.node[idx]['labels']) == range(10) + assert sorted(g.node[idx]['labels']) == range(10) assert g.edges() == []