graph_based_image_segmentation/
lib.rs

1//! # Efficient Graph-Based Image Segmentation
2//!
3//! This repository contains a Rust implementation of the graph-based image segmentation algorithms
4//! described in \c[1] (available [here](http://cs.brown.edu/~pff/segment/))
5//! focussing on generating over-segmentations, also referred to as superpixels.
6//!
7//! | Contours                 | Labels                 |
8//! |--------------------------|------------------------|
9//! | ![](https://github.com/sunsided/graph-based-image-segmentation/raw/842c931f9e301913a9101827ca880d1f03f27572/images/contours.jpg) | ![](https://github.com/sunsided/graph-based-image-segmentation/raw/842c931f9e301913a9101827ca880d1f03f27572/images/labels.jpg) |
10//!
11//! Please note that this is a reference implementation and not particularly fast.
12//!
13//! ```plain
14//! [1] P. F. Felzenswalb and D. P. Huttenlocher.
15//!     Efficient Graph-Based Image Segmentation.
16//!     International Journal of Computer Vision, volume 59, number 2, 2004.
17//! ```
18//!
19//! The implementation is based on [this work](https://github.com/davidstutz/graph-based-image-segmentation) by David Stutz,
20//! which in turn was used in \[2] for evaluation.
21//!
22//! ```plain
23//! [2] D. Stutz, A. Hermans, B. Leibe.
24//!     Superpixels: An Evaluation of the State-of-the-Art.
25//!     Computer Vision and Image Understanding, 2018.
26//! ```
27//!
28//! ## Example use
29//!
30//! ```no_run
31//! use opencv::imgcodecs::{imread, IMREAD_COLOR};
32//! use graph_based_image_segmentation::{Segmentation, EuclideanRGB, NodeMergingThreshold};
33//!
34//! fn main() {
35//!     let mut image = imread("data/tree.jpg", IMREAD_COLOR).unwrap();
36//!
37//!     let threshold = 10f32;
38//!     let segment_size = 10;
39//!     let mut segmenter = Segmentation::new(
40//!         EuclideanRGB::default(),
41//!         NodeMergingThreshold::new(threshold),
42//!         segment_size,
43//!     );
44//!
45//!     // NOTE: The image should be blurred before use; this is left out here for brevity.
46//!     let labels = segmenter.segment_image(&image);
47//! }
48//! ```
49mod graph;
50mod segmentation;
51
52pub use graph::ImageNodeColor;
53
54pub use segmentation::{
55    Distance, EuclideanRGB, ManhattanRGB, NodeMerging, NodeMergingThreshold, Segmentation,
56};