trimMask: Remove Objects by Size, Proximity to Edge and Eccentricity

View source: R/trimMask.R

trimMaskR Documentation

Remove Objects by Size, Proximity to Edge and Eccentricity

Description

Remove large and small objects from an integer Image mask, remove objects that are near the edge of the image, and remove eccentric objects.

Usage

trimMask(
  mask,
  cutoff = FALSE,
  k = c(1.5, 3),
  border = 0,
  brush = 0,
  ecc.max = 1,
  reenumerate = TRUE
)

Arguments

mask

Object mask or list of masks with connected pixels having the same integer value.

cutoff

Optional integer value of length 1 or 2 specifying the limits for the area in pixels. If only one value is provided, it is assumed to be the lower limit. A value of FALSE or NA prevents size exclusion from occurring. A value of NULL makes use of the multiplier parameter k to determine the cutoff limits. Either of the two values in cutoff can be specified as NA to use the multiplier parameter for that position.

k

Numeric value of length 2 specifying the lower and upper multiplier to determine the cutoff from the median and mad of the area if cutoff is NULL.

border

Objects within this many pixels of the edge will be excluded.

brush

After coercion to the nearest odd integer, values > 0 dilate the mask whereas values < 0 erode the mask.

ecc.max

Exclude objects with elliptical eccentricity greater than this value.

reenumerate

Logical value (default of TRUE) passed to rmObjects() to re-enumerate the objects after trimming.

Details

For each non-NA value in cutoff, objects smaller than cutoff[1] and larger than cutoff[2] will be removed. Otherwise, objects smaller than median(area) - k[1]*mad(area) and larger than median(area)+ k[2]*mad(area) will be removed. Objects that are within border pixels of the edge will be removed. Objects that have eccentricity greater than ecc.max will be removed. A circle has eccentricity of 0 and a straight line has eccentricity of 1. Note that EBImage provides a poor approximation of this value. The final mask will be dilated or eroded if brush is non-zero using a disc-shaped brush with size determined by the adjusted value of brush.

Value

Object mask or list of masks with objects removed and re-enumerated.

Examples


  x <- readImage(system.file("extdata", "by_folder/a1/file001.tif", package = "virustiter"))
  xm <- nucMask(x)
  xm2 <- trimMask(xm, cutoff = c(200, 400))
  xm3 <- trimMask(xm, border = 24)
  xm4 <- trimMask(xm, ecc.max = 0.75)
  plot(colorLabels(combine(xm, xm2, xm3, xm4)), all = TRUE)
  sapply(list(xm, xm2, xm3, xm4), max) # how many remain?


ornelles/virustiter documentation built on March 15, 2024, 9:28 a.m.