Create transform between coordinate orientations
Source:R/as_ieegio_transform.R
transform_orientation.RdGenerates an affine transformation to convert coordinates or coordinate
frames between different anatomical orientation conventions (e.g., RAS to LPS).
Supports all 48 possible 3D orientations including axis permutations, plus
FSL scaled-voxel coordinates (which require an image for conversion).
Usage
transform_orientation(
space_from,
orientation_from,
orientation_to,
interpretation = c("active", "passive"),
image = NULL
)Arguments
- space_from
either an
ieegio_spaceobject or a character string identifying the source space. If provided,orientation_frommust be omitted (orientation is extracted from the space object).- orientation_from
character string specifying the source orientation (e.g.,
"RAS","LPS","FSL"). Only used ifspace_fromis missing. Must be one of the 48 valid orientation codes plus"FSL".- orientation_to
character string specifying the target orientation. Must be one of the 48 valid orientation codes plus
"FSL".- interpretation
character string specifying transform interpretation:
"active"(default): Point transform - transforms point coordinates from one orientation to another. Use this when you have coordinates in the source orientation and want to convert them."passive": Axis transform - transforms the coordinate frame/basis vectors. This is the transpose of the active transform. Use this when transforming reference frames or basis vectors.
- image
optional image for FSL coordinate conversion. Required when either
orientation_fromororientation_tois"FSL"(but not both). Can be a file path or anieegio_volumeobject.
Details
The function creates orthogonal transformations (rotations and reflections) to convert between different anatomical coordinate conventions. For active transforms, the matrix can be directly applied to homogeneous point coordinates. For passive transforms, the matrix transforms coordinate axes/frames instead.
Common orientation codes (first 8):
RAS,LAS,LPS,RPS,LPI,RPI,LAI,RAI(standard axis order)
Extended orientations (40 more) include axis permutations like:
PIR,AIL,SAR, etc. (permuted axes)
FSL Coordinates:
When "FSL" orientation is involved, an image is required for conversion
because FSL coordinates are image-dependent (scaled voxels with possible X-flip).
Three scenarios are supported:
FSL -> FSL: Identity transform (no image needed)FSL -> RAS/other: Usesvox2ras %*% fsl2voxfrom imageRAS/other -> FSL: Usesvox2fsl %*% ras2voxfrom image
The relationship between active and passive interpretations:
passive_matrix = t(active_matrix) for orthogonal transforms.
Examples
# Active transform: convert point coordinates from RAS to LPS
trans <- transform_orientation(orientation_from = "RAS",
orientation_to = "LPS",
interpretation = "active")
trans$data[[1]] # diag(-1, -1, 1, 1)
#> [,1] [,2] [,3] [,4]
#> [1,] -1 0 0 0
#> [2,] 0 -1 0 0
#> [3,] 0 0 1 0
#> [4,] 0 0 0 1
# Apply to a point
point_ras <- c(10, 20, 30, 1)
point_lps <- trans$data[[1]] %*% point_ras
# Using a space object
space <- new_space("scanner", orientation = "RAS")
trans <- transform_orientation(space_from = space,
orientation_to = "LPS")
# Passive transform: transform coordinate axes
trans_passive <- transform_orientation(orientation_from = "RAS",
orientation_to = "LPS",
interpretation = "passive")
# With axis permutation
trans <- transform_orientation(orientation_from = "RAS",
orientation_to = "PIR")
if (FALSE) { # \dontrun{
# FSL to RAS conversion (requires image)
trans_fsl2ras <- transform_orientation(orientation_from = "FSL",
orientation_to = "RAS",
image = "brain.nii.gz")
} # }