findBgnd: Find Background Value by Otsu's method or a best guess

View source: R/findBgnd.R

findBgndR Documentation

Find Background Value by Otsu's method or a best guess

Description

Calculate a value between background and foreground pixels using an approximation of Otsu's method for a bimodal mixture of values or a unimodal normal distribution. This function assumes that the background value will lie to the right of the left-most population.

Usage

findBgnd(x, mult = 2.5, log = TRUE)

Arguments

x

Fluorescent values to evaluate.

mult

Numeric multiplier applied to the standard deviation, with default value of 2.5.

log

A logical flag to use log-transformed values.

Details

Data are assumed to be drawn from two unimodal, continuous distributions where the background population follows a normal distribution. The maximum of this population is determined from a kernel density estimate and the left half of the distribution is fit to a Gaussian distribution with the fitdistr function. The value returned is the position of the peak + mult times the estimated standard deviation of the distribution.

Because fluorescent values are typically log-transformed before analysis, the values are log-transformed by default before analysis. This can be turned off with the log parameter. Typically, the parameter mult must be empirically determined. Note that with mult = 0, the mean value of the background intensity will be returned.

If the distribution is heavily skewed to the left (mostly dark values), the standard deviation of the distribution will be estimated as 1.35x the interquartile range.

Value

The value estimated as position of the background peak + mult * standard deviation of the normal population.

See Also

getZero

getBgnd

Examples

  x <- c(rlnorm(200), rlnorm(120, 4))
  plot(density(log(x)))
  bg <- sapply(0:4, function(m) findBgnd(x, mult = m))
  abline(v = log(bg), col = 1:5) # background limit
  legend("topleft", legend = 0:4, title = "mult", lty = 1, col = 1:5)


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