diff --git a/doc/examples/plot_rag_merge.py b/doc/examples/plot_rag_merge.py index 0f8ca1cb..d454a096 100644 --- a/doc/examples/plot_rag_merge.py +++ b/doc/examples/plot_rag_merge.py @@ -61,8 +61,10 @@ img = data.coffee() labels = segmentation.slic(img, compactness=30, n_segments=400) g = graph.rag_mean_color(img, labels) -labels2 = graph.merge_hierarchical(labels, g, 40, False, True, - merge_mean_color, _weight_mean_color) +labels2 = graph.merge_hierarchical(labels, g, thresh=40, rag_copy=False, + in_place_merge=True, + merge_func=merge_mean_color, + weight_func=_weight_mean_color) g2 = graph.rag_mean_color(img, labels2) diff --git a/skimage/graph/tests/test_rag.py b/skimage/graph/tests/test_rag.py index df78ed7d..ca21b27c 100644 --- a/skimage/graph/tests/test_rag.py +++ b/skimage/graph/tests/test_rag.py @@ -135,7 +135,7 @@ def test_rag_hierarchical(): img = np.zeros((8, 8, 3), dtype='uint8') labels = np.zeros((8, 8), dtype='uint8') - img[:, :, :] = 30 + img[:, :, :] = 31 labels[:, :] = 1 img[0:4, 0:4, :] = 10, 10, 10 @@ -146,14 +146,18 @@ def test_rag_hierarchical(): g = graph.rag_mean_color(img, labels) g2 = g.copy() - thresh = 17.3206 # just above 10*sqrt(3) + thresh = 20 # more than 11*sqrt(3) result = merge_hierarchical_mean_color(labels, g, thresh) - assert len(np.unique(result)) == 2 + assert(np.all(result[0:4, 0:4] == result[0, 0])) + assert(np.all(result[4:, 0:4] == result[4, 0])) + assert(np.all(result[:, 4:] == result[-1, -1])) result = merge_hierarchical_mean_color(labels, g2, thresh, in_place_merge=True) - assert len(np.unique(result)) == 2 + assert(np.all(result[0:4, 0:4] == result[0, 0])) + assert(np.all(result[4:, 0:4] == result[4, 0])) + assert(np.all(result[:, 4:] == result[-1, -1])) result = graph.cut_threshold(labels, g, thresh) - assert len(np.unique(result)) == 1 + assert np.all(result == result[0, 0])