Detrending images with detrendr

Rory Nolan

2018-04-24

Detrend image series.

First let’s load the library:

library(detrendr)

An image in need of detrending

The package contains a sample image series which can be found at
system.file("extdata", "bleached.tif", package = "detrendr"). It’s 500 frames of diffusing fluorescent particles which are bleaching over the course of the acquisition. We can see they’re bleaching by displaying every 99th frame.

library(magrittr)
path <- system.file("extdata", "bleached.tif", package = "detrendr")
img <- ijtiff::read_tif(path, msg = FALSE)
every100th <- purrr::map(seq(1, dim(img)[4], by = 99), ~ img[, , 1, .]) %>% 
  purrr::reduce(~ cbind(.x, max(img), .y))
ijtiff::display(every100th)

Detrending

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.

#> elapsed 
#>   2.421

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

Above we used exponential filtering detrending, but we could also use boxcar or polynomial.

#> elapsed 
#>   1.136
#> Warning in best_degree(img[, , i, ], purpose = purpose, parallel =
#> parallel): The polynomial degree found for your detrend was 17. Degrees
#> above 3 are not recommended as they usually indicate eccentric fits. It
#> would be wise to use another detrending method (exponential or boxcar).
#> elapsed 
#>   4.395

Let’s check the mean brightness of each:

#> [1] 1.620298
#> [1] 1.510938
#> [1] 1.597765

So we see that different methods give different results.