Commit 7180569b authored by Andrey Filippov's avatar Andrey Filippov

Before textures artefacts correction

parent 38b6b0d7
......@@ -43,6 +43,7 @@ public class IntersceneLma {
) {
this.thread_invariant = thread_invariant;
this.num_components = (disparity_weight > 0) ? 3 : 2;
this.disparity_weight = disparity_weight;
}
public int getNumComponents() {
......
......@@ -36,6 +36,8 @@ public class IntersceneLmaParameters {
public boolean ilma_thread_invariant = true; // Do not use DoubleAdder, provide results not dependent on threads
public boolean [] ilma_lma_select = new boolean [ErsCorrection.DP_NUM_PARS]; // first three will not be used
public double [] ilma_regularization_weights = new double [ErsCorrection.DP_NUM_PARS]; // first three will not be used
public double [] ilma_regularization_weights0 = new double [ErsCorrection.DP_NUM_PARS]; // Use after spiral
public boolean ilma_translation_priority = false; // expect translation for thepre-ref scene to be probable than rotation
public boolean ilma_ignore_ers = false; // ignore linear and angular velocities, assume tham zeroes
public boolean ilma_ers_adj_lin = false; // adjust linear ERS for scene-to-ref (LWIR does not work, check with high-speed)
public boolean ilma_ers_adj_ang = false; // adjust angular ERS for scene-to-ref (LWIR does not work, check with high-speed)
......@@ -107,6 +109,7 @@ public class IntersceneLmaParameters {
ilma_regularization_weights[ErsCorrection.DP_DSX]= 0.0;
ilma_regularization_weights[ErsCorrection.DP_DSY]= 0.0;
ilma_regularization_weights[ErsCorrection.DP_DSZ]= 0.0;
ilma_regularization_weights0 = ilma_regularization_weights.clone();
}
public void dialogQuestions(GenericJTabbedDialog gd) {
......@@ -132,6 +135,15 @@ public class IntersceneLmaParameters {
"Weight of "+ErsCorrection.DP_DERIV_NAMES[i]+" pull, 1.0 means that the paramter offset from initial corresponding to 1 image pixel\n"+
" will cause error equal to all reprojection ones");
}
gd.addMessage("Regularization parameters to be used first after spiral");
for (int i = ErsCorrection.DP_DVAZ; i < ErsCorrection.DP_NUM_PARS; i++) {
gd.addNumericField(ErsCorrection.DP_DERIV_NAMES[i], this.ilma_regularization_weights0[i], 6,8,"",
"Weight of "+ErsCorrection.DP_DERIV_NAMES[i]+" pull, 1.0 means that the paramter offset from initial corresponding to 1 image pixel\n"+
" will cause error equal to all reprojection ones");
}
gd.addCheckbox ("Expect translation not rotation", this.ilma_translation_priority,
"Expect translation to be more likely than rotation for the first movement after the spiral search" );
gd.addMessage("LMA other parameters");
gd.addCheckbox ("Ignore linear and angular velocities", this.ilma_ignore_ers,
"Ignore calculated linear and angular velocities when correlating scenes to the reference one" );
......@@ -187,6 +199,10 @@ public class IntersceneLmaParameters {
for (int i = ErsCorrection.DP_DVAZ; i < ErsCorrection.DP_NUM_PARS; i++) {
this.ilma_regularization_weights[i] = gd.getNextNumber();
}
for (int i = ErsCorrection.DP_DVAZ; i < ErsCorrection.DP_NUM_PARS; i++) {
this.ilma_regularization_weights0[i] = gd.getNextNumber();
}
this.ilma_translation_priority = gd.getNextBoolean();
this.ilma_ignore_ers = gd.getNextBoolean();
this.ilma_ers_adj_lin = gd.getNextBoolean();
this.ilma_ers_adj_ang = gd.getNextBoolean();
......@@ -216,7 +232,9 @@ public class IntersceneLmaParameters {
for (int i = ErsCorrection.DP_DVAZ; i < ErsCorrection.DP_NUM_PARS; i++) {
properties.setProperty(prefix+ErsCorrection.DP_DERIV_NAMES[i]+"_sel", this.ilma_lma_select[i]+"");
properties.setProperty(prefix+ErsCorrection.DP_DERIV_NAMES[i]+"_regweight", this.ilma_regularization_weights[i]+"");
properties.setProperty(prefix+ErsCorrection.DP_DERIV_NAMES[i]+"_regweight0", this.ilma_regularization_weights0[i]+"");
}
properties.setProperty(prefix+"ilma_translation_priority", this.ilma_translation_priority+"");
properties.setProperty(prefix+"ilma_ignore_ers", this.ilma_ignore_ers+"");
properties.setProperty(prefix+"ilma_ers_adj_lin", this.ilma_ers_adj_lin+"");
properties.setProperty(prefix+"ilma_ers_adj_ang", this.ilma_ers_adj_ang+"");
......@@ -247,7 +265,11 @@ public class IntersceneLmaParameters {
if (properties.getProperty(pn_sel)!=null) this.ilma_lma_select[i]=Boolean.parseBoolean(properties.getProperty(pn_sel));
pn_sel = prefix+ErsCorrection.DP_DERIV_NAMES[i]+"_regweight";
if (properties.getProperty(pn_sel)!=null) this.ilma_regularization_weights[i]=Double.parseDouble(properties.getProperty(pn_sel));
pn_sel = prefix+ErsCorrection.DP_DERIV_NAMES[i]+"_regweight0";
if (properties.getProperty(pn_sel)!=null) this.ilma_regularization_weights0[i]=Double.parseDouble(properties.getProperty(pn_sel));
}
//
if (properties.getProperty(prefix+"ilma_translation_priority")!=null)this.ilma_translation_priority=Boolean.parseBoolean(properties.getProperty(prefix+"ilma_translation_priority"));
if (properties.getProperty(prefix+"ilma_ignore_ers")!=null) this.ilma_ignore_ers=Boolean.parseBoolean(properties.getProperty(prefix+"ilma_ignore_ers"));
if (properties.getProperty(prefix+"ilma_ers_adj_lin")!=null) this.ilma_ers_adj_lin=Boolean.parseBoolean(properties.getProperty(prefix+"ilma_ers_adj_lin"));
if (properties.getProperty(prefix+"ilma_ers_adj_ang")!=null) this.ilma_ers_adj_ang=Boolean.parseBoolean(properties.getProperty(prefix+"ilma_ers_adj_ang"));
......@@ -287,6 +309,8 @@ public class IntersceneLmaParameters {
ilp.ilma_thread_invariant = this.ilma_thread_invariant;
System.arraycopy(this.ilma_lma_select, 0, ilp.ilma_lma_select, 0, ilma_lma_select.length);
System.arraycopy(this.ilma_regularization_weights, 0, ilp.ilma_regularization_weights, 0, ilma_regularization_weights.length);
System.arraycopy(this.ilma_regularization_weights0,0, ilp.ilma_regularization_weights0, 0, ilma_regularization_weights0.length);
ilp.ilma_translation_priority =this.ilma_translation_priority;
ilp.ilma_ignore_ers = this.ilma_ignore_ers;
ilp.ilma_ers_adj_lin = this.ilma_ers_adj_lin;
ilp.ilma_ers_adj_ang = this.ilma_ers_adj_ang;
......
......@@ -238,7 +238,8 @@ public class IntersceneMatchParameters {
public double half_avg_diff = 0.2; // when L2 of x,y difference from average of neibs - reduce twice
// Detect initial match
public double min_ref_str = 0.15; // 0.22; // For orientations: use only tiles of the reference scene DSI_MAIN is stronger
public double min_ref_str = 0.33; // 0.22; // For orientations: use only tiles of the reference scene DSI_MAIN is stronger
public double min_ref_frac = 0.2; // 0.22; if fraction number of reliable tiles is less than this, use best possible
public int pix_step = 4; // Azimuth/tilt search step in pixels
public int search_rad = 10; // Search radius in steps
public double maybe_sum = 1.0; // minimal sum of strengths (will search for the best)
......@@ -759,6 +760,8 @@ public class IntersceneMatchParameters {
gd.addMessage ("Initial search for the inter-scene match");
gd.addNumericField("DSI_MAIN minimal strength", this.min_ref_str, 5,7,"",
"Match only tiles where DSI_MAIN is stronger than that (and has LMA).");
gd.addNumericField("DSI_MAIN minimal fraction", this.min_ref_frac, 5,7,"",
"If relative number of the reliable tiles is less than this - use this best fraction.");
gd.addNumericField("Azimuth/tilt step", this.pix_step, 0,3,"pix",
"Search in a spiral starting with no-shift with this step between probes, in approximate pixels");
......@@ -1169,6 +1172,7 @@ public class IntersceneMatchParameters {
this.half_disparity = gd.getNextNumber();
this.half_avg_diff = gd.getNextNumber();
this.min_ref_str = gd.getNextNumber();
this.min_ref_frac = gd.getNextNumber();
this.pix_step = (int) gd.getNextNumber();
this.search_rad = (int) gd.getNextNumber();
this.maybe_sum = gd.getNextNumber();
......@@ -1492,6 +1496,7 @@ public class IntersceneMatchParameters {
properties.setProperty(prefix+"centroid_radius", this.centroid_radius+""); // double
properties.setProperty(prefix+"n_recenter", this.n_recenter+""); // int
properties.setProperty(prefix+"min_ref_str", this.min_ref_str+""); // double
properties.setProperty(prefix+"min_ref_frac", this.min_ref_frac+""); // double
properties.setProperty(prefix+"td_weight", this.td_weight+""); // double
properties.setProperty(prefix+"pd_weight", this.pd_weight+""); // double
properties.setProperty(prefix+"td_nopd_only", this.td_nopd_only+""); // boolean
......@@ -1784,6 +1789,7 @@ public class IntersceneMatchParameters {
if (properties.getProperty(prefix+"centroid_radius")!=null) this.centroid_radius=Double.parseDouble(properties.getProperty(prefix+"centroid_radius"));
if (properties.getProperty(prefix+"n_recenter")!=null) this.n_recenter=Integer.parseInt(properties.getProperty(prefix+"n_recenter"));
if (properties.getProperty(prefix+"min_ref_str")!=null) this.min_ref_str=Double.parseDouble(properties.getProperty(prefix+"min_ref_str"));
if (properties.getProperty(prefix+"min_ref_frac")!=null) this.min_ref_frac=Double.parseDouble(properties.getProperty(prefix+"min_ref_frac"));
if (properties.getProperty(prefix+"td_weight")!=null) this.td_weight=Double.parseDouble(properties.getProperty(prefix+"td_weight"));
if (properties.getProperty(prefix+"pd_weight")!=null) this.pd_weight=Double.parseDouble(properties.getProperty(prefix+"pd_weight"));
if (properties.getProperty(prefix+"td_nopd_only")!=null) this.td_nopd_only=Boolean.parseBoolean(properties.getProperty(prefix+"td_nopd_only"));
......@@ -2086,6 +2092,8 @@ public class IntersceneMatchParameters {
imp.centroid_radius = this.centroid_radius;
imp.n_recenter = this.n_recenter;
imp.min_ref_str = this.min_ref_str;
imp.min_ref_frac = this.min_ref_frac;
imp.td_weight = this.td_weight;
imp.pd_weight = this.pd_weight;
imp.td_nopd_only = this.td_nopd_only;
......
......@@ -3538,6 +3538,7 @@ public class OpticalFlow {
scenes_xyzatr[i] = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters,
clt_parameters.imp.use_lma_dsi,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
null, // double [] min_max, // null or pair of minimal and maximal offsets
null, // int [] fail_reason, // null or int[1]: 0 - OK, 1 - LMA, 2 - min, 3 - max
......@@ -4510,12 +4511,14 @@ public class OpticalFlow {
final int threadsMax, // int threadsMax,
final boolean updateStatus,
final int debugLevel) {
int num_scene_retries = 10;
int retry_radius = 2;
double scale_extrap_atr = clt_parameters.imp.scale_extrap_atr;
double scale_extrap_xyz = clt_parameters.imp.scale_extrap_xyz;
int avg_len = clt_parameters.imp.avg_len;
double maximal_series_rms = 0.0;
double min_ref_str = clt_parameters.imp.min_ref_str;
double min_ref_frac= clt_parameters.imp.min_ref_frac;
int min_num_scenes = clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it
int max_num_scenes = clt_parameters.imp.max_num_scenes; // cut longer series
......@@ -4547,10 +4550,17 @@ public class OpticalFlow {
int debug_scene = -15;
boolean debug2 = !batch_mode; // false; // true;
boolean [] reliable_ref = null;
boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
double [] reduced_strength = new double[1];
if (min_ref_str > 0.0) {
reliable_ref = quadCLTs[ref_index].getReliableTiles( // will be null if does not exist.
min_ref_str, // double min_strength,
true); // boolean needs_lma);
min_ref_frac, // double min_ref_frac,
true, // boolean needs_lma);
reduced_strength); // if not null will return >0 if had to reduce strength (no change if did not reduce)
if (reduced_strength[0] > 0) {
use_lma_dsi = false; // too few points
}
if (debug2) {
double [] dbg_img = new double [reliable_ref.length];
for (int i = 0; i < dbg_img.length; i++) {
......@@ -4565,7 +4575,9 @@ public class OpticalFlow {
}
double [][][] scenes_xyzatr = new double [quadCLTs.length][][]; // previous scene relative to the next one
scenes_xyzatr[ref_index] = new double[2][3]; // all zeros
boolean after_spiral = false;
boolean got_spiral = false;
int search_rad = clt_parameters.imp.search_rad; // 10;
for (int scene_index = ref_index - 1; scene_index >= earliest_scene ; scene_index--) {
if ((ref_index - scene_index) >= max_num_scenes){
earliest_scene = scene_index + 1;
......@@ -4585,15 +4597,21 @@ public class OpticalFlow {
QuadCLT scene_QuadClt = quadCLTs[scene_index];
// get initial xyzatr:
// TODO:repeat spiralSearchATR if found scene was too close
if (scene_index == ref_index - 1) { // search around for the best fit
// if (scene_index == ref_index - 1) { // search around for the best fit
if (!got_spiral) { // search around for the best fit
use_atr = spiralSearchATR(
clt_parameters, // CLTParameters clt_parameters,
use_lma_dsi, // may be turned off by the caller if there are too few points
search_rad, // int search_rad
quadCLTs[ref_index], // QuadCLT reference_QuadClt,
scene_QuadClt, // QuadCLT scene_QuadClt,
reliable_ref, // ********* boolean [] reliable_ref,
debugLevel);
if (use_atr == null) {
if (num_scene_retries-- > 0) {
search_rad = retry_radius; // faster, no need/sense to look far
continue;
}
earliest_scene = scene_index + 1;
if (debugLevel > -3) {
System.out.println("Pass multi scene "+scene_index+" (of "+ quadCLTs.length+") "+
......@@ -4602,18 +4620,23 @@ public class OpticalFlow {
}
// set this and all previous to null
for (; scene_index >= 0 ; scene_index--) {
ers_reference.addScene(quadCLTs[scene_index].getImageName(), null);
if (quadCLTs[scene_index] == null) {
System.out.println("setInitialOrientations(): quadCLTs["+scene_index+"] is alreadu null!");
} else {
ers_reference.addScene(quadCLTs[scene_index].getImageName(), null); // null pointer
}
}
break; // failed with even first before reference
}
after_spiral = true;
got_spiral = true;
scenes_xyzatr[scene_index] = new double [][] {new double[3], use_atr};
} else { // assume linear motion
after_spiral = false;
if (scene_index == debug_scene) {
System.out.println("adjusting orientation, scene_index="+scene_index);
System.out.println("adjusting orientation, scene_index="+scene_index);
}
// int avg_len = 1; // 3;
// double scale_xyz = 0.0; // 0.5;
int na = avg_len;
if ((scene_index + 1 + na) > ref_index) {
na = ref_index - (scene_index + 1);
......@@ -4635,8 +4658,14 @@ public class OpticalFlow {
last_diff);
}
// Refine with LMA
double [][] initial_pose = new double[][]{
scenes_xyzatr[scene_index][0].clone(),
scenes_xyzatr[scene_index][1].clone()};
boolean rot_to_transl = after_spiral && clt_parameters.ilp.ilma_translation_priority;
double [] reg_weights = rot_to_transl? clt_parameters.ilp.ilma_regularization_weights0 : clt_parameters.ilp.ilma_regularization_weights;
scenes_xyzatr[scene_index] = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters,
use_lma_dsi, // clt_parameters.imp.use_lma_dsi,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
min_max, // double [] min_max, // null or pair of minimal and maximal offsets
fail_reason, // int [] fail_reason, // null or int[1]: 0 - OK, 1 - LMA, 2 - min, 3 - max
......@@ -4644,12 +4673,12 @@ public class OpticalFlow {
null, // double [] ref_disparity, // null or alternative reference disparity
reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles
scene_QuadClt, // QuadCLT scene_QuadCLT,
scenes_xyzatr[scene_index][0], // xyz
scenes_xyzatr[scene_index][1], // atr
scenes_xyzatr[scene_index][0], // double [] scene_xyz_pull, // if both are not null, specify target values to pull to
scenes_xyzatr[scene_index][1], // double [] scene_atr_pull, //
initial_pose[0], // xyz
initial_pose[1], // atr
initial_pose[0], // double [] scene_xyz_pull, // if both are not null, specify target values to pull to
rot_to_transl? (new double[3]):initial_pose[1], // double [] scene_atr_pull, //
clt_parameters.ilp.ilma_lma_select, // final boolean[] param_select,
clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights,
reg_weights, // clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights,
lma_rms, // double [] rms, // null or double [2]
clt_parameters.imp.max_rms, // double max_rms,
clt_parameters.imp.debug_level); // 1); // -1); // int debug_level);
......@@ -4660,13 +4689,15 @@ public class OpticalFlow {
adjust_OK = false;
}
// FAIL_REASON_ROLL
handle_failure: {
if (!adjust_OK) {
boolean OK = false;
// boolean OK = false;
System.out.println("LMA failed at nscene = "+scene_index+". Reason = "+fail_reason[0]);
if (fail_reason[0]==FAIL_REASON_MIN) {
if ((fail_reason[0]==FAIL_REASON_MIN) || ((fail_reason[0]==FAIL_REASON_LMA) && !got_spiral)) {
if (fpn_skip) {
System.out.println("fpn_skip is set, just skipping this scene");
continue; // to next scene
System.out.println("fpn_skip is set, just using initial pose");
scenes_xyzatr[scene_index] = initial_pose;
break handle_failure; // to next scene
} else {
System.out.println("fpn_skip is not set, aborting series and adjusting earliest_scene");
// set this and all previous to null
......@@ -4682,10 +4713,30 @@ public class OpticalFlow {
// set this and all previous to null
for (; scene_index >= 0 ; scene_index--) {
ers_reference.addScene(quadCLTs[scene_index].getImageName(), null);
// quadCLTs[scene_index] = null; // completely remove early scenes?
// quadCLTs[scene_index] = null; // completely remove early scenes?
}
break;
}
}
if (after_spiral && (scene_index < (ref_index-1))) { // need to interpolate skipped scenes
// here we expect very small translations/angles, so linear scaling is OK
double s = 1.0 / (ref_index - scene_index);
for (int interp_index = ref_index-1; interp_index > scene_index; interp_index--) {
scenes_xyzatr[interp_index] = new double[2][3];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
scenes_xyzatr[interp_index][i][j] =
scenes_xyzatr[scene_index][i][j] * s *(interp_index - scene_index);
}
}
ers_reference.addScene(scene_QuadClt.getImageName(),
scenes_xyzatr[interp_index][0],
scenes_xyzatr[interp_index][1],
ZERO3, // ers_scene.getErsXYZ_dt(),
ZERO3 // ers_scene.getErsATR_dt()
);
}
}
/* old version
if (scenes_xyzatr[scene_index] == null) {
......@@ -4875,6 +4926,7 @@ public class OpticalFlow {
int test_ers1 = clt_parameters.imp.test_ers1; // try adjusting a pair of scenes with ERS. Other scene index
test_ers &= (test_ers0 >= 0) && (test_ers1 >= 0);
double min_ref_str = clt_parameters.imp.min_ref_str;
double min_ref_frac= clt_parameters.imp.min_ref_frac;
double [] ref_blue_sky = null; // turn off "lma" in the ML output
if (reuse_video) { // disable all other options
generate_mapped = false;
......@@ -5106,14 +5158,20 @@ public class OpticalFlow {
null, // String path, // full name with extension or w/o path to use x3d directory
debugLevel+1);
}
double [] reduced_strength = new double[1];
// boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
if (quadCLTs[ref_index].getNumOrient() < min_num_orient) {
boolean [] reliable_ref = null;
if (min_ref_str > 0.0) {
reliable_ref = quadCLTs[ref_index].getReliableTiles( // will be null if does not exist.
min_ref_str, // double min_strength,
true); // boolean needs_lma);
min_ref_frac, // double min_ref_frac,
true, // boolean needs_lma);
reduced_strength); // if not null will return >0 if had to reduce strength (no change if did not reduce)
}
// if (reduced_strength[0] > 0) {
// use_lma_dsi = false; // too few points
// }
// on last pass use final max MB correction same as for render (mb_max_gain - typical =5.0),
// for earlier - mb_max_gain_inter (which may be smaller - typical = 2.0)
double mb_max_gain = clt_parameters.imp.mb_max_gain;
......@@ -6624,6 +6682,7 @@ public class OpticalFlow {
double [][] adjusted_xyzatr = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters,
clt_parameters.imp.use_lma_dsi,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
null, // double [] min_max, // null or pair of minimal and maximal offsets
null, // int [] fail_reason, // null or int[1]: 0 - OK, 1 - LMA, 2 - min, 3 - max
......@@ -6784,7 +6843,7 @@ public class OpticalFlow {
public static ImagePlus renderSceneSequence(
CLTParameters clt_parameters,
Rectangle fov_tiles,
int mode3d,
int mode3d, // for older compatibility mode3d = -1 for RAW, 0 - INF, 1 - FG, 2 BG
boolean toRGB,
double [] stereo_xyz, // offset reference camera {x,y,z}
int sensor_mask,
......@@ -7014,6 +7073,8 @@ public class OpticalFlow {
public static double [] spiralSearchATR(
CLTParameters clt_parameters,
boolean use_lma_dsi, // may be turned off by the caller if there are too few points
int search_rad, // to reduce for the next scenes on failure (FPN filter)
QuadCLT reference_QuadClt,
QuadCLT scene_QuadClt,
boolean [] reliable_ref,
......@@ -7027,7 +7088,7 @@ public class OpticalFlow {
int sensor_mask_inter = clt_parameters.imp.sensor_mask_inter ; //-1;
float [][][] facc_2d_img = new float [1][][];
int pix_step = clt_parameters.imp.pix_step; // 4;
int search_rad = clt_parameters.imp.search_rad; // 10;
// int search_rad = clt_parameters.imp.search_rad; // 10;
double maybe_sum = clt_parameters.imp.maybe_sum; // 8.0;
double sure_sum = clt_parameters.imp.sure_sum; // 30.0;
double maybe_avg = clt_parameters.imp.maybe_avg; // 0.005;
......@@ -7038,7 +7099,7 @@ public class OpticalFlow {
double sure_fom = clt_parameters.imp.sure_fom; // 10.0; // good - 30, second good - 10
boolean treat_serch_fpn = clt_parameters.imp.treat_serch_fpn;// use FPN (higher) thresholds during search (even if offset is not small)
boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
// boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
double [][] pose = new double [2][3];
double angle_per_step = reference_QuadClt.getGeometryCorrection().getCorrVector().getTiltAzPerPixel() * pix_step;
......@@ -7374,6 +7435,7 @@ public class OpticalFlow {
if (high_res_motion_vectors) {
scenes_xyzatr[i] = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters,
clt_parameters.imp.use_lma_dsi,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
null, // double [] min_max, // null or pair of minimal and maximal offsets
null, // int [] fail_reason, // null or int[1]: 0 - OK, 1 - LMA, 2 - min, 3 - max
......@@ -7487,6 +7549,7 @@ public class OpticalFlow {
if (high_res_motion_vectors) {
scenes_xyzatr[i] = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters,
clt_parameters.imp.use_lma_dsi,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
null, // double [] min_max, // null or pair of minimal and maximal offsets
null, // int [] fail_reason, // null or int[1]: 0 - OK, 1 - LMA, 2 - min, 3 - max
......@@ -7632,6 +7695,7 @@ public class OpticalFlow {
if (high_res_motion_vectors) {
scenes_xyzatr[i] = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters,
clt_parameters.imp.use_lma_dsi,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
null, // double [] min_max, // null or pair of minimal and maximal offsets
null, // int [] fail_reason, // null or int[1]: 0 - OK, 1 - LMA, 2 - min, 3 - max
......@@ -12750,8 +12814,20 @@ public class OpticalFlow {
disparity_map[ImageDtt.DISPARITY_INDEX_CM+1]};
}
// remove disparity average, only detect tilts
if (use3D_lma_tilt_only) {
double average_disparity = 0;
double average_absolute_disparity = 0;
{
double sw = 0, swd = 0;
for (int i = 0; i < scene_pXpYD.length; i++) {
if ((scene_pXpYD[i]!=null) && !Double.isNaN(scene_pXpYD[i][2])) {
sw+=1.0;
swd += scene_pXpYD[i][2];
}
}
average_absolute_disparity = swd/sw;
// remove average disparity and multiply by average disparity to have the same influence ratio to tild
sw = 0;
swd = 0;
for (int i = 0; i < scene_disparity_strength[0].length; i++) {
if (Double.isNaN(scene_disparity_strength[0][i]) || Double.isNaN(scene_disparity_strength[1][i])) {
scene_disparity_strength[0][i]=0;
......@@ -12760,9 +12836,12 @@ public class OpticalFlow {
sw += scene_disparity_strength[1][i];
swd += scene_disparity_strength[0][i] * scene_disparity_strength[1][i];
}
double avg = swd/sw;
average_disparity = swd/sw;
double magic_scale = use3D_lma? 1.0 : ref_scene.getTileProcessor().getMagicScale();
for (int i = 0; i < scene_disparity_strength[0].length; i++) {
scene_disparity_strength[0][i] -= avg;
// scene_disparity_strength[0][i] = (scene_disparity_strength[0][i] - average_disparity) / average_absolute_disparity;
scene_disparity_strength[0][i] = (scene_disparity_strength[0][i] - average_disparity) /magic_scale;
scene_disparity_strength[0][i] = 1.0 / average_absolute_disparity;
}
}
}
......@@ -14094,7 +14173,7 @@ public class OpticalFlow {
double mb_tau = clt_parameters.imp.mb_tau; // 0.008; // time constant, sec
// double mb_max_gain = clt_parameters.imp.mb_max_gain_inter; // 5.0; // motion blur maximal gain (if more - move second point more than a pixel
int margin = clt_parameters.imp.margin;
double second_margin = 1.1; // allow slightly larger offset for readjsutments (to be limited by the first pass)
int earliest_scene = 0;
boolean use_combo_dsi = clt_parameters.imp.use_combo_dsi;
boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
......@@ -14103,7 +14182,7 @@ public class OpticalFlow {
int tilesY = quadCLTs[ref_index].getTileProcessor().getTilesY();
int tile_size = quadCLTs[ref_index].getTileProcessor().getTileSize();
double min_offset = clt_parameters.imp.min_offset;
double max_offset = clt_parameters.imp.max_rel_offset * tilesX * tile_size;
double max_offset = second_margin*clt_parameters.imp.max_rel_offset * tilesX * tile_size;
double max_roll = clt_parameters.imp.max_roll_deg*Math.PI/180.0;
boolean fpn_skip = clt_parameters.imp.fpn_skip; // if false - fail as before
boolean fpn_rematch = clt_parameters.imp.fpn_rematch; // if false - keep previous
......@@ -14168,7 +14247,7 @@ public class OpticalFlow {
scenes_xyzatr[ref_index] = new double[2][3]; // all zeros
// should have at least next or previous non-null
int debug_scene = -15;
int debug_scene = -8;
double maximal_series_rms = 0.0;
double [][] mb_vectors_ref = null;
TpTask[][] tp_tasks_ref = null;
......@@ -14218,7 +14297,8 @@ public class OpticalFlow {
}
System.out.println();
}
boolean [] failed_scenes = new boolean[quadCLTs.length];
int num_failed =0;
for (int nscene = ref_index; nscene >= earliest_scene; nscene--) {
if (nscene == debug_scene) {
System.out.println("nscene = "+nscene);
......@@ -14251,8 +14331,8 @@ public class OpticalFlow {
if (dbg_mb_img != null) {
boolean show_corrected = false;
if (nscene == debug_scene) {
System.out.println("nscene = "+nscene);
System.out.println("nscene = "+nscene);
System.out.println("2.nscene = "+nscene);
System.out.println("3.nscene = "+nscene);
}
dbg_mb_img[nscene] = new double [tilesX*tilesY*2];
Arrays.fill(dbg_mb_img[nscene],Double.NaN);
......@@ -14442,13 +14522,21 @@ public class OpticalFlow {
adjust_OK = false;
}
// FAIL_REASON_ROLL
handle_failure: {
if (!adjust_OK) {
boolean OK = false;
System.out.println("LMA failed at nscene = "+nscene+". Reason = "+fail_reason[0]);
if (fail_reason[0]==FAIL_REASON_MIN) {
if ((fail_reason[0]==FAIL_REASON_MIN) || ((fail_reason[0]==FAIL_REASON_LMA))) {
if (fpn_skip) {
System.out.println("fpn_skip is set, just skipping this scene");
continue; // to next scene
failed_scenes[nscene] = true;
num_failed++;
scenes_xyzatr[nscene] = new double[][] {
scene_xyz_pre, // for now restore original, pre-adjustment
scene_atr_pre // for now restore original, pre-adjustment
};
break handle_failure;
// continue; // to next scene
} else {
System.out.println("fpn_skip is not set, aborting series and adjusting earliest_scene");
// set this and all previous to null
......@@ -14468,6 +14556,7 @@ public class OpticalFlow {
}
break;
}
}
// overwrite old data
ers_reference.addScene(ts,
scenes_xyzatr[nscene][0],
......@@ -14741,6 +14830,7 @@ public class OpticalFlow {
public static double[][] adjustPairsLMAInterscene(
CLTParameters clt_parameters,
boolean use_lma_dsi,
boolean fpn_disable, // disable fpn filter if images are known to be too close
double [] min_max, // null or pair of minimal and maximal offsets
int [] fail_reason, // null or int[1]: 0 - OK, 1 - LMA, 2 - min, 3 - max
......@@ -14758,7 +14848,7 @@ public class OpticalFlow {
double max_rms,
int debug_level)
{
boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
// boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
if (ref_disparity == null) {
ref_disparity = reference_QuadClt.getDLS()[use_lma_dsi?1:0];
}
......@@ -14925,10 +15015,11 @@ public class OpticalFlow {
}
}
if (show_corr_fpn && (debug_level > -1)) { // now not needed, restore if needed
int num_components = intersceneLma.getNumComponents();
// int num_components = intersceneLma.getNumComponents();
int num_components = 2;
String [] fpn_dbg_titles = new String[num_components + scene_QuadClt.getNumSensors() * 2];
fpn_dbg_titles[0] = "X_avg";
fpn_dbg_titles[1] = "X_avg";
fpn_dbg_titles[1] = "Y_avg";
if (num_components > 2) {
fpn_dbg_titles[2] = "Disp";
}
......@@ -14974,12 +15065,17 @@ public class OpticalFlow {
fpn_dbg_titles);
}
if (show_corr_fpn) { // repeat after last adjustment to get images
String [] fpn_dbg_titles = new String[2 + scene_QuadClt.getNumSensors() * 2];
fpn_dbg_titles[00] = "X_avg";
fpn_dbg_titles[1] = "X_avg";
// int num_components = intersceneLma.getNumComponents();
int num_components = 2; // herte - no disparity
String [] fpn_dbg_titles = new String[num_components + scene_QuadClt.getNumSensors() * 2];
fpn_dbg_titles[0] = "X_avg";
fpn_dbg_titles[1] = "Y_avg";
if (num_components > 2) {
fpn_dbg_titles[2] = "Disp";
}
for (int i = 0; i < scene_QuadClt.getNumSensors(); i++) {
fpn_dbg_titles[2 + 2*i] = "X-"+i;
fpn_dbg_titles[3 + 2*i] = "Y-"+i;
fpn_dbg_titles[num_components + 0 + 2*i] = "X-"+i;
fpn_dbg_titles[num_components + 1 + 2*i] = "Y-"+i;
}
float [][] dbg_corr_fpn = new float [fpn_dbg_titles.length][];
coord_motion = interCorrPair( // new double [tilesY][tilesX][][];
......
......@@ -1363,10 +1363,14 @@ public class QuadCLTCPU {
dsi,
silent);
}
//min_ref_frac
public boolean [] getReliableTiles(
double min_strength,
boolean needs_lma) {
double min_ref_frac,
boolean needs_lma,
double [] reduced_strength // if not null will return >0 if had to reduce strength (no change if did not reduce)
) {
int NUM_BINS = 1024;
double [][] main_dsi = readDsiMain();
if (main_dsi == null) {
return null;
......@@ -1376,6 +1380,9 @@ public class QuadCLTCPU {
if ((strength == null) || (needs_lma && (disparity_lma == null) )) {
return null;
}
int min_reliable = (int) Math.round (strength.length * min_ref_frac);
strength = strength.clone();
boolean [] reliable = new boolean [strength.length];
for (int i = 0; i < reliable.length; i++) {
reliable[i] = (strength[i] >= min_strength) &&
......@@ -1384,11 +1391,50 @@ public class QuadCLTCPU {
boolean [] blue_sky = getBooleanBlueSky();
if (blue_sky != null) {
for (int i = 0; i < reliable.length; i++) {
reliable[i] &= !blue_sky[i];
if (blue_sky[i]){
reliable[i] = false;
strength[i] = 0.0;
}
}
}
int num_reliable = 0;
for (boolean b: reliable) if (b) num_reliable++;
if (num_reliable < min_reliable) { // not enough, select best tiles, ignoring LMA
double max_str = 0;
for (double s:strength) if ((s > max_str) )max_str= s; // NaN OK
if (max_str == 0) return null;
int [] hist = new int[NUM_BINS];
int num_gt0 = 0;
for (double s:strength) if (s > 0) { // verify enough > 0
int bin = (int) Math.floor(NUM_BINS * s /max_str);
if (bin >= NUM_BINS) bin = NUM_BINS - 1;
hist[bin]++;
num_gt0++;
}
if (num_gt0 < min_reliable) {
return null; // not enough non-zero values
}
num_reliable = 0;
int num_prev = 0;
int bin = NUM_BINS - 1;
for (; num_reliable < min_reliable; bin--) {
num_prev = num_reliable;
num_reliable += hist[bin];
}
double threshold = (bin + 1.0 * (num_reliable - min_reliable) / (num_reliable - num_prev)) * max_str / NUM_BINS;
num_reliable = 0;
for (int i = 0; i < reliable.length; i++) {
reliable[i] = (strength[i] > threshold);
if (reliable[i]) num_reliable++;
}
if (reduced_strength != null) {
reduced_strength[0] = threshold;
}
}
return reliable;
}
public double [][] readDsiMain(){
double [][] main_dsi = new double [TwoQuadCLT.DSI_SLICES.length][];
int slices = restoreDSI(
......
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