Histogram equalization: Difference between revisions

Content deleted Content added
.
Tag: Reverted
review: you don't want to use that first option. consistent terminology.
 
(29 intermediate revisions by 11 users not shown)
Line 3:
{{Use American English|date=March 2021}}
{{Use mdy dates|date=March 2021}}
[[Image:Histogrammeinebnung.png|thumb|right|300px|alt=A histogram which is zero apart from a central area containing strong peaks is transformed by stretching the peaked area to fill the entire x-axis.|Histograms of an image before and after equalization.]]
 
'''Histogram equalization''' is a method in [[image processing]] of [[contrast (vision)|contrast]] adjustment using the [[image]]'s [[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]]).
[[Image:Histogrammeinebnung.png|thumb|right|300px|alt=A histogram which is zero apart from a central area containing strong peaks is transformed by stretching the peaked area to fill the entire x-axis.|Histograms of an image before and after equalization.]]
 
==Overview==
This method usually increases the global [[contrast (vision)|contrast]] of many images, especially when the image is represented by a narrow range of intensity values. Through this adjustment, the [[luminous intensity|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 usedtend to degrade image contrast.Çağrı...Fevzii... mehdix
 
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 [[photographsphotograph]]s 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 (mathematics)|operatoroperation]]. So, in theory, if the histogram equalization [[function (mathematics)|function]] is known, then the original histogram can be recovered. The calculation is not [[computation]]ally intensive. A disadvantage of the method is that it is indiscriminate. It may increase the contrast of background [[signal noise|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.
 
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 (mathematics)|operator]]. So in theory, if the histogram equalization [[function (mathematics)|function]] is known, then the original histogram can be recovered. The calculation is not [[computation]]ally intensive. A disadvantage of the method is that it is indiscriminate. It may increase the contrast of background [[signal noise|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 [[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 betterpreferred 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 limitinglimited 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 modifying the algorithm to improve the contrast without producing brightness mean-shift and detail loss artifacts by modifying the HE algorithm.<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>
 
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]].<ref>{{cite journal|last=Laughlin|first=S.B|year=1981|title=A simple coding procedure enhances a neuron's information capacity|journal=Z. Naturforsch.|volume=9–10(36):910–2}}</ref>
 
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.<ref>{{cite journalmanual|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>
 
==Implementation==
Consider a discrete [[Grayscale|grayscale image]] {''x''}<math>X</math> and let ''n<submath>in_i</submath>'' be the number of occurrences of gray level ''<math>i''</math>. The probability of ana occurrencepixel ofvalue achosen pixeluniformly ofrandomly levelfrom image <math>X</math> being ''<math>i</math>'' in the image, is
:<math>\ p_xp_X(i) = 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), ''n<math>n_i</math>'' being the total number of pixels in the image with value ''<math>i</math>'', and <math>p_x(i)n</math> being the total number of pixels in factthe image. Then <math>p_X(i)</math> is the image's histogram for pixel value for ''<math>i</math>'', with the histogram normalized to [0,have a total area of 1].
 
Let us alsothen define the ''[[cumulative distribution function]]'' correspondingof topixels in image ''<math>X</math>''. For value ''<math>i</math>'' asit is
:<math>\operatorname{cdf}_x_X(i) = \sum_{j=0}^i p_xp_X(x=j)</math>,
which is also the image's accumulated normalized histogram.
 
We would like to create a transformation of the form <math>\ y=T(x):[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_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]]);. itIt is defined as
:<math>\ y = T(ki) = \operatorname{cdf}_x_X(ki)</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 {''x''}<math>X</math>. In order to map the values back into their original range, the following simple transformation needs to be applied onto theeach resulttransformed image value <math>k</math>:
where <math>\ k </math> is in the range <math> [0,L-1]) </math>.
A:<math>\ morek^\prime detailed= derivationk is\cdot(\max(i) provided- in\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>
Notice that <math>\ T </math> 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:
:<math>\ y^\prime = y \cdot(\max\{x\} - \min\{x\}) + \min\{x\}= y \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>\ yk </math> is a real value while <math>\ yk^\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>\ yk^\prime = \operatorname{round} (yk \cdot(L- 1))</math>.
However, detailed analysis results in slightly different formulation. The mapped value <math>\ yk^\prime </math> should be 0 for the range of <math>0<yk \leq1/L</math>. And <math>\ yk^\prime =1</math> for <math>1/L < yk \leq 2/L</math>, <math>\ yk^\prime = 2 </math> for <math>2/L < yk \leq 3/L</math>, ...., and finally <math>\ yk^\prime =L-1</math> for <math>(L-1)/L < yk \leq 1</math>. Then the quantization formula from <math>\ yk</math> to <math>\ yk^\prime </math> should be
 
<math>yk^\prime=\operatorname{ceil}(L \cdot yk)-1 </math>.
 
(Note: <math>yk^\prime=-1 </math> when <math>\ yk=0 </math> , however, it does not happen just because <math>\ yk=0 </math> means that there is no pixel corresponding to that value.)
 
== OfOn color images ==
The above describes-described histogram equalization works on a grayscale image. However itIt can also be used on color images. byOne option is 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 an RGB imagewhich maylikely yieldproduces 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 color space]] in particular, then the algorithm can be applied to the [[luminance]] or value channel without resulting in changes to the hue andcolor saturationproperties 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]]-->
 
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, itwhich resultsresult 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 cdfCDF defined by the isoISO-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>
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 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. 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 144 ⟶ 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 201 ⟶ 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 279 ⟶ 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 287 ⟶ 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 301 ⟶ 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 319 ⟶ 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 338 ⟶ 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 414 ⟶ 405:
|}
 
Notice that the minimum value (52) is now 0 and the maximum value (154) is now 255.
 
:{|