Reinhard tone mapper in Radiance?

Hello Radiance community,
Is there a way to apply Reinhard’s tone mapping on HDRIs using Radiance? my intention is to generate images that when displayed on a computer screen would be close to how they would be perceived in reality.

Thanks,
Belal Abboushi

There is a tool called pcond that, while it doesn’t use Reinhard’s tone-mapping, does have a number of options to simulate perception. It is based on our 1997 TVCG paper, linked on my publications page (#31).

If you want Reinhard’s global tone operator, there is a reinhard.cal file included in the ray/src/cal/cal/ directory included in Radiance. You’ll need to set the parameters appropriately, which is a little bit tricky. The following C-shell script will do it for you:

#!/bin/csh -fe
#
# Compute Erik Reinhard's photographic tone-mapping
#
if ($#argv == 2) then
	if ("$argv[1]" =~ "-p*") then
		set params_only
		shift argv
	endif
endif
if ($#argv != 1) then
	echo Usage: $0 input.hdr \> output.pic
	echo Or: $0 -params input.hdr
	exit 1
endif
phisto $1 > /tmp/rtm$$.histo
set ns=`rcalc -e '$1=$2' /tmp/rtm$$.histo | total`
set lmin=`sed -n '2s/	.*$//p' /tmp/rtm$$.histo`
set lavg=`rcalc -e '$1=$1*$2/'$ns /tmp/rtm$$.histo | total`
set lmax=`tail -2 /tmp/rtm$$.histo | sed -n '1s/	.*$//p'`
rm /tmp/rtm$$.histo
set settings="log2:log10(2);Lwht:1.5*2^($lmax/log2-$lmin/log2-5);alpha:.18*4^((2*$lavg-$lmin-$lmax)/($lmax-$lmin));gsca:alpha/10^$lavg"
if ( $?params_only ) then
	exec rcalc -n -e $settings:q -o 'Lwht:${ Lwht }; gsca:${ gsca };'" Lmin:10^$lmin; Lmax:10^$lmax;"
endif
exec pcomb -e 'ro=m*ri(1);go=m*gi(1);bo=m*bi(1)' \
	-e $settings:q \
	-e 'L=WE*gsca*li(1)' \
	-e 'm=WE*gsca*(1+L/(Lwht*Lwht))/(1+L)' -o $1
1 Like

Thanks very much Greg, much appreciated! I’ll experiment with the script you shared. And the method described in the paper you shared seems really interesting.

Hi Belal and Greg,

Sorry, I’m very late to the discussion, but just in case: Jan (Wienold) and I were able to use other TMOs, including Reinhard02, in by using PFSTools. You can then use the commands pfsin [inputfilename] | pfstmo_reinhard02 | pfsout [outputfilename] to use the Reinhard02 operator (along with many others).

Take care,
Kynthia

1 Like

Thanks Kynthia, this looks neat!