Running a macro with the Scale command headless fails

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

Running a macro with the Scale command headless fails

Gregory Jefferis-2
Hello,

I'd like to run an IJ1 macro headless. It uses the Scale command. This fails apparently because the Scale dialog box cannot be run headless.

Can anyone suggest a workaround? Minimal example below.

With many thanks,

Greg.

PS I tried to sign up for http://forum.imagej.net/ using both GitHub & google authentication (gmail address) and directly with my @cam.ac.uk email. I never received a confirmation email. A repeat of this? http://forum.imagej.net/t/forum-server-issues-registration-and-notification-emails-not-sent/3371

--- simple_scale.ijm ---
run("Bat Cochlea Volume (19K)");
run("Scale...", "x=.5 y=.5 z=.5 width=60 height=77 depth=57 interpolation=Bilinear average process");
--- snip ---


$ /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --run simple_scale.ijm -batch
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release

$ /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --run simple_scale.ijm -batch
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
java.lang.NullPointerException
        at ij.plugin.Scaler.showDialog(Scaler.java:253)
        at ij.plugin.Scaler.run(Scaler.java:42)
        at ij.IJ.runPlugIn(IJ.java:187)
        at ij.Executer.runCommand(Executer.java:137)
        at ij.Executer.run(Executer.java:66)
        at ij.IJ.run(IJ.java:297)
        at ij.macro.Functions.doRun(Functions.java:601)
        at ij.macro.Functions.doFunction(Functions.java:96)
        at ij.macro.Interpreter.doStatement(Interpreter.java:230)
        at ij.macro.Interpreter.doStatements(Interpreter.java:218)
        at ij.macro.Interpreter.run(Interpreter.java:115)
        at ij.macro.Interpreter.run(Interpreter.java:85)
        at ij.macro.Interpreter.run(Interpreter.java:96)
        at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:155)
        at ij.IJ.runMacro(IJ.java:134)
        at ij.IJ.runMacro(IJ.java:123)
        at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1052)
        at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1048)
        at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:999)
        at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1048)
        at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:136)
        at org.scijava.script.ScriptModule.run(ScriptModule.java:159)
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
        at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:237)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)



--
Gregory Jefferis, PhD                   Tel: +44 1223 267048
Division of Neurobiology
MRC Laboratory of Molecular Biology
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
http://jefferislab.org
http://www.zoo.cam.ac.uk/departments/connectomics


--
Gregory Jefferis, PhD
Division of Neurobiology
MRC Laboratory of Molecular Biology
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
http://jefferislab.org
http://www.zoo.cam.ac.uk/departments/connectomics

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

Re: Running a macro with the Scale command headless fails

Straub, Volko A. (Dr.)
Hi Gregory,


You could try to use:


setVoxelSize(width, height, depth, unit)
Defines the voxel dimensions and unit of length ("pixel", "mm", etc.) for the current image or stack. A "um" unit will be converted to "µm". The depth argument is ignored if the current image is not a stack. See also: getVoxelSize<https://imagej.nih.gov/ij/developer/macro/functions.html#getVoxelSize>.


Hope this helps,

Volko

________________________________
From: Gregory Jefferis <[hidden email]>
Sent: 31 December 2017 09:15:38
To: [hidden email]
Subject: Running a macro with the Scale command headless fails

Hello,

I'd like to run an IJ1 macro headless. It uses the Scale command. This fails apparently because the Scale dialog box cannot be run headless.

Can anyone suggest a workaround? Minimal example below.

With many thanks,

Greg.

PS I tried to sign up for http://forum.imagej.net/ using both GitHub & google authentication (gmail address) and directly with my @cam.ac.uk email. I never received a confirmation email. A repeat of this? http://forum.imagej.net/t/forum-server-issues-registration-and-notification-emails-not-sent/3371

--- simple_scale.ijm ---
run("Bat Cochlea Volume (19K)");
run("Scale...", "x=.5 y=.5 z=.5 width=60 height=77 depth=57 interpolation=Bilinear average process");
--- snip ---


$ /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --run simple_scale.ijm -batch
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release

$ /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --run simple_scale.ijm -batch
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
java.lang.NullPointerException
        at ij.plugin.Scaler.showDialog(Scaler.java:253)
        at ij.plugin.Scaler.run(Scaler.java:42)
        at ij.IJ.runPlugIn(IJ.java:187)
        at ij.Executer.runCommand(Executer.java:137)
        at ij.Executer.run(Executer.java:66)
        at ij.IJ.run(IJ.java:297)
        at ij.macro.Functions.doRun(Functions.java:601)
        at ij.macro.Functions.doFunction(Functions.java:96)
        at ij.macro.Interpreter.doStatement(Interpreter.java:230)
        at ij.macro.Interpreter.doStatements(Interpreter.java:218)
        at ij.macro.Interpreter.run(Interpreter.java:115)
        at ij.macro.Interpreter.run(Interpreter.java:85)
        at ij.macro.Interpreter.run(Interpreter.java:96)
        at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:155)
        at ij.IJ.runMacro(IJ.java:134)
        at ij.IJ.runMacro(IJ.java:123)
        at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1052)
        at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1048)
        at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:999)
        at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1048)
        at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:136)
        at org.scijava.script.ScriptModule.run(ScriptModule.java:159)
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
        at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:237)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)



--
Gregory Jefferis, PhD                   Tel: +44 1223 267048
Division of Neurobiology
MRC Laboratory of Molecular Biology
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
http://jefferislab.org
http://www.zoo.cam.ac.uk/departments/connectomics


--
Gregory Jefferis, PhD
Division of Neurobiology
MRC Laboratory of Molecular Biology
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
http://jefferislab.org
http://www.zoo.cam.ac.uk/departments/connectomics

--
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: Running a macro with the Scale command headless fails

Gregory Jefferis-2
Thanks a lot for the response however I don't think that will help, so let me clarify. I need to resample the image (reducing the number of pixels on each axis) not change the spatial calibration. Many thanks, Greg.

Sent from my iPhone

> On 31 Dec 2017, at 09:37, Straub, Volko A. (Dr.) <[hidden email]> wrote:
>
> setVoxelSize(width, height, depth, unit)
> Defines the voxel dimensions and unit of length ("pixel", "mm", etc.) for the current image or stack. A "um" unit will be converted to "µm". The depth argument is ignored if the current image is not a stack. See also: getVoxelSize<https://imagej.nih.gov/ij/developer/macro/functions.html#getVoxelSize>.

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

Re: Running a macro with the Scale command headless fails

Herbie
Good day Gregory,

not being a specialist for non-GUI operation of ImageJ but this call
works for me (_plain_ ImageJ-1.51t under macOS 10.11.6, Java 1.6.0):

////////// macro "testMacro.txt"
path = getArgument();
open(path);
run("Scale...", "x=0.5 y=0.5 z=0.5 width=60 height=77 depth=57
interpolation=Bilinear average process");
print("success");
//////////

_Terminal (with result, i.e. ImageJ launched and running)_:
java -jar /Applications/ImageJ/ImageJ.app/Contents/Resources/Java/ij.jar
-macro /Applications/ImageJ/macros/testMacro.txt
/Applications/ImageJ/testimages/bat-cochlea-volume.tif

_Terminal (result not shown and not saved, i.e. ImageJ doesn't launch)_:
java -jar /Applications/ImageJ/ImageJ.app/Contents/Resources/Java/ij.jar
-batch /Applications/ImageJ/macros/testMacro.txt
/Applications/ImageJ/testimages/bat-cochlea-volume.tif

HTH

Herbie

::::::::::::::::::::::::::::::::::::::::::::::
Am 31.12.17 um 15:05 schrieb Gregory Jefferis:

> Thanks a lot for the response however I don't think that will help, so let me clarify. I need to resample the image (reducing the number of pixels on each axis) not change the spatial calibration. Many thanks, Greg.
>
> Sent from my iPhone
>
>> On 31 Dec 2017, at 09:37, Straub, Volko A. (Dr.) <[hidden email]> wrote:
>>
>> setVoxelSize(width, height, depth, unit)
>> Defines the voxel dimensions and unit of length ("pixel", "mm", etc.) for the current image or stack. A "um" unit will be converted to "µm". The depth argument is ignored if the current image is not a stack. See also: getVoxelSize<https://imagej.nih.gov/ij/developer/macro/functions.html#getVoxelSize>.
>
> --
> 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: Running a macro with the Scale command headless fails

Gregory Jefferis-2
Dear Herbie,

Thanks a lot for your response. However, I specifically need to be able to run this script headless on a cluster (see https://imagej.net/Headless <https://imagej.net/Headless>) and for that I need to use the --headless switch to the Fiji/ImageJ launcher.

At your suggestion, I did try using the plain ImageJ 1.50 distribution (http://wsr.imagej.net/distros/linux/ij150-linux64-java8.zip) on the target Linux cluster but I got the early error pasted below. Further testing revealed that headless support is broken within ImageJ itself before it even tries to run a script, so that is not going to help me.

So the question remains, if I use the Fiji/ImageJ launcher, is there a way to get round the fact that the Scale... command does not work headless? This could be another way of resampling images in x,y,z that does not depend on a GUI element that cannot be run headless.

Many thanks,

Greg.

[jefferis@hex ImageJ]$ ./ImageJ --headless -batch simple_scale.ijm
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
Exception in thread "main" java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.MenuComponent.<init>(MenuComponent.java:159)
        at java.awt.MenuItem.<init>(MenuItem.java:214)
        at java.awt.MenuItem.<init>(MenuItem.java:198)
        at java.awt.Menu.<init>(Menu.java:157)
        at java.awt.Menu.<init>(Menu.java:137)
        at ij.Menus.getMenu(Menus.java:775)
        at ij.Menus.getMenu(Menus.java:765)
        at ij.Menus.addMenuBar(Menus.java:105)
        at ij.IJ.init(IJ.java:362)
        at ij.IJ.runMacroFile(IJ.java:146)
        at ij.ImageJ.main(ImageJ.java:716)

I


> On 31 Dec 2017, at 17:38, Herbie <[hidden email]> wrote:
>
> Good day Gregory,
>
> not being a specialist for non-GUI operation of ImageJ but this call works for me (_plain_ ImageJ-1.51t under macOS 10.11.6, Java 1.6.0):
>
> ////////// macro "testMacro.txt"
> path = getArgument();
> open(path);
> run("Scale...", "x=0.5 y=0.5 z=0.5 width=60 height=77 depth=57 interpolation=Bilinear average process");
> print("success");
> //////////
>
> _Terminal (with result, i.e. ImageJ launched and running)_:
> java -jar /Applications/ImageJ/ImageJ.app/Contents/Resources/Java/ij.jar -macro /Applications/ImageJ/macros/testMacro.txt /Applications/ImageJ/testimages/bat-cochlea-volume.tif
>
> _Terminal (result not shown and not saved, i.e. ImageJ doesn't launch)_:
> java -jar /Applications/ImageJ/ImageJ.app/Contents/Resources/Java/ij.jar -batch /Applications/ImageJ/macros/testMacro.txt /Applications/ImageJ/testimages/bat-cochlea-volume.tif
>
> HTH
>
> Herbie
>
> ::::::::::::::::::::::::::::::::::::::::::::::
> Am 31.12.17 um 15:05 schrieb Gregory Jefferis:
>> Thanks a lot for the response however I don't think that will help, so let me clarify. I need to resample the image (reducing the number of pixels on each axis) not change the spatial calibration. Many thanks, Greg.
>> Sent from my iPhone
>>> On 31 Dec 2017, at 09:37, Straub, Volko A. (Dr.) <[hidden email]> wrote:
>>>
>>> setVoxelSize(width, height, depth, unit)
>>> Defines the voxel dimensions and unit of length ("pixel", "mm", etc.) for the current image or stack. A "um" unit will be converted to "µm". The depth argument is ignored if the current image is not a stack. See also: getVoxelSize<https://imagej.nih.gov/ij/developer/macro/functions.html#getVoxelSize>.
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
Gregory Jefferis, PhD
Division of Neurobiology
MRC Laboratory of Molecular Biology
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
http://jefferislab.org
http://www.zoo.cam.ac.uk/departments/connectomics




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

Re: Running a macro with the Scale command headless fails

Herbie
Sorry Greg,

of being of no help with this issue!

The meaning of "headless" and "without GUI" appears not being
well-defined. I have no experience with running applications on clusters
but I remember some posts on this list and on the Forum that deal with
similar problems.

As far as I remember things may improve with ImageJ-2 but as the great
software architect recently mentioned: "[...] some of the IJ2 API is not
yet fully stabilized." The interpretation of this statement is left to
experts like you.

Good luck and have a successful New Year

Herbie

::::::::::::::::::::::::::::::::::::::::::::::
Am 02.01.18 um 14:50 schrieb Gregory Jefferis:

> Dear Herbie,
>
> Thanks a lot for your response. However, I specifically need to be able to run this script headless on a cluster (see https://imagej.net/Headless <https://imagej.net/Headless>) and for that I need to use the --headless switch to the Fiji/ImageJ launcher.
>
> At your suggestion, I did try using the plain ImageJ 1.50 distribution (http://wsr.imagej.net/distros/linux/ij150-linux64-java8.zip) on the target Linux cluster but I got the early error pasted below. Further testing revealed that headless support is broken within ImageJ itself before it even tries to run a script, so that is not going to help me.
>
> So the question remains, if I use the Fiji/ImageJ launcher, is there a way to get round the fact that the Scale... command does not work headless? This could be another way of resampling images in x,y,z that does not depend on a GUI element that cannot be run headless.
>
> Many thanks,
>
> Greg.
>
> [jefferis@hex ImageJ]$ ./ImageJ --headless -batch simple_scale.ijm
> Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
> Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
> Exception in thread "main" java.awt.HeadlessException
> at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
> at java.awt.MenuComponent.<init>(MenuComponent.java:159)
> at java.awt.MenuItem.<init>(MenuItem.java:214)
> at java.awt.MenuItem.<init>(MenuItem.java:198)
> at java.awt.Menu.<init>(Menu.java:157)
> at java.awt.Menu.<init>(Menu.java:137)
> at ij.Menus.getMenu(Menus.java:775)
> at ij.Menus.getMenu(Menus.java:765)
> at ij.Menus.addMenuBar(Menus.java:105)
> at ij.IJ.init(IJ.java:362)
> at ij.IJ.runMacroFile(IJ.java:146)
> at ij.ImageJ.main(ImageJ.java:716)
>
> I
>
>
>> On 31 Dec 2017, at 17:38, Herbie <[hidden email]> wrote:
>>
>> Good day Gregory,
>>
>> not being a specialist for non-GUI operation of ImageJ but this call works for me (_plain_ ImageJ-1.51t under macOS 10.11.6, Java 1.6.0):
>>
>> ////////// macro "testMacro.txt"
>> path = getArgument();
>> open(path);
>> run("Scale...", "x=0.5 y=0.5 z=0.5 width=60 height=77 depth=57 interpolation=Bilinear average process");
>> print("success");
>> //////////
>>
>> _Terminal (with result, i.e. ImageJ launched and running)_:
>> java -jar /Applications/ImageJ/ImageJ.app/Contents/Resources/Java/ij.jar -macro /Applications/ImageJ/macros/testMacro.txt /Applications/ImageJ/testimages/bat-cochlea-volume.tif
>>
>> _Terminal (result not shown and not saved, i.e. ImageJ doesn't launch)_:
>> java -jar /Applications/ImageJ/ImageJ.app/Contents/Resources/Java/ij.jar -batch /Applications/ImageJ/macros/testMacro.txt /Applications/ImageJ/testimages/bat-cochlea-volume.tif
>>
>> HTH
>>
>> Herbie
>>
>> ::::::::::::::::::::::::::::::::::::::::::::::
>> Am 31.12.17 um 15:05 schrieb Gregory Jefferis:
>>> Thanks a lot for the response however I don't think that will help, so let me clarify. I need to resample the image (reducing the number of pixels on each axis) not change the spatial calibration. Many thanks, Greg.
>>> Sent from my iPhone
>>>> On 31 Dec 2017, at 09:37, Straub, Volko A. (Dr.) <[hidden email]> wrote:
>>>>
>>>> setVoxelSize(width, height, depth, unit)
>>>> Defines the voxel dimensions and unit of length ("pixel", "mm", etc.) for the current image or stack. A "um" unit will be converted to "µm". The depth argument is ignored if the current image is not a stack. See also: getVoxelSize<https://imagej.nih.gov/ij/developer/macro/functions.html#getVoxelSize>.
>>> --
>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> Gregory Jefferis, PhD
> Division of Neurobiology
> MRC Laboratory of Molecular Biology
> Francis Crick Avenue
> Cambridge Biomedical Campus
> Cambridge, CB2 OQH, UK
>
> http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
> http://jefferislab.org
> http://www.zoo.cam.ac.uk/departments/connectomics
>
>
>
>
> --
> 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: Running a macro with the Scale command headless fails

Michael Schmid-3
In reply to this post by Gregory Jefferis-2
Hi Greg,

instead of Image>Scale you can also try Image>Adjust>Size.

Internally, these two built-in plugins (Scaler and Resizer) are quite
similar, so chances are not too high that the Resizer will work in
Headless mode if the Scaler does not. The only difference that gives you
a slight chance for a headless 'Size' command is the absence of a
FocusListener in the Resizer.

If you are happy with just averaging adjacent pixels (1/2, 1/3, 1/4 etc.
of the original size, just averaging, no bilinear/bicubic kernel), there
is also Image>Transform>Bin. This one has a somewhat simpler dialog,
with a better chance to work in headless mode.

You could also try JavaScript (or Java, BeanShell) instead of the Macro
language; then you can directly access a few public methods of the
Resizer (z direction) or ImageProcessor and Binner(x&y direction,
unfortunately for single images only) without a dialog (the 'scale' has
no suitable method):

   ImagePlus Resizer.zScale(ImagePlus imp, int newDepth, int
interpolationMethod)

   ImageProcessor Binner.shrink(ImageProcessor ip, int xshrink, int
yshrink, int method)

   ImageProcessor ImageProcessor.resize(int dstWidth, int dstHeight)


As far as I remember, the 'headless' mode in ImageJ2/Fiji is quite a
hack - it applies some patches to the compiled ImageJ1 code (ImageJ1
heavily depends on the user interface)...

See also
   http://imagej.net/Headless
   http://imagej.net/Scripting_Headless


Michael
________________________________________________________________


On 02/01/2018 14:50, Gregory Jefferis wrote:

> Dear Herbie,
>
> Thanks a lot for your response. However, I specifically need to be able to run this script headless on a cluster (see https://imagej.net/Headless <https://imagej.net/Headless>) and for that I need to use the --headless switch to the Fiji/ImageJ launcher.
>
> At your suggestion, I did try using the plain ImageJ 1.50 distribution (http://wsr.imagej.net/distros/linux/ij150-linux64-java8.zip) on the target Linux cluster but I got the early error pasted below. Further testing revealed that headless support is broken within ImageJ itself before it even tries to run a script, so that is not going to help me.
>
> So the question remains, if I use the Fiji/ImageJ launcher, is there a way to get round the fact that the Scale... command does not work headless? This could be another way of resampling images in x,y,z that does not depend on a GUI element that cannot be run headless.
>
> Many thanks,
>
> Greg.
>
> [jefferis@hex ImageJ]$ ./ImageJ --headless -batch simple_scale.ijm
> Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
> Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
> Exception in thread "main" java.awt.HeadlessException
> at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
> at java.awt.MenuComponent.<init>(MenuComponent.java:159)
> at java.awt.MenuItem.<init>(MenuItem.java:214)
> at java.awt.MenuItem.<init>(MenuItem.java:198)
> at java.awt.Menu.<init>(Menu.java:157)
> at java.awt.Menu.<init>(Menu.java:137)
> at ij.Menus.getMenu(Menus.java:775)
> at ij.Menus.getMenu(Menus.java:765)
> at ij.Menus.addMenuBar(Menus.java:105)
> at ij.IJ.init(IJ.java:362)
> at ij.IJ.runMacroFile(IJ.java:146)
> at ij.ImageJ.main(ImageJ.java:716)
>
> I
>
>
>> On 31 Dec 2017, at 17:38, Herbie <[hidden email]> wrote:
>>
>> Good day Gregory,
>>
>> not being a specialist for non-GUI operation of ImageJ but this call works for me (_plain_ ImageJ-1.51t under macOS 10.11.6, Java 1.6.0):
>>
>> ////////// macro "testMacro.txt"
>> path = getArgument();
>> open(path);
>> run("Scale...", "x=0.5 y=0.5 z=0.5 width=60 height=77 depth=57 interpolation=Bilinear average process");
>> print("success");
>> //////////
>>
>> _Terminal (with result, i.e. ImageJ launched and running)_:
>> java -jar /Applications/ImageJ/ImageJ.app/Contents/Resources/Java/ij.jar -macro /Applications/ImageJ/macros/testMacro.txt /Applications/ImageJ/testimages/bat-cochlea-volume.tif
>>
>> _Terminal (result not shown and not saved, i.e. ImageJ doesn't launch)_:
>> java -jar /Applications/ImageJ/ImageJ.app/Contents/Resources/Java/ij.jar -batch /Applications/ImageJ/macros/testMacro.txt /Applications/ImageJ/testimages/bat-cochlea-volume.tif
>>
>> HTH
>>
>> Herbie
>>
>> ::::::::::::::::::::::::::::::::::::::::::::::
>> Am 31.12.17 um 15:05 schrieb Gregory Jefferis:
>>> Thanks a lot for the response however I don't think that will help, so let me clarify. I need to resample the image (reducing the number of pixels on each axis) not change the spatial calibration. Many thanks, Greg.
>>> Sent from my iPhone
>>>> On 31 Dec 2017, at 09:37, Straub, Volko A. (Dr.) <[hidden email]> wrote:
>>>>
>>>> setVoxelSize(width, height, depth, unit)
>>>> Defines the voxel dimensions and unit of length ("pixel", "mm", etc.) for the current image or stack. A "um" unit will be converted to "µm". The depth argument is ignored if the current image is not a stack. See also: getVoxelSize<https://imagej.nih.gov/ij/developer/macro/functions.html#getVoxelSize>.
>>> --
>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> Gregory Jefferis, PhD
> Division of Neurobiology
> MRC Laboratory of Molecular Biology
> Francis Crick Avenue
> Cambridge Biomedical Campus
> Cambridge, CB2 OQH, UK
>
> http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
> http://jefferislab.org
> http://www.zoo.cam.ac.uk/departments/connectomics
>
>
>
>
> --
> 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: Running a macro with the Scale command headless fails

Gregory Jefferis-2
> On 2 Jan 2018, at 18:16, Michael Schmid <[hidden email]> wrote:
>
> instead of Image>Scale you can also try Image>Adjust>Size.
>
> Internally, these two built-in plugins (Scaler and Resizer) are quite similar, so chances are not too high that the Resizer will work in Headless mode if the Scaler does not. The only difference that gives you a slight chance for a headless 'Size' command is the absence of a FocusListener in the Resizer.


This worked! Thanks so much, Michael.

In my example it would be called:

run("Size...", "width=60 height=76 depth=57 average interpolation=Bilinear");

There is a minor inconvenience of having to calculate the new size explicitly rather than just asking for 0.5x smaller, which is what I wanted, but that is a small price to pay.

> You could also try JavaScript (or Java, BeanShell) instead of the Macro language;


In future I might go for JavaScript or Groovy (sounds like this might be a better switch than BeanShell) but I have a few fairly complex macros that I don't want to rewrite from scratch for now.

Thanks again,

Greg.

--
Gregory Jefferis, PhD
Division of Neurobiology
MRC Laboratory of Molecular Biology
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
http://jefferislab.org
http://www.zoo.cam.ac.uk/departments/connectomics




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

Re: Running a macro with the Scale command headless fails

ctrueden
In reply to this post by Gregory Jefferis-2
Hi Greg,

> This fails apparently because the Scale dialog box cannot be run
> headless.

Indeed, it does not work, because that command has hardcoded assumptions
about having a certain number of text fields:

https://github.com/imagej/ImageJA/blob/v1.51s/src/main/java/ij/plugin/Scaler.java#L257-L258

It might be possible to change ImageJ2's headless mode to still return
actual AWT components (as long as they are not java.awt.Window objects).
But I unfortunately cannot investigate it now. If you are interested in
attempting that, I could give some pointers.

> Can anyone suggest a workaround?

Did you try using xvfb?
http://imagej.net/Headless#Xvfb

> PS I tried to sign up for http://forum.imagej.net/ using both GitHub &
> google authentication (gmail address) and directly with my @cam.ac.uk
> email. I never received a confirmation email.

Your "jefferis" account was already activated, but "gjefferis" was not. I
have now activated it. I also increased both accounts to trust level 2. So
choose the one you like better and we can merge/delete the other one.

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden
Did you know ImageJ has a forum? http://forum.imagej.net/


On Sun, Dec 31, 2017 at 3:15 AM, Gregory Jefferis <[hidden email]>
wrote:

> Hello,
>
> I'd like to run an IJ1 macro headless. It uses the Scale command. This
> fails apparently because the Scale dialog box cannot be run headless.
>
> Can anyone suggest a workaround? Minimal example below.
>
> With many thanks,
>
> Greg.
>
> PS I tried to sign up for http://forum.imagej.net/ using both GitHub &
> google authentication (gmail address) and directly with my @cam.ac.uk
> email. I never received a confirmation email. A repeat of this?
> http://forum.imagej.net/t/forum-server-issues-
> registration-and-notification-emails-not-sent/3371
>
> --- simple_scale.ijm ---
> run("Bat Cochlea Volume (19K)");
> run("Scale...", "x=.5 y=.5 z=.5 width=60 height=77 depth=57
> interpolation=Bilinear average process");
> --- snip ---
>
>
> $ /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --run
> simple_scale.ijm -batch
> Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m;
> support was removed in 8.0
> Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is
> deprecated and will likely be removed in a future release
>
> $ /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless
> --run simple_scale.ijm -batch
> Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m;
> support was removed in 8.0
> Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is
> deprecated and will likely be removed in a future release
> java.lang.NullPointerException
>         at ij.plugin.Scaler.showDialog(Scaler.java:253)
>         at ij.plugin.Scaler.run(Scaler.java:42)
>         at ij.IJ.runPlugIn(IJ.java:187)
>         at ij.Executer.runCommand(Executer.java:137)
>         at ij.Executer.run(Executer.java:66)
>         at ij.IJ.run(IJ.java:297)
>         at ij.macro.Functions.doRun(Functions.java:601)
>         at ij.macro.Functions.doFunction(Functions.java:96)
>         at ij.macro.Interpreter.doStatement(Interpreter.java:230)
>         at ij.macro.Interpreter.doStatements(Interpreter.java:218)
>         at ij.macro.Interpreter.run(Interpreter.java:115)
>         at ij.macro.Interpreter.run(Interpreter.java:85)
>         at ij.macro.Interpreter.run(Interpreter.java:96)
>         at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:155)
>         at ij.IJ.runMacro(IJ.java:134)
>         at ij.IJ.runMacro(IJ.java:123)
>         at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1052)
>         at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1048)
>         at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.
> java:999)
>         at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1048)
>         at net.imagej.legacy.plugin.IJ1MacroEngine.eval(
> IJ1MacroEngine.java:136)
>         at org.scijava.script.ScriptModule.run(ScriptModule.java:159)
>         at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
>         at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
>         at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
>         at org.scijava.thread.DefaultThreadService$3.call(
> DefaultThreadService.java:237)
>         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>         at java.util.concurrent.ThreadPoolExecutor.runWorker(
> ThreadPoolExecutor.java:1142)
>         at java.util.concurrent.ThreadPoolExecutor$Worker.run(
> ThreadPoolExecutor.java:617)
>         at java.lang.Thread.run(Thread.java:745)
>
>
>
> --
> Gregory Jefferis, PhD                   Tel: +44 1223 267048
> Division of Neurobiology
> MRC Laboratory of Molecular Biology
> Francis Crick Avenue
> Cambridge Biomedical Campus
> Cambridge, CB2 OQH, UK
>
> http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
> http://jefferislab.org
> http://www.zoo.cam.ac.uk/departments/connectomics
>
>
> --
> Gregory Jefferis, PhD
> Division of Neurobiology
> MRC Laboratory of Molecular Biology
> Francis Crick Avenue
> Cambridge Biomedical Campus
> Cambridge, CB2 OQH, UK
>
> http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
> http://jefferislab.org
> http://www.zoo.cam.ac.uk/departments/connectomics
>
> --
> 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: Running a macro with the Scale command headless fails

Wayne Rasband-2
In reply to this post by Gregory Jefferis-2
> On Dec 31, 2017, at 4:15 AM, Gregory Jefferis <[hidden email]> wrote:
>
> Hello,
>
> I'd like to run an IJ1 macro headless. It uses the Scale command. This fails apparently because the Scale dialog box cannot be run headless.
>
> Can anyone suggest a workaround? Minimal example below.

This bug is fixed in the latest ImageJ daily build (1.51u4).

-wayne

> With many thanks,
>
> Greg.
>
> PS I tried to sign up for http://forum.imagej.net/ using both GitHub & google authentication (gmail address) and directly with my @cam.ac.uk email. I never received a confirmation email. A repeat of this? http://forum.imagej.net/t/forum-server-issues-registration-and-notification-emails-not-sent/3371
>
> --- simple_scale.ijm ---
> run("Bat Cochlea Volume (19K)");
> run("Scale...", "x=.5 y=.5 z=.5 width=60 height=77 depth=57 interpolation=Bilinear average process");
> --- snip ---
>
>
> $ /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --run simple_scale.ijm -batch
> Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
> Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
>
> $ /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --run simple_scale.ijm -batch
> Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
> Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
> java.lang.NullPointerException
> at ij.plugin.Scaler.showDialog(Scaler.java:253)
> at ij.plugin.Scaler.run(Scaler.java:42)
> at ij.IJ.runPlugIn(IJ.java:187)
> at ij.Executer.runCommand(Executer.java:137)
> at ij.Executer.run(Executer.java:66)
> at ij.IJ.run(IJ.java:297)
> at ij.macro.Functions.doRun(Functions.java:601)
> at ij.macro.Functions.doFunction(Functions.java:96)
> at ij.macro.Interpreter.doStatement(Interpreter.java:230)
> at ij.macro.Interpreter.doStatements(Interpreter.java:218)
> at ij.macro.Interpreter.run(Interpreter.java:115)
> at ij.macro.Interpreter.run(Interpreter.java:85)
> at ij.macro.Interpreter.run(Interpreter.java:96)
> at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:155)
> at ij.IJ.runMacro(IJ.java:134)
> at ij.IJ.runMacro(IJ.java:123)
> at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1052)
> at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1048)
> at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:999)
> at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1048)
> at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:136)
> at org.scijava.script.ScriptModule.run(ScriptModule.java:159)
> at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
> at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
> at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
> at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:237)
> at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> at java.lang.Thread.run(Thread.java:745)
>
>
>
> --
> Gregory Jefferis, PhD                   Tel: +44 1223 267048
> Division of Neurobiology
> MRC Laboratory of Molecular Biology
> Francis Crick Avenue
> Cambridge Biomedical Campus
> Cambridge, CB2 OQH, UK
>
> http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
> http://jefferislab.org
> http://www.zoo.cam.ac.uk/departments/connectomics
>
>
> --
> Gregory Jefferis, PhD
> Division of Neurobiology
> MRC Laboratory of Molecular Biology
> Francis Crick Avenue
> Cambridge Biomedical Campus
> Cambridge, CB2 OQH, UK
>
> http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
> http://jefferislab.org
> http://www.zoo.cam.ac.uk/departments/connectomics

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