Skip to content

Instantly share code, notes, and snippets.

@mpaquette
Created August 29, 2018 11:44
Show Gist options
  • Save mpaquette/5d59ad195778f9d984c5def42f53de6e to your computer and use it in GitHub Desktop.
Save mpaquette/5d59ad195778f9d984c5def42f53de6e to your computer and use it in GitHub Desktop.
Rotate bvecs with ANTS transform matrix
from scipy.io import loadmat
import numpy as np
import sys
if __name__ == "__main__":
print('input_ants_rigid_transform input_bvecs output_bvec')
# Loading Ants transform
trans = loadmat(sys.argv[1])
matrice = trans['AffineTransform_double_3_3'][:9].reshape((3,3))
#loading bvecs
bvecs = np.genfromtxt(sys.argv[2])
# heuristic to have bvecs shape 3xN
if bvecs.shape[0] != 3:
bvecs = bvecs.T
# Rotating bvecs
newbvecs = np.dot(matrice, bvecs)
# saving bvecs
np.savetxt(sys.argv[3], newbvecs)
@mpaquette
Copy link
Author

ex ants command:
antsRegistration -d 3 -o [./b0_28_to_16_,./b0_28_to_16_warped.nii.gz] -n BSpline -w [0.005,0.995] -u -r [b0_16_9.nii.gz,b0_28_7.nii.gz,1] -t Rigid[0.1] -m MI[b0_16_9.nii.gz,b0_28_7.nii.gz,1,32,Regular,0.25] -c [1000x500x250x100,1e-6,10] -f 8x4x2x1 -s 3x2x1x0vox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment