Note: This page has been translated by MathWorks. Please click here

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

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

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)`

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

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

transforms
the intensity image `J`

= histeq(`I`

,`n`

)`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`

.

transforms
the colormap associated with the indexed image `newmap`

= histeq(`X`

,`map`

,`hgram`

)`X`

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

,`newmap`

)
approximately matches the target histogram `hgram`

.
The `histeq`

function returns the transformed colormap
in `newmap`

. `length(hgram)`

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

.

When you supply a desired histogram `hgram`

, `histeq`

chooses
the grayscale transformation *T* to minimize

$$\left|{c}_{1}(T(k))-{c}_{0}(k)\right|,$$

`A`

, `hgram`

for all intensities `histeq`

uses
the transformation `X`

(or the colormap)
to their new values.If you do not specify `hgram`

, `histeq`

creates
a flat `hgram`

,

hgram = ones(1,n)*prod(size(A))/n;

and then applies the previous algorithm.

Was this topic helpful?