Skip to content

Commit

Permalink
Handle FSL/FLIRT quirk where images whose xforms have positive determ…
Browse files Browse the repository at this point in the history
…inant are flipped before transformation
  • Loading branch information
jonclayden committed Sep 27, 2024
1 parent ca84a06 commit 77bca4d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions R/affine.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,20 @@ convertAffine <- function (affine, source = NULL, target = NULL, newType = c("ni
sourceScaling <- diag(c(sqrt(colSums(sourceXform[1:3,1:3]^2)), 1))
targetScaling <- diag(c(sqrt(colSums(targetXform[1:3,1:3]^2)), 1))

# Handle FSL/FLIRT quirk where images whose xforms have positive determinant are flipped before transformation
if (det(sourceXform[1:3,1:3]) > 0)
{
orient <- unlist(strsplit(orientation(sourceXform), ""))
orient[1] <- switch(orient[1], R="L", L="R", A="P", P="A", S="I", I="S")
orientation(sourceXform) <- paste(orient, collapse="")
}
if (det(targetXform[1:3,1:3]) > 0)
{
orient <- unlist(strsplit(orientation(targetXform), ""))
orient[1] <- switch(orient[1], R="L", L="R", A="P", P="A", S="I", I="S")
orientation(targetXform) <- paste(orient, collapse="")
}

# NiftyReg transforms convert world coordinates from target to source space
# FSL transforms convert pseudo-world coordinates (scaled only) from source to target space
if (newType == "fsl")
Expand Down

0 comments on commit 77bca4d

Please sign in to comment.