Skip to content

Instantly share code, notes, and snippets.

View petebankhead's full-sized avatar

Pete petebankhead

View GitHub Profile
@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
*/
@petebankhead
petebankhead / QuPath-Export cell masks.groovy
Created June 11, 2022 17:14
Export images of individual cell nuclei, with corresponding binary masks.
/**
* Export images of individual cell nuclei, with corresponding binary masks.
* Written for QuPath v0.3.2.
*
* See https://forum.image.sc/t/generate-bounding-box-images-and-their-corresponding-xml-json-files-with-each-separate-annotation/68119/
*
* @author Pete Bankhead
*/
import qupath.lib.images.servers.LabeledImageServer
@petebankhead
petebankhead / QuPath-Loop channels.groovy
Created May 18, 2022 18:29
QuPath script to loop through displayed channels
/**
* Simple script for QuPath v0.3.2 that loops through all available channels,
* displaying them in turn for 1 second.
*
* Written for https://forum.image.sc/t/how-do-i-script-qupath-to-change-the-displayed-channel/67216
*
* @author Pete Bankhead
*/
def viewer = getCurrentViewer()
@petebankhead
petebankhead / QuPath-Export scaled annotations to GeoJSON.groovy
Created May 16, 2022 12:03
QuPath script to export annotation to GeoJSON using calibrated pixel sizes
/**
* Export QuPath annotations in GeoJSON using calibrated pixel sizes
* (rather than pixel units).
*
* Written for QuPath v0.3.2
*
* @author Pete Bankhead
*/
// Define export directory (or null if we don't want to export, but just print the GeoJSON)
@petebankhead
petebankhead / QuPath-Selected density map centroid values.groovy
Created March 22, 2022 11:35
Modified script to add density map values to *some* detection centroids in QuPath v0.3
/**
* Script to add density map values to *some* detection centroids in QuPath v0.3,
* limited to only use a subset of the detections on the image.
*
* It does this by copying the relevant objects and adding them to a temporary ImageData.
*
* Note that this hasn't been tested very much... and assumes a 2D image.
* At the very least, you should use 'Measure -> Show measurement maps' as a sanity check.
*
* Written for https://forum.image.sc/t/qupath-number-of-detections-per-tile/64603/14
@petebankhead
petebankhead / QuPath-Density map centroid values.groovy
Last active March 22, 2022 12:18
Script to add density map values to detection centroids in QuPath v0.3
/**
* Script to add density map values to detection centroids in QuPath v0.3.
*
* Note that this hasn't been tested very much... and assumes a 2D image.
* At the very least, you should use 'Measure -> Show measurement maps' as a sanity check.
*
* Written for https://forum.image.sc/t/qupath-number-of-detections-per-tile/64603/10
*
* @author Pete Bankhead
*/
@petebankhead
petebankhead / QuPath-Export instance labels.groovy
Created March 22, 2022 08:46
Export annotations representing instance labels from an image, in QuPath v0.3
/*
* Export annotations representing instance labels from an image.
*
* This supports exporting regions of an image (rather than the whole thing)
* defined using the annotation shape (i.e. rectangle) or classification.
*
* See the comments for more information, and parameters to adjust.
*
* Note that the instance labels are applied globalled, so if multiple distinct
* regions are export, the labels are not guaranteed to start from 1 or be consecutive