I was facing the same problem some time ago for identifying ellipsoids corresponding to binary regions. By developing the maths it is possible retrieve a factor of sqrt(5)
for converting the square root of eigen values to ellipsoid radiusses.
The regionprops3
function from Matlab uses a factor of 4
, therefore the factor sqrt(5/16)
fixes the difference.
The maths involve integration using spherical coordinates, and linearisation of trigonometric expression.
As I could not find any other document or resource explaining it, I propose to write it here (hoping this is adequate...).
Development
Definitions
Let a>b>c
be the three radiusses of the ellipsoid.
We can assume the ellipsoid is centered and aligned with the three main axes,
the longest radius along x, the smallest one along z.
In that case, the eigen values correspond to the three
second-order centered moments lambda_1 = mu200
, lambda_2 = mu020
, and lambda_2 = mu002
.
The idea is then to compute explicitely these values from the parameters of the ellipsoid.
For mu200, the definition is:
mu200 = \int \int \int I(x,y,z) x^2 dx dy dz
with I(x,y,z)
being 1 within the ellipsoid, and 0 otherwise.
Integration using spherical coordinates
For the integration, it is more convenient to use spherical coordinates (rho, theta, phi)
, corresponding to the radius, inclination with the vertical, and azimuth.
They corresponds to:
x = rho * a * cos(phi) * sin(theta)
y = rho * b * sin(phi) * sin(theta)
z = rho * c * sin(theta)
The change of coordinates requires the use of the Jacobian of the transform.
In that case, its determinant is
a * b * c * rho^2 * sin(theta)
The moment integral for mu200 is then
mu200 = a * b *c \int_0^{2*pi} \int_0^pi \int_0^1 (a * rho * cos(phi) * sin(theta) )^2 * rho^2 * sin(theta) drho dtheta dphi
Can be simplified into
mu200 = ( a^3 * b * c / 5 ) \int_0^{2*pi} \int_0^pi (sin(theta))^3 dtheta (cos(phi))^2 dphi
The integral over theta can be developed using the linearisation of sin^3 theta:
sin^3(theta) = (3/4) * sin(theta) - (1/4) * sin(theta)
Then the inner integral becomes:
\int_0^pi (sin(theta))^3 dtheta = 4/3
Incorporating into the full integral:
mu200 = ( a^3 * b * c / 5 ) * (4/3) \int_0^{2*pi} (cos(phi))^2 dphi
mu200 = ( a^3 * b * c / 5 ) * (4/3) * (1/2) 2*pi
mu200 = (4 * pi / 3) * (a^3 * b * c / 5)
Identification
Denoting by m000 = (4 * pi / 3) * a * b * c
the volume of the ellipsoid, one gets:
mu200 = (a^2 / 5) * V
In regionprops3
function, the covariance matrix is obtained by normalizing by the volume.
We therefore have:
lambda_1 = a^2 / 5
and the relation:
a = sqrt(5) * sqrt(lambda1)