How to export annotations as binary masks in batches

How to export annotations as binary masks in batches?I used this script,Script(s) of the Day: Exporting & importing binary masks | Pete’s blog. But in “run for project”, I get the following result,image
how should I modify the script? Or I cannot export multiple pictures as masks in one project ?

Hi @day0, the blog is out of date now & most of the important stuff has been updated and added to the main documentation. Have you checked out this page?
https://qupath.readthedocs.io/en/latest/docs/advanced/exporting_annotations.html

Thank you very much. I re-used the script and changed it to “.multichannelOutput(true)”. I still got the following results in “run for project”. How should I solve this problem?

There really isn’t enough information for anyone to answer properly. I don’t know which script you used specifically, what annotations you have, or how they are classified.

I use this Exporting annotations — QuPath 0.2.3 documentation use this, I just simply annotate it on the picture.

There are multiple scripts on that page, so it still isn’t clear exactly what you’ve run. However my guess is that you may have copied & pasted one of the scripts that requires your annotations to be classified, but you haven’t classified them.

Note the descriptions in the text, e.g.

The following script creates a LabeledImageServer , and loops through all annotations in an image with the clasifications Tumor , Stroma and Other

Sorry, I used the script under “Individual annotations”,


I added the class again, and still got the following results in “run for project”.

Does it work without ‘Run for project’?

If so, the issue is probably that you need to save the annotations on the current image. ‘Run for project’ operates on the saved data files – so if you have unsaved changes open in the current viewer then these won’t have any impact.

Thank you very much, it works!

1 Like

I have another question. I want to export the annotation marked as binary mask and the original image at the same time. I used this script Exporting annotations — QuPath 0.2.3 documentation, #Labeled tiles part. how to determine the “.tileSize(512)” in the script to export the original size? The result is similar to this.

To get output similar to your examples, you probably want the Individual annotations script instead.

You’ll need to modify it slightly to include the original image as well – see Exporting Stardist2D nuclei mask within annotations - #5 by petebankhead