Skip to content

Instantly share code, notes, and snippets.

View petebankhead's full-sized avatar

Pete petebankhead

View GitHub Profile
@petebankhead
petebankhead / QuPath_Open extensions directory.groovy
Created July 31, 2018 04:49
QuPath script to open the extensions directory in Windows Explorer/Mac Finder
/**
* Script to open the QuPath extensions directory.
* This is handy if you want to add/remove extensions manually.
*
* Since it depends on java.awt.Desktop, it may not be supported on all platforms.
*
* @author Pete Bankhead
*/
@petebankhead
petebankhead / QuPath-Update cell measurement names.groovy
Created August 5, 2018 13:42
Script to update cell measurement names for a multichannel fluorescence image to incorporate actual stored channel names
/**
* Script to update cell measurement names for a multichannel fluorescence image
* to incorporate actual stored channel names, rather than the defaults of
* 'Channel 1', 'Channel 2' etc.
*
* @author Pete Bankhead
*/
import qupath.lib.scripting.QPEx
@petebankhead
petebankhead / QuPath-Multiple cell classifications.groovy
Last active August 5, 2018 16:01
Demo script showing a simple method of assigning classifications for a multichannel fluorescence image
/**
* Demo script showing a simple method of assigning classifications for a multichannel fluorescence image.
*
* Note that at the time of writing, this requires the most recent (pre-release) QuPath version.
* See https://petebankhead.github.io for more information.
*
* The channel names here refer to the sample image 'LuCa-7color_[13860,52919]_1x1component_data.tif'
* from Perkin Elmer, after running 'Update measurement names.groovy' script.
*
* The original image is part of Bio-Formats demo data, under Creative Commons Attribution 4.0 International License
@petebankhead
petebankhead / QuPath-Select by classification name.groovy
Created August 5, 2018 16:48
Helper script for QuPath to find objects with one or more classifications
/**
* Helper script for QuPath to find objects with one or more classifications.
*
* @author Pete Bankhead
*/
// Insert as many or few classifications here as required
selectObjects {checkForClassifications(it.getPathClass(), 'CD8', 'FoxP3')}
print 'Selected ' + getSelectedObjects().size()
@petebankhead
petebankhead / QuPath-Flipping ROIs.groovy
Last active February 1, 2021 13:25
Flip a ROI vertically or horizontally in QuPath v0.2
/**
* Flip the ROIs for QuPath objects (usually annotations) vertically or horizontally.
*
* This creates new objects that are then added to the current image hierarchy.
*
* This also shows the method by which any arbitrary AffineTransform may be
* applied to an object by scripting.
*
* Note: This version is updated for QuPath v0.2.
*
@petebankhead
petebankhead / QuPath-Creating tumor margin annotations.groovy
Last active February 24, 2021 15:47
QuPath script to help with annotating tumor regions, separating the tumor margin from the center.
/**
* Script to help with annotating tumor regions, separating the tumor margin from the center.
*
* Here, each of the margin regions is approximately 500 microns in width.
*
* NOTE: This version has been updated for v0.2.0-m6 and to use Java Topology Suite.
*
* @author Pete Bankhead
*/
@petebankhead
petebankhead / QuPath-Export overlay image.groovy
Created September 15, 2018 11:25
Export an image thumbnail & overlay as separate images
/**
* Export an image thumbnail & overlay as separate images.
*
* The overlay is written as PNG with transparent background.
*
* @author Pete Bankhead
*/
import qupath.lib.regions.RegionRequest
@petebankhead
petebankhead / QuPath-Measurement mapper demo.groovy
Last active March 19, 2021 19:54
Set a MeasurementMapper in QuPath v0.1.2 to control detection object display in a script
/**
* Set a MeasurementMapper in QuPath v0.2 to control the display in a script.
*
* Revised version of a script for v0.1.2.
*
* @author Pete Bankhead
*/
import qupath.lib.gui.tools.MeasurementMapper
@petebankhead
petebankhead / QuPath-Reset TMA core metadata.groovy
Created September 20, 2018 13:01
Remove metadata from TMA cores (e.g. 'notes') in QuPath
getTMACoreList().each {
it.clearMetadata()
}
fireHierarchyUpdate()
@petebankhead
petebankhead / QuPath-Remove tiny objects.groovy
Created September 20, 2018 13:02
Remove very tiny annotation objects in QuPath
// Remove really tiny objects (here, with areas <= 1 pixel.... and also lines)
// They can be created when using the wand/brush & subtracting almost all of a region (for example)
tinyAreas = getAnnotationObjects().findAll {
return !it.isPoint() && it.getROI().getArea() <= 1
}
print 'Number of objects to remove: ' + tinyAreas.size()
removeObjects(tinyAreas, true)