Detrend Images

Detrend fluorescence microscopy image series for fluorescence fluctuation and correlation spectroscopy ('FCS' and 'FFS') analysis. This package contains functionality published in a 2016 paper but it has been extended since then with the Robin Hood algorithm and thus contains unpublished work.

Detrend image series.

Travis-CI Build Status AppVeyor Build Status CRAN_Status_Badge RStudio CRAN downloads Project Status: Active – The project has reached a stable, usable state and is being actively developed.


To install the release version (recommended) from CRAN, in R, enter


To install the development version, in R, first install devtools via install.packages("devtools"). Then enter



First let's load the library:


Image I/O and display

The package contains a sample image series which can be found at system.file("extdata", "cells.tif", package = "detrendr"). Let's read it in and inspect the first and last frames:

path <- system.file("extdata", "bleached.tif", package = "detrendr")
img <- ijtiff::read_tif(path)
dim(img)  # img has 500 frames
mean(img[, , 1, 1])  # first channel, first frame
#> [1] 152.4489
mean(img[, , 1, 500])  # first channel, last frame
#> [1] 68.51583


We see that the intensity is much lower for the last frame, this is because the image series has been bleached. We can correct for this (and check how long it takes):

system.time(corrected <- img_detrend_exp(img, "auto", 
                                         seed = 0, parallel = 2))["elapsed"]
#> elapsed 
#>   7.589
mean(corrected[, , 1, 1])  # first channel, first frame
#> [1] 112.9569
mean(corrected[, , 1, 500])  # first channel, last frame
#> [1] 103.33

So we see that the corrected series does not have this drop-off in intensity.


For more detailed instruction on how to use the package, see vignette("detrendr").


Contributions to this package are welcome. The preferred method of contribution is through a github pull request. Feel free to contact me by creating an issue. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.


detrendr 0.6.1


  • Require necessary version of glue.
  • Temporary fix for upcoming R 3.6 which patches base::sample(). A more permanent fix should be provided when R 3.6 has landed.

detrendr 0.6.0


  • A pkgdown website!


  • Robin Hood parameter finding is now repeated several (at least 9) times to find a sensible consensus value.
  • Robin Hood parameter finding includes an adjustment step to avoid over-estimating the number of swaps required.

detrendr 0.5.2


  • Detrending was not working well for images which had dimension 1 in x or y.

detrendr 0.5.1


  • Fix tests for CRAN fedora and mac.

detrendr 0.5.0


  • The package no longer depends on RSAGA, making it lighter.
  • Robin Hood detrending has been added.

detrendr 0.4.0


  • Add the option to detrend for the purpose of FCS or FFS.

detrendr 0.3.0


  • Batch processing: detrend an entire folder with the likes of dir_detrend_exp().


  • Asymmetric images caused R to crash.
  • NAs in simulated brightnesses were needlessly causing the automatic parameter-finding routines to fail.

detrendr 0.2.0


  • The process of extending time series prior to smoothing is not done any more. This was introducing errors for images with low counts. Smoothing works fine without it. Dropping this extension gives a massive improvement in detrending speed :-)
  • TIFF I/O and image display are now taken care of by the ijtiff package.
  • Images are now represented in the style of an ijtiff::ijtiff_img.


  • This package no longer exports functions for TIFF I/O nor image display.

detrendr detrendr 0.1.0

  • The first CRAN-worthy version.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.6.14 by Rory Nolan, 8 months ago,

Report a bug at

Browse source code at

Authors: Rory Nolan [aut, cre] , Luis Alvarez [ctb, cph] , Sergi Padilla-Parra [ctb, ths, cph]

Documentation:   PDF Manual  

BSD_3_clause + file LICENSE license

Imports arrayhelpers, autothresholdr, checkmate, doParallel, dplyr, filesstrings, foreach, ijtiff, iterators, magrittr, parallel, plyr, purrr, Rcpp, RcppParallel, rlang, stringr, tools, withr

Suggests abind, covr, ggplot2, glue, graphics, gridExtra, knitr, lattice, MASS, matrixStats, mgcv, pacman, R.utils, rmarkdown, spelling, testthat, tidyr

Linking to Rcpp, RcppParallel

System requirements: GNU make

Imported by nandb.

See at CRAN