Raise error when single colored image is passed in threshold_otsu method

This commit is contained in:
Himanshu Mishra
2016-01-24 20:57:40 +05:30
parent b9c951335a
commit 28f19d3076
+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)