Dr. D. Y.
Patil Group of Institutions’ Technical Campus
Dr. D. Y. PATIL SCHOOL OF ENGINEERING
Dr. D. Y. Patil Knowledge City, Charholi Bk., Via. Lohegaon, Pune – 412 105.
Department of Electronics and Telecommunication Engineering
EXPERIMENT NO.3
To perform histogram equalization.
Date of Performance
Date of Checking
Digital Image and Video Processing Lab BE E&TC (2015 course) Sem-I
Dr. D. Y. Patil Group of Institutions’ Technical Campus
Dr. D. Y. PATIL SCHOOL OF ENGINEERING
Dr. D. Y. Patil Knowledge City, Charholi Bk., Via. Lohegaon, Pune – 412 105.
Department of Electronics and Telecommunication Engineering
Title: To perform histogram equalization and modification of given image.
Objectives:
To study histogram of various image.
To equalize and enhance histogram of given image
Aim: Write a program for histogram plotting and equalization.
Software: Scilab
Theory:
In addition to standard mathematical functions, it is sometimes advantageous to
construct a transfer function for a specific image. We desire a specific algorithm that gives
reproducible and optimal results. The most popular of these methods is called histogram
equalization. To understand it, we must begin with the image brightness histogram. The
conventional histogram plot shows the number of pixels in the image having each of the
256 possible values of stored brightness. Peaks in the histogram correspond to the more
common brightness values, which often correspond to particular structures that are
present. Valleys indicate brightness values that are less common in the image. The data can
also be plotted as a cumulative curve, which is simply the integral or summation of the
values. If this curve is used as the display transfer function, the result is a display in which
all of the available 256 brightness values are equally used. The histogram of this processed
image shows this uniform distribution and a linear cumulative plot. This procedure is
called histogram equalization.
Generally, images have unique brightness histograms. Even images of different
areas of the same sample or scene, in which the various structures present have consistent
brightness levels wherever they occur, will have different histograms, depending on the
area covered by each structure. Changing the overall illumination or camera settings will
shift the peaks in the histogram. In addition, most real images exhibit some variation in
brightness within features (e.g., from the edge to the center) or in different regions.
The objective of histogram equalization is to map an input image to an output image
such that its histogram is uniform after the mapping.
Let r represent the gray levels in the image to be enhanced and s is the enhanced output
with a transformation of the form s=T(r).
Digital Image and Video Processing Lab BE E&TC (2015 course) Sem-I
Dr. D. Y. Patil Group of Institutions’ Technical Campus
Dr. D. Y. PATIL SCHOOL OF ENGINEERING
Dr. D. Y. Patil Knowledge City, Charholi Bk., Via. Lohegaon, Pune – 412 105.
Department of Electronics and Telecommunication Engineering
Assumption:
1. T(r) is single-valued and monotonically increasing in the interval [0, 1], which preserves
the order from black to white in the gray scale.
2. 0 ≤ T(r) ≤1 for 0 ≤ r ≤1, which guarantees the mapping is consistent with the allowed
range of pixel values.
If 𝑃𝑟 (𝑟) and 𝑇(𝑟)are known and T-1(s) satisfies condition (a), the pdf of the transformed
gray levels is
𝑑𝑟
𝑃𝑠 (𝑠) = 𝑃𝑟 (𝑟) ⋮ −1 (𝑠)
𝑑𝑠 𝑟=𝑇
𝑟
If 𝑠 = 𝑇(𝑟) = ∫0 𝑃𝑟 (𝑤)𝑑𝑤 𝑓𝑜𝑟 0 ≤ 𝑟 ≤ 1, then we have
𝑑𝑠
= 𝑃𝑟 (𝑟) And hence 𝑃𝑠 (𝑠) = 1 𝑓𝑜𝑟 0 ≤ 𝑠 ≤ 1
𝑑𝑟
Using a transformation function equal to the cumulative distribution of r produces an
image whose gray levels have a uniform density, which implies an increase in the dynamic
range of the pixels. In order to be useful for digital image processing, equations should be
formulated in discrete form:
𝑛𝑘 𝑛𝑗
𝑃𝑟 (𝑟𝑘 ) = And 𝑆𝑘 = 𝑇(𝑟𝑘 ) = ∑𝑘𝑗=0 𝑤ℎ𝑒𝑟𝑒 𝑘 = 0,1,2 … … . . 𝐿 − 1
𝑛 𝑛
A plot of 𝑃𝑟 (𝑟𝑘 ) versus 𝑟𝑘 is actually a histogram, and the technique used for obtaining a
uniform histogram is known as histogram equalization or histogram linearization.
Algorithm:
1. Start
2. Read input image and convert it to gray scale.
3. Plot the image along with its original histogram using inbuilt function.
4. Consider the temporary array, say (temp[])and store values of number of pixels
having corresponding levels of intensity into this array with two nested for loops.
Initialized with respect to size of the image(M*N).
5. Divide the array (temp (i)) with the size of the image to obtain the normalized
histogram along with the probabilities of occurrences of gray scales.
6. Now perform cumulative addition for every value in the array i.e.
Digital Image and Video Processing Lab BE E&TC (2015 course) Sem-I
Dr. D. Y. Patil Group of Institutions’ Technical Campus
Dr. D. Y. PATIL SCHOOL OF ENGINEERING
Dr. D. Y. Patil Knowledge City, Charholi Bk., Via. Lohegaon, Pune – 412 105.
Department of Electronics and Telecommunication Engineering
𝑆𝑘 = 𝐺𝑚𝑎𝑥 ∑ 𝑃(𝑟𝑖)
𝑖=0
Where 𝑃(𝑟𝑖) = 𝑛𝑜𝑟𝑚𝑎𝑙𝑖𝑠𝑒𝑑 ℎ𝑖𝑠𝑡𝑜𝑔𝑟𝑎𝑚
𝐺𝑚𝑎𝑥 =maximum value of gray level present in the image.
7. Here 𝐺𝑚𝑎𝑥 =255 and to implement the above function, initialize a for loop with
respect to total number of gray levels (0-255).
8. Round off the decimal values to the closest gray level.
9. Display the histogram equalized image.
10. Also plot the histogram of this image and compare it with the histogram of original
image plotted in step 3.
11. End.
Conclusion:
Digital Image and Video Processing Lab BE E&TC (2015 course) Sem-I