Created
December 11, 2011 10:04
Revisions
-
satra revised this gist
Dec 13, 2011 . 2 changed files with 32 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ #DOES NOT WORK: GIFTI READ/WRITE is broken import nibabel as nb import nibabel.gifti as gifti This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ import nibabel as nb import nibabel.gifti as gifti # load combined file # created with: mris_convert --combinesurfs lh.pial rh.pial ./pial.gii surf = gifti.read('pial.gii') #load orig affine transform ao = nb.load('orig.nii').get_affine() # load conformed affine ac = nb.load('conformed.nii').get_affine() # create freesurfer conformed volume to surface transform matrix import numpy as np M = np.array([[-1,0,0,128], [0, 0, 1, -128], [0, -1, 0, 128], [0,0,0,1]],dtype=np.float32) # create transform to go to native space xfm = np.dot(ac, np.linalg.inv(M)) # transform the two data arrays storing left and right vertices xfmda0 = np.dot(xfm, np.hstack((surf.darrays[0].data, np.ones((surf.darrays[0].data.shape[0],1)))).T)[:3,:].T # write directly to vtk from tvtk.api import tvtk mesh = tvtk.PolyData(points=xfmda0, polys=surf.darrays[1].data) w = tvtk.XMLPolyDataWriter(input=mesh, file_name='polydata.vtp') w.write() -
satra revised this gist
Dec 12, 2011 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,11 +25,12 @@ xfmda0 = np.dot(xfm, np.hstack((surf.darrays[0].data, np.ones((surf.darrays[0].data.shape[0],1)))).T)[:3,:].T xfmda1 = np.dot(xfm, np.hstack((surf.darrays[1].data, np.ones((surf.darrays[1].data.shape[0],1)))).T)[:3,:].T da = surf.darrays[0] indtype = da.data.dtype # set the data surf.darrays[0] = da.from_array(xfmda0.astype(indtype), da.intent, da.datatype) surf.darrays[1] = da.from_array(xfmda1.astype(indtype), da.intent, da.datatype) # write to file gifti.write(surf, 'xfmpial.gii') -
satra revised this gist
Dec 12, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ M = np.array([[-1,0,0,128], [0, 0, 1, -128], [0, -1, 0, 128], [0,0,0,1]],dtype=np.float32) # create transform to go to native space xfm = np.dot(ac, np.linalg.inv(M)) -
satra revised this gist
Dec 12, 2011 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,9 +25,11 @@ xfmda0 = np.dot(xfm, np.hstack((surf.darrays[0].data, np.ones((surf.darrays[0].data.shape[0],1)))).T)[:3,:].T xfmda1 = np.dot(xfm, np.hstack((surf.darrays[1].data, np.ones((surf.darrays[1].data.shape[0],1)))).T)[:3,:].T indtype = surf.darrays[0].data.dtype # set the data surf.darrays[0].data = xfmda0.astype(indtype) surf.darrays[1].data = xfmda1.astype(indtype) # write to file gifti.write(surf, 'xfmpial.gii') -
satra created this gist
Dec 11, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ import nibabel as nb import nibabel.gifti as gifti # load combined file # created with: mris_convert --combinesurfs lh.pial rh.pial ./pial.gii surf = gifti.read('pial.gii') #load orig affine transform ao = nb.load('orig.nii').get_affine() # load conformed affine ac = nb.load('conformed.nii').get_affine() # create freesurfer conformed volume to surface transform matrix import numpy as np M = np.array([[-1,0,0,128], [0, 0, 1, -128], [0, -1, 0, 128], [0,0,0,1]],dtype=float) # create transform to go to native space xfm = np.dot(ac, np.linalg.inv(M)) # transform the two data arrays storing left and right vertices xfmda0 = np.dot(xfm, np.hstack((surf.darrays[0].data, np.ones((surf.darrays[0].data.shape[0],1)))).T)[:3,:].T xfmda1 = np.dot(xfm, np.hstack((surf.darrays[1].data, np.ones((surf.darrays[1].data.shape[0],1)))).T)[:3,:].T # set the data surf.darrays[0].data = xfmda0 surf.darrays[1].data = xfmda1 # write to file gifti.write(surf, 'xfmpial.gii')