Converting and developing RAW photos on Linux automatically

Converting and developing RAW photos on Linux automatically

Taking photos is fun and easy.

Just kidding, it’s a fractal of complexity, FOMO, and slowly realizing how little you actually know.

However, one nice thing is that using some simple Unix/Linux tools, it’s remarkably easy to mass produce good looking JPEG images from your raw photos, without having to actually learn Lightroom.

After a few days of fiddling with the settings, I’ve come up with this bash script to process my images:

/usr/local/bin/autoraw

When run, it handles all the conversion itself:

% autoraw P1190515.RW2

Loading Panasonic DMC-GX85 image from P1190515.RW2 ...
Wavelet denoising...
Scaling with darkness 143, saturation 4095, and
multipliers 1.000000 0.435374 0.702381 0.435374
AHD interpolation...
Blending highlights...
Converting to sRGB colorspace...
Writing data to standard output ...
-=>P1190515.raw.jpg TIFF 3464x4608 3464x4608+0+0 8-bit sRGB 6.10639MiB 0.270u 0:00.270
    1 image files updated

How does it work? Good question!

The first part of the tool uses dcraw to process the raw image with sane default settings:

dcraw -w -c -v -n 200 -b ${2:-1} -H 0 -T "$DIR/$FILE.$FMT"

This uses the white balance from the camera, sets the exposure, rolls off the whites, and performs a very gentle denoise.

The second line is where the real magick happens:

convert - -verbose \
  -modulate '100,125' \
  -contrast-stretch '0.3x0%' \
  -level '0%,100%,1.2' \
  -sigmoidal-contrast '2.50,50%' \
  -adaptive-sharpen '0x4.0' \
  -quality '90' -auto-orient \
  $DIR/$FILE.jpg

This imagemagick command is rather complicated, but does some important work. First, the saturation is increased by 25%. Then, by using the contrast-stretch function, the black & white points are set, then the darker midtones are turned up slightly, then a sigmoid contrast curve is applied to add a pleasing gamma shift to the image. Finally, the image is sharpened and output as a high quality JPEG image.

The final part of the script simply copies the EXIF data from the original photo to the JPEG image, preserving the timestamp, camera settings, and any other metadata that may be desirable to maintain.

The end result is pleasing, and without much effort dozens of images can be processed this way.