Add contour tracing example
This commit is contained in:
1 parent
88a25f3812
commit
fd9b027eea
1 file changed
+33
@@ -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
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user