Closed dgutman closed 7 years ago
This is certainly possible. The easiest way to start would be to write a Groovy script for the import, although you could also create a Java extension if needed. The latter would require more code, but could incorporate extra user-friendliness (e.g. a menu item, drag-and-drop support).
For each boundary, the process would be something like this:
Most code for specific ROIs is here - so you could create rectangles, ellipses or lines if required, or just stick with PolygonROI for polygons. The most useful constructor is:
public PolygonROI(float[] x, float[] y, int c, int z, int t)
For c
, z
and t
(channel, z-slide & time point) you can probably use -1
, 0
, 0
by default.
After creating your polygon ROI, then create a PathAnnotationObject
with the ROI:
public PathAnnotationObject(ROI pathROI)
and finally you can add this annotation to the hierarchy simply with
addObject(annotation)
I have some memory of Aperio ImageScope having a concept of layers, and also 'negative' regions; I don't know if this would also be in your XML. If so, these may not have exact matches inside QuPath, but there are various tricks you could use if you find they are needed (e.g. combining or subtracting ROIs, adding them to the hierarchy in different ways, setting names, classifications or colors etc.).
If you haven't already, I suggest checking out the Wiki for Writing custom scripts and Advanced scripting with IntelliJ, which can help with writing the code and accessing the QuPath source.
Finally, it may also be useful to know that, if you want to use any other Java libraries to help, then you can drag the required Jar file onto QuPath to copy it into QuPath's extensions directory. Even if the Jar isn't a 'real' QuPath extension, this means that it will still be available on QuPath's classpath when running the script. This could be useful if your XML parsing code is already contained in a Jar, or if you want to add another library (e.g. groovy-xml.jar
) to help with scripting the parsing.
Hopefully that helps to get started.
Just in case anyone still needs this I put up a gist of a script I wrote to go directly from Aperio to QuPath: https://gist.github.com/DanaCase/9cfc23912fee48e437af03f97763d78e
We have a lot of annotations previously done using Aperio ScanScope which generates the XML files. We already have code that can parse those files and eliminate the boundaries for the various objects/layers....
We'd like to be able to compare analysis results done using QuPath with those we previously did in ScanScope, without having to redraw the annotations ...
If we had the boundaries of the shapes (lets just assume polygons for general use case), would it be possible to somehow import them and create an annotation layer we could use for analysis?
Hey @dgutman can you share the code on how to parse those XML files for annotations, actually I have an XML file for the .scn digital histopathology image and one of those XML files has 4 vertices for a region while another XML file has 2 vertices for a region and I am baffled on how to work with them, It would be of great help if you could please share the code for parsing the image scope anootation.xml file, they need to be converted into MS COCO .json format with bounding boxes, so if you have conversion code too, that would be super helpful. Thanking you in advance, Warm regards, Harshit
Hey everyone I was working with .xml files of image scope for annotation of .scn WSIs and I want to parse those XML files so that they can be later converted into MS COCO .json annotation format with boxes. can anyone share the link on how to parse those? XML files of annotations, the problem is I have 2 XML files and both of them have different structures like one XML has 4 vertices for a region and the other XML file has 2 vertices for a region and when I open both of them in image scope .scn images they both show ellipse kinda polygon region and I need to convert those coordinates into bounding boxes rectangular shape (xmin ymin ,xmax,ymax). Also , the XML files are for different .scn images. Any kind of code notebook, snippet, or resource is welcome. Thanking you all in advance for creating such an amazing platform for discussion, Warm regards, Harshit
We have a lot of annotations previously done using Aperio ScanScope which generate the XML files. We already have code that can parse those files and get out the boundaries for the various objects/layers....
We'd like to be able to compare analysis results done using QuPath with those we previously did in ScanScope, without having to redraw the annotations ...
If we had the boundaries of the shapes (lets just assume polygons for general use case), would it be possible to somehow import them and create an annotation layer we could use for analysis?