Histogram equalization: Difference between revisions

Content deleted Content added
start review: rm unused acro defs. reorder for flow. link improvements. clarifications.
Line 28:
 
==Implementation==
Consider a discrete [[Grayscale|grayscale image]] {''x''}<math>X</math> and let ''n<sub>i</sub>'' be the number of occurrences of gray level ''i''. The probability of ana occurrencepixel ofvalue achosen pixeluniformly ofrandomly levelfrom image <math>X</math> being ''i'' 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), ''nn_i'' being the total number of pixels in the image with value i, and <math>p_x(i)</math>''n'' being in fact the image'stotal histogramnumber forof pixelpixels valuein i,the normalized to [0,1]image.
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 alsothen define the ''[[cumulative distribution function]]'' correspondingof topixels in image ''X''. For value ''i'' 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>\ ki </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 {''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 transformed image value resultk:
:<math>\ yk^\prime = yk \cdot(\max\{x\}(i) - \min\{x\}(i)) + \min\{x\}(i)= yk \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.)
 
== Of color images ==