hdrprep

How it works

The processing of the images files happens in three steps:

  1. Image registration,
  2. Image cropping,
  3. Repair of the EXIF header.

Step 1: Image registration

ALE was designed to compose several images of the same scene and exposure into one composite image, thus improving the colour fidelity, reducing aliasing and generally improving the image quality.

In hdrprep, ALE is used to register the images, i.e. shift them in x and y direction, so they produce an exact match. While it should also be possible to correct for rotation between sucessive shots, this is generally not necessary for hand-held exposures.

Because of the varying exposure that is required for generating HDR images, the individual frames may change a lot. ALE normally uses one reference image and aligns all others with respect to this reference image. In our case, however, it's better to only align neighbours (in terms of exposure), so that the reference frame is always the immediate successor. After the images are sorted by exposure, image one is registered with reference to image zero, image two is aligned to image one and so on.

ale --translation --mc 10 --exp-extend --trans-save=ale_align.trans0 \
image0.jpg image1.jpg ale_out.jpg

The result from super-positioning the two frames, ale_out.jpg, is of no interest to us and is removed immediately. The example below is the transformation file produced by ALE.

# created by ALE transformation file handler version 3
# producing transformation file syntax version 2
V 2
# Comment: Target output file is ale_out.jpg
# Comment: Original frame is image0.jpg
# Comment: Avg magnitude [r=0.644784 g=0.597020 b=0.506608]
# Comment: Supplemental frame image1.jpg
# Comment: Avg magnitude [r=0.540994 g=0.492723 b=0.410629]
# Comment: Exposure [r=1.191726 g=1.211532 b=1.233626]
E 2048.000000 1536.000000 -2.500000 -1.375000 0.000000

What we are interested in is the line beginning with 'E'. E stands for Euklidian and describes the applied transformation. The first two values indicate the image dimension, the next two the offset in x and y necessary to register the two images, and the last value would mark the rotation. ALE is not meant to produce multiple output files. All images would normally be merged into one, but without response curve calibration as is necessary for HDR generation. For this reason, we can only use it to compute the offsets. Please note from the example output hat ALE operates with sub-pixel accuracy.

Step 2: Image cropping

With the offsets generated by ALE, the cropping is done by ImageMagick's convert. Since the reference frame is the first image of the sequence, image0, the x, y shift for imagen is the sum of the x, y offsets of images[1...n], for example:

Image 012 345 6
Offsetrelative x-2.500-0.2500.250 -0.500-1.500-0.625
Offsetabsolute x-2-3-2 -3-4-5

Step 3: Repair of EXIF header

This step is optional and depends on the HDR software used. Although virtually all modern digital cameras store information about camera and image settings in the EXIF header of the photograph, the interpretation of the EXIF standard often leaves a lot to be desired. In particular, the ISO film sensitivity if stored in proprietary extensions within the EXIF information by many models.

Since HDR software needs to determine the exposure setting for each frame, it is essential that aperture, shutter speed and film sensitivity can be retrieved.

The excellent Perl module Image::ExifTool is capable of reading and modifying EXIF headers, even the ones not conforming to the specifications. This allows us to fix corrupted headers in JPEG images. Below are a few lines from the EXIF information of a digital photograph.

File Type                       : JPEG
Make                            : NIKON
Camera Model Name               : E995
Exposure Time                   : 1/125
F Number                        : 2.6
Exposure Program                : Manual
ISO                             : 100
Date/Time Original              : 2005:12:04 23:14:08
Flash                           : No Flash
Focal Length                    : 8.2mm
Quality                         : Fine
White Balance                   : Incandescent