write.fs.transform.itk: Write an ITK text transform file.

View source: R/write_fs_transform.R

write.fs.transform.itkR Documentation

Write an ITK text transform file.

Description

Write a transformation in the text file format of ITK, which the tools built on ITK read: 3D Slicer (which calls it the 'ITK Transform' format), ANTs (via ConvertTransformFile), SimpleITK, and the workflows that write their transformations with them. The file name extension is usually .tfm or .txt.

An ITK transform operates on the world coordinates of the images, which in ITK are left-posterior-superior, so only a transformation that maps LPS coordinates can be written. Use transform2lps to convert a transformation in RAS coordinates.

Usage

write.fs.transform.itk(tf, filepath)

Arguments

tf

an fs.transform instance whose matrix maps LPS coordinates to LPS coordinates.

filepath

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

Value

the fs.transform instance tf, invisibly.

Note

The file that is written uses the class 'AffineTransform_double_3_3', i.e. the parameters are stored in double precision, and it states a center of rotation of zero, with the center folded into the translation. This is exactly the form that FreeSurfer's lta_convert --outitk writes, and the form that lta_convert --initk can read: it rejects the 'float' variant of the classes and ignores a non-zero center of rotation, see the note in read.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(), write.fs.transform.dat(), write.fs.transform.fslmat(), write.fs.transform.lta(), write.fs.transform.xfm()

Examples

xfm_file <- system.file("extdata", "talairach.xfm", package = "freesurferformats", mustWork = TRUE)
out_file <- tempfile(fileext = ".tfm")
write.fs.transform.itk(transform2lps(read.fs.transform(xfm_file)), out_file)
readLines(out_file)
unlink(out_file)


freesurferformats documentation built on Sept. 25, 2026, 1:07 a.m.