Re: combine function of the ROI manager
Posted by
Nathaniel Ryckman on
Mar 28, 2011; 9:01pm
URL: http://imagej.273.s1.nabble.com/combine-function-of-the-ROI-manager-tp3685239p3685243.html
-wayne
Rasband, Wayne (NIH/NIMH) [E] wrote
On Aug 6, 2010, at 1:13 PM, Sebastien Tosi wrote:
> Thank you Wayne, this works fine. Now I have to find out how to call
> javascript from a macro and pass arguments to the script (here basically the
> 2 indexes of the ROIs to be merged)... what is the best way to do this?
A macro can call JavaScript using the eval() function. Here is an example:
index1 = 1;
index2 = 3;
script =
"index1="+index1+";\n" +
"index1="+index2+";\n" +
"manager = RoiManager.getInstance();\n" +
"if (manager==null)\n" +
" IJ.error(\"ROI Manager is not open\");\n" +
"rois = manager.getRoisAsArray();\n" +
"roi1 = new ShapeRoi(rois[1]);\n" +
"roi2 = new ShapeRoi(rois[3]);\n" +
"combined = roi1.or(roi2);\n" +
"manager.addRoi(combined);\n";
eval("script", script);
-wayne
I am disappointed that script is needed to do such a basic task. I guess it's worth it since ImageJ is really versatile in most other respects.
The problem is that the script hack doesn't work in batch mode for me. I know that there is
a RoiManager instance running because roiManager("Count") is working properly, but still the script "RoiManager.getInstance()" is returning null.
Any advice or ideas? Where could I find more about how the ROI Manager works in batch mode?
Thanks!