Merge pull request #1903 from OrkoHunter/threshold_otsu_min_color

threshold_otsu can't work with one color images
This commit is contained in:
Juan Nunez-Iglesias
2016-01-26 10:05:09 +11:00
2 changed files with 14 additions and 1 deletions
+8 -1
View File
@@ -1,5 +1,7 @@
import numpy as np
from numpy.testing import assert_equal, assert_almost_equal
from numpy.testing import (assert_equal,
assert_almost_equal,
assert_raises)
import skimage
from skimage import data
@@ -162,6 +164,11 @@ def test_otsu_astro_image():
with expected_warnings(['grayscale']):
assert 109 < threshold_otsu(img) < 111
def test_otsu_one_color_image():
img = np.ones((10, 10), dtype=np.uint8)
assert_raises(TypeError, threshold_otsu, img)
def test_li_camera_image():
camera = skimage.img_as_ubyte(data.camera())
assert 63 < threshold_li(camera) < 65
+6
View File
@@ -129,6 +129,12 @@ def threshold_otsu(image, nbins=256):
"grayscale images; image shape {0} looks like an RGB image"
warnings.warn(msg.format(image.shape))
# Check if the image is multi-colored or not
if image.min() == image.max():
raise TypeError("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()))
hist, bin_centers = histogram(image.ravel(), nbins)
hist = hist.astype(float)