Functions > Image Processing > Morphological Processing > Example: Thinning and Skeletonization
Example: Thinning and Skeletonization
Use thin and skeleton to transform objects in an image into a set of lines that run roughly down the center of each object.
Unlike the thinning operation, skeleton retains the size of the input object. The endpoints of the skeleton extend all the way to the edges of the input object.
For information on using this example, refer to About Image Processing Examples.
thin
This function first binarizes the input image based on the threshold value b. The output is a binary image of structure lines or arcs of intensity 1 and background pixels of intensity 0.
1. Create an image of a rectangular box:
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
2. Apply the thinning function to the rectangular box using a threshold of 1:
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
(s1_thin.bmp)
Thinning a rectangle results in a single line that approximates the medial axis of the rectangle.
3. Read in an image containing the letter D and a period, and then apply the thinning function using a threshold of 128:
Click to copy this expression
Click to copy this expression
Click to copy this expression
(d_bw.bmp)
(d_bw_thin.bmp)
The application of thinning is used in optical character recognition technologies. Thinning preserves the basic shape and structure of the objects on the image.
4. Read in a more complex image, and then apply the thinning function using a threshold of 128:
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
(pinetree.bmp)
(pinetree_thin_b128.bmp)
skeleton
1. Apply the skeleton function to image M without specifying the optional threshold argument b:
Click to copy this expression
Click to copy this expression
(pinetree.bmp)
(pinetree_skltn.bmp)
2. Specify the threshold value b, and then apply the skeleton function to the same image:
Click to copy this expression
Click to copy this expression
Click to copy this expression
(pinetree.bmp)
(pinetree_skltn_b1.bmp)
3. Apply the skeleton function to the original image S using a threshold value of 1:
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
(s1_thin.bmp)
(s2_skltn.bmp)
The skeleton function first binarizes the input image based on the threshold value b. The output is a binary image of structure lines or arcs of intensity 1 and background pixels of intensity 0.
4. Read in a new image, and apply the skeleton function using a threshold of 128:
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
(flower.bmp)
(flower_skltn_b128.bmp)
5. Skeletonize the pine tree image using a threshold value of 128:
Click to copy this expression
Click to copy this expression
Click to copy this expression
(pinetree.bmp)
(pinetree_skltn_b128)
Was this helpful?