From 4deeb1f802bca6a849f1077a7371655cd296557f Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Mon, 14 Dec 2015 19:06:43 +1100 Subject: [PATCH] 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. --- skimage/future/graph/rag.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/skimage/future/graph/rag.py b/skimage/future/graph/rag.py index e97a2293..8710f9bd 100644 --- a/skimage/future/graph/rag.py +++ b/skimage/future/graph/rag.py @@ -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`.