skimage 0.17.2

NotesParametersReturnsBackRef
rescale_intensity(image, in_range='image', out_range='dtype')

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

Notes

versionchanged

The dtype of the output array has changed to match the output dtype, or float if the output range is specified by a pair of floats.

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 :None:None:`DTYPE_RANGE`.

2-tuple

Use :None:None:`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.

Return image after stretching or shrinking its intensity levels.

See Also

equalize_hist

Examples

By default, the min/max intensities of the input image are stretched to the limits allowed by the image's dtype, since :None:None:`in_range` defaults to 'image' and :None:None:`out_range` defaults to 'dtype':

This example is valid syntax, but we were not able to check execution
>>> image = np.array([51, 102, 153], dtype=np.uint8)
... rescale_intensity(image) array([ 0, 127, 255], dtype=uint8)

It's easy to accidentally convert an image dtype from uint8 to float:

This example is valid syntax, but we were not able to check execution
>>> 1.0 * image
array([ 51., 102., 153.])

Use rescale_intensity to rescale to the proper range for float dtypes:

This example is valid syntax, but we were not able to check execution
>>> image_float = 1.0 * image
... rescale_intensity(image_float) array([0. , 0.5, 1. ])

To maintain the low contrast of the original, use the :None:None:`in_range` parameter:

This example is valid syntax, but we were not able to check execution
>>> rescale_intensity(image_float, in_range=(0, 255))
array([0.2, 0.4, 0.6])

If the min/max value of :None:None:`in_range` is more/less than the min/max image intensity, then the intensity levels are clipped:

This example is valid syntax, but we were not able to check execution
>>> rescale_intensity(image_float, in_range=(0, 102))
array([0.5, 1. , 1. ])

If you have an image with signed integers but want to rescale the image to just the positive range, use the :None:None:`out_range` parameter. In that case, the output dtype will be float:

This example is valid syntax, but we were not able to check execution
>>> image = np.array([-10, 0, 10], dtype=np.int8)
... rescale_intensity(image, out_range=(0, 127)) array([ 0. , 63.5, 127. ])

To get the desired range with a specific dtype, use .astype() :

This example is valid syntax, but we were not able to check execution
>>> rescale_intensity(image, out_range=(0, 127)).astype(np.int8)
array([  0,  63, 127], dtype=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) array([127, 127, 127], dtype=int32)

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

skimage.exposure._adapthist.equalize_adapthist skimage.exposure.exposure.rescale_intensity

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /skimage/exposure/exposure.py#313
type: <class 'function'>
Commit: