Use the concomp function to perform connected component labeling of an image. Two pixels are connected if they have the same value, and connectivity can be classified as 4 (only horizontal or vertical neighbors) or 8 (horizontal, vertical and diagonal neighbors). Connected components are a useful way to automate image feature recognition, bounding like areas and holes in the image.
3. Perform the connected component labeling using the first connectivity type.
In this case, there are two 4-connected components with pixel value 100.
4. Perform the connected component labeling using the second connectivity type.
In this case, there is one 8-connected component with pixel value 100.
5. Examine the effect of connected component labeling on a binary image, defined by a two-dimensional sinc function.
6. Define range variables.
7. Define a range of values.
8. Define an image matrix.
9. Define a threshold and then binarize and plot the image.
(cc_binarized.bmp)
10. Define a foreground intensity value and the connectivity type, then apply the connected-components labeling algorithm to this image.
Counting the distinct image regions, the algorithm is expected to identify 9 unique connected components in this image.
11. Calculate the number of components found by the algorithm.
12. Define a color palette matrix, then use it to convert the grayscale matrix to color. This allows you to look at the connected-component image using false color to enhance the components visually.
(color_d.bmp)
The 4-column colormap matrix specifies grayscale intensity in the first column, and RGB values in the second through fourth columns, respectively.
13. Compute the size of the 9 components.
14. Extract the largest single component (index 3, size 35 pixels) from this image and display it, again in false color.
(cimg_3.bmp)
The matrix comp is a 101 x 101 matrix of 0's except for elements that correspond to the largest component. The pixels of comp are multiplied by 3 in order to preserve the color of the component.