Module: exposure

skimage.exposure.cumulative_distribution(image) Return cumulative distribution function (cdf) for the given image.
skimage.exposure.equalize(*args, **kwargs)
skimage.exposure.equalize_adapthist(image[, ...]) Contrast Limited Adaptive Histogram Equalization.
skimage.exposure.equalize_hist(image[, nbins]) Return image after histogram equalization.
skimage.exposure.histogram(image[, nbins]) Return histogram of image.
skimage.exposure.rescale_intensity(image[, ...]) Return image after stretching or shrinking its intensity levels.

cumulative_distribution

skimage.exposure.cumulative_distribution(image, nbins=256)

Return cumulative distribution function (cdf) for the given image.

Parameters :

image : array

Image array.

nbins : int

Number of bins for image histogram.

Returns :

img_cdf : array

Values of cumulative distribution function.

bin_centers : array

Centers of bins.

References

[R38]http://en.wikipedia.org/wiki/Cumulative_distribution_function

equalize

skimage.exposure.equalize(*args, **kwargs)

equalize_adapthist

skimage.exposure.equalize_adapthist(image, ntiles_x=8, ntiles_y=8, clip_limit=0.01, nbins=256)

Contrast Limited Adaptive Histogram Equalization.

Parameters :

image : array-like

Input image.

ntiles_x : int, optional

Number of tile regions in the X direction. Ranges between 2 and 16.

ntiles_y : int, optional

Number of tile regions in the Y direction. Ranges between 2 and 16.

clip_limit : float: optional

Clipping limit, normalized between 0 and 1 (higher values give more contrast).

nbins : int, optional

Number of gray bins for histogram (“dynamic range”).

Returns :

out : ndarray

Equalized image.

Notes

  • The algorithm relies on an image whose rows and columns are even multiples of the number of tiles, so the extra rows and columns are left at their original values, thus preserving the input image shape.

  • For color images, the following steps are performed:
    • The image is converted to LAB color space
    • The CLAHE algorithm is run on the L channel
    • The image is converted back to RGB space and returned
  • For RGBA images, the original alpha channel is removed.

References

[R39]http://tog.acm.org/resources/GraphicsGems/gems.html#gemsvi
[R40]https://en.wikipedia.org/wiki/CLAHE#CLAHE

equalize_hist

skimage.exposure.equalize_hist(image, nbins=256)

Return image after histogram equalization.

Parameters :

image : array

Image array.

nbins : int

Number of bins for image histogram.

Returns :

out : float array

Image array after histogram equalization.

Notes

This function is adapted from [R41] with the author’s permission.

References

[R41](1, 2) http://www.janeriksolem.net/2009/06/histogram-equalization-with-python-and.html
[R42]http://en.wikipedia.org/wiki/Histogram_equalization

histogram

skimage.exposure.histogram(image, nbins=256)

Return histogram of image.

Unlike numpy.histogram, this function returns the centers of bins and does not rebin integer arrays. For integer arrays, each integer value has its own bin, which improves speed and intensity-resolution.

Parameters :

image : array

Input image.

nbins : int

Number of bins used to calculate histogram. This value is ignored for integer arrays.

Returns :

hist : array

The values of the histogram.

bin_centers : array

The values at the center of the bins.

rescale_intensity

skimage.exposure.rescale_intensity(image, in_range=None, out_range=None)

Return image after stretching or shrinking its intensity levels.

The image intensities are uniformly rescaled such that the minimum and maximum values given by in_range match those given by out_range.

Parameters :

image : array

Image array.

in_range : 2-tuple (float, float)

Min and max allowed intensity values of input image. If None, the allowed min/max values are set to the actual min/max values in the input image.

out_range : 2-tuple (float, float)

Min and max intensity values of output image. If None, use the min/max intensities of the image data type. See skimage.util.dtype for details.

Returns :

out : array

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

Examples

By default, intensities are stretched to the limits allowed by the dtype:

>>> 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:

>>> 1.0 * image
array([  51.,  102.,  153.])

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

>>> image_float = 1.0 * image
>>> rescale_intensity(image_float)
array([ 0. ,  0.5,  1. ])

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

>>> rescale_intensity(image_float, in_range=(0, 255))
array([ 0.2,  0.4,  0.6])

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))
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 out_range parameter:

>>> image = np.array([-10, 0, 10], dtype=np.int8)
>>> rescale_intensity(image, out_range=(0, 127))
array([  0,  63, 127], dtype=int8)