Skip to content

Instantly share code, notes, and snippets.

View petebankhead's full-sized avatar

Pete petebankhead

View GitHub Profile
@petebankhead
petebankhead / QuPath Memory Monitor.groovy
Last active March 9, 2026 22:51
Groovy script to help monitor QuPath's memory use over time
/**
* A basic GUI to help monitor memory usage in QuPath.
*
* This helps both to find & address out-of-memory troubles by
* 1. Showing how much memory is in use over time
* 2. Giving a button to clear the tile cache - which can be
* using up precious memory
* 3. Giving quick access to control the number of threads used
* for parallel processing
*
@petebankhead
petebankhead / QuPath_cells_to_areas.groovy
Created February 20, 2018 13:30
QuPath script to calculate areas (e.g. of tumor) based upon classified cells only
/**
* QuPath script to calculate areas (e.g. of tumor) based upon classified cells only.
*
* It works by using a distance transform applied to binary images generated from the
* objects of each class, and then assigns each pixel to the closest object.
*
* Having done this, new annotations are generated for these regions.
*
* WARNINGS!
* - This will remove *all* previous annotations & replace them with new annotations
@petebankhead
petebankhead / QuPath_Combine_measurement_tables.groovy
Created February 20, 2018 20:11
Script to combine the measurement tables exported by QuPath into a single text file
/**
* Script to combine results tables exported by QuPath.
*
* This is particularly intended to deal with the fact that results tables of annotations can produce results
* with different column names, numbers and orders - making them awkward to combine later manually.
*
* It prompts for a directory containing exported text files, and then writes a new file in the same directory.
* The name of the new file can be modified - see the first lines below.
*
* Note: This hasn't been tested very extensively - please check the results carefully, and report any problems so they
@petebankhead
petebankhead / QuPath_export_annotations_for_project.groovy
Created February 20, 2018 20:16
Export annotations for a project in QuPath
/*
* QuPath v0.1.2 has some bugs that make exporting annotations a bit annoying, specifically it doesn't include the 'dot'
* needed in the filename if you run it in batch, and it might put the 'slashes' the wrong way on Windows.
* Manually fixing these afterwards is not very fun.
*
* Anyhow, until this is fixed you could try the following script with Run -> Run for Project.
* It should create a new subdirectory in the project, and write text files containing results there.
*
* @author Pete Bankhead
*/
@petebankhead
petebankhead / QuPath-Set multiple cell intensity classifications.groovy
Created February 25, 2018 18:03
Script to set cell intensity sub-classifications based on an arbitrary number of thresholds
/**
* Script to set cell intensity sub-classifications based on an arbitrary number
* of thresholds.
*
* Note: Because QuPath's dynamic measurements only care about negative/positive or
* negative/1+/2+/3+, any further classifications (e.g. 4+, 5+) won't be part of the
* summary scores (e.g. H-score or even Positive %)!
* Be warned and be careful!
*
* For 3 thresholds or fewer, the built-in setCellIntensityClassifications method is preferable.
@petebankhead
petebankhead / QuPath-Simplify annotations.groovy
Created February 28, 2018 16:46
Simplify annotation shapes by removing vertices
/**
* A script to simplify the ROIs of all selected annotation objects.
*
* @author Pete Bankhead
*/
import qupath.lib.gui.QuPathGUI
import qupath.lib.objects.PathAnnotationObject
import qupath.lib.roi.PolygonROI
import qupath.lib.roi.ShapeSimplifierAwt
@petebankhead
petebankhead / QuPath-Image to ImagePlus.groovy
Last active March 3, 2018 18:27
Extract an image from QuPath to an ImagePlus
/**
* Request an image from QuPath as an (ImageJ) ImagePlus.
* The aim is to avoid the (arbitrary) size threshold in v0.1.2 of QuPath.
*
* @author Pete Bankhead
*/
import ij.IJ
import qupath.imagej.gui.IJExtension
import qupath.imagej.helpers.IJTools
@petebankhead
petebankhead / QuPath-Detecting regions with the help of ImageJ.groovy
Created March 8, 2018 13:21
Whole slide image processing with QuPath & ImageJ
/**
* Demonstration of how to use ImageJ + QuPath to detect stained regions in
* a brightfield image.
*
* @author Pete Bankhead
*/
import ij.CompositeImage
import ij.IJ
@petebankhead
petebankhead / QuPath-Create rectangle annotation.groovy
Created March 9, 2018 15:52
Create a rectangle annotation with a specified size
/**
* Create a region annotation with a fixed size in QuPath, based on the current viewer location.
*
* @author Pete Bankhead
*/
import qupath.lib.objects.PathAnnotationObject
import qupath.lib.objects.classes.PathClassFactory
import qupath.lib.roi.RectangleROI
import qupath.lib.scripting.QPEx
@petebankhead
petebankhead / QuPath-Export binary masks.groovy
Last active June 25, 2025 09:32
Script to export annotated regions as binary masks (revised for v0.2.0-m6)
/**
* Script to export binary masks corresponding to all annotations of an image,
* optionally along with extracted image regions.
*
* Note: Pay attention to the 'downsample' value to control the export resolution!
*
* @author Pete Bankhead
*/
import qupath.lib.images.servers.ImageServer