Auto brightness/contrast in macro unexpected behavior

Hi,
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(“Brightness/Contrast…”);
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.
David

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).

See:

https://imagej.nih.gov/ij/docs/guide/146-28.html#toc-Subsection-28.2

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…

David

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?

Thanks

David

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

http://imagej.1557.x6.nabble.com/Auto-Brightness-Contrast-and-setMinAndMax-td4968628.html

http://wiki.cmci.info/documents/120206pyip_cooking/python_imagej_cookbook#automatic_brightnesscontrast_button

The second link also provides an ImageJ macro!

2 Likes

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

David

1 Like