Class Cellpose2D

java.lang.Object
qupath.ext.biop.cellpose.Cellpose2D

public class Cellpose2D extends Object
Dense object detection based on the cellpose and omnipose publications
 Stringer, C., Wang, T., Michaelos, M. et al.
     "Cellpose: a generalist algorithm for cellular segmentation"
     Nat Methods 18, 100–106 (2021). doi.org/10.1038/s41592-020-01018-x
 
And
 Cutler, K.J., Stringer, C., Lo, T.W. et al.
     "Omnipose: a high-precision morphology-independent solution for bacterial cell segmentation"
     Nat Methods 19, 1438–1448 (2022). https://doi.org/10.1038/s41592-022-01639-4
 
See the main repos at https://github.com/mouseland/cellpose and https://github.com/kevinjohncutler/omnipose

The structure of this extension was adapted from the qupath-stardist-extension at https://github.com/qupath/qupath-extension-stardist This way the Cellpose builder mirrors the StarDist2D builder, which should allow users familiar with the StarDist extension to use this one.

  • Field Details

    • extendChannelOp

      public qupath.opencv.ops.ImageOp extendChannelOp
    • useGPU

      public boolean useGPU
    • outputModelName

      public String outputModelName
    • simplifyDistance

      protected double simplifyDistance
    • op

      protected qupath.opencv.ops.ImageDataOp op
    • globalPreprocess

      protected OpCreators.TileOpCreator globalPreprocess
    • preprocess

      protected List<qupath.opencv.ops.ImageOp> preprocess
    • pixelSize

      protected double pixelSize
    • cellExpansion

      protected double cellExpansion
    • cellConstrainScale

      protected double cellConstrainScale
    • ignoreCellOverlaps

      protected boolean ignoreCellOverlaps
    • creatorFun

      protected Function<qupath.lib.roi.interfaces.ROI,qupath.lib.objects.PathObject> creatorFun
    • globalPathClass

      protected qupath.lib.objects.classes.PathClass globalPathClass
    • constrainToParent

      protected boolean constrainToParent
    • tileWidth

      protected int tileWidth
    • tileHeight

      protected int tileHeight
    • measureShape

      protected boolean measureShape
    • compartments

      protected Collection<qupath.lib.analysis.features.ObjectMeasurements.Compartments> compartments
    • measurements

      protected Collection<qupath.lib.analysis.features.ObjectMeasurements.Measurements> measurements
    • cellposeSetup

      protected CellposeSetup cellposeSetup
    • parameters

      protected LinkedHashMap<String,String> parameters
    • model

      protected String model
    • overlap

      protected Integer overlap
    • modelDirectory

      protected File modelDirectory
    • groundTruthDirectory

      public File groundTruthDirectory
    • nThreads

      protected int nThreads
    • doReadResultsAsynchronously

      protected boolean doReadResultsAsynchronously
  • Constructor Details

    • Cellpose2D

      public Cellpose2D()
  • Method Details

    • builder

      public static CellposeBuilder builder(String modelPath)
      Create a builder to customize detection parameters. This accepts either Text describing the built-in models from cellpose (cyto, cyto2, nuc) or a path to a custom model (as a String)
      Parameters:
      modelPath - name or path to model to use for prediction.
      Returns:
      this builder
    • builder

      public static CellposeBuilder builder(File builderPath)
      Load a previously serialized builder. See CellposeBuilder(File) and CellposeBuilder.saveBuilder(String)
      Parameters:
      builderPath - path to the builder JSON file.
      Returns:
      this builder
    • imageNormalizationBuilder

      public static OpCreators.ImageNormalizationBuilder imageNormalizationBuilder()
      Build a normalization op that can be based upon the entire (2D) image, rather than only local tiles.

      Example:

       
         var builder = Cellpose2D.builder()
              .preprocess(
                      Cellpose2D.imageNormalizationBuilder()
                              .percentiles(0, 99.8)
                              .perChannel(false)
                              .downsample(10)
                              .build()
              ).pixelSize(0.5) // Any other options to customize StarDist2D
              .build()
       
       

      Note that currently this requires downsampling the image to a manageable size.

      Returns:
      a builder for a normalization op
    • getTrainingDirectory

      public File getTrainingDirectory()
      The directory that was used for saving the training images
      Returns:
      the directory
    • getValidationDirectory

      public File getValidationDirectory()
      The directory that was used for saving the validation images
      Returns:
      the directory
    • detectObjects

      public void detectObjects(qupath.lib.images.ImageData<BufferedImage> imageData, Collection<? extends qupath.lib.objects.PathObject> parents)
      Detect cells within one or more parent objects, firing update events upon completion.
      Parameters:
      imageData - the image data containing the object
      parents - the parent objects; existing child objects will be removed, and replaced by the detected cells
    • detectObjectsImpl

      public void detectObjectsImpl(qupath.lib.images.ImageData<BufferedImage> imageData, Collection<? extends qupath.lib.objects.PathObject> parents)
      Detect cells within one or more parent objects, firing update events upon completion.
      Parameters:
      imageData - the image data containing the object
      parents - the parent objects; existing child objects will be removed, and replaced by the detected cells
    • train

      public File train()
      Executes the cellpose training by 1. Saving the images 2. running cellpose 3. moving the resulting model file to the desired directory
      Returns:
      a link to the model file, which can be displayed
    • getOutputLog

      public List<String> getOutputLog()
      Returns the log from running the cellpose command, with any error messages and status updates of the cellpose process You can use this during training or prediction
      Returns:
      the entire dump of the cellpose log, each line is one element of the String array.
    • getTrainingResults

      public ij.measure.ResultsTable getTrainingResults()
      Returns a parsed version of the cellpose log as a ResultsTable with columns Epoch, Time, Loss, Loss Test and LR
      Returns:
      an ImageJ ResultsTable that can be displayed with ResultsTable.show(String)
    • getQCResults

      public ij.measure.ResultsTable getQCResults()
      Get the results table associated with the Quality Control run
      Returns:
      the results table with the QC metrics
    • showTrainingGraph

      public void showTrainingGraph(boolean show, boolean save)
      Displays a JavaFX graph as a dialog, so you can inspect the Losses per epoch also saves the graph to the QC folder if requested
      Parameters:
      save - boolean deciding whether plot should be saved
    • showTrainingGraph

      public void showTrainingGraph()
      Overloaded method for backwards compatibility.
    • saveTrainingImages

      public void saveTrainingImages()
      Goes through the current project and saves the images and masks to the training and validation directories