You are on page 1of 8

Medialogi, Gruppe 835

Thinning is a morphological operation that is used to remove selected foreground pixels from binary images, somewhat like erosion or opening. It can be used for several applications, but is particularly useful for skeletonization. In this mode it is commonly used to tidy up the output of edge detectors by reducing all lines to single pixel thickness. Thinning is normally only applied to binary images, and produces another binary image as output [1], see figure [1].

Skeleton by the means of Thinning


Principle

Figure 1: From left: 1. original shape, 2. Thinning, 3. Skeletonization

Medialogi, Gruppe 835

Algorithm
The thinning operation makes use of a structuring element. These elements are of the extended type meaning they can contain both ones and zeros. The thinning operation is related to the hit-and-miss transform and can be expressed quite simply in terms of it. The thinning of an image I by a structuring element J is:

Where the subtraction is a logical subtraction defined by

In other words the origin of the structuring element is translated to every possible pixel position within the image. At each position the element is compared to the underlying image. If the structuring element and the image exactly match the image pixel underneath the origin of the structuring element is set to zero (background). If they dont match it is left unchanged. Note that the origin of the element must never be zero but it can be either blank or one.

Skeletonizing algorithm
The skeleton of a region may be defined via the Medial Axis Transformation (MAT): The MAT of a region R with border B is as follows: For each point p in R, we find its closest neighbor in B If p has more than one such neighbor, it I said to belong to the medial axis (skeleton) of R

The MAT of a region has an intuitive definition based on the so-called prairie fire concept. Consider an image region, as a prairie of uniform dry grass, and suppose a fire is lit along its border. All fire fronts will advance into the region at the same speed. The MAT of the region is then the set of points reached by more than one fire front at the same time, see figure [2].

Figure 2: Boundary and superimposed skeleton on top. Direct implementation of MAT of a region is typically an expensive computational process, as it involves calculating distance of every interior point to every point on the boundary of a region. To increase the

Medialogi, Gruppe 835

efficiency of these calculations, thinning algorithms have been designed that iteratively delete edge points on the region to the constraints that deletion of these points [2]. 1) Does not remove end points 2) Does not break connectivity 3) Does not cause excessive erosion of the region Thinning algorithm In order to find the skeleton, Gonzales and Woods [2] present an algorithm for thinning binary regions. Region points are assumed to have value 1, and background points value 0. The iterative method consists of successive passes, where certain conditions have to be met or the point in question is deleted (inverted). The definition of a contour point is any pixel with value 1, that has at least one 8-neighbor valued 0. The 8neighbor notation is shown is figure [3].

Figure 3: The 8-neighbor relationship For step 1 of the iteration, the following conditions for P1 must be met in order for the point to change. That is being converted to background value. a) b) T(P1) = 1 c) P2 * P4 *P6 = 0 d) P4 * P6 * P8 = 0 Where N(P1) is the number of non-zero neighbors of P1, aka. P2+P3++P8+P9 = N(P1). And T(P1) is the number of 0 -> 1 transitions that happens in ordered sequence, aka. P2,P3,P8,P9. So if the assigned points near P1 looks like figure 3, N(P1) = 4 and T(P1)= 3.

Figure 4: An example of processing the point P1

Medialogi, Gruppe 835

In step 2 conditions a) and b) remains the same, but c) and d) are changed to: c) P2 * P4 * P8 = 0 d) P2 * P6 * P8 = 0 If one or more conditions in a) -> d) are violated, the value of the point in question are unchanged, if all conditions are satisfied the point is flagged for deletion. However the point is not deleted until all border points have been processed. Once all border points are processed, results from step 1 is applied, then follows processing the conditions in step 2, and then deleting points flagged in step 2. This routine covers one iteration of the algorithm, which is then repeated for each point. Condition a) is violated when contour point P1 only has one or seven neighbors with the value 1. If it has one neighbor, the point is the end of a skeleton stroke, and should not be deleted. If it has seven neighbors, deleting the point P1 would cause erosion into the region. Condition b) is violated when it is applied to a point on a stroke 1 pixel thick. So this condition prevents deletion of points, which would cause disconnection of segments of a skeleton structure. When a point P1 satisfy c) and d), as well as a) and b), the point is either an east or south boundary point or a north-west corner point in the boundary. In either case P1 is not part of the skeleton and should be removed. Similarly the conditions c) and d) correspond to north or west boundary points, or a south-east corner point. All of the conditions having minimum 2 zero 8-neighbors. Example To start a standard image of a human bone has been converted into a binary image using the ImageJ program [1]. Figure [5] shows the results.

Figure 5: The original picture converted into a bitmap picture Running the MATLAB code presented in the previous section, but changing the number of iterations the algorithm runs through, can be represented as stopping the code before skeleton reaches a single stroke.

Medialogi, Gruppe 835

Figure 6: An illustration Figure [6] shows the effect of changing the iterations to 10 in picture A, and 20 in picture B. The change should be implemented in the last paragraph of the function. >> fs = bwmorph(f, 'skel', 10); >> imshow(f), figure, imshow(fs) The INF, which is used in the book by Gonzales and Woods, refers to running the iterations until the skeleton no longer changes. At some points, no additional changes are made to the structure of the skeleton, and so the code is stopped.

Figure 7: Picture A (left) and B (right) shows results of MATLAB code. The end result is a skeleton of the bone as shown in figure [7] picture A and a superimposed image of the skeleton on top of the original binary image as picture B.

Medialogi, Gruppe 835

Implementation
The Skeleton via thinning algorithm has been implemented in MatLab. The following chapter will describe the code used for this implementation. Before loading an image it must be changed into a binary image in order to perform morphological operations on it. imread(); loads the picture. bwmorph(); is a function available in Matlab, which is able to apply a specific morphological operation to a binary image. bwmorph requires (imageName, morphologicalOperation, numberOfAppliedOperations). In this cast the operator is thinning and it is repeated 10 and 20 times. imshow(); displays the images.
f = imread('binary.tif); g1 =bwmorph(f, 'thin', 10); g2 =bwmorph(f, 'thin', 20); imshow(g1), figure, imshow(g2)

The original picture

10times thinning

20times thinning

The final result can be displayed when applying the morphological operation Inf times. In order of displaying the two different main subjects of this mini-project the method skeletonization has also been implemented and displayed beneath this chapter.
ginf = bwmorph(f, 'thin', Inf); fs = bwmorph(f, 'skel', Inf); imshow(ginf), figure, imshow(fs)

Inf times thinning

Inf times skeletonization

Medialogi, Gruppe 835

Results
The original picture: 3D_WoodenGeisha. Another example: The original picture: Amazonas_River.

Transforming the picture into binary. Using ImageJ to transform the original picture into a binary picture is required before the skeletonization via thinning.

To filter some of the the noise away an open was used.

The results of the binary image shows the skeleton of the original image.

Remaining is the skeleton of the river, which makes it easier to determine the river meandering.

Medialogi, Gruppe 835

Reference
[1] http://homepages.inf.ed.ac.uk/rbf/HIPR2/thin.htm [2] Digital Image processing Gonzales, Woods. 2nd edition 2002 ISBN: 0201180758

You might also like