Skip to main content
added 1278 characters in body
Source Link
Sumit
  • 16k
  • 2
  • 33
  • 74

Here is what I get.

img = Import["https://i.sstatic.net/o3S3Q.jpg"];

red = Fold[ImageSubtract, #[[1]], Rest[#]] &@ColorSeparate[img]

enter image description here

b = Binarize[red]

enter image description here

pos = ComponentMeasurements[b, {"Centroid", "EquivalentDiskRadius"}];
Length[pos]

633

Fine Tuning

Since the flowers in the top left corner are comparatively dull in colour, they are not properly identified. In such case a segment wise fine tuning may be helpful.

Consider a $300 \times 300$ block at top left corner. The previous method give 13 flower in this region.

im2 = ImageTake[img, {0, 300}, {0, 300}];

red = Fold[ImageSubtract, #[[1]], Rest[#]] &@ColorSeparate[im2]
b = Binarize[%];
pos = ComponentMeasurements[b, {"Centroid", "EquivalentDiskRadius"}];
Length[pos]

13

Now we do a manual fine tuning by eliminating other colors.

im3 = ColorReplace[im2, Green, 0.3];
MorphologicalComponents[im3] // Colorize;
ColorReplace[%, DominantColors[%]] // Binarize;
fls = ComponentMeasurements[%, {"Centroid", "EquivalentDiskRadius"}];
Length[fls]

92

Show[im2, Graphics[{Red, Circle[#, 10] & /@ fls[[All, 2, 1]],
                    Black, Circle[#, 10] & /@ pos[[All, 2, 1]]}]]

enter image description here

So our count increases by (92-13) = 79.

You might want to use this method for the whole image. In that case it will consider the lady as a lot of flowers and that would be 'mathematically' incorrect.

Here is what I get.

img = Import["https://i.sstatic.net/o3S3Q.jpg"];

red = Fold[ImageSubtract, #[[1]], Rest[#]] &@ColorSeparate[img]

enter image description here

b = Binarize[red]

enter image description here

pos = ComponentMeasurements[b, {"Centroid", "EquivalentDiskRadius"}];
Length[pos]

633

Here is what I get.

img = Import["https://i.sstatic.net/o3S3Q.jpg"];

red = Fold[ImageSubtract, #[[1]], Rest[#]] &@ColorSeparate[img]

enter image description here

b = Binarize[red]

enter image description here

pos = ComponentMeasurements[b, {"Centroid", "EquivalentDiskRadius"}];
Length[pos]

633

Fine Tuning

Since the flowers in the top left corner are comparatively dull in colour, they are not properly identified. In such case a segment wise fine tuning may be helpful.

Consider a $300 \times 300$ block at top left corner. The previous method give 13 flower in this region.

im2 = ImageTake[img, {0, 300}, {0, 300}];

red = Fold[ImageSubtract, #[[1]], Rest[#]] &@ColorSeparate[im2]
b = Binarize[%];
pos = ComponentMeasurements[b, {"Centroid", "EquivalentDiskRadius"}];
Length[pos]

13

Now we do a manual fine tuning by eliminating other colors.

im3 = ColorReplace[im2, Green, 0.3];
MorphologicalComponents[im3] // Colorize;
ColorReplace[%, DominantColors[%]] // Binarize;
fls = ComponentMeasurements[%, {"Centroid", "EquivalentDiskRadius"}];
Length[fls]

92

Show[im2, Graphics[{Red, Circle[#, 10] & /@ fls[[All, 2, 1]],
                    Black, Circle[#, 10] & /@ pos[[All, 2, 1]]}]]

enter image description here

So our count increases by (92-13) = 79.

You might want to use this method for the whole image. In that case it will consider the lady as a lot of flowers and that would be 'mathematically' incorrect.

Source Link
Sumit
  • 16k
  • 2
  • 33
  • 74

Here is what I get.

img = Import["https://i.sstatic.net/o3S3Q.jpg"];

red = Fold[ImageSubtract, #[[1]], Rest[#]] &@ColorSeparate[img]

enter image description here

b = Binarize[red]

enter image description here

pos = ComponentMeasurements[b, {"Centroid", "EquivalentDiskRadius"}];
Length[pos]

633