Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petebankhead/5144d39eefe3961b6b289675e6005fbc to your computer and use it in GitHub Desktop.
Save petebankhead/5144d39eefe3961b6b289675e6005fbc to your computer and use it in GitHub Desktop.
Create a convex hull annotation around all selected objects in QuPath
/**
* Create a convex hull annotation surrounding all selected objects.
*
* Note that this
* - was written using QuPath v0.4.x (but probably works in some earlier releases)
* - doesn't work very well for ellipse objects, but should be ok with other shapes
* - assumes that you only have a 2D image (you'd need to change the 'image plane' part for z-stacks or timeseries)
*
* It was written for https://forum.image.sc/t/qupath-script-command-to-draw-polygon-annotation-from-points/76833
*
* @author Pete Bankhead
*/
def selected = getSelectedObjects()
def points = []
for (def pathObject in selected) {
points.addAll(pathObject.getROI().getAllPoints())
}
def hullPoints = qupath.lib.roi.ConvexHull.getConvexHull(points)
def roi = ROIs.createPolygonROI(hullPoints, ImagePlane.getDefaultPlane())
def hullAnnotation = PathObjects.createAnnotationObject(roi)
addObject(hullAnnotation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment