Este artículo también está disponible en Español: HDR en Linux.
It has been several years now since I decided to completely delete MS-Windows out of my computer at home. Now I use Linux exclusively; this operating system has given me a great flexibility and freedom in my tasks, but it has forced me to search for an alternate workflow to work with my photos. In this article, I will explain my current workflow when dealing with HDR's, using Linux and native software only.
Preparing the shots
Unless there is a good reason not to carry a tripod, I always use one when doing HDR. There exists software that can align the images (more on that later), but the algorithm is not perfect, and sometimes it cannot correct all the differences between shots; in those cases, halos will appear on the final result. When I cannot use a tripod, I activate the exposure bracketing option in my camera, selecting the maximum range that it can do (3 exposures at -2EV, 0EV, +2EV), and shot in a quick sequence.
Using a tripod, on the other hand, allows me to be more creative about the exposure time: for night photography, for example, I usually set the camera at "bulb" mode, put the diaphragm at f/16, and do nine shots between one second and four minutes, doubling the time between shots.
Unloading the images
Obviously, the first thing I do back home is unloading the pictures to the computer. I could use a card reader, but Compact Flash cards have flimsy connector (in fact, one of the pins in my reader broke some time ago).
I connect the camera with an USB cable, and download the pictures using gThumb. As soon as I connect the camera to the computer, it is detected and a new window appears in my desktop, where I can select the photographs and download them. This software puts each set of files in a different folder, named according to the date and time they where downloaded; this feature is very convenient to me, because I can use that folders later, as sets pending to be processed. When there are HDR shots in a set, I place each one of them in a separated sub-folder.
Converting to TIFF
Next step is converting the RAW files to TIFF format. I choose lossless 16bit TIFF files because it is the best method to preserve all the information contained in the images. I use UFRaw for this task; from the directory which contains the RAW files (CR2 extension in my case), I do the conversion with the command:
ufraw-batch --wb=camera --gamma=0.45 --linearity=0.10 --exposure=0.0 --saturation=1.0 --out-type=tiff16 --overwrite IMG_????.CR2
That command produces a TIFF file for each RAW file found in the folder; the values of "gamma" and "linearity" are specific to my camera (a Canon 400D, you should consult the program documentation to find the correct values for yours), the rest are pretty standard.
Aligning the images
In case I could not use a tripod, I must align the images generated above. The fastest method I have found is by means of another program distributed with Hugin:
align_image_stack -a AIS_ IMG_????.tif
That command will generate files called AIS_????.tif, which I rename back to IMG_????.tif; that way I do not need to adapt the next step.
Before entering the HDR realm, I use enfuse to do an exposure merge:
enfuse -o enfuse.tif IMG_????.tif
This software does not try to make a mathematical reconstruction of the scene, as the HDR technique does; instead, what enfuse does is grab the best parts of each image. And it works quite well: in most cases, the result is completely satisfactory, and I do not need to continue with the rest of the process.
Generating the HDR
When I am not satisfied with the result, or when I want to give a more surreal appearance to the picture, I step fully into HDR. First, I need an HDR file, which will contain a reconstruction of the actual light from the original scene. Two programs are required for this step, both of them included in PFSTools:
dcraw2hdrgen IMG_????.CR2 | sed -e "s/CR2/tif/" > hdrgen.txt pfsinhdrgen hdrgen.txt | pfshdrcalibrate -b 16 -x | pfsout pfs.hdr
I have an HDR file now, called pfs.hdr, which cannot be edited directly; instead, I have to bring it back to the LDR realm...
There are several 'operators' to do the conversion from HDR to LDR; after trying several of them, I selected two: Mantiuk06 y Fattal02.
pfsin pfs.hdr | pfstmo_mantiuk06 -e 1 -s 1 | pfsgamma --gamma 2.2 | pfsoutimgmagick pfstmo_mantiuk06.tif pfsin pfs.hdr | pfstmo_fattal02 -s 1 | pfsoutimgmagick pfstmo_fattal02.tif
The version produced with Mantiuk is quite usable; in fact, the results resemble those produced by enfuse. The version produced by Fattal are too strong for my tastes; however, I have found a method to use them.
Now, I merge these three versions of the image (enfuse.tif, pfstmo_mantiuk06.tif y pfstmo_fattal02.tif) using GIMP. First I place the enfuse version at the bottom; on top of that, I put the Mantiuk version, with an opacity of 50%; and then, at the uppermost layer, the Fattal version, in "overlay" mode.
If I am not satisfied with the results, I generally tweak the levels and the opacity of those layers, until I obtain a good result. I also use GIMP to clone any minor defects that the photos may have.
Then I export the resulting image, again using TIFF to preserve as much detail as possible, and I move on to the next step.
For the final retouching (color correction, sharpness adjustment, contrast and brightness increase, noise reduction, ...), I use RawTherapee; and then export the results to the final JPEG file.
These are the homepages of the software mentioned in this article:
- gThumb: Basically, this is a program to capture photos from a camera and manage them into folders. It has been integrated into Gnome, and comes within most Linux distributions.
- UFRaw: I used this one for a while, as a RAW converted, but I feel that there are better options available; now, I use it exclusively to make batch conversions. It is also available with most major Linux distributions, even thought not all of them install it as a default.
- Hugin: In my humble opinion, this is the best software available to do panoramas, perspective and lens corrections, and lots of other fancy things to images. In this article, I have used Hugin for a very basic alignment on images. This is also available for most major Linux distributions; but, in this case, I compile the sources myself, which can be obtained directly from the project's web page.
- PFSTools: The reference in HDR world; it is a set of command line tools, that comprehends all the steps involved in HDR photography. There is a GUI version, Qtpfsgui, but I do not like it.
- GIMP: Who has not heard about GIMP? Quite similar to PhotoShop, but lacking some functionality; however, amateurs like me have more that we need with GIMP.
- RawTherapee: My current Raw editor of choice. This is the only non-free-as-in-freedom software that I use, but at least it is free-as-in-beer.
There is a second part to this article at: Script to make HDRs with Linux
2009/07/27: I have updated this article, to enhance the tonemapping step, using parameters that produce a better result.
2009/07/27: Thanks to the help of an anonymous reader, the outputs from the tone-mapping step are now TIFF files; I hope this will improve the quality of the final image.
2011/01/20: I have solved a bug in the HDR creation (use "
pfshdrcalibrate" instead of "
pfsclam"), to produce much better results.