Commit ca8d6ea6 authored by Andrey Filippov's avatar Andrey Filippov

modified ML output

parent 47597794
......@@ -248,11 +248,23 @@ public class BiQuadParameters {
public boolean ml_copyJP4 = true; // Copy source jp4 files when running "Ground truth" command
public int ml_hwidth = 4; // Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)
public double ml_disparity_sweep = 1.0; // Disparity sweep around ground truth, each side
public int ml_sweep_steps = 21; // Number of disparity sweep steps
public boolean ml_randomize = true; // randomize ofset within 1 step (reduces ml_sweep_steps by 1)
public double ml_disparity_sweep = 2.0; // Disparity sweep around ground truth, each side
public int ml_sweep_steps = 1; // Number of disparity sweep steps
public boolean ml_randomize = true; // randomize offset within 1 step (reduces ml_sweep_steps by 1)
// enhancing main camera dsi for generation of the ml files
public double ml_rig_tolerance = 2.0; // replace main camera disparity if it differs from rig by more than this
public double ml_rnd_offset = 0.5; // add random offset to rig disparity if there is no suitable data from main camera neighbors
public double ml_main_tolerance = 1.0; // look for neighbors within this disparity difference from the rig disparity
public int ml_grow_steps = 2; // measure correlation for the tiles in the undefined areas around known (to match 5x5 clusters
public int ml_grow_mode = 2; // -1 - prefer background, 0 - use average. 1 - prefer foreground, 2 - auto (closest to rig )
public double ml_new_strength = 0.5; // assign this fraction of known strengths average to the tiles where strength is unknown (expanded tiles with extrapolated target)
public boolean ml_main = true; // generate ML from main camera DSI
public boolean ml_main_rnd = true; // generate ML from main camera DSI with random offset
public boolean ml_rig_rnd = true; // generate ML from rig DSI (GT) with random offset
public boolean ml_keep_aux = false; // true; // include auxiliary camera data in the ML output
public boolean ml_keep_inter = false; // true; // include inter-camera correlation data in the ML output
public boolean ml_keep_hor_vert = true; // include combined horizontal and vertical pairs data in the ML output
......@@ -656,13 +668,36 @@ public class BiQuadParameters {
gd.addNumericField("Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)", this.ml_hwidth, 0,3,"",
"Amount of data to export to the ML system");
gd.addNumericField("Disparity sweep around ground truth, each side", this.ml_disparity_sweep, 3,6,"",
"Sweep symmetrically target disparity around the ground truth disparity, each side");
"Sweep symmetrically target disparity around the ground truth disparity, each side. If 0 sweep_steps == 0 - use as random offset amplitude");
gd.addNumericField("Number of target disparity sweep steps", this.ml_sweep_steps, 0,3,"",
"Generate this many files for each file set. Each tile results depend on the target disparity and this tile data, do not depend on other tiles target disparity");
gd.addCheckbox ("Randomize offset", this.ml_randomize,
"Each tile will have individual offset, but it the range between the filename and next higher. Reduces sweep steps by 1");
gd.addMessage("Enhancing main camera dsi for generation of the ml files");
gd.addNumericField("Max disparity difference between rig and main camera", this.ml_rig_tolerance, 3,6,"",
"Replace main camera disparity if it differs from rig by more than this");
gd.addNumericField("Random disparity offset amplitude", this.ml_rnd_offset, 3,6,"",
"Add random offset to rig disparity if there is no suitable data from main camera neighbors");
gd.addNumericField("Maximal neighbor difference from rig disparity to estimate missing main camera disparity",this.ml_main_tolerance, 3,6,"",
"Look for neighbors within this disparity difference from the rig disparity");
gd.addNumericField("Extrapolate around defined tiles (2 for 5x5 clusters)", this.ml_grow_steps, 0,3,"",
"Measure correlation for the tiles in the undefined areas around known (to match 5x5 clusters");
gd.addNumericField("Extrapolation mode: -1 - BG, +1-FG, 0 - average, 2 -auto", this.ml_grow_mode, 0,3,"",
"-1 - prefer background, 0 - use average. 1 - prefer foreground");
gd.addNumericField("Extrapolated tile strength", this.ml_new_strength, 3,6,"",
"Assign this fraction of average neighbors strength strength to the tiles where strength is unknown (expanded tiles with extrapolated target)");
gd.addCheckbox ("Generate ML 2d correlations from main camera DSI", this.ml_main,
"Target disparity/convergence extracted from the main camera DSI, filtered and expanded");
gd.addCheckbox ("Generate ML from main camera DSI with random offset", this.ml_main_rnd,
"Same as above, random offset is added to the target disparity/convergence");
gd.addCheckbox ("Generate ML from rig DSI (GT) with random offset", this.ml_rig_rnd,
"Main camera data is not used, offset is just random from the rig (ground truth)");
gd.addCheckbox ("Include auxiliary camera data in the ML output", this.ml_keep_aux,
"ML output will have the second set of the layers for the auxiliary camera. Disparity values should be scaled for the camera baseline");
gd.addCheckbox ("Keep inter-camera correlation data", this.ml_keep_inter,
......@@ -881,7 +916,19 @@ public class BiQuadParameters {
this.ml_hwidth= (int) gd.getNextNumber();
this.ml_disparity_sweep= gd.getNextNumber();
this.ml_sweep_steps= (int) gd.getNextNumber();
this.ml_randomize= gd.getNextBoolean();
this.ml_randomize= gd.getNextBoolean();
this.ml_rig_tolerance= gd.getNextNumber();
this.ml_rnd_offset= gd.getNextNumber();
this.ml_main_tolerance= gd.getNextNumber();
this.ml_grow_steps= (int) gd.getNextNumber();
this.ml_grow_mode= (int) gd.getNextNumber();
this.ml_new_strength= gd.getNextNumber();
this.ml_main= gd.getNextBoolean();
this.ml_main_rnd= gd.getNextBoolean();
this.ml_rig_rnd= gd.getNextBoolean();
this.ml_keep_aux= gd.getNextBoolean();
this.ml_keep_inter= gd.getNextBoolean();
this.ml_keep_tbrl= gd.getNextBoolean();
......@@ -1093,6 +1140,18 @@ public class BiQuadParameters {
properties.setProperty(prefix+"ml_disparity_sweep", this.ml_disparity_sweep+"");
properties.setProperty(prefix+"ml_sweep_steps", this.ml_sweep_steps+"");
properties.setProperty(prefix+"ml_randomize", this.ml_randomize+"");
properties.setProperty(prefix+"ml_rig_tolerance", this.ml_rig_tolerance+"");
properties.setProperty(prefix+"ml_rnd_offset", this.ml_rnd_offset+"");
properties.setProperty(prefix+"ml_main_tolerance", this.ml_main_tolerance+"");
properties.setProperty(prefix+"ml_grow_steps", this.ml_grow_steps+"");
properties.setProperty(prefix+"ml_grow_mode", this.ml_grow_mode+"");
properties.setProperty(prefix+"ml_new_strength", this.ml_new_strength+"");
properties.setProperty(prefix+"ml_main", this.ml_main+"");
properties.setProperty(prefix+"ml_main_rnd", this.ml_main_rnd+"");
properties.setProperty(prefix+"ml_rig_rnd", this.ml_rig_rnd+"");
properties.setProperty(prefix+"ml_keep_aux", this.ml_keep_aux+"");
properties.setProperty(prefix+"ml_keep_inter", this.ml_keep_inter+"");
properties.setProperty(prefix+"ml_keep_tbrl", this.ml_keep_tbrl+"");
......@@ -1302,6 +1361,19 @@ public class BiQuadParameters {
if (properties.getProperty(prefix+"ml_sweep_steps")!=null) this.ml_sweep_steps=Integer.parseInt(properties.getProperty(prefix+"ml_sweep_steps"));
if (properties.getProperty(prefix+"ml_randomize")!=null) this.ml_randomize=Boolean.parseBoolean(properties.getProperty(prefix+"ml_randomize"));
if (properties.getProperty(prefix+"ml_rig_tolerance")!=null) this.ml_rig_tolerance=Double.parseDouble(properties.getProperty(prefix+"ml_rig_tolerance"));
if (properties.getProperty(prefix+"ml_rnd_offset")!=null) this.ml_rnd_offset=Double.parseDouble(properties.getProperty(prefix+"ml_rnd_offset"));
if (properties.getProperty(prefix+"ml_main_tolerance")!=null) this.ml_main_tolerance=Double.parseDouble(properties.getProperty(prefix+"ml_main_tolerance"));
if (properties.getProperty(prefix+"ml_grow_steps")!=null) this.ml_grow_steps=Integer.parseInt(properties.getProperty(prefix+"ml_grow_steps"));
if (properties.getProperty(prefix+"ml_grow_mode")!=null) this.ml_grow_mode=Integer.parseInt(properties.getProperty(prefix+"ml_grow_mode"));
if (properties.getProperty(prefix+"ml_new_strength")!=null) this.ml_new_strength=Double.parseDouble(properties.getProperty(prefix+"ml_new_strength"));
if (properties.getProperty(prefix+"ml_main")!=null) this.ml_main=Boolean.parseBoolean(properties.getProperty(prefix+"ml_main"));
if (properties.getProperty(prefix+"ml_main_rnd")!=null) this.ml_main_rnd=Boolean.parseBoolean(properties.getProperty(prefix+"ml_main_rnd"));
if (properties.getProperty(prefix+"ml_rig_rnd")!=null) this.ml_rig_rnd=Boolean.parseBoolean(properties.getProperty(prefix+"ml_rig_rnd"));
if (properties.getProperty(prefix+"ml_keep_aux")!=null) this.ml_keep_aux=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_aux"));
if (properties.getProperty(prefix+"ml_keep_inter")!=null) this.ml_keep_inter=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_inter"));
if (properties.getProperty(prefix+"ml_keep_tbrl")!=null) this.ml_keep_tbrl=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_tbrl"));
......@@ -1510,8 +1582,21 @@ public class BiQuadParameters {
bqp.ml_hwidth= this.ml_hwidth;
bqp.ml_disparity_sweep= this.ml_disparity_sweep;
bqp.ml_sweep_steps= this.ml_sweep_steps;
bqp.ml_main = this.ml_main;
bqp.ml_main_rnd = this.ml_main_rnd;
bqp.ml_rig_rnd = this.ml_rig_rnd;
bqp.ml_keep_aux= this.ml_keep_aux;
bqp.ml_randomize = this.ml_randomize;
bqp.ml_rig_tolerance= this.ml_rig_tolerance;
bqp.ml_rnd_offset= this.ml_rnd_offset;
bqp.ml_main_tolerance= this.ml_main_tolerance;
bqp.ml_grow_steps= this.ml_grow_steps;
bqp.ml_grow_mode= this.ml_grow_mode;
bqp.ml_new_strength= this.ml_new_strength;
bqp.ml_keep_inter= this.ml_keep_inter;
bqp.ml_keep_tbrl= this.ml_keep_tbrl;
bqp.ml_keep_hor_vert= this.ml_keep_hor_vert;
......
......@@ -5686,6 +5686,7 @@ private Panel panel1,
return false;
}
int indx = 0;
String [] used_models =getUsedModels();
for (Path p:files) {
int count = p.getNameCount();
......@@ -5706,7 +5707,7 @@ private Panel panel1,
System.out.println("DSI combo file (GT data) for the model:"+model+", version:"+version+": "+dsi_combo_path+" does not exist");
continue;
}
// overwrite extrinsics in current properties form the model file
// overwrite extrinsics in current properties from the model file
MLStats.loadProperties(
full_conf_path.toString(), // String path,
PROPERTIES); // Properties properties)
......@@ -5786,8 +5787,335 @@ private Panel panel1,
return true;
}
String [] getUsedModels() {
String [] models = {"1527257933_150165",
"1527257933_150165",
"1527257939_550165",
"1527257939_550165",
"1527257947_950165",
"1527257947_950165",
"1527257932_350165",
"1527257932_350165",
"1527257941_950165",
"1527257941_950165",
"1527257932_550165",
"1527257932_550165",
"1527257947_750165",
"1527257947_750165",
"1527257935_350165",
"1527257935_350165",
"1527257927_750165",
"1527257946_550165",
"1527257946_550165",
"1527257949_950165",
"1527257949_950165",
"1527257944_750165",
"1527257944_750165",
"1527257938_750165",
"1527257938_750165",
"1527257940_550165",
"1527257940_550165",
"1527257937_150165",
"1527257937_150165",
"1527257924_950165",
"1527257924_950165",
"1527257924_950165",
"1527257941_350165",
"1527257941_350165",
"1527257944_350165",
"1527257944_350165",
"1527257945_950165",
"1527257945_950165",
"1527257941_550165",
"1527257941_550165",
"1527257943_550165",
"1527257943_550165",
"1527257939_150165",
"1527257939_150165",
"1527257933_950165",
"1527257933_950165",
"1527257938_350165",
"1527257938_350165",
"1527257936_750165",
"1527257936_750165",
"1527257928_750165",
"1527257940_950165",
"1527257940_950165",
"1527257943_950165",
"1527257943_950165",
"1527257937_750165",
"1527257937_750165",
"1527257943_750165",
"1527257943_750165",
"1527257941_750165",
"1527257941_750165",
"1527257936_550165",
"1527257936_550165",
"1527257942_750165",
"1527257942_750165",
"1527257931_550165",
"1527257949_350165",
"1527257949_350165",
"1527257924_550165",
"1527257924_550165",
"1527257924_550165",
"1527257940_350165",
"1527257940_350165",
"1527257948_550165",
"1527257948_550165",
"1527257930_950165",
"1527257947_550165",
"1527257947_550165",
"1527257925_750165",
"1527257925_750165",
"1527257931_750165",
"1527257944_950165",
"1527257944_950165",
"1527257929_550165",
"1527257948_750165",
"1527257948_750165",
"1527257930_150165",
"1527257930_350165",
"1527257931_150165",
"1527257942_550165",
"1527257942_550165",
"1527257937_350165",
"1527257937_350165",
"1527257941_150165",
"1527257941_150165",
"1527257938_150165",
"1527257938_150165",
"1527257928_350165",
"1527257948_350165",
"1527257948_350165",
"1527257932_750165",
"1527257932_750165",
"1527257946_750165",
"1527257946_750165",
"1527257926_950165",
"1527257928_550165",
"1527257925_350165",
"1527257925_350165",
"1527257947_150165",
"1527257947_150165",
"1527257930_750165",
"1527257927_350165",
"1527257929_750165",
"1527257937_550165",
"1527257937_550165",
"1527257933_350165",
"1527257933_350165",
"1527257944_150165",
"1527257944_150165",
"1527257931_950165",
"1527257936_950165",
"1527257936_950165",
"1527257928_950165",
"1527257925_150165",
"1527257925_150165",
"1527257924_750165",
"1527257924_750165",
"1527257924_750165",
"1527257937_950165",
"1527257937_950165",
"1527257946_150165",
"1527257946_150165",
"1527257949_750165",
"1527257949_750165",
"1527257942_150165",
"1527257942_150165",
"1527257926_150165",
"1527257931_350165",
"1527257942_950165",
"1527257942_950165",
"1527257939_350165",
"1527257939_350165",
"1527257934_550165",
"1527257934_550165",
"1527257945_550165",
"1527257945_550165",
"1527257935_150165",
"1527257935_150165",
"1527257945_150165",
"1527257945_150165",
"1527257942_350165",
"1527257942_350165",
"1527257930_550165",
"1527257945_350165",
"1527257945_350165",
"1527257947_350165",
"1527257947_350165",
"1527257938_550165",
"1527257938_550165",
"1527257927_150165",
"1527257927_950165",
"1527257933_750165",
"1527257933_750165",
"1527257934_750165",
"1527257934_750165",
"1527257949_150165",
"1527257949_150165",
"1527257944_550165",
"1527257944_550165",
"1527257933_550165",
"1527257933_550165",
"1527257936_350165",
"1527257936_350165",
"1527257940_750165",
"1527257940_750165",
"1527257935_550165",
"1527257935_550165",
"1527257928_150165",
"1527257943_150165",
"1527257943_150165",
"1527257948_150165",
"1527257948_150165",
"1527257932_950165",
"1527257932_950165",
"1527257949_550165",
"1527257949_550165",
"1527257926_750165",
"1527257948_950165",
"1527257948_950165",
"1527257934_950165",
"1527257934_950165",
"1527257926_350165",
"1527257926_550165",
"1527257929_150165",
"1527257925_550165",
"1527257925_550165",
"1527257934_150165",
"1527257934_150165",
"1527257924_350165",
"1527257924_350165",
"1527257924_350165",
"1527257934_350165",
"1527257934_350165",
"1527257943_350165",
"1527257943_350165",
"1527257946_950165",
"1527257946_950165",
"1527257938_950165",
"1527257938_950165",
"1527257935_950165",
"1527257935_950165",
"1527257917_550165",
"1527257917_550165",
"1527257917_550165",
"1527257917_550165",
"1527257939_950165",
"1527257939_950165",
"1527257924_150165",
"1527257924_150165",
"1527257924_150165",
"1527257939_750165",
"1527257939_750165",
"1527257946_350165",
"1527257946_350165",
"1527257935_750165",
"1527257935_750165",
"1527257925_950165",
"1527257925_950165",
"1527257945_750165",
"1527257945_750165",
"1527257929_350165",
"1527257927_550165",
"1527257940_150165",
"1527257940_150165",
"1527257936_150165",
"1527257936_150165",
"1527257929_950165",
"1527257932_150165",
"1527257932_150165",
"1527182809_496892",
"1527182811_296892",
"1527182807_696892",
"1527182807_896892",
"1527182811_696892",
"1527182801_896892",
"1527182801_296892",
"1527182809_896892",
"1527182810_896892",
"1527182803_496892",
"1527182809_696892",
"1527182807_296892",
"1527182807_096892",
"1527182806_096892",
"1527182808_696892",
"1527182801_696892",
"1527182804_696892",
"1527182803_696892",
"1527182810_496892",
"1527182811_496892",
"1527182802_296892",
"1527182802_496892",
"1527182808_296892",
"1527182810_296892",
"1527182808_496892",
"1527182811_896892",
"1527182804_096892",
"1527182810_096892",
"1527182802_896892",
"1527182802_096892",
"1527182805_496892",
"1527182804_496892",
"1527182804_296892",
"1527182810_696892",
"1527182808_896892",
"1527182803_096892",
"1527182802_696892",
"1527182806_696892",
"1527182801_096892",
"1527182808_096892",
"1527182805_296892",
"1527182809_096892",
"1527182801_496892",
"1527182811_096892",
"1527182809_296892",
"1527182806_496892",
"1527182805_096892",
"1527182807_496892",
"1527182806_296892",
"1527182804_896892",
"1527182803_296892",
"1527182806_896892",
"1527182803_896892",
"1527182805_896892",
"1527182805_696892",
"1527256857_750165",
"1527256877_350165",
"1527256858_150165",
"1527256818_750165",
"1527256818_750165",
"1527256856_350165",
"1527256837_150165",
"1527256818_550165",
"1527256818_550165",
"1527256875_350165",
"1527256878_350165",
"1527256878_950165",
"1527256856_750165",
"1527256877_550165",
"1527256858_950165",
"1527256836_350165",
"1527256816_550165",
"1527256816_550165",
"1527256837_550165",
"1527256855_950165",
"1527256838_550165",
"1527256855_350165",
"1527256836_750165",
"1527256875_550165",
"1527256818_350165",
"1527256818_350165",
"1527256835_750165",
"1527256837_950165",
"1527256818_950165",
"1527256818_950165"};
return models;
}
public boolean dsiHistogram() {
......
......@@ -1826,26 +1826,6 @@ if (debugLevel > -100) return true; // temporarily !
quadCLT_main.tp.clt_3d_passes.add(rig_scan);
quadCLT_main.tp.saveCLTPasses(true); // rig pass
/*
// generate ML data if enabled
if (clt_parameters.rig.ml_generate) {
outputMLData(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
if (clt_parameters.rig.ml_copyJP4) {
copyJP4src(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
debugLevel); // final int debugLevel)
}
}
*/
}
public boolean [] selectAuxOcclusions(
......@@ -2090,6 +2070,30 @@ if (debugLevel > -100) return true; // temporarily !
System.out.println("==== Generating ML data for the DSI that DOES NOT include extracted vertical poles ====");
}
}
// Create filtered/expanded min and rig DSI
double [][] main_dsi = enhanceMainDSI(
main_disparity_strength, // double [][] main_dsi,
rig_disparity_strength, // double [][] rig_dsi,
clt_parameters.rig.ml_rig_tolerance, // double rig_tolerance,
clt_parameters.rig.ml_rnd_offset, // double rnd_offset,
clt_parameters.rig.ml_main_tolerance, // double main_tolerance,
clt_parameters.rig.ml_grow_steps, // int grow_steps,
clt_parameters.rig.ml_grow_mode, // int grow_mode,
clt_parameters.rig.ml_new_strength, // double new_strength)
// debugLevel + 3); // int debugLevel);
debugLevel + 0); // int debugLevel);
double [][] rig_dsi = enhanceMainDSI(
rig_disparity_strength, // double [][] main_dsi,
rig_disparity_strength, // double [][] rig_dsi,
clt_parameters.rig.ml_rig_tolerance, // double rig_tolerance,
clt_parameters.rig.ml_rnd_offset, // double rnd_offset,
clt_parameters.rig.ml_main_tolerance, // double main_tolerance,
clt_parameters.rig.ml_grow_steps, // int grow_steps,
clt_parameters.rig.ml_grow_mode, // int grow_mode,
clt_parameters.rig.ml_new_strength, // double new_strength)
// debugLevel + 3); // int debugLevel);
debugLevel + 0); // int debugLevel);
if (ml_directory == null) ml_directory= quadCLT_main.correctionsParameters.selectMlDirectory(
quadCLT_main.image_name,
true, // smart,
......@@ -2099,48 +2103,138 @@ if (debugLevel > -100) return true; // temporarily !
clt_parameters.transform_size, // int transform_size,
2.0, // double wndx_scale, // (wndy scale is always 1.0)
(debugLevel > -1)); // boolean debug)
// Create test data that does not rely on the rig measurements
String img_name_main =quadCLT_main.image_name+"-ML_DATA-";
double [][] ml_data_main = remeasureRigML(
0.0, // double disparity_offset_low,
0.0, // double disparity_offset_high,
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
// disparity_bimap, // double [][] src_bimap,
main_disparity_strength[0], // double [] disparity_main, // main camera disparity to use - if null, calculate from the rig one
rig_disparity_strength[0], // double [] disparity,
rig_disparity_strength[1], // double [] strength,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_parameters.rig.ml_hwidth, // int ml_hwidth
clt_parameters.rig.ml_fatzero, // double fatzero,
//change if needed?
0, // int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
saveMlFile(
img_name_main, // String ml_title,
ml_directory, // String ml_directory,
Double.NaN, // double disp_offset_low,
Double.NaN, // double disp_offset_high,
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
corr2d, //Correlation2d corr2d, // to access "other" layer
clt_parameters.rig.ml_8bit, // boolean use8bpp,
clt_parameters.rig.ml_limit_extrim, // double limit_extrim,
clt_parameters.rig.ml_keep_aux, // boolean keep_aux,
clt_parameters.rig.ml_keep_inter, // boolean keep_inter,
clt_parameters.rig.ml_keep_hor_vert, // boolean keep_hor_vert,
clt_parameters.rig.ml_keep_tbrl, // boolean ml_keep_tbrl,
clt_parameters.rig.ml_keep_debug, // boolean keep_debug,
clt_parameters.rig.ml_fatzero, // double ml_fatzero,
clt_parameters.rig.ml_hwidth, // int ml_hwidth,
ml_data_main, // double [][] ml_data,
clt_parameters.rig.ml_show_ml, // boolean show,
debugLevel); // int debugLevel
// zero random offset:
if ( clt_parameters.rig.ml_main) {
double [][] ml_data_main = remeasureRigML(
0.0, // double disparity_offset_low,
Double.NaN, // 0.0, // double disparity_offset_high,
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
// disparity_bimap, // double [][] src_bimap,
main_dsi[0], // double [] disparity_main, // main camera disparity to use - if null, calculate from the rig one
rig_disparity_strength[0], // double [] disparity,
rig_disparity_strength[1], // double [] strength,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_parameters.rig.ml_hwidth, // int ml_hwidth
clt_parameters.rig.ml_fatzero, // double fatzero,
//change if needed?
0, // int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
saveMlFile(
img_name_main, // String ml_title,
ml_directory, // String ml_directory,
Double.NaN, // double disp_offset_low,
Double.NaN, // double disp_offset_high,
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
corr2d, //Correlation2d corr2d, // to access "other" layer
clt_parameters.rig.ml_8bit, // boolean use8bpp,
clt_parameters.rig.ml_limit_extrim, // double limit_extrim,
clt_parameters.rig.ml_keep_aux, // boolean keep_aux,
clt_parameters.rig.ml_keep_inter, // boolean keep_inter,
clt_parameters.rig.ml_keep_hor_vert, // boolean keep_hor_vert,
clt_parameters.rig.ml_keep_tbrl, // boolean ml_keep_tbrl,
clt_parameters.rig.ml_keep_debug, // boolean keep_debug,
clt_parameters.rig.ml_fatzero, // double ml_fatzero,
clt_parameters.rig.ml_hwidth, // int ml_hwidth,
ml_data_main, // double [][] ml_data,
clt_parameters.rig.ml_show_ml, // boolean show,
debugLevel); // int debugLevel
}
// Create images from main cameras, but adding random disparity offset
if ( clt_parameters.rig.ml_main_rnd) {
double [][] ml_data_main = remeasureRigML(
0.0, // double disparity_offset_low,
clt_parameters.rig.ml_disparity_sweep, // 0.0, // double disparity_offset_high,
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
// disparity_bimap, // double [][] src_bimap,
main_dsi[0], // double [] disparity_main, // main camera disparity to use - if null, calculate from the rig one
rig_disparity_strength[0], // double [] disparity,
rig_disparity_strength[1], // double [] strength,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_parameters.rig.ml_hwidth, // int ml_hwidth
clt_parameters.rig.ml_fatzero, // double fatzero,
//change if needed?
0, // int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
saveMlFile(
img_name_main, // String ml_title,
ml_directory, // String ml_directory,
Double.NaN, // double disp_offset_low,
clt_parameters.rig.ml_disparity_sweep, // double disp_offset_high,
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
corr2d, //Correlation2d corr2d, // to access "other" layer
clt_parameters.rig.ml_8bit, // boolean use8bpp,
clt_parameters.rig.ml_limit_extrim, // double limit_extrim,
clt_parameters.rig.ml_keep_aux, // boolean keep_aux,
clt_parameters.rig.ml_keep_inter, // boolean keep_inter,
clt_parameters.rig.ml_keep_hor_vert, // boolean keep_hor_vert,
clt_parameters.rig.ml_keep_tbrl, // boolean ml_keep_tbrl,
clt_parameters.rig.ml_keep_debug, // boolean keep_debug,
clt_parameters.rig.ml_fatzero, // double ml_fatzero,
clt_parameters.rig.ml_hwidth, // int ml_hwidth,
ml_data_main, // double [][] ml_data,
clt_parameters.rig.ml_show_ml, // boolean show,
debugLevel); // int debugLevel
}
// Create images from main cameras, but adding random disparity offset
if ( clt_parameters.rig.ml_rig_rnd) {
double [][] ml_data_main = remeasureRigML(
0.0, // double disparity_offset_low,
clt_parameters.rig.ml_disparity_sweep, // 0.0, // double disparity_offset_high,
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
rig_dsi[0], // double [] disparity_main, // main camera disparity to use - if null, calculate from the rig one
rig_disparity_strength[0], // double [] disparity,
rig_disparity_strength[1], // double [] strength,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_parameters.rig.ml_hwidth, // int ml_hwidth
clt_parameters.rig.ml_fatzero, // double fatzero,
//change if needed?
0, // int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
saveMlFile(
img_name_main, // String ml_title,
ml_directory, // String ml_directory,
Double.NaN, // double disp_offset_low,
-clt_parameters.rig.ml_disparity_sweep, // double disp_offset_high,
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
corr2d, //Correlation2d corr2d, // to access "other" layer
clt_parameters.rig.ml_8bit, // boolean use8bpp,
clt_parameters.rig.ml_limit_extrim, // double limit_extrim,
clt_parameters.rig.ml_keep_aux, // boolean keep_aux,
clt_parameters.rig.ml_keep_inter, // boolean keep_inter,
clt_parameters.rig.ml_keep_hor_vert, // boolean keep_hor_vert,
clt_parameters.rig.ml_keep_tbrl, // boolean ml_keep_tbrl,
clt_parameters.rig.ml_keep_debug, // boolean keep_debug,
clt_parameters.rig.ml_fatzero, // double ml_fatzero,
clt_parameters.rig.ml_hwidth, // int ml_hwidth,
ml_data_main, // double [][] ml_data,
clt_parameters.rig.ml_show_ml, // boolean show,
debugLevel); // int debugLevel
}
// Old code:
// Create images from tig with random offset
// TODO: add extrapolation, similar to main camera?
for (int sweep_step = 0; sweep_step < clt_parameters.rig.ml_sweep_steps; sweep_step++){
double disparity_offset_low = 0;
double disparity_offset_high = Double.NaN;
......@@ -2199,7 +2293,6 @@ if (debugLevel > -100) return true; // temporarily !
if (clt_parameters.rig.ml_randomize && (sweep_step == (clt_parameters.rig.ml_sweep_steps-2))) { // reduce by 1 for random
break;
}
}
}
......@@ -4535,8 +4628,8 @@ if (debugLevel > -100) return true; // temporarily !
public void saveMlFile(
String ml_title,
String ml_directory,
double disp_offset_low,
double disp_offset_high,
double disp_offset_low, // NaN - Main camera is used
double disp_offset_high, // !NaN and isNaN(disp_offset_low) - random amplitude: positive - from main, negative - from rig
QuadCLT quadCLT_main,
QuadCLT quadCLT_aux,
Correlation2d corr2d, // to access "other" layer
......@@ -4567,7 +4660,19 @@ if (debugLevel > -100) return true; // temporarily !
title+=String.format("%8.5f",disp_offset_high).trim();
}
} else {
title += "-MAIN";
// title += "-MAIN";
if (Double.isNaN(disp_offset_high)) {
title += "-MAIN";
} else {
if (disp_offset_high > 0) {
title += "-MAIN_RND";
title+=String.format("%8.5f",disp_offset_high).trim();
} else {
disp_offset_high = -disp_offset_high;
title+="-RIG_RND";
title+=String.format("%8.5f",disp_offset_high).trim();
}
}
}
int [] aux_indices = {
ImageDtt.ML_TOP_AUX_INDEX, // 8 - top pair 2d correlation center area (auxiliary camera)
......@@ -5668,8 +5773,23 @@ if (debugLevel > -100) return true; // temporarily !
// double [] disparity = src_bimap[ImageDtt.BI_TARGET_INDEX];
// double [] strength = src_bimap[ImageDtt.BI_STR_CROSS_INDEX];
boolean [] selection = new boolean [strength.length];
for (int nTile = 0; nTile < selection.length; nTile++) {
selection[nTile] = strength[nTile] > 0.0;
if (disparity_main != null) {
for (int nTile = 0; nTile < selection.length; nTile++) {
// selection[nTile] = strength[nTile] > 0.0;
selection[nTile] = (strength[nTile] > 0.0) || !Double.isNaN(disparity_main[nTile]); // measuring correlation for clusters - around defined tiles
if (selection[nTile] && Double.isNaN(disparity[nTile])) {
disparity[nTile] = 0.0; // it will not be used
strength[nTile] = 0.0; // should already be set
}
}
}
if (!(disparity_offset_high > disparity_offset_low)) { // otherwise offset to the rig data is used
for (int nTile = 0; nTile < selection.length; nTile++) {
if (selection[nTile] && Double.isNaN(disparity[nTile])) {
disparity[nTile] = 0.0; // it will not be used
strength[nTile] = 0.0; // should already be set
}
}
}
Random rnd = new Random(System.nanoTime());
Correlation2d corr2d = new Correlation2d(
......@@ -5679,7 +5799,8 @@ if (debugLevel > -100) return true; // temporarily !
(debugLevel > -1)); // boolean debug)
for (int nTile = 0; nTile < disparity.length; nTile++) {
if (((selection == null) || (selection[nTile]) && !Double.isNaN(disparity[nTile]))) {
// if (((selection == null) || (selection[nTile]) && !Double.isNaN(disparity[nTile]))) {
if ((selection == null) || selection[nTile]) {
int tileY = nTile / tilesX;
int tileX = nTile % tilesX;
tile_op[tileY][tileX] = tile_op_all;
......@@ -5690,8 +5811,10 @@ if (debugLevel > -100) return true; // temporarily !
if ((disparity_main != null) && !Double.isNaN(disparity_main[nTile])) {
// Use actuall disparity from the main camera
disparity_offset = disparity_main[nTile] - disparity[nTile];
if (!Double.isNaN(disparity_offset_high) && (disparity_offset_high > 0.0)) {
disparity_offset += disparity_offset_high* (2 * rnd.nextDouble() - 1.0);
}
}
disparity_array[tileY][tileX] = disparity[nTile]+disparity_offset;
corr2d.saveMlTilePixel(
tileX, // int tileX,
......@@ -5727,9 +5850,6 @@ if (debugLevel > -100) return true; // temporarily !
threadsMax, // maximal number of threads to launch // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
return ml_data;
}
......@@ -6396,7 +6516,210 @@ if (debugLevel > -100) return true; // temporarily !
}
return dsi;
}
/**
* Enhance main DSI data to prepare ML files:
* 1. remove tiles that are too different from the rig (> rig_tolerance) - that may me different object
* 2. replace undefined tiles that have rig data with average of 8 neighbors within
* rig_tolerance from rig disparity. If there are no suitable neighbors, use
* random offset from rig disparity within +/- rnd_offset
* 3. grow defined data, each layer using min/max/average from the known neighbors
* 4. assign new_strength to previously undefined tiles
* @param main_dsi
* @param rig_dsi
* @param rig_tolerance
* @param rnd_offset
* @param main_tolerance
* @param grow_steps
* @param grow_mode : -1 - min, 0 - average, +1 - max
* @param new_strength
* @return 'enhanced' disparity/strength for the main camera
*/
public double [][] enhanceMainDSI(
double [][] main_dsi,
double [][] rig_dsi,
double rig_tolerance,
double rnd_offset,
double main_tolerance,
int grow_steps,
int grow_mode,
double inher_strength,
int debugLevel)
{
double [][] dbg_img = null;
int num_dbg = 0;
String [] dbg_titles = null;
if (debugLevel > 1) {
num_dbg = grow_steps + 4;
dbg_img = new double [2 * num_dbg][];
dbg_titles = new String [2 * num_dbg];
dbg_img[0] = main_dsi[0].clone();
dbg_img[0 + num_dbg] = main_dsi[1].clone();
dbg_titles[0] = "main_d";
dbg_titles[0 + num_dbg] = "main_s";
dbg_img[1] = rig_dsi [0].clone();
dbg_img[1 + num_dbg] = rig_dsi [1].clone();
dbg_titles[1] = "rig_d";
dbg_titles[1 + num_dbg] = "rig_s";
}
final int tilesX = this.quadCLT_main.tp.getTilesX();
final int tilesY = this.quadCLT_main.tp.getTilesY();
TileNeibs tnImage = new TileNeibs(tilesX, tilesY); // biCamDSI_persistent.tnImage;
double [][] enh_dsi = {main_dsi[0].clone(),main_dsi[1].clone()};
int num_too_far = 0;
int num_by_neib = 0;
int num_rnd = 0;
int num_extrapolated = 0;
for (int nTile = 0; nTile < enh_dsi[0].length;nTile++) {
// Remove from main camera measurements those that do not have rig data or differ from rig by more than rig_tolerance
if (Double.isNaN(rig_dsi[0][nTile]) || (Math.abs(rig_dsi[0][nTile] - enh_dsi[0][nTile]) > rig_tolerance)) {
enh_dsi[1][nTile] = 0.0;
enh_dsi[0][nTile] = Double.NaN;
if (!Double.isNaN(rig_dsi[0][nTile])) {
num_too_far++; // count only too far, not NaN-s
}
}
}
double [] new_disp = enh_dsi[0].clone();
double [] new_str = enh_dsi[1].clone();
Random rnd = new Random(System.nanoTime());
for (int nTile = 0; nTile < enh_dsi[0].length;nTile++) if (Double.isNaN(enh_dsi[0][nTile]) && !Double.isNaN(rig_dsi[0][nTile])){
double sw = 0.0;
double sdw = 0.0;
int nneibs = 0;
for (int dir = 0; dir < 8; dir++) {
int nTile1 = tnImage.getNeibIndex(nTile, dir);
if ( (nTile1 >= 0) &&
!Double.isNaN(enh_dsi[0][nTile1]) &&
(Math.abs(enh_dsi[0][nTile1] - rig_dsi[0][nTile]) <= main_tolerance)) {
double w = enh_dsi[1][nTile1];
sw += w;
sdw += w * enh_dsi[0][nTile1];
nneibs++;
}
}
if (sw > 0) {
new_disp[nTile] = sdw/sw;
new_str[nTile] = inher_strength * sw/nneibs;
num_by_neib++;
} else {
new_disp[nTile] = rig_dsi[0][nTile] + rnd_offset*(2 * rnd.nextDouble() - 1.0);
new_str[nTile] = inher_strength * rig_dsi[1][nTile];
num_rnd++;
}
}
for (int nTile = 0; nTile < enh_dsi[0].length;nTile++) if (Double.isNaN(enh_dsi[0][nTile]) && !Double.isNaN(rig_dsi[0][nTile])){
enh_dsi[0][nTile] = new_disp[nTile];
enh_dsi[1][nTile] = new_str[nTile];
}
if (dbg_img != null) {
dbg_img[2] = enh_dsi[0].clone();
dbg_img[2 + num_dbg] = enh_dsi[1].clone();
dbg_titles[2] = "enh_preexp_d";
dbg_titles[2 + num_dbg] = "enh_preexp_s";
}
// double inher_strength = 0.5;
boolean [] exp_full = null;
if (grow_steps > 0) for (int n_expand = 0; n_expand < (grow_steps+1); n_expand++) {
boolean [] selection = new boolean[enh_dsi[0].length];
for (int nTile = 0; nTile < enh_dsi[0].length;nTile++) {
selection[nTile] = !Double.isNaN(enh_dsi[0][nTile]);
}
if (n_expand == (grow_steps-1)) {
exp_full = selection.clone();
tnImage.growSelection(2, exp_full, null); // hor, vert and diagonal
tnImage.growSelection(1, selection, null); // only hor/vert
} else if ((n_expand == grow_steps) && (exp_full != null)) {
selection = exp_full;
} else {
tnImage.growSelection(1, selection, null); // only hor/vert
}
// tnImage.growSelection(2, selection, null);
for (int nTile = 0; nTile < enh_dsi[0].length;nTile++) if (selection[nTile] && Double.isNaN((enh_dsi[0][nTile]))){
double sw = 0.0;
double sdw = 0.0;
int ntiles = 0;
double d_min = Double.POSITIVE_INFINITY;
double d_max = Double.NEGATIVE_INFINITY;
for (int dir = 0; dir < 8; dir++) {
int nTile1 = tnImage.getNeibIndex(nTile, dir);
if ((nTile1 >= 0) && !Double.isNaN(enh_dsi[0][nTile1])){
double d = enh_dsi[0][nTile1];
if (d < d_min) {
d_min = d;
}
if (d > d_max) {
d_max = d;
}
double w = enh_dsi[1][nTile1];
sw += w;
sdw += w * enh_dsi[0][nTile1];
ntiles++;
}
}
if (sw > 0.0) {
double d_avg = sdw/sw;
switch (grow_mode) {
case -1: new_disp[nTile] = d_min; break;
case 1: new_disp[nTile] = d_max; break;
case 0: new_disp[nTile] = d_avg; break;
default: {
// find - which of the min,max, avg is closer to rig (if available, if not - use avg)
if (!Double.isNaN(rig_dsi[0][nTile])) {
double [] diffs = {Math.abs(d_min - rig_dsi[0][nTile]), Math.abs(d_max - rig_dsi[0][nTile]),Math.abs(d_avg - rig_dsi[0][nTile])};
if ((diffs[0] < diffs[1]) && (diffs[0] < diffs[2])){
new_disp[nTile] = d_min;
} else if (diffs[1] < diffs[2]) {
new_disp[nTile] = d_max;
} else {
new_disp[nTile] = d_avg;
}
} else {
new_disp[nTile] = d_avg;
}
}
}
new_str[nTile] = inher_strength * sw/ntiles;
num_extrapolated++;
} else {
new_disp[nTile] = Double.NaN;
new_str[nTile] = 0.0;
}
}
for (int nTile = 0; nTile < enh_dsi[0].length;nTile++) if (selection[nTile] && Double.isNaN(enh_dsi[0][nTile]) && !Double.isNaN(new_disp[nTile]) ){
enh_dsi[0][nTile] = new_disp[nTile];
enh_dsi[1][nTile] = new_str[nTile]; // new_strength;
}
if (dbg_img != null) {
dbg_img[3+n_expand] = enh_dsi[0].clone();
dbg_img[3+n_expand + num_dbg] = enh_dsi[1].clone();
dbg_titles[3+n_expand] = "enh_exp"+n_expand+"_d";
dbg_titles[3+n_expand + num_dbg] = "enh_exp"+n_expand+"_s";
}
}
if (debugLevel > 0) {
System.out.println("enhanceMainDSI(): num_too_far="+num_too_far+", num_by_neib="+num_by_neib+", num_rnd="+num_rnd+", num_extrapolated="+num_extrapolated);
}
if (dbg_img != null) {
(new showDoubleFloatArrays()).showArrays(
dbg_img,
tilesX,
tilesY,
true,
"enhanced_dsi_dbg",
dbg_titles);
}
return enh_dsi;
}
public void regenerateML(
String path_DSI, // Combo DSI path
String model_dir, // model/version directory
......@@ -6411,10 +6734,20 @@ if (debugLevel > -100) return true; // temporarily !
final boolean updateStatus,
final int debugLevel) throws Exception
{
this.startTime=System.nanoTime();
boolean new_dir_only = true;
String ml_dir = (ml_subdir == null)? null: (model_dir+Prefs.getFileSeparator()+ml_subdir);
if (new_dir_only) {
File dir = new File(ml_dir);
if (dir.exists()){
System.out.println("Directory already exists: "+dir+", and new_dir_only=true -> skipping generation");
return;
}
}
double [][] rig_dsi = getRigDSI(path_DSI, false);
double [][] main_dsi = getRigDSI(path_DSI, true);
String [] sourceFiles=quadCLT_main.correctionsParameters.getSourcePaths();
QuadCLT.SetChannels [] set_channels_main = quadCLT_main.setChannels(debugLevel);
QuadCLT.SetChannels [] set_channels_aux = quadCLT_aux.setChannels(debugLevel);
......@@ -6473,12 +6806,25 @@ if (debugLevel > -100) return true; // temporarily !
threadsMax, // maximal number of threads to launch
debugLevel); // final int debugLevel);
// now tp is defined
/*
main_dsi = enhanceMainDSI(
main_dsi, // double [][] main_dsi,
rig_dsi, // double [][] rig_dsi,
clt_parameters.rig.ml_rig_tolerance, // double rig_tolerance,
clt_parameters.rig.ml_rnd_offset, // double rnd_offset,
clt_parameters.rig.ml_main_tolerance, // double main_tolerance,
clt_parameters.rig.ml_grow_steps, // int grow_steps,
clt_parameters.rig.ml_grow_mode, // int grow_mode,
clt_parameters.rig.ml_new_strength, // double new_strength)
// debugLevel + 3); // int debugLevel);
debugLevel + 0); // int debugLevel);
*/
quadCLT_main.tp.rig_pre_poles_ds = rig_dsi; // use rig data from the COMBO-DSI file
quadCLT_main.tp.main_ds_ml = main_dsi; // use rig data from the COMBO-DSI file
// quadCLT_main.tp.resetCLTPasses();
// quadCLT_aux.tp.resetCLTPasses();
String ml_dir = (ml_subdir == null)? null: (model_dir+Prefs.getFileSeparator()+ml_subdir);
// String ml_dir = (ml_subdir == null)? null: (model_dir+Prefs.getFileSeparator()+ml_subdir);
outputMLData(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
......
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