|Deletions are marked like this.||Additions are marked like this.|
|Line 2:||Line 2:|
'''See also:'''[[http://trackvis.org/docs/?subsect=fileformat|TrackVis file format]]
Author: Dan Ginsburg
See also:TrackVis file format
One series of transformations that can be useful is to get trackvis trk tractography data into the same space as freesurfer surfaces (e.g. smoothwm, pial). Before beginning, it is worth stating an assumption that this wiki page makes about coordinate frames:
- The frames-of-reference referred to by "tkReg", "tkRAS", and "Surface RAS" in the freesurfer documentation all refer to the same frame-of-reference. On this page, I use only the term "tkReg" to refer to this frame-of-reference. Elsewhere in freesurfer commands and documents you may see these referred to by any of the three names.
In order to get the trk vertices and surfaces into the same space, the following steps must be taken:
1. Load vertices from a ''trk'' file and put them in CRS (Column, Row, Slice) of the B0 volume
The first step is to load the trk data from a file. The file format is described in detail at the following link. The vertices inside the trk file are stored in units of millimeters (mm). In order to transform these into CRS (of the diffusion volume), the following must be done:
trk_verts_crs.xyz = trk_verts.xyz / (trkHeader.voxel_size, trkHeader.voxel_size, trkHeader.voxel_size)
In other words, simply divide the trk coordinates from the file by the voxel_size in the header to place the coordinates into CRS (of the diffusion volume).
2. Transform the ''trk'' vertices from CRS -> tkReg (also called "Surface RAS" or "tkRAS")
Once the trk vertices are in CRS, the next step is to transform them into the tkReg frame-of-reference (which is elsewhere also referred to as "SurfaceRAS" and "tkRAS"). The reason for this is because the surfaces (smoothwm, pial, etc.) are stored in the tkReg frame-of-reference.
In order to obtain the CRS2XYZtkreg matrix for the diffusion volume, use the following command on the b0 volume generated by the Diffusion Toolkit:
mri_info dti_b0.nii --vox2ras-tkr
This will output to the console a 4x4 transformation matrix that transforms from CRS (of the diffusion volume) to tkReg (we'll call this matrix CRS2XYZtkreg). In order to transform the trk CRS vertices into tkReg space, you would use this 4x4 transformation and do the following math:
trk_verts_tkreg = CRS2XYZtkreg * trk_verts_crs
The trk_verts_tkreg are now stored in the same frame-of-reference as the freesurfer surfaces.
3. Load vertices for a surface (e.g., lh.smoothwm)
The next step is to load the vertices from the freesurfer surface file. These are stored in the tkReg frame-of-reference.
4. Apply tkReg-to-tkReg registration matrix to surface vertices
Finally, the last step is to register the B0 to the T1 volume in order to account for any movement between the two scans. Typically, this should be a small amount of movement given the acquisition occurred at the same time. The following command will generate a 4x4 transformation matrix between the B0 and T1 volumes:
bbregister --s <subject> --mov dti_b0.nii --init-fsl --reg bbregister.dat --bold --tol1d 1e-3
This will produce a tkReg-to-tkReg registration matrix between the B0 volume and the original T1 volume in bbregister.dat. You should of course verify the registration matrix is correct using a tool such as tkregister2 or freeview. The final step is now to take the loaded surface vertices and transform them by this 4x4 registration matrix.
mris_verts_registered_tkreg = bbregister_matrix * mris_verts_tkreg
The tracks and surfaces should now be registered and in the tkReg frame-of-reference.