_           _                 
 | |_ ___  __| |____  ___ _   _ 
 | __/ _ \/ _` |_  / / _ \ | | |
 | ||  __/ (_| |/ / |  __/ |_| |
  \__\___|\__,_/___(_)___|\__,_|

Using ImageMagick to correct white balance in a batch of photos using a white reference

I had the problem of fixing the white balance in a set of photos I had taken with the camera settings wrong. I had "Tungsten light (Approx. 3200K)" selected on my Canon 700D, but I was taking photos outdoors, so I should probably have set it to "Daylight (Approx. 5200K)". The result was that all of the photos had a kind of blueish tint.

Using ImageMagick, I was able to correct the white balance for the whole set of files as follows:

#!/bin/bash

for file in IMG*.JPG ; do echo $file ; convert $file \( +clone \( white_reference.jpg -gravity Center -crop "128x128+0+0" -scale "1x1" -negate \) +dither -interpolate Integer -clut \) -compose Overlay -composite ${file%.JPG}_WB.JPG ; done

The core of that script is from a solution suggested by user "stupid" on the ImageMagick web forum:

https://www.imagemagick.org/discourse-server/viewtopic.php?t=15564

I just wrapped it in a bash for loop.