Package qupath.ext.biop.cellpose
Class Cellpose2D
- java.lang.Object
-
- qupath.ext.biop.cellpose.Cellpose2D
-
public class Cellpose2D extends java.lang.Object
Dense object detection based on the following publication and codeStringer, 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/cellposeThe 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 Summary
Fields Modifier and Type Field Description java.lang.Integer
batchSize
protected java.lang.Double
cellConstrainScale
protected java.lang.Double
cellExpansion
protected CellposeSetup
cellposeSetup
protected java.lang.Integer
channel1
protected java.lang.Integer
channel2
protected java.util.Collection<qupath.lib.analysis.features.ObjectMeasurements.Compartments>
compartments
protected java.lang.Boolean
constrainToParent
protected java.util.function.Function<qupath.lib.roi.interfaces.ROI,qupath.lib.objects.PathObject>
creatorFun
protected java.lang.Double
diameter
protected java.lang.Boolean
doCluster
protected java.lang.Boolean
excludeEdges
protected java.lang.Double
flowThreshold
protected qupath.lib.objects.classes.PathClass
globalPathClass
protected java.lang.Boolean
ignoreCellOverlaps
protected java.lang.Boolean
invert
protected java.lang.Double
iouThreshold
java.lang.Double
learningRate
protected java.lang.Double
maskThreshold
protected java.util.Collection<qupath.lib.analysis.features.ObjectMeasurements.Measurements>
measurements
protected java.lang.Boolean
measureShape
protected java.lang.Integer
minTrainMasks
protected java.lang.String
model
protected java.io.File
modelDirectory
protected java.lang.Integer
nEpochs
protected qupath.opencv.ops.ImageDataOp
op
protected java.lang.Integer
overlap
protected java.lang.Double
pixelSize
double
simplifyDistance
protected java.lang.Integer
tileHeight
protected java.lang.Integer
tileWidth
protected java.io.File
trainDirectory
protected java.lang.Boolean
useGPU
protected java.lang.Boolean
useOmnipose
protected java.io.File
valDirectory
-
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 predictionij.measure.ResultsTable
getQCResults()
Get the results table associated with the Quality Control runjava.io.File
getTrainingDirectory()
The directory that was used for saving the training imagesij.measure.ResultsTable
getTrainingResults()
Returns a parsed version of the cellpose log as a ResultsTable with columns Epoch, Time, Loss, Loss Test and LRjava.io.File
getValidationDirectory()
The directory that was used for saving the validation imagesvoid
saveTrainingImages()
Save training images for the projectvoid
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 requestedjava.io.File
train()
Executes the cellpose training by 1.
-
-
-
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
-
minTrainMasks
protected java.lang.Integer minTrainMasks
-
cellposeSetup
protected CellposeSetup cellposeSetup
-
useGPU
protected java.lang.Boolean useGPU
-
-
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
-
builder
public static CellposeBuilder builder(java.io.File builderPath)
Load a previously serialized builder. SeeCellposeBuilder(File)
andCellposeBuilder.saveBuilder(String)
- Parameters:
builderPath
- path to the builder JSON file.- Returns:
- this builder
-
getTrainingDirectory
public java.io.File getTrainingDirectory()
The directory that was used for saving the training images- Returns:
-
getValidationDirectory
public java.io.File getValidationDirectory()
The directory that was used for saving the validation images- Returns:
-
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 objectparents
- 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 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()
Save training images for the project
-
-