Skip to content

BF: Replace problematic rotmat->quaternion routine with call-out to more robust, pre-existing niftio routine

Paul McCarthy requested to merge bf/rotmat-to-quatern into master

The existing miscmaths::rotmat2quat routine will fail for certain inputs, such as:

 0  0 -1  0
 0 -1  0  0
-1  0  0  0
 0  0  0  1

This affine will cause all of the if / else conditionals in the existing routine to evaluate to false, with the effect that the output vector will be unchanged and, in most cases, will be left as containing all zeros. This can cause errors in users of this routine, such as avscale which is in turn used by fslreorient2std. Such a failure can be reproduced by saving the above affine to a text file aff.mat, and running avscale aff.mat.

The proposed fix is to replace the routine with a call-out to the pre-existing and more robust implementation from the original niftio library, which is available in the NewNifti::legacy::nifti_mat44_to_quatern function.

Edited by Paul McCarthy

Merge request reports