 # 2nd moment of area: formula used?

Hi,

I am using both a custom code and the ‘slice geometry’ module from ImageJ to compute the maximum and minimum moment of area of a stack of slices. However, I get a difference between the two outputs and I don’t get why.

In my custom code, I use the following formula, based on Mohr’s circle, to compute Imin and Imax:
I_min = (Ixx + Iyy)/2 - sqrt( (Ixx-Iyy)^2/2 + Ixy^2 ) ;
I_max = (Ixx + Iyy)/2 + sqrt( (Ixx-Iyy)^2/2 + Ixy^2 ) ;

Except this formula, every pre-processing step is the same. Therefore, does anyone know which precise formula is applied in ‘slice geometry’?

Thanks a lot for the help !

Code is available to read here

No particular geometry is assumed: it’s just a sum of squares of distances from an axis (and parallel axis theorem IIRC). You should get a very similar answer that an annulus-assuming method gets if you run it on an annulus or circle.

Hi,

Thanks a lot for the reply, I have found my mistake, which was “stupidly” in the parentheses:

``````I_min(k) = (Ixx + Iyy)/2 - sqrt(  (Ixx-Iyy)^2/4  + Ixy^2 ) ;
I_max(k) = (Ixx + Iyy)/2 + sqrt(  (Ixx-Iyy)^2/4  + Ixy^2 ) ;
``````

However, could you explain me what you mean by “each pixel’s own moment” ?

Each pixel represents a finite area in the plane, not an infinitely small point. So for each pixel you have to add a small adjustment (“the pixel’s own moment”) to compensate, which is the squared area of the rectangle (usually a square) within the pixel grid divided by 12, because the second moment of area of a square is w⁴ /12

``````// + /12 is for each pixel's own moment
final double Myys = sxxs - (sxs * sxs / sumAreaFractions) + sumAreaFractions * vW * vW / 12;
final double Mxxs = syys - (sys * sys / sumAreaFractions) + sumAreaFractions * vH * vH / 12;
final double Mxys = sxys - (sxs * sys / sumAreaFractions) + sumAreaFractions * vH * vW / 12;
``````

I remember being sceptical when the necessity for this correction was pointed out, because pixels are not little squares, and ran some tests on rectangles. I highly recommend generating some test images with easily predictable Imin and Imax, (e.g. discs, annuli, rectangles, rotated rectangles, rotated rectangles with a hole in the middle, etc.) to see how your results compare to easily computed examples.

1 Like

I see ! Indeed running test images always help

Thanks a lot

1 Like