Reconstruct motion parameters from 3dvolreg -1Dmatrix_save

Hi all. If I only had the output of 3dvolreg -1Dmatrix_save transforms bold.nii.gz, how would I reproduce the parameters that are saved when you pass -1Dfile?

I’m sure there’s an AFNI tool that would do this, but for the life of me I can’t figure out what to search to find the answer.

Hi, Chris-

Just to check quickly—Do you still have the dataset bold.nii.gz? The easiest way to do what you are asking would be to save the 1D file of rigid body motion parameters directly, which is typically what is done when an script uses 3dvolreg, such as:

    3dvolreg -verbose -zpad 1 -base vr_base_min_outlier+orig       \
             -1Dfile dfile.r$run.1D -prefix rm.epi.volreg.r$run    \
             -cubic                                                \
             -1Dmatrix_save mat.r$run.vr.aff12.1D                  \

Above, you get 2 outputs of similar info, for different purposes from the pb* file (which is the bold.nii.gz here).

Decomposing an affine transform (3x3 matrix of scale+shear+rotation plus a 3x1 vector of translations) into the individual parameters is tricky, in general. I would have to do a little more digging later about this. Sidenote: going from parameters-> matrix is done with 1dApar2mat. I guess at least if you have 3dvolreg output specifically, the affine transform should just be rigid body?


Hi Paul. I do have the BOLD file, but the idea is to find one canonical output that the others can be derived from. The affine matrices seem ideal, as they have higher decimal precision than the rigid parameters and can be more directly used with any transform application tool.

The primary use case would be 3dvolreg outputs, but in principle I can get rigid body affines from anywhere and rewrite them to volreg conventions. I am happy to assume rigidity / verify negligible scale and shear.

Hi, Chris-

I see, OK.

It is easier to go 1D (=parameters) → mat file (affine matrix+vector) than the other way around. That would give some primacy. If precision is the downside, I would think it is possible to output higher precision numbers, say with a “-high_prec” option, perhaps.

It is true that affine matrices might be more widely used, but they are less flexible once in that form, because the general decompositions (back to rotations, translations, shear, etc.) aren’t that easy to do. Doing the decomposition approximations, even for just rigid body matrices, might inherently reduce the precision, anyways (I’d have to look more deeply at that, but that is my initial guess).

We typically use the 1D file parameters for motion estimates, regressors and plotting motion. And we use the matrix transform forms to concatenate with the more general affines, as well as other nonlinear transforms if present.


1 Like