Differences between revisions 1 and 2
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
One series of transformations that can be useful is to get [[http://www.trackvis.org/|trackvis]] ''trk'' tractography data into the same space as freesurfer surfaces (e.g. smoothwm, pial). In order to do this, the following steps must be taken: One series of transformations that can be useful is to get [[http://www.trackvis.org/|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 do get the ''trk'' vertices and surfaces into the same space, the following steps must be taken:
Line 5: Line 9:
The first step is to load the ''trk'' data from a file. The file format is described in detail at the following [[http://www.trackvis.org/docs/?subsect=fileformat|link]]. The first step is to load the ''trk'' data from a file. The file format is described in detail at the following [[http://www.trackvis.org/docs/?subsect=fileformat|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[0], trkHeader.voxel_size[1], trkHeader.voxel_size[2])
}}}

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).
Line 9: Line 19:
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 [[http://www.trackvis.org/dtk/|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.
Line 11: Line 37:
=== 4. Apply tkRAS-to-tkRAS registration matrix to surface vertices === The next step is to load the vertices from the freesurfer surface file. These are stored in the tkReg frame-of-reference.
Line 13: Line 39:
=== 4. Apply tkReg-to-tkReg registration matrix to surface vertices ===
Line 14: Line 41:
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:
Line 15: Line 43:
''orig.mgz'' volume must first be registered with the B0 volume produced by the diffusion toolkit (e.g., ''dti_b0.nii') {{{
  bbregister --s <subject> --mov dti_b0.nii --init-fsl --reg bbregister.dat --bold --tol1d 1e-3
}}}
Line 17: Line 47:
This page describes how to transform coordinate from TrackVis 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.

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 do 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[0], trkHeader.voxel_size[1], trkHeader.voxel_size[2])

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.

FreeSurferTrackVisTransforms (last edited 2021-09-22 11:37:59 by DevaniCordero)