Warping MNI ROI to diffusion subject space

Hi there,

I’m trying to warp an ROI of the VTA from MNI into diffusion subjectspace. I have tried the following, but my result looks to be flipped or rotated. Any advice would be hugely appreciated!

mkdir -p ${dir_subj}/warps/diffusion_space
mkdir -p ${dir_subj}/warps/t1_space
mkdir -p ${dir_subj}/warps/standard_space

cd ${dir_subj}

printf "\n ${subj}: [DWI to T1]"

flirt -in ${dir_subj}/${subj}_ALL_meanb0s.nii.gz -ref ${dir_subj}/${subj}_T1.nii.gz -omat ${dir_subj}/warps/t1_space/${subj}_DWI2T1.mat -out ${dir_subj}/warps/t1_space/${subj}_meanb02T1

printf "\n ${subj}: [T1 to MNI]"

flirt -in ${dir_subj}/${subj}_T1.nii.gz -ref ${FSLDIR}/data/standard/MNI152_T1_2mm_brain.nii.gz -out ${dir_subj}/warps/standard_space/${subj}_T12MNI -omat ${dir_subj}/warps/standard_space/${subj}_T12MNI.mat

fnirt --in=${dir_subj}/${subj}_T1.nii.gz --aff=${dir_subj}/warps/standard_space/${subj}_T12MNI.mat --cout=${dir_subj}/warps/standard_space/${subj}_T12MNI_warp --ref=${FSLDIR}/data/standard/MNI152_T1_2mm_brain.nii.gz --config=T1_2_MNI152_2mm

printf "\n ${subj}: [MNI to T1]"

invwarp -w ${dir_subj}/warps/standard_space/${subj}_T12MNI_warp -r ${dir_subj}/${subj}_T1.nii.gz -o ${dir_subj}/warps/t1_space/${subj}_MNI2T1.nii.gz

applywarp --ref=${dir_subj}/${subj}_T1.nii.gz --in=${FSLDIR}/data/standard/MNI152_T1_2mm_brain.nii.gz --warp=${dir_subj}/warps/t1_space/${subj}_MNI2T1 --out=${dir_subj}/warps/t1_space/${subj}_MNI2T1_warped

printf "\n ${subj}: [T1 to DWI]"

convert_xfm -omat ${dir_subj}/warps/diffusion_space/${subj}_T12DWI.mat -inverse ${dir_subj}/warps/t1_space/${subj}_DWI2T1.mat

applywarp --ref=${dir_subj}/${subj}_ALL_meanb0s.nii.gz --in=${dir_subj}/${subj}_T1.nii.gz --postmat=${dir_subj}/warps/diffusion_space/${subj}_T12DWI.mat --out=${dir_subj}/warps/diffusion_space/${subj}_T12DWI_warped

printf "\n ${subj}: Warping ROI masks to subject DWI space..."

applywarp --ref=${dir_subj}/${subj}_T1.nii.gz --in=${dir_masks}/VTA_lh.nii.gz --warp=${dir_subj}/warps/t1_space/${subj}_MNI2T1 --out=${dir_subj}/warps/t1_space/${subj}_VTA_lh2T1.nii.gz

applywarp --ref=${dir_subj}/${subj}_ALL_meanb0s.nii.gz --in=${dir_subj}/warps/t1_space/${subj}_VTA_lh2T1.nii.gz --postmat=${dir_subj}/warps/diffusion_space/${subj}_T12DWI.mat --out=${dir_subj}/warps/diffusion_space/${subj}_VTA_lh2DWI.nii.gz

fslmaths ${dir_subj}/warps/diffusion_space/${subj}_VTA_lh2DWI.nii.gz -bin -thr .0000000001 ${dir_subj}/warps/diffusion_space/${subj}_VTA_lh2DWI_bin.nii.gz

This is what it should look like:

I have now also tried a different method that has been suggested in a previous post, but it doesn’t seem to work either:

antsRegistration --verbose 1 --dimensionality 3 --float 0 --output [ants,antsWarped.nii.gz,antsInverseWarped.nii.gz] --interpolation Linear --use-histogram-matching 1 --winsorize-image-intensities [0.005,0.995] --transform Rigid[0.1] --metric CC[${subj}_T1.nii.gz,${subj}_ALL_meanb0s.nii.gz,1,4,Regular,0.1] --convergence [1000x500x250x100,1e-6,10] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform Affine[0.1] --metric CC[${subj}_T1.nii.gz,${subj}_ALL_meanb0s.nii.gz,1,4,Regular,0.2] --convergence [1000x500x250x100,1e-6,10] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform SyN[0.1,3,0] --metric CC[${subj}_T1.nii.gz,${subj}_ALL_meanb0s.nii.gz,1,4] --convergence [100x70x50x20,1e-6,10] --shrink-factors 4x2x2x1 --smoothing-sigmas 2x2x1x0vox -x [${subj}_T1.nii.gz,${subj}_ALL_meanb0s.nii.gz]

warpinit ${FSLDIR}/data/standard/MNI152_T1_2mm_brain.nii.gz identity_warp[].nii

for i in {0..2}; do
    antsApplyTransforms -d 3 -e 0 -i identity_warp${i}.nii -o mrtrix_warp${i}.nii -r ${subj}_T1.nii.gz -t ants1Warp.nii.gz -t ants0GenericAffine.mat --default-value 2147483647

warpcorrect mrtrix_warp[].nii mrtrix_warp_corrected.nii.gz

mrtransform ${FSLDIR}/data/standard/MNI152_T1_2mm_brain.nii.gz -warp mrtrix_warp_corrected.nii.gz warped_input_image.nii.gz

When I then check the MNI warp it doesn’t match at all:

Any help would be greatly appreciated!

Did you check whether the warps themselves (rather than their conversion) are fine by applying them with FSL/ANTs? Chances are the registration itself was not successful.

Thanks for your reply! I’m not sure how I’d do that. Any chance you could describe it briefly? I only checked the image overlays…

Hi Lena,

For me personally, any time I’m dealing with external softwares that read / write NIfTIs, I immediately do a:

mrconvert in.mif out.nii -strides +1,+2,+3

Some softwares / software tools make certain assumptions about correspondence between image strides and spatial directions, and can do weird things if the NIfTI transform is far from identity. If you’ve not done this prior to the specified code I would suggest trying that first.

Beyond that, since it can be hard to tell what’s gone wrong from just the transformed ROIs, I would suggest explicitly applying all of the estimated transformations to the relevant image data and checking those for spatial correspondence. Quite often a registration command will also export as an output the transformed image, but there will be some other command to take the outcome of a registration process and apply it to some other data; using the latter, but running it on the image data rather than parcellation information, will verify whether your usage of the second command is erroneous. You can also do this after operations like inverting a non-linear warp field.

I would also note that your registration of DWI to T1w is currently 12 DoF, whereas for inter-modality intra-session 6 DoF would typically be recommended, and this can be achieved simply through modification of the image header transformation (through transformconvert flirt_import and mrtransform).


Hi Rob,

Changing the strides helped massively with the orientation!

However, the ROIs still seem slightly off. When I check the co-registrations between the images, they look great, so I don’t think it’s anything with the matrix files. I have noticed I get a better result if I use applywarp instead of flirt:

applywarp --ref={dir_subj}/{subj}_T1.nii.gz --in={dir_masks}/VTA_lh.nii.gz --warp={dir_subj}/warps/t1_space/{subj}_MNI2T1 --out={dir_subj}/warps/t1_space/${subj}_VTA_lh2T12.nii.gz --interp=nn

applywarp --ref={dir_subj}/{subj}_mean_bzero.nii.gz --in={dir_subj}/warps/t1_space/{subj}_VTA_lh2T12.nii.gz --postmat={dir_subj}/warps/diffusion_space/{subj}_T12dwi.mat --out={dir_subj}/warps/diffusion_space/{subj}_VTA_lh2dwi2.nii.gz;

But they ROI’s are just nudged a bit:

Any thoughts on what I could try?

Thanks, Lena