@sophia1 the main ways to export images (possibly including annotations) are summarized at
The main thing to decide is whether QuPath should do the tiling or not… which may depend partially upon whether your regions are too big to export in one go.
To export a rectangle corresponding to a single annotation, use
// Write the region of the image corresponding to the currently-selected object
def roi = getSelectedROI()
def requestROI = RegionRequest.createInstance(server.getPath(), 1, roi)
writeImageRegion(server, requestROI, '/path/to/export/region.tif')
But you’ll still probably need an associated mask, so need to look into annotation export as well… which means the
The labels/masks are important because at some point you need to decide whether or not a tile that overlaps your annotation boundary is included in your ‘tumor’ class for training. Exporting an annotation mask alongside your image allows you to control/check this later, e.g. in your Python code.
For example, you might decide to include a tile if its centroid is in the tumour region, if > 50% is within the tumour region… etc. Personally, I think it’s better to have a simple export script in QuPath that provides the information that you can later untangle in Python according to your precise application – rather than writing a complex QuPath script that makes these decisions at the point of export.
That’s the rationale for the
LabeledImageServer design as they currently are: they give flexible ways to export image tiles and masks for deep learning training. You can use either the
TileExporter or the
LabeledImageServer, both of them together, or neither if you prefer to write an alternative export script.