# Tcktransform

**URL:** <https://community.mrtrix.org/t/tcktransform/4098>\
**Category:** Uncategorized\
**Tags:** tractography\
**Created:** [September 18, 2020, 1:48pm UTC](https://community.mrtrix.org/t/tcktransform/4098 "2020-09-18T13:48:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![WuXiao](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@WuXiao](https://community.mrtrix.org/u/WuXiao)\
**Post date:** [September 18, 2020, 1:48pm UTC](https://community.mrtrix.org/t/tcktransform/4098/1 "2020-09-18T13:48:34Z")

</div>

Dear all,  
We have some doubts about normalization of tck file.  
we have got the tck file in the native space in line with B0 image. we also have the nonlinear registration file i.e. warp image, from the registration between B0 and MNI template with fsl. Next, we want to check the tracts in the MNI space, but meet the problem of using tcktransform. Could someone share the experience of tract registration, or what transform file should be used in the command “tcktransform in transform out”?  
Many thanks!

---

<div class="post-metadata">

**Author:** ![maxpietsch](https://community.mrtrix.org/user_avatar/community.mrtrix.org/maxpietsch/32/25_2.png) [@maxpietsch](https://community.mrtrix.org/u/maxpietsch)\
**Post date:** [September 21, 2020, 8:20am UTC](https://community.mrtrix.org/t/tcktransform/4098/2 "2020-09-21T08:20:18Z")

</div>

`tcktransform` currently requires warps in the MRtrix3 format. See [Registration: using transformations generated from other packages](https://community.mrtrix.org/t/registration-using-transformations-generated-from-other-packages/2259) for how to generate and apply these and optionally [here](https://gist.github.com/maxpietsch/0085181a263e276139a93c3a0a1a00b5) for a full worked example of `tcktransform`.

---

<div class="post-metadata">

**Author:** ![WuXiao](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@WuXiao](https://community.mrtrix.org/u/WuXiao)\
**Post date:** [October 9, 2020, 2:06pm UTC](https://community.mrtrix.org/t/tcktransform/4098/4 "2020-10-09T14:06:33Z")

</div>

Hi @maxpietsch  
Thanks for your reply.  
I tried some code according to your reply. But they didn’t work.  
I have b0 image (`nodif.nii.gz`), template image (`MNI152_T1_1mm_brain.nii.gz`), the tractography result `(MNI152_T1_1mm_brain.nii.gz`) and warp image got from FSL(`MNI_2nodif_warp.nii.gz`, `nodif_2MNI_warp.nii.gz)`  
I want to transform the tck file to MNI space.  
I tried three methods.  
First, I used `transformconvert` and `warpconvert` to convert `nodif_2MNI_warp.nii.gz` to a warp format usable in MRtrix3, then used it to transform tck file to MNI space.  
But, `transformconvert` allows to convert linear transformation matrices and `warpconvert` requires the warpfull file is 5D format. I don’t know to how to convert the warp I have got from FSL. Is there any other command available?

Second， I used the `mrregister` to get the warp then transform tck file to MNI space:

```auto
mrregister nodif.nii.gz MNI152_T1_1mm_brain.nii.gz -nl_warp_full warp_full.mif
warpconvert warp_full.mif warpfull2deformation w_t2s.mif -from 2 -template nodif.nii.gz 
tcktransform SD_Stream_SIFT.tck w_t2s.mif subject_at_template.tck

```

But the result not correct.  
The transformed tracts on the template:

 ![image](https://community.mrtrix.org/uploads/default/original/2X/c/c20940e7fc54d35d361be021aff9c6527b25235a.png)

Third, I want to try [these code](https://community.mrtrix.org/t/registration-using-transformations-generated-from-other-packages/2259). But I only tried the command `warpinit`. Because I didn’t install ANTs and have never used it.  
`warpinit MNI152_T1_1mm_brain.nii.gz.nii.gz inv_identity_warp.nii.gz`  
inv\_identity\_warp.nii.gz seems to be right.

 ![image](https://community.mrtrix.org/uploads/default/original/2X/c/c9e69c715fc7cd9f01c72b5c8f433d35cb3ae4d1.png)

If I don’t use ANTs, how can I do that?

Stay healthy and stay happy!  
Best regards,

Wu Xiao

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [October 21, 2020, 8:32am UTC](https://community.mrtrix.org/t/tcktransform/4098/5 "2020-10-21T08:32:03Z")

</div>

Hi Wu,

> `warpconvert` requires the `warpfull` file is 5D format. I don’t know to how to convert the warp I have got from FSL. Is there any other command available?

Only the `warpconvert` conversion operations that start with “`warpfull`” necessitate 5D full warp file format. Given that format contains information over and above that of a 4D warp field, there is no way to convert from the latter to the former. `warpconvert` can however convert between “displacement” and “deformation” fields, which are both 4D; the difference between these two is explained in the `warpconvert` help page.

> Second， I used the `mrregister` to get the warp then transform tck file to MNI space:  
> `$ mrregister nodif.nii.gz MNI152_T1_1mm_brain.nii.gz -nl_warp_full warp_full.mif`

This will not produce a good result, as `mrregister` currently only supports the squared-difference metric, and therefore cannot be used to register images of different modalities that contain different contrasts.

> Third, I want to try these code. But I only tried the command warpinit. Because I didn’t install ANTs and have never used it. … If I don’t use ANTs, how can I do that?

While it may not be possible to follow the instructions from that wiki page command by command if using a registration software other than ANTs, the same logic may still apply depending on the content of the warp file that you are using, which in turn depends on the software and how it was used.

* * *

The key for you is image `MNI_2nodif_warp.nii.gz`. As described in the wiki post, warping streamlines requires the inverse transformation: streamline vertices are “pushed” to their new locations, as opposed to image transformation, where data for each target image voxel are “pulled” from the image being transformed. But the fact that you are provided with _both_ “`MNI_2nodif_warp.nii.gz`” and “`nodif_2MNI_warp.nii.gz`” means that this inversion has already taken place (whether implicitly during registration, or explicitly calculated afterwards for you).

The question then is, in what format does this image provide its non-linear transformation? Simply running commands that produce the incorrect result may not be terribly useful here. It would be more direct to instead inspect the raw values that are contained within the image, to determine whether it is a displacement or deformation field, and therefore whether or not it requires conversion in order for `tcktransform` to interpret the data correctly. I don’t know whether it’s possible for displacement fields to be defined w.r.t. image axis spacing and/or orientations… but at least using the right input image, and the right interpretation of displacement vs. deformation, should get you close to the correct result.

Cheers  
Rob

---

<div class="post-metadata">

**Author:** ![maxpietsch](https://community.mrtrix.org/user_avatar/community.mrtrix.org/maxpietsch/32/25_2.png) [@maxpietsch](https://community.mrtrix.org/u/maxpietsch)\
**Post date:** [October 21, 2020, 8:40am UTC](https://community.mrtrix.org/t/tcktransform/4098/6 "2020-10-21T08:40:28Z")

</div>

> [@WuXiao](#):
>
> FSL(MNI\_2nodif\_warp.nii.gz, nodif\_2MNI\_warp.nii.gz)

To summarise, these files are in FSL format, instead of converting them yourself, apply the correct warp to the files produced by `warpinit` as described in [Registration: using transformations generated from other packages](https://community.mrtrix.org/t/registration-using-transformations-generated-from-other-packages/2259) but using [applywarp](https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FNIRT/UserGuide#Now_what.3F_--_applywarp.21) instead of `antsApplyTransforms`. See for instance [here](https://community.mrtrix.org/t/bug-in-warpinit/1496).

---

<div class="post-metadata">

**Author:** ![LiuYuchen](https://community.mrtrix.org/user_avatar/community.mrtrix.org/liuyuchen/32/2896_2.png) [@LiuYuchen](https://community.mrtrix.org/u/LiuYuchen)\
**Post date:** [November 11, 2020, 2:34pm UTC](https://community.mrtrix.org/t/tcktransform/4098/7 "2020-11-11T14:34:09Z")

</div>

Hi，  
I was dealing with the similar problem: to transform the \*.tck in native DWI space to MNI space using the FSL generated warps image between DWI and MNI, the results seems good:

 ![image](https://community.mrtrix.org/uploads/default/original/2X/4/44baad4ec61c2956eb2a8dba427cf7bb6e9081bc.png)  
background is the MNI\_3mm\_brain.nii, and the red color is the transformed tck.nii.

here are the commands I used:

```auto
#generate the MNI2DWI transformation warp by mrtrix (combined with the fsl warps: warps_MNI2dwi.nii.gz)
warpinit MNI152_T1_3mm_brain.nii.gz inv_identity_warp_no.nii
applywarp --ref=b0_brain.nii.gz --in=inv_identity_warp_no.nii --warp=warps_MNI2dwi.nii.gz --out=mrtrix_warp_MNI2dwi.nii.gz
#check the warping results by applying it to MNI_3mm_brain
mrtransform MNI152_T1_3mm_brain.nii.gz -warp mrtrix_warp_MNI2dwi.nii.gz MNI2dwi.nii.gz
#tcktransform
tcktransform ACT_WM.tck mrtrix_warp_MNI2dwi.nii.gz tck2MNI.tck -force
tckmap tck2MNI.tck tck2MNI.nii -template MNI152_T1_3mm_brain.nii.gz -force

```

---

<div class="post-metadata">

**Author:** ![maxpietsch](https://community.mrtrix.org/user_avatar/community.mrtrix.org/maxpietsch/32/25_2.png) [@maxpietsch](https://community.mrtrix.org/u/maxpietsch)\
**Post date:** [November 12, 2020, 11:46am UTC](https://community.mrtrix.org/t/tcktransform/4098/8 "2020-11-12T11:46:51Z")

</div>

Thanks, @LiuYuchen! If you want, I think it’d be great if you could add your minimal working example (and optionally also the command that generate the warp) as a section `## Warping tracks files to MNI space using FLS warps` or similar to the end of the wiki post [Registration: using transformations generated from other packages](https://community.mrtrix.org/t/registration-using-transformations-generated-from-other-packages/2259).

---

<div class="post-metadata">

**Author:** ![LiuYuchen](https://community.mrtrix.org/user_avatar/community.mrtrix.org/liuyuchen/32/2896_2.png) [@LiuYuchen](https://community.mrtrix.org/u/LiuYuchen)\
**Post date:** [November 12, 2020, 1:05pm UTC](https://community.mrtrix.org/t/tcktransform/4098/9 "2020-11-12T13:05:29Z")

</div>

> [@maxpietsch](#):
>
> `## Warping tracks files to MNI space using FLS warps` or similar to the end of the wiki post [Registration: using transformations generated from other packages](https://community.mrtrix.org/t/registration-using-transformations-generated-from-other-packages/2259).

Glad to share my little experience 😀  
Do I need to create a new topic?

---

<div class="post-metadata">

**Author:** ![maxpietsch](https://community.mrtrix.org/user_avatar/community.mrtrix.org/maxpietsch/32/25_2.png) [@maxpietsch](https://community.mrtrix.org/u/maxpietsch)\
**Post date:** [November 12, 2020, 2:52pm UTC](https://community.mrtrix.org/t/tcktransform/4098/10 "2020-11-12T14:52:24Z")

</div>

Great! In the [wiki category](https://community.mrtrix.org/c/wiki/12), all posts are encouraged to be edited by anyone who can contribute something to that topic. Donald described it [here](https://community.mrtrix.org/t/about-the-wiki-category/1828).

So, to edit that post, just click the green icon

 ![Screenshot 2020-11-12 at 15.42.30](https://community.mrtrix.org/uploads/default/original/2X/c/cadc6cfaeee9d41cfe378434f5a8d19bb5cfb0ff.png) and add your description and code. I think it fits best as a separate section at the end to show a fully contained example using FSL warps. Thanks!

---

<div class="post-metadata">

**Author:** ![LiuYuchen](https://community.mrtrix.org/user_avatar/community.mrtrix.org/liuyuchen/32/2896_2.png) [@LiuYuchen](https://community.mrtrix.org/u/LiuYuchen)\
**Post date:** [November 12, 2020, 3:05pm UTC](https://community.mrtrix.org/t/tcktransform/4098/11 "2020-11-12T15:05:51Z")

</div>

Got it 😉

---

<div class="post-metadata">

**Author:** ![maxpietsch](https://community.mrtrix.org/user_avatar/community.mrtrix.org/maxpietsch/32/25_2.png) [@maxpietsch](https://community.mrtrix.org/u/maxpietsch)\
**Post date:** [November 25, 2020, 6:23pm UTC](https://community.mrtrix.org/t/tcktransform/4098/12 "2020-11-25T18:23:39Z")

</div>

@LiuYuchen and anyone reading this: You might want to use `warpcorrect` on the output of `applywarp` as the output of `applywarp` can contain `0,0,0` at locations outside the FOV of the source image. Since the image is subsequently interpreted as a deformation field, you _can_ end up pulling image intensity values from that location or get spurious streamline vertices at locations that the original image did not cover.
