Class ShapeSimplifier

java.lang.Object
qupath.lib.roi.ShapeSimplifier

public class ShapeSimplifier extends Object
Helper methods for simplifying shapes, such removing polygon points while retaining a similar overall shape at a coarser level.

This can help manage storage and performance requirements when working with large numbers of ROIs, especially in terms of repainting speed.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Path2D
    simplifyPath(Path2D path, double altitudeThreshold)
    Create a simplified path (fewer coordinates) using method based on Visvalingam's Algorithm, processing all segments.
    static Path2D
    simplifyPath(Path2D path, double altitudeThreshold, int segmentPointThreshold, double discardBoundsLength)
    Create a simplified path (fewer coordinates) using method based on Visvalingam's Algorithm, optionally skipping segments with few points.
    static PolygonROI
    simplifyPolygon(PolygonROI polygon, double altitudeThreshold)
    Create a simplified polygon (fewer coordinates) using method based on Visvalingam's Algorithm.
    static void
    simplifyPolygonPoints(List<Point2> points, double altitudeThreshold)
    Create a simplified polygon (fewer coordinates) using method based on Visvalingam's Algorithm.
    static ROI
    simplifyROI(ROI roi, double altitudeThreshold)
    Simplify a ROI using either polygon or general shape methods.
    static ROI
    simplifyShape(ROI shapeROI, double altitudeThreshold)
    Create a simplified shape (fewer coordinates) using method based on Visvalingam's Algorithm.
    static List<Point2>
    Apply a simple 3-point moving average to a list of points.

    Methods inherited from class java.lang.Object

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

    • ShapeSimplifier

      public ShapeSimplifier()
  • Method Details

    • simplifyPolygonPoints

      public static void simplifyPolygonPoints(List<Point2> points, double altitudeThreshold)
      Create a simplified polygon (fewer coordinates) using method based on Visvalingam's Algorithm. The input is a list of points (the vertices) belonging to a closed polygon. This list is modified in place.

      See references: https://hydra.hull.ac.uk/resources/hull:8338 https://www.jasondavies.com/simplify/ http://bost.ocks.org/mike/simplify/

      Parameters:
      points -
      altitudeThreshold -
    • simplifyShape

      public static ROI simplifyShape(ROI shapeROI, double altitudeThreshold)
      Create a simplified shape (fewer coordinates) using method based on Visvalingam's Algorithm.

      See references: https://hydra.hull.ac.uk/resources/hull:8338 https://www.jasondavies.com/simplify/ http://bost.ocks.org/mike/simplify/

      Parameters:
      shapeROI -
      altitudeThreshold -
      Returns:
    • simplifyPath

      public static Path2D simplifyPath(Path2D path, double altitudeThreshold)
      Create a simplified path (fewer coordinates) using method based on Visvalingam's Algorithm, processing all segments.

      See references: https://hydra.hull.ac.uk/resources/hull:8338 https://www.jasondavies.com/simplify/ http://bost.ocks.org/mike/simplify/

      Parameters:
      path -
      altitudeThreshold -
      Returns:
      See Also:
    • simplifyPath

      public static Path2D simplifyPath(Path2D path, double altitudeThreshold, int segmentPointThreshold, double discardBoundsLength)
      Create a simplified path (fewer coordinates) using method based on Visvalingam's Algorithm, optionally skipping segments with few points.

      This method introduces segmentPointThreshold because simplifying multipolygons can produce a 'jagged' effect when the simplification is applied to segments that contain only a few vertices. This was particularly noticeable in QuPath's viewer, where a high altitude threshold is used.

      See references: https://hydra.hull.ac.uk/resources/hull:8338 https://www.jasondavies.com/simplify/ http://bost.ocks.org/mike/simplify/

      Parameters:
      path - the path to simplify
      altitudeThreshold - the altitude threshold
      segmentPointThreshold - the minimum number of points in a closed segment for simplification to be applied; segments with fewer points (after removing duplicates) will be retained unchanged.
      discardBoundsLength - discard segments if bounding box dimensions are both smaller than this value; if ≤ 0, no segments are discarded based on bounding box size. This can be important when simplification is use to help render very large shapes at a low resolution.
      Returns:
      the path with vertices (and possibly some segments) removed
      Since:
      v0.6.0
      See Also:
    • smoothPoints

      public static List<Point2> smoothPoints(List<Point2> points)
      Apply a simple 3-point moving average to a list of points.
      Parameters:
      points -
      Returns:
    • simplifyPolygon

      public static PolygonROI simplifyPolygon(PolygonROI polygon, double altitudeThreshold)
      Create a simplified polygon (fewer coordinates) using method based on Visvalingam's Algorithm.

      See references: Hydra Jason Davies Mike Bostock

      Parameters:
      polygon -
      altitudeThreshold -
      Returns:
    • simplifyROI

      public static ROI simplifyROI(ROI roi, double altitudeThreshold)
      Simplify a ROI using either polygon or general shape methods.
      Parameters:
      roi - the input ROI
      Returns:
      a simplified copy of the input