This page was created by the AI4Life project using data provided by Emiliana Giacomello at University of Trieste. All the images demonstrated in this tutorial are provided under CC-BY licence.
If any of the instructions are not working, please open an issue or contact us at ai4life@fht.org!
Project challenges: sample alignment, cell instance segmentation, cell linking.
- Introduction
- Installation
- Pipeline overview
- Step #1: Data-specific preprocessing in Fiji
- Step #2: Align the images with BigWarp
- Step #3: Link the cells with TrackMate
- How to train your own Cellpose model
- Conclusion
Researchers from the University of Trieste are studying the regulation of the metabolical properties in murine skeletal muscles. They want to analyze a series of sections of a single muscle stained with different markers and imaged with light microscopy. The goal of the analysis is to segment all cells in each section and identify them across different acquired images. Although the cells should be present in each section, their morphology can be vastly different, making identification across sections a challenging task.
In this tutorial, we will demonstrate how to align the different muscle slices to each other using ImageJ BigWarp, then segment muscle cells with Cellpose and link them between multiple images using ImageJ Trackmate.
Here is an exaple of two resulting images, where all the cells are segmented and the same cells are marked with the same color:
Let's get started!
-
Data-specific preprocessing in Fiji
-
Aligning images with ImageJ BigWarp
-
Segmentation with Cellpose and cell linking with ImageJ Trackmate.
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 Cellpose installation for official instructions.
If you are using GPU check out GPU version (CUDA) on Windows or Linux section.
Cellpose installation details
- Create a new python environment:
conda create -n cellpose python=3.9 conda activate cellpose
- If you have a GPU, install PyTorch by following the official instructions. 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
- If you have a GPU, check if the Pytorch 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
Download example images here: TBD
Crop the empty background:
- If necessary, add scale information to the image in
Image > Properties... >
.
Set the pixel width and height to the estimated number of microns. For example: Now you should see the scale on top of the image: - Press
Edit › Selection › Select Bounding Box
to select the non-empty region. If it did not work, try usingSelect Bounding Box (guess background color)
- Press
Image › Crop
to crop the region. - You can scale the image to reduce its size for faster pipeline performance.
PressImage > Scale...
and enter the desired scale, like 0.5 or 0.25.
BigWarp is an ImageJ plugin that helps to align and register images using interest points as a reference. This plugin comes with Fiji, so no installation should be required.
-
Open two cropped images, the
target image
one will be a reference, and themoving image
will be the one scaled and rotated. -
Go to
Plugins > BigDataViewer > Big Warp
. -
Select your two images:
-
Press Space to enter
Landmark mode
. -
Put reference points on both images alternately.
In case of an error - delete the error point in theLandmarks
window.
You can press Space again to exit theLandmark mode
to be able to zoom, move, and rotate the images. -
Place points on several same cells. Try to cover all sides of the sample, like so:
-
We suggest using affine transform for aligning to avoid warping artifacts. Press
F2
to select the “Affine” transformation type from the menu. -
Press
T
to see the result -
Press
File > Export moving image > OK
to export the rotated image. The new image will be opened in a new window.
To link cells between images we will be using a plugin designed for tracking - Trackmate.
-
Download and unzip the pretrained segmentation model: cellpose_model.zip
-
Make a stack of images. Open all the images,
Image > Stacks > Images to Stack
. -
Open up TrackMate
Plugins > Tracking > TrackMate
-
In the first window, it's possible select out the region you want to process and click
Refresh ROI
-
In the next step, select the
Cellpose Detector
-
Check if
Path to cellpose
is correct. It should be the same location that you installed your cellpose into. It should look like:/Users/emilianagiacomello/miniforge3/envs/cellpose/bin/python
-
Select
Custom
model fromPretrained model
and add a path to the downloaded model. -
Check if the approximate diameter of your objects in
Cell diameter
is correct. Here is an example of final settings: -
Press
preview
to run prediction on one image and check the result. The cells found on the image should now be highlighted. -
Press Next until you see the
Select Tracker
window. SelectManual tracking
.
- Press Next until you see this window, and push the
TrackScheme
button.
-
Now you should select the
Spot edit
tool in the main window, on the right side. -
Click on one of the cells, go to the next image and
Shift + Click
on the same cell on the other staining, and then PressL
. You should see a small line appear, meaning the cells were linked.
- You can export a table with links and spot features in the
Tracks
window.
Label
is the name of the cell’s ROI, and Track ID is the of the link you created.
You can export the resulting CSV for the downstream analysis. - You can also export the segmentation results as ROI, which will have the same IDs as in the table above. Click Next until you see “Select an action” window, choose “Export spots to IJ ROIs” and press “Execute”:
You can watch a video tutorial on how to use Cellpose here - https://www.cellpose.org/
- Activate the
cellpose
enviroment you installed before. - Run
cellpose
application. - 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
In this tutorial, we showed how to align murine muscle images with ImageJ BigWarp, segment cells with Cellpose and link them between multiple images using ImageJ Trackmate.
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.