Skip to content

Instantly share code, notes, and snippets.

View petebankhead's full-sized avatar

Pete petebankhead

View GitHub Profile
@petebankhead
petebankhead / ImageJ_area_map.groovy
Created November 22, 2016 17:20
Convert an ImageJ binary image into an area map
/**
* Groovy script to convert a binary image into one in which every foreground pixel
* has a value equal to the area of the (8-connected) region containing it.
*
* Why?
*
* Well, this gives a way to apply an area-based threshold quickly and intuitively.
* Simply set a threshold on the area map, and apply it to create a new binary image.
*
* Created by Pete on 22/11/2016.
@petebankhead
petebankhead / ImageJ_pixel_access.groovy
Last active November 23, 2016 06:10
Different methods of accessing pixels within an ImageProcessor of ImageJ1
/**
* Testing different methods of accessing pixel values from
* an ImageProcessor within ImageJ1.
*
* (Personally, I prefer getf(x, y)....)
*
* Created by Pete on 23/11/2016.
*/
import ij.process.*
@petebankhead
petebankhead / QuPath_export_images.groovy
Created December 6, 2016 11:55
Export a thumbnail image, with and without an overlay, using QuPath
/**
* Export a thumbnail image, with and without an overlay, using QuPath.
*
* For tissue microarrays, the scripting code written by the 'File -> Export TMA data'
* command is probably more appropriate.
*
* However, for all other kinds of images where batch export is needed this script can be used.
*
* @author Pete Bankhead
*/
@petebankhead
petebankhead / QuPath_Run_menu_command.groovy
Last active December 6, 2016 14:25
Script that can be used to programmatically run a command from a QuPath menu
/*
* Sample script to run a GUI command from QuPath v0.1.1
*
* @author Pete Bankhead
*/
// Specify command to run
// Note: Only the simple name is required if the menu item has a unique name
// Otherwise, the full path to the menu item should be give, separated by >
@petebankhead
petebankhead / QuPath_Assign_TMA_core_metadata_by_row.groovy
Last active December 9, 2016 16:10
Simple script to assign metadata values to TMA cores according to row in QuPath
/**
* Simple script to assign metadata values to TMA cores according to row.
*
* @author Pete Bankhead
*/
import qupath.lib.scripting.QP
@petebankhead
petebankhead / QuPath_Assign_annotation_to_TMA_core_by_centroid.groovy
Created December 11, 2016 13:42
Assign a selected annotation to be a child of whichever TMA core contains its centroid
/*
* Assign a selected annotation to be a child of whichever TMA core contains its centroid.
*
* This can be useful whenever an annotation is drawn *slightly* overlapping the core,
* and so is not automatically assigned to be a child of the core - but it should be.
*
* @author Pete Bankhead
*/
// Ensure annotation is selected!
@petebankhead
petebankhead / Launch_QuPath_from_Fiji.groovy
Created December 21, 2016 22:55
Launching QuPath from within Fiji... sort of (it only partly works)
// Change this to reflect the path to QuPath!
// Here, I'm using a Mac.
// Note: I copied all native libraries (*.dylib, *.jnilib) into Fiji.app/lib/macos so that they could be found.
def pathQuPath = "/Users/pete/Desktop/QuPath.app/Contents/Java/"
// Get the Groovy classloader
def cl = this.class.classLoader
// Figure out where the main QuPath Jars are to be found
def dirBase = new File(pathQuPath)
@petebankhead
petebankhead / QuPath_guiscript_menu_trigger.groovy
Created December 31, 2016 13:02
Short script to show use of 'guiscript=true' within a script run through QuPath v0.1.2
// guiscript=true
def qupath = getQuPath()
def menuItem = qupath.getMenuItem("Automate>Show workflow command history")
menuItem.fire()
/* If guiscript=true is missing from the first line,
* then menuItem.fire() will fail because it is called on the wrong thread.
*
* In this case, the required syntax would be:
*
@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