Skip to contents

Opens a small Shiny app with the source and the target cells rasterized side by side. Click a recognizable point on the source, then the same point on the target, and repeat. From three pairs on, the app fits the affine map from the source to the target (least squares, see affine_from_landmarks()) and shows the source moved by it over the target, so you can see whether it is good enough as a starting point for lddmm(), which has no affine pre-fit of its own. Add pairs where the overlay is still off. "Done" closes the app and returns the matrix.

Usage

landmark_affine(source, target, dx = NULL, blur = 1.5, ...)

Arguments

source, target

The cells of the source and of the target: data frames with columns x and y (or matrices with two columns), in the same units.

dx

Pixel size of the displayed images, in the units of the coordinates. The default makes the largest extent about 250 pixels.

blur

Width of the Gaussian kernel of the images, in pixels (see rasterize()).

...

Passed to shiny::runApp(), for example launch.browser = FALSE or port = 4321.

Value

A 2 x 3 affine matrix [L | T] taking the (x, y) positions of the source to the target, NULL if you leave without one. Use it with apply_affine(). The matrix is also printed as R code, so that you can paste it into your script and not repeat the clicking.

Details

The images are made with rasterize() from the cells you give, with the pixel size and blur set in the app, only for display: the landmarks are in the coordinates of the cells.

The app is interactive and needs the 'shiny' package. Close the browser tab, or press "Cancel", to leave without a result (NULL is returned).

Examples

if (interactive()) {
  dir <- system.file("extdata", package = "RSTalign", mustWork = TRUE)
  read_cells <- function(pattern) {
    d <- read.csv(list.files(dir, pattern = pattern, full.names = TRUE))
    data.frame(x = d$center_x, y = d$center_y)
  }
  source_cells <- read_cells("S2R3[.]csv[.]gz$")
  target_cells <- read_cells("S2R2[.]csv[.]gz$")
  M0 <- landmark_affine(source_cells, target_cells)
  source_start <- apply_affine(source_cells, M0)
}