Commit 86180e37 authored by Andrey Filippov's avatar Andrey Filippov

CLAUDE: Clamp corr_offset_scale in refineMotionVectors to not exceed scan range

corr_offset_eff is now computed after corr_pairs_ref so the upper bound
(corr_pairs_ref / corr_offset) is available; lower bound kept at 1.
Clamping is flagged in the existing println when it activates.
Co-authored-by: 's avatarClaude <claude@elphel.com>
parent 520cb0d7
...@@ -2064,14 +2064,7 @@ public class CuasMotion { ...@@ -2064,14 +2064,7 @@ public class CuasMotion {
String dbg_suffix, String dbg_suffix,
int dbg_iter_index, // to generate different image names for different iteration to simplify "save as" images int dbg_iter_index, // to generate different image names for different iteration to simplify "save as" images
int debugLevel) { int debugLevel) {
// TODO: limit corr_offset_scale so corr_offset_eff will not exceed scan range (but keep >=1)
final int max_index_dbg = 5; // show images for the first iterations only final int max_index_dbg = 5; // show images for the first iterations only
// By Claude on 05/13/2026: scale corr_offset for residual measurement.
// S>1 uses larger frame separation (better SNR for small residuals); result is divided by S to normalize.
// offset_scale for mask positioning and corr_offset_mv in correlatePairs stay on original corr_offset.
// final int corr_offset_scale = (int) Math.round(recalc_mv_boost); // TODO: promote to config or derive from other params
final int corr_offset_eff = corr_offset * corr_offset_scale;
final int tileSize = GPUTileProcessor.DTT_SIZE; // 8 pixels final int tileSize = GPUTileProcessor.DTT_SIZE; // 8 pixels
final int tilesX = cuasMotion.tilesX; final int tilesX = cuasMotion.tilesX;
final int width = cuasMotion.gpu_max_width; final int width = cuasMotion.gpu_max_width;
...@@ -2085,13 +2078,17 @@ public class CuasMotion { ...@@ -2085,13 +2078,17 @@ public class CuasMotion {
// Boosted pair count, centered on frame_center // Boosted pair count, centered on frame_center
final int corr_pairs_ref = (int) Math.round(2 * half_accum_range * recalc_mv_boost); final int corr_pairs_ref = (int) Math.round(2 * half_accum_range * recalc_mv_boost);
// By Claude on 05/14/2026: clamp corr_offset_scale so corr_offset_eff <= corr_pairs_ref (keep >=1)
final int corr_offset_eff = corr_offset * Math.max(1, Math.min(corr_offset_scale, corr_pairs_ref / corr_offset));
// Hard-coded debug selectors: set >= 0 to enable per-scan/per-tile visualisation // Hard-coded debug selectors: set >= 0 to enable per-scan/per-tile visualisation
final int dbg_nseq = 97; // 40; // 41; // 157; // -(116); // 57; // 20; // -1; final int dbg_nseq = 97; // 40; // 41; // 157; // -(116); // 57; // 20; // -1;
final int dbg_tile = 54+38*80; //52+38*80; // 50+38*80; // 55+38*80; // -(17 + 33*80); // 48+32*80; // 50+38*80; // -1; final int dbg_tile = 54+38*80; //52+38*80; // 50+38*80; // 55+38*80; // -(17 + 33*80); // 48+32*80; // 50+38*80; // -1;
final int corr_offset_scale_eff = corr_offset_eff / corr_offset; // actual scale after clamping
if (debugLevel >= 0) { if (debugLevel >= 0) {
System.out.println("refineMotionVectors(): corr_offset="+corr_offset+", corr_offset_scale="+corr_offset_scale+ System.out.println("refineMotionVectors(): corr_offset="+corr_offset+", corr_offset_scale="+corr_offset_scale+
", corr_offset_eff="+corr_offset_eff+ ", corr_offset_eff="+corr_offset_eff+
(corr_offset_scale_eff != corr_offset_scale ? " (CLAMPED from "+corr_offset_scale+" to "+corr_offset_scale_eff+")" : "")+
", dbg_nseq="+dbg_nseq+", dbg_tile="+dbg_tile); ", dbg_nseq="+dbg_nseq+", dbg_tile="+dbg_tile);
} }
// Pre-compute integer-pixel raised-cosine mask kernel once (shared across all nseq) // Pre-compute integer-pixel raised-cosine mask kernel once (shared across all nseq)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment