Generating Nuclei Segmentations for vEM using Cellpose

Alyson Petruncio, Aubrey Weigel, CellMap Project Team, Emma Avetissian, Jeff L Rhoades

Published: 2024-08-02 DOI: 10.17504/protocols.io.n2bvjnq8pgk5/v1

Abstract

This protocol details the process of generating nucleus segmentations in FIB-SEM (Focused Ion Beam Scanning Electron Microscopy) image stacks of cells and tissues using Cellpose. These segmentations are crucial for gaining biological insights and training deep learning models on cell and organelle segmentation. The protocol covers the application of Cellpose for fine-tuning 2D models specifically for nuclei segmentation. Once fine-tuned, the model is used to generate 3D predictions for the entire dataset. These segmentations can be further refined through manual approaches, utilized for visualization, or employed in training other machine learning models.  

Steps

Introduction:

1.

The purpose of this protocol is to provide comprehensive instructions on how to create nuclei segmentations in FIB-SEM datasets on OpenOrganelle.org using Cellpose.

Cellpose is a generalist algorithm developed by Stringer et al., (2020) to segment cellular structures. Cellpose also provides software for manual segmentation and model training. In this protocol we discuss the use of Cellpose v3.0.9.

Citation
Stringer C, Wang T, Michaelos M, Pachitariu M 2021 Cellpose: a generalist algorithm for cellular segmentation. https://doi.org/10.1038/s41592-020-01018-x
OpenOrganelle.org is an online platform that provides access to high-resolution 3D electron microscopy images of cellular structures for scientific research and education.

In this protocol you can expect to find: 

  • OpenOrganelle Overview
  • Using Fiji to save files in the cloud locally as 2D tiffs
  • Cellpose in 2D and Model Training
  • Cellpose in 3D and Predictions
  • Final Touches

OpenOrganelle Overview

2.

OpenOrganelle (Heinrich et al, 2021) is a collection of focused ion beam scanning electron microscopy (FIB-SEM) datasets curated by the Janelia CellMap Project Team. Each dataset on OpenOrganelle includes important background information about the sample, protocol, contributors, and more. The “VIEW” button opens a new tab to view the chosen dataset in Neuroglancer. Each dataset is also accompanied by a Fiji link which copies the location of the dataset in the S3 bucket (see Figure 1). This link was used to read data into Fiji and save as 2D slices for Cellpose. 

Figure 1: OpenOrganelle page. The Fiji link is located on the right-hand side.
Figure 1: OpenOrganelle page. The Fiji link is located on the right-hand side.

Citation
Heinrich L, Bennett D, Ackerman D, Park W, Bogovic J, Eckstein N, Petruncio A, Clements J, Pang S, Xu CS, Funke J, Korff W, Hess HF, Lippincott-Schwartz J, Saalfeld S, Weigel AV, COSEM Project Team 2021 Whole-cell organelle segmentation in volume electron microscopy. https://doi.org/10.1038/s41586-021-03977-3

Citation
Schindelin J, Arganda-Carreras I, Frise E, Kaynig V, Longair M, Pietzsch T, Preibisch S, Rueden C, Saalfeld S, Schmid B, Tinevez JY, White DJ, Hartenstein V, Eliceiri K, Tomancak P, Cardona A 2012 Fiji: an open-source platform for biological-image analysis. https://doi.org/10.1038/nmeth.2019

Using Fiji to save files in the cloud locally as 2D tiffs

3.

Once the Fiji link from OpenOrganelle has been copied, it can be pasted into Fiji

Figure 2: How to open a dataset from OpenOrganelle in Fiji 
Figure 2: How to open a dataset from OpenOrganelle in Fiji 

4.

Head to:  File  → ImportHDF5/N5/Zarr/...

5.

Paste the link into the search bar. 

6.

Click Detect Datasets

7.

Navigate through the file container by clicking the dropdown, e.g.  “em”.

Choose resolution, e.g., s0 (original), s1 (2x downsample), s3 (4x downsample), etc.  

Note
This step involves reading the data from the S3 bucket into your local computer memory. The datasets can be very large; care should be taken when choosing which resolution to read. The approximate size of the image volume is listed e.g., "s0 (12400x500x9382, int16 → 16-bit) (116.3 GB)"

8.

Click OK. See Figure 2.

9.

Once the dataset is open in Fiji, it can be saved as a sequence of 2D slices for reading into Cellpose.

From the open dataset window go to:  File   Save As   Image Sequence  → Save into a new folder r

See Figure 3.

Figure 3: Process of saving 2D slices in Fiji. 
Figure 3: Process of saving 2D slices in Fiji. 

10.

Before closing the image in Fiji, save a second copy of the dataset as a 3D tiff. This will be used for generating 3D predictions in a later step in Cellpose. If the image is closed before creating the 3D tiff, you can simply drag the folder containing the image sequence into the main Fiji bar to open it. To save it as a 3D tiff: 

FileSave AsTiff

See Figure 4.

Figure 4: How to save 2D slices as a 3D tiff. 
Figure 4: How to save 2D slices as a 3D tiff. 

Note
While creating annotations in Cellpose for model finetuning, it is helpful to keep the image volume open in Fiji as a reference. It is not always evident what an organelle is from just the 2D slices presented in Cellpose. To open the 3D tiff, drag the tiff file into the main Fiji menu. A scroll bar will appear at the bottom for viewing the entire stack. 

Cellpose in 2D and Model Training

11.

To begin using Cellpose on the dataset, open the program (see Appendix). More detailed instructions for general Cellpose use can be found on https://cellpose.readthedocs.io/en/latest/gui.html. Within Cellpose go to:  File  → Load Image  → Select a slice for segmentation  

See Figure 5.

Figure 5: How to load a single slice for annotation in Cellpose. 
Figure 5: How to load a single slice for annotation in Cellpose. 

AB
ZoomHold right click and drag
ZoomScroll wheel
PanHold left click and drag
Create maskTap right click and drag
Remove maskCtrl left click
Undo remove maskCtrl Y
Toggle mask visibilityX
Toggle mask outlinesZ

Table 1: Basic key binds for annotation in Cellpose

12.

Annotate the nuclei as accurately as possible.

At first, it may be beneficial to use an existing model to make annotating easier. Out of the box, the cyto2_cp3 model tends to give promising results for nuclei in FIB-SEM volumes of tissue. If the model does not catch anything, try annotating a couple slices manually and training a model. Continue to use and improve the model by periodically adding more training slices.

Note
Make sure to clean up missing spots, mistaken predictions, and tidy up the edges.

Refer to Figure 6 for what a completed slice might look like. 

Figure 6: Example of a fully annotated slice from the dataset jrc_mus-kidney-2. 
Figure 6: Example of a fully annotated slice from the dataset jrc_mus-kidney-2. 

13.

Once the annotation is complete, save the slice along with the masks.  

File → *Save masks and image (as _seg.npy)

This file will automatically be saved into the folder where the rest of the 2D slices can be found.

Note
Do not change the name as this is how Cellpose will recognize that the file should be used for training. 

14.

To train a model on annotated slices, go to: 

ModelsTrain new model with image+masks in folder

14.1.

Set the initial model to cyto2_cp3

14.2.

Adjust n_epochs to change the number of epochs (we generally went with 1000)

14.3.

Name the model for organizational purposes. Click “OK” and wait for the training to finish.

Note
We found that training took at most 15 minutes and the largest amount of training slices required for an adequate model was 38 slices. Progress can be tracked in the terminal (See Figure 7). The model’s file will automatically be created in a separate “models” folder that is placed inside the folder that contains the 2D slices.  

Figure 7. Screenshot of the terminal while training is in progress. The number after “[INFO]” displays the current epoch. 
Figure 7. Screenshot of the terminal while training is in progress. The number after “[INFO]” displays the current epoch. 
15.

To run this model on a new 2D slice

15.1.

Open the blank 2D slice and locate the section labeled “Other models” on the left-hand side of the program.

15.2.

Open the dropdown for custom models, select the new model, and click run. 

15.3.

Repeat this process, making use of previous models, annotating additional slices until the model performs satisfactorily on 2D slices.

Cellpose in 3D and Predictions

16.

Cellpose can extend models that were trained exclusively on 2D data to perform predictions in 3D. Once the model demonstrates a satisfactory performance in 2D, we attempt to run a prediction in 3D.

Note
In Cellpose v3.0.9, to create a 3D prediction, the program requires explicitly instructing the program to handle 3D data via a specific flag. This adjustment ensures that Cellpose interprets and processes the volumetric data correctly.

16.1.

Close Cellpose 

16.2.

Into the terminal enter:

python -m cellpose --Zstack

This will alert Cellpose to load data as 3D 

16.3.

Now load in the previously saved 3D volume by: 

FileLoad ImageSelect the tiff file

17.

Once the tiff has loaded, run the custom model as described for 2D in Step 15.

This may take a while (on the order of tens of minutes) and progress can be tracked in the terminal.

The process will be complete when the masks are visible (see Figure 8).

Figure 8: A finetuned Cellpose model has been applied to the dataset jrc_mus-kidney-2.
Figure 8: A finetuned Cellpose model has been applied to the dataset jrc_mus-kidney-2.

The terminal will also contain how many masks were found at the end of the run (see Figure 9).  

Figure 9: Screenshot of the terminal after Cellpose ran a 3D prediction. The arrow points to where the terminal lists out how many masks were found. 
Figure 9: Screenshot of the terminal after Cellpose ran a 3D prediction. The arrow points to where the terminal lists out how many masks were found. 
18.

To save the masks go to: 

FileSave masks as PNG/tiff

Figure 10: Example results of Cellpose segmentations from three datasets. Shown are 3D renderings of the segmentations that have been manually proofread.
Figure 10: Example results of Cellpose segmentations from three datasets. Shown are 3D renderings of the segmentations that have been manually proofread.

推荐阅读

Nature Protocols
Protocols IO
Current Protocols
扫码咨询