Run an ImageJ macro in headless mode - Problem with opening an image stack

Dear developers and users,

I’m facing a problem which seems to belong to a similar category of problems met previously by other people (see “Starting a headless macro from Matlab through a system command”, " Running macro from command line in window" and " Reading TIFF file fails on the command line") and related with executing an ImageJ macro in headless mode.

My OS is Linux CentOS 6.9 with a 64 bit kernel.

The ImageJ macro is RunKMeansClustering.txt (3.9 KB)
. Its original filename has ending in .ijm as usual for an ImageJ macro, if that may be of any concern to you (I just needed to rename its file as a .txt file otherwise Discourse would not allow to upload it).

This macro was produced by using the ImageJ Macro Recorder and it runs successfully without any kind of problems when started from the Macro Editor.

I need to run such ImageJ macro in headless mode because I want to run it on a compute node of a cluster where I cannot stream the X11 server output to the cluster’s master node (or, better, I could do that but I would prefer not to have to do that, of course).

I’m calling such ImageJ macro in headless mode with the following command from a BASH shell:

$IMAGEJ --allow-multiple --headless --console -macro $IMAGEJMACROKMEANSCLUST

where IMAGEJ is an environment variable defining the full path of ImageJ’s executable filename, e.g. in a BASH shell environment,

export IMAGEJ="/opt/"

If I run such command I obtain the same type of error which was also mentioned in the 3 posts cited above, i.e.,

Unsupported format or not found

If I reduce the macro to its minimum, e.g., to its first command (at lines 27-28), I still get the same error.
Such command tries to open a stack of 2D TIFF files (it’s a phase contrast X-ray tomogram).
Here S2B_16bit_phase_crop_0001.tif (4.3 MB) an example of 2D TIFF image being a slice of that tomogram.

If I try to open a single 2D TIFF image with the open(…) ImageJ macro function I do not get the same error. Thus it seems to me that the problem does not stem from the type of TIFF file I’m trying to open (the SCIFIO option is unchecked in the “Edit” - > “Option” -> “ImageJ2 …” settings.
The problem seems to stem from trying to open a stack of 2D images by the “Image sequence …” command.

Any suggestion of how I could address this problem or, first, how to trace the source of the problem back would be extremely useful, as I would need to be able to run literally hundreds of such macros for respective, distinct tomograms and that would be a typical task for a compute cluster.

Thanks in advance to anybody for any suggestion.

Best regards,


Hi Michele,

I cannot really address your problem directly. I never used the headless option.

However in the past I ran a lot of Fiji processing on a cluster.
Using a Virtual Frame Buffer (xvfb) really worked well in my hands.

Here is the project to it:

If you have any particular questions for running Fiji on a cluster I am happy to help.


This is not really related, but I find that some commands do not work properly in headless mode like getNumber() for instance. Can you print the stack trace and send us @MichelleGriffa?