I am trying to apply U-Net multi-class segmentation procedure on whole slide histopathology brightfield images that were annotated in QuPath by several tissue region categories such as tumor, normal, stroma etc.
See example of multi class annotations (showing only a small subset of a slide):

I need to bring the QuPath annotations into a single whole slide binary multi-channel PNG image where each tissue region category has its mask coded (for all the regions/elements in the slide) in the corresponding channel, in addition to a background channel annotating all the non annotated pixels. Alternatively, I would have a Python Numpy array coding the same annotation, but these two formats are interchangeable. Alternatively, XML output of the annotations should work too.
The problem is that Python access to QuPath project files is not possible, and QuPath groovy scripts focus on tiles or individual ROIs instead of the whole image.
Is there an existing script performing such task or can you advise how to arrive at one that does so?
Thanks
QuPath lets you export patches in the GeoJSON format. You can build a mask of the annotations using python directly by making a blank numpy array and using
from matplotlib.patches import Polygonto draw the polygons using the data you have exported.To load the whole slide image in python use openslide python.
I am guessing that you plan to use a low resolution version of the whole slide image, otherwise you will be facing some memory problems. So you can pull out a low resolution image of the whole slide image and downscale the numpy array of annotations to match the dimensions of the image.