Commit a57f2dfc authored by Andrey Filippov's avatar Andrey Filippov

Claude: refineMotionVectors() — improved debug images

- Masked frames: replace single-frame display with full fmin..fmax stack
  (scene_titles used as slice labels; scroll to watch target stay in place)
- Source frame display removed (not needed alongside masked stack)
- Single-tile corr2d block removed; replaced by full CORR2D multi-slice image
  after the nseq loop — one slice per keyframe, same tiled layout as *CORR2D.tiff,
  slice-labeled from scene_titles, uses corr_border_contrast from CLTParameters
Co-Authored-By: 's avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent 872107bf
...@@ -1560,6 +1560,15 @@ public class CuasMotion { ...@@ -1560,6 +1560,15 @@ public class CuasMotion {
} }
return multi_targets; return multi_targets;
} }
public static double [][][][] readDoubleHyperHyperstack( // slices should contain two ":"
String path){
return readDoubleHyperHyperstack(
path, // String path,
null, // int [] wh, // should be null or int[2]
null, // String [][] ptop_titles, // should be null or String [1][]
null, // String [][] pslice_titles, // should be null or String [1][]
null); // int [] err_num_ext); }
}
public static double [][][][] readDoubleHyperHyperstack( // slices should contain two ":" public static double [][][][] readDoubleHyperHyperstack( // slices should contain two ":"
String path, String path,
...@@ -1577,10 +1586,13 @@ public class CuasMotion { ...@@ -1577,10 +1586,13 @@ public class CuasMotion {
err_num[0] = 1; err_num[0] = 1;
return null; return null;
} }
if (wh!= null) { if (wh == null) {
wh = new int[2];
}
// if (wh!= null) {
wh[0] = imp.getWidth(); wh[0] = imp.getWidth();
wh[1] = imp.getHeight(); wh[1] = imp.getHeight();
} // }
int num_slices = imp.getStackSize(); int num_slices = imp.getStackSize();
String [] slice_labels = imp.getStack().getSliceLabels(); String [] slice_labels = imp.getStack().getSliceLabels();
...@@ -1925,121 +1937,7 @@ public class CuasMotion { ...@@ -1925,121 +1937,7 @@ public class CuasMotion {
return effective_strength; return effective_strength;
} }
public static boolean [][] filter5Targets( // should work for motion vectors and target coordinates
final double [][][] target_sequence,
final boolean use_motion, // true - use motion vectors confidence, false - use target confidence
final boolean select_new, // true - use only untested tiles, false - use good tiles
final double min_confidence, // 0 OK
final double lma_horizon, // target below horizon
final int tilesX,
final int range, // 1 or 2
final int [] remain,
final int [] passes, // debugging - number of passes required
final int debugLevel){
final int conf_index = use_motion ? CuasMotionLMA.RSLT_MSCORE : CuasMotionLMA.RSLT_QSCORE;
final int num_seq = target_sequence.length;
final int num_tiles = target_sequence[0].length;
final int tilesY = num_tiles/ tilesX;
final boolean [][] filter5 = new boolean [num_seq][num_tiles];
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
final int dbg_tile = -(38+45*80);
final int dbg_seq0 = 13;
final int dbg_seq1 = 14;
final int ihorizon = (lma_horizon > 0) ?( (int) Math.ceil(lma_horizon/GPUTileProcessor.DTT_SIZE)) : -1; // tiles with tileY >= ihorizon are removed
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
TileNeibs tn = new TileNeibs(tilesX, tilesY);
boolean [] prohibit = new boolean [num_tiles];
for (int nSeq = ai.getAndIncrement(); nSeq < num_seq; nSeq = ai.getAndIncrement()) {
double [][] targets = target_sequence[nSeq];
int num_total = 0;
Arrays.fill(prohibit, false);
for (int ntile = 0; ntile < num_tiles; ntile++) {
/// if ((targets[ntile] == null) || !(targets[ntile][conf_index] >= min_confidence) || (targets[ntile][CuasMotionLMA.RSLT_FAIL] > 0)) { // added failed
if ((targets[ntile] == null) ||
!(targets[ntile][conf_index] >= min_confidence) ||
(select_new ? !Double.isNaN(targets[ntile][CuasMotionLMA.RSLT_FAIL]) : (targets[ntile][CuasMotionLMA.RSLT_FAIL] > 0))) { // defined: good or bad
if ((ntile == dbg_tile) && (nSeq >= dbg_seq0) && (nSeq <= dbg_seq1)) {
System.out.println("filter5Targets()):0: ntile="+ntile+", nSeq="+nSeq);
}
prohibit[ntile] = true;
}
}
if ((ihorizon > 0) && (ihorizon < tilesY)) {
Arrays.fill(prohibit, ihorizon*tilesX, num_tiles, true);
}
int num_this_pass = 0;
int npass = 0;
do {
npass++;
num_this_pass = 0;
for (int tileY = 0; tileY < tilesY; tileY++) {
for (int tileX = 0; tileX < tilesX; tileX++) {
int ntile = tileX + tilesX * tileY;
if ((ntile == dbg_tile) && (nSeq >= dbg_seq0) && (nSeq <= dbg_seq1)) {
System.out.println("filter5Targets()):1: ntile="+ntile+", nSeq="+nSeq+", npass="+npass+", num_this_pass="+num_this_pass+", num_total="+num_total);
}
// if ((conf[ntile] > 0.0) && !prohibit[ntile]) {
if (!prohibit[ntile]) { // targets[ntile][conf_index] >0 here by the prohibit preset
boolean ismax = true;
check_max:{
double cval = targets[ntile][conf_index] - min_confidence;
if (cval <= 0) {
ismax = false;
prohibit[ntile] = true; // not needed
break check_max;
}
for (int dy = -range; dy <= range; dy++) {
for (int dx = -range; dx <= range; dx++) {
int indx = tn.getNeibIndex(ntile, dx, dy);
if ((indx >= 0) && !prohibit[indx]) {
// double val = conf[indx]- min_confidence;
double val = targets[indx][conf_index]- min_confidence;
if (val > cval) {
ismax = false;
break check_max;
}
}
}
}
}
if (ismax) {
filter5[nSeq][ntile] = true; // ismax;
// prohibit all around, including this one
for (int dy = -range; dy <= range; dy++) {
for (int dx = -range; dx <= range; dx++) {
int indx = tn.getNeibIndex(ntile, dx, dy);
if (indx >= 0) { // && ((filtered == null) || !filtered[nSeq][indx])){
prohibit[indx] = true;
}
}
}
num_this_pass++;
}
}
}
}
num_total+=num_this_pass;
} while (num_this_pass > 0);
if (remain != null) {
remain[nSeq] = num_total;
}
if (passes != null) {
passes[nSeq] = npass;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return filter5;
}
private static void setBadHorizon( private static void setBadHorizon(
final double [][][] target_sequence, final double [][][] target_sequence,
final double horizon_y, final double horizon_y,
...@@ -2314,7 +2212,7 @@ public class CuasMotion { ...@@ -2314,7 +2212,7 @@ public class CuasMotion {
// 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 = 20; // -1; final int dbg_nseq = 20; // -1;
final int dbg_tile = 51+38*80; // -1; final int dbg_tile = 50+38*80; // -1;
// Pre-compute integer-pixel raised-cosine mask kernel once (shared across all nseq) // Pre-compute integer-pixel raised-cosine mask kernel once (shared across all nseq)
final int r1i = (int) Math.ceil(recalc_mv_r1); final int r1i = (int) Math.ceil(recalc_mv_r1);
...@@ -2339,6 +2237,10 @@ public class CuasMotion { ...@@ -2339,6 +2237,10 @@ public class CuasMotion {
final float[][] fpixels_masked = new float[nframes][width * height]; final float[][] fpixels_masked = new float[nframes][width * height];
final Thread[] threads = ImageDtt.newThreadArray(); final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0);
final boolean show_dbg = (dbg_nseq >= 0 || dbg_tile >= 0) && debugLevel >= 0;
// Collect per-nseq correlation for end-of-method CORR2D stack
final double[][][] corr2d_ref = show_dbg ? new double[targets_nonoverlap.length][][] : null;
final String[] scene_titles_all = cuasMotion.getSceneTitles();
for (int nseq = 0; nseq < targets_nonoverlap.length; nseq++) { for (int nseq = 0; nseq < targets_nonoverlap.length; nseq++) {
// Skip scan positions where no target has a known centroid yet // Skip scan positions where no target has a known centroid yet
...@@ -2420,13 +2322,19 @@ public class CuasMotion { ...@@ -2420,13 +2322,19 @@ public class CuasMotion {
} }
ImageDtt.startAndJoin(threads); ImageDtt.startAndJoin(threads);
// Debug: show the masked source frame at frame_center for this scan // Debug: show full fmin..fmax masked frame stack for dbg_nseq
if (nseq == dbg_nseq && debugLevel >= 0) { if (nseq == dbg_nseq && debugLevel >= 0) {
int f_show = Math.max(fmin_alloc, Math.min(fmax_alloc, frame_center)); int fcount = fmax_alloc - fmin_alloc + 1;
ShowDoubleFloatArrays.showArrays(fpixels_masked[f_show].clone(), width, height, float[][] stack_slices = new float[fcount][];
"refineMotionVectors-masked-nseq" + nseq + "-f" + f_show); String[] stack_titles = new String[fcount];
ShowDoubleFloatArrays.showArrays(fpixels[f_show], width, height, for (int fi = 0; fi < fcount; fi++) {
"refineMotionVectors-source-nseq" + nseq + "-f" + f_show); stack_slices[fi] = fpixels_masked[fmin_alloc + fi].clone();
int f = fmin_alloc + fi;
stack_titles[fi] = (scene_titles_all != null && f < scene_titles_all.length)
? scene_titles_all[f] : "f" + f;
}
ShowDoubleFloatArrays.showArrays(stack_slices, width, height, true,
"refineMotionVectors-masked-nseq" + nseq, stack_titles);
} }
TDCorrTile[] tdCorrTiles = cuasMotion.correlatePairs( TDCorrTile[] tdCorrTiles = cuasMotion.correlatePairs(
...@@ -2447,6 +2355,9 @@ public class CuasMotion { ...@@ -2447,6 +2355,9 @@ public class CuasMotion {
0xFE, 0xFE,
fat_zero * scale_fat_zero, fat_zero * scale_fat_zero,
debugLevel); debugLevel);
if (corr2d_ref != null) {
corr2d_ref[nseq] = corr_tiles_pd;
}
double[][] vector_field = TDCorrTile.getMismatchVector( double[][] vector_field = TDCorrTile.getMismatchVector(
corr_tiles_pd, corr_tiles_pd,
...@@ -2455,15 +2366,6 @@ public class CuasMotion { ...@@ -2455,15 +2366,6 @@ public class CuasMotion {
n_recenter, n_recenter,
true); true);
// Debug: show 2D correlation tile for the debug tile
if (nseq == dbg_nseq && dbg_tile >= 0 && dbg_tile < corr_tiles_pd.length
&& corr_tiles_pd[dbg_tile] != null && debugLevel >= 0) {
int corr_side = 2 * GPUTileProcessor.DTT_SIZE - 1; // 15
float[] corr_img = new float[corr_side * corr_side];
for (int i = 0; i < corr_img.length; i++) corr_img[i] = (float) corr_tiles_pd[dbg_tile][i];
ShowDoubleFloatArrays.showArrays(corr_img, corr_side, corr_side,
"refineMotionVectors-corr2d-nseq" + nseq + "-tile" + dbg_tile);
}
// Add differential MV to targets_nonoverlap in-place // Add differential MV to targets_nonoverlap in-place
for (int ntile = 0; ntile < targets_nonoverlap[nseq].length; ntile++) { for (int ntile = 0; ntile < targets_nonoverlap[nseq].length; ntile++) {
...@@ -2480,6 +2382,28 @@ public class CuasMotion { ...@@ -2480,6 +2382,28 @@ public class CuasMotion {
target[CuasMotionLMA.RSLT_VY] += vector_field[ntile][INDX_VY]; target[CuasMotionLMA.RSLT_VY] += vector_field[ntile][INDX_VY];
} }
} }
// Debug: CORR2D overview — one slice per keyframe, same layout as *CORR2D.tiff
if (show_dbg && corr2d_ref != null) {
final int corr_size = 2 * GPUTileProcessor.DTT_SIZE - 1; // 15
String[] slice_titles_ref = new String[targets_nonoverlap.length];
for (int i = 0; i < targets_nonoverlap.length; i++) {
int frame_center = frame0 + i * corr_inc;
slice_titles_ref[i] = (scene_titles_all != null && frame_center < scene_titles_all.length)
? scene_titles_all[frame_center] : "nseq" + i;
}
double[][] dbg_2d_corrs = ImageDtt.corr_partial_dbg(
corr2d_ref,
cuasMotion.tilesX,
corr_size,
clt_parameters.corr_border_contrast,
debugLevel);
ShowDoubleFloatArrays.makeArrays(
dbg_2d_corrs,
cuasMotion.tilesX * (corr_size + 1),
cuasMotion.tilesY * (corr_size + 1),
"refineMotionVectors-CORR2D",
slice_titles_ref).show();
}
} }
/** /**
...@@ -7921,6 +7845,9 @@ public class CuasMotion { ...@@ -7921,6 +7845,9 @@ public class CuasMotion {
System.out.println("testCuasScanMotion(): wrong format for a pair of strength, fraction values."); System.out.println("testCuasScanMotion(): wrong format for a pair of strength, fraction values.");
} }
} }
boolean reuse_non_centered = true; // make a parameter
double filter_below_horizon=5; double filter_below_horizon=5;
int start_frame = 0; int start_frame = 0;
...@@ -7939,80 +7866,101 @@ public class CuasMotion { ...@@ -7939,80 +7866,101 @@ public class CuasMotion {
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");
// final 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
if (reuse_non_centered) {
String x3d_path = parentCLT.getX3dDirectory();
String noncentered_path = x3d_path + Prefs.getFileSeparator() + model_prefix+"-ROUND_ONE"+".tiff";
target_sequence_multi = readDoubleHyperHyperstack( // slices should contain two ":"
noncentered_path); // String path,
if (debugLevel > -4) {
if (target_sequence_multi!= null) {
System.out.println("locateAndFreezeTargetsMulti(): reusing non-centered data from "+noncentered_path);
} else {
System.out.println("locateAndFreezeTargetsMulti(): non-centered data not found: "+noncentered_path);
System.out.println("Will calculate and save non-centered targets");
}
}
// niter = 19; //
}
final int num_seq = motion_sequence.length; final int num_seq = motion_sequence.length;
final int num_tiles = motion_sequence[0].length; final int num_tiles = motion_sequence[0].length;
final double [][][][] target_sequence_multi = new double [num_seq][num_tiles][][]; if (target_sequence_multi == null) {
int niter=0; // final double [][][][]
// first pass, using non-centered targets target_sequence_multi = new double [num_seq][num_tiles][][];
// double boost_accum_pairs = slow_mode? 1.0:4.0; // just for testing, unconditionally boost tracking cameras exposure time // first pass, using non-centered targets
for (; niter < num_cycles; niter++) { // double boost_accum_pairs = slow_mode? 1.0:4.0; // just for testing, unconditionally boost tracking cameras exposure time
boolean save_filtered_low = intermed_low && (niter < iter_show); for (; niter < num_cycles; niter++) {
boolean save_filtered_high = intermed_high && (niter < iter_show); boolean save_filtered_low = intermed_low && (niter < iter_show);
totals = getRemain(motion_sequence, target_sequence_multi, num_all, num_undef, num_good, num_bad); boolean save_filtered_high = intermed_high && (niter < iter_show);
if (totals[TOTALS_UNDEFINED] == 0) { totals = getRemain(motion_sequence, target_sequence_multi, num_all, num_undef, num_good, num_bad);
if (debugLevel > -4) System.out.println ("No undefined tiles left, breaking loop"); if (totals[TOTALS_UNDEFINED] == 0) {
break; if (debugLevel > -4) System.out.println ("No undefined tiles left, breaking loop");
} break;
if (save_filtered_low && debug_more) {
ImagePlus imp_ms1 = showTargetSequence(
motion_sequence, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-MS1-n"+niter,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_ms1);
}
// double [][] effective_strength =
// ==== does it need to be re-calculated ? =====
getEffectiveStrengthMV( // calculate tiles effective strength by the motion vectors. Combine with the target LMA?
motion_sequence, // final double [][][] motion_scan,
niter, // int niter, // save iteration number on failure if >=
cuasMotion.tilesX, // final int tilesX)
0, // final double min_score_mv,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost); // double speed_boost);
if (save_filtered_low && debug_more) {
ImagePlus imp_mv_strength = showTargetSequence(
motion_sequence, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-MV_STRENGTH-n"+niter,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_mv_strength);
}
int [][] filter5 = filter5Targets( // will ignore failed tiles
motion_sequence, // final double [][][] target_sequence,
target_sequence_multi, // final double [][][][] target_sequence_multi,
// if use motion and select_new will only consider tiles (and compare motion scores in motion_sequence) that have nulls in target_sequence_multi[nseq][ntile]
// if not use motion and select_new will only consider (and compare scores) tiles that have [RSLT_CENTERED] = 0.0
// if not select_new (assumes not use motion) will return best (and good) target indices
true, // final boolean use_motion, // true - use motion vectors confidence, false - use target confidence
true, // final boolean select_new, // true - use only untested tiles, false - use good tiles
min_score_mv, // double min_confidence,
target_horizon, // final double lma_horizon, // target below horizon
cuasMotion.tilesX, // final int tilesX,
max_range, // final int range, // 1 or 2
filter5_remain, // final int [] remain){
passes, // final int [] passes, // debugging - numer of passes required
debugLevel); // final int debugLevel)
boolean good_only= false;
boolean show_empty = true; // false; // show scenes with no (valid) targets
if (save_filtered_low) {
ImagePlus imp_filter5 = ShowDoubleFloatArrays.makeArrays(
filter5,
cuasMotion.tilesX,
cuasMotion.tilesY,
model_prefix+"-FILTER5_SELECTED_MULTI-n"+niter, // Selected to test
slice_titles);
if (!batch_mode) {
imp_filter5.show();
} }
parentCLT.saveImagePlusInModelDirectory(imp_filter5); // ImagePlus imp) if (save_filtered_low && debug_more) {
/* ImagePlus imp_ms1 = showTargetSequence(
motion_sequence, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-MS1-n"+niter,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_ms1);
}
// double [][] effective_strength =
// ==== does it need to be re-calculated ? =====
// Only used in int [][] filter5 = filter5Targets( // will ignore failed tiles
// for centered tile pass, trying to eliminate with null for the motion sequence
getEffectiveStrengthMV( // calculate tiles effective strength by the motion vectors. Combine with the target LMA?
motion_sequence, // final double [][][] motion_scan,
niter, // int niter, // save iteration number on failure if >=
cuasMotion.tilesX, // final int tilesX)
0, // final double min_score_mv,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost); // double speed_boost);
if (save_filtered_low && debug_more) {
ImagePlus imp_mv_strength = showTargetSequence(
motion_sequence, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-MV_STRENGTH-n"+niter,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_mv_strength);
}
int [][] filter5 = filter5Targets( // will ignore failed tiles
motion_sequence, // final double [][][] target_sequence,
target_sequence_multi, // final double [][][][] target_sequence_multi,
// if use motion and select_new will only consider tiles (and compare motion scores in motion_sequence) that have nulls in target_sequence_multi[nseq][ntile]
// if not use motion and select_new will only consider (and compare scores) tiles that have [RSLT_CENTERED] = 0.0
// if not select_new (assumes not use motion) will return best (and good) target indices
true, // final boolean use_motion, // true - use motion vectors confidence, false - use target confidence
true, // final boolean select_new, // true - use only untested tiles, false - use good tiles
min_score_mv, // double min_confidence,
target_horizon, // final double lma_horizon, // target below horizon
cuasMotion.tilesX, // final int tilesX,
max_range, // final int range, // 1 or 2
filter5_remain, // final int [] remain){
passes, // final int [] passes, // debugging - numer of passes required
debugLevel); // final int debugLevel)
boolean good_only= false;
boolean show_empty = true; // false; // show scenes with no (valid) targets
if (save_filtered_low) {
ImagePlus imp_filter5 = ShowDoubleFloatArrays.makeArrays(
filter5,
cuasMotion.tilesX,
cuasMotion.tilesY,
model_prefix+"-FILTER5_SELECTED_MULTI-n"+niter, // Selected to test
slice_titles);
if (!batch_mode) {
imp_filter5.show();
}
parentCLT.saveImagePlusInModelDirectory(imp_filter5); // ImagePlus imp)
/*
ImagePlus imp_target_sequence_multi = showTargetSequence( ImagePlus imp_target_sequence_multi = showTargetSequence(
target_sequence_multi, // final double [][][][] targets_multi, target_sequence_multi, // final double [][][][] targets_multi,
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
...@@ -8022,277 +7970,277 @@ public class CuasMotion { ...@@ -8022,277 +7970,277 @@ public class CuasMotion {
!batch_mode, // boolean show, !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_target_sequence_multi); parentCLT.saveImagePlusInModelDirectory(imp_target_sequence_multi);
*/ */
} }
if (debugLevel > -4) printStatsLine("filter5 remain",true,filter5_remain); if (debugLevel > -4) printStatsLine("filter5 remain",true,filter5_remain);
int filter5_total = getTotal(filter5_remain); int filter5_total = getTotal(filter5_remain);
if (filter5_total == 0) { if (filter5_total == 0) {
if (debugLevel > -4) System.out.println ("No filter5 tiles left, breaking loop"); if (debugLevel > -4) System.out.println ("No filter5 tiles left, breaking loop");
break; break;
} }
// was motion_scan_filtered // was motion_scan_filtered
double [][][] targets_nonoverlap = applyFilter( // motion vectors // will have nulls not top try double [][][] targets_nonoverlap = applyFilter( // motion vectors // will have nulls not top try
motion_sequence, // double [][][] motion_scan, motion_sequence, // double [][][] motion_scan,
filter5); // boolean [][] filter5) filter5); // boolean [][] filter5)
// Here target_sequence_multi is yet empty // Here target_sequence_multi is yet empty
/* /*
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)
*/ */
// Anything remains? we'll see after extension // Anything remains? we'll see after extension
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
cuasMotion.tilesX, // final int tilesX) cuasMotion.tilesX, // final int tilesX)
2, // final int range, // 1 or 2 2, // final int range, // 1 or 2
null); // remain); // final int [] remain) 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(
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-n"+niter,// String title,
!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-n"+niter,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_ext);
// show good and bad accumulated here too?
}
if (save_filtered_low && debug_more) { // perform new accumulations of shifted non-conflicting tiles
float [][] fpixels_accumulated = cuasMotion.shiftAndRenderAccumulate(
// targets_nonoverlap will contain motion vectors used fro the next fpixels_accumulated clt_parameters, // CLTParameters clt_parameters,
ImagePlus imp_novl = showTargetSequence( false, // final boolean center,
targets_nonoverlap, // double [][][] vector_fields_sequence, false, // final boolean fill_zeros,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null fpixels_tum, // final float [][] fpixels,
model_prefix+"-SELECTED-TO-TRY-n"+niter,// String title, extended_scan, // final double [][][] vector_field,
!batch_mode, // boolean show, frame0, // final int frame0, // for vector_field[0]
cuasMotion.tilesX); // int tilesX) { corr_inc, // final int frame_step,
parentCLT.saveImagePlusInModelDirectory(imp_novl); half_accum_range, // final int half_range,
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-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-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)
}
ImagePlus imp_ext = showTargetSequence( // replace center frames with the accumulated ones
extended_scan, // double [][][] vector_fields_sequence, if (debugLevel > -4) {
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null System.out.println("Starting render, iteration = "+niter);
model_prefix+"-EXTENDED-n"+niter,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_ext);
// show good and bad accumulated here too?
}
// perform new accumulations of shifted non-conflicting tiles
float [][] fpixels_accumulated = cuasMotion.shiftAndRenderAccumulate(
clt_parameters, // CLTParameters clt_parameters,
false, // final boolean center,
false, // final boolean fill_zeros,
fpixels_tum, // final float [][] fpixels,
extended_scan, // final double [][][] vector_field,
frame0, // final int frame0, // for vector_field[0]
corr_inc, // final int frame_step,
half_accum_range, // final int half_range,
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-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
} }
ImagePlus imp_acc = ShowDoubleFloatArrays.makeArrays(
fpixels_accumulated, // double[][] pixels, // show just fpixels_accumulated
cuasMotion.gpu_max_width, // move outside? compare to slice_titles known
cuasMotion.gpu_max_height, // Calculate both centroid and LMA target parametes, return both
title, // model_prefix+"-ACCUMULATED-n"+niter, // String title, // targets_new will contain motion vectors, centroid, and LMA results combined
slice_titles); //save_filtered_high
imp_acc.getProcessor().setMinAndMax(-input_range/2, input_range/2); float [][] accum_debug = save_filtered_high? new float [num_corr_samples][]:null; //fpixels_accumulated.length]
if (!batch_mode) { boolean keep_failed = false; // keep failed targets
imp_acc.show(); double [][][][] targets_new_multi = getAccumulatedCoordinatesMulti(
keep_failed, // final boolean keep_failed, // keep failed targets
niter, // final int when, // set if >=0 for failures
false, // 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
centered_radius, // final double centered_radius,
centered_blur, // final double centered_radius_blur,
duplicate_tolerance, // 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-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-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)
} }
parentCLT.saveImagePlusInModelDirectory(imp_acc); // ImagePlus imp)
} if (save_filtered_low && debug_more) {
String title = model_prefix+"-NEW-TARGETS-MULTI-n"+niter;
// replace center frames with the accumulated ones if (boost_accum_pairs > 1.0) {
if (debugLevel > -4) { title+="-BOOST"+boost_accum_pairs;
System.out.println("Starting render, iteration = "+niter); }
} ImagePlus imp_new = showTargetSequence(
targets_new_multi, // final double [][][][] targets_multi,
// show just fpixels_accumulated slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
// move outside? compare to slice_titles known title, // model_prefix+"-NEW-TARGETS-MULTI-n"+niter,// String title,
// Calculate both centroid and LMA target parametes, return both good_only, // final boolean good_only,
// targets_new will contain motion vectors, centroid, and LMA results combined show_empty, // final boolean show_empty, // show scenes with no (valid) targets
//save_filtered_high !batch_mode, // boolean show,
float [][] accum_debug = save_filtered_high? new float [num_corr_samples][]:null; //fpixels_accumulated.length] cuasMotion.tilesX); // int tilesX) {
boolean keep_failed = false; // keep failed targets parentCLT.saveImagePlusInModelDirectory(imp_new); // ImagePlus imp)
double [][][][] targets_new_multi = getAccumulatedCoordinatesMulti(
keep_failed, // final boolean keep_failed, // keep failed targets
niter, // final int when, // set if >=0 for failures
false, // 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
centered_radius, // final double centered_radius,
centered_blur, // final double centered_radius_blur,
duplicate_tolerance, // 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-MULTI-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
} }
ImagePlus imp_acc = ShowDoubleFloatArrays.makeArrays(
accum_debug, // double[][] pixels, // evaluate scores here to reduce the number of attempts for centered targets
cuasMotion.gpu_max_width, getEffectiveStrengthLMA(
cuasMotion.gpu_max_height, targets_new_multi, // final double [][][] target_coords, // LMA
title, // model_prefix+"-ACCUMULATED_FILTERED-MULTI-n"+niter, // String title, target_strength, // final double target_strength,
slice_titles); target_frac, // final double [][] target_frac, // pairs - strength, minimal fraction for that strength
imp_acc.getProcessor().setMinAndMax(-input_range/2, input_range/2); lma_rms, // final double lma_rms, // = 1.5; // Maximal RMS (should always match, regardless if A)
if (!batch_mode) { lma_arms, // final double lma_arms, // = 0.06; // Maximal absolute RMS (should match one of cuas_lma_arms OR cuas_lma_rrms (0.484)
imp_acc.show(); 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,
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_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,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title, // model_prefix+"-NEW-TARGETS_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) {
parentCLT.saveImagePlusInModelDirectory(imp_new_scores); // ImagePlus imp)
} }
parentCLT.saveImagePlusInModelDirectory(imp_acc); // ImagePlus imp)
}
if (save_filtered_low && debug_more) {
String title = model_prefix+"-NEW-TARGETS-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,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title, // model_prefix+"-NEW-TARGETS-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_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,
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_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,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title, // model_prefix+"-NEW-TARGETS_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) {
parentCLT.saveImagePlusInModelDirectory(imp_new_scores); // ImagePlus imp)
}
int num_new = addNewResults( int num_new = 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,
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, niter, // 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"); System.out.println("Added "+num_new+" new tiles as good/bad");
} }
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"+niter;
if (boost_accum_pairs > 1.0) { if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs; title+="-BOOST"+boost_accum_pairs;
} }
ImagePlus imp_new_scores = showTargetSequence(
target_sequence_multi, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title, // model_prefix+"-ADDED_NEW_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_new_scores); // ImagePlus imp)
}
if (num_new == 0) {
if (debugLevel > -4) System.out.println ("Nothing added from last try, breaking the loop.\n");
break; // breaks here
}
totals = getRemain(motion_sequence, target_sequence_multi, num_all, num_undef, num_good, num_bad);
if (debugLevel > -4) printStats ("After iteration "+niter, true, num_all, num_undef, num_good, num_bad);
if (debugLevel > -4) {
System.out.println("Non-centered iteration "+niter+" DONE.\n");
}
} //for (niter=0; niter < max_iter; niter++)
if (intermed_low || reuse_non_centered) {
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
title, // model_prefix+"-ADDED_NEW_MULTI-n"+niter,// String title, model_prefix+"-ROUND_ONE",// String title,
good_only, // final boolean good_only, false, // good_only, // final boolean good_only,
show_empty, // final boolean show_empty, // show scenes with no (valid) targets false, // show_empty, // final boolean show_empty, // show scenes with no (valid) targets
!batch_mode, // boolean show, !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_new_scores); // ImagePlus imp) parentCLT.saveImagePlusInModelDirectory(imp_new_scores); // ImagePlus imp)
} }
if (num_new == 0) {
if (debugLevel > -4) System.out.println ("Nothing added from last try, breaking the loop.\n");
break; // breaks here
}
totals = getRemain(motion_sequence, target_sequence_multi, num_all, num_undef, num_good, num_bad);
if (debugLevel > -4) printStats ("After iteration "+niter, true, num_all, num_undef, num_good, num_bad);
if (debugLevel > -4) {
System.out.println("Non-centered iteration "+niter+" DONE.\n");
}
} //for (niter=0; niter < max_iter; niter++)
if (intermed_low) {
ImagePlus imp_new_scores = showTargetSequence(
target_sequence_multi, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-ROUND_ONE",// String title,
false, // good_only, // final boolean good_only,
false, // show_empty, // final boolean show_empty, // show scenes with no (valid) targets
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_new_scores); // ImagePlus imp)
} }
//=========================================================================== //===========================================================================
if (debugLevel > -4) { if (debugLevel > -4) {
...@@ -8329,7 +8277,7 @@ public class CuasMotion { ...@@ -8329,7 +8277,7 @@ public class CuasMotion {
} }
int [][] filter5 = filter5Targets( // will ignore failed tiles int [][] filter5 = filter5Targets( // will ignore failed tiles
motion_sequence, // final double [][][] target_sequence, null, // motion_sequence, // final double [][][] target_sequence,
target_sequence_multi, // final double [][][][] target_sequence_multi,non-centered marked as "used" target_sequence_multi, // final double [][][][] target_sequence_multi,non-centered marked as "used"
// if use motion and select_new will only consider tiles (and compare motion scores in motion_sequence) that have nulls in target_sequence_multi[nseq][ntile] // if use motion and select_new will only consider tiles (and compare motion scores in motion_sequence) that have nulls in target_sequence_multi[nseq][ntile]
// if not use motion and select_new will only consider (and compare scores) tiles that have [RSLT_CENTERED] = 0.0 // if not use motion and select_new will only consider (and compare scores) tiles that have [RSLT_CENTERED] = 0.0
...@@ -8341,7 +8289,7 @@ public class CuasMotion { ...@@ -8341,7 +8289,7 @@ public class CuasMotion {
cuasMotion.tilesX, // final int tilesX, cuasMotion.tilesX, // final int tilesX,
max_range, // final int range, // 1 or 2 max_range, // final int range, // 1 or 2
filter5_remain, // final int [] remain){ filter5_remain, // final int [] remain){
passes, // final int [] passes, // debugging - numer of passes required passes, // final int [] passes, // debugging - number of passes required
debugLevel); // final int debugLevel) debugLevel); // final int debugLevel)
if (save_filtered_low) { if (save_filtered_low) {
...@@ -8413,7 +8361,7 @@ public class CuasMotion { ...@@ -8413,7 +8361,7 @@ public class CuasMotion {
// show good and bad accumulated here too? // show good and bad accumulated here too?
} }
// Andrey 05/05/2026 moved here (earlier) so shiftAndRenderAccumulate() will use update 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) { if (recalc_mv) {
refineMotionVectors( refineMotionVectors(
...@@ -8669,7 +8617,21 @@ public class CuasMotion { ...@@ -8669,7 +8617,21 @@ public class CuasMotion {
} }
return target_sequence_multi; // target_sequence; // contains all tiles, good or bad, their data and when they were defined return target_sequence_multi; // target_sequence; // contains all tiles, good or bad, their data and when they were defined
} }
/**
* if (select_new && !use_motion) , fill mark all selected non-centered as "used"
* @param motion_sequence
* @param target_sequence_multi
* @param use_motion_in
* @param select_new_in
* @param min_confidence
* @param lma_horizon
* @param tilesX
* @param range
* @param remain
* @param passes
* @param debugLevel
* @return
*/
public static int [][] filter5Targets( // should work for motion vectors and target coordinates returns index of selected target or -1 for unselected public static int [][] filter5Targets( // should work for motion vectors and target coordinates returns index of selected target or -1 for unselected
final double [][][] motion_sequence, // may be null final double [][][] motion_sequence, // may be null
final double [][][][] target_sequence_multi, // not null final double [][][][] target_sequence_multi, // not null
...@@ -8688,16 +8650,16 @@ public class CuasMotion { ...@@ -8688,16 +8650,16 @@ public class CuasMotion {
final int debugLevel){ final int debugLevel){
final boolean use_motion = (motion_sequence != null) ? use_motion_in : false; final boolean use_motion = (motion_sequence != null) ? use_motion_in : false;
final boolean select_new = (motion_sequence != null) ? select_new_in : false; final boolean select_new = (motion_sequence != null) ? select_new_in : false;
boolean debug_now = (debugLevel>5); boolean debug_now = (debugLevel<5);
final int num_seq = target_sequence_multi.length; final int num_seq = target_sequence_multi.length;
final int num_tiles = target_sequence_multi[0].length; final int num_tiles = target_sequence_multi[0].length;
final int tilesY = num_tiles/ tilesX; final int tilesY = num_tiles/ tilesX;
final int [][] filter5 = new int [num_seq][num_tiles]; final int [][] filter5 = new int [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_tile = debug_now ?(53+38*80) : -1; final int dbg_tile = debug_now ?(50+38*80) : -1;
final int dbg_seq0 = debug_now ? 47: -1; final int dbg_seq0 = debug_now ? 20: -1;
final int dbg_seq1 = debug_now ? 49: -1; final int dbg_seq1 = debug_now ? 21: -1;
final int ihorizon = (lma_horizon > 0) ?( (int) Math.ceil(lma_horizon/GPUTileProcessor.DTT_SIZE)) : -1; // tiles with tileY >= ihorizon are removed final int ihorizon = (lma_horizon > 0) ?( (int) Math.ceil(lma_horizon/GPUTileProcessor.DTT_SIZE)) : -1; // tiles with tileY >= ihorizon are removed
if (dbg_tile >=0) { if (dbg_tile >=0) {
System.out.println("filter5Targets()):00: use_motion="+use_motion+", select_new="+select_new+", ihorizon="+ihorizon); System.out.println("filter5Targets()):00: use_motion="+use_motion+", select_new="+select_new+", ihorizon="+ihorizon);
......
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