Script for 'Send Region to ImageJ'

Hello,
I am very new to QuPath scripting, so please forgive me for what I assume is quite a simple problem!
When I select an annotation and ‘Send Region to ImageJ’ I have the option of including the overlay, which is what I need for my analysis.
However, when I run this script: https://qupath.readthedocs.io/en/latest/docs/scripting/overview.html#working-with-imagej
I do get the same output in imageJ except the overlay with the cell detection is not there. So my question is what can I add to the script in order to take the overlay into the ImageJ export.

One other minor thing is that using the script the output file is the file name of the scan, but when I use the command in QuPath it is the name of the Annotation. How would this be handled in the script?

Many thanks

To clarify, do you want the overlay as an ImageJ overlay (ROI manager), or the overlay as part of the image (burned in)?

You can try adding this to the end of the existing script:

def overlay = IJExtension.extractOverlay(getCurrentHierarchy(), request,
    getCurrentViewer().getOverlayOptions(), 
    {it != roi}
    )
imp.setOverlay(overlay)

Alternatively you could use this script, which should do much the same thing:

import qupath.imagej.gui.IJExtension

double downsample = 2.0

def server = getCurrentServer()
def selectedObject = getSelectedObject()
def request = RegionRequest.createInstance(server.getPath(), downsample, selectedObject.getROI())
boolean setROI = true

def imp = IJExtension.extractROIWithOverlay(
    getCurrentServer(),
    selectedObject,
    getCurrentHierarchy(),
    request,
    setROI,
    getCurrentViewer().getOverlayOptions()
    ).getImage()
 
 imp.show()

I’m not sure exactly what you mean here, since none of these scripts output any files. So not sure if it helps but you can set the name of the image in ImageJ with

imp.setTitle("Something")
1 Like

Thanks a lot Pete, that did work!
I have another question more focused on what I am trying to achieve with my analysis. Should I start another thread?

Good! And thanks for asking, I’d say yes to starting a new thread - helps to keep threads short and focussed when looking for an answer later :slight_smile: