39 lines
1017 B
Rust
39 lines
1017 B
Rust
mod common;
|
|
|
|
use ccvl::kernel::Kernel;
|
|
use ccvl::*;
|
|
|
|
fn draw(
|
|
img: &mut image::Image<image::SRGBA>,
|
|
path: &Vec<(usize, usize)>,
|
|
colour: image::SRGBA,
|
|
) {
|
|
let n = path.len();
|
|
for i in 0..n {
|
|
let (x0, y0) = path[i];
|
|
let (x1, y1) = path[(i + 1) % n];
|
|
draw::line(x0, y0, x1, y1, img, colour);
|
|
}
|
|
}
|
|
|
|
fn approx(a: f32, b: f32, epsilon: f32) -> bool {
|
|
(a - b).abs() <= epsilon
|
|
}
|
|
|
|
fn main() -> std::process::ExitCode {
|
|
common::process_image(|mut img| {
|
|
let greyscale = img.map(|p| image::Luminance::from(p));
|
|
let blurred = kernel::gaussian::<5>(1.2).convolve_sat(&greyscale);
|
|
let thresholded = filter::threshold_auto(blurred);
|
|
let contours =
|
|
contour::find(&thresholded, image::Luminance { y: 0.0 });
|
|
for contour in contours {
|
|
draw(&mut img, &contour.vertices, match contour.kind {
|
|
contour::Kind::Outer => colours::GREEN,
|
|
contour::Kind::Inner => colours::BLUE,
|
|
});
|
|
}
|
|
img
|
|
})
|
|
}
|