How to use Hugin to perform image alignment and stacking for HDR and/or stiched panorama and still preserve (sort-of) signal linearity for later edits ?
When shooting the pictures, ensure you lock AE (auto-exposure) and AF (auto-focus) so the whole series of images to stack have the same exposure reference and same focal distance.
If you are not bracketing for exposure (meaning if you don’t intend to use HDR blending), expose to protect highlights in the brightest region of your panorama.
- Open your series of raw images in darktable.
- Disable all modules except demosaic, lens correction, dithering and orientation. Disable even white balance, color calibration, highlights reconstruction, exposure and especially filmic/base curve.
- Export your raws in TIFF 16 bits with Rec2020 linear color space.
You could export in EXR or TIFF 32 bits but Hugin expects images encoded between 0 and 1, so display-referred (linear or non-linear), therefore integer file formats are enough. Since raw images are usually 12 or 14 bits linear, if using 16 bits, you don’t need non-linear transforms either.
You guessed it… we will force Hugin to blend the signal as raw as possible. The images will look green, that’s normal.
Alternatively, if you have an identity ICC profile you may use it at input and output (overwrite the standard matrix at input profile) so the camera RGB is completely untouched before merging.
- Import the TIFFs sequence in Hugin,
- Create control points in “feature matching”,
- Optimise geometry for “everything”, click “calculate”
- Optimise photometry for “high dynamic range, fixed exposure”, click “calculate”
- Go to “stitcher” tab,
- Select “High dynamic range” (EXR or TIFF, doesn’t really matter for color, TIFF may be smaller) as output,
- Select “built-in” for HDR merger and Blender options. Merging options should use “Average”.
- Export (Stitch !)
- Copy-paste the white-balance values for D65 from one of your source raws to your stitched HDR/pano,
- In exposure module, brighten the image by quite a lot to nail average luminance.
- Bring back highlights with filmic (here with contrast = 2, latitude = 20%, shadows/highlights balance = + 50 %)
- Finish color to taste.
#1 - Failure to nuke darktable white balance and highlights clipping before going to Hugin resulted, in this image, in magenta posterized halos on the wall behind the desk lamp. Merging non-white-balanced and without any kind of highlights reconstruction helps getting back as much highlights color as possible, from valid exposures. WB and highlights get fixed on the merged/stitched final image.
#2 - I haven’t checked Hugin source code but from what I see and what I read in the UI, its HDR blending is a simple averaging, which should let the signal linear if you input it linear. For this reason, it is important that you have at least one picture where highlights are 100% unclipped. In any case, Hugin doesn’t seem to be doing any nasty HDR tonemapping thing, which is good for us.
#3 - I haven’t tested in details if Hugin can accept unbounded EXR files in input, but it doesn’t matter to us here since we come from camera bounded 14 bits linear… Using 32 bits EXR would only use disk space for nothing.
#4 - Ever wondered what filmic shadows/highlights balance is for ? Let’s set it to -18% (it was + 50% before):
White emissive on top of white reflective makes the difference much clearer than usual.
#5 - In case you can shoot exposure bracketing on a tripod, you can ditch Hugin and directly use darktable’s HDR merging. It’s scene-referred compliant too.
#6 - Always shoot bracketed if your subject is not moving, there is no reason not to. Stacking images helps not only with dynamic range but also with noise. That’s actually how smartphones manage to get very good results with shitty sensors. It’s still possible to deal with moving subjects through stacking by using masks, but the overhead is not worth the extra quality.
Real-life pano obtained with this method (non-HDR):