3 releases
Uses old Rust 2015
0.1.2 | Feb 24, 2018 |
---|---|
0.1.1 | Feb 16, 2018 |
0.1.0 | Feb 10, 2018 |
#11 in #euclidean
Used in chanvese
11KB
200 lines
This crate provides an implementation of a distance transform of binary grids using Squared Euclidean distances. It is a port of the C++ implementation of Distance Transforms of Sampled Functions by P. Felzenszwalb and D. Huttenlocher.
Examples
To use the functions inside module distance_transform::utils
you need to
compile this crate with the feature image-utils.
extern crate distance_transform;
extern crate image;
use distance_transform::*;
use distance_transform::utils;
use std::fs::File;
fn main() {
// create a 128x128 binary image
let imgwidth = 128usize;
let imgheight = 128usize;
let mut bimg = BoolGrid::new(imgwidth, imgheight);
// draw a circle
for (x, y, value) in bimg.iter_mut() {
let pos = (x as isize - 64)*(x as isize - 64)
+ (y as isize - 64)*(y as isize - 64);
*value = pos < 32*32 && pos > 31*31;
}
// do the distance transformation and
// take the square root since squared distances are calculated
let fmm = utils::sqrt_img(dt2d(&bimg));
// scale values to range [0, 255] and save as image
let fmm_img = utils::min_max_scaling(&fmm, &(0., 255.));
let ref mut fmm_out = File::create("fmm_out.png").unwrap();
utils::save_float_grid(&fmm_img, fmm_out, image::PNG).unwrap();
}
Dependencies
~0–325KB