Skip to content

Instantly share code, notes, and snippets.

@steermomo
Created February 13, 2019 06:00
Show Gist options
  • Save steermomo/e4fc29fdcf249ec672ec27e871b96c40 to your computer and use it in GitHub Desktop.
Save steermomo/e4fc29fdcf249ec672ec27e871b96c40 to your computer and use it in GitHub Desktop.
import qupath.lib.scripting.QP
import qupath.lib.geom.Point2
import qupath.lib.roi.PolygonROI
import qupath.lib.objects.PathAnnotationObject
import qupath.lib.images.servers.ImageServer
//Aperio Image Scope displays images in a different orientation
def rotated = false
def server = QP.getCurrentImageData().getServer()
def h = server.getHeight()
def w = server.getWidth()
// need to add annotations to hierarchy so qupath sees them
def hierarchy = QP.getCurrentHierarchy()
//Prompt user for exported aperio image scope annotation file
def file = getQuPath().getDialogHelper().promptForFile('xml', null, 'aperio xml file', null)
def text = file.getText()
//print(text)
def list = new XmlSlurper().parseText(text)
//println("hello world")
println(list.Annotation)
list.Annotations.each {
// println("hello world")
it.Annotation.each { region ->
// println("hello world")
def tmp_points_list = []
region.Coordinates.Coordinate.each{ vertex ->
if (rotated) {
X = vertex.@Y.toDouble()
Y = h - vertex.@X.toDouble()
}
else {
X = vertex.@X.toDouble()
Y = vertex.@Y.toDouble()
}
tmp_points_list.add(new Point2(X, Y))
}
def roi = new PolygonROI(tmp_points_list)
def annotation = new PathAnnotationObject(roi)
hierarchy.addPathObject(annotation, false)
}
}
@steermomo
Copy link
Author

steermomo commented Feb 13, 2019

将ASAP的标注XML转为QuPath能够加载的标注.
出自于https://gist.github.com/DanaCase/9cfc23912fee48e437af03f97763d78e
做了些修改以适用于ASAP某医院的标注

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