From d5819f664ab8bb14653915b4b5d99d5eb713359f Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Mon, 14 Dec 2015 17:11:11 +1100 Subject: [PATCH] Add tests for generic RAG construction --- skimage/future/graph/tests/test_rag.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/skimage/future/graph/tests/test_rag.py b/skimage/future/graph/tests/test_rag.py index 35c22218..e5882e20 100644 --- a/skimage/future/graph/tests/test_rag.py +++ b/skimage/future/graph/tests/test_rag.py @@ -178,3 +178,21 @@ def test_ncut_stable_subgraph(): new_labels, _, _ = segmentation.relabel_sequential(new_labels) assert new_labels.max() == 0 + + +def test_generic_rag_2d(): + labels = np.array([[1, 2], [3, 4]], dtype=np.uint8) + g = graph.RAG(labels) + assert g.has_edge(1, 2) and g.has_edge(2, 4) and not g.has_edge(1, 4) + h = graph.RAG(labels, connectivity=2) + assert h.has_edge(1, 2) and h.has_edge(1, 4) and h.has_edge(2, 3) + + +def test_generic_rag_3d(): + labels = np.arange(8, dtype=np.uint8).reshape((2, 2, 2)) + g = graph.RAG(labels) + assert g.has_edge(0, 1) and g.has_edge(1, 3) and not g.has_edge(0, 3) + h = graph.RAG(labels, connectivity=2) + assert h.has_edge(0, 1) and h.has_edge(0, 3) and not h.has_edge(0, 7) + k = graph.RAG(labels, connectivity=3) + assert k.has_edge(0, 1) and k.has_edge(1, 2) and k.has_edge(2, 5)