Package qupath.opencv.dnn
Class DnnObjectClassifier
java.lang.Object
qupath.lib.classifiers.object.AbstractObjectClassifier<BufferedImage>
qupath.opencv.dnn.DnnObjectClassifier
- All Implemented Interfaces:
ObjectClassifier<BufferedImage>,UriResource
public class DnnObjectClassifier
extends AbstractObjectClassifier<BufferedImage>
implements UriResource
Initial implementation of a patch-based
ObjectClassifier using an OpenCV-compatible DNN.
Warning! This implementation is likely to change in the future.
-
Field Summary
Fields inherited from interface qupath.lib.classifiers.object.ObjectClassifier
PROJECT_LOCATION -
Constructor Summary
ConstructorsConstructorDescriptionDnnObjectClassifier(PathObjectFilter filter, DnnModel model, List<PathClass> pathClasses, int width, int height, double requestedPixelSize) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionintclassifyObjects(ImageData<BufferedImage> imageData, Collection<? extends PathObject> pathObjects, boolean resetExistingClass) Classify the objects in the specified collection.getMissingFeatures(ImageData<BufferedImage> imageData, Collection<? extends PathObject> pathObjects) Check for missing features, returning the names and number of input objects missing the specified features.Get the classifications set by this classifier.getURIs()Get all the URIs required for this resource.protected inttryToClassify(List<? extends PathObject> pathObjects, ImageServer<BufferedImage> server, double downsample, IntFunction<PathClass> classifier) Try to classify a batch of objects.protected booleantryToClassify(PathObject pathObject, ImageServer<BufferedImage> server, double downsample, IntFunction<PathClass> classifier) booleanupdateURIs(Map<URI, URI> replacements) Update the specified URIs.Methods inherited from class qupath.lib.classifiers.object.AbstractObjectClassifier
classifyObjects, getCompatibleObjectsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface qupath.lib.io.UriResource
getUris, updateUris
-
Constructor Details
-
DnnObjectClassifier
public DnnObjectClassifier(PathObjectFilter filter, DnnModel model, List<PathClass> pathClasses, int width, int height, double requestedPixelSize) Constructor.- Parameters:
filter- filter to select compatible optionsmodel- wrapper for the DNN model, including optional preprocessingpathClasses- ordered list of classifications, corresponding to the predicted labelswidth- patch width, in pixels, at the classification sizeheight- patch height, in pixels, at the classification siderequestedPixelSize- requested pixel size, in calibrated units, used to calculate the downsample value
-
-
Method Details
-
getPathClasses
Description copied from interface:ObjectClassifierGet the classifications set by this classifier.- Specified by:
getPathClassesin interfaceObjectClassifier<BufferedImage>- Returns:
-
classifyObjects
public int classifyObjects(ImageData<BufferedImage> imageData, Collection<? extends PathObject> pathObjects, boolean resetExistingClass) Description copied from interface:ObjectClassifierClassify the objects in the specified collection. This provides a means to specify exactly which objects should be classified, avoiding reliance onObjectClassifier.getCompatibleObjects(ImageData).Note: this method does not typically fire any hierarchy change/object classification events. It is up to the caller to fire these events if required.
- Specified by:
classifyObjectsin interfaceObjectClassifier<BufferedImage>- Parameters:
imageData- data that may or may not be required for classification depending upon how features are extractedpathObjects- the objects to classifyresetExistingClass-- Returns:
- the number of objects whose classification was changed.
- See Also:
-
tryToClassify
protected boolean tryToClassify(PathObject pathObject, ImageServer<BufferedImage> server, double downsample, IntFunction<PathClass> classifier) -
tryToClassify
protected int tryToClassify(List<? extends PathObject> pathObjects, ImageServer<BufferedImage> server, double downsample, IntFunction<PathClass> classifier) Try to classify a batch of objects.- Parameters:
pathObjects-server-downsample-classifier-- Returns:
- number of classified objects
-
getMissingFeatures
public Map<String,Integer> getMissingFeatures(ImageData<BufferedImage> imageData, Collection<? extends PathObject> pathObjects) Description copied from interface:ObjectClassifierCheck for missing features, returning the names and number of input objects missing the specified features. This is useful as a warning that the input for the classifier may not be valid. Default implementation returns an empty map; however, implementations should attempt to provide a meaningful output if possible. Features that are not missing should not be included in the output.- Specified by:
getMissingFeaturesin interfaceObjectClassifier<BufferedImage>- Parameters:
imageData- image containing the objects to testpathObjects- objects to test for missing features; if not available,ObjectClassifier.getCompatibleObjects(ImageData)will be called.- Returns:
- a map of feature names and the number of objects missing the corresponding features.
-
getURIs
Description copied from interface:UriResourceGet all the URIs required for this resource. This is often an empty or singleton list.- Specified by:
getURIsin interfaceUriResource- Returns:
- the required URIs
- Throws:
IOException
-
updateURIs
Description copied from interface:UriResourceUpdate the specified URIs.Warning! This should be used sparingly, particularly for objects that are otherwise immutable. It is intended only for correcting paths that have become invalid (e.g. because of files being relocated or transferred between computers) before first use of the object. It should not be used to manipulate an object after construction. Indeed, some implementations may throw an
UnsupportedOperationExceptionif called too late.- Specified by:
updateURIsin interfaceUriResource- Parameters:
replacements- replacement map, where the key gives the current URI and the value gives its replacement.- Returns:
- true if URIs were changed, false otherwise
- Throws:
IOException
-