Apply Multiple Hald CLUT Presets in a Single Action with a Bash Shell Script

Hald CLUT files offer a straightforward way to apply color corrections to an image (read the Linux Photography book to learn more about Hald CLUT and its usage). Install ImageMagick on your system, and you can easily apply a Hald CLUT preset to an image file using the following command:

convert foo.JPG hald-9.png -hald-clut foo-modified.jpeg

But what if you have a handful of Hald CLUT files and you want to apply them all to a specific photo?

A relatively simple Bash shell script can automate this otherwise tedious task:

#!/usr/bin/env bash
if [ -z "$1" ]; then
  echo "Specify the required parameter."
  exit 1
fi
dir="hald-clut"
if [ ! -d "$dir" ]; then
  mkdir -p "$dir"
fi
for file in *.png; do
  prefix="${file%.*}"
  bname=$(basename "$1")
  echo "Applying $file Hald-CLUT ..."
  convert "$1" "$file" -hald-clut "$dir/$prefix-$bname"
done

The script picks .png Hald CLUT files in the current working directory one-by-one and applies them to the specified image file. The modified files are saved in the separate hald-clut directory, and each file is prefixed with the name of the applied Hald-CLUT file.

Here is how this works in practice. First of all, paste the code above into a text file and save it under the hald-clut name. Use then the following commands to copy the created file to the /usr/local/bin directory and make the script executable:

sudo cp hald-clut /usr/local/bin/
sudo chown root:root /usr/local/bin/hald-clut
sudo chmod 755 /usr/local/bin/hald-clut

Now, let’s say you want to apply all Hald CLUT presets in the hald-clut-files directory to the foo.JPG file. In the terminal, switch to the directory, and run the hald-clut path/to/foo.JPG command (replace path/to/foo.JPG with the actual path to the desired file). This apply all presets to the foo.JPG image and saves the resulting files in the hald-clut-files/hald-clut directory.

This is an excerpt from the Linux Photography book. Get your copy here.

Advertisement

Tech writer covering Linux and open source software

Tagged with: , ,
Posted in Open Source, Photography, Scribbles, Software

Recipes for automated and streamlined photographic workflow on Linux

Use digiKam? Get this book!

Practical advice for nighttime photography

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

%d bloggers like this: