Skip to content

Inertia Tensor in real units may not be sorted! #1

@jlegrand62

Description

@jlegrand62

When computing inertia tensors, eigenvalues are returned sorted in decreasing order by SVD.
But if we ask for real values, order may change due to non-homogeneous voxelsize!

In spatial_image_analysis.py, change:

coord = coordinates_centering3D(xyz, center)
# compute the variance-covariance matrix (1/N*P.P^T):
cov = compute_covariance_matrix(coord)
# Find the eigen values and vectors.
eig_val, eig_vec = eigen_values_vectors(cov)
# convert to real-world units if asked:
if real:
    for i in xrange(3):
        eig_val[i] *= np.linalg.norm( np.multiply(eig_vec[i],self._voxelsize) )

into

coord = coordinates_centering3D(xyz, center)
# convert to real-world units if asked:
if real:
    coord = np.multiply(coord, self._voxelsize) )
# compute the variance-covariance matrix (1/N*P.P^T):
cov = compute_covariance_matrix(coord)
# Find the eigen values and vectors.
eig_val, eig_vec = eigen_values_vectors(cov)

to be sure to keep the eigenvector sorted by eigenvalues !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions