JavaScript batch mode doesn't have open images?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

JavaScript batch mode doesn't have open images?

Adam Goode
Hi,

I am converting some old macros to JavaScript to use with the -batch
command line. The macro contains some run(...) commands that call other
plugins that open multiple windows. With the old macro system, in batch
mode, I could close images and work with the active image, but with
JavaScript, there are never any images open. IJ.getImage() produces an
error.

It looks like the Interpreter class contains a mechanism for holding
onto images in batch mode (the imageTable). Can this be made to work
when executing JavaScript?



Thanks,

Adam
Reply | Threaded
Open this post in threaded view
|

Re: JavaScript batch mode doesn't have open images?

Adam Goode
On 06/21/2010 06:18 PM, Rasband, Wayne (NIH/NIMH) [E] wrote:

> On Jun 21, 2010, at 4:47 PM, Adam Goode wrote:
>
>> Hi,
>>
>> I am converting some old macros to JavaScript to use with the -batch
>> command line. The macro contains some run(...) commands that call other
>> plugins that open multiple windows. With the old macro system, in batch
>> mode, I could close images and work with the active image, but with
>> JavaScript, there are never any images open. IJ.getImage() produces an
>> error.
>>
>> It looks like the Interpreter class contains a mechanism for holding
>> onto images in batch mode (the imageTable). Can this be made to work
>> when executing JavaScript?
>
> Adam,
>
> Batch mode mode only works with macros. Plugins and scripts need to work with images, in the form of ImagePlus and ImageProcessor objects, that have not been displayed. Do the plugins you are using have public methods that return processed images without displaying them?
>


Hi,

Looking through the ImageJ code, it appears that setting
Interpreter.batchMode to true should be all that is needed to enable the
batch mode window list. Indeed, adding this JavaScript makes things work
again in batch mode:

 Packages.ij.macro.Interpreter.batchMode = true;

This is clearly a hacky workaround, would it be possible for this to be
set by ImageJ when "-batch" is specified, even when JavaScript is
executed? Getting JavaScript to work as well as the old macro language
would be very useful for our project and I think would be useful to
others as well. And as far as I can see, there are only a few things
missing at this point.


Thanks,

Adam
Reply | Threaded
Open this post in threaded view
|

Re: JavaScript batch mode doesn't have open images?

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Adam Goode
On Jun 21, 2010, at 4:47 PM, Adam Goode wrote:

> Hi,
>
> I am converting some old macros to JavaScript to use with the -batch
> command line. The macro contains some run(...) commands that call other
> plugins that open multiple windows. With the old macro system, in batch
> mode, I could close images and work with the active image, but with
> JavaScript, there are never any images open. IJ.getImage() produces an
> error.
>
> It looks like the Interpreter class contains a mechanism for holding
> onto images in batch mode (the imageTable). Can this be made to work
> when executing JavaScript?

This bug is fixed in the 1.44d7 daily build. Methods that open an image, like IJ.getImage(), now work as expected in "-batch" command line ".js" scripts. The image is not displayed but it can be retrieved by calling WindowManager.getCurrentImage(). ImageJ commands that display multiple images, such as IJ.run(imp, "Split Channels", ""), also work.

-wayne