Aligns an image with the reference image. See details for more information about the process.

alignImage(object, ...)

# S4 method for class 'SPATA2'
alignImage(
  object,
  img_name,
  opt = "set",
  angle = NULL,
  flip_h = NULL,
  flip_v = NULL,
  stretch_h = NULL,
  stretch_v = NULL,
  transl_h = NULL,
  transl_v = NULL
)

# S4 method for class 'SpatialData'
alignImage(
  object,
  img_name,
  opt = "set",
  angle = NULL,
  flip_h = NULL,
  flip_v = NULL,
  stretch_h = NULL,
  stretch_v = NULL,
  transl_h = NULL,
  transl_v = NULL
)

# S4 method for class 'HistoImage'
alignImage(
  object,
  opt = "set",
  angle = NULL,
  flip_h = NULL,
  flip_v = NULL,
  stretch_h = NULL,
  stretch_v = NULL,
  transl_h = NULL,
  transl_v = NULL
)

alignImageAuto(object, ...)

# S4 method for class 'SpatialData'
alignImageAuto(
  object,
  img_name,
  step = 0.01,
  stop_at = 25,
  plot_progress = TRUE,
  verbose = TRUE
)

alignImageInteractive(object, ...)

# S4 method for class 'SPATA2'
alignImageInteractive(object)

# S4 method for class 'SpatialData'
alignImageInteractive(object, window_size = "800px")

Arguments

object

An object of class SPATA2 or, in case of S4 generics, objects of classes for which a method has been defined.

...

Used to absorb deprecated arguments or functions.

img_name

Character value. The name of the image of interest. If NULL, the active image is chosen by default. Either way, must be one of getImageNames().

opt

Character value. Either 'add' or 'set'. Decides whether the input adjustments are added to the existing ones or set (replacing them).

angle

Numeric value ranging between 0-359. Determines if/how much the image is supposed to be rotated. Always rotates in clockwise direction.

flip_h, flip_v

Logical values. Determine if the image is supposed to be flipped around the horizontal or vertical axis.

stretch_h, stretch_v

Numeric values. Determine if and how the image is supposed to be stretched along the horizontal or vertical axis.

transl_h, transl_v

Numeric values. Determine if and how the image is supposed to be translated along the hhorizontal or vertical axis.

step

Numeric value specifying the accuracy of the alignment via vertical and horizontal translation. If step >= 1, it is interpreted as a pixel value. For example, step = 2 translates the image 2 pixels to the right, then 4 pixels to the right, and so on. If step < 1, the final step value is calculated as round(side.length * step, digits = 0) where side.length is equal to the height and width of the reference image. See details for more.

verbose

Logical. If TRUE, informative messages regarding the computational progress will be printed.

(Warning messages will always be printed.)

stop_after

Numeric value specifying the maximum number of consecutive iterations during optimization of the image translation without improvement. If stop_at >= 1, it is interpreted as an absolute number of attempts. For instance, setting stop_after = 25 makes the function stop after 25 iterations without any improvement. If stop_at < 1, the maximum number of consecutive iterations without any improvement allowed is calculated by the total number of translations possible times stop_at. See details for more.

Value

The updated input object, containing the added, removed or computed results.

Details

The transformations required to align image X with the reference image are stored as instructions in the HistoImage container of the respective image. More precisely, in slot @transformations. The image itself remains as is after being loaded. The transformations are applied upon extraction of the image. Use getImageTransformations() to otbain the instructions currently stored.

Examples


library(SPATA2)
library(tidyverse)

data("example_data")

object <- example_data$object_UKF275T_diet


# ----- prepare
library(SPATA2)
library(EBImage)
library(tidyverse)

data("example_data")

object <- example_data$object_UKF275T_diet

img_bad <-
  getImage(object) %>%
  translate(v = c(25, 20), bg.col = "green")

#----- opt = "set" (the default)
object <- registerImage(object, img = img_bad, img_name = "bad", overwrite = T)
object <- activateImage(object, img_name = "bad")

plotSurface(object, pt_clr = "red", display_image = T)

object <- alignImage(object, img_name = "bad", opt = "set", transl_h = -25, transl_v = -20)

plotSurface(object, pt_clr = "red", display_image = T)

#----- opt = "add"
object <- registerImage(object, img = img_bad, img_name = "bad", overwrite = T)
object <- activateImage(object, img_name = "bad")

plotSurface(object, pt_clr = "red", display_image = T)

object <- alignImage(object, img_name = "bad", opt = "add", transl_h = -15, transl_v = -10)

plotSurface(object, pt_clr = "red", display_image = T)

object <- alignImage(object, img_name = "bad", opt = "add", transl_h = -10, transl_v = -10)

plotSurface(object, pt_clr = "red", display_image = T)

# ----- interactive

if(FALSE){ # diffused, run separately

  object <- alignImageInteractive(object)

}