use super::helpers::*;
use crate::nlmeans::*;
fn luma_params(motion_compensation: MotionCompensationMode) -> NlmParams {
NlmParams {
temporal_radius: 2,
search_radius: 2,
patch_radius: 1,
strength: 1.2,
self_weight: 1.0,
channels: ChannelMode::Luma,
prefilter: PrefilterMode::None,
motion_compensation,
hq: None,
}
}
fn denoise_uniform(w: u32, h: u32, params: NlmParams) {
let client = make_client();
let frame = make_uniform_frame(w, h, 1, 0.5);
let mut d = NlmDenoiser::<R>::new(&client, params, w, h);
for _ in 0..5 {
d.push_frame(&frame);
}
let result = d.denoise().unwrap().unwrap().to_vec();
assert_eq!(result.len(), (w * h) as usize);
for (i, &v) in result.iter().enumerate() {
assert!(
(v - 0.5).abs() < 1e-3,
"pixel {i}: expected 0.5 (uniform input passthrough), got {v}"
);
}
}
#[test]
fn denoises_when_the_frame_ring_slot_stride_is_unaligned() {
denoise_uniform(34, 34, luma_params(MotionCompensationMode::None));
}
#[test]
fn denoises_the_nlm_spatial_pilot_when_the_reference_ring_slot_stride_is_unaligned() {
let mut params = luma_params(MotionCompensationMode::None);
params.prefilter = PrefilterMode::NlmSpatial {
strength_scale: DEFAULT_PILOT_STRENGTH_SCALE,
};
denoise_uniform(34, 34, params);
}
#[test]
fn denoises_with_motion_compensation_when_the_pyramid_slot_stride_is_unaligned() {
denoise_uniform(
42,
28,
luma_params(MotionCompensationMode::Mvtools {
blksize: 8,
overlap: 4,
search_radius: 2,
pyramid_levels: 2,
estimation: MotionEstimation::Direct,
}),
);
}