Download - Image Topology ( Part 3 )
Image Topology (Part 3)
Dr. Bai-ling ZhangSchool of Computer Science &
MathematicsVictoria University of Technology
SCM3511 Image Processing 2, Week 5
Skeletonization: Example
Application Example: hand gesture recognition
Skeleton of a binary object: a collection of lines and curves which encapsulate the size/shape of the object.
What is a skeleton? A skeleton can be defined by medial axis of an object: a pixel is on the
medial axis if is equidistant from at least two pixels on the boundary of the object.
Methods of approaching the medial axis Imagine the object to be burning up by a fire which advances at a constant
rate from the boundary. The places where two lines of fire meet form the medial axis.
Consider the set of all circles lying within the object which touch at least two points on the boundary. The centres of all such circles form the medial axis.
Topological methods We can directly define those pixels which are to be
deleted to obtain the final skeleton. In general, we want to delete pixels which can be deleted
without changing the connectivity of an object: i.e., the number of components, the number of holes, or the
relationship of objects and holes unchanged
Example 1A non-deletable pixel: creates a hole
Example 2A non-deletable pixel: removes a hole
Example 3A non-deletable pixel: disconnects an object
Example 4A non-deletable pixel:
4-connectivity8-connectivity
4-connectivity
A pixel which can be deleted without changing the 4-connectivity of the object is called 4-simple;
A pixel which can be deleted without changing the 8-connectivity of the object is called 8-simple.
Neither 4-simpleNor 8-simple
8-simpleNot 4-simple
Check for deletability for a pixel
A pixel’s deletability can be tested by checking its 3x3 neighbourhood.
— The top two pixels and the bottom two pixels become separated, thus breaking up the object.
— The top two pixels and the bottom two pixels are joined by a chain of pixels outside the neighbourhood, i.e, all pixels will encircle a hole, and removing the central pixel will remove the hole
For this example, checking the deletability of the central pixel:
Check for deletability for a pixel
To check whether a pixel is 4-simple or 8-simple, introduce some numbers associated with the neighbourhood of a foreground pixel
Define Np : the 3x3 neighbourhood of p,
Np* : the 3x3 neighbourhood excluding p
A(p): the number of 4-components in Np*
C(p): the number of 8-components in Np*
B(p): the number of foreground pixels in Np*
A(p) = 2C(p) = 2B(p) = 4
A(p) = 2C(p) = 1B(p) = 5
The importance of simple points for deletion
Since C(p)=1 the central pixel is 8-simple and so can be deleted without affecting the 8-connectivity of the object. But since A(p)~=1, the central pixel is not 4-simple and so cannot be deleted without affecting the 4-connectivity of the object.
A(p): the number of 4-components in Np*
C(p): the number of 8-components in Np*
B(p): the number of foreground pixels in Np*
A foreground pixel p is 4-simple iff A(p)=1, and is 8-simple iff C(p)=1
• • o• • •o o •
A(p)=2 C(p)=1
• • o• • •o o •
• • o• • •o o •
Calculating A(p) and C(p) For A(p) we are only interested in the case where A(p)=1 and this can be determined by calculating the crossing number X(p) of a foreground pixel
The crossing number X(p) of a foreground pixel p is defined to be the number of times a 0 is followed by a 1 as we traverse the 8-neighbours of p in a clockwise direction
If X(p) =1, then A(p)=1 and so p is 4-simple
p1 p2 p3
p8 p p4
p7 p6 p5
p1, p2, p3, p4, p5, p6, p7, p8, p1
1 1 00 p 00 1 1
1, 1, 0, 0, 1, 1, 0, 0, 1 X(p)=2
Calculating A(p)
1 1 01 P 10 0 1
1, 1, 0, 1, 1, 0, 0, 1, 1 X(p)=2
1 1 11 P 11 0 0
1, 1, 1, 1, 0, 0, 1, 1, 1 X(p)=1
1 1 10 P 01 0 1
1, 1, 0, 0, 1, 0, 1, 0, 1 X(p)=3
Calculating crossing number in MatlabA matrix 3x3 matrix a in Matlab can be indexed using single indexing as:
Create two sequences:
(1). The neighbouring pixels in clockwise order:
(2) The neighbouring pixels starting at a(4):
a(1) a(4) a(7)a(2) a(5) a(8)a(3) a(6) a(9)
>>p=[a(1) a(4) a(7) a(8) a(9) a(6) a(3) a(2)];
>> pp =[p(2:8) p(1)];
Calculating crossing number in Matlab
pp(i) =p(i+1) with pp(8)=p(1).
A “0,1” is counted if for any i with , we have p(i)=0 andpp(i)=1. This will occur if and only if
is equal to 1.
>> crossnum = sum((1-p).*pp);
(1-p(i))*pp(i)
So
Calculating C(p) in Matlab
p1 p2 p3
p8 p p4
p7 p6 p5
• • oo • oo • •
• • o• • • o o •
_ _ _ _
2 3 4 4 5 6 6 7 8 8 1 2( ) [ ( )] [ ( )] [ ( )] [ ( )]C p P p p P p p P p p P p p
How not to do skeletonization In general, a skeletonization algorithm works by an iteration
process: at each step identifying deletable pixels, and deleting them. The algorithm will continue until no further deletions are possible.
One way to remove pixels:
At each step, find all foreground pixels which are 4-simple, and delete them all.
BUT….They are all 4-simple !Deleting them all will thus remove the object completely.
0 0 0 0 0 00 1 1 1 1 00 1 1 1 1 00 0 0 0 0 0
Zhang-Suen skeletonization algorithm
An extra test for deletability needed to avoid deleting too many pixels.Two options:1. Provide a step-wise algorithm, and change the test for deletability at each step2. Apply a different test for deletability according to where the pixel lies on the image grid.
Z-S algorithm
For odd iterations, delete only pixels which are on the right hand side, or bottom of an object, or on a north-west corner.
For even iterations, delete only pixels which are on the left hand side, or top of an object, or on a south-east corner.
Zhang-Suen algorithm
Delete all fagged pixels.
Continue until there are no more deletable pixels in two successive iterations.
Step NFlag a foreground pixel p=1 to be deletable if
1. 2B(p)62. X(p)=13. If N is odd, then p2 p4 p6 = 0
p4 p6 p8 = 04. If N is even, then p2 p4 p8 = 0
P2 p6 p8 = 0
If N is odd, then p4=0, or p6=0, or
p2=p8=0
If N is even, then p2=0, or p8=0, or
p4=p6=0
Item 1 ensures that we don't delete pixels which have only oneneighbour, or have seven or more.
The boxed pixels show those which will be deleted by steps 1
If N is odd, delete only pixels which are (1) on the right hand side, or (2) bottom of an object, or (3) on a north-west corner
Example: Step 1
Step 2:
If N is even , delete only pixels which are (1) on the left hand side, or (2) top of an object, or (3) on a south-east corner.
Matlab Implementation of Z-S algorithm
Set up lookup tables:
Apply these lookup tables alternately until there is no change in the image for two successive iterations.
Manage this by keeping three images at any given time: the current image, the previous image, and the last.
If the current and last images are equal, we stop. Otherwise, push the images back:
one for the odd iterations, one for the even.
last previousprevious current
current applylut(current,lut)
Example:
First create a binary image
L= zeros(12,10);L(2:11,2:6)=1; L(7:11,7:9)=1;
Then apply the zs algorithm:LS=zs(L)