Simple Macro gives different results depending on how it's executed

Hi there,

I have issues with my macro. To reproduce the problem, I put together a very simple macro which gives me different results.

reproduce.zip (900.2 KB)

The macro (given; path needs to be adapted) loads an image (given), applies a gamma correction with value 0.3 and saves the result image. It opens the given image again, applies a gamma correction with value 0.7 and saves the result image.

If I run the macro from the macro editor, I get two different result images (as expected). If I execute it via commandline like this:

/Applications/_MyApplications/Fiji.app/Contents/MacOS/ImageJ-macosx --headless --console -macro test_gamma.ijm

the result images are exactly the same. They seem to ignore the given values and use some default instead? Why is that? Is there any way to prevent it? I’m not sure whether this behaiour is specific to the gamma-function but I’ve tested other calls which where fine…

I will be happy to get an explanation and even happier to get a solution…

This appears to be a Fiji headless mode bug. You can work around it by running the macro using

/Applications/_MyApplications/Fiji.app/Contents/MacOS/ImageJ-macosx -batch test_gamma.ijm

1 Like

@Wayne
Thanks for your answer. I still have problems as I’m running the macro on a machine without graphical user interface. Starting Fiji like you suggested gives me the following message:

‘No GUI detected. Falling back to headless mode.’

Results are still not as expected, so I guess it uses the headless mode anyhow… Any further idea?

Best,
Antje

It seems that I could solve it by using ‘xvfb’ to simulate a GUI. So my call now looks like this:

/sw/bin/xvfb-run -a /path/to/Fiji/app/ImageJ-macosx -batch test_gamma.ijm

One question left:
Is this bug with the headless mode known? Is it a problem for multiple functions (so where would I have to expect problems?).

I’m not sure if it makes a difference, but can you also try including the --ij2 flag, and using the --run flag instead of -macro, as recommended in the Scripting Headless documentation:

/Applications/_MyApplications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --console --run test_gamma.ijm

@imagejan
Thanks for the suggestion. Unfortunately, it does not make any difference…

I reproduced the issue here. This happens with the gamma function but works e.g. with the multiply function as expected. It seems to me that the Fiji headless bytecode manipulation that patches ImageJ1 needs to be updated to work with the generic dialog slider that the gamma dialog uses now.
@ctrueden maybe?

Oh, wow, thanks for digging!

These backwards-incompatible changes in ImageJ 1.x are a nightmare for reproducibility, as this topic here demonstrates…

The fixes will likely have to go here:

The Gamma dialog now uses the 5 parameters signature:

here the change history:

1 Like

The latest ImageJ daily build (1.52p44) works around this bug. To upgrade, use the Help>Update ImageJ command and select “daily build” from the drop down menu. View the code changes at

1 Like

@Wayne
thanks a lot for fixing the problem so fast!
I looked around in the docs but I did not find how to get the “daily build” via command line (as I do not have any GUI there). Can you (or anybody else) help me with that?

You have to replace your version of ij.jar with the version available from:
http://wsr.imagej.net/download/daily-build/ij.jar

Thanks a lot! Replacing the jar did the trick. Now, I finally could run my macro :slight_smile: