Convert a transformation to the world (RAS) coordinate space.
Source:R/transforms_convert.R
transform2world.RdTransformation files often store their matrix in voxel coordinates, which means that the matrix alone cannot be used to transform world coordinates (e.g. the coordinates of a brain surface vertex, or a peak coordinate from another study): the geometry of the volumes the matrix relates is required as well. This function converts such a transformation into one that operates on world coordinates.
The result depends on the format the transformation was read from, because the formats disagree about their world space, which is why this is not a pure matrix operation:
For an FSL matrix ('fslmat'), the world space is the one FSL uses: unit voxel axes with a flipped first axis, see
fsl.scaled.voxel.matrix. Both MRtrix3 and FreeSurfer implement exactly this, and the result is a transformation between FSL world coordinates. Thesrcanddstentries of the result have the frame 'fsl'.For an LTA of type 0 (VOX2VOX), the world space is the RAS space of the two volume geometries: the result is
vox2ras_dst \%*\% matrix \%*\% solve(vox2ras_src). The descriptors have the frame 'scanner'.
Arguments
- tf
an
fs.transforminstance with a matrix in voxel coordinates (space_inandspace_outare 'voxel'). A transformation that already operates on world coordinates is returned unchanged.- src
NULLor the volume the transformation maps from (the-inimage of FSL, thesrcvolume of an LTA). Required for FSL matrices, since their files do not record the volumes.- dst
NULLor the volume the transformation maps to (the-refimage of FSL, thedstvolume of an LTA). Required for FSL matrices.
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(),
write.fs.transform(),
write.fs.transform.dat(),
write.fs.transform.fslmat(),
write.fs.transform.itk(),
write.fs.transform.lta(),
write.fs.transform.xfm()
Examples
# Read an LTA file, which records both volumes it relates, and convert it to world coordinates.
lta_file <- system.file("extdata", "talairach.lta", package = "freesurferformats", mustWork = TRUE)
tf <- read.fs.transform(lta_file)
tf_world <- transform2world(tf)
tf_world$space_in
#> [1] "ras"
tf_world$matrix
#> [,1] [,2] [,3] [,4]
#> [1,] 1.054775715 0.05151368 0.007081697 0.06612823
#> [2,] -0.060359493 0.85348159 0.274788439 -20.39745541
#> [3,] 0.005556736 -0.33849043 1.116058946 11.51445715
#> [4,] 0.000000000 0.00000000 0.000000000 1.00000000