Skip to content

Instantly share code, notes, and snippets.

View petebankhead's full-sized avatar

Pete petebankhead

View GitHub Profile
@petebankhead
petebankhead / QuPath-Create surrounding annotation.groovy
Last active May 11, 2023 16:52
Interactively create a convex or concave hull annotation from the selected objects in QuPath v0.4.
/**
* Create a convex or concave hull annotation from the selected objects.
*
* The calculations are performed using Java Topology Suite's 'ConcaveHullOfPolygons' class -
* see https://locationtech.github.io/jts/javadoc/org/locationtech/jts/algorithm/hull/ConcaveHullOfPolygons.html
*
* This was written for QuPath v0.4.3.
* If it's useful enough, a similar feature might be added to QuPath directly in the future.
*
* @author Pete Bankhead
@petebankhead
petebankhead / QuPath-Find splits along ROI contours.groovy
Created April 13, 2023 13:42
Create a point annotation showing equally-spaced splits along a polyline or simple polygon
/**
* Create a point annotation showing equally-spaced splits
* along a polyline or simple polygon (i.e. no holes or
* self-intersections).
*
* See https://forum.image.sc/t/divide-free-hand-lines-at-regular-interval/79845/4
*
* Written for QuPath v0.4.3 using JTS.
*
* @author Pete Bankhead
@petebankhead
petebankhead / QuPath-Create rectangles for points.groovy
Last active December 11, 2023 15:47
Create fixed-sized square annotations around the points of a selected point annotation in QuPath
/**
* Create fixed-sized square annotations around the points of a selected
* point annotation.
*
* Written for QuPath v0.4 and v0.5.
* See https://forum.image.sc/t/is-it-possible-to-create-annotations-on-click/79270
*
* Edited 12/2023 to support multiple selected point annotations (not just one).
*
* @author Pete Bankhead
@petebankhead
petebankhead / QuPath-Intersect annotations.groovy
Created February 13, 2023 17:11
Constrain all selected annotations so that they fall inside unselected annotations
/**
* Constrain all selected annotations so that they fall inside unselected annotations.
*
* This is intended for a case where
* - you have some annotations that define a region of interest (e.g. all tissue)
* - some other annotations that partially overlap the first annotations, but which *should* be inside
*
* If you select the second annotations and run this script, it should remove the parts that are outside the first
* annotations - effectively cleaning up the image.
*
@petebankhead
petebankhead / QuPath-Convex hull around selected objects.groovy
Created February 4, 2023 05:52
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
*
@petebankhead
petebankhead / QuPath-Extract hyperstack and overlay.groovy
Created January 19, 2023 19:05
QuPath script to extract a hyperstack + overlay and send it to ImageJ (written for v0.4.2)
/**
* QuPath script to extract a stack/hyperstack + overlay and send it to ImageJ.
*
* This will either extract a hyperstack for the bounding box of the current selected object,
* or for the entire image if no object is selected.
*
* Written for https://forum.image.sc/t/qupath-how-to-send-multiple-annotations-containing-more-annotations-to-imagej-with-all-z-slices-and-re-name/76107
*
* Tested (to an extent...) with QuPath v0.4.2
*
@petebankhead
petebankhead / QuPath-Add pixel classifier measurements to cells.groovy
Last active February 26, 2024 16:49
Add pixel classifier measurements to all cells in an image using QuPath
/**
* Add pixel classifier measurements to all cells in an image.
*
* This is intended to overcome the fact that measurements can be quite slow because they aren't parallelized.
*
* Written for QuPath v0.3.2.
* See https://forum.image.sc/t/qupath-measure-pixel-classifier-area-per-cell-detection-for-wsis/72701
*
* Warning! This hasn't been extensively tested - please report any problems on the forum.
*
@petebankhead
petebankhead / QuPath-Set accelerators for menu items.groovy
Last active October 14, 2022 07:39
Set KeyCombination accelerators for menu items in QuPath v0.3.2
/**
* QuPath script to set accelerators for specific menu items.
*
* Written for QuPath v0.3.2
* In answer to https://forum.image.sc/t/feature-request-windows-with-favorite-menu-items/72721/3
*
* @author Pete Bankhead
*/
def combos = [
@petebankhead
petebankhead / QuPath-Sum detection areas.groovy
Last active September 26, 2022 17:14
Sum the area of detections with a specified classification in QuPath
/**
* Sum the area of detections with a specified classification.
* Written for QuPath v0.3.2.
*
* @author Pete Bankhead
*/
// Define name of the class of detection objects
def className = 'Positive'
@petebankhead
petebankhead / QuPath-Rotate all objects.groovy
Created September 19, 2022 05:36
Rotate all QuPath objects in an image by 180 degrees, translating them so they remain within the image
/**
* Rotate all objects in an image by 180 degrees, translating them so they
* remain within the image.
*
* Written for QuPath v0.3.2
*
* See https://forum.image.sc/t/overlaying-h-e-and-tissue-annotations-in-qupath/71861/3
*
* @author Pete Bankhead
*/