Superpixels for Rust

This crate contains algorithms for segmenting an image into perceptually similar regions.

Currently it only has one implementation: - SLIC (Simple Linear Iterative Clustering) translated to Rust.

Example Command-line Usage

cargo run --features="build-binary" -- \ --outline-image=assets/hawaii_outline.jpg assets/hawaii.jpg

Test image Segmented Test image

Library Usage

The superpixel executable is a reasonably compact example. This crate expects images in the format of the image crate, specially a image::DynamicImage::Rgb8.

```rust extern crate superpixel; extern crate image;

use std::vec::Vec; use std::iter::repeat; use std::time::Instant;

use image::DynamicImage;

use superpixel::{LABColor,rgbtolabimage,dosegmentationwithnumsuperpixels,saveimagewithsegment_boundaries};

...

let img : image:DynamicImage::Rgb8 = ...; // get your image from somewhere

// SLIC operates on LAB space let mut labvec : Vec = repeat(Default::default()).take((img.width() * img.height()) as usize).collect(); rgbtolabimage(&img, &mut lab_vec);

let num_patches = 9000; let compactness = 20; let iterations = 10;

// klabels has the pixel labelling to segment id let mut klabels : Vec = vec![]; // while 9000 superpixels/patches are requested, the exact number may differ so the actual number is returned let numsuperpixels = dosegmentationwithnumsuperpixels( &img, &mut labvec, img.width(), img.height(), &mut klabels, num_patches, compactness, iterations);

// debug image for showing where segment boundaries are let outlinefn = "test.png"; let outlinecolor = image::Rgb([255u8, 255u8, 255u8]); saveimagewithsegmentboundaries(&img, &klabels, &outlinefn, &outlinecolor); ```

Windows

When developing on Windows - if you have installed 64bit libraries, and 64bit MSVC rust, you need to do

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64

before running cargo build

License

MIT