Last active
February 26, 2024 16:49
-
-
Save petebankhead/62487aa2a6c772ac9b7ecc6f449e5749 to your computer and use it in GitHub Desktop.
Add pixel classifier measurements to all cells in an image using QuPath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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