Created
February 4, 2023 05:52
-
-
Save petebankhead/5144d39eefe3961b6b289675e6005fbc to your computer and use it in GitHub Desktop.
Create a convex hull annotation around all selected objects in QuPath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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