use crate::graph::{ImageEdge, ImageNode};
use crate::segmentation::NodeMerging;
#[derive(Debug, Clone, Copy)]
pub struct NodeMergingThreshold {
c: f32,
}
impl NodeMergingThreshold {
pub fn new(c: f32) -> Self {
Self { c }
}
}
impl NodeMerging for NodeMergingThreshold {
fn should_merge(&self, s_n: &ImageNode, s_m: &ImageNode, e: &ImageEdge) -> bool {
let threshold_n = s_n.max_w + self.c / s_n.n as f32;
let threshold_m = s_m.max_w + self.c / s_m.n as f32;
let threshold = threshold_n.min(threshold_m);
e.w < threshold
}
}