FSnormals.py: Difference between revisions
No edit summary |
(→Usage) |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
==Description== |
==Description== |
||
The FSnormals.py program will take a FreeSurfer surface, and output a list of all the vertices and their surface normals. Crucially, given an image in ortho/MEG space, as produced by AFNI's 3dTagAlign or [[orthohull.py|orthohull.py]], FSnormals.py will rotate the surface normals to MEG space. This program is required for use before sam_coreg can be run. Python must be installed. In addition, you must set the FREESURFER_HOME directory and, optionally, the SUBJECTS_DIR. Note that the default SUBJECTS_DIR is $FREESURFER_HOME/subjects, which is probably not where your images are. In addition to producing the surface normals, FSnormals.py will also preserve the annotation from freesurfer which gives the cortical parcel that any given |
The FSnormals.py program will take a FreeSurfer surface, and output a list of all the vertices and their surface normals. Crucially, given an image in ortho/MEG space, as produced by AFNI's 3dTagAlign or [[orthohull.py|orthohull.py]], FSnormals.py will rotate the surface normals to MEG space. This program is required for use before sam_coreg can be run. Python must be installed. In addition, you must set the FREESURFER_HOME directory and, optionally, the SUBJECTS_DIR. Note that the default SUBJECTS_DIR is $FREESURFER_HOME/subjects, which is probably not where your images are. In addition to producing the surface normals, FSnormals.py will also preserve the annotation from freesurfer which gives the cortical parcel that any given vertex belongs to. |
||
==Usage== |
==Usage== |
||
FSnormals.py [-q] [-a annotation] ... [-t ortho+orig] [-i fac] [-p parcfile] |
|||
FSnormals.py subject [surface] |
|||
[-g "step radius"] [-r thresh] [-L|-R|-B] -o outputfile subject [surface] |
|||
The subject argument corresponds to the FreeSurfer subject designation, and denotes a directory under $SUBJECTS_DIR. The surface argument denotes the surface to use: orig, pial, white, or smoothwm (default). |
|||
Other options: |
Other options: |
||
{| |
{| |
||
Line 14: | Line 16: | ||
| style="width: 10em" | -q || Operate quietly, default is verbose |
| style="width: 10em" | -q || Operate quietly, default is verbose |
||
|- valign="top" |
|- valign="top" |
||
| -a annotation || Restrict the output to |
| -a <annotation> || Restrict the output to an annotation region, denoted by its number (see the corresponding ctab for a list of numbers and regions in the label/ directory of each subject's FreeSurfer directory). To select multiple regions, repeat this option. Note that in the output, positive numbers denote the left hemisphere, and negative numbers denote the right. The -L, -R, and -B options control which values (positive, negative, or both) appear in the output. |
||
|- valign="top" |
|- valign="top" |
||
|-p parcfile|| Specify the parcellation file to use. The default is aparc.a2009s, which is the Destrieux atlas. Other options include aparc (the Desikan-Killiany atlas) and aparc.DKTatlas (the Desikan-Killiany-Tourville atlas). |
|-p parcfile || Specify the parcellation file to use. The default is aparc.a2009s, which is the Destrieux atlas. Other options include aparc (the Desikan-Killiany atlas) and aparc.DKTatlas (the Desikan-Killiany-Tourville atlas). |
||
|- valign="top" |
|- valign="top" |
||
| -t ortho+orig|| Rotate the output vertices and surface normals into the space defined by the ortho+orig space |
| -t ortho+orig || Rotate the output vertices and surface normals into the space defined by the ortho+orig space. In order to use this, ortho+orig must have been generated using the 3dTagAlign command (typically using orthohull). |
||
|- valign="top" |
|- valign="top" |
||
| -i fac || |
| -i <fac> || Move each vertex along its normal vector according to v' = v + fac * n (fac in mm, may be negative). Note that this conversion is done before resampling to a grid (if -g is used). |
||
|- valign="top" |
|- valign="top" |
||
| -g "<step> <radius>" || This option restricts the output vertices to the grid defined by the ortho+orig MRI (you must use -t in this case). The step argument is an integer specifying the number of MRI voxels between output grid points. At each grid point, all the normal vectors within a ball of the given radius (mm) are averaged together to form the output normal. For example -g "3 1.5" means one grid point every 3 MRI voxels, and an averaging ball with a 3 mm (2 x 1.5) diameter. |
|||
⚫ | | -r thresh || Use this option to filter out vertices which have near radial normals. The threshold is the absolute value of the dot product of the vertex's position vector (relative to the centroid) with the normal vector, so it ranges from 0 to 1. Large values allow more radial normals, small values (e.g. -r 0.2) pass only more tangential normals. |
||
|- valign="top" |
|- valign="top" |
||
⚫ | | -r <thresh> || Use this option to filter out vertices which have near radial normals. The threshold is the absolute value of the dot product of the vertex's position vector (relative to the centroid) with the normal vector, so it ranges from 0 to 1. Large values allow more radial normals, small values (e.g. -r 0.2) pass only more tangential normals. |
||
⚫ | |||
|- valign="top" |
|- valign="top" |
||
⚫ | |||
| -o outputfule || Specify an output prefix to use. Otherwise, the output defaults to aparc.a2009s.norm, or whatever parcellation is specified by -p. |
|||
|- valign="top" |
|||
| -o <filename> || Specify an output filename to use. This is a non-optional option. |
|||
|} |
|} |
||
==Output Files== |
|||
The output of FSnormals.py is a single text file. Each line of the file is a single vertex, and contains seven columns: vx, vy, vz, nx, ny, nz, annot. vx, vy, and vz are the coordinates in meters. nx, ny, and nz denote the normal vector for that vertex. The last number is the annotation or region number, positive for left hemisphere and negative for right. |
|||
==Example== |
|||
To use FSnormals.py to generate an Atlas file for use with [[sam_wts]], you must use the -g and -t options: |
|||
$ FSnormals.py -g "4 2" -t ortho+orig -o atlas -i 1 subjid |
|||
Assume the ortho+orig MRI has a voxel size of 1x1x1 mm and was created from an original anat+orig MRI. This will start with the smoothwm FreeSurfer surface for subject subjid, which should have been created from the anat+orig MRI, then rotate the surface into the ortho space, move all the vertices 1 mm up along the surface normal, and output a grid with a spacing of 4x4x4 mm, averaging all the normals within 2 mm of each gridpoint. Note that if there are no surface vertices within the specified radius from a grid point, that grid point will be ignored in the output. |
|||
The output atlas file should be placed in the MRIDirectory specified in the sam_wts parameter file, and named using the AtlasName parameter. |
Latest revision as of 08:51, 30 July 2019
Return to Source Localization - SAM
Description
The FSnormals.py program will take a FreeSurfer surface, and output a list of all the vertices and their surface normals. Crucially, given an image in ortho/MEG space, as produced by AFNI's 3dTagAlign or orthohull.py, FSnormals.py will rotate the surface normals to MEG space. This program is required for use before sam_coreg can be run. Python must be installed. In addition, you must set the FREESURFER_HOME directory and, optionally, the SUBJECTS_DIR. Note that the default SUBJECTS_DIR is $FREESURFER_HOME/subjects, which is probably not where your images are. In addition to producing the surface normals, FSnormals.py will also preserve the annotation from freesurfer which gives the cortical parcel that any given vertex belongs to.
Usage
FSnormals.py [-q] [-a annotation] ... [-t ortho+orig] [-i fac] [-p parcfile] [-g "step radius"] [-r thresh] [-L|-R|-B] -o outputfile subject [surface]
The subject argument corresponds to the FreeSurfer subject designation, and denotes a directory under $SUBJECTS_DIR. The surface argument denotes the surface to use: orig, pial, white, or smoothwm (default). Other options:
-q | Operate quietly, default is verbose |
-a <annotation> | Restrict the output to an annotation region, denoted by its number (see the corresponding ctab for a list of numbers and regions in the label/ directory of each subject's FreeSurfer directory). To select multiple regions, repeat this option. Note that in the output, positive numbers denote the left hemisphere, and negative numbers denote the right. The -L, -R, and -B options control which values (positive, negative, or both) appear in the output. |
-t ortho+orig | Rotate the output vertices and surface normals into the space defined by the ortho+orig space. In order to use this, ortho+orig must have been generated using the 3dTagAlign command (typically using orthohull). |
-i <fac> | Move each vertex along its normal vector according to v' = v + fac * n (fac in mm, may be negative). Note that this conversion is done before resampling to a grid (if -g is used). |
-g "<step> <radius>" | This option restricts the output vertices to the grid defined by the ortho+orig MRI (you must use -t in this case). The step argument is an integer specifying the number of MRI voxels between output grid points. At each grid point, all the normal vectors within a ball of the given radius (mm) are averaged together to form the output normal. For example -g "3 1.5" means one grid point every 3 MRI voxels, and an averaging ball with a 3 mm (2 x 1.5) diameter. |
-r <thresh> | Use this option to filter out vertices which have near radial normals. The threshold is the absolute value of the dot product of the vertex's position vector (relative to the centroid) with the normal vector, so it ranges from 0 to 1. Large values allow more radial normals, small values (e.g. -r 0.2) pass only more tangential normals. |
-L, -R, -B | -L or -R means just output the left or right hemisphere, respectively. The default is -B, which will output both. Note that a positive annotation value (See -a above) will still specify a right hemisphere region, if -R or -B is used. |
-o <filename> | Specify an output filename to use. This is a non-optional option. |
Output Files
The output of FSnormals.py is a single text file. Each line of the file is a single vertex, and contains seven columns: vx, vy, vz, nx, ny, nz, annot. vx, vy, and vz are the coordinates in meters. nx, ny, and nz denote the normal vector for that vertex. The last number is the annotation or region number, positive for left hemisphere and negative for right.
Example
To use FSnormals.py to generate an Atlas file for use with sam_wts, you must use the -g and -t options:
$ FSnormals.py -g "4 2" -t ortho+orig -o atlas -i 1 subjid
Assume the ortho+orig MRI has a voxel size of 1x1x1 mm and was created from an original anat+orig MRI. This will start with the smoothwm FreeSurfer surface for subject subjid, which should have been created from the anat+orig MRI, then rotate the surface into the ortho space, move all the vertices 1 mm up along the surface normal, and output a grid with a spacing of 4x4x4 mm, averaging all the normals within 2 mm of each gridpoint. Note that if there are no surface vertices within the specified radius from a grid point, that grid point will be ignored in the output.
The output atlas file should be placed in the MRIDirectory specified in the sam_wts parameter file, and named using the AtlasName parameter.