Free Access Week - Data Engineering + BI
Data Engineering and BI courses are free this week!
Free Access Week - Jun 2-8

detrendr (version 0.1.0)

detrending: Detrend images.

Description

Correct images for bleaching (or any other effect that introduces an unwanted trend) by detrending.

Usage

img_detrend_boxcar(img, l, seed = NULL, parallel = FALSE)

img_detrend_exp(img, tau, cutoff = 0.05, seed = NULL, parallel = FALSE)

img_detrend_polynom(img, degree, seed = NULL, parallel = FALSE)

Arguments

img

The image series to be detrended. This must be a 3-dimensional array of non-negative integers, with the matrix defined as img[, , 1] being the first frame of the image series.

l

The length parameter for boxcar detrending. The size of the sliding window will be 2 * l + 1. This must be a positive integer. Set this to "auto" to use Nolan's algorithm to automatically find a suitable value for this parameter (recommended).

seed

Random numbers may be generated during the detrending process. For reproducibility, you can set a seed for this random number generation here.

parallel

Would you like to use multiple cores to speed up this function? If so, set the number of cores here, or to use all available cores, use parallel = TRUE.

tau

The tau parameter for exponential filtering detrending. This must be a positive number. Set this to "auto" to use Nolan's algorithm to automatically find a suitable value for this parameter (recommended).

cutoff

In exponential filtering detrending, for the weighted average, every point gets a weight. This can slow down the computation massively. However, many of the weights will be approximately zero. With cutoff, we say that any point with weight less than or equal to cutoff times the maximum weight may be ignored; so with cutoff = 0.05, any weight less than 5% of the maximum weight may be ignored. The default value of this parameter is sensible and its value should not be set to anything else without good reason.

degree

The degree of the polynomial to use for the polynomial detrending. This must be a positive integer. Set this to "auto" to use Nolan's algorithm to automatically find a suitable value for this parameter (recommended).

Value

The detrended image, an object of class detrended_img.

Details

There are 3 detrending methods available: boxcar, exponential filtering and polynomial. These are described in detail in Nolan et al., 2017.

  • Exponential filtering detrending is a moving weighted average method where for parameter tau the weights are calculated as exp(t/tau) where t is the distance from the point of interest.

  • Polynomial detrending works by fitting a polynomial line to a series of points and then correcting the series to remove the trend detailed by this polynomial fit.

References

Rory Nolan, Luis A. J. Alvarez, Jonathan Elegheert, Maro Iliopoulou, G. Maria Jakobsdottir, Marina Rodriguez-Mu<U+00F1>oz, A. Radu Aricescu, Sergi Padilla-Parra; nandb<U+2014>number and brightness in R with a novel automatic detrending algorithm, Bioinformatics, https://doi.org/10.1093/bioinformatics/btx434.

Examples

Run this code
# NOT RUN {
## These examples are not run on CRAN because they take too long.
## You should still try them for yourself.
img <- read_tif(system.file('extdata', 'bleached.tif', package = 'detrendr'),
                n_ch = 1)
corrected <- img_detrend_boxcar(img, "auto", seed = 0, parallel = 2)
corrected10 <- img_detrend_boxcar(img, 10, seed = 0, parallel = 2)
corrected50 <- img_detrend_boxcar(img, 50, seed = 0, parallel = 2)
corrected100 <- img_detrend_boxcar(img, 100, seed = 0, parallel = 2)
corrected300 <- img_detrend_boxcar(img, 300, seed = 0, parallel = 2)
corrected <- img_detrend_exp(img, "auto", seed = 0, parallel = 2)
corrected10 <- img_detrend_exp(img, 10, seed = 0, parallel = 2)
corrected50 <- img_detrend_exp(img, 50, seed = 0, parallel = 2)
corrected100 <- img_detrend_exp(img, 100, seed = 0, parallel = 2)
corrected1000 <- img_detrend_exp(img, 1000, seed = 0, parallel = 2)
corrected <- img_detrend_polynom(img, "auto", seed = 0, parallel = 2)
corrected1 <- img_detrend_polynom(img, 1, seed = 0, parallel = 2)
corrected2 <- img_detrend_polynom(img, 2, seed = 0, parallel = 2)
corrected4 <- img_detrend_polynom(img, 4, seed = 0, parallel = 2)
corrected8 <- img_detrend_polynom(img, 8, seed = 0, parallel = 2)
# }

Run the code above in your browser using DataLab