-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial
In this tutorial, we explain how to preprocess raw images to enhance their quality, which directly improves the accuracy of segmentation and tracking. We provide instructions on running CellProfiler, using TrackRefiner on the results from CellProfiler, and interpreting the output of TrackRefiner.
The dataset used in this tutorial, available for download from the provided link, is based on the ‘agar’ scenario with a 3-minute interval time and a 10-minute doubling time.
Be Careful: Ensure your images are in the correct order.
Sometimes, issues arise when images are named inconsistently, such as frame_9, frame_10, ..., frame_100. This naming format can cause problems because the file system may sort the images in an unexpected order (e.g., frame_100 might appear between frame_10 and frame_11). To avoid this, the number of digits in the filenames should be consistent. For example, use names like frame_009, frame_010, ..., frame_100. This ensures proper numerical sorting and prevents issues during processing.
Improving image quality reduces the risk of noise, segmentation errors, and inaccurate tracking.
To achieve this, you can use tools such as ImageJ.
An important recommendation during preprocessing is to maximize the contrast between the borders and interiors of objects, as this helps segmentation tools better detect and define the complete regions of objects and distinguish between them. For instance, you can apply the Unsharp Mask filter in ImageJ, adjust brightness/contrast, or utilize other methods that improve clarity and make object boundaries more distinguishable.
Additionally, you can crop the region of interest (ROI) in your images using ImageJ's crop option. By cropping, you can remove noisy or irrelevant parts of the images, such as bacteria outside the walls of a microfluidic scenario or regions beyond your area of interest.
Jitter can significantly affect tracking accuracy. To reduce jitter, you can use the following script provided by TrackRefiner trackrefiner-jitter-remover:
trackrefiner-jitter-remover -i raw_images_K12 -o modified_images_K12
In this script, the -i argument specifies the folder containing your input images, which can be the output from the Enhancing Image Quality step or your raw images if their quality is sufficient. The -o argument defines the output directory where the corrected images will be saved. This script removes jitter from the specified folder of images using phase cross-correlation and saves the aligned images to the designated output directory. It supports grayscale and multi-channel (e.g., RGB or 3-channel fluorescence microscopy images).
The script also supports predefined shift correction using the s argument. This feature is useful when you calculate alignment shifts based on one set of images and want to apply those same shifts to a different but related set.
To use this option, provide a CSV file using the -s argument:
trackrefiner-jitter-remover -i other_images -o aligned_images -s shift.csv
The CSV file must contain three columns:
-
ImageNumber: the index of each image in the order they appear (starting from 1) -
Shift_X: the horizontal shift to apply -
Shift_Y: the vertical shift to apply
When this argument is used, the script skips shift estimation and directly applies the shifts specified in the file to each corresponding image in the input folder.
You can also control the direction in which jitter correction is applied. R (Reverse) mode processes images from last to first, while F (Forward) mode processes images from first to last.
You can set the processing direction using the -d argument:
trackrefiner-jitter-remover -i raw_images -o corrected_images -d F
By default, the script uses R(Reverse) mode (-d R).
Note: If the amount of jitter in your images is high, this script will reduce it but may not completely eliminate it. It’s a good idea to visually inspect your images before and after jitter removal to evaluate the improvements.
The results of preprocessing on K12 data are available for download from the following link:
Once your images have been preprocessed, the next step is segmentation. Segmentation involves dividing the image into distinct regions, allowing us to identify and isolate objects for further analysis. It is a necessary step for quantifying the characteristics of objects and enabling their tracking over time.
Various softwares/tools, such as ilastik, Omnipose, and others, can be used for segmentation. The results can then be introduced into CellProfiler to measure phenotypes and track objects over time.
It is important to note that TrackRefiner relies on CellProfiler outputs. Therefore, while segmentation can be performed using the tool of your choice, phenotype measurement and tracking must be conducted using CellProfiler.
In our previous study, "A benchmarked comparison of software packages for time-lapse image processing of monolayer bacterial population dynamics" we demonstrated that integrating CellProfiler with Omnipose is an effective solution for most types of bacteria. To leverage this integration, you can add the omnipose plugin to CellProfiler and perform segmentation, phenotype measurement, and tracking directly within its interface.
On the following page, you can see how to install CellProfiler and add the Omnipose plugin into it, along with our suggested pipeline for analyzing bacterial data:
Installation Guide for CellProfiler and Plugins
The CellProfiler pipeline you use should export the following files and directories:
- Segmentation files for each frame in
.npyformat, where object pixels are unified in a specific color.- Segmentation files are exported by converting objects into images with the color map set to "Color" using the ConvertObjectsToImage module and saved in
.npyformat using the SaveImages module.
- Segmentation files are exported by converting objects into images with the color map set to "Color" using the ConvertObjectsToImage module and saved in
- A CSV file containing measured bacterial features (e.g., length, orientation) and tracking information.
- Shape-based features are extracted Using the MeasureObjectSizeShape module, and Tracking is performed using the TrackObjects module.
- A CSV file containing bacterial neighbor information.
- Neighbors for each bacterium are identified using the MeasureObjectsNeighbors module.
You can download the results of segmentation, phenotype measurement, and tracking for the K12 dataset from the following link:
Cellprofiler_Omnipose_output_K12.zip
- Segmentation files are stored in the objects folder.
- FilterObjects.csv contains measured bacterial features and tracking information.
- Object relationships.csv contains bacterial neighbor information.
Before running TrackRefiner, it is important to account for aspects that may influence its performance:
- Noise or Incorrect Segmentations: If your dataset contains a significant amount of noise or segmentation errors, it can negatively affect TrackRefiner's ability to refine the tracking of bacteria accurately.
- High Interval Time: When the interval time between frames is too high, bacterial divisions may be missed. Additionally, this can cause the tracking to skip over the mother, jumping directly from a bacterial ancestor to its descendants, which reduces the accuracy of TrackRefiner's output.
Installation Instructions for TrackRefiner
To install TrackRefiner, please follow the instructions on the Installation-Guide.
TrackRefiner can be run in two ways:
- Command-Line Interface (CLI)
trackrefiner-cli - Graphical User Interface (GUI)
trackrefiner-gui
For detailed information about TrackRefiner's input parameters, please refer to the Required and Optional Parameters.
To process the K12 dataset using the CLI version of TrackRefiner, the following command has been used:
trackrefiner-cli -i Cellprofiler_Omnipose_output_K12/FilterObjects.csv \
-s Cellprofiler_Omnipose_output_K12/objects/ \
-n Cellprofiler_Omnipose_output_K12/Object relationships.csv -t 3 -d 20
Alternatively, to use the GUI, TrackRefiner can be run on the K12 dataset by configuring the parameters as shown in the following image:
The results of TrackRefiner on the K12 dataset can be downloaded from
Trackrefiner_K12.zip.
Note 1: Handling Dynamic ROI in Images
When the region of interest (ROI) in your images changes over time due to frame movement, objects outside the dynamic ROI may still appear in the results. Since the ROI is dynamic, excluding these objects during preprocessing through cropping might not be feasible. To address this issue, you can define either a static ROI for all images or a dynamic ROI for each image using the Boundary Limits and Dynamic Boundaries parameters of TrackRefiner.
To become more familiar with the outputs of TrackRefiner, refer to the the TrackRefiner Outputs.