This page was created by the AI4Life project using data provided by Madeline Lovejoy and Rafael Garcia-Mata (PhD) at Garcia-Mata Lab
If any of the instructions are not working, please open an issue or contact us at ai4life@fht.org!
Project challenges: denoising, cell instance segmentation, cell tracking.
- Introduction
- Installation
- Denoising with N2V
- Segmentation with Cellpose
- Tracking with Trackmate-Cellpose
- Conclusion
Researchers from The University of Toledo Garcia-Mata Lab are imaging a confluent 2D monolayer of epithelial cells. The monolayer is scratched with a pipette tip, and the video shows the migration of the cells to close the wound. They would like to compare the behavior of different cell lineages automatically. They are interested in segmenting and tracking individual cells and nuclei in time.
In this tutorial, we will demonstrate how to segment and track individual epithelial cells in a series of images obtained with fluorescence microscopy.
We will start by denoising the images using N2V Python package, which denoises microscopy images using deep learning. Next, we will segment cells using Cellpose, a popular deep-learning cell segmentation algorithm. Finally, we'll track the segmented cells using the TrackMate plugin in Fiji.
Here is a visualization of the original data and resulting tracking:
Data is provided under a CC-BY license.
Let's get started! 🚀
We recommend installing conda or mamba. Go to the website and follow the installation instructions for your operating system.
During installation, select the installation folder that you have permissions for, such as your home folder.
Follow N2V installation for official instructions.
N2V installation details
- Open terminal (such as Terminal on MacOS, for Windows we recommand Git for Windows)
- Create and activate a new conda environment:
conda create -n n2v python=3.9 conda activate n2v
- Install Tensorflow by following the official instructions. If you have no GPU available, install the CPU version.
N2V only supports Tensorflow 2. We'll now install version 2.13.0 with GPU support as an example:pip install tensorflow[and-cuda]==2.13.0
- Check if the installation is correct. If you are using GPU, this command should return a list of available devices:
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
- Install N2V and Jupyter:
pip install n2v jupyter
Follow Cellpose installation for official instructions.
If you are using GPU check out GPU version (CUDA) on Windows or Linux section.
Cellpose installation details
- We recommend creating a new separate environment:
conda create -n cellpose python=3.9 conda activate cellpose
- Install PyTorch by following the official instructions.
If you have a GPU, select a version that is compatible with your driver version. Follow this link for older versions.
We will be installing PyTorch version 1.12 and cudatoolkit version 11.3 as an example:conda install pytorch==1.12.0 torchvision==0.13.0 cudatoolkit=11.3 -c pytorch
- Check if the installation is correct. If you are using GPU, this command should return a list of available devices:
python -c "import torch; print([torch.cuda.get_device_properties(i) for i in range(torch.cuda.device_count())])"`
- Install Cellpose:
pip install pyqt5 "cellpose[gui]"
- Check the installation by running Cellpose. You should see the Cellpose window open:
cellpose
Follow TrackMate-Cellpose for official instructions.
TrackMate-Cellpose installation details
- Open Fiji.
- Add The TrackMate-Cellpose update site and restart Fiji.
- In your cellpose conda environment, run this command to find where your python is installed:
which python
- Open TrackMate and select Cellpose detector from the list of available detectors.
- Insert the path to your python in Path to Cellpose
If the images are noisy, denoising can help achieve better segmentation performance. Most deep learning segmentation models are trained with clean images, so noise in the data severely affects the resulting accuracy.
You will likely need to re-train the denoising model for different experiments because differences in noise distribution will affect the performance, but worry not N2V is quite fast to train!
N2V offers a Python package and a napari plugin, or if you do not have a GPU available, you can try using a Google Colab N2V notebook from ZeroCostDL4Mic.
- Download the example jupyter notebook here: N2V_denoising.ipynb
- Download example data series here: TBD
- Activate the conda environment
conda activate n2v
- Run jupyter service
jupyter notebook
- In the opened browser page, open the notebook and follow the instructions.
- To run a pre-trained model, download and unzip the pretrained model. Then, in the Jupyter Notebook, go to the section 7. Prediction.
Here is an example of an original and denoised image:
Cellpose is a popular deep-learning cell segmentation algorithm.
- Download and unzip pre-trained models for membrane and nuclei segmentation: cellpose_membrane_model.zip
- Activate the conda environment
conda activate cellpose
- Run Cellpose
cellpose
- Select the channels you want to segment. If you want to segment entire cells, add the membranes as
chan to segment
and nuclei aschan2
. If you want to segment only nuclei, and them tochan to segment
and leavechan2
empty. - Calibrate the average object size automatically by clicking
callibrate
. The circle on the bottom-left should be approximately the size of the objects you want to segment. - Check how default models perform on the data by clicking any in the
model zoo
section. - Add a custom pretrained model to the interface:
Models > Add custom torch model to GUI
. - Select this model in the
custom models
section and run it by clickingrun model
.
You can watch a video tutorial on how to use Cellpose here - https://www.cellpose.org/
-
Find the best working model from the
model zoo
section. -
Look through the errors in the predictions and correct a few of them.
Click Help
>Help with GUI
for help with labeling controls. -
Train a new model on the corrected data. Click
Models
>Train new model
. -
Choose the best model from step 3 as an initial model. You cannot select a custom model as an initial model.
-
We suggest using the following settings:
-
After training, you’ll see your new model in the
custom models
section. It will also be saved in the folder with your data.Cell diameter
will also be updated with what the model learned from the data. -
You can continue iterating: predict with the model - fix a couple of mistakes - train a new model - fix mistakes - train a new model
To use the resulting model on a time series and track the segmentations, install the TrackMate-Cellpose integration in Fiji.
-
Open a denoised time series.
-
Check if
Path to cellpose
is correct. -
Select
Custom
model fromPretrained model
. -
Select the channels you want to segment.
-
Select the path to your model. Enter the channels you want to segment and the approximate diameter of your objects.
Here is an example of the settings: -
Press
preview
to run prediction on one timepoint and check the result. The objects on the image should now be highlighted. -
Press
next
to run prediction on all time points (it can take a while). Do not filter the resulting spots. -
For tracking, we chose the LAP tracker. Here are the settings we used:
-
Here are the visualization settings we used:
-
To improve the results, consider different distance settings, feature penalties, and track filtering.
In this tutorial, we showed how to use N2V, https://www.cellpose.org/, and TrackMate-Cellpose to segment and track nuclei of epithelial cells in a series of images obtained with fluorescence microscopy.
AI4Life is a Horizon Europe-funded project that brings together the computational and life science communities.
AI4Life has received funding from the European Union’s Horizon Europe research and innovation programme under grant agreement number 101057970. Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Research Council Executive Agency. Neither the European Union nor the granting authority can be held responsible for them.