Package qupath.ext.biop.cellpose
Class Cellpose2D
java.lang.Object
qupath.ext.biop.cellpose.Cellpose2D
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-xAnd
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-4See 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.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected double
protected double
protected CellposeSetup
protected Collection<qupath.lib.analysis.features.ObjectMeasurements.Compartments>
protected boolean
protected Function<qupath.lib.roi.interfaces.ROI,
qupath.lib.objects.PathObject> protected boolean
qupath.opencv.ops.ImageOp
protected qupath.lib.objects.classes.PathClass
protected OpCreators.TileOpCreator
protected boolean
protected Collection<qupath.lib.analysis.features.ObjectMeasurements.Measurements>
protected boolean
protected String
protected File
protected int
protected qupath.opencv.ops.ImageDataOp
protected Integer
protected LinkedHashMap<String,
String> protected double
protected List<qupath.opencv.ops.ImageOp>
protected double
protected int
protected int
boolean
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic CellposeBuilder
Load a previously serialized builder.static CellposeBuilder
Create a builder to customize detection parameters.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.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.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
Get the results table associated with the Quality Control runThe directory that was used for saving the training imagesij.measure.ResultsTable
Returns a parsed version of the cellpose log as a ResultsTable with columns Epoch, Time, Loss, Loss Test and LRThe directory that was used for saving the validation imagesBuild a normalization op that can be based upon the entire (2D) image, rather than only local tiles.void
Goes through the current project and saves the images and masks to the training and validation directoriesvoid
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 requestedtrain()
Executes the cellpose training by 1.
-
Field Details
-
extendChannelOp
public qupath.opencv.ops.ImageOp extendChannelOp -
useGPU
public boolean useGPU -
outputModelName
-
simplifyDistance
protected double simplifyDistance -
op
protected qupath.opencv.ops.ImageDataOp op -
globalPreprocess
-
preprocess
-
pixelSize
protected double pixelSize -
cellExpansion
protected double cellExpansion -
cellConstrainScale
protected double cellConstrainScale -
ignoreCellOverlaps
protected boolean ignoreCellOverlaps -
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
-
measurements
-
cellposeSetup
-
parameters
-
model
-
overlap
-
modelDirectory
-
groundTruthDirectory
-
nThreads
protected int nThreads -
doReadResultsAsynchronously
protected boolean doReadResultsAsynchronously
-
-
Constructor Details
-
Cellpose2D
public Cellpose2D()
-
-
Method Details
-
builder
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
Load a previously serialized builder. SeeCellposeBuilder(File)
andCellposeBuilder.saveBuilder(String)
- Parameters:
builderPath
- path to the builder JSON file.- Returns:
- this builder
-
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
The directory that was used for saving the training images- Returns:
- the directory
-
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 objectparents
- 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 objectparents
- the parent objects; existing child objects will be removed, and replaced by the detected cells
-
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
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
-