You are here: Architecture and Design > Pipeline Design

## Pipeline Design

An image processing pipeline is a system in which each image “stage” performs one specific operation on an image or a piece of an image, and then passes the resulting image data on to the next stage. The MrSID SDK uses this model to provide the ability to construct workflows that read, write, and manipulate images in a variety of ways.

###### Image Stages

There are three basic types of image stages:

- Image reader: an image reader will generate (“decode”) pixel data from some external image source, such as a TIFF or MrSID file. A reader serves as the initial stage of a pipeline and passes pixel data to its successor stage(s).
- Image filter: an image filter or “transformer” will change the pixel data received from its predecessor image stage(s) in some way and pass the new data on to its successor image stage(s). Examples of filters include colorspace and datatype transformers, which change the properties of pixels; mosaickers, which combine multiple images into one image; and histogram stretchers, which dynamically scale the pixel values within some numeric range.
- Image writer: an image writer will produce (“encode”) some external image object, such as an NITF or JPEG 2000 file. A writer serves as the final stage of a pipeline, receiving data from its predecessor stage; it can be viewed as the “opposite” of an image reader.

The simplest pipeline consists trivially of just a single image reader. The reader may or may not be connected to one or more filter stages. (As we will see later, a writer may not be required for all workflows.)

###### Some Examples

In Figure 1 an image pipeline is shown consisting of a MrSID image reader connected to a filter that changes the image’s colorspace. Given a filename, the MrSID reader will pass pixel data to the filter, which will transform the (presumably RGB) pixel data to grayscale pixel data.

Figure 1: Simple pipeline with MrSID image reader and color space filter

Figure 2 shows a pipeline that reads raw image data (in BIP/BIL/BSQ form), performs some dynamic range adjustments on the data in a filter stage, and writes the image out again as a raw file. Such a pipeline might be used to massage 12-bit image data to more easily displayed 8-bit data.

Figure 2: Pipeline that reads and writes raw image data

Figure 3 shows a pipeline with two GeoTIFF image readers that are connected to a mosaicking stage, which is in turn connected to a JPEG 2000 writer. (The GeoTIFF images are presumed to be “compatible” in a geospatial sense.)

Figure 3: Pipeline with two image readers, a mosaicking filter and a JP2 writer

Finally, Figure 4 shows a watermarking pipeline: a JPEG watermark is inserted onto the base TIFF image, and the result is written to a MrSID file. Note how this pipeline diagram is structurally similar to Figure 3.

Figure 4: Watermarking pipeline

###### Implementation

Several abstract classes are used to construct the pipeline system.

- LTIImage provides the basic properties of an image, such as width and height, pixel type, etc.
- LTIImageStage extends the LTIImage class by adding functions for reading pixel data from an image.
- LTIImageReader extends the LTIImageStage class to serve as the base class for all readers.
- LTIImageFilter extends the LTIImageStage class to serve as the base class for all filters. The constructor for an LTIImageFilter takes an LTIImageStage.
- LTIImageWriter is the base class for all writers. It does not inherit from any of the above classes as it serves only as a “sink”, i.e. it does not export any image properties as an LTIImage would. The constructor for an LTIImageWriter takes an LTIImageStage.

Figure 5 shows the inheritance diagram for these classes. These classes, and classes derived from them, are described in subsequent sections.

Figure 5: Inheritance

Another class, LTIImageStageManager, is a base class for managing a set of LTIImageStage objects – it can be thought of as an array of such objects. It used for passing a set of image stages to certain types of mosaic filters to reduce their resource usage. The LTIImageStageManager is also used for “wrapping” file formats that can hold multiple images.