Functions > Image Processing > Feature Extraction > Example: Shape Features
  
Example: Shape Features
Use the shape_features and concomp functions to compute shape-related features of an image and perform connected component labeling of pixels.
shape_features is useful for computing features such as centroids and spatial variances and moments of an input image. This function is used with image morphology and connected component labelling techniques to classify objects in an image. The function returns a matrix whose rows correspond to the component labels in the image, and whose columns correspond to calculated features. You can check which columns correspond to which feature by checking the overview of Shape Features.
concomp performs connected component labeling of pixels with grayscale value fg in matrix M.
For information on using this example, refer to About Image Processing Examples.
1. Read in an image.
Click to copy this expression
(part.gif)
2. Define the structuring elements matrix (4 orthogonal neighbors) and its row/column coordinates.
Click to copy this expression
Click to copy this expression
Click to copy this expression
3. Turn the image into a simple, connected component image by binarizing, using morphology functions to simplify it.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Erosion spreads light objects in an image further apart. Dilation enlarges light objects, reassembling an image that has become disjointed. The intensity threshold at which to erode or dilate is set to 1.
4. Apply the connected component labeling function to the simplified image, using 8-connected neighbors.
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
5. Compare the simplified and the component-connected images.
Click to copy this expression
Click to copy this expression
Click to copy this expression
(part_clean.bmp)
(part_color.bmp)
The component-connected image is shown in false color to make the five different connected components more obvious.
6. Apply the shape_features function to the component-connected image.
Click to copy this expression
The output is 5-row (1 row per connected component), 51-column (one column per feature) output matrix. Pick out a few features of the components.
7. Examine the X and Y centroid coordinates.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
8. Examine the X and Y spatial variances.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
9. Examine the area.
Click to copy this expression
Click to copy this expression
10. Examine the invariant moment 1.
Click to copy this expression
Click to copy this expression
The shape_features function does not use the built-in ORIGIN variable, which specifies the starting index of an array for other functions.