Class ObjectMerger

java.lang.Object
qupath.lib.objects.utils.ObjectMerger

public class ObjectMerger extends Object
Helper class for merging objects using different criteria.

This is designed to be used for post-processing a segmentation, to help resolve tile boundaries.

Since:
v0.5.0
  • Method Details

    • merge

      public List<PathObject> merge(Collection<? extends PathObject> pathObjects)
      Calculate the result of applying the merging strategy to the input objects.

      The output list will contain the same number of objects or fewer. Objects that are not merged will be returned unchanged, while objects that are merged will be replaced by a new objects with a new ROI.

      New objects will be assigned new IDs. Classifications will be preserved, but other measurements and properties will not be.

      No guarantees are made about the mutability or ordering of the returned list.

      Parameters:
      pathObjects - the input objects for which merges should be calculated
      Returns:
      a list of objects, with the same number or fewer than the input
    • createSharedTileBoundaryMerger

      public static ObjectMerger createSharedTileBoundaryMerger(double sharedBoundaryThreshold)
      Create an object merger that uses a shared boundary IoU criterion and default overlap tolerance.

      Objects will be merged if they a common boundary and have the same classification. A small overlap tolerance is used to compensate for sub-pixel misalignment of tiles.

      This is intended for post-processing a tile-based segmentation, where the tiling has been strictly enforced (i.e. any objects have been clipped to non-overlapping tile boundaries).

      Parameters:
      sharedBoundaryThreshold - minimum intersection-over-union (IoU) proportion of the possibly-clipped boundary for merging
      Returns:
      an object merger that uses a shared boundary criterion
      See Also:
    • createSharedTileBoundaryMerger

      public static ObjectMerger createSharedTileBoundaryMerger(double sharedBoundaryThreshold, double overlapTolerance)
      Create an object merger that uses a shared boundary IoU criterion and overlap tolerance.

      Objects will be merged if they share a common boundary and have the same classification. A small overlap tolerance can be used to compensate for slight misalignment of tiles.

      After identifying a common boundary line between ROIs, the ROI boundaries are intersected with the line, and the two intersections are subsequently intersected with each other to determine the shared intersection. The length of the shared intersection is then used to compute the intersection over union.

      This is intended for post-processing a tile-based segmentation, where the tiling has been strictly enforced (i.e. any objects have been clipped to non-overlapping tile boundaries).

      Parameters:
      sharedBoundaryThreshold - minimum intersection-over-union (IoU) proportion of the possibly-clipped boundary * for merging
      overlapTolerance - amount of overlap allowed between objects, in pixels. If zero, the boundary must be shared exactly. A typical value is 0.125, which allows for a small, sub-pixel overlap.
      Returns:
      an object merger that uses a shared boundary criterion and overlap tolerance
    • createSharedClassificationMerger

      public static ObjectMerger createSharedClassificationMerger()
      Create an object merger that can merge together any objects with similar ROIs (e.g. points, areas), the same classification, and are on the same image plane.

      The ROIs to not need to be touching; the resulting merged objects can have discontinuous ROIs.

      Returns:
      an object merger that can merge together any objects with similar ROIs and the same classification
    • createTouchingMerger

      public static ObjectMerger createTouchingMerger()
      Create an object merger that can merge together any objects with similar ROIs (e.g. points, areas) that also touch one another.

      Objects must also have the same classification and be on the same image plane to be mergeable.

      Note that this is a strict criterion following the Java Topology Suite definition of touching, which requires that the boundaries of the geometries intersect, but the interiors do not intersect.

      This strictness can cause unexpected results due to floating point precision issues, unless it is certain that the ROIs are perfectly aligned (e.g they are generated using integer coordinates on a pixel grid).

      If this is not the case, createSharedTileBoundaryMerger(double, double) is usually preferable, since it can include a small overlap tolerance.

      Returns:
      an object merger that can merge together any objects with similar ROIs and the same classification
      See Also: