D.Badawi
D.Badawi

Reputation: 175

Number of dots in an image

I have an image which has plain dots scattered across. The dots are of the same size and they are solid (I can read the color to decide whether a point is inside or not). What is the most efficient algorithm to find the exact number of the dots? I thought of Monte Carlo, but I don't know the sufficient number of random points that I should use. Any advice? Edit: it's a white image that contains dots only.

Upvotes: 0

Views: 74

Answers (1)

MBo
MBo

Reputation: 80197

This is good case for image processing algorithms. For example, using OpenCV library, you could exploit the next approach:

If image format is color, convert it to gray scale (cvtColor)

Make image binary (pure black and white) with color inversion (cvThreshold with THRESH_BINARY_INV) to make white spots on the black background

Find connected components (findContours) - after that contours.size gives you number of dots

If you don't want to use any libraries, key point is connected components labeling

The simplest way to make CCL for small dots - using of Floodfill algorithm.

Make flood fill for background pixels, mark them with 0.

Scan through all pixels. When you meet unmarked one (at X,Y), start new flood fill with next marker value K (1,2 etc).

After each floodfill return to the next coordinate (X+1,Y) and continue scanning.

The last K value is the number of spots.

Upvotes: 2

Related Questions