mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-05 17:55:27 +08:00
Add range check against better judgment
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user