QuPath export rendered image in batch mode


I am using the wonderful #qupath (thanks @petebankhead and the QuPath team!!), version 0.2.1, on Linux, but ran into a little snag that I am pretty sure must have an “easy” fix, but I can’t find it…

Here’s the script. I have 37 images in the project. I would like to batch (“Run for project”) through all of them. Sounds easy enough…except that if you have an image in the viewer, it always saves the same image (changes the filename though!!). If no image is open (i.e. fresh from opening the project), I get a NullPointerException (see below)

import qupath.lib.gui.images.servers.RenderedImageServer

double downsample = 10.0

def viewer = getCurrentViewer()
def server = RenderedImageServer.createRenderedServer(viewer)

def request = RegionRequest.createInstance(server, downsample)
def img = server.readBufferedImage(request)

def name = getProjectEntry().getImageName()
def path = buildFilePath(PROJECT_BASE_DIR,‘rgb overlays results’, name.replaceAll(’.svs’,’-withTumors.png’))
writeImage(img, path)
print ‘Done!’


INFO: Starting script at Tue Jul 07 14:04:52 CDT 2020
ERROR: NullPointerException at line 6: null

ERROR: qupath.lib.gui.images.servers.RenderedImageServer.(RenderedImageServer.java:73)

If there is no easy fix, is there a way to force a viewer to appear/update to the current image in batch mode? Sort of like turning batch mode off in ImageJ…?

Thanks for any help…

If you are referring to something like what Pete has written here:

then you need a viewer open for the script to know things like “which layers are turned on or off” “how are the brightness and contrast settings set” etc.
Once you have a single image open, you can run it for project. Note that it uses the imageData to access the image, not the viewer. It looks like your script does not access the imageData (per image) and keeps accessing at the current viewer (what you have open) over and over.

1 Like

Thanks!! Exactly what I was looking for… So sorry for not having spotted that post! Worked like a charm…

And was able to tune the display with :

// Tune options for opacity 30%
def options = viewer.getOverlayOptions()

Thanks agani

1 Like