Cropped TIFF

From Wiki
Revision as of 13:01, 21 November 2022 by Tobias (talk | contribs) (The Gimp -> GIMP (official naming))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A common situation when stitching images together is that most of the output image or layer is empty. This happens particularly during perspective correction or when creating High resolution partial panoramas from large numbers of photos.

This is ok except that panorama tools will labouriously process the geometry for all these empty pixels, which then consume valuable memory and disc space.

The TIFF specification allows for an image canvas to include a smaller image at an offset within the larger area using the XPOSITION, YPOSITION, TIFFTAG_PIXAR_IMAGEFULLWIDTH and TIFFTAG_PIXAR_IMAGEFULLHEIGHT TIFF tags, which is ideal for a typical panoramic image that is mostly empty space.

hugin, nona and PTmender can be told to create such cropped TIFF files by adding r:CROP as a TIFF option to the panorama format section of the p line in a stitching script. Two TIFF output formats are supported, TIFF_m and TIFF_multilayer (note that TIFF_multilayer is only supported by nona).

For example the following p line produces multiple cropped TIFF files with LZW compression:

 p f0 w1000 h500 v120 n"TIFF_m c:LZW r:CROP"

enblend can read these cropped TIFF files since version 2.4, so this technique is useful when working with enblend. Additionally the GIMP image editor can open multilayer cropped TIFF files directly, though it cannot save them. It can be convenient to edit the alpha masks in multi-layer TIFFs before passing them to enblend with the help of a script; see Multi-Layer TIFF editing with the GIMP.

Preserving TIFF offset when editing with GIMP

Using cropped intermediate images is very useful - they use less diskspace and less resources are needed to generate them. Unfortunately, GIMP does not preserve the TIFF offset - and this is very unfortunate if you want to mask out some passing object in some of the remapped images, and blend them later with enblend. There's a way to preserve TIFF offset, though. First we have to figure out what the original offset of the image we will be editing is (of course, it is suggested to create a backup copy of the image anyway). To find that out, execute:

tiffdump <remappedd.tiff> | grep Position

an example output could be:

XPosition (286) RATIONAL (5) 1<19.1667>
YPosition (287) RATIONAL (5) 1<2.54>

Here we can see that both X and Y offset is used. Important values in this output are 286 and 287, which denote TIFF data entries. Values at the end are actual offsets (19.1667 and 2.54).

Now, after editing the image in GIMP, we will want to restore these offsets like:

tiffset -s 286 19.1667 <remappedd.tiff>
tiffset -s 287 2.54 <remappedd.tiff>

Of course, if one of the offsets is 0 when dumping the data, there is no need to set it on the resulting image. Both tiffdump and tiffset are part of the libtiff package.