Class Cellpose2D


  • public class Cellpose2D
    extends java.lang.Object
    Dense object detection based on the following publication and code
     Stringer, C., Wang, T., Michaelos, M. et al.
         "Cellpose: a generalist algorithm for cellular segmentation"
         Nat Methods 18, 100–106 (2021). https://doi.org/10.1038/s41592-020-01018-x
     
    See the main repo at https://github.com/mouseland/cellpose

    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.

    • Constructor Summary

      Constructors 
      Constructor Description
      Cellpose2D()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static CellposeBuilder builder​(java.io.File builderPath)
      Load a previously serialized builder.
      static CellposeBuilder builder​(java.lang.String modelPath)
      Create a builder to customize detection parameters.
      void detectObjects​(qupath.lib.images.ImageData<java.awt.image.BufferedImage> imageData, java.util.Collection<? extends qupath.lib.objects.PathObject> parents)
      Detect cells within one or more parent objects, firing update events upon completion.
      java.lang.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
      ij.measure.ResultsTable getQCResults()
      Get the results table associated with the Quality Control run
      ij.measure.ResultsTable getTrainingResults()
      Returns a parsed version of the cellpose log as a ResultsTable with columns Epoch, Time, Loss, Loss Test and LR
      void showTrainingGraph()
      Overloaded method for backwards compatibility.
      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
      java.io.File train()
      Executes the cellpose training by 1.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • learningRate

        public java.lang.Double learningRate
      • batchSize

        public java.lang.Integer batchSize
      • simplifyDistance

        public double simplifyDistance
      • channel1

        protected java.lang.Integer channel1
      • channel2

        protected java.lang.Integer channel2
      • iouThreshold

        protected java.lang.Double iouThreshold
      • maskThreshold

        protected java.lang.Double maskThreshold
      • flowThreshold

        protected java.lang.Double flowThreshold
      • model

        protected java.lang.String model
      • diameter

        protected java.lang.Double diameter
      • op

        protected qupath.opencv.ops.ImageDataOp op
      • pixelSize

        protected java.lang.Double pixelSize
      • cellExpansion

        protected java.lang.Double cellExpansion
      • cellConstrainScale

        protected java.lang.Double cellConstrainScale
      • ignoreCellOverlaps

        protected java.lang.Boolean ignoreCellOverlaps
      • creatorFun

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

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

        protected java.lang.Boolean constrainToParent
      • tileWidth

        protected java.lang.Integer tileWidth
      • tileHeight

        protected java.lang.Integer tileHeight
      • overlap

        protected java.lang.Integer overlap
      • measureShape

        protected java.lang.Boolean measureShape
      • compartments

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

        protected java.util.Collection<qupath.lib.analysis.features.ObjectMeasurements.Measurements> measurements
      • invert

        protected java.lang.Boolean invert
      • useOmnipose

        protected java.lang.Boolean useOmnipose
      • excludeEdges

        protected java.lang.Boolean excludeEdges
      • doCluster

        protected java.lang.Boolean doCluster
      • modelDirectory

        protected java.io.File modelDirectory
      • trainDirectory

        protected java.io.File trainDirectory
      • valDirectory

        protected java.io.File valDirectory
      • nEpochs

        protected java.lang.Integer nEpochs
      • useGPU

        protected java.lang.Boolean useGPU
    • Constructor Detail

      • Cellpose2D

        public Cellpose2D()
    • Method Detail

      • builder

        public static CellposeBuilder builder​(java.lang.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
      • detectObjects

        public void detectObjects​(qupath.lib.images.ImageData<java.awt.image.BufferedImage> imageData,
                                  java.util.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 java.io.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 java.lang.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 teh 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.