diff --git a/src/filter/mod.rs b/src/filter/mod.rs index 16576ce1..1d99608f 100644 --- a/src/filter/mod.rs +++ b/src/filter/mod.rs @@ -280,6 +280,7 @@ impl<'a, K: Num + Copy + 'a> Kernel<'a, K> { /// Returns 2d correlation of an image. Intermediate calculations are performed /// at type K, and the results converted to pixel Q via f. Pads by continuity. + /// This version uses rayon to parallelize the computation. #[cfg(feature = "rayon")] pub fn filter_parallel(&self, image: &Image

, f: F) -> Image where @@ -417,6 +418,7 @@ where /// Returns 2d correlation of an image with a 3x3 row-major kernel. Intermediate calculations are /// performed at type K, and the results clamped to subpixel type S. Pads by continuity. +/// This version uses rayon to parallelize the computation. #[must_use = "the function does not modify the original image"] #[cfg(feature = "rayon")] pub fn filter3x3_parallel(image: &Image

, kernel: &[K]) -> Image> diff --git a/src/gradients.rs b/src/gradients.rs index e698f935..a01f4aba 100644 --- a/src/gradients.rs +++ b/src/gradients.rs @@ -69,7 +69,7 @@ pub fn horizontal_sobel(image: &GrayImage) -> Image> { } /// Convolves an image with the [`HORIZONTAL_SOBEL`](static.HORIZONTAL_SOBEL.html) -/// kernel to detect horizontal gradients. +/// kernel to detect horizontal gradients. This version uses rayon to parallelize the computation. #[cfg(feature = "rayon")] pub fn horizontal_sobel_parallel(image: &GrayImage) -> Image> { filter3x3_parallel(image, &HORIZONTAL_SOBEL) @@ -82,7 +82,7 @@ pub fn vertical_sobel(image: &GrayImage) -> Image> { } /// Convolves an image with the [`VERTICAL_SOBEL`](static.VERTICAL_SOBEL.html) -/// kernel to detect vertical gradients. +/// kernel to detect vertical gradients. This version uses rayon to parallelize the computation. #[cfg(feature = "rayon")] pub fn vertical_sobel_parallel(image: &GrayImage) -> Image> { filter3x3_parallel(image, &VERTICAL_SOBEL) @@ -95,7 +95,7 @@ pub fn horizontal_scharr(image: &GrayImage) -> Image> { } /// Convolves an image with the [`HORIZONTAL_SCHARR`](static.HORIZONTAL_SCHARR.html) -/// kernel to detect horizontal gradients. +/// kernel to detect horizontal gradients. This version uses rayon to parallelize the computation. #[cfg(feature = "rayon")] pub fn horizontal_scharr_parallel(image: &GrayImage) -> Image> { filter3x3_parallel(image, &HORIZONTAL_SCHARR) @@ -108,7 +108,7 @@ pub fn vertical_scharr(image: &GrayImage) -> Image> { } /// Convolves an image with the [`VERTICAL_SCHARR`](static.VERTICAL_SCHARR.html) -/// kernel to detect vertical gradients. +/// kernel to detect vertical gradients. This version uses rayon to parallelize the computation. #[cfg(feature = "rayon")] pub fn vertical_scharr_parallel(image: &GrayImage) -> Image> { filter3x3_parallel(image, &VERTICAL_SCHARR) @@ -121,7 +121,7 @@ pub fn horizontal_prewitt(image: &GrayImage) -> Image> { } /// Convolves an image with the [`HORIZONTAL_PREWITT`](static.HORIZONTAL_PREWITT.html) -/// kernel to detect horizontal gradients. +/// kernel to detect horizontal gradients. This version uses rayon to parallelize the computation. #[cfg(feature = "rayon")] pub fn horizontal_prewitt_parallel(image: &GrayImage) -> Image> { filter3x3_parallel(image, &HORIZONTAL_PREWITT) @@ -134,7 +134,7 @@ pub fn vertical_prewitt(image: &GrayImage) -> Image> { } /// Convolves an image with the [`VERTICAL_PREWITT`](static.VERTICAL_PREWITT.html) -/// kernel to detect vertical gradients. +/// kernel to detect vertical gradients. This version uses rayon to parallelize the computation. #[cfg(feature = "rayon")] pub fn vertical_prewitt_parallel(image: &GrayImage) -> Image> { filter3x3_parallel(image, &VERTICAL_PREWITT) @@ -146,6 +146,7 @@ pub fn sobel_gradients(image: &GrayImage) -> Image> { } /// Returns the magnitudes of gradients in an image using Sobel filters. +/// This version uses rayon to parallelize the computation. #[cfg(feature = "rayon")] pub fn sobel_gradients_parallel(image: &GrayImage) -> Image> { gradients_parallel(image, &HORIZONTAL_SOBEL, &VERTICAL_SOBEL, |p| p) @@ -228,7 +229,7 @@ where } /// Computes per-channel gradients using Sobel filters and calls `f` -/// to compute each output pixel. +/// to compute each output pixel. This version uses rayon to parallelize the computation. /// /// # Examples /// ``` @@ -309,6 +310,13 @@ pub fn prewitt_gradients(image: &GrayImage) -> Image> { gradients(image, &HORIZONTAL_PREWITT, &VERTICAL_PREWITT, |p| p) } +/// Returns the magnitudes of gradients in an image using Prewitt filters. +/// This version uses rayon to parallelize the computation. +#[cfg(feature = "rayon")] +pub fn prewitt_gradients_parallel(image: &GrayImage) -> Image> { + gradients_parallel(image, &HORIZONTAL_PREWITT, &VERTICAL_PREWITT, |p| p) +} + // TODO: Returns directions as well as magnitudes. // TODO: Support filtering without allocating a fresh image - filtering functions could // TODO: take some kind of pixel-sink. This would allow us to compute gradient magnitudes @@ -374,6 +382,7 @@ where // TODO: Support filtering without allocating a fresh image - filtering functions could // TODO: take some kind of pixel-sink. This would allow us to compute gradient magnitudes // TODO: and directions without allocating intermediates for vertical and horizontal gradients. +/// Similar to [`gradients`]. This version uses rayon to parallelize the computation. fn gradients_parallel( image: &Image

, horizontal_kernel: &[i32; 9],