Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Histogram of image data

```
[counts,binLocations]
= imhist(I)
```

`[counts,binLocations] = imhist(I,n)`

`[counts,binLocations] = imhist(X,map)`

`imhist(___)`

`[`

calculates the histogram for the grayscale image `counts`

,`binLocations`

]
= imhist(`I`

)`I`

. The
`imhist`

function returns the histogram counts in
`counts`

and the bin locations in
`binLocations`

. The number of bins in the histogram is
determined by the image type.

You optionally can compute the histogram counts and bin locations

`[`

specifies the number of bins, `counts`

,`binLocations`

] = imhist(`I`

,`n`

)`n`

, used to calculate the
histogram.

`[`

calculates the histogram for the indexed image `counts`

,`binLocations`

] = imhist(`X`

,`map`

)`X`

with
colormap `map`

. The histogram has one bin for each entry in
the colormap.

This syntax is not supported on a GPU.

`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 colorbar of the colormap
`map`

.

If you use this syntax when `I`

is a
`gpuArray`

, then no plot is displayed.
`imhist`

returns the histogram counts in
`ans`

and does not return the histogram bin
locations.

For grayscale images, the

`n`

bins of the histogram are each half-open intervals of width*A*/(*n*−1). In particular, the*p*th bin is the half-open interval$$\frac{A(p-1.5)}{(n-1)}-B\le x<\frac{A(p-0.5)}{(n-1)}-B,$$

where

*x*is the intensity value. The scale factor*A*and offset*B*depend on the type of the image class as follows:double single int8 int16 int32 uint8 uint16 uint32 logical *A*1 1 255 65535 4294967295 255 65535 4294967295 1 *B*0 0 128 32768 2147483648 0 0 0 0 To display the histogram from

`counts`

and`binLocations`

, use the command

.`stem`

(binLocations,counts)