Friday, December 24, 2010

A quick look at HDR

Your eyes can easily adjust to accommodate the lighting conditions of your environment.  If you are in a room with brightly lit areas and deep shadows, the pupils of your eyes will increase or decrease in size to adjust the amount of light so that you can see both extremes in fair detail.  When you photograph a scene such as this you set the aperture (and shutter speed) of the camera to insure the proper exposure for the amount of light present.  If the "dynamic range" is too wide, there may be some areas that are either too dark or too light to see any detail.   The following photographs were taken in my garage (you can click on any of the images to go to full size). Photo 3) was taken with automatic exposure settings, and you can see that there are areas in the photo that are completely overexposed (the garage windows and the light on the clay pot), and areas where the shadows are so dark that detail is lost.  The other images were taken by varying the exposure to allow more or less light to be used.


 1)  Overexposed by 3.3 stops
 2) Overexposed by 1.7 stops
 3) "Proper" exposure
 4) Underexposed by 1.7 stops
5) Underexposed by 3.4 stops







Notice that in the 1) you can see details in the back corner where there is little light, but nearly everything else is "washed out".  In 5) very little detail inside the garage is visible, but you can actually see some details outside the garage through the windows.

HDR techniques allow us to combine two or more of these images so that the overall dynamic range is compressed.  The following two images were created from the above images using HDR software:

 PhotoShop CS5.  (easy, simple, $$$$$)
Hugin.  (confusing, free)







PhotoShop allows you to do some initial adjustments during the HDR creation.  The image using only the defaults was a bit dull and a underexposed using the defaults, so I applied a few adjustments to get it to match the Hugin HDR.  If you enlarge the two HDR images you can see a few differences--for example there is a bit of ghosting in the upper left corner of the Hugin image, but in general they both have a significantly larger dynamic range than the "proper exposure" in 3).

References:
1)  Wiki article on HDR (in depth, but quite good).  http://en.wikipedia.org/wiki/High_dynamic_range_imaging
2)  Creating HDR images with PhotoShop CS5
3)  Creating HDR images with Hugin

Thursday, December 23, 2010

Creating HDR images with Hugin

While PhotoShop CS5 is the easy way to generate HDR images, Hugin is an amazingly powerful and versatile program that can be used to create HDR images as well as stunning panoramas.  The great thing about Hugin is that it is absolutely free (open source software)--the bad thing is that it is not as easy to master as PhotoShop (although some would disagree with that statement).  Go to the link How to install Hugin on your computer if you do not have Hugin installed on your system.

The following screen captures should help guide you through the somewhat complex procedure you need to follow to generate your HDR.  Remember that you can click on the image to enlarge it if you have trouble reading it.  I have tried to highlight the important tabs and controls discussed in red.

After starting Hugin, select the files that you want to merge into an HDR image (either use the Load images button or drag the files into the Hugin window.


After loading the images, click on the "Images" tag and you should see a view similar to the following:


You can examine each of the individual images by selecting them from the list.  A thumbnail and some of the efix data for the photo.  You should not check to make sure that the Settings box has "Autopano-SIFT-C" selected (and make sure you have loaded it--see "How to install Hugin on your computer".  Then click on the "Create control points" box.


You should see a pop up box that will show what the program is doing (don't worry about what it says--it is mainly useful when debugging problems).  After a few second (or longer, depending on your computer, number of images, etc.), a new pop up box will appear telling you how many control points were located:


After clicking on the "OK", switch to the Assistant tab as shown below.  Make sure the lens type is "Normal (rectilinear)" and then select "Align..."  After a few minutes a new window (Fast Panorama preview) will appear.  If it does not, click on the symbol in the Hugin toolbar with the "GL" on the image.


By using the various tools available (start with drag), your can adjust the image so that it appears as shown below:


Once the image in the preview window appears correct, go to the "Stitcher" tab in the main Hugin window.


Click on the "Calculate Field of View" tab, followed by the "Calculate Optimal Size" tab.  Next, click on the "Camera and Lens" tab.


Click on "Reset" and set Exposure "to zero (no exposure correction)".  Click on OK and return to the Stitcher window.


In the Stitcher window, make sure Recitlinear is still selected, check the "Fused and blended panorama" box in "Output", and click the "Stitch Now" button.  You will get a pop up box asking for the location and name you wish for the final HDR image.

At this point I will confess that much of what I have described above had been determined by trial and error.  It may be possible that some of this is unnecessary, and there may be other pitfalls that I have not described.  One (annoying?) feature I have noticed in Hugin is that it tends to occasionally remember what you did the last time you ran the program, so some times you may find a box selected in a way you did not expect.  Feel free to let me know if you find errors and I will try to correct them.

How to install Hugin on your computer

Hugin--"an easy to use cross-platform panoramic imaging toolchain based on Panorama Tools."
If you don't have Hugin, get it!  If you have it, make sure your version is current!  Hugin is one of a number of "open source" projects that groups of volunteers are developing.  SourceForge allows groups to share and distribute software and is a fantastic resource for users looking for free software.  The best place to keep current with Hugin is the Hugin SourceForge page at: http://hugin.sourceforge.net/.

On the Hugin SourceForge page there will be a link to download locations for stable binary releases for various platforms.  When you go to that link you will want to download the latest precompiled version for the platform you are using (windows, Mac, possibly others).  The version in use for these demos is the windows 2009.4.0.  When you click on the (in my case) windows link you should get the download panel:

 
After downloading (click on Save File button) the "Hugin_2009_0_4_win32_setup.exe" file, execute it and the executable files will be installed. One additional program, Autopano-SIFT, (used to find similarcontrol points in the images) must also be downloaded, but it is not included with the preinstalled software due to licensing issues.  Go the the Autopano-SIFT link, select "Download", then select "autopano-sift-2.3-win-1.exe" to download the file and put it in the Hugin folder that was created during the latter installation (probably in the C:\Program Files directory).

Once you have Hugin installed, I strongly suggest you spend some time going through the Tutorials that can be reached from the Hugin Home page.

Creating HDR images with PhotoShop CS5

As is the case with most things in PhotoShop, once you know how to do something it is easy--unless you don't do it every day and forget!  This is just a quick how-to for creating images with CS5 (the same instructions will work with CS4 as well although the interfaces are a bit different).

(Remember, you can click on the images below to enlarge)

The easiest (and preferable method) is to use Bridge.  I know a few people who have never learned to use Bridge--don't be one of them!  With bridge you simply select the images you want to merge into and HDR and then select Tools; PhotoShop; Merge to HDR Pro:


This technique will merge the selected images and bring up a dialog box that allows you to "fine-tune" the image:

One particularly useful tool is the "Remove ghosts" checkbox shown above.  Checking this box will eliminate "ghosts" due to leaves blowing, people moving, etc.

There may be times when you would prefer to have a finer control over the image.  In such cases you can load the individual images into PhotoShop layers and then :
    1)  Select all levels
    2)  From the menu select: "Edit; Auto-Align Layers"
    3)  Upon completion select: "Edit; Auto-Blend Layers"
    4)  Check the "Stack images" button
At this point you can see what parts of each image are used in the composite and can presumably adjust the layer masks.  Note that this is the same procedure used to stack images to increase the depth of field such as in photomicroscopy.