fsl.data.freesurfer

This module provides the FreesurferMesh class, which can be used for loading Freesurfer geometry and vertex data files.

The following types of files generated by Freesurfer are recognised by this module:

  • Core geometry files, defining the cortical mesh. Each core geometry file has the same number of vertices and same triangle definitions.

  • Extra geometry files, defining the cortical mesh. Extra geometry files may have a different number of vertices and/or triangle definitions.

  • Vertex data files (a.k.a. 'curv' files), containing a scalar value for every vertex in the mesh. This data may also be contained in mgz/mgh files.

  • Label files, containing indices of a sub-set of vertices in the mesh.

  • Annotation files, containing a label value, and an RGBA colour for a subset of vertices in the mesh.

The following functions are also available:

loadVertexDataFile

Loads the given Freesurfer vertex data, label, or annotation file.

isCoreGeometryFile

Decorator which can be used to memoize a function or method. Use like so::.

isGeometryFile

Decorator which can be used to memoize a function or method. Use like so::.

isVertexDataFile

Decorator which can be used to memoize a function or method. Use like so::.

isVertexLabelFile

Decorator which can be used to memoize a function or method. Use like so::.

isVertexAnnotFile

Decorator which can be used to memoize a function or method. Use like so::.

relatedGeometryFiles

Returns a list of all files which (look like they) are freesurfer geometry files which correspond to the given geometry file.

relatedVertexDataFiles

Returns a list of all files which (look like they) are vertex data, label, or annotation files related to the given freesurfer geometry file.

findReferenceImage

Attempts to locate the volumetric reference image for (what is assumed to be) the given Freesurfer geometry file.

fsl.data.freesurfer.CORE_GEOMETRY_FILES = ['?h.orig', '?h.pial', '?h.white', '?h.inflated', '?h.sphere', '?h.pial_semi_inflated']

File patterns for identifying the core Freesurfer geometry files.

fsl.data.freesurfer.CORE_GEOMETRY_DESCRIPTIONS = ['Freesurfer surface (original)', 'Freesurfer surface (pial)', 'Freesurfer surface (white matter)', 'Freesurfer surface (inflated)', 'Freesurfer surface (sphere)', 'Freesurfer surface (pial semi-inflated)']

A description for each extension in GEOMETRY_EXTENSIONS.

fsl.data.freesurfer.EXTRA_GEOMETRY_FILES = ['?h.orig.nofix', '?h.smoothwm.nofix', '?h.inflated.nofix', '?h.qsphere.nofix', '?h.sphere.nofix', '?h.white.preaparc']

Other geometry files which may be present in Freesurfer output.

fsl.data.freesurfer.VERTEX_DATA_FILES = ['?h.thickness', '?h.curv', '?h.area', '?h.sulc']

File patterns which are interpreted as Freesurfer vertex data files, containing a scalar value for every vertex in the mesh.

fsl.data.freesurfer.VERTEX_MGH_FILES = ['?h.*.mgh', '?h.*.mgz']

File patterns which are interpreted as MGH files containing a scalar value for every vertex in the mesh.

fsl.data.freesurfer.VERTEX_LABEL_FILES = ['?h.*.label']

File patterns which are interpreted as Freesurfer vertex label files, containing a scalar value for a sub-set of vertices in the mesh.

fsl.data.freesurfer.VERTEX_ANNOT_FILES = ['?h.*.annot']

File patterns which are interpreted as Freesurfer vertex annotation files, containing a scalar value and an RGBA colour for a sub-set of vertices in the mesh.

class fsl.data.freesurfer.FreesurferMesh(*args, **kwargs)[source]

Bases: Mesh

The FreesurferMesh class represents a triangle mesh loaded from a Freesurfer geometry file.

__init__(filename, fixWinding=False, loadAll=False)[source]

Load the given Freesurfer surface file using nibabel.

Parameters:
  • infile – A Freesurfer geometry file (e.g. *.pial).

  • fixWinding – Passed through to the addVertices() method for the first vertex set.

  • loadAll – If True, the infile directory is scanned for other freesurfer surface files which are then loaded as additional vertex sets.

loadVertices(infile, key=None, **kwargs)[source]

Overrides Mesh.loadVertices(). If the given infile looks like a Freesurfer file, it is loaded via nibabel.freesurfer.load_geometry. Otherwise, it is passed to Mesh.loadVertices().

loadVertexData(infile, key=None)[source]

Overrides Mesh.loadVertexData(). If the given infile looks like a Freesurfer file, it is loaded via the loadVertexDataFile() function. Otherwise, it is passed through to the base-class function.

If the given infile is a vertex annotation file, it is assumed that the file contains a value for every vertex in the mesh.

getVertexDataColourTable(key)[source]

If the given key refers to a Freesurfer .annot file, the corresponding RGBA lookup table and label names can be retrieved via this method.

__annotations__ = {}
__module__ = 'fsl.data.freesurfer'
fsl.data.freesurfer.loadVertexDataFile(infile)[source]

Loads the given Freesurfer vertex data, label, or annotation file.

This function return different things depending on what infile is:

  • If infile is a vertex data file, a (nvertices,) array is returned, containing one value for each vertex in the mesh.

  • If infile is a mgh/mgz file, the image data is returned as-is, with dimensions of length 1 squeezed out (under the assumption that the image contains scalar vertex data).

  • If infile is a vertex label file, a tuple containing the following is returned:

    • a (n,) array, containing the indices of all vertices that are specified in the file.

    • a (n,) array, containing scalar value for each vertex

  • If infile is a vertex annotation file, a tuple containing the following is returned:

    • a (n,) array containing the indices of all n vertices that are specified in the file.

    • a (l, 5) array containing the RGBA colour, and the label value, for every label that is specified in the file.

    • A list of length l, containing the names of every label that is specified in the file.

fsl.data.freesurfer.relatedGeometryFiles(fname)[source]

Returns a list of all files which (look like they) are freesurfer geometry files which correspond to the given geometry file.

fsl.data.freesurfer.relatedVertexDataFiles(fname)[source]

Returns a list of all files which (look like they) are vertex data, label, or annotation files related to the given freesurfer geometry file.

fsl.data.freesurfer.findReferenceImage(fname)[source]

Attempts to locate the volumetric reference image for (what is assumed to be) the given Freesurfer geometry file.