skimage2.util._prescale_value_range#
- skimage2.util._prescale_value_range(image, *, mode)[source]#
Rescale the value range of
imageaccording to the selectedmode.For now, this private function handles prescaling (
prescaleparameter) for public API that needs a value range to be known and well-defined.- Parameters:
- imagendarray
Image to rescale.
- mode{‘minmax’, ‘none’, ‘legacy’}, optional
Controls the rescaling behavior for
image.'minmax'Normalize
imagebetween 0 and 1 regardless of dtype. After normalization,rescaled_imagewill have a floating dtype (according to_supported_float_type()).'none'Don’t rescale the value range of
imageat all and return a copy ofimage. Useful whenimagehas already been rescaled.'legacy'Normalize only if
imagehas an integer dtype. Ifimageis of floating dtype, it is left alone. Seeskimage2.util.img_as_float()for more details.
- Returns:
- rescaled_imagendarray
The rescaled
imageof the same shape but possibly with a different dtype.
- Raises:
- ValueError
Rescaling an
imagewithmode='minmax'that contains NaN or infinity is not supported for now. In those cases, consider replacing the unsupported values manually.
Examples
>>> import numpy as np >>> image = np.array([-10, 45, 100], dtype=np.int8)
>>> _prescale_value_range(image, mode="minmax") array([0. , 0.5, 1. ])
>>> _prescale_value_range(image, mode="legacy") array([-0.07874016, 0.35433071, 0.78740157])
>>> _prescale_value_range(image, mode="none") array([-10, 45, 100], dtype=int8)