Delete cytoplasm from detections / convert only nuclei to annotations

Is there any way to delete the cytoplasm from cell detections? I want to train a classifier using data from both nuclei and cytoplasm (nucleus expansion), since cytoplasm info impoves the classifiers significantly, but then I want to convert ONLY the nuclus detections to annotations (for mask export to deep learning segmentation). I’m only able to convert the full cell detections (nucleus pluss cytoplasm merged) to annotations, but I would like to create annotations from detections from the nuclei only. Anyone?

Using this script for conversion from detections to annotations:

import qupath.lib.objects.PathAnnotationObject

// Create new annotations with the same ROIs and classifications as the detections
def detections = getDetectionObjects()
def newAnnotations = detections.collect {detection -> new PathAnnotationObject(detection.getROI(), detection.getPathClass())}

// Remove the detections, add the annotations

Instead of detection.getROI(), use detection.getNucleusROI().

Or PathObjectTools.getROI(detection, true) if you want to get the nucleus where available, and the main ROI if no nucleus can be found.


Excellent, thank you, Pete!

In case I ever dig into something like this for DL training, it looks like it is possible for the LabelServer to use detections instead of annotations? There is a setting for “useDetections(),” which seems like it might be a faster way to go (at least, if there are many, many nuclei).

Of course, it might be slower to strip out all of the detections and temporarily replace them with nuclei detections than to create annotations, in some (most?) cases.

1 Like