computer_vision_prerequisite_edge_detection
computer_vision_prerequisite_edge_detection
Detection
Grey-scale image (8 bits/pixel)
binary decimal
0
255
2
256 shades of grey
Digital Image (8-bit) and Image Matrix (5x5)
0 255 0 0 255
0 255 0 0 255
0 255 0 0 255
0 255 0 0 255
0 255 0 0 255
Binary Image Image matrix
255 255 255 255 255
100 100 100 100 100
50 50 50 50 50
0 0 0 0 0
50 50 50 50 50
Grey Image Image matrix 3
Digital Color Image and Image Matrix
255 255 0 0 0
255 255 0 0 0
255 255 0 0 0
255 255 0 0 0 255 0 0 255 0
255 255 0 0 0 255 0 0 255 0
Red component 255 0 0 255 0
255 0 0 255 0
255 0 0 0 255
255 0 0 255 0
Image
255 0 0 0 255 Green component
255 0 0 0 255
255 0 0 0 255
255 0 0 0 255
4
Blue component
Image Filtering
54 100 208 1 1 1
45 90 185 1 1 1
23 42 86
3x3 part of Image 3*3 Smoothing Filter
54 100 208
49 106 198
45 90 185
45 90 185 1 1 1
23 42 86
3x3 part of Image 3*3 Smoothing Filter
54 100 208
49 106 198
45 90 185
Image f (x, y) 23 42 86
54 100 208
49 115 198
45 90 185
After averaging
Smoothing Spatial Filtering
Origin x
23 42 86 1 1 1
49 106 185 1 1 1
23 42 86
3*3 Smoothing
54 100 208
49 106 198
Filter
45 90 185
e = 94.77 95
23 42 86
54 95 208
45 90 185
Smoothing Spatial Filtering
Origin x
23 42 86 1 1 1
49 106 185 1 1 1
23 42 86
3*3 Smoothing
54 100 208
49 106 198
Filter
45 90 185
e = 94.77 95
23 42 86
54 95 208
45 90 185
Smoothing Spatial Filtering
Original Image
Application of average filter
45 56 42 63 54
20 47 56 28 53
63 59 26 38 47
67 36 27 48 51
43 36 42 65 43
Example: Spatial filters
45 56 42 63 54 45 56 42 63 54 45 56 42 63 54
20 47 56 28 53 20 47 56 28 53 20 47 56 28 53
63 59 26 38 47 63 59 26 38 47 63 59 26 38 47
67 36 27 48 51 67 36 27 48 51 67 36 27 48 51
43 36 42 65 43 43 36 42 65 43 43 36 42 65 43
Apply filter on top Move filter to
left corner process each pixel
Example: Spatial filters
Image matrix is given below. Determine the effect of
1. 3x3 and 5x5 averaging filters
2. 3x3 weighted averaging filter
45 56 42 63 54 45 56 42 63 54
20 47 56 28 53 20 46 46 45 53
1 1 1
63 59 26 38 47 63 44 41 42 47
x (1/9) 1 1 1 =
67 36 27 48 51 67 44 42 43 51
1 1 1
43 36 42 65 43 43 36 42 65 43
45 56 42 63 54 1 1 1 1 1 45 56 42 63 54
20 47 56 28 53 1 1 1 1 1 20 47 56 28 53
x (1/25)
63 59 26 38 47 1 1 1 1 1= 63 59 46 38 47
67 36 27 48 51 1 1 1 1 1 67 36 27 48 51
43 36 42 65 43 1 1 1 1 1 43 36 42 65 43
Example: Spatial filters
-1
Mask/ filter for gy
0
1
Image Gradient/ Gradient Vector
gy
𝑀= 𝑔𝑥 2 + 𝑔𝑦 2 ( x, y) tan
1
gx
• M is magnitude and α is angle of gradient
• Size of matrix for magnitude and angle is same as image
• Magnitude is the value of rate of change in the direction of
gradient vector
• Magnitude of gradient is used to measure how strong the
change in image intensity is
Image Gradients
• The gradient orientation is used to determine in which direction
the change in intensity is pointing
• Direction of edge is normal to direction of gradient
• Direction of gradient is also called edge normal
Image Gradients
• The gradient orientation is used to determine in which direction
the change in intensity is pointing
• Direction of edge is normal to direction of gradient
• Direction of gradient is also called edge normal
Gradient of image
image gx gy
10 10 50 10 10 -1
-1 0 1 -1
10 10 50 10 10 0
0
10 10 50 10 10 1
1
10 10 50 10 10
gy 𝑀𝑎𝑔 = 𝑔𝑥 2 + 𝑔𝑦 2
gx
10 40 0 -40 10 10 10 50 10 10 10 10 50 10 10
10 40 0 -40 10 0 0 0 0 0 10 40 0 40 10
10 40 0 -40 10 0 0 0 0 0 10 40 0 40 10
10 40 0 -40 10 10 10 50 10 10 10 10 50 10 10
Sobel Filters for gradient
Filter for gx Filter for gy
image
10 10 50 10 10 -1 0 1 -1 -2 -1
10 10 50 10 10 -2 0 2 0 0 0
10 10 50 10 10 -1 0 1 1 2 1
10 10 50 10 10
gy 𝑀𝑎𝑔 = 𝑔𝑥 2 + 𝑔𝑦 2
gx
10 10 50 10 10 10 10 50 10 10 10 10 50 10 10
10 160 0 -160 10 10 0 0 0 10 10 160 0 160 10
10 160 0 -160 10 10 0 0 0 10 10 160 0 160 10
10 10 50 10 10 10 10 50 10 10 10 10 50 10 10
Gradient Magnitudes
Filter for gx Filter for gy Magnitude using Sobel
-1 0 1 -1 -2 -1 10 10 50 10 10
-2 0 2 0 0 0 10 160 0 160 10
image
-1 0 1 1 2 1 10 160 0 160 10
10 10 50 10 10 50
10 10 10 10
10 10 50 10 10
10 10 50 10 10 Filter for gx Filter for gy Magnitude
10 10 50 10 10 10 10 50 10 10
-1 0 1 -1
10 40 0 40 10
0
10 40 0 40 10
1
10 10 50 10 10
Image Gradients
Image
Image Gradients
Image
gx
Image Gradients
Image
gx gy
Image Gradients
Image
Magnitude, M
gx gy
Laplacian Filter
0 1 0 -1 -1 -1
1 -4 1 -1 8 -1
0 1 0 -1 -1 -1
10 10 100 10 10
10 -180 180 -180 10
100 180 0 180 100
=
10 -180 180 -180 10
10 10 100 10 10
Edge Detection Filters and Noise
Edge detectors are sensitive to noise
Image
after
Noisy image edge
detection
37
Edge Detection Filters and Noise
Edge detectors are sensitive to noise
Image
after
Noisy image threshold
ing
Image
Image after
after threshold
averaging ing
38
Edge Detection Filters and Noise
Edge detectors are sensitive to noise
Image
after
Noisy image edge
detection
Image
Image after
after edge
averaging detection
1 2 1 1 4 7 4 1 1 1 1 1 1
4 20 33 20 4 1 2 2 2 1
(1/16) 2 4 2 (1/330) 7 33 54 33 7 (1/34) 1 2 2 2 1
4 20 33 20 4 1 2 2 2 1
1 2 1
1 4 7 4 1 1 1 1 1 1