write.fs.label: Write vertex indices to file in FreeSurfer label format

Description Usage Arguments Value See Also Examples

View source: R/write_fs_label.R

Description

Write vertex coordinates and vertex indices defining faces to a file in FreeSurfer binary surface format. For a subject (MRI image pre-processed with FreeSurfer) named 'bert', an example file would be 'bert/label/lh.cortex'.

Usage

1
2
3
4
5
6
7
write.fs.label(
  filepath,
  vertex_indices,
  vertex_coords = NULL,
  vertex_data = NULL,
  indices_are_one_based = TRUE
)

Arguments

filepath

string. Full path to the output label file. If it ends with ".gz", the file is written in gzipped format. Note that this is not common, and that other software may not handle this transparently.

vertex_indices

instance of class 'fs.label' or an integer vector, the label. The vertex indices included in the label. As returned by read.fs.label.

vertex_coords

an *n* x 3 float matrix of vertex coordinates, where *n* is the number of 'vertex_indices'. Optional, defaults to NULL, which will write placeholder data. The vertex coordinates are not used by any software I know (you should get them from the surface file). Will be used from 'fs.label' instance if given.

vertex_data

a numerical vector of length *n*, where *n* is the number of 'vertex_indices'. Optional, defaults to NULL, which will write placeholder data. The vertex data are not used by any software I know (you should get them from a morphometry file). Will be used from 'fs.label' instance if given.

indices_are_one_based

logical, whether the given indices are one-based, as is standard in R. Indices are stored zero-based in label files, so if this is TRUE, all indices will be incremented by one before writing them to the file. Defaults to TRUE. If FALSE, it is assumed that they are zero-based and they are written to the file as-is. Will be used from 'fs.label' instance if given.

Value

dataframe, the dataframe that was written to the file (after the header lines).

See Also

Other label functions: read.fs.label.gii(), read.fs.label.native(), read.fs.label()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
    # Write a simple label containing only vertex indices:
    label_vertices = c(1,2,3,4,5,1000,2000,2323,34,34545,42);
    write.fs.label(tempfile(fileext=".label"), label_vertices);

    # Load a full label, write it back to a file:
    labelfile = system.file("extdata", "lh.entorhinal_exvivo.label",
     package = "freesurferformats", mustWork = TRUE);
    label = read.fs.label(labelfile, full=TRUE);
    write.fs.label(tempfile(fileext=".label"), label);

## End(Not run)

freesurferformats documentation built on Feb. 11, 2022, 5:06 p.m.