Opening and merging microscope images in R

First off I’ll start by saying: there are plenty of free software that are better suited to manipulating microscope images such as ImageJ/FIJI or even python/Scikit-image. However R is great for analysing the numerical data that comes from image analysis, and I was tired of my disjointed workflow that usually involved finding an interesting result in R, and then firing up FIJI to check the image associated with that result – and I actually had the image URLS in my metadata, so I wanted a way for R to read that image URL, open the image and display it in a useful manner.

I found the raster package that can open .tif files, I’ve not tried it with any unusual file formats, though BioFormats should probably be your port of call in that case.

Example

I’m going to use some example images from the Broad Bioimage Benchmark collection, which are Drosophila Kc157 cells imaged in two channels stained for DNA and actin.

To load the images use the raster function.

And to display the individual channels simply use plot .

Then to plot the merged images. If you don’t want to stretch the intensity values to maximise contrast, remove the stretch = "lin" argument.

If you want to change the colours of the channels you have to tell plotRGB which position in the brick object you want each colour. It seems you have to use all RGB channels.

Tada!

Next steps

I’ve found this quite slow when opening and merging high-resolution .tifs, somewhere in the order of 30 seconds for three 10MB files. Next step is data-points within a scatter plot linked to the images, click the point and the associated merged image will be displayed – shouldn’t be too difficult…