Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv SimpleBlobDetector filterByInertia meaning?

Tags:

opencv

I don't understand what filterByInertia means... neither do I understand the documentation's little description :

By ratio of the minimum inertia to maximum inertia. Extracted blobs will have this ratio between minInertiaRatio (inclusive) and maxInertiaRatio (exclusive).

like image 391
Kiarash Avatar asked Feb 08 '13 10:02

Kiarash


3 Answers

Blob Characteristics. The above image pretty much explains what the different filter parameters do. SimpleBlobDetector is happiest when it sees a circular blob, and different filters filter out different kids of deviations from the circular shape.

Inertia measures the the ratio of the minor and major axes of a blob.

The figure also shows the difference between circularity and inertia. I have copied this figure from Blob Detection Tutorial at LearnOpenCV.com

like image 160
Satya Mallick Avatar answered Oct 05 '22 02:10

Satya Mallick


I've been wondering this for a while also; the OpenCV documentation isn't very helpful when it comes to blob detection.

Based on the descriptions of other blob analyzers, the inertia of a blob is "the inertial resistance of the blob to rotation about its principal axes". It depends on how the mass of the blob (I guess in this case the area) is distributed throughout the blob's shape.

There's a lot of mathy stuff involved -- most of which I don't remember how to do -- but the result at the bottom of this page on the properties of binary images sums it up fairly well (blob detection is done by converting the input image to a series of binary images):

The ratio I_min/I_max gives us some idea of how rounded the object is. This ratio will be 0 for a line and 1 for a circle.

So basically, by specifying minInertiaRatio and maxInertiaRatio you can filter the blobs based on how elongated they are. An inertia ratio of 0 will yield elongated blobs (closer to lines) and an inertia ratio of 1 will yield blobs where the area is more concentrated toward the center (closer to circles).

like image 26
Walfie Avatar answered Oct 05 '22 02:10

Walfie


Here's a physical intepretation:

If you cut the blob out on a piece of card, you could find its center of gravity, and then attach an axle to it, crossing this point (the axle being parallel to the card), and then spin it, and measure its moment of inertia. Depending on the shape, you may get different values according to how you place the axle. For an ellipse, you get the lowest value when the axle is attached along the long (major) axis, and the largest when the the axle is placed along the short axis (so that more of the card is far from the axle). For a circle the inertia is always the same, of course.

If there are different values, there will be always be a 'max' inertia at some orientation, and a 'min' with the axle placed 90 degrees away from the 'max'. The inertia ratio is simply the ratio between these intertias, min/max.

For shapes which are not ellipses, the metric tells you whether the overall shape is roughly elongated, or roughly the same size in all directions; without caring in particular about an uneven boundary or cuts and concavities (which roundness and convexity look at).

Mathematically, it does something like this:

  1. Consider the set of points within the blob to be a population of (x,y) samples
  2. Find the mean of these, and the covariance matrix x vs. y
  3. Find the two eigenvalues of the covariance matrix (which are the same as its singular values, due to the nature of this matrix)
  4. The inertia ratio is the ratio between these two values, smallest/largest.
like image 34
greggo Avatar answered Oct 05 '22 04:10

greggo