Aa Dip 2 2 (Segmentation)
Aa Dip 2 2 (Segmentation)
By:
Dr. Ankush Agarwal
Outline
© ankush agarwal 2
SEGMENTATION
© ankush agarwal 3
Segmentation
© ankush agarwal 4
Segmentation
© ankush agarwal 5
Segmentation
© ankush agarwal 6
Segmentation
Discontinuity Similarity
© ankush agarwal 7
Segmentation
© ankush agarwal 8
Segmentation (Basic Idea)
© ankush agarwal 9
Thresholding
© ankush agarwal 10
Thresholding (Types)
• Global Thresholding
– If T is the only function of f(x, y), then the threshold is called global
threshold
– Apply the same threshold to the whole image
• Local Thresholding
– If T is a function of both f(x, y) & p(x, y), then the threshold is called local
– The threshold depends on local property
© ankush agarwal 11
Thresholding
© ankush agarwal 12
Thresholding
• Eg:
– Disk = 255 and background = 127
– Segment the image into two regions: disk and background
– What will be the threshold values?
© ankush agarwal 13
Global Thresholding
© ankush agarwal 14
Global Thresholding (Algorithm)
© ankush agarwal 15
Global Thresholding (Problem)
© ankush agarwal 16
Global Thresholding (Problem)
© ankush agarwal 17
Global Thresholding (Problem)
© ankush agarwal 18
Adaptive Thresholding
© ankush agarwal 19
SEGMENTATION (SIMILARITY)
© ankush agarwal 20
Region
© ankush agarwal 21
Region based approach
© ankush agarwal 22
Region based approach
© ankush agarwal 23
Region growing
© ankush agarwal 24
Region splitting
© ankush agarwal 26
Region splitting
R
I1 I2
I41 I42 I1 I2 I3 I4
I3
I43 I44
I41 I41 I41 I41
© ankush agarwal 27
Region splitting
• Advantage
– Created regions are adjacent and homogenous
• Disadvantage
– Over splitting, since no merge is performed
– More clusters
• Improvement
– Split and Merge
© ankush agarwal 28
Region splitting and merging
• After splitting
• Merging phase
– If 2 adjacent regions are homogenous, they are merged
• Repeat merging step, until no further merging is possible
© ankush agarwal 29
SEGMENTATION (DISCONTINUITY)
© ankush agarwal 30
Segmentation (Discontinuity)
© ankush agarwal 31
Segmentation (Discontinuity)
© ankush agarwal 32
Segmentation (Discontinuity)
0 1 0 0 -1 0
1 -4 1 -1 4 -1 90° isotropic
0 1 0 0 -1 0
1 1 1 -1 -1 -1
45° isotropic 1 -8 1 -1 8 -1
1 1 1 -1 -1 -1
© ankush agarwal 33
Segmentation (DiscontinuityPoint)
© ankush agarwal 34
Segmentation (Discontinuity Point)
7 7 7 7 7 7 7 -1 -1 -1
7 10 7 7 7 7 7 -1 8 -1 24 -3
3 0 0 0
7 7 7 7 7 7 7 -1 -1 -1 -3
3 -3
3 0 0 0
7 7 7 7 7 7 7 P 0 0 3 3 3
7 7 7 7 4 7 7 0 0 3 24
-24 3
7 7 7 7 7 7 7 0 0 3 3 3
7 7 7 7 7 7 7
I Rp =I º|IPº P|
© ankush agarwal 35
Segmentation (Discontinuity Line)
-1 -1 -1 -1 -1 2 -1 2 -1 2 -1 -1
2 2 2 -1 2 -1 -1 2 -1 -1 2 -1
-1 -1 -1 2 -1 -1 -1 2 -1 -1 -1 2
© ankush agarwal 36
Segmentation (Discontinuity Line)
1 1 1 1 1 1 1 1 -1 -1 -1
1 1 1 1 1 1 1 3 2 2 2 0 0 0 0 2 2
1 1 1 1 1 1 3 1 -1 -1 -1 0 0 0 2 2 0
1 1 1 1 1 3 1 1 H 6 6 6 0 0 2
3 3 3 3 3 1 1 1 12 12 12 6 2 2
1 1 1 1 1 1 1 1 6 6 6 4 2 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1
I |I º H|
© ankush agarwal 37
Segmentation (Discontinuity Line)
1 1 1 1 1 1 1 1 -1 -1 2
1 1 1 1 1 1 1 3 -1 2 -1 0 0 0 0 2 4
1 1 1 1 1 1 3 1 2 -1 -1 0 0 0 2 4 12
1 1 1 1 1 3 1 1 D45º 0 0 0 0 12 4
3 3 3 3 3 1 1 1 0 0 0 6 4 2
1 1 1 1 1 1 1 1 0 0 0 4 2 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1
I |I º D45º|
© ankush agarwal 38
Segmentation (Discontinuity Line)
1 1 1 1 1 1 1 1 -1 2 -1
1 1 1 1 1 1 1 3 -1 2 -1 0 0 0 0 2 2
1 1 1 1 1 1 3 1 -1 2 -1 0 0 0 2 2 0
1 1 1 1 1 3 1 1 V 0 0 0 0 0 2
3 3 3 3 3 1 1 1 0 0 0 0 2 2
1 1 1 1 1 1 1 1 0 0 0 2 2 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1
I |I º V|
© ankush agarwal 39
Segmentation (Discontinuity Line)
1 1 1 1 1 1 1 1 2 -1 -1
1 1 1 1 1 1 1 3 -1 2 -1 0 0 0 0 4 4
1 1 1 1 1 1 3 1 -1 -1 2 0 0 0 4 4 0
1 1 1 1 1 3 1 1 D-45º 0 0 0 6 0 4
3 3 3 3 3 1 1 1 0 0 0 0 4 4
1 1 1 1 1 1 1 1 0 0 0 2 4 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1
I |I º D-45º|
© ankush agarwal 40
Segmentation (Discontinuity Line)
1 1 1 1 1 1 1 1
1 10 10 10 10 14 14 3
1 10 10 10 14 14 12
3 1
1 16 16 16 16 12
3 14 1
3 12
3 12
3 12
3 36 14 14 1
1 16 16 16 14 14 10 1
1 10 10 10 10 10 10 1
1 1 1 1 1 1 1 1
© ankush agarwal 41
Segmentation (Discontinuity Edge)
© ankush agarwal 42
Segmentation (Discontinuity Edge)
• Edge linking
– process takes an unordered set of edge pixels produced by an edge
detector as i/p to form an ordered list of edgels
• Edge following
– process takes the entire edge strength or gradient image as i/p &
produces geometric primitives such as lines or curves
© ankush agarwal 45
Segmentation (Discontinuity Edge Derivative)
© ankush agarwal 46
Segmentation (Discontinuity Edge Derivative)
1 1 1 1 2 2 2
Robert -1 -2 -1 -1 -1 -1
1 1 1 1 2 2 2
1 1 1 1 2 2 2 1 0 0 0 0 0 0 0
2 2 2 2 1 1 1 0 -1 1 2 1 1 1 1
2 2 2 2 1 1 1 G45º SH PH
2 2 2 2 1 1 1 -1 0 1 -1 0 1
0 1
2 2 2 2 1 1 1 -2 0 2 -1 0 1
-1 0
I -1 0 1 -1 0 1
G-45º
SV PV
Sobel Prewitt
© ankush agarwal 47
Segmentation (Discontinuity Edge Derivative)
• Motivation
– Detect sudden changes in image intensity
– Gradient: sensitive to intensity changes
• Gradient T
f f
f
x y
© ankush agarwal 48
Segmentation (Discontinuity Edge Derivative)
© ankush agarwal 49
Segmentation (Discontinuity Edge Derivative)
• Eg:
– Find the strength & the direction of the edge at the highlighted pixel
– Pixels in gray are 0 and white are 1
Solution
• Derivative is computed by using a 3x3 neighbourhood
– subtract the pixels in the top row from bottom row (x direction)
– similarly obtain the derivative in the y direction
-1 -1 -1 -1 0 1
0 0 0 -1 0 1
1 1 1 -1 0 1
© ankush agarwal 50
Segmentation (Discontinuity Edge Derivative)
• Eg:
– Find the strength & the direction of the edge at the highlighted pixel
– Pixels in gray are 0 and white are 1
I (x, y)
Gx x 2
I
G y I (x, y) 2
y
| I | Gx2 G y2 2 2
Gy
(x, y) tan
1
1 45
x
G
© ankush agarwal 51
Simple edge detection using gradient
© ankush agarwal 52
CANNY EDGE DETECTOR
© ankush agarwal 53
Canny (Characteristics)
© ankush agarwal 54
Canny (Steps)
© ankush agarwal 55
Canny (Steps – Gaussian filter)
© ankush agarwal 56
Canny (Steps - Derivative)
© ankush agarwal 57
Canny (Steps - Magnitude and Orientation)
© ankush agarwal 58
Canny (Steps - Apply Non Maxima Suppression)
© ankush agarwal 59
Canny (Steps - Apply Non Maxima Suppression)
© ankush agarwal 61
Canny (Steps – Apply Hysteresis Thresholding)
© ankush agarwal 62
Canny
• Eg:
– Compute derivative
© ankush agarwal 63
Canny
• Eg:
– Compute magnitude and orientation
-4 -3 -1 0 0 2 1 1 0 0
-3 -4 -3 -1 0 1 2 3 1 0
0 -1 -3 -4 -3 0 1 3 2 1
0 0 -1 -3 -4 0 0 1 1 2
0 0 0 0 -1 0 0 0 0 1
© ankush agarwal 64
Canny
• Eg:
– Apply Non-maxima suppression
© ankush agarwal 65
Canny
• Eg:
– Apply Hysteresis Threshold
© ankush agarwal 66
HOUGH TRANSFORM
© ankush agarwal 67
Hough Transform
y = mx+c c = -mx+y
variable: x, y variable: m, c
parameter: m, c parameter: x, y
© ankush agarwal 68
Hough Transform
• Eg:
© ankush agarwal 69
Hough Transform
• Step 1:
– Known
• -1.2<=m<=-0.8
• step_m = 0.1
© ankush agarwal 70
Hough Transform
• Step 2:
– Compute c
© ankush agarwal 71
Hough Transform
• Step 3:
– Find min and max of c
(x,y) = (4,1) (x,y) = (3,2) (x,y) = (2,3) (x,y) = (1,4)
• Range: 4.2 to 5.8 c = -4m+1 c = -3m+2 c = -2m+3 c = -m+4
• Interval: 0.1 m c m c m c m c
-0.8 4.2 -0.8 4.4 -0.8 4.6 -0.8 4.8
-0.9 4.6 -0.9 4.7 -0.9 4.8 -0.9 4.9
-1.0 5.0 -1.0 5.0 -1.0 5.0 -1.0 5.0
-1.1 5.4 -1.1 5.3 -1.1 5.2 -1.1 5.1
-1.2 5.8 -1.2 5.6 -1.2 5.4 -1.2 5.2
© ankush agarwal 72
Hough Transform
• Step 4:
– Voting
© ankush agarwal 73
Hough Transform
• Step 5:
– Find equation
• m =-1.0
• c = 5.0
• y = -x+5
© ankush agarwal 74
Hough Transform
• Problem
– The slope of line parallel to y – axis is infinity, the computer can not
handle it.
– So, we follow another parameterization of a line
– p = x cos θ + y sin θ
© ankush agarwal 75
Hough Transform
y
6
5
4
3
p = x cos θ + y sinθ
2
Edgels: (0,5), (1,4), (3,2), (3,3), (5,0)
1
0
0 1 2 3 4 5 6 x
© ankush agarwal 76
Hough Transform
p = x cos θ + y sinθ
© ankush agarwal 77
Hough Transform
0 cos θ + 5 sin θ 1 cos θ + 4 sin θ 3 cos θ + 2 sin θ 3 cos θ + 3 sin θ 5 cos θ + 0 sin θ
0 0 1 3 3 5
90 5 4 2 3 0
© ankush agarwal 78
Hough Transform
© ankush agarwal 79