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 / DoG_filter.ijm
Created December 27, 2016 19:05
An example ImageJ macro implementing a Difference of Gaussians filter
// Prompt to get sigma values for the Difference of Gaussians filtering
Dialog.create("Choose filter sizes for DoG filtering");
Dialog.addNumber("Gaussian sigma 1", 1);
Dialog.addNumber("Gaussian sigma 2", 2);
Dialog.show();
sigma1 = Dialog.getNumber();
sigma2 = Dialog.getNumber();
// Get the current image
idOrig = getImageID();
@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_subcellular_detection_location.groovy
Created January 1, 2017 11:12
Set the classification of a subcellular detection according to whether it is inside or outside the nucleus
// Note: This sets the class according to spot/cluster location,
// but does not try to set meaningful colors at this point
// Get all spots/clusters
def clusters = getObjects({p -> p.class == qupath.imagej.detect.cells.SubcellularDetection.SubcellularObject.class})
// Loop through all clusters
for (c in clusters) {
// Find the containing cell
def cell = c.getParent()