Skip to content

Instantly share code, notes, and snippets.

View petebankhead's full-sized avatar

Pete petebankhead

View GitHub Profile
@petebankhead
petebankhead / QuPath-Polylines to polygons.groovy
Created May 1, 2024 07:59
Script to convert all polyline annotations to polygons in QuPath.
/**
* Script to convert all polyline annotations to polygons in QuPath.
* Written for QuPath v0.5 (may work in other versions).
*/
def lineObjects = getAnnotationObjects().findAll {it.getROI().isLine()}
def polygonObjects = []
def selectedObjects = getSelectedObjects() as List
for (lineObject in lineObjects) {
def line = lineObject.getROI()
@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-Merge unmixed files to pyramid.groovy
Last active March 6, 2024 08:12
QuPath script to merge multiple TIFF fields of view to write a single pyramidal OME-TIFF (requires QuPath v0.2.0)
/**
* Convert TIFF fields of view to a pyramidal OME-TIFF.
*
* Locations are parsed from the baseline TIFF tags, therefore these need to be set.
*
* One application of this script is to combine spectrally-unmixed images.
* Be sure to read the script and see where default settings could be changed, e.g.
* - Prompting the user to select files (or using the one currently open the viewer)
* - Using lossy or lossless compression
*
@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-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-Add small image overlay.groovy
Last active February 22, 2024 18:39
Add a 'small' image overlay to the image currently open in the viewer in QuPath v0.4.x
/**
* Add a 'small' image overlay to the image currently open in the QuPath viewer.
* Here, 'small' indicates something that ImageIO can handle, and which isn't pyramidal.
*
* @author Pete Bankhead
*
* Updated 1/2023 to be compatible with QuPath v0.4.x
*/
@petebankhead
petebankhead / QuPath-Import binary masks.groovy
Created March 13, 2018 12:27
Script to import binary masks & create annotations (see also QuPath-Export binary masks.groovy)
/**
* Script to import binary masks & create annotations, adding them to the current object hierarchy.
*
* It is assumed that each mask is stored in a PNG file in a project subdirectory called 'masks'.
* Each file name should be of the form:
* [Short original image name]_[Classification name]_([downsample],[x],[y],[width],[height])-mask.png
*
* Note: It's assumed that the classification is a simple name without underscores, i.e. not a 'derived' classification
* (so 'Tumor' is ok, but 'Tumor: Positive' is not)
*
@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 / Create PyTorch launcher (Windows).groovy
Last active November 16, 2023 15:28
QuPath script to create a .bat file to launch QuPath using paths from a conda environment
/**
* Groovy script to generate a batch script to launch QuPath while setting the PATH
* from a conda environment.
*
* This is useful to add GPU support with Deep Java Library (DJL) without needing to install
* CUDA system-wide.
*
* This script was written for QuPath v0.5.
* You should read the top part and change the variables to match what you need.
*/
@petebankhead
petebankhead / QuPath-Threshold pixel classification.groovy
Created June 14, 2023 08:58
QuPath script to threshold pixel classification outputs with fixed (non-default) threshold values
/**
* QuPath v0.4.3 script to threshold probability outputs from a pixel classifier.
*
* By default, converting the pixel classifier output to probabilities will always
* apply a softmax operation and take the class with the highest probability.
*
* This script provides an alternative, whereby you can specify a probability threshold
* for one or more channels, and threshold to create objects from that.
* Using a higher threshold can then restrict the object creation of more confident predictions.
*