From 4b53c92c141f73d7fedd2555db28fe98b3149c31 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 20 Jul 2012 16:34:07 -0400 Subject: [PATCH 1/2] BUG: Fix OTSU thresholding tests with matplotlib IO plugin. The matplotlib IO returns float arrays from [0, 1], which gives difference results than a ubyte array. Explicitly convert to a ubyte array in the tests. --- skimage/filter/tests/test_thresholding.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/skimage/filter/tests/test_thresholding.py b/skimage/filter/tests/test_thresholding.py index 59d7e431..8278fa6f 100644 --- a/skimage/filter/tests/test_thresholding.py +++ b/skimage/filter/tests/test_thresholding.py @@ -73,11 +73,13 @@ class TestSimpleImage(): def test_otsu_camera_image(): - assert threshold_otsu(data.camera()) == 87 + camera = skimage.img_as_ubyte(data.camera()) + assert threshold_otsu(camera) == 87 def test_otsu_coins_image(): - assert threshold_otsu(data.coins()) == 107 + coins = skimage.img_as_ubyte(data.coins()) + assert threshold_otsu(coins) == 107 def test_otsu_coins_image_as_float(): @@ -86,7 +88,8 @@ def test_otsu_coins_image_as_float(): def test_otsu_lena_image(): - assert threshold_otsu(data.lena()) == 141 + lena = skimage.img_as_ubyte(data.lena()) + assert threshold_otsu(lena) == 141 if __name__ == '__main__': From 67eb914ef6d8468ed7333c3ab31017be7457dd83 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 20 Jul 2012 19:09:05 -0400 Subject: [PATCH 2/2] TST: Add buffer for threshold tests. In case conversion from float to integer is imprecise. --- skimage/filter/tests/test_thresholding.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skimage/filter/tests/test_thresholding.py b/skimage/filter/tests/test_thresholding.py index 8278fa6f..97d3d9e3 100644 --- a/skimage/filter/tests/test_thresholding.py +++ b/skimage/filter/tests/test_thresholding.py @@ -74,12 +74,12 @@ class TestSimpleImage(): def test_otsu_camera_image(): camera = skimage.img_as_ubyte(data.camera()) - assert threshold_otsu(camera) == 87 + assert 86 < threshold_otsu(camera) < 88 def test_otsu_coins_image(): coins = skimage.img_as_ubyte(data.coins()) - assert threshold_otsu(coins) == 107 + assert 106 < threshold_otsu(coins) < 108 def test_otsu_coins_image_as_float(): @@ -89,7 +89,7 @@ def test_otsu_coins_image_as_float(): def test_otsu_lena_image(): lena = skimage.img_as_ubyte(data.lena()) - assert threshold_otsu(lena) == 141 + assert 140 < threshold_otsu(lena) < 142 if __name__ == '__main__':