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.
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)
#> [1] "#Insight Transform File V1.0"
#> [2] "#Transform 0"
#> [3] "Transform: AffineTransform_double_3_3"
#> [4] "Parameters: 1.1115360000000001 0.040947999999999998 -0.012534999999999999 -0.029729999999999999 0.98115399999999997 -0.342306 -0.022960999999999999 0.45258799999999999 1.1112219999999999 0.80355799999999999 19.558083 10.04454"
#> [5] "FixedParameters: 0 0 0"
unlink(out_file)