diff --git a/akaze/Cargo.toml b/akaze/Cargo.toml index ccc65846..b55c9e9d 100644 --- a/akaze/Cargo.toml +++ b/akaze/Cargo.toml @@ -26,6 +26,7 @@ float-ord = { version = "0.3.2", default-features = false } space = "0.17.0" bitarray = "0.9.0" thiserror = { version = "1.0.40", default-features = false } +imageproc = "0.23.0" [dev-dependencies] diff --git a/akaze/src/image.rs b/akaze/src/image.rs index 63964e4c..99b8f84e 100644 --- a/akaze/src/image.rs +++ b/akaze/src/image.rs @@ -1,5 +1,6 @@ use derive_more::{Deref, DerefMut}; -use image::{DynamicImage, ImageBuffer, Luma, Pixel}; +use image::{DynamicImage, ImageBuffer, Luma}; +use imageproc::filter::separable_filter_equal; use log::*; use ndarray::{azip, s, Array2, ArrayView2, ArrayViewMut2}; use nshare::{MutNdarray2, RefNdarray2}; @@ -310,11 +311,11 @@ fn gaussian_kernel(r: f32, kernel_size: usize) -> Vec { /// # Return value /// The resulting image after the filter was applied. pub fn gaussian_blur(image: &GrayFloatImage, r: f32) -> GrayFloatImage { - // a separable Gaussian kernel - let kernel_size = (f32::ceil(r) as usize) * 2 + 1usize; + assert!(r > 0.0, "sigma must be > 0.0"); + let kernel_radius = (2.0 * r).ceil() as usize; + let kernel_size = kernel_radius * 2 + 1; let kernel = gaussian_kernel(r, kernel_size); - let img_horizontal = horizontal_filter(image, &kernel); - vertical_filter(&img_horizontal, &kernel) + GrayFloatImage(separable_filter_equal(image, &kernel)) } #[cfg(test)]