Package qupath.opencv.ml.pixel
Class PixelClassifierTools
java.lang.Object
qupath.opencv.ml.pixel.PixelClassifierTools
Helper methods for working with pixel classification.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic enumOptions when creating objects from a pixel classifier.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic booleanaddMeasurements(Collection<? extends PathObject> objectsToMeasure, PixelClassificationMeasurementManager manager, String measurementID) Add measurements to specified objects from aPixelClassificationMeasurementManager.static booleanaddMeasurementsToSelectedObjects(ImageData<BufferedImage> imageData, PixelClassifier classifier, String measurementID) Add measurements to selected objects based upon the output of aPixelClassifier.static voidclassifyCellsByCentroid(ImageData<BufferedImage> imageData, PixelClassifier classifier, boolean preferNucleusROI) Classify cells according to the prediction of the pixel corresponding to the cell centroid using aPixelClassifier.static voidclassifyDetectionsByCentroid(ImageData<BufferedImage> imageData, PixelClassifier classifier) Classify detections according to the prediction of the pixel corresponding to the detection centroid using aPixelClassifier.static voidclassifyObjectsByCentroid(ImageData<BufferedImage> imageData, PixelClassifier classifier, Collection<PathObject> pathObjects, boolean preferNucleusROI) Classify objects according to the prediction of the pixel corresponding to the object's ROI centroid using aPixelClassifier.static voidclassifyObjectsByCentroid(ImageServer<BufferedImage> classifierServer, Collection<PathObject> pathObjects, boolean preferNucleusROI) Apply classification from a server to a collection of objects.static booleancreateAnnotationsFromPixelClassifier(ImageData<BufferedImage> imageData, PixelClassifier classifier, double minArea, double minHoleArea, PixelClassifierTools.CreateObjectOptions... options) Create annotation objects based upon the output of a pixel classifier, applied to selected objects.static booleancreateAnnotationsFromPixelClassifier(PathObjectHierarchy hierarchy, ImageServer<BufferedImage> classifierServer, double minArea, double minHoleArea, PixelClassifierTools.CreateObjectOptions... options) Create annotation objects based upon anImageServerthat provides classification or probability output, applied to selected objects.static booleancreateDetectionsFromPixelClassifier(ImageData<BufferedImage> imageData, PixelClassifier classifier, double minArea, double minHoleArea, PixelClassifierTools.CreateObjectOptions... options) Create detection objects based upon the output of a pixel classifier, applied to selected objects.static booleancreateDetectionsFromPixelClassifier(PathObjectHierarchy hierarchy, ImageServer<BufferedImage> classifierServer, double minArea, double minHoleArea, PixelClassifierTools.CreateObjectOptions... options) Create detection objects based upon anImageServerthat provides classification or probability output, applied to selected objects.createMeasurementManager(ImageData<BufferedImage> imageData, PixelClassifier classifier) Create aPixelClassificationMeasurementManagerthat can be used to generate measurements from applying a pixel classifier to an image.createMeasurementManager(ImageServer<BufferedImage> classifierServer) Create aPixelClassificationMeasurementManagerthat can be used to generate measurements from anImageServerwhere pixels provide classification or probability information.static Collection<PathObject> createObjectsFromPixelClassifier(ImageServer<BufferedImage> server, Map<Integer, PathClass> labels, ROI roi, Function<ROI, ? extends PathObject> creator, double minArea, double minHoleArea, boolean doSplit) Create objects based upon anImageServerthat provides classification or probability output.static booleancreateObjectsFromPredictions(ImageServer<BufferedImage> server, PathObjectHierarchy hierarchy, Collection<PathObject> selectedObjects, Function<ROI, ? extends PathObject> creator, double minArea, double minHoleArea, PixelClassifierTools.CreateObjectOptions... options) Create objects from an image (usually created with a pixel classifier) where values represent classifications or predictions.static ImageServer<BufferedImage> createPixelClassificationServer(ImageData<BufferedImage> imageData, PixelClassifier classifier) Create anImageServerthat displays the results of applying aPixelClassifierto an image.static ImageServer<BufferedImage> createPixelClassificationServer(ImageData<BufferedImage> imageData, PixelClassifier classifier, String id, ColorModel colorModel, boolean cacheAllTiles) Create anImageServerthat displays the results of applying aPixelClassifierto an image.static ImageServer<BufferedImage> createThresholdServer(ImageServer<BufferedImage> server, int channel, double threshold, PathClass below, PathClass aboveEquals) Create a newImageServerby applying a threshold to one channel of another server.static ImageServer<BufferedImage> createThresholdServer(ImageServer<BufferedImage> server, Map<Integer, ? extends Number> thresholds, PathClass below, PathClass aboveEquals) Create a newImageServerby applying a threshold to one or more channels of another server.static intgetClassification(ImageServer<BufferedImage> server, int x, int y, int z, int t) Request the classification for a specific pixel.
- 
Constructor Details- 
PixelClassifierToolspublic PixelClassifierTools()
 
- 
- 
Method Details- 
createDetectionsFromPixelClassifierpublic static boolean createDetectionsFromPixelClassifier(PathObjectHierarchy hierarchy, ImageServer<BufferedImage> classifierServer, double minArea, double minHoleArea, PixelClassifierTools.CreateObjectOptions... options) throws IOException Create detection objects based upon anImageServerthat provides classification or probability output, applied to selected objects. If no objects are selected, objects are created across the entire image.- Parameters:
- hierarchy-
- classifierServer-
- minArea- the minimum area of connected regions to retain
- minHoleArea- the minimum area of connected 'hole' regions to retain
- options- additional options to control how objects are created
- Returns:
- true if changes were made to the hierarchy, false otherwise
- Throws:
- IOException
 
- 
createDetectionsFromPixelClassifierpublic static boolean createDetectionsFromPixelClassifier(ImageData<BufferedImage> imageData, PixelClassifier classifier, double minArea, double minHoleArea, PixelClassifierTools.CreateObjectOptions... options) throws IOException Create detection objects based upon the output of a pixel classifier, applied to selected objects. If no objects are selected, objects are created across the entire image.- Parameters:
- imageData- the original image data, which will be the input to the pixel classifier
- classifier- the pixel classifier
- minArea- the minimum area of connected regions to retain
- minHoleArea- the minimum area of connected 'hole' regions to retain
- options- additional options to control how objects are created
- Returns:
- true if changes were made to the hierarchy, false otherwise
- Throws:
- IOException
 
- 
createObjectsFromPredictionspublic static boolean createObjectsFromPredictions(ImageServer<BufferedImage> server, PathObjectHierarchy hierarchy, Collection<PathObject> selectedObjects, Function<ROI, ? extends PathObject> creator, double minArea, double minHoleArea, PixelClassifierTools.CreateObjectOptions... options) throws IOExceptionCreate objects from an image (usually created with a pixel classifier) where values represent classifications or predictions.- Parameters:
- server- the image to threshold
- hierarchy- the hierarchy to which the objects should be added
- selectedObjects- the selected objects, if the classification should be constrained to these
- creator- function to create an object of the required type
- minArea- the minimum size of a connected region to retain, in calibrated units
- minHoleArea- the minimum size of a hole to retain, in calibrated units
- options- additional options to control how objects are created
- Returns:
- true if the command ran successfully to completion, false otherwise.
- Throws:
- IOException
- See Also:
 
- 
createAnnotationsFromPixelClassifierpublic static boolean createAnnotationsFromPixelClassifier(ImageData<BufferedImage> imageData, PixelClassifier classifier, double minArea, double minHoleArea, PixelClassifierTools.CreateObjectOptions... options) throws IOException Create annotation objects based upon the output of a pixel classifier, applied to selected objects. If no objects are selected, objects are created across the entire image.- Parameters:
- imageData- the original image data, which will be the input to the pixel classifier
- classifier- the pixel classifier
- minArea- the minimum area of connected regions to retain
- minHoleArea- the minimum area of connected 'hole' regions to retain
- options- additional options to control how objects are created
- Returns:
- true if changes were made to the hierarchy, false otherwise
- Throws:
- IOException
 
- 
createAnnotationsFromPixelClassifierpublic static boolean createAnnotationsFromPixelClassifier(PathObjectHierarchy hierarchy, ImageServer<BufferedImage> classifierServer, double minArea, double minHoleArea, PixelClassifierTools.CreateObjectOptions... options) throws IOException Create annotation objects based upon anImageServerthat provides classification or probability output, applied to selected objects. If no objects are selected, objects are created across the entire image.- Parameters:
- hierarchy-
- classifierServer-
- minArea- the minimum area of connected regions to retain
- minHoleArea- the minimum area of connected 'hole' regions to retain
- options- additional options to control how objects are created
- Returns:
- true if changes were made to the hierarchy, false otherwise
- Throws:
- IOException
 
- 
createObjectsFromPixelClassifierpublic static Collection<PathObject> createObjectsFromPixelClassifier(ImageServer<BufferedImage> server, Map<Integer, PathClass> labels, ROI roi, Function<ROI, throws IOException? extends PathObject> creator, double minArea, double minHoleArea, boolean doSplit) Create objects based upon anImageServerthat provides classification or probability output.- Parameters:
- server- image server providing pixels from which objects should be created
- labels- classification labels; if null, these will be taken from ImageServer#getMetadata() and all non-ignored classifications will be used. Providing a map makes it possible to explicitly exclude some classifications.
- roi- region of interest in which objects should be created (optional; if null, the entire image is used)
- creator- function to create an object from a ROI (e.g. annotation or detection)
- minArea- minimum area for an object fragment to retain, in calibrated units based on the pixel calibration
- minHoleArea- minimum area for a hole to fill, in calibrated units based on the pixel calibration
- doSplit- if true, split connected regions into separate objects
- Returns:
- the objects created within the ROI
- Throws:
- IOException
 
- 
createPixelClassificationServerpublic static ImageServer<BufferedImage> createPixelClassificationServer(ImageData<BufferedImage> imageData, PixelClassifier classifier) Create anImageServerthat displays the results of applying aPixelClassifierto an image.- Parameters:
- imageData- the image to which the classifier should apply
- classifier- the pixel classifier
- Returns:
- the classification ImageServer
 
- 
createPixelClassificationServerpublic static ImageServer<BufferedImage> createPixelClassificationServer(ImageData<BufferedImage> imageData, PixelClassifier classifier, String id, ColorModel colorModel, boolean cacheAllTiles) Create anImageServerthat displays the results of applying aPixelClassifierto an image.- Parameters:
- imageData- the image to which the classifier should apply
- classifier- the pixel classifier
- id- an ID to use for the- ImageServer; this may be null, in which case an ID will be derived (if possible from a JSON representation of the classifier)
- colorModel- optional colormodel for the classifier (may be null to use the default)
- cacheAllTiles- optionally request that all tiles are computed immediately as the classifier is created. This is useful for images that are 'small' and where the classification can comfortably be held in RAM.
- Returns:
- the classification ImageServer
 
- 
createThresholdServerpublic static ImageServer<BufferedImage> createThresholdServer(ImageServer<BufferedImage> server, Map<Integer, ? extends Number> thresholds, PathClass below, PathClass aboveEquals) Create a newImageServerby applying a threshold to one or more channels of another server. This is particularly useful where one channel represents intensities to threshold, and one channel should be used as a mask.- Parameters:
- server- the server to threshold
- thresholds- map between channel numbers (zero-based) and thresholds
- below- the classification for pixels whose values are below the threshold in any channel
- aboveEquals- the classification for pixels whose values are greater than or equal to the threshold in all channels
- Returns:
- the thresholded server
 
- 
createThresholdServerpublic static ImageServer<BufferedImage> createThresholdServer(ImageServer<BufferedImage> server, int channel, double threshold, PathClass below, PathClass aboveEquals) Create a newImageServerby applying a threshold to one channel of another server.- Parameters:
- server- the server to threshold
- channel- the channel to threshold (zero-based)
- threshold- the threshold value to apply
- below- the classification for pixels below the threshold (must not be null)
- aboveEquals- the classification for pixels greater than or equal to the threshold (must not be null)
- Returns:
- the thresholded server
 
- 
createMeasurementManagerpublic static PixelClassificationMeasurementManager createMeasurementManager(ImageData<BufferedImage> imageData, PixelClassifier classifier) Create aPixelClassificationMeasurementManagerthat can be used to generate measurements from applying a pixel classifier to an image.- Parameters:
- imageData- the image to which the classifier should be applied
- classifier- the pixel classifier
- Returns:
- the PixelClassificationMeasurementManager
 
- 
createMeasurementManagerpublic static PixelClassificationMeasurementManager createMeasurementManager(ImageServer<BufferedImage> classifierServer) Create aPixelClassificationMeasurementManagerthat can be used to generate measurements from anImageServerwhere pixels provide classification or probability information.- Parameters:
- classifierServer- the classification image server
- Returns:
- the PixelClassificationMeasurementManager
 
- 
addMeasurementsToSelectedObjectspublic static boolean addMeasurementsToSelectedObjects(ImageData<BufferedImage> imageData, PixelClassifier classifier, String measurementID) Add measurements to selected objects based upon the output of aPixelClassifier.- Parameters:
- imageData- the image data, which will be input to the classifier and which contains the selected objects to measure. If no objects are selected, measurements will be applied to the entire image.
- classifier- the pixel classifier
- measurementID- identifier that is prepended to measurement names, to make these identifiable later (optional; may be null)
- Returns:
- true if measurements were added, false otherwise
 
- 
addMeasurementspublic static boolean addMeasurements(Collection<? extends PathObject> objectsToMeasure, PixelClassificationMeasurementManager manager, String measurementID) Add measurements to specified objects from aPixelClassificationMeasurementManager.- Parameters:
- objectsToMeasure- the objects to measure.
- manager- the manager used to generate measurements
- measurementID- identifier that is prepended to measurement names, to make these identifiable later (optional; may be null)
- Returns:
- true if measurements were added, false otherwise
 
- 
classifyObjectsByCentroidpublic static void classifyObjectsByCentroid(ImageServer<BufferedImage> classifierServer, Collection<PathObject> pathObjects, boolean preferNucleusROI) Apply classification from a server to a collection of objects.- Parameters:
- classifierServer- an- ImageServerwith output type
- pathObjects-
- preferNucleusROI-
 
- 
getClassificationpublic static int getClassification(ImageServer<BufferedImage> server, int x, int y, int z, int t) throws IOException Request the classification for a specific pixel.If the output for the server is ImageServerMetadata.ChannelType.PROBABILITYand only one channel is available, the return value will be -1 if the probability is less than 0.5 (or 127.5 if 8-bit).- Parameters:
- server-
- x-
- y-
- z-
- t-
- Returns:
- Throws:
- IOException
 
- 
classifyCellsByCentroidpublic static void classifyCellsByCentroid(ImageData<BufferedImage> imageData, PixelClassifier classifier, boolean preferNucleusROI) Classify cells according to the prediction of the pixel corresponding to the cell centroid using aPixelClassifier.- Parameters:
- imageData- the- ImageDatacontaining the cells
- classifier- the classifier
- preferNucleusROI- whether to use the nucleus ROI (if available) rather than the cell ROI
 
- 
classifyDetectionsByCentroidpublic static void classifyDetectionsByCentroid(ImageData<BufferedImage> imageData, PixelClassifier classifier) Classify detections according to the prediction of the pixel corresponding to the detection centroid using aPixelClassifier. If the detections are cells, the nucleus ROI is used where possible.- Parameters:
- imageData- the- ImageDatacontaining the cells
- classifier- the classifier
 
- 
classifyObjectsByCentroidpublic static void classifyObjectsByCentroid(ImageData<BufferedImage> imageData, PixelClassifier classifier, Collection<PathObject> pathObjects, boolean preferNucleusROI) Classify objects according to the prediction of the pixel corresponding to the object's ROI centroid using aPixelClassifier.- Parameters:
- imageData- the- ImageDatacontaining the cells
- classifier- the classifier
- pathObjects- the objects to classify
- preferNucleusROI- use the nucleus ROI in the case of cells; ignored for all other object types
 
 
-