0% found this document useful (0 votes)
36 views27 pages

DIGITAL IMAGE PROCESSING Lecture Series 4-Spring 2023

Histogram equalization is a technique to enhance contrast in images by spreading out the most frequent intensity values. It works by calculating the cumulative distribution function (CDF) of the intensity levels and mapping them uniformly. This mapping spreads out the histogram over the entire intensity range. The main steps are: 1) Calculate the histogram, 2) Compute the CDF, 3) Map the CDF to new output intensity levels using the entire intensity range. Histogram equalization enhances contrast by spreading out the most frequent intensity values in the histogram over a wider range of values.

Uploaded by

Muhib U Rehman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views27 pages

DIGITAL IMAGE PROCESSING Lecture Series 4-Spring 2023

Histogram equalization is a technique to enhance contrast in images by spreading out the most frequent intensity values. It works by calculating the cumulative distribution function (CDF) of the intensity levels and mapping them uniformly. This mapping spreads out the histogram over the entire intensity range. The main steps are: 1) Calculate the histogram, 2) Compute the CDF, 3) Map the CDF to new output intensity levels using the entire intensity range. Histogram equalization enhances contrast by spreading out the most frequent intensity values in the histogram over a wider range of values.

Uploaded by

Muhib U Rehman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

CS457 DIGITAL IMAGE PROCESSING

Lecture Series 4
 Introduction to Histogram
 Histogram Equalization
https://m-wasim.wixsite.com/m-wasim DIGITAL IMAGE PROCESSING BY DR. M. WASIM 1
HISTOGRAM PROCESSING
 Histogram Equalization
 Histogram Matching
 Local Histogram Processing
 Using Histogram Statistics for Image Enhancement

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 2


HISTOGRAM PROCESSING
Histogram Equalization
 Histogram equalization is a technique for adjusting image
intensities to enhance contrast.
 It is done by spreading the histogram of an image uniformly
distributed.
 Histogram equalization is nothing but frequency distribution
plot.

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 3


HISTOGRAM PROCESSING
Histogram Equalization
 Advantages of histogram processing:
• Image enhancement
• Image statics
• Image Compression
• Image Segmentation

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 4


HISTOGRAM PROCESSING
Histogram h(rk )  nk
rk is the k th intensity value
nk is the number of pixels in the image with intensity rk
nk
Normalized histogram p( rk ) 
MN
nk : the number of pixels in the image of
size M  N with intensity rk

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 5


HISTOGRAM PROCESSING
The intensity levels in an image may be viewed as
random variables in the interval [0, L-1].
Let pr ( r ) and ps ( s) denote the probability density
function (PDF) of random variables r and s.

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 6


HISTOGRAM PROCESSING
s  T (r ) 0  r  L 1
a. T(r) is a strictly monotonically increasing function
in the interval 0  r  L -1;
b. 0  T (r )  L -1 for 0  r  L -1.

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 7


HISTOGRAM PROCESSING
s  T (r ) 0  r  L 1
a. T(r) is a strictly monotonically increasing function
in the interval 0  r  L -1;
b. 0  T (r )  L -1 for 0  r  L -1.

T (r ) is continuous and differentiable.

ps ( s)ds  pr (r )dr

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 8


HISTOGRAM PROCESSING

188 =[1011 1100]


192 =[1100 0000]
198 =[1100 0110]
173 =[1010 1101]
178 =[1011 0010]
174 =[1010 1110]
168 =[1010 1000]
168 =[1010 1000]
162 =[1010 0010]

2/8/2016 DIGITAL IMAGE PROCESSING BY M. WASIM & SYED FAISAL ALI 9


EXAMPLE: HISTOGRAM PROCESSING
Example: Perform histogram equalization

[ ]
44444
3 454 3
35553
3 454 3 =no. of pixels
44444 P()=Probability occurrence of intensity level
14 P()=
6
5
DIGITAL IMAGE PROCESSING BY DR. M. WASIM 10
HISTOGRAM PROCESSING
Table
Gray Running Running Sum/cdf Round Off New Values
Level Sum ()
0 0 0 0/25=0 0 0 0
1 0 0 0/25=0 0 0 0
2 0 0 0/25=0 0 0 0
3 6 6 6/25=0.24 1.68 2 2
4 14 20 20/25=0.8 5.6 6 6
5 5 25 25/25=1 7 7 7
6 0 25 25/25=1 7 7 7
7 0 25 (cdf) 25/25=1 7 7 7

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 11


New Gray level after
HISTOGRAM PROCESSING histogram
equalization
0 0
1 0
2 0
3 2
4 6
5 7
6 7
Original histogram New histogram 7 7

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 12


EXAMPLE: HISTOGRAM PROCESSING

[ ][ ]
44444 6666 6
3 454 3 2676 2
35553 = 27772
3 454 3 2676 2
44444 6666 6

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 13


EXAMPLE: HISTOGRAM PROCESSING
Perform histogram equalization

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 14


EXAMPLE: HISTOGRAM PROCESSING
Perform histogram equalization
I = imread('pout.tif');
J = histeq(I);
subplot(2,2,1);
imshow( I );
subplot(2,2,2);
imhist(I) subplot(2,2,3);
imshow( J ); subplot(2,2,4);
imhist(J)

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 15


HISTOGRAM EQUALIZATION
Histogram equalization: is a technique for adjusting image intensities to enhance
contrast. Let f be a given image represented as a mr by mc matrix of integer pixel
intensities ranging. from 0 to L − 1. L is the number of possible intensity values,
often 256.

2/8/2016 DIGITAL IMAGE PROCESSING BY M. WASIM & SYED FAISAL ALI 16


HISTOGRAM EQUALIZATION
We need 6 steps
Step 1:
1. Find the frequency of each pixel value.
Consider an image matrix (Im) =
Find the number of occurrences of each value.
Example: Pixel value of 1 occurs 3 times, similarly pixel value of 2 is 2, 3 is 1, 4 is
2 and 5 is 1.

2/8/2016 DIGITAL IMAGE PROCESSING BY M. WASIM & SYED FAISAL ALI 17


HISTOGRAM EQUALIZATION
Step 2:
Find the probability of each frequency.
The pixel value of 1 occurrences = frequency (1)/no. of pixels.
Example:
For pixel value 1 frequency = 3/9 = 0.333
Solve for all the values

2/8/2016 DIGITAL IMAGE PROCESSING BY M. WASIM & SYED FAISAL ALI 18


HISTOGRAM EQUALIZATION
Step 3:
Find the Cumulative Histogram of each Pixel:
The cumulative histogram of 1 = 3.
Cumulative histogram of 2 = cumulative histogram of 1 + frequency of 2 = 3+2 = 5
Cumulative histogram of 3 = cumulative histogram of 2 + frequency of 3 = 5+1 = 6
Cumulative histogram of 4 = cumulative histogram of 3 + frequency of 4 = 6+2 = 8
Cumulative histogram of 5 = cumulative histogram of 4 + frequency of 5 = 8+1 = 9

2/8/2016 DIGITAL IMAGE PROCESSING BY M. WASIM & SYED FAISAL ALI 19


HISTOGRAM EQUALIZATION
Step 4:
Find the cumulative distribution probability of each pixel.
(cdf) of 1 = cumulative histogram of 1/no. of pixels = 3/9.
Find each pixel value.
(cdf) of 2 = cumulative histogram of 2/no. of pixels = 5/9.
(cdf) of 3 = cumulative histogram of 3/no. of pixels = 6/9.
(cdf) of 4 = cumulative histogram of 4/no. of pixels = 8/9.
(cdf) of 5 = cumulative histogram of 5/no. of pixels = 9/9.

2/8/2016 DIGITAL IMAGE PROCESSING BY M. WASIM & SYED FAISAL ALI 20


HISTOGRAM EQUALIZATION
Step 5:
Calculate the final value of each pixel by multiply cdf with no. of bins.
cdf of 1 = (3/9)*(5) = 0.333 * 5 = 1.66
Round off the values.
Therefore cdf of 1 = 2
2 = 0.5 *5 = 2.7 = 3
3 = 0.66 * 5 = 3.3 = 3
4 = 0.88 * 5 = 4.44 = 4
5=1*5=5
2/8/2016 DIGITAL IMAGE PROCESSING BY M. WASIM & SYED FAISAL ALI 21
HISTOGRAM EQUALIZATION
Step 6:
Now replace the final values : Original image matrix (Im) =

Plot the matrix and compare with the initial.


Intensity and its occuranc
3.5

3
frequency
2.5
3.5
3 2

2.5 1.5
2
1
1.5
1 0.5

0.5 0
1 2 3 4 5
0
2 3 4 5

2/8/2016 DIGITAL IMAGE PROCESSING BY M. WASIM & SYED FAISAL ALI 22


PRACTICE HISTOGRAM
EQUALIZATION
a) Verify your answer by
making excel sheet and
MATLAB Code and plot
both graph.
b) Compare the graphs and
comment.

2/8/2016 DIGITAL IMAGE PROCESSING BY M. WASIM & SYED FAISAL ALI 23


GRAY SCALE INTENSITY
(i,j) – a]
Of Image I(x,y) is defined as
20 100 50 160 200
50 30 65 45 90 Matrix I(i,j)
80 100 50 35 65
90 80 70 160 40
80 100 90 20 30

2/8/2016 DIGITAL IMAGE PROCESSING BY M. WASIM & SYED FAISAL ALI 24


GRAY SCALE INTENSITY
Here a = 20 (minimum intensity present in image)
b = 200 (maximum intensity present in image)
K = 0 – (k-1) = 256-1 = 255
For J(0,3) = *[I(0,3)-20]
=
=1.41* 140 = 197.55
Similarly find J(0,3), J(1,2), J(2,0), J(2,4), J(3,3), J(4,0), J(4,2)
Update matrix image I(i,j)

2/8/2016 DIGITAL IMAGE PROCESSING BY M. WASIM & SYED FAISAL ALI 25


GRAY LEVEL
TRANSFORMATION
20 100 50 160 200
50 30 65 45 90
r = input gray scale (reference) Matrix 1 80 100 50 35 65
c = scaling factor =1 90 80 70 160 40
80 100 90 20 30
Ύ = 0.02
Sol: r =I(i,j) -> Select from image matrix(Im)and solve S.
S0 = 1 (160)^ 0.02 = 106834
S1 = 1(200)^0.02 = 1.11178
S2 = 1(65)^0.02 = 1.08070
Solve for all the other grayscale values
2/8/2016 DIGITAL IMAGE PROCESSING BY M. WASIM & SYED FAISAL ALI 26
EXAMPLE: HISTOGRAM PROCESSING
Is histogram equalization always good?

No

DIGITAL IMAGE PROCESSING BY DR. M. WASIM 27

You might also like