Skip to content

Derivation of motion parameters from HMC transforms #94

@effigies

Description

@effigies

FSL motion parameters are not straightforwardly related to the transform matrices that they generate. They are calculated relative to the center of mass of the reference image, rather than the reference frame, which is what the affines encode.

This is the straightforward way to extract extract motion parameters from the affines:

import nitransforms as nt
import pandas as pd
from scipy.spatial.transform import Rotation

affines = nt.linear.load(motion_xfm)
trans = affines.matrix[:, :3, 3]
rot = Rotation.from_matrix(affine.matrix[:, :3, :3]).as_euler('XYZ')

params = pd.DataFrame(data=np.concatenate((trans, rot), axis=1), columns=['trans_x', 'trans_y', 'trans_z', 'rot_x', 'rot_y', 'rot_z'])

Here are the original FSL (left) and affine-derived (right) parameters (rotations * 50 for comparability):

params

Here is the correlation matrix with the FSL parameters:

corr

The correlations are reasonably good (>0.8 for all but trans_x).

Some code for generating similar plots:

from matplotlib import pyplot as plt
import seaborn as sns

fslparams = pd.read_csv(timeseries_tsv, delimiter='\t')[['trans_x', 'trans_y', 'trans_z', 'rot_x', 'rot_y', 'rot_z']]

corr = pd.concat([fslparams, params], axis=1).corr().iloc[:6, 6:]
cmap = sns.diverging_palette(230, 20, as_cmap=True)
sns.heatmap(corr, cmap=cmap, vmax=1, annot=True)
plt.show()

ax1 = plt.subplot(2, 1, 1)
ax2 = plt.subplot(2, 1, 2)
sns.lineplot(fslparams * [1, 1, 1, 50, 50, 50], ax=ax1)
sns.lineplot(params * [1, 1, 1, 50, 50, 50], ax=ax2)
plt.show()

Related: #12

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