skimage2.util.rescale_legacy#

skimage2.util.rescale_legacy(image)[source]#

Rescale value range based on dtype (legacy skimage behavior).

Parameters:
imagendarray

Input image.

Returns:
rescaled_imagendarray

Rescaled image, of same shape as input image but with a floating dtype (See Notes).

See also

rescale_minmax

Rescale image to the value range [0, 1].

Notes

Rescales the value range according to the dtype of image according to the same logic as the legacy function skimage.util.img_as_float().

  • With a signed integer dtype, image is rescaled to the range [-1., 1.].

  • With an unsigned integer dtype, image is rescaled to the range [0., 1.].

  • With a floating dtype, the output range will not be modified; the range can be outside the above ranges.

Examples

Signed integers are scaled to range [-1., 1.] >>> rescale_legacy(np.array([-128, 0, 127], dtype=np.int8)) array([-1., 0., 1.])

Unsigned integers are scaled to range [0., 1.] >>> rescale_legacy(np.array([0, 127, 255], dtype=np.uint8)) array([0. , 0.49803922, 1. ])

Range of floating input is preserved >>> rescale_legacy(np.array([0, 127, 255], dtype=float)) array([ 0., 127., 255.])