Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ fn hysteresis(input: &Image<Luma<f32>>, low_thresh: f32, high_thresh: f32) -> Im
// Track neighbors until no neighbor is >= low_thresh.
while let Some((nx, ny)) = edges.pop() {
let neighbor_indices = [
(nx + 1, ny - 1),
(nx + 1, ny),
(nx + 1, ny + 1),
(nx, ny + 1),
(nx, ny - 1),
(nx - 1, ny - 1),
(nx - 1, ny),
(nx - 1, ny + 1),
Expand All @@ -142,6 +144,13 @@ fn hysteresis(input: &Image<Luma<f32>>, low_thresh: f32, high_thresh: f32) -> Im
let out_neighbor = *out.get_pixel(neighbor_idx.0, neighbor_idx.1);
if in_neighbor[0] >= low_thresh && out_neighbor[0] == 0 {
out.put_pixel(neighbor_idx.0, neighbor_idx.1, max_brightness);
if neighbor_idx.0 == 0
|| neighbor_idx.0 >= input.width() - 1
|| neighbor_idx.1 == 0
|| neighbor_idx.1 >= input.height() - 1
{
continue;
}
edges.push((neighbor_idx.0, neighbor_idx.1));
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,19 @@ mod tests {
let image2 = gaussian_blur_f32(&image, 6f32);
assert_pixels_eq_within!(image2, image, 1e-6);
}

#[test]
fn test_canny_zero_threshold_panic() {
let image = image::GrayImage::new(10, 10);
_ = crate::edges::canny(&image, 0.0, 0.0);
}

#[test]
fn test_canny_one_border_pixel_panic() {
let mut image = image::GrayImage::new(10, 10);
*image.get_pixel_mut(9, 0) = Luma([255u8]);
_ = crate::edges::canny(&image, 0.0, 100.0);
}
}

#[cfg(not(miri))]
Expand Down
Binary file modified tests/data/truth/zebra_canny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading