Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petebankhead/62487aa2a6c772ac9b7ecc6f449e5749 to your computer and use it in GitHub Desktop.
Save petebankhead/62487aa2a6c772ac9b7ecc6f449e5749 to your computer and use it in GitHub Desktop.
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.
*
* @author Pete Bankhead
*/
// Define measurement ID and size of the sublists to work with
String pixelClassifierName = 'Some classifier name'
String measurementID = 'Some measurement'
int subListLength = 128
// Get the current image and load a pixel classifier
def imageData = getCurrentImageData()
def pixelClassifier = loadPixelClassifier(pixelClassifierName)
// Get all the cells
def cells = getCellObjects()
// Split into smaller lists
def littleLists = cells.collate(subListLength)
// Process the little lists in parallel
littleLists.parallelStream()
.forEach(list -> {
// Create a measurement manager for the image and classifier
def manager = PixelClassifierTools.createMeasurementManager(imageData, pixelClassifier)
PixelClassifierTools.addMeasurements(list, manager, measurementID)
})
// Fire update event
fireHierarchyUpdate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment