pub fn distance_transform(image: &GrayImage, norm: Norm) -> GrayImage
Expand description
Returns an image showing the distance of each pixel from a foreground pixel in the original image.
A pixel belongs to the foreground if it has non-zero intensity. As the image has a bit-depth of 8, distances saturate at 255.
ยงExamples
use image::GrayImage;
use imageproc::distance_transform::{distance_transform, Norm};
let image = gray_image!(
0, 0, 0, 0, 0;
0, 0, 0, 0, 0;
0, 0, 1, 0, 0;
0, 0, 0, 0, 0;
0, 0, 0, 0, 0
);
// L1 norm
let l1_distances = gray_image!(
4, 3, 2, 3, 4;
3, 2, 1, 2, 3;
2, 1, 0, 1, 2;
3, 2, 1, 2, 3;
4, 3, 2, 3, 4
);
assert_pixels_eq!(distance_transform(&image, Norm::L1), l1_distances);
// LInf norm
let linf_distances = gray_image!(
2, 2, 2, 2, 2;
2, 1, 1, 1, 2;
2, 1, 0, 1, 2;
2, 1, 1, 1, 2;
2, 2, 2, 2, 2
);
assert_pixels_eq!(distance_transform(&image, Norm::LInf), linf_distances);