Login  Register

Re: Thresholder in headless macro mode results in NullPointerException

Posted by Michael Schmid on Oct 07, 2014; 3:51pm
URL: http://imagej.273.s1.nabble.com/Thresholder-in-headless-macro-mode-results-in-NullPointerException-tp5009940p5009944.html

Hi Konrad,

the "setThreshold(77, 173);" command should be fine in headless mode, but "Convert to Mask" calls the Thresholder ("Threshold" panel), which needs the Graphic User Interface.

You could try the changeValues(v1, v2, v3) command instead:
  http://rsb.info.nih.gov/ij/developer/macro/functions.html#changeValues

Assuming you have an 8-bit image:
  changeValues(0, 76, 0);
  changeValues(174, 255, 0);
  changeValues(77, 173, 255);

Another option to try would be "setThreshold(77, 173);" followed by Edit>Selection>Create Mask. In contrast to "Convert to Mask", that will give you a separate output image.

Michael
________________________________________________________________
On Oct 7, 2014, at 16:32, Konrad Rokicki wrote:

> Hi all,
>
> I'm trying to run a macro on a cluster. I can use Xvfb, but it's very hard
> to debug problems when dialog boxes popup while this is running on a
> cluster. So I thought I'd try Fiji's headless mode:
>
> ImageJ-linux64 --headless -macro macro.ijm
>
> Most of the macro works well, but I can't seem to get the Thresholder to
> work. I reduced the problem to a very simple macro:
>
> open("test.tif");
> setThreshold(77, 173);
> run("Convert to Mask", "method=Default background=Dark black");
>
> This results in a strange exception:
>
> java.lang.NullPointerException
>    at ij.plugin.Thresholder.convertStack(Thresholder.java:75)
>    at ij.plugin.Thresholder.run(Thresholder.java:48)
>    at ij.IJ.runPlugIn(IJ.java:172)
>    at ij.Executer.runCommand(Executer.java:131)
>    at ij.Executer.run(Executer.java:64)
>    at ij.IJ.run(IJ.java:272)
>    at ij.macro.Functions.doRun(Functions.java:591)
>    at ij.macro.Functions.doFunction(Functions.java:89)
>    at ij.macro.Interpreter.doStatement(Interpreter.java:227)
>    at ij.macro.Interpreter.doStatements(Interpreter.java:215)
>    at ij.macro.Interpreter.run(Interpreter.java:112)
>    at ij.macro.Interpreter.run(Interpreter.java:82)
>    at ij.macro.Interpreter.run(Interpreter.java:93)
>    at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:153)
>    at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:137)
>    at ij.IJ.runMacroFile(IJ.java:133)
>    at net.imagej.legacy.IJ1Helper.runMacroFile(IJ1Helper.java:802)
>    at
> net.imagej.legacy.LegacyCommandline$Macro.handle(LegacyCommandline.java:178)
>    at
> org.scijava.console.DefaultConsoleService.processArgs(DefaultConsoleService.java:75)
>    at net.imagej.Main.launch(Main.java:64)
>    at net.imagej.Main.main(Main.java:73)
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>    at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>    at java.lang.reflect.Method.invoke(Method.java:597)
>    at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:258)
>    at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:184)
>    at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:76)
>
> After inspecting the Plugin's source code, I can't find any reason this
> exception might occur at that location. I'm guessing this has to do with
> the way Fiji is instrumenting the dialog portions of the plugin to remove
> the dependency on AWT?
>
> The exception seems very similar to the one I was getting when I was trying
> to use run("Colors...", "background=black"). I was able to fix that by
> switching to setBackgroundColor(), so I wonder if there's also a workaround
> for running the thresholder.
>
> I should mention that I've tried using various versions of Fiji, including
> the lifeline versions and the latest build.
>
> Thank you,
> Konrad
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html