Historical:16 bit panorama blending using 8 bit Gimp

From PanoTools.org Wiki
Jump to navigation Jump to search

As Gimp with version 2.10 or higher supports 16 bit this tutorial is outdated.

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.
  • Develop to 16 bit tiff in RawTherapee, with minimal conversion settings
    • Use a wide gamut icc on output (for example prophoto), so color space selection can be left to later.
    • No sharpening, no curves, no exposure correction, no black level adjustment etc
      • If you want deconvolution sharpening is however preferably applied here on the individual images.
    • No lens distortion correction necessary, Hugin has that built in.
    • Enable Highlight reconstruction. This may alter exposure a little but Hugin can deal with this.
    • CA correction, noise reduction if necessary is ok to apply here.
    • A rough/reference white balance or color correction may be suitable to apply here.
  • Use Hugin to make the panorama.
    • Hand-made control points often superior to auto, especially in difficult conditions (stuff moving in the pictures)
      • Generally 3-4 control points per image pair is enough
    • Make sure EV in panorama preview is equal to or slightly brighter than the brightest image to avoid clipping
      • It is better to control clipping in the final post-processing step.
      • May need to use more points per image (several thousands) than standard to get good photometric optimization in the exposure tab.
    • Select "Remapped images: Exposure corrected, low dynamic range" as output. Disable any panorama output, it won't be needed.
      • 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).
    • Example command: "tiffcp ho-0001.tif ho-0002.tif ... ho-000N.tif multipage.tif"
    • 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 need to know Hugin canvas size and top/left offset, this can be seen in the Hugin project, or be calculated from the tif, use tiffinfo from libtiff tools to get information: "ImageFullWidth: 12229 (canvas x size), ImageFullLength: 16187 (canvas y size), Resolution: 150, 150 pixels/inch, Position: 11.5133, 17.7667 (x offset = resolution * 11.5133 = 150 * 11.5133 = 1727 pixels).
    • 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
    • Example: "composite -compose Dst_In ho-0000-gimp.tif flat-0000.tif masked-0000.tif"
    • 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.
  • Final processing of the stitched/blended 16 bit tiff in RawTherapee
    • Color correction, exposure correction, sharpening, shadows/highligths etc
    • This final processing step does not alter the 16 bit panorama tiff so it can be made over and over again with different settings, which is a key feature of this workflow.