L5-L6 - Image Segmentation-1
L5-L6 - Image Segmentation-1
Name of Faculty:
Dr. Umesh Sahu
(Assistant Professor)
Manipal Institute of Technology, Manipal, India
−1−
Syllabus
Image acquisition and pre-processing: [15]
Vision system components, Image acquisition and analysis, Image
formation - Sampling & Quantization, simple operations on image,
Image enhancement Spatial Domain and frequency domain methods,
Image noise, image restoration, morphological operations,
Segmentation, image analysis, representation of regions, Feature
extraction, fundamentals of color image processing, conversion of
color spaces.
Original image
Ideal image is
often has
composed of the
inconsistencies
fewest possible
due to light and
distinct intensities.
noise.
What is
Edge
A set of edge pixels are obtained detection?
f =
Gx2 + Gy
2 1/ 2
f ( x, y) − f ( x, y) E
0 0 0 0 0 0 Link 2
0 0 0
0 0 0
Link 1
Hough transform
f1 f3
f4
f2
f (x. y ) T: : background
No. of Pixels
0 255
T Gray Values
Dark Bright
Manipal Institute of Technology, Manipal, India
− 19 −
Manipal Institute of Technology, Manipal, India
− 20 −
Object Background
No. of Pixels
MATLAB Demo
1 if f ( x, y ) T
g ( x, y ) = f(x,y) = intensity at (x,y)
0 if f ( x, y ) T
P(x,y) = some property at (x,y)
Dynamic threshold
T is a function
of [x, y, P(x, y) f(x, y)].
Example 10.15
Manipal Institute of Technology, Manipal, India
− 27 −
Manual
Thresholding
Global
Thresholding
Tutorial_3_10_1.m
2000.00
Background
1500.00
1000.00
500.00
Pb(z)
▪ Po + P b = 1 0.00
0.00 50.00
Object
100.00 150.00 200.00 250.00
i
Po(z)
T
Manipal Institute of Technology, Manipal, India
− 31 −
Optimal Global Thresholding
P(i ) = h( i ) / N
▪where h(i) is the histogram of an N pixel image
( T ) = i − o ( T ) P(i ) / po ( T )
T 2
2
o
i=0
( T ) = i − b ( T ) P( i ) / pb ( T )
255 2
2
b
i = T +1
2000.00
Histogram
1500.00
Within group variance
1000.00
500.00
0.00 i
0.00 50.00 100.00 150.00 200.00 250.00
0.025
0.01
• where 0.005
k L−1
Po = pi , Pb = pi 0
0 50 100 150 200 250 300
i=0 i=k+1
Original Image
Global
Optimal Thresholding
Thresholding
MATLAB Inbuilt
Function:
level = graythresh(x);
Tutorial_3_10_1.m
Image
T22 T23
T21
Example 10.20
Manipal Institute of Technology, Manipal, India
− 46 −
MATLAB Demo
Tutorial_3_10_2.m
The size of the neighborhood has to be large enough to cover sufficient foreground and
background pixels, otherwise a poor threshold is chosen.
On the other hand, choosing regions which are too large can violate the assumption of
approximately uniform illumination.
This method is less computationally intensive than the Chow and Kaneko approach and
produces good results for some applications.
Manipal Institute of Technology, Manipal, India
− 48 −
Adaptive thresholding - Local thresholding
MATLAB Demo
Tutorial_3_10_2.m
k =1
Pk = p i
where
mk =
1
i pi
Pk iCk
iCk
• OpenCV Python\
• Simple thresholding: cv2.threshold()
• Adaptive thresholding: cv2.adaptiveThreshold()
• Without a-priori knowledge, compute the histogram and choose the gray-
level values corresponding to the strongest peaks.
• Closed boundaries
4-connectivity 8-connectivity
1 1 1
Region 1
1 1 1 Part 1
1 0 1 1 0 1
0 1 0 Region 2 0 1 0 Part 2
0 0 1 0 0 1
1 1 1 1 1 1
1 1 1 1 1 1
Key:
similarity
measure
Example 10.23
Manipal Institute of Technology, Manipal, India
− 64 −
Original figure The Seed Points
seed point 7 3 0
label a b c
5 7 7 5 6 7 7 6 a a a a a a a a
6 7 6 5 2 2 7 5 a a a a c c a a
5 6 7 5 0 2 5 6 a a a a c c a a
5 6 0 0 1 1 7 7 a a c c c c a a
2 0 2 0 1 3 7 6 c c c c c b a a
0 2 1 4 3 4 4 4 c c c b b b b b
2 0 2 0 4 3 5 5 c c c c b b b b
5 5 4 4 5 5 4 5 b b b b b b b b
▪Disadvantages:
1. Computationally expensive
2. It is a local method with no global view of the problem.
3. Sensitive to noise.
The main problem with region splitting is determining where to split a region.
–Split into four disjoint quadrants any region Ri for which P(Ri) = FALSE.
• Unlike RG, region splitting starts with the whole image as a single region
and subdivides it into subsidiary regions recursively while a condition of
homogeneity is not satisfied.
• Region merging is the opposite of splitting, and works as a way of
avoiding over-segmentation
Iteration 1
split merge
Iteration 2
split merge
Iteration 3
split merge
1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2
1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0
3 1 4 9 9 8 1 0 3 1 4 9 9 8 1 0
1 1 8 8 8 4 1 0 1 1 8 8 8 4 1 0
1 1 6 6 6 3 1 0 1 1 6 6 6 3 1 0
1 1 5 6 6 3 1 0 1 1 5 6 6 3 1 0
1 1 5 6 6 2 1 0 1 1 5 6 6 2 1 0
1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0
1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2
1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0
3 1 4 9 9 8 1 0 3 1 4 9 9 8 1 0
1 1 8 8 8 4 1 0 1 1 8 8 8 4 1 0
1 1 6 6 6 3 1 0 1 1 6 6 6 3 1 0
1 1 5 6 6 3 1 0 1 1 5 6 6 3 1 0
1 1 5 6 6 2 1 0 1 1 5 6 6 2 1 0
1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0
Final segmented
Sample image
result
8
1
References:
1. https://towardsdatascience.com/metrics-to-evaluate-your-semantic-segmentation-model-6bcb99639aa2
2. Zou, K. H., Warfield, S. K., Bharatha, A., Tempany, C. M., Kaus, M. R., Haker, S. J., Wells, W. M., 3rd, Jolesz, F. A., & Kikinis, R. (2004).
Statistical validation of image segmentation quality based on a spatial overlap index. Academic radiology, 11(2), 178–189.
https://doi.org/10.1016/s1076-6332(03)00671-8
Image from Vlad Shmyhlo in article: Image Segmentation: Kaggle experience (Part 1 of 2) in TDS
• Ships:
• Area of Overlap = 0, Area of Union = (5+0)-0 =5
• Area of Overlap/Area of Union = 0%
• Background:
• Area of Overlap = 95, Area of Union = (95+100)–95 = 100
• Area of Overlap/Area of Union =95%
• Mean IoU = (Ships + Background)/2 = (0%+95%)/2 = 47.5%
ThIt is obvious that 47.5 is a much better indication of the success of segmentation.