Exporting multiple images to ImageJ using scripting

Hi all,
I’m looking to export multiple images from Qupath to ImageJ in one go using the script editor. At the moment I have been using the “Sending Image Region to ImageJ” button for each individual image. Does anyone have experience in trying this and would be able to help please?


The bit that actually saves the image is commented out, but this gives a starting point: https://petebankhead.github.io/qupath/scripting/2018/03/07/script-extracting-image-regions-to-imagej.html

Cheers Pete,
I’ll give it a go!


Hi Pete,

That script works great thanks. Just one more thing, is it possible to export detection objects created in qupath along with the image into ImageJ using this method? Sorry, I’m just starting out with the .groovy scripting.

Thanks again for your help, love the program.


1 Like

Ah, not so easily. With v0.1.2 I think this is probably the key method:

I can’t promise the method hasn’t shifted amidst all the refactoring I’m doing for v0.2.0 at the moment… although the benefit is that it should be more logical and documented after the changes.

It’s definitely scripting one way or another, just more complex. The minimal code to get something working will depend on

  • which version of QuPath you’re using
  • if you’re exporting a full image at full resolution, or a downsampled region
  • if your detections are cells, and you need both the nucleus ROI and the cell boundary ROI or just one of them
  • if you need annotations as well as detections transferred
  • if you need to handle extra dimensions (e.g. a time series or z-stack)

If you can describe in more detail what you want & for what purpose I’ll give a bit more thought to the simplest way to do it. For example, if you really want to get the detections to ImageJ because you’re wanting to get a binary mask then that could be generated directly in the script without any need to bother converting all the ROIs.

This commit adds more options to the command to send regions to ImageJ, and also handles multiple selections (i.e. by selecting multiple objects, you can send them all to ImageJ in one go without needing to script it).

Coming up in the next release…



Hi Pete,

Sorry for the late reply, I’ve been on holiday the past week.

We’re using Quapath 0.2.0
We are using down-sampled regions as these are whole face sections were looking at

We are using the pixel classifier to detect tumor and stroma and create detections from that. We’re then deleting the tumor detection as we’re only interested in the stroma. So essentially we’re looking to bring across the down-sampled image to imageJ with the one detection for stroma. We don’t need any time series or z-stack. We also don’t need any annotations transferred over, just the single stroma detection.

Once that’s in ImageJ, we are extracting random patches from the stroma area.

Thank you for taking the time to look into this,


If little tile images are the end goal, have you tried any of the QuPath scripts that do similar things? Not sure if there was something specific you were missing that needed to be run through FIJI.
An example.


This would be perfect for what we’re doing!

Unfortunately when I tried it, it saves the first tile ok, but after that I get an error:

ERROR: Error writing N:/Students/3053897 Kris McCombe/1_Image2.jpg with JPEG
ERROR: Unable to write N:/Students/3053897 Kris McCombe/1 1C_Image2.jpg! No compatible writer found.

Any ideas what causes this?

Thanks again for all your help,


It is trying to write a JPEG, so it might fail if you aren’t on a brightfield image? Not sure. There are other posts/issues about various writers not working, but again, I haven’t really played with it too much.

*Yes, a quick search shows: https://groups.google.com/forum/#!topic/qupath-users/ub6TC9IMmZ8