Menu
Home Explore People Places Arts History Plants & Animals Science Life & Culture Technology
On this page
Histogram equalization
Method in image processing of contrast adjustment using the image's histogram

Histogram equalization is a method in image processing of contrast adjustment using the image's histogram.

Related Image Collections Add Image
We don't have any YouTube videos related to Histogram equalization yet.
We don't have any PDF documents related to Histogram equalization yet.
We don't have any Books related to Histogram equalization yet.
We don't have any archived web articles related to Histogram equalization yet.

Overview

This method usually increases the global contrast of many images, especially when the image is represented by a narrow range of intensity values. Through this adjustment, the intensities can be better distributed on the histogram utilizing the full range of intensities evenly. This allows for areas of lower local contrast to gain a higher contrast. Histogram equalization accomplishes this by effectively spreading out the highly populated intensity values which are used to degrade image contrast.

The method is useful in images with backgrounds and foregrounds that are both bright or both dark. In particular, the method can lead to better views of bone structure in x-ray images, and to better detail in photographs that are either over or under-exposed. A key advantage of the method is that it is a fairly straightforward technique adaptive to the input image and an invertible operator. So in theory, if the histogram equalization function is known, then the original histogram can be recovered. The calculation is not computationally intensive. A disadvantage of the method is that it is indiscriminate. It may increase the contrast of background noise, while decreasing the usable signal.

In scientific imaging where spatial correlation is more important than intensity of signal (such as separating DNA fragments of quantized length), the small signal-to-noise ratio usually hampers visual detections.

Histogram equalization often produces unrealistic effects in photographs; however it is very useful for scientific images like thermal, satellite or x-ray images, often the same class of images to which one would apply false-color. Also histogram equalization can produce undesirable effects (like visible image gradient) when applied to images with low color depth. For example, if applied to 8-bit image displayed with 8-bit gray-scale palette it will further reduce color depth (number of unique shades of gray) of the image. Histogram equalization will work the best when applied to images with much higher color depth than palette size, like continuous data or 16-bit gray-scale images.

There are two ways to think about and implement histogram equalization, either as image change or as palette change. The operation can be expressed as P(M(I)) where I is the original image, M is histogram equalization mapping operation and P is a palette. If we define a new palette as P'=P(M) and leave image I unchanged then histogram equalization is implemented as palette change or mapping change. On the other hand, if palette P remains unchanged and image is modified to I'=M(I) then the implementation is accomplished by image change. In most cases palette change is better as it preserves the original data.

Modifications of this method use multiple histograms, called subhistograms, to emphasize local contrast, rather than overall global contrast. Examples of such methods include adaptive histogram equalization, contrast limiting adaptive histogram equalization or CLAHE, multipeak histogram equalization (MPHE), and multipurpose beta optimized bihistogram equalization (MBOBHE). The goal of these methods, especially MBOBHE, is to improve the contrast without producing brightness mean-shift and detail loss artifacts by modifying the HE algorithm.1

A signal transform equivalent to histogram equalization also seems to happen in biological neural networks so as to maximize the output firing rate of the neuron as a function of the input statistics. This has been proved in particular in the fly retina.2

Histogram equalization is a specific case of the more general class of histogram remapping methods. These methods seek to adjust the image to make it easier to analyze or improve visual quality (e.g., retinex)

Back projection

The back projection (or "project") of a histogrammed image is the re-application of the modified histogram to the original image, functioning as a look-up table for pixel brightness values.

For each group of pixels taken from the same position from all input single-channel images, the function puts the histogram bin value to the destination image, where the coordinates of the bin are determined by the values of pixels in this input group. In terms of statistics, the value of each output image pixel characterizes the probability that the corresponding input pixel group belongs to the object whose histogram is used.3

Implementation

Consider a discrete grayscale image {x} and let ni be the number of occurrences of gray level i. The probability of an occurrence of a pixel of level i in the image is

  p x ( i ) = p ( x = i ) = n i n , 0 ≤ i < L {\displaystyle \ p_{x}(i)=p(x=i)={\frac {n_{i}}{n}},\quad 0\leq i<L}

  L {\displaystyle \ L} being the total number of gray levels in the image (typically 256), n being the total number of pixels in the image, and p x ( i ) {\displaystyle p_{x}(i)} being in fact the image's histogram for pixel value i, normalized to [0,1].

Let us also define the cumulative distribution function corresponding to i as

cdf x ⁡ ( i ) = ∑ j = 0 i p x ( x = j ) {\displaystyle \operatorname {cdf} _{x}(i)=\sum _{j=0}^{i}p_{x}(x=j)} ,

which is also the image's accumulated normalized histogram.

We would like to create a transformation of the form   y = T ( x ) {\displaystyle \ y=T(x)} to produce a new image {y}, with a flat histogram. Such an image would have a linearized cumulative distribution function (CDF) across the value range, i.e.

cdf y ⁡ ( i ) = ( i + 1 ) K {\displaystyle \operatorname {cdf} _{y}(i)=(i+1)K} for 0 ≤ i < L {\displaystyle 0\leq i<L}

for some constant   K {\displaystyle \ K} . The properties of the CDF allow us to perform such a transform (see Inverse distribution function); it is defined as

  y = T ( k ) = cdf x ⁡ ( k ) {\displaystyle \ y=T(k)=\operatorname {cdf} _{x}(k)}

where   k {\displaystyle \ k} is in the range [ 0 , L − 1 ] ) {\displaystyle [0,L-1])} . Notice that   T {\displaystyle \ T} maps the levels into the range [0,1], since we used a normalized histogram of {x}. In order to map the values back into their original range, the following simple transformation needs to be applied on the result:

  y ′ = y ⋅ ( max { x } − min { x } ) + min { x } = y ⋅ ( L − 1 ) {\displaystyle \ y^{\prime }=y\cdot (\max\{x\}-\min\{x\})+\min\{x\}=y\cdot (L-1)} .

A more detailed derivation is provided in University of California, Irvine Math 77C - Histogram Equalization.

  y {\displaystyle \ y} is a real value while   y ′ {\displaystyle \ y^{\prime }} has to be an integer. An intuitive and popular method4 is applying the round operation:

  y ′ = round ⁡ ( y ⋅ ( L − 1 ) ) {\displaystyle \ y^{\prime }=\operatorname {round} (y\cdot (L-1))} .

However, detailed analysis results in slightly different formulation. The mapped value   y ′ {\displaystyle \ y^{\prime }} should be 0 for the range of 0 < y ≤ 1 / L {\displaystyle 0<y\leq 1/L} . And   y ′ = 1 {\displaystyle \ y^{\prime }=1} for 1 / L < y ≤ 2 / L {\displaystyle 1/L<y\leq 2/L} ,   y ′ = 2 {\displaystyle \ y^{\prime }=2} for 2 / L < y ≤ 3 / L {\displaystyle 2/L<y\leq 3/L} , ...., and finally   y ′ = L − 1 {\displaystyle \ y^{\prime }=L-1} for ( L − 1 ) / L < y ≤ 1 {\displaystyle (L-1)/L<y\leq 1} . Then the quantization formula from   y {\displaystyle \ y} to   y ′ {\displaystyle \ y^{\prime }} should be

y ′ = ceil ⁡ ( L ⋅ y ) − 1 {\displaystyle y^{\prime }=\operatorname {ceil} (L\cdot y)-1} .

(Note: y ′ = − 1 {\displaystyle y^{\prime }=-1} when   y = 0 {\displaystyle \ y=0} , however, it does not happen just because   y = 0 {\displaystyle \ y=0} means that there is no pixel corresponding to that value.)

Of color images

The above describes histogram equalization on a grayscale image. However it can also be used on color images by applying the same method separately to the Red, Green and Blue components of the RGB color values of the image. However, applying the same method on the Red, Green, and Blue components of an RGB image may yield dramatic changes in the image's color balance since the relative distributions of the color channels change as a result of applying the algorithm. However, if the image is first converted to another color space, Lab color space, or HSL/HSV color space in particular, then the algorithm can be applied to the luminance or value channel without resulting in changes to the hue and saturation of the image.5 There are several histogram equalization methods in 3D space. Trahanias and Venetsanopoulos applied histogram equalization in 3D color space6 However, it results in "whitening" where the probability of bright pixels are higher than that of dark ones.7 Han et al. proposed to use a new cdf defined by the iso-luminance plane, which results in uniform gray distribution.8

Examples

For consistency with statistical usage, "CDF" (i.e. Cumulative distribution function) should be replaced by "cumulative histogram", especially since the article links to cumulative distribution function which is derived by dividing values in the cumulative histogram by the overall amount of pixels. The equalized CDF is defined in terms of rank as r a n k / p i x e l c o u n t {\displaystyle rank/pixelcount} .

Small image

The 8-bit grayscale image shown has the following values:

5255615979617661
62595510494855971
6365661131441046372
6470701261541097169
677368106122886868
6879607077665875
6985645855616583
7087696865737890

The histogram for this image is shown in the following table. Pixel values that have a zero count are excluded for the sake of brevity.

ValueCountValueCountValueCountValueCountValueCount
5216427218521131
5536537328711221
5826627518811261
5936717619011441
6016857719411541
6146937811042
6217047921061
6327128311091

The cumulative distribution function (cdf) is shown below. Again, pixel values that do not contribute to an increase in the cdf are excluded for brevity.

v, Pixel Intensitycdf(v)h(v), Equalized v
5210
55412
58620
59932
601036
611453
621557
631765
641973
652285
662493
672597
6830117
6933130
7037146
7139154
7240158
7342166
7543170
7644174
7745178
7846182
7948190
8349194
8551202
8752206
8853210
9054215
9455219
10457227
10658231
10959235
11360239
12261243
12662247
14463251
15464255
(Please note that h ( v ) = ceil ⁡ ( cdf ⁡ ( v ) ) − 1 {\displaystyle h(v)=\operatorname {ceil} (\operatorname {cdf} (v))-1} version is not illustrated yet.)

This cdf shows that the minimum value in the subimage is 52 and the maximum value is 154. The cdf of 64 for value 154 coincides with the number of pixels in the image. The cdf must be normalized to [ 0 , 255 ] {\displaystyle [0,255]} . The general histogram equalization formula is:

h ( v ) = r o u n d ( cdf ⁡ ( v ) − cdf min ( M × N ) − cdf min × ( L − 1 ) ) {\displaystyle h(v)=\mathrm {round} \left({\frac {\operatorname {cdf} (v)-\operatorname {cdf} _{\min }}{(M\times N)-\operatorname {cdf} _{\min }}}\times (L-1)\right)}

where cdfmin is the minimum non-zero value of the cumulative distribution function (in this case 1), M × N gives the image's number of pixels (for the example above 64, where M is width and N the height) and L is the number of grey levels used (in most cases, like this one, 256).

Note that to scale values in the original data that are above 0 to the range 1 to L-1, inclusive, the above equation would instead be:

h ( v ) = r o u n d ( cdf ⁡ ( v ) − cdf min ( M × N ) − cdf min × ( L − 2 ) ) + 1 {\displaystyle h(v)=\mathrm {round} \left({\frac {\operatorname {cdf} (v)-\operatorname {cdf} _{\min }}{(M\times N)-\operatorname {cdf} _{\min }}}\times (L-2)\right)+1}

where cdf(v) > 0. Scaling from 1 to 255 preserves the non-zero-ness of the minimum value.

The equalization formula for the example scaling data from 0 to 255, inclusive, is:

h ( v ) = r o u n d ( cdf ⁡ ( v ) − 1 63 × 255 ) {\displaystyle h(v)=\mathrm {round} \left({\frac {\operatorname {cdf} (v)-1}{63}}\times 255\right)}

For example, the cdf of 78 is 46. (The value of 78 is used in the bottom row of the 7th column.) The normalized value becomes

h ( 78 ) = r o u n d ( 46 − 1 63 × 255 ) = r o u n d ( 0.714286 × 255 ) = 182 {\displaystyle h(78)=\mathrm {round} \left({\frac {46-1}{63}}\times 255\right)=\mathrm {round} \left(0.714286\times 255\right)=182}

Once this is done then the values of the equalized image are directly taken from the normalized cdf to yield the equalized values:

01253321905317453
57321222721920232154
65859323925122765158
73146146247255235154130
97166117231243210117117
117190361461789320170
1302027320125385194
14620613011785166182215

Notice that the minimum value (52) is now 0 and the maximum value (154) is now 255.

OriginalEqualized
Histogram of Original imageHistogram of Equalized image

Full-sized image

See also

References

  1. Hum, Yan Chai; Lai, Khin Wee; Mohamad Salim, Maheza Irna (October 11, 2014). "Multiobjectives bihistogram equalization for image contrast enhancement". Complexity. 20 (2): 22–36. Bibcode:2014Cmplx..20b..22H. doi:10.1002/cplx.21499. /wiki/Bibcode_(identifier)

  2. Laughlin, S.B (1981). "A simple coding procedure enhances a neuron's information capacity". Z. Naturforsch. 9–10(36):910–2.

  3. Intel Corporation (2001). "Open Source Computer Vision Library Reference Manual" (PDF). Archived from the original (PDF) on April 9, 2015. Retrieved January 11, 2015. {{cite journal}}: Cite journal requires |journal= (help) https://web.archive.org/web/20150409155114/http://www.cs.unc.edu/~stc/FAQs/OpenCV/OpenCVReferenceManual.pdf

  4. Gonzalez, Rafael C. (2018). Digital image processing. Richard E. Woods (4th ed.). New York, NY: Pearson. pp. 138–140. ISBN 978-1-292-22304-9. OCLC 991765590. 978-1-292-22304-9

  5. S. Naik and C. Murthy, "Hue-preserving color image enhancement without gamut problem," IEEE Trans. Image Processing, vol. 12, no. 12, pp. 1591–1598, Dec. 2003 https://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=1257395

  6. P. E. Trahanias and A. N. Venetsanopoulos, "Color image enhancement through 3-D histogram equalization," in Proc. 15th IAPR Int. Conf. Pattern Recognition, vol. 1, pp. 545–548, Aug.-Sep. 1992. https://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=202045

  7. N. Bassiou and C. Kotropoulos, "Color image histogram equalization by absolute discounting back-off," Computer Vision and Image Understanding, vol. 107, no. 1-2, pp.108-122, Jul.-Aug. 2007 http://www.sciencedirect.com/science/article/pii/S1077314206002141

  8. Han, Ji-Hee; Yang, Sejung; Lee, Byung-Uk (2011). "A Novel 3-D Color Histogram Equalization Method with Uniform 1-D Gray Scale Histogram". IEEE Transactions on Image Processing. 20 (2): 506–512. Bibcode:2011ITIP...20..506H. doi:10.1109/TIP.2010.2068555. PMID 20801744. S2CID 17972519. /wiki/Bibcode_(identifier)