Transfer class from parent annotation to detections

Hi! Wondering if anyone has a working script for transfering the class of the parent annotation to the detections it covers. Something like
“select all detections with parent annotations of class (‘tumor’)”
Then, classifySelected(‘Tumor’).

The following script should do it for all annotations:

def hierarchy = getCurrentHierarchy()

def annotations = getAnnotationObjects()
for (annotation in annotations) {
    def pathClass = annotation.getPathClass()
    def detections = hierarchy.getObjectsForROI(null, annotation.getROI())
        .findAll {it.isDetection()}
    detections.each {it.setPathClass(pathClass)}
}
fireHierarchyUpdate()

Note that it doesn’t make any special efforts to handle nested annotations that may have different classifications.

Depending upon the goal, Selection mode might be a simpler alternative.

4 Likes

Thanks so much, Pete! Haven’t tried it, but from my experience pretty much everything you suggest works:) It’s for batch processing so selection mode wouldn’t work I think.