Skip to content

Instantly share code, notes, and snippets.

@oesteban
Created September 10, 2013 19:40
Show Gist options
  • Save oesteban/6514493 to your computer and use it in GitHub Desktop.
Save oesteban/6514493 to your computer and use it in GitHub Desktop.
Old code for transforming surfaces from freesurfer
# http://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferTrackVisTransforms
tkr1_tfm = fsbt.mri_info( op.join( tpms_dir, 'wm_volume_fraction.nii.gz' ), 'vox2ras-tkr' )
r2v_tfm = fsbt.mri_info( op.join( tpms_dir, 'wm_volume_fraction.nii.gz' ), 'ras2vox' )
tkr2_tfm = fsbt.mri_info( op.join( tpms_dir, 'wm_volume_fraction.nii.gz' ), 'ras2vox-tkr' )
v2r_tfm = fsbt.mri_info( op.join( tpms_dir, 'wm_volume_fraction.nii.gz' ), 'vox2ras' )
tfm = np.dot( tkr2_tfm, v2r_tfm )
M = tfm[0:3,0:3]
O = tfm[0:3,3]
print O
O = [ -0.25, -0.25, -0.25]
surf = op.join( working_dir, 'test.vtk' )
r = tvtk.PolyDataReader( file_name=surf )
vtk = r.output
r.update()
for i,point in enumerate( vtk.points ):
vtk.points[i] = np.dot( M, point ) - O
w = tvtk.PolyDataWriter( file_name=op.join( working_dir, 'wm_corrected2.vtk' ), input=vtk )
w.update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment