Add range check against better judgment

This commit is contained in:
cgohlke
2012-06-06 18:51:47 -07:00
parent bbc5b8e552
commit 96bad2e4cf
+5 -2
View File
@@ -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: