Skip to content

Commit

Permalink
Fix Gaussian blur loosing value. (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanemagnenat authored Apr 28, 2024
1 parent 965684c commit a178c50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ fn gaussian_kernel_f32(sigma: f32) -> Vec<f32> {
kernel_data[kernel_radius + i] = value;
kernel_data[kernel_radius - i] = value;
}
let sum: f32 = kernel_data.iter().sum();
kernel_data.iter_mut().for_each(|x| *x /= sum);
kernel_data
}

Expand Down
14 changes: 14 additions & 0 deletions tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,20 @@ fn test_gaussian_blur_stdev_10() {
});
}

#[test]
fn test_gaussian_on_u8_white_idempotent() {
let image = ImageBuffer::<Luma<u8>, Vec<u8>>::from_pixel(64, 64, Luma([255]));
let image2 = gaussian_blur_f32(&image, 10f32);
assert_pixels_eq_within!(image2, image, 0);
}

#[test]
fn test_gaussian_on_f32_white_idempotent() {
let image = ImageBuffer::<Luma<f32>, Vec<f32>>::from_pixel(64, 64, Luma([1.0]));
let image2 = gaussian_blur_f32(&image, 10f32);
assert_pixels_eq_within!(image2, image, 1e-6);
}

#[test]
fn test_adaptive_threshold() {
use imageproc::contrast::adaptive_threshold;
Expand Down

0 comments on commit a178c50

Please sign in to comment.