Crate graph_based_image_segmentation

Source
Expand description

§Efficient Graph-Based Image Segmentation

This repository contains a Rust implementation of the graph-based image segmentation algorithms described in \c[1] (available here) focussing on generating over-segmentations, also referred to as superpixels.

ContoursLabels

Please note that this is a reference implementation and not particularly fast.

[1] P. F. Felzenswalb and D. P. Huttenlocher.
    Efficient Graph-Based Image Segmentation.
    International Journal of Computer Vision, volume 59, number 2, 2004.

The implementation is based on this work by David Stutz, which in turn was used in [2] for evaluation.

[2] D. Stutz, A. Hermans, B. Leibe.
    Superpixels: An Evaluation of the State-of-the-Art.
    Computer Vision and Image Understanding, 2018.

§Example use

use opencv::imgcodecs::{imread, IMREAD_COLOR};
use graph_based_image_segmentation::{Segmentation, EuclideanRGB, NodeMergingThreshold};

fn main() {
    let mut image = imread("data/tree.jpg", IMREAD_COLOR).unwrap();

    let threshold = 10f32;
    let segment_size = 10;
    let mut segmenter = Segmentation::new(
        EuclideanRGB::default(),
        NodeMergingThreshold::new(threshold),
        segment_size,
    );

    // NOTE: The image should be blurred before use; this is left out here for brevity.
    let labels = segmenter.segment_image(&image);
}

Structs§

EuclideanRGB
Euclidean RGB distance.
ImageNodeColor
Represents a pixel in a video. Each pixel is represented by its color which is needed to compute the weights between pixels.
ManhattanRGB
Manhattan (i.e. L1) distance.
NodeMergingThreshold
The original criterion described in
Segmentation
Implementation of graph based image segmentation as described in the paper by Felzenswalb and Huttenlocher.

Traits§

Distance
Trait to be implemented by a concrete distance. The distance defines how the weights between nodes in the image graph are computed. See the paper by Felzenswalb and Huttenlocher for details.
NodeMerging
The magic part of the graph segmentation, i.e. s given two nodes decide whether to add an edge between them (i.e. merge the corresponding segments). See the paper by Felzenswalb and Huttenlocher for details.