Commit 4adfcfa1 authored by Andrey Filippov's avatar Andrey Filippov

Experimenting with refineMotionVectors(), before adding corr_offset

scaling
parent db5c9d75
......@@ -991,6 +991,7 @@ public class CuasMotion {
targObj.put("vx", multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_VX]);
targObj.put("vy", multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_VY]);
targObj.put("vconf", multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_VSTR]);
targObj.put("vboost", multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_VFRAC]);
break;
case PAR_PXYAR: // By Claude on 05/08/2026
targObj.put("px", tileSize * x + tileSize/2.0 + multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_X]);
......@@ -1125,7 +1126,7 @@ public class CuasMotion {
int npar = CuasMotionLMA.RSLT_A;
int fw = 9;
final int PAR_UPXY=-4,PAR_VPXY=-3,PAR_PXYAR=-2,PAR_PXY=-1;
String [] extra_choices = {"upX/upY/range", "vX/vY/conf", "pX/pY/A/RMSE/R", "pX/pY/A"};
String [] extra_choices = {"upX/upY/range", "vX/vY/conf/vboost", "pX/pY/A/RMSE/R", "pX/pY/A"};
String [] choices = new String [num_pars+extra_choices.length];
for (int i = -extra_choices.length; i < 0; i++) {
choices[i + extra_choices.length] = String.format("%2d: %s", i, extra_choices[i+extra_choices.length]); // pvf_top_titles[0])
......@@ -1228,10 +1229,11 @@ public class CuasMotion {
System.out.print(String.format("(%8.3f, %8.3f, %8.3f)",upx,upy,urng));
break;
case PAR_VPXY:
double vx = multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_VX];
double vy = multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_VY];
double vconf = multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_VSTR];
System.out.print(String.format("(%8.4f, %8.4f, %8.5f)",vx,vy,vconf));
double vx = multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_VX];
double vy = multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_VY];
double vconf = multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_VSTR];
double vboost = multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_VBOOST];
System.out.print(String.format("(%8.4f, %8.4f, %8.5f, %4.1f)",vx,vy,vconf, vboost));
break;
case PAR_PXYAR: //RSLT_A
double px1 = tileSize * tx + tileSize/2 + multi_targets[nseq][ntile][ntarg][CuasMotionLMA.RSLT_X];
......@@ -2012,10 +2014,11 @@ public class CuasMotion {
double [] target = CuasMotionLMA.getEmpty();
// Store the raw displacement over one correlation-pair separation
// (cuas_corr_offset scenes). Convert later with getFrameVelocityScale()
target[CuasMotionLMA.RSLT_VX] = vector_field[ntile][INDX_VX] * scale_vxy;
target[CuasMotionLMA.RSLT_VY] = vector_field[ntile][INDX_VY] * scale_vxy;
target[CuasMotionLMA.RSLT_VSTR] = vector_field[ntile][INDX_STRENGTH];
target[CuasMotionLMA.RSLT_VFRAC] = vector_field[ntile][INDX_FRAC];
target[CuasMotionLMA.RSLT_VX] = vector_field[ntile][INDX_VX] * scale_vxy;
target[CuasMotionLMA.RSLT_VY] = vector_field[ntile][INDX_VY] * scale_vxy;
target[CuasMotionLMA.RSLT_VSTR] = vector_field[ntile][INDX_STRENGTH];
target[CuasMotionLMA.RSLT_VFRAC] = vector_field[ntile][INDX_FRAC];
target[CuasMotionLMA.RSLT_VBOOST] = boost_pairs; // save what boost for the number of pairs was used
targets[nscan][ntile] = target;
}
// for debugging: to see each 2d correlation
......@@ -2057,7 +2060,7 @@ public class CuasMotion {
int corr_offset, // inter-frame distance for correlation pairs
int dbg_iter_index, // to generate different image names for different iteration to simplify "save as" images
int debugLevel) {
final int max_index_dbg = 10; // show images for the first iterations only
final int max_index_dbg = 5; // show images for the first iterations only
final int tileSize = GPUTileProcessor.DTT_SIZE; // 8 pixels
final int tilesX = cuasMotion.tilesX;
final int width = cuasMotion.gpu_max_width;
......@@ -2073,8 +2076,8 @@ public class CuasMotion {
final int corr_pairs_ref = (int) Math.round(2 * half_accum_range * recalc_mv_boost);
// Hard-coded debug selectors: set >= 0 to enable per-scan/per-tile visualisation
final int dbg_nseq = 40; // 41; // 157; // -(116); // 57; // 20; // -1;
final int dbg_tile = 52+38*80; // 50+38*80; // 55+38*80; // -(17 + 33*80); // 48+32*80; // 50+38*80; // -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;
// Pre-compute integer-pixel raised-cosine mask kernel once (shared across all nseq)
final int r1i = (int) Math.ceil(recalc_mv_r1);
......@@ -2092,7 +2095,7 @@ public class CuasMotion {
}
if ((dbg_nseq >= 0 || dbg_tile >= 0) && (debugLevel >= 0) && (dbg_iter_index<= max_index_dbg)) {
ShowDoubleFloatArrays.showArrays(mask_kernel.clone(), mside, mside,
"refineMotionVectors-mask-r0_" + recalc_mv_r0 + "-r1_" + recalc_mv_r1+"-niter"+dbg_iter_index);
"refineMotionVectors-mask-boost"+recalc_mv_boost+"-r0_" + recalc_mv_r0 + "-r1_" + recalc_mv_r1+"-niter"+dbg_iter_index);
}
// Allocate staging array once; each nseq clears only the frames it needs
......@@ -2196,7 +2199,7 @@ public class CuasMotion {
? scene_titles_all[f] : "f" + f;
}
ShowDoubleFloatArrays.showArrays(stack_slices, width, height, true,
"refineMotionVectors-masked-nseq" + nseq+"-niter"+dbg_iter_index, stack_titles);
"refineMotionVectors-boost"+recalc_mv_boost+"-masked-nseq" + nseq+"-niter"+dbg_iter_index, stack_titles);
}
if ((nseq == dbg_nseq) && (debugLevel >= 0) && (dbg_iter_index<= max_index_dbg)) {
int fcount = fmax_alloc - fmin_alloc + 1;
......@@ -2209,7 +2212,7 @@ public class CuasMotion {
? scene_titles_all[f] : "f" + f;
}
ShowDoubleFloatArrays.showArrays(stack_slices, width, height, true,
"refineMotionVectors-nseq" + nseq+"-niter"+dbg_iter_index, stack_titles);
"refineMotionVectors-boost"+recalc_mv_boost+"-nseq" + nseq+"-niter"+dbg_iter_index, stack_titles);
}
TDCorrTile[] tdCorrTiles = cuasMotion.correlatePairs( // By Claude on 05/06/2026
......@@ -2238,7 +2241,7 @@ public class CuasMotion {
}
// Indices into TDCorrTile.getMismatchVector() result {vx, vy, strength, fraction} // By Claude on 05/08/2026
final int INDX_VX = 0, INDX_VY = 1;
final int INDX_VX = 0, INDX_VY = 1, INDX_STR=2;
double[][] vector_field = TDCorrTile.getMismatchVector(
corr_tiles_pd,
-rstr, // rmax < 0: no relative-strength filter (same convention as getTargetsFromCorr2d)
......@@ -2253,15 +2256,17 @@ public class CuasMotion {
if (target == null || Double.isNaN(target[CuasMotionLMA.RSLT_X])) continue;
if (vector_field[ntile] == null) continue;
if (ntile == dbg_tile && debugLevel >= 0) {
System.out.printf("refineMotionVectors(): nseq=%3d ntile=%4d before: VX=%9.4f VY=%9.4f delta: dVX=%8.4f dVY=%8.4f after: VX1=%9.4f VY1=%9.4f\n",
System.out.printf("refineMotionVectors(): nseq=%3d ntile=%4d before: VX=%9.4f VY=%9.4f delta: dVX=%8.4f dVY=%8.4f after: VX1=%9.4f VY1=%9.4f VSTR=%9.4f\n",
nseq, ntile,
target[CuasMotionLMA.RSLT_VX], target[CuasMotionLMA.RSLT_VY],
vector_field[ntile][INDX_VX], vector_field[ntile][INDX_VY],
target[CuasMotionLMA.RSLT_VX] + vector_field[ntile][INDX_VX],
target[CuasMotionLMA.RSLT_VY] + vector_field[ntile][INDX_VY]);
target[CuasMotionLMA.RSLT_VY] + vector_field[ntile][INDX_VY],
vector_field[ntile][INDX_STR]);
}
target[CuasMotionLMA.RSLT_VX] += vector_field[ntile][INDX_VX];
target[CuasMotionLMA.RSLT_VY] += vector_field[ntile][INDX_VY];
target[CuasMotionLMA.RSLT_VX] += vector_field[ntile][INDX_VX]; // disable for testing
target[CuasMotionLMA.RSLT_VY] += vector_field[ntile][INDX_VY];
target[CuasMotionLMA.RSLT_VSTR] = vector_field[ntile][INDX_STR];
}
}
// Debug: CORR2D overview — one slice per keyframe, same layout as *CORR2D.tiff
......@@ -2288,7 +2293,7 @@ public class CuasMotion {
dbg_2d_corrs,
cuasMotion.tilesX * (corr_size + 1),
cuasMotion.tilesY * (corr_size + 1),
"refineMotionVectors-CORR2D"+"-n"+dbg_iter_index,
"refineMotionVectors-CORR2D-boost"+recalc_mv_boost+"-n"+dbg_iter_index,
slice_titles_ref).show();
}
}
......@@ -5648,6 +5653,7 @@ public class CuasMotion {
final boolean keep_failed, // keep failed targets
final int when, // set if >=0 for failures
final boolean centered, // accum_data was centered, use target_sequence[][][CuasMotionLMA.RSLT_X], target_sequence[][][CuasMotionLMA.RSLT_Y] (if not NaN)
final double boost_exposure, // scale number of accumulated pairs (virtual tracking camera exposure time)
final double [][][] probed_sequence, // contains vector_fields data, single target per tile
final float [][] accum_data, // should be around 0, no low-freq
final double lmax_fraction, // 0.7; // Check if local maximum is separated from the surrounding by this fraction of the maximum value
......@@ -6146,6 +6152,8 @@ public class CuasMotion {
targets[indx] = target;
targets_list.add(indx);
}// keep_failed
// set RSLT_BOOST
target[CuasMotionLMA.RSLT_BOOST] = boost_exposure;
} // if (mv != null) {
} // for (int indx = 0; indx < max_candidate.size(); indx++) {
......@@ -7529,10 +7537,11 @@ public class CuasMotion {
}
}
if (replace) {
target[ntile][CuasMotionLMA.RSLT_VX] = target_b[ntile][CuasMotionLMA.RSLT_VX];
target[ntile][CuasMotionLMA.RSLT_VY] = target_b[ntile][CuasMotionLMA.RSLT_VY];
target[ntile][CuasMotionLMA.RSLT_VSTR] = target_b[ntile][CuasMotionLMA.RSLT_VSTR];
target[ntile][CuasMotionLMA.RSLT_VFRAC] = target_b[ntile][CuasMotionLMA.RSLT_VFRAC];
target[ntile][CuasMotionLMA.RSLT_VX] = target_b[ntile][CuasMotionLMA.RSLT_VX];
target[ntile][CuasMotionLMA.RSLT_VY] = target_b[ntile][CuasMotionLMA.RSLT_VY];
target[ntile][CuasMotionLMA.RSLT_VSTR] = target_b[ntile][CuasMotionLMA.RSLT_VSTR];
target[ntile][CuasMotionLMA.RSLT_VFRAC] = target_b[ntile][CuasMotionLMA.RSLT_VFRAC];
target[ntile][CuasMotionLMA.RSLT_VBOOST] = target_b[ntile][CuasMotionLMA.RSLT_VBOOST];
}
}
}
......@@ -7659,7 +7668,9 @@ public class CuasMotion {
int precorr_ra = clt_parameters.imp.cuas_precorr_ra; // By Claude on 05/07/2026
int accum_ra = clt_parameters.imp.cuas_accum_ra; // By Claude on 05/07/2026: LPF for shiftAndRenderAccumulate
boolean cuas_gaussian_ra = clt_parameters.imp.cuas_gaussian_ra; // By Claude on 05/07/2026
boolean accum_boosted = clt_parameters.imp.cuas_accum_boosted;// By AF on 05/12/2026
// at least one of accum_boosted, accum_base should be used, normally both
boolean accum_base = clt_parameters.imp.cuas_accum_base || !accum_boosted; // By AF on 05/12/2026
for (int i = 0; i < target_frac.length; i++) {
if (clt_parameters.imp.cuas_target_frac[i].length >= 2) {
target_frac[i][0] = clt_parameters.imp.cuas_target_frac[i][0];
......@@ -7803,18 +7814,6 @@ public class CuasMotion {
imp_filter5.show();
}
parentCLT.saveImagePlusInModelDirectory(imp_filter5); // ImagePlus imp)
/*
ImagePlus imp_target_sequence_multi = showTargetSequence(
target_sequence_multi, // final double [][][][] targets_multi,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-TARGET-SEQUENCE-MULTI-n"+niter,// String title,
good_only, // final boolean good_only,
show_empty, // final boolean show_empty, // show scenes with no (valid) targets
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_target_sequence_multi);
*/
}
if (debugLevel > -4) printStatsLine("filter5 remain",true,filter5_remain);
......@@ -7905,6 +7904,7 @@ public class CuasMotion {
keep_failed, // final boolean keep_failed, // keep failed targets
niter, // final int when, // set if >=0 for failures
false, // final boolean centered,
boost_accum_pairs, // final double boost_exposure,
targets_nonoverlap, // final double [][][] vector_fields, // centers
fpixels_accumulated, // final double [][] accum_data, // should be around 0, no low-freq
lmax_fraction, // final double cuas_lmax_fraction, // 0.7; // Check if local maximum is separated from tye surrounding by this fraction of the maximum value
......@@ -8089,8 +8089,8 @@ public class CuasMotion {
double recalc_mv_r0 = clt_parameters.imp.cuas_recalc_mv_r0;
double recalc_mv_r1 = clt_parameters.imp.cuas_recalc_mv_r1;
lma_rrms = clt_parameters.imp.cuas_lma_rrms2; // = 0.15; // Maximal relative to A rms. OK is when (RMS < cuas_lma_arms) || (RMS < cuas_lma_rrms * A)
lma_mina = clt_parameters.imp.cuas_lma_mina2; // = 1.0; // Minimal A (amplitude)
double lma_rrms2 = clt_parameters.imp.cuas_lma_rrms2; // = 0.15; // Maximal relative to A rms. OK is when (RMS < cuas_lma_arms) || (RMS < cuas_lma_rrms * A)
double lma_mina2 = clt_parameters.imp.cuas_lma_mina2; // = 1.0; // Minimal A (amplitude)
if (debugLevel > -4) {
System.out.println("Updated for the centered pass lma_rrms="+lma_rrms);
System.out.println("Updated for the centered pass lma_mina="+lma_mina);
......@@ -8179,14 +8179,6 @@ public class CuasMotion {
filter5); // boolean [][] filter5)
// Anything remains? we'll see after extension
/*
double [][][] extended_scan = extendMotionScan(
targets_nonoverlap, // final double [][][] motion_scan,
null, // filter5, // final boolean [][] filtered, // centers, should be non-overlapped
cuasMotion.tilesX, // final int tilesX)
2, // final int range, // 1 or 2
null); // remain); // final int [] remain)
*/
if (save_filtered_low && debug_more) {
// targets_nonoverlap will contain motion vectors used fro the next fpixels_accumulated
ImagePlus imp_novl = showTargetSequence(
......@@ -8196,18 +8188,8 @@ public class CuasMotion {
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_novl);
/*
ImagePlus imp_ext = showTargetSequence(
extended_scan, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-EXTENDED-CENTERED-n"+niter,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_ext);
// show good and bad accumulated here too?
*/
}
/*
// Andrey 05/05/2026 moved here (earlier) so shiftAndRenderAccumulate() will use updated motion vector
// By Claude on 05/05/2026 — re-correlate with spatial mask around known target
if (recalc_mv) {
......@@ -8226,7 +8208,7 @@ public class CuasMotion {
smooth, // boolean smooth,
corr_offset, // int corr_offset,
niter - niter0, // int dbg_iter_index,
-1); // debugLevel); // int debugLevel)
debugLevel); // -1); // debugLevel); // int debugLevel)
}
double [][][] extended_scan = extendMotionScan(
targets_nonoverlap, // final double [][][] motion_scan,
......@@ -8243,189 +8225,249 @@ public class CuasMotion {
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_ext);
}
*/
// double [][][][] targets_new_multi = null;
int num_new = 0;
{
// perform new accumulations of shifted non-conflicting tiles
float [][] fpixels_accumulated = cuasMotion.shiftAndRenderAccumulate(
clt_parameters, // CLTParameters clt_parameters,
true, // false, // final boolean center, // why is it false here?
false, // final boolean fill_zeros,
fpixels_accum, // By Claude on 05/07/2026: LPF'd with accum_ra (was fpixels_tum)
extended_scan, // final double [][][] vector_field,
frame0, // final int frame0, // for vector_field[0]
corr_inc, // final int frame_step, // keep for slow
half_accum_range, // final int half_range, // scale for slow
boost_accum_pairs,// final double boost_pairs,
smooth, // final boolean smooth,
corr_offset, // final int corr_offset, // interframe distance for correlation
true); // final boolean batch_mode) {
if (save_filtered_high) {
String title = model_prefix+"-ACCUMULATED-CENTERED-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
}
ImagePlus imp_acc = ShowDoubleFloatArrays.makeArrays(
fpixels_accumulated, // double[][] pixels,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
title, // model_prefix+"-ACCUMULATED-CENTERED-n"+niter, // String title,
slice_titles);
imp_acc.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (!batch_mode) {
imp_acc.show();
}
parentCLT.saveImagePlusInModelDirectory(imp_acc); // ImagePlus imp)
if (accum_boosted) {
// Andrey 05/05/2026 moved here (earlier) so shiftAndRenderAccumulate() will use updated motion vector
// By Claude on 05/05/2026 — re-correlate with spatial mask around known target
if (recalc_mv) {
refineMotionVectors(
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // boolean batch_mode,
cuasMotion, // CuasMotion cuasMotion,
recalc_mv_boost, // double recalc_mv_boost,
recalc_mv_r0, // double recalc_mv_r0,
recalc_mv_r1, // double recalc_mv_r1,
fpixels_refine, // By Claude on 05/07/2026: LPF'd with precorr_ra (was fpixels_tum)
targets_nonoverlap, // double [][][] targets_nonoverlap,
frame0, // int frame0,
corr_inc, // int corr_inc,
half_accum_range, // int half_accum_range,
smooth, // boolean smooth,
corr_offset, // int corr_offset,
niter - niter0, // int dbg_iter_index,
debugLevel); // -1); // debugLevel); // int debugLevel)
}
// replace center frames with the accumulated ones
if (debugLevel > -4) {
System.out.println("Starting render, iteration = "+niter);
}
// show just fpixels_accumulated
// move outside? compare to slice_titles known
// Calculate both centroid and LMA target parametes, return both
// targets_new will contain motion vectors, centroid, and LMA results combined
//save_filtered_high
float [][] accum_debug = save_filtered_high? new float [num_corr_samples][]:null; //fpixels_accumulated.length]
boolean keep_failed = false; // keep failed targets
double [][][][] targets_new_multi = getAccumulatedCoordinatesMulti(
keep_failed, // final boolean keep_failed, // keep failed targets
niter, // final int when, // set if >=0 for failures
true, // final boolean centered,
targets_nonoverlap, // final double [][][] vector_fields, // centers
fpixels_accumulated, // final double [][] accum_data, // should be around 0, no low-freq
lmax_fraction, // final double cuas_lmax_fraction, // 0.7; // Check if local maximum is separated from tye surrounding by this fraction of the maximum value
lmax_flt_neglim, // final double lmax_flt_neglim, // -0.3; // limit negative data to reduce ridge influence (make -10 to disable)
lmax_flt_hsigma, // final double lmax_flt_hsigma, // 1.0 // HPF (~UM) subtract GB with this sigma from the data tile
lmax_flt_lsigma, // final double lmax_flt_lsigma, // 1.0 // LPF - GB result of the previous subtraction
lmax_flt_scale, // final double lmax_flt_scale, // 5.0 // scale filtering result
cuasMotion.sky_mask, // final double sky_mask,
sky_threshold, // final double sky_threshold, // 0.9 // minimal value of the sky mask where target is possible
target_horizon+filter_below_horizon, // final double lma_horizon,
lmax_hack_ridge, // final double lmax_hack_ridge, // 0.45; // Hack for ridges: remove horizontal streaks, where average(abs()) for the line exceeds fraction of abs max 0.32-good, 0.55 - bad
lmax_radius, // final int cuas_lmax_radius, // 3; // look inside cuas_lmax_radius* 2 + 1 square for the local maximum isolation
lmax_radius, // final double centered_radius,
0.5, // final double centered_radius_blur,
1.0, // final double pix_tolerance, //
// lmax_zero, // final boolean cuas_lmax_zero, // true; // zero all data outside this radius from the maximum
target_radius, // final double centroid_radius,
n_recenter, // final int n_recenter, // re-center window around new maximum. 0 -no refines (single-pass)
cuasMotion.tilesX, // final int tilesX){
no_border, // final boolean no_border,
// Moving target LMA
lma_sigma, // final double lma_sigma,
wnd_pedestal, // final double wnd_pedestal,
lma_r0, // final double lma_r0,
lma_ovrsht, // final double lma_ovrsht,
// CUAS Motion LMA parameters
lma_fit_xy, // final boolean lma_fit_xy,
lma_fit_a, // final boolean lma_fit_a,
lma_fit_c, // final boolean lma_fit_c,
lma_fit_r, // final boolean lma_fit_r,
lma_fit_k, // final boolean lma_fit_k,
lambda, // final double lambda,
lambda_good, // final double lambda_good,
lambda_bad, // final double lambda_bad,
lambda_max, // final double lambda_max,
rms_diff, // final double rms_diff,
num_iter, // final int num_iter,0, // final double pre_min_a, // pre-filter minimal LMA-A (half finbal?)
lma_pre_mina*lma_mina,// final double pre_min_a, // 0.5 //scale cuas_lma_mina to filter initial candidates (if there are > one of them)
min_keep, // final int min_keep, // 2; // keep at least this number of candidates before using cuas_lma_pre_mina filter
accum_debug, // final float [][] accum_debug,
parentCLT, // final QuadCLT parentCLT, // debug only, maybe null in other cases
debugLevel); // final int debugLevel);
if (accum_debug != null) {
String title = model_prefix+"-ACCUMULATED_FILTERED-CENTERED-MULTI-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
}
ImagePlus imp_acc = ShowDoubleFloatArrays.makeArrays(
accum_debug, // double[][] pixels,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
title, // model_prefix+"-ACCUMULATED_FILTERED-CENTERED-MULTI-n"+niter, // String title,
slice_titles);
imp_acc.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (!batch_mode) {
imp_acc.show();
}
parentCLT.saveImagePlusInModelDirectory(imp_acc); // ImagePlus imp)
}
// no need to to evaluate scores now - can be done all at once when all non-centered will be replaced by centered, removed (almost) duplicates
// evaluating scores, but it is not needed
// new results are sorted by decreasing amplitude, there should be only one - test it. If not still use only the first
// continue niter for "when"
// keep only one (best) result for centered getAccumulatedCoordinatesMulti()
if (save_filtered_low && debug_more) {
String title = model_prefix+"-NEW-TARGETS-CENTERED-MULTI-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
}
ImagePlus imp_new = showTargetSequence(
targets_new_multi, // final double [][][][] targets_multi,
double [][][] extended_scan = extendMotionScan(
targets_nonoverlap, // final double [][][] motion_scan,
null, // filter5, // final boolean [][] filtered, // centers, should be non-overlapped
cuasMotion.tilesX, // final int tilesX)
2, // final int range, // 1 or 2
null); // remain); // final int [] remain)
if (save_filtered_low && debug_more) {
ImagePlus imp_ext = showTargetSequence(
extended_scan, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title, // model_prefix+"-NEW-TARGETS-CENTERED-MULTI-n"+niter,// String title,
good_only, // final boolean good_only,
show_empty, // final boolean show_empty, // show scenes with no (valid) targets
model_prefix+"-EXTENDED-CENTERED-n"+niter,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_new); // ImagePlus imp)
parentCLT.saveImagePlusInModelDirectory(imp_ext);
}
double [][][][] targets_new_multi=getNewCenteredTargets(
clt_parameters, // CLTParameters clt_parameters,
cuasMotion, // CuasMotion cuasMotion,
fpixels_accum, // float [][] fpixels_accum,
targets_nonoverlap, // double [][][] targets_nonoverlap,
extended_scan, // double [][][] extended_scan,
frame0, // int frame0,
corr_inc, // int corr_inc,
half_accum_range, // int half_accum_range,
boost_accum_pairs, // double boost_accum_pairs,
smooth, // boolean smooth,
corr_offset, // int corr_offset, // interframe distance for correlation
save_filtered_high, // boolean save_filtered_high,
model_prefix, // String model_prefix,
niter, // int niter,
input_range, // double input_range,
lmax_fraction, // double lmax_fraction,
lmax_flt_neglim, // double lmax_flt_neglim,
lmax_flt_hsigma, // double lmax_flt_hsigma,
lmax_flt_lsigma, // double lmax_flt_lsigma,
lmax_flt_scale, // double lmax_flt_scale,
sky_threshold, // double sky_threshold,
target_horizon, // double target_horizon,
filter_below_horizon, // double filter_below_horizon,
lmax_hack_ridge, // double lmax_hack_ridge,
lmax_radius, // double lmax_radius,
target_radius, // double target_radius,
n_recenter, // int n_recenter,
no_border, // boolean no_border,
// Moving target LMA
lma_sigma, // double lma_sigma,
wnd_pedestal, // double wnd_pedestal,
lma_r0, // double lma_r0,
lma_ovrsht, // double lma_ovrsht,
// CUAS Motion LMA // // CUAS Motion LMA parameters
lma_fit_xy, // boolean lma_fit_xy,
lma_fit_a, // boolean lma_fit_a,
lma_fit_c, // boolean lma_fit_c,
lma_fit_r, // boolean lma_fit_r,
lma_fit_k, // boolean lma_fit_k,
lambda, // double lambda,
lambda_good, // double lambda_good,
lambda_bad, // double lambda_bad,
lambda_max, // double lambda_max,
rms_diff, // double rms_diff,
num_iter, // int num_iter,
min_keep, // int min_keep,
save_filtered_low, // boolean save_filtered_low,
debug_more, // boolean debug_more,
good_only, // boolean good_only,
show_empty, // boolean show_empty,
num_corr_samples, // int num_corr_samples,
target_strength, // double target_strength,
target_frac, // double [][] target_frac,
lma_rms, // double lma_rms,
lma_arms, // double lma_arms,
lma_pre_mina, // double lma_pre_mina,
// use lma_mina2, lma_rrms2 !
lma_mina2, // double lma_mina,
lma_rrms2, // double lma_rrms,
lma_maxr, // double lma_maxr,
lma_minr1, // double lma_minr1,
lma_mink, // double lma_mink,
lma_maxk, // double lma_maxk,
lma_a2a, // double lma_a2a,
slow_fast_mismatch, // double slow_fast_mismatch,
fail_mismatch, // boolean fail_mismatch,
offcenter, // double offcenter,
noisemax, // double noisemax,
factor_lim, // double factor_lim,
factor_pow, // double factor_pow,
score_coeff, // double [] score_coeff,
slow_score, // double slow_score,
batch_mode, // boolean batch_mode,
debugLevel); // int debugLevel);
// evaluate scores here to reduce the number of attempts for centered targets
getEffectiveStrengthLMA(
targets_new_multi, // final double [][][] target_coords, // LMA
target_strength, // final double target_strength,
target_frac, // final double [][] target_frac, // pairs - strength, minimal fraction for that strength
lma_rms, // final double lma_rms, // = 1.5; // Maximal RMS (should always match, regardless if A)
lma_arms, // final double lma_arms, // = 0.06; // Maximal absolute RMS (should match one of cuas_lma_arms OR cuas_lma_rrms (0.484)
lma_rrms, // final double lma_rrms, // = 0.15; // Maximal relative to A rms. OK is when (RMS < cuas_lma_arms) || (RMS < cuas_lma_rrms * A)
lma_mina, // final double lma_mina, // = 1.0; // Minimal A (amplitude)
lma_maxr, // final double lma_maxr, // = 5.0; // Minimal K (overshoot) = 3.0
lma_minr1, // final double lma_minr1,// = 1.0; // Minimal R1 (radius of positive peak)
lma_mink, // final double lma_mink, // = 0.0; // Minimal K (overshoot) = 1.0
lma_maxk, // final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0// final double lma_a2a,
lma_a2a, // final double lma_a2a,
0, // max_mismatch, // final double max_mismatch, apply only during final, when mismatch scores are calculated
slow_fast_mismatch,// final double slow_fast_mismatch, // // 1.5; allow larger mismatch between slow and fast
fail_mismatch, // final boolean fail_mismatch,
offcenter, // final double offcenter,
cuasMotion.getNoiseMap(), // final double [] noise_map,
noisemax, // final double noise_max,
target_horizon, // final double lma_horizon, // horizon as maximal pixel Y
cuasMotion.tilesX); // final int tilesX,
int [] remain_es_centered = getScore(
targets_new_multi, // final double [][][] target_sequence, // modifies certain fields (scores)
factor_lim, // final double importance_limit,
factor_pow, // final double importance_power, // Raise each factor to this power before combining
score_coeff, // final double [] importance, // for now (each - squared?): [0] - Amplitude (A/A0), 1 - RMS (RMS0/RMS), 2 - RRMS((RMS/A0) / (RMS/A)
slow_score, // final double slow_score, // multiply total score for targets detected in slow target mode
cuasMotion.tilesX); // final int tilesX,
if (save_filtered_low) {
String title = model_prefix+"-NEW-TARGETS_CENTERED_SCORES_MULTI-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
}
//int
num_new += addNewResults(
target_sequence_multi, // final double [][][] target_sequence, // will only process non-nulls here
targets_new_multi, // final double [][][] new_sequence,
// add just one best here?
1, // final int num_best, // if >0, limit number of best results to add
niter, // final int when_iter,
debugLevel); // final int debugLevel);
ImagePlus imp_new_scores = showTargetSequence(
targets_new_multi, // double [][][] vector_fields_sequence,
if (debugLevel > -4) {
System.out.println("Added "+num_new+" new tiles as good/bad at boosted iteration "+niter+".");
}
}
if (accum_base) {
// Andrey 05/05/2026 moved here (earlier) so shiftAndRenderAccumulate() will use updated motion vector
// By Claude on 05/05/2026 — re-correlate with spatial mask around known target
if (recalc_mv) {
refineMotionVectors(
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // boolean batch_mode,
cuasMotion, // CuasMotion cuasMotion,
1.0, // recalc_mv_boost, // double recalc_mv_boost,
recalc_mv_r0, // double recalc_mv_r0,
recalc_mv_r1, // double recalc_mv_r1,
fpixels_refine, // By Claude on 05/07/2026: LPF'd with precorr_ra (was fpixels_tum)
targets_nonoverlap, // double [][][] targets_nonoverlap,
frame0, // int frame0,
corr_inc, // int corr_inc,
half_accum_range, // int half_accum_range,
smooth, // boolean smooth,
corr_offset, // int corr_offset,
niter - niter0, // int dbg_iter_index,
debugLevel); // -1); // debugLevel); // int debugLevel)
}
double [][][] extended_scan = extendMotionScan(
targets_nonoverlap, // final double [][][] motion_scan,
null, // filter5, // final boolean [][] filtered, // centers, should be non-overlapped
cuasMotion.tilesX, // final int tilesX)
2, // final int range, // 1 or 2
null); // remain); // final int [] remain)
if (save_filtered_low && debug_more) {
ImagePlus imp_ext = showTargetSequence(
extended_scan, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title, // model_prefix+"-NEW-TARGETS_CENTERED_SCORES_MULTI-n"+niter,// String title,
good_only, // final boolean good_only,
show_empty, // final boolean show_empty, // show scenes with no (valid) targets
model_prefix+"-EXTENDED-CENTERED-n"+niter,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_new_scores); // ImagePlus imp)
parentCLT.saveImagePlusInModelDirectory(imp_ext);
}
double [][][][] targets_new_multi=getNewCenteredTargets(
clt_parameters, // CLTParameters clt_parameters,
cuasMotion, // CuasMotion cuasMotion,
fpixels_accum, // float [][] fpixels_accum,
targets_nonoverlap, // double [][][] targets_nonoverlap,
extended_scan, // double [][][] extended_scan,
frame0, // int frame0,
corr_inc, // int corr_inc,
half_accum_range, // int half_accum_range,
1.0, // boost_accum_pairs, // double boost_accum_pairs,
smooth, // boolean smooth,
corr_offset, // int corr_offset, // interframe distance for correlation
save_filtered_high, // boolean save_filtered_high,
model_prefix, // String model_prefix,
niter, // int niter,
input_range, // double input_range,
lmax_fraction, // double lmax_fraction,
lmax_flt_neglim, // double lmax_flt_neglim,
lmax_flt_hsigma, // double lmax_flt_hsigma,
lmax_flt_lsigma, // double lmax_flt_lsigma,
lmax_flt_scale, // double lmax_flt_scale,
sky_threshold, // double sky_threshold,
target_horizon, // double target_horizon,
filter_below_horizon, // double filter_below_horizon,
lmax_hack_ridge, // double lmax_hack_ridge,
lmax_radius, // double lmax_radius,
target_radius, // double target_radius,
n_recenter, // int n_recenter,
no_border, // boolean no_border,
// Moving target LMA
lma_sigma, // double lma_sigma,
wnd_pedestal, // double wnd_pedestal,
lma_r0, // double lma_r0,
lma_ovrsht, // double lma_ovrsht,
// CUAS Motion LMA // // CUAS Motion LMA parameters
lma_fit_xy, // boolean lma_fit_xy,
lma_fit_a, // boolean lma_fit_a,
lma_fit_c, // boolean lma_fit_c,
lma_fit_r, // boolean lma_fit_r,
lma_fit_k, // boolean lma_fit_k,
lambda, // double lambda,
lambda_good, // double lambda_good,
lambda_bad, // double lambda_bad,
lambda_max, // double lambda_max,
rms_diff, // double rms_diff,
num_iter, // int num_iter,
min_keep, // int min_keep,
save_filtered_low, // boolean save_filtered_low,
debug_more, // boolean debug_more,
good_only, // boolean good_only,
show_empty, // boolean show_empty,
num_corr_samples, // int num_corr_samples,
target_strength, // double target_strength,
target_frac, // double [][] target_frac,
lma_rms, // double lma_rms,
lma_arms, // double lma_arms,
lma_pre_mina, // double lma_pre_mina,
// use lma_mina2, lma_rrms2 !
lma_mina2, // double lma_mina,
lma_rrms2, // double lma_rrms,
lma_maxr, // double lma_maxr,
lma_minr1, // double lma_minr1,
lma_mink, // double lma_mink,
lma_maxk, // double lma_maxk,
lma_a2a, // double lma_a2a,
slow_fast_mismatch, // double slow_fast_mismatch,
fail_mismatch, // boolean fail_mismatch,
offcenter, // double offcenter,
noisemax, // double noisemax,
factor_lim, // double factor_lim,
factor_pow, // double factor_pow,
score_coeff, // double [] score_coeff,
slow_score, // double slow_score,
batch_mode, // boolean batch_mode,
debugLevel); // int debugLevel);
//int
num_new += addNewResults(
......@@ -8437,11 +8479,9 @@ public class CuasMotion {
debugLevel); // final int debugLevel);
if (debugLevel > -4) {
System.out.println("Added "+num_new+" new tiles as good/bad at iteration "+niter+".");
System.out.println("Added "+num_new+" new tiles as good/bad at base iteration "+niter+".");
}
}
if (save_filtered_low) {
String title = model_prefix+"-ADDED_NEW_CENTERED_MULTI-n"+niter;
if (boost_accum_pairs > 1.0) {
......@@ -8485,6 +8525,266 @@ public class CuasMotion {
}
return target_sequence_multi; // target_sequence; // contains all tiles, good or bad, their data and when they were defined
}
private static double [][][][] getNewCenteredTargets(
CLTParameters clt_parameters,
CuasMotion cuasMotion,
float [][] fpixels_accum,
double [][][] targets_nonoverlap, // final double [][][] vector_fields, // centers
double [][][] extended_scan,
int frame0, // for vector_field[0]
int corr_inc, // final int frame_step, // keep for slow
int half_accum_range, // final int half_range, // scale for slow
double boost_accum_pairs,// final double boost_pairs,
boolean smooth, // final boolean smooth,
int corr_offset, // interframe distance for correlation
boolean save_filtered_high,
String model_prefix,
int niter,
double input_range,
double lmax_fraction,
double lmax_flt_neglim,
double lmax_flt_hsigma,
double lmax_flt_lsigma,
double lmax_flt_scale,
double sky_threshold,
double target_horizon,
double filter_below_horizon,
double lmax_hack_ridge,
double lmax_radius,
double target_radius, // final double centroid_radius,
int n_recenter, // final int n_recenter, // re-center window around new maximum. 0 -no refines (single-pass)
boolean no_border,
// Moving target LMA
double lma_sigma,
double wnd_pedestal,
double lma_r0,
double lma_ovrsht,
// CUAS Motion LMA parameters
boolean lma_fit_xy,
boolean lma_fit_a,
boolean lma_fit_c,
boolean lma_fit_r,
boolean lma_fit_k,
double lambda,
double lambda_good,
double lambda_bad,
double lambda_max,
double rms_diff,
int num_iter,
int min_keep, // 2; // keep at least this number of candidates before using cuas_lma_pre_mina filter
boolean save_filtered_low,
boolean debug_more,
boolean good_only,
boolean show_empty, // show scenes with no (valid) targets
int num_corr_samples,
double target_strength,
double [][] target_frac, // pairs - strength, minimal fraction for that strength
double lma_rms, // = 1.5; // Maximal RMS (should always match, regardless if A)
double lma_arms, // = 0.06; // Maximal absolute RMS (should match one of cuas_lma_arms OR cuas_lma_rrms (0.484)
double lma_pre_mina,
// use lma_mina2, lma_rrms2 !
double lma_mina,
double lma_rrms, // = 0.15; // Maximal relative to A rms. OK is when (RMS < cuas_lma_arms) || (RMS < cuas_lma_rrms * A)
double lma_maxr, // = 5.0; // Minimal K (overshoot) = 3.0
double lma_minr1,// = 1.0; // Minimal R1 (radius of positive peak)
double lma_mink, // = 0.0; // Minimal K (overshoot) = 1.0
double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0// final double lma_a2a,
double lma_a2a,
double slow_fast_mismatch, // // 1.5; allow larger mismatch between slow and fast
boolean fail_mismatch,
double offcenter,
double noisemax,
double factor_lim,
double factor_pow,
double [] score_coeff,
double slow_score, // multiply total score for targets detected in slow target mode
boolean batch_mode,
int debugLevel){
// perform new accumulations of shifted non-conflicting tiles
float [][] fpixels_accumulated = cuasMotion.shiftAndRenderAccumulate(
clt_parameters, // CLTParameters clt_parameters,
true, // false, // final boolean center, // why is it false here?
false, // final boolean fill_zeros,
fpixels_accum, // By Claude on 05/07/2026: LPF'd with accum_ra (was fpixels_tum)
extended_scan, // final double [][][] vector_field,
frame0, // final int frame0, // for vector_field[0]
corr_inc, // final int frame_step, // keep for slow
half_accum_range, // final int half_range, // scale for slow
boost_accum_pairs,// final double boost_pairs,
smooth, // final boolean smooth,
corr_offset, // final int corr_offset, // interframe distance for correlation
true); // final boolean batch_mode) {
if (save_filtered_high) {
String title = model_prefix+"-ACCUMULATED-CENTERED-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
}
ImagePlus imp_acc = ShowDoubleFloatArrays.makeArrays(
fpixels_accumulated, // double[][] pixels,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
title, // model_prefix+"-ACCUMULATED-CENTERED-n"+niter, // String title,
cuasMotion.slice_titles);
imp_acc.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (!batch_mode) {
imp_acc.show();
}
cuasMotion.parentCLT.saveImagePlusInModelDirectory(imp_acc); // ImagePlus imp)
}
// replace center frames with the accumulated ones
if (debugLevel > -4) {
System.out.println("Starting render, iteration = "+niter);
}
// show just fpixels_accumulated
// move outside? compare to slice_titles known
// Calculate both centroid and LMA target parametes, return both
// targets_new will contain motion vectors, centroid, and LMA results combined
//save_filtered_high
float [][] accum_debug = save_filtered_high? new float [num_corr_samples][]:null; //fpixels_accumulated.length]
boolean keep_failed = false; // keep failed targets
double [][][][] targets_new_multi = getAccumulatedCoordinatesMulti(
keep_failed, // final boolean keep_failed, // keep failed targets
niter, // final int when, // set if >=0 for failures
true, // final boolean centered,
boost_accum_pairs, // final double boost_exposure,
targets_nonoverlap, // final double [][][] vector_fields, // centers
fpixels_accumulated, // final double [][] accum_data, // should be around 0, no low-freq
lmax_fraction, // final double cuas_lmax_fraction, // 0.7; // Check if local maximum is separated from tye surrounding by this fraction of the maximum value
lmax_flt_neglim, // final double lmax_flt_neglim, // -0.3; // limit negative data to reduce ridge influence (make -10 to disable)
lmax_flt_hsigma, // final double lmax_flt_hsigma, // 1.0 // HPF (~UM) subtract GB with this sigma from the data tile
lmax_flt_lsigma, // final double lmax_flt_lsigma, // 1.0 // LPF - GB result of the previous subtraction
lmax_flt_scale, // final double lmax_flt_scale, // 5.0 // scale filtering result
cuasMotion.sky_mask, // final double sky_mask,
sky_threshold, // final double sky_threshold, // 0.9 // minimal value of the sky mask where target is possible
target_horizon+filter_below_horizon, // final double lma_horizon,
lmax_hack_ridge, // final double lmax_hack_ridge, // 0.45; // Hack for ridges: remove horizontal streaks, where average(abs()) for the line exceeds fraction of abs max 0.32-good, 0.55 - bad
lmax_radius, // final int cuas_lmax_radius, // 3; // look inside cuas_lmax_radius* 2 + 1 square for the local maximum isolation
lmax_radius, // final double centered_radius,
0.5, // final double centered_radius_blur,
1.0, // final double pix_tolerance, //
// lmax_zero, // final boolean cuas_lmax_zero, // true; // zero all data outside this radius from the maximum
target_radius, // final double centroid_radius,
n_recenter, // final int n_recenter, // re-center window around new maximum. 0 -no refines (single-pass)
cuasMotion.tilesX, // final int tilesX){
no_border, // final boolean no_border,
// Moving target LMA
lma_sigma, // final double lma_sigma,
wnd_pedestal, // final double wnd_pedestal,
lma_r0, // final double lma_r0,
lma_ovrsht, // final double lma_ovrsht,
// CUAS Motion LMA parameters
lma_fit_xy, // final boolean lma_fit_xy,
lma_fit_a, // final boolean lma_fit_a,
lma_fit_c, // final boolean lma_fit_c,
lma_fit_r, // final boolean lma_fit_r,
lma_fit_k, // final boolean lma_fit_k,
lambda, // final double lambda,
lambda_good, // final double lambda_good,
lambda_bad, // final double lambda_bad,
lambda_max, // final double lambda_max,
rms_diff, // final double rms_diff,
num_iter, // final int num_iter,0, // final double pre_min_a, // pre-filter minimal LMA-A (half finbal?)
lma_pre_mina*lma_mina,// final double pre_min_a, // 0.5 //scale cuas_lma_mina to filter initial candidates (if there are > one of them)
min_keep, // final int min_keep, // 2; // keep at least this number of candidates before using cuas_lma_pre_mina filter
accum_debug, // final float [][] accum_debug,
cuasMotion.parentCLT, // final QuadCLT parentCLT, // debug only, maybe null in other cases
debugLevel); // final int debugLevel);
if (accum_debug != null) {
String title = model_prefix+"-ACCUMULATED_FILTERED-CENTERED-MULTI-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
}
ImagePlus imp_acc = ShowDoubleFloatArrays.makeArrays(
accum_debug, // double[][] pixels,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
title, // model_prefix+"-ACCUMULATED_FILTERED-CENTERED-MULTI-n"+niter, // String title,
cuasMotion.slice_titles);
imp_acc.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (!batch_mode) {
imp_acc.show();
}
cuasMotion.parentCLT.saveImagePlusInModelDirectory(imp_acc); // ImagePlus imp)
}
// no need to to evaluate scores now - can be done all at once when all non-centered will be replaced by centered, removed (almost) duplicates
// evaluating scores, but it is not needed
// new results are sorted by decreasing amplitude, there should be only one - test it. If not still use only the first
// continue niter for "when"
// keep only one (best) result for centered getAccumulatedCoordinatesMulti()
if (save_filtered_low && debug_more) {
String title = model_prefix+"-NEW-TARGETS-CENTERED-MULTI-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
}
ImagePlus imp_new = showTargetSequence(
targets_new_multi, // final double [][][][] targets_multi,
cuasMotion.slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title, // model_prefix+"-NEW-TARGETS-CENTERED-MULTI-n"+niter,// String title,
good_only, // final boolean good_only,
show_empty, // final boolean show_empty, // show scenes with no (valid) targets
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
cuasMotion.parentCLT.saveImagePlusInModelDirectory(imp_new); // ImagePlus imp)
}
// evaluate scores here to reduce the number of attempts for centered targets
getEffectiveStrengthLMA(
targets_new_multi, // final double [][][] target_coords, // LMA
target_strength, // final double target_strength,
target_frac, // final double [][] target_frac, // pairs - strength, minimal fraction for that strength
lma_rms, // final double lma_rms, // = 1.5; // Maximal RMS (should always match, regardless if A)
lma_arms, // final double lma_arms, // = 0.06; // Maximal absolute RMS (should match one of cuas_lma_arms OR cuas_lma_rrms (0.484)
lma_rrms, // final double lma_rrms, // = 0.15; // Maximal relative to A rms. OK is when (RMS < cuas_lma_arms) || (RMS < cuas_lma_rrms * A)
lma_mina, // final double lma_mina, // = 1.0; // Minimal A (amplitude)
lma_maxr, // final double lma_maxr, // = 5.0; // Minimal K (overshoot) = 3.0
lma_minr1, // final double lma_minr1,// = 1.0; // Minimal R1 (radius of positive peak)
lma_mink, // final double lma_mink, // = 0.0; // Minimal K (overshoot) = 1.0
lma_maxk, // final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0// final double lma_a2a,
lma_a2a, // final double lma_a2a,
0, // max_mismatch, // final double max_mismatch, apply only during final, when mismatch scores are calculated
slow_fast_mismatch,// final double slow_fast_mismatch, // // 1.5; allow larger mismatch between slow and fast
fail_mismatch, // final boolean fail_mismatch,
offcenter, // final double offcenter,
cuasMotion.getNoiseMap(), // final double [] noise_map,
noisemax, // final double noise_max,
target_horizon, // final double lma_horizon, // horizon as maximal pixel Y
cuasMotion.tilesX); // final int tilesX,
int [] remain_es_centered = getScore(
targets_new_multi, // final double [][][] target_sequence, // modifies certain fields (scores)
factor_lim, // final double importance_limit,
factor_pow, // final double importance_power, // Raise each factor to this power before combining
score_coeff, // final double [] importance, // for now (each - squared?): [0] - Amplitude (A/A0), 1 - RMS (RMS0/RMS), 2 - RRMS((RMS/A0) / (RMS/A)
slow_score, // final double slow_score, // multiply total score for targets detected in slow target mode
cuasMotion.tilesX); // final int tilesX,
if (save_filtered_low) {
String title = model_prefix+"-NEW-TARGETS_CENTERED_SCORES_MULTI-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
}
ImagePlus imp_new_scores = showTargetSequence(
targets_new_multi, // double [][][] vector_fields_sequence,
cuasMotion.slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title, // model_prefix+"-NEW-TARGETS_CENTERED_SCORES_MULTI-n"+niter,// String title,
good_only, // final boolean good_only,
show_empty, // final boolean show_empty, // show scenes with no (valid) targets
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
cuasMotion.parentCLT.saveImagePlusInModelDirectory(imp_new_scores); // ImagePlus imp)
}
return targets_new_multi;
}
/**
* if (select_new && !use_motion) , fill mark all selected non-centered as "used"
* @param motion_sequence
......
......@@ -71,68 +71,70 @@ public class CuasMotionLMA {
public static final int RSLT_MAX2A = 9;
public static final int RSLT_ITERS = 10;
public static final int RSLT_CENTERED=11; //1: this target was evaluated in centered mode, 0 - was in non-centered, -1 - consumed in non-centered
// add
public static final int RSLT_BOOST= 12; // target accumulated with boosted "exposure time" (based scaled this)
public static final int RSLT_CENT_X = 13;
public static final int RSLT_CENT_Y = 14;
public static final int RSLT_CENT_MX= 15;
public static final int RSLT_CENT_F = 16;
public static final int RSLT_CENT_X = 12;
public static final int RSLT_CENT_Y = 13;
public static final int RSLT_CENT_MX= 14;
public static final int RSLT_CENT_F = 15;
public static final int RSLT_VX = 17;
public static final int RSLT_VY = 18;
public static final int RSLT_VSTR = 19;
public static final int RSLT_VFRAC = 20;
public static final int RSLT_VBOOST = 21; // motion vector was calculated with boosted number of accumulated scene pairs (based scaled this)
public static final int RSLT_VX = 16;
public static final int RSLT_VY = 17;
public static final int RSLT_VSTR = 18;
public static final int RSLT_VFRAC = 19;
public static final int RSLT_BX = 20;
public static final int RSLT_BY = 21; // RSLT_BX+1;
public static final int RSLT_AX = 22; // RSLT_BX+2;
public static final int RSLT_AY = 23; // RSLT_BX+3;
public static final int RSLT_MISMATCH_BEFORE = 24;
public static final int RSLT_MISMATCH_AFTER = 25; // RSLT_MISMATCH_BEFORE+1;
public static final int RSLT_MISMATCH_DIRS= 26;
public static final int RSLT_MATCH_LENGTH= 27; // is one less than the total length (0 - isolated)
public static final int RSLT_BEFORE_LENGTH= 28; // just for debug
public static final int RSLT_AFTER_LENGTH= 29; // just for debug
public static final int RSLT_SEQ_TRAVEL= 30;
public static final int RSLT_MSCORE = 31;
public static final int RSLT_QA = 32;
public static final int RSLT_QRMS = 33;
public static final int RSLT_QRMS_A = 34;
public static final int RSLT_QCENTER = 35;
public static final int RSLT_QMATCH = 36;
public static final int RSLT_QMATCH_LEN= 37;
public static final int RSLT_QTRAVEL= 38;
public static final int RSLT_QSCORE = 39;
public static final int RSLT_STRONGER = 40; // index of stronger neighbor (may be more)
public static final int RSLT_SLOW = 41; // 1 - slow, 0 - fast
public static final int RSLT_WHEN = 42;
public static final int RSLT_FAIL = 43;
public static final int RSLT_DISPARITY= 44; // disparity from single keyframe sequences
public static final int RSLT_DISP_DIFF= 45; // disparity difference between what?
public static final int RSLT_DISP_STR = 46; // disparity strength
public static final int RSLT_RANGE = 47; // range (meters) found from RSLT_DISPARITY, modified by RSLT_INFINITY
public static final int RSLT_GLOBAL = 48; // local target ID (1-based)
public static final int RSLT_GLENGTH = 49; // length (symmetrical around this one) for which disparity and range are provided
public static final int RSLT_GDISPARITY= 50; // disparity from accumulation of the range (RSLT_GLENGTH)
public static final int RSLT_GDISP_DIFF= 51; // disparity difference for a range
public static final int RSLT_GDISP_STR = 52; // disparity strength for a range
public static final int RSLT_GRANGE = 53; // global range - calculated for long sequences (and its fractions)
public static final int RSLT_FL_PX = 54; // flight log px
public static final int RSLT_FL_PY = 55; // flight log py
public static final int RSLT_FL_DISP = 56; // flight log true disparity
public static final int RSLT_FL_RANGE = 57; // flight log range (meters)
public static final int RSLT_INFINITY = 58; // disparity at infinity used for range calculation
public static final int RSLT_TARGET_ID = 59; // unique target id for the whole sequence of segments. 1 is reserved for the UAS
public static final int RSLT_VEL_AWAY = 60; // axial velocity (positive - away), range derivative (m/s), calculated from the difference to the previous/next series range
public static final int RSLT_VEL_RIGHT = 61; // lateral velocity, right ( calculated from angular and RSLT_GRANGE
public static final int RSLT_VEL_UP = 62; // lateral velocity, up ( calculated from angular and RSLT_GRANGE
public static final int RSLT_RANGE_LIN = 63; // range linear interpolated using previous/next series if the same target is present there
public static final int RSLT_BX = 22;
public static final int RSLT_BY = 23; // RSLT_BX+1;
public static final int RSLT_AX = 24; // RSLT_BX+2;
public static final int RSLT_AY = 25; // RSLT_BX+3;
public static final int RSLT_MISMATCH_BEFORE = 26;
public static final int RSLT_MISMATCH_AFTER = 27; // RSLT_MISMATCH_BEFORE+1;
public static final int RSLT_MISMATCH_DIRS= 28;
public static final int RSLT_MATCH_LENGTH= 29; // is one less than the total length (0 - isolated)
public static final int RSLT_BEFORE_LENGTH= 30; // just for debug
public static final int RSLT_AFTER_LENGTH= 31; // just for debug
public static final int RSLT_SEQ_TRAVEL= 32;
public static final int RSLT_MSCORE = 33;
public static final int RSLT_QA = 34;
public static final int RSLT_QRMS = 35;
public static final int RSLT_QRMS_A = 36;
public static final int RSLT_QCENTER = 37;
public static final int RSLT_QMATCH = 38;
public static final int RSLT_QMATCH_LEN= 39;
public static final int RSLT_QTRAVEL= 40;
public static final int RSLT_QSCORE = 41;
public static final int RSLT_STRONGER = 42; // index of stronger neighbor (may be more)
public static final int RSLT_SLOW = 43; // 1 - slow, 0 - fast
public static final int RSLT_WHEN = 44;
public static final int RSLT_FAIL = 45;
public static final int RSLT_DISPARITY= 46; // disparity from single keyframe sequences
public static final int RSLT_DISP_DIFF= 47; // disparity difference between what?
public static final int RSLT_DISP_STR = 48; // disparity strength
public static final int RSLT_RANGE = 49; // range (meters) found from RSLT_DISPARITY, modified by RSLT_INFINITY
public static final int RSLT_GLOBAL = 50; // local target ID (1-based)
public static final int RSLT_GLENGTH = 51; // length (symmetrical around this one) for which disparity and range are provided
public static final int RSLT_GDISPARITY= 52; // disparity from accumulation of the range (RSLT_GLENGTH)
public static final int RSLT_GDISP_DIFF= 53; // disparity difference for a range
public static final int RSLT_GDISP_STR = 54; // disparity strength for a range
public static final int RSLT_GRANGE = 55; // global range - calculated for long sequences (and its fractions)
public static final int RSLT_FL_PX = 56; // flight log px
public static final int RSLT_FL_PY = 57; // flight log py
public static final int RSLT_FL_DISP = 58; // flight log true disparity
public static final int RSLT_FL_RANGE = 59; // flight log range (meters)
public static final int RSLT_INFINITY = 60; // disparity at infinity used for range calculation
public static final int RSLT_TARGET_ID = 61; // unique target id for the whole sequence of segments. 1 is reserved for the UAS
public static final int RSLT_VEL_AWAY = 62; // axial velocity (positive - away), range derivative (m/s), calculated from the difference to the previous/next series range
public static final int RSLT_VEL_RIGHT = 63; // lateral velocity, right ( calculated from angular and RSLT_GRANGE
public static final int RSLT_VEL_UP = 64; // lateral velocity, up ( calculated from angular and RSLT_GRANGE
public static final int RSLT_RANGE_LIN = 65; // range linear interpolated using previous/next series if the same target is present there
public static final int RSLT_LEN = RSLT_RANGE_LIN + 1;
public static final String [] LMA_TITLES =
{"X-OFFS","Y-OFFS", "AMPLITUDE", "RADIUS","RAD_POS", "OVERSHOOT","OFFSET","RMSE","RMSE/A","MAX2A","ITERATIONS",
"CENTERED",
"CENTERED", "EXP-BOOST",
"Centr-X","Centr-Y","Centr-max","Centr-frac",
"Vx", "Vy", "V-conf","V-frac", // from motion vectors
"Vx", "Vy", "V-conf","V-frac", "V-boost",// from motion vectors
"X-before", "Y-before","X-after","Y-after", // from getHalfBeforeAfterPixXY()
"ERR-BEFORE", "ERR-AFTER", "BA-DIRS", // before dir + 16*after dir
"Match-length",
......
......@@ -795,7 +795,11 @@ min_str_neib_fpn 0.35
public int cuas_corr_pairs = 20; // number of correlation pairs to accumulate
public double cuas_boost_slow = 4.0; // if >1 and the motion vector is below tile_size/cuas_boost_slow, scale corr_pairs
public double cuas_boost_mv_lim = 1.8; // Do not boost if motion vector faster than this (before in code equiv 1.8 pix)
public double cuas_boost_accum = 4.0; // if >1 increase tracking camera exposure (TODO: conditional / compete)
public double cuas_boost_accum = 4.0; // if >1 increase tracking camera exposure (TODO: conditional / compete)
public boolean cuas_accum_base = true; // Accumulate centered targets with base "exposure"
public boolean cuas_accum_boosted = true; // Accumulate centered targets with boosted "exposure"
public double cuas_boost_mstr = 0.007; // scale corr_pairs if motion strength is below
public double cuas_boost_xstr = 0.2; // never scale if stronger
public int cuas_corr_offset = 5; // offset between motion detection pairs
......@@ -2709,6 +2713,10 @@ min_str_neib_fpn 0.35
"Do not boost if motion vector faster than this (before in code equiv 1.8 pix).");
gd.addNumericField("Increase tracking camera exposure", this.cuas_boost_accum, 5,8,"",
"If >1 increase tracking camera exposure (later - conditional).");
gd.addCheckbox ("Accumulate tracking base exposuer", this.cuas_accum_base,
"Accumulate centered targets with base \"exposure\".");
gd.addCheckbox ("Accumulate tracking boosted exposuer", this.cuas_accum_boosted,
"Accumulate centered targets with boosted \"exposure\".");
gd.addNumericField("Boost pairs for weak targets", this.cuas_boost_mstr, 5,8,"",
"Scale corr_pairs if motion strength is below, regardless of speed.");
gd.addNumericField("Never boost stronger", this.cuas_boost_xstr, 5,8,"",
......@@ -4392,18 +4400,18 @@ min_str_neib_fpn 0.35
this.cuas_boost_slow = gd.getNextNumber();
this.cuas_boost_mv_lim = gd.getNextNumber();
this.cuas_boost_accum = gd.getNextNumber();
this.cuas_accum_base = gd.getNextBoolean();
this.cuas_accum_boosted = gd.getNextBoolean();
this.cuas_boost_mstr = gd.getNextNumber();
this.cuas_boost_xstr = gd.getNextNumber();
this.cuas_corr_offset = (int) gd.getNextNumber();
this.cuas_gaussian_ra = gd.getNextBoolean();
this.cuas_temporal_um = (int) gd.getNextNumber();
this.cuas_tum_threshold = gd.getNextNumber();
this.cuas_precorr_ra = (int) gd.getNextNumber();
this.cuas_corr_step = (int) gd.getNextNumber();
this.cuas_accum_ra = (int) gd.getNextNumber();
this.cuas_accum_step = (int) gd.getNextNumber();
this.cuas_half_step = gd.getNextBoolean();
this.cuas_max_range = (int) gd.getNextNumber();
this.cuas_fin_range = (int) gd.getNextNumber();
......@@ -5704,6 +5712,8 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"cuas_boost_slow", this.cuas_boost_slow+""); // double
properties.setProperty(prefix+"cuas_boost_mv_lim", this.cuas_boost_mv_lim+""); // double
properties.setProperty(prefix+"cuas_boost_accum", this.cuas_boost_accum+""); // double
properties.setProperty(prefix+"cuas_accum_base", this.cuas_accum_base+""); // boolean
properties.setProperty(prefix+"cuas_accum_boosted", this.cuas_accum_boosted+""); // boolean
properties.setProperty(prefix+"cuas_boost_mstr", this.cuas_boost_mstr+""); // double
properties.setProperty(prefix+"cuas_boost_xstr", this.cuas_boost_xstr+""); // double
properties.setProperty(prefix+"cuas_corr_offset", this.cuas_corr_offset+""); // int
......@@ -6951,6 +6961,8 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"cuas_boost_slow")!=null) this.cuas_boost_slow=Double.parseDouble(properties.getProperty(prefix+"cuas_boost_slow"));
if (properties.getProperty(prefix+"cuas_boost_mv_lim")!=null) this.cuas_boost_mv_lim=Double.parseDouble(properties.getProperty(prefix+"cuas_boost_mv_lim"));
if (properties.getProperty(prefix+"cuas_boost_accum")!=null) this.cuas_boost_accum=Double.parseDouble(properties.getProperty(prefix+"cuas_boost_accum"));
if (properties.getProperty(prefix+"cuas_accum_base")!=null) this.cuas_accum_base=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_accum_base"));
if (properties.getProperty(prefix+"cuas_accum_boosted")!=null) this.cuas_accum_boosted=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_accum_boosted"));
if (properties.getProperty(prefix+"cuas_boost_mstr")!=null) this.cuas_boost_mstr=Double.parseDouble(properties.getProperty(prefix+"cuas_boost_mstr"));
if (properties.getProperty(prefix+"cuas_boost_xstr")!=null) this.cuas_boost_xstr=Double.parseDouble(properties.getProperty(prefix+"cuas_boost_xstr"));
if (properties.getProperty(prefix+"cuas_corr_offset")!=null) this.cuas_corr_offset=Integer.parseInt(properties.getProperty(prefix+"cuas_corr_offset"));
......@@ -8215,6 +8227,8 @@ min_str_neib_fpn 0.35
imp.cuas_boost_slow = this.cuas_boost_slow;
imp.cuas_boost_mv_lim = this.cuas_boost_mv_lim;
imp.cuas_boost_accum = this.cuas_boost_accum;
imp.cuas_accum_base = this.cuas_accum_base;
imp.cuas_accum_boosted = this.cuas_accum_boosted;
imp.cuas_boost_mstr = this.cuas_boost_mstr;
imp.cuas_boost_xstr = this.cuas_boost_xstr;
imp.cuas_corr_offset = this.cuas_corr_offset;
......
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