Histogram equalization: Difference between revisions

Content deleted Content added
No edit summary
review: you don't want to use that first option. consistent terminology.
 
(2 intermediate revisions by 2 users not shown)
Line 25:
The ''back projection'' 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.<ref>{{cite manual|year=2001|title=Open Source Computer Vision Library Reference Manual|url=http://www.cs.unc.edu/~stc/FAQs/OpenCV/OpenCVReferenceManual.pdf|archive-url=https://web.archive.org/web/20150409155114/http://www.cs.unc.edu/~stc/FAQs/OpenCV/OpenCVReferenceManual.pdf|url-status=dead|archive-date=April 9, 2015|author=Intel Corporation|access-date=2015-01-11}}</ref><!--[[User:Kvng/RTH]]-->
 
==Implementation==
Consider a discrete [[Grayscale|grayscale image]] <math>X</math> and let <math>n_i</math> 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.
 
Let us then define the ''[[cumulative distribution function]]'' of pixels in image ''<math>X</math>''. For value ''<math>i</math>'' it is
Line 41:
:<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>:
:<math>\ k^\prime = k \cdot(\max(i) - \min(i)) + \min(i)= k \cdot(L- 1)</math><ref>{{web archive |url=https://web.archive.org/web/20200601000000*/https://www.math.uci.edu/icamp/courses/math77c/demos/hist_eq.pdf |title=University of California, Irvine Math 77C - Histogram Equalization}}</ref>
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
Line 53 ⟶ 52:
 
== On color images ==
The above-described histogram equalization works on a grayscale image. It can also be used on color images. One option is applying the method separately to the red, green and blue components of the [[RGB]] color values of the image, which likely produces 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|Lab]], or [[HSL and HSV|HSL/HSV]] in particular, then the algorithm can be applied to the [[luminance]] or value channel without resulting in changes to color properties 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><!--[[User:Kvng/RTH]]-->
 
The above describes histogram equalization on a grayscale image. 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, which may however 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. If the image is first converted to another color space, [[Lab color space|Lab]], or [[HSL and HSV|HSL/HSV]] 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>
 
==Examples==