
vigra
Open Source C++ Library for Image Analysis
Flexible, Generic Algorithms for Image Segmentation, Feature Extraction & Machine Learning in C++.
What is vigra?
VIGRA (Vision with Generic Algorithms) is a highly flexible and reusable C++ computer vision library built around generic programming principles. It emphasizes algorithmic modularity and performance by leveraging compile-time polymorphism, enabling developers to integrate powerful image processing capabilities into their applications without sacrificing speed. The library provides a rich set of generic algorithms for filtering, segmentation, feature extraction, and machine learning, all designed to work seamlessly with custom data structures via image iterators and accessors.
Designed with extensibility in mind, VIGRA allows users to plug in their own image containers and data layouts while retaining full access to its optimized algorithmic core. Its modular architecture supports a wide range of computer vision tasks—from basic filtering and morphological operations to advanced tasks like texture analysis, object detection, and supervised learning. With clean, well-documented code and a focus on correctness and efficiency, VIGRA serves as both a practical tool and a reference implementation for modern image analysis techniques in research and industry.
Getting Started with vigra
To begin using vigra, you can install it from source via the official [vigra GitHub repository](https://github.com/ukoethe/vigra). The library requires CMake and a modern C++ compiler (C++11 or newer). After cloning, run `cmake . && make && make install`. Alternatively, if you're using conda, you can install it via `conda install -c conda-forge vigra`. The library also provides Python bindings (`vigra` package) for rapid prototyping and integration into scientific Python workflows. Comprehensive documentation, including tutorials and API references, is available online and in the installed `doc/vigra/` directory.
Install vigra via CMake (C++ Build)
git clone https://github.com/ukoethe/vigra.git
cd vigra
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
make -j$(nproc)
sudo make install
Generic Image Filtering & Morphology
VIGRA provides a comprehensive suite of generic image filtering and morphological operations that work with arbitrary image types and pixel formats. Its design leverages compile-time polymorphism to ensure high performance while maintaining flexibility. You can apply Gaussian smoothing, median filtering, Sobel edge detection, and morphological operations like dilation, erosion, opening, and closing. These operations are implemented as template functions and can be applied directly to custom image containers through image iterators, enabling seamless integration into existing codebases without data copying or conversion overhead.
Apply Gaussian Smoothing to a 2D Image
#include <vigra/gaussianSmoothing.hxx>
#include <vigra/impex.hxx>
int main() {
vigra::FImage src, dest;
vigra::importImage("input.png", src);
vigra::gaussianSmoothing(src, dest, 1.5);
vigra::exportImage(dest, "output.png");
return 0;
}
Multi-dimensional Image Segmentation
VIGRA supports robust image segmentation techniques, including watershed segmentation, region merging, and graph-based methods. These algorithms operate on multi-dimensional images (2D, 3D, or higher) and handle both scalar and vector-valued data. The library provides efficient data structures for region adjacency graphs (RAGs) and supports user-defined region features for supervised or unsupervised segmentation. This makes it ideal for applications like medical image analysis, remote sensing, and industrial inspection where accurate region delineation is critical.
Watershed Segmentation on Gradient Image
#include <vigra/watersheds.hxx>
#include <vigra/gradient.hxx>
vigra::FImage img, grad;
vigra::importImage("input.png", img);
vigra::imageGradientMagnitude(img, grad);
vigra::FImage labels;
vigra::watersheds(grad, labels);
// labels now contains segmented regions
Feature Extraction & Texture Analysis
VIGRA includes powerful feature extraction routines for computing histograms, gradients, texture descriptors (e.g., Gabor filters, LBP), and statistical measures (mean, variance, skewness, kurtosis). These features are essential for classification, object recognition, and content-based image retrieval. The library supports both point-wise and region-based feature computation, and its generic design allows features to be computed directly on custom image layouts. This flexibility enables efficient processing of large-scale image datasets and integration into machine learning pipelines.
Compute Local Binary Pattern (LBP) Features
#include <vigra/lbp.hxx>
#include <vigra/linear_algebra.hxx>
vigra::FImage img;
vigra::importImage("input.png", img);
vigra::MultiArray<2, float> lbp;
vigra::lbp(img, lbp, 8, 2); // 8 neighbors, radius 2
// lbp now contains LBP histogram features per pixel
Machine Learning Integration
VIGRA integrates machine learning algorithms such as decision trees, random forests, and SVMs directly into the image analysis pipeline. It supports supervised learning for pixel classification (e.g., land cover mapping, medical diagnosis) and unsupervised clustering. Features extracted from images can be fed directly into VIGRA’s learning modules without intermediate conversion. The library also provides utilities for cross-validation, model evaluation, and prediction, making it suitable for building end-to-end computer vision systems with reproducible and scalable workflows.
Train a Random Forest Classifier for Pixel Classification
#include <vigra/random_forest.hxx>
#include <vigra/feature_vector.hxx>
// Assume 'features' is a MultiArray<2, float> of shape (N, D)
// and 'labels' is a MultiArray<1, int> of length N
vigra::RandomForest rf;
rf.train(features, labels, 100, 5); // 100 trees, depth 5
// Use rf.predict() for inference on new data
