Enhance contrast using histogram equalization

`J = histeq(I,hgram)`

J = histeq(I,n)

[J, T] = histeq(I)

[gpuarrayJ, gpuarrayT] = histeq(gpuarrayI,___)

newmap = histeq(X, map, hgram)

newmap = histeq(X, map)

[newmap, T] = histeq(X,___)

`J = histeq(I,hgram)`

transforms
the intensity image `I`

so that the histogram of
the output intensity image `J`

with `length(hgram)`

bins
approximately matches `hgram`

. The vector `hgram`

should
contain integer counts for equally spaced bins with intensity values
in the appropriate range: [0, 1] for images of class `double`

,
[0, 255] for images of class `uint8`

, and [0, 65535]
for images of class `uint16`

. `histeq`

automatically
scales `hgram`

so that `sum(hgram)`

`=`

`prod(size(I))`

.
The histogram of `J`

will better match `hgram`

when `length(hgram)`

is
much smaller than the number of discrete levels in `I`

.

`J = histeq(I,n)`

transforms
the intensity image `I`

, returning in `J`

an
intensity image with `n`

discrete gray levels. A
roughly equal number of pixels is mapped to each of the `n`

levels
in `J`

, so that the histogram of `J`

is
approximately flat. (The histogram of `J`

is flatter
when `n`

is much smaller than the number of discrete
levels in `I`

.) The default value for `n`

is
64.

`[J, T] = histeq(I)`

returns
the grayscale transformation that maps gray levels in the image `I`

to
gray levels in `J`

.

`[gpuarrayJ, gpuarrayT] = histeq(gpuarrayI,___)`

performs
the histogram equalization on a GPU. The input image and the output
image are gpuArrays. This syntax requires the Parallel Computing Toolbox™.

`newmap = histeq(X, map, hgram)`

transforms
the colormap associated with the indexed image `X`

so
that the histogram of the gray component of the indexed image `(X,newmap)`

approximately
matches `hgram`

. The `histeq`

function
returns the transformed colormap in `newmap`

. `length(hgram)`

must
be the same as `size(map,1)`

.

`newmap = histeq(X, map)`

transforms
the values in the colormap so that the histogram of the gray component
of the indexed image `X`

is approximately flat. It
returns the transformed colormap in `newmap`

.

`[newmap, T] = histeq(X,___)`

returns
the grayscale transformation `T`

that maps the gray
component of `map`

to the gray component of `newmap`

.

Code Generation support: Yes.

MATLAB Function Block support: Yes.

`I`

can be of class `uint8`

, `uint16`

, `int16`

, `single`

,
or `double`

. The output image `J`

has
the same class as `I`

. The optional output `T`

is
always of class `double`

.

`gpuarrayI`

is a gpuArray of class `uint8`

, `uint16`

, `int16`

, `single`

,
or `double`

. The output image `gpuarrayJ`

has
the same class as `gpuarrayI`

. The optional output `gpuarrayT`

is
always a gpuArray of class `double`

.

`X`

can be of class `uint8`

, `single`

,
or `double`

. The output colormap `newmap`

is
always of class `double`

.

Enhance the contrast of an intensity image using histogram equalization.

I = imread('tire.tif'); J = histeq(I); imshow(I) figure, imshow(J)

Display a histogram of the original image.

figure; imhist(I,64)

Compare it to a histogram of the processed image.

figure; imhist(J,64)

This example performs the same histogram equalization on the GPU.

I = gpuArray(imread('tire.tif')); J = histeq(I); figure imshow(I), figure, imshow(J)

Was this topic helpful?