How can I batch-process images to adjust contrast in terminal?

Solution 1:

One excellent option is to use ImageMagick's -brightness-contrast option in combination with a bash for loop.

To see how it all works first find a test image and experiment with the following syntax:

convert -brightness-contrast 10x5 input.jpg output.jpg

The -brightness-contrast option has 2 elements:

  1. -brightness. In the example above this has been set at 10 and possible settings are from -100 to +100. Positive values increase the brightness while negative values decrease the brightness. Using a '0' value means that the brightness will remain unchanged.
  2. -contrast. In the example above this has been set at 5 and again possible settings are from -100 to +100. Positive values increase the contrast while negative values decrease the contrast. Using a '0' value means that the contrast will remain unchanged.

Once you have found the settings best for your image you can navigate to the folder holding your images and run a bash for loop:

for j in *.jpg
do 
  convert -brightness-contrast 10x5 "$j" altered_"$j"
done

Here you can see I have made a small naming alteration for the output file which you can of course tailor to your specific needs.

There are many different ways to accomplish your goal with ImageMagick but this would be my own choice as it is both the easiest to use and to understand :).

References:

  • ImageMagick -brightness-contrast: All of the details on this command from the ImageMagick web site.