Unable to track IFOF with 5TT


I am trying to trace the IFOF on multishell data. It worked really well when I tracked it without the 5TT images as follows:

tckgen fod_wm.mif IOFF/left/${subj}_IOFF_L.tck -fslgrad bvec bval -seed_image IOFF/left/frontal_L.mif -include IOFF/left/temporal_L.mif -include IOFF/left/occipital_L.mif -mask ${subj}_mask.mif -step 1 -number 500000 -maxnum 500000 -maxlength 200 -minlength 25 -stop

but it doesn’t work at all if I include the 5TT images:

tckgen fod_wm.mif IOFF/left/${subj}_IOFF_3_L.tck -act 5TT.mif -backtrack -crop_at_gmwmi -fslgrad bvec bval -seed_gmwmi ${subj}_5TT_mask.mif -include IOFF/left/frontal_L.mif -include IOFF/left/temporal_L.mif -include IOFF/left/occipital_L.mif -step 0.2 -number 500000 -maxnum 500000 -maxlength 200 -minlength 4

I tried several different things, including changing the minlength, step size and seeding from a ROI instead of the 5TT mask. It worked well when I tracked other pathways so I’m not sure why it doesn’t work for this track.

Thank you!

Hey Lena,

Have you tried overlaying the 5TT image in diffusion space, or vice versa? It may be that the co-registration between the two is poor.

In addition, I’ve noticed you have used the 5TT file for the -seed_gmwmi option. I presume this is the 5 tissue-type file (i.e. GM/WM etc) with 5 volumes, created by 5ttgen. For the seed_gmwmi argument, I believe you have to select the image that pertains to voxels on the GM/WM interface. This can be created by:

5tt2gmwmi 5TTmask.mif gmwmi.mif

Then select gmwmi.mif for the seed_gmwmi option.

Hope this helps,



On top of Alistair’s comments, there’s a couple of other things to look out for:

  • When targeted tracking doesn’t yield any tracks, it’s very limited in terms of what feedback you get from the process. One thing to try is removing one of the ROIs: that may give some clues as to why those streamlines that traverse two of the three regions fail to go on and traverse the third. Using the -info option in tckgen will also give you some statistics on why streamlines were terminated / rejected.

  • (just in case) If you’re using ROIs that are defined entirely within the GM ribbon, streamlines generated using ACT will, depending on how the ribbon is defined, either frequently or always miss the ROIs. This is because with ACT streamlines are terminated as soon as they encounter the GM-WM interface, and don’t track ‘into’ cortical grey matter; hence they may never ‘intersect’ with the ROIs. Dilating the mask ROIs a little may help here (I have a better implementation solution on the way…).

  • 0.2mm is an extremely small step size for the default tracking algorithm in tckgen (iFOD2). The settings for first-order methods, such as SD_PROB in the old MRtrix 0.2 version, tend to include a much smaller step size, but these settings don’t really translate directly to the iFOD2 method. I would suggest trying with the default step size instead.

  • The iFOD2 algorithm is based entirely on the FOD image, which does not require the use of a diffusion gradient table. So your option -fslgrad bvec bval won’t be having any effect on the command, and can be omitted.

Let us know how you go!

Hi Alistair and Rob,

Thanks for the fast reply!

I created the image for the –seed_gmwmi as follows: 5tt2gmwmi 5TT.mif ${subj}_5TT_mask.mif so I think that should be the right one. I probably should have labelled it differently.

I tried running it again with the default step size, but still no tracks. I’ll try to exclude a ROI and look at the stats.

I think however the problem is that the 5TT image and diffusion space aren’t co-registered very well. At the moment I processed the T1 images in freesurfer using recon-all and then tried to register them to the eddy-current corrected dwi images as follows before running 5TT: flirt -in T1.nii.gz -ref eddy_corrected_data.nii.gz -dof 6 -out a_flirt.nii

I know there is quite a bit of info on the forum, but I’m still not quite sure what the best transformation would be. Could you maybe let me know what you’d suggest in this case and if it’s okay co-register the images after recon-all or should I do it before?

Cheers, Lena

Hey Lena,

No problem at all.

Yes, the co-registration can be quite tricky and there are various options out there. I spent a fair bit of time on fine-tuning this.

Just a quick question, I presume your diffusion data has been eddy-corrected to correct for spatial inhomogeneties? And your 5TT files have been constructed in Freesurfer space? You have to be very careful with the image transforms etc.

I’m currently using freesurfer’s bbregister, which I’ve found to be pretty accurate in it’s co-alignment.

It follows as:

bbregister --s $subj --mov meanb0bet.nii.gz --init-fsl --reg register.dat --dti --fslmat diff2FS.mat

transformconvert diff2FS.mat meanb0bet.nii.gz $SUBJECTS_DIR/$subj/mri/brain.mgz flirt_import diff2FSMR.mat -force

mrtransform 5TT.nii r5TT.nii -linear diff2FSMR.mat -inverse -force


$subj = subject name that has been processed with recon-all
meanb0bet.nii.gz = mean diffusion b0
5TT.nii = 5 tissue-type file that is in freesurfer space with its original data strides ([ -1 3 -2 ])

I do my co-registrations after recon-all as I’m wary about the signal intensities during the segmentation.

Hope this helps.

Btw - I know that you are at UQ with Marta. I’m at QIMR so I would be happy to help out with the pipeline I have set up here.



Hi Alistair,

Thanks so much for your help with this!

I actually created the 5TT with the fsl algorithm before. When I try to run it with the freesurfer algorithm I keep getting the following error message:

5ttgen: [ERROR] Command failed: mrconvert /Users/uqloestr/Desktop/P1002/aseg.mgz /tmp/5ttgen-tmp-AGLB2J/input.mif
5ttgen: Output of failed command:
5ttgen: Changing back to original directory (/Users/uqloestr/Desktop/P1002)
5ttgen: Script failed while executing the command: mrconvert /Users/uqloestr/Desktop/P1002/aseg.mgz /tmp/5ttgen-tmp-AGLB2J/input.mif
5ttgen: For debugging, inspect contents of temporary directory: /tmp/5ttgen-tmp-AGLB2J/

I tried using the aseg.mgz, aparc+aseg.mgz and aparc.a2009s+aseg.mgz images both with the .mgz and the .nii.gz extensions but I keep getting the same error message. Do you know why this is?

Sorry, I just keep running into more issues with this…

Thanks again for your help!

Cheers, Lena

Hi Lena,

Without looking at the data, it’s a bit hard to make a judgement. Perhaps @rsmith knows more about these invoked errors?

I would suggest 4 options to troubleshoot:

  1. Recall the command with the -verbose option set, copy and paste the outputted text?
  2. Inspect the temp directory /tmp/5ttgen-tmp-AGLB2J/
  3. Recall the command and manually specify the temp dir as -tempdir .
  4. Visualize the quality of the freesurfer ouput segmentations



Hi Lena,

Firstly I should clarify that Alistair was asking about here:

… And your 5TT files have been constructed in Freesurfer space? …

, is the image grid & transformation in which the T1 image used to generate the 5TT image is defined. Where this image comes from, and whether or not any spatial transformations have been applied to it, will influence whether or not these image data are aligned spatially with the diffusion images. Note that this doesn’t necessitate that the 5TT and diffusion images be sampled on the same voxel grid; only that they align in scanner space (best checked using the Overlay tool in mrview).

This is different to the 5ttgen algorithm used, which influences how a T1 contrast image is ‘converted’ into a 5TT image. While I have provided an algorithm to do this based on a FreeSurfer parcellation, the ‘5ttgen fsl’ algorithm is generally recommended.

Nevertheless, if you do want to get 5ttgen freesurfer working, the script has unfortunately in this case provided no information whatsoever regarding why it has failed (there’s nothing after the “5ttgen: Output of failed command:” line). Historically, when this has occurred, it’s been due to running out of storage space in the location where the scripts create their temporary directories (/tmp/ in your case). So my first suggestion is to clear out any expired temporary files in this location and try again.


Hi Rob and Alistair,

Thanks for getting back to me. I think I know how to do the transformation after the 5TT now with the code you sent, Alistair. However, while trying to figure it out I read more about the 5TTgen scripts and was wondering if I actually did the right thing to start with. I initially ran it with 5ttgen fsl which worked fine, however I used the T1 image that was generated with freesurfer during recon-all. Do I actually have to run recon-all at all if I use the 5ttgen fsl script or is it enough to provide the raw T1 image (generated from the DICOMs)?

Cheers, Lena

You can use either.

If you are to use the freesurfer-derived output in 5ttgen fsl, my recommendation is to use the brain.mgz file and set the -premasked option on.

If you are to use the native space image (i.e. from the DICOMs) - it is not within the same image grid as the freesurfer option. Hence, when you are using the bbregister option - it will take a few more transformations to overlay everything within the same space.

My recommendation will initially is to use the freesurfer-derived brain into 5ttgen fsl with the premasked option turned on. This way you will get the hang of all the working parts.



I think that better than brain.mgz is to use norm.mgz, given the fact, that ’ the brain.mgz is very aggressively filtered explicitly for cortex and wipes away some subcortical boundaries (e.g. lateral thalamus) ’ - citation of this post in FreeSurfer forum:

Therefore your accuracy of determination of subcortical gray matter is limited with brain.mgz.

Maybe, even better option would be to use brain.mgz for estimation of cortical GM, but use norm.mgz for estimation of subcortical GM.

Or, as I pointed out here:

maybe the best option for 5tt generation would be to use output of FreeSurfer’s mri_compute_volume_fractions.


Hi Alistair and Antonin,

I ran the 5TTgen with both, the brain.mgz and the norm.mgz. The results with bain.mgz look slightly better. The transformation worked well, too so thanks a lot for that! I still can’t seem to trace the IFOF, but I will try a few different ROIs and settings.

Thanks for your help with this!

Cheers, Lena

Great to hear.

Ok, that’s weird.

I would suggest two things:

  1. Visualise the GM/WM interface image - with the ROI’s overlayed. If they do not spatially overlap, then obviously no tracks will generate.

  2. Turn the -seed_gmwmi option off when tracking. Try instead the -seed_image argument.