Learn R Programming

freesurferformats (version 1.1.0)

write.fs.transform: Write a transformation matrix to a file.

Description

Save an fs.transform instance in one of the supported transformation file formats.

A transformation stores its matrix together with the coordinate spaces it maps between, and the formats disagree about which spaces they can express. A transformation is only written if the format can represent it exactly, because a silent conversion would change the meaning of the matrix: FSL matrix files, for example, store voxel-to-voxel matrices, so a transformation in world coordinates must be converted first with transform2voxel. A format that cannot express the transformation at all is an error, not a warning.

Usage

write.fs.transform(tf, filepath, format = "auto")

Value

the fs.transform instance tf, invisibly.

Arguments

tf

an fs.transform instance, the transformation to write.

filepath

character string, the full path of the file to write.

format

character string, the file format, one of 'auto' (guess from the file extension), 'fslmat' (an FSL/FLIRT matrix file, i.e. a plain text 4x4 matrix as written by FSL's flirt -omat), 'lta' (write.fs.transform.lta), 'dat' (write.fs.transform.dat), 'xfm' (write.fs.transform.xfm) or 'itk' (write.fs.transform.itk).

See Also

Other header coordinate space: invert.fs.transform(), is.fs.transform(), mghheader.is.ras.valid(), mghheader.ras2vox(), mghheader.ras2vox.tkreg(), mghheader.scanner2tkreg(), mghheader.tkreg2scanner(), mghheader.vox2ras(), mghheader.vox2ras.tkreg(), print.fs.transform(), read.fs.transform(), read.fs.transform.dat(), read.fs.transform.fslmat(), read.fs.transform.itk(), read.fs.transform.lta(), read.fs.transform.xfm(), sm0to1(), sm1to0(), summary.fs.transform(), transform2lps(), transform2ras(), transform2voxel(), transform2world(), write.fs.transform.dat(), write.fs.transform.fslmat(), write.fs.transform.itk(), write.fs.transform.lta(), write.fs.transform.xfm()

Examples

Run this code
tf <- read.fs.transform(system.file("extdata", "talairach.lta",
  package = "freesurferformats", mustWork = TRUE
))
out_file <- tempfile(fileext = ".mat")
# An LTA of type 0 is a voxel-to-voxel transformation, so it can be written as an FSL matrix.
write.fs.transform(tf, out_file, format = "fslmat")
read.fs.transform(out_file)$matrix
unlink(out_file)

# The same transformation can be written in the FreeSurfer formats of the spaces it maps between.
out_file <- tempfile(fileext = ".lta")
write.fs.transform(tf, out_file)
unlink(out_file)

Run the code above in your browser using DataLab