Package qupath.lib.analysis
Class DistanceTools
java.lang.Object
qupath.lib.analysis.DistanceTools
Static methods for calculating distances between objects.
- Author:
- Pete Bankhead
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.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.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.static double
computeCoordinateDistance
(Coordinate coord, Collection<Coordinate> targets) Compute the shortest distance from a coordinate to one of a collection of target coordinates.static double
computeCoordinateDistance
(Coordinate coord, STRtree tree) Compute the distance to the nearest coordinate stored within anSTRtree
.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 withinstatic double
computeDistance
(Coordinate coord, Geometry geometry, PointOnGeometryLocator locator, boolean signedDistance) Compute the shortest distance from a coordinate to a target geometry.static STRtree
createCoordinateCache
(Collection<Coordinate> coords) Create anSTRtree
to enable nearest neighbor searching for a collection of coordinates.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.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.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.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.
-
Constructor Details
-
DistanceTools
public DistanceTools()
-
-
Method Details
-
detectionToAnnotationDistances
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
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 distancestargetObjects
- target objects; no measurements will be addedpixelWidth
- 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 distancestargetObjects
- target objects; no measurements will be addedpixelWidth
- 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 listsignedDistances
- 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 distancestargetObjects
- target objects; no measurements will be addedpixelWidth
- 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
Compute the shortest distance from a coordinate to one of a collection of target coordinates.- Parameters:
coord
-targets
-- Returns:
-
computeCoordinateDistance
Compute the distance to the nearest coordinate stored within anSTRtree
. This assumes that all items in the tree are coordinates (and nothing else!).- Parameters:
coord
- the query coordinatetree
- theSTRtree
containing existing coordinates- Returns:
- distance to the closest coordinate found in tree, or Double.POSITIVE_INFINITY is no coordinate is found
- See Also:
-
createCoordinateCache
Create anSTRtree
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 coordinategeometry
- the target geometrylocator
- 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 coordinategeometry
- the target geometrylocator
- a locator created for the target Geometry or null; if available, computations may be fastersignedDistance
- 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
-