Skip to content

Commit

Permalink
Added Morpho tps registration for BANC->JRC2018F and BANC-mirror
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbates committed Jul 10, 2024
1 parent b760c66 commit a542a89
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 12 deletions.
106 changes: 105 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,108 @@
# banc.mesh <- malevnc:::decode_neuroglancer_mesh(bytes)
# banc.surf <- as.hxsurf(banc.mesh)
# banc.surf$Vertices[,"Z"] <- banc.surf$Vertices[,"Z"]*0.9462 # scaling Jasper worked out
# save(banc.surf, file="data/BANC.surf.rda")
# usethis::use_data(banc.surf, overwrite = TRUE)

#' Thin-Plate Spline Registration from BANC to JRC2018F templatebrain
#'
#' @description
#' A thin-plate spline (TPS) registration object that transforms 3D points
#' from the BANC nanometer coordinate system
#' to the D. melanogaster template brain JRC2018F coordinate system.
#'
#' @format An object of class \code{tpsCoeff} created using \code{Morpho::computeTransform}.
#' It contains the following components:
#' \describe{
#' \item{Lw}{Matrix of TPS coefficients}
#' \item{refmat}{Reference matrix (source landmarks)}
#' \item{tarmat}{Target matrix (target landmarks)}
#' \item{lattice}{3D array representing the deformation grid}
#' \item{lambda}{Smoothing parameter used in the TPS computation}
#' \item{scale}{Logical indicating whether scaling was used}
#' \item{reflection}{Logical indicating whether reflection was allowed}
#' }
#'
#' @details
#' This TPS registration was computed based on landmark correspondences
#' derived from an Elastix registration between the BANC and JRC2018F spaces.
#' It provides a smooth, interpolated transformation for any point in the BANC space
#' to its corresponding location in the JRC2018F space.
#'
#' @usage data(banc_to_jrc2018f_tpsreg)
#'
#' @source
#' Derived from Elastix registration results using the \code{banc_to_JRC2018F}
#' function and landmark correspondences extracted from that registration.
#'
#' @examples
#' \dontrun{
#' data(banc_to_jrc2018f_tpsreg)
#'
#' # Transform BANC points to JRC2018F using the TPS registration
#' banc_points <- matrix(rnorm(300), ncol=3) # Example BANC points
#' jrc2018f_points <- Morpho::tps3d(banc_points, banc_to_jrc2018f_tpsreg)
#' }
#'
#' @seealso
#' \code{\link{banc_to_JRC2018F}} for the function that performs transformations
#' between BANC and JRC2018F spaces.
#' \code{\link[Morpho]{computeTransform}} for details on creating tpsCoeff objects.
#'
#' @name banc_to_jrc2018f_tpsreg
#' @docType data
"banc_to_jrc2018f_tpsreg"

#' Thin-Plate Spline Registration for Mirroring in BANC Space
#'
#' @description
#' A thin-plate spline (TPS) registration object that mirrors 3D points
#' within the BANC (Buhmann et al. Adult Neural Connectome) coordinate system.
#'
#' @format An object of class \code{tpsCoeff} created using \code{Morpho::computeTransform}.
#' It contains the following components:
#' \describe{
#' \item{Lw}{Matrix of TPS coefficients}
#' \item{refmat}{Reference matrix (source landmarks)}
#' \item{tarmat}{Target matrix (mirrored landmarks)}
#' \item{lattice}{3D array representing the deformation grid}
#' \item{lambda}{Smoothing parameter used in the TPS computation}
#' \item{scale}{Logical indicating whether scaling was used}
#' \item{reflection}{Logical indicating whether reflection was allowed}
#' }
#'
#' @details
#' This TPS registration was computed to allow mirroring of points directly within
#' the BANC coordinate system. It provides a smooth, interpolated transformation
#' for any point in the BANC space to its mirrored counterpart, accounting for
#' any asymmetries in the BANC reference brain.
#'
#' @usage data(banc_mirror_tpsreg)
#'
#' @source
#' Derived from landmark correspondences between original and mirrored points
#' in the BANC space, possibly utilizing transformations to and from the
#' JRC2018F space for accurate mirroring.
#'
#' @examples
#' \dontrun{
#' data(banc_mirror_tpsreg)
#'
#' # Mirror BANC points using the TPS registration
#' banc_points <- matrix(rnorm(300), ncol=3) # Example BANC points
#' mirrored_points <- Morpho::tps3d(banc_points, banc_mirror_tpsreg)
#' }
#'
#' @seealso
#' \code{\link{banc_mirror}} for the function that performs mirroring
#' of points in BANC space.
#' \code{\link{banc_to_jrc2018f_tpsreg}} for the TPS registration between
#' BANC and JRC2018F spaces.
#' \code{\link[Morpho]{computeTransform}} for details on creating tpsCoeff objects.
#'
#' @name banc_mirror_tpsreg
#' @docType data
"banc_mirror_tpsreg"




4 changes: 2 additions & 2 deletions R/xform.R
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,15 @@ banc_mirror <- function(x,
x.jrc2018f <- banc_to_JRC2018F(x=x, units="um", subset=NULL, inverse=FALSE, transform_file = transform_files[1], method = method)

# Mirror
x.jrc2018f.m <- nat.templatebrains::mirror_brain(x.jrc2018f, brain = "JRC2018F", ... )
x.jrc2018f.m <- nat.templatebrains::mirror_brain(x.jrc2018f, brain = nat.flybrains::JRC2018F, transform = "flip")

# Back to BANC
x.banc.m <- banc_to_JRC2018F(x=x, units="um", subset=NULL, inverse=TRUE , transform_file = transform_files[2], method = method)

}else{

# Use pre-calculated tps reg
x.banc.m <- nat::xform(xyzf, reg = banc_miror_tpsreg)
x.banc.m <- nat::xform(xyzf, reg = banc_mirror_tpsreg)

}

Expand Down
Binary file added data/banc_mirror_tpsreg.rda
Binary file not shown.
Binary file added data/banc_to_jrc2018f_tpsreg.rda
Binary file not shown.
14 changes: 7 additions & 7 deletions man/banc_decapitate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/banc_mirror.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions man/banc_mirror_tpsreg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/banc_to_JRC2018F.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions man/banc_to_jrc2018f_tpsreg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a542a89

Please sign in to comment.