Commit c09cca3b authored by Andrey Filippov's avatar Andrey Filippov

Starting dual-boost centered processing

parent a86749dc
...@@ -2674,7 +2674,8 @@ public class CuasMotion { ...@@ -2674,7 +2674,8 @@ public class CuasMotion {
double k = Math.PI/2/(half_range_boosted + 0.5); double k = Math.PI/2/(half_range_boosted + 0.5);
for (int i = 1; i <= half_range_boosted; i ++) { for (int i = 1; i <= half_range_boosted; i ++) {
window_full[half_range_boosted + i] = smooth ? (Math.cos(i*k)):1.0; window_full[half_range_boosted + i] = smooth ? (Math.cos(i*k)):1.0;
s0+=2 * window_full[half_range_boosted + i]; window_full[half_range_boosted - i] = smooth ? (Math.cos(i*k)):1.0; // By Claude on 05/11/2026
s0+=2 * window_full[half_range_boosted + i];
} }
for (int i = 0; i < window_full.length; i ++) { for (int i = 0; i < window_full.length; i ++) {
window_full[i] /= s0; window_full[i] /= s0;
...@@ -2754,7 +2755,7 @@ public class CuasMotion { ...@@ -2754,7 +2755,7 @@ public class CuasMotion {
// may be faster if process only where vector_field[nseq][ntile] is not null // may be faster if process only where vector_field[nseq][ntile] is not null
for (int nSeq = ai.getAndIncrement(); nSeq < frames_accum.length; nSeq = ai.getAndIncrement()) { for (int nSeq = ai.getAndIncrement(); nSeq < frames_accum.length; nSeq = ai.getAndIncrement()) {
for (int i = 0; i < frames_accum[nSeq].length; i++) { for (int i = 0; i < frames_accum[nSeq].length; i++) {
frames_accum[nSeq][i] *=-1; frames_accum[nSeq][i] *=-0.625; // By Claude on 05/11/2026: restore pre-fix amplitude (window fix doubled it)
if (zero_fill && Double.isNaN(frames_accum[nSeq][i])){ if (zero_fill && Double.isNaN(frames_accum[nSeq][i])){
frames_accum[nSeq][i] = 0f; frames_accum[nSeq][i] = 0f;
} }
...@@ -8242,199 +8243,205 @@ public class CuasMotion { ...@@ -8242,199 +8243,205 @@ public class CuasMotion {
cuasMotion.tilesX); // int tilesX) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_ext); parentCLT.saveImagePlusInModelDirectory(imp_ext);
} }
// perform new accumulations of shifted non-conflicting tiles // double [][][][] targets_new_multi = null;
float [][] fpixels_accumulated = cuasMotion.shiftAndRenderAccumulate( int num_new = 0;
clt_parameters, // CLTParameters clt_parameters, {
true, // false, // final boolean center, // why is it false here? // perform new accumulations of shifted non-conflicting tiles
false, // final boolean fill_zeros, float [][] fpixels_accumulated = cuasMotion.shiftAndRenderAccumulate(
fpixels_accum, // By Claude on 05/07/2026: LPF'd with accum_ra (was fpixels_tum) clt_parameters, // CLTParameters clt_parameters,
extended_scan, // final double [][][] vector_field, true, // false, // final boolean center, // why is it false here?
frame0, // final int frame0, // for vector_field[0] false, // final boolean fill_zeros,
corr_inc, // final int frame_step, // keep for slow fpixels_accum, // By Claude on 05/07/2026: LPF'd with accum_ra (was fpixels_tum)
half_accum_range, // final int half_range, // scale for slow extended_scan, // final double [][][] vector_field,
boost_accum_pairs,// final double boost_pairs, frame0, // final int frame0, // for vector_field[0]
smooth, // final boolean smooth, corr_inc, // final int frame_step, // keep for slow
corr_offset, // final int corr_offset, // interframe distance for correlation half_accum_range, // final int half_range, // scale for slow
true); // final boolean batch_mode) { boost_accum_pairs,// final double boost_pairs,
if (save_filtered_high) { smooth, // final boolean smooth,
String title = model_prefix+"-ACCUMULATED-CENTERED-n"+niter; corr_offset, // final int corr_offset, // interframe distance for correlation
if (boost_accum_pairs > 1.0) { true); // final boolean batch_mode) {
title+="-BOOST"+boost_accum_pairs; if (save_filtered_high) {
String title = model_prefix+"-ACCUMULATED-CENTERED-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
}
ImagePlus imp_acc = ShowDoubleFloatArrays.makeArrays(
fpixels_accumulated, // double[][] pixels,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
title, // model_prefix+"-ACCUMULATED-CENTERED-n"+niter, // String title,
slice_titles);
imp_acc.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (!batch_mode) {
imp_acc.show();
}
parentCLT.saveImagePlusInModelDirectory(imp_acc); // ImagePlus imp)
} }
ImagePlus imp_acc = ShowDoubleFloatArrays.makeArrays(
fpixels_accumulated, // double[][] pixels, // replace center frames with the accumulated ones
cuasMotion.gpu_max_width, if (debugLevel > -4) {
cuasMotion.gpu_max_height, System.out.println("Starting render, iteration = "+niter);
title, // model_prefix+"-ACCUMULATED-CENTERED-n"+niter, // String title,
slice_titles);
imp_acc.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (!batch_mode) {
imp_acc.show();
} }
parentCLT.saveImagePlusInModelDirectory(imp_acc); // ImagePlus imp)
}
// replace center frames with the accumulated ones // show just fpixels_accumulated
if (debugLevel > -4) { // move outside? compare to slice_titles known
System.out.println("Starting render, iteration = "+niter); // Calculate both centroid and LMA target parametes, return both
} // targets_new will contain motion vectors, centroid, and LMA results combined
//save_filtered_high
// show just fpixels_accumulated float [][] accum_debug = save_filtered_high? new float [num_corr_samples][]:null; //fpixels_accumulated.length]
// move outside? compare to slice_titles known boolean keep_failed = false; // keep failed targets
// Calculate both centroid and LMA target parametes, return both double [][][][] targets_new_multi = getAccumulatedCoordinatesMulti(
// targets_new will contain motion vectors, centroid, and LMA results combined keep_failed, // final boolean keep_failed, // keep failed targets
//save_filtered_high niter, // final int when, // set if >=0 for failures
true, // final boolean centered,
float [][] accum_debug = save_filtered_high? new float [num_corr_samples][]:null; //fpixels_accumulated.length] targets_nonoverlap, // final double [][][] vector_fields, // centers
boolean keep_failed = false; // keep failed targets fpixels_accumulated, // final double [][] accum_data, // should be around 0, no low-freq
double [][][][] targets_new_multi = getAccumulatedCoordinatesMulti( 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
keep_failed, // final boolean keep_failed, // keep failed targets lmax_flt_neglim, // final double lmax_flt_neglim, // -0.3; // limit negative data to reduce ridge influence (make -10 to disable)
niter, // final int when, // set if >=0 for failures lmax_flt_hsigma, // final double lmax_flt_hsigma, // 1.0 // HPF (~UM) subtract GB with this sigma from the data tile
true, // final boolean centered, lmax_flt_lsigma, // final double lmax_flt_lsigma, // 1.0 // LPF - GB result of the previous subtraction
targets_nonoverlap, // final double [][][] vector_fields, // centers lmax_flt_scale, // final double lmax_flt_scale, // 5.0 // scale filtering result
fpixels_accumulated, // final double [][] accum_data, // should be around 0, no low-freq cuasMotion.sky_mask, // final double sky_mask,
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 sky_threshold, // final double sky_threshold, // 0.9 // minimal value of the sky mask where target is possible
lmax_flt_neglim, // final double lmax_flt_neglim, // -0.3; // limit negative data to reduce ridge influence (make -10 to disable) target_horizon+filter_below_horizon, // final double lma_horizon,
lmax_flt_hsigma, // final double lmax_flt_hsigma, // 1.0 // HPF (~UM) subtract GB with this sigma from the data tile 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_flt_lsigma, // final double lmax_flt_lsigma, // 1.0 // LPF - GB result of the previous subtraction lmax_radius, // final int cuas_lmax_radius, // 3; // look inside cuas_lmax_radius* 2 + 1 square for the local maximum isolation
lmax_flt_scale, // final double lmax_flt_scale, // 5.0 // scale filtering result lmax_radius, // final double centered_radius,
cuasMotion.sky_mask, // final double sky_mask, 0.5, // final double centered_radius_blur,
sky_threshold, // final double sky_threshold, // 0.9 // minimal value of the sky mask where target is possible 1.0, // final double pix_tolerance, //
target_horizon+filter_below_horizon, // final double lma_horizon, // lmax_zero, // final boolean cuas_lmax_zero, // true; // zero all data outside this radius from the maximum
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 target_radius, // final double centroid_radius,
lmax_radius, // final int cuas_lmax_radius, // 3; // look inside cuas_lmax_radius* 2 + 1 square for the local maximum isolation n_recenter, // final int n_recenter, // re-center window around new maximum. 0 -no refines (single-pass)
lmax_radius, // final double centered_radius, cuasMotion.tilesX, // final int tilesX){
0.5, // final double centered_radius_blur, no_border, // final boolean no_border,
1.0, // final double pix_tolerance, // // Moving target LMA
// lmax_zero, // final boolean cuas_lmax_zero, // true; // zero all data outside this radius from the maximum lma_sigma, // final double lma_sigma,
target_radius, // final double centroid_radius, wnd_pedestal, // final double wnd_pedestal,
n_recenter, // final int n_recenter, // re-center window around new maximum. 0 -no refines (single-pass) lma_r0, // final double lma_r0,
cuasMotion.tilesX, // final int tilesX){ lma_ovrsht, // final double lma_ovrsht,
no_border, // final boolean no_border, // CUAS Motion LMA parameters
// Moving target LMA lma_fit_xy, // final boolean lma_fit_xy,
lma_sigma, // final double lma_sigma, lma_fit_a, // final boolean lma_fit_a,
wnd_pedestal, // final double wnd_pedestal, lma_fit_c, // final boolean lma_fit_c,
lma_r0, // final double lma_r0, lma_fit_r, // final boolean lma_fit_r,
lma_ovrsht, // final double lma_ovrsht, lma_fit_k, // final boolean lma_fit_k,
// CUAS Motion LMA parameters lambda, // final double lambda,
lma_fit_xy, // final boolean lma_fit_xy, lambda_good, // final double lambda_good,
lma_fit_a, // final boolean lma_fit_a, lambda_bad, // final double lambda_bad,
lma_fit_c, // final boolean lma_fit_c, lambda_max, // final double lambda_max,
lma_fit_r, // final boolean lma_fit_r, rms_diff, // final double rms_diff,
lma_fit_k, // final boolean lma_fit_k, num_iter, // final int num_iter,0, // final double pre_min_a, // pre-filter minimal LMA-A (half finbal?)
lambda, // final double lambda, 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)
lambda_good, // final double lambda_good, min_keep, // final int min_keep, // 2; // keep at least this number of candidates before using cuas_lma_pre_mina filter
lambda_bad, // final double lambda_bad, accum_debug, // final float [][] accum_debug,
lambda_max, // final double lambda_max, parentCLT, // final QuadCLT parentCLT, // debug only, maybe null in other cases
rms_diff, // final double rms_diff, debugLevel); // final int debugLevel);
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) if (accum_debug != null) {
min_keep, // final int min_keep, // 2; // keep at least this number of candidates before using cuas_lma_pre_mina filter String title = model_prefix+"-ACCUMULATED_FILTERED-CENTERED-MULTI-n"+niter;
accum_debug, // final float [][] accum_debug, if (boost_accum_pairs > 1.0) {
parentCLT, // final QuadCLT parentCLT, // debug only, maybe null in other cases title+="-BOOST"+boost_accum_pairs;
debugLevel); // final int debugLevel); }
ImagePlus imp_acc = ShowDoubleFloatArrays.makeArrays(
if (accum_debug != null) { accum_debug, // double[][] pixels,
String title = model_prefix+"-ACCUMULATED_FILTERED-CENTERED-MULTI-n"+niter; cuasMotion.gpu_max_width,
if (boost_accum_pairs > 1.0) { cuasMotion.gpu_max_height,
title+="-BOOST"+boost_accum_pairs; title, // model_prefix+"-ACCUMULATED_FILTERED-CENTERED-MULTI-n"+niter, // String title,
} slice_titles);
ImagePlus imp_acc = ShowDoubleFloatArrays.makeArrays( imp_acc.getProcessor().setMinAndMax(-input_range/2, input_range/2);
accum_debug, // double[][] pixels, if (!batch_mode) {
cuasMotion.gpu_max_width, imp_acc.show();
cuasMotion.gpu_max_height, }
title, // model_prefix+"-ACCUMULATED_FILTERED-CENTERED-MULTI-n"+niter, // String title, parentCLT.saveImagePlusInModelDirectory(imp_acc); // ImagePlus imp)
slice_titles);
imp_acc.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (!batch_mode) {
imp_acc.show();
} }
parentCLT.saveImagePlusInModelDirectory(imp_acc); // ImagePlus imp) // no need to to evaluate scores now - can be done all at once when all non-centered will be replaced by centered, removed (almost) duplicates
} // evaluating scores, but it is not needed
// new results are sorted by decreasing amplitude, there should be only one - test it. If not still use only the first
// continue niter for "when"
// keep only one (best) result for centered getAccumulatedCoordinatesMulti()
// no need to to evaluate scores now - can be done all at once when all non-centered will be replaced by centered, removed (almost) duplicates
// evaluating scores, but it is not needed
// new results are sorted by decreasing amplitude, there should be only one - test it. If not still use only the first
// continue niter for "when"
// keep only one (best) result for centered getAccumulatedCoordinatesMulti()
if (save_filtered_low && debug_more) {
String title = model_prefix+"-NEW-TARGETS-CENTERED-MULTI-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
}
if (save_filtered_low && debug_more) { ImagePlus imp_new = showTargetSequence(
String title = model_prefix+"-NEW-TARGETS-CENTERED-MULTI-n"+niter; targets_new_multi, // final double [][][][] targets_multi,
if (boost_accum_pairs > 1.0) { slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title+="-BOOST"+boost_accum_pairs; title, // model_prefix+"-NEW-TARGETS-CENTERED-MULTI-n"+niter,// String title,
good_only, // final boolean good_only,
show_empty, // final boolean show_empty, // show scenes with no (valid) targets
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_new); // ImagePlus imp)
} }
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-CENTERED-MULTI-n"+niter,// String title,
good_only, // final boolean good_only,
show_empty, // final boolean show_empty, // show scenes with no (valid) targets
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_new); // ImagePlus imp)
}
// evaluate scores here to reduce the number of attempts for centered targets // evaluate scores here to reduce the number of attempts for centered targets
getEffectiveStrengthLMA( getEffectiveStrengthLMA(
targets_new_multi, // final double [][][] target_coords, // LMA targets_new_multi, // final double [][][] target_coords, // LMA
target_strength, // final double target_strength, target_strength, // final double target_strength,
target_frac, // final double [][] target_frac, // pairs - strength, minimal fraction for that 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_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_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_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_mina, // final double lma_mina, // = 1.0; // Minimal A (amplitude)
lma_maxr, // final double lma_maxr, // = 5.0; // Minimal K (overshoot) = 3.0 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_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_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_maxk, // final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0// final double lma_a2a,
lma_a2a, // 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 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 slow_fast_mismatch,// final double slow_fast_mismatch, // // 1.5; allow larger mismatch between slow and fast
fail_mismatch, // final boolean fail_mismatch, fail_mismatch, // final boolean fail_mismatch,
offcenter, // final double offcenter, offcenter, // final double offcenter,
cuasMotion.getNoiseMap(), // final double [] noise_map, cuasMotion.getNoiseMap(), // final double [] noise_map,
noisemax, // final double noise_max, noisemax, // final double noise_max,
target_horizon, // final double lma_horizon, // horizon as maximal pixel Y target_horizon, // final double lma_horizon, // horizon as maximal pixel Y
cuasMotion.tilesX); // final int tilesX, cuasMotion.tilesX); // final int tilesX,
int [] remain_es_centered = getScore( int [] remain_es_centered = getScore(
targets_new_multi, // final double [][][] target_sequence, // modifies certain fields (scores) targets_new_multi, // final double [][][] target_sequence, // modifies certain fields (scores)
factor_lim, // final double importance_limit, factor_lim, // final double importance_limit,
factor_pow, // final double importance_power, // Raise each factor to this power before combining 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) 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 slow_score, // final double slow_score, // multiply total score for targets detected in slow target mode
cuasMotion.tilesX); // final int tilesX, cuasMotion.tilesX); // final int tilesX,
if (save_filtered_low) {
String title = model_prefix+"-NEW-TARGETS_CENTERED_SCORES_MULTI-n"+niter;
if (boost_accum_pairs > 1.0) {
title+="-BOOST"+boost_accum_pairs;
}
if (save_filtered_low) { ImagePlus imp_new_scores = showTargetSequence(
String title = model_prefix+"-NEW-TARGETS_CENTERED_SCORES_MULTI-n"+niter; targets_new_multi, // double [][][] vector_fields_sequence,
if (boost_accum_pairs > 1.0) { slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title+="-BOOST"+boost_accum_pairs; title, // model_prefix+"-NEW-TARGETS_CENTERED_SCORES_MULTI-n"+niter,// String title,
good_only, // final boolean good_only,
show_empty, // final boolean show_empty, // show scenes with no (valid) targets
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_new_scores); // ImagePlus imp)
} }
ImagePlus imp_new_scores = showTargetSequence( //int
targets_new_multi, // double [][][] vector_fields_sequence, num_new += addNewResults(
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null target_sequence_multi, // final double [][][] target_sequence, // will only process non-nulls here
title, // model_prefix+"-NEW-TARGETS_CENTERED_SCORES_MULTI-n"+niter,// String title, targets_new_multi, // final double [][][] new_sequence,
good_only, // final boolean good_only, // add just one best here?
show_empty, // final boolean show_empty, // show scenes with no (valid) targets 1, // final int num_best, // if >0, limit number of best results to add
!batch_mode, // boolean show, niter, // final int when_iter,
cuasMotion.tilesX); // int tilesX) { debugLevel); // final int debugLevel);
parentCLT.saveImagePlusInModelDirectory(imp_new_scores); // ImagePlus imp)
}
int num_new = addNewResults(
target_sequence_multi, // final double [][][] target_sequence, // will only process non-nulls here
targets_new_multi, // final double [][][] new_sequence,
// add just one best here?
1, // final int num_best, // if >0, limit number of best results to add
niter, // final int when_iter,
debugLevel); // final int debugLevel);
if (debugLevel > -4) { if (debugLevel > -4) {
System.out.println("Added "+num_new+" new tiles as good/bad at iteration "+niter+"."); System.out.println("Added "+num_new+" new tiles as good/bad at iteration "+niter+".");
}
} }
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"+niter;
if (boost_accum_pairs > 1.0) { if (boost_accum_pairs > 1.0) {
......
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