linear transform track file

Hi, is there any tool can linearly transform a tck file with a tranformation matrix, as the " tcktransform" needs an image warp

1 Like

A workaround is to create a linear warp from a linear transform.

Assuming you have a target space image target.mif and an affine transformation A.txt, you can create a warp wi_Ai.mif that does the same as applying A.txt:

$ cat A.txt
1 0 0 50
0 1 0 0
0 0 1 0

# create an identity warp
$ warpinit image.mif wi.mif

# either transform the identity warp to obtain the affine warp `wi_Ai.mif`
$ mrtransform wi.mif -linear A.txt wi_Ai.mif -template target.mif -interp linear -nan
# or compose warp and linear transform:
# $ transformcompose wi.mif A.txt wi_Ai.mif -template target.mif

# check that warp and transformation are equivalent:
# apply the warp
$ mrtransform image.mif -warp wi_Ai.mif image_warped.mif
#  directly use the linear transformation:
$ mrtransform image.mif -linear A.txt image_transformed.mif -template target.mif
$ mrview image_warped.mif image_transformed.mif

Note that the direction and reference space for warps applied to images and to track files are different. See here for more information.

Cheers,
Max

1 Like

For clarity, this is a bit of a feature hole at the moment that we will hopefully rectify. I had this functionality implemented a long time ago, but in an exceptionally large feature development branch that is well and truly incomplete, and hence it never made it to the public release.

Dear Max,

thank you for this. But I am confused as to what the image.mif in the warpinit command should be:

Let’s say I have done streamlines tracking in native diffusion space for a single patient and I want to align the streamlines with a T1 image of the same patient (move the streamlines to the T1 space).

In this case should the image.mif be the native diffusion image (say a b0 image) or the T1 image?

Thank you in advance.

Best regards

Samuel

In the example above image.mif is the source image that is warped to target space either by the linear transformation A or the equivalent warp wi_Ai.mif. Warping streamlines from source space to target space requires the inverse transformation:

warpinit T1.mif w_i.mif
transformcompose w_i.mif rigid_t1_to_dwi.txt warp_streamlines_dwi_to_T1.mif -template dwi.mif

A complete example of warping streamlines to target space either using nonlinear or linear transformations can be found here.

1 Like