Registration of structural and diffusion weighted data

Dear MRtrix-Experts,

I am looking into ways of registering structural to DWI data. (T1 weighted 1x1x1, bias-field corrected and DWI 2x2x2, corrected for bias-field, eddy currents and geometric distortions).

All registration is done by FLS flirt, rigid 6DOF
.
As I suppose, there are 2 options:

Option 1: Register T1 to DWI first, then perform 5ttgen and freesurfer pipeline on registered T1

  • involves resizing the T1 data to original resolution (Freesurfer doesn’t like low-res T1s)
  • Benefits: no further transformation of masks / parcellations neccessary (as there are all aligned already)
  • Drawback (maybe): fast and freesurfer are not performed on original, but interpolated data.

Option 2: Run 5ttgen and freesurfer pipeline on original data, transform masks / cortical parcellations later on using a transformation matrix generated by T1 > DWI registration

  • Benefits: fast / freesurfer runs on original data
  • Drawback: masks have to be transformed to DWI data later on. This is especially problematic for the freesurfer sementations (aparc+aseg), which consists of discrete values (i.e. 1,2,3 etc.) and get interpolated into continues values (with no meaningful reference to the LUT-file).

What do you think about these options? I was wondering if there is a way this is supposed to be done.

Also: thank you for providing MRtrix! It’s a great tool and I am glad everything works so well!

Bastian

Hi Bastian,

A few thoughts:

  • I haven’t played with flirt much myself, but it should be possible to apply the estimated rigid-body transformation to the header of the moving image only; effectively the ‘voxel grid’ of the moving image is translated & rotated, but the image intensities are unaffected. Subsequent resampling of the moving image onto the grid of the target image is not a compulsory component of affine registration, and should not be thought of as such. Indeed, it’s better to perform this registration but retain image volumes in their native resolution; many MRtrix3 capabilities are explicitly designed to properly handle multi-modal image data that are not on a common voxel grid.

    (From memory, this is achieved using flirt -omat <flirt output>, then mrtransform -linear <flirt output> -flip 0; anyone correct me if I got this wrong)

  • Personally I have always registered T1 to (pre-processed) DWI before anatomical image processing (including before importing to FreeSurfer); that way, any images subsequently derived from the T1 should be inherently aligned to the DWI without requiring further explicit registration, and without necessitating manual tracking of which images are aligned and which are not.

  • Not that it should be necessary here, but since you brought it up: Any resampling of images with discrete values (e.g. aparc+aseg) should be performed with nearest-neighbour interpolation: this will maintain the labels from the input image during resampling, which is necessary in such contexts.

Cheers
Rob

1 Like

Hi Rob,

Great, thanks for your advice. I didn’t know that options exists with mrtransform. I’ll try that (as well as the new registration command).

Bastian

Hi Bastian,

Have a look at transformcalc if you want to convert flirt’s linear transformation files into a format usable by mrtrix:

transformcalc <flirt_output> <image_in> <image_ref> flirt_import <output_matrix>

Cheers,
Max

great, thanks for the advise!

Just a comment.

Updated some old scripts that uses FLIRT for registration for this purpose. So the ref image is the highres structural image and moving image a suitable dwi image. Now with transformconvert you don’t have to bother with flipping dims for the subsequent mrtransform

So in principle it works like this:

flirt -in mov_brain.nii.gz -ref ref_brain.nii.gz -dof 6 -omat mov2ref.mat

transformconvert mov2ref.mat mov_brain.nii.gz ref_brain.nii.gz flirt_import mov2ref_mrtrix.txt

mrtransform -linear mov2ref_mrtrix.txt -inverse ref.nii.gz new_ref.nii.gz

Then the header qform is updated with the linear transformation (in this case only 6 dof) so that new_ref.nii.gz lives in moving-space.

5 Likes

Hi Finn and Rob,

Thanks for the codes.

I tried the following to register the raw T1 to the bias-corrected DTI image using flirt with 6 DOF.

flirt -in a_T1.nii -ref a_biascorrected.nii -dof 6 -out a_flirt.nii

Now that the T1 and DWI are registered, is it advisable to proceed with 5ttgen on the down sampled T1?

Cheers.

Hi all

I use flirt boundary based registration (bbr) to align diffusion and structural images.

flirt -in nodif_brain.nii.gz -ref structural_brain.nii.gz -dof 6 -omat tmp.mat

flirt -in nodif_brain.nii.gz -ref structural_brain.nii.gz -dof 6 -cost bbr -wmseg structural_WMseg.nii.gz -init tmp.nii.gz -omat diff_to_structural-bbr.mat -schedule $FSLDIR/etc/flirtsch/bbr.sch

where structural_WMseg.nii.gz is a white matter segmentation (binary image) from the structural image, e.g. from FSL FAST.

Then transform the flirt matrix to mrtrix format

transformconvert diff_to_structural-bbr.mat nodif_brain.nii.gz structural_brain.nii.gz flirt_import diff_to_structural-bbr-mrtrixformat.txt

And apply to the structural image

mrtransform structural.nii.gz -linear diff_to_structural-bbr-mrtrixformat.txt structural.coreg.nii.gz -inverse

When working with freesurfer, I usually use mri/nu.mgz as structural.nii.gz, and apply mri/brainmask.mgz to get structural_brain.nii.gz.

Cheers
Kerstin

8 Likes

Hi @ElijahMak ,

That’s “ok”, but the thing is: you don’t have to down sample the T1; you can simply apply the transformation using MRtrix commands, which will change the transformation in the header rather than down sampling the T1 to the diffusion grid. That’s what the 2 commands as posted by @Kerstin above achieve (transformconvert ... and mrtransform ...). In this way, all subsequent processing and visualisation of the T1 can still benefit of the original higher resolution of that image!

1 Like

@ElijahMak It’s also worth noting that your DWI volumes have not been corrected for EPI susceptibility distortions… This means that ACT can’t faithfully map a position in real space to corresponding anatomy in both the DWI and (tissue-segmented) T1 volumes. There’s nothing technically stopping you from still using ACT; but correction of those distortions is generally considered a prerequisite for ACT to be able to apply the correct anatomical priors in the correct places.

1 Like

Thanks @ThijsDhollander, @rsmith, and @Kerstin for your help with the commands. They are extremely helpful! I managed to get the T1 aligned for 5ttgen.

I had the T1s and DTIs previously processed in Freesurfer (recon-all and dt_recon), so the DTI data were already registered to the T1 using boundary-based registration. I then used the Freesurfer’s registration to register the aparc+aseg.mgz to the preprocessed DTI.

Here are my steps, and hopefully this might be helpful for others who have already processed the T1 dataset and want to use the aparc+aseg.mgz, especially after QC and manual edits have been painstakingly done in Freesurfer. If there are any other ways to improve or correct the workflow, please let me know :slight_smile:

  1. Use a Freesurfer command to convert the registration matrix into an ITK format

lta_convert -inlta register.lta (DTI to T1 from BBR) --outitk itk.txt

  1. Use the transformconvert in MRtrix to convert the itk format into MRtrix format

transformconvert itk.txt itk_import Freesurfer_to_ITK_MRTRIX.txt

mrtransform aparc+aseg.mgz -linear Freesurfer_to_ITK_MRTRIX.txt aparc+aseg_to_DTI.mgz (output) -inverse -interp nearest

Thanks for that too, @rsmith. Unfortunately, we did not have another acquisition of reversed phase-encoding to correct for those distortions which seem to be highly localised in the frontal regions from my dataset. From the SIFT page, it is recommended that SIFT be used with ACT if distortion correction is not available? Could you elaborate on how this work and how the processing mask is automatically derived in SIFT? I’ll take another look at the SIFT paper over the next few days too!

No DWI distortion correction available

SIFT should ideally be used in conjunction with ACT; by passing the ACT 5TT image to tcksift using the -act option, the command will automatically derive a processing mask that will limit the contribution of non-pure-white-matter voxels toward the model. Without this information, non-pure-white-matter voxels adversely affect both streamlines tractography, and the construction of the SIFT model.

Reviving an old thread so I don’t need to make a new one -

This is a basic question - do I need to skullstrip my T1 images before rigid-body registration to the DWI series? I’m not quite clear on how registration will be accurate if one of the inputs has a skull surrounding the brain & the other has already been preprocessed & skullstripped.

Thank you kindly!

If the skull stripping works reliably then I would definitely recommend it. However, much more important is to make sure that the intensity ranges of the DWI and T1 images are similar and that there is a positive linear correlation between the intensity values across modalities as mrregister uses a sum of squared differences metric.

Thank you for the response. How do I go about checking the similarity of intensity ranges? As of now I’m using FSL’s flirt to do the rigid transformation, but will experiment with mrregister.

Looking at mrregister’s page & under Rigid Registration Options, I see the option -rigid_metric; would this be a relevant option to use in terms of variation in intensity ranges?

Hi @aszymanski,

Currently, you won’t be able to succesfully register a DWI dataset with a T1 image via mrregister, since the latter uses an SSD metric. For this task, you’ll currently have to resort to another package or tool, such as FSL’s flirt (see some people earlier in this thread using it succesfully for this purpose). I have been working with @Dave and @rtabbara on a solution for this particular problem, that will also incorporate optional EPI distortion correction (in case you would not have reverse phase encoded b=0 pairs). It’s not publicly available yet, but will likely become available at some point in the future!

Cheers,
Thijs

1 Like

Hi all

Thanks for providing so much information.
I’m trying to reproduce Kerstins above mentioned protocol for image registration.
Unfortunately I get an error message after the 2nd command:

Could not open matrix file tmp.nii.gz

I can run the command without the -init part and continue, but after mrtransform, I receive a non-registered and quite distorted t1 (see image at the end). Flirt registration from within the fsl gui works fine, but there I end up with such a low quality t1 image which is not useful at all :confused:
I tried it with skull stripped images as well - also not successful.
Does anyone have suggestions for a better registration?

I appreciate any help and I am sorry for my naive question.
Best regards, Lucius

Unfortunately I get an error message after the 2nd command:

Pretty sure tmp.nii.gz should be replaced with tmp.mat: This is the transformation estimate generated by the first command, that is then being fed back to flirt as the “initial” transform estimate via the -init option.

Flirt registration from within the fsl gui works fine, but there I end up with such a low quality t1 image which is not useful at all

This is because with default usage, flirt provides an output image that is both transformed and re-gridded to the target image. The trick is to have flirt output the transformation matrix, then apply that transformation in a way that alters only the image transformation matrix in the header, and doesn’t resample the image onto a new voxel grid. I really need to add this one to the FAQ…

Does anyone have suggestions for a better registration?

It’s hard to tell from a single-slice image, but one suggestion I will make is that if your T1 image contains a lot of neck, the image intensities in that region may contribute to calculation of the cost function that drives the registration; hence when flirt does its initial “coarse” search to find an approximate overlap, it could align the brain in the FA image with the middle of the neck in the T1. This is just a matter of understanding that registration algorithms are not magic black boxes, and sometimes need a bit of help; for instance, you could crop the neck out of the image, or if the images are intrinsically nearly-aligned you could instruct flirt to not perform the coarse search (where it e.g. tests to see if one image is rotated 90 degrees with respect to the other), and focus on fine improvement of the established near-algnment.

Rob

Dear Rob

Thank you very much for your helpful answer!
Yes, I’m certain, that this information provided in the FAQ will help a lot of users.

I’m in the process of implementing mrtrix at our neurosurgical department and use it as a more detailed, second opinion tool to Brainlab’s Elements program, to support op-planning and op-navigation.
If in the future the mrregister command is able to perform successful t1-dti/dwi registrations it would be much more comfortable and from our perspective even easier to integrate mrtrix in a clinical setting…

Thanks again, Lucius

Hi, Lucius,

Have you solved the mismatch problem yet? I meet the same problem when I do co-registration (register DTI image to T1 image of the same subject).
I firstly do recon-all with T1 image, it will transfer T1 image to Talairach space, I named it t1_freesurfer.nii.gz

flirt -in DTI.nii.gz -ref t1_freesurfer.nii.gz -out DTI_flirtto_t1_freesurfer_tmp.nii.gz -omat DTI_flirtto_t1_freesurfer_tmp.mat -dof 6

flirt -in DTI.nii.gz -ref t1_freesufer.nii.gz -out DTI_flirtto_t1_freesurfer.nii.gz -init DTI_flirtto_t1_freesurfer_tmp.mat -omat DTI_flirtto_t1_freesurfer.mat -dof 6

transformconvert DTI_flirtto_t1_freesurfer.mat DTI.nii.gz t1_freesurfer.nii.gz flirt_import DTI_flirtto_t1_freesurfer_mrtrixformat.txt

mrtransform DTI.nii.gz -linear DTI_flirtto_t1_freesurfer_mrtrixformat.txt DTI_in_t1_freesurfer.nii.gz

However, The result:


Then I tried to use epi_reg (a script designed to register EPI images (typically functional or diffusion) to structural (e.g. T1-weighted) images) :

It seems works, but the outpur file is extremely large( original DTI->61.8 MB , output DTI->519.4 MB ),which brings a lot of pressure when I do fiber tracking. So I have to give up this method.


Finally, I find dt_recon will register the current diffusion data to the structural data in its process. As announced by FreeSurfer, Input the bvalue and direction information using bvec and bval text files with the same format as the files used in FSL diffusion processing.

It works. Register DTI image to T1 image in(talairach ? MNI305) space. In fact, I’m not sure it is talairach or MNI 305 as FreeSurfer announced.

Before run dt_recon, I have to run recon-all command, which takes more than 10 hours with even my machine is quite nice (8 CPU cores and Titan Graphic Cards).

I sincerely hope Mrtrix developers can provide some functions on intra-subject registraion, registration from functional/diffusion image to structual image. It will really be very convenience for the users.

Many Thanks,
Chaoqing