A problem running ImageJ in headless mode

Hi,
I have a problem running ImageJ 1.51i java 1.8.0_112 (64 bit) in the headless mode on LinuxMint 17 Qiana.
I think the problem is with the ImageJ launcher. When I run the following command:

[path_to_ImageJ]/ij.jar helloImageJ.py -b &

It works. (helloImageJ.py just prints hello to the console)

On the other hand, when I write the following command:

[path_to_ImageJ]/ImageJ helloImageJ.py -b &

I get the following error message:

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Unrecognized option: -b
Warning: falling back to System JVM
Unrecognized option: -b
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Any idea how to fix this problem? I need to work in batch mode, because the goal is to obviously run my image analysis script in headless mode. (rather than the hello world program)

Thanks,
Avital

I don’t know if that helps, but have you tried using the double-dash (--) to separate the Java options from the ImageJ options when running the launcher?

See the Java options page on the wiki.

Thanks, Jan - when I try to use the double dash:

[path_to_ImageJ]/ImageJ --ij2 --headless --run helloImageJ.py -b &

I get the following error message:

Without ij-launcher, ‘-ijjarpath’ cannot be handled

Any other ideas how I can make ImageJ work? And I do need it to work in batch mode, because I want to process images.

Thanks.
Avital

Have you followed the instructions on the Scripting Headless page exactly? At the moment you should use the syntax:

./ImageJ-linux64 --ij2 --headless --run path/to/script [key1=value1,key2=value2,...]

That will be simplified in the future, but for now, you need to write it like that.

Hi Jan and Curtis,
If I try to run the file Greetings.js: (this is what’s in the file)

// @String name
// @OUTPUT String greeting

// A JavaScript script with parameters.
// It is the duty of the scripting framework to harvest
// the 'name' parameter from the user, and then display
// the 'greeting' output parameter, based on its type.

greeting = "Hello, " + name + "!";

With the following command:

./ImageJ-linux64 --ij2 --headless --run [Path_to_script]/Greeting.js 'name="Mr Kraken"' > [Path_to_log]/Greetings &

The log file has only the following sentence:

Unsupported format or not found

How should I change this command so that it would work?

Thanks,
Avital

Thanks for pointing that out, @Avital_Steinberg. I believe this is a bug, which has already been fixed in the code, but not yet released.

I will be cutting a new release of ImageJ2 within the next few days, so this issue should be fixed very soon.

Sorry for the inconvenience.

Thanks, Curtis - and when the new release of ImageJ2 comes out, will there be instructions how to work in batch mode? Because my coworkers are counting on me to analyze thousands of images. (we have a high throughput microscope)

Hi,

Maybe its worth taking a look at KNIME for batch processing, see http://knime.imagej.net. This paper may help getting started.

Let me know if you need help.

Christian

2 Likes

Thanks, Christian - I am indeed interested in learning KNIME (not instead of using ImageJ in batch mode which I would like to do anyway). I will go over the paper you attached before I go to Portugal. I hope to meet you there and learn more about KNIME.

For 2-D data batch processing I would highly recommend CellProfiler.
You can also learn about it in Protugal if you do not know it yet.

I remember hearing about it from you at the EMBL - you did great things with it. I’ll be happy to meet you again and hear more about it. What I’m doing now is 3D, but I enjoyed trying out your machine learning application that recognized phenotypes.

You just write setBatchMode(true) in your macro like usual? There should be no need for a “batch mode” command line flag?

I second Christian’s suggestion. KNIME is worth the investment to learn.

2 Likes

I have now uploaded the new release of ImageJ2. After you update, you should have version 2.0.0-rc-56, which includes bug-fixes to the command-line features.

2 Likes

Great - thanks! I’ll try it out.

1 Like

I upgraded ImageJ to version 2.0.0-rc-56 and since the daily build was 1.51h, I updated it to the 1.51i daily build. (I need this build) The problem is that it didn’t work. When I tried to run the script called printArgs.js, which has the following contents:

//@String NAME
importClass(Packages.ij.IJ);

var ARGS = NAME.split("-");
var STRSKIP = parseInt(ARGS[0]);
var STRUNTIL = parseInt(ARGS[1]);
var SKIP = parseInt(STRSKIP);
var UNTIL = parseInt(STRUNTIL);

IJ.log("SKIP: " + SKIP + " and UNTIL: " + UNTIL);

Using the following command:

[path_to_ImageJ]/ImageJ-linux64 --ij2 --headless --[path_to_script]/printArgs.js 'NAME="0-1"' > [path_to_log]/PrintArgs &

I got the following error message:

File is not in a supported format, a reader plugin is not available, or it was not found.
[path_to_ImageJ]/NAME="0-1"

Any idea how I can get it to work?
Thanks,
Avital

1 Like

Yes, you need to use --ij2 --headless --run printArgs.js. Note the --run argument here.

See the Scripting Headless page.

Thanks, Curtis - now I can run that script, but if I try to use the RoiManager, it gives me an error message.

When I run the command:

[path_to_ImageJ]/ImageJ-linux64 --ij2 --headless --run [path_to_script]/printArgs.js 'NAME="0-1"' > [path_to_log]/PrintArgs &

When the script is:

//@String NAME
importClass(Packages.ij.plugin.frame.RoiManager);
importClass(Packages.ij.IJ);

var ARGS = NAME.split("-");
var STRSKIP = parseInt(ARGS[0]);
var STRUNTIL = parseInt(ARGS[1]);
var SKIP = parseInt(STRSKIP);
var UNTIL = parseInt(STRUNTIL);

IJ.log("SKIP: " + SKIP + " and UNTIL: " + UNTIL);

var rm = new RoiManager();// initiating the ROI manager
if (rm==null)

I get the following error message:

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
java.awt.HeadlessException
    at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
    at java.awt.Window.<init>(Window.java:536)
    at java.awt.Frame.<init>(Frame.java:420)
    at ij.plugin.frame.PlugInFrame.<init>(PlugInFrame.java:13)
    at ij.plugin.frame.RoiManager.<init>(RoiManager.java:76)
    at jdk.nashorn.internal.scripts.Script$4$printArgs.:program(/media/elusers/users/avital/Scripts/printArgs.js:13)
    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:640)
    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
    at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:446)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:403)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)
    at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:150)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
    at org.scijava.script.ScriptModule.run(ScriptModule.java:176)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
    at org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

We were running it headless using Java 6 with Xvfb before, and now we’d like to use ImageJ Java 8. How can we do that?

Thanks,
Avital

For now at least, you will still need to use xvfb. The ImageJ Legacy component does not patch IJ1’s ROI Manager to work headless—it only patches the main ImageJ window and the GenericDialog. The Headless page explains somewhat, if you have not seen it already.

Alternately, it might be possible to store your ROIs as overlays instead of using a RoiManager object. I did not look carefully, though.

Thanks, Curtis - my PI set up the xvfb a long time ago (with ImageJ Java 6) and doesn’t seem to remember how to do it. How can I use xvfb with ImageJ Java 8?

It should be the same as with Java 6. This link is everything I know about it: http://imagej.net/Headless#Xvfb