Counting cells under microscope is always laborious and null. Those in the art would be relieved with assistance of a powerful image processing package, EBImage. Images are treated as “Image” objects, essentially multi-dimensional arrays. The class “Image” contains spatial information, pixel intensities, color channels, etc. Image objects are easily processed or modified using matrix algebraic operators. You can read the introduction document and their paper for more information.
In general, there are four steps using EBImage to automate your counting job.
- read the photos into R environment with readImage();
- extract the channel you intend to process with channel() or just subset();
- filter the noise, which is important to the result;
- get the result, e.g. the count number, labelled photo, phenotypic features.
The resulting image is shown here.
As I mention, the third step is critical, while the rest steps are straightforward. It would be easy when the background is as clean as a blue sky. But it is hard when the background gets dirty. For this particular photo, I used three steps to remove the noisy background: use thresh() to filter out noisy pixels; use opening() to enhance the morphological shapes; remove spots with less number of pixels. It turned out very well. The original code is published here at github.
The effectiveness of this filtering step is greatly dependent on the image quality. It means if the background is a mess, there is very little room for improvement. Instead of trying a bunch of filter parameters, however, there is one alternative way which requires manual curation. Use paintObjects(opac, col) to output cell-masked images, then check the cell counts. This would leave some additional work after automated processing. So rule of thumb, why just take some clean shots of your cells?
Btw, the authors locate at EMBL. No wonder the package name looks familiar.