diff --git a/skimage/util/dtype.py b/skimage/util/dtype.py index ed1ae35b..44476e44 100644 --- a/skimage/util/dtype.py +++ b/skimage/util/dtype.py @@ -31,8 +31,9 @@ def convert(image, dtype, force_copy=False, uniform=False): Warnings are issued in case of precision loss, or when negative values are clipped during conversion to unsigned integer types (sign loss). - Floating point values will be clipped to the range [0.0, 1.0] or - [-1.0, 1.0] when converting to unsigned or signed integers respectively. + Floating point values are expected to be normalized and will be clipped + to the range [0.0, 1.0] or [-1.0, 1.0] when converting to unsigned or + signed integers respectively. Numbers are not shifted to the negative side when converting from unsigned to signed integer types. Negative values will be clipped when @@ -152,6 +153,8 @@ def convert(image, dtype, force_copy=False, uniform=False): imax_in = np.iinfo(dtype_in).max if kind_in == 'f': + if np.min(image) < -1.0 or np.max(image) > 1.0: + raise ValueError("Images of type float must be between -1 and 1.") if kind == 'f': # floating point -> floating point if itemsize_in > itemsize: