skimage2.exposure.histogram#

skimage2.exposure.histogram(image, nbins=256, source_range='image', normalize=False, *, channel_axis=None)[source]#

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.

If channel_axis is not set, the histogram is computed on the flattened image. For color or multichannel images, set channel_axis to use a common binning for all channels. Alternatively, one may apply the function separately on each channel to obtain a histogram for each color channel with separate binning.

Parameters:
imagearray

Input image.

nbinsint, optional

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

source_range{‘image’, ‘dtype’}, optional

‘image’ (default) determines the range from the input image. ‘dtype’ determines the range from the expected range of the images of that data type.

normalizebool, optional

If True, normalize the histogram by the sum of its values.

channel_axisint or None, optional

If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.

Returns:
histarray

The values of the histogram. When channel_axis is not None, hist will be a 2D array where the first axis corresponds to channels.

bin_centersarray

The values at the center of the bins.

Examples

>>> from _skimage2 import data, exposure, img_as_float
>>> image = img_as_float(data.camera())
>>> np.histogram(image, bins=2)
(array([ 93585, 168559]), array([0. , 0.5, 1. ]))
>>> exposure.histogram(image, nbins=2)
(array([ 93585, 168559]), array([0.25, 0.75]))