As in other domains, reusability is a major goal of software design in the field of image processing and analysis. Three main requirements must be met by a design method in this domain: First, reusability must not lead to performance degradation. Second, especially good support for algorithm reuse is needed since algorithms are the most important abstractions. Third, the method must lead to independent components that can be combined in many different ways, according to the requirements of the application context.
During the past several years we have been developing the generic image processing and analysis library VIGRA which achieves these goals by applying the design principles of the Standard Template Library (STL). Based on a detailed analysis of algorithm requirements, we have defined new iterator categories for 2-dimensional and cyclic data access. Iterators conforming to these requirements were implemented for many different image and graph data structures. To further decouple our algorithms from the underlying data representations, we have found promotion traits and data accessors extremely useful, because they allow us to treat scalar and multi-spectral (e.g., RGB) images uniformly.
As a result, we can easily customize our algorithms for the task at hand. This leads to dramatic reductions in source code size (up to 90%) and development time since we do not need different algorithm implementations for minor variations, as was the case in traditional libraries. Our experience with over 50 algorithms currently implemented shows that generic programming on the basis of the C++ template mechanism is well suited to achieving high flexibility without loss of performance.