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.
2. Define the structuring elements matrix (4 orthogonal neighbors) and its row/column coordinates.
3. Turn the image into a simple, connected component image by binarizing, using morphology functions to simplify it.
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.
5. Compare the simplified and the component-connected images.
(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.
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.
8. Examine the X and Y spatial variances.
9. Examine the area.
10. Examine the invariant moment 1.
The shape_features function does not use the built-in ORIGIN variable, which specifies the starting index of an array for other functions.