Problem with registering AAL parcellated image with DTI tract file

Hello,
I have created the Whole-brain tractogram using following commands

Step 3.1 - Preparing Anatomical constrained tractography (ACT)

Step 3.1.1 - Preparing Mask for streamline termination

5ttgen fsl T1w.mif 5tt.mif
dwiextract sub_unbiased.mif - -bzero | mrmath - mean mean_b0.mif -axis 3
mrconvert 5tt.mif 5tt.nii.gz
mrconvert mean_b0.mif mean_b0.nii.gz
fslroi 5tt.nii.gz 5tt_gm.nii.gz 0 1
flirt -in mean_b0.nii.gz -ref 5tt_gm.nii.gz -interp nearestneighbour -dof 6 -omat diff2struct_fsl.mat
transformconvert diff2struct_fsl.mat mean_b0.nii.gz 5tt.nii.gz flirt_import diff2struct_mrtrix.txt
mrtransform 5tt.mif -linear diff2struct_mrtrix.txt -inverse 5tt_coreg.mif

Step 3.1.2 - Preparing a mask for streamline seeding

5tt2gmwmi 5tt_coreg.mif gmwmSeed_coreg.mif

Step 3.2 - Creating streamlines

time tckgen -act 5tt_coreg.mif -backtrack -seed_gmwmi gmwmSeed_coreg.mif -maxlength 250 -cutoff 0.06 -select 10000000 wmfod_norm.mif tracks_10M.tck

Step 3.3 - Reducing the number of streamlines

tcksift2 -act 5tt_coreg.mif -out_mu sift_mu.txt -out_coeffs sift_coeffs.txt -nthreads 8 tracks_20M.tck wmfod_norm.mif sift_10M.txt

Next, to create AAL percillated file in subject space

bet2 T1w.nii.gz T1_masked.nii -m -f 0.3
flirt -in T1_masked.nii.gz -ref $FSL_DIR/data/standard/MNI152_T1_1mm_brain.nii.gz -dof 12 -omat T12MNI.mat -interp nearestneighbour -datatype int -out T12MNI.nii.gz

convert_xfm -omat MNI2T1.mat -inverse T12MNI.mat

flirt -in AAL.nii.gz -ref T1_masked.nii.gz -applyxfm -init MNI2T1.mat -interp nearestneighbour -out AAL_sub.nii

Tract file is not properly register in subject space. This may cause poor registration error while using tck2cinnectome for SC.

tck2connectome: [WARNING] The following nodes are missing from the parcellation image:
tck2connectome: [WARNING] 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, …
Should I tranform the images to DTI space?

I have been trying to solve the problem for two years. Any kind of help would be greatly appreciated.

Hi,

Step 3.1.1 - Preparing Mask for streamline termination

5ttgen fsl T1w.mif 5tt.mif
dwiextract sub_unbiased.mif - -bzero | mrmath - mean mean_b0.mif -axis 3
mrconvert 5tt.mif 5tt.nii.gz
mrconvert mean_b0.mif mean_b0.nii.gz
fslroi 5tt.nii.gz 5tt_gm.nii.gz 0 1
flirt -in mean_b0.nii.gz -ref 5tt_gm.nii.gz -interp nearestneighbour -dof 6 -omat diff2struct_fsl.mat
transformconvert diff2struct_fsl.mat mean_b0.nii.gz 5tt.nii.gz flirt_import diff2struct_mrtrix.txt
mrtransform 5tt.mif -linear diff2struct_mrtrix.txt -inverse 5tt_coreg.mif

This step look right, however I will do the flirt registration between the masked b0 and the masked T1w and without -interp nearestneighbour.

However the error is here:

There are two main points:

  • An affine registration between the atlas and the subjects is usually not good enough, you need to add a non rigid registration on top. This can be don with several commands: fnirt or mmorf from fsl, antsRegistration from ants or mrregister from MRtrix (among others)
  • This will give you the registration between the atlas and the T1w. You need to combine them with the registration from the T1w and the diffusion image, you can use the one you have previously computed.

I hope this helps.

Best regards,

Manuel

1 Like

Hi @math_priyanka

This post might also be of interest: Registration: using transformations generated from other packages.

Cheers
William

1 Like

I am quite confused about the basic concepts of registration and transformation in MNI space.
I have subject-specific DTI images and T1w images. Additionally, I have a fixed AAL image and an MNI template. Here’s what I’ve done so far:
I have coregistered segmented T1 images to DTI space and then coregistered the AAL image to DTI space.
Based on my understanding, where should I co-register the segmented images with the parcellated image? In MNI space or in DTI space? And then, I also want to generate the white matter tracts.
Could you please help me understand?

Hi @math_priyanka,

To create the connectome, generally, you want everything in the DTI space. You want to do:

  • T1w (tissue segmentation) → dwi
  • MNI (with labels) → T1w (using a non rigid transformation) → dwi (using the same transformation calculated in the first step)

I hope this helps.

Best regards,

Manuel

1 Like

Ok. Now it is clear. I will do accordingly.
Thank you Manuel.

Hi manuel
What i found following your instruction:
#t1w to dwi
fslroi 5tt.nii.gz 5tt_gm.nii.gz 0 1
flirt -in mean_b0.nii.gz -ref 5tt_gm.nii.gz -dof 6 -omat dwi2t1.mat -interp nearestneighbour -datatype int -out dwi2t1.nii.gz
convert_xfm -omat t12dwi.mat -inverse dwi2t1.mat

#AAL to MNI
flirt -in AAL.nii.gz -ref $FSL_DIR/data/standard/MNI152_T1_1mm_brain.nii.gz -dof 6 -omat AAL2MNI.mat -interp nearestneighbour -datatype int -out AAL2MNI.nii.gz
convert_xfm -omat MNI2AAL.mat -inverse AAL2MNI.mat

#MNI(roi) to T1w
flirt -in AAL2MNI.nii.gz -ref T1_masked -omat mni2t1.mat -interp nearestneighbour -datatype int -out mni2t1.nii.gz
fnirt --in=AAL2MNI.nii.gz --ref=T1_masked.nii.gz --aff=mni2t1.mat --cout=mni2t1_transf
applywarp --ref=T1w.nii.gz --in=AAL2MNI.nii.gz --warp=mni2t1_transf --out=my_warped_mni2ti


It becomes enlarged. is it due to no-rigid transformation?
Also during fnirt run,

Warning, Jacobian not within prescribed range. Prescription is 0.01 – 100 and obtained range is -5.90809 – 78.8052
is appearing
T1w to DWI
flirt -in my_warped_mni2ti -ref mean_b0 -applyxfm -init t12dwi.mat -interp nearestneighbour -out AAL_sub.nii


This image completely rotated.

Hi,

There are few thing going on here.

The AAL labels should be aligned to the MNI, so you don’t have to register those images.

Let’s assume you have T1.nii.gz, T1_masked.nii.gz, mean_b0.nii.gz and mean_b0_masked.nii.gz. The suffix masked denotes the skull stripped versions of the image.

# t1w to dwi
flirt -in mean_b0_masked.nii.gz -ref T1_masked.nii.gz -dof 6 -omat dwi2t1.mat -datatype int -out dwi2t1.nii.gz
convert_xfm -omat t12dwi.mat -inverse dwi2t1.mat

This step it shouldn’t make a big difference, but is better to register intensity images, rather than a tissue probability map to an intensity image. Also, you can check the epi_reg script for this step.

Now, you don’t need to register the AAL to the MNI, they are already aligned, you need to register the MNI to your T1w

#MNI to T1w
 flirt -in MNI.nii.gz -ref T1_masked -omat mni2t1.mat -datatype int -out mni2t1.nii.gz
 fnirt --in=MNI.nii.gz --ref=T1_masked.nii.gz --aff=mni2t1.mat --cout=mni2t1_transf --config=T1_2_MNI152_2mm
 applywarp --ref=T1w.nii.gz --in=AAL.nii.gz --warp=mni2t1_transf --out=my_warped_mni2ti --interp=nn

Note this final file, are the AAL labels in the T1w space, not the final image you want for the connectome.

Finally, bring the AAL labels to the dwi space:

#AAL to dwi
applywarp --ref=mean_b0.nii.gz --in=AAL.nii.gz --warp=mni2t1_transf --postmat=t12dwi.mat --out=AAL_sub.nii.gz --interp=nn

AAL_sub.nii.gz should be aligned with the mean_b0.nii.gz and is the file you need to perform connectomics.

This case works if you have corrected your dwi for EPI distortions, if not the process is slightly more complicated. I hope this helps.

Best regards,

Manuel

1 Like

Hello Manuel,
Thank you for your help.

For the conversion from T1w to DWI, I used epi_reg as you suggested. However, a peculiar issue arises when I transform MNI space to T1 space - the transformed image appears to be rotated.

flirt -in $FSL_DIR/data/standard/MNI152_T1_2mm_brain.nii.gz -ref T1_masked -omat mni2t1.mat -datatype int -out mni2t1.nii.gz

Now, if i use T1w insted of T1_masked image, the output is below:

I did correct epi distortion by dwifslpreproc but without using AP and PA files. Does this happen because of that?
This my preprocessed image

Thank again.

Hello Manuel,
You are right. WHen i corrected EPI distortion, the image did not rotate. The registration seems good.

But whenever i tried with tck2connectome:

tck2connectome -symmetric -zero_diagonal -scale_invnodevol -tck_weights_in sift_10M.txt tracks_10M.tck AAL_sub.nii.gz SC_10M.csv -out_assignment assignments_SC.csv
Output is

t> ck2connectome: [WARNING] The following nodes are missing from the parcellation image:

tck2connectome: [WARNING] 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, …

do i need to do the levelconvert?
I used it also, but it does not make any difference.
IS there anything with the percillated file?

Thank you

Hi,

When you said that you correct for EPI distortion, do you mean you used a fieldmap or reverse phase encoded direction in dwifslpreproc?

Yes. Visually the image will look the same, but the intensities of the labels will change to be order from 1 in increasing units. Also, do you need to use nearest neighbor interpolation when moving the labels, another interpolation method could introduce external values to the label image generating false labels.

Did you used the skull stripped image of the MNI and your T1w? this will improve your registration.

Best regards,

Manuel

Hello Manuel,
The problem is my AAL.nii file. I have downloaded from [Neurofunctional Imaging Group (GIN-IMN)] and then preprocessed the final steps. And it runs fine.
Thank you for all your help.
Regards
Priyanka

1 Like

Dear Manuel,

My data doesn’t have both AP and PA b0 so I can’t correct the EPI distortion, I ran your register command lines, and the effect is not very good, could you please tell me how can I improve the effect with single direction dwi data?

Best regards,
Yuting

Hi,

In that case you have two main options:

  • use your T1w for correction of the EPI distortions. This can be done in different ways but my personal preference is to use Syn-B0. This will correct your diffusion data and from there you can apply the steps explained before.

  • Second options is not to correct the data and do a non rigid registration between the T1w and the B0. This is what has been done historically but is not recommended nowadays.

I hope this helps.

Best regards,

Manuel

Hello Manuel,

Thanks for your reply. I have another question. When I run fnirt with --config=T1_2_MNI152_2mm, it will trigger the fnirt -help and won’t run the command. Are there any steps that I missed?

fnirt --in=MNI.nii.gz --ref=T1_masked.nii.gz --aff=mni2t1.mat --cout=mni2t1_transf --config=T1_2_MNI152_2mm

Best regards,
Yuting

Hi,

Maybe try the full name of the config file? T1_2_MNI152_2mm.cnf

The rest seems fine, maybe you have copied the command from somewhere and is a problem with the dashes?

Sorry not to be more helpful, since this is an fsl question, you’ll have better results posting it here.

Best regards,

Manuel

1 Like

Thanks very much for your reply. I will post my question to the FSL email list

I also face the same problem with the config file in fnirt. Rewriting the command sometimes helps, but not always.

Thanks. Unfortunately, it didn’t help in my case :cry:. I tried to rewrite, run with and without the postfix .cnf, or copy the config file to my working directory, but none of these helped. Now I just use the transformation without a config file, it looks also acceptable.

I used to do the same. Hopefully your post in FSL forum, would help us.