Move max_id logic to top of RAG constructor

max_id is used during RAG building iteration, resulting in an error if
it is not defined ahead of the generic_filter stage.
This commit is contained in:
Juan Nunez-Iglesias
2015-12-14 19:06:43 +11:00
parent 53d3154f09
commit 4deeb1f802
+4 -6
View File
@@ -98,6 +98,10 @@ class RAG(nx.Graph):
def __init__(self, label_image=None, connectivity=1, data=None, **attr):
super(RAG, self).__init__(data, **attr)
if self.number_of_nodes() == 0:
self.max_id = 0
else:
self.max_id = max(self.nodes_iter())
if label_image is not None:
# The footprint is constructed such that the first
@@ -130,12 +134,6 @@ class RAG(nx.Graph):
strides=((0,) * label_image.ndim)),
extra_arguments=(self,))
try:
self.max_id = max(self.nodes_iter())
except ValueError:
# Empty sequence
self.max_id = 0
def merge_nodes(self, src, dst, weight_func=min_weight, in_place=True,
extra_arguments=[], extra_keywords={}):
"""Merge node `src` and `dst`.