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.
cargo run --features="build-binary" -- \
--outline-image=assets/hawaii_outline.jpg assets/hawaii.jpg
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
let num_patches = 9000; let compactness = 20; let iterations = 10;
// klabels has the pixel labelling to segment id
let mut klabels : Vec
// debug image for showing where segment boundaries are let outlinefn = "test.png"; let outlinecolor = image::Rgb([255u8, 255u8, 255u8]); saveimagewithsegmentboundaries(&img, &klabels, &outlinefn, &outlinecolor); ```
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
MIT