Login  Register

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

Posted by dscho on Jun 13, 2014; 4:28pm
URL: http://imagej.273.s1.nabble.com/Headless-ImageJ2-rc2-Analyze-Particles-returns-no-result-tp5008127p5008203.html

Hi Paul,

On Fri, 13 Jun 2014, Paul van Schayck wrote:

> Thank you for your extensive response.

You are welcome.

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

Yes, I should have been more clear on that account. But then, I am already
surprised that the "imp = IJ.openImage(imagePath);" does not return
null... ;-) Good that it works, though!

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

Hmm... I cannot reproduce in my Fiji.app/...

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

This is for the cases where you run ImageJ2 commands headlessly in a
script... I will elaborate on that more when we're out of the user-centric
phase of the release cycle: at the moment, I cannot focus on
developer-centric issues.  But I will definitely write a nice blog post
about the intended use in scripts!

Ciao,
Johannes

P.S.: I am *about* to merge the branch and then release, so that finally
your macro works again. Sorry for the delay!

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