Consider all pixels on the boundaries of foreground regions (i.e. foreground points that have at least one background neighbour). Delete any such point that has more than one foreground neighbour, as long as doing so does not locally disconnect (i.e. split into two) the region containing that pixel. Iterate until convergence.
Figure 1 Structuring elements for skeletonization by morphological thinning. At each iteration, the image is first thinned by the left hand structuring element, and then by the right hand one, and then with the remaining six 90° rotations of the two elements. The process is repeated in cyclic fashion until none of the thinnings produces any further change. As usual, the origin of the structuring element is at the center.
Figure 2 Example skeletonization by morphological thinning of a simple binary shape, using the above structuring elements. Note that the resulting skeleton is connected.
Figure 3 Some applications of thinning. 1 simply finds the boundary of a binary object, i.e. it deletes any foreground points that don't have at least one neighbouring background point. Note that the detected boundary is 4-connected. 2 does the same thing but produces an 8-connected boundary. 3a and 3b are used for pruning. At each thinning iteration, each element must be used in each of its four 90° rotations. Pruning is normally carried out for only a limited number of iterations to remove short spurs, since pruning until convergence will actually remove all pixels except those that form closed loops.
Figure 4 Shows the masks used in the character recognition example. 1 shows the mask used in combination with thinning to obtain the skeleton. 2 was used in combination with thinning to prune the skeleton and with the hit-and-miss operator to find the end points of the skeleton. Each mask was used in each of its 45° rotations.