1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
//! 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][1] by //! P. Felzenszwalb and D. Huttenlocher. //! //! [1]: http://cs.brown.edu/~pff/dt/ //! //! # 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(); //! } //! ``` pub mod grid; pub use grid::*; #[cfg(feature = "image-utils")] pub mod utils; #[cfg(feature = "image-utils")] pub use utils::*; pub mod dt; pub use dt::*;