Extract individual white parts of binarized image
One approach is to use:
MorphologicalComponents[Erosion[img, 1]] // Colorize
Then you can access the individual colored sections using ComponentMeasurements. For example:
ComponentMeasurements[comp // Colorize, {"Image", "Count", "Mean"}, All, "Dataset"]
gives a long list of all the segments and how large they are. You can sort them by many different properties. Here is a piece of the output:
You're looking for MorphologicalComponents[*the image*]
. This function groups connected areas of white pixels and assigns them a single integer. For example;
mc = MorphologicalComponents[Binarize[*the image*]]
Then
Graphics[Flatten@
Table[Style[Text[mc[[i, j]], {i, j}], 8], {i, 300, 350}, {j, 300,
350}], ImageSize -> 8 72]
gives the following subset of the mc
data
As you can see, each cluster of white pixels now has a unique number, such as 81 in the case of the upper left corner of this graphic. The 0s correspond to the black areas. You can use SelectComponents[mc, -criteria-]
to search for large, small, round, etc features. Below I choose the 10 largest.
Colorize@SelectComponents[mc, "Area", -10]
To see which integers are assigned to which cluster of white pixels, use the following;
centroids = ComponentMeasurements[mc, "Centroid"];
where centroids[[1]]
gives 1 -> {674.491, 672.}
Show[
Colorize@mc,
Graphics[ {White,
Table[ Text[centroids[[i, 1]], centroids[[i, 2]]], {i, Length@centroids}]}]
]