Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter contours made of overlapping circles in OpenCV

I am working, using OpenCV/C++ framework, on a program that basically count elliptical objects that can overlap.

After threshold the image and finding contours of all the objects

My next step involves excluding object that are not made of overlapping ellipses (I will segment the remaining ones later).

I end-up with objects such as these ones:

enter image description here

In this example image, all the objects in the right are negative whilst the ones in the left are valid.

My current filter excludes object mainly on the ground of their isoperimetric quotient. However, as I have objects featuring different sizes and noise, I am not always satisfied with this approach.

Ideally, I would like to have an additional metric to increase the efficiency of my current filter.

Since I have to repeat this analysis on many contours, it should not be to costly.

I have thought about approaches such as:

  • Something based on an histogram of the value of the angle between all triplets of successive points in the contour ?
  • Mathematically fitting a "poly-ellipse" (I would have no idea about how to do that)?
  • Match freeman chains ?

But I am convinced that I missed something obvious that is more efficient and less messy. Do you have any suggestions, Thank you :),

EDIT: As Regis rightly suggested, any shape could in fact be made of a sufficient number of circles. Therefore, in order to make my problem solvable, I will add the following assumptions:

  1. No more than 16 ellipses/object.
  2. The ellipses cannot be to flat: Major axis/Minor axis < 3.
  3. Within an object, the area of the largest ellipse over the area of the smallest one must be lower than 10.
like image 549
Quentin Geissmann Avatar asked Jul 29 '12 17:07

Quentin Geissmann


1 Answers

One possibility would be to try:

  1. Extract contours of objects
  2. Sample points at regular spacing along the contour
  3. Use these points to determine the direction at regular spacing (it may be best to use a complex number to express this direction to avoid wraparound problems)
  4. Use these directions to compute the curvature at regular spacing
  5. Base a metric on this curvature, e.g. look for objects which have more than 80% of the curvature samples in the correct range.

The graph you are expecting to see for curvature is a series of constant values (or slowly varying if the shape is an ellipse instead of a circle), with sudden discontinuities where it changes from one circle to another.

If your image is noisy, you may wish to lowpass filter the curvature values first.

Shapes made out of circles/ellipses will mostly have significant curvature all around the perimeter, while shapes made out of straight edges will have parts of low curvature.

like image 196
Peter de Rivaz Avatar answered Oct 12 '22 08:10

Peter de Rivaz