use purecv::core::Matrix;
use purecv::imgproc::{threshold, ThresholdTypes};
use purecv::version;
fn main() {
println!("--- purecv Threshold Example ---\n");
println!("purecv v{}", version::get_version());
let data: Vec<u8> = vec![
10, 50, 100, 130, 150, 170, 200, 220, 30, 60, 90, 127, 128, 180, 210, 255,
];
let src = Matrix::<u8>::from_vec(4, 4, 1, data);
println!("Source matrix (4x4, 1ch):");
print_matrix_u8(&src);
let (thresh_val, binary) =
threshold(&src, 127.0, 255.0, ThresholdTypes::THRESH_BINARY).unwrap();
println!("\nBINARY (thresh={thresh_val}):");
print_matrix_u8(&binary);
let (_, binary_inv) = threshold(&src, 127.0, 255.0, ThresholdTypes::THRESH_BINARY_INV).unwrap();
println!("\nBINARY_INV:");
print_matrix_u8(&binary_inv);
let (_, trunc) = threshold(&src, 127.0, 255.0, ThresholdTypes::THRESH_TRUNC).unwrap();
println!("\nTRUNC:");
print_matrix_u8(&trunc);
let (_, tozero) = threshold(&src, 127.0, 255.0, ThresholdTypes::THRESH_TOZERO).unwrap();
println!("\nTOZERO:");
print_matrix_u8(&tozero);
let (_, tozero_inv) = threshold(&src, 127.0, 255.0, ThresholdTypes::THRESH_TOZERO_INV).unwrap();
println!("\nTOZERO_INV:");
print_matrix_u8(&tozero_inv);
println!("\nDone.");
}
fn print_matrix_u8(m: &Matrix<u8>) {
for r in 0..m.rows {
let start = r * m.cols * m.channels;
let end = start + m.cols * m.channels;
let row = &m.data[start..end];
println!(" {:?}", row);
}
}