Main Content

Getting Started with Cellpose

Segment microscopy images using the Medical Imaging Toolbox™ Interface for Cellpose Library support package. Using the support package, you can apply pretrained models from the Cellpose Library, or retrain a model with your own data. To learn more about the pretrained models and their training data, see the Cellpose Library Documentation.

Cellpose models can segment different cell types across microscopy modalities, or segment other types of objects. Cellpose is a single-class instance segmentation algorithm, meaning the models label many objects of one type. For example, cellpose can detect hundreds of blood cells in an image, but it cannot classify red blood cells versus white blood cells. The algorithm labels each instance separately, as indicated by the different colored masks in this figure.

Cellpose labels predicted for different microscopy images and a non-microscopy image of coins

Install Support Package

You can install the Medical Imaging Toolbox Interface for Cellpose Library from Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons. The support package also requires Deep Learning Toolbox™ and Computer Vision Toolbox™. Processing images on a GPU requires a supported GPU device and Parallel Computing Toolbox™.

The Cellpose Library uses Python®. The Medical Imaging Toolbox Interface for Cellpose Library support package internally uses the pyenv function to interface with the Cellpose Library and automatically load a compatible Python environment. You do not need to configure the Python environment.

Apply Pretrained Cellpose Model

For many microscopy images, a pretrained model with default options can give accurate results. When working with a new data set, try a pretrained model using these steps.

  1. Load the image to segment. Cellpose models expect a 2-D intensity image as input. If you have an RGB or multichannel image, you can convert it to a grayscale image by using the im2gray function, or extract a specific color channel by using the imsplit function.

    img = imread("AT3_1m4_01.tif");

  2. Create a cellpose object to configure a pretrained model from the Cellpose Library. This code configures an instance of the cyto2 model.

    cp = cellpose(Model="cyto2");

  3. Segment the image, specifying the approximate cell diameter in pixels. If you do not know the cell diameter for your image, you can measure it by using the Image Viewer app.

    labels = segmentCells2D(cp,img,ImageCellDiameter=56);

  4. Display the results.

    B = labeloverlay(img,labels);
    imshow(B)

    Segmented microscopy showing labels predicted by the cyto2 model

For a detailed example that compares pretrained models, see Choose Pretrained Cellpose Model for Cell Segmentation.

Refine Pretrained Cellpose Model

To refine the results of a pretrained model, try tuning the model parameters. Tuning affects the preprocessing and postprocessing performed by the model, and does not modify the underlying deep learning network. For a detailed example, see Refine Cellpose Segmentation by Tuning Model Parameters.

This image shows labels predicted using Cellpose with default parameter settings and after refinement. The zoomed in regions show areas where the refined model labels cell membrane protrusions that the default model misses.

Side-by-side comparison of a microscopy image labeled using default versus refined cellpose parameters.

Train Cellpose Model Using Transfer Learning

If none of the pretrained models work well, try retraining a model using transfer learning. For an example, see Train Custom Cellpose Model.

References

[1] Stringer, Carsen, Tim Wang, Michalis Michaelos, and Marius Pachitariu. “Cellpose: A Generalist Algorithm for Cellular Segmentation.” Nature Methods 18, no. 1 (January 2021): 100–106. https://doi.org/10.1038/s41592-020-01018-x.

[2] Pachitariu, Marius, and Carsen Stringer. “Cellpose 2.0: How to Train Your Own Model.” Nature Methods 19, no. 12 (December 2022): 1634–41. https://doi.org/10.1038/s41592-022-01663-4.

See Also

| | | |

Related Topics

External Websites