From 3217c5ea8fbaf5520564d43fe770c4fab5038ed0 Mon Sep 17 00:00:00 2001 From: Dan Costinas Date: Wed, 22 May 2024 15:01:53 +0300 Subject: [PATCH] Add test --- src/contrast.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/contrast.rs b/src/contrast.rs index 92c1c2e8..9267e7fe 100644 --- a/src/contrast.rs +++ b/src/contrast.rs @@ -462,6 +462,23 @@ mod tests { } } + #[test] + fn test_adaptive_thesholding_with_delta() { + let mut image = GrayImage::from_pixel(3, 3, Luma([100u8])); + image.put_pixel(2, 2, Luma::black()); + + //big delta should make the theshold for the black pixel small enough to be white + let binary = adaptive_threshold_with_delta(&image, 1, 100); + let expected = GrayImage::from_pixel(3, 3, Luma::white()); + assert_pixels_eq!(binary, expected); + + //smaller delta should make the theshold the pixel to be black + let binary = adaptive_threshold_with_delta(&image, 1, 50); + let mut expected = GrayImage::from_pixel(3, 3, Luma::white()); + expected.put_pixel(2, 2, Luma::black()); + assert_pixels_eq!(binary, expected); + } + #[test] fn test_histogram_lut_source_and_target_equal() { let mut histc = [0u32; 256];