Hugin pano/HDR + darktable in scene-referred

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 ?

1. How to shoot ?

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.

1. Prepare the raws

  1. Open your series of raw images in darktable.
  2. Disable all modules except demosaic, lens correction, dithering and orientation. Disable even white balance, color calibration, highlights reconstruction, exposure and especially filmic/base curve.
  3. 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.

2. Operate Hugin

  1. Import the TIFFs sequence in Hugin,
  2. Create control points in “feature matching”,
  3. Optimise geometry for “everything”, click “calculate”
  4. Optimise photometry for “high dynamic range, fixed exposure”, click “calculate”

3. Export from Hugin

  1. Go to “stitcher” tab,
  2. Select “High dynamic range” (EXR or TIFF, doesn’t really matter for color, TIFF may be smaller) as output,
  3. Select “built-in” for HDR merger and Blender options. Merging options should use “Average”.
  4. Export (Stitch !)

4. Import in darktable and process

  1. Copy-paste the white-balance values for D65 from one of your source raws to your stitched HDR/pano,
  2. In exposure module, brighten the image by quite a lot to nail average luminance.

  1. Bring back highlights with filmic (here with contrast = 2, latitude = 20%, shadows/highlights balance = + 50 %)

  1. 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):


Wow, thank you for the instructions. Just when I have a picture I need to stack. I followed your guide but I failed at optimize geometry step. Hugin kept creating a too small field of view or doing nothing at all with any geometric I chose. If I post the RAWs here, would you give it a try?

1 Like

I suppose you need to calculate the field of view/optimal size/crop before exporting: (just hit the buttons in the right order)

1 Like

There could be an error in the automatically created control points that prevents the optimizer from working properly. After Create Control Points, in the Control Points tab you can select each pair of images and see if there are any points that are obviously in the wrong place. Or can try to fix them automatically - after Create Control Points, right click in the list of photos in the Photos tab and select Control Points → Clean control points.

1 Like

This is why I like the scene referred way over the basecurve these days.

In the dark days of Lightroom having its panomerge feature you had to bake in your edits before the merge or else you’d lose access to the camera styles (I don’t remember what the exact term was, but it is where Adobe kept their version of basecurve for “Camera Neutral” or “Camera Landscape” settings) and a few other ACR gubbins. Fimic doesn’t care, linear data be linear data. TIFF, RAW, etc. Things may have changed in the time since I last used Adobe but that always annoyed me that you had to bake in your RAW conversion before the final pano product.

Edit: scene referred gives you more flexibility is the crux of what I’m getting at here, at least in how these tools have been designed so far. My guess is Adobe isn’t overly worried about interoperability with other tools as much.

The main issue I have with Hugin is its fussiness on input files. Aurélien briefly addressed that.

@lhutton I don’t know which version of ACR you last used. Same here: I haven’t played with the CC in a long time, and even though I have had it at work recently, I won’t use it if I can help it. Later versions of ACR do allow you to merge raw files before adjustments[1] but as far as I know don’t have panorama and alignment capabilities as Hugin does. Last I checked panomerge and the alignment tool are still separate and have been collecting dust and as a result performing worse than they have previously.

[1] Unfortunately, it still imposes its built-in beautifying adjustments afterward so you can’t do scene-referred editing.

@afre the last version I used was 5.x circa 2012 or thereabouts. The panorama function would send out to PS to do the merge but it would functionally export the RAWs to TIFFs with the adjustments baked in. But from what I remember you didn’t have access to do all the RAW adjustments when it came back into LR after the merge and like you mention the beautifying adjustments were baked in.

I know what you mean. The integration of LR/ACR has improved a lot since. In many ways, LR is now better than PS (at least being developed much more heavily) due to Adobe’s shifting strategy toward mobile and touch and appified software. In this sense, its software is even less relevant to people like you and I and this community.

So, although many of us know how to make panos, do HDR and use dt in a scene-referred manner, tutorials like this one are very helpful to the community. Keep it up @aurelienpierre!