Applying warp to tck file with tcktransform

Hi Mrtrix community,
I seem to be running into some trouble transforming tractography that was done in native space into MNI common space.
i am using a warp file made with fsl FNIRT. based on previous threads here, I used:

warpconvert warp_mni2diff.nii.gz displacement2deformation warp_def.nii.gz
tcktransform tracts warp_def.nii.gz tracts2template.tck

the result is not only not registered to the template image, but also seems to be pretty much the same as the original tracts, but with less tracts. Weirdly, the original tracts seem to fit the template better than the transformed ones.

the original tracts on the template:

the transformed tracts on the template:

obviously, I’m doing something wrong. I know the warp is fine because I used it to transform the template atlas to native space and it worked perfectly, so any input as to what is wrong in my process would be helpful.
thanks a lot in advance!

You have to use the inverse warp for transforming streamlines (explanation).

I’m trying to convert native to common space, and using the common to native transform. As far as I understand that’s the right one.


Yes, I think I got the wrong end of the stick…

This tripped me up. Did you use mrtransform for this? If not, the first check would be to transform the template image to subject space with mrtransform and the warp warp_def.nii.gz. I suspect this does not work.

Assuming your warp_mni2diff.nii.gz is the output of fnirt and you did not use mrtransform, I think you’ll need to convert that warp to MRtrix format as described in the docs. I’d not use warpconvert but use warpinit, use the fsl tool to warp these images (applywarp I think) and then use warpcorrect to sanitise the warp.

I have no experience with fnirt but you might not need to do the conversion and be fine with the warpconvert command depending on the image strides of the images used in fnirt (I’d try -1,2,3 first).

If my assumptions are off again, please provide the full commands you used.


Hi Max, Ronnie, and MRtrix experts,

I have a set of streamlines in individual subject spaces which I would like to register into a group template space. I created a group template of my 30 subjects’ FA maps using the population_template command. This command created a template file (which looks good), and folders for linear_transformations, transformed images and warps.

I’m not too sure on the commands to be used for the step of actually registering individual subjects’ .tck files into the group template space. I tried tcktransform as above, but for some reason I don’t seem to have it installed! I checked which version of MRtrix I have by running mrconvert -version, which shows:
== mrconvert 3.0_RC2-117-gf098f097 ==

Any tips or advice would be much appreciated!


OK, the issue here is that this command was renamed for 3.0_RC3 – it used to be called tcknormalise in prior versions. I’m pretty sure usage is otherwise identical though…

Thanks Donald. I used tcknormalise to apply the warp .mif to the native .tck, resulting in a warped .tck that looks like this:

Which is obviously a little off. Do I need to also apply the linear transformation .txt generated by the population_template command? If so - how do I go about this as I understand mrtransform can only apply linear transformations to images, not track files.

Secondly - it looks like there are a few erroneous streamlines introduced during this step (straight lines with no anatomical basis):

Is there anything I can do about these?

Many thanks in advance,

I think we’re going to need input from @maxpietsch on this one… :pleading_face:

Yes, a little. Note that you need to apply the reverse warp (template to subject). Probably best to provide us with the commands used to generate the warps and to transform the streamlines.

No, the warp incorporates these unless you converted the warp to NIfTI file format.

Yes, however, mrtransform can also apply warps. tcktransform can currently only apply warps (nonlinear or not).

They are most likely introduced by out of bounds values. Again, best if you give us the commands that you used.

Thanks Max.

I’m using data from 30 healthy control subjects (named C01-C30).

  1. To generate the population template:

Move all subjects’ t1Brain.nii.gz to ~/Desktop/data/ctrl/frontalparc/ctrl_template_t1Brain, pre-pending subject ID.

population_template ~/Desktop/data/ctrl/frontalparc/ctrl_template_t1Brain t1Brain_template.nii.gz -transformed_dir ./transformed/ -linear_transformations_dir ./linear_transformations -warp_dir ./warps

  1. For each subject, then ran tckgen to create streamlines for cerebellar projections. These are in /dti/frontal_parc/tckgen_l_drtc_rnmask_5mseeds_bi.tck

  2. Then ran (for one example subject shown above, C01):
    tcknormalise <C01_dir>/dti/frontal_parc/tckgen_l_drtc_rnmask_5mseeds_bi.tck ~/Desktop/data/ctrl/frontalparc/ctrl_template_t1Brain/warps/C01.mif C01_l_drtc_warped.tck, resulting in the above snapshots.

Hope this makes sense. Let me know if there’s any more info you need.


I am surprised that does not throw an error or at least a warning. The warps produced by population template are actually 4 warps (“warp_full”) stored in one 5D file, you’ll need to convert this to a single deformation field from template to subject space and apply that warp to tcktransform. I think the following should work:

warpconvert ~/Desktop/data/ctrl/frontalparc/ctrl_template_t1Brain/warps/C01.mif warpfull2deformation -from 1 -template ~/Desktop/data/ctrl/frontalparc/ctrl_template_t1Brain/C01.mif - | tcknormalise "$C01_dir"/dti/frontal_parc/tckgen_l_drtc_rnmask_5mseeds_bi.tck - C01_l_drtc_warped.tck

Dear Max,

Thanks for taking the time to look into this for me. I followed those steps for subject C01. Just to check:

I had to add “-type” before warpfull2deformation on my version of the command. Also, the -template image in the warpconvert command, should that be C01’s warp.mif or C01’s actual T1.nii.gz?

The result is similar, although it appears to be aligned in the z axis, and with fewer ‘out of bounds’ SLs, although clearly some way still to go!


That means your version is older than Aug 2017, probably best to update (ac7e73576bec4).

I think there is a mistake in my command: -from 1 should have been -from 2. Please see here for a full worked example and adjust the relevant commands to your data.

Also, this assumes that subject FOD image and subject T1 are aligned (please check with mrview <your subject T1> -overlay.load <your subject FOD> -overlay.opacity 0.3)? If not you need to concatenate the transformation from DWI to T1 to T1 template (feed the output of warpconvert and the linear transformation from T1 to DWI data into transformcompose, in that order and use the DWI image as -template argument). As a sanity check, you should be able to use the resulting warp to transform the T1 template to subject DWI space (mrtransform). You can debug this step by step by warping the streamlines twice, once from subject DWI to subject T1 space (by generating a linear warp field), then to T1 template space using the output of warpconvert.

Hi Max,

Thanks for that last bit of advice - that did it. I was trying to put them into T1 template space, which just confused things. Using the commands provided above it was relatively straighforward to warp the SLs into group FA space.

^ single subject’s left DRTC warped to and overlaid on group template


1 Like