ImageJ2 RC - Headless execution of "Remove Outliers..."

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

ImageJ2 RC - Headless execution of "Remove Outliers..."

Paul van Schayck
Dear Johannes,

Another problem when running a macro headless. This time with the
function Remove Outliers. Consider this macro:

run("Cardio (768K, RGB DICOM)");
// Remove outliers
run("Remove Outliers...", "radius=2 threshold=50 which=Dark");
run("Remove Outliers...", "radius=2 threshold=50 which=Bright");
getStatistics(area, mean, min, max, std, histogram);
Array.getStatistics(histogram, min, max, mean, stdDev);
print(max);

This is using the cardio sample image. The printed value when running
headless is: 762916. When running from the script editor the value is:
761070. This is due to the Remove Outliers command, when that is
removed the reported value is the same in both headless and not
headless.

Is this another case where parameters are not being parsed correctly?

Thank you,

Paul

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

Re: ImageJ2 RC - Headless execution of "Remove Outliers..."

dscho
Hi Michael,

On Mon, 16 Jun 2014, Michael Schmid wrote:

> it seems that the operation in headless mode is not
>   run("Remove Outliers...", "radius=2 threshold=50 which=Dark");
> but
>   run("Remove Outliers...", "radius=2 threshold=0 which=Bright");
>
> Also, in the second operation, the threshold is 0, not 50 in spite of the macro parameter.
>
> So the 'threshold' and 'whichOutliers' variables are not read from the macro parameters in the GenericDialog of the RankFilters, and they keep their initial values of 0.  I don't see any reference to the GenericDialog as a jawa.awt object that could cause trouble.

Thank you for your detailed analysis! Once I am through with fixing a bug
that prevents Aryeh from working, I will take care of this one.

> Sorry, I have no idea about the headless mode (seems to be in Fiji, I
> did not find it in the source code of 'vanilla' ImageJ?).

Actually, it is pretty well described in http://fiji.sc/Headless. I just
edited it another time, not really adding new information, just trying to
present it in an even clearer form.

And yes, it is not in the source code of vanilla ImageJ 1.x. Despite many
a discussion with Wayne, we were not able to fix the design of ImageJ 1.x
to allow headless execution; the code supporting run(command, options) is
*heavily* intertwined with the GenericDialog, therefore you cannot change
it without breaking existing plugins (although that might not stop these
changes if there is enough interest...).

Ciao,
Johannes

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

Re: ImageJ2 RC - Headless execution of "Remove Outliers..."

Paul van Schayck
Hey Michael,

Thank you for your analysis. Maybe you're then also able to shed some
light on the following. Consider the following JS script:

importClass(Packages.ij.IJ)
importClass(Packages.ij.WindowManager)
importClass(Packages.ij.plugin.filter.RankFilters)
importClass(Packages.ij.io.FileSaver)

IJ.run("Cardio (768K, RGB DICOM)");
imp = WindowManager.getCurrentImage()

ranker = new RankFilters()
ranker.rank(imp.getProcessor(), 2, RankFilters.OUTLIERS, 1, 50)
ranker.rank(imp.getProcessor(), 2, RankFilters.OUTLIERS, 0, 50)

/*IJ.run(imp,"Remove Outliers...", "radius=2 threshold=50 which=Dark");
IJ.run(imp,"Remove Outliers...", "radius=2 threshold=50 which=Bright");*/

fs = FileSaver(imp)
fs.saveAsPng(outputDir + "\\" + imp.getShortTitle() + ".png")


The JS code using RankFilters() directly will not produce the same
output as the (commented) IJ.run() commands. What's going on here?
They seem the same commands. Please note that this is not being run
headless in this case.

Thank you,

Paul

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

Re: ImageJ2 RC - Headless execution of "Remove Outliers..."

Paul van Schayck
Hey everyone,

I found an answer my own question. Sorry for the noise. See below for
the answer.

On Tue, Jun 17, 2014 at 9:07 AM, Paul van Schayck <[hidden email]> wrote:

> importClass(Packages.ij.IJ)
> importClass(Packages.ij.WindowManager)
> importClass(Packages.ij.plugin.filter.RankFilters)
> importClass(Packages.ij.io.FileSaver)
>
> IJ.run("Cardio (768K, RGB DICOM)");
> imp = WindowManager.getCurrentImage()
>
> ranker = new RankFilters()
> ranker.rank(imp.getProcessor(), 2, RankFilters.OUTLIERS, 1, 50)
> ranker.rank(imp.getProcessor(), 2, RankFilters.OUTLIERS, 0, 50)
>
> /*IJ.run(imp,"Remove Outliers...", "radius=2 threshold=50 which=Dark");
> IJ.run(imp,"Remove Outliers...", "radius=2 threshold=50 which=Bright");*/
>
> fs = FileSaver(imp)
> fs.saveAsPng(outputDir + "\\" + imp.getShortTitle() + ".png")
>
> The JS code using RankFilters() directly will not produce the same
> output as the (commented) IJ.run() commands. What's going on here?
> They seem the same commands. Please note that this is not being run
> headless in this case.

When using "imp.getProcessor().convertToFloat()" the results are the
same. I found the use of this in [1]. I see now that I should read the
PlugInFilter flags in the API docs to figure out whether this is
necessary.

Kind regards,

Paul

[1] http://www.ini.uzh.ch/~acardona/fiji-tutorial/

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

Re: ImageJ2 RC - Headless execution of "Remove Outliers..."

Jerome Mutterer-3
In reply to this post by dscho
Dear all,

On 16 June 2014 18:13, Johannes Schindelin <[hidden email]>
wrote:

> ...
>
> Actually, it is pretty well described in http://fiji.sc/Headless. I just
> edited it another time, not really adding new information, just trying to
> present it in an even clearer form.


I cloned fiji and tried to build headless.jar as described in the page
linked above, but I'm getting an exception. I'm pasting my terminal session
below:

Last login: Tue Jun 17 08:34:14 on console

> capucine:~ jmutterer$ git clone https://mutterer@.../fiji/fiji.git
> Cloning into 'fiji'...
> remote: Reusing existing pack: 100316, done.
> remote: Counting objects: 3, done.
> remote: Compressing objects: 100% (3/3), done.
> remote: Total 100319 (delta 0), reused 0 (delta 0)
> Receiving objects: 100% (100319/100319), 247.48 MiB | 3.23 MiB/s, done.
> Resolving deltas: 100% (61117/61117), done.
> Checking connectivity... done.
> capucine:~ jmutterer$ cd fiji/
> capucine:fiji jmutterer$ ./Build.sh misc/headless.jar
> No JDK found; cloning it
> Submodule 'java/macosx-java3d' (http://fiji.sc/java/macosx-java3d.git)
> registered for path 'java/macosx-java3d'
> Initialized empty Git repository in
> /Users/jmutterer/fiji/java/macosx-java3d/.git/
> remote: Counting objects: 20, done.
> remote: Compressing objects: 100% (11/11), done.
> remote: Total 20 (delta 3), reused 20 (delta 3)
> Unpacking objects: 100% (20/20), done.
> From http://fiji.sc/java/macosx-java3d
>  * [new branch]      master     -> origin/master
> HEAD is now at 4f39642 Revert "Add sunjce_provider.jar to enable ssh via
> JSch"
> Downloading sc.fiji:javac:1.6.0.24-ubuntu-fiji1
> Downloading org.scijava:scijava-common:2.23.0
> Downloading org.scijava:minimaven:2.1.2
> Exception in thread "main" java.lang.NoClassDefFoundError: bsh/Interpreter
> Caused by: java.lang.ClassNotFoundException: bsh.Interpreter
> at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
> at java.security.AccessController.doPrivileged(Native Method)
>  at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>  at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
>
Sincerely,

Jerome.
--
Jerome Mutterer
CNRS - Institut de biologie moléculaire des plantes
 12, rue du Général Zimmer
67084 Strasbourg Cedex
T 0367155339
www.ibmp.cnrs.fr

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

Re: ImageJ2 RC - Headless execution of "Remove Outliers..."

dscho
Hi Jerome,

On Tue, 17 Jun 2014, Jerome Mutterer wrote:

> On 16 June 2014 18:13, Johannes Schindelin <[hidden email]>
> wrote:
>
> > ...
> >
> > Actually, it is pretty well described in http://fiji.sc/Headless. I just
> > edited it another time, not really adding new information, just trying to
> > present it in an even clearer form.
>
>
> I cloned fiji and tried to build headless.jar as described in the page
> linked above, but I'm getting an exception.

As pointed out in http://fiji.sc/Headless#Possible_solutions (in the
yellow box, in particular the red text, please indicate how to make this
better documented), you do not need to build headless.jar anymore.

If you *have* to build it (e.g. when running in an environment that does
not allow you to runtime-patch due to a restricted class loader), it is
true that for the moment, you *have* to run "./Build.sh" before running
"./Build misc/headless.jar" for the moment.

You will probably agree that in this light, the bug you reported is a
little less urgent than the bug Paul reported because the latter is not
easily worked around. But do feel free to open a bug report either on
http://fiji.sc/bugzilla/ (if you feel you are more like a user) or on
https://github.com/fiji/fiji/issues/new (if you feel you are more like a
scientific developer) so it is not forgotten.

Ciao,
Johannes

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

Re: ImageJ2 RC - Headless execution of "Remove Outliers..."

Jerome Mutterer-3
Dear Johannes,

On 17 June 2014 16:03, Johannes Schindelin <[hidden email]>
wrote:

> ...
> If you *have* to build it (e.g. when running in an environment that does
> not allow you to runtime-patch due to a restricted class loader), it is
> true that for the moment, you *have* to run "./Build.sh" before running
> "./Build misc/headless.jar" for the moment.
>
>
Thanks for the explanation. It works fine this way indeed.
I added this to the wiki headless page, in the hope that you're less likely
to be
distracted from more urgent tasks in the future. ;-)

Thanks a lot, sincerely,
Jerome.


--
Jerome Mutterer
CNRS - Institut de biologie moléculaire des plantes
 12, rue du Général Zimmer
67084 Strasbourg Cedex
T 0367155339
www.ibmp.cnrs.fr

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

Re: ImageJ2 RC - Headless execution of "Remove Outliers..."

dscho
Hi Jerome,

On Tue, 17 Jun 2014, Jerome Mutterer wrote:

> On 17 June 2014 16:03, Johannes Schindelin <[hidden email]>
> wrote:
>
> > ...
> > If you *have* to build it (e.g. when running in an environment that does
> > not allow you to runtime-patch due to a restricted class loader), it is
> > true that for the moment, you *have* to run "./Build.sh" before running
> > "./Build misc/headless.jar" for the moment.
> >
> >
> Thanks for the explanation. It works fine this way indeed.  I added this
> to the wiki headless page, in the hope that you're less likely to be
> distracted from more urgent tasks in the future. ;-)

Thank you so much for that, it indeed relieves me of yet another task in
these crazy IJ2 times!

Ciao,
Johannes

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