Machine_Learning_Course_Shashi_Lecture_03
Machine_Learning_Course_Shashi_Lecture_03
Shashikant Dugad,
IISER Mohali
● For a given original image, obtain intensity histogram, n = h(I), where, a) n is number of
pixels having intensity I and b) range of intensity is 0<= I < (2m - 1) èTotal # of bins in
histogram are (2m - 1)
○ Note: ∑ 𝒏 = ∑ 𝒉(𝑰) = 𝑵𝟐
𝒏
● Probability of a pixel having intensity I is: 𝒑 𝑰 = 𝑵𝟐
where, ∑ 𝒑(𝑰) = 𝟏
● The above two conditions make T(I) a bijective function, thus inversible
○ Therefore, there exist a function that provides, I = T-1(I’)
● Cumulative Distribution Function (CDF) for input image can be defined as:
𝑰 𝑰
𝟏
𝑭𝒓 𝑰 = 𝑷(𝒓 ≤ 𝑰) = * 𝒑𝒓 𝒊 = 𝟐 * 𝒏𝒊
𝑵
𝒊,𝟎 𝒊,𝟎
We put the first condition of T(r) precisely to make the above step hold true. The second
condition is needed as s is the intensity value for the output image and so must be between o
and (L-1).
So, a pdf of s can be obtained by differentiating FS( x ) with respect to x. We get the following
relation:
ps (s) = pr (r) dr
ds
The above step used Leibnitz’s integral rule. Using the above derivative, we get:
ps (s) = pr (r) dr
ds
= pr (r) 1
(L−1)pr (r)
= 1
L−1
Now, we extend the above continuous case to the discrete case. The natural replacement of the
integral sign is the summation. Hence, we are left with the following histogram equalization
transformation function.
(L−1)
sk = T (rk ) = (L − 1) ∑kj=0 pr (rj ) = N2
∑kj=0 nj
Since s must have integer values, any non-integer value obtained from the above function is
rounded off to the nearest integer.
Figure 4.2: The original image has very poor contrast since the gr
A: Original
are in a very small range. Histogram scaling improves the contrast b
gaps in the final histogram. Top: Original
B: Histogram Scaling image and histogram.
Image and resulting histogram after histogram scaling.
C: Histogram Equalization
find the value k2 such that
C Shashikant R.
k2-1 k2 8
3:The
Theoriginal
originalimage
image has
has very
very poor
poor contrast
contrast theDugad,
since the
since grayIISER
gray Mohali
values
values
.L Pi :::; ql + q2 < .L Pi.
Image before and after Histogram Equalization
https://en.wikipedia.org/wiki/Histogram_equalization
Source:
Shashikant R. Dugad, IISER Mohali 9
n g
d i
h ol
e s
h r
T
● Normal Thresholding:
● Otsu Thresholding
M(i, j) = P(i, j) if pixel intensity P(i, j) > p0
● Regional Thresholding:
M(i, j) = P(i, j) if pixel intensity p0 < P(i, j) < p1
M(i, j) = 0 if pixel intensity P(i, j) <= p0 || P(i, j) >= p1
3. Visit each pixel assigned to region R2. If the pixel has a neighbour in region
R1, then reassign the pixel to region R1
'500
3500
3000
25001
1
. .
(c)
87
(d)
.
(c) (d)
(a) (b)
(a)
2 3 4
(d)
(b)
Figure 3.10: The building of a quad tree. (a) Original image, "gray region."
(d)
(b) Original split into four subregions (the left node in the tree corresponds to
the top left region in the image). Note that two of these regions are also gray
regions. (c) Splitting the gray regions from (b) into four subregions. One of
Figure 3.10: The building of a quad tree. (a)is Original
these regions image,
still a gray region. "gray
(d) Splitting of the region."
last gray region and
the final quad tree.
(b) Original split into four subregions (the left node in the tree corresponds to
the top left region in the image). Note that two of these regions are also gray
regions. (c) Splitting the gray regions from (b) into four subregions. One of
these regions is still a gray region. (d) Splitting of the last gray region and
the final quad tree. Shashikant R. Dugad, IISER Mohali 17
Otsu Thresholding Algorithm
● Source: https://en.wikipedia.org/wiki/Otsu%27s_method
● The algorithm returns a single intensity threshold that separate pixels into
two classes, foreground and background.
● Weights ω0 and ω1 are the probabilities of the two classes separated by a threshold t, σ02
and σ12 are variances in each of of these two classes
𝐭'𝟏 𝐋'𝟏
𝐧𝐢
𝐩 𝐢 = . 𝛚𝟎 𝐭 = 2 𝐩 𝐢 . 𝐚𝐧𝐝. 𝛚𝟏 𝐭 = 2 𝐩 𝐢 𝐚𝐧𝐝. 𝛚𝟎 𝒕 + 𝛚𝟏 𝐭 = 𝟏
𝐍𝐱𝐌
𝐢%𝟎 𝐢%𝐭
which is expressed in terms of class probabilities and class means , where the class me
● μ0, μ1 and μT are the means of regions a) below threshold t, b) above threshold t and
, and are:
entire region respectively,
● Step 2: Obtain ω0, ω1, μ0 and μ1 (hence σb) at each intensity value of t
varying between 0 to L-1
● Select that value of t as the final threshold at which σb(t) has maximum
value
dof
Shashikant R. Dugad, IISER Mohali 22
ively searches for the threshold that
Adaptive Thresholding
Ø ADAPTIVE_THRESH_MEAN_C:
Threshold value is the mean of
neighbourhood area.
Ø ADAPTIVE_THRESH_GAUSSIAN_C:
Threshold value is the weighted sum of
neighbourhood values where weights
are a gaussian window.