Created
September 2, 2025 13:42
-
-
Save rvalieris/d52493fc6e1dc0303b73bba95eaaaa2c to your computer and use it in GitHub Desktop.
Converts Qupath qpdata annotations to geojson
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 static groovy.io.FileType.FILES | |
| def WSI_DIR = '/path/to/WSI/' | |
| def WSI_EXT = '.svs' | |
| def WSI_ANNOTS_DIR = '/path/to/qpdata/annots/' | |
| def WSI_ANNOTS_EXT = '.qpdata' | |
| def OUT_DIR = '/path/to/outputs/' | |
| def wsi_map = [:] | |
| new File(WSI_DIR).eachFileRecurse(FILES) { | |
| if(it.name.endsWith(WSI_EXT)) { | |
| def key = it.name.replace(WSI_EXT, '') | |
| wsi_map[key] = it.toString() | |
| } | |
| } | |
| new File(WSI_ANNOTS_DIR).eachFileRecurse(FILES) { | |
| if(it.name.endsWith(WSI_ANNOTS_EXT)) { | |
| def key = it.name.replace(WSI_ANNOTS_EXT, '') | |
| var server = qupath.lib.images.servers.ImageServerProvider.buildServer(wsi_map[key], java.awt.image.BufferedImage.class); | |
| def imageData = qupath.lib.io.PathIO.readImageData(it, null, server, BufferedImage) | |
| var hier = imageData.getHierarchy() | |
| var annots = hier.getAnnotationObjects() | |
| exportObjectsToGeoJson(annots, OUT_DIR+'/'+key+'.geojson') | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment