Created
May 29, 2023 12:06
-
-
Save petebankhead/6d6f7ed2f4e505befdcc3b4083548952 to your computer and use it in GitHub Desktop.
QuPath script to export images corresponding to all the annotation bounding boxes in an image
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
/** | |
* QuPath script to export images corresponding to all the annotation bounding boxes in an image. | |
* Written for QuPath v0.4.3. | |
*/ | |
// Export at full resolution (or change this value) | |
double downsample = 1.0 | |
// Export to a subdirectory of the current project | |
def dir = buildPathInProject("export") | |
mkdirs(dir) | |
// Loop through annotations and export | |
def server = getCurrentServer() | |
def annotations = getAnnotationObjects() | |
for (def annotation in annotations) { | |
def request = RegionRequest.createInstance( | |
server.getPath(), | |
downsample, | |
annotation.getROI() | |
) | |
def name = getCurrentImageNameWithoutExtension() | |
def outputName = "${name}-${request.x} [${request.y},${request.width},${request.height}].tif" | |
def path = buildFilePath(dir, outputName) | |
println path | |
writeImageRegion(server, request, path) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment