# Histogram equalization

In this exercise we will try to balance out the spectrum of intensities in image.

A histogram is an accurate representation of the distribution of numerical data. It is an estimate of the probability distribution of a continuous variable (quantitative variable). To construct a histogram, the first step is to “bin” the range of values—that is, divide the entire range of values into a series of intervals—and then count how many values fall into each interval. The bins are usually specified as consecutive, non-overlapping intervals of a variable. The bins (intervals) must be adjacent, and are often (but are not required to be) of equal size.

First, a histogram for an image has to be computed. Histogram states how many pixels in an image have a particular value i. In our images, i ∈ (0, L], where L stands for number of brightness levels in the image. In our case, it is 256. A histogram value for a value i is given by number of pixel with intensity i:

*p(i) = Ni*

In probability theory and statistics, the cumulative distribution function (CDF, also cumulative density function) of a real-valued random variable X, or just distribution function of X, evaluated at x, is the probability that X will take a value less than or equal to x.

*Probability distributions examples*

To compute the CDF:

And finally we can equalize old values, into new image given my formula:

where h(v) is new value for old pixel with value v, cdf_min is the least non zero value element of cumulative distribution function and L represents the number of maximum values (For U8 = 256).

*Equalized Image*

*Sollution in LV*

Data | Value |
---|---|

Source | https://en.wikipedia.org/wiki/Histogram_equalizationhtt |

Code |