Grid/Collection Stitching in headless mode?

I’m trying to use a script to perform tile stitching using the (awesome) “Grid/Collection Stitching” plugin. After figuring out how to run a simple macro headless, I am now having some trouble with this plugin, which raises “java.awt.HeadlessException.”

I’m concerned that the plugin may not be compatible with headless mode, if it always instantiates a UI element. Does anyone know if this is the case?

Thank in advance,

Here is the script:

    from ij import IJ
    stitchOptions  = "type=[Grid: row-by-row]"
    stitchOptions += " order=[Right & Down                ]"
    stitchOptions += " grid_size_x=2 grid_size_y=2"
    stitchOptions += " tile_overlap=20" 
    stitchOptions += " first_file_index_i=1"
    stitchOptions += " directory=[/Users/bbraun/Box Sync/colony microscopy/10xObj/BSB 384 Experiment-237/Experiment-237-tif]"
    stitchOptions += " file_names=Experiment-237_z01m{i}.tif"
    stitchOptions += " output_textfile_name=TileConfiguration_script.txt"
    stitchOptions += " fusion_method=[Linear Blending]"
    stitchOptions += " regression_threshold=0.30"
    stitchOptions += " max/avg_displacement_threshold=4"
    stitchOptions += " absolute_displacement_threshold=3"
    stitchOptions += " compute_overlap"
    stitchOptions += " ignore_z_stage"
    stitchOptions += " computation_parameters=[Save computation time (but use more RAM)]"
    stitchOptions += " image_output=[Write to disk]"
    stitchOptions += " output_directory=[/Users/bbraun/Box Sync/colony microscopy/10xObj/BSB 384 Expt-257/scripts/]"`

    #print stitchOptions"Grid/Collection stitching", stitchOptions);

Here are the warnings and errors:

    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
    Jan 19 16:31:33 PEDS-1CJF6T6-LT ImageJ-macosx[8746] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
    Jan 19 16:31:33 PEDS-1CJF6T6-LT ImageJ-macosx[8746] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
    	at java.awt.GraphicsEnvironment.checkHeadless(
    	at java.awt.Window.<init>(
    	at java.awt.Frame.<init>(
    	at ij.plugin.frame.PlugInFrame.<init>(
    	at ij.plugin.frame.Editor.<init>(
    	at ij.Executer.openExample(
    	at ij.Executer.runCommand(
    	at ij.macro.Functions.doRun(
    	at ij.macro.Functions.doFunction(
    	at ij.macro.Interpreter.doStatement(
    	at ij.macro.Interpreter.doStatements(
    	at ij.plugin.Macro_Runner.runMacro(
    	at ij.IJ.runMacro(
    	at ij.IJ.runMacro(
    	at net.imagej.legacy.IJ1Helper$
    	at net.imagej.legacy.IJ1Helper$
    	at net.imagej.legacy.IJ1Helper.runMacroFriendly(
    	at net.imagej.legacy.IJ1Helper.runMacro(
    	at net.imagej.legacy.LegacyCommandline$Run.handle(
    	at org.scijava.console.DefaultConsoleService.processArgs(
    	at net.imagej.legacy.LegacyConsoleService.processArgs(
    	at org.scijava.AbstractGateway.launch(
    	at net.imagej.Main.launch(
    	at net.imagej.Main.main(
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    	at java.lang.reflect.Method.invoke(
    	at net.imagej.launcher.ClassLauncher.launch(
    	at net.imagej.launcher.ClassLauncher.main(

Just solved my own problem after banging my head just right on my desk.

No problems when called via macro. Fails only when called via script. Presumably the function used by the plugin to check if it is in macro mode does not recognize if being run in a script.

Thanks to the authors for making this possible! I might suggest that this tip for running headless be added to the documentation.

1 Like

Great that you found a solution! I still think it should also be possible to call plugins like this one from any script language without getting a HeadlessException

It would be great if you even do that yourself: it’s a wiki, and maintaining the documentation is a community effort. So feel free to register a wiki account (if you haven’t done so yet) and edit the Image Stitching page. :slight_smile:

1 Like

Good idea - I did not know it was a wiki. However, I’m not certain I was not making a more general error with regard to scripting, so I will not do this quite yet. Thanks!