Detecting multiple shapes in an image and calculating the average

This question can be answered with any type of programming language, because I need help with algorithms, but I prefer Delphi. I have the task of detecting and counting several shapes (between 1 and N - mostly circular or Elipse) of random images and calculate their middle and return them as image coordinates. The middle of each form may have a fill (but it does not matter). Shapes at least 1+ pixels apart. None of the shapes will be mixed with another or the angle of the image. The background of the image always has the same background color, which actually does not matter, because the borders / frames of the shapes always differ compared to the background. This makes it easy to detect shapes. I thought about going pixel by pixel and collecting the coordinates, and then drawing as an invisible rectangle / square around each shape to calculate the middle. Then I also heard about scanline, but I do not think that in this case it will be faster. So my question is: how can I calculate:

  • How many figures in the picture.
  • How can I calculate the (more or less) exact midpoint of them.

A few shots to visualize the task:

This is an image with random shapes (mostly close circles). As you can see, they are different from each other.

Shapes in a picture

Then I could easily draw / calculate an imaginary rectangle / square around each figure and calculate the middle of it like this: Shapes in a picture with rectangles / squares around them

After I have the rectangles / squares. I can easily figure out the middle. How to start?

PS: I drew some circles in mspaint. I must add that all the figures are CLOSED, which allows to fill EVERY shape on the image without problems!

Thank you for your help.

+6
source share
1 answer

Calculate MSER (maximum stable extreme areas) for the image. I can not explain this algorithm here. More detailed information about the algorithm can be found in the page Maximum stable extreme regions .

It will also give you a centroid.

This algorithm is implemented as built-in functions in OpenCv and Matlab 2012b.

Another method that I can think of, and possibly simpler than the previous one, is to use the algorithm of related components and counting the number of objects. More information on this can be found in Gonzalez and Woods' book on digital image processing.

0
source

All Articles