How To: Automate HDR on Linux - Part 3
Now that we have a .EXR file laying around, it’s time to do some tone mapping. In this part of the series we’ll be looking at a script to tone map that file. Well, actually several scripts. When I prepare a photo from HDR I tend to use several different tone-mapping operators, and then I use the Gimp to combine them into a final image. Here we have scripts for the fattal02, mantiuk06, and reinhard05 operators of the pfstmo project. Then we have a wrapper script to make it easy to run all three tone mapping scripts with one command.
Any of the scripts below can be run without any command line arguments in one of the HDR directories from our previous steps. You can edit the scripts to choose to process the full size images or the thumb that was created in the last step.
Mode can also be passed in on the command line. Valid options are ‘full’ or ‘thumb’.
Download tone_map_exr_fattal.sh
#!/bin/bashLONGDIR=$(pwd)
DIR=${LONGDIR##*/}
SMALLSIZE=1024
MODE=thumb
#MODE should be 'full' or 'thumb'
OUTPUTDIR=.
if [ $# = 1 ]; then
echo "custom mode: $1"
MODE=$1
fi
if [ $# = 2 ]; then
echo "custom num: $2"
DIR=$2
fi
alfas=( 0.1 )
betas=( 0.94 )
sats=( 0.90 )
gamas=( 1 )
echo "running pfstone mapping operation"
I=1; #img # (useful for panos)
for a in "${alfas[@]}"
do
for b in "${betas[@]}"
do
for s in "${sats[@]}"
do
for g in "${gamas[@]}"
do
if [ -f $OUTPUTDIR/$DIR.$MODE.auto_fattal02_a.$a-b.$b-s.$s-g.$g--$I.jpg ]; then
echo " image exists remove to regenerate $OUTPUTDIR/$DIR.$MODE.auto_fattal02_a.$a-b.$b-s.$s-g.$g--$I.jpg"
else
echo "generating image"
pfsin $DIR.$MODE.exr | pfstmo_fattal02 -a $a -b $b -s $s | pfsgamma -g $g | pfsout $OUTPUTDIR/$DIR.$MODE.auto_fattal02_a.$a-b.$b-s.$s-g.$g--$I.jpg
fi
if [ -f $OUTPUTDIR/$DIR.aligned.$MODE.auto_fattal02_a.$a-b.$b-s.$s-g.$g--$I.jpg ]; then
echo " image exists remove to regenerate $OUTPUTDIR/$DIR.aligned.$MODE.auto_fattal02_a.$a-b.$b-s.$s-g.$g--$I.jpg"
else
if [ -f $OUTPUTDIR/$DIR.aligned.$MODE.exr ]; then
echo "generating image"
pfsin $DIR.aligned.$MODE.exr | pfstmo_fattal02 -a $a -b $b -s $s | pfsgamma -g $g | pfsout $OUTPUTDIR/$DIR.aligned.$MODE.auto_fattal02_a.$a-b.$b-s.$s-g.$g--$I.jpg
fi
fi
((I++));
done
done
done
done
Mantiuk05
Download tone_map_exr_mantiuk.sh
#!/bin/bashLONGDIR=$(pwd)
DIR=${LONGDIR##*/}
SMALLSIZE=1024
MODE=thumb
#MODE should be 'full' or 'thumb'
OUTPUTDIR=.
if [ $# = 1 ]; then
echo "custom mode: $1"
MODE=$1
fi
if [ $# = 2 ]; then
echo "custom num: $2"
DIR=$2
fi
mfacs=( 0.25 )
msats=( 1 )
mgamas=( 0.6 )
echo "running pfstone mapping operation"
#This one scales the images within 1024x1024
I=1; #img # (useful for panos)
for a in "${mfacs[@]}"
do
for s in "${msats[@]}"
do
for g in "${mgamas[@]}"
do
if [ -f $OUTPUTDIR/$DIR.$MODE.auto_mantiuk06_f.$a-s.$s-g.$g--$I.jpg ]; then
echo " image exists remove to regenerate $OUTPUTDIR/$DIR.$MODE.auto_mantiuk06_f.$a-s.$s-g.$g--$I.jpg"
else
echo "generating image"
pfsin $DIR.$MODE.exr | pfsgamma -g $g | pfstmo_mantiuk06 -f $a -s $s | pfsout $OUTPUTDIR/$DIR.$MODE.auto_mantiuk06_f.$a-s.$s-g.$g--$I.jpg
fi
if [ -f $OUTPUTDIR/$DIR.aligned.$MODE.auto_mantiuk06_f.$a-s.$s-g.$g--$I.jpg ]; then
echo " image exists remove to regenerate $OUTPUTDIR/$DIR.aligned.$MODE.auto_mantiuk06_f.$a-s.$s-g.$g--$I.jpg"
else
echo "generating image"
pfsin $DIR.aligned.$MODE.exr | pfsgamma -g $g | pfstmo_mantiuk06 -f $a -s $s | pfsout $OUTPUTDIR/$DIR.aligned.$MODE.auto_mantiuk06_f.$a-s.$s-g.$g--$I.jpg
fi
fi
((I++));
done
done
done
Reinhard05
Download tone_map_exr_reinhard05.sh
#!/bin/bash
################################
# Written by Jeremy Green
# http://www.rhythmandcode.com/
################################
LONGDIR=$(pwd)
DIR=${LONGDIR##*/}
SMALLSIZE=1024
MODE=full
#MODE should be 'full' or 'thumb'
OUTPUTDIR=.if [ $# = 1 ]; then
echo "custom mode: $1"
MODE=$1
fi
if [ $# = 2 ]; then
echo "custom num: $2"
DIR=$2
fi
brightnesses=( -8 )
chromatic_adaptations=( 0.92 )
light_adaptations=( 0.95 )
echo "running pfstone mapping operation"
#This one scales the images within 1024x1024
I=1; #img # (useful for panos)
for b in "${brightnesses[@]}"
do
for c in "${chromatic_adaptations[@]}"
do
for l in "${light_adaptations[@]}"
do
if [ -f $OUTPUTDIR/$DIR.$MODE.auto_reinhard05_b.$b-c.$c-l.$l--$I.jpg ]; then
echo " image exists remove to regenerate $OUTPUTDIR/$DIR.$MODE.auto_reinhard05_b.$b-c.$c-l.$l--$I.jpg"
else
echo "generating image"
pfsin $DIR.$MODE.exr | pfstmo_reinhard05 -c $c -b $b -l $l | pfsout $OUTPUTDIR/$DIR.$MODE.auto_reinhard05_b.$b-c.$c-l.$l--$I.jpg
fi
if [ -f $OUTPUTDIR/$DIR.aligned.$MODE.auto_reinhard05_b.$b-c.$c-l.$l--$I.jpg ]; then
echo " image exists remove to regenerate $OUTPUTDIR/$DIR.aligned.$MODE.auto_reinhard05_b.$b-c.$c-l.$l--$I.jpg"
else
echo "generating image"
pfsin $DIR.aligned.$MODE.exr | pfstmo_reinhard05 -c $c -b $b -l $l | pfsout $OUTPUTDIR/$DIR.aligned.$MODE.auto_reinhard05_b.$b-c.$c-l.$l--$I.jpg
fi
fi
((I++));
done
done
done
Pulling it all together
This script will run all of the above scripts in the directory it’s run from. It expects that the other scripts live in ~/bin. You’ll need to update the script if you put the somewhere else.
#!/bin/bash ################################ # Written by Jeremy Green # http://www.rhythmandcode.com/ ################################ echo "~/bin/tone_map_exr_fattal.sh" ~/bin/tone_map_exr_fattal.sh echo "~/bin/tone_map_exr_mantiuk.sh" ~/bin/tone_map_exr_mantiuk.sh echo "~/bin/tone_map_exr_reinhard05.sh" ~/bin/tone_map_exr_reinhard05.sh