diff --git a/src/filter.rs b/src/filter.rs index 5588ff0..8d787df 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -1,3 +1,5 @@ +pub mod canny; pub mod sobel; +pub use canny::canny; pub use sobel::sobel; diff --git a/src/filter/canny.rs b/src/filter/canny.rs new file mode 100644 index 0000000..26ddc9d --- /dev/null +++ b/src/filter/canny.rs @@ -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) -> Image { + 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 }, + }) +}