morph: Morph several images into one

View source: R/morph.R

morphR Documentation

Morph several images into one

Description

Given a set of images, rotate them to the same orientation (with img_make_horizontal()), align them to their centroid (with img_center()), average them, and, optionally, adjust the grey levels of the resulting, morphed, image (see adjust_grey).

Usage

morph(
  x,
  adjust_grey = FALSE,
  threshold = 2/255,
  invert = TRUE,
  fun = NULL,
  ...
)

Arguments

x

list of images, of type imager::cimg(), or list/vector of file paths that are then read with img_read().

adjust_grey

whether to adjust the mean grey level of the morphed image to match that of the original images it was constructed with. Usually, computing the average (i.e. the morphing) results in lighter images; this compensates it a little. Note that it requires more intense computation and is therefore switched off by default.

threshold

grey level threshold used to separate the foreground object from the background for the adjustment of grey level. Ignored when adjust_grey is FALSE.

invert

passed to img_read() when x is a list/vector of file paths: whether to invert the images when reading them. If images are inverted upon being read, the morphed result is inverted back to be produced with the same aspect as the input files.

fun

function to apply to each image, as a pre-processing step (a typical one is img_chop() to remove a scale bar added to the image).

...

passed to fun.

Value

The morphed image, as a imager::cimg() object.

Examples

# get a list of images to morph
amph <- list.files(system.file("extdata", "amphipoda",
                   package="morphr"), full.names=TRUE)
# read and plot a couple
img_read(amph[1]) %>% img_show()
img_read(amph[3]) %>% img_show()
# now morph them all
morph(amph) %>% img_show()
morph(amph, adjust_grey=TRUE) %>% img_show()

cres <- list.files(system.file("extdata", "creseidae",
                   package="morphr"), full.names=TRUE)
img_read(cres[1]) %>% img_show()
img_read(cres[2]) %>% img_show()
morph(cres) %>% img_show()
morph(cres, adjust_grey=TRUE) %>% img_show()

jiho/morphr documentation built on May 11, 2024, 9:32 p.m.