skimage2.util._prescale_value_range#

skimage2.util._prescale_value_range(image, *, mode)[source]#

Rescale the value range of image according to the selected mode.

For now, this private function handles prescaling (prescale parameter) 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 image between 0 and 1 regardless of dtype. After normalization, rescaled_image will have a floating dtype (according to _supported_float_type()).

'none'

Don’t rescale the value range of image at all and return a copy of image. Useful when image has already been rescaled.

'legacy'

Normalize only if image has an integer dtype. If image is of floating dtype, it is left alone. See skimage2.util.img_as_float() for more details.

Returns:
rescaled_imagendarray

The rescaled image of the same shape but possibly with a different dtype.

Raises:
ValueError

Rescaling an image with mode='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)