(c) 2019 Justin Bois. With the exception of pasted graphics, where the source is noted, this work is licensed under a Creative Commons Attribution License CC-BY 4.0. All code contained herein is licensed under an MIT license.
This document was prepared at Caltech with financial support from the Donna and Benjamin M. Rosen Bioengineering Center.
This lesson was generated from a Jupyter notebook. You can download the notebook here.
As you probably noticed during the previous two lessons, there are often a lot of small operations that are sometimes necessary before you can even extract the useful data from the image! Rather than writing out each step whenever you want to process an image, you should write a boilerplate function that can be used to segment any phase contrast image of bacteria. Your function should execute the following steps.
- Correct for "hot" or "bad" pixels in an image.
- Correct for uneven illumination.
- Perform a thresholding operation.
- Remove bacteria or objects near/touching the image border.
- Remove objects that are too large (or too small) to be bacteria. Think carefully! For multipurpose function, would you always want the same area cutoff?
- Remove improperly segmented cells.
- Return a labeled segmentation mask.
A set of discrete operations like this is called a pipeline. It is usefull to think of image processing, or data processing for that matter, as a pipeline consisting of successive steps. This helps codify how you are extracting conclusions from your data and improves reproducibility.
After putting your pipeline into a function, run the pipeline on both the Bacillus subtilis Lesson 35 and the E. coli Lesson 36 image sets. Does your function work well in both cases? Note that in both of these image sets, the interpixel distance is 0.0626 µm per pixel.
%load_ext watermark
%watermark -v -p jupyterlab