HDR workflow with hugin
Still here? There are two basic ways of creating an HDR panorama:
- Stitch several panoramas of the same scene, each one at a different exposure, and merge them together into a single HDR file.
- Create a set of HDR shots of the scene and then stitch them together.
Each has advantages and disadvantages: The first technique is simpler and has the advantage that the final HDR step can be skipped and substituted with a Contrast Blending approach, but has the potential for misalignments causing ghosting problems. The second technique is presented here since it involves a greater range of tools.
Preparing the HDR images
Unless you have an expensive HDR camera, you will be merging bracketed shots to create the HDR images - Unfortunately this means that you are limited to static scenes and landscapes.
Taking bracketed shots
The number of shots required depends on the dynamic range of the scene you need to capture and the capabilities of your camera.
Many cameras have an auto-bracketing mode that takes three or five shots two stops apart with one press of the button. This may be adequate, though a typical outdoor scene might have a dynamic range of eighteen stops which would require eight shots two stops apart.
Whatever method you choose, it should be obvious that you need a good tripod to keep the camera steady.
Merging bracketed shots with pfscalibration
There are other tools for merging bracketed images, but pfscalibration is Free Software and does the job.
Calibrating the camera response curve
Generally when a digital camera creates a JPEG or TIFF file, it takes a 12bit per-channel dynamic range image captured by the CCD and compresses it using a camera response curve into a 8bit output file.
If you are working with RAW images, the camera response is generally linear and doesn't need calibrating, so you can skip this step.
A quick way to derive the response curve for later use is to take a series of five bracketed JPEG shots one stop apart. eg. 2, 1, 0.5, 0.25 & 0.125 seconds exposure. First extract the exposure times from the EXIF data:
jpeg2hdrgen *.jpg > mycamera.hdrgen
Then extract the response curve, by comparing the photos, and save it:
pfsinhdrgen mycamera.hdrgen | pfshdrcalibrate -v -s mycamera.response
By default this mycamera.response file contains a weighting table that effectively throws away the brightest and darkest pixels. So open the file in a text editor, find the weighting table at the end, and change the zeroed values (0.000000000) to a positive number (0.001000000).
Aligning the shots
Even with a tripod, unless you have a programmable camera, remote control or very steady hands; it is unlikely that your series of bracketed pictures align perfectly, so:
- Start up a new hugin project for each series and load the images. Set the field of view, lens parameters and projection type, ie. if your lens is a fisheye, set this for both the input and output projection.
- Create a few hundred control points between each pair of consecutive photos with the g key in the control point tab.
- Fine tune all points and delete any with a correlation less than 90% (ie. enter -0.9 in select by distance and delete).
- Optimise positions and delete any control points with an error greater than 0.2 pixels, reoptimise.
- Adjust the field-of view in the stitching tab to something slightly smaller than the input size so there are no transparent edges.
- Stitch to multiple TIFF format.
- Rename the output TIFF files to match the input images.
convert DSCN4804.tif DSCN4804.ppm convert DSCN4804.ppm DSCN4804.tif rm DSCN4804.ppm
Merging the bracketed images to OpenEXR HDR format
Create a hdrgen file listing each of your bracketed photos and their exposure times, you can base this on the mycamera.hdrgen file created earlier.
Then use this and your camera response file to create an EXR file:
pfsinhdrgen mypicture.hdrgen | pfshdrcalibrate -v -f mycamera.response | pfsoutexr mypicture.exr
Check the output with pfsview:
pfsinexr mypicture.exr | pfsview
Converting to floating-point TIFF format
Correcting chromatic aberration
Stitching with hugin
- Everything will appear very dark since our images represent linear sensor data.
- Information about the field of view was lost, so this will need to be re-entered manually or re-optimised with PTOptimizer.
This TIFF file is in floating-point 32bit per channel IEEE format. This is impossible to display in its entirety at once, so you possibly want to create final 8bit per channel human-readable images.
Adjusting in a GUI tool
Alternatively, use pfstools to manipulate the image: pfstools has the facility to read HDR TIFF files, unfortunately it chokes on the alpha channel created by nona and enblend - Use cinepaint to open the TIFF file, flatten and save as EXR.
This can be viewed with pfsview:
pfsinexr stitch.exr | pfsview
A quick way to create a good usable 8bit per channel image is to select logarithmic mapping, adjust the exposure slider until you see a good range of shadows and highlights, zoom 1:1 and save as PNG.
A related package to pfstools called pfstmo can do automatic tone mapping of an HDR image and compress it into a low dynamic range output. There are many options and techniques available, commands look like this:
pfsinexr stitch.exr | pfstmo_drago03 | pfsgamma -g 2.2 | pfsout stitch.png
pfsinexr stitch.exr | pfsoutrgbe stitch.hdr pfsinrgbe stitch.hdr | pfstmo_drago03 | pfsgamma -g 2.2 | pfsout stitch.png