Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petebankhead/6d6f7ed2f4e505befdcc3b4083548952 to your computer and use it in GitHub Desktop.
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
/**
* 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