Running an ImageJ Macro for a Whole Project

287 views
Skip to first unread message

Alexander Katsis

unread,
Jan 12, 2018, 2:46:37 PM1/12/18
to QuPath users
I have a QuPath script which I am using and can run it for all images in my project. I also have an ImageJ macro which runs as intended from the ImageJ macro runner. Now what I want to do is incorporate this ImageJ macro runner into my QuPath script so that it can be run for all images in the project. Essentially for all images I want to run a QuPath script that generates detections, then kick out these detections to ImageJ and run a macro there. I have tried looking at the ImageJ Macro Runner API but am still stuck. 

Any help would be much appreciated.

Thanks,

Alex  

Pete

unread,
Jan 12, 2018, 4:27:44 PM1/12/18
to QuPath users
The API doesn't currently make this very easy, although it probably should... Although depending on what you ImageJ macro does, it might be preferable to skip this step and do all the work in QuPath + Groovy.

Anyway, maybe the following helps:

import qupath.imagej.plugins.ImageJMacroRunner
import qupath.lib.plugins.parameters.ParameterList

// Create a macro runner so we can check what the parameter list contains
def params = new ImageJMacroRunner(getQuPath()).getParameterList()
print ParameterList.getParameterListJSON(params, ' ')

// Change the value of a parameter, using the JSON to identify the key
params.getParameters().get('downsampleFactor').setValue(4.0 as double)
print ParameterList.getParameterListJSON(params, ' ')

// Get the macro text and other required variables
def macro = 'print("Overlay size: " + Overlay.size)'
def imageData = getCurrentImageData()
def annotations = getAnnotationObjects()

// Loop through the annotations and run the macro
for (annotation in annotations) {
   
ImageJMacroRunner.runMacro(params, imageData, null, annotation, macro)
}
print 'Done!'

I don't know how well or robustly it works, and the manipulation of the ParameterList is a bit awkward.  But hopefully it gives a starting point.

Alexander Katsis

unread,
Jan 19, 2018, 11:35:46 AM1/19/18
to QuPath users
Hi Pete,

Thanks a lot for that. I will play around with it some more and see if I can get it to work.

-Alex

Alexander Katsis

unread,
Jan 19, 2018, 2:17:22 PM1/19/18
to QuPath users
Just to give a follow up, it worked great for what I needed to do. I definitely suggest this approach to anyone who needs to do batch QuPath and ImageJ together.

micros...@gmail.com

unread,
Jan 19, 2018, 2:46:35 PM1/19/18
to QuPath users
Were you able to return data from ImageJ to QuPath?  I remember that being a stumbling block elsewhere with the Send Overlay to QuPath command.  Just wondering if you found some way around that, or your macro did not involve returning new data to QuPath.

Alexander Katsis

unread,
Jan 19, 2018, 6:14:13 PM1/19/18
to QuPath users
My macro didn't send anything back to QuPath, it just saved ImageJ modified images. It's something I want to try out at some point though.
Reply all
Reply to author
Forward
0 new messages