Commit fea4dfdc authored by Andrey Filippov's avatar Andrey Filippov

Works, before multi-target

parent 61eb0d79
...@@ -30,6 +30,7 @@ import java.awt.Button; ...@@ -30,6 +30,7 @@ import java.awt.Button;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Dialog; import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Frame; import java.awt.Frame;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
...@@ -10099,6 +10100,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener { ...@@ -10099,6 +10100,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
//getSelectedFiles //getSelectedFiles
JFileChooser fc = new JFileChooser(); JFileChooser fc = new JFileChooser();
fc.setPreferredSize(new Dimension(800, 1000));
fc.setFileSelectionMode(directory ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY); fc.setFileSelectionMode(directory ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(true); fc.setMultiSelectionEnabled(true);
if ((title != null) && (title.length() > 0)) if ((title != null) && (title.length() > 0))
...@@ -10148,6 +10150,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener { ...@@ -10148,6 +10150,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
} }
JFileChooser fc = new JFileChooser(); JFileChooser fc = new JFileChooser();
fc.setPreferredSize(new Dimension(800, 1000));
fc.setFileSelectionMode(directory ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY); fc.setFileSelectionMode(directory ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false); fc.setMultiSelectionEnabled(false);
if ((title != null) && (title.length() > 0)) if ((title != null) && (title.length() > 0))
......
...@@ -8,6 +8,7 @@ import java.io.IOException; ...@@ -8,6 +8,7 @@ import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -823,6 +824,18 @@ public class CuasMotion { ...@@ -823,6 +824,18 @@ public class CuasMotion {
System.out.println("Failed to motion vectors from "+path_vf); System.out.println("Failed to motion vectors from "+path_vf);
continue; 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 generateExtractFilterMovingTargets( // move parameters to clt_parameters
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode, batch_mode, // final boolean batch_mode,
...@@ -1217,7 +1230,7 @@ public class CuasMotion { ...@@ -1217,7 +1230,7 @@ public class CuasMotion {
final int num_iter, final int num_iter,
final float [][] accum_debug, final float [][] accum_debug,
final int debugLevel){ final int debugLevel){
if (debugLevel > -4 ) { if (debugLevel > 0 ) {
System.out.println("getAccumulatedCoordinates(): "+((sky_mask == null)? "NOT ":"")+"using sky_mask"); System.out.println("getAccumulatedCoordinates(): "+((sky_mask == null)? "NOT ":"")+"using sky_mask");
} }
final boolean dbg_hack_ridge = (debugLevel > 0); // true; final boolean dbg_hack_ridge = (debugLevel > 0); // true;
...@@ -1241,10 +1254,9 @@ public class CuasMotion { ...@@ -1241,10 +1254,9 @@ public class CuasMotion {
param_select[CuasMotionLMA.INDX_C] = lma_fit_c; param_select[CuasMotionLMA.INDX_C] = lma_fit_c;
param_select[CuasMotionLMA.INDX_RR0] = lma_fit_r; param_select[CuasMotionLMA.INDX_RR0] = lma_fit_r;
param_select[CuasMotionLMA.INDX_K] = lma_fit_k; 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 int dbg_seq = 13;
final boolean use_filters = (lmax_flt_hsigma > 0) && (lmax_flt_lsigma > 0) && (lmax_flt_scale > 0); 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++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
public void run() { public void run() {
...@@ -1351,49 +1363,13 @@ public class CuasMotion { ...@@ -1351,49 +1363,13 @@ public class CuasMotion {
if (col == 0) { if (col == 0) {
System.out.println("row="+row+", mask_y="+mask_y+"col="+col+", mask_x="+mask_x+", mask_val="+mask_val+", pindx="+pindx); 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 // find absolute maximum (after "hacking" and masking
int ntile_amax = TileNeibs.getAmaxTile( int ntile_amax = TileNeibs.getAmaxTile(
pix_tile); //double [] data) 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 // filtering tile for better maximum selection
if (pix_tile_filtered != null) { if (pix_tile_filtered != null) {
System.arraycopy(pix_tile, 0, pix_tile_filtered, 0, pix_tile_filtered.length); System.arraycopy(pix_tile, 0, pix_tile_filtered, 0, pix_tile_filtered.length);
...@@ -1556,24 +1532,10 @@ public class CuasMotion { ...@@ -1556,24 +1532,10 @@ public class CuasMotion {
int col = GPUTileProcessor.DTT_SIZE + (int) Math.round(target[CuasMotionLMA.RSLT_X]); 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 row = GPUTileProcessor.DTT_SIZE + (int) Math.round(target[CuasMotionLMA.RSLT_Y]);
int pindx = col+row*tile2; 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)) { if (!tn.isInside(pindx)) {
target[CuasMotionLMA.RSLT_ITERS] = -2; // outside of the 16x16 tiles -> LMA failed to converge target[CuasMotionLMA.RSLT_ITERS] = -2; // outside of the 16x16 tiles -> LMA failed to converge
} else if (disabled[pindx]) { } else if (disabled[pindx]) {
target[CuasMotionLMA.RSLT_FAIL] = CuasMotionLMA.FAIL_HORIZON; 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])) { if (centered && !Double.isNaN(target_sequence[nSeq][ntile][CuasMotionLMA.RSLT_X])) {
double x0 = target_sequence[nSeq][ntile][CuasMotionLMA.RSLT_X]; double x0 = target_sequence[nSeq][ntile][CuasMotionLMA.RSLT_X];
...@@ -1885,6 +1847,7 @@ public class CuasMotion { ...@@ -1885,6 +1847,7 @@ public class CuasMotion {
final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0 final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0
final double lma_a2a, final double lma_a2a,
final double max_mismatch, final double max_mismatch,
final double good_mismatch, //do not add to score if worse
final boolean fail_mismatch, final boolean fail_mismatch,
final double lma_horizon, // horizon as maximal pixel Y final double lma_horizon, // horizon as maximal pixel Y
final int tilesX ) { final int tilesX ) {
...@@ -1892,7 +1855,8 @@ public class CuasMotion { ...@@ -1892,7 +1855,8 @@ public class CuasMotion {
final double SAFE_CENT_MX = 3 * target_strength; // Find a more elegant solution final double SAFE_CENT_MX = 3 * target_strength; // Find a more elegant solution
final int num_seq = target_sequence.length; final int num_seq = target_sequence.length;
final int num_tiles = target_sequence[0].length; final int num_tiles = target_sequence[0].length;
final 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 int dbg_tile = -(34 + 34*80);
final Thread[] threads = ImageDtt.newThreadArray(); final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0);
...@@ -1920,8 +1884,20 @@ public class CuasMotion { ...@@ -1920,8 +1884,20 @@ public class CuasMotion {
double MM_AFTER = lma_rslts[CuasMotionLMA.RSLT_MISMATCH_AFTER]; double MM_AFTER = lma_rslts[CuasMotionLMA.RSLT_MISMATCH_AFTER];
double x = lma_rslts[CuasMotionLMA.RSLT_X]; double x = lma_rslts[CuasMotionLMA.RSLT_X];
double y = lma_rslts[CuasMotionLMA.RSLT_Y]; 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; boolean failed = true;
try_failures: { try_failures: {
// start with centroid tests // start with centroid tests
...@@ -1991,7 +1967,6 @@ public class CuasMotion { ...@@ -1991,7 +1967,6 @@ public class CuasMotion {
lma_rslts[CuasMotionLMA.RSLT_FAIL] = CuasMotionLMA.FAIL_FAR; lma_rslts[CuasMotionLMA.RSLT_FAIL] = CuasMotionLMA.FAIL_FAR;
break try_failures; // below horizon line break try_failures; // below horizon line
} }
failed = false; // all tests passed failed = false; // all tests passed
} }
...@@ -2007,14 +1982,12 @@ public class CuasMotion { ...@@ -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] = 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 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) { if (MM_BEFORE <= good_mismatch) {
quality_factors[IMPORTANCE_MISMATCH] += Math.max(0,(max_mismatch - MM_BEFORE)/max_mismatch); // 0 .. 1 quality_factors[IMPORTANCE_MISMATCH] += Math.max(0,(good_mismatch - MM_BEFORE)/good_mismatch); // 0 .. 1
} }
if (MM_AFTER <= max_mismatch) { if (MM_AFTER <= good_mismatch) {
quality_factors[IMPORTANCE_MISMATCH] += Math.max(0,(max_mismatch - MM_AFTER)/max_mismatch); // 0 .. 1 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; quality_factors[IMPORTANCE_CENTER] = cxy*cxy;
} }
// save quality factors // save quality factors
...@@ -2098,9 +2071,99 @@ public class CuasMotion { ...@@ -2098,9 +2071,99 @@ public class CuasMotion {
return remain; 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;
}
public static double [][] getEffectiveStrengthMV( // calculate tiles effective strength by the motion vectors. Combine with the target LMA? public static double [][] getEffectiveStrengthMV( // calculate tiles effective strength by the motion vectors. Combine with the target LMA?
final double [][][] targets_sequence, final double [][][] targets_sequence,
...@@ -4135,25 +4198,33 @@ public class CuasMotion { ...@@ -4135,25 +4198,33 @@ public class CuasMotion {
fpixels, // float [][] fpixels, fpixels, // float [][] fpixels,
cuasMotion, // CuasMotion cuasMotion, cuasMotion, // CuasMotion cuasMotion,
targets_good, // double [][][] targets_good, // all targets, including conflicting targets_good, // double [][][] targets_good, // all targets, including conflicting
// String [] scene_titles, // recreate slice_titles from scene titles?
slice_titles, // String [] slice_titles, slice_titles, // String [] slice_titles,
debugLevel); // final int debugLevel) debugLevel); // final int debugLevel)
boolean remove_isolated= clt_parameters.imp.cuas_isolated;
generateExtractFilterMovingTargets( // move parameters to clt_parameters if (remove_isolated) {
clt_parameters, // CLTParameters clt_parameters, removeShortTargetSequences(
batch_mode, // final boolean batch_mode, clt_parameters, // CLTParameters clt_parameters,
parentCLT, // QuadCLT parentCLT, // batch_mode, // final boolean batch_mode,
// three arrays needed parentCLT, // QuadCLT parentCLT, //
fpixels, // final float [][] fpixels, targets_nonconflict, // final double [][][] target_sequence,
targets_nonconflict, // final double [][][] vf_sequence, // center tiles (not extended), null /non-null only cuasMotion, // final CuasMotion cuasMotion,
// frame0, // final int frame0, // for vector_field[0] // source scene corresponding to the first sequence slice_titles, // String [] slice_titles,
cuasMotion, // final CuasMotion cuasMotion, debugLevel); // final int debugLevel)
uasLogReader, // UasLogReader uasLogReader, }
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
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,
parentCLT, // QuadCLT parentCLT, //
// three arrays needed
fpixels, // final float [][] fpixels,
targets_nonconflict, // final double [][][] vf_sequence, // center tiles (not extended), null /non-null only
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 { ...@@ -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_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
good_mismatch, // final double good_mismatch, //do not add to score if worse
fail_mismatch, // final boolean fail_mismatch, fail_mismatch, // final boolean fail_mismatch,
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,
...@@ -4911,6 +4983,7 @@ public class CuasMotion { ...@@ -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_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,
max_mismatch, // final double max_mismatch, 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, fail_mismatch, // final boolean fail_mismatch,
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,
...@@ -5114,7 +5187,8 @@ public class CuasMotion { ...@@ -5114,7 +5187,8 @@ public class CuasMotion {
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 lma_maxk, // final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0
lma_a2a, // final double lma_a2a, lma_a2a, // final double lma_a2a,
max_mismatch, // final double max_mismatch, 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, fail_mismatch, // final boolean fail_mismatch,
target_horizon, // final double lma_horizon, // target below horizon target_horizon, // final double lma_horizon, // target below horizon
cuasMotion.tilesX); // final int tilesX, cuasMotion.tilesX); // final int tilesX,
...@@ -5171,7 +5245,8 @@ public class CuasMotion { ...@@ -5171,7 +5245,8 @@ public class CuasMotion {
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 lma_maxk, // final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0
lma_a2a, // final double lma_a2a, lma_a2a, // final double lma_a2a,
max_mismatch, // final double max_mismatch, 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, fail_mismatch, // final boolean fail_mismatch,
target_horizon, // final double lma_horizon, // target below horizon target_horizon, // final double lma_horizon, // target below horizon
cuasMotion.tilesX); // final int tilesX, cuasMotion.tilesX); // final int tilesX,
...@@ -5256,67 +5331,24 @@ public class CuasMotion { ...@@ -5256,67 +5331,24 @@ public class CuasMotion {
} }
public static void removeShortTargetSequences(
public static void generateExtractFilterMovingTargets( // move parameters to clt_parameters
CLTParameters clt_parameters, CLTParameters clt_parameters,
final boolean batch_mode, final boolean batch_mode,
QuadCLT parentCLT, // QuadCLT parentCLT,
final float [][] fpixels,
double [][][] target_sequence, // non-overlap only if consider marked stronger tiles double [][][] target_sequence, // non-overlap only if consider marked stronger tiles
CuasMotion cuasMotion, CuasMotion cuasMotion,
UasLogReader uasLogReader,
String [] scene_titles, // recreate slice_titles from scene titles?
String [] slice_titles, String [] slice_titles,
final int debugLevel) { final int debugLevel) {
String model_prefix = parentCLT.getImageName()+getParametersSuffix(clt_parameters,null); String model_prefix = parentCLT.getImageName()+getParametersSuffix(clt_parameters,null);
final int corr_offset = clt_parameters.imp.cuas_corr_offset; 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 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 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= 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 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 max_mismatch = clt_parameters.imp.cuas_max_mismatch; // 2;
double good_mismatch = clt_parameters.imp.cuas_good_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_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() // for getEffectiveStrengthLMA(), may be moved out of this method to resolveTargetsConflicts()
double target_strength = clt_parameters.imp.cuas_target_strength; double target_strength = clt_parameters.imp.cuas_target_strength;
double [][] target_frac = new double [clt_parameters.imp.cuas_target_frac.length][2]; double [][] target_frac = new double [clt_parameters.imp.cuas_target_frac.length][2];
...@@ -5336,16 +5368,7 @@ public class CuasMotion { ...@@ -5336,16 +5368,7 @@ public class CuasMotion {
double factor_lim = clt_parameters.imp.cuas_factor_lim; double factor_lim = clt_parameters.imp.cuas_factor_lim;
double factor_pow = clt_parameters.imp.cuas_factor_pow; double factor_pow = clt_parameters.imp.cuas_factor_pow;
double [] score_coeff = clt_parameters.imp.cuas_score_coeff.clone(); 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[][][] // 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 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; final int num_corr_samples = target_sequence.length;
int [] filter5_remain = new int [num_corr_samples]; int [] filter5_remain = new int [num_corr_samples];
...@@ -5353,8 +5376,6 @@ public class CuasMotion { ...@@ -5353,8 +5376,6 @@ public class CuasMotion {
int [] num_undef = new int [num_corr_samples]; int [] num_undef = new int [num_corr_samples];
int [] num_good = new int [num_corr_samples]; int [] num_good = new int [num_corr_samples];
int [] num_bad = new int [num_corr_samples]; int [] num_bad = new int [num_corr_samples];
/* */
// Should be already calculated // Should be already calculated
getHalfBeforeAfterPixXY( // fills fields in the target_sequence tiles getHalfBeforeAfterPixXY( // fills fields in the target_sequence tiles
target_sequence, // final double [][][] targets, target_sequence, // final double [][][] targets,
...@@ -5378,160 +5399,222 @@ public class CuasMotion { ...@@ -5378,160 +5399,222 @@ public class CuasMotion {
parentCLT.saveImagePlusInModelDirectory(imp_no_singles_lma); // ImagePlus imp) parentCLT.saveImagePlusInModelDirectory(imp_no_singles_lma); // ImagePlus imp)
if (debugLevel > -4) System.out.println(); if (debugLevel > -4) System.out.println();
} }
/* */
// Should be already removed? // Should be already removed?
getRemain(target_sequence, num_all, num_undef, num_good, num_bad); 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 (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)
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) { filterIsolatedTargets( // overwrites "good", does not change "when"
ImagePlus imp_no_singles_lma= showTargetSequence( target_sequence, // final double [][][] targets,
target_sequence, // double [][][] target_scene_sequence, min_seq, // final int min_seq_length, // minimal sequence length not including first/last keyframes (may include)
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null min_seq_fl, // final int min_seq_length_fl,// < min_seq_length minimal sequence length that includes first/last keyframes
model_prefix+"-NOSINGLES", // String title, max_mismatch, // final double max_mismatch, // if <=0, do not calculate mismatch_ba and filter
!batch_mode, // boolean show, cuasMotion.tilesX); // int tilesX) {
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_no_singles_lma); // ImagePlus imp) if (intermed_low) {
if (debugLevel > -4) System.out.println(); ImagePlus imp_no_singles_lma= showTargetSequence(
} target_sequence, // double [][][] target_scene_sequence,
calculateMismatchBeforeAfter( // fills fields in the target_sequence tiles slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
target_sequence, // final double [][][] targets, model_prefix+"-NOSINGLES", // String title,
true, // final boolean good_only, !batch_mode, // boolean show,
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) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_no_singles_lma); // ImagePlus imp)
if (debugLevel > -4) System.out.println();
}
calculateMismatchBeforeAfter( // fills fields in the target_sequence tiles
target_sequence, // final double [][][] targets,
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) { if (intermed_low) {
ImagePlus imp_no_singles_lma= showTargetSequence( ImagePlus imp_no_singles_lma= showTargetSequence(
target_sequence, // double [][][] target_scene_sequence, target_sequence, // double [][][] target_scene_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-NOSINGLES2", // String title, model_prefix+"-NOSINGLES2", // String title,
!batch_mode, // boolean show, !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_no_singles_lma); // ImagePlus imp) parentCLT.saveImagePlusInModelDirectory(imp_no_singles_lma); // ImagePlus imp)
if (debugLevel > -4) System.out.println(); if (debugLevel > -4) System.out.println();
} }
// re-calculate score after removing short sequences // re-calculate score after removing short sequences
calculateMismatchBeforeAfter( // fills fields in the target_sequence tiles calculateMismatchBeforeAfter( // fills fields in the target_sequence tiles
target_sequence, // final double [][][] targets, target_sequence, // final double [][][] targets,
true, // final boolean good_only, true, // final boolean good_only,
cuasMotion.tilesX); // final int tilesX) cuasMotion.tilesX); // final int tilesX)
getEffectiveStrengthLMA( filterIsolatedTargets( // overwrites "good", does not change "when"
target_sequence, // final double [][][] target_coords, // LMA target_sequence, // final double [][][] targets,
target_strength, // final double target_strength, min_seq, // final int min_seq_length, // minimal sequence length not including first/last keyframes (may include)
target_frac, // final double [][] target_frac, // pairs - strength, minimal fraction for that strength min_seq_fl, // final int min_seq_length_fl,// < min_seq_length minimal sequence length that includes first/last keyframes
lma_rms, // final double lma_rms, // = 1.5; // Maximal RMS (should always match, regardless if A) max_mismatch, // final double max_mismatch, // if <=0, do not calculate mismatch_ba and filter
lma_arms, // final double lma_arms, // = 0.06; // Maximal absolute RMS (should match one of cuas_lma_arms OR cuas_lma_rrms (0.484) cuasMotion.tilesX); // int tilesX) {
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) if (intermed_low) {
lma_mina, // final double lma_mina, // = 1.0; // Minimal A (amplitude) ImagePlus imp_final_score = showTargetSequence(
lma_maxr, // final double lma_maxr, // = 5.0; // Minimal K (overshoot) = 3.0 target_sequence, // double [][][] vector_fields_sequence,
lma_minr1, // final double lma_minr1,// = 1.0; // Minimal R1 (radius of positive peak) slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
lma_mink, // final double lma_mink, // = 0.0; // Minimal K (overshoot) = 1.0 model_prefix+"-PRE-FINAL_SCORE",// String title,
lma_maxk, // final double lma_maxk, // = 5.0; // Minimal K (overshoot) = 3.0 !batch_mode, // boolean show,
lma_a2a, // final double lma_a2a, cuasMotion.tilesX); // int tilesX) {
max_mismatch, // final double max_mismatch, parentCLT.saveImagePlusInModelDirectory(imp_final_score);
false, // fail_mismatch, // final boolean fail_mismatch, }
target_horizon, // final double lma_horizon, // target below horizon
cuasMotion.tilesX); // final int tilesX, getEffectiveStrengthLMA(
target_sequence, // 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
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,
// int [] remain_es2 = // int [] remain_es2 =
getScore( // calculates composite sceres getScore( // calculates composite sceres
target_sequence, // final double [][][] target_sequence, // modifies certain fields (scores) target_sequence, // 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)
cuasMotion.tilesX); // final int tilesX, cuasMotion.tilesX); // final int tilesX,
if (intermed_low) { if (intermed_low) {
ImagePlus imp_final_score = showTargetSequence( ImagePlus imp_final_score = showTargetSequence(
target_sequence, // double [][][] vector_fields_sequence, target_sequence, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-FINAL_SCORE",// String title, model_prefix+"-FINAL_SCORE",// String title,
!batch_mode, // boolean show, !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_final_score); parentCLT.saveImagePlusInModelDirectory(imp_final_score);
} }
// getRemain(target_sequence, num_all, num_undef, num_good, num_bad); // getRemain(target_sequence, num_all, num_undef, num_good, num_bad);
getRemain(target_sequence, null, null, num_good, null); getRemain(target_sequence, null, null, num_good, null);
if (debugLevel > -4) printStats ("After final score", true, null, null, num_good, null); if (debugLevel > -4) printStats ("After final score", true, null, null, num_good, null);
boolean[][] filter5 = filter5Targets( boolean[][] filter5 = filter5Targets(
target_sequence, // final double [][][] target_sequence, target_sequence, // final double [][][] target_sequence,
false, // final boolean use_motion, // true - use motion vectros confidence, false - use target confidence false, // final boolean use_motion, // true - use motion vectros confidence, false - use target confidence
false, // final boolean select_new, // true - use only untested tiles, false - use good tiles false, // final boolean select_new, // true - use only untested tiles, false - use good tiles
min_score_lma, // min_mv_strength, // double min_confidence, min_score_lma, // min_mv_strength, // double min_confidence,
target_horizon, // final double lma_horizon, // target below horizon target_horizon, // final double lma_horizon, // target below horizon
cuasMotion.tilesX, // final int tilesX, cuasMotion.tilesX, // final int tilesX,
2, // max_range, // final int range, // 1 or 2 2, // max_range, // final int range, // 1 or 2
filter5_remain, // final int [] remain){ filter5_remain, // final int [] remain){
null, // passes, // final int [] passes, // debugging - number of passes required null, // passes, // final int [] passes, // debugging - number of passes required
debugLevel); // final int debugLevel) debugLevel); // final int debugLevel)
if (debugLevel > -4) printStatsLine("After filter5 remaining non-conflicting targets", true,filter5_remain); if (debugLevel > -4) printStatsLine("After filter5 remaining non-conflicting targets", true,filter5_remain);
// apply filter5 to targets_good // apply filter5 to targets_good
findStrongerNeighbor(// does not modify "when" findStrongerNeighbor(// does not modify "when"
target_sequence, // final double [][][] target_sequence, target_sequence, // final double [][][] target_sequence,
filter5, // final boolean [][] filter5) filter5, // final boolean [][] filter5)
true, // final boolean mark_failed, true, // final boolean mark_failed,
cuasMotion.tilesX); // final int tilesX) { cuasMotion.tilesX); // final int tilesX) {
// now failed by neighbors are marked as non-NaN (tile index or -1), not as failed // now failed by neighbors are marked as non-NaN (tile index or -1), not as failed
getRemain(target_sequence, null, null, num_good, null); getRemain(target_sequence, null, null, num_good, null);
if (debugLevel > -4) printStats ("After removing by neighbors", true, null, null, num_good, null); if (debugLevel > -4) printStats ("After removing by neighbors", true, null, null, num_good, null);
if (intermed_low) { if (intermed_low) {
ImagePlus imp_neibs = showTargetSequence( ImagePlus imp_neibs = showTargetSequence(
target_sequence, // double [][][] vector_fields_sequence, target_sequence, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-NO_CONFLICTS",// String title, model_prefix+"-NO_CONFLICTS",// String title,
!batch_mode, // boolean show, !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_neibs);
}
calculateMismatchBeforeAfter( // fills fields in the target_sequence tiles
target_sequence, // final double [][][] targets,
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) { cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_neibs);
}
if (intermed_low) { calculateMismatchBeforeAfter( // fills fields in the target_sequence tiles
ImagePlus imp_no_singles_lma= showTargetSequence( target_sequence, // final double [][][] targets,
target_sequence, // double [][][] target_scene_sequence, true, // final boolean good_only,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null cuasMotion.tilesX); // final int tilesX)
model_prefix+"-NOSINGLES3", // String title, filterIsolatedTargets( // overwrites "good", does not change "when"
!batch_mode, // boolean show, target_sequence, // final double [][][] targets,
cuasMotion.tilesX); // int tilesX) { min_seq, // final int min_seq_length, // minimal sequence length not including first/last keyframes (may include)
parentCLT.saveImagePlusInModelDirectory(imp_no_singles_lma); // ImagePlus imp) min_seq_fl, // final int min_seq_length_fl,// < min_seq_length minimal sequence length that includes first/last keyframes
if (debugLevel > -4) System.out.println(); max_mismatch, // final double max_mismatch, // if <=0, do not calculate mismatch_ba and filter
} cuasMotion.tilesX); // int tilesX) {
if (intermed_low) {
ImagePlus imp_no_singles_lma= showTargetSequence(
target_sequence, // double [][][] target_scene_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-NOSINGLES3", // String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
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); 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); 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;
// create larger, 5x5 vector field for accumulation -> 3x3 // create larger, 5x5 vector field for accumulation -> 3x3
double [][][] extended_targets = extendMotionScan( double [][][] extended_targets = extendMotionScan(
...@@ -5577,36 +5660,6 @@ public class CuasMotion { ...@@ -5577,36 +5660,6 @@ public class CuasMotion {
parentCLT.saveImagePlusInModelDirectory(imp_accumulated5x5); // ImagePlus imp) 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 velocity_scale = 1.0/corr_offset;
double [][][] targets60hz = new double [fpixels.length][][]; double [][][] targets60hz = new double [fpixels.length][][];
...@@ -5703,7 +5756,125 @@ public class CuasMotion { ...@@ -5703,7 +5756,125 @@ public class CuasMotion {
final double max_mismatch_in, // if <=0, do not calculate mismatch_ba and filter final double max_mismatch_in, // if <=0, do not calculate mismatch_ba and filter
final int tilesX) { final int tilesX) {
final int num_seq = targets.length; 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) { if (num_seq <0) {
filterIsolatedTargets( // overwrites "good", does not change "when" filterIsolatedTargets( // overwrites "good", does not change "when"
targets, // final double [][][] targets, targets, // final double [][][] targets,
...@@ -5712,6 +5883,7 @@ public class CuasMotion { ...@@ -5712,6 +5883,7 @@ public class CuasMotion {
tilesX); // final int tilesX) tilesX); // final int tilesX)
return; return;
} }
*/
final int num_tiles = targets[0].length; final int num_tiles = targets[0].length;
final double max_mismatch = (max_mismatch_in > 0) ? max_mismatch_in : Double.POSITIVE_INFINITY; 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 boolean [][] good_tiles = new boolean [num_seq][num_tiles];
...@@ -5908,7 +6080,9 @@ public class CuasMotion { ...@@ -5908,7 +6080,9 @@ public class CuasMotion {
return; return;
} }
@Deprecated
public static void filterIsolatedTargets( // overwrites "good", does not change "when" public static void filterIsolatedTargets( // overwrites "good", does not change "when"
final double [][][] targets, final double [][][] targets,
boolean remove_2seq, boolean remove_2seq,
...@@ -6148,17 +6322,6 @@ public class CuasMotion { ...@@ -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_BEFORE] = mm[0];
target[CuasMotionLMA.RSLT_MISMATCH_AFTER] = mm[1]; target[CuasMotionLMA.RSLT_MISMATCH_AFTER] = mm[1];
target[CuasMotionLMA.RSLT_MISMATCH_DIRS] = encodeDirs(mm_dirs); target[CuasMotionLMA.RSLT_MISMATCH_DIRS] = encodeDirs(mm_dirs);
......
...@@ -6094,7 +6094,7 @@ public class OpticalFlow { ...@@ -6094,7 +6094,7 @@ public class OpticalFlow {
} else { } else {
if (debugLevel > -4) { 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(); // setCenterAverage();
......
...@@ -412,13 +412,18 @@ public class QuadCLTCPU { ...@@ -412,13 +412,18 @@ public class QuadCLTCPU {
// If both local and parent exist - combine // If both local and parent exist - combine
// If rad old-style from parent - save it there as cumulative // If rad old-style from parent - save it there as cumulative
//What about DSI? //What about DSI?
if (debugLevel >-4) {
System.out.println("Restoring CenterClt");
}
double tolerance = clt_parameters.imp.cuas_clt_threshold; double tolerance = clt_parameters.imp.cuas_clt_threshold;
double decay = clt_parameters.imp.cuas_decay_average; double decay = clt_parameters.imp.cuas_decay_average;
if ((full_path != null) && full_path.endsWith(Prefs.getFileSeparator())) { // null if ((full_path != null) && full_path.endsWith(Prefs.getFileSeparator())) { // null
full_path = full_path.substring(0, full_path.length()-1); 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; double [][] parent_dsi = null;
int tilesX = ref_clt.getTilesX(); int tilesX = ref_clt.getTilesX();
int num_colors = ref_clt.getNumColors(); 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