Skip to content

Commit

Permalink
Merge pull request #2118 from local-minimum/patch-1
Browse files Browse the repository at this point in the history
Fixing Error and documentation on Otsu Threshold
  • Loading branch information
jni committed Jun 1, 2016
2 parents 292a0be + 1d7c4fd commit c821143
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion skimage/filters/tests/test_thresholding.py
Expand Up @@ -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())
Expand Down
11 changes: 8 additions & 3 deletions skimage/filters/thresholding.py
Expand Up @@ -110,6 +110,11 @@ 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
----------
Expand All @@ -133,9 +138,9 @@ 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 " \
"having more than one color. The input image seems " \
"to have just one color {0}.".format(image.min()))
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()))

hist, bin_centers = histogram(image.ravel(), nbins)
hist = hist.astype(float)
Expand Down

0 comments on commit c821143

Please sign in to comment.