getShift: Determine Optimal Image Shift

View source: R/getShift.R

getShiftR Documentation

Determine Optimal Image Shift

Description

Determine the optimal x-y shift to align the target image with the (nuclear) mask.

Usage

getShift(mask, target, parscale = c(25, 25), FUN = idiff, value = FALSE)

Arguments

mask

An object mask with connected pixels having the same integer value.

target

A fluorescent Image object corresponding to the nuclear masks in mask.

parscale

A numeric vector of length 2 used as the parscale parameter for the optim function. See optim for more details.

FUN

Function to be minimized over x[1] and x[2] by optim. See the details for more information.

value

Logical value (default FALSE) to return the magnitude of the determined shift (sqrt(dx^2 + dy^2)).

Details

This optimization function FUN accepts three arguments (x, mask, target) where x is a numeric vector of length two representing the x and y position in the integer Image mask (mask) and the Image object (target). FUN must return a single value representing the difference between the two images. The optim function minimizes FUN with respect to x[1] and x[2]. The default function is designed to align nuclear masks with predominantly nuclear signals and should be replaced for other localization patterns.

The argument parscale is used by optim to scale the parameters in x such that a unit change in the parameter amounts to unit change in the optimizing function empirically, c(25, 25) seems to be in the middle of a robust range.

Value

If value = FALSE, a list of subpixel translations named "dx" and "dy" that can be applied to the argument target with translate to maximize the alignment between mask and target.

If value = TRUE, a list of values of the shift required for each image.

Examples

 path <- system.file("extdata", "by_folder/b2", package = "virustiter")
 x <- getImages(path)
 getShift(nucMask(x$nuc[[1]]), x$tgt[[1]], value = TRUE)
 getShift(nucMask(x$nuc[[1]]), x$tgt[[1]])


ornelles/virustiter documentation built on March 29, 2024, 8:30 p.m.