Main Content

cellpose

Configure Cellpose model for cell segmentation

Since R2023b

    Description

    Use the cellpose object and its object functions to segment cells in microscopy images using the Cellpose Library.

    A cellpose object specifies the model to use as well as options for segmentation. You can specify a pretrained model from the Cellpose Library or a custom trained model. To perform segmentation, pass the cellpose object to the segmentCells2D or segmentCells3D object function for 2-D or 3-D images, respectively. Train a custom model by using the trainCellpose function. Download all pretrained models from the library using the downloadCellposeModels function.

    Note

    This functionality requires Deep Learning Toolbox™, Computer Vision Toolbox™, and the Medical Imaging Toolbox™ Interface for Cellpose Library. 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.

    Creation

    Description

    example

    cp = cellpose creates a cellpose object with default property values. The first time you call this syntax, the function downloads the cyto2 network from the Cellpose Library, which requires an internet connection.

    cp = cellpose(Name=Value) sets the Model and ModelFolder properties, or specifies additional arguments using one or more name-value arguments. For example, ExecutionEnvironment="gpu" specifies to use a GPU for segmentation.

    Input Arguments

    expand all

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: cellpose(Acceleration="openvino") applies OpenVINO™ acceleration during segmentation.

    Use ensemble model, specified as a numeric or logical 0 (false) or 1 (true). For some pretrained models, including cyto2, cyto, and nuclei, the Cellpose Library offers multiple versions that have been trained using different initial parameter values. Set this argument to true to download all versions of the specified Model and segment images using the average result across the ensemble of versions. An ensemble model can be more accurate for some data sets, but takes longer to run.

    This argument corresponds to the net_avg parameter in the Cellpose Library.

    Data Types: logical

    Hardware resource for segmentation, specified as one of these values.

    • "auto" — Use a GPU if Parallel Computing Toolbox™ is installed and a supported GPU device is available. Otherwise, use the CPU.

    • "cpu" — Use the CPU.

    • "gpu" — Use the GPU. If you choose this option and Parallel Computing Toolbox or a supported GPU is not available, then the software returns an error.

    For information on supported GPU devices, see GPU Computing Requirements (Parallel Computing Toolbox).

    Data Types: char | string

    Apply CPU acceleration, specified as "none" or "openvino". When set to "openvino", the cellpose object applies Open Visual Inference and Neural network Optimization (OpenVINO) acceleration on a CPU. This argument has no effect when using GPU. The actual increase in speed depends on your CPU.

    OpenVINO acceleration can improve performance when segmenting:

    • Multiple 2-D images of the same size

    • A single 3-D image the same size in all dimensions

    When you enable OpenVINO acceleration, the software returns an error if you try to segment multiple images of different sizes.

    Data Types: char | string

    Properties

    expand all

    This property is read-only.

    Model name, specified as a string scalar or character vector. Specify Model as the name of a pretrained model from the Cellpose Library, the name of a custom trained model in the default ModelFolder, or the absolute path to a custom trained model. You can specify a pretrained model as one of these options.

    • "cyto"

    • "cyto2"

    • "CP"

    • "CPx"

    • "nuclei"

    • "livecell"

    • "LC1"

    • "LC2"

    • "LC3"

    • "LC4"

    • "tissuenet"

    • "TN1"

    • "TN2"

    • "TN3"

    The first time you specify a given pretrained model, the function downloads it from the Cellpose Library, which requires an internet connection. To learn more about the pretrained models and their training data, see the Cellpose Library Documentation.

    This property is read-only.

    Model folder path, specified as a scalar string or character vector of the path to the folder containing the model Model. By default, ModelFolder is a subfolder named cellposeModels within the folder returned by the userpath function. This property has no effect if you specify Model as an absolute path to a custom trained model.

    This property is read-only.

    Detectable cell diameter, specified as a numeric scalar. This property specifies the typical cell diameter that the model is trained to detect, in pixels. The model should be used to process images of cells with a diameter similar to DetectableCellDiameter. The range of diameters a model is actually able to detect varies across models, and can be explored using trial and error.

    This property corresponds to the diam_mean parameter in the Cellpose Library.

    Data Types: double

    This property is read-only.

    Training cell diameter, specified as a numeric scalar. This property specifies the average cell diameter in the images used to train the model. This property corresponds to the diam_labels parameter in the Cellpose Library.

    Data Types: double

    Object Functions

    segmentCells2DSegment 2-D image using Cellpose
    segmentCells3DSegment 3-D image volume using Cellpose

    Examples

    collapse all

    Create a cellpose object with default property values.

    cp = cellpose
    cp = 
    
      cellpose with properties:
    
        DetectableCellDiameter: 30
          TrainingCellDiameter: 30
                   ModelFolder: "C:\Documents\MATLAB\cellposeModels\"
                         Model: "cyto2"

    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.

    Version History

    Introduced in R2023b