Aligning photos taken at different focus distances to merge into a single extended Depth of Field image.

Panorama tools is particularly useful for this process since it allows
sub-pixel alignment and has a sophisticated lens correction model for
applying distortion - Even photos taken years apart with different cameras
can be aligned perfectly.

Most tools for HDR generation such as photomatix have some level of
automatic alignment, so this may be sufficient for most purposes. Otherwise the hdrprep perl script
automates the process described below: