Main Content

imhist

Histogram of image data

Description

[计数,binLocations] = imhist(I)calculates the histogram for the grayscale imageI. Theimhistfunction returns the histogram counts in计数and the bin locations inbinLocations. The number of bins in the histogram is determined by the image type.

[计数,binLocations] = imhist(I,n)specifies the number of bins,n, used to calculate the histogram.

[计数,binLocations] = imhist(X,cmap)calculates the histogram for the indexed imageXwith colormapcmap. The histogram has one bin for each entry in the colormap.

example

imhist(___)displays a plot of the histogram. If the input image is an indexed image, then the histogram shows the distribution of pixel values above a color bar of the colormapcmap.

Examples

collapse all

Read a grayscale image into the workspace.

I = imread('pout.tif');

Display a histogram of the image. SinceIis grayscale, by default the histogram will have 256 bins.

imhist(I)

Figure contains 2 axes objects. Axes object 1 contains an object of type stem. Axes object 2 contains 2 objects of type image, line.

Load a 3-D dataset.

loadmristack

Display the histogram of the data. Since the image is grayscale,imhistuses 256 bins by default.

imhist(mristack)

Figure contains 2 axes objects. Axes object 1 contains an object of type stem. Axes object 2 contains 2 objects of type image, line.

Input Arguments

collapse all

Grayscale image, specified as a numeric array of any dimension. If the image has data typesingleordouble, then values must be in the range [0, 1]. IfIhas values outside the range [0, 1], then you can use therescalefunction to rescale values to the expected range.

Data Types:single|double|int8|int16|int32|uint8|uint16|uint32|logical

Number of bins, specified as a positive integer. IfIis a grayscale image, thenimhistuses a default value of 256 bins. IfIis a binary image, thenimhistuses two bins.

Example:50

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

Indexed image, specified as a numeric array of any dimension.

Data Types:single|double|uint8|uint16|logical

Colormap associated with indexed imageX, specified as ac-by-3 numeric matrix with values in the range [0, 1]. Each row is a three-element RGB triplet that specifies the red, green, and blue components of a single color of the colormap.The colormap must be at least as long as the largest index inX.

Data Types:double

Output Arguments

collapse all

Histogram counts, returned as a numeric array. If the histogram is computed for an indexed image,X, then the length of计数is the same as the length of the colormap,cmap.

Bin locations, returned as a numeric array.

提示

  • For grayscale images, thenbins of the histogram are each half-open intervals of widthA/(n−1). In particular, thepthbin is the half-open interval

    A ( p 1.5 ) ( n 1 ) B x < A ( p 0.5 ) ( n 1 ) B ,

    wherexis the intensity value. The scale factorAand offsetBdepend on the type of the image class as follows:

    Data Type A B
    double 1 0
    single 1 0
    int8 255 128
    int16 65,535 32,768
    int32 4,294,967,295 2,147,483,648
    uint8 255 0
    uint16 65,535 0
    uint32 4,294,967,295 0
    logical 1 0

  • To display the histogram from计数andbinLocations, use the commandstem(binLocations计数).

Extended Capabilities

H版istory

Introduced before R2006a

See Also

||