Class CellposeBuilder
- java.lang.Object
-
- qupath.ext.biop.cellpose.CellposeBuilder
-
public class CellposeBuilder extends java.lang.Object
This class will contain all parameters that are usable by cellpose
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CellposeBuilder
batchSize(int batchSize)
Defines the batch size for trainingCellpose2D
build()
Create aCellpose2D
, all ready for detection.CellposeBuilder
cellConstrainScale(double scale)
Constrain any cell expansion defined usingcellExpansion(double)
based upon the nucleus size.CellposeBuilder
cellExpansion(double distance)
Amount by which to expand detected nuclei to approximate the cell area.CellposeBuilder
cellposeChannels(int channel1, int channel2)
Sets the channels to use by cellpose, in case there is an issue with the order or the number of exported channelsCellposeBuilder
channels(int... channels)
Specify channels.CellposeBuilder
channels(java.lang.String... channels)
Specify channels by name.CellposeBuilder
channels(qupath.lib.images.servers.ColorTransforms.ColorTransform... channels)
Define the channels (or color transformers) to apply to the input image.CellposeBuilder
classify(java.lang.String pathClassName)
Request that a classification is applied to all created objects.CellposeBuilder
classify(qupath.lib.objects.classes.PathClass pathClass)
Request that a classification is applied to all created objects.CellposeBuilder
clusterDBSCAN()
DBSCAN clustering.CellposeBuilder
compartments(qupath.lib.analysis.features.ObjectMeasurements.Compartments... compartments)
Specify the compartments within which intensity measurements are made.CellposeBuilder
constrainToParent(boolean constrainToParent)
If true, constrain nuclei and cells to any parent annotation (default is true).CellposeBuilder
createAnnotations()
Create annotations rather than detections (the default).CellposeBuilder
diameter(double diameter)
The extimated diameter of the objects to detect.CellposeBuilder
epochs(int nEpochs)
Defines the number of epochs for trainingCellposeBuilder
excludeEdges()
Exclude on edges.CellposeBuilder
flowThreshold(double threshold)
Flow threshold to apply for detection, between 0 and 1.CellposeBuilder
ignoreCellOverlaps(boolean ignore)
If true, ignore overlaps when computing cell expansion.CellposeBuilder
inputAdd(double... values)
Add an offset as a preprocessing step.CellposeBuilder
inputScale(double... values)
Multiply by a scale factor as a preprocessing step.CellposeBuilder
invert()
Inverts the image channels within cellpose.CellposeBuilder
iou(double iouThreshold)
Select the Intersection over Union (IoU) cutoff for excluding overlapping detections.CellposeBuilder
learningRate(double learningRate)
Defines the learning rateCellposeBuilder
maskThreshold(double threshold)
Probability threshold to apply for detection, between 0 and 1.CellposeBuilder
measureIntensity()
Request default intensity measurements are made for all available cell compartments.CellposeBuilder
measureIntensity(java.util.Collection<qupath.lib.analysis.features.ObjectMeasurements.Measurements> measurements)
Request specified intensity measurements are made for all available cell compartments.CellposeBuilder
measureShape()
Request shape measurements are made for the detected cell or nucleus.CellposeBuilder
modelDirectory(java.io.File modelDir)
Define the directory where the newly trained model should be savedCellposeBuilder
normalizePercentiles(double min, double max)
Apply percentile normalization to the input image channels.CellposeBuilder
pixelSize(double pixelSize)
Resolution at which the cell detection should be run.CellposeBuilder
preprocess(qupath.opencv.ops.ImageOp... ops)
Add preprocessing operations, if required.CellposeBuilder
saveBuilder(java.lang.String name)
Save this builder as a JSON file in order to be able to reuse it in placeCellposeBuilder
tileSize(int tileSize)
Size in pixels of a tile used for detection.CellposeBuilder
tileSize(int tileWidth, int tileHeight)
Size in pixels of a tile used for detection.CellposeBuilder
useGPU()
Use a GPU for prediction or training.CellposeBuilder
useOmnipose()
Use Omnipose implementation: Adds --omni flag to command
-
-
-
Method Detail
-
pixelSize
public CellposeBuilder pixelSize(double pixelSize)
Resolution at which the cell detection should be run. The units depend upon thePixelCalibration
of the input image.The default is to use the full resolution of the input image.
For an image calibrated in microns, the recommended default is approximately 0.5.
- Parameters:
pixelSize
- Pixel size in microns for the analysis- Returns:
- this builder
-
channels
public CellposeBuilder channels(int... channels)
Specify channels. Useful for detecting nuclei for one channel within a multi-channel image, or potentially for trained models that support multi-channel input.- Parameters:
channels
- 0-based indices of the channels to use- Returns:
- this builder
-
channels
public CellposeBuilder channels(java.lang.String... channels)
Specify channels by name. Useful for detecting nuclei for one channel within a multi-channel image, or potentially for trained models that support multi-channel input.- Parameters:
channels
- 0-based indices of the channels to use- Returns:
- this builder
-
channels
public CellposeBuilder channels(qupath.lib.images.servers.ColorTransforms.ColorTransform... channels)
Define the channels (or color transformers) to apply to the input image.This makes it possible to supply color deconvolved channels, for example.
- Parameters:
channels
- ColorTransform channels to use, typically only used internally- Returns:
- this builder
-
preprocess
public CellposeBuilder preprocess(qupath.opencv.ops.ImageOp... ops)
Add preprocessing operations, if required.- Parameters:
ops
- series of ImageOps to apply to this server before saving the images- Returns:
- this builder
-
normalizePercentiles
public CellposeBuilder normalizePercentiles(double min, double max)
Apply percentile normalization to the input image channels.Note that this can be used in combination with
preprocess(ImageOp...)
, in which case the order in which the operations are applied depends upon the order in which the methods of the builder are called.Warning! This is applied on a per-tile basis. This can result in artifacts and false detections without background/constant regions. Consider using
inputAdd(double...)
andinputScale(double...)
as alternative normalization strategies, if appropriate constants can be determined to apply globally.- Parameters:
min
- minimum percentilemax
- maximum percentile- Returns:
- this builder
-
inputAdd
public CellposeBuilder inputAdd(double... values)
Add an offset as a preprocessing step. Usually the value will be negative. Along withinputScale(double...)
this can be used as an alternative (global) normalization.Note that this can be used in combination with
preprocess(ImageOp...)
, in which case the order in which the operations are applied depends upon the order in which the methods of the builder are called.- Parameters:
values
- either a single value to add to all channels, or an array of values equal to the number of channels- Returns:
- this builder
-
inputScale
public CellposeBuilder inputScale(double... values)
Multiply by a scale factor as a preprocessing step. Along withinputAdd(double...)
this can be used as an alternative (global) normalization.Note that this can be used in combination with
preprocess(ImageOp...)
, in which case the order in which the operations are applied depends upon the order in which the methods of the builder are called.- Parameters:
values
- either a single value to add to all channels, or an array of values equal to the number of channels- Returns:
- this builder
-
tileSize
public CellposeBuilder tileSize(int tileSize)
Size in pixels of a tile used for detection. Note that tiles are independently normalized, and therefore tiling can impact the results. Default is 1024.- Parameters:
tileSize
- if the regions must be broken down, how large should the tiles be, in pixels (width and height)- Returns:
- this builder
-
tileSize
public CellposeBuilder tileSize(int tileWidth, int tileHeight)
Size in pixels of a tile used for detection. Note that tiles are independently normalized, and therefore tiling can impact the results. Default is 1024.- Parameters:
tileWidth
- if the regions must be broken down, how large should the tiles be (width), in pixelstileHeight
- if the regions must be broken down, how large should the tiles be (height), in pixels- Returns:
- this builder
-
cellposeChannels
public CellposeBuilder cellposeChannels(int channel1, int channel2)
Sets the channels to use by cellpose, in case there is an issue with the order or the number of exported channels- Parameters:
channel1
- the main channelchannel2
- the second channel (typically nuclei)- Returns:
- this builder
-
maskThreshold
public CellposeBuilder maskThreshold(double threshold)
Probability threshold to apply for detection, between 0 and 1.- Parameters:
threshold
- probability threshold between 0 and 1 (default 0.5)- Returns:
- this builder
-
flowThreshold
public CellposeBuilder flowThreshold(double threshold)
Flow threshold to apply for detection, between 0 and 1.- Parameters:
threshold
- flow threshold (default 0.0)- Returns:
- this builder
-
diameter
public CellposeBuilder diameter(double diameter)
The extimated diameter of the objects to detect. Cellpose will further downsample the images in order to match their expected diameter- Parameters:
diameter
- in pixels- Returns:
- this builder
-
invert
public CellposeBuilder invert()
Inverts the image channels within cellpose. Adds the --invert flag to the command- Returns:
- this builder
-
useOmnipose
public CellposeBuilder useOmnipose()
Use Omnipose implementation: Adds --omni flag to command- Returns:
- this builder
-
excludeEdges
public CellposeBuilder excludeEdges()
Exclude on edges. Adds --exclude_on_edges flag to command- Returns:
- this builder
-
clusterDBSCAN
public CellposeBuilder clusterDBSCAN()
DBSCAN clustering. Reduces oversegmentation of thin features, adds --cluster flag to command.- Returns:
- this builder
-
useGPU
public CellposeBuilder useGPU()
Use a GPU for prediction or training. Whether this works or nt will depend on your cellpose environment- Returns:
- this Builder
-
modelDirectory
public CellposeBuilder modelDirectory(java.io.File modelDir)
Define the directory where the newly trained model should be saved- Parameters:
modelDir
- a directory (does not need to exist yet) where to save the cellpose model- Returns:
- this Builder
-
epochs
public CellposeBuilder epochs(int nEpochs)
Defines the number of epochs for training- Parameters:
nEpochs
- number of epochs for training- Returns:
- this Builder
-
learningRate
public CellposeBuilder learningRate(double learningRate)
Defines the learning rate- Parameters:
learningRate
- learning rate per epoch- Returns:
- this Builder
-
batchSize
public CellposeBuilder batchSize(int batchSize)
Defines the batch size for training- Parameters:
batchSize
- batch size for training- Returns:
- this Builder
-
iou
public CellposeBuilder iou(double iouThreshold)
Select the Intersection over Union (IoU) cutoff for excluding overlapping detections. Default of 0.1 is good enough- Parameters:
iouThreshold
- distance threshold- Returns:
- this builder
-
cellExpansion
public CellposeBuilder cellExpansion(double distance)
Amount by which to expand detected nuclei to approximate the cell area. Units are the same as for thePixelCalibration
of the input image.Warning! This is rather experimental, relying heavily on JTS and a convoluted method of resolving overlaps using a Voronoi tessellation.
In short, be wary.
- Parameters:
distance
- cell expansion distance in microns- Returns:
- this builder
-
cellConstrainScale
public CellposeBuilder cellConstrainScale(double scale)
Constrain any cell expansion defined usingcellExpansion(double)
based upon the nucleus size. Only meaningful for values > 1; the nucleus is expanded according to the scale factor, and used to define the maximum permitted cell expansion.- Parameters:
scale
- a number to multiply each pixel in the image by- Returns:
- this builder
-
classify
public CellposeBuilder classify(qupath.lib.objects.classes.PathClass pathClass)
Request that a classification is applied to all created objects.- Parameters:
pathClass
- the PathClass of all detections resulting from this run- Returns:
- this builder
-
classify
public CellposeBuilder classify(java.lang.String pathClassName)
Request that a classification is applied to all created objects. This is a convenience method that get aPathClass
fromPathClassFactory
.- Parameters:
pathClassName
- the name of the PathClass for all detections- Returns:
- this builder
-
ignoreCellOverlaps
public CellposeBuilder ignoreCellOverlaps(boolean ignore)
If true, ignore overlaps when computing cell expansion.- Parameters:
ignore
- ignore overlaps when computing cell expansion.- Returns:
- this builder
-
constrainToParent
public CellposeBuilder constrainToParent(boolean constrainToParent)
If true, constrain nuclei and cells to any parent annotation (default is true).- Parameters:
constrainToParent
- constrain nuclei and cells to any parent annotation- Returns:
- this builder
-
createAnnotations
public CellposeBuilder createAnnotations()
Create annotations rather than detections (the default). If cell expansion is not zero, the nucleus will be included as a child object.- Returns:
- this builder
-
measureIntensity
public CellposeBuilder measureIntensity()
Request default intensity measurements are made for all available cell compartments.- Returns:
- this builder
-
measureIntensity
public CellposeBuilder measureIntensity(java.util.Collection<qupath.lib.analysis.features.ObjectMeasurements.Measurements> measurements)
Request specified intensity measurements are made for all available cell compartments.- Parameters:
measurements
- the measurements to make- Returns:
- this builder
-
measureShape
public CellposeBuilder measureShape()
Request shape measurements are made for the detected cell or nucleus.- Returns:
- this builder
-
compartments
public CellposeBuilder compartments(qupath.lib.analysis.features.ObjectMeasurements.Compartments... compartments)
Specify the compartments within which intensity measurements are made. Only effective ifmeasureIntensity()
andcellExpansion(double)
have been selected.- Parameters:
compartments
- cell compartments for intensity measurements- Returns:
- this builder
-
saveBuilder
public CellposeBuilder saveBuilder(java.lang.String name)
Save this builder as a JSON file in order to be able to reuse it in place- Parameters:
name
- // A name to append to the JSON file. Keep it meaningful for your needs- Returns:
-
build
public Cellpose2D build()
Create aCellpose2D
, all ready for detection.- Returns:
- a Cellpose2D object, ready to be run
-
-