# Detect circles in image

I have an image that has pixelated circles in it (a cross section of wires). I want to identify the wires, their location and count them.

The circles never overlap and the wires are all within a 95% radius. However the spacing might not be exact as there can be gaps between the wires.

What is a good way to find the geometric mean of the group of pixels that represent a wire?

The above picture is what I would like to do, to fit a circle to a group of pixels (which I did using paint). I would think that the first step is to find the geometric mean of the group.

I did try using a tophat kernel and threshold to emphasize the centers, but I end up with a few pixels and no center pixel. I need to identify the center and end up with only one pixel which is difficult to do with thresholding since the pixel values differ in brightness.

Raw picture:

• Can you post a raw picture? – Tolga Birdal Oct 4 '17 at 23:14
• Yep, its small though – Voltage Spike Oct 4 '17 at 23:32
• This is too low res. Why do you work with such an image? – Tolga Birdal Oct 4 '17 at 23:58

1) Normalize your image to range $[0,255]$.

2) Select a threshold and threshold the image. For your image, what worked is: $\tau=[140-150]$.

3) Compute a Euclidean distance transform.

4) Apply watersheds segmentation.

If I apply this procedure, here is what I get:

Not perfect, but maybe a good start. The result looks similar to performing a Voronoi diagram on a smoothed/noise filtered version of the image.

Now to each region, one could fit a circle, using any algorithm (edge extraction and fitting or Hough transform etc.) For now, I used a simple circle fitting to the edges:

Again, not the best, but could be a sufficient starting point.

I also think that you would find the following useful:

Segmentation Methods for Light Microscope Image

Detecting Spheric Particles