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.

Then I could easily draw / calculate an imaginary rectangle / square around each figure and calculate the middle of it like this: 
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.
source share