A few days ago I started working on a Tool that would make creating HDR Images out of 2 over-exposed and under-exposed Images a very simple task !
I implemented it using HLSL (High Level Shader Language) as a Pixel Shader Function, why? because it’s faster that way and I want to get used to writing HLSL code :)

According to the Wikipedia Article:
“High Dynamic Range Imaging (HDRI or just HDR) is a set of Techniques that allow a greater dynamic range of luminances between the lightest and darkest areas of an image than standard imaging techniques of photographic methods”
In other words, usually when you take a photo of a scene with a lot of luminance levels (eg: sunlight entering a dark room from a small opening) the result is either you see the bright areas clearly but the dark areas appear almost black or you see the dark areas clearly but the bright areas appear almost white, in HDR Imaging you can see both areas clearly.

To create an HDR Image, you either generate it by computer rendering (like games with 3D-ish graphics) or use one of the Professional Cameras that have Auto Exposure Bracketing (AEB) or use a normal camera to shoot some over-exposed and under-exposed photos of the same scene (without moving you hands!) then merging them with an application (this post’s image illustrates this).

So since I want to take pictures of real life scenes (not computer generated), I don’t have a professional camera and I don’t have Photoshop (or other apps that make HDR Images), I decided to write my own app :)
Some of you might be thinking “Why the hell is he torturing himself by writing the app when he could just get a free one to do that for him ?!!”, well actually that’s not torture, to me it’s a lot of fun and a way to learn new stuff instead of doing my boring University Assignments :D

I wont go much into details on how I implemented this using HLSL, but basically the Pixel Shader Function is called on every pixel before being rendered onto the screen, so for each pixel I calculate 2 values (one for each image) that represent how close or far is the color of this pixel from a certain threshold (default is 0.5 which is grey) and these values control how much each of the 2 pixels (from each image) is contributing to the color of the Output pixel, and by applying this on each pixel from both input images, the output image’s exposure is as close as possible to the threshold set by the user.
(you might need to read that paragraph a few more times as well as the code in the .fx file to get it :D)

I made an HDR Photo before, it was an Amazing Sunset at the GUC (yeah the small image you see in this post’s image), take a look at it on Flickr !
It took me a lot of time to make because I had to do everything manually on Paint.NET (although it had some nice tools that made it less of a nightmare), the cool thing is that I achieved the same results with this HDR Tool but with much less effort (ignoring the coding effort :D).

So anyways, if you just want to run the application and give it a try, you need to have .NET Framework 3.0 or 3.5 (it’s part of Windows 7) and DirectX 9.0c (XNA needs it and no, DirectX 10 or 11 wont make it work), however you don’t have to install XNA because I already zipped the necessary DLLs with the application, I uploaded the zip file to SkyDrive and embedded below.
Owe and BTW, you also need to have a Graphics Card that supports Pixel Shader 2.0, but you shouldn’t worry about that if you bought your PC in the year 2005 or later.

If you want to see the code download the source code which I also uploaded to SkyDrive and embedded below and you can view it with any text editor (the effect file were the HLSL code is written is in the Contents Folder), however if you want to edit the code and compile it you’ll have to have Visual Studio 2008 or Visual C# 2008 Express and XNA Game Studio 3.1.