Auto brightness/contrast in macro unexpected behavior

This is my original image:
original.tif (3.1 MB)
When I manually apply the Auto Brightness/Contrast, I get the following image:
BCauto_manual.tif (3.1 MB)
However, when I run the macro lines (recorded with the macro recorder) on the original image:
run(“Enhance Contrast”, “saturated=0.35”);
run(“Apply LUT”);
I get a different result:
BCauto_FromMacro.tif (3.1 MB)

Any idea why? I was expecting the same output.
Thanks in advance.

I have to admit this is not intuitive but conform with the user guide (see link below).

If you press “Set” in the GUI the following macro is produced in the macro recorder to restrict the display range:

run(“Enhance Contrast”, “saturated=0.35”);
setMinAndMax(18014, 25464);

which does the same as using the GUI (see the different histogramm display range when using only the first command).


Thank you, the macro code does produce the same image now. But as you said, it is not very intuitive at all as you would expect the macro recorder to record that additional step as well. I mean when one press Apply in the GUI, that is to reset the min and max of the image to the min and max found by pressing Auto. Unless I am missing something…


Actually I still have a problem. Your solution works if you know the min and max beforehand and/or want to always apply the same min and max.
I know I can record the values of min and max with “getMinAndMax(min, max)”, but I still need to press the Auto button in the Brightness/Contrast window beforehand. Which I don’t want to do because I have hundreds of images to process. Is there a way around that? How do I reproduce “Pressing the Auto button in Brightness/Contrast” in a macro?



See the link explanation in this older thread provided by @Kota:

The second link also provides an ImageJ macro!


That is exactly what I needed. Thank you for digging out this old thread.


1 Like