16 bit panorama blending using 8 bit Gimp

16 bit tiff is often a desired output from Hugin. That way you have the flexibility to make final color correction, exposure correction, highlight/shadow compression, color space changes etc after the stitching is complete, without losing significant precision or risk banding artifacts which 8 bit editing may lead to.

Hugin can produce 16 bit output. However if you want to do manual blending for whole or parts of the image (may be useful if you need wide blends to make seams invisible, such as seams passing moving water) there is the problem that 16 bit photo editing software is hard to come by. The most popular free software photo edit application is Gimp, which has very good functions for blending but it is still limited to 8 bit editing (as of 2011). Among commercial software Adobe Photoshop is the most popular alternative for 16 bit editing, but it is expensive and overkill if you only need to do blending.

Here is a workflow to workaround Gimp's 8 bit limitation, with the help of imagemagick and libtiff tools (also free software). This workflow allows for hand-made Gimp blending through layer masks, but you cannot do retouching like clone/heal if required that must be left to a final 8 bit step.

Here RawTherapee is used as the raw developer software (free), but you could be using something else.

The workflow for blending panorama output from Hugin is a bit more complicated (compared to just blending normal images) due to cropped tiff images with canvas size larger than the image itself which neither Gimp or Imagemagick handles well, so one have to do some extra steps. For 16 bit panorama editing and blending in general it is almost necessary to have a 64 bit system with lots of RAM (8 gig or more). The tiff files easily get larger than a gig.

Take photos for your panorama

It's ok to have different exposure on different parts of the panorama, just make sure there is sufficent overlap so Hugin can figure out exposure.

Wide overlap also makes it easier to resolve difficult fitting, since there's a larger area to do blending in.

Or maybe you want stitched output too, it may be nice to use as base and do manual blends only on the difficult parts.

This workflow assumes you want LDR output, not HDR.

Cropped tiff output from Nona should be enabled (default).

Unfortunately most tiff programs don't handle cropped tiffs well, and this workflow becomes much more messy with it, but it is worth it from a memory consumption perspective (Gimp consumes a lot less memory with cropped layers).

Make multipage tiff from Hugin output, using tiffcp (included in libtiff tools).

Multipage tiff is required for Gimp to open all layers with correct offsets and canvas size.

Blend the panorama using Gimp

If not already done, in preferences increase the allowed RAM consumption to say 80% of your RAM, hopefully several gigabytes. Gimp becomes very slow to work with if RAM cache is too small.

Open the multipage tiff, pages as layers. Convert to 8 bit (will be done automatically), but keep color space.

If you by some reason only want a subset of the layers, still open all layers so that you get the correct canvas size, and then remove unwanted ones.

Blend the images in Gimp using layer masks until satisfactory panorama stitching is achieved

Save each layer as an individual tiff. Next version of Gimp (version 2.8) will probably support multilayer tiff which will make this step less cumbersome. There are also some scripts out there to save layers as tiffs in a single operation.

The layer mask should be transferred to the tiff alpha channel (default).

Make flat versions of Hugin tif output to be used for alpha channel application.

This is messy but necessary due to poor tiff canvas/offset handling in Imagemagick/Gimp.

You also need the crop size, can be found out in Gimp or Hugin project.

Make flat, cropped and repaged versions of the hugin output layers, the canvas size, offset and crop must be given because Imagemagick does not get it, example: "convert ho-0000.tif -page 12229x16187 -flatten -crop 8736x12291+1727+2665 +repage flat-0000.tif"

Apply the alpha channel from the Gimp output on the original 16 bit Hugin output, using Imagemagick

The masks will of course be 8 bit and up-converted to 16 bit, but this is no problem for image quality, since blending is dithered and the actual blended image data is 16 bit.

Note that in cases when the original tiff lacks alpha channel (will not happen in this Hugin workflow though) you need to add the "-matte" parameter to the compose command, or else the masked parts of the output will not become transparent.

Combine the masked 16 bit output to one large tiff

Note that layers must be combined in the same order as they are in Gimp. Use the same ordering throughout the workflow.

Imagemagick requires huge amounts of memory if all layers are combined at once. You may need to do it a few layers at a time. Example "convert 1.tif 2.tif 3.tif -flatten s1.tif", then "convert s1.tif 4.tif 5.tif -flatten s2.tif", etc.