Warping functional ROIs from MNI space to wmFOD template space

Hi,

With recent versions of MRtrix, prior to throwing this error, you should have seen a warning message that the images do not overlap, hence registration failed to the point that the lowest cost is non-overlapping images. Anatomical and DWI-based images are difficult to register with mrregister as they have different contrasts and intensity ranges and we currently only support the sum of squares metric.

For now, I’d register the anatomical (T1) and DWI-based (average b=0 or first ODF volume) images with ANTs. Assuming you want to use nonlinear registration with antsRegistration, the steps are to align the moving image input.nii (your T1) with the fixed reference image reference.nii (your average b0 or first volume of the ODF image) are currently described in the wiki. (For linear registration, see for instance here).

For example:

First, get the average b0 image from your preprocessed DWI image (prior to dwi2fod) with dwiextract -bzero and mrmath mean, save it as .nii file. Then register that to the T1 image:

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[reference.nii,input.nii,1,4,Regular,0.1] --convergence [1000x500x250x100,1e-6,10] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform Affine[0.1] --metric CC[reference.nii,input.nii,1,4,Regular,0.2] --convergence [1000x500x250x100,1e-6,10] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform SyN[0.1,3,0] --metric CC[reference.nii,input.nii,1,4] --convergence [100x70x50x20,1e-6,10] --shrink-factors 4x2x2x1 --smoothing-sigmas 2x2x1x0vox -x [reference_mask.nii.gz,input_mask.nii.gz]
  1. Generate an identity (deformation field) warp using the image you wish to warp (“source”; or “moving” image):
warpinit input.mif identity_warp[].nii
  1. Transform this identity warp using the registration program that was used to generate the warp.

For example, if you are using the ANTs registration package:

for i in {0..2}; do
    antsApplyTransforms -d 3 -e 0 -i identity_warp${i}.nii -o mrtrix_warp${i}.nii -r reference.nii -t ants1Warp.nii.gz -t ants0GenericAffine.mat --default-value 2147483647
done
  1. Correct the warp

The resulting 3 3D images mrtrix_warp?.nii hold the voxel-specific corresponding (x, y, z) scanner-space locations. However, locations in the target space to which no known location exists within the moving space need to be handled explicitly. Neglecting this can result in many voxels in the output mrtrix_warp pointing to the location defined by the out of bounds value, such as the origin (0.0, 0.0, 0,0).

Out of bounds locations should ideally be marked by the transformation command with a unique special value that prevents using that part of the warp. Manually convert out of bound markers to vectors of nans with the tool warpcorrect:

$ warpcorrect mrtrix_warp[].nii mrtrix_warp_corrected.mif
  1. Warp the image
mrtransform input.nii -warp mrtrix_warp_corrected.mif warped_input_image.mif

You can check that the conversion went as expected by comparison with ANTs’ output:

mrview input_warped.mif -overlay.load antsWarped.nii.gz -overlay.opacity 0.3
  1. Apply the warp to your ROI (with regridding):
mrtransform roi_input.nii -warp mrtrix_warp_corrected.mif -interp nearest roi_reference.mif

Note that the resulting image has the same voxel grid as the reference image (DWI). You might want to increase the resolution of the ROI for tracking. You can upsample the warp prior to applying it with mrresize -scale and use linear interpolation to preserve spatial resolution.

  1. Check everything worked: mrview fod.mif -roi.load roi_reference.mif -roi.opacity 0.3

Cheers,
Max

2 Likes