pub fn erode(image: &GrayImage, norm: Norm, k: u8) -> GrayImage
Expand description
Sets all pixels within distance k
of a background pixel to black.
A pixel is treated as belonging to the foreground if it has non-zero intensity.
ยงExamples
use image::GrayImage;
use imageproc::morphology::erode;
use imageproc::distance_transform::Norm;
let image = gray_image!(
0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 255, 255, 255, 255, 255, 255, 255, 0;
0, 255, 255, 255, 255, 255, 255, 255, 0;
0, 255, 255, 255, 255, 255, 255, 255, 0;
0, 255, 255, 255, 0, 255, 255, 255, 0;
0, 255, 255, 255, 255, 255, 255, 255, 0;
0, 255, 255, 255, 255, 255, 255, 255, 0;
0, 255, 255, 255, 255, 255, 255, 255, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0
);
// L1 norm - the outermost foreground pixels are eroded,
// as well as those horizontally and vertically adjacent
// to the centre background pixel.
let l1_eroded = gray_image!(
0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 255, 255, 255, 255, 255, 0, 0;
0, 0, 255, 255, 0, 255, 255, 0, 0;
0, 0, 255, 0, 0, 0, 255, 0, 0;
0, 0, 255, 255, 0, 255, 255, 0, 0;
0, 0, 255, 255, 255, 255, 255, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0
);
assert_pixels_eq!(erode(&image, Norm::L1, 1), l1_eroded);
// LInf norm - all pixels eroded using the L1 norm are eroded,
// as well as the pixels diagonally adjacent to the centre pixel.
let linf_eroded = gray_image!(
0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 255, 255, 255, 255, 255, 0, 0;
0, 0, 255, 0, 0, 0, 255, 0, 0;
0, 0, 255, 0, 0, 0, 255, 0, 0;
0, 0, 255, 0, 0, 0, 255, 0, 0;
0, 0, 255, 255, 255, 255, 255, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0
);
assert_pixels_eq!(erode(&image, Norm::LInf, 1), linf_eroded);