sina-mansour / UKB-connectomics

This repository will host scripts used to map structural and functional brain connectivity matrices for the UK biobank dataset.
https://www.biorxiv.org/content/10.1101/2023.03.10.532036v1
61 stars 7 forks source link

The alignment of the diffusion and structural MRI spaces #7

Closed sina-mansour closed 2 years ago

sina-mansour commented 2 years ago

Following on the suggestion by @Lestropie (this commit):

RS: As discussed, they should be aligned well, but this may not be the case; requires further investigation to determine whether or not an explicit registration step should be included here (and indeed what tool would be used if so).

sina-mansour commented 2 years ago

I've searched a little further in the UKB documents, and this is my understanding so far:

From what I understood, all DWI data we are using for tractography was provided in a "GDCorrected dMRI space". To the best of my knowledge, this space is never directly mapped to the "Tigh FOV T1 space" which is used in the structural T1 processing pipeline.

Hence, I will add a linear registration to align the mean b0 image to the 5tt image using flirt. I'll try to use this blog post as a guideline. However, something that I'm yet unsure about is how many degrees of freedom to use in flirt. The blog post suggested 6, but I was thinking that 9 or 12 may provide higher flexibility to align the two images.

P.S. This pdf documentation provided valuable information beyond to what's already explained in the UKbiobank paper.

Lestropie commented 2 years ago

The registration should absolutely be 6 DoF. Any non-zero higher-order affine components would by definition be erroneous given it's the same brain with very little time between the acquisitions.

I've not invested a huge amount in inter-modal registration myself. A lot of people I think use BBR, but I've not played with it. Personally I use a linear version of this method to generate the images for registration (code) and use first for the registration itself.

sina-mansour commented 2 years ago

I have implemented a rigid body transformation similar to the code here. However, I'm not sure if this rigid transformation is performing good enough or not. I've provided the screenshots of the mean b0 and the T1 registered to DWI space images.

mean b0 image:

image

T1 registered to DWI:

image

Overlay with opacity to see the two on top of each other:

image

And this is the boundary seed overlaid on mean b0 image:

image

Please let me know what you think about these images. I personally think the alignment is not as good as expected, the T1 is more stretched along left-right axis, whereas DWI is more stretched along the inferior-superior axis. That's why I'm thinking maybe a general affine transformation may be better. However, I'm not sure if that's normal or whether I'm nitpicking. I'll prepare similar images for another subject to ensure it's not a single-case issue.

Lestropie commented 2 years ago

It indeed doesn't look quite right. However don't know whether it's an inadequacy of the method being used, or whether there is indeed residual non-rigid geometric differences between the two images. This would need to be evaluated more closely before resorting to a general affine transformation however. I hear of people using BBR a lot. And you could try other image contrasts, i.e. not using the contrast-matched technique.

If there are non-rigid differences between the two modalities, this would point at a major issue with upstream image processing, whether it be EPI susceptibility distortion correction or gradient non-linearity distortion correction or something else. This would be a major concern, and you'd want to be communicating with UKB to accurately diagnose and understand the issue, rather than hiding it under a theoretically inappropriate processing step (which, depending on the nature of the issue, may itself not be adequate; e.g. if it's either of the examples above, a general affine would itself be not enough also).

sina-mansour commented 2 years ago

Following your suggestions and also seeking advice from @mdibiase1 (Maria) who's kindly agreed to provide advice and assistance, I'm planning to conduct the following alternative rigid body registrations to find which method works best on our data:

  1. The method used here which involves averaging two rigid transformations of contrast matched maps (currently implemented)
  2. The two initial rigid transformations of the method above before averaging (I'm thinking one of the two may actually be imperfect)
  3. Registration of the DWI to T1 directly without contrast matching
  4. Registration of the DWI (mean b0) to the T2 image which has a similar contrast
  5. Alternative to mrregister try using FLIRT with a BBR cost function
sina-mansour commented 2 years ago

After implementing multiple alternative approaches, two approaches resulted in fairly accurate registrations (both can be linked to this discussion thread):

  1. using FSL FLIRT with normmi cost function
  2. using FSL FLIRT with the BBR cost function

The main difference was that the normmi cost function (~10sec) was a lot quicker than the BBR (~5min).

Hence, I think it's best to use the former. Here is an overlaid view of T1 (blue) on DWI (red) after this rigid transformation (I think the main imperfections of this registration are around the cerebellum, which we will not use in the connectivity maps):

image

Further notes:

Lestropie commented 2 years ago

No contrast matching was performed and DWI mean b0 was directly registered to T1

Yep that's fine if using normalised mutual information.

... around the cerebellum, which we will not use in the connectivity maps

Is there a strong justification for this? If you include it in the matrices, and people consider those connnections to be of no interest, then they can simply erase the corresponding rows / columns; whereas if someone wants those data, but you have omitted them, there's nothing that can be done to restore.

You also don't want to fall for the trap of removing the cerebellum nodes from the parcellation image, only to have streamlines terminating within the cerebellum being attributed to parcels at the inferior part of the occipital / temporal lobes.

mdibiase1 commented 2 years ago

Assuming masked data were used for registration, perhaps we can improve results around the cerebellum by improving the T1 mask? Do you mind sharing an image of the T1 mask superimposed onto the T1w image with some transparency applied to the mask?

Lestropie commented 2 years ago

Also make sure that if transforming DWI data to the T1w image, it needs to be done in a way that applies the rotation of that transformation to the DWI gradient table. So e.g. following flirt, using transformconvert and then mrtransform.

sina-mansour commented 2 years ago

Do you mind sharing an image of the T1 mask superimposed onto the T1w image with some transparency applied to the mask?

Here's the T1 (unmasked image) with a transparent overlay of the mask:

image

sina-mansour commented 2 years ago

Is there a strong justification for this? If you include it in the matrices, and people consider those connnections to be of no interest, then they can simply erase the corresponding rows / columns; whereas if someone wants those data, but you have omitted them, there's nothing that can be done to restore.

Normally the brain atlases that are being used to map structural connectomes do not include the cerebellum. So, basically, it's not a decision that is being made as a result of this potential inaccurate registration. Traditionally, SC mapping approaches use atlases comprising cortical regions and subcortical nuclei to form the network nodes.

However, if we also decide to store the endpoint information for every subject, then that could be used to extract information about cerebellar connectivity. This way if someone uses an atlas with the cerebellum included, they can map cerebellar connectivity without the need to repeat tractography.

sina-mansour commented 2 years ago

Also make sure that if transforming DWI data to the T1w image, it needs to be done in a way that applies the rotation of that transformation to the DWI gradient table. So e.g. following flirt, using transformconvert and then mrtransform.

I'll be registering the DWI to the T1 image. However, I'll use an inverse linear transform to get all structural images back to diffusion space. The final script (will clean it in the next commit) uses flirt followed by transformconvert and mrtransform.

mdibiase1 commented 2 years ago

T1 mask looks good.

sina-mansour commented 2 years ago

Assuming masked data were used for registration, perhaps we can improve results around the cerebellum by improving the T1 mask?

Following on this suggestion @mdibiase1 , I started looking at the masks. While the T1 mask (presented in an earlier comment) seems to be pretty accurate, the diffusion mask is not as accurate upon checking, especially around the cerebellum (image below). Is there a way to get a better DWI brain mask than what is provided?

image

sina-mansour commented 2 years ago

Just to update you on what I've been trying to get a better DWI brain mask:

I've tried the following approaches; neither worked directly out of the box:

  1. FSL bet with the robust flag (seems to lose posterior frontal regions and include anterior regions out of the brain):

image

  1. using dwi2mask from mrtrix (better alignment to the anterior parts of brain and also the cerebellum, but peculiar masking of subcortical brain regions):

image

For the first option, I'll try to play with some of bet's extra options and see what happens. For the latter, @Lestropie do you know why this is happening or how to correct for it?

mdibiase1 commented 2 years ago

underinclusive: maybe try -f 0.2 -g -0.05 (with -R flag)?

sina-mansour commented 2 years ago

underinclusive: maybe try -f 0.2 -g -0.05 (with -R flag)?

Definitely gets more inclusive under this setting:

image

sina-mansour commented 2 years ago

Additionally, regarding the problem with the dwi2mask having holes around the ventricles, I came across this thread in which Thijs suggested a bias field correction may resolve the issue, but trying that made no big difference. (I tried the default dwibiascorrect -ants)

mdibiase1 commented 2 years ago

Is registration improved (around the cerebellum) after using this new mask to skull strip the mean b0 volume?

Lestropie commented 2 years ago

DWI masking is a persistent problem. So much so that in 3.1.0 dwi2mask is completely overhauled, providing ~ 10 different algorithms so that people can choose what works for their data.

Bias field correction typically helps, but it's also a circular problem in that good bias field correction requires a good brain mask. The approach I use myself is an iterative combination of CSD & mtnormalise, selecting those voxels where the sum of components of the tissue decomposition is greater than 0.5.

In all cases, this will need to be checked across a number of exemplar subjects.

mdibiase1 commented 2 years ago

In all cases, this will need to be checked across a number of exemplar subjects.

Yes - and checked on subjects from both scanners

sina-mansour commented 2 years ago

I have implemented a few other skull stripping approaches and I think we can now make a decision on what to use:

Two approaches yielded good dwi brain masks:

The latter resulted in a more accurate mask, but both provided good rigid registration between T1 and DWI.

Hence, I decided to go with the simpler approach (FSL BET). The picture below is the alignment we get using the FSL BET mask:

image

I will finalize this pipeline for now, but we'll need to check the masks for a few subjects to ensure that this works.

Yes - and checked on subjects from both scanners

I didn't know that there were different scanners, where do they store this information?

Lestropie commented 2 years ago

FSL BET with the options -f 0.2 -g -0.05 -R

Do we know how the UKB-provided brain masks were derived? I would have estimated that they would have been BET-based, but they may have used different parameters, or they may not have used the -R option.

sina-mansour commented 2 years ago

In the protocol paper, this is not so clear. All they mention is that bedpostX was performed:

image

Digging further into UKB material there's also this which doesn't really mention what's happening either:

image

Digging even deeper, this is the git repository storing their pipeline:

https://git.fmrib.ox.ac.uk/falmagro/UK_biobank_pipeline_v_1/-/tree/master/bb_diffusion_pipeline

From what I understand, they use the brain mask generated from the fieldmap:

https://git.fmrib.ox.ac.uk/falmagro/UK_biobank_pipeline_v_1/-/blob/master/bb_diffusion_pipeline/bb_eddy/bb_pre_eddy#L37

And what I see is that the fieldmap mask was generated by some sort of warping, dilating, and transforming of the T1 brain mask:

https://git.fmrib.ox.ac.uk/falmagro/UK_biobank_pipeline_v_1/-/blob/master/bb_structural_pipeline/bb_post_topup#L66-70

So basically, no they didn't use bet directly on b0 images, they've rather transformed the T1 mask to the diffusion space but the rationale is not that clear to me.

Speaking of the fieldmap files, these are the files provided by UKB:

1000094_2_0/fieldmap/
├── fieldmap_fout_to_T1_brain_rad.nii.gz
├── fieldmap_iout_mean.nii.gz
├── fieldmap_iout_mean_ud.nii.gz
├── fieldmap_iout_to_T1.mat
├── fieldmap_mask.nii.gz
├── fieldmap_mask_ud.nii.gz
├── fieldmap_out_fieldcoef.nii.gz
└── fieldmap_out_movpar.txt

There's a mask file (fieldmap_mask_ud.nii.gz) and a linear warp (fieldmap_iout_to_T1.mat) which may be similar to what we're computing, but I'm not sure if it's worth using these files instead of our current approach (generating a mask using bet, and transforming mean_b0 to T1 with this mask).

sina-mansour commented 2 years ago

@Lestropie

I also noticed that they only use the bvals and bvecs (not the eddy_rotated bvecs) in the bedpostX scripts:

https://git.fmrib.ox.ac.uk/falmagro/UK_biobank_pipeline_v_1/-/blob/master/bb_diffusion_pipeline/bb_bedpostx/bb_bedpostx_gpu

I'm not sure what's correct but wanted to flag this just to make sure what we're doing is ok:

https://github.com/sina-mansour/UKB-connectomics/blob/main/scripts/bash/probabilistic_tractography_native_space.sh#L51-L53

Lestropie commented 2 years ago

Propagating a T1w-derived brain mask to DWI is going to be problematic if the registration between T1w and DWI is imperfect, as reported in this particular Issue. So us deriving a DWI brain mask through some other approach is wholly justified. You may additionally want to speak to UKB as to whether they have any interest in our providing transformation matrices and/or DWI brain masks from our chosen approach to their database.

Regarding rotation of gradient directions (#12), I'd say that's a mistake on their part. I have some vague recollection of uncertainty regarding whether or not the rotations applied by eddy were correct, but I don't recall how far up the hierarchy that uncertainty went. Primary reference for motivation of use of rotated vectors: http://dx.doi.org/10.1002/mrm.21890