Histogram equalization: Difference between revisions

Content deleted Content added
review: rm unnec bold and paren
No edit summary
Line 7:
'''Histogram equalization''' is a method in [[image processing]] of [[contrast (vision)|contrast]] adjustment using the [[Image histogram|image's histogram]].
 
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]]).
 
==Overview==
Line 16:
Histogram equalization often produces unrealistic effects in photographs; however it is very useful for scientific images like [[Thermography|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 [[List of 8-bit computer hardware palettes|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 (computing)|palette]] size, like [[Continuous function|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 (computing)|palette]] change. The operation can be expressed as ''<math>P(M( I ))''</math> where ''<math>I''</math> is the original image, ''<math>M''</math> is histogram equalization mapping operation and ''<math>P''</math> is a palette. If we define a new palette as ''<math>P' = P(M)''</math> and leave image ''<math>I</math>'' unchanged then histogram equalization is implemented as [[Palette (computing)|palette]] change or mapping change. On the other hand, if palette <math>P</math> remains unchanged and image is modified to ''<math>I ' = M(I)''</math> then the implementation is accomplished by image change. In most cases palette change is preferred 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]] and variations including, contrast limited adaptive histogram equalization, multipeak histogram equalization, and multipurpose beta-optimized bihistogram equalization (MBOBHE). The goal of these methods, especially MBOBHE, is to modifying the algorithm to improve the contrast without producing brightness mean-shift and detail loss artifacts.<ref>{{cite journal|last1=Hum|first1=Yan Chai|last2=Lai|first2=Khin Wee|last3=Mohamad Salim|first3=Maheza Irna|title=Multiobjectives bihistogram equalization for image contrast enhancement|journal=Complexity|date=11 October 2014|volume=20|issue=2|pages=22–36|doi=10.1002/cplx.21499|bibcode=2014Cmplx..20b..22H}}</ref>
Line 28:
 
==Implementation==
Consider a discrete [[Grayscale|grayscale image]] <math>X</math> and let ''n<submath>in_i</submath>'' be the number of occurrences of gray level ''<math>i''</math>. The probability of a pixel value chosen uniformly randomly from image <math>X</math> being ''<math>i</math>'', is
:<math>\ p_X(i) = \frac{n_i}{n},\quad 0 \le i < L </math>
<math>L</math> being the total number of gray levels in the image (typically 256), ''<math>n_i</math>'' being the number of pixels in the image with value ''<math>i</math>'', and ''<math>n''</math> being the total number of pixels in the image. Then <math>p_X(i)</math> is the image's histogram's value for ''<math>i</math>'', with the histogram normalized to have a total area of 1.
Then <math>p_X(i)</math> is the image's histogram's value for i, with the histogram normalized to have a total area of 1.
 
Let us then define the ''[[cumulative distribution function]]'' of pixels in image ''<math>X</math>''. For value ''<math>i</math>'' it is
:<math>\operatorname{cdf}_X(i) = \sum_{j=0}^i p_X(j)</math>,
which is also the image's accumulated normalized histogram.
Line 39 ⟶ 38:
We would like to create a transformation <math>T:[0,L-1] \rightarrow [0,L-1]</math> to produce a new image <math>y</math>, with a flat histogram. Such an image would have a linearized cumulative distribution function (CDF) across the value range, i.e.
:<math>\operatorname{cdf}_Y(i) = (i+1) K</math> for <math> 0 \le i < L </math>
for some constant <math>K</math>. The properties of the CDF allow us to perform such a transform (see [[Cumulative distribution function#Inverse distribution function (quantile function)|Inverse distribution function]]). It is defined as
:<math>\ T(i) = \operatorname{cdf}_X(i)</math>
where <math>\ i </math> is in the range <math> [0,L-1] </math>. Notice that <math>\ T </math> maps the levels into the range <math>[0,1]</math>, since we used a normalized histogram of <math>X</math>. In order to map the values back into their original range, the following simple transformation needs to be applied to each transformed image value <math>k</math>:
where <math>\ i </math> is in the range <math> [0,L-1]) </math>.
Notice that <math>\ T </math> maps the levels into the range [0,1], since we used a normalized histogram of <math>X</math>. In order to map the values back into their original range, the following simple transformation needs to be applied to each transformed image value k:
:<math>\ k^\prime = k \cdot(\max(i) - \min(i)) + \min(i)= k \cdot(L- 1)</math>.
A more detailed derivation is provided in [https://web.archive.org/web/20200601000000*/https://www.math.uci.edu/icamp/courses/math77c/demos/hist_eq.pdf University of California, Irvine Math 77C - Histogram Equalization].
 
<math>\ k </math> is a real value while <math>\ k^\prime </math> has to be an integer. An intuitive and popular method<ref>{{Cite book|last=Gonzalez|first=Rafael C.|url=https://www.worldcat.org/oclc/991765590|title=Digital image processing|date=2018|publisher=Pearson|others=Richard E. Woods|isbn=978-1-292-22304-9|edition=4th|___location=New York, NY|pages=138–140|oclc=991765590}}</ref> is applying the round operation:
:<math>\ k^\prime = \operatorname{round} (k \cdot(L- 1))</math>.
However, detailed analysis results in slightly different formulation. The mapped value <math>\ k^\prime </math> should be 0 for the range of <math>0<k \leq1/L</math>. And <math>\ k^\prime =1</math> for <math>1/L < k \leq 2/L</math>, <math>\ k^\prime = 2 </math> for <math>2/L < k \leq 3/L</math>, ...., and finally <math>\ k^\prime =L-1</math> for <math>(L-1)/L < k \leq 1</math>. Then the quantization formula from <math>\ k</math> to <math>\ k^\prime </math> should be
 
<math>k^\prime=\operatorname{ceil}(L \cdot k)-1 </math>.
 
(Note: <math>k^\prime=-1 </math> when <math>\ k=0 </math> , however, it does not happen just because <math>\ k=0 </math> means that there is no pixel corresponding to that value.)
 
== On color images ==
 
The above describes histogram equalization on a grayscale image. However itIt can also be used on color images by applying the same method separately to the Redred, Greengreen and Blueblue components of the [[RGB]] color values of the image. However, applying the same method on the Red, Green, and Blue components of anwhich RGBmay image mayhowever 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, ifIf the image is first converted to another color space, [[Lab color space|Lab]], or [[HSL and HSV|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.<ref>S. Naik and C. Murthy, "[https://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=1257395 Hue-preserving color image enhancement without gamut problem]," IEEE Trans. Image Processing, vol. 12, no. 12, pp. 1591–1598, Dec. 2003</ref> There are several histogram equalization methods in 3D space<ref>P. E. Trahanias and A. N. Venetsanopoulos, "[https://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=202045 Color image enhancement through 3-D histogram equalization]," in Proc. 15th IAPR Int. Conf. Pattern Recognition, vol. 1, pp. 545–548, Aug.-Sep. 1992.</ref> which result in "whitening" where the probability of bright pixels are higher than that of dark ones.<ref>N. Bassiou and C. Kotropoulos, "[http://www.sciencedirect.com/science/article/pii/S1077314206002141 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</ref> Han et al. proposed to use a new CDF defined by the ISO-luminance plane, which results in uniform gray distribution.<ref>{{Cite journal|doi = 10.1109/TIP.2010.2068555|title = A Novel 3-D Color Histogram Equalization Method with Uniform 1-D Gray Scale Histogram|year = 2011|last1 = Han|first1 = Ji-Hee|last2 = Yang|first2 = Sejung|last3 = Lee|first3 = Byung-Uk|journal = IEEE Transactions on Image Processing|volume = 20|issue = 2|pages = 506–512|pmid = 20801744| bibcode=2011ITIP...20..506H |s2cid = 17972519}}</ref>
There are several histogram equalization methods in 3D space. Trahanias and Venetsanopoulos applied histogram equalization in 3D color space<ref>P. E. Trahanias and A. N. Venetsanopoulos, "[https://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=202045 Color image enhancement through 3-D histogram equalization]," in Proc. 15th IAPR Int. Conf. Pattern Recognition, vol. 1, pp. 545–548, Aug.-Sep. 1992.</ref> However, it results in "whitening" where the probability of bright pixels are higher than that of dark ones.<ref>N. Bassiou and C. Kotropoulos, "[http://www.sciencedirect.com/science/article/pii/S1077314206002141 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</ref> Han et al. proposed to use a new cdf defined by the iso-luminance plane, which results in uniform gray distribution.<ref>{{Cite journal|doi = 10.1109/TIP.2010.2068555|title = A Novel 3-D Color Histogram Equalization Method with Uniform 1-D Gray Scale Histogram|year = 2011|last1 = Han|first1 = Ji-Hee|last2 = Yang|first2 = Sejung|last3 = Lee|first3 = Byung-Uk|journal = IEEE Transactions on Image Processing|volume = 20|issue = 2|pages = 506–512|pmid = 20801744| bibcode=2011ITIP...20..506H |s2cid = 17972519}}</ref>
 
==Examples==
Line 141 ⟶ 138:
|}
 
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.
 
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.
:{| class="wikitable"
|-
Line 198 ⟶ 194:
|}
 
The [[cumulative distribution function]] (cdfCDF) is shown below. Again, pixel values that do not contribute to an increase in the cdffunction are excluded for brevity.
:{| class="wikitable"
|-
! <math>v</math>, Pixel Intensity !! cdf<math>\operatorname{CDF}(v) </math>!! <math>h(v)</math>, Equalizedequalized <math>v</math>
|-
| 52||1||0
Line 276 ⟶ 272:
|-
| 154||64||255
|} (Please note that <math>h(v)=\operatorname{ceil}(\operatorname{cdfCDF}(v))-1 </math> version is not illustrated yet.)
 
This cdfCDF shows that the minimum value in the subimage is 52 and the maximum value is 154. The cdfCDF of 64 for value 154 coincides with the number of pixels in the image. The cdfCDF must be normalized to <math>[0,255]</math>. The general histogram equalization formula is:
 
:<math>
Line 284 ⟶ 280:
\mathrm{round}
\left(
\frac {\operatorname{cdfCDF}(v) - \operatorname{cdfCDF}_{\min}} {(M \times N) - \operatorname{cdfCDF}_{\min}}
\times (L - 1)
\right)
</math>
 
where cdf<submath>\operatorname{CDF}_{\min}</submath> is the minimum non-zero value of the cumulative distribution function (in this case 1), <math>M ×\times N</math> gives the image's number of pixels (for the example above 64, where <math>M</math> is width and <math>N</math> the height) and <math>L</math> 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'' <math>L-1</math>'', inclusive, the above equation would instead be:''
 
''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:''
 
:<math>
Line 298 ⟶ 293:
\mathrm{round}
\left(
\frac {\operatorname{cdfCDF}(v) - \operatorname{cdfCDF}_{\min}} {(M \times N) - \operatorname{cdfCDF}_{\min}}
\times (L - 2)
\right) + 1
</math>
''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:
Line 316 ⟶ 310:
</math>
 
For example, the cdfCDF of 78 is 46. (The value of 78 is used in the bottom row of the 7th column.) The normalized value becomes:
 
:<math>
Line 335 ⟶ 329:
</math>
 
Once this is done then the values of the equalized image are directly taken from the normalized cdfCDF to yield the equalized values:
 
{| class="wikitable"
Line 411 ⟶ 405:
|}
 
Notice that the minimum value (52) is now 0 and the maximum value (154) is now 255.
 
:{|