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.
Arguments
- tf
an
fs.transforminstance, 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
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
#> [,1] [,2] [,3] [,4]
#> [1,] 1.054775715 0.007081697 -0.05151368 -2.029556
#> [2,] 0.005556736 1.116058946 0.33849043 -5.882306
#> [3,] 0.060359493 -0.274788439 0.85348159 37.464622
#> [4,] 0.000000000 0.000000000 0.00000000 1.000000
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)