# Help with image processing

Greetings all,

I have the attached image and I need to find an automatic way to get the coordinates of all circles that belongs to the first circle (inner). For that I used Python. I already have all the coordinates, I just need to find a way to know which one belongs to the first circle and which one is outside. I tried contour, radial profile, euclidean distance but I couldn’t make it work because it is not a perfect circle… Can you suggest me something? Someone told me to try here in the ImageJ forum, I never used such tool.

Image original and the first circle highlighted.

PS: the size of the circle and the number of coordinates (red dots) changes over time.

Thanks.

So if you try to compute the distance from each point to the center of the image, you cannot kick out the outliers that would have a larger distance ?

I could kick some of them, but I would still got some points outside the circle because they would be inside the working-distance range.

Some random ideas and questions.
How regular is the distribution of points? Will there always be X degrees of angle from some central point between two red spots?
How consistently centered is the image?

Could you segment based on “low values” (blue?) and size to obtain a large central object (no other blue intensity area is that large), then perform a distance transform from that central object to the red spot coordinates. If the images are similar to the ones shown, there should be a very small distance transform value from the edge of that large central object.

I guess the question is, since size changes over time, will the central blue area always be the largest blue area? Have the highest circularity?

Following what @Research_Associate has said:
It would be helpful if you could describe how you’ve identified the red spots and which packages you’re using.

I came across this `scipy.spatial.ConvexHull` which takes the points and generates a convex hull - I think you could generate a convex hull for all possible combinations of points (`itertools.product` or `itertools.combinations` would be useful here) and then pick the hull which uses the largest number of points but doesn’t encompass any points.

The points used to generate that convex hull should be the ones that belong to that inner circle. As a method of verification, you could use `scipy.ndimage.binary_fill_holes` to create a solid mask from which you can assess the circularity, diameter, etc (using `label` and `regionprops` from `skimage.measure`).

EDIT On reflection, I still think convex hull is probably the way forward, but it wouldn’t be so simple as described above. It would likely have to take into account the circularity of the resulting object, or evenness (addition of points to what’s displayed here would decrease circularity which could be estimated using the approaches mentioned in my last paragraph `skimage.measure` etc.)

Thanks for all the answers. I will provide a little more detail:

@awant First, to identify the red spots I am using basically some filters.maximum_filter and filters.minimum_filter together with ndimage.label and ndimage.center_of_mass… In short, using scipy.ndimage.

@Research_Associate, The image it will always be centered like shown in the initial post. The first circle only get smaller and then another circle bigger will show up. I need to assign all the red points (from initial radius to final radius) to the first circle and then the points of the second one to the next circle and so on. The blue central area get smaller with time because the radius of the first circle decreases until it complete disappears and only remains the second circle.

The size of the image doesn’t change over time, only the radius of the circle until it complete disappears. I kind solved by calculating distance over x and y axis separately and also by cutting more the image so I have only the main circle focused, removing unwanted red points as much as possible… Still testing to see if this is working properly.