44
11.7. THINNING AND SKELETONIZATION
177
In that context, the once
only parameter of thinning is one, so that it would
erode an image only one time. Setting once
only to zero causes thinning to
keep eroding until the objects in the image are all one-pixel wide.
This basic thinning technique works well, but it is impossible to re-create
the original object from the result of thinning. Re-creating the original re-
quires the medial axis transform.
The medial axis transform nds the points in an object that form lines
down its center, that is, its medial axis. It is easier to understand the medial
axis transform if you rst understand the Euclidean distance measure (don’t
you lovethese bigterms that really mean verysimplethings?). The Euclidean
distance measure is the shortest distance from a pixel in an object to the edge
of the object. Figure 11.30 shows a square, its Euclidian distance measure
(distance to the edge), and its medial axis transform.
The medial axis transform consists of all points in an object that are
minimally distant to more than one edge of the object. Every pixel in the
bottom of Figure 11.30 was the shortest distance to two edges of the object.
The advantage of the medial axis transform is you can re-create the original
object from the transform (more homework). Figure 11.31 shows a rectangle
(from Figure 11.29) and its medial axis transform. Figure 11.32 shows a
block letter A, and going clockwise, the result of exterior outline, medial axis
transform, and thinning.
Listing 11.2 shows the source code to implement the Euclidean distance
measure and the medial axis transform. edm calculates the Euclidean dis-
tance measure. It loops through the image and calls distance
8to do most of
the work. distance
8has eight sections to calculate eight distances from any
value pixel to the nearest zero pixel. distance
8returns the shortest distance
it found.
The functions mat and mat
dcalculate the medial axis transform in a
similar manner. mat loops through the image and calls mat
dto do the
work. mat
d calculates the eight distances and records the two shortest
distances. If these two are equal, the pixel in question is minimally distant
to two edges, is part of the medial axis transform, and causes mat
dto return
value.