Class AbstractDetections

java.lang.Object
qupath.ext.braian.AbstractDetections
Direct Known Subclasses:
ChannelDetections, OverlappingDetections

public abstract class AbstractDetections extends Object
This abstract class defines the interface to handle groups of different cell detections groups. It works by using on "container" annotations, inside which all the cells are grouped. By default, AbstractDetections allows to classify its detections by applying PartialClassifiers.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractDetections(String id, Collection<qupath.lib.objects.classes.PathClass> detectionClasses, qupath.lib.objects.hierarchy.PathObjectHierarchy hierarchy)
    Constructs an object that groups together detections of the same kind.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyClassifiers(List<PartialClassifier> classifiers, qupath.lib.images.ImageData<?> imageData)
    applies a list of classifiers in sequence to the detections of the instance kind.
    protected qupath.lib.objects.PathAnnotationObject
    createContainer(qupath.lib.objects.PathAnnotationObject containerParent, boolean overwrite)
    Creates a duplicate child annotation to be used as container
    boolean
    Two detection objects are functionally the same if they are compatible with each other and they have the same containers
    void
    Updates the internal representation to the current state.
    protected static Stream<qupath.lib.objects.PathDetectionObject>
    getChildrenDetections(qupath.lib.objects.PathAnnotationObject annotation)
     
    List<qupath.lib.objects.PathAnnotationObject>
     
    abstract String
     
    qupath.lib.objects.classes.PathClass
     
    protected static Stream<qupath.lib.objects.PathDetectionObject>
    getDetectionsInside(qupath.lib.objects.PathAnnotationObject annotation, qupath.lib.objects.hierarchy.PathObjectHierarchy hierarchy)
    returns the detections inside the given annotation
    protected static Stream<qupath.lib.objects.PathDetectionObject>
    getDetectionsInside(qupath.lib.roi.interfaces.ROI roi, qupath.lib.objects.hierarchy.PathObjectHierarchy hierarchy)
    returns the detections inside the given ROI
    List<qupath.lib.objects.classes.PathClass>
     
    qupath.lib.objects.classes.PathClass
     
    protected qupath.lib.objects.hierarchy.PathObjectHierarchy
     
     
    Optional<qupath.lib.objects.PathObject>
    getOverlappingObjectIfPresent(qupath.lib.objects.PathObject o)
     
    boolean
    isChannelDetection(qupath.lib.objects.PathObject o, boolean all)
    checks whether the given object is a detection belonging to the instance kind
    protected <T> boolean
    isCompatibleClassifier(qupath.lib.classifiers.object.ObjectClassifier<T> classifier)
     
    boolean
    Check whether two AbstractDetections are compatible.
    boolean
    isContainer(qupath.lib.objects.PathObject o)
     
    boolean
    If there are no detections within the current instance.
    Stream<qupath.lib.objects.PathDetectionObject>
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractDetections

      public AbstractDetections(String id, Collection<qupath.lib.objects.classes.PathClass> detectionClasses, qupath.lib.objects.hierarchy.PathObjectHierarchy hierarchy) throws NoCellContainersFoundException
      Constructs an object that groups together detections of the same kind. To do so, it searches for container annotations of detections having a name compatible with getContainersName()
      Parameters:
      id - identification of this group of detections
      detectionClasses - classifications used to identify the detections
      hierarchy - where to find the detections
      Throws:
      NoCellContainersFoundException - if there is no compatible container in the hierarchy
      See Also:
  • Method Details

    • getDetectionsInside

      protected static Stream<qupath.lib.objects.PathDetectionObject> getDetectionsInside(qupath.lib.objects.PathAnnotationObject annotation, qupath.lib.objects.hierarchy.PathObjectHierarchy hierarchy)
      returns the detections inside the given annotation
      Parameters:
      annotation - where to search the detections
      hierarchy - where to find the detections
      Returns:
      a stream of detections found inside annotations
    • getDetectionsInside

      protected static Stream<qupath.lib.objects.PathDetectionObject> getDetectionsInside(qupath.lib.roi.interfaces.ROI roi, qupath.lib.objects.hierarchy.PathObjectHierarchy hierarchy)
      returns the detections inside the given ROI
      Parameters:
      roi - where to search the detections
      hierarchy - where to find the detections
      Returns:
      a stream of detections found inside annotations
    • getChildrenDetections

      protected static Stream<qupath.lib.objects.PathDetectionObject> getChildrenDetections(qupath.lib.objects.PathAnnotationObject annotation)
    • fireUpdate

      public void fireUpdate() throws NoCellContainersFoundException
      Updates the internal representation to the current state. If a new container of detections is added and overlaps the old containers, it updates the old detections with the new ones. Additionally, it makes sure that the newer containers don't overlap with the old ones.
      If container annotations or detections are touched outside of BraiAn, it's better to call this method.
      Throws:
      NoCellContainersFoundException - if there is no compatible container in the hierarchy
    • isEmpty

      public boolean isEmpty()
      If there are no detections within the current instance.
      If the state was changed outside of this extension, you might need to call fireUpdate() first.
      Returns:
      True, if no detections are found within the current state. False otherwise.
      See Also:
    • getContainers

      public List<qupath.lib.objects.PathAnnotationObject> getContainers()
      Returns:
      the container annotations
    • getHierarchy

      protected qupath.lib.objects.hierarchy.PathObjectHierarchy getHierarchy()
    • getId

      public String getId()
      Returns:
      a string often used to identify detections and their container annotations
    • toStream

      public Stream<qupath.lib.objects.PathDetectionObject> toStream()
      Returns:
      a stream of the given detections, in no particular order
    • getOverlappingObjectIfPresent

      public Optional<qupath.lib.objects.PathObject> getOverlappingObjectIfPresent(qupath.lib.objects.PathObject o)
      Parameters:
      o - the object to search an overlapping detection for
      Returns:
      the detection that overlaps the given object
      See Also:
    • getContainersName

      public abstract String getContainersName()
      Returns:
      the name used by the containers of detections of the instance kind
    • isContainer

      public boolean isContainer(qupath.lib.objects.PathObject o)
      Parameters:
      o - the object to test
      Returns:
      true if the given object is a container of these detections. False otherwise
    • getContainersPathClass

      public qupath.lib.objects.classes.PathClass getContainersPathClass()
      Returns:
      the classification used to indentify containers of detections of the instance kind
    • getDiscardedDetectionsPathClass

      public qupath.lib.objects.classes.PathClass getDiscardedDetectionsPathClass()
      Returns:
      the classification used to identify detections of the instance kind that were discarded
    • getDetectionsPathClasses

      public List<qupath.lib.objects.classes.PathClass> getDetectionsPathClasses()
      Returns:
      the classifications used to identify the detections of the instance kind
    • isChannelDetection

      public boolean isChannelDetection(qupath.lib.objects.PathObject o, boolean all)
      checks whether the given object is a detection belonging to the instance kind
      Parameters:
      o - the object to test
      all - if true, considers discarded detections also as belonging to the instance kind
      Returns:
      true if the given object belongs to the instance kind
    • createContainer

      protected qupath.lib.objects.PathAnnotationObject createContainer(qupath.lib.objects.PathAnnotationObject containerParent, boolean overwrite)
      Creates a duplicate child annotation to be used as container
      Parameters:
      containerParent - the annotation to use as a model for the container
      overwrite - if true, deletes all previously created containers, if any
      Returns:
      the new container, as child of containerParent
    • applyClassifiers

      public void applyClassifiers(List<PartialClassifier> classifiers, qupath.lib.images.ImageData<?> imageData)
      applies a list of classifiers in sequence to the detections of the instance kind. The order of the classifiers is important. If they work on overlapping annotations, the intersection is classified using the latter classifier.
      If a classifier's output is not compatible with the instance, the corresponding PartialClassifier will be skipped.
      Parameters:
      classifiers - the sequence of partial classifiers to apply
      imageData - the imageData used by the classifiers
      See Also:
    • isCompatibleClassifier

      protected <T> boolean isCompatibleClassifier(qupath.lib.classifiers.object.ObjectClassifier<T> classifier)
    • isCompatibleWith

      public boolean isCompatibleWith(AbstractDetections other)
      Check whether two AbstractDetections are compatible. They are compatible if they work on the same hierarchy, they have the same getId(), they work on the same type of containers and on the same getDetectionsPathClasses()
      Parameters:
      other - an instance of the detections to check against the current one
      Returns:
      true, if compatible. False otherwise.
      See Also:
    • equals

      public boolean equals(Object obj)
      Two detection objects are functionally the same if they are compatible with each other and they have the same containers
      Overrides:
      equals in class Object
      Parameters:
      obj -
      Returns:
      True, if they are functionally the same. False otherwise
      See Also: