Now let’s read in an image:
img <- ijtiff::read_tif(system.file("extdata", "50_big.tif", package = "nandb"))
#> Reading 50_big.tif: a 100x100 pixel image of unsigned integer type with 1 channel and 50 frames . . .
#> Done.
dim(img) # get img's dimensions
#> [1] 100 100 1 50
So we can see that img
is a 3-dimensional array of \(1\) slices each of which is a \(100 \times 100\) image. We can view the mean projection of the stack:
Now we can calculate the brightness image based on this image series, with an exponential filtering detrend with a time constant of (say) 10 frames and using the Huang thresholding method via
img_brightness <- brightness(img, "e", tau = "auto", thresh = "Huang")
ijtiff::display(img_brightness[, , 1, 1])
and we can see what happens when we median filter.
img_brightness_med <- brightness(img, "e", tau = "auto",
thresh = "Huang", filt = "median")
ijtiff::display(img_brightness_med[, , 1, 1])
We can save the brightness image (let’s do it without median filtering this time).
We can take a look at the distribution of brightnesses in that image:
db <- density(img_brightness, na.rm = TRUE) %>%
{data.frame(x = .$x, y = .$y)}
ggplot(db, aes(x, y)) + geom_line() +
labs(x = "brightness", y = "frequency") +
xlim(-2, 2)
#> Warning: Removed 206 rows containing missing values (geom_path).
and we can compare it to the distribution of brightnesses from immobile particles:
immobile_brightnesses <- matrix(rpois(50 * 10^6, 50), nrow = 10^6) %>%
{apply(., 1, var) / rowMeans(.) - 1}
di <- density(immobile_brightnesses) %>% {data.frame(x = .$x, y = .$y)}
rbind(mutate(db, mobility = "mobile"), mutate(di, mobility = "immobile")) %>% mutate(mobility = factor(mobility)) %>%
ggplot(aes(x, y)) + geom_line(aes(colour = mobility)) +
labs(x = "brightness", y = "frequency") +
xlim(-2, 2)
#> Warning: Removed 206 rows containing missing values (geom_path).