From e74db662cbba56f8c192586ca4ac34d5e5330376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Thu, 21 Nov 2013 23:58:39 +0100 Subject: [PATCH] Add test case for *_boundaries functions --- skimage/segmentation/tests/test_boundaries.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 skimage/segmentation/tests/test_boundaries.py diff --git a/skimage/segmentation/tests/test_boundaries.py b/skimage/segmentation/tests/test_boundaries.py new file mode 100644 index 00000000..2fff52f8 --- /dev/null +++ b/skimage/segmentation/tests/test_boundaries.py @@ -0,0 +1,59 @@ +import numpy as np +from numpy.testing import assert_array_equal +from skimage.segmentation import find_boundaries, mark_boundaries + + +def test_find_boundaries(): + image = np.zeros((10, 10)) + image[2:7, 2:7] = 1 + + ref = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 1, 1, 1, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) + + result = find_boundaries(image) + assert_array_equal(result, ref) + + +def test_mark_boundaries(): + image = np.zeros((10, 10)) + label_image = np.zeros((10, 10)) + label_image[2:7, 2:7] = 1 + + ref = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 1, 1, 1, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) + result = mark_boundaries(image, label_image, color=(1, 1, 1)).mean(axis=2) + assert_array_equal(result, ref) + + ref = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 1, 1, 1, 1, 1, 2, 0], + [0, 0, 1, 2, 2, 2, 2, 1, 2, 0], + [0, 0, 1, 2, 0, 0, 0, 1, 2, 0], + [0, 0, 1, 2, 0, 0, 0, 1, 2, 0], + [0, 0, 1, 2, 0, 0, 0, 1, 2, 0], + [0, 0, 1, 1, 1, 1, 1, 2, 2, 0], + [0, 0, 2, 2, 2, 2, 2, 2, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) + result = mark_boundaries(image, label_image, color=(1, 1, 1), + outline_color=(2, 2, 2)).mean(axis=2) + assert_array_equal(result, ref) + + +if __name__ == "__main__": + np.testing.run_module_suite()