Corrected new id logic

This commit is contained in:
Vighnesh Birodkar
2014-10-04 22:33:10 +05:30
parent febef86bbb
commit 3a9df73590
2 changed files with 9 additions and 5 deletions
+5 -1
View File
@@ -15,6 +15,7 @@ from scipy.ndimage import filters
from scipy import ndimage as nd
import math
from .. import draw, measure, segmentation, util, color
import random
try:
from matplotlib import colors
from matplotlib import cm
@@ -96,7 +97,10 @@ class RAG(nx.Graph):
dst_nbrs = set(self.neighbors(dst))
neighbors = (src_nbrs & dst_nbrs) - set([src, dst])
if not in_place:
new = self.number_of_nodes() + 1
# Randomly select an id
new = random.randint(1, 99999999)
while new in self:
new = random.randint(1, 99999999)
self.add_node(new)
for neighbor in neighbors:
+4 -4
View File
@@ -41,10 +41,10 @@ def test_rag_merge():
assert gc.edge[1][2]['weight'] == 20
assert gc.edge[2][3]['weight'] == 40
g.merge_nodes(1, 4, in_place=True)
g.merge_nodes(2, 3, in_place=True)
g.merge_nodes(3, 4)
assert sorted(g.node[4]['labels']) == list(range(5))
g.merge_nodes(1, 4)
g.merge_nodes(2, 3)
n = g.merge_nodes(3, 4, in_place=False)
assert sorted(g.node[n]['labels']) == list(range(5))
assert g.edges() == []