Image Topology 329
Returning again to Figure 11.20(b), since C(p) = 1 the central pixel p is 8-simple and so
can be deleted without affecting the 8-connectivity of the object. But since A(p) = 1, the
central pixel p is not 4-simple and so cannot be deleted without affecting the 4-connectivity
of the object. This is exemplified in Figure 11.3.
Note that A(p) and B(p) can be computed simply by using the various labeling functions
discussed earlier. For example, consider the neighborhood shown in Figure 11.20(b):
MATLAB/Octave
>> n = [1 1 0;1 1 1;0 0 1]
>> n(5) = 0;
>> max(max(bwlabel(n,4)))
ans =
2
>> max(max(bwlabel(n,8)))
ans =
1
Similarly:
Python
In : from skimage.measure import label
In : n = np.array([[1,1,0],[1,1,1],[0,0,1]])
In : n[1,1] = 0
In : label(n,4,background=0).max()+1
Out: 2
In : label(n,8,background=0).max()+1
Out: 1
How Not To Do Skeletonization
So now we know how to check if a pixel can be deleted without effecting the connectivity
of the object. 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 is as follows:
At each step, find all foreground pixels that are 4-simple and delete them all.
Sounds good? Let’s try it on a small rectangle of size 2 × 4:
0 0 0 0 0 0
0 1 1 1 1 0
0 1 1 1 1 0
0 0 0 0 0 0
If we check the pixels in this object carefully, we will find that they are all 4-simple. Deleting
them all will thus remove the object completely: a very undesirable result. Clearly we need
to b e a bit more careful about which pixels we can delete and when. We need to add an
extra test for deletability, so that we do not delete too many pixels.
We have two options here:
1. We can provide a step-wise algorithm, and change the test for de letability at each
step.