CV_Lecture_2-DD-Don
CV_Lecture_2-DD-Don
Processing
Image Topology
Dr Wafaa Shalash
Introduction
◼ Definition: The study of properties of a figure that are
unaffected by any deformation, as long as there is no
tearing or joining of the figure.
◼ Digital topology deals with the topological properties of
digital image and provides a sound mathematical basis for
image processing operations such as image thinning,
border following and connected component labelling.
Matrix structure is also a consistent mathematical
framework for image processing
3
Simple Example : Count number of Coins
N = 22
Each connected part take a
specific label
4 4-nghbr 8 8-nghbr
• • • • 6
Paths
◼ Suppose that P and Q are any two pixels (not
necessarily adjacent), and suppose P and Q can
be joined by a sequence of pixels as shown:
4-adjacent 8-adjacent
4-connected 8-connected
4-component
4-component
8
Formal Definition of a Path
❑ Symmetric:
❑ Transitive:
2nd foreground pixel in 2nd row 3rd foreground pixel in 2nd row
Upper neighbor : foreground Upper neighbor : background
Left neighbor : foreground Left neighbor : background 15
1st foreground pixel in 3rd row:
1st foreground pixel in 3rd row: Upper neighbor :foreground ( label 3)
Upper neighbor :background Left neighbor : foreground (label 4)
Left neighbor : background
4-neighb
our
Step 2. We have the following equivalent classes of labels
4-connected
{1,2} and {3, 4,5}
Step 3. Each pixel with labels 1 or 2 from the first step will be
assigned label 1, and each pixel with labels 3, 4, or 5
from the first step will be assigned label 2 16
Example 2
Original Binary image Pass 1:
in this path,
he take
the lift
Pass 2:
17
Example 3
Original Binary image Pass 1:
Pass 2:
Based on 4-Connected or
8-connected ?
18
Matlab bwlabel Function
You have to do Segmentation,
before
Connected Component
Figure after seg number of connected comp
◼ Syntax: (BW) (4or8)
L = bwlabel(BW,n)
[L,num] = bwlabel(BW,n)
◼ Description:
❑ L = bwlabel(BW,n) returns a matrix L, of the same size as
BW, containing labels for the connected objects in BW. n can
have a value of either 4 or 8, where 4 specifies 4-connected
objects and 8 specifies 8-connected objects (defaults to 8).
❑ The elements of L are integer values greater than or equal to
0. The pixels labeled 0 are the background. The pixels
labeled 1 make up one object, the pixels labeled 2 make up a
second object, and so on.
❑ [L,num] = bwlabel(BW,n) returns in num the number of
connected objects found in BW.
◼ See the supplemental notes on using lookup table.
19
Distances and Metrics
d 8 ( x, y ) d 4 ( x, y )
21
The Distance Transform
◼ How to find the distance of every pixel from a region
R?
◼ A well-known method is Chamfering
◼ Algorithm:
❑ Given: subset S of image
❑ Initialization: elements of S contain 0, and for others.
❑ Step1: Row by row, from top to bottom and left to right:
F ( p) = min F ( p), M f ( p, q) + F (q)
qN p( )
❑ Step2: Row by row, from bottom to top and right to left:
F ( p) = min F ( p), M b ( p, q) + F (q)
qN ( p )
22
Chamfer distance
• Average distance to nearest feature
How expensive is a
naïve
implementation?
Edge image
edges
original distance transform
// 0 if j is in P, infinity otherwise
◼ Mask1: 1
1 0 0 1
1
Forward mask, Mf Backward mask, Mb
◼ Mask 3:
11 11
11 7 5 7 11
5 0 0 5
11 7 5 7 11
11 11
34
Example
◼ Initialization:
0 0
(using 3-4 chamfer)
0
4 3 4 0
fw
3 0 3 bw 0
4 3 4
◼ Step1: ???
qN p( )
F ( p) = min F ( p), M f ( p, q) + F (q)
◼ Step2: ??? F ( p) = min F ( p), M b ( p, q) + F (q)
qN ( p )
35
Summary
◼ We discussed
❑ Neighbors and Adjacency
❑ Definition of path
❑ Equivalence relation
❑ Component labeling
❑ Distance metrics
◼ Euclidean distance
◼ Metrics for 4- and 8-path
◼ Chamfering
36