Skip to contents

Opens an interactive viewer where images are interactive objects that can be rotated, moved, scaled and mirrored. It is often difficult to automate image registration for H&E images, in particular if tissue sections are damaged, distorted or folded. In such situations, manual registration can be very useful.

Usage

RunAlignment(object, ...)

# S3 method for default
RunAlignment(
  object,
  container_width = "800px",
  container_height = "650px",
  launch_browser = TRUE,
  ...
)

# S3 method for Seurat
RunAlignment(
  object,
  image_height = 400,
  container_width = "800px",
  container_height = "650px",
  launch_browser = TRUE,
  verbose = TRUE,
  ...
)

Arguments

object

An object

...

Arguments passed to other methods

container_width, container_height

Width and height of paper widget given in pixels.

launch_browser

Should the app be opened in the default browser? Default is TRUE. Set launch_browser = getOption("shiny.launch.browser", interactive()) to use the RStudio built-in browser.

image_height

An integer used for rescaling images

verbose

Print messages

Value

An object with aligned images

default method

Takes a list of images prepared with the prep_image function and send them to the interactive application. When the application stops (after clicking "quit & save") a tibble is returned with information about the rigid transformations applied to the images.

Seurat method

Takes a Seurat object with at least 2 tissue sections and opens an interactive shiny application where rigid transformations can be applied to the images. When the application stops (after clicking "quit & save"), the transformations are applied to the images using RigidTransformImages and a Seurat object is returned. If no transformations are supplied, the function will return the input Seurat object unmodified.

See also

Author

Ludvig Larsson

Examples


library(semla)
library(magick)

im_mbrain <- system.file("extdata/mousebrain/spatial",
                         "tissue_lowres_image.jpg",
                         package = "semla")

img1 <- prep_image(im_mbrain |>
                     image_read(),
                   height = 256)
img2 <- prep_image(im_mbrain |>
                     image_read() |>
                     image_flip(),
                   height = 256)

# Align images and find transform
if (FALSE) {
if (interactive()) {
  transforms <- RunAlignment(object = list(img1, img2))
}
}


se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla"))
se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla"))
se_merged <- MergeSTData(se_mbrain, se_mcolon) |> 
  LoadImages()
#> 
#> ── Loading H&E images ──
#> 
#>  Loading image from /private/var/folders/91/twz8ld_x3f98sr9yc2hq9xpn47blx2/T/RtmpQDm3p7/temp_libpathed1b712617f8/semla/extdata/mousebrain/spatial/tissue_lowres_image.jpg
#>  Scaled image from 600x565 to 400x377 pixels
#>  Loading image from /private/var/folders/91/twz8ld_x3f98sr9yc2hq9xpn47blx2/T/RtmpQDm3p7/temp_libpathed1b712617f8/semla/extdata/mousecolon/spatial/tissue_lowres_image.jpg
#>  Scaled image from 541x600 to 400x444 pixels
#>  Saving loaded H&E images as 'rasters' in Seurat object

# Run alignment application on a Seurat object
if (FALSE) {
if (interactive()) {
  se_merged <- RunAlignment(se_merged)
}
}