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 protected double
cellConstrainScale
protected double
cellExpansion
protected CellposeSetup
cellposeSetup
protected java.util.Collection<qupath.lib.analysis.features.ObjectMeasurements.Compartments>
compartments
protected boolean
constrainToParent
protected java.util.function.Function<qupath.lib.roi.interfaces.ROI,qupath.lib.objects.PathObject>
creatorFun
protected boolean
doLog
protected qupath.lib.objects.classes.PathClass
globalPathClass
protected OpCreators.TileOpCreator
globalPreprocess
protected boolean
ignoreCellOverlaps
protected java.util.Collection<qupath.lib.analysis.features.ObjectMeasurements.Measurements>
measurements
protected boolean
measureShape
protected java.lang.String
model
protected java.io.File
modelDirectory
protected qupath.opencv.ops.ImageDataOp
op
protected java.lang.Integer
overlap
protected java.util.LinkedHashMap<java.lang.String,java.lang.String>
parameters
protected double
pixelSize
protected java.util.List<qupath.opencv.ops.ImageOp>
preprocess
protected double
simplifyDistance
protected int
tileHeight
protected int
tileWidth
protected java.io.File
trainDirectory
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 imagesstatic OpCreators.ImageNormalizationBuilder
imageNormalizationBuilder()
Build a normalization op that can be based upon the entire (2D) image, rather than only local tiles.void
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
-
doLog
protected boolean doLog
-
simplifyDistance
protected double simplifyDistance
-
op
protected qupath.opencv.ops.ImageDataOp op
-
globalPreprocess
protected OpCreators.TileOpCreator globalPreprocess
-
preprocess
protected java.util.List<qupath.opencv.ops.ImageOp> preprocess
-
pixelSize
protected double pixelSize
-
cellExpansion
protected double cellExpansion
-
cellConstrainScale
protected double cellConstrainScale
-
ignoreCellOverlaps
protected 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 boolean constrainToParent
-
tileWidth
protected int tileWidth
-
tileHeight
protected int tileHeight
-
measureShape
protected 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
-
cellposeSetup
protected CellposeSetup cellposeSetup
-
parameters
protected java.util.LinkedHashMap<java.lang.String,java.lang.String> parameters
-
model
protected java.lang.String model
-
overlap
protected java.lang.Integer overlap
-
modelDirectory
protected java.io.File modelDirectory
-
trainDirectory
protected java.io.File trainDirectory
-
valDirectory
protected java.io.File valDirectory
-
-
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:
-
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:
-
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
-
-