Write a transformation in the FreeSurfer tkregister format (register.dat), the format that
mri_vol2vol --reg, tkregister2 and bbregister use. Such a matrix maps the voxel coordinates of the
movable volume (the source) to RAS coordinates in the tkregister frame of the target volume, see
mghheader.vox2ras.tkreg, so a transformation can only be written if this is what it maps.
Arguments
- tf
an
fs.transforminstance whose matrix maps voxel coordinates to RAS coordinates.- filepath
character string, the full path of the file to write.
- subject
NULLor character string, the subject identifier to store in the first line of the file. This is metadata for the tools that read the file and does not influence the transformation. IfNULLandtfhas asubjectfield (as read byread.fs.transform.dat), that value is used.- in_plane_resolution
NULLor numerical vector of length 2, the in-plane and between-plane resolution of the movable volume in millimeters, stored in the second and third line of the file. These are metadata that describe the acquisition and do not influence the transformation. IfNULLandtfhas the corresponding fields, they are used, otherwise they are derived from the geometry of the source volume, and set to 1 if that is not available either.
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(),
write.fs.transform.fslmat(),
write.fs.transform.itk(),
write.fs.transform.lta(),
write.fs.transform.xfm()
Examples
dat_file <- system.file("extdata", "register.dat", package = "freesurferformats", mustWork = TRUE)
tf <- read.fs.transform(dat_file)
out_file <- tempfile(fileext = ".dat")
write.fs.transform.dat(tf, out_file)
max(abs(read.fs.transform(out_file)$matrix - tf$matrix)) # 0
#> [1] 0
unlink(out_file)