Macro to adjust brightness and contrast by a given value

Hello, I hope you are all well and doing fine in the current situation with COVID 19!

I am new to ImageJ and try to use it for batchadjustments on a set of preedited color jpg images (photos). Meaning the goal is to adjust the brigthness and the contrast of a stack of jpg-images and adjust each image with specific (given) correction values (e.g. reduce brightness of image1 by 2 and increase brightnesse of image2 by 5).

ImageJ can normalize the histogram of an image using Enhance Contrast (, “Enhance Contrast…”, “saturated=2 equalize”):wink: and can autoadjust brightness and contrast using, “Enhance Contrast”, “saturated=0.35”);. Both creates a neutral histogram, but does not adjust to specific values.

I can modify the LUT using getLut(reds, greens, blues) and setLut(reds, greens, blues) by first converting the images to 8bit color which results in a loss of data or in an HSB Stack which takes a lot of ressources and time if I’ve to convert all images to HSB and back.

The Image / Adjust / B&C is the exact function I need, but I can’t do this correction manually as we are talking of approx. 15.000 images. Sadly the macro recorder only records the buttons and not the liveadjustments when you move the bars of min/max/brightness/contrast.

Is there a function / command / macro / something to adjust the brightness of an rgb to a specific value without first converting it?

Thank you in advance and I wish you a great and healty weekend


there are two built-in macro functions, setMinAndMax(min, max) and setMinAndMax(min, max, channels). The second one is specifically for RGB images, allowing to set min and max for color channels. For the full documentation and examples, see

Note that these functions, when used with a stack, apply the values only to the active slice (this is, however, no problem for photos). With stacks, one can loop over all slices like so:

for (i = 1; i <= nSlices; i++) {
   setMinAndMax(0, 64); //sets min to 0, max to 64