graph_based_image_segmentation/segmentation/
node_merging_threshold.rs1use crate::graph::{ImageEdge, ImageNode};
2use crate::segmentation::NodeMerging;
3use std::cell::Cell;
4
5#[derive(Debug, Clone, Copy)]
11pub struct NodeMergingThreshold {
12 c: f32,
14}
15
16impl NodeMergingThreshold {
17 pub fn new(c: f32) -> Self {
21 Self { c }
22 }
23}
24
25impl NodeMerging for NodeMergingThreshold {
26 fn should_merge(&self, s_n: &Cell<ImageNode>, s_m: &Cell<ImageNode>, e: &ImageEdge) -> bool {
27 let s_n = s_n.get();
28 let s_m = s_m.get();
29 debug_assert_ne!(s_m.id, s_n.id);
30
31 let threshold_n = s_n.max_w + self.c / s_n.n as f32;
32 let threshold_m = s_m.max_w + self.c / s_m.n as f32;
33
34 let threshold = threshold_n.min(threshold_m);
36 e.w < threshold
37 }
38}