
Manually apply rigid transformations to images
manual-transform-images.RdOpens 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, ...)
# Default S3 method
RunAlignment(
  object,
  container_width = "800px",
  container_height = "650px",
  launch_browser = TRUE,
  ...
)
# S3 method for class '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 
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
Other image transformations:
MaskImages(),
RigidTransformImages()
Other transforms:
CoordAndImageTransform(),
CoordMirror(),
CoordTransform(),
ImageTranslate(),
RigidTransformImages()
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) { # \dontrun{
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/z8/nrcst881607gn95xh3_4qvb00000gp/T/RtmpAdeL2K/temp_libpath109e41827971/semla/extdata/mousebrain/spatial/tissue_lowres_image.jpg
#> ℹ Scaled image from 600x565 to 400x377 pixels
#> ℹ Loading image from /private/var/folders/z8/nrcst881607gn95xh3_4qvb00000gp/T/RtmpAdeL2K/temp_libpath109e41827971/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) { # \dontrun{
if (interactive()) {
  se_merged <- RunAlignment(se_merged)
}
} # }