Class DelaunayTools

java.lang.Object
qupath.lib.analysis.DelaunayTools

public class DelaunayTools extends Object
Tools for creating and querying Delaunay triangulations and Voronoi diagrams.
Author:
Pete Bankhead
  • Constructor Details

    • DelaunayTools

      public DelaunayTools()
  • Method Details

    • newBuilder

      public static DelaunayTools.Builder newBuilder(Collection<PathObject> pathObjects)
      Create a new DelaunayTools.Builder to compute a triangulation using the specified objects.
      Parameters:
      pathObjects -
      Returns:
    • createFromCentroids

      public static DelaunayTools.Subdivision createFromCentroids(Collection<PathObject> pathObjects, boolean preferNucleusROI)
      Create a DelaunayTools.Subdivision using the centroid coordinates of ROIs.

      Note: centroids must be distinct. If multiple objects have identical centroids, one or more objects may be lost from the resulting DelaunayTools.Subdivision.

      Parameters:
      pathObjects - collection of objects from which to construct the DelaunayTools.Subdivision
      preferNucleusROI - if true, prefer the nucleus ROI when extracting the centroid from a cell
      Returns:
      a new DelaunayTools.Subdivision computed from the centroids of the provided objects
      See Also:
    • createFromGeometryCoordinates

      public static DelaunayTools.Subdivision createFromGeometryCoordinates(Collection<PathObject> pathObjects, boolean preferNucleusROI, double densifyFactor)
      Create a DelaunayTools.Subdivision using the boundary coordinates of ROIs. This is primarily useful for computing Voronoi faces centered on ROIs rather than single points, i.e. to identify pixels closest to specific objects.

      Notes:

      Parameters:
      pathObjects - collection of objects from which to construct the DelaunayTools.Subdivision
      preferNucleusROI - if true, prefer the nucleus ROI when extracting geometries from a cell
      densifyFactor - amount to 'density' each ROI; this is needed to interpolate coordinates (suggested value = 4.0)
      Returns:
      a new DelaunayTools.Subdivision computed from the provided objects
      See Also:
    • sameClassificationPredicate

      public static BiPredicate<PathObject,PathObject> sameClassificationPredicate()
      BiPredicate that returns true for objects that share the same classification.
      Returns:
    • centroidDistancePredicate

      public static BiPredicate<PathObject,PathObject> centroidDistancePredicate(double maxDistance, boolean preferNucleus)
      BiPredicate that returns true for objects with ROI centroids within a specified distance.
      Parameters:
      maxDistance - maximum separation between ROI centroids
      preferNucleus - if true, prefer nucleus centroids for cell objects
      Returns:
      true for object pairs with close centroids
    • boundaryDistancePredicate

      public static BiPredicate<PathObject,PathObject> boundaryDistancePredicate(double maxDistance, boolean preferNucleus)
      BiPredicate that returns true for objects with ROI boundaries within a specified distance.
      Parameters:
      maxDistance - maximum separation between ROI boundaries
      preferNucleus - if true, prefer nucleus ROIs for cell objects
      Returns:
      true for object pairs with close boundaries
    • createAnnotationsFromSubdivision

      public static List<PathObject> createAnnotationsFromSubdivision(DelaunayTools.Subdivision subdivision, ROI bounds)
      Create annotations surrounding objects within a specified subdivision based on Voronoi faces. This can be used to create annotations based upon existing detections.
      Parameters:
      subdivision - subdivision representing object relationships
      bounds - if provided, clip the annotations to fit within the ROI
      Returns:
      a list of annotations, one for each classification represented by objects within the subdivision within the bounds
    • classifyObjectsByCluster

      public static Collection<PathObject> classifyObjectsByCluster(Collection<Collection<? extends PathObject>> clusters, Function<Integer,PathClass> pathClassFun)
      Assign object classifications based upon pre-computed clusters.
      Parameters:
      clusters - a collection of PathObject collections, each of which corresponds to a cluster of related objects.
      pathClassFun - function used to create a PathClass from a cluster number (determined by where it falls within the collection).
      Returns:
      a collection of objects that have had their classifications set by this method
    • classifyObjectsByCluster

      public static Collection<PathObject> classifyObjectsByCluster(Collection<Collection<? extends PathObject>> clusters)
      Assign object classifications based upon pre-computed clusters.
      Parameters:
      clusters - a collection of PathObject collections, each of which corresponds to a cluster of related objects.
      Returns:
      a collection of objects that have had their classifications set by this method
    • nameObjectsByCluster

      public static Collection<PathObject> nameObjectsByCluster(Collection<Collection<? extends PathObject>> clusters, Function<Integer,PathClass> pathClassFun)
      Assign object classifications based upon pre-computed clusters.
      Parameters:
      clusters - a collection of PathObject collections, each of which corresponds to a cluster of related objects.
      pathClassFun - function used to create a PathClass from a cluster number (determined by where it falls within the collection). However rather than set this as the object classification, it will be used to set the name and color of the object (so as to avoid overriding an existing classification).
      Returns:
      a collection of objects that have had their classifications set by this method
    • nameObjectsByCluster

      public static Collection<PathObject> nameObjectsByCluster(Collection<Collection<? extends PathObject>> clusters)
      Assign object names based upon pre-computed clusters.
      Parameters:
      clusters - a collection of PathObject collections, each of which corresponds to a cluster of related objects.
      Returns:
      a collection of objects that have had their classifications set by this method