diff --git a/doc/examples/plot_rag_merge.py b/doc/examples/plot_rag_merge.py index ac7eab7f..00236d95 100644 --- a/doc/examples/plot_rag_merge.py +++ b/doc/examples/plot_rag_merge.py @@ -4,9 +4,9 @@ RAG Merging =========== This example constructs a Region Adjacency Graph (RAG) and progressively merges -regions which are similar in color. Merging two adjacent regions produces +regions that are similar in color. Merging two adjacent regions produces a new regions with all the pixels from the merged regions. Regions are merged -till no two adjacent regions are similar enough. +until no highly similar regions remain. """ diff --git a/skimage/graph/graph_merge.py b/skimage/graph/graph_merge.py index 69aa94f1..59a623a5 100644 --- a/skimage/graph/graph_merge.py +++ b/skimage/graph/graph_merge.py @@ -38,8 +38,9 @@ def merge_hierarchical(labels, rag, thresh): rag : RAG The Region Adjacency Graph. thresh : float - The threshold. Nodes are merged until the minimum edge weight in the - graph exceeds `thresh`. + The threshold. Regions connected by an edges with smaller wegiht than + `thresh` are merged. A high value of `thresh` would mean that a lot of + regions are merged, and the output will contain fewer regions. Returns ------- @@ -71,11 +72,9 @@ def merge_hierarchical(labels, rag, thresh): rag.merge_nodes(x, y, _hmerge) - count = 0 arr = np.arange(labels.max() + 1) - for n, d in rag.nodes_iter(data=True): - for l in d['labels']: - arr[l] = count - count += 1 + for ix, (n, d) in enumerate(rag.nodes_iter(data=True)): + for label in d['labels']: + arr[label] = ix return arr[labels]