Realistic Looking HDRs from the command line

Synonym, originally uploaded by earlycj5.

Just recently, I don’t know where I’ve been, I discovered a nice little program, Enfuse, for blending exposure layers. It was installed on my UbuntuStudio machine when I installed my favorite panorama creator, Hugin.

Since I often work with single RAW files from my Nikon using UFRAW to create multiple exposures I took it a step further I found a Bash script to take a single RAW file and use the ufraw-batch command to reate an enhanced dynamic range image from the RAW file.

When I tried to use it the first time it segfaulted. Removing the .ufrawrc file in my home directory fixed this issue for me.

I ended up tweaking the script file to suit my own needs with some of the UFRAW options, but in the end, I’m quite impressed with the quality of image and the ease with which I was able to generate it.

“Synonym” was my first attempt at this, I’ll be using this for many more photos I’m sure as I like the flexibility of HDR but never was totally satisfied with the way QTPFSGUI images turned out.  Tonemapping just lead to unrealistic looking images that I didn’t care for.  This is much faster and easier too.

Below is my tweaked version of the script for the latest version of UFRAW.

Save as enfuse_raw.sh in your ~/bin directory, set the file to be executable ‘chmod u+x enfuse_raw.sh’ and enjoy!

#!/bin/bash

if [ ! "$1" ]
then
	echo "Please specify filename."
	exit 1
fi

if [ ! -f "$1" ]
then
	echo "Error: file does not exist"
	exit 1
fi

# extract the filename without extension
filename=`basename "$1" | sed 's/\.\([^\/\.]*$\)//'`

# check lower limit param
if [ $2 ]
then
	lower_limit="$2"
else
	lower_limit=-3
fi

# check upper limit param
if [ $3 ]
then
	upper_limit="$3"
else
	upper_limit=3
fi

# make sure lower limit < upper limit
if [ $upper_limit -le $lower_limit ]
then
	echo "Error: upper limit is smaller than lower limit."
	exit 1
fi

echo "Processing from $lower_limit to $upper_limit."

file_list=""

# should we use -3 exposure from RAW
if [ $lower_limit -lt -2 ]
then
	if [ ! -f "${filename}_N3.tiff" ]
	then
		ufraw-batch  --wb=camera --exposure=-3 --saturation=1.25 --black-point=auto --out-type=tiff --out-depth=8 --output=${filename}_N3.tiff "$1"
	fi
	file_list="${filename}_N3.tiff"
fi

# should we use -2 exposure from RAW
if [ $lower_limit -le -2 -a $upper_limit -ge -2 ]
then
	if [ ! -f ${filename}_N2.tiff ]
	then
		ufraw-batch  --wb=camera --exposure=-2  --saturation=1.25 --black-point=auto --out-type=tiff --out-depth=8 --output=${filename}_N2.tiff "$1"
	fi
	file_list="${file_list} ${filename}_N2.tiff"
fi

# should we use -1 exposure from RAW
if [ $lower_limit -le -1 -a $upper_limit -ge -1 ]
then
	if [ ! -f ${filename}_N1.tiff ]
	then
		ufraw-batch  --wb=camera --exposure=-1 --saturation=1.25 --black-point=auto --out-type=tiff --out-depth=8 --output=${filename}_N1.tiff "$1"
	fi
	file_list="${file_list} ${filename}_N1.tiff"
fi

# should we use 0 exposure from RAW
if [ $lower_limit -le 0 -a $upper_limit -ge 0 ]
then
	if [ ! -f ${filename}_0.tiff ]
	then
		ufraw-batch  --wb=camera --exposure=0 --saturation=1.25 --black-point=auto --out-type=tiff --out-depth=8 --output=${filename}_0.tiff "$1"
	fi
	file_list="${file_list} ${filename}_0.tiff"
fi

# should we use +1 exposure from RAW
if [ $lower_limit -le 1 -a $upper_limit -ge 1 ]
then
	if [ ! -f ${filename}_P1.tiff ]
	then
		ufraw-batch  --wb=camera --exposure=1  --saturation=1.25 --black-point=auto --out-type=tiff --out-depth=8 --output=${filename}_P1.tiff "$1"
	fi
	file_list="${file_list} ${filename}_P1.tiff"
fi

# should we use +2 exposure from RAW
if [ $lower_limit -le 2 -a $upper_limit -ge 2 ]
then
	if [ ! -f ${filename}_P2.tiff ]
	then
		ufraw-batch  --wb=camera --exposure=2  --saturation=1.25 --black-point=auto --out-type=tiff --out-depth=8 --output=${filename}_P2.tiff "$1"
	fi
	file_list="${file_list} ${filename}_P2.tiff"
fi

# should we use +3 exposure from RAW
if [ $upper_limit -gt 2 ]
then
	if [ ! -f ${filename}_P3.tiff ]
	then
		ufraw-batch  --wb=camera --exposure=3  --saturation=1.25 --black-point=auto --out-type=tiff --out-depth=8 --output=${filename}_P3.tiff "$1"
	fi
	file_list="${file_list} ${filename}_P3.tiff"
fi

# run enfuse with default parameter, edit this line for more advance enfuse options
enfuse ${file_list} -o ${filename}_enfused.tiff $4 $5 $6 $7 $8 $9

# uncomment the next line to auto clean up, else just leave the temp files to experiment more
rm ${file_list}

echo "Done: final output file is ${filename}_enfused.tiff"
exit 0
Advertisement

About this entry