From 8b6460b06eb333af9de44330b65fb6308e453f28 Mon Sep 17 00:00:00 2001 From: Martin Zackrisson Date: Mon, 30 May 2016 11:13:58 +0200 Subject: [PATCH 1/5] Correcting the Error raised for Otsu Threshold The previous error, `TypeError` did not reflect the test done and would typically be raised while `image` indeed had the correct type. --- skimage/filters/thresholding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/filters/thresholding.py b/skimage/filters/thresholding.py index 331ea3f4..d21bd579 100644 --- a/skimage/filters/thresholding.py +++ b/skimage/filters/thresholding.py @@ -133,7 +133,7 @@ def threshold_otsu(image, nbins=256): # Check if the image is multi-colored or not if image.min() == image.max(): - raise TypeError("threshold_otsu is expected to work with images " \ + raise ValueError("threshold_otsu is expected to work with images " \ "having more than one color. The input image seems " \ "to have just one color {0}.".format(image.min())) From e167be511d7a2f2ae481952e9db2248cfdf1b685 Mon Sep 17 00:00:00 2001 From: Martin Zackrisson Date: Mon, 30 May 2016 11:25:55 +0200 Subject: [PATCH 2/5] Corrected indentation to follow PEP8 --- skimage/filters/thresholding.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/filters/thresholding.py b/skimage/filters/thresholding.py index d21bd579..285af6d4 100644 --- a/skimage/filters/thresholding.py +++ b/skimage/filters/thresholding.py @@ -134,8 +134,8 @@ def threshold_otsu(image, nbins=256): # Check if the image is multi-colored or not if image.min() == image.max(): raise ValueError("threshold_otsu is expected to work with images " \ - "having more than one color. The input image seems " \ - "to have just one color {0}.".format(image.min())) + "having more than one color. The input image seems " \ + "to have just one color {0}.".format(image.min())) hist, bin_centers = histogram(image.ravel(), nbins) hist = hist.astype(float) From f4123a4e36c7a82061f6024c61245aa9ef144950 Mon Sep 17 00:00:00 2001 From: Martin Zackrisson Date: Mon, 30 May 2016 11:29:35 +0200 Subject: [PATCH 3/5] Added missing documentation about raised error --- skimage/filters/thresholding.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/skimage/filters/thresholding.py b/skimage/filters/thresholding.py index 285af6d4..ccd88be4 100644 --- a/skimage/filters/thresholding.py +++ b/skimage/filters/thresholding.py @@ -110,6 +110,12 @@ def threshold_otsu(image, nbins=256): threshold : float Upper threshold value. All pixels intensities that less or equal of this value assumed as foreground. + + Raises + ------ + + ValueError + If `image` only contains a single grayscale value. References ---------- From 9174110faa39807d4dd5bb715a530b5a0dd5af48 Mon Sep 17 00:00:00 2001 From: Martin Zackrisson Date: Mon, 30 May 2016 13:36:47 +0200 Subject: [PATCH 4/5] Removed empty line from docstring --- skimage/filters/thresholding.py | 1 - 1 file changed, 1 deletion(-) diff --git a/skimage/filters/thresholding.py b/skimage/filters/thresholding.py index ccd88be4..2f9023d6 100644 --- a/skimage/filters/thresholding.py +++ b/skimage/filters/thresholding.py @@ -113,7 +113,6 @@ def threshold_otsu(image, nbins=256): Raises ------ - ValueError If `image` only contains a single grayscale value. From 1d7c4fd535d27c69bb4106bf962c2805362e1ac8 Mon Sep 17 00:00:00 2001 From: Martin Zackrisson Date: Mon, 30 May 2016 13:38:55 +0200 Subject: [PATCH 5/5] Corrected Otsu test error raising assertion --- skimage/filters/tests/test_thresholding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/filters/tests/test_thresholding.py b/skimage/filters/tests/test_thresholding.py index 03557caf..c5d583b2 100644 --- a/skimage/filters/tests/test_thresholding.py +++ b/skimage/filters/tests/test_thresholding.py @@ -167,7 +167,7 @@ def test_otsu_astro_image(): def test_otsu_one_color_image(): img = np.ones((10, 10), dtype=np.uint8) - assert_raises(TypeError, threshold_otsu, img) + assert_raises(ValueError, threshold_otsu, img) def test_li_camera_image(): camera = skimage.img_as_ubyte(data.camera())