mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-16 11:21:25 +08:00
Graph can now merge non adjacent nodes
This commit is contained in:
@@ -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']
|
||||
|
||||
@@ -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() == []
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user