Detrending images with detrendr

Rory Nolan

2018-02-17

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.422

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 
#>    0.94
#> Warning in best_degree(img[, , i, ], seed = seed, 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.849

Let’s check the mean brightness of each:

#> [1] 1.599681
#> [1] 1.449115
#> [1] 1.597455

So we see that different methods give different results.