Beruflich Dokumente
Kultur Dokumente
Histogram Processing
Histogram: It is a plot of frequency of occurrence of an event.
freq. of occurrence
event
Histogram Processing
Histogram of images provide a global description of their appearance.
Enormous information is obtained. It is a spatial domain technique. Histogram of an image represents relative frequency of occurrence of various gray levels. Histogram can be plotted in two ways:
Histogram Processing
First Method: X-axis has gray levels & Y-axis has No. of pixels in each gray levels.
Gray Level
0 1 2 3 4 5 6
nk 40 30
20
10
3 Gray Levels
Histogram Processing
Second Method: X-axis has gray levels & Y-axis has probability of occurrence of gray levels. P(k) = nk / n; where, k gray level nk no. of pixels in kth gray level n total number of pixels in an image
Prob. Of Occurrence 1 Gray Level No. of Pixels (nk) 0 40 1 20 2 10 3 15 4 10 5 3 6 2 n = 100 P(k) 0.4 0.2 0.1 0.15 0.1 0.03 0.02 1
Histogram Processing
Advantage of 2nd method: Maximum value plotted will always be 1. White 1, Black 0. Great deal of information can be obtained just by looking at histogram. Types of Histograms:
P(k) P( k)
rk
rk
P(k)
P( k)
rk
rk
Histogram Processing
Advantage of 2nd method: Maximum value plotted will always be 1. White 1, Black 0. Great deal of information can be obtained just by looking at histogram. Types of Histograms:
P(k) Dark Image P( k) Bright Image
rk
rk
P(k)
P( k)
Equalized Image
rk
rk
Histogram Processing
The last graph represent the best image. It is a high contrast image. Our aim would be to transform the first 3 histograms into the 4th type. In other words we try to increase the dynamic range of the image.
Histogram Stretching
1) Linear stretching: Here, we dont alter the basic shape. We use basic equation of a straight line having a slope. (Smax - Smin)/(rmax - rmin) Where, Smax max gray level of output image Smin min gray level of output image rmax max gray level of input image rmin min gray level of input image
0 min
max
0 min
max
Histogram Processing
S = T(r) = ((Smax - Smin)/(rmax - rmin))(r - rmin) + Smin
Smax
Smin
rmin
rmax
Histogram Processing
Ex. 1) Perform Histogram Stretching so that the new image has a dynamic range of 0 to 7 [0, 7]. Gray Levels No. of Pixels 0 0 1 0 2 50 3 60 4 50 5 20 6 10 7 0
Histogram Processing
Ex. 1) Perform Histogram Stretching so that the new image has a dynamic range of 0 to 7 [0, 7]. Gray Levels No. of Pixels Soln:rmin = 2; 0 0 1 2 3 4 5 20 6 10 7 0
0 50 rmax = 6; smin = 0;
60 50 smax = 7;
slope = ((smax smin)/(rmax - rmin)) = ((7 - 0)/(6 - 2)) = 7 / 4 = 1.75. S = (7 / 4)(r - 2) + 0; S = (7 / 4)(r - 2) r
2 3 4 5 6
(7 / 4)(r - 2) = S
0 =0 7/4 = 1.75 = 2 7/2 = 3.5 = 4 21/4 = 5.25 = 5 7 =7
Histogram Processing
Ex. 1) Perform Histogram Stretching so that the new image has a dynamic range of 0 to 7 [0, 7]. Gray Levels No. of Pixels 0 50 1 0 2 60 3 0 4 50 5 20 6 0 7 10
60 50 40 30
20 10 0 1 2 3 4 5 6 7
60 50 40 30
20 10 0 1 2 3 4 5 6 7
Histogram Processing
Ex. 2) Perform Histogram Stretching so that the new image has a dynamic range of 0 to 7 . Gray Levels No. of Pixels 0 100 1 90 2 85 3 70 4 0 5 0 6 0 7 0
Histogram Processing
Ex. 2) Perform Histogram Stretching so that the new image has a dynamic range of 0 to 7 . Gray Levels No. of Pixels 0 100 1 0 2 90 3 0 4 0 5 85 6 0 7 70
Histogram Equalization
2) Histogram Equalization:
o Linear stretching is a good technique but not perfect since the shape remains the same.
o Most of the time we need a flat histogram. o It cant be achieved by Histogram Stretching. o Thus, new technique of Histogram Equalization came into use. o Perfect image is one where all gray levels have equal number of pixels. o Here, our objective is not only to spread the dynamic range but also to have equal pixels at all gray levels.
Histogram Equalization
nk
Normal Histogram
Histogram Equalization
o We have to search for a transform that converts any random histogram into flat histogram. o S = T(r) o We have to find T which produces equal values in each gray levels. o The Transform should satisfy following 2 conditions: (i) T(r) must be single value & monotonically increasing in the interval, 0 r 1.
(ii)
0 T(r) 1 for 0 r 1 0 S 1 for 0 r 1 Here, range of r is [0, 1] (Normalized range) instead of [0, 255].
Histogram Equalization
These two conditions mean:
1)
T(r)
S S2
T(r)
S1
S1
r1 fig. (a)
r2
r1 fig. (b)
r2
Histogram Equalization
In fig.(a) r1 & r2 are mapped as single gray level i.e. S1.
Two different gray levels occupy same in modified image. Big Drawback! Hence, transformation has to be single value. This preserves order from black to white. A gray level transformation with single value and monotonically increasing is shown in fig.(b).
2) If condition (ii) is not satisfied then mapping will not be consistent with the allowed range of pixel value. S will go beyond the valid range.
Histogram Equalization
Since, the Transformation is single value & monotonically increasing, the inverse Transformation exists. r = T-1(S) ; 0 S 1 Gray levels for continuous variables can be characterized by their probability density Pr(r) & Ps(S).
From Probability theory, we know that, If Pr(r) & Ps(S) are known & if T-1(S) satisfies condition (i) then the probability density of the transferred gray level is
Ps(S) = [Pr(r). dr/ ds] r = T-1(S) ----(a) Prob. Density (Original Image) x inv. Slope of transformation
Histogram Equalization
Now lets find a transform which would give us a flat histogram.
Cumulative Density Function (CDF) is preferred. CDF is obtained by simply adding up all the PDFs. S = T(r)
r
S = Pr(r) dr ; 0 r 1
0
diff. wrt. r
ds / dr = Pr(r) Equating eqn(a) & eqn(b), we get Ps(s) = *1+ ; 0 S 1 i.e. Ps(s) = 1 ---------(b)
Histogram Equalization
A bad Histogram becomes a flat histogram when we find the CDF.
Pr(r) 1
CDF Pr(r) dr
Ps(s) 1
0 1 f Non-Uniform Function
0 1 S Uniform Function
Histogram Equalization
NOTE: If n is total no. of pixels in an image, then PDF is given by:
S = T(r) = Pr(rk) dr
0
In discrete domain,
r
Sk = T(rk) =
k=0
Pr(rk) (CDF)
Histogram Equalization
Prob. 1) Equalize the given histogram
3 656
4 329
5 245
122 81
900
800 700 600 500 400 300 200 100 0 1 2 3 4 5 6 7 r
Histogram Equalization
Gray Levels (rk) 0 1 2 No. of Pixels nk 790 1023 830 (PDF) Pr(rk) = nk/n 0.19 0.25 0.21 (CDF) Sk = Pk(rk) 0.19 0.44 0.65 (L-1) Sk = 7 x Sk 1.33 3.08 4.55 Rounding off 1 3 5
3 4
5 6 7
656 329
245 122 81
0.16 0.08
0.06 0.03 0.02
0.81 0.89
0.95 0.98 1
5.67 6.23
6.65 6.86 7
6 6
7 7 7
n = 4096
Equating Gray Levels to No. of Pixels: 0 -> 0 4 -> 0 1 -> 790 5 -> 850 2 -> 0 6 -> 985 3 -> 1023 7 -> 448 Total : 4096
Hence Verified!!!
Histogram Equalization
Equalized Histogram:
0 0
1 790
2 0
3 1023
4 0
nk 1000
900
800 700 600 500 400 300 200 100 0 1 2 3 4 5 6 7 r
Histogram Equalization
Prob. 2) Equalize the given histogram
0 100
1 90
2 50
3 20
4 0
5 0
6 0
7 0
90
80 70 60 50 40 30 20 10 0 1 2 3 4 5 6 7 r
Histogram Equalization
Prob. 3) Equalize the above histogram twice.
0 0
1 0
2 0
3 100
4 0
5 90
6 50
7 20
90
80 70 60 50 40 30 20 10 0 1 2 3 4 5 6 7 r
Histogram Equalization
Prob. 3) Equalize the above histogram twice.
0 70
1 20
2 7
3 3
90
80 70 60 50 40 30 20 10 0 1 2 3 r
Histogram Equalization
Prob. 1) What effect would setting to zero the lower order bit plane have on the histogram of an image shown? 0 4 1 5 2 6 3 7
no. of pixels 1
8 12
9 13
10 14
11 15
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 no. of levels
Histogram Equalization
Prob. 1) What effect would setting to zero the lower order bit plane have on the histogram of an image shown? 0 4 1 5 2 6 3 7
8 12
9 13
10 14
11 15
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
Histogram Equalization
Prob. 1) What effect would setting to zero the lower order bit plane have on the histogram of an image shown? 0 4 1 5 2 6 3 7
8 12
9 13
10 14
11 15
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
0000
0000
0000
0000
1100
1101
1110
1111
0100
0100
0100
0100
1000
1000
1000
1000
1100
1100
1100
1100
Histogram Equalization
Prob. 1) What effect would setting to zero the lower order bit plane have on the histogram of an image shown? 0 0 0 0 0 1 2 3 4 4 4 4 4 5 6 7 8 8 8 8 8 9 10 11 0000 0001 0010 0011 12 12 12 12 12 13 14 15 0100 0101 0110 0111
1000 1001 1010 1011 0000 0000 0000 0000
1100
1101
1110
1111
0100
0100
0100
0100
1000
1000
1000
1000
1100
1100
1100
1100
Histogram Equalization
Prob. 1) What effect would setting to zero the lower order bit plane have on the histogram of an image shown? 0 0 0 0 0 1 2 3 4 4 4 4 4 5 6 7 8 8 8 8 8 9 10 11 12 12 12 12 12 13 14 15
0000 0000 0000 0000
4
0100 0100 0100 0100
no. of pixels
1000
1000
1000
1000
1100
1100
1100
1100
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 no. of levels
Histogram Equalization
Prob. 2) What effect would setting to zero the higher order bit plane have on the histogram of an image shown? Comment on the image. 0 4 1 5 2 6 3 7
8 12
9 13
10 14
11 15
Histogram Equalization
Prob. 3) Given below is the slope transformation & the image. Draw the frequency tables for the original & the new image. Assume Imin=0, Imax = 7 2 5 3 5 4 2 2 4 I
3 6
6 3
3 5
5 5
Imax
Imin
mmin
mmax
Frequency Domain
2-D Discrete Fourier Transform & Its Inverse:
If f(x, y) is a digital image of size M X N then its Fourier Transform is given by:
M-1 N-1
F(u, v) =
x=0 y=0
-----------(1)
for u = 0, 1, 2, ., M-1 & v = 0, 1, 2, .., N-1. Given the transform F(u, v), we can obtain f(x, y) by using Inverse discrete Fourier Transform (IDFT):
M-1 N-1
f(x, y) = (1/MN)
u=0 v=0
------------(2)
for x = 0, 1, 2, .M-1 & y = 0, 1, 2, .., N-1 Eqn. (1) & (2) constitute the 2-D discrete Fourier transform pair.
Frequency Domain
2-D convolution Theorem:
f(x, y)*h(x, y) =
m=0 n=0
-----------(3)
for x = 0, 1, 2, .M-1 & y = 0, 1, 2, ..N-1 The 2-D convolution theorem is given by the expressions f(x, y) h(x, y)
and conversely f(x, y) x h(x, y) F(u, v) H(u, v) ---------------(5)
F(u, v) x H(u, v)
--------------(4)
Frequency Domain
Prob 4) Find the convolution of an image x(m, n) & h(m, n) shown in the fig. below: y(p, q) = x(m1, n1) h(m2, n2)
0 -1 0
-1 4 -1
1 -1 0
3x3 (m, n)
1 1
1 -1
2x2 (m, n)
Frequency Domain
Prob 4) Find the convolution of an image x(m, n) & h(m, n) shown in the fig. below: y(p, q) = x(m1, n1) h(m2, n2)
0 -1 0
-1 4 -1
1 -1
origin
1 1
1 -1
2x2 (m2, n2)
0
3x3 (m1, n1)
p = m1 + m2 -1 = 3 + 2 -1 = 4 columns
q = n1 + n2 -1 = 3 + 2 -1 = 4 rows
Frequency Domain
x(m, n) 1
-1 0
0 -1 0
-1 4 -1
1 1
h(m, n) 1
-1
1 -1
h(m, -n) 1
1 -1
h(-m, -n)
Frequency Domain
x(m, n) 1
-1 0 -1 1 1 1
h(-m, -n)
0 -1 0
-1 4 -1
y(0, 0)
Frequency Domain
x(m, n) 1
-1 0 -1 1 1 1
h(1-m, -n)
0 -1 0
-1 4 -1
y(1, 0)
-6
Frequency Domain
x(m, n) 1
-1 0 0 0 -1 1
h(2-m, -n)
0 -1 0
-1 4 -1
1 1
y(2, 0)
-6
Frequency Domain
x(m, n) 1
-1 0 0 0 0 0
h(3-m, -n)
0 -1 0
-1 4 -1
-1 1
1 1
y(3, 0)
-6
Frequency Domain
x(m, n) 1
-1 0
h(-m, 1-n)
-1 1 1 1
0 -1 0
-1 4 -1
y(0, 1)
-6
Frequency Domain
x(m, n) 1
-1 0
h(-m, 2-n)
-1 1 0 1 1 0
0 -1 0
-1 4 -1
y(0, 2)
-1 2
-6
Frequency Domain
x(m, n) 1
-1 0 -1 1 1 1
h(1-m, 1-n)
0 -1 0
-1 4 -1
y(1, 1)
-1 2 5
-6
Frequency Domain
x(m, n) 1
-1 0
h(1-m, 2-n)
-1 1 0 1 1 0
0 -1 0
-1 4 -1
y(1, 2)
-1 2
0 5
-6
Frequency Domain
x(m, n) 1
-1 0 0 0 -1 1
h(2-m, 1-n)
0 -1 0
-1 4 -1
1 1
y(2, 1)
-1 2
0 5 -2
-6
Frequency Domain
x(m, n) 1
-1 0
0 -1 0
-1 4 -1
0 0 0
-1 1 0
h(2-m, 2-n) 1
1 0
y(2, 2)
-1 2
0 5
1 -2
-6
Frequency Domain
x(m, n) 1
-1 0
h(-1-m, -n)
-1 1 1 1
0 -1 0
-1 4 -1
y(-1, 0)
-1 2
0 5
1 -2
-1
-6
Frequency Domain
x(m, n) 1
-1 0
h(-1-m, 1-n)
-1 1 1 1
0 -1 0
-1 4 -1
y(-1, 1) -1
-1 2
0 5
1 -2
-1
-6
Frequency Domain
x(m, n) 1
-1 0
h(-1-m, 2-n)
-1 1 0 1 1 0
0 -1 0
-1 4 -1
y(-1, 2)
0 -1
-1 2
0 5
1 -2
-1
-6
Frequency Domain
x(m, n) 1
-1 0
h(-1-m, -1-n)
-1 1 1 1
0 -1 0
-1 4 -1
y(-1, -1)
0 -1
-1 2
0 5
1 -2
-1 0
-6
Frequency Domain
x(m, n) 1
-1 0
h(-m, -1-n)
-1 1 1 1
0 -1 0
-1 4 -1
y(0, -1)
0 -1
-1 2
0 5
1 -2
-1 0
4 -1
-6
Frequency Domain
x(m, n) 1
-1 0
h(1-m, -1-n)
-1 1 1 1
0 -1 0
-1 4 -1
y(1, -1)
0 -1
-1 2
0 5
1 -2
-1 0
4 -1
-6 1
Frequency Domain
x(m, n) 1
-1 0
h(2-m, -1-n)
0 0 -1 1 1 1
0 -1 0
-1 4 -1
y(2, -1)
0 -1
-1 2
0 5
1 -2
-1 0
4 -1
-6 1
1 0
Frequency Domain
x(m, n) 1
-1 0
h(-m, -n)
-1 1 1 1
0 -1 0
-1 4 -1
y(m, n)
0 -1
-1 2
0 5
1 -2
-1 0
4 -1
-6 1
1 0
Frequency Domain
Homomorphic Filtering: Illumination-Reflectance model for an image f(x, y) is given by: f(x, y) = i(x, y)r(x, y) ------------(1) where, i(x, y) illumination r(x, y) reflectance
It is used to develop a frequency domain procedure for improving image appearance by : (i) simultaneous intensity range compression and (ii) contrast enhancement.
Eqn (1) cant be directly operated on the frequency components of illumination & reflectance This is because F*f(x, y)+ F*i(x, y)]F[r(x, y)]
Frequency Domain
Then F{z(x, y)} = F{ln f(x, y)} = F{ln i(x, y)} + F{ln r(x, y)} Or Z(u, v) = Fi(u, v) + Fr(u, v) Where Fi(u, v) & Fr(u, v) are FT of ln i(x, y) & r(x, y) resp. We can filter Z(u, v) by using a filter H(u, v) so that S(u, v) = H(u, v)Z(u, v) = H(u, v) Fi(u, v) + H(u, v) Fr(u, v) Filtered image in spatial domain is s(x, y) = F-1{S(u, v)} = F-1{H(u, v) Fi(u, v)} + F-1{H(u, v) Fr(u, v)}
Frequency Domain
Defining
r(x, y) = F-1{H(u, v) Fr(u, v)} We can express it in form s(x, y) = i(x, y) + r(x, y) Finally, we reverse the process by taking the exponential of the filtered result to form the output image: g(x, y) = es(x, y) = ei(x, y) er(x, y) = i0(x, y) r0(x, y)
Where, i0(x, y) & r0(x, y) are the illumination and reflectance components of the output (processed) image.
Frequency Domain
f(x, y)
ln DFT H(u, v) (DFT)-1 exp
g(x, y)
This method is based on special case of a class of systems known as Homomorphic systems.
Q.2) Why an ideal LPF not suitable for smoothing operation? Explain how the Gaussian LPF overcomes the drawback of ideal LPF.
Q.3) Write in short about Minimum Mean Square Error (Wiener) filtering. Q.4) Suppose F(u, v) is a 2D Fourier transform of an image f(x, y) and a new function G(u, v) is obtained as G(u, v) = f(u/2, v/2). What would be the image g(x, y) after taking the Inverse Fourier transform of G(u, v)? Q.5) Write a short note on Histogram Equalization. Q.6) Write a short note on Bit Plane Slicing.
700 1350
Compute the Gray level histogram of the output image obtained by enhancing the input by histogram equalization technique. [7m]
Q.9) What is Histogram Matching? Explain. [5m]
Q.10) What are the advantages and disadvantages of median filter? Obtain output image by applying 3 x 3 median filter on the following image. [8m]
[ 2 4 15 0] [ 3 5 2 6] [11 0 2 10] [ 6 16 0 2]
End of Unit-3