# TIFF

From PanoTools.org Wiki

The Tagged Image File Format (TIFF) is a widely used and open image format[*] used to store and exchange digital images of all kinds. For general information see the w:TIFF[*] Wikipedia page

TIFF is a very versatile file format with many flavors. TIFF files typically have a .tif file extension. If you can't see file extensions, you may want to enable windows file extensions[*] as you will have great difficulty editing and manipulating image files otherwise.

## Compression issues

TIFF can contain almost any image data. However, there are some common forms of image data compression found inside a TIFF file:

- No compression is the most compatible form but results in the largest files.
- JPEG Simply a JPEG file stored inside a TIFF tag, lossy compression.
- LZW is a very common, lossless compression scheme resulting in smaller 8 bit files. LZW was patented in most countries until 2004 and hence was not found in many freeware distributions. This compression method is not useful for 16 bit TIFFs.
- ZIP (Deflate) is lossless too but not very common although it usually results in smaller files than LZW and was not patented.
- PackBits A not very common, lossless compression scarcely supported by image editing software. Photoshop[*] for example can read PackBits compressed TIFFs but not write them.
- G3 and G4 compression is used for 1-bit FAX documents only.

PTStitcher (and hence all the GUI front-ends[*] that use it) outputs PackBits compressed image files if the output format is TIFF. There is a bug in Photoshop[*] prior to Version 9 (CS2) that prevents to open PackBits compressed files beyond a certain size. See opening large TIFFs with Photoshop[*] for details.

## Bit depth

TIFF can contain data of varying bit depth but for photographic purpose only 8-bit or 16-bit per channel are of interest. However, there is a specification that contains 32-bit data per channel floating point format for high dynamic range images.

There can be any number of channels. Common examples are

- a single channel specifying a black-and-white image
- three channels specifying a color image in RGB[*] color space
- four channels specifying a color image in CMYK[*] color space.
- any number of additional channels (called alpha channels) specifying masks, selections, additional color channels or what ever.

All channels in an image have the same bit depth, hence a RGB[*] image with 16-bit per channel often is reffered to as a 48-bit image, with 8-bit per channel as a 24-bit image.

The Panotools main applications process 8-bit as well as 16-bit per channel images. Details see Full 16 bit workflow[*]

## Alpha channels and masks

Alpha channels are used by panotools to store masks. A mask contains information to which extent the image should be used. For this purpose the alpha channel contains a black-and-white image where the pixel value determines the transparency of the corresponding image pixel.

A white alpha channel pixel causes the corresponding image pixel to be seen to 100%, a black alpha channel pixel indicates a totally transparent image pixel. A alpha channel pixel with 50% gray indicates 50% transparency.

This is particularily useful to blend between images. PTStitcher, the main stitching application of the Panorama Tools[*], is capable of reading and writing masked TIFF image files in RGB color space. A mask in the source image is treated as image border and remapped to the output image accordingly.

- If the output type 'without feather' (TIFF_m) is used, a mask is created that reflects the remapped input image borders.
- For the 'with feather' (TIFF_mask) output the mask is calculated to give a seam between adjacent images that lies more or less in the middle of the overlap area. There is a 'feather' parameter to control the width of a grayscale gradient to allow for smooth blending between the images. See PTStitcher sample script on Jim Watters page for details: [1]

In any case there is a problem to use this alpha channels as intended in Photoshop[*], since Photoshop does not know about the intended use. It loads the alpha channel but doesn't use it to control transparency. This can be achieved manually by loading the alpha channel as selection and creating a mask with 'reveal selection'. Erik Krause provides a Photoshop action set on his page that can be used to automate this for all images in a panorama: Stitching actions[*]

## Layers

Standard TIFF doesn't support layers. If a Photoshop[*] document with layers is saved as TIFF Photoshop creates a flat TIFF image file (for compatibility) and the layer data in a separate TIFF tag. This separate TIFF tag can be compressed using RLE (run length encoding) or ZIP compression. ZIP usually results in smaller files, smaller even as if saved as PSD (where you can't choose the compression format).

Some applications (like for example nona, the PTStitcher replacement in the hugin package) can write single files that contain multiple TIFF images. If these TIFF files are loaded into Photoshop[*] only the first image will be visible. They can be split into single images with tiffsplit from the TIFF tools package or ImageMagick[*] (See Tools section).

Current versions of the Gimp[*] image editor can read these TIFF files with multiple images, though they are flattened to one image when saved - A workaround is to save these layers as separate files using the save-layers-tiff[*] plug-in.

nona and PTmender can create cropped TIFF output where the image data is just a small area within the final image dimensions. This is a useful way to save resources when assembling many images into a final panorama. Cropped TIFF input files are also supported by enblend.

## Non-image data

Since TIFF is a tagged format it can contain additional non-image data either comparable to the EXIF data in JPEG files or other. Photoshop[*] for example inserts XML formatted data that causes warning messages in some programs based on the common TIFF libraries. At least some of the EXIF tools can be used to view and/or manipulate the corresponding data in TIFF files, too.

TIFF supports embedded color profiles[*]. Unfortunately PTStitcher discards the profile information when it saves TIFF files (the nona stitcher doesn't have this bug). Hence the appropriate profile should be assigned to PTStitcher result images when loaded into a color management aware image editor.

## Tools and sources

Although the major image processors and viewers cope very well with TIFF it might be necessary from time to time to use some other tools - for batch processing, for conversion of scarcely supported TIFF flavors or simply to get enhanced information.

- TIFF tools - A free package available from libtiff.org: [2] Windows executables at the Gnu Win32 Project: [3]
- ImageMagick[*] command line image processing package.
- TIFF libraries and specification from libtiff.org: [4]
- Little CMS[*] provides a tool called tifficc for applying an ICC colour profile to a TIFF file: wikipedia: LittleCMS[*]

## BigTiff

One approach to overcome the current file size limitations of the format is a new TIFF specification called BigTiff for the free libTIFF library: http://bigtiff.org/

Retrieved from "http://wiki.panotools.org/index.php?title=TIFF&oldid=15865[*]"