From 296438d08ed52cf42b7d7cf5d56bf15356fb9a27 Mon Sep 17 00:00:00 2001 From: Himanshu Mishra Date: Thu, 14 Jan 2016 17:51:46 +0530 Subject: [PATCH] Raise a warning if the image is not grayscale --- skimage/filters/thresholding.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/skimage/filters/thresholding.py b/skimage/filters/thresholding.py index de33593e..2362254b 100644 --- a/skimage/filters/thresholding.py +++ b/skimage/filters/thresholding.py @@ -8,6 +8,7 @@ import numpy as np from scipy import ndimage as ndi from ..exposure import histogram from .._shared.utils import assert_nD +import warnings def threshold_adaptive(image, block_size, method='gaussian', offset=0, @@ -123,6 +124,11 @@ def threshold_otsu(image, nbins=256): ----- The input image must be Grayscale. """ + if image.shape[-1] in (3, 4): + msg = "threshold_otsu is expected to work correctly only for " \ + "grayscale images; image shape {} looks like an RGB image" + warnings.warn(msg.format(image.shape)) + hist, bin_centers = histogram(image.ravel(), nbins) hist = hist.astype(float)