Digital Image Processing
Lecture 12: Image Topology
April 11, 2005
Prof. Charlene Tsai
Before Lecture …
Mid-term exam
Date: 4/18
Time: 10:15~11:30
Venue: ??? (will announce online)
Materials: mostly from the in-class quizzes
and homeworks.
All in-class quizzes (up to lecture 11) are
available online.
Digital Image Processing
Lecture 1
2
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.
A region with 3
connected
components
(objects)
A region with
2 holes
Digital Image Processing
Lecture 1
3
Another example
How many bacteria here?
Digital Image Processing
Lecture 1
4
Neighbors and Adjacency
We often have interests in classifying pixels into
different categories
Neighbourhoods:
4 4-nghbr
8 8-nghbr
Two pixels P and Q are 4-adjacent if they are 4neighbours of one another, and 8-adjacent if they are
8-neighbours of one another.
•
4-adjacent
•
P
•
•
Digital Image Processing
Lecture 1
•
•
•
•
P
•
•
•
•
8-adjacent
5
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
If the path contains only 4-adjacent pixels, then P, Q
are 4-connected.
If the path contains 8-adjacent pixels, then P and Q
are 8-connected
Digital Image Processing
Lecture 1
6
Components
A set of pixels all of which are 4-connected to
each other is called a 4-component; if all the
pixels are 8-connected the set is an 8component.
One 8-component
4-component
Digital Image Processing
4-component
Lecture 1
7
Formal Definition of a Path
A 4-path from P to Q is a sequence of pixels
P = p0, p1, p2, …, pn = Q
such that for each i=0,1,…, n-1, pixel pi is 4adjacent to pixel pi+1.
An 8-path is where the pixels in the sequence
connecting P and Q are 8-adjacent
Digital Image Processing
Lecture 1
8
Properties of Connectivity –
Equivalence Relations
A relation x~y between two objects x and y is
an equivalence relation if the relation is
Reflexive:
Symmetric:
Transitive:
Examples for equivalence relation?
Examples that are not equivalence relation?
Digital Image Processing
Lecture 1
9
Equivalence Relations
Some examples:
— Numeric equality
— Set cardinality
— Connectedness
Examples of some relations
which are not equivalence:
— Personal relations
— Subset relation
— Pixel adjacency
The importance of the equivalence relation concept is
that it allows us a very neat way of dealing with
issues of connectedness.
Equivalence class: the set of all objects equivalent
to each other.
Digital Image Processing
Lecture 1
10
Connected Component Labelling
Define the components of a binary image as
being the equivalence classes of the
connectedness equivalence relation.
Finding all equivalence classes of connected
pixels in a binary image is called connected
component labelling.
The result of connected component labeling
is another image in which everything in one
connected region is labelled "1" (for
example), everything in another connected
region is labelled "2", etc.
Digital Image Processing
Lecture 1
11
Connected Component Labelling (con’d)
Labelling all the 4-components of a binary
image, starting a the top left and working
across and down.
“Scan” the image row by row moving across
from left to right.
Assign labels to pixels in the image; these
labels will be the numbers of the components
of the image.
A pixel in the image will be called a foreground
pixel (fp); a pixel not in the image will be called
a background pixel (bp).
Digital Image Processing
Lecture 1
12
Connected Component Labelling:
Algorithm
1. Check the state of p. If it is a bp, move on to the next
scanning position. If it is fp, check the state of u and
l. If they are both bp, assign p a new label.
If only one of u and l are fp, assign the label to p
If both u and l are fp, but different labels, assign
either label to p, and make the 2 labels
equivalent.
2. At the end of the scan, all foreground pixels have l
been labelled, but some labels may be equivalent.
Then sort the labels into equivalence classes, and
assign a different label to each class.
3. Do a second pass through the image, replacing the
label on each foreground pixel with the label
assigned to its equivalence class in the previous
step
Digital Image Processing
Lecture 1
u
p
13
Example 1
The first foreground pixel
Upper neighbor : non-existent
Left neighbor : background
First foreground pixel in 2nd row
Upper neighbor : background
Left neighbor : non-existent
Step 1.
2nd foreground pixel in 2nd row
Upper neighbor : foreground
Left
neighbor : foreground
Digital Image Processing
3rd foreground pixel in 2nd row
Upper neighbor : background
LeftLecture
neighbor
: background
1
14
1st foreground pixel in 3rd row:
Upper neighbor :background
Left neighbor : background
1st foreground pixel in 3rd row:
Upper neighbor :foreground ( label 3)
Left neighbor : foreground (label 4)
Step 2. We have the following equivalent classes of labels
{1,2} and {3, 4,5}
Assign label 1 to the first class, and
label 2 to the second class
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
Digital Image Processing
Lecture 1
15
Example 2
Original Binary image
Pass 1:
Pass 2:
Digital Image Processing
Lecture 1
16
Example 3
Pass 1:
Original Binary image
Pass 2:
Digital Image Processing
Lecture 1
17
Matlab bwlabel Function
Syntax:
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 4connected 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.
Digital Image Processing
Lecture 1
18
Distances and Metrics
A distance function d(x,y) is called a metric if
it satisfies the following:
1. d x, y d y, x (symmetry)
2. d x, y 0 and d x, y 0 iff x y (positivit y)
3. d x, y d y, z d x, z (the triangle inquality)
A standard distance metric is Euclidean
distance (a straight line between 2 points)
d x, y
where
x1 y1 2 x2 y2 2
x x1 , x2 and y y1 , y2
Digital Image Processing
Lecture 1
19
Distance Metrics for Grid
d8 x, y
d 4 x, y
The Euclidean distance is
52 22 5.39
For 4-path and 8-path?
d 4 x, y x1 y1 x2 y2 (taxicab metric)
d8 x, y max x1 y1 , x2 y2
Digital Image Processing
Lecture 1
20
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
Digital Image Processing
Lecture 1
21
Masks for Chamfering
Mask1:
1
1
0
0
1
Forward mask, Mf
1
Backward mask, Mb
Mask2: 3-4 chamfer (most popular)
4
3
3
0
4
4
Forward mask, Mf
Digital Image Processing
Lecture 1
0
3
3
4
Backward mask, Mb
22
Masks for Chamfering (con’d)
Mask 3:
11
11
11
7
5
5
0
7
11
11
7
11
Forward mask, Mf
Digital Image Processing
0
5
5
7
11
11
Backward mask, Mb
Lecture 1
23
Example
Initialization:
(using 3-4 chamfer)
fw
4
3
4
3
0
3
4
3 bw
4
Step1: ???
0 0
0
0
0
F ( p) min F ( p), M f ( p, q) F (q)
qN p
F ( p), M b ( p, q) F (q)
Step2: ??? F ( p) qmin
N p
Digital Image Processing
Lecture 1
24
Summary
We discussed
Neighbors and Adjacency
Definition of path
Equivalence relation
Component labeling
Distance metrics
Euclidean distance
Metrics for 4- and 8-path
Chamfering
Digital Image Processing
Lecture 1
25
© Copyright 2026 Paperzz