Skip to content

Instantly share code, notes, and snippets.

@SachidanandAlle
Created September 28, 2022 06:31
Show Gist options
  • Save SachidanandAlle/465d7393cccb2dc092ea1897aaeddced to your computer and use it in GitHub Desktop.
Save SachidanandAlle/465d7393cccb2dc092ea1897aaeddced to your computer and use it in GitHub Desktop.
Import ASAP xml into QuPath
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
def server = QP.getCurrentImageData().getServer()
def hierarchy = QP.getCurrentHierarchy()
def file = new File("C:\\Dataset\\JP2K-33003-1-patch-2217_4809_368_268.xml")
//def file = getQuPath().getDialogHelper().promptForFile('xml', null, 'asap xml file', null)
def text = file.getText()
def doc = new XmlParser().parseText(text)
doc.Annotations.Annotation.Coordinates.each { region ->
def points = []
region.Coordinate.each{ vertex ->
X = vertex.@X.toDouble()
Y = vertex.@Y.toDouble()
points.add(new Point2(X, Y))
}
def roi = new PolygonROI(points)
def annotation = new PathAnnotationObject(roi)
hierarchy.addPathObject(annotation, false)
}
QP.fireHierarchyUpdate(hierarchy);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment