L3v3-Image Enhancement and Preprocessing
L3v3-Image Enhancement and Preprocessing
• Pixels, 4-adjacency,
P P
8-adjacency, m-adjacency
• Implications?
Distance measures
• Given pixels p, q, and z at (x,y), (s,t) and (u,v) respectively,
• D is a distance function (or metric) if:
– D(p,q) >= 0 (D(p,q)=0 iff p=q),
– D(p,q) = D(q,p), and
– D(p,z) <= D(p,q) + D(q,z).
• The Euclidean distance between p and q is given by:
• The pixels having distance less than or equal to some value r from (x,y) are
the points contained in a disk of radius r centered at (x,y)
Distance measures
• The D4 distance (also called the city block distance) between p and q is
given by:
• The pixels having a D4 distance less than some r from (x,y) form a
diamond centered at (x,y)
• Example: pixels where D4 <= 2
• The D8 distance (also called the chessboard distance) between p and q is
given by:
• The pixels having a D8 distance less than some r from (x,y) form a square
centered at (x,y)
• Example: pixels where D8 <= 2
Distance measures and connectivity
• Mean of greylevels:
M 1 N 1
1
m
P
I (i, j )
i 0 j 0
• Variance of greylevels:
M 1 N 1
1
I (i, j) m
2 2
V
P i 0 j 0
• Signal to noise ratio (SNR), reflects the dispersion of the grey levels in the
image :
SNR m
•
Extremas (min and max levels) et scope (max-min)
15
Statistical Analysis
I (i, j ) m
I ' (i, j )
• Profile of line segment …
16
Statistical Analysis
17
Statistical Analysis
n2k 1
n2k 1
H(n)
p(n)
P p(n)1
n0
18
Statistical Analysis
• Quantity of information
– The amount of information provided by a level n is inversely
proportional to the probability of this greylevel
I(n)Log2(p(n))
• Entropy
– Measurement of the average amount of information provided by
each level of the image
2k 1
E(Image) p(n)Log2(p(n))
n0
19
Statistical Analysis
• Cumulative Histogramm
– Constructed from the histogram of then gray levels according to the formula :
H C ( n) H ( q )
q 0
n 0;2 k 1
– with Hc(0)=H(0) and Hc(2k-1)=P
H c ( n)
pC (n)
P
20
4
x 10
7
0
1800 0 50 100 150 200 250 300
1600
1400
1200
Histogramme cumulation
1000
black
800
Histogramme
600
400
white
200
0
0 50 100 150 200 250 21
300
Statistical Analysis
• Histogramme in x and in y
– Consists in summing all the gray levels of the pixels present in the
same row or the same column and this for all the rows or columns of
the image.
1 M 1
– Respectively N
i[0;M-1] and j [0;N-1]
H row (i ) I (i, j )
j 0
H column ( j ) I (i, j )
i 0
22
Statistical Analysis
• Let: 2
k=4 or K=16
6
10 11 10 12 12 12 11 12 11 10 12 7
10
11 11 11 12 10 9 8 8 7 7 7 7
13 12 11 10 9 8 7 7 7 6 6 8 12
13 11 11 10 8 7 6 6 5 6 5 7 2 4 6 8 10 12
14 12 11 12 7 7 4 4 4 6 5 5
13 14 13 14 8 7 5 6 5 4 3 5 Calculate and propose a code /
14 15 15 13 9 9 7 7 6 6 7 7 algorithm:? - Mean and standard
12 12 11 13 10 7 8 9 8 7 9 11
deviation? - Min and max value? -
3 0 2 1 3 10 11 12 11 10 11 12
2 3 2 1 2 10 12 13 13 14 13 13 Histogram row and column? -
2 0 0 0 11 12 13 14 13 14 14 15 Histogram and cumulative histogram
1 1 1 11 12 13 13 13 12 13 14 15
24
Brightness / Contrast
• Examples of « light » and « dark » images:
Large population of
pixels at low levels
5
x 10
2.5 6000
5000
2
Large population of
4000
1.5
pixels at high levels
3000
1
2000
0.5
1000
0
0 50 100 150 200 250 300
25 0
0 50 100 150 200 250 300
Brightness / Contrast
4 4
x 10 x 10
2 18
1.8 16
1.6
14
1.4
12
1.2
10
1
Large population of pixels
8 high and low levels
0.8 Absence ofpixels high
0.6
and low levels 6
4
0.4
0.2 2
0
0 50 100 150 200 250 300
26 0
0 50 100 150 200 250 300
Image Enhancement and Correction
Distortion due to Camera Misfocus
Camera lens
Distortion due to motion
Camera lens
Distortion due to Random Noise
•Video cameras usually have electronic gain adjustment, but this can
only (attempt to) compensate for changes in overall brightness levels
Local Averaging - Smoothing
Enhancing Contrast by Adjusting
Grey Values in the Image
A number of techniques, such as histogram equalisation and gamma correction,
involve remapping grey values in the image.
contrast suppressed
output grey values
mapping function
contrast
enhanced
1
f (Divide by 255 to get a value
f ' 255 between 0 and 1, raise to a
255 power, then rescale back to 0 to
255.)
Gamma correction: examples
Image normalisation revisited
• changes the range of pixel intensity values
• Go to slides 33-35
Histogram Equalisation
• Let ni be the frequency of grey level i. The probability of an occurrence of a pixel of level i in
the image is
L = total number of image grey levels , n = total number of image pixels , and being in fact the
image's histogram for pixel value i, normalized to [0,1].
58
1D Zero-order (Replication)
f(n)
n
f(x)
59
1D First-order Interpolation
(Linear)
f(n)
n
f(x)
60
Linear Interpolation Formula
a 1-a
f(n+a)=(1-a)f(n)+af(n+1), 0<a<1
61
Numerical Examples
f(n)=[0,120,180,120,0]
Interpolate at 1/2-pixel
f(x)=[0,60,120,150,180,150,120,60,0], x=n/2
Interpolate at 1/3-pixel
f(x)=[0,20,40,60,80,100,120,130,140,150,160,170,180,…], x=n/6
62
1D Third-order Interpolation
(Cubic)*
f(n)
f(x)
x
Cubic spline fitting
63
From 1D to 2D
Old wisdom: divide and conquer
2D interpolation can be decomposed into two sequential
1D interpolations.
The ordering does not matter (row-column = column-row)
Such separable implementation is not optimal but enjoys low
computational complexity
64
Graphical Interpretation
of Interpolation at Half-pixel
row column
f(m,n) g(m,n)
65
Numerical Examples
a b
c d
zero-order
first-order
a a b b
a a b b
a (a+b)/2 b
c c d d (a+c)/2 (a+b+c+d)/4 (b+d)/2
c (c+d)/2 d
c c d d
66
Numerical Examples (Con’t)
Col n Col n+1
b
a 1-a
Y
1-b
68
Thresholding
• Thresholding of an image
– Diminution in the number of grey levels of an image
• highlighting regions
• simplification of information acceleration of processing
– Example of “binarisation” (Thresholding that produces a binary image)
• If we had an image I1, at grey level threshold S et I2 the image that results :
– If I1(i,j) S, I2(i,j) = 0
– if I1(i,j) > S, I2(i,j) = 255
S=2
70
N2 N2 N2
K-1 K-1 K-1
V2
V3
V2
V1 V1 V1
0 N1 0 N1 0 N1
0 S1 K-1 0 S1 S2 K-1 0 S1 K-D
Simple thresholding Double thresholding High-pass thresholding
N2 N2 N2
K-1 K-1 K-1
V2 V1
V1
V1
0 N1 0 N1 0 N1
0 S1 S2 K-1 0 S1 S2 K-1 S1 K-1
0
Band-pass thresholding Band-rejection Low-pass
71
Thresholding
– Should it be adaptive?
• calculated image by image
• Optimal threshold value
72
Thresholding (Otsu’s algorithm)
H(n)
C0s
{m0s; P0s} C1s
{m1s; P1s}
n
0 s s0 K-1
73
Thresholding
74
Thresholding
s max
jh(j) jh(j)
m0s j min
s m1s j max
s 1
h(j)
j min
h(j)
j s 1
– We calculate the new threshold s, so that s=(m + m )/2
0
s
1
s
– We iterate till determining the value of s0 which corresponds to the valeu of the theshold so that
there’s no further change (convergence of the algorithm)
– Generalisable to more than two classes
– Methode of the type method "dynamic clouds"
75