diff --git a/src/gradients.rs b/src/gradients.rs index 8a99ef2a..a8e93984 100644 --- a/src/gradients.rs +++ b/src/gradients.rs @@ -330,6 +330,8 @@ where #[cfg(test)] mod tests { use crate::filter::filter_clamped; + #[cfg(feature = "rayon")] + use crate::filter::filter_clamped_parallel; use super::*; use image::{ImageBuffer, Luma}; @@ -411,6 +413,23 @@ mod tests { assert_pixels_eq!(filtered, expected); } + #[test] + #[cfg(feature = "rayon")] + fn test_horizontal_sobel_gradient_image_parallel() { + let image = gray_image!( + 3, 2, 1; + 6, 5, 4; + 9, 8, 7); + + let expected = gray_image!(type: i16, + -4, -8, -4; + -4, -8, -4; + -4, -8, -4); + + let filtered = filter_clamped_parallel(&image, kernel::SOBEL_HORIZONTAL_3X3); + assert_pixels_eq!(filtered, expected); + } + #[test] fn test_vertical_sobel_gradient_image() { let image = gray_image!( @@ -427,6 +446,23 @@ mod tests { assert_pixels_eq!(filtered, expected); } + #[test] + #[cfg(feature = "rayon")] + fn test_vertical_sobel_gradient_image_parallel() { + let image = gray_image!( + 3, 6, 9; + 2, 5, 8; + 1, 4, 7); + + let expected = gray_image!(type: i16, + -4, -4, -4; + -8, -8, -8; + -4, -4, -4); + + let filtered = filter_clamped_parallel(&image, kernel::SOBEL_VERTICAL_3X3); + assert_pixels_eq!(filtered, expected); + } + #[test] fn test_horizontal_scharr_gradient_image() { let image = gray_image!( @@ -443,6 +479,23 @@ mod tests { assert_pixels_eq!(filtered, expected); } + #[test] + #[cfg(feature = "rayon")] + fn test_horizontal_scharr_gradient_image_parallel() { + let image = gray_image!( + 3, 2, 1; + 6, 5, 4; + 9, 8, 7); + + let expected = gray_image!(type: i16, + -16, -32, -16; + -16, -32, -16; + -16, -32, -16); + + let filtered = filter_clamped_parallel(&image, kernel::SCHARR_HORIZONTAL_3X3); + assert_pixels_eq!(filtered, expected); + } + #[test] fn test_vertical_scharr_gradient_image() { let image = gray_image!( @@ -459,6 +512,23 @@ mod tests { assert_pixels_eq!(filtered, expected); } + #[test] + #[cfg(feature = "rayon")] + fn test_vertical_scharr_gradient_image_parallel() { + let image = gray_image!( + 3, 6, 9; + 2, 5, 8; + 1, 4, 7); + + let expected = gray_image!(type: i16, + -16, -16, -16; + -32, -32, -32; + -16, -16, -16); + + let filtered = filter_clamped_parallel(&image, kernel::SCHARR_VERTICAL_3X3); + assert_pixels_eq!(filtered, expected); + } + #[test] fn test_horizontal_prewitt_gradient_image() { let image = gray_image!( @@ -476,6 +546,23 @@ mod tests { } #[test] + fn test_horizontal_prewitt_gradient_image_parallel() { + let image = gray_image!( + 3, 2, 1; + 6, 5, 4; + 9, 8, 7); + + let expected = gray_image!(type: i16, + -3, -6, -3; + -3, -6, -3; + -3, -6, -3); + + let filtered = filter_clamped_parallel(&image, kernel::PREWITT_HORIZONTAL_3X3); + assert_pixels_eq!(filtered, expected); + } + + #[test] + #[cfg(feature = "rayon")] fn test_vertical_prewitt_gradient_image() { let image = gray_image!( 3, 6, 9; @@ -491,6 +578,23 @@ mod tests { assert_pixels_eq!(filtered, expected); } + #[test] + #[cfg(feature = "rayon")] + fn test_vertical_prewitt_gradient_image_parallel() { + let image = gray_image!( + 3, 6, 9; + 2, 5, 8; + 1, 4, 7); + + let expected = gray_image!(type: i16, + -3, -3, -3; + -6, -6, -6; + -3, -3, -3); + + let filtered = filter_clamped_parallel(&image, kernel::PREWITT_VERTICAL_3X3); + assert_pixels_eq!(filtered, expected); + } + #[test] fn test_horizontal_roberts_gradient_image() { let image = gray_image!( @@ -506,6 +610,24 @@ mod tests { let filtered = filter_clamped(&image, kernel::ROBERTS_HORIZONTAL_2X2); assert_pixels_eq!(filtered, expected); } + + #[test] + #[cfg(feature = "rayon")] + fn test_horizontal_roberts_gradient_image_parallel() { + let image = gray_image!( + 3, 6, 9; + 2, 5, 8; + 1, 4, 7); + + let expected = gray_image!(type: i16, + 0, -3, -3; + 1, -2, -2; + 1, -2, -2); + + let filtered = filter_clamped_parallel(&image, kernel::ROBERTS_HORIZONTAL_2X2); + assert_pixels_eq!(filtered, expected); + } + #[test] fn test_vertical_roberts_gradient_image() { let image = gray_image!( @@ -521,6 +643,23 @@ mod tests { let filtered = filter_clamped(&image, kernel::ROBERTS_VERTICAL_2X2); assert_pixels_eq!(filtered, expected); } + + #[test] + #[cfg(feature = "rayon")] + fn test_vertical_roberts_gradient_image_parallel() { + let image = gray_image!( + 3, 6, 9; + 2, 5, 8; + 1, 4, 7); + + let expected = gray_image!(type: i16, + 0, 3, 3; + 1, 4, 4; + 1, 4, 4); + + let filtered = filter_clamped_parallel(&image, kernel::ROBERTS_VERTICAL_2X2); + assert_pixels_eq!(filtered, expected); + } } #[cfg(not(miri))]