corrmatch 0.1.0

CPU-first template matching with ZNCC/SSD and coarse-to-fine pyramid search
Documentation
use crate::kernel::ScanRoi;
use crate::util::{CorrMatchError, CorrMatchResult};
use crate::ImageView;

pub(crate) fn clamp_scan_roi(
    image: ImageView<'_, u8>,
    tpl_width: usize,
    tpl_height: usize,
    roi: ScanRoi,
) -> CorrMatchResult<Option<ScanRoi>> {
    let img_width = image.width();
    let img_height = image.height();
    if img_width < tpl_width || img_height < tpl_height {
        return Err(CorrMatchError::RoiOutOfBounds {
            x: 0,
            y: 0,
            width: tpl_width,
            height: tpl_height,
            img_width,
            img_height,
        });
    }

    let max_x = img_width - tpl_width;
    let max_y = img_height - tpl_height;
    Ok(roi.clamp_inclusive(max_x, max_y))
}