Thresholder in headless macro mode results in NullPointerException

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

Thresholder in headless macro mode results in NullPointerException

Konrad Rokicki
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
Reply | Threaded
Open this post in threaded view
|

Re: Thresholder in headless macro mode results in NullPointerException

dscho
Hi Konrad,

On Tue, 7 Oct 2014, Konrad Rokicki wrote:

> 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

Please understand that all the limitations mentioned in

        http://imagej.net/Headless#The_--headless_mode

apply... In particular:

> 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)

The source code is here:

        https://github.com/imagej/imagej1/blob/master/ij/plugin/Thresholder.java#L75

As you can see, the Thresholder *expects* a graphical user interface so
that it can attach item listeners. Of course, in headless mode this is
invalid, but the Thresholder was never prepared for that case (in fact,
ImageJ 1.x was never prepared for that case, the headless mode is an
add-on hack that cannot really change ImageJ 1.x). Therefore, the
Thresholder tries to access a combobox that was never instantiated and
therefore operates on a `null` value, trying to call the addItemListener()
method on it (which does not make sense in headless mode, either).

As a workaround, you might want to use the Auto Threshold plugin in
headless mode instead.

Ciao,
Johannes

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

how to set a color pixel from a macro?

Franklin Shaffer-2
I'm reading values of color pixel from an image and converting the hex value to color values to r, g , b.  
 
I want to change the r,g,b values then write the new values to the pixel from a macro.
 
I can make it work with the Fill tool, but it is extremely slow.
 
Is there a better way to change the value of a color pixel from a macro?
 
Thanks,
Frank Shaffer
 
 
Senior Research Engineer
USDOE National Energy Technology Laboratory
Office of Research & Development
Mail Stop 84-202
626 Cochran's Mill Road
Pittsburgh, PA 15236
 
[hidden email]
Office:  412-386-5964
Cell:  724-970-7262

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Thresholder in headless macro mode results in NullPointerException

Michael Schmid
In reply to this post by Konrad Rokicki
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
Reply | Threaded
Open this post in threaded view
|

Re: how to set a color pixel from a macro?

Herbie-4
In reply to this post by Franklin Shaffer-2
Frank Shaffer,

is this

"changeValues(v1, v2, v3);
Changes pixels in the image or selection that have a value in the range
v1-v2 to v3. For example, changeValues(0,5,5) changes all pixels less
than 5 to 5, and changeValues(0x0000ff,0x0000ff,0xff0000) changes all
blue pixels in an RGB image to red."

ImageJ-macro command, what you are looking for?

For more macro commands have a look at:

<http://rsb.info.nih.gov/ij/developer/macro/functions.html>

HTH

Herbie

:::::::::::::::::::::::::::::::::::::::::
On 07.10.14 17:44, Franklin Shaffer wrote:

> I'm reading values of color pixel from an image and converting the hex value to color values to r, g , b.
>
> I want to change the r,g,b values then write the new values to the pixel from a macro.
>
> I can make it work with the Fill tool, but it is extremely slow.
>
> Is there a better way to change the value of a color pixel from a macro?
>
> Thanks,
> Frank Shaffer
>
>
> Senior Research Engineer
> USDOE National Energy Technology Laboratory
> Office of Research & Development
> Mail Stop 84-202
> 626 Cochran's Mill Road
> Pittsburgh, PA 15236
>
> [hidden email]
> Office:  412-386-5964
> Cell:  724-970-7262
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how to set a color pixel from a macro?

Franklin Shaffer-2
I want to change the rgb values of a single pixel.
 
I believe changeValues(v1, v2, v3); changes the values of all pixels within a certain range.
 
Thanks,
Frank


>>> Herbie <[hidden email]> 10/7/2014 11:52 AM >>>
Frank Shaffer,

is this

"changeValues(v1, v2, v3);
Changes pixels in the image or selection that have a value in the range
v1-v2 to v3. For example, changeValues(0,5,5) changes all pixels less
than 5 to 5, and changeValues(0x0000ff,0x0000ff,0xff0000) changes all
blue pixels in an RGB image to red."

ImageJ-macro command, what you are looking for?

For more macro commands have a look at:

<http://rsb.info.nih.gov/ij/developer/macro/functions.html>

HTH

Herbie

:::::::::::::::::::::::::::::::::::::::::
On 07.10.14 17:44, Franklin Shaffer wrote:

> I'm reading values of color pixel from an image and converting the hex value to color values to r, g , b.
>
> I want to change the r,g,b values then write the new values to the pixel from a macro.
>
> I can make it work with the Fill tool, but it is extremely slow.
>
> Is there a better way to change the value of a color pixel from a macro?
>
> Thanks,
> Frank Shaffer
>
>
> Senior Research Engineer
> USDOE National Energy Technology Laboratory
> Office of Research & Development
> Mail Stop 84-202
> 626 Cochran's Mill Road
> Pittsburgh, PA 15236
>
> [hidden email]
> Office:  412-386-5964
> Cell:  724-970-7262
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how to set a color pixel from a macro?

Herbie-4
Frank Shaffer,

what about, for example

makeRectangle(128, 128, 1, 1);
changeValues(0x000000, 0xffffff, 0xff0000);

HTh

Herbie

::::::::::::::::::::::::::::::::::::::::::
On 07.10.14 17:57, Franklin Shaffer wrote:

> I want to change the rgb values of a single pixel.
>
> I believe changeValues(v1, v2, v3); changes the values of all pixels within a certain range.
>
> Thanks,
> Frank
>
>
>>>> Herbie <[hidden email]> 10/7/2014 11:52 AM >>>
> Frank Shaffer,
>
> is this
>
> "changeValues(v1, v2, v3);
> Changes pixels in the image or selection that have a value in the range
> v1-v2 to v3. For example, changeValues(0,5,5) changes all pixels less
> than 5 to 5, and changeValues(0x0000ff,0x0000ff,0xff0000) changes all
> blue pixels in an RGB image to red."
>
> ImageJ-macro command, what you are looking for?
>
> For more macro commands have a look at:
>
> <http://rsb.info.nih.gov/ij/developer/macro/functions.html>
>
> HTH
>
> Herbie
>
> :::::::::::::::::::::::::::::::::::::::::
> On 07.10.14 17:44, Franklin Shaffer wrote:
>> I'm reading values of color pixel from an image and converting the hex value to color values to r, g , b.
>>
>> I want to change the r,g,b values then write the new values to the pixel from a macro.
>>
>> I can make it work with the Fill tool, but it is extremely slow.
>>
>> Is there a better way to change the value of a color pixel from a macro?
>>
>> Thanks,
>> Frank Shaffer
>>
>>
>> Senior Research Engineer
>> USDOE National Energy Technology Laboratory
>> Office of Research & Development
>> Mail Stop 84-202
>> 626 Cochran's Mill Road
>> Pittsburgh, PA 15236
>>
>> [hidden email]
>> Office:  412-386-5964
>> Cell:  724-970-7262
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how to set a color pixel from a macro?

Michael Schmid
In reply to this post by Franklin Shaffer-2
Hi Frank,

you can use getPixel and setPixel; but you have to get the color information from it by masking with bitwise 'and' (& operator) and shifting to the prper position of the hex number.

As an example, the following macro modifies the red and blue values for an image.

for (y=0; y<getHeight(); y++)
 for (x=0; x<getWidth(); x++) {

   c = getPixel(x,y);     //get all colors
   r = (c&0xff0000)>>16;  //convert to separate colors r, g, b
   g = (c&0xff00)>>8;
   b = c&0xff;

   //modify as you like, e.g.
   r = round(0.9*r);
   b = round(1.1*b);


   // make sure values are not below 0 (can't happen in this example)
   // and not above 255
   if (r>255) r=255;
   if (g>255) g=255;
   if (b>255) b=255;

   // put together into one number and write back
   putPixel(x, y, (r<<16)+(g<<8)+b); //needs integer r, g, b
 }



Michael
________________________________________________________________

Michael
________________________________________________________________
Michael Schmid                    email: [hidden email]
Institut für Angewandte Physik, Technische Universität Wien
Wiedner Hauptstr. 8-10/E134, A 1040 Wien, Austria
Tel. +43 1 58801-13452 or -13453, Fax +43 1 58801 13499
________________________________________________________________

On Oct 7, 2014, at 17:57, Franklin Shaffer wrote:

> I want to change the rgb values of a single pixel.
>
> I believe changeValues(v1, v2, v3); changes the values of all pixels within a certain range.
>
> Thanks,
> Frank
>
>
>>>> Herbie <[hidden email]> 10/7/2014 11:52 AM >>>
> Frank Shaffer,
>
> is this
>
> "changeValues(v1, v2, v3);
> Changes pixels in the image or selection that have a value in the range
> v1-v2 to v3. For example, changeValues(0,5,5) changes all pixels less
> than 5 to 5, and changeValues(0x0000ff,0x0000ff,0xff0000) changes all
> blue pixels in an RGB image to red."
>
> ImageJ-macro command, what you are looking for?
>
> For more macro commands have a look at:
>
> <http://rsb.info.nih.gov/ij/developer/macro/functions.html>
>
> HTH
>
> Herbie
>
> :::::::::::::::::::::::::::::::::::::::::
> On 07.10.14 17:44, Franklin Shaffer wrote:
>> I'm reading values of color pixel from an image and converting the hex value to color values to r, g , b.
>>
>> I want to change the r,g,b values then write the new values to the pixel from a macro.
>>
>> I can make it work with the Fill tool, but it is extremely slow.
>>
>> Is there a better way to change the value of a color pixel from a macro?
>>
>> Thanks,
>> Frank Shaffer
>>
>>
>> Senior Research Engineer
>> USDOE National Energy Technology Laboratory
>> Office of Research & Development
>> Mail Stop 84-202
>> 626 Cochran's Mill Road
>> Pittsburgh, PA 15236
>>
>> [hidden email]
>> Office:  412-386-5964
>> Cell:  724-970-7262
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how to set a color pixel from a macro?

Franklin Shaffer-2
That worked.  Thank you!

>>> Michael Schmid <[hidden email]> 10/7/2014 12:05 PM >>>
Hi Frank,

you can use getPixel and setPixel; but you have to get the color
information from it by masking with bitwise 'and' (& operator) and
shifting to the prper position of the hex number.

As an example, the following macro modifies the red and blue values for
an image.

for (y=0; y<getHeight(); y++)
for (x=0; x<getWidth(); x++) {

   c = getPixel(x,y);     //get all colors
   r = (c&0xff0000)>>16;  //convert to separate colors r, g, b
   g = (c&0xff00)>>8;
   b = c&0xff;

   //modify as you like, e.g.
   r = round(0.9*r);
   b = round(1.1*b);


   // make sure values are not below 0 (can't happen in this example)
   // and not above 255
   if (r>255) r=255;
   if (g>255) g=255;
   if (b>255) b=255;

   // put together into one number and write back
   putPixel(x, y, (r<<16)+(g<<8)+b); //needs integer r, g, b
}



Michael
________________________________________________________________

Michael
________________________________________________________________
Michael Schmid    email:
[hidden email]
Institut für Angewandte Physik, Technische Universität Wien
Wiedner Hauptstr. 8-10/E134, A 1040 Wien, Austria
Tel. +43 1 58801-13452 or -13453, Fax +43 1 58801 13499
________________________________________________________________

On Oct 7, 2014, at 17:57, Franklin Shaffer wrote:

> I want to change the rgb values of a single pixel.
>
> I believe changeValues(v1, v2, v3); changes the values of all pixels
within a certain range.

>
> Thanks,
> Frank
>
>
>>>> Herbie <[hidden email]> 10/7/2014 11:52 AM >>>
> Frank Shaffer,
>
> is this
>
> "changeValues(v1, v2, v3);
> Changes pixels in the image or selection that have a value in the
range
> v1-v2 to v3. For example, changeValues(0,5,5) changes all pixels less

> than 5 to 5, and changeValues(0x0000ff,0x0000ff,0xff0000) changes all

> blue pixels in an RGB image to red."
>
> ImageJ-macro command, what you are looking for?
>
> For more macro commands have a look at:
>
> <http://rsb.info.nih.gov/ij/developer/macro/functions.html>
>
> HTH
>
> Herbie
>
> :::::::::::::::::::::::::::::::::::::::::
> On 07.10.14 17:44, Franklin Shaffer wrote:
>> I'm reading values of color pixel from an image and converting the
hex value to color values to r, g , b.
>>
>> I want to change the r,g,b values then write the new values to the
pixel from a macro.
>>
>> I can make it work with the Fill tool, but it is extremely slow.
>>
>> Is there a better way to change the value of a color pixel from a
macro?

>>
>> Thanks,
>> Frank Shaffer
>>
>>
>> Senior Research Engineer
>> USDOE National Energy Technology Laboratory
>> Office of Research & Development
>> Mail Stop 84-202
>> 626 Cochran's Mill Road
>> Pittsburgh, PA 15236
>>
>> [hidden email]
>> Office:  412-386-5964
>> Cell:  724-970-7262
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Thresholder in headless macro mode results in NullPointerException

Konrad Rokicki
In reply to this post by Michael Schmid
Hi Michael,

That's exactly what I was looking for. I have a 16-bit image, so the
changeValues approach doesn't work in this case, but it's good to know.
However, the "Create Mask" approach does work in a headless macro.

I still have some problems to work through, because I am getting different
results in headless and non-headless modes. It's possible that it's caused
by having to disable batch mode in headless mode. I have some kind of
strange dependency on batch mode, since the macro is quite complex, and it
seems that windows are getting ordered and selected differently in batch vs
non-batch mode.

Thanks for your help,
Konrad


On Tue, Oct 7, 2014 at 11:51 AM, Michael Schmid <[hidden email]>
wrote:

> 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
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Thresholder in headless macro mode results in NullPointerException

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Konrad Rokicki
On Oct 7, 2014, at 10:32 AM, 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)

This bug is fixed in the latest ImageJ daily build (1.49i13). The GenericDialog.getChoices() method call at line 74 in Thresholder.java returns null in headless mode.

-wayne

>    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