Login  Register

Re: Headless ImageJ2-rc2 - Analyze Particles returns no result

Posted by Paul van Schayck on Jun 13, 2014; 11:24am
URL: http://imagej.273.s1.nabble.com/Headless-ImageJ2-rc2-Analyze-Particles-returns-no-result-tp5008127p5008194.html

Dear Johannes,

Thank you for your extensive response.

On Thu, Jun 12, 2014 at 4:03 PM, Johannes Schindelin
<[hidden email]> wrote:
>> I'm also trying to rewrite the macro to js, still struggling a bit with
>> that, should the bug also be visible there?
>
> Yes. Both problems (that the image was not properly registered with ImageJ
> 1.x as well as the 0 particles found problem caused by the parseDouble()
> method being incorrect in headless mode) would persist.

Hmm.. this is contratary to what I found using this script:

importClass(Packages.ij.IJ)
importClass(Packages.ij.plugin.filter.ParticleAnalyzer)
importClass(Packages.ij.measure.Measurements)
importClass(Packages.ij.measure.ResultsTable)

imp = IJ.openImage(imagePath);
IJ.run(imp, "8-bit", "");
IJ.setThreshold(imp, 1, 255);
IJ.run(imp, "Convert to Mask", ""); // How to use ij.plugin.Thresholder?
table = ResultsTable()
pa = ParticleAnalyzer(0, Measurements.CENTER_OF_MASS, table, 300,
Number.POSITIVE_INFINITY, 0.4, 1.0)
pa.analyze(imp)
print(table.getCounter())

This does work headless. However, maybe you meant running the Analyse
particle command through IJ.run() will not work. In that case, ignore
this comment.

> Actually, my preferred way to run scripts is to call
>
>         ImageJ-<platform> script.bsh
>
> or
>
>         ImageJ-<platform> script.js

Running scripts this way in pure ImageJ has been giving this exception
for me for a few weeks. However, it does work in the daily Fiji build.

Exception in thread "main" java.lang.NullPointerException
        at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:248)
        at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:184)
        at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:76)

> directly. This will not spin up a context or for that matter, ImageJ, for
> you, but makes it possible to use ImageJ truly as a library. You would
> probably want to start up a context anyway, like this:
>
>         importClass(Packages.net.imagej.ImageJ);
>
>         ij = ImageJ();
>         ij.command().run(...);
>

I'm not sure what you mean by this latest example. In which case would
you like to use this?

Thank you,

Paul

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