Created
December 9, 2011 14:51
-
-
Save satra/1451812 to your computer and use it in GitHub Desktop.
apply transforms to trackvis tracks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enthought.mayavi import mlab | |
import streamlines | |
import numpy as np | |
from nibabel import load | |
from colorsys import rgb_to_hsv | |
# filename = "DeterministicTractography/QBALLRecon/hardiO10.trk" | |
trkfilename = "/software/data/STUT/DTI_TV/PWS04/dtk_35/dti_35.trk" #%hardiO10.trk_cross_streamline_id_20.trk" | |
bfilename = "/software/data/STUT/DTI_TV/PWS04/dt_recon/lowb.nii" | |
mrfilename = "/software/data/MIBR/data/PWS04/head.nii" | |
reg = np.genfromtxt('/software/data/STUT/DTI_TV/PWS04/dt_recon/register.dat',skiprows=4,comments='r') | |
bimg = load(bfilename) | |
mrimg = load(mrfilename) | |
M = np.array([[-1,0,0,128], | |
[0, 0, 1, -128], | |
[0, -1, 0, 128], | |
[0,0,0,1]],dtype=float) | |
M1 = np.array([[-2,0,0,128], | |
[0, 0, 2, -64], | |
[0, -2, 0, 128], | |
[0,0,0,1]],dtype=float) | |
s = streamlines.Streamlines() | |
s.loadTrk(trkfilename) | |
s.printHeaderTrk() | |
aff = bimg.get_affine() | |
#xfm = np.dot(np.dot(np.dot(img2.get_affine(),np.linalg.inv(M)),reg),aff) | |
xfm = np.dot(mrimg.get_affine(),np.dot(np.linalg.inv(M),np.dot(np.linalg.inv(reg),M1))) | |
print xfm | |
#s.affineTransform(np.dot(aff[0:3,0:3],np.diag(1./s.header['voxel_size'])),aff[0:3,3]) | |
s.affineTransform(np.dot(xfm[0:3,0:3],np.diag(1./s.header['voxel_size'])),xfm[0:3,3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment