The process described above can be greatly simplified and even improved when using Linux or a compatible terminal command line environment (like MacOS Terminal with the Homebrew package manager or Windows 10/11 with WSL). Libraw includes a small command-line tool called “4channels” that converts a raw image file into four separate TIFF files for each of its red/green/green/blue color channels. Using the command-line image converter Imagemagick, we can reassemble these split files into a new, “Foveon-like” RGB image.
Here is a shell script that automates this process:
#!/bin/sh
# extract four color channels from a raw digital photograph
# & downsample them into one RGB tiff image, without conventional demosaicing
# Dependencies: libraw (command line tool 4channels), ImageMagick (commandline tool convert), exiftool
input=$*
output="$input-foveon.tiff"
echo $input
echo 'splitting color channels...'
4channels $input > /dev/null
echo 'recombining color channels...'
# first combine the two green channels into one
convert $input.G* -background black -channel GG -depth 16 -combine -compress zip green.tiff 2> /dev/null
# combine final rgb image
convert $input.R.tiff green.tiff $input.B.tiff -set colorspace RGB -background black -channel RGB -depth 32 -define quantum:format=floating-point -combine -colorspace sRGB -compress zip $output 2> /dev/null
# restore original exif tags
exiftool -overwrite_original -TagsFromFile $input "-all:all>all:all" $output > /dev/null
# cleanup temporary files
rm green.tiff $input.[RBG].tiff $input.G2.tiff
You can save this shell script under a name like “truergb”, make it executable (by typing “chmod 700 truergb”), put it in a system directory for executable programs (usually: /usr/local/bin/) and convert your raw image (such as: test.dng) by typing “truergb test.dng”. The result is a 32-bit color TIFF file “test.dng-truergb.tiff”.
Because our script applies an sRGB curve to the merged color channels, the output image looks better and requires fewer visual corrections than images created with RawTherapee/Gimp or with the Darktable workflow. As described above, you can make these final corrections in an image editor of your choice (RawTherapee, Darktable, Gimp, Photoshop, Lightroom…).
To convert a whole set of Raw files into Foveon-like images in one go, open your terminal, go to the folder where the files were saved (using the “cd” command) and type:
for p in *.* ; do truergb $p ; done
After finishing this command, you will find all “Foveon-like” TIFF images in the same directory as the original raw image files.