{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / exposure / exposure / rescale_intensity

function

skimage.exposure.exposure:rescale_intensity

source: /dev/scikit-image/src/skimage/exposure/exposure.py :491

Signature

def   rescale_intensity ( image in_range = image out_range = dtype )

Summary

Return image after stretching or shrinking its intensity levels.

Extended Summary

The desired intensity range of the input and output, in_range and out_range respectively, are used to stretch or shrink the intensity range of the input image. See examples below.

Parameters

image : array

Image array.

in_range, out_range : str or 2-tuple, optional

Min and max intensity values of input and output image. The possible values for this parameter are enumerated below.

'image'

Use image min/max as the intensity range.

'dtype'

Use min/max of the image's dtype as the intensity range.

dtype-name

Use intensity range based on desired dtype. Must be valid key in DTYPE_RANGE.

2-tuple

Use range_values as explicit min/max intensities.

Returns

out : array

Image array after rescaling its intensity. This image is the same dtype as the input image.

Notes

Examples

By default, the min/max intensities of the input image are stretched to the limits allowed by the image's dtype, since `in_range` defaults to 'image' and `out_range` defaults to 'dtype':
image = np.array([51, 102, 153], dtype=np.uint8)
rescale_intensity(image)
It's easy to accidentally convert an image dtype from uint8 to float:
1.0 * image
Use `rescale_intensity` to rescale to the proper range for float dtypes:
image_float = 1.0 * image
rescale_intensity(image_float)
To maintain the low contrast of the original, use the `in_range` parameter:
rescale_intensity(image_float, in_range=(0, 255))
If the min/max value of `in_range` is more/less than the min/max image intensity, then the intensity levels are clipped:
rescale_intensity(image_float, in_range=(0, 102))
If you have an image with signed integers but want to rescale the image to just the positive range, use the `out_range` parameter. In that case, the output dtype will be float:
image = np.array([-10, 0, 10], dtype=np.int8)
rescale_intensity(image, out_range=(0, 127))
To get the desired range with a specific dtype, use ``.astype()``:
rescale_intensity(image, out_range=(0, 127)).astype(np.int8)
If the input image is constant, the output will be clipped directly to the output range:
image = np.array([130, 130, 130], dtype=np.int32)
rescale_intensity(image, out_range=(0, 127)).astype(np.int32)

See also

equalize_hist

Aliases

  • skimage.exposure.rescale_intensity

Referenced by