IP Module2
IP Module2
(Part 1)
Image Enhancement
❖ Objective
– To process an image so that the result is more suitable than the
original image for a specific application.
01
Image Enhancement
Image Enhancement
Linear Filtering
02
Outline of the Chapter
❖ Point Processing
❖ Piecewise Linear Transformations
❖ Histogram Processing
❖ Arithmetic & Logic Operations
03
Point Processing
04
Point Processing Operations
05
Examples of Point Processing Operations
– Image Negative
– Contrast Stretching
– Thresholding
– Noise Clipping
– Dynamic Range Compression
– Gray (Intensity) Level Slicing
– Bit-plane Slicing
– Image Subtraction and Addition
06
Image Negative
❖ Transformation Function
s = ( L − 1) − r
( L − 1)
0 ( L − 1)
Input gray level, r
07
Image Negative
08
Log Transformation
❖ Transformation Function
s = c log(1 + r ) r 0
( L − 1)
0 ( L − 1)
Input gray level, r
– Maps narrow range of low gray levels of input image to wider range of gray
levels in the output image.
– Useful in displaying Fourier spectrums
09
Log Transformation
11
Power-Law Transformation
❖ Transformation Function
s = c r c, 0
( L − 1)
0 1
1
0
0 ( L − 1)
Input gray level, r
– For < 1 : Maps narrow range of low gray levels of input image to wider
range of gray levels in the output image.
– For > 1 : Maps narrow range of high gray levels of input image to wider
range of gray levels in the output image.
12
Power-Law Transformation
– Effect of changing
13
Power-Law Transformation
= 0.5 = 1.5
– Gamma Correction
15
Piecewise Linear Transformations
16
Piecewise Linear Transformations
❖ Contrast Stretching
❖ Gray Level Slicing
❖ Bit-plane Slicing
17
Contrast Stretching
18
Contrast Stretching contd…
❖ Transformation Function
s = m1 r 0 r r1
= m2 (r − r1 ) + s1 r1 r r2
= m3 (r − r2 ) + s2 r2 r L − 1
( L − 1)
Output gray level, s (r2 , s2 ) m3
m2
T (r )
m1 (r1 , s1 )
0
0 ( L − 1)
Input gray level, r
Slope is kept more than unity in the region where contrast stretching is
needed
19
Special cases of Contrast Stretching
❖ Case 1: r1 = s1 and r2 = s2
– Identity Transformation
– Gray levels are unchanged
( L − 1)
(r2 , s2 )
Output gray level, s
( r1 , s1 )
0
0 ( L − 1)
Input gray level, r
20
Special cases of Contrast Stretching contd…
❖ Case 2: r1 = r2 , s1 = 0 and s2 = L − 1
– Thresholding
– Converts gray image to binary image
– An important initial operation in segmentation
( L − 1)
Output gray level, s
(r2 , s2 )
( r1 , s1 )
0
0 ( L − 1)
Input gray level, r
21
Special cases of Contrast Stretching contd…
Example of Thresholding
22
Special cases of Contrast Stretching contd…
❖ Case 3: r1 r2 , s1 = 0 and s2 = L − 1
– Clipping
– If the useful image signal is known to be in the range (r1,r2), clipping
helps in noise removal
( L − 1) (r2 , s2 )
Output gray level, s
(r1 , s1 )
0
0 ( L − 1)
Input gray level, r
23
Special cases of Contrast Stretching contd…
Example of Clipping
s2
s1
0 A B ( L − 1)
Input gray level, r
26
Gray Level Slicing contd…
0 A B ( L − 1)
Input gray level, r
❖ Applications of Intensity Level Slicing
– Enhancing masses of water in satellite images
– Enhancing flaws in X-ray images
– Segmentation of low temperature regions in an infrared image
27
Gray Level Slicing contd…
r1 = 30, r2 = 40
s1 = 0, s2 = 255
28
Bit-plane Slicing
31
Histogram Processing
❖ Histogram:
Histogram of a digital image with gray levels in range [0,L-1] is a
discrete function
h(rk)=nk
where rk= kth gray level
nk = no. of pixels in the image having gray level rk
❖ Normalized Histogram:
nk
p (rk ) = Probability Distribution Function
n
where n = total no. of pixels in the image
32
What does Histogram Tell Us?
(125,180)
(55,160)
35
What does Histogram Tell Us? contd…
36
Histogram Equalization
37
Histogram Equalization contd…
❖ If the above conditions are satisfied, then we can write the Inverse
Transformation Function from s to r as
r = T –1(s) 0≤s≤1
40
Histogram Equalization contd…
❖ Consider pr(r) and ps(s) be the PDFs of input and output gray levels
41
Histogram Equalization contd…
ds d T (r )
=
dr dr
d
r
= pr ( w) dw
dr 0
= pr (r ) (3)
42
Histogram Equalization contd…
nk
p (rk ) = k = 0,1, , L − 1
n
k
sk = T (rk ) = pr (rj )
j =0
k nj
= k = 0,1, , L − 1
j =0 n
43
Example of Histogram Equalization
r = [0,7]
0 1 3 4 0 6
5
4 1 3 2 0
4
2 6 2 2 6
3
2 0 7 5 7 2
2 0 4 3 5 1
0 rk
0 1 2 3 4 5 6 7
45
Example of Histogram Equalization contd…
46
Example of Histogram Equalization contd…
s
1 7
0.9285
0.857 6
0.7855
0.714 5
0.6425
0.571 4
0.5005
0.429 3
0.3575
0.286 2
0.2145
0.143 1
0.0715
0 0
0 1 2 3 4 5 6 7 r
0.143
0.286
0.429
0.571
0.714
0.857
0
1
47
Example of Histogram Equalization contd…
r s
0 1
0 1 3 4 0 1 2 1 2 4 5 1
4 1 3 2 0 2 4 5 2 4 4 1
2 6 2 2 6 3 4 4 6 4 4 6
2 0 7 5 7 4 5 4 1 7 6 7
2 0 4 3 5 5 6 4 1 5 4 6
6 6
7 7
48
Histogram Equalization contd…
48
Histogram Equalization contd…
50
Histogram Matching
k
vk = G ( z ) = pz ( zi ) = sk
i =0
k = 0,1, 2, , L − 1
zk = G −1[T (rk )] = G −1 ( sk )
k = 0,1, 2, , L − 1
52
Histogram Matching contd…
Example
Example
Problem
Modify the histogram A as given in histogram B
Histogram A
Normalized gray level rk 0 1/7 2/7 3/7 4/7 5/7 6/7 1
No. of pixels nr 790 1023 850 656 329 245 122 81
Histogram B
Normalized gray level zk 0 1/7 2/7 3/7 4/7 5/7 6/7 1
No. of pixels nz 0 0 0 614 819 1230 819 614
56
Histogram Matching contd…
Closest valid
rk nr pr(rk) sk
level
0 790 0.19 0.19 1/7
1 81 0.02 1 1
57
Histogram Matching contd…
sk ns ps(sk)
0 0 0
2/7 0 0
4/7 0 0
58
Histogram Matching contd…
Closest valid
zk nz pz(zk) vk
level
0 0 0 0 0
1/7 0 0 0 0
2/7 0 0 0 0
1 614 0.15 1 1
59
Histogram Matching contd…
sk ns zk sk nz
0 0 0 0 0
2/7 0 2/7 0 0
1 488 1 1 488
60
Arithmetic & Logical Operations
61
Image Subtraction
62
Image Subtraction contd…
Image 2
Image 1
65
Image Subtraction contd…
66
Image Subtraction contd…
g rescaled ( x, y ) =
( g ( x, y ) − g min ) ( L − 1)
( g max − g min )
67
Image Subtraction contd…
68
Image Subtraction contd…
g rescaled ( x, y ) = g ( x, y )
69
Logical Operations
01
Spatial Filtering
02
Neighborhood of a pixel
3x3 neighborhood
5x5 neighborhood
7x7 neighborhood
2x2 neighborhood
4x4 neighborhood
03
Mechanics of Spatial Filtering
04
Mechanics of Spatial Filtering contd…
where a = (m − 1) / 2 and b = (n − 1) / 2
➢ 2-D Convolution will expand the image
06
Spatial Frequency
07
Classification of Spatial Filters
Spatial Filters
Mid-point filter
08
Smoothing Filters
09
Linear Low Pass Filtering
10
Mask for Low Pass Filtering
1 1 1 1 1 1 1 1
1
x 1 1 1 1 1 1 1 1
9
1
1 1 1 x 1 1 1 1 1
25
3x3 Mask 1 1 1 1 1
1 1 1 1 1
5x5 Mask
Weighted Average Mask / Gaussian Mask
1 2 1
1
x 2 4 2
16
1 2 1
3x3 Mask
11
Example of Low Pass filtering
1 1 1 5 3 4 7 10
1
x 1 1 1
9
3 2 4 7 10
1 1 1
2 2 4 5 7
10 0 0 11 10
1 2 2 3 4
1 3 2 10 10
1 1 1 1 2
1 1 3 10 10
2 3 1 1 2 6 2 3 8 10
1 1 1 1 2 4 2 4 8 10
Image 1 2 4 6 8
1 2 1
1 2 2 2 3 4
x 2 4 2
16
1 2 1 1 1 1 1 2
12
Effect of Mask size
Original Image LP Filtering with 3x3 Mask LP Filtering with 5x5 Mask
LP Filtering with 9x9 Mask LP Filtering with 15x15 Mask LP Filtering with 35x35 Mask
– Median filter
– Min filter
– Max filter
– Midpoint Filter
14
Median Filter
fˆ ( x, y ) = median{ g ( s, t )}
( s ,t )S xy
15
Median Filter contd…
2 3 4 6 6 2 3 4 6 6
0 15 2 6 6 2 2 4 6 6
Median
1 2 3 15 14 1 2 3 6 13
Filter
1 3 12 0 13 2 3 4 12 13
2 4 11 12 11 2 4 11 11 11
Median of [0,1,2,2,2,3,3,4,15] = 2
16
Median Filter contd…
17
Median Filter contd…
18
Max and Min Filters
19
Max and Min Filters contd…
2 2 2 2 6
2 2 2 2 2
Min
2 2 0 0 0
Filter
2 2 0 0 0
2 2 0 0 0
20
Midpoint Filters
21
Midpoint Filters contd…
2 3 4 6 6 8 8 9 4 6
0 15 2 6 6 8 8 9 9 11
Midpoint
1 2 3 15 14 8 8 8 8 8
Filter
1 3 12 0 13 3 7 6 8 8
2 4 11 12 11 3 7 6 7 7
22
Sharpening Filters
23
Sharpening Filters
➢ Sharp edges & abrupt change in pixel values are made further
dominant.
➢ Areas of constant gray levels are converted to dark after High Pass
filtering.
24
Sharpening Filters contd…
➢ Input image may be blurred due to poor focus or other defects of the
imaging device.
25
Sharpening Filters contd…
26
Conditions for the derivative function
27
Derivative of Digital Image
28
Derivative of Digital Image contd…
f
f y = G y = = f ( x, y − 1) − f ( x, y )
y
30
First Order Derivative : Gradient contd…
f = mag ( f )
= Gx 2 + G y 2
2
f f
2
= +
x y
31
Various Gradient Operators
Gradient Operator
-1 -1 1
-1 0 0 -1
0 1 1 0
32
Mask and their effects
Gx
-1
1 Gx + G y
Gy
-1 1
33
Mask and their effects
Gx
0 -1
Gx + G y
1 0
Gy
-1 0
0 1
34
Various Gradient Operators contd…
Prewitt Operator
-1 -1 -1 -1 0 1
0 0 0 -1 0 1
1 1 1 -1 0 1
35
Various Gradient Operators contd…
Sobel Operator
-1 -2 -1 -1 0 1
0 0 0 -2 0 2
1 2 1 -1 0 1
36
Example of Gradient Operators
37
Second Order Derivative : Laplacian
x y 2
2 f
= f ( x, y + 1) + f ( x, y − 1) − 2 f ( x, y )
y 2
2 f = f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1) − 4 f ( x, y )
38
Second Order Derivative : Laplacian contd…
Laplacian Operator
0 1 0
1 -4 1
0 1 0
39
Mask and their effects
0 1 0
1 -4 1
0 1 0
40
Various Laplacian Operators
0 1 0 1 1 1
1 -4 1 1 -8 1
0 1 0 1 1 1
0 -1 0 -1 -1 -1
-1 4 -1 -1 8 -1
0 -1 0 -1 -1 -1
41
Example of Laplacian Filtering
0 0 0 0 0
0 -1 0 -15 -15 -15 0 0
-1 4 -1 15 15 30 -15 0
0 -1 0 0 0 15 -15 0
0 0 0 0 0
0 0 15 -15 0
0 0 0 0 0
15 15 15 0 0
15 15 15 0 0
0 0 0 0 0
15 15 15 0 0
-1 -1 -1 -45 -45 -30 -15 0
-1 8 -1 45 45 75 -30 0
-1 -1 -1 0 0 45 -45 0
0 0 45 -45 0
42
Image Sharpening using Laplacian Filter
43
Image Sharpening using Laplacian Filter contd…
44
Image Sharpening using Laplacian Filter contd…
if 2 f = f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1) − 4 f ( x, y )
then g ( x, y ) = f ( x, y ) − f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1) + 4 f ( x, y )
= 5 f ( x, y ) − f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1)
0 -1 0
45
Image Sharpening using Laplacian Filter contd…
0 1 0
1 -4 1
0 1 0
0 -1 0
-1 5 -1
0 -1 0
46
Image Sharpening using Laplacian Filter contd…
47
1st Order versus 2nd Order
48
High-Boost Filtering
49
High-Boost Filtering contd…
f hb ( x, y ) = ( A − 1) f ( x, y ) + f s ( x, y ) where A 1
and f s ( x, y ) = sharpened image
50
High-Boost Filtering contd…
51
Various High-Boost Operators
0 -1 0 -1 -1 -1
-1 A+4 -1 -1 A+8 -1
0 -1 0 -1 -1 -1
52
Image Sharpening using High-Boost Filter contd…
53