HDR

Tushar Khot
tushar@cs.wisc.edu

Taking Images

I used my personal Nikon D40 to take multiple pictures of various scenes around Capitol.
But the cloudy and windy days ensured that the trees and clouds moved between two pictures. Hence some of them actually have blurring/ghosting.

HDR

For learning the response curve for D40, I used Debevec's approach[1] to generate the Radiance map. The response curve and image that I obtained for one of the images:

Monona Terrace

As you can see over here too, the response curve for the blue curve is slightly shifted to indicate that the dark regions of the image have higher values for the blue channel.

Implementation
I used C++ in Linux to implement the HDR approach. For reading and writing image files I used Cimg library.
For performing SVD and solving the linear system, I used the Gnu Scientific Library, GSL.
For outputting the HDR file, I used files provided by Cornell Graphics.
While running these experiments, I learnt that the lambda value is very important for a good response curve. For small values of lambda, the curve would be wavy in the middle.
The equations actually use the square root of lambda. Hence even though in my script lambda is set to 150, this is actually the square root of lambda.
I also realized that instead of actually selecting the pixels, I could let the code randomly select pixels. But this also meant that it may not be perfect and hence I take 4 times the required number of pixels to compensate.
This means it takes more time but better than manually selecting pixels everytime.


How To Run
cd src/cs766
make clean # Do this if you are using a 32 bit machine.
make #Modify the Makefile if using 32-bit machine. Instruction in makefile.
sh run.sh

run.sh will create a nik12.hdr file in the current directory. This needs to be copied to a Windows machine for using HDRShop.
run.sh also has some other commented lines that you can use for generating HDR files for other image sets. Just replace the existing flags with any set of commented flags.
run.sh will also generate nik12_[red|green|blue]_m.dat that is used by matlab.

Tone Mapping

For tone mapping the output HDR image, I used Reinhard's HDRShop plugin based on their 2002 paper[3]. Some sample images that were generated:



As I was working on this alone, I implemented just one additional extension. I used Matlab to implement Reinhard's paper in 2005 for dynamic range reduction[2]. After facing problems with C++, I decided to implement it in Matlab. But since Matlab had problems reading the HDR, I outputted the red, blue and green matrices and loaded them in Matlab.
This approach basically tries to compute new intensities at each pixel using:
I = I/(I + g(Ia))
g(I) = (f*I)^m
where Ia is a combination of local and global intensities.
This approach still needs tonemapping after the intensities are normalized. It is more of a pre-processing stage before tonemapping.
The effect on the image is not much but is more pleasing to the eye.
This approach introduces some dependence between the various colour channels and also adapts the pixels to the average intensities.
Also this approach has very few parameters to be manually set.
NOTE: The default parameters are used for both approaches.

Using Dynamic Range Reduction before Tonemapping

Normal Tonemapping

Using Dynamic Range Reduction before Tonemapping

Normal Tonemapping



How To Run
run.sh would have generated the required matrices needed by the Matlab code. In Matlab:
Go to the directory where HW1 is extracted
cd src/cs766
ptonemap nik12_

Modify nik12_ to nik4_|nik6_|nik8_ if you changed the flags in run.sh.
This will generate a new HDR file with intensities between 0 and 1. Now use the HDRShop tonemap plugin to obtain the new image.
Locations
All the outputs generated using hdr12 are in the "output" directory.
All the tonemapped images for my images are in the same directory as this html page.(nik4.jpg,nik6.jpg,nik8.jpg,nik10.jpg,nik12.jpg)
All the input images are in src/cs766Im
Main code is in src/cs766 and some utility functions written by me are in src/lib
Feel free to contact me, if the code doesn't work as expected. There are many library and 64 bit dependencies that may cause problems.

My favourite Artifact: [nik12_mat.jpg]



References

[1]. Paul E. Debevec, Jitendra Malik, Recovering High Dynamic Range Radiance Maps from Photographs, SIGGRAPH 1997.
[2]. Erik Reinhard, Kate Devlin, Dynamic Range Reduction Inspired by Photoreceptor Physiology, IEEE TVCG 2005.
[3]. Erik Reinhard, Michael Stark, Peter Shirley, Jim Ferwerda, Photographics Tone Reproduction for Digital Images, SIGGRAPH 2002.