Hi Pete,
thank you for the 2 scripts.
Both did not bring any change.
I assume that the problem might arise before in the conversion of the positive pixelcount into Annotation-ROIs.
I tried with two scripts. Both do not show the same behavior.
selectObjects {
return it.getPathClass() == getPathClass('Positive')
}
/* Author: Micros in QuPath Forum
* A script to create annotation object(s) having the same ROI as any
* (other) currently selected object(s).
*/
import qupath.lib.objects.PathAnnotationObject
import qupath.lib.roi.RectangleROI
import qupath.lib.scripting.QP
// Set this to true to use the bounding box of the ROI, rather than the ROI itself
boolean useBoundingBox = false
// Get the current hierarchy
def hierarchy = QP.getCurrentHierarchy()
// Get the select objects
def selected = hierarchy.getSelectionModel().getSelectedObjects()
// Check we have anything to work with
if (selected.isEmpty()) {
print("No objects selected!")
return
}
// Loop through objects
def newAnnotations = new ArrayList<>()
for (def pathObject in selected) {
// Unlikely to happen... but skip any objects not having a ROI
if (!pathObject.hasROI()) {
print("Skipping object without ROI: " + pathObject)
continue
}
// Don't create a second annotation, unless we want a bounding box
if (!useBoundingBox && pathObject.isAnnotation()) {
print("Skipping annotation: " + pathObject)
continue
}
// Create an annotation for whichever object is selected, with the same class
// Note: because ROIs are (or should be) immutable, the same ROI is used here, rather than a duplicate
def roi = pathObject.getROI()
if (useBoundingBox)
roi = new RectangleROI(
roi.getBoundsX(),
roi.getBoundsY(),
roi.getBoundsWidth(),
roi.getBoundsHeight(),
roi.getC(),
roi.getZ(),
roi.getT())
def annotation = new PathAnnotationObject(roi, pathObject.getPathClass())
newAnnotations.add(annotation)
print("Adding " + annotation)
}
// Actually add the objects
hierarchy.addPathObjects(newAnnotations, false)
if (newAnnotations.size() > 1)
print("Added " + newAnnotations.size() + " annotation(s)")
and
/*
* Convert annotation objects to detections.
* Warning! This may be very slow, and a bad idea!
* It is intended to show the different behavior between
* detection & annotation objects.
*/
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
removeObjects(detections, false)
addObjects(newAnnotations)
surprisingly also a simple operation like subtract annotations does not work with the resulting Annotation ROI from the Positive Pixel-Count.