Exporting image overlay v0.2.0-m5

Hi,
I am using v0.2.0-m5 and I am trying to export an image overlay with annotation. I was using a script posted here when I was working with an older version and I have done my best to modify the methods and script to adhere to those compatible with the version I am using, but I keep getting an error. I would like the output to be similar to the image below.

I was able to achieve something similar through the user interface by selecting Rendered RGB, but I need to export many many images - so is there a way to script this command without opening the images in the viewer?

Desired Output

Script I have been using

import qupath.lib.gui.QuPathGUI
import qupath.lib.gui.viewer.OverlayOptions
import qupath.lib.regions.RegionRequest
// Aim for an output resolution of approx 20 µm/pixel
double requestedPixelSize = 20
// Create the output directory, if required
def path = buildFilePath(PROJECT_BASE_DIR, "image_exports")
mkdirs(path)
// Get the imageData & server
def imageData = getCurrentImageData()
def server = imageData.getServer()
def cal = server.getPixelCalibration()
// Get the file name from the current server
def name = server.getMetadata().getName()
// We need to get the display settings (colors, line thicknesses, opacity etc.) from the current viewer, if available
def overlayOptions = QuPathGUI.getInstance() == null ? new OverlayOptions() : QuPathGUI.getInstance().getViewer().getOverlayOptions()
// Calculate downsample factor depending on the requested pixel size
double downsample = requestedPixelSize / cal.getAveragedPixelSizeMicrons()
def request = RegionRequest.createInstance(imageData.getServerPath(), downsample, 0, 0, server.getWidth(), server.getHeight())
// Write output image, with and without overlay
def dir = new File(path)
def fileImage = new File(dir, name + ".jpg")
def img = ImageWriterTools.writeImageRegion(server, request, fileImage.getAbsolutePath())
def fileImageWithOverlay = new File(dir, name + "-overlay.jpg")
ImageWriterTools.writeImageRegionWithOverlay(img, imageData, overlayOptions, request, fileImageWithOverlay.getAbsolutePath())

Error Log

ERROR: Error at line 32: No signature of method: static qupath.lib.images.writers.ImageWriterTools.writeImageRegionWithOverlay() is applicable for argument types: (Boolean, qupath.lib.images.ImageData, qupath.lib.gui.viewer.OverlayOptions...) values: [true, ImageData: Brightfield (H-DAB), 2012-124-28F MFC 409.mrxs, ...]

ERROR: Script error
    at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1525)
    at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1511)
    at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:50)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
    at Script238.run(Script238.groovy:33)
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317)
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155)
    at qupath.lib.gui.scripting.DefaultScriptEditor.executeScript(DefaultScriptEditor.java:797)
    at qupath.lib.gui.scripting.DefaultScriptEditor.executeScript(DefaultScriptEditor.java:731)
    at qupath.lib.gui.scripting.DefaultScriptEditor.executeScript(DefaultScriptEditor.java:711)
    at qupath.lib.gui.scripting.DefaultScriptEditor$2.run(DefaultScriptEditor.java:1111)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)

Thanks for all your help!

You may want to consider the full 0.2.0 release for this.
https://qupath.readthedocs.io/en/latest/docs/advanced/exporting_images.html
There are sample scripts in the link above, and you should be able to open the 0.2.0-m5 project in full 0.2.0 (I think, but you can always make a copy of your project just to be safe). You can have multiple versions of QuPath on a computer at a time. I often put one version in “Dark mode” and keep one normal to help remind myself of which I am using at any given time.

Thanks for your reply!
I downloaded 0.2.0 and was unable to open the project in the newer version, so I re-imported my images and annotations.
I tried the different scripts but none of them did what I had hoped. They exported the images, but the exports did not show the annotation. Additionally, sometimes I would receive an error that said “No compatible writer!”

It also seems that the scripts in the link you provided are suited for exporting individual images, however I would like to export all the images with the annotation overlay in my project.

Is there any way to do this in v0.2.0-m5?

1 Like

Ah, sorry, it looks like writeImageRegionWithOverlay() was removed sometime before 0.2.0. I’m not sure about M5 anymore, it has been a long time. I can see how this functionality would be useful, though. I seem to remember a few months ago going through my whole project exporting one rendered RGB at a time.

At the moment the Rendered RGB you already mentioned is the only way I know of, but maybe @petebankhead has other options.

@petercla here is a script you may try with v0.2.0:

I haven’t tested it with v0.2.0-m5 – I suspect it may not be compatible due to further changes since then. I’m afraid I can’t really help with old milestone versions; it has been so long since I wrote the code that I can really only support the very latest version (and to some extent earlier stable releases). I would really recommend updating to the stable release if you can.

Since it is for export and not processing, you may be able to open your project (back it up first, just in case!) in v0.2.0 to run this script only.

1 Like