Commit b7ce93be authored by Andrey Filippov's avatar Andrey Filippov

Made refineMotionVectors work with fast targets

parent b691e9f3
...@@ -239,6 +239,10 @@ public class CuasMotion { ...@@ -239,6 +239,10 @@ public class CuasMotion {
public static final int ANLZ_GE = 4; // list tiles with targets with parameter >= value (such as AMPLITUDE >= 1.0) public static final int ANLZ_GE = 4; // list tiles with targets with parameter >= value (such as AMPLITUDE >= 1.0)
public static final int ANLZ_LE = 5; // list tiles with targets with parameter <= value (such as RMSE <= 0.5) public static final int ANLZ_LE = 5; // list tiles with targets with parameter <= value (such as RMSE <= 0.5)
public static final int WHEN_PHASE1 = 0; // phase 1 RSLT_WHEN start
public static final int WHEN_PHASE2 = 100; // phase 2 RSLT_WHEN start
public static final int WHEN_FINISH = 200; // RSLT_WHEN start after phase 2
public int when_fail = 0; // will maintain (increment) and use for "RSLT_WHEN" when setting RSLT_FAIL
public static void setCuasAnnots( public static void setCuasAnnots(
String annot, String annot,
...@@ -804,7 +808,7 @@ public class CuasMotion { ...@@ -804,7 +808,7 @@ public class CuasMotion {
} }
/** /**
* Trying to fix centered mode probably broken when switching to multi-varian targets. * Trying to fix centered mode probably broken when switching to multi-variant targets.
* It uses data from the selected target variant, including RSLT_X, RSLT_Y data * It uses data from the selected target variant, including RSLT_X, RSLT_Y data
* @param target_sequence_multi * @param target_sequence_multi
* @param filter5 * @param filter5
...@@ -2013,7 +2017,10 @@ public class CuasMotion { ...@@ -2013,7 +2017,10 @@ public class CuasMotion {
final double [][][] extended = new double [num_seq][num_tiles][]; final double [][][] extended = new double [num_seq][num_tiles][];
final Thread[] threads = ImageDtt.newThreadArray(); final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0);
final int dbg_nseq = 26; // 125; // 100; // 161; // 36; // 28; // 97; // 40; // 41; // 157; // -(116); // 57; // 20; // -1;
final int dbg_tile = 19+34*80; // 15+33*80; // 12+37*80; //55+38*80; // 51+38*80; // 54+38*80; //52+38*80; // 50+38*80; // 55+38*80; // -(17 + 33*80); // 48+32*80; // 50+38*80; // -1;
for (int irange = range; irange > 0; irange--) { // to try 5x5, but make sure 3x3 are always as needed for (int irange = range; irange > 0; irange--) { // to try 5x5, but make sure 3x3 are always as needed
final int firange = irange;
ai.set(0); ai.set(0);
final int frange = irange; final int frange = irange;
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
...@@ -2025,13 +2032,15 @@ public class CuasMotion { ...@@ -2025,13 +2032,15 @@ public class CuasMotion {
double [][] ms = motion_scan[nSeq]; double [][] ms = motion_scan[nSeq];
boolean has_filter = (filtered != null) && (filtered[nSeq] != null); boolean has_filter = (filtered != null) && (filtered[nSeq] != null);
boolean [] centers = has_filter ? filtered[nSeq] : new boolean [ms.length]; boolean [] centers = has_filter ? filtered[nSeq] : new boolean [ms.length];
if (nSeq == dbg_nseq) {
System.out.println("extendMotionScan(): nSeq="+nSeq+" irange="+firange+" has_filter="+has_filter);
}
if (!has_filter) { if (!has_filter) {
for (int i = 0; i < centers.length; i++) { for (int i = 0; i < centers.length; i++) {
centers[i] = (ms[i] != null) && centers[i] = (ms[i] != null) &&
Double.isNaN(ms[i][CuasMotionLMA.RSLT_STRONGER]) && // should not have stronger neighbor Double.isNaN(ms[i][CuasMotionLMA.RSLT_STRONGER]) && // should not have stronger neighbor
(Double.isNaN(ms[i][CuasMotionLMA.RSLT_FAIL]) || (Double.isNaN(ms[i][CuasMotionLMA.RSLT_FAIL]) ||
(ms[i][CuasMotionLMA.RSLT_FAIL]==CuasMotionLMA.FAIL_NONE) || (ms[i][CuasMotionLMA.RSLT_FAIL]==CuasMotionLMA.FAIL_NONE));
(ms[i][CuasMotionLMA.RSLT_FAIL]==CuasMotionLMA.FAIL_PENDING)); // By Claude on 05/07/2026
} }
} }
if ((filtered != null) && (filtered[nSeq] == null)) { if ((filtered != null) && (filtered[nSeq] == null)) {
...@@ -2040,6 +2049,9 @@ public class CuasMotion { ...@@ -2040,6 +2049,9 @@ public class CuasMotion {
for (int tileY = 0; tileY < tilesY; tileY++) { for (int tileY = 0; tileY < tilesY; tileY++) {
for (int tileX = 0; tileX < tilesX; tileX++) { for (int tileX = 0; tileX < tilesX; tileX++) {
int ntile = tileX + tilesX * tileY; int ntile = tileX + tilesX * tileY;
if ((nSeq == dbg_nseq) && (ntile == dbg_tile)) {
System.out.println("extendMotionScan(): nSeq="+nSeq+" irange="+firange+" ntile="+ntile);
}
if (centers[ntile]) { if (centers[ntile]) {
num++; num++;
double [] mv = motion_scan[nSeq][ntile]; double [] mv = motion_scan[nSeq][ntile];
...@@ -2231,8 +2243,8 @@ public class CuasMotion { ...@@ -2231,8 +2243,8 @@ public class CuasMotion {
final int corr_offset_eff = corr_offset * Math.max(1, Math.min(corr_offset_scale, corr_pairs_ref / corr_offset)); 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 = 125; // 100; // 161; // 36; // 28; // 97; // 40; // 41; // 157; // -(116); // 57; // 20; // -1; final int dbg_nseq = 26; // 125; // 100; // 161; // 36; // 28; // 97; // 40; // 41; // 157; // -(116); // 57; // 20; // -1;
final int dbg_tile = 15+33*80; // 12+37*80; //55+38*80; // 51+38*80; // 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 = 19+34*80; // 15+33*80; // 12+37*80; //55+38*80; // 51+38*80; // 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 final int corr_offset_scale_eff = corr_offset_eff / corr_offset; // actual scale after clamping
if ((dbg_nseq < 0) || (dbg_nseq >= targets_nonoverlap.length) || (dbg_tile < 0) || (dbg_tile >= targets_nonoverlap[dbg_nseq].length)) { if ((dbg_nseq < 0) || (dbg_nseq >= targets_nonoverlap.length) || (dbg_tile < 0) || (dbg_tile >= targets_nonoverlap[dbg_nseq].length)) {
debugLevel = -2; debugLevel = -2;
...@@ -2248,6 +2260,8 @@ public class CuasMotion { ...@@ -2248,6 +2260,8 @@ public class CuasMotion {
if (debugLevel >= 0) { if (debugLevel >= 0) {
System.out.println("\nrefineMotionVectors(): dbg_iter_index="+dbg_iter_index+", corr_offset="+corr_offset+", corr_offset_scale="+corr_offset_scale+ System.out.println("\nrefineMotionVectors(): dbg_iter_index="+dbg_iter_index+", corr_offset="+corr_offset+", corr_offset_scale="+corr_offset_scale+
", corr_offset_eff="+corr_offset_eff+ ", corr_offset_eff="+corr_offset_eff+
", recalc_mv_boost="+recalc_mv_boost+
", corr_pairs_ref="+corr_pairs_ref+
(corr_offset_scale_eff != corr_offset_scale ? " (CLAMPED from "+corr_offset_scale+" to "+corr_offset_scale_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);
} }
...@@ -6624,7 +6638,8 @@ public class CuasMotion { ...@@ -6624,7 +6638,8 @@ public class CuasMotion {
*/ */
public static int [] removeWeakerDuplicates( // needs sortMultiTargets before (assuming earlier - stronger) and after (to remove null) public static int [] removeWeakerDuplicates( // needs sortMultiTargets before (assuming earlier - stronger) and after (to remove null)
final double [][][][] target_multi, final double [][][][] target_multi,
final double pix_tolerance) { final double pix_tolerance,
final int when_fail) {
final double pix_tolerance2 = pix_tolerance * pix_tolerance; final double pix_tolerance2 = pix_tolerance * pix_tolerance;
final int num_seq = target_multi.length; final int num_seq = target_multi.length;
final int num_tiles = target_multi[0].length; final int num_tiles = target_multi[0].length;
...@@ -6649,15 +6664,11 @@ public class CuasMotion { ...@@ -6649,15 +6664,11 @@ public class CuasMotion {
double dty = ty2-ty1; double dty = ty2-ty1;
double dt2 = dtx*dtx+dty*dty; double dt2 = dtx*dtx+dty*dty;
if (dt2 < pix_tolerance2) {// indx2 is a duplicate, remove its reference from the list if (dt2 < pix_tolerance2) {// indx2 is a duplicate, remove its reference from the list
/*
if ((targets[indx2][CuasMotionLMA.RSLT_FAIL] == CuasMotionLMA.FAIL_NONE) &&
(targets[indx2][CuasMotionLMA.RSLT_FAIL] == CuasMotionLMA.FAIL_NONE)) {
adup_good.getAndIncrement();
}
*/
// FAIL_NONE for both is now tested above // FAIL_NONE for both is now tested above
adup_good.getAndIncrement(); adup_good.getAndIncrement();
targets[indx2] = null; // targets[indx2] = null;
targets[indx2][CuasMotionLMA.RSLT_FAIL] = CuasMotionLMA.FAIL_DUPLICATE;
targets[indx2][CuasMotionLMA.RSLT_WHEN] = when_fail;
adup.getAndIncrement(); adup.getAndIncrement();
break; // for (int indx1 = 0; indx1 < indx2; indx1++) if (targets[indx1] != null){ break; // for (int indx1 = 0; indx1 < indx2; indx1++) if (targets[indx1] != null){
} }
...@@ -8117,7 +8128,7 @@ public class CuasMotion { ...@@ -8117,7 +8128,7 @@ public class CuasMotion {
int [] totals = null; int [] totals = null;
int [] passes = new int [num_corr_samples]; // debugging filter5 int [] passes = new int [num_corr_samples]; // debugging filter5
String model_prefix = parentCLT.getImageName()+getParametersSuffix(clt_parameters,null)+(cuasMotion.slow_targets? "-SLOW":"-FAST"); String model_prefix = parentCLT.getImageName()+getParametersSuffix(clt_parameters,null)+(cuasMotion.slow_targets? "-SLOW":"-FAST");
cuasMotion.when_fail = CuasMotion.WHEN_PHASE1;
if (clt_parameters.imp.cuas_reuse_centered) { // By Claude on 05/24/2026 if (clt_parameters.imp.cuas_reuse_centered) { // By Claude on 05/24/2026
String x3d_path = parentCLT.getX3dDirectory(); String x3d_path = parentCLT.getX3dDirectory();
String centered_path = x3d_path + Prefs.getFileSeparator() + model_prefix+"-ROUND_TWO_GOOD"+".tiff"; String centered_path = x3d_path + Prefs.getFileSeparator() + model_prefix+"-ROUND_TWO_GOOD"+".tiff";
...@@ -8134,7 +8145,8 @@ public class CuasMotion { ...@@ -8134,7 +8145,8 @@ public class CuasMotion {
// final double [][][][] target_sequence_multi = null; // final double [][][][] target_sequence_multi = null;
double [][][][] target_sequence_multi = null; double [][][][] target_sequence_multi = null;
int niter=0; // maybe start from 19 to match skipped non-center and have the same file names // int niter=0; // maybe start from 19 to match skipped non-center and have the same file names
cuasMotion.when_fail = CuasMotion.WHEN_PHASE1;
if (reuse_non_centered) { if (reuse_non_centered) {
String x3d_path = parentCLT.getX3dDirectory(); String x3d_path = parentCLT.getX3dDirectory();
String noncentered_path = x3d_path + Prefs.getFileSeparator() + model_prefix+"-ROUND_ONE"+".tiff"; String noncentered_path = x3d_path + Prefs.getFileSeparator() + model_prefix+"-ROUND_ONE"+".tiff";
...@@ -8174,7 +8186,7 @@ public class CuasMotion { ...@@ -8174,7 +8186,7 @@ public class CuasMotion {
// Calculate and set motion vectors strengths/failures // Calculate and set motion vectors strengths/failures
setEffectiveStrengthMV( // calculate tiles effective strength by the motion vectors. Combine with the target LMA? setEffectiveStrengthMV( // calculate tiles effective strength by the motion vectors. Combine with the target LMA?
target_sequence_multi, // final double [][][] motion_scan, target_sequence_multi, // final double [][][] motion_scan,
niter, // int niter, // save iteration number on failure if >= cuasMotion.when_fail, // int niter, // save iteration number on failure if >=
cuasMotion.tilesX, // final int tilesX) cuasMotion.tilesX, // final int tilesX)
// Let them fail here and not be considered at all // Let them fail here and not be considered at all
min_score_mv, // 0, // final double min_score_mv, min_score_mv, // 0, // final double min_score_mv,
...@@ -8183,9 +8195,10 @@ public class CuasMotion { ...@@ -8183,9 +8195,10 @@ public class CuasMotion {
speed_boost); // double speed_boost); speed_boost); // double speed_boost);
// first pass, using non-centered targets // first pass, using non-centered targets
for (; niter < num_cycles; niter++) { for (int it_indx=0; it_indx < num_cycles; it_indx++) { // local iteration index for WHEN
boolean save_filtered_low = intermed_low && (niter < iter_show); cuasMotion.when_fail = CuasMotion.WHEN_PHASE1+it_indx;
boolean save_filtered_high = intermed_high && (niter < iter_show); boolean save_filtered_low = intermed_low && (it_indx < iter_show);
boolean save_filtered_high = intermed_high && (it_indx < iter_show);
totals = getRemain( totals = getRemain(
target_sequence_multi, // final double [][][][] target_sequence_multi, target_sequence_multi, // final double [][][][] target_sequence_multi,
num_all, // int [] num_all_in, num_all, // int [] num_all_in,
...@@ -8206,18 +8219,19 @@ public class CuasMotion { ...@@ -8206,18 +8219,19 @@ public class CuasMotion {
if (debugLevel > -4) System.out.println ("No undefined tiles left, breaking loop"); if (debugLevel > -4) System.out.println ("No undefined tiles left, breaking loop");
break; break;
} }
if (save_filtered_low && debug_more) { if (save_filtered_low && debug_more) {
ImagePlus imp_ms1 = showTargetSequence( ImagePlus imp_ms1 = showTargetSequence(
motion_sequence, // double [][][] vector_fields_sequence, motion_sequence, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-MS1-n"+niter,// String title, model_prefix+"-MS1-n"+cuasMotion.when_fail,// String title,
!batch_mode, // boolean show, !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_ms1); parentCLT.saveImagePlusInModelDirectory(imp_ms1);
} }
if (save_filtered_low && debug_more) { if (save_filtered_low && debug_more) {
String title = model_prefix+"-PRE-SELECT-n"+niter; String title = model_prefix+"-PRE-SELECT-n"+cuasMotion.when_fail;
ImagePlus imp_pre_select = showTargetSequence( ImagePlus imp_pre_select = showTargetSequence(
target_sequence_multi, // double [][][] vector_fields_sequence, target_sequence_multi, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
...@@ -8251,7 +8265,7 @@ public class CuasMotion { ...@@ -8251,7 +8265,7 @@ public class CuasMotion {
filter5, filter5,
cuasMotion.tilesX, cuasMotion.tilesX,
cuasMotion.tilesY, cuasMotion.tilesY,
model_prefix+"-FILTER5_SELECTED_MULTI-n"+niter, // Selected to test model_prefix+"-FILTER5_SELECTED_MULTI-n"+cuasMotion.when_fail, // Selected to test
slice_titles); slice_titles);
if (!batch_mode) { if (!batch_mode) {
imp_filter5.show(); imp_filter5.show();
...@@ -8283,7 +8297,7 @@ public class CuasMotion { ...@@ -8283,7 +8297,7 @@ public class CuasMotion {
ImagePlus imp_novl = showTargetSequence( ImagePlus imp_novl = showTargetSequence(
targets_nonoverlap, // double [][][] vector_fields_sequence, targets_nonoverlap, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-SELECTED-TO-TRY-n"+niter,// String title, model_prefix+"-SELECTED-TO-TRY-n"+cuasMotion.when_fail,// String title,
!batch_mode, // boolean show, !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_novl); parentCLT.saveImagePlusInModelDirectory(imp_novl);
...@@ -8291,7 +8305,7 @@ public class CuasMotion { ...@@ -8291,7 +8305,7 @@ public class CuasMotion {
ImagePlus imp_ext = showTargetSequence( ImagePlus imp_ext = showTargetSequence(
extended_scan, // double [][][] vector_fields_sequence, extended_scan, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-EXTENDED-n"+niter,// String title, model_prefix+"-EXTENDED-n"+cuasMotion.when_fail,// String title,
!batch_mode, // boolean show, !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_ext); parentCLT.saveImagePlusInModelDirectory(imp_ext);
...@@ -8320,7 +8334,7 @@ public class CuasMotion { ...@@ -8320,7 +8334,7 @@ public class CuasMotion {
corr_offset, // int corr_offset, // interframe distance for correlation corr_offset, // int corr_offset, // interframe distance for correlation
save_filtered_high, // boolean save_filtered_high, save_filtered_high, // boolean save_filtered_high,
model_prefix, // String model_prefix, model_prefix, // String model_prefix,
niter, // int niter, cuasMotion.when_fail, // int niter,
input_range, // double input_range, input_range, // double input_range,
lmax_fraction, // double lmax_fraction, lmax_fraction, // double lmax_fraction,
...@@ -8392,14 +8406,14 @@ public class CuasMotion { ...@@ -8392,14 +8406,14 @@ public class CuasMotion {
target_sequence_multi, // final double [][][] target_sequence, // will only process non-nulls here target_sequence_multi, // final double [][][] target_sequence, // will only process non-nulls here
targets_new_multi, // final double [][][] new_sequence, targets_new_multi, // final double [][][] new_sequence,
0, // final int num_best, // if >0, limit number of best results to add 0, // final int num_best, // if >0, limit number of best results to add
niter, // final int when_iter, cuasMotion.when_fail, // final int when_iter,
debugLevel); // final int debugLevel); debugLevel); // final int debugLevel);
if (debugLevel > -4) { if (debugLevel > -4) {
System.out.println("Added "+num_new+" new tiles as good/bad with BOOST="+boost_accum_pairs); System.out.println("Added "+num_new+" new tiles as good/bad with BOOST="+boost_accum_pairs);
} }
if (save_filtered_low) { if (save_filtered_low) {
String title = model_prefix+"-ADDED_NEW_MULTI-n"+niter; String title = model_prefix+"-ADDED_NEW_MULTI-n"+cuasMotion.when_fail;
if (boost_accum_pairs > 1.0) { if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs; title+="-BOOST"+boost_accum_pairs;
} }
...@@ -8434,7 +8448,7 @@ public class CuasMotion { ...@@ -8434,7 +8448,7 @@ public class CuasMotion {
corr_offset, // int corr_offset, // interframe distance for correlation corr_offset, // int corr_offset, // interframe distance for correlation
save_filtered_high, // boolean save_filtered_high, save_filtered_high, // boolean save_filtered_high,
model_prefix, // String model_prefix, model_prefix, // String model_prefix,
niter, // int niter, cuasMotion.when_fail, // int niter,
input_range, // double input_range, input_range, // double input_range,
lmax_fraction, // double lmax_fraction, lmax_fraction, // double lmax_fraction,
...@@ -8506,14 +8520,14 @@ public class CuasMotion { ...@@ -8506,14 +8520,14 @@ public class CuasMotion {
target_sequence_multi, // final double [][][] target_sequence, // will only process non-nulls here target_sequence_multi, // final double [][][] target_sequence, // will only process non-nulls here
targets_new_multi, // final double [][][] new_sequence, targets_new_multi, // final double [][][] new_sequence,
0, // final int num_best, // if >0, limit number of best results to add 0, // final int num_best, // if >0, limit number of best results to add
niter, // final int when_iter, cuasMotion.when_fail, // final int when_iter,
debugLevel); // final int debugLevel); debugLevel); // final int debugLevel);
if (debugLevel > -4) { if (debugLevel > -4) {
System.out.println("Added "+num_new+" new tiles as good/bad, base (no boost mode)"); System.out.println("Added "+num_new+" new tiles as good/bad, base (no boost mode)");
} }
if (save_filtered_low) { if (save_filtered_low) {
String title = model_prefix+"-ADDED_NEW_MULTI-n"+niter; String title = model_prefix+"-ADDED_NEW_MULTI-n"+cuasMotion.when_fail;
ImagePlus imp_new_scores = showTargetSequence( ImagePlus imp_new_scores = showTargetSequence(
target_sequence_multi, // double [][][] vector_fields_sequence, target_sequence_multi, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
...@@ -8538,9 +8552,9 @@ public class CuasMotion { ...@@ -8538,9 +8552,9 @@ public class CuasMotion {
null, // int [] num_noncentered_in, null, // int [] num_noncentered_in,
num_good, // int [] num_good_in, num_good, // int [] num_good_in,
num_bad); // int [] num_bad_in) num_bad); // int [] num_bad_in)
if (debugLevel > -4) printStats ("After iteration "+niter, true, num_all, num_undef, num_good, num_bad); if (debugLevel > -4) printStats ("After iteration "+cuasMotion.when_fail, true, num_all, num_undef, num_good, num_bad);
if (debugLevel > -4) { if (debugLevel > -4) {
System.out.println("Non-centered iteration "+niter+" DONE.\n"); System.out.println("Non-centered iteration "+cuasMotion.when_fail+" DONE.\n");
} }
} //for (niter=0; niter < max_iter; niter++) } //for (niter=0; niter < max_iter; niter++)
...@@ -8557,9 +8571,12 @@ public class CuasMotion { ...@@ -8557,9 +8571,12 @@ public class CuasMotion {
} }
} // end of phase 1 } // end of phase 1
if (debugLevel > -4) { if (debugLevel > -4) {
System.out.println("\n========================== Starting centered iterations =============================.\n"); System.out.println("\n========================== Starting centered iterations =============================.\n");
} }
cuasMotion.when_fail = CuasMotion.WHEN_PHASE2; // whill be overwritten inside loop
// By Claude on 05/05/2026 — optional MV refinement parameters for centered loop // By Claude on 05/05/2026 — optional MV refinement parameters for centered loop
int recalc_mv_num = slow_mode ? 0 : clt_parameters.imp.cuas_recalc_mv_num; int recalc_mv_num = slow_mode ? 0 : clt_parameters.imp.cuas_recalc_mv_num;
double recalc_mv_boost = clt_parameters.imp.cuas_recalc_mv_boost; double recalc_mv_boost = clt_parameters.imp.cuas_recalc_mv_boost;
...@@ -8617,7 +8634,7 @@ public class CuasMotion { ...@@ -8617,7 +8634,7 @@ public class CuasMotion {
if (early_en) { if (early_en) {
int [] early_fail = earlyFail( // Fail after Phase 1 int [] early_fail = earlyFail( // Fail after Phase 1
target_sequence_multi, // final double [][][][] target_multi, target_sequence_multi, // final double [][][][] target_multi,
niter, // final int niter, cuasMotion.when_fail, // final int niter,
early_boosts, // final boolean early_boosts, early_boosts, // final boolean early_boosts,
early_mscore, // final double min_mscore, early_mscore, // final double min_mscore,
early_vstr, // final double min_vstr, early_vstr, // final double min_vstr,
...@@ -8643,10 +8660,11 @@ public class CuasMotion { ...@@ -8643,10 +8660,11 @@ public class CuasMotion {
true); // final boolean trim_nulls) { // trim null targets true); // final boolean trim_nulls) { // trim null targets
int [] num_duplicates = removeWeakerDuplicates( // needs sortMultiTargets and after int [] num_duplicates = removeWeakerDuplicates( // needs sortMultiTargets and after
target_sequence_multi, // final double [][][][] target_multi, target_sequence_multi, // final double [][][][] target_multi,
duplicate_tolerance); // final double pix_tolerance) duplicate_tolerance, // final double pix_tolerance)
cuasMotion.when_fail); // final int when_fail)
if (debugLevel > -4) System.out.println("Removed "+num_duplicates[1]+" good duplicate targets (total with bad - "+num_duplicates[0]+")."); if (debugLevel > -4) System.out.println("Removed "+num_duplicates[1]+" good duplicate targets (total with bad - "+num_duplicates[0]+").");
sortMultiTargets( sortMultiTargets( // moves FAILED after good (and duplicates are now FAILED
target_sequence_multi, // final double [][][][] target_multi, target_sequence_multi, // final double [][][][] target_multi,
true); // final boolean trim_nulls) { // trim null targets true); // final boolean trim_nulls) { // trim null targets
...@@ -8674,15 +8692,18 @@ public class CuasMotion { ...@@ -8674,15 +8692,18 @@ public class CuasMotion {
} }
} }
/*
int niter_lim = niter+ num_cycles; int niter_lim = niter+ num_cycles;
int iter_show1 = iter_show + niter; int iter_show1 = iter_show + niter;
int niter0 = niter; // for debugging, so (niter - niter0) will start from 0 int niter0 = niter; // for debugging, so (niter - niter0) will start from 0
for (; niter < niter_lim; niter++) { */
// for (; niter < niter_lim; niter++) {
for (int it_indx2=0; it_indx2 < num_cycles; it_indx2++) {
cuasMotion.when_fail = CuasMotion.WHEN_PHASE2+it_indx2;
boolean good_only= false; boolean good_only= false;
boolean show_empty = true; // false; // show scenes with no (valid) targets boolean show_empty = true; // false; // show scenes with no (valid) targets
boolean save_filtered_low = intermed_low && (it_indx2 < iter_show);
boolean save_filtered_low = intermed_low && (niter < iter_show1); boolean save_filtered_high = intermed_high && (it_indx2 < iter_show);
boolean save_filtered_high = intermed_high && (niter < iter_show1);
totals = getRemain( totals = getRemain(
target_sequence_multi, // final double [][][][] target_sequence_multi, target_sequence_multi, // final double [][][][] target_sequence_multi,
num_all, // int [] num_all_in, num_all, // int [] num_all_in,
...@@ -8717,7 +8738,7 @@ public class CuasMotion { ...@@ -8717,7 +8738,7 @@ public class CuasMotion {
filter5, filter5,
cuasMotion.tilesX, cuasMotion.tilesX,
cuasMotion.tilesY, cuasMotion.tilesY,
model_prefix+"-FILTER5_SELECTED_MULTI_CENTERED-n"+niter, // Selected to test model_prefix+"-FILTER5_SELECTED_MULTI_CENTERED-n"+cuasMotion.when_fail, // Selected to test
slice_titles); slice_titles);
if (!batch_mode) { if (!batch_mode) {
imp_filter5.show(); imp_filter5.show();
...@@ -8729,7 +8750,7 @@ public class CuasMotion { ...@@ -8729,7 +8750,7 @@ public class CuasMotion {
ImagePlus imp_marked_used = showTargetSequence( ImagePlus imp_marked_used = showTargetSequence(
target_sequence_multi, // double [][][] vector_fields_sequence, target_sequence_multi, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-MARKED_USED-n"+niter,// String title, model_prefix+"-MARKED_USED-n"+cuasMotion.when_fail,// String title,
good_only, // final boolean good_only, good_only, // final boolean good_only,
show_empty, // final boolean show_empty, // show scenes with no (valid) targets show_empty, // final boolean show_empty, // show scenes with no (valid) targets
!batch_mode, // boolean show, !batch_mode, // boolean show,
...@@ -8745,7 +8766,7 @@ public class CuasMotion { ...@@ -8745,7 +8766,7 @@ public class CuasMotion {
break; break;
} }
// render and process in centered mode // render and process in centered mode
/*
double [][][] targets_nonoverlap = applyFilter( // motion vectors // will have nulls not top try double [][][] targets_nonoverlap = applyFilter( // motion vectors // will have nulls not top try
target_sequence_multi, // double [][][][] target_sequence_multi target_sequence_multi, // double [][][][] target_sequence_multi
filter5); // boolean [][] filter5) filter5); // boolean [][] filter5)
...@@ -8756,15 +8777,32 @@ public class CuasMotion { ...@@ -8756,15 +8777,32 @@ public class CuasMotion {
ImagePlus imp_novl = showTargetSequence( ImagePlus imp_novl = showTargetSequence(
targets_nonoverlap, // double [][][] vector_fields_sequence, targets_nonoverlap, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-SELECTED-TO-TRY-CENTERED-n"+niter,// String title, model_prefix+"-SELECTED-TO-TRY-CENTERED-n"+cuasMotion.when_fail,// String title,
!batch_mode, // boolean show, !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_novl); parentCLT.saveImagePlusInModelDirectory(imp_novl);
} }
*/
int num_new = 0; int num_new = 0;
boolean need_sel_to_try = true;
double effective_boost = boost_accum_pairs; // default virtual exposure scale double effective_boost = boost_accum_pairs; // default virtual exposure scale
if (accum_boosted) { if (accum_boosted) {
double [][][] targets_nonoverlap = applyFilter( // motion vectors // will have nulls not top try
target_sequence_multi, // double [][][][] target_sequence_multi
filter5); // boolean [][] filter5)
if (save_filtered_low && debug_more && need_sel_to_try) {
// targets_nonoverlap will contain motion vectors used fro the next fpixels_accumulated
ImagePlus imp_novl = showTargetSequence(
targets_nonoverlap, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-SELECTED-TO-TRY-CENTERED-n"+cuasMotion.when_fail,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_novl);
need_sel_to_try = false;
}
// Andrey 05/05/2026 moved here (earlier) so shiftAndRenderAccumulate() will use updated motion vector // 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 // By Claude on 05/05/2026 — re-correlate with spatial mask around known target
if (recalc_mv_num > 0) { if (recalc_mv_num > 0) {
...@@ -8791,7 +8829,7 @@ public class CuasMotion { ...@@ -8791,7 +8829,7 @@ public class CuasMotion {
speed_pref, // double speed_pref, speed_pref, // double speed_pref,
speed_boost, // double speed_boost); speed_boost, // double speed_boost);
"-first", // String dbg_suffix, "-first", // String dbg_suffix,
niter - niter0, // int dbg_iter_index, cuasMotion.when_fail, // int dbg_iter_index,
debugLevel); // -1); // debugLevel); // int debugLevel) debugLevel); // -1); // debugLevel); // int debugLevel)
if (recalc_mv_num > 1) { if (recalc_mv_num > 1) {
refineMotionVectors( // just testing conversion refineMotionVectors( // just testing conversion
...@@ -8815,10 +8853,20 @@ public class CuasMotion { ...@@ -8815,10 +8853,20 @@ public class CuasMotion {
speed_pref, // double speed_pref, speed_pref, // double speed_pref,
speed_boost, // double speed_boost); speed_boost, // double speed_boost);
"-second", // String dbg_suffix, "-second", // String dbg_suffix,
niter - niter0, // int dbg_iter_index, cuasMotion.when_fail,// int dbg_iter_index,
debugLevel); // -1); // debugLevel); // int debugLevel) debugLevel); // -1); // debugLevel); // int debugLevel)
} }
} }
boolean debug_extra = debugLevel > -5;
if (save_filtered_low && debug_more && debug_extra) {
ImagePlus imp_ext = showTargetSequence(
targets_nonoverlap, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-BEFORE-EXTENDED-CENTERED-n"+cuasMotion.when_fail,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_ext);
}
double [][][] extended_scan = extendMotionScan( double [][][] extended_scan = extendMotionScan(
targets_nonoverlap, // final double [][][] motion_scan, targets_nonoverlap, // final double [][][] motion_scan,
null, // filter5, // final boolean [][] filtered, // centers, should be non-overlapped null, // filter5, // final boolean [][] filtered, // centers, should be non-overlapped
...@@ -8829,7 +8877,7 @@ public class CuasMotion { ...@@ -8829,7 +8877,7 @@ public class CuasMotion {
ImagePlus imp_ext = showTargetSequence( ImagePlus imp_ext = showTargetSequence(
extended_scan, // double [][][] vector_fields_sequence, extended_scan, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-EXTENDED-CENTERED-n"+niter,// String title, model_prefix+"-EXTENDED-CENTERED-n"+cuasMotion.when_fail,// String title,
!batch_mode, // boolean show, !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_ext); parentCLT.saveImagePlusInModelDirectory(imp_ext);
...@@ -8851,7 +8899,7 @@ public class CuasMotion { ...@@ -8851,7 +8899,7 @@ public class CuasMotion {
corr_offset, // int corr_offset, // interframe distance for correlation corr_offset, // int corr_offset, // interframe distance for correlation
save_filtered_high, // boolean save_filtered_high, save_filtered_high, // boolean save_filtered_high,
model_prefix, // String model_prefix, model_prefix, // String model_prefix,
niter, // int niter, cuasMotion.when_fail,// int niter,
input_range, // double input_range, input_range, // double input_range,
lmax_fraction, // double lmax_fraction, lmax_fraction, // double lmax_fraction,
...@@ -8923,14 +8971,28 @@ public class CuasMotion { ...@@ -8923,14 +8971,28 @@ public class CuasMotion {
targets_new_multi, // final double [][][] new_sequence, targets_new_multi, // final double [][][] new_sequence,
// add just one best here? // add just one best here?
1, // final int num_best, // if >0, limit number of best results to add 1, // final int num_best, // if >0, limit number of best results to add
niter, // final int when_iter, cuasMotion.when_fail, // final int when_iter,
debugLevel); // final int debugLevel); debugLevel); // final int debugLevel);
if (debugLevel > -4) { if (debugLevel > -4) {
System.out.println("Added "+num_new+" new tiles as good/bad at boosted iteration "+niter+"."); System.out.println("Added "+num_new+" new tiles as good/bad at boosted iteration "+cuasMotion.when_fail+".");
} }
} }
if (accum_base) { if (accum_base) {
double [][][] targets_nonoverlap = applyFilter( // motion vectors // will have nulls not top try
target_sequence_multi, // double [][][][] target_sequence_multi
filter5); // boolean [][] filter5)
if (save_filtered_low && debug_more && need_sel_to_try) {
// targets_nonoverlap will contain motion vectors used fro the next fpixels_accumulated
ImagePlus imp_novl = showTargetSequence(
targets_nonoverlap, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-SELECTED-TO-TRY-CENTERED-n"+cuasMotion.when_fail,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_novl);
}
// Andrey 05/05/2026 moved here (earlier) so shiftAndRenderAccumulate() will use updated motion vector // 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 // By Claude on 05/05/2026 — re-correlate with spatial mask around known target
if (recalc_mv_num > 0) { if (recalc_mv_num > 0) {
...@@ -8955,7 +9017,7 @@ public class CuasMotion { ...@@ -8955,7 +9017,7 @@ public class CuasMotion {
speed_pref, // double speed_pref, speed_pref, // double speed_pref,
speed_boost, // double speed_boost); speed_boost, // double speed_boost);
"-first", // String dbg_suffix, "-first", // String dbg_suffix,
niter - niter0, // int dbg_iter_index, cuasMotion.when_fail, // int dbg_iter_index,
debugLevel); // -1); // debugLevel); // int debugLevel) debugLevel); // -1); // debugLevel); // int debugLevel)
if (recalc_mv_num > 1) { if (recalc_mv_num > 1) {
refineMotionVectors( refineMotionVectors(
...@@ -8979,7 +9041,7 @@ public class CuasMotion { ...@@ -8979,7 +9041,7 @@ public class CuasMotion {
speed_pref, // double speed_pref, speed_pref, // double speed_pref,
speed_boost, // double speed_boost); speed_boost, // double speed_boost);
"-second", // String dbg_suffix, "-second", // String dbg_suffix,
niter - niter0, // int dbg_iter_index, cuasMotion.when_fail, // int dbg_iter_index,
debugLevel); // -1); // debugLevel); // int debugLevel) debugLevel); // -1); // debugLevel); // int debugLevel)
} }
} }
...@@ -8993,7 +9055,7 @@ public class CuasMotion { ...@@ -8993,7 +9055,7 @@ public class CuasMotion {
ImagePlus imp_ext = showTargetSequence( ImagePlus imp_ext = showTargetSequence(
extended_scan, // double [][][] vector_fields_sequence, extended_scan, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-EXTENDED-CENTERED-n"+niter,// String title, model_prefix+"-EXTENDED-CENTERED-n"+cuasMotion.when_fail,// String title,
!batch_mode, // boolean show, !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_ext); parentCLT.saveImagePlusInModelDirectory(imp_ext);
...@@ -9014,7 +9076,7 @@ public class CuasMotion { ...@@ -9014,7 +9076,7 @@ public class CuasMotion {
corr_offset, // int corr_offset, // interframe distance for correlation corr_offset, // int corr_offset, // interframe distance for correlation
save_filtered_high, // boolean save_filtered_high, save_filtered_high, // boolean save_filtered_high,
model_prefix, // String model_prefix, model_prefix, // String model_prefix,
niter, // int niter, cuasMotion.when_fail,// int niter,
input_range, // double input_range, input_range, // double input_range,
lmax_fraction, // double lmax_fraction, lmax_fraction, // double lmax_fraction,
...@@ -9083,19 +9145,19 @@ public class CuasMotion { ...@@ -9083,19 +9145,19 @@ public class CuasMotion {
debugLevel); // int debugLevel); debugLevel); // int debugLevel);
//int //int
num_new += addNewResults( int num_new1 = addNewResults(
target_sequence_multi, // final double [][][] target_sequence, // will only process non-nulls here target_sequence_multi, // final double [][][] target_sequence, // will only process non-nulls here
targets_new_multi, // final double [][][] new_sequence, targets_new_multi, // final double [][][] new_sequence,
// add just one best here? // add just one best here?
1, // final int num_best, // if >0, limit number of best results to add 1, // final int num_best, // if >0, limit number of best results to add
niter, // final int when_iter, cuasMotion.when_fail, // final int when_iter,
debugLevel); // final int debugLevel); debugLevel); // final int debugLevel);
num_new += num_new1;
if (debugLevel > -4) { if (debugLevel > -4) {
System.out.println("Added "+num_new+" new tiles as good/bad at base iteration "+niter+"."); System.out.println("Added "+num_new1+" new tiles as good/bad at base iteration "+cuasMotion.when_fail+".");
} }
if (save_filtered_low) { if (save_filtered_low) {
String title = model_prefix+"-ADDED_NEW_CENTERED_MULTI-n"+niter; String title = model_prefix+"-ADDED_NEW_CENTERED_MULTI-n"+cuasMotion.when_fail;
title+="-BOOST"+effective_boost+"-NOBOOST"; // boost_accum_pairs; title+="-BOOST"+effective_boost+"-NOBOOST"; // boost_accum_pairs;
ImagePlus imp_new_scores = showTargetSequence( ImagePlus imp_new_scores = showTargetSequence(
target_sequence_multi, // double [][][] vector_fields_sequence, target_sequence_multi, // double [][][] vector_fields_sequence,
...@@ -9122,10 +9184,10 @@ public class CuasMotion { ...@@ -9122,10 +9184,10 @@ public class CuasMotion {
num_good, // int [] num_good_in, num_good, // int [] num_good_in,
num_bad); // int [] num_bad_in) num_bad); // int [] num_bad_in)
if (debugLevel > -4) printStats ("After centered iteration "+niter, true, num_all, num_undef, num_good, num_bad); if (debugLevel > -4) printStats ("After centered iteration "+cuasMotion.when_fail, true, num_all, num_undef, num_good, num_bad);
if (debugLevel > -4) { if (debugLevel > -4) {
System.out.print((new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime())+": ")); System.out.print((new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime())+": "));
System.out.println("Centered iteration "+niter+" DONE.\n"); System.out.println("Centered iteration "+cuasMotion.when_fail+" DONE.\n");
} }
} //for (niter=0; niter < max_iter; niter++) } //for (niter=0; niter < max_iter; niter++)
boolean good_only= false; boolean good_only= false;
...@@ -9741,7 +9803,8 @@ public class CuasMotion { ...@@ -9741,7 +9803,8 @@ public class CuasMotion {
// mark all "used" targets (non-centered, after all centered are added) as failed // mark all "used" targets (non-centered, after all centered are added) as failed
public static void failUsed( public static void failUsed(
final double [][][][] target_sequence) { final double [][][][] target_sequence,
final int when_fail) {
final int num_seq = target_sequence.length; final int num_seq = target_sequence.length;
final int num_tiles = target_sequence[0].length; final int num_tiles = target_sequence[0].length;
final Thread[] threads = ImageDtt.newThreadArray(); final Thread[] threads = ImageDtt.newThreadArray();
...@@ -9757,6 +9820,7 @@ public class CuasMotion { ...@@ -9757,6 +9820,7 @@ public class CuasMotion {
double [] target = target_sequence[nSeq][ntile][ntarg]; double [] target = target_sequence[nSeq][ntile][ntarg];
if ((target != null) && (target[CuasMotionLMA.RSLT_FAIL] == CuasMotionLMA.FAIL_NONE) && (target[CuasMotionLMA.RSLT_CENTERED] == CuasMotionLMA.CENTERED_USED)) { if ((target != null) && (target[CuasMotionLMA.RSLT_FAIL] == CuasMotionLMA.FAIL_NONE) && (target[CuasMotionLMA.RSLT_CENTERED] == CuasMotionLMA.CENTERED_USED)) {
target[CuasMotionLMA.RSLT_FAIL] = CuasMotionLMA.FAIL_USED; target[CuasMotionLMA.RSLT_FAIL] = CuasMotionLMA.FAIL_USED;
target[CuasMotionLMA.RSLT_WHEN] = when_fail;
} }
} }
} }
...@@ -10373,7 +10437,9 @@ public class CuasMotion { ...@@ -10373,7 +10437,9 @@ public class CuasMotion {
} }
// Used non-centered tiles are not needed anymore, mark them as failed to simplify processing // Used non-centered tiles are not needed anymore, mark them as failed to simplify processing
failUsed(targets_multi); // final double [][][][] target_sequence) { if (debugLevel > -4) System.out.println("Using "+cuasMotion.when_fail+" for RSLT_WHEN in failUsed()");
failUsed(targets_multi, // final double [][][][] target_sequence) {
cuasMotion.when_fail++ ); // final int when_fail);
boolean debug_extra = debugLevel > -5; boolean debug_extra = debugLevel > -5;
if (intermed_low && debug_more && debug_extra) { if (intermed_low && debug_more && debug_extra) {
ImagePlus imp_dup = showTargetSequence( ImagePlus imp_dup = showTargetSequence(
...@@ -10401,10 +10467,12 @@ public class CuasMotion { ...@@ -10401,10 +10467,12 @@ public class CuasMotion {
cuasMotion.tilesX); // int tilesX) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_dup); parentCLT.saveImagePlusInModelDirectory(imp_dup);
} }
// Will not mark as failed for duplicates - implement?
if (debugLevel > -4) System.out.println("Using "+cuasMotion.when_fail+" for RSLT_WHEN in removeWeakerDuplicates()");
int [] num_duplicates = removeWeakerDuplicates( // needs sortMultiTargets and after int [] num_duplicates = removeWeakerDuplicates( // needs sortMultiTargets and after
targets_multi, // final double [][][][] target_multi, targets_multi, // final double [][][][] target_multi,
duplicate_tolerance); // final double pix_tolerance) duplicate_tolerance, // final double pix_tolerance)
cuasMotion.when_fail++); // final int when_fail)
if (intermed_low && debug_more && debug_extra) { if (intermed_low && debug_more && debug_extra) {
ImagePlus imp_dup = showTargetSequence( ImagePlus imp_dup = showTargetSequence(
targets_multi, // double [][][] vector_fields_sequence, targets_multi, // double [][][] vector_fields_sequence,
...@@ -10539,11 +10607,16 @@ public class CuasMotion { ...@@ -10539,11 +10607,16 @@ public class CuasMotion {
} }
// apply filter5 to targets_good // apply filter5 to targets_good
findStrongerNeighbor(// does not modify "when" if (debugLevel > -4) System.out.println("Using "+cuasMotion.when_fail+" for RSLT_WHEN in findStrongerNeighbor()");
findStrongerNeighbor(// does not modify "when" - now 05.30.2026 does
targets_multi, // final double [][][][] target_multi, targets_multi, // final double [][][][] target_multi,
filter5, // final boolean [][] filter5) filter5, // final boolean [][] filter5)
true, // false, // final boolean mark_failed, true, // false, // final boolean mark_failed,
cuasMotion.when_fail++, // final int when_fail,
cuasMotion.tilesX); // final int tilesX) { cuasMotion.tilesX); // final int tilesX) {
if (intermed_low && debug_more) { if (intermed_low && debug_more) {
ImagePlus imp_neibs = showTargetSequence( ImagePlus imp_neibs = showTargetSequence(
targets_multi, // double [][][] vector_fields_sequence, targets_multi, // double [][][] vector_fields_sequence,
...@@ -10657,6 +10730,7 @@ public class CuasMotion { ...@@ -10657,6 +10730,7 @@ public class CuasMotion {
final double [][][][] target_multi, final double [][][][] target_multi,
final int [][] filter5, final int [][] filter5,
final boolean mark_failed, final boolean mark_failed,
final int when_fail,
final int tilesX) { final int tilesX) {
final int range = 2; final int range = 2;
final int num_seq = target_multi.length; final int num_seq = target_multi.length;
...@@ -10701,6 +10775,7 @@ public class CuasMotion { ...@@ -10701,6 +10775,7 @@ public class CuasMotion {
} }
if (mark_failed && (filter5[nSeq][ntile] != ntarg)) { if (mark_failed && (filter5[nSeq][ntile] != ntarg)) {
targets[ntarg][CuasMotionLMA.RSLT_FAIL] = CuasMotionLMA.FAIL_NEIGHBOR; targets[ntarg][CuasMotionLMA.RSLT_FAIL] = CuasMotionLMA.FAIL_NEIGHBOR;
targets[ntarg][CuasMotionLMA.RSLT_WHEN] = when_fail;
} }
} }
} }
...@@ -10777,10 +10852,6 @@ public class CuasMotion { ...@@ -10777,10 +10852,6 @@ public class CuasMotion {
motion_sequence_fast, // double [][][] target_sequence, motion_sequence_fast, // double [][][] target_sequence,
false, // boolean slow_mode, false, // boolean slow_mode,
debugLevel); // final int debugLevel) debugLevel); // final int debugLevel)
double [][][][] targets_good_multi = targets_fast; double [][][][] targets_good_multi = targets_fast;
/* /*
* Before running with slow_en== true, verify temporal (scene) offset between slow and fast mode. * Before running with slow_en== true, verify temporal (scene) offset between slow and fast mode.
...@@ -10812,6 +10883,7 @@ public class CuasMotion { ...@@ -10812,6 +10883,7 @@ public class CuasMotion {
targets_slow, // final double [][][][] targets_slow, targets_slow, // final double [][][][] targets_slow,
slow_score); // final double scale_slow){ // if >0, limit number of best results to add slow_score); // final double scale_slow){ // if >0, limit number of best results to add
} }
this.when_fail = CuasMotion.WHEN_FINISH;
sortMultiTargets( // maybe only needed after slow branch? sortMultiTargets( // maybe only needed after slow branch?
targets_good_multi, // final double [][][][] target_multi, targets_good_multi, // final double [][][][] target_multi,
...@@ -10824,9 +10896,6 @@ public class CuasMotion { ...@@ -10824,9 +10896,6 @@ public class CuasMotion {
fpixels, // float [][] fpixels, fpixels, // float [][] fpixels,
targets_good_multi, // double [][][][] targets_good_multi, // all targets, including conflicting targets_good_multi, // double [][][][] targets_good_multi, // all targets, including conflicting
debugLevel); // final int debugLevel) debugLevel); // final int debugLevel)
} }
setTargets(targets_nonconflict); setTargets(targets_nonconflict);
return; return;
......
...@@ -166,7 +166,7 @@ public class CuasMotionLMA { ...@@ -166,7 +166,7 @@ public class CuasMotionLMA {
"Phase1-index","Phase1-score","Phase1-amplitude","Phase1-mscore","Phase1-vstr", "Phase1-index","Phase1-score","Phase1-amplitude","Phase1-mscore","Phase1-vstr",
"Phase1-vboost", "Phase1-exp_boost"}; "Phase1-vboost", "Phase1-exp_boost"};
public static final String EXTRA_SLICE_DISCARD_ON_LOAD = "Targets"; public static final String EXTRA_SLICE_DISCARD_ON_LOAD = "Targets";
public static final int FAIL_PENDING = -1; // By Claude on 05/07/2026: motion sentinel — tile tracked but not yet processed by LMA // public static final int FAIL_PENDING = -1; // By Claude on 05/07/2026: motion sentinel — tile tracked but not yet processed by LMA
public static final int FAIL_NONE = 0; public static final int FAIL_NONE = 0;
public static final int FAIL_MOTION = 1; // motion strength/fraction too low, also - motion score too low public static final int FAIL_MOTION = 1; // motion strength/fraction too low, also - motion score too low
public static final int FAIL_NO_MAX = 2; // no suitable local maximum public static final int FAIL_NO_MAX = 2; // no suitable local maximum
......
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