Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing/Pregeneration Annotations.. #61

Closed
dgutman opened this issue Mar 31, 2017 · 4 comments
Closed

Importing/Pregeneration Annotations.. #61

dgutman opened this issue Mar 31, 2017 · 4 comments

Comments

@dgutman
Copy link

dgutman commented Mar 31, 2017

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?

@petebankhead
Copy link
Member

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:

  • Create a region of interest from the exported coordinates
  • Create an annotation for the ROI
  • Add the annotation to the object hierarchy

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.

@DanaCase
Copy link

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

petebankhead added a commit to petebankhead/qupath that referenced this issue Apr 23, 2020
qupath#455
qupath#238
qupath#61

In the end, just easier to add it. Also, XmlUtil.serialize(String) makes pretty-printing straightforward.
@Monk5088
Copy link

Monk5088 commented Aug 5, 2022

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

@Monk5088
Copy link

Monk5088 commented Aug 5, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants