Rotating bvecs after correction for susceptibility-induced distortions using T1

Dear MRtrix users

does anybody know a good way to rotate bvecs after correcting for susceptibility-induced distortions in DWI data based on a T1 image?

I have used this script (https://github.com/kathrynalpert/app-dwi2t1-nonlinear) to correct these distortions. However, rotating does not work (based on a FSL-format affine transform matrix).

The script refers to a subscript:

line 95-97

#apply affine reg to bvec
/opt/HCPpipelines/global/scripts/Rotate_bvecs.sh dwi_corrected.bvec
${nm}0GenericAffine_fsl.txt $outdir/dwi.bvecs

which applies the transformation matrix of the DWI to t1 registration to bvecs. It is unclear to me which subscript was used. I tried to use the rotate_bvecs script of the HCPpipeline

(https://github.com/Washington-University/HCPpipelines/blob/master/global/scripts/Rotate_bvecs.sh)

however the output consisted entirely of zeros.

I have tried to find an answer in the mailing list, however, was not succesful. Any help would be greatly appreciated. Thank you very much

In MRtrix3 we try to deal with such manipulations intrinsically: by embedding the diffusion gradient table in the image header, any rotation applied to image data will automatically be applied to the gradient table as well, without having to rely on the explicit instantiation of such scripts.

So my suggestion would be: after the ANTs call, convert the estimated transformation to MRtrix3 format, and apply it to a .mif image that has the diffusion gradient table in the image header.

Hi Rob
Can I chime in here?
I am trying to combine two DWI datasets that have been acquired on different days.
For convenience let’s call them a_DWI.mif and b_DWI.mif
So I like to align b_DWI.mif to a_DWI.mif.
First I extract the B0 images for example into a_B0.nii and b_B0.nii, and then I could use great many tools for example flirt to align b to a and get a rigid transform matrix b2a.txt

Do I understand right that all I have to do then is combine the existing rotation matrix in b_DWI.mif and the b2a.txt?
best
Mark

I think in this case, it’s best to rely on eddy (via dwifslpreproc) to get the alignment right (including the bvecs). The only concern is to ensure the data are scaled equivalently before merging, which you can do with dwicat. I’d try that first, and only look into alternatives if that doesn’t work.

Over and above making your life “easier” by using dwicat / dwifslpreproc, concatenating the data prior to dwifslpreproc will also mean that data are transformed and resampled to correct for all sources of misalignment in a single step. Registering and transforming one independently-preprocessed DWI series onto another independently-preprocessed DWI series will introduce a second interpolation step into the former, which is not ideal.

Nevertheless:

Do I understand right that all I have to do then is combine the existing rotation matrix in b_DWI.mif and the b2a.txt?

I would not describe this as a “combination”, but an “application”. As long as the matrix is properly encoded as “the transformation necessary to apply to the data in B in order for it to spatially overlap with the data in A”, then mrtransform will apply that transformation to both the image data (cleverly applying it to the header transformation matrix rather than necessitating a resampling of image intensities) and the diffusion gradient table.

Well, it does sound good, but the problem is Scan A and Scan B will require different distortion correction.
Be it because they are acquired in different sessions, or for example one scan is recorded with PA phase encoding and the other with AP phase encoding.

One could try a second round of dwifslpreproc with only using alignment, but skipping topup and the more sophisticated eddy steps.
But I haven’t quite figured how to set those flags.

I haven’t looked desperately, mostly because I find that rigid alignment simply does not do a sufficiently good job aligning two sessions. I find not even affine seems flexible enough. So I am currently using the nonlinear atlas fitting procedures from ANTs. They seem to do quite an excellent job.
M.

That should be fine: topup is designed to handle misregistration between the b=0 images and performs realignment internally. It’s also designed to process images with different phase encoding (indeed, it relies on the data having different PE directions and/or bandwidth). And eddy will deal with any gradient reorientation as part of its own processing, and output a corrected gradient table that dwifslpreproc will insert right back into your .mif header. As long as dwifslpreproc is provided with enough information to figure the PE & DW direction for each image volume, it’ll invoke topup & eddy appropriately to do both distortion correction and realignment (along with outlier rejection & replacement and eddy-current distortion correction).

The only minor concern I would have is whether the distortions would differ substantially between the two sessions due to different rotations relative to the main B0 field. Newer versions of topup & eddy try to account for this, I think – but if the rotation is small, I don’t expect that to cause problems either.

In short, I’d still recommend you dwicat your datasets and pass them to dwifslpreproc as-is…

-rpe_none should keep topup out of the equation…
just not sure if eddy is not gonna mess something up?
And I know the remaining distortions are larger than one thinks.
M

Ah, yes, that would make my advice moot… I was assuming that you’d want to use topup if you have different PE directions, and avoid registration to T1. Any reason you can’t do that?

Well, it does sound good, but the problem is Scan A and Scan B will require different distortion correction.
Be it because they are acquired in different sessions, or for example one scan is recorded with PA phase encoding and the other with AP phase encoding.

Sorry, I overlooked the “acquired on different days” bit.

The different phase encoding is actually not an issue; what is an issue is if the patient’s position within the scanner bore is sufficiently different for the B0 inhomogeneity field to differ (over and above cross-session rigid-body translations & rotations). You could try capturing the mean field by combining both datasets to topup and using eddy’s estimation of interaction between motion and inhomogeneity, but my suspicion is that if the distribution of movement is essentially binomial then it’s going to have a hard time estimating such.

But if that doesn’t work, then I would probably suggest processing the two independently, and then registering and resampling both onto an average voxel grid mraverageheader so that the magnitude of interpolation effects are equivalent between the two sessions.