Project idea: Improve annotation export for AI training #2
Replies: 5 comments 8 replies
-
|
I like this. I was quite happy when I managed to export pre-processed tiles containing object instances, but then I noticed that my total number of instances was greater than 65535 and the tiles were exported as RGB images. I have to admit, I wasn't able to modify the |
Beta Was this translation helpful? Give feedback.
-
|
I'd really like to be able to specify the image downsampling method when resampling images as part of the TileExporter call but I cant find where the default downsampling algorithm is specified, if someone knows where it is, that would be tremendesouly helpful, but otherwise I'll keep digging... |
Beta Was this translation helpful? Give feedback.
-
|
I have not looked it up in the code (so @petebankhead please correct me), but I am fairly confident the only type of downsampling that would be supported by default would be a mean. Other methods (decimation, median, etc.) would not preserve the quantitative nature of the data, and that is usually the point of this type of analysis (not always, but usually). Other methods tend to be useful for upsampling - there is a whole variety of options, but that is creating data rather than preserving it. |
Beta Was this translation helpful? Give feedback.
-
|
@SalmaDammak here's the script from this afternoon (or morning) :) // Delete old annotations created by this script
// (to make debugging easier when running multiple times...)
def toDelete = getAnnotationObjects().findAll(p -> p.getPathClass() == getPathClass('My new intersection'))
removeObjects(toDelete, true)
// Get all annotations classified as tumor
def hierarchy = getCurrentHierarchy()
def annotations = getAnnotationObjects()
def tumorAnnotations = annotations.findAll(a -> a.getPathClass() == getPathClass('Tumor'))
// Store list of new annotations
// Means we can add them in one go (and avoid firing lots of addObject events)
def newAnnotations = []
// Loop through tumor annotations
for (def a in tumorAnnotations) {
// Get all the objects that overlap with the ROI bounding box
def region = ImageRegion.createInstance(a.getROI())
def overlapping = hierarchy.getObjectsForRegion(null, region, null)
overlapping.remove(a)
// Check for objects that overlap the tumor annotation
def geometry = a.getROI().getGeometry()
overlapping = overlapping.findAll(a2 -> a2.isAnnotation() && geometry.intersects(a2.getROI().getGeometry()))
// Loop through the overlapping objects
for (def overlappingObject in overlapping) {
// Compute the intersection
def overlappingROI = overlappingObject.getROI()
def roiIntersection = RoiTools.intersection([a.getROI(), overlappingROI])
// Calculate dice score
def areaIntersection = roiIntersection.getArea()
def dice = 2 * areaIntersection / (overlappingROI.getArea() + a.getROI().getArea())
// Create new annotation for the intersection and add dice score as a measurement
def newAnnotation = PathObjects.createAnnotationObject(roiIntersection, getPathClass('My new intersection'))
newAnnotation.getMeasurementList().putMeasurement('Dice', dice)
newAnnotation.getMeasurementList().close()
newAnnotations << newAnnotation
}
}
// Add the new (intersection) annotations all in one go
addObjects(newAnnotations) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
A lot of questions on the forum are about exporting annotations and image patches in specific ways - usually for AI training.
Currently, the main approach is to use a scripting recipe from
Project
The challenge is that everyone seems to want export in some slightly different way... so the current recipes often aren't quite enough.
The goals of this project are to:
Beta Was this translation helpful? Give feedback.
All reactions