-
-
Save sbalci/22b34a341759e84781ce7501e2f62f76 to your computer and use it in GitHub Desktop.
Convert Exported Aperio Image Scope Annotations to QuPath Annotations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = true | |
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() | |
def list = new XmlSlurper().parseText(text) | |
list.Annotation.each { | |
it.Regions.Region.each { region -> | |
def tmp_points_list = [] | |
region.Vertices.Vertex.each{ vertex -> | |
if (rotated) { | |
X = [email protected]() | |
Y = h - [email protected]() | |
} | |
else { | |
X = [email protected]() | |
Y = [email protected]() | |
} | |
tmp_points_list.add(new Point2(X, Y)) | |
} | |
def roi = new PolygonROI(tmp_points_list) | |
def annotation = new PathAnnotationObject(roi) | |
hierarchy.addPathObject(annotation, false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment