graph_based_image_segmentation/segmentation/
euclidean_distance.rs1use crate::graph::ImageNodeColor;
2use crate::segmentation::Distance;
3
4#[derive(Debug, Clone, Copy)]
15pub struct EuclideanRGB {}
16
17unsafe impl Sync for EuclideanRGB {}
18unsafe impl Send for EuclideanRGB {}
19
20const NORMALIZATION_TERM: f32 = 441.6729559300637f32; impl Default for EuclideanRGB {
23 fn default() -> Self {
24 Self {}
25 }
26}
27
28impl Distance for EuclideanRGB {
29 #[inline(always)]
30 fn distance(&self, n: &ImageNodeColor, m: &ImageNodeColor) -> f32 {
31 let dr = n.r as f32 - m.r as f32;
32 let dg = n.g as f32 - m.g as f32;
33 let db = n.b as f32 - m.b as f32;
34 (dr * dr + dg * dg + db * db).sqrt() / NORMALIZATION_TERM
35 }
36}