Skip to content

Instantly share code, notes, and snippets.

View petebankhead's full-sized avatar

Pete petebankhead

View GitHub Profile
@petebankhead
petebankhead / QuPath-Split rectangle.groovy
Last active April 18, 2021 17:59
Split a rectangle into equal parts along its longest dimension in QuPath v0.2.
/**
* Split a rectangle into equal parts along its longest dimension.
* Rotated rectangles are supported.
*
* Written for https://forum.image.sc/t/how-to-divide-annotation-roi-into-equal-dimension-bins/51563/8
*
* @author Pete Bankhead
*/
// Number of regions to create
@petebankhead
petebankhead / QuPath-Create random points.groovy
Created April 8, 2021 19:47
Generate a point annotation containing randomly distributed points in QuPath v0.2 or v0.3
/**
* This script generates a point annotation containing randomly generated points in QuPath v0.2 or v0.3.
*
* These can optionally be constrained to fall within the selected ROI, within the entire image,
* or within the largest circle that falls within the entire image.
*
* For the original motivation behind this script, see https://forum.image.sc/t/digital-chalkley-point-graticule-overlay/51211
*
* @author Pete Bankhead
*/
@petebankhead
petebankhead / QuPath-Remove detections at annotation boundaries.groovy
Created February 18, 2021 18:00
Remove detections that have ROIs that touch the border of any annotation ROI in QuPath v0.2
/**
* Remove detections that have ROIs that touch the border of any annotation ROI in QuPath v0.2.
*
* Note that there are some non-obvious subtleties involved depending upon how ROIs are accessed -
* see the 'useHierarchyRule' option for more info.
*
* Written for https://forum.image.sc/t/remove-detected-objects-touching-annotations-border/49053
*
* @author Pete Bankhead
*/
@petebankhead
petebankhead / QuPath-Copy annotations across stacks.groovy
Last active November 14, 2022 19:17
opy QuPath annotations across z-slices or timepoints, to aid 3D annotation
/**
* Copy QuPath annotations across z-slices or timepoints.
*
* This is a convenience script to help (slightly) annotating in 3D or 4D images.
*
* (This hasn't been very thoroughly checked - if it doesn't seem to work for you,
* it might just not work... you can use the comments to discuss this)
*
* @author Pete Bankhead
*/
@petebankhead
petebankhead / QuPath-Visualize annotations across z-slices.groovy
Created January 15, 2021 10:42
Visualize annotations on all z-slices in QuPath v0.2
/**
* QuPath script to visualize annotations on all z-slices, not just the current one.
*
* This is handy when annotating structures visible across z-slices, but where they might
* appear with better contrast in different slices.
*
* @author Pete Bankhead
*/
@petebankhead
petebankhead / QuPath-DeepCell demo.groovy
Last active December 2, 2020 19:04
Demo script showing one way to use the DeepCell Kiosk ImageJ plugin from QuPath
/**
* Run cell detection using the DeepCell Kiosk ImageJ plugin from
* https://github.com/vanvalenlab/kiosk-imagej-plugin
*
* For authorship & license of Deep Cell see http://deepcell.org
*
* To use the script, drag the Kiosk plugin on top of QuPath to make it available as an extension.
* Then select a (small!) region of interest in a compatible image and run this script from QuPath's script editor.
*
* Note that the image needs to be in a compatible format -
@petebankhead
petebankhead / QuPath-Pretty print OME-XML.groovy
Created November 30, 2020 16:54
Pretty print OME-XML from a Bio-Formats reader
server = getCurrentServer()
xml = server.dumpMetadata()
print groovy.xml.XmlUtil.serialize(xml)
@petebankhead
petebankhead / QuPath-Detect with ImageJ.groovy
Created September 9, 2020 18:12
General template for using ImageJ to detect ROIs from QuPath v0.2
/**
* General template for using ImageJ to detect ROIs from QuPath.
*
* Note the results of this script are terrible; it just applies a threshold per tile (calculated per tile).
* Its purpose is to show the process... not to do something useful in itself.
*
* However, in principle you just need to change the 'detectRois' method to something better to have something
* that might be worthwhile.
*
* @author Pete Bankhead
@petebankhead
petebankhead / QuPath-Synchronize image names for export.groovy
Created August 14, 2020 17:20
Update the image name in the ImageServer metadata to match with the image name in the project in QuPath v0.2.x.
/**
* Update the image name in the ImageServer metadata to match with the image name in the project.
*
* This can be used (with caution!) to work around the fact that v0.2.x uses the name from the server
* in measurement tables when they are export - not the project.
*
* Using 'Run -> Run for project' to apply it to all images in a project.
* Best back up (as always) before doing anything that will change data files, but an additional
* safeguard here is that the original metadata can still be accessed via server.getOriginalMetadata(),
* and can be reset by double-clicking the 'Metadata changed' entry under the 'Image' tab.
@petebankhead
petebankhead / QuPath-Import qpdata files to project.groovy
Created August 14, 2020 14:39
Import images from .qpdata files into a new project in QuPath v0.2.x.
/**
* Import images from .qpdata files into a new project in QuPath v0.2.x.
*
* The purpose of this is to help recover data from files that were saved outside a project.
* It may not work for all images, but should work for most 'straightforward' examples (i.e. a single image per image file).
*
* If your .qpdata files are already part of a v0.1.2 project, use 'File -> Project... -> Import images from v0.1.2' instead.
* If your .qpdata files are already part of a v0.2.0 project, use 'File -> Project... -> Add images' and add the .qpproj file instead.
*
* Warning! This hasn't been very extensively tested (I always use projects from the start...).