Consider the following image
I would like to cluster the points obtained after edge detection and subsequently, would like to color the clustered edge points.
My attempt:
img = URLExecute["https://i.stack.imgur.com/4q309.png"];
edgeImg = img // EdgeDetect;
edgePoints = PixelValuePositions[edgeImg, 1];
clusteredEdgePoints = FindClusters[edgePoints, Method -> "NeighborhoodContraction"];
{edgeImg, Graphics[{ColorData["DarkRainbow"][RandomReal[]], Line[#]} & /@
clusteredEdgePoints]}
Question:
One can observe, FindClusters
did not group inner and outer ellipses. How should I tell FindClusters
to group inner and outer ellipses? or is there any other alternative?
Note: I would like to keep the question as general as possible that is I would not want to enter the number of clusters explicitly.
Some other images can be as follows:
img1 = URLExecute["https://i.stack.imgur.com/Z150N.png"];
img2 = URLExecute["https://i.stack.imgur.com/spkHI.png"];
FindClusters[edgePoints, 2, Method -> "Agglomerate", CriterionFunction -> "RSquared"]
. Playing around withMethod
andCriterionFunction
is worthwhile. $\endgroup$