# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# imhist

Histogram of image data

## Syntax

imhist(I)
imhist(I,n)
imhist(X,map)
[counts,binLocations] = imhist(I)
[counts,binLocations] = imhist(gpuarrayI,___)

## Description

example

imhist(I) calculates the histogram for the intensity image I and displays a plot of the histogram. The number of bins in the histogram is determined by the image type.

imhist(I,n) calculates the histogram, where I specifies the number of bins used in the histogram. n also specifies the length of the colorbar displayed at the bottom of the histogram plot.

imhist(X,map) displays a histogram for the indexed image X. This histogram shows the distribution of pixel values above a colorbar of the colormap map. The colormap must be at least as long as the largest index in X. The histogram has one bin for each entry in the colormap.

[counts,binLocations] = imhist(I) returns the histogram counts in counts and the bin locations in binLocations so that stem(binLocations,counts) shows the histogram. For indexed images, imhist returns the histogram counts for each colormap entry. The length of counts is the same as the length of the colormap.

example

[counts,binLocations] = imhist(gpuarrayI,___) performs the histogram calculation on a GPU. The input image and the return values are gpuArrays. This syntax requires the Parallel Computing Toolbox™. When the input image is a gpuArray, imhist does not automatically display the histogram. To display the histogram, use stem(binLocations,counts).

## Examples

collapse all

Read a grayscale image into the workspace.

Display a histogram of the image. Since I is grayscale, by default the histogram will have 256 bins.

imhist(I)

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

imhist(mristack)

Create array of class uint16.

Calculate histogram. Because imhist does not automatically display the plot of the histogram when run on a GPU, this example uses stem to plot the histogram.

[counts,x] = imhist(I);
stem(x,counts);

## Input Arguments

collapse all

Input intensity image, specified as a numeric array. I can be 2-D, 3-D, or N-D.

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

Number of bins, specified as a numeric scalar. If I is a grayscale image, imhist uses a default value of 256 bins. If I is a binary image, imhist uses two bins.

Example: [counts,x] = imhist(I,50);

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

Input indexed image, specified as a numeric array. X can be 2-D, 3-D, or N-D.

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

Colormap associated with indexed image, specified as a p-by-3 array.

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

Input image, specified as a gpuArray.

## Output Arguments

collapse all

Histogram counts, returned as a numeric array.

Bin locations, returned as a numeric array.

## Tips

• For intensity images, the n bins of the histogram are each half-open intervals of width A/(n−1). In particular, the pth bin is the half-open interval

$\frac{A\left(p-1.5\right)}{\left(n-1\right)}-B\le x<\frac{A\left(p-0.5\right)}{\left(n-1\right)}-B,$

where x is the intensity value. The scale factor A and offset B depend on the type of the image class as follows:

doublesingleint8int16int32uint8uint16uint32logical
A112556553542949672952556553542949672951
B001283276821474836480000