Class DistanceTools

java.lang.Object
qupath.lib.analysis.DistanceTools

public class DistanceTools extends Object
Static methods for calculating distances between objects.
Author:
Pete Bankhead
  • Constructor Details

    • DistanceTools

      public DistanceTools()
  • Method Details

    • detectionToAnnotationDistances

      public static void detectionToAnnotationDistances(ImageData<?> imageData, boolean splitClassNames)
      Compute the distance for all detection object centroids to the closest annotation with each valid, not-ignored classification and add the result to the detection measurement list.
      Parameters:
      imageData -
      splitClassNames - if true, split the classification name. For example, if an image contains classifications for both "CD3: CD4" and "CD3: CD8", distances will be calculated for all components (e.g. "CD3", "CD4" and "CD8").
      See Also:
    • detectionToAnnotationDistancesSigned

      public static void detectionToAnnotationDistancesSigned(ImageData<?> imageData, boolean splitClassNames)
      Compute the signed distance for all detection object centroids to the closest annotation with each valid, not-ignored classification and add the result to the detection measurement list.
      Parameters:
      imageData -
      splitClassNames - if true, split the classification name. For example, if an image contains classifications for both "CD3: CD4" and "CD3: CD8", distances will be calculated for all components (e.g. "CD3", "CD4" and "CD8").
      Since:
      v0.4.0
      See Also:
    • detectionToAnnotationDistances

      public static void detectionToAnnotationDistances(ImageData<?> imageData, boolean splitClassNames, boolean signedDistances)
      Compute the distance for all detection object centroids to the closest annotation with each valid, not-ignored classification and add the result to the detection measurement list.
      Parameters:
      imageData -
      splitClassNames - if true, split the classification name. For example, if an image contains classifications for both "CD3: CD4" and "CD3: CD8", distances will be calculated for all components (e.g. "CD3", "CD4" and "CD8").
      signedDistances - optionally calculate signed distances, i.e. negative values for source centroids that occur inside target objects representing the distance to the target object boundary
      Since:
      v0.4.0
    • detectionCentroidDistances

      public static void detectionCentroidDistances(ImageData<?> imageData, boolean splitClassNames)
      Compute the distance for all detection object centroids to the closest annotation with each valid, not-ignored classification and add the result to the detection measurement list.
      Parameters:
      imageData -
      splitClassNames - if true, split the classification name. For example, if an image contains classifications for both "CD3: CD4" and "CD3: CD8", distances will be calculated for all components (e.g. "CD3", "CD4" and "CD8").
    • centroidToBoundsDistance2D

      public static void centroidToBoundsDistance2D(Collection<PathObject> sourceObjects, Collection<PathObject> targetObjects, double pixelWidth, double pixelHeight, String measurementName)
      Calculate the distance between source object centroids and the boundary of specified target objects, adding the result to the measurement list of the source objects. Calculations are all made in 2D; distances will not be calculated between objects occurring on different z-planes of at different timepoints.
      Parameters:
      sourceObjects - source objects; measurements will be added based on centroid distances
      targetObjects - target objects; no measurements will be added
      pixelWidth - pixel width to use in Geometry conversion (use 1 for pixel units)
      pixelHeight - pixel height to use in Geometry conversion (use 1 for pixel units)
      measurementName - the name of the measurement to add to the measurement list
    • centroidToBoundsDistance2D

      public static void centroidToBoundsDistance2D(Collection<PathObject> sourceObjects, Collection<PathObject> targetObjects, double pixelWidth, double pixelHeight, String measurementName, boolean signedDistances)
      Calculate the (optionally signed) distance between source object centroids and the boundary of specified target objects, adding the result to the measurement list of the source objects. Calculations are all made in 2D; distances will not be calculated between objects occurring on different z-planes of at different timepoints.
      Parameters:
      sourceObjects - source objects; measurements will be added based on centroid distances
      targetObjects - target objects; no measurements will be added
      pixelWidth - pixel width to use in Geometry conversion (use 1 for pixel units)
      pixelHeight - pixel height to use in Geometry conversion (use 1 for pixel units)
      measurementName - the name of the measurement to add to the measurement list
      signedDistances - optionally calculate signed distances, i.e. negative values for source centroids that occur inside target objects representing the distance to the target object boundary
      Since:
      v0.4.0
    • centroidToCentroidDistance2D

      public static void centroidToCentroidDistance2D(Collection<PathObject> sourceObjects, Collection<PathObject> targetObjects, double pixelWidth, double pixelHeight, String measurementName)
      Calculate the distance between source object centroids and the centroid of specified target objects, adding the result to the measurement list of the source objects. Calculations are all made in 2D; distances will not be calculated between objects occurring on different z-planes of at different timepoints.
      Parameters:
      sourceObjects - source objects; measurements will be added based on centroid distances
      targetObjects - target objects; no measurements will be added
      pixelWidth - pixel width to use in Geometry conversion (use 1 for pixel units)
      pixelHeight - pixel height to use in Geometry conversion (use 1 for pixel units)
      measurementName - the name of the measurement to add to the measurement list
    • computeCoordinateDistance

      public static double computeCoordinateDistance(Coordinate coord, Collection<Coordinate> targets)
      Compute the shortest distance from a coordinate to one of a collection of target coordinates.
      Parameters:
      coord -
      targets -
      Returns:
    • computeCoordinateDistance

      public static double computeCoordinateDistance(Coordinate coord, STRtree tree)
      Compute the distance to the nearest coordinate stored within an STRtree. This assumes that all items in the tree are coordinates (and nothing else!).
      Parameters:
      coord - the query coordinate
      tree - the STRtree containing existing coordinates
      Returns:
      distance to the closest coordinate found in tree, or Double.POSITIVE_INFINITY is no coordinate is found
      See Also:
    • createCoordinateCache

      public static STRtree createCoordinateCache(Collection<Coordinate> coords)
      Create an STRtree to enable nearest neighbor searching for a collection of coordinates.
      Parameters:
      coords - the coordinates to insert into the tree
      Returns:
      the tree
    • computeDistance

      public static double computeDistance(Coordinate coord, Geometry geometry, PointOnGeometryLocator locator)
      Compute the (unsigned) shortest distance from a coordinate to a target geometry, or zero if the coordinate occurs within
      Parameters:
      coord - the coordinate
      geometry - the target geometry
      locator - a locator created for the target Geometry or null; if available, computations may be faster
      Returns:
      See Also:
    • computeDistance

      public static double computeDistance(Coordinate coord, Geometry geometry, PointOnGeometryLocator locator, boolean signedDistance)
      Compute the shortest distance from a coordinate to a target geometry. This is primarily intended for computing distances for exterior coordinates, however a signed distance can optionally be returned for interior coordinates.
      Parameters:
      coord - the coordinate
      geometry - the target geometry
      locator - a locator created for the target Geometry or null; if available, computations may be faster
      signedDistance - if false, return 0 for coordinates occurring inside areas; if true, return a negative value representing the distance to the boundary of the area
      Returns:
      Since:
      v0.4.0