From fd9b027eea7f2fd56e023a79985abea4b1e34c0f Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Thu, 29 Oct 2026 10:29:06 +0000 Subject: [PATCH] Add contour tracing example --- examples/contours.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/contours.rs diff --git a/examples/contours.rs b/examples/contours.rs new file mode 100644 index 0000000..abbdae5 --- /dev/null +++ b/examples/contours.rs @@ -0,0 +1,33 @@ +mod common; + +use ccvl::*; + +const OUTER: image::SRGBA = image::SRGBA { + r: 0.0, + g: 1.0, + b: 0.0, + a: 1.0, +}; +const INNER: image::SRGBA = image::SRGBA { + r: 0.0, + g: 0.0, + b: 1.0, + a: 1.0, +}; + +fn main() -> std::process::ExitCode { + common::process_image(|mut img| { + let greyscale = img.map(|p| image::Luminance::from(p)); + let thresholded = filter::threshold_auto(greyscale); + let contours = contour::find(thresholded); + for contour in contours { + for (x, y) in contour.trace { + *img.at_mut(x, y) = match contour.kind { + contour::Kind::Inner => INNER, + contour::Kind::Outer => OUTER, + }; + } + } + img + }) +}