Skip to content

Instantly share code, notes, and snippets.

@satra
Created January 24, 2013 14:46
Show Gist options
  • Save satra/4622498 to your computer and use it in GitHub Desktop.
Save satra/4622498 to your computer and use it in GitHub Desktop.
fix mri_convert produced gradients
img = nib.load(imgfile)
bvecs = np.genfromtxt(bvecs)
def get_trackvis_mat(aff):
"""based on input from ruopeng @ tracvkis
"""
for i in range(10):
#aff = aff.dot(np.linalg.inv(np.eye(3) + 3*aff.T.dot(aff)).dot(3*np.eye(3) + aff.T.dot(aff)))
aff = 0.5 * (aff + np.linalg.inv(aff.T))
return np.dot(aff, np.array([[1,0,0],[0,-1,0],[0,0,1]]))
if rotate:
mat = get_trackvis_mat(img.get_affine().copy()[:3, :3])
bvecs = mat.dot(bvecs.T).T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment