MRtrix tutorial available on OSF

Hi @tkimura @Darius @martahedl,

As @rsmith mentioned, we should use the T1 for registration and not any of the 5tt outputs. I’m going through @martahedl’s excellent tutorial myself, and altered that portion of the pipeline as follows to get a good registration (using a T1_BET and a mean_bzero_BET).

#Create T1_raw.mif
mrconvert ../T1/ T1_raw.mif

#Run 5ttgen with -nocleanup option (so you have the T1_BET.nii.gz for registration)
5ttgen fsl T1_raw.mif 5tt_nocoreg.mif -nocleanup

#Create mean bzero image and BET it
#Visually check BET accuracy and tweak BET command if needed.
dwiextract dwi_den_unr_preproc_unbiased.mif - -bzero | mrmath - mean mean_b0_preprocessed.mif -axis 3
mrconvert mean_b0_preprocessed.mif mean_b0_preprocessed.nii.gz
bet mean_b0_preprocessed.nii.gz mean_b0_preprocessed_BET.nii.gz -c 47 49 30 -f 0.4

#Register mean_b0_preprocessed_BET with T1_BET (found inside 5ttgen temp folder)
#Visually check accuracy and tweak flirt command if needed.
flirt -in mean_b0_preprocessed_BET.nii.gz -ref 5ttgen-tmp-*/T1_BET.nii.gz -interp nearestneighbour -dof 6 -omat diff2struct_fsl.mat -out mean_b0_preprocessed_BET_regFSL.nii.gz -finesearch 5

#Convert FSL transform to MRTRIX transform
transformconvert diff2struct_fsl.mat mean_b0_preprocessed_BET.nii.gz 5ttgen-tmp-*/T1_BET.nii.gz flirt_import diff2struct_mrtrix.txt

#Apply (inverse) transform to the 5ttgen data
mrtransform 5tt_nocoreg.mif -linear diff2struct_mrtrix.txt -inverse 5tt_coreg.mif

For some reason I had to include the flip argument to get the same orientation as the other images.

I would have thought that transformconvert flirt_import would not need any additional manual manipulation like this. But there’s a whole history of dealing with axis definitions for FSL / NIfTI compatibility. Did you happen to perform an explicit -strides +1,+2,+3 or -strides -1,+2,+3 when producing the NIfTIs for FSL? If you find that including these fixes the issue, but omitting them leaves the remaining erroneous axis flip, we might be missing a step in the flirt_import processing.

Just a small tweak to what I wrote above: I get better bzero to T1w registration (as one would expect) using the boundary-based registration available in FLIRT. FSL offers the epi_reg script for this, and it performs well even without having to BET the bzero image.

epi_reg --epi=mean_b0_preprocessed.nii.gz --t1=T1.nii.gz --t1brain=T1_BET.nii.gz --wmseg=T1_BET_pve_2.nii.gz --out=diff2struct_fsl

Hi everyone,

I’m facing some problems similar to those of @tkimura and @Daniel123 in the previous messages. I followed all the commands of step 4.1.1 in the tutorial (see below), but when I mrview the results 5tt_coreg.mif turned out to be flipped to a saggital axis.

dwiextract dwi_den_unr_preproc_unbiased.mif - -bzero | mrmath – mean mean_b0_preprocessed.mif –axis 3
mrconvert mean_b0_preprocessed.mif mean_b0_preprocessed.nii.gz
mrconvert 5tt_nocoreg.mif 5tt_nocoreg.nii.gz
flirt –in mean_b0_preprocessed.nii.gz –ref 5tt_nocoreg.nii.gz –interp nearestneighbour –dof 6 –omat diff2struct_fsl.mat
transformconvert diff2struct_fsl.mat mean_b0_preprocessed.nii.gz 5tt_nocoreg.nii.gz flirt_import diff2struct_mrtrix.txt
mrtransform 5tt_nocoreg.mif –linear diff2struct_mrtrix.txt –inverse 5tt_coreg.mif

mrview dwi_den_unr_preproc_unbiased.mif –overlay.load 5tt_nocoreg.mif –overlay.colourmap 2 -overlay.load 5tt_coreg.mif –overlay.colourmap 1  

I do not really understand previous mentioned directions (sorry, I’m far from experienced). Hope there is anyone who could help me to solve this problem.


Hi Rianne,

The “5tt_nocoreg.nii.gz” image is not really appropriate to be using for registration. @martahedl: Is it possible to update the tutorial?

The simplest modification to make is:

  • Convert your unregistered T1-weighted image to NIfTI;

  • Use that image as the reference image for the flirt command;

  • When calling transformconvert, make sure you replace 5tt_nocoreg.nii.gz with the T1-weighted image you used as the reference image in your flirt call;

  • Leave the mrtransform call as it is: Even though you used the T1-weighted image as the reference image for registration, you still need to transform the 5TT image so that it spatially overlaps with the DWI data.


It took me a while, but I finally managed to update the tutorial with respect to this issue. Also, I made a few more changes to make it compatible with the new release (e.g. changing dwipreproc to dwifslpreproc).

1 Like