Commit 96562ce2 authored by Andrey Filippov's avatar Andrey Filippov

Next snapshot, debugging

parent 019655f7
......@@ -258,6 +258,9 @@ public class Interscene {
quadCLTs[cent_index].saveInterProperties( // save properties for interscene processing (extrinsics, ers, ...) // null pointer
null, // String path, // full name with extension or w/o path to use x3d directory
debugLevel+1);
if (debugLevel > -3) {
System.out.println("setInitialOrientationsCenterIms(): return earliest_scene2="+earliest_scene2);
}
return earliest_scene2;
}
......@@ -448,6 +451,7 @@ public class Interscene {
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
true, // boolean disable_ers,
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
quadCLTs[ref_index], // QuadCLT reference_QuadCLT,
......@@ -820,6 +824,7 @@ public class Interscene {
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
true, // boolean disable_ers,
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
quadCLTs[ref_index], // QuadCLT reference_QuadCLT,
......@@ -966,6 +971,7 @@ public class Interscene {
public static int reAdjustPairsLMAInterscene( // after combo dgi is available and preliminary poses are known
CLTParameters clt_parameters,
double mb_max_gain,
boolean disable_ers,
boolean [] reliable_ref, // null or bitmask of reliable reference tiles
QuadCLT [] quadCLTs,
int ref_index,
......@@ -1363,6 +1369,7 @@ public class Interscene {
clt_parameters, // CLTParameters clt_parameters,
false, // boolean initial_adjust,
fpn_disable, // boolean fpn_disable, // disable fpn filter if images are known to be too close
disable_ers, // boolean disable_ers,
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
quadCLTs[ref_index], // QuadCLT reference_QuadCLT,
......@@ -1484,6 +1491,7 @@ public class Interscene {
CLTParameters clt_parameters,
boolean use_lma_dsi,
boolean fpn_disable, // disable fpn filter if images are known to be too close
boolean disable_ers,
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
QuadCLT reference_QuadClt,
......@@ -1533,6 +1541,7 @@ public class Interscene {
clt_parameters, // CLTParameters clt_parameters,
true, // boolean initial_adjust,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
disable_ers, // boolean disable_ers,
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
reference_QuadClt, // QuadCLT reference_QuadClt,
......@@ -1561,6 +1570,7 @@ public class Interscene {
CLTParameters clt_parameters,
boolean initial_adjust,
boolean fpn_disable, // disable fpn filter if images are known to be too close
boolean disable_ers,
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
QuadCLT reference_QuadClt,
......@@ -1641,9 +1651,8 @@ public class Interscene {
for (int i:ErsCorrection.DP_ERS_INDICES) {
ers_lma |= param_select[i];
}
boolean disable_ers=false;
boolean [] param_select_mod = param_select;
if (ers_lma && filter_by_ers) {
if (ers_lma && filter_by_ers && !disable_ers) {
double [][] quad_strengths = getQuadStrengths(
coord_motion, // double [][][] coord_motion,
gap_frac, //double gap_frac, // 0.25
......@@ -1651,31 +1660,30 @@ public class Interscene {
for (int i = 0; i < quad_strengths[0].length; i++) {
if ((quad_strengths[0][i] < min_quad_tiles) || (quad_strengths[1][i] < min_quad_weight)) {
disable_ers = true;
if (clt_parameters.imp.debug_level > -2) {
System.out.print("adjustPairsLMAInterscene(): insufficient data for ERS, skipping. ");
System.out.println ("quad_defined = ["+((int)quad_strengths[0][0])+","
+((int)quad_strengths[0][1])+","+((int)quad_strengths[0][2])+","+((int)quad_strengths[0][3])+"] (needed = "+
min_quad_tiles +"), rel_strengths = ["
+quad_strengths[1][0]+","+quad_strengths[1][1]+","
+quad_strengths[1][2]+","+quad_strengths[1][3]+"] (needed "
+min_quad_weight+")");
}
break;
}
}
if (disable_ers) {
param_select_mod = param_select.clone();
for (int i:ErsCorrection.DP_ERS_INDICES) {
param_select_mod[i] = false;
}
// now just copy ers from the reference
ErsCorrection ers_ref = reference_QuadClt.getErsCorrection();
ErsCorrection ers_scene = scene_QuadClt.getErsCorrection();
ers_scene.ers_watr_center_dt = ers_ref.ers_watr_center_dt.clone();
ers_scene.ers_wxyz_center_dt = ers_ref.ers_wxyz_center_dt.clone();
if (clt_parameters.imp.debug_level > -2) {
System.out.print("adjustPairsLMAInterscene(): insufficient data for ERS, skipping. ");
System.out.println ("quad_defined = ["+((int)quad_strengths[0][0])+","
+((int)quad_strengths[0][1])+","+((int)quad_strengths[0][2])+","+((int)quad_strengths[0][3])+"] (needed = "+
min_quad_tiles +"), rel_strengths = ["
+quad_strengths[1][0]+","+quad_strengths[1][1]+","
+quad_strengths[1][2]+","+quad_strengths[1][3]+"] (needed "
+min_quad_weight+")");
}
}
if (disable_ers) {
param_select_mod = param_select.clone();
for (int i:ErsCorrection.DP_ERS_INDICES) {
param_select_mod[i] = false;
}
// now just copy ers from the reference
ErsCorrection ers_ref = reference_QuadClt.getErsCorrection();
ErsCorrection ers_scene = scene_QuadClt.getErsCorrection();
ers_scene.ers_watr_center_dt = ers_ref.ers_watr_center_dt.clone();
ers_scene.ers_wxyz_center_dt = ers_ref.ers_wxyz_center_dt.clone();
}
intersceneLma.prepareLMA(
camera_xyz0, // final double [] scene_xyz0, // camera center in world coordinates (or null to use instance)
camera_atr0, // final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance)
......
......@@ -44,6 +44,16 @@ public class IntersceneMatchParameters {
public boolean sfm_use = true; // use SfM to improve depth map
public double sfm_min_base = 2.0; // use SfM if baseline exceeds this
public int sfm_num_pairs = 16; // desired number of SfM pairs to average
public double sfp_tolerance = 0.05; // average SfM pairs if their baselines differ less
public int sfm_readjust = 5; // number of SfM readjustment cycles
public double sfm_prev_frac = 0.6; // update if new sfm gain > this fraction of the old one
public int sfm_shrink = 2; // shrink sfm gain area before applying sfm_fade_sigma
public double sfm_fade_sigma = 3.0; // fade SfM gains at the edges
public double sfm_min_str = 0.4; // update if correction strength exceeds
public boolean sfm_use_neibs = true; // use neighbors if individual corr is too weak
public double sfm_neib_too_str= 0.4; // do not count neighbors stronger than that
public double sfm_neib_str= 0.5; // update if no-individual and neibs correction strength exceeds
public double [] getImsMountATR() {
......@@ -443,6 +453,28 @@ public class IntersceneMatchParameters {
gd.addNumericField("Minimal SfM baseline", this.sfm_min_base, 5,8,"m",
"Use SfM only if the baseline (lateral offset between scenes in a series) exceeds this value.");
gd.addNumericField("Number of SfM pairs to average", this.sfm_num_pairs, 0,3,"",
"Desired number of SfM pairs to average, will be reduced if not enough or tolerance (below) is violated.");
gd.addNumericField("SfP inter-pair baseline tolerance", this.sfp_tolerance, 5,8,"",
"Average SfM pairs if their baselines differ less.");
gd.addNumericField("Readjust SfM cycles", this.sfm_readjust, 0,3,"",
"Number of SfM readjustment cycles.");
gd.addNumericField("Minimal SfM gain from previous", this.sfm_prev_frac, 5,8,"",
"Update if new sfm gain > this fraction of the old one.");
gd.addNumericField("Shrink SfM area", this.sfm_shrink, 0,3,"",
"Shrink sfm gain area before applying sfm_fade_sigmas.");
gd.addNumericField("Fade SfM area sigma", this.sfm_fade_sigma, 5,8,"",
"Fade SfM gains at the edges.");
gd.addNumericField("Minimal correlation strength", this.sfm_min_str, 5,8,"",
"Update if correction strength of individual tiles exceeds.");
gd.addCheckbox ("Use neighbors", this.sfm_use_neibs,
"Use neighbors if individual corr is too weak.");
gd.addNumericField("Too strong neighbors", this.sfm_neib_too_str, 5,8,"",
"Do not accumulate neighbors stronger than that.");
gd.addNumericField("Minimal neighbors strength", this.sfm_neib_str, 5,8,"",
"Update if no-individual and neighbors correction strength exceeds this.");
gd.addTab ("Scene Series", "Processing series of scenes and multi-series sets");
gd.addMessage ("Build series options");
......@@ -1114,6 +1146,16 @@ public class IntersceneMatchParameters {
this.ims_mount_xyz = IntersceneMatchParameters. StringToDoubles(gd.getNextString(), 3);
this.sfm_use = gd.getNextBoolean();
this.sfm_min_base = gd.getNextNumber();
this.sfm_num_pairs = (int) gd.getNextNumber();
this.sfp_tolerance = gd.getNextNumber();
this.sfm_readjust = (int) gd.getNextNumber();
this.sfm_prev_frac = gd.getNextNumber();
this.sfm_shrink = (int) gd.getNextNumber();
this.sfm_fade_sigma = gd.getNextNumber();
this.sfm_min_str = gd.getNextNumber();
this.sfm_use_neibs = gd.getNextBoolean();
this.sfm_neib_too_str = gd.getNextNumber();
this.sfm_neib_str = gd.getNextNumber();
this.center_reference = gd.getNextBoolean();
this.force_ref_dsi = gd.getNextBoolean();
this.force_orientations = gd.getNextBoolean();
......@@ -1469,7 +1511,17 @@ public class IntersceneMatchParameters {
properties.setProperty(prefix+"ims_mount_xyz", IntersceneMatchParameters.doublesToString(this.ims_mount_xyz));
properties.setProperty(prefix+"sfm_use", this.sfm_use + ""); // boolean
properties.setProperty(prefix+"sfm_min_base", this.sfm_min_base+""); // double
properties.setProperty(prefix+"center_reference", this.center_reference + ""); // boolean
properties.setProperty(prefix+"sfm_num_pairs", this.sfm_num_pairs+""); // int
properties.setProperty(prefix+"sfp_tolerance", this.sfp_tolerance+""); // double
properties.setProperty(prefix+"sfm_readjust", this.sfm_readjust+""); // int
properties.setProperty(prefix+"sfm_prev_frac", this.sfm_prev_frac+""); // double
properties.setProperty(prefix+"sfm_shrink", this.sfm_shrink+""); // int
properties.setProperty(prefix+"sfm_fade_sigma", this.sfm_fade_sigma+""); // double
properties.setProperty(prefix+"sfm_min_str", this.sfm_min_str+""); // double
properties.setProperty(prefix+"sfm_use_neibs", this.sfm_use_neibs+""); // boolean
properties.setProperty(prefix+"sfm_neib_too_str", this.sfm_neib_too_str+""); // double
properties.setProperty(prefix+"sfm_neib_str", this.sfm_neib_str +""); // double
properties.setProperty(prefix+"center_reference", this.center_reference + ""); // boolean
properties.setProperty(prefix+"force_ref_dsi", this.force_ref_dsi + ""); // boolean
properties.setProperty(prefix+"force_orientations", this.force_orientations + ""); // boolean
properties.setProperty(prefix+"run_ly", this.run_ly + ""); // boolean
......@@ -1784,6 +1836,16 @@ public class IntersceneMatchParameters {
if (properties.getProperty(prefix+"ims_mount_xyz")!=null) this.ims_mount_xyz= IntersceneMatchParameters.StringToDoubles(properties.getProperty(prefix+"ims_mount_xyz"),3);
if (properties.getProperty(prefix+"sfm_use")!=null) this.sfm_use=Boolean.parseBoolean(properties.getProperty(prefix+"sfm_use"));
if (properties.getProperty(prefix+"sfm_min_base")!=null) this.sfm_min_base=Double.parseDouble(properties.getProperty(prefix+"sfm_min_base"));
if (properties.getProperty(prefix+"sfm_num_pairs")!=null) this.sfm_num_pairs=Integer.parseInt(properties.getProperty(prefix+"sfm_num_pairs"));
if (properties.getProperty(prefix+"sfp_tolerance")!=null) this.sfp_tolerance=Double.parseDouble(properties.getProperty(prefix+"sfp_tolerance"));
if (properties.getProperty(prefix+"sfm_readjust")!=null) this.sfm_readjust=Integer.parseInt(properties.getProperty(prefix+"sfm_readjust"));
if (properties.getProperty(prefix+"sfm_prev_frac")!=null) this.sfm_prev_frac=Double.parseDouble(properties.getProperty(prefix+"sfm_prev_frac"));
if (properties.getProperty(prefix+"sfm_shrink")!=null) this.sfm_shrink=Integer.parseInt(properties.getProperty(prefix+"sfm_shrink"));
if (properties.getProperty(prefix+"sfm_fade_sigma")!=null) this.sfm_fade_sigma=Double.parseDouble(properties.getProperty(prefix+"sfm_fade_sigma"));
if (properties.getProperty(prefix+"sfm_min_str")!=null) this.sfm_min_str=Double.parseDouble(properties.getProperty(prefix+"sfm_min_str"));
if (properties.getProperty(prefix+"sfm_use_neibs")!=null) this.sfm_use_neibs=Boolean.parseBoolean(properties.getProperty(prefix+"sfm_use_neibs"));
if (properties.getProperty(prefix+"sfm_neib_too_str")!=null) this.sfm_neib_too_str=Double.parseDouble(properties.getProperty(prefix+"sfm_neib_too_str"));
if (properties.getProperty(prefix+"sfm_neib_str")!=null) this.sfm_neib_str=Double.parseDouble(properties.getProperty(prefix+"sfm_neib_str"));
if (properties.getProperty(prefix+"center_reference")!=null) this.center_reference=Boolean.parseBoolean(properties.getProperty(prefix+"center_reference"));
if (properties.getProperty(prefix+"force_ref_dsi")!=null) this.force_ref_dsi=Boolean.parseBoolean(properties.getProperty(prefix+"force_ref_dsi"));
if (properties.getProperty(prefix+"force_orientations")!=null) this.force_orientations=Boolean.parseBoolean(properties.getProperty(prefix+"force_orientations"));
......@@ -2126,6 +2188,16 @@ public class IntersceneMatchParameters {
imp.ims_mount_xyz = this.ims_mount_xyz.clone();
imp.sfm_use = this.sfm_use;
imp.sfm_min_base = this.sfm_min_base;
imp.sfm_num_pairs = this.sfm_num_pairs;
imp.sfp_tolerance = this.sfp_tolerance;
imp.sfm_readjust = this.sfm_readjust;
imp.sfm_prev_frac = this.sfm_prev_frac;
imp.sfm_shrink = this.sfm_shrink;
imp.sfm_fade_sigma = this.sfm_fade_sigma;
imp.sfm_min_str = this.sfm_min_str;
imp.sfm_use_neibs = this.sfm_use_neibs;
imp.sfm_neib_too_str = this.sfm_neib_too_str;
imp.sfm_neib_str = this.sfm_neib_str;
imp.center_reference = this.center_reference;
imp.force_ref_dsi = this.force_ref_dsi;
imp.force_orientations = this.force_orientations;
......
......@@ -3572,6 +3572,7 @@ public class OpticalFlow {
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
false, // boolean disable_ers,
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
reference_QuadClt, // QuadCLT reference_QuadCLT,
......@@ -4885,7 +4886,7 @@ public class OpticalFlow {
boolean OK = false;
int es1 = -1;
if (center_reference) {
ref_index = Interscene.setInitialOrientationsCenterIms(
es1 = Interscene.setInitialOrientationsCenterIms(
clt_parameters, // final CLTParameters clt_parameters,
min_num_scenes, // int min_num_scenes,
colorProcParameters, // final ColorProcParameters colorProcParameters,
......@@ -4896,14 +4897,20 @@ public class OpticalFlow {
last_index, // final int ref_index,
set_channels, // final QuadCLT.SetChannels [] set_channels,
batch_mode, // final boolean batch_mode,
earliest_scene, // int earliest_scene,
earliest_scene, // int ,
start_ref_pointers, // int [] start_ref_pointers, // [0] - earliest valid scene, [1] ref_index
threadsMax, // final int threadsMax,
updateStatus, // final boolean updateStatus,
debugLevel);
OK = ref_index >= 0;
OK = es1 >= 0;
if (OK) {
ref_index =quadCLTs[last_index].getReferenceIndex(quadCLTs);
int [] first_last_index = quadCLTs[ref_index].getFirstLastIndex(quadCLTs);
earliest_scene = first_last_index[0];
last_index = first_last_index[1];
}
} else if (ims_use) {
es1 = Interscene.setInitialOrientationsIms(
earliest_scene = Interscene.setInitialOrientationsIms(
clt_parameters, // final CLTParameters clt_parameters,
min_num_scenes, // int min_num_scenes,
colorProcParameters, // final ColorProcParameters colorProcParameters,
......@@ -4916,9 +4923,9 @@ public class OpticalFlow {
threadsMax, // final int threadsMax,
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
OK = es1 >=0;
OK = earliest_scene >=0;
} else {
es1= Interscene.setInitialOrientations(
earliest_scene= Interscene.setInitialOrientations(
clt_parameters, // final CLTParameters clt_parameters,
min_num_scenes, // int min_num_scenes,
colorProcParameters, // final ColorProcParameters colorProcParameters,
......@@ -4931,7 +4938,7 @@ public class OpticalFlow {
threadsMax, // final int threadsMax,
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
OK = es1 >=0;
OK = earliest_scene >=0;
}
if (!OK) {
return null;
......@@ -5033,7 +5040,7 @@ public class OpticalFlow {
debugLevel); // final int debugLevel)
*/
// int num_avg_pairs = 16; // number of scene pairs to average
int num_avg_pairs = 1; // number of scene pairs to average
int num_avg_pairs = clt_parameters.imp.sfm_num_pairs; // number of scene pairs to average
QuadCLT[][][] scenes_seq_pairs = new QuadCLT[3][num_avg_pairs][2];
for (int i = 0; i < num_avg_pairs; i++) {
scenes_seq_pairs[0][i][0] = quadCLTs[ref_index + num_avg_pairs - 1 - i];
......@@ -5045,7 +5052,19 @@ public class OpticalFlow {
scenes_seq_pairs[2][i][0] = quadCLTs[last_index - i];
scenes_seq_pairs[2][i][1] = quadCLTs[earliest_scene + num_avg_pairs - 1 - i];
}
double [][] sfm_dsn = StructureFromMotion.sfmPairsSet(
clt_parameters, // final CLTParameters clt_parameters,
quadCLTs[ref_index], // final QuadCLT ref_scene,
scenes_seq_pairs, // scenes_pairs, // final QuadCLT [][] scenes_pairs,
mb_max_gain, // double mb_max_gain,
batch_mode, // final boolean batch_mode,
debugLevel); // final int debugLevel)
if (sfm_dsn != null) {
combo_dsn_final = sfm_dsn;
done_sfm = true;
}
/*
for (int num_seq = 0; num_seq < scenes_seq_pairs.length; num_seq++) {
double [][] sfm_dsn = StructureFromMotion.sfmPair(
clt_parameters, // final CLTParameters clt_parameters,
......@@ -5059,6 +5078,7 @@ public class OpticalFlow {
done_sfm = true;
}
}
*/
}
if (!done_sfm) { // first pass or sfm failed
// should skip scenes w/o orientation 06/29/2022
......@@ -5119,9 +5139,11 @@ public class OpticalFlow {
if (quadCLTs[ref_index].getNumOrient() < (min_num_orient - 1)) {
mb_max_gain = clt_parameters.imp.mb_max_gain_inter;
}
boolean disable_ers = (quadCLTs[ref_index].getNumOrient() < 2); // first orient - no ERS!
earliest_scene = Interscene.reAdjustPairsLMAInterscene( // after combo dsi is available and preliminary poses are known
clt_parameters, // CLTParameters clt_parameters,
mb_max_gain, // double mb_max_gain,
disable_ers, // boolean disable_ers,
reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles
quadCLTs, // QuadCLT [] quadCLTs,
ref_index, // int ref_index,
......@@ -6698,6 +6720,7 @@ public class OpticalFlow {
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
false, // boolean disable_ers,
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
quadCLTs[other_ref[1]], // QuadCLT reference_QuadCLT,
......@@ -7267,6 +7290,7 @@ public class OpticalFlow {
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
false, // boolean disable_ers,
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
reference_QuadClt, // QuadCLT reference_QuadCLT,
......@@ -7381,6 +7405,7 @@ public class OpticalFlow {
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
false, // boolean disable_ers,
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
reference_QuadClt, // QuadCLT reference_QuadCLT,
......@@ -7527,6 +7552,7 @@ public class OpticalFlow {
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
false, // boolean disable_ers,
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
reference_QuadClt, // QuadCLT reference_QuadCLT,
......@@ -11927,7 +11953,7 @@ public class OpticalFlow {
final int tilesY = scene.getTileProcessor().getTilesY();
final int transform_size = scene.getTileProcessor().getTileSize();
final int tiles =tilesX * tilesY;
boolean debug_images = (debug_level > 0) && clt_parameters.ofp.enable_debug_images;
String [] dbg_titles = {"str", "lma", "clean-lma", "disp","-sky","-lma","by-lma","-nonlma", "few_weak", "old-disp","old-sngl","weak","filled"};
double [][] dbg_img = new double [dbg_titles.length][];
double [] clean_lma = dls[1].clone();
......@@ -12121,7 +12147,7 @@ public class OpticalFlow {
ImageDtt.startAndJoin(threads);
if ((debug_level > 0) && (clt_parameters.ofp.enable_debug_images)) {
if (debug_images) {
dbg_titles = new String[]{"disp", "disp_outliers", "disp_blur", "disp_filled", "str", "str_filled"};
dbg_img = new double[][]{dls[0], disp_outliers, ds[0], ds_filled[0], ds[1], ds_filled[1]};
ShowDoubleFloatArrays.showArrays(
......
......@@ -254,7 +254,11 @@ public class TDCorrTile {
* @param tilesX number of tiles in a scan row.
* @param neib_weights_od 2-element array of the relative (to the center tile) weights
* of neighbors in four orthogonal [0] and four diagonal [1]
* directions.
* directions.
* @param corr_pd pixel-domain phase correlation corresponding to tiles to discard too
* strong neighbors. They likely belong the foreground while this (weak)
* is from the background. If null - do not filter by strength.
* @param neib_too_strong discard stronger neighbors from accumulating.
* @param process_all process tiles even if the center tile is null. False - process only
* the tiles around non-null ones.
* @return
......@@ -263,6 +267,8 @@ public class TDCorrTile {
TDCorrTile [] tiles,
final int tilesX,
double [] neib_weights_od, // {orhto, diag}
double [][] corr_pd,
double neib_too_strong,
final boolean process_all
) {
final int tilesY = tiles.length / tilesX;
......@@ -286,6 +292,16 @@ public class TDCorrTile {
for (int dir = 0; dir < tn.dirs; dir++) {
int iTile1 = tn.getNeibIndex(iTile, dir);
if ((iTile1 >=0) && (tiles[iTile1] != null)) {
if ((corr_pd != null) && (corr_pd[iTile1] != null)) {
boolean is_weak = true;
for (double s:corr_pd[iTile1]) if (s >= neib_too_strong) {
is_weak = false;
break;
}
if (!is_weak) {
continue; // skip this strong neighbor from accumulating
}
}
if (rslt[iTile] == null) {
rslt[iTile] = tiles[iTile1].clone();
rslt[iTile].scale(weights[dir]);
......@@ -413,10 +429,16 @@ public class TDCorrTile {
int nTile = (indices[nt * num_pairs] >> GPUTileProcessor.CORR_NTILE_SHIFT);
int fdata_offset = (nt * num_pairs + index_combo) * corr_size_td;
double [] tile_data = new double [corr_size_td];
for (int i = 0; i < tile_data.length; i++) {
tile_data[i] =fdata[fdata_offset+i];
copy_data: {
for (int i = 0; i < tile_data.length; i++) {
double d = fdata[fdata_offset+i];
if (Double.isNaN(d)) {
break copy_data; // accumulated tile may be NaN
}
tile_data[i] =d;
}
tiles[nTile] = new TDCorrTile (index_combo, tile_data); // default weight = 16?
}
tiles[nTile] = new TDCorrTile (index_combo, tile_data); // default weight = 16?
}
}
};
......
......@@ -27,6 +27,7 @@ import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
import com.elphel.imagej.cameras.CLTParameters;
import com.elphel.imagej.common.DoubleGaussianBlur;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.gpu.GPUTileProcessor;
//import com.elphel.imagej.cameras.ColorProcParameters;
......@@ -43,6 +44,7 @@ import com.elphel.imagej.tileprocessor.IntersceneLma;
import com.elphel.imagej.tileprocessor.OpticalFlow;
import com.elphel.imagej.tileprocessor.QuadCLT;
import com.elphel.imagej.tileprocessor.TDCorrTile;
import com.elphel.imagej.tileprocessor.TileNeibs;
import ij.ImagePlus;
......@@ -103,6 +105,7 @@ public class StructureFromMotion {
double [] interscene_ref_disparity = null; // keep null to use old single-scene disparity for interscene matching
if (use_combo_dsi) {
interscene_ref_disparity = ds[0].clone(); // use_lma_dsi ?
/* use conditioned!
if (use_lma_dsi) {
for (int i = 0; i < interscene_ref_disparity.length; i++) {
if (Double.isNaN(dls[1][i])) {
......@@ -110,6 +113,7 @@ public class StructureFromMotion {
}
}
}
*/
}
double [][] ref_pXpYD = null;
......@@ -285,6 +289,7 @@ public class StructureFromMotion {
double [] interscene_ref_disparity = null; // keep null to use old single-scene disparity for interscene matching
if (use_combo_dsi) {
interscene_ref_disparity = ds[0].clone(); // use_lma_dsi ?
/* use conditioned!
if (use_lma_dsi) {
for (int i = 0; i < interscene_ref_disparity.length; i++) {
if (Double.isNaN(dls[1][i])) {
......@@ -292,6 +297,7 @@ public class StructureFromMotion {
}
}
}
*/
}
double [] ref_disparity = interscene_ref_disparity;
......@@ -380,6 +386,8 @@ public class StructureFromMotion {
pairs_TD_all[npair], // pairs_TD, // TDCorrTile [] tiles,
tilesX, // final int tilesX,
neib_weights_od, //double [] neib_weights_od, // {orhto, diag}
null, // double [][] corr_pd,
0.0, // double neib_too_strong,
true); // final boolean process_all
}
......@@ -498,11 +506,15 @@ public class StructureFromMotion {
final int debugLevel) {
boolean show_disp_corr = false; //true;
boolean show_disp_seq = true;
int num_readjust = 5;
final double min_strength = 0.4; // update if correction strength exceeds
final boolean use_neibs = true;
final double min_neib_strength= 0.5; // update if no-individual and neibs correction strength exceeds
final double prev_sfm_frac = 0.6; // update if new sfm gain > this fraction of the old one
final int num_readjust = clt_parameters.imp.sfm_readjust; // 5;
final double min_strength = clt_parameters.imp.sfm_min_str; // 0.4; // update if correction strength exceeds
final double neib_too_strong = clt_parameters.imp.sfm_neib_too_str; // 0.4; // do not count neighbors stronger than that
final int sfm_shrink = clt_parameters.imp.sfm_shrink; // 5;
final double fade_sigma = clt_parameters.imp. sfm_fade_sigma; // 3.0; // fade SfM gains at the edges
final boolean use_neibs = clt_parameters.imp.sfm_use_neibs; // true;
final double min_neib_strength= clt_parameters.imp.sfm_neib_str; // 0.5; // update if no-individual and neibs correction strength exceeds
final double prev_sfm_frac = clt_parameters.imp.sfm_prev_frac; // 0.6; // update if new sfm gain > this fraction of the old one
final double range_disparity_offset = clt_parameters.imp.range_disparity_offset;
final double centroid_radius = clt_parameters.imp.centroid_radius; // final double centroid_radius, // 0 - use all tile, >0 - cosine window around local max
final int n_recenter = clt_parameters.imp.n_recenter; // when cosine window, re-center window this many times
......@@ -552,6 +564,7 @@ public class StructureFromMotion {
double [] interscene_ref_disparity = null; // keep null to use old single-scene disparity for interscene matching
if (use_combo_dsi) {
interscene_ref_disparity = ds[0].clone(); // use_lma_dsi ?
/* use conditioned!
if (use_lma_dsi) {
for (int i = 0; i < interscene_ref_disparity.length; i++) {
if (Double.isNaN(dls[1][i])) {
......@@ -559,6 +572,7 @@ public class StructureFromMotion {
}
}
}
*/
}
if (interscene_ref_disparity == null) {
......@@ -614,10 +628,19 @@ public class StructureFromMotion {
range_disparity_offset, // final double range_disparity_offset, // disparity at actual infinity // clt_parameters.imp.range_disparity_offset ; final double mb_max_gain,
corr_fz_inter, // final double corr_fz_inter,
use_neibs, // final boolean use_neibs,
centroid_radius, // final double centroid_radius, // 0 - use all tile, >0 - cosine window around local max
neib_too_strong, // final double neib_too_strong,
centroid_radius, // final double centroid_radius, // 0 - use all tile, >0 - cosine window around local max
n_recenter, // final int n_recenter, // when cosine window, re-center window this many times
batch_mode, // final boolean batch_mode,
debugLevel); // final int debugLevel)
if ((sfm_shrink > 0) || (fade_sigma > 0.0)) {
shrinkFadeSfmGain(
sfm_shrink, // final int sfm_shrink,
fade_sigma, // final double fade_sigma,
sfmCorr, // final SfmCorr [] sfmCorr,
tilesX); // final int tilesX)
}
if (show_disp_corr) {
String [] dbg_titles = {"corr", "corr_str","neib_corr", "neib_str","old_sfm","new_sfm"};
......@@ -656,16 +679,19 @@ public class StructureFromMotion {
for (int nTile = ai.getAndIncrement(); nTile < sfmCorr.length; nTile = ai.getAndIncrement())
if (sfmCorr[nTile] != null){
if (sfmCorr[nTile].sfm_gain >= prev_sfm_frac*ref_sfm_gain[nTile]){
// Update some strength too?
if ((sfmCorr[nTile].corr_ind != null) && (sfmCorr[nTile].corr_ind[1] > min_strength)) {
ref_disparity[nTile] += sfmCorr[nTile].corr_ind[0];
ref_sfm_gain[nTile] = sfmCorr[nTile].sfm_gain;
} else if ((sfmCorr[nTile].corr_neib != null) && (sfmCorr[nTile].corr_neib[1] > min_neib_strength)) {
ref_disparity[nTile] += sfmCorr[nTile].corr_neib[0];
ref_sfm_gain[nTile] = sfmCorr[nTile].sfm_gain;
if (prev_sfm_frac*sfmCorr[nTile].sfm_gain >= ref_sfm_gain[nTile]){ // copy 100%
// Update some strength too?
if ((sfmCorr[nTile].corr_ind != null) && (sfmCorr[nTile].corr_ind[1] > min_strength)) {
ref_disparity[nTile] += sfmCorr[nTile].corr_ind[0];
ref_sfm_gain[nTile] = sfmCorr[nTile].sfm_gain;
} else if ((sfmCorr[nTile].corr_neib != null) && (sfmCorr[nTile].corr_neib[1] > min_neib_strength)) {
ref_disparity[nTile] += sfmCorr[nTile].corr_neib[0];
ref_sfm_gain[nTile] = sfmCorr[nTile].sfm_gain;
}
}
}
}
}
}
};
}
......@@ -703,6 +729,341 @@ public class StructureFromMotion {
return combo_dsn_final;
}
public static double [][] sfmPairsSet(
final CLTParameters clt_parameters,
final QuadCLT ref_scene,
final QuadCLT [][][] scene_pairs_sets,
final double mb_max_gain,
final boolean batch_mode,
final int debugLevel) {
boolean show_disp_corr_ind = false; //true;
boolean show_disp_corr = false; //true;
boolean show_disp_seq = true;
final int dbg_tile = -( 52+58*80);
final int num_readjust = clt_parameters.imp.sfm_readjust; // 5;
final double min_strength = clt_parameters.imp.sfm_min_str; // 0.4; // update if correction strength exceeds
final double neib_too_strong = clt_parameters.imp.sfm_neib_too_str; // 0.4; // do not count neighbors stronger than that
final int sfm_shrink = clt_parameters.imp.sfm_shrink; // 5;
final double fade_sigma = clt_parameters.imp. sfm_fade_sigma; // 3.0; // fade SfM gains at the edges
final boolean use_neibs = clt_parameters.imp.sfm_use_neibs; // true;
final double min_neib_strength= clt_parameters.imp.sfm_neib_str; // 0.5; // update if no-individual and neibs correction strength exceeds
final double prev_sfm_frac = clt_parameters.imp.sfm_prev_frac; // 0.6; // update if new sfm gain > this fraction of the old one
final double range_disparity_offset = clt_parameters.imp.range_disparity_offset;
final double centroid_radius = clt_parameters.imp.centroid_radius; // final double centroid_radius, // 0 - use all tile, >0 - cosine window around local max
final int n_recenter = clt_parameters.imp.n_recenter; // when cosine window, re-center window this many times
// 16 puts scale same as with older code
final double corr_fz_inter = 16* clt_parameters.getGpuFatZeroInter(ref_scene.isMonochrome());
final int tilesX = ref_scene.getTileProcessor().getTilesX();
final int tilesY = ref_scene.getTileProcessor().getTilesY();
ErsCorrection ers_reference = ref_scene.getErsCorrection();
boolean use_combo_dsi = true;
boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
double [][] ref_xyzatr = new double [][] {ZERO3,ZERO3};
double [][] ref_xyzatr_dt= {
ers_reference.getErsXYZ_dt(),
ers_reference.getErsATR_dt()
};
for (int i = 0; i < ref_xyzatr_dt.length; i++) {
if (ref_xyzatr_dt[i] == null) {
System.out.println("sfmPair(): ref_xyzatr_dt["+i+"] == null");
ref_xyzatr_dt[i] = ZERO3.clone();
}
}
// double [] disparity_raw = new double [tilesX * tilesY];
// Arrays.fill(disparity_raw,clt_parameters.disparity);
double [][] combo_dsn_final = ref_scene.restoreComboDSI(true); // also sets quadCLTs[ref_index].dsi and blue sky
if (combo_dsn_final[OpticalFlow.COMBO_DSN_INDX_SFM_GAIN] == null) {
combo_dsn_final[OpticalFlow.COMBO_DSN_INDX_SFM_GAIN] =
new double [combo_dsn_final[OpticalFlow.COMBO_DSN_INDX_DISP].length];
if (debugLevel > -3) {
System.out.println("sfmPair(): Initializing missing COMBO_DSN_INDX_SFM_GAIN data.");
}
}
final double [] ref_sfm_gain = combo_dsn_final[OpticalFlow.COMBO_DSN_INDX_SFM_GAIN].clone();
double [][] dls = { // Update to use FG? Or FG/no BG?
combo_dsn_final[OpticalFlow.COMBO_DSN_INDX_DISP],
combo_dsn_final[OpticalFlow.COMBO_DSN_INDX_LMA],
combo_dsn_final[OpticalFlow.COMBO_DSN_INDX_STRENGTH]
};
double [][] ds = OpticalFlow.conditionInitialDS(
true, // boolean use_conf, // use configuration parameters, false - use following
clt_parameters, // CLTParameters clt_parameters,
dls, // double [][] dls
ref_scene, // QuadCLT scene,
debugLevel);
double [] interscene_ref_disparity = null; // keep null to use old single-scene disparity for interscene matching
if (use_combo_dsi) {
interscene_ref_disparity = ds[0].clone(); // use_lma_dsi ?
/* use conditioned!
if (use_lma_dsi) {
for (int i = 0; i < interscene_ref_disparity.length; i++) {
if (Double.isNaN(dls[1][i])) {
interscene_ref_disparity[i] = Double.NaN;
}
}
}
*/
}
if (interscene_ref_disparity == null) {
interscene_ref_disparity =ref_scene.getDLS()[use_lma_dsi?1:0];
}
final double [] ref_disparity = interscene_ref_disparity;
double [][] disp_adj = show_disp_seq? (new double [num_readjust+1][]):null;
if (disp_adj != null) {
disp_adj[0] = ref_disparity.clone();
}
final int num_sets = scene_pairs_sets.length;
final int [] num_set_pairs = new int [num_sets];
final double[][][][][] scenes_xyzatr_sets = new double[num_sets][][][][];
final double[][][][][] scenes_xyzatr_dt_sets = new double[num_sets][][][][];
for (int nset=0; nset < num_sets; nset++) {
int num_pairs = scene_pairs_sets[nset].length;
num_set_pairs[nset] = num_pairs;
scenes_xyzatr_sets[nset]= new double[num_pairs][2][][]; // 2 scenes
scenes_xyzatr_dt_sets[nset]=new double[num_pairs][2][][];// 2 scenes;
for (int npair = 0; npair < num_pairs; npair++) {
QuadCLT [] scenes = scene_pairs_sets[nset][npair];
for (int nscene = 0; nscene < scenes.length; nscene++) {
String ts = scenes[nscene].getImageName();
if (ts.equals(ref_scene.getImageName())) {
scenes_xyzatr_sets[nset][npair][nscene] = ref_xyzatr;
scenes_xyzatr_dt_sets[nset][npair][nscene]= ref_xyzatr_dt;
} else {
if ((ers_reference.getSceneXYZ(ts)== null) || (ers_reference.getSceneATR(ts)== null)) {
System.out.println("sfmPairsSet(): no pose for timestamp "+ts);
return null;
}
scenes_xyzatr_sets[nset][npair][nscene] = new double[][] {ers_reference.getSceneXYZ(ts),ers_reference.getSceneATR(ts)};
scenes_xyzatr_dt_sets[nset][npair][nscene]= new double[][] {ers_reference.getSceneErsXYZ_dt(ts),ers_reference.getSceneErsATR_dt(ts)};
for (int i = 0; i < scenes_xyzatr_dt_sets[nset][npair][nscene].length; i++) {
if (scenes_xyzatr_dt_sets[nset][npair][nscene][i] == null) {
System.out.println("sfmPairsSet(): scenes_xyzatr_dt_sets["+nset+"]["+i+"] == null");
scenes_xyzatr_dt_sets[nset][npair][nscene][i] = ZERO3.clone();
}
}
}
}
}
}
for (int ntry = 0; ntry < num_readjust; ntry++) {
final SfmCorr [] sfmCorrCombo = new SfmCorr [tilesX*tilesY];
double [] sum_weights_ind= new double [tilesX*tilesY];
double [] sum_weights_neib=new double [tilesX*tilesY];
for (int nset=0; nset < num_sets; nset++) {
SfmCorr [] sfmCorr = getSfmCorr(
clt_parameters, // final CLTParameters clt_parameters,
ref_scene, // final QuadCLT ref_scene,
ref_disparity, // final double [] ref_disparity,
ref_xyzatr, // final double[][] ref_xyzatr, // new double[num_pairs][2][][]; // 2 scenes
ref_xyzatr_dt, // final double[][] ref_xyzatr_dt, // new double[num_pairs][2][][];// 2 scenes
scene_pairs_sets[nset], // final QuadCLT[][] scene_pairs,
scenes_xyzatr_sets[nset], // final double[][][][] scenes_xyzatr, // new double[num_pairs][2][][]; // 2 scenes
scenes_xyzatr_dt_sets[nset],// final double[][][][] scenes_xyzatr_dt, // new double[num_pairs][2][][];// 2 scenes
mb_max_gain, // final double mb_max_gain,
range_disparity_offset, // final double range_disparity_offset, // disparity at actual infinity // clt_parameters.imp.range_disparity_offset ; final double mb_max_gain,
corr_fz_inter, // final double corr_fz_inter,
use_neibs, // final boolean use_neibs,
neib_too_strong, // final double neib_too_strong,
centroid_radius, // final double centroid_radius, // 0 - use all tile, >0 - cosine window around local max
n_recenter, // final int n_recenter, // when cosine window, re-center window this many times
batch_mode, // final boolean batch_mode,
debugLevel); // final int debugLevel)
if ((sfm_shrink > 0) || (fade_sigma > 0.0)) {
shrinkFadeSfmGain(
sfm_shrink, // final int sfm_shrink,
fade_sigma, // final double fade_sigma,
sfmCorr, // final SfmCorr [] sfmCorr,
tilesX); // final int tilesX)
}
if (show_disp_corr_ind) {
String [] dbg_titles = {"corr", "corr_str","neib_corr", "neib_str","old_sfm","new_sfm"};
double [][] dbg_2d_corr = new double [dbg_titles.length][sfmCorr.length];
for (int i = 0; i < dbg_2d_corr.length; i++) {
Arrays.fill(dbg_2d_corr[i], Double.NaN);
}
dbg_2d_corr[4] = ref_sfm_gain.clone();
for (int nTile = 0; nTile < sfmCorr.length; nTile++) if (sfmCorr[nTile] != null) {
dbg_2d_corr[5][nTile] = sfmCorr[nTile].sfm_gain;
if (sfmCorr[nTile].corr_ind != null) {
dbg_2d_corr[0][nTile] = sfmCorr[nTile].corr_ind[0];
dbg_2d_corr[1][nTile] = sfmCorr[nTile].corr_ind[1];
}
if (sfmCorr[nTile].corr_neib != null) {
dbg_2d_corr[2][nTile] = sfmCorr[nTile].corr_neib[0];
dbg_2d_corr[3][nTile] = sfmCorr[nTile].corr_neib[1];
}
}
ShowDoubleFloatArrays.showArrays(
dbg_2d_corr,
tilesX,
tilesY,
true,
"sfm_corr-"+nset+"-"+scene_pairs_sets[nset][num_set_pairs[nset]-1][1].getImageName()+"-"+
scene_pairs_sets[nset][0][0].getImageName()+"-"+num_set_pairs[nset]+"-"+String.format("%02d", ntry),
dbg_titles);
}
// combine corrections
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < sfmCorr.length; nTile = ai.getAndIncrement()) {
if (nTile == dbg_tile) {
System.out.println("sfmPairsSet().1: dbg_tile="+dbg_tile);
}
if (sfmCorr[nTile] != null){
if (sfmCorrCombo[nTile]==null) {
sfmCorrCombo[nTile] = new SfmCorr();
}
if (sfmCorr[nTile].corr_ind != null) {
if (sfmCorrCombo[nTile].corr_ind == null) {
sfmCorrCombo[nTile].corr_ind= new double[2];
}
sfmCorrCombo[nTile].corr_ind[0]+= sfmCorr[nTile].corr_ind[0] * sfmCorr[nTile].sfm_gain;
sfmCorrCombo[nTile].corr_ind[1]+= sfmCorr[nTile].corr_ind[1] * sfmCorr[nTile].sfm_gain;
sum_weights_ind[nTile]+=sfmCorr[nTile].sfm_gain;
if (sfmCorr[nTile].sfm_gain > sfmCorrCombo[nTile].sfm_gain) {
sfmCorrCombo[nTile].sfm_gain = sfmCorr[nTile].sfm_gain;
}
}
if (sfmCorr[nTile].corr_neib != null) {
if (sfmCorrCombo[nTile].corr_neib == null) {
sfmCorrCombo[nTile].corr_neib= new double[2];
}
sfmCorrCombo[nTile].corr_neib[0]+= sfmCorr[nTile].corr_neib[0] * sfmCorr[nTile].sfm_gain;
sfmCorrCombo[nTile].corr_neib[1]+= sfmCorr[nTile].corr_neib[1] * sfmCorr[nTile].sfm_gain;
sum_weights_neib[nTile]+=sfmCorr[nTile].sfm_gain;
if (sfmCorr[nTile].sfm_gain > sfmCorrCombo[nTile].sfm_gain) {
sfmCorrCombo[nTile].sfm_gain = sfmCorr[nTile].sfm_gain;
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
} // for (int nset=0; nset < num_sets; nset++)
// combine corrections
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
final double wscale = -0.5/Math.log(prev_sfm_frac);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < sfmCorrCombo.length; nTile = ai.getAndIncrement()) {
if (nTile == dbg_tile) {
System.out.println("sfmPairsSet().2: dbg_tile="+dbg_tile);
}
if (sfmCorrCombo[nTile] != null){
if (sum_weights_ind[nTile] > 0) { // do it now just for debug images
sfmCorrCombo[nTile].corr_ind[0] /= sum_weights_ind[nTile];
sfmCorrCombo[nTile].corr_ind[1] /= sum_weights_ind[nTile];
}
if (sum_weights_neib[nTile] > 0) {
sfmCorrCombo[nTile].corr_neib[0] /= sum_weights_neib[nTile];
sfmCorrCombo[nTile].corr_neib[1] /= sum_weights_neib[nTile];
}
if (sfmCorrCombo[nTile].sfm_gain >= prev_sfm_frac*ref_sfm_gain[nTile]){
double w = 1.0;
if (ref_sfm_gain[nTile] > 0) {
w = 0.5 + wscale*Math.log(sfmCorrCombo[nTile].sfm_gain/ref_sfm_gain[nTile]);
}
if (w < 0.0) w = 0;
else if (w > 1.0) w = 1.0;
// Update some strength too?
if ((sfmCorrCombo[nTile].corr_ind != null) && (sfmCorrCombo[nTile].corr_ind[1] > min_strength)) {
ref_disparity[nTile] += w *sfmCorrCombo[nTile].corr_ind[0];
// TODO: add same (as above) for strengths?
ref_sfm_gain[nTile] = (1-w) *ref_sfm_gain[nTile] + w * sfmCorrCombo[nTile].sfm_gain;
} else if ((sfmCorrCombo[nTile].corr_neib != null) && (sfmCorrCombo[nTile].corr_neib[1] > min_neib_strength)) {
ref_disparity[nTile] += w *sfmCorrCombo[nTile].corr_neib[0];
// TODO: add same (as above) for strengths?
ref_sfm_gain[nTile] = (1-w) *ref_sfm_gain[nTile] + w * sfmCorrCombo[nTile].sfm_gain;
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
if (show_disp_corr) {
String [] dbg_titles = {"corr", "corr_str","neib_corr", "neib_str","old_sfm","new_sfm"};
double [][] dbg_2d_corr = new double [dbg_titles.length][sfmCorrCombo.length];
for (int i = 0; i < dbg_2d_corr.length; i++) {
Arrays.fill(dbg_2d_corr[i], Double.NaN);
}
dbg_2d_corr[4] = ref_sfm_gain.clone();
for (int nTile = 0; nTile < sfmCorrCombo.length; nTile++) if (sfmCorrCombo[nTile] != null) {
dbg_2d_corr[5][nTile] = sfmCorrCombo[nTile].sfm_gain;
if (sfmCorrCombo[nTile].corr_ind != null) {
dbg_2d_corr[0][nTile] = sfmCorrCombo[nTile].corr_ind[0];
dbg_2d_corr[1][nTile] = sfmCorrCombo[nTile].corr_ind[1];
}
if (sfmCorrCombo[nTile].corr_neib != null) {
dbg_2d_corr[2][nTile] = sfmCorrCombo[nTile].corr_neib[0];
dbg_2d_corr[3][nTile] = sfmCorrCombo[nTile].corr_neib[1];
}
}
ShowDoubleFloatArrays.showArrays(
dbg_2d_corr,
tilesX,
tilesY,
true,
"sfm_corr-combo-"+scene_pairs_sets[0][num_set_pairs[0]-1][1].getImageName()+"-"+
scene_pairs_sets[0][0][0].getImageName()+"-"+String.format("%02d", ntry),
dbg_titles);
}
// replace weak tiles with average?
if (disp_adj != null) {
disp_adj[ntry + 1] = ref_disparity.clone();
}
} // ntry
if (disp_adj != null) {
ShowDoubleFloatArrays.showArrays(
disp_adj,
tilesX,
tilesY,
true,
"SfM-disparity-multi-"+scene_pairs_sets[0][num_set_pairs[0]-1][1].getImageName()+"-"+
scene_pairs_sets[0][num_set_pairs[0]-1][0].getImageName()+"-"+num_set_pairs.length);
}
// Re-calc BG?
combo_dsn_final[OpticalFlow.COMBO_DSN_INDX_DISP] = ref_disparity.clone();
combo_dsn_final[OpticalFlow.COMBO_DSN_INDX_LMA] = ref_disparity.clone();
combo_dsn_final[OpticalFlow.COMBO_DSN_INDX_DISP_FG] = ref_disparity.clone();
combo_dsn_final[OpticalFlow.COMBO_DSN_INDX_DISP_BG_ALL] = ref_disparity.clone();
combo_dsn_final[OpticalFlow.COMBO_DSN_INDX_SFM_GAIN] = ref_sfm_gain.clone();
String rslt_suffix = "-INTER-INTRA";
rslt_suffix += (clt_parameters.correlate_lma?"-LMA":"-NOLMA");
ref_scene.saveDoubleArrayInModelDirectory( // error
rslt_suffix, // String suffix,
OpticalFlow.COMBO_DSN_TITLES, // combo_dsn_titles_full, // null, // String [] labels, // or null
combo_dsn_final, // dbg_data, // double [][] data,
tilesX, // int width,
tilesY); // int height)
return combo_dsn_final;
}
/**
* Calculate SfM disparity correction from a set of scene pairs with approximately
* the same position offset in each pair by consolidating 2D correlation data in
......@@ -725,6 +1086,7 @@ public class StructureFromMotion {
* @param corr_fz_inter Fat zero correction. Recommended value:
* (16* clt_parameters.getGpuFatZeroInter(ref_scene.isMonochrome())
* @param use_neibs if true, will generate data for averaging between neighbors
* @param neib_too_strong do not accumulate neighbor if it is too strong
* @param centroid_radius
* @param n_recenter
* @param batch_mode batch mode (suppress all debug images)
......@@ -746,6 +1108,7 @@ public class StructureFromMotion {
final double range_disparity_offset, // disparity at actual infinity // clt_parameters.imp.range_disparity_offset ; final double mb_max_gain,
final double corr_fz_inter,
final boolean use_neibs,
final double neib_too_strong,
final double centroid_radius, // 0 - use all tile, >0 - cosine window around local max
final int n_recenter, // when cosine window, re-center window this many times
final boolean batch_mode,
......@@ -803,9 +1166,11 @@ public class StructureFromMotion {
double [][] neibs_PD = null;
if (use_neibs) {
TDCorrTile [] neibs_TD = TDCorrTile.calcNeibs(
accum_TD, // pairs_TD, // TDCorrTile [] tiles,
accum_TD, // pairs_TD, // TDCorrTile [] tiles,
tilesX, // final int tilesX,
neib_weights_od, //double [] neib_weights_od, // {orhto, diag}
neib_weights_od, // double [] neib_weights_od, // {orhto, diag}
accum_PD, // double [][] corr_pd,
neib_too_strong, // double neib_too_strong,
true); // final boolean process_all
neibs_PD = TDCorrTile.convertTDtoPD(
ref_scene.getGPU(), // final GpuQuad gpuQuad,
......@@ -882,6 +1247,69 @@ public class StructureFromMotion {
return sfmCorr;
}
public static void shrinkFadeSfmGain(
final int sfm_shrink,
final double fade_sigma,
final SfmCorr [] sfmCorr,
final int tilesX) {
final int tilesY = sfmCorr.length / tilesX;
final TileNeibs tn = new TileNeibs(tilesX,tilesY);
final boolean [] sfm_defined = new boolean [sfmCorr.length];
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < sfmCorr.length; nTile = ai.getAndIncrement()) if (sfmCorr[nTile] != null){
sfm_defined[nTile] = sfmCorr[nTile].sfm_gain > 0;
}
}
};
}
ImageDtt.startAndJoin(threads);
if (sfm_shrink > 0) {
tn.shrinkSelection(
sfm_shrink, // final int shrink, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
sfm_defined, // final boolean [] tiles,
null); // final boolean [] prohibit)
}
if (fade_sigma > 0) {
final double [] gain_scale = new double [sfm_defined.length];
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < sfmCorr.length; nTile = ai.getAndIncrement()) if (sfm_defined[nTile]){
gain_scale[nTile] = 2.0;
}
}
};
}
ImageDtt.startAndJoin(threads);
DoubleGaussianBlur gb = new DoubleGaussianBlur();
gb.blurDouble(gain_scale, tilesX, tilesY, fade_sigma, fade_sigma, 0.01);
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < sfmCorr.length; nTile = ai.getAndIncrement()) if (sfmCorr[nTile] != null){
if (sfm_defined[nTile]) {
double g = gain_scale[nTile]-1;
sfmCorr[nTile].sfm_gain *= g * g;
} else {
sfmCorr[nTile].sfm_gain = 0.0; // null; // or use sfmCorr[nTile] = null?
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
}
/**
* Calculate disparity correction from the pixel-domain 2D correlation data
......
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