Commit fea4dfdc authored by Andrey Filippov's avatar Andrey Filippov

Works, before multi-target

parent 61eb0d79
......@@ -30,6 +30,7 @@ import java.awt.Button;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
......@@ -10099,6 +10100,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
//getSelectedFiles
JFileChooser fc = new JFileChooser();
fc.setPreferredSize(new Dimension(800, 1000));
fc.setFileSelectionMode(directory ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(true);
if ((title != null) && (title.length() > 0))
......@@ -10148,6 +10150,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
}
JFileChooser fc = new JFileChooser();
fc.setPreferredSize(new Dimension(800, 1000));
fc.setFileSelectionMode(directory ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false);
if ((title != null) && (title.length() > 0))
......
......@@ -8,6 +8,7 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.concurrent.atomic.AtomicInteger;
import javax.imageio.ImageIO;
import java.nio.file.Paths;
......@@ -823,6 +824,18 @@ public class CuasMotion {
System.out.println("Failed to motion vectors from "+path_vf);
continue;
}
if (remove_isolated) {
removeShortTargetSequences(
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
parentCLT, // QuadCLT parentCLT, //
vf_sequence, // final double [][][] target_sequence,
cuasMotion, // final CuasMotion cuasMotion,
slice_titles, // String [] slice_titles,
debugLevel); // final int debugLevel)
}
generateExtractFilterMovingTargets( // move parameters to clt_parameters
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
......@@ -1217,7 +1230,7 @@ public class CuasMotion {
final int num_iter,
final float [][] accum_debug,
final int debugLevel){
if (debugLevel > -4 ) {
if (debugLevel > 0 ) {
System.out.println("getAccumulatedCoordinates(): "+((sky_mask == null)? "NOT ":"")+"using sky_mask");
}
final boolean dbg_hack_ridge = (debugLevel > 0); // true;
......@@ -1241,10 +1254,9 @@ public class CuasMotion {
param_select[CuasMotionLMA.INDX_C] = lma_fit_c;
param_select[CuasMotionLMA.INDX_RR0] = lma_fit_r;
param_select[CuasMotionLMA.INDX_K] = lma_fit_k;
final int dbg_tile = (31 + 45 * 80); //(38 + 45 * 80);
final int dbg_tile = -(31 + 45 * 80); //(38 + 45 * 80);
final int dbg_seq = 13;
final boolean use_filters = (lmax_flt_hsigma > 0) && (lmax_flt_lsigma > 0) && (lmax_flt_scale > 0);
// final boolean[] fpn_mask= no_border? (new boolean[0]) : null;
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
......@@ -1351,49 +1363,13 @@ public class CuasMotion {
if (col == 0) {
System.out.println("row="+row+", mask_y="+mask_y+"col="+col+", mask_x="+mask_x+", mask_val="+mask_val+", pindx="+pindx);
}
// pix_tile[pindx] *= mask_val;
// if (mask_val < sky_threshold) {
// disabled[pindx] = true; // disallow maximums in this area
// }
}
}
}
}
// find absolute maximum (after "hacking" and masking
int ntile_amax = TileNeibs.getAmaxTile(
pix_tile); //double [] data)
/*
if (lmax_hack_ridge > 0) {
Arrays.fill(disabled,false);
disabled = new boolean[pix_tile.length];
double thresh = pix_tile[ntile_amax] * lmax_hack_ridge;
for (int row=0; row < tile2; row++) {
double s = 0;
int n = 0;
for (int col = 0; col < tile2; col++) {
double d = Math.abs(pix_tile[row*tile2+col]);
if (!Double.isNaN(d)) {
s += d;
n++;
}
}
s/= n;
if (s > thresh) {
for (int col = 0; col < tile2; col++) {
int pindx = row*tile2+col;
disabled[pindx] = true;
pix_tile[pindx] = 0.0;
}
}
}
}
*/
// filtering tile for better maximum selection
if (pix_tile_filtered != null) {
System.arraycopy(pix_tile, 0, pix_tile_filtered, 0, pix_tile_filtered.length);
......@@ -1556,24 +1532,10 @@ public class CuasMotion {
int col = GPUTileProcessor.DTT_SIZE + (int) Math.round(target[CuasMotionLMA.RSLT_X]);
int row = GPUTileProcessor.DTT_SIZE + (int) Math.round(target[CuasMotionLMA.RSLT_Y]);
int pindx = col+row*tile2;
/*
if (pindx > 256) {
System.out.println("nSeq="+nSeq+", ntile="+ntile+
", target[CuasMotionLMA.RSLT_X]="+target[CuasMotionLMA.RSLT_X]+
", target[CuasMotionLMA.RSLT_Y]="+target[CuasMotionLMA.RSLT_Y]+
", row="+row+", col="+col);
}
*/
if (!tn.isInside(pindx)) {
target[CuasMotionLMA.RSLT_ITERS] = -2; // outside of the 16x16 tiles -> LMA failed to converge
} else if (disabled[pindx]) {
target[CuasMotionLMA.RSLT_FAIL] = CuasMotionLMA.FAIL_HORIZON;
/*
if (ntile == dbg_tile) { // if ((nSeq==dbg_seq) && (ntile == dbg_tile)) {
System.out.println("getAccumulatedCoordinates(): nSeq="+nSeq+", ntile="+ntile+
", centered="+centered+", pindx="+pindx);
}
*/
}
if (centered && !Double.isNaN(target_sequence[nSeq][ntile][CuasMotionLMA.RSLT_X])) {
double x0 = target_sequence[nSeq][ntile][CuasMotionLMA.RSLT_X];
......@@ -1885,6 +1847,7 @@ public class CuasMotion {
final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0
final double lma_a2a,
final double max_mismatch,
final double good_mismatch, //do not add to score if worse
final boolean fail_mismatch,
final double lma_horizon, // horizon as maximal pixel Y
final int tilesX ) {
......@@ -1892,7 +1855,8 @@ public class CuasMotion {
final double SAFE_CENT_MX = 3 * target_strength; // Find a more elegant solution
final int num_seq = target_sequence.length;
final int num_tiles = target_sequence[0].length;
final double center_scale = 0.5*Math.PI/GPUTileProcessor.DTT_SIZE;
// final double center_scale = 0.5*Math.PI/GPUTileProcessor.DTT_SIZE;
final double center_scale = 0.25*Math.PI/GPUTileProcessor.DTT_SIZE;
final int dbg_tile = -(34 + 34*80);
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
......@@ -1920,8 +1884,20 @@ public class CuasMotion {
double MM_AFTER = lma_rslts[CuasMotionLMA.RSLT_MISMATCH_AFTER];
double x = lma_rslts[CuasMotionLMA.RSLT_X];
double y = lma_rslts[CuasMotionLMA.RSLT_Y];
double cxy= Math.max(0,Math.cos(x * center_scale)) * Math.max(0,Math.cos(y * center_scale));
double cxy = 1.0;
if ((Math.abs(x) > 0.5*GPUTileProcessor.DTT_SIZE) || (Math.abs(y) > 0.5*GPUTileProcessor.DTT_SIZE)) {
cxy = 0.0;
} else {
double ax = Math.abs(x) - 0.25*GPUTileProcessor.DTT_SIZE;
double ay = Math.abs(x) - 0.25*GPUTileProcessor.DTT_SIZE;
if (ax > 0) {
cxy *= Math.cos(ax * center_scale);
}
if (ay > 0) {
cxy *= Math.cos(ay * center_scale);
}
}
// double cxy= Math.max(0,Math.cos(x * center_scale)) * Math.max(0,Math.cos(y * center_scale));
boolean failed = true;
try_failures: {
// start with centroid tests
......@@ -1991,7 +1967,6 @@ public class CuasMotion {
lma_rslts[CuasMotionLMA.RSLT_FAIL] = CuasMotionLMA.FAIL_FAR;
break try_failures; // below horizon line
}
failed = false; // all tests passed
}
......@@ -2007,14 +1982,12 @@ public class CuasMotion {
quality_factors[IMPORTANCE_RMS] = Math.max(0,(inv_rms - inv_rms_lim)/ inv_rms_lim); // only >0 for small max-es
quality_factors[IMPORTANCE_RMS_A] = Math.max(0,(inv_rel_rms - inv_rel_rms_lim)/ inv_rel_rms_lim); // only >0 for small max-es
if (MM_BEFORE <= max_mismatch) {
quality_factors[IMPORTANCE_MISMATCH] += Math.max(0,(max_mismatch - MM_BEFORE)/max_mismatch); // 0 .. 1
if (MM_BEFORE <= good_mismatch) {
quality_factors[IMPORTANCE_MISMATCH] += Math.max(0,(good_mismatch - MM_BEFORE)/good_mismatch); // 0 .. 1
}
if (MM_AFTER <= max_mismatch) {
quality_factors[IMPORTANCE_MISMATCH] += Math.max(0,(max_mismatch - MM_AFTER)/max_mismatch); // 0 .. 1
if (MM_AFTER <= good_mismatch) {
quality_factors[IMPORTANCE_MISMATCH] += Math.max(0,(good_mismatch - MM_AFTER)/good_mismatch); // 0 .. 1
}
// GPUTileProcessor.DTT_SIZE
// double cxy= Math.max(0,Math.cos(x * center_scale) * Math.cos(y * center_scale));
quality_factors[IMPORTANCE_CENTER] = cxy*cxy;
}
// save quality factors
......@@ -2098,7 +2071,97 @@ public class CuasMotion {
return remain;
}
public static double [][][][] convertToMultiTarget(
final double [][][] target_sequence) {
final int num_seq = target_sequence.length;
final int num_tiles = target_sequence[0].length;
final double [][][][] target_multi = new double[num_seq][num_tiles][][];
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nSeq = ai.getAndIncrement(); nSeq < num_seq; nSeq = ai.getAndIncrement()) {
for (int ntile = 0; ntile < num_tiles; ntile++) if (target_sequence[nSeq][ntile] != null) {
target_multi[nSeq][ntile] = new double[][] {target_sequence[nSeq][ntile]};
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return target_multi;
}
public static double [][][] convertFromToMultiTarget(
final double [][][][] target_multi) {
final int num_seq = target_multi.length;
final int num_tiles = target_multi[0].length;
final double [][][] target_sequence = new double[num_seq][num_tiles][];
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nSeq = ai.getAndIncrement(); nSeq < num_seq; nSeq = ai.getAndIncrement()) {
for (int ntile = 0; ntile < num_tiles; ntile++) {
double [][] targets = target_multi[nSeq][ntile];
if ((targets != null) && (targets.length > 0)) {
target_sequence[nSeq][ntile] = targets[0];
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return target_sequence;
}
public static void sortMultiTargets(
final double [][][][] target_multi) {
final int num_seq = target_multi.length;
final int num_tiles = target_multi[0].length;
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nSeq = ai.getAndIncrement(); nSeq < num_seq; nSeq = ai.getAndIncrement()) {
for (int ntile = 0; ntile < num_tiles; ntile++) {
double [][] targets = target_multi[nSeq][ntile];
if ((targets != null) && (target_multi.length > 1)) {
Integer [] indices = new Integer[targets.length];
Arrays.sort(indices, new Comparator<Integer>() { // decreasing weight
@Override
public int compare(Integer lhs, Integer rhs) { // descending score
if ((targets[lhs][CuasMotionLMA.RSLT_FAIL] == CuasMotionLMA.FAIL_NONE) && (targets[rhs][CuasMotionLMA.RSLT_FAIL] != CuasMotionLMA.FAIL_NONE)) {
return -1;
} else if ((targets[lhs][CuasMotionLMA.RSLT_FAIL] != CuasMotionLMA.FAIL_NONE) && (targets[rhs][CuasMotionLMA.RSLT_FAIL] == CuasMotionLMA.FAIL_NONE)) {
return 1;
}
return (targets[lhs][CuasMotionLMA.RSLT_QSCORE]> targets[rhs][CuasMotionLMA.RSLT_QSCORE]) ?
-1 : ((targets[lhs][CuasMotionLMA.RSLT_QSCORE] < targets[rhs][CuasMotionLMA.RSLT_QSCORE]) ? 1 : 0);
}
});
double [][] targets_orig = targets.clone(); // shallow
for (int i = 0; i < targets.length; i++) {
targets[i] = targets_orig[indices[i]];
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return;
}
......@@ -4135,10 +4198,20 @@ public class CuasMotion {
fpixels, // float [][] fpixels,
cuasMotion, // CuasMotion cuasMotion,
targets_good, // double [][][] targets_good, // all targets, including conflicting
// String [] scene_titles, // recreate slice_titles from scene titles?
slice_titles, // String [] slice_titles,
debugLevel); // final int debugLevel)
boolean remove_isolated= clt_parameters.imp.cuas_isolated;
if (remove_isolated) {
removeShortTargetSequences(
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
parentCLT, // QuadCLT parentCLT, //
targets_nonconflict, // final double [][][] target_sequence,
cuasMotion, // final CuasMotion cuasMotion,
slice_titles, // String [] slice_titles,
debugLevel); // final int debugLevel)
}
generateExtractFilterMovingTargets( // move parameters to clt_parameters
clt_parameters, // CLTParameters clt_parameters,
......@@ -4147,13 +4220,11 @@ public class CuasMotion {
// three arrays needed
fpixels, // final float [][] fpixels,
targets_nonconflict, // final double [][][] vf_sequence, // center tiles (not extended), null /non-null only
// frame0, // final int frame0, // for vector_field[0] // source scene corresponding to the first sequence
cuasMotion, // final CuasMotion cuasMotion,
uasLogReader, // UasLogReader uasLogReader,
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
slice_titles, // String [] slice_titles,
debugLevel); // final int debugLevel)
}
......@@ -4870,6 +4941,7 @@ public class CuasMotion {
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
good_mismatch, // final double good_mismatch, //do not add to score if worse
fail_mismatch, // final boolean fail_mismatch,
target_horizon, // final double lma_horizon, // horizon as maximal pixel Y
cuasMotion.tilesX); // final int tilesX,
......@@ -4911,6 +4983,7 @@ public class CuasMotion {
lma_maxk, // final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0// final double lma_a2a,
lma_a2a, // final double lma_a2a,
max_mismatch, // final double max_mismatch,
good_mismatch, // final double good_mismatch, //do not add to score if worse
fail_mismatch, // final boolean fail_mismatch,
target_horizon, // final double lma_horizon, // horizon as maximal pixel Y
cuasMotion.tilesX); // final int tilesX,
......@@ -5115,6 +5188,7 @@ public class CuasMotion {
lma_maxk, // final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0
lma_a2a, // final double lma_a2a,
max_mismatch, // final double max_mismatch,
good_mismatch, // final double good_mismatch, //do not add to score if worse
fail_mismatch, // final boolean fail_mismatch,
target_horizon, // final double lma_horizon, // target below horizon
cuasMotion.tilesX); // final int tilesX,
......@@ -5172,6 +5246,7 @@ public class CuasMotion {
lma_maxk, // final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0
lma_a2a, // final double lma_a2a,
max_mismatch, // final double max_mismatch,
good_mismatch, // final double good_mismatch, //do not add to score if worse
fail_mismatch, // final boolean fail_mismatch,
target_horizon, // final double lma_horizon, // target below horizon
cuasMotion.tilesX); // final int tilesX,
......@@ -5256,67 +5331,24 @@ public class CuasMotion {
}
public static void generateExtractFilterMovingTargets( // move parameters to clt_parameters
public static void removeShortTargetSequences(
CLTParameters clt_parameters,
final boolean batch_mode,
QuadCLT parentCLT, //
final float [][] fpixels,
QuadCLT parentCLT,
double [][][] target_sequence, // non-overlap only if consider marked stronger tiles
CuasMotion cuasMotion,
UasLogReader uasLogReader,
String [] scene_titles, // recreate slice_titles from scene titles?
String [] slice_titles,
final int debugLevel) {
String model_prefix = parentCLT.getImageName()+getParametersSuffix(clt_parameters,null);
final int corr_offset = clt_parameters.imp.cuas_corr_offset;
final int corr_pairs = clt_parameters.imp.cuas_corr_pairs;
final boolean half_step = clt_parameters.imp.cuas_half_step; // true;
final boolean smooth = clt_parameters.imp.cuas_smooth; // true;
final int corr_inc = half_step ? (corr_offset/2) : corr_offset;
final int half_accum_range = corr_pairs/2;
final double mask_width = clt_parameters.imp.cuas_mask_width; // 9;
final double mask_blur = clt_parameters.imp.cuas_mask_blur; // 3;
final boolean mask_round = clt_parameters.imp.cuas_mask_round; // false;
boolean remove_isolated= clt_parameters.imp.cuas_isolated;
// boolean remove_2seq= clt_parameters.imp.cuas_remove_2seq;
// boolean remove_2seq_all= clt_parameters.imp.cuas_remove_2seq_all;
int min_seq= clt_parameters.imp.cuas_min_seq; // 3; // minimal number of consecutive key frames for the same target
int min_seq_fl= clt_parameters.imp.cuas_min_seq_fl; // 2; // minimal number of consecutive key frames for the same target that includes first or last key frame
double max_mismatch = clt_parameters.imp.cuas_max_mismatch; // 2;
double good_mismatch = clt_parameters.imp.cuas_good_mismatch; // 2;
// boolean target_by_horizon = clt_parameters.imp.cuas_by_horizon; // true;
// double target_horizon= clt_parameters.imp.cuas_horizon; // a90
int target_type = clt_parameters.imp.cuas_target_type; // 0; // 0 - unknown, 1 - known, 2 - friend, 3 - foe
int known_type = clt_parameters.imp.cuas_known_type; // 2; // Target location matching UAS flight log: 0; // 0 - unknown, 1 - known, 2 - friend, 3 - foe
double known_err = clt_parameters.imp.cuas_known_err; // 20; // Maximal distance between the detected target and UAS log position (in raw image pixels);
double input_range = clt_parameters.imp.cuas_input_range; // 5;
boolean scale2x = clt_parameters.imp.cuas_scale2x; //true;
boolean ra_background = clt_parameters.imp.cuas_ra_background; //true;
boolean intermed_low = clt_parameters.imp.cuas_intermed_low; //true;
boolean intermed_high = clt_parameters.imp.cuas_intermed_high; //true;
// boolean intermed_giga = clt_parameters.imp.cuas_intermed_giga; //false;
boolean save_mono = clt_parameters.imp.cuas_save_mono; //true;
boolean save_color = clt_parameters.imp.cuas_save_color; //true;
boolean save_video = clt_parameters.imp.cuas_save_video; //true;
boolean target_debug = clt_parameters.imp.cuas_target_debug; //true;
boolean show_true_rng = clt_parameters.imp.cuas_show_true_rng; // show true range (from the flight log)
boolean cuas_gaussian_ra = clt_parameters.imp.cuas_gaussian_ra; // use temporal Gaussian instead of running average
boolean center_targ = false; // clt_parameters.imp.cuas_center_targ;
// for getEffectiveStrengthLMA(), may be moved out of this method to resolveTargetsConflicts()
double target_strength = clt_parameters.imp.cuas_target_strength;
double [][] target_frac = new double [clt_parameters.imp.cuas_target_frac.length][2];
......@@ -5336,16 +5368,7 @@ public class CuasMotion {
double factor_lim = clt_parameters.imp.cuas_factor_lim;
double factor_pow = clt_parameters.imp.cuas_factor_pow;
double [] score_coeff = clt_parameters.imp.cuas_score_coeff.clone();
// end of for getScore(), may be moved out of this method to resolveTargetsConflicts()
int start_frame = 0;
int seq_length = corr_offset + corr_pairs;
final int frame0 = start_frame + seq_length/2;
// Assuming non-conflicting tiles in the target_sequence[][][]
double interseq_scale = 0.5* corr_inc/corr_offset; // multiply target velocity to get offset in the middle between the key frames
final int num_corr_samples = target_sequence.length;
int [] filter5_remain = new int [num_corr_samples];
......@@ -5353,8 +5376,6 @@ public class CuasMotion {
int [] num_undef = new int [num_corr_samples];
int [] num_good = new int [num_corr_samples];
int [] num_bad = new int [num_corr_samples];
/* */
// Should be already calculated
getHalfBeforeAfterPixXY( // fills fields in the target_sequence tiles
target_sequence, // final double [][][] targets,
......@@ -5378,13 +5399,10 @@ public class CuasMotion {
parentCLT.saveImagePlusInModelDirectory(imp_no_singles_lma); // ImagePlus imp)
if (debugLevel > -4) System.out.println();
}
/* */
// Should be already removed?
getRemain(target_sequence, num_all, num_undef, num_good, num_bad);
if (debugLevel > -4) printStats ("\ngenerateExtractFilterMovingTargets(): before isolated removal", true,num_all, num_undef, num_good, num_bad);
if (remove_isolated) {
filterIsolatedTargets( // overwrites "good", does not change "when"
target_sequence, // final double [][][] targets,
min_seq, // final int min_seq_length, // minimal sequence length not including first/last keyframes (may include)
......@@ -5430,6 +5448,22 @@ public class CuasMotion {
true, // final boolean good_only,
cuasMotion.tilesX); // final int tilesX)
filterIsolatedTargets( // overwrites "good", does not change "when"
target_sequence, // final double [][][] targets,
min_seq, // final int min_seq_length, // minimal sequence length not including first/last keyframes (may include)
min_seq_fl, // final int min_seq_length_fl,// < min_seq_length minimal sequence length that includes first/last keyframes
max_mismatch, // final double max_mismatch, // if <=0, do not calculate mismatch_ba and filter
cuasMotion.tilesX); // int tilesX) {
if (intermed_low) {
ImagePlus imp_final_score = showTargetSequence(
target_sequence, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-PRE-FINAL_SCORE",// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_final_score);
}
getEffectiveStrengthLMA(
target_sequence, // final double [][][] target_coords, // LMA
target_strength, // final double target_strength,
......@@ -5444,6 +5478,7 @@ public class CuasMotion {
lma_maxk, // final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0
lma_a2a, // final double lma_a2a,
max_mismatch, // final double max_mismatch,
good_mismatch, // final double good_mismatch, //do not add to score if worse
false, // fail_mismatch, // final boolean fail_mismatch,
target_horizon, // final double lma_horizon, // target below horizon
cuasMotion.tilesX); // final int tilesX,
......@@ -5525,13 +5560,61 @@ public class CuasMotion {
parentCLT.saveImagePlusInModelDirectory(imp_no_singles_lma); // ImagePlus imp)
if (debugLevel > -4) System.out.println();
}
getRemain(target_sequence, num_all, num_undef, num_good, num_bad);
if (debugLevel > -4) printStats ("generateExtractFilterMovingTargets(): after isolated removal", true,num_all, num_undef, num_good, num_bad);
}
public static void generateExtractFilterMovingTargets( // move parameters to clt_parameters
CLTParameters clt_parameters,
final boolean batch_mode,
QuadCLT parentCLT, //
final float [][] fpixels,
double [][][] target_sequence, // non-overlap only if consider marked stronger tiles
CuasMotion cuasMotion,
UasLogReader uasLogReader,
String [] scene_titles, // recreate slice_titles from scene titles?
String [] slice_titles,
final int debugLevel) {
String model_prefix = parentCLT.getImageName()+getParametersSuffix(clt_parameters,null);
final int corr_offset = clt_parameters.imp.cuas_corr_offset;
final int corr_pairs = clt_parameters.imp.cuas_corr_pairs;
final boolean half_step = clt_parameters.imp.cuas_half_step; // true;
final boolean smooth = clt_parameters.imp.cuas_smooth; // true;
final int corr_inc = half_step ? (corr_offset/2) : corr_offset;
final int half_accum_range = corr_pairs/2;
final double mask_width = clt_parameters.imp.cuas_mask_width; // 9;
final double mask_blur = clt_parameters.imp.cuas_mask_blur; // 3;
final boolean mask_round = clt_parameters.imp.cuas_mask_round; // false;
int target_type = clt_parameters.imp.cuas_target_type; // 0; // 0 - unknown, 1 - known, 2 - friend, 3 - foe
int known_type = clt_parameters.imp.cuas_known_type; // 2; // Target location matching UAS flight log: 0; // 0 - unknown, 1 - known, 2 - friend, 3 - foe
double known_err = clt_parameters.imp.cuas_known_err; // 20; // Maximal distance between the detected target and UAS log position (in raw image pixels);
double input_range = clt_parameters.imp.cuas_input_range; // 5;
boolean scale2x = clt_parameters.imp.cuas_scale2x; //true;
boolean ra_background = clt_parameters.imp.cuas_ra_background; //true;
boolean intermed_low = clt_parameters.imp.cuas_intermed_low; //true;
boolean intermed_high = clt_parameters.imp.cuas_intermed_high; //true;
boolean save_mono = clt_parameters.imp.cuas_save_mono; //true;
boolean save_color = clt_parameters.imp.cuas_save_color; //true;
boolean save_video = clt_parameters.imp.cuas_save_video; //true;
boolean target_debug = clt_parameters.imp.cuas_target_debug; //true;
boolean show_true_rng = clt_parameters.imp.cuas_show_true_rng; // show true range (from the flight log)
boolean cuas_gaussian_ra = clt_parameters.imp.cuas_gaussian_ra; // use temporal Gaussian instead of running average
boolean center_targ = false; // clt_parameters.imp.cuas_center_targ;
int start_frame = 0;
int seq_length = corr_offset + corr_pairs;
final int frame0 = start_frame + seq_length/2;
}
getRemain(target_sequence, num_all, num_undef, num_good, num_bad);
if (debugLevel > -4) printStats ("generateExtractFilterMovingTargets(): after isolated removal", true,num_all, num_undef, num_good, num_bad);
// create larger, 5x5 vector field for accumulation -> 3x3
double [][][] extended_targets = extendMotionScan(
......@@ -5577,36 +5660,6 @@ public class CuasMotion {
parentCLT.saveImagePlusInModelDirectory(imp_accumulated5x5); // ImagePlus imp)
}
// testing centered
// Testing centered
/*
float [][] fpixels_accumulated_centered = cuasMotion.shiftAndRenderAccumulate(
clt_parameters, // CLTParameters clt_parameters,
true, // final boolean center,
false, // final boolean fill_zeros,
fpixels, // final float [][] fpixels,
extended_targets, // 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,
smooth, // final boolean smooth,
corr_offset, // final int corr_offset, // interframe distance for correlation
true); // final boolean batch_mode) {
if (intermed_high) {
ImagePlus imp_acc = ShowDoubleFloatArrays.makeArrays(
fpixels_accumulated_centered, // double[][] pixels,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
model_prefix+"-ACCUMULATED_CENTERED", // 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)
}
*/
double velocity_scale = 1.0/corr_offset;
double [][][] targets60hz = new double [fpixels.length][][];
......@@ -5703,7 +5756,125 @@ public class CuasMotion {
final double max_mismatch_in, // if <=0, do not calculate mismatch_ba and filter
final int tilesX) {
final int num_seq = targets.length;
final int num_tiles = targets[0].length;
final double max_mismatch = (max_mismatch_in > 0) ? max_mismatch_in : Double.POSITIVE_INFINITY;
final boolean [][] good_tiles = new boolean [num_seq][num_tiles];
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
TileNeibs tn = new TileNeibs(tilesX, num_tiles/tilesX);
for (int nSeq = ai.getAndIncrement(); nSeq < num_seq; nSeq = ai.getAndIncrement()) {
for (int ntile = 0; ntile < num_tiles; ntile++) if ((targets[nSeq][ntile] != null)
&& (targets[nSeq][ntile][CuasMotionLMA.RSLT_FAIL]==CuasMotionLMA.FAIL_NONE) &&
(targets[nSeq][ntile][CuasMotionLMA.RSLT_MISMATCH_DIRS]>0)) {
double [] ba = {targets[nSeq][ntile][CuasMotionLMA.RSLT_MISMATCH_BEFORE],targets[nSeq][ntile][CuasMotionLMA.RSLT_MISMATCH_AFTER]};
int [] dirs = decodeDirs(targets[nSeq][ntile][CuasMotionLMA.RSLT_MISMATCH_DIRS]);
for (int i = 0; i < ba.length; i++) {
if ((dirs[i] < 0) || (ba[i] > max_mismatch)) {
ba[i] = Double.NaN;
}
}
boolean has_fl = (nSeq==0) || (nSeq == (num_seq-1));
int seq_len = 1;
if (Double.isNaN(ba[0]) && Double.isNaN(ba[1])) { // no connections either way
continue;
}
int nseq1 = nSeq;
int ntile1 = ntile;
check_long_enough: {
if ((seq_len >= min_seq_length) || (has_fl && (seq_len >= min_seq_length_fl))) {
break check_long_enough;
}
// check after
int ba_index = 1;// 0 - before, 1 - after
// if required length is 0 or 1
while ((nseq1 < num_seq)) {// && (targets[nseq1][ntile1][CuasMotionLMA.RSLT_MISMATCH_AFTER] < max_mismatch) ) { // NaN will exit the loop
if ( (targets[nseq1][ntile1] == null) ||
(targets[nseq1][ntile1][CuasMotionLMA.RSLT_FAIL] != CuasMotionLMA.FAIL_NONE) ||
!(targets[nseq1][ntile1][CuasMotionLMA.RSLT_MISMATCH_AFTER] <= max_mismatch)) {
break;
}
int dir = decodeDirs(targets[nSeq][ntile][CuasMotionLMA.RSLT_MISMATCH_DIRS])[ba_index]; // direction to the tile in the next/previous keyframe
if (dir < 0) { // should not happen
break;
}
ntile1 = tn.getNeibIndex(ntile1, dir);
if (ntile1 < 0) { // should not happen
break;
}
nseq1++;
seq_len++;
has_fl |= (nseq1==0) || (nseq1 == (num_seq-1));
if ((seq_len >= min_seq_length) || (has_fl && (seq_len >= min_seq_length_fl))) {
break check_long_enough;
}
}
// check before
nseq1 = nSeq;
ntile1 = ntile;
ba_index = 0;// 0 - before, 1 - after
while ((nseq1 >= 0)) {// && (targets[nseq1][ntile1][CuasMotionLMA.RSLT_MISMATCH_BEFORE] < max_mismatch) ) { // NaN will exit the loop
if ( (targets[nseq1][ntile1] == null) ||
(targets[nseq1][ntile1][CuasMotionLMA.RSLT_FAIL]!=CuasMotionLMA.FAIL_NONE) ||
!(targets[nseq1][ntile1][CuasMotionLMA.RSLT_MISMATCH_BEFORE] <= max_mismatch)) {
break;
}
int dir = decodeDirs(targets[nSeq][ntile][CuasMotionLMA.RSLT_MISMATCH_DIRS])[ba_index]; // direction to the tile in the next/previous keyframe
if (dir < 0) { // should not happen
break;
}
ntile1 = tn.getNeibIndex(ntile1, dir);
if (ntile1 < 0) { // should not happen
break;
}
nseq1--;
seq_len++;
has_fl |= (nseq1==0) || (nseq1 == (num_seq-1));
if ((seq_len >= min_seq_length) || (has_fl && (seq_len >= min_seq_length_fl))) {
break check_long_enough;
}
}
continue; // not long enough to match requirements - not a good target
}
good_tiles [nSeq][ntile] = true;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nSeq = ai.getAndIncrement(); nSeq < num_seq; nSeq = ai.getAndIncrement()) {
for (int ntile = 0; ntile < num_tiles; ntile++) if ((targets[nSeq][ntile] != null) && !good_tiles[nSeq][ntile]) {
targets[nSeq][ntile][CuasMotionLMA.RSLT_FAIL] = CuasMotionLMA.FAIL_MISMATCH;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return;
}
public static void filterIsolatedTargetsDebug( // overwrites "good", does not change "when"
final double [][][] targets,
final int min_seq_length, // minimal sequence length not including first/last keyframes (may include)
final int min_seq_length_fl,// < min_seq_length minimal sequence length that includes first/last keyframes
final double max_mismatch_in, // if <=0, do not calculate mismatch_ba and filter
final int tilesX) {
final int num_seq = targets.length;
/*
if (num_seq <0) {
filterIsolatedTargets( // overwrites "good", does not change "when"
targets, // final double [][][] targets,
......@@ -5712,6 +5883,7 @@ public class CuasMotion {
tilesX); // final int tilesX)
return;
}
*/
final int num_tiles = targets[0].length;
final double max_mismatch = (max_mismatch_in > 0) ? max_mismatch_in : Double.POSITIVE_INFINITY;
final boolean [][] good_tiles = new boolean [num_seq][num_tiles];
......@@ -5909,6 +6081,8 @@ public class CuasMotion {
}
@Deprecated
public static void filterIsolatedTargets( // overwrites "good", does not change "when"
final double [][][] targets,
boolean remove_2seq,
......@@ -6148,17 +6322,6 @@ public class CuasMotion {
}
}
}
// Leveling chances (scores) of the first and last keyframes with the other ones:
// mm_dirs will still be -1
// Not needed, as targets only compete for the same keyframe, and removal is controlled by a separate parameter
// (cuas_remove_2seq_all).
/*
if (nSeq == 0) {
mm[0] = mm[1];
} else if (nSeq == (num_seq-1)) {
mm[1] = mm[0];
}
*/
target[CuasMotionLMA.RSLT_MISMATCH_BEFORE] = mm[0];
target[CuasMotionLMA.RSLT_MISMATCH_AFTER] = mm[1];
target[CuasMotionLMA.RSLT_MISMATCH_DIRS] = encodeDirs(mm_dirs);
......
......@@ -6094,7 +6094,7 @@ public class OpticalFlow {
} else {
if (debugLevel > -4) {
System.out.println("Spipping update of center CLT (it is reaed from "+center_CLT.getImagePath()+").");
System.out.println("Skipping update of center CLT (it is read from "+center_CLT.getImagePath()+").");
}
}
// setCenterAverage();
......
......@@ -412,13 +412,18 @@ public class QuadCLTCPU {
// If both local and parent exist - combine
// If rad old-style from parent - save it there as cumulative
//What about DSI?
if (debugLevel >-4) {
System.out.println("Restoring CenterClt");
}
double tolerance = clt_parameters.imp.cuas_clt_threshold;
double decay = clt_parameters.imp.cuas_decay_average;
if ((full_path != null) && full_path.endsWith(Prefs.getFileSeparator())) { // null
full_path = full_path.substring(0, full_path.length()-1);
}
if (debugLevel >-4) {
System.out.println("Restoring CenterClt, full_path="+full_path);
}
double [][] parent_dsi = null;
int tilesX = ref_clt.getTilesX();
int num_colors = ref_clt.getNumColors();
......
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