Chain together components for Canny edge detection

This commit is contained in:
cdo committed 2026-10-27 19:17:25 +00:00
1 parent 0c44ce6396
commit c95d05f1ac
2 files changed
+24

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
pub mod canny;
pub mod sobel;
pub use canny::canny;
pub use sobel::sobel;
+22
View File
@@ -0,0 +1,22 @@
mod double_threshold;
mod gradient_threshold;
mod hysteresis;
use double_threshold::*;
use gradient_threshold::*;
use hysteresis::*;
use crate::image::*;
use crate::kernel::Kernel;
use crate::*;
pub fn canny(img: Image<Luminance>) -> Image<Luminance> {
let blurred = kernel::gaussian::<5>(2.0).convolve(&img);
let sobel = filter::sobel(blurred);
let maxima = gradient_threshold(sobel);
let candidates = double_threshold(maxima);
let edges = hysteresis(candidates);
edges.map(|p| Luminance {
y: if p { 1.0 } else { 0.0 },
})
}