5

I have a pre-processed image, from which I have to get coordinates of some components.

sample image

There are 7 green components (pigs actually) that I have already isolated from an angry bird screen shot. So what I want is to locate those six components on the image.

I tried

ImageValuePositions[u, RGBColor[1, 0, 0], .1]
{ Mean[#1], Mean[#2]}& @@@ Transpose /@ FindClusters[%];
LocatorPane[ %, sample image]

But it doesn't work at all. Could anyone help me out?

sample2

How should I figure this out?

user10495
  • 515
  • 1
  • 5
  • 4

2 Answers2

6
Show[i, Graphics@{PointSize[Large], 
                  Point@ComponentMeasurements[
                           MorphologicalComponents[DeleteSmallComponents[
                                        ChanVeseBinarize[i, TargetColor -> Green], 10]], 
                           "Centroid"][[All, 2]]}]

Mathematica graphics

Edit

You can specify a convex method for the morph. components and then you won't need deleting the small components:

Show[i, Graphics@{PointSize[Medium], 
                  Point@ComponentMeasurements[
                           MorphologicalComponents[
                              ChanVeseBinarize[i, TargetColor -> Green], 
                           Method -> "Convex"],
                        "Centroid"][[All, 2]]}]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
2

Here's an approach quite similar to what you tried. First, allG is all the green points which are then clustered into the 7 groups called clus. The mean of each group provides an approximation to the central point of the clusters.

img=Import["https://i.stack.imgur.com/uO8QJ.png"];
allG = ImageValuePositions[img, Green];
clus = FindClusters[allG, 7];
Mean[clus[[#]]] & /@ Range[7]
{{182.542, 179.264}, {288.831, 20.1529}, {299.942, 18.1395}, {315.611, 15.8951}, 
 {255.067, 13.1082}, {230.66, 5.70168}, {255.8, 4.24286}}

Consolidating this into one command yields:

Mean[FindClusters[ImageValuePositions[img, Green], 7][[#]]] & /@ Range[7]

which gives the same answer as above.

bill s
  • 68,936
  • 4
  • 101
  • 191