Commit b5f3d42a authored by Andrey Filippov's avatar Andrey Filippov

Using main camera -only DSI in the model where aux camera is occluded

parent dbd2a71c
......@@ -237,9 +237,13 @@ public class BiQuadParameters {
public double rf_min_disp = 0.02; // Minimal tile disparity to keep in scan
public boolean rf_remove_unselected = true; // Remove tiles that are not selected
public boolean oc_fill_aux_occl = true; // Fill rig DSI gaps non-zero for the main camera
public double oc_min_disparity = 15; // Tile occlusions can only happen for near objects
public double oc_min_strength = 0.1; // Minimal main camera strength
public boolean ml_generate = false; // Generate ML data automatically when running ground truth
// public boolean ml_generate = false; // Generate ML data automatically when running ground truth - MOVED to BATCH parameters
public boolean ml_poles = true; // Generate ML data from the DSI that includes extracted poles
public boolean ml_copyJP4 = true; // Copy source jp4 files when running "Ground truth" command
......@@ -631,11 +635,17 @@ public class BiQuadParameters {
"Minimal disparity (in master camera pixels) for the tile to be saved for plane extraction");
gd.addCheckbox ("Remove tiles that are not selected", this.rf_remove_unselected,
"Remove (set strength to 0.0, disparity to Double.NaN for all tiles that are not selected");
gd.addCheckbox ("Fill rig gaps by the main camera", this.oc_fill_aux_occl,
"Areas where aux camera image is occluded");
gd.addNumericField("Minimal main camera disparity to use for rig DSI gaps", this.oc_min_disparity, 3,6,"pix",
"Legitimate full tile occlusions can happen for near objects only");
gd.addNumericField("Minimal main camera strength to fill rig DSI gaps", this.oc_min_strength, 3,6,"",
"Filter out too weak replacements");
gd.addTab("ML","Parameters related to the ML files generation for the dual-quad camera rig");
gd.addCheckbox ("Generate ML data automatically", this.ml_generate,
"Generate ML data automatically when running ground truth (may run separately from a command button)");
// gd.addCheckbox ("Generate ML data automatically", this.ml_generate,
// "Generate ML data automatically when running ground truth (may run separately from a command button)");
gd.addCheckbox ("Generate ML data from the DSI that includes extracted poles", this.ml_poles,
"If unchecked - use DSI w/o poles data");
gd.addCheckbox ("Copy JP4 source images when generating ML data", this.ml_copyJP4,
......@@ -853,8 +863,12 @@ public class BiQuadParameters {
this.rf_min_disp= gd.getNextNumber();
this.rf_remove_unselected= gd.getNextBoolean();
this.oc_fill_aux_occl= gd.getNextBoolean();
this.oc_min_disparity= gd.getNextNumber();
this.oc_min_strength= gd.getNextNumber();
this.ml_generate= gd.getNextBoolean();
// this.ml_generate= gd.getNextBoolean();
this.ml_poles= gd.getNextBoolean();
this.ml_copyJP4= gd.getNextBoolean();
......@@ -1061,7 +1075,11 @@ public class BiQuadParameters {
properties.setProperty(prefix+"rf_min_disp", this.rf_min_disp+"");
properties.setProperty(prefix+"rf_remove_unselected", this.rf_remove_unselected+"");
properties.setProperty(prefix+"ml_generate", this.ml_generate+"");
properties.setProperty(prefix+"oc_fill_aux_occl", this.oc_fill_aux_occl+"");
properties.setProperty(prefix+"oc_min_disparity", this.oc_min_disparity+"");
properties.setProperty(prefix+"oc_min_strength", this.oc_min_strength+"");
// properties.setProperty(prefix+"ml_generate", this.ml_generate+"");
properties.setProperty(prefix+"ml_poles", this.ml_poles+"");
properties.setProperty(prefix+"ml_copyJP4", this.ml_copyJP4+"");
properties.setProperty(prefix+"ml_hwidth", this.ml_hwidth+"");
......@@ -1264,7 +1282,11 @@ public class BiQuadParameters {
if (properties.getProperty(prefix+"rf_min_disp")!=null) this.rf_min_disp=Double.parseDouble(properties.getProperty(prefix+"rf_min_disp"));
if (properties.getProperty(prefix+"rf_remove_unselected")!=null) this.rf_remove_unselected=Boolean.parseBoolean(properties.getProperty(prefix+"rf_remove_unselected"));
if (properties.getProperty(prefix+"ml_generate")!=null) this.ml_generate=Boolean.parseBoolean(properties.getProperty(prefix+"ml_generate"));
if (properties.getProperty(prefix+"oc_fill_aux_occl")!=null) this.oc_fill_aux_occl=Boolean.parseBoolean(properties.getProperty(prefix+"oc_fill_aux_occl"));
if (properties.getProperty(prefix+"oc_min_disparity")!=null) this.oc_min_disparity=Double.parseDouble(properties.getProperty(prefix+"oc_min_disparity"));
if (properties.getProperty(prefix+"oc_min_strength")!=null) this.oc_min_strength=Double.parseDouble(properties.getProperty(prefix+"oc_min_strength"));
// if (properties.getProperty(prefix+"ml_generate")!=null) this.ml_generate=Boolean.parseBoolean(properties.getProperty(prefix+"ml_generate"));
if (properties.getProperty(prefix+"ml_poles")!=null) this.ml_poles=Boolean.parseBoolean(properties.getProperty(prefix+"ml_poles"));
if (properties.getProperty(prefix+"ml_copyJP4")!=null) this.ml_copyJP4=Boolean.parseBoolean(properties.getProperty(prefix+"ml_copyJP4"));
if (properties.getProperty(prefix+"ml_hwidth")!=null) this.ml_hwidth=Integer.parseInt(properties.getProperty(prefix+"ml_hwidth"));
......@@ -1468,7 +1490,11 @@ public class BiQuadParameters {
bqp.rf_min_disp= this.rf_min_disp;
bqp.rf_remove_unselected= this.rf_remove_unselected;
bqp.ml_generate= this.ml_generate;
bqp.oc_fill_aux_occl = this.oc_fill_aux_occl;
bqp.oc_min_disparity = this.oc_min_disparity;
bqp.oc_min_strength = this.oc_min_strength;
// bqp.ml_generate= this.ml_generate;
bqp.ml_poles= this.ml_poles;
bqp.ml_copyJP4= this.ml_copyJP4;
bqp.ml_hwidth= this.ml_hwidth;
......
......@@ -134,6 +134,7 @@ public class EyesisCorrectionParameters {
public boolean clt_batch_surf = true; // Create super-tile 2.5d surfaces
public boolean clt_batch_assign = true; // Assign tiles to surfaces
public boolean clt_batch_gen3d = true; // Generate 3d output: x3d and/or obj+mtl
public boolean clt_batch_genMl = true; // Generate ML output
public boolean clt_batch_dbg1 = true; // Generate debug images if a single set is selected
public boolean clt_batch_dsi = true; // Create and save DSI combo image with the model
public boolean clt_batch_dsi_aux = false; // Calculate and save aux camera DSI (currently it is offset from the main/rig data
......@@ -268,6 +269,7 @@ public class EyesisCorrectionParameters {
cp.clt_batch_surf= this.clt_batch_surf;
cp.clt_batch_assign= this.clt_batch_assign;
cp.clt_batch_gen3d= this.clt_batch_gen3d;
cp.clt_batch_genMl= this.clt_batch_genMl;
cp.clt_batch_dbg1= this.clt_batch_dbg1;
cp.clt_batch_dsi= this.clt_batch_dsi;
......@@ -422,6 +424,8 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"clt_batch_surf", this.clt_batch_surf+"");
properties.setProperty(prefix+"clt_batch_assign", this.clt_batch_assign+"");
properties.setProperty(prefix+"clt_batch_gen3d", this.clt_batch_gen3d+"");
properties.setProperty(prefix+"clt_batch_genMl", this.clt_batch_genMl+"");
properties.setProperty(prefix+"clt_batch_dbg1", this.clt_batch_dbg1+"");
properties.setProperty(prefix+"clt_batch_dsi", this.clt_batch_dsi+"");
......@@ -571,6 +575,8 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"clt_batch_surf")!= null) this.clt_batch_surf=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_surf"));
if (properties.getProperty(prefix+"clt_batch_assign")!= null) this.clt_batch_assign=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_assign"));
if (properties.getProperty(prefix+"clt_batch_gen3d")!= null) this.clt_batch_gen3d=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_gen3d"));
if (properties.getProperty(prefix+"clt_batch_genMl")!= null) this.clt_batch_genMl=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_genMl"));
if (properties.getProperty(prefix+"clt_batch_dbg1")!= null) this.clt_batch_dbg1=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_dbg1"));
if (properties.getProperty(prefix+"clt_batch_dsi")!= null) this.clt_batch_dsi=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_dsi"));
......@@ -919,6 +925,8 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Create super-tile 2.5d surfaces", this.clt_batch_surf); // 26
gd.addCheckbox ("Assign tiles to surfaces", this.clt_batch_assign); // 27
gd.addCheckbox ("Generate 3d output: x3d and/or obj+mtl", this.clt_batch_gen3d); // 28
gd.addCheckbox ("Generate ML output files", this.clt_batch_genMl); // 28
gd.addCheckbox ("Generate debug images if a single set is selected", this.clt_batch_dbg1); // 29
gd.addCheckbox ("Create DSI combo image", this.clt_batch_dsi,
......@@ -1000,6 +1008,7 @@ public class EyesisCorrectionParameters {
this.clt_batch_surf= gd.getNextBoolean(); // 26
this.clt_batch_assign= gd.getNextBoolean(); // 27
this.clt_batch_gen3d= gd.getNextBoolean(); // 28
this.clt_batch_genMl= gd.getNextBoolean(); // 28
this.clt_batch_dbg1= gd.getNextBoolean(); // 29
this.clt_batch_dsi= gd.getNextBoolean();
this.clt_batch_dsi_aux= gd.getNextBoolean();
......@@ -2642,6 +2651,7 @@ public class EyesisCorrectionParameters {
public int ly_par_sel = 0; // Manually select the parameter mask bit 0 - sym0, bit1 - sym1, ... (0 - use checkbox selections above)
public double ly_inf_frac = 0.5; // Relative weight of infinity calibration data
public double ly_inf_max_disparity = 0.2; // Maximal disparity to be treated as infinity when adjusting with rig data
public boolean ly_inf_disp= false; // Correct disparity for infinity tiles
public boolean ly_inf_force= false; // Force convergence correction during extrinsic, even with no infinity data
public boolean ly_poly = false; // Use polynomial correction, false - correct tilt/azimuth/roll of each sensor
......@@ -3222,8 +3232,10 @@ public class EyesisCorrectionParameters {
public PoleProcessorParameters poles = new PoleProcessorParameters();
public MeasuredLayersFilterParameters mlfp = new MeasuredLayersFilterParameters();
public HashMap<String,Double> z_corr_map = new HashMap<String,Double>();
public HashMap<String,Double> z_corr_map = new HashMap<String,Double>(); //old one
public HashMap<String,Double> infinity_distace_map = new HashMap<String,Double>(); //new one
public static String Z_CORR_PREFIX = "z_corr.";
public static String INFINITY_DISTANCE_PREFIX = "infinity_distance.";
public boolean batch_run = false; // turned on only while running in batch mode
......@@ -3369,6 +3381,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"ly_inf_frac", this.ly_inf_frac +"");
properties.setProperty(prefix+"ly_inf_max_disparity",this.ly_inf_max_disparity +"");
properties.setProperty(prefix+"ly_inf_disp", this.ly_inf_disp+"");
properties.setProperty(prefix+"ly_inf_force", this.ly_inf_force+"");
properties.setProperty(prefix+"ly_poly", this.ly_poly+"");
......@@ -3888,13 +3901,29 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+Z_CORR_PREFIX+entry.getKey(), entry.getValue().toString());
}
}
setPropertiesInfinityDistance(prefix, properties);
/*
if (infinity_distace_map != null) {
for (HashMap.Entry<String,Double> entry : infinity_distace_map.entrySet()){
properties.setProperty(prefix+INFINITY_DISTANCE_PREFIX+entry.getKey(), entry.getValue().toString());
}
}
*/
img_dtt.setProperties (prefix+"_img_dtt", properties);
mlfp.setProperties (prefix+"_mlfp", properties);
rig.setProperties (prefix+"_rig", properties);
poles.setProperties (prefix+"_poles", properties);
}
public void setPropertiesInfinityDistance(String prefix,Properties properties){
if (infinity_distace_map != null) {
for (HashMap.Entry<String,Double> entry : infinity_distace_map.entrySet()){
properties.setProperty(prefix+INFINITY_DISTANCE_PREFIX+entry.getKey(), entry.getValue().toString());
}
}
}
public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"transform_size")!=null) this.transform_size=Integer.parseInt(properties.getProperty(prefix+"transform_size"));
if (properties.getProperty(prefix+"clt_window")!=null) this.clt_window=Integer.parseInt(properties.getProperty(prefix+"clt_window"));
......@@ -4035,6 +4064,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"ly_par_sel")!=null) this.ly_par_sel=Integer.parseInt(properties.getProperty(prefix+"ly_par_sel"));
if (properties.getProperty(prefix+"ly_inf_frac")!=null) this.ly_inf_frac=Double.parseDouble(properties.getProperty(prefix+"ly_inf_frac"));
if (properties.getProperty(prefix+"ly_inf_max_disparity")!=null) this.ly_inf_max_disparity=Double.parseDouble(properties.getProperty(prefix+"ly_inf_max_disparity"));
if (properties.getProperty(prefix+"ly_inf_disp")!=null) this.ly_inf_disp=Boolean.parseBoolean(properties.getProperty(prefix+"ly_inf_disp"));
......@@ -4568,7 +4598,14 @@ public class EyesisCorrectionParameters {
z_corr_map.put(s.substring(li), Double.parseDouble(properties.getProperty(s)));
}
}
img_dtt.getProperties (prefix+"_img_dtt", properties);
String full_prefix_infinity_distance = prefix+INFINITY_DISTANCE_PREFIX;
int lii = full_prefix_infinity_distance.length();
for (String s:ss){
if (s.indexOf(full_prefix_infinity_distance) == 0){
infinity_distace_map.put(s.substring(lii), Double.parseDouble(properties.getProperty(s)));
}
}
img_dtt.getProperties (prefix+"_img_dtt", properties);
mlfp.getProperties (prefix+"_mlfp", properties);
rig.getProperties (prefix+"_rig", properties);
poles.getProperties (prefix+"_poles", properties);
......@@ -4744,6 +4781,10 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Manual parameter mask selection (0 use checkboxes above)", this.ly_par_sel, 0, 5,"",
"bit 0 - sym0, bit1 - sym1, ...");
gd.addNumericField("Relative weight of infinity calibration data", this.ly_inf_frac, 3);
gd.addNumericField("Maximal disparity to be treated as infinity when adjusting with the rig data", this.ly_inf_max_disparity, 8,3,"pix",
"Only used in guided (by rig data) mode");
gd.addCheckbox ("Correct disparity for infinity tiles )has to disable until code fixed)", this.ly_inf_disp);
gd.addCheckbox ("Force convergence correction during extrinsic, even with no infinity data", this.ly_inf_force);
gd.addCheckbox ("*Use polynomial correction, false - correct tilt/azimuth/roll of each sensor)", this.ly_poly);
......@@ -5514,6 +5555,7 @@ public class EyesisCorrectionParameters {
this.ly_par_sel= (int) gd.getNextNumber();
this.ly_inf_frac= gd.getNextNumber();
this.ly_inf_max_disparity= gd.getNextNumber();
this.ly_inf_disp= gd.getNextBoolean();
this.ly_inf_force= gd.getNextBoolean();
......@@ -6228,6 +6270,44 @@ public class EyesisCorrectionParameters {
}
return true;
}
public boolean modifyInfCorr (String title) {
if (infinity_distace_map == null){
infinity_distace_map = new HashMap<String,Double>();
}
GenericDialog gd = new GenericDialog(title);
if (infinity_distace_map.size() > 0) {
gd.addMessage("Edit \"infinity\" (when mountains are too close) distance (in m), set == 0.0 to remove for the following");
gd.addMessage("Press \"Cancel\" to exit");
for (HashMap.Entry<String,Double> entry : infinity_distace_map.entrySet()){
gd.addNumericField(entry.getKey(), entry.getValue(), 1,6, "m");
}
}
gd.addMessage("Add new infinity correction");
gd.addStringField ("Timestamp string (seconds_microseconds):", "", 40);
gd.addNumericField("Infinity distance", 0, 1,6,"m");
gd.addCheckbox ("Clear list", false);
WindowTools.addScrollBars(gd);
gd.showDialog();
if (gd.wasCanceled()) return false;
HashMap<String,Double> new_map = new HashMap<String,Double>();
for (HashMap.Entry<String,Double> entry : infinity_distace_map.entrySet()){
double d = gd.getNextNumber();
if (d != 0.0) {
new_map.put(entry.getKey(),d);
}
}
String new_ts = gd.getNextString();
double d = gd.getNextNumber();
if (gd.getNextBoolean()){
infinity_distace_map = new HashMap<String,Double>();
} else {
infinity_distace_map = new_map;
}
if(new_ts.length() > 0){
infinity_distace_map.put(new_ts, d);
}
return true;
}
}
public static class DCTParameters {
......
......@@ -583,6 +583,8 @@ private Panel panel1,
// addButton("CLT 2*4 images", panelClt4, color_conf_process);
// addButton("CLT 2*4 images - 2", panelClt4, color_conf_process);
// addButton("CLT 2*4 images - 3", panelClt4, color_conf_process);
addButton("Rig offset", panelClt4, color_configure);
addButton("Save offset", panelClt4, color_process);
addButton("SHOW extrinsics", panelClt4, color_configure);
addButton("RIG DSI", panelClt4, color_conf_process);
addButton("MAIN extrinsics", panelClt4, color_process);
......@@ -1171,6 +1173,12 @@ private Panel panel1,
return;
/* ======================================================================== */
} else if (label.equals("Save offset")) {
saveInfinityOffsets(null,CORRECTION_PARAMETERS.resultsDirectory);
return;
/* ======================================================================== */
} else if (label.equals("Restore")) {
String path= loadProperties(null,CORRECTION_PARAMETERS.resultsDirectory,true, PROPERTIES);
if (path != null) {
......@@ -3703,6 +3711,12 @@ private Panel panel1,
if (!CLT_PARAMETERS.modifyZCorr("Modify infinity per image set disparity corrections")) break;
}
return;
/* ======================================================================== */
} else if (label.equals("Rig offset")) {
while (true) {
if (!CLT_PARAMETERS.modifyInfCorr("Modify infinity offset per image set disparity corrections")) break;
}
return;
/* ======================================================================== */
} else if (label.equals("Select CLT image")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
......@@ -5360,19 +5374,6 @@ private Panel panel1,
public boolean batchRig() {
long startTime=System.nanoTime();
/* if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null) || (QUAD_CLT.tp.clt_3d_passes.size() == 0)) {
boolean OK = clt3d(
false, // boolean adjust_extrinsics,
false); // boolean adjust_poly);
if (! OK) {
String msg = "DSI data is not available and \"CLT 3D\" failed";
IJ.showMessage("Error",msg);
System.out.println(msg);
return false;
}
}
*/
// load needed sensor and kernels files
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
......@@ -6709,7 +6710,59 @@ private Panel panel1,
}
public void saveInfinityOffsets(
String path, // full path or null
String directory) { // use as default directory if path==null
String [] patterns= {".corr-xml",".xml"};
if (path==null) {
path= selectFile(true, // save
"Save configuration selection", // title
"Select configuration file", // button
new MultipleExtensionsFileFilter(patterns, "XML Configuration files (*.corr-xml)"), // filter
directory); // may be ""
} else path+=patterns[0];
if (path==null) return;
Properties properties = new Properties();
CLT_PARAMETERS.setPropertiesInfinityDistance("CLT_PARAMETERS.", properties);
// setAllProperties(properties);
OutputStream os;
try {
os = new FileOutputStream(path);
} catch (FileNotFoundException e1) {
// missing config directory
File dir = (new File(path)).getParentFile();
if (!dir.exists()){
dir.mkdirs();
try {
os = new FileOutputStream(path);
} catch (FileNotFoundException e2) {
IJ.showMessage("Error","Failed to create directory "+dir.getName()+" to save configuration file: "+path);
return;
}
} else {
IJ.showMessage("Error","Failed to open configuration file: "+path);
return;
}
}
try {
properties.storeToXML(os,
"last updated " + new java.util.Date(), "UTF8");
} catch (IOException e) {
IJ.showMessage("Error","Failed to write XML configuration file: "+path);
return;
}
try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (DEBUG_LEVEL> -3) System.out.println("Configuration parameters are saved to "+path);
}
/* ======================================================================== */
......
......@@ -154,6 +154,7 @@ public class GeometryCorrection {
return ro.getParNorm(index);
}
public double [] getRigCorrection(
double infinity_importance, // of all measurements
double dx_max, // = 0.3;
......@@ -165,6 +166,7 @@ public class GeometryCorrection {
boolean adjust_distance,
boolean adjust_forward, // not used
double scale_correction,
double infinity_disparity,
ArrayList<Integer> tile_list,
QuadCLT qc_main,
double [] strength,
......@@ -184,6 +186,7 @@ public class GeometryCorrection {
adjust_distance, // boolean adjust_distance,
adjust_forward, // boolean adjust_forward, // not used
scale_correction, // double scale_correction,
infinity_disparity, // double infinity_disparity,
tile_list, // ArrayList<Integer> tile_list,
qc_main, // QuadCLT qc_main,
strength, // double [] strength,
......@@ -192,6 +195,7 @@ public class GeometryCorrection {
target_disparity, // double [] target_disparity,
debugLevel); // int debugLevel)
}
// correction of cameras mis-alignment
public CorrVector getCorrVector(double [] vector){
return new CorrVector(vector);
......@@ -376,87 +380,6 @@ public class GeometryCorrection {
}
recalcRXY();
}
public double setupYW(
double infinity_importance, // of all measurements
double dx_max, // = 0.3;
double dx_pow, // = 1.0;
ArrayList<Integer> tile_list,
QuadCLT qc,
double [] strength,
double [] diff_x, // used only with target_disparity == 0
double [] diff_y,
double [] target_disparity) {
y_vector = new double[2*tile_list.size()];
w_vector = new double[2*tile_list.size()];
xy_vector = new double[2*tile_list.size()];
d_vector = new double[tile_list.size()];
tile_vector= new int[tile_list.size()];
boolean [] is_inf = new boolean[tile_list.size()];
double sumw_inf = 0.0,sumw_near=0.0;
double sum2_inf = 0.0,sum2_near = 0.0;
int tilesX = qc.tp.getTilesX();
double tileSize = qc.tp.getTileSize();
// double dx_max = 0.2;
// double dx_pow = 1.0;
for (int i = 0; i < tile_list.size(); i++) {
int nTile = tile_list.get(i);
int tileY = nTile / tilesX;
int tileX = nTile % tilesX;
double w = strength[nTile];
double inf_w_corr = 1.0;
if ((dx_max > 0) && (dx_pow > 0)){
inf_w_corr = (dx_max - diff_x[nTile])/dx_max;
if (inf_w_corr < 0.0) inf_w_corr = 0.0; // favor negative (more infinity)
if (dx_pow != 1.0) {
inf_w_corr = Math.pow(inf_w_corr,dx_pow);
}
}
if (target_disparity[nTile] == 0.0) { // only for infinity tiles
w *= inf_w_corr;
y_vector[2*i + 0] = diff_x[nTile];
w_vector[2*i + 0] = w;
y_vector[2*i + 1] = diff_y[nTile];
w_vector[2*i + 1] = w;
sumw_inf += 2*w;
sum2_inf += w*(diff_x[nTile]*diff_x[nTile]+diff_y[nTile]*diff_y[nTile]);
is_inf[i] = true;
} else {
y_vector[2*i + 1] = diff_y[nTile];
w_vector[2*i + 1] = w;
sumw_near += w;
sum2_near += w*diff_y[nTile]*diff_y[nTile];
}
xy_vector[2*i + 0] = (tileX + 0.5) * tileSize;
xy_vector[2*i + 1] = (tileY + 0.5) * tileSize;
d_vector[i] = target_disparity[nTile];
tile_vector[i] = nTile;
}
if (infinity_importance > 1.0) infinity_importance = 1.0;
else if (infinity_importance < 0.0) infinity_importance =0.0;
double k_inf = 0.0, k_near = 0.0;
if ((sumw_inf > 0.0) && (sumw_near > 0.0)){
k_inf = infinity_importance/sumw_inf;
k_near = (1.0 - infinity_importance)/sumw_near;
} else if (sumw_inf > 0.0){
infinity_importance = 1.0;
k_inf = infinity_importance/sumw_inf;
} else if (sumw_near > 0.0) {
infinity_importance = 0.0;
k_near = (1.0 - infinity_importance)/sumw_near;
}
double sum2 = k_inf*sum2_inf+k_near*sum2_near;
for (int i = 0; i < is_inf.length; i++) {
if (is_inf[i]) {
w_vector[2 * i + 0] *= k_inf;
w_vector[2 * i + 1] *= k_inf;
} else {
w_vector[2 * i + 1] *= k_near;
}
}
return Math.sqrt(sum2); // RMS
}
double [][] getJacobianTransposed(
GeometryCorrection gc_main,
......@@ -585,6 +508,7 @@ public class GeometryCorrection {
boolean adjust_distance,
boolean adjust_forward, // not used
double scale_correction,
double infinity_disparity,
ArrayList<Integer> tile_list,
QuadCLT qc_main,
double [] strength,
......@@ -604,6 +528,7 @@ public class GeometryCorrection {
infinity_importance, // of all measurements
dx_max, // double dx_max, // = 0.3;
dx_pow, // double dx_pow, // = 1.0;
infinity_disparity, // double infinity_disparity,
tile_list,
qc_main,
strength,
......@@ -692,10 +617,91 @@ public class GeometryCorrection {
return vector;
}
// public double [] getAuxOffset() {
// double [] aux_offset= {baseline * Math.cos(aux_angle)/getDisparityRadius(), baseline * Math.sin(aux_angle)/getDisparityRadius()};
// return aux_offset;
// }
public double setupYW(
double infinity_importance, // of all measurements
double dx_max, // = 0.3;
double dx_pow, // = 1.0;
double infinity_disparity,
ArrayList<Integer> tile_list,
QuadCLT qc,
double [] strength,
double [] diff_x, // used only with target_disparity == 0
double [] diff_y,
double [] target_disparity) {
y_vector = new double[2*tile_list.size()];
w_vector = new double[2*tile_list.size()];
xy_vector = new double[2*tile_list.size()];
d_vector = new double[tile_list.size()];
tile_vector= new int[tile_list.size()];
boolean [] is_inf = new boolean[tile_list.size()];
double sumw_inf = 0.0,sumw_near=0.0;
double sum2_inf = 0.0,sum2_near = 0.0;
int tilesX = qc.tp.getTilesX();
double tileSize = qc.tp.getTileSize();
// double dx_max = 0.2;
// double dx_pow = 1.0;
for (int i = 0; i < tile_list.size(); i++) {
int nTile = tile_list.get(i);
int tileY = nTile / tilesX;
int tileX = nTile % tilesX;
double w = strength[nTile];
double inf_w_corr = 1.0;
if ((dx_max > 0) && (dx_pow > 0)){
inf_w_corr = (dx_max - diff_x[nTile])/dx_max;
if (inf_w_corr < 0.0) inf_w_corr = 0.0; // favor negative (more infinity)
if (dx_pow != 1.0) {
inf_w_corr = Math.pow(inf_w_corr,dx_pow);
}
}
if (target_disparity[nTile] == infinity_disparity) { // only for infinity tiles
w *= inf_w_corr;
y_vector[2*i + 0] = diff_x[nTile];
w_vector[2*i + 0] = w;
y_vector[2*i + 1] = diff_y[nTile];
w_vector[2*i + 1] = w;
sumw_inf += 2*w;
sum2_inf += w*(diff_x[nTile]*diff_x[nTile]+diff_y[nTile]*diff_y[nTile]);
is_inf[i] = true;
} else {
y_vector[2*i + 1] = diff_y[nTile];
w_vector[2*i + 1] = w;
sumw_near += w;
sum2_near += w*diff_y[nTile]*diff_y[nTile];
}
xy_vector[2*i + 0] = (tileX + 0.5) * tileSize;
xy_vector[2*i + 1] = (tileY + 0.5) * tileSize;
d_vector[i] = target_disparity[nTile];
tile_vector[i] = nTile;
}
if (infinity_importance > 1.0) infinity_importance = 1.0;
else if (infinity_importance < 0.0) infinity_importance =0.0;
double k_inf = 0.0, k_near = 0.0;
if ((sumw_inf > 0.0) && (sumw_near > 0.0)){
k_inf = infinity_importance/sumw_inf;
k_near = (1.0 - infinity_importance)/sumw_near;
} else if (sumw_inf > 0.0){
infinity_importance = 1.0;
k_inf = infinity_importance/sumw_inf;
} else if (sumw_near > 0.0) {
infinity_importance = 0.0;
k_near = (1.0 - infinity_importance)/sumw_near;
}
System.out.println("setupYW(): k_inf="+k_inf+" k_near="+k_near);
double sum2 = k_inf*sum2_inf+k_near*sum2_near;
for (int i = 0; i < is_inf.length; i++) {
if (is_inf[i]) {
w_vector[2 * i + 0] *= k_inf;
w_vector[2 * i + 1] *= k_inf;
} else {
w_vector[2 * i + 1] *= k_near;
}
}
return Math.sqrt(sum2); // RMS
}
public void recalcRXY() {
if (rXY != null) {
// rXY_aux = rXY; // FIXME: put real stuff !!!
......
......@@ -7589,6 +7589,8 @@ public class ImageDtt {
final double [][][][][][] clt_kernels_aux, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
final boolean keep_clt_data,
final int [][] woi_tops,
final double [][][] ers_delay, // if not null - fill with tile center acquisition delay
final int threadsMax, // maximal number of threads to launch
final int debugLevel)
{
......@@ -7717,8 +7719,12 @@ public class ImageDtt {
}
}
// final double [] corr_max_weights_poly =(((clt_parameters.max_corr_sigma > 0) && (disparity_bimap != null))?
// setMaxXYWeights(clt_parameters.max_corr_sigma,max_search_radius_poly): null); // here use square anyway
if (ers_delay != null) {
ers_delay[0] = new double [quad_main][];
for (int i = 0; i < quad_main; i++) ers_delay[0][i] = new double [tilesX*tilesY];
ers_delay[1] = new double [quad_aux][];
for (int i = 0; i < quad_aux; i++) ers_delay[1][i] = new double [tilesX*tilesY];
}
dtt.set_window(clt_parameters.clt_window);
final double [] lt_window = dtt.getWin2d(); // [256]
......@@ -7820,6 +7826,11 @@ public class ImageDtt {
centerX,
centerY,
disparity_aux); // + disparity_corr);
// acquisition time of the tiles centers in scanline times
if (ers_delay != null) {
for (int i = 0; i < quad_main; i++) ers_delay[0][i][nTile] = centersXY_main[i][1]-woi_tops[0][i];
for (int i = 0; i < quad_aux; i++) ers_delay[1][i][nTile] = centersXY_aux[i][1]- woi_tops[1][i];
}
if ((globalDebugLevel > 0) && (tileX == debug_tileX) && (tileY == debug_tileY)) {
for (int i = 0; i < quad_main; i++) {
......
......@@ -80,6 +80,7 @@ public class QuadCLT {
double [][][] image_data = null;
boolean [][] saturation_imp = null; // (near) saturated pixels or null
boolean is_aux = false;
int [] woi_tops; // used to calculate scanline timing
// magic scale should be set before using TileProcessor (calculated disparities depend on it)
......@@ -2671,6 +2672,7 @@ public class QuadCLT {
}
ImagePlus [] imp_srcs = new ImagePlus[channelFiles.length];
this.woi_tops = new int [channelFiles.length];
double [] scaleExposures = new double[channelFiles.length];
for (int srcChannel=0; srcChannel<channelFiles.length; srcChannel++){
int nFile=channelFiles[srcChannel];
......@@ -2705,6 +2707,7 @@ public class QuadCLT {
imp_srcs[srcChannel], // ImagePlus imp_src,
eyesisCorrections.pixelMapping.sensors[srcChannel].getSensorWH(),
true); // boolean replicate);
woi_tops[srcChannel] = Integer.parseInt((String) imp_srcs[srcChannel].getProperty("WOI_TOP"));
scaleExposures[srcChannel] = 1.0;
if (!Double.isNaN(referenceExposures[nFile]) && (imp_srcs[srcChannel].getProperty("EXPOSURE")!=null)){
scaleExposures[srcChannel] = referenceExposures[nFile]/Double.parseDouble((String) imp_srcs[srcChannel].getProperty("EXPOSURE"));
......@@ -3364,6 +3367,7 @@ public class QuadCLT {
int debugLevel)
{
ImagePlus [] imp_srcs = new ImagePlus[channelFiles.length];
this.woi_tops = new int [channelFiles.length];
// double [] scaleExposures = new double[channelFiles.length]; //
double [][] dbg_dpixels = new double [channelFiles.length][];
// int [] fullWindowWH = geometryCorrection.getSensorWH();
......@@ -3400,10 +3404,12 @@ public class QuadCLT {
}
// imp_srcs[srcChannel].show(); // REMOVE ME!
woi_tops[srcChannel] = Integer.parseInt((String) imp_srcs[srcChannel].getProperty("WOI_TOP"));
imp_srcs[srcChannel] = padBayerToFullSize(
imp_srcs[srcChannel], // ImagePlus imp_src,
eyesisCorrections.pixelMapping.sensors[srcChannel].getSensorWH(),
true); // boolean replicate);
scaleExposures[srcChannel] = 1.0;
if (!Double.isNaN(referenceExposures[nFile]) && (imp_srcs[srcChannel].getProperty("EXPOSURE")!=null)){
scaleExposures[srcChannel] = referenceExposures[nFile]/Double.parseDouble((String) imp_srcs[srcChannel].getProperty("EXPOSURE"));
......@@ -4863,6 +4869,7 @@ public class QuadCLT {
}
ImagePlus [] imp_srcs = new ImagePlus[channelFiles.length];
this.woi_tops = new int [channelFiles.length];
boolean [][] saturation_imp = (clt_parameters.sat_level > 0.0)? new boolean[channelFiles.length][] : null;
double [] scaleExposures = new double[channelFiles.length];
for (int srcChannel=0; srcChannel<channelFiles.length; srcChannel++){
......@@ -4898,6 +4905,7 @@ public class QuadCLT {
imp_srcs[srcChannel], // ImagePlus imp_src,
eyesisCorrections.pixelMapping.sensors[srcChannel].getSensorWH(),
true); // boolean replicate);
woi_tops[srcChannel] = Integer.parseInt((String) imp_srcs[srcChannel].getProperty("WOI_TOP"));
scaleExposures[srcChannel] = 1.0;
if (!Double.isNaN(referenceExposures[nFile]) && (imp_srcs[srcChannel].getProperty("EXPOSURE")!=null)){
scaleExposures[srcChannel] = referenceExposures[nFile]/Double.parseDouble((String) imp_srcs[srcChannel].getProperty("EXPOSURE"));
......@@ -6670,7 +6678,7 @@ public class QuadCLT {
}
double [][][] new_corr;
final double inf_max_disparity = 2.0;
// final double inf_max_disparity = 2.0;
double [][][] gt_disparity_strength = {rig_disp_strength};
new_corr = ac.lazyEyeCorrectionFromGT(
geometryCorrection_main, //final GeometryCorrection geometryCorrection_main, // if not null - this is an AUX camera of a rig
......@@ -6700,7 +6708,7 @@ public class QuadCLT {
clt_parameters.ih_min_samples, // 10, // final int hist_min_samples,
clt_parameters.ih_norm_center, // true, // final boolean hist_norm_center, // if there are more tiles that fit than min_samples, replace with
clt_parameters.ly_inf_frac, // 0.5, // final double inf_fraction, // fraction of the weight for the infinity tiles
inf_max_disparity, // final double inf_max_disparity, // use all smaller disparities as inf_fraction
clt_parameters.ly_inf_max_disparity, // inf_max_disparity, // final double inf_max_disparity, // use all smaller disparities as inf_fraction
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
scans14, // disp_strength, // scans, // double [][] disp_strength,
gt_disparity_strength, // double [][][] gt_disparity_strength, // 1 pair for each 14 entries of scans_14 (normally - just 1 scan
......@@ -8706,8 +8714,7 @@ public class QuadCLT {
}
ImagePlus [] imp_srcs = new ImagePlus[channelFiles.length];
/// boolean [][] saturation_imp = (clt_parameters.sat_level > 0.0)? new boolean[channelFiles.length][] : null;
/// double [] scaleExposures = new double[channelFiles.length]; //
this.woi_tops = new int [channelFiles.length];
double [][] dbg_dpixels = batch_mode? null : (new double [channelFiles.length][]);
for (int srcChannel=0; srcChannel<channelFiles.length; srcChannel++){
......@@ -8743,6 +8750,7 @@ public class QuadCLT {
imp_srcs[srcChannel], // ImagePlus imp_src,
eyesisCorrections.pixelMapping.sensors[srcChannel].getSensorWH(),
true); // boolean replicate);
woi_tops[srcChannel] = Integer.parseInt((String) imp_srcs[srcChannel].getProperty("WOI_TOP"));
scaleExposures[srcChannel] = 1.0;
if (!Double.isNaN(referenceExposures[nFile]) && (imp_srcs[srcChannel].getProperty("EXPOSURE")!=null)){
scaleExposures[srcChannel] = referenceExposures[nFile]/Double.parseDouble((String) imp_srcs[srcChannel].getProperty("EXPOSURE"));
......
......@@ -337,6 +337,7 @@ public class TwoQuadCLT {
final boolean updateStatus,
final int debugLevel){
final boolean batch_mode = clt_parameters.batch_run; //disable any debug images
final boolean get_ers = !batch_mode;
// boolean batch_mode = false;
boolean infinity_corr = false;
double [][] scaleExposures= {scaleExposures_main, scaleExposures_aux};
......@@ -405,6 +406,9 @@ public class TwoQuadCLT {
ImageDtt image_dtt = new ImageDtt();
double [][] ml_data = null;
int [][] woi_tops = {quadCLT_main.woi_tops,quadCLT_aux.woi_tops};
final double [][][] ers_delay = get_ers?(new double [2][][]):null;
final double [][][][][][][] clt_bidata = // new double[2][quad][nChn][tilesY][tilesX][][]; // first index - main/aux
image_dtt.clt_bi_quad (
......@@ -435,10 +439,15 @@ public class TwoQuadCLT {
quadCLT_aux.getCLTKernels(), // final double [][][][][][] clt_kernels_aux, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
clt_parameters.corr_magic_scale, // final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
true, // final boolean keep_clt_data,
woi_tops, // final int [][] woi_tops,
ers_delay, // final double [][][] ers_delay, // if not null - fill with tile center acquisition delay
threadsMax, // final int threadsMax, // maximal number of threads to launch
debugLevel); // final int globalDebugLevel);
if (ers_delay !=null) {
showERSDelay(ers_delay);
}
double [][] texture_nonoverlap_main = null;
double [][] texture_nonoverlap_aux = null;
......@@ -793,6 +802,34 @@ public class TwoQuadCLT {
return results;
}
public void showERSDelay(double [][][] ers_delay)
{
int tilesX = quadCLT_main.tp.getTilesX();
int tilesY = quadCLT_main.tp.getTilesY();
int nTiles = tilesX * tilesY;
int nchn_main = ers_delay[0].length;
int nchn_aux = ers_delay[1].length;
double [][] dbg_img = new double[nchn_main + nchn_aux][tilesX*tilesY];
for (int nTile = 0; nTile< nTiles; nTile++) {
double avg_dly = 0;
for (int i = 0; i < nchn_main; i++) {
avg_dly += ers_delay[0][i][nTile];
}
avg_dly /= nchn_main;
for (int i = 0; i < nchn_main; i++) {
dbg_img[i][nTile] = ers_delay[0][i][nTile] - avg_dly;
}
for (int i = 0; i < nchn_aux; i++) {
dbg_img[i + nchn_main][nTile] = ers_delay[1][i][nTile] - avg_dly;
}
}
(new showDoubleFloatArrays()).showArrays(
dbg_img,
tilesX,
tilesY,
true,
"ERS_DELAYS");
}
......@@ -1049,7 +1086,6 @@ public class TwoQuadCLT {
return true;
}
public boolean processInfinityRig(
QuadCLT quadCLT_main,
QuadCLT quadCLT_aux,
......@@ -1087,6 +1123,23 @@ FIXME - make it work
debugLevel); // final int debugLevel);
if (debugLevel > -100) return true; // temporarily !
*/
double disparity_correction_main = 0.0; // actual disparity in main camera pixels for "infinity" objects
if (clt_parameters.infinity_distace_map.containsKey(quadCLT_main.image_name)){
double infinity_distance = clt_parameters.infinity_distace_map.get(quadCLT_main.image_name);
disparity_correction_main = quadCLT_main.geometryCorrection.getDisparityFromZ(infinity_distance);
if (debugLevel > -5) {
System.out.println("Found infinity distance record for "+quadCLT_main.image_name+", it is "+infinity_distance+
" m, corresponding to "+disparity_correction_main+" pixels of the main camera.");
}
} else {
if (debugLevel > -5) {
System.out.println("No infinity distance record for "+quadCLT_main.image_name+" found, considering far objects to be true infinity");
}
}
if (debugLevel > -5) {
System.out.println("disparity_correction_main= "+disparity_correction_main);
}
final int tilesX = quadCLT_main.tp.getTilesX();
// perform full re-measure cycles
......@@ -1101,9 +1154,9 @@ if (debugLevel > -100) return true; // temporarily !
ArrayList<Integer> tile_list = new ArrayList<Integer>();
// measure and refine
for (int disp_step = 0; disp_step < clt_parameters.rig.rig_num_disp_steps; disp_step++) {
double disparity = 0.0;
if (clt_parameters.rig.rig_num_disp_steps > 1) {
disparity = disp_step * clt_parameters.rig.rig_disp_range/(clt_parameters.rig.rig_num_disp_steps -1);
double disparity = disparity_correction_main;
if (disp_step > 0) {
disparity += disp_step * clt_parameters.rig.rig_disp_range/(clt_parameters.rig.rig_num_disp_steps -1);
}
disparity_bimap = measureNewRigDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
......@@ -1121,7 +1174,7 @@ if (debugLevel > -100) return true; // temporarily !
debugLevel); // final int debugLevel);
if (disparity_bimap != null){
if (clt_parameters.show_map && (debugLevel > 2) && clt_parameters.rig.rig_mode_debug){
if (clt_parameters.show_map && (debugLevel > -2) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
......@@ -1131,7 +1184,7 @@ if (debugLevel > -100) return true; // temporarily !
ImageDtt.BIDISPARITY_TITLES);
}
}
if (disparity > 0.0) { // refine non-infinity passes
if (disp_step > 0) { // refine non-infinity passes
// first - refine once for the main camera
double [][] prev_bimap = null;
double [] scale_bad = null;
......@@ -1144,6 +1197,7 @@ if (debugLevel > -100) return true; // temporarily !
null, // scale_bad, // double [] scale_bad,
2, //0, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
true, // boolean keep_inf, // keep expected disparity 0.0 if it was so
disparity_correction_main, // double inf_disparity,
clt_parameters.rig.refine_min_strength , // double refine_min_strength, // do not refine weaker tiles
clt_parameters.rig.refine_tolerance , // double refine_tolerance, // do not refine if absolute disparity below
null, // tile_list, // ArrayList<Integer> tile_list, // or null
......@@ -1182,6 +1236,7 @@ if (debugLevel > -100) return true; // temporarily !
scale_bad, // double [] scale_bad,
2, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
true, // boolean keep_inf, // keep expected disparity 0.0 if it was so
disparity_correction_main, // double inf_disparity,
clt_parameters.rig.refine_min_strength , // double refine_min_strength, // do not refine weaker tiles
clt_parameters.rig.refine_tolerance , // double refine_tolerance, // do not refine if absolute disparity below
null, // tile_list, // ArrayList<Integer> tile_list, // or null
......@@ -1215,6 +1270,7 @@ if (debugLevel > -100) return true; // temporarily !
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
true, // boolean select_infinity,
true, // boolean select_noninfinity,
disparity_correction_main, // double inf_disparity,
disparity_bimap, // double[][] disparity_bimap,
tilesX); // int tilesX,
if (debugLevel > -1) showListedRigTiles(
......@@ -1227,7 +1283,7 @@ if (debugLevel > -100) return true; // temporarily !
// short cycle (remeasure only for the list). May also break from it if RMS is not improving
for (int num_short_cycle = 0; num_short_cycle < clt_parameters.rig.rig_adjust_short_cycles;num_short_cycle++) {
// refine for the existing list - all listed tiles, no thersholds
// refine for the existing list - all listed tiles, no thresholds
disparity_bimap = refineRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
......@@ -1237,6 +1293,7 @@ if (debugLevel > -100) return true; // temporarily !
2, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
// will still re-measure infinity if refine_min_strength == 0.0
true, // boolean keep_inf, // keep expected disparity 0.0 if it was so
disparity_correction_main, // double inf_disparity,
0.0, // double refine_min_strength, // do not refine weaker tiles
0.0, // double refine_tolerance, // do not refine if absolute disparity below
tile_list, // ArrayList<Integer> tile_list, // or null
......@@ -1268,6 +1325,7 @@ if (debugLevel > -100) return true; // temporarily !
clt_parameters.rig.rig_adjust_distance, // boolean adjust_distance,
clt_parameters.rig.rig_adjust_forward, // boolean adjust_forward, // not used
clt_parameters.rig.rig_correction_scale, // double scale_correction,
disparity_correction_main, // double infinity_disparity,
tile_list, // ArrayList<Integer> tile_list,
quadCLT_main, // QuadCLT qc_main,
disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX], // double [] strength,
......@@ -1298,6 +1356,7 @@ if (debugLevel > -100) return true; // temporarily !
}
public boolean processPoles(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
......@@ -1389,8 +1448,6 @@ if (debugLevel > -100) return true; // temporarily !
final boolean updateStatus,
final int debugLevel)// throws Exception
{
// boolean combine_oldsel_far = clt_parameters.rig.rf_master_infinity; // = true;
// boolean combine_oldsel_near = clt_parameters.rig.rf_master_near; // = false; //
if ((quadCLT_main.tp == null) || (quadCLT_main.tp.clt_3d_passes == null)) {
String msg = "DSI data not available. Please run\"CLT 3D\" first";
IJ.showMessage("ERROR",msg);
......@@ -1479,11 +1536,6 @@ if (debugLevel > -100) return true; // temporarily !
}
if (dbg_sel!=null) dbg_sel[4] = selection.clone(); // far+near+old
// if ((combine_oldsel_far || combine_oldsel_near) && (was_select != null) ) {
// for (int nTile=0; nTile < selection.length; nTile++) {
// selection[nTile] |= was_select[nTile] && (infinity_select[nTile]? combine_oldsel_far : combine_oldsel_near) ;
// }
// }
boolean [] selection_lone = biCamDSI.selectLoneFar(
clt_parameters.rig.ltfar_trusted_s, // double min_far_strength,
clt_parameters.rig.ltfar_trusted_d, // double min_far_disparity,
......@@ -1584,7 +1636,6 @@ if (debugLevel > -100) return true; // temporarily !
// CLT ASSIGN needs best texture for each tile. Initially will just copy from the previous master
// composite scan, later - fill disparity gaps and re-measure
/*
* TODO: interpolate disparities before measuring to fill gaps?
public double [][][][][] getRigTextures(
......@@ -1670,6 +1721,96 @@ if (debugLevel > -100) return true; // temporarily !
}
}
// Add areas from the main camera that correspond do occlusions of the aux (and so missing rig data). No real analysis of the occlusions here,
// just filling gaps where rig data is 0.0 strengtth
if (clt_parameters.rig.oc_fill_aux_occl) {
if (debugLevel > -4) {
System.out.println("Trying to fill rig gaps with main camera data (assuming aux cam occlusions)");
}
//scan_last
double [][] main_last_scan = quadCLT_main.tp.getShowDS(scan_last,
false); // boolean force_final);
double disp_scale_inter = quadCLT_main.geometryCorrection.getDisparityRadius()/quadCLT_aux.geometryCorrection.getBaseline(); // 4.8
// TODO: Move to parameters
double disp_atol = 0.2;
double disp_rtol = 0.1;
double strength_boost = 1.5;
// boolean
boolean [] sel_occl = selectAuxOcclusions(
main_last_scan, // double [][] ds_main,
f_rig_disparity_strength, // double [][] ds_rig,
disp_scale_inter, // double disp_rig_scale,
clt_parameters.rig.oc_min_strength, // double min_strength,
clt_parameters.grow_disp_max, // double max_disparity,
disp_atol, // double disp_atol,
disp_rtol, // double disp_rtol,
clt_parameters.transform_size, // int tileSize, // 8
1); // int debugLevel);
if (sel_occl != null) {
if (debugLevel > -4) {
double [][] dbg_img = new double [5][];
String [] titles = {"disp_main","disp_rig","disp_occl","str_main","str_rig"};
dbg_img[0] = main_last_scan[0];
dbg_img[1] = f_rig_disparity_strength[0];
dbg_img[2] = main_last_scan[0].clone();
dbg_img[3] = main_last_scan[1];
dbg_img[4] = f_rig_disparity_strength[1];
for (int nTile = 0; nTile < sel_occl.length; nTile++) {
if (!sel_occl[nTile]) {
dbg_img[2][nTile] = Double.NaN;
}
}
(new showDoubleFloatArrays()).showArrays(
dbg_img,
tilesX,
dbg_img[0].length/tilesX,
true,
quadCLT_main.image_name+"Aux_occlusions",
titles);
}
int num_replaced_occl = 0;
for (int nTile = 0; nTile < f_rig_disparity_strength[1].length; nTile++) { // only missing tiles
// if (nTile== 50582) {
// System.out.println("Replacing occlusions, nTile="+nTile);
// }
if (sel_occl[nTile]) {
f_rig_disparity_strength[0][nTile] = main_last_scan[0][nTile];
f_rig_disparity_strength[1][nTile] = strength_boost* main_last_scan[1][nTile];
selection[nTile] = true;
num_replaced_occl ++;
}
}
if (debugLevel > -4) {
System.out.println("Replaced "+num_replaced_occl+" empty tiles in rig DSI with main camera data");
}
} else {
if (debugLevel > -4) {
System.out.println("No occluded tiles replaced");
}
}
/*
int num_replaced_occl = 0;
for (int nTile = 0; nTile < f_rig_disparity_strength[1].length; nTile++) { // only missing tiles
if (nTile== 50582) {
System.out.println("Replacing occlusions, nTile="+nTile);
}
if (f_rig_disparity_strength[1][nTile] <= 0.0) { // only missing tiles
if ( (main_last_scan[0][nTile] >= clt_parameters.rig.oc_min_disparity) && // only near objects
(main_last_scan[1][nTile] >= clt_parameters.rig.oc_min_strength)) { // only strong tiles
f_rig_disparity_strength[0][nTile] = main_last_scan[0][nTile];
f_rig_disparity_strength[1][nTile] = main_last_scan[1][nTile];
selection[nTile] = true;
num_replaced_occl ++;
}
}
}
*/
}
CLTPass3d rig_scan = quadCLT_main.tp.compositeScan(
f_rig_disparity_strength[0], // final double [] disparity,
f_rig_disparity_strength[1], // final double [] strength,
......@@ -1681,6 +1822,7 @@ 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(
......@@ -1699,6 +1841,77 @@ if (debugLevel > -100) return true; // temporarily !
debugLevel); // final int debugLevel)
}
}
*/
}
public boolean [] selectAuxOcclusions(
double [][] ds_main,
double [][] ds_rig,
double disp_rig_scale,
double min_strength,
double max_disparity,
double disp_atol,
double disp_rtol,
int tileSize, // 8
int debugLevel)
{
TileNeibs tnImage = biCamDSI_persistent.tnImage;
int tilesX= tnImage.getSizeX();
int tilesY= tnImage.getSizeY();
int numTiles = tilesY*tilesX;
boolean [] occl_sel = new boolean [numTiles];
int num_replaced_occl = 0;
for (int nTile = 0; nTile < numTiles; nTile++) { // only missing tiles
if (nTile== 47120) {
System.out.println("Replacing occlusions, nTile="+nTile);
}
if ((ds_rig[1][nTile] <= 0.0) && (ds_main[1][nTile] >= min_strength)) { // only missing tiles
// See if aux camera may be potentially occluded for this tile
int tileX = nTile % tilesX;
int tileY = nTile / tilesX;
double disp = ds_main[0][nTile];
for (int tx = tileX+1; tx < tilesX; tx++) {
disp += tileSize*disp_rig_scale; // disparity of the next tile right (here we assume aux is to the right of the main!)
if (disp > max_disparity) {
break;
}
int nTile1 = tnImage.getIndex(tx, tileY);
if (nTile1>= 0) {
double mn = (ds_rig[1][nTile1] > 0.0) ? ds_rig[0][nTile1]: Double.NaN;
double mx = mn;
for (int dir = 0; dir < 8; dir++) {
int nTile2 = tnImage.getNeibIndex(nTile1, dir);
if (nTile2 >= 0) if ((ds_rig[1][nTile2] > 0.0) && !Double.isNaN(ds_rig[0][nTile2])){
if (!(ds_rig[0][nTile2] > mn)) mn = ds_rig[0][nTile2]; // mn==NaN - assign
if (!(ds_rig[0][nTile2] < mx)) mx = ds_rig[0][nTile2]; // mn==NaN - assign
}
}
if (!Double.isNaN(mn)) {
double disp_avg = 0.5*(mn+mx);
double disp_tol = disp_atol + disp_avg*disp_rtol;
if (mx < (disp_avg + disp_tol)) mx = disp_avg + disp_tol;
if (mn < (disp_avg - disp_tol)) mn = disp_avg - disp_tol;
if ((disp >= mn) && (disp <=mx)) { // that may be occlusion
occl_sel[nTile] = true;
num_replaced_occl ++;
if (debugLevel > 0) {
System.out.println("Tile ("+tileX+", "+tileY+") may have an occlusion for aux camera by ("+
(nTile1 % tilesX)+", "+(nTile1 / tilesX)+")");
}
break; // for (int nTile = 0; nTile < numTiles; nTile++)
}
}
}
}
}
}
if (debugLevel > 0) {
System.out.println("Found "+num_replaced_occl+" potential aux camera occluded tiles");
}
if (num_replaced_occl == 0) {
occl_sel = null; // not caller to bother
}
return occl_sel;
}
public double [][][][][] getRigTextures(
......@@ -1733,6 +1946,7 @@ if (debugLevel > -100) return true; // temporarily !
}
}
ImageDtt image_dtt = new ImageDtt();
int [][] woi_tops = {quadCLT_main.woi_tops,quadCLT_aux.woi_tops};
image_dtt.clt_bi_quad (
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_parameters.fat_zero, // final double fatzero, // May use correlation fat zero from 2 different parameters - fat_zero and rig.ml_fatzero
......@@ -1760,6 +1974,8 @@ if (debugLevel > -100) return true; // temporarily !
quadCLT_aux.getCLTKernels(), // final double [][][][][][] clt_kernels_aux, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
clt_parameters.corr_magic_scale, // final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
false, // true, // final boolean keep_clt_data,
woi_tops, // final int [][] woi_tops,
null, // final double [][][] ers_delay, // if not null - fill with tile center acquisition delay
threadsMax, // final int threadsMax, // maximal number of threads to launch
debugLevel-2); // final int globalDebugLevel);
......@@ -1937,6 +2153,8 @@ if (debugLevel > -100) return true; // temporarily !
ml_data, // double [][] ml_data,
clt_parameters.rig.ml_show_ml, // boolean show,
debugLevel); // int debugLevel
Runtime.getRuntime().gc();
System.out.println("Generated ML data, offset = "+disparity_offset+", --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
}
}
......@@ -2026,6 +2244,7 @@ if (debugLevel > -100) return true; // temporarily !
scale_bad, // double [] scale_bad,
refine_inter, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
false, // boolean keep_inf, // keep expected disparity 0.0 if it was so
0.0, // double inf_disparity,
0.0, // clt_parameters.rig.refine_min_strength , // double refine_min_strength, // do not refine weaker tiles
refine_tolerance , // double refine_tolerance, // do not refine if absolute disparity below
trusted_infinity, // tile_list, // ArrayList<Integer> tile_list, // or null
......@@ -2139,6 +2358,7 @@ if (debugLevel > -100) return true; // temporarily !
scale_bad, // double [] scale_bad,
refine_inter, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
false, // boolean keep_inf, // keep expected disparity 0.0 if it was so
0.0, // double inf_disparity,
0.0, // clt_parameters.rig.refine_min_strength , // double refine_min_strength, // do not refine weaker tiles
clt_parameters.rig.refine_tolerance , // double refine_tolerance, // do not refine if absolute disparity below
trusted_near, // tile_list, // ArrayList<Integer> tile_list, // or null
......@@ -2278,6 +2498,7 @@ if (debugLevel > -100) return true; // temporarily !
scale_bad, // double [] scale_bad,
refine_inter, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
false, // boolean keep_inf, // keep expected disparity 0.0 if it was so
0.0, // double inf_disparity,
0.0, // clt_parameters.rig.refine_min_strength , // double refine_min_strength, // do not refine weaker tiles
clt_parameters.rig.refine_tolerance , // double refine_tolerance, // do not refine if absolute disparity below
trusted_near, // tile_list, // ArrayList<Integer> tile_list, // or null
......@@ -2773,6 +2994,7 @@ if (debugLevel > -100) return true; // temporarily !
scale_bad, // double [] scale_bad,
refine_inter, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
false, // boolean keep_inf, // keep expected disparity 0.0 if it was so
0.0, // double inf_disparity,
0.0, // clt_parameters.rig.refine_min_strength , // double refine_min_strength, // do not refine weaker tiles
clt_parameters.rig.refine_tolerance , // double refine_tolerance, // do not refine if absolute disparity below
trusted_measurements, // tile_list, // ArrayList<Integer> tile_list, // or null
......@@ -4009,6 +4231,7 @@ if (debugLevel > -100) return true; // temporarily !
disparity_array, // double [][] disparity_array,
2, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
false, // boolean keep_inf, // keep expected disparity 0.0 if it was so
0.0, // double inf_disparity,
0.0, // double refine_min_strength, // do not refine weaker tiles
0.0, // double refine_tolerance, // do not refine if absolute disparity below
disp_scale_main, // double disp_scale_main, // 1.0
......@@ -4191,6 +4414,7 @@ if (debugLevel > -100) return true; // temporarily !
scale_bad, // double [] scale_bad,
refine_inter, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
false, // boolean keep_inf, // keep expected disparity 0.0 if it was so
0.0, // double inf_disparity,
0.0, // clt_parameters.rig.refine_min_strength , // double refine_min_strength, // do not refine weaker tiles
clt_parameters.rig.refine_tolerance , // double refine_tolerance, // do not refine if absolute disparity below
trusted_lt, // null, // trusted_lt, // tile_list, // ArrayList<Integer> tile_list, // or null
......@@ -4715,6 +4939,7 @@ if (debugLevel > -100) return true; // temporarily !
* @param prev_bimap results of the even older measurements to interpolate if there was an overshoot
* @param refine_mode reference camera data: 0 - main camera, 1 - aux camera, 2 - cross-camera
* @param keep_inf do not refine expected disparity for infinity, unless refine_min_strength == 0
* @param inf_sel if not null - selects "infinity" tiles that shoild not be remeasured
* @param refine_min_strength do not refine weaker tiles
* @param refine_tolerance do not refine if residual disparity (after FD pre-shift by expected disparity) less than this
* @param tile_list list of selected tiles or null. If null - try to refine all tiles, otherwise - only listed tiles
......@@ -4725,6 +4950,7 @@ if (debugLevel > -100) return true; // temporarily !
* @param debugLevel debug level
* @return results of the new measurements combined with the old results
*/
public double [][] refineRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
......@@ -4733,6 +4959,7 @@ if (debugLevel > -100) return true; // temporarily !
double [] scale_bad,
int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
boolean keep_inf, // keep expected disparity 0.0 if it was so
double inf_disparity,
double refine_min_strength, // do not refine weaker tiles
double refine_tolerance, // do not refine if absolute disparity below
ArrayList<Integer> tile_list, // or null
......@@ -4757,6 +4984,7 @@ if (debugLevel > -100) return true; // temporarily !
scale_bad, //
refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
keep_inf, // keep expected disparity 0.0 if it was so
inf_disparity, // double inf_disparity,
refine_min_strength, // do not refine weaker tiles
refine_tolerance, // do not refine if absolute disparity below
selection,
......@@ -4778,6 +5006,7 @@ if (debugLevel > -100) return true; // temporarily !
double [] scale_bad,
int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
boolean keep_inf, // keep expected disparity 0.0 if it was so
double inf_disparity,
double refine_min_strength, // do not refine weaker tiles
double refine_tolerance, // do not refine if absolute disparity below
boolean [] selection,
......@@ -4813,6 +5042,7 @@ if (debugLevel > -100) return true; // temporarily !
disparity_array, // double [][] disparity_array,
refine_mode, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
keep_inf, // boolean keep_inf, // keep expected disparity 0.0 if it was so
inf_disparity, // double inf_disparity,
refine_min_strength, // double refine_min_strength, // do not refine weaker tiles
refine_tolerance, // double refine_tolerance, // do not refine if absolute disparity below
disp_scale_main, // double disp_scale_main, // 1.0
......@@ -4862,6 +5092,160 @@ if (debugLevel > -100) return true; // temporarily !
return disparity_bimap;
}
public double [][] refineRig_new(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][] src_bimap, // current state of measurements
double [][] prev_bimap, // previous state of measurements or null
double [] scale_bad,
int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
boolean keep_inf, // keep expected disparity 0.0 if it was so
boolean [] inf_sel, // infinity selection
double refine_min_strength, // do not refine weaker tiles
double refine_tolerance, // do not refine if absolute disparity below
ArrayList<Integer> tile_list, // or null
int [] num_new,
EyesisCorrectionParameters.CLTParameters clt_parameters,
boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
final boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
boolean [] selection = null;
if (tile_list != null) {
selection = new boolean [quadCLT_main.tp.getTilesX() * quadCLT_main.tp.getTilesY()];
if (inf_sel == null) {
for (int nTile:tile_list) selection[nTile] = true;
} else {
for (int nTile:tile_list) selection[nTile] = !inf_sel[nTile];
}
} else if (inf_sel != null) {
selection = new boolean [quadCLT_main.tp.getTilesX() * quadCLT_main.tp.getTilesY()];
for (int nTile = 0; nTile < selection.length; nTile++) {
selection[nTile] = !inf_sel[nTile];
}
}
return refineRigSel_new(
quadCLT_main, // tiles should be set
quadCLT_aux,
src_bimap, // current state of measurements
prev_bimap, // previous state of measurements or null
scale_bad, //
refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
keep_inf, // keep expected disparity 0.0 if it was so
refine_min_strength, // do not refine weaker tiles
refine_tolerance, // do not refine if absolute disparity below
selection,
num_new,
clt_parameters,
notch_mode, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
lt_rad, // final int // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
no_int_x0, // boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
}
public double [][] refineRigSel_new(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][] src_bimap, // current state of measurements
double [][] prev_bimap, // previous state of measurements or null
double [] scale_bad,
int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
boolean keep_inf, // keep expected disparity 0.0 if it was so
double refine_min_strength, // do not refine weaker tiles
double refine_tolerance, // do not refine if absolute disparity below
boolean [] selection,
int [] num_new,
EyesisCorrectionParameters.CLTParameters clt_parameters,
final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
final int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
final boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
int tilesX =quadCLT_main.tp.getTilesX();
int tilesY =quadCLT_main.tp.getTilesY();
int [][] tile_op = new int [tilesY][tilesX];
double [][] disparity_array = new double [tilesY][tilesX];
double disp_scale_main = 1.0/clt_parameters.corr_magic_scale; // Is it needed?
double disp_scale_aux = disp_scale_main * quadCLT_main.geometryCorrection.getDisparityRadius()/quadCLT_aux.geometryCorrection.getDisparityRadius();
double disp_scale_inter = disp_scale_main * quadCLT_main.geometryCorrection.getDisparityRadius()/quadCLT_aux.geometryCorrection.getBaseline();
int tile_op_all = clt_parameters.tile_task_op; //FIXME Use some constant?
int numMeas = 0;
for (int tileY = 0; tileY<tilesY;tileY++) {
for (int tileX = 0; tileX<tilesX;tileX++) {
int nTile = tileY * tilesX + tileX;
if (((selection == null) || selection[nTile]) && !Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
if (prepRefineTile(
(lt_rad > 0),
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
tile_op_all, // int tile_op_all,
src_bimap, // double [][] src_bimap, // current state of measurements
prev_bimap, // double [][] prev_bimap, // previous state of measurements or null
scale_bad, // double [] scale_bad,
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
refine_mode, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
keep_inf, // boolean keep_inf, // keep expected disparity 0.0 if it was so
0.0, // double inf_disparity,
refine_min_strength, // double refine_min_strength, // do not refine weaker tiles
refine_tolerance, // double refine_tolerance, // do not refine if absolute disparity below
disp_scale_main, // double disp_scale_main, // 1.0
disp_scale_aux, //double disp_scale_aux, // ~0.58
disp_scale_inter, //double disp_scale_inter, // ~4.86
// scale_step, // double scale_step, // scale for "unstable tiles"
tileX, // int tileX,
tileY, // int tileY,
nTile )) numMeas++; //int nTile
}
}
}
if (debugLevel >0) {
System.out.println("refineRigSel() mode="+refine_mode+": Prepared "+numMeas+" to measure");
}
double [][] disparity_bimap = measureRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
null, // double [][] ml_data, // data for ML - 10 layers - 4 center areas (3x3, 5x5,..) per camera-per direction, 1 - composite, and 1 with just 1 data (target disparity)
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_parameters.fat_zero, // double fatzero,
notch_mode, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
lt_rad, // final int // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
no_int_x0, // final boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
// combine with old results for tiles that were not re-measured
for (int tileY = 0; tileY<tilesY;tileY++) {
for (int tileX = 0; tileX<tilesX;tileX++) {
int nTile = tileY * tilesX + tileX;
// FIXME: see if the parameter is needed
// if ((selection == null) || selection[nTile]) {
if (Double.isNaN(disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile]) && !Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
if (nTile == 35509) {
System.out.println("refineRigSel(): nTile="+nTile);
}
for (int i = 0; i < disparity_bimap.length; i++) {
disparity_bimap[i][nTile] = src_bimap[i][nTile];
}
}
// }
}
}
if (num_new != null) {
num_new[0] = numMeas;
}
return disparity_bimap;
}
/**
* Add measurements with new specified disparity of the main camera
* @param quadCLT_main main camera QuadCLT instance (should have tp initialized)
......@@ -4869,8 +5253,6 @@ if (debugLevel > -100) return true; // temporarily !
* @param src_bimap results of the older measurements (now includes expected disparity) or null (no old results available)
* @param disparity new expected disparity value to try
* @param tile_list list of selected tiles or null. If not null, will not re-measure listed tiles
* @param saturation_main saturated pixels bitmaps for the main camera
* @param saturation_aux saturated pixels bitmaps for the auxiliary camera
* @param clt_parameters various configuration parameters
* @param threadsMax maximal number of threads to use
* @param updateStatus update IJ status bar
......@@ -4935,6 +5317,9 @@ if (debugLevel > -100) return true; // temporarily !
for (int tileY = 0; tileY<tilesY;tileY++) {
for (int tileX = 0; tileX<tilesX;tileX++) {
int nTile = tileY * tilesX + tileX;
if (nTile == 35509) {
System.out.println("measureNewRigDisparity(): nTile="+nTile);
}
boolean use_old = false;
// if (Double.isNaN(disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile]) && !Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
if (Double.isNaN(disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
......@@ -5017,8 +5402,6 @@ if (debugLevel > -100) return true; // temporarily !
}
private boolean prepRefineTile(
boolean remeasure_nan, // use old suggestion if result of the measurement was NaN
EyesisCorrectionParameters.CLTParameters clt_parameters,
......@@ -5030,6 +5413,7 @@ if (debugLevel > -100) return true; // temporarily !
double [][] disparity_array,
int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter, 3 - inter-dx
boolean keep_inf, // keep expected disparity 0.0 if it was so
double inf_disparity,
double refine_min_strength, // do not refine weaker tiles
double refine_tolerance, // do not refine if absolute disparity below
double disp_scale_main, // 1.0
......@@ -5044,10 +5428,10 @@ if (debugLevel > -100) return true; // temporarily !
// check if it was measured (skip NAN)
if (Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) return false;
// check if it is infinity and change is prohibited
if (keep_inf && (src_bimap[ImageDtt.BI_TARGET_INDEX][nTile] == 0.0)) {
if (keep_inf && (src_bimap[ImageDtt.BI_TARGET_INDEX][nTile] == inf_disparity)) {
if ((refine_min_strength == 0.0) || (refine_tolerance == 0.0)) {
tile_op[tileY][tileX] = tile_op_all;
disparity_array[tileY][tileX] = 0.0;
disparity_array[tileY][tileX] = inf_disparity;
return true;
}
return false;
......@@ -5135,7 +5519,6 @@ if (debugLevel > -100) return true; // temporarily !
return true;
}
double [][] measureRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
......@@ -5154,6 +5537,7 @@ if (debugLevel > -100) return true; // temporarily !
double [][] disparity_bimap = new double [ImageDtt.BIDISPARITY_TITLES.length][]; //[0] -residual disparity, [1] - orthogonal (just for debugging) last 4 - max pixel differences
int [][] woi_tops = {quadCLT_main.woi_tops,quadCLT_aux.woi_tops};
image_dtt.clt_bi_quad (
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
fatzero, // final double fatzero, // May use correlation fat zero from 2 different parameters - fat_zero and rig.ml_fatzero
......@@ -5180,6 +5564,8 @@ if (debugLevel > -100) return true; // temporarily !
quadCLT_aux.getCLTKernels(), // final double [][][][][][] clt_kernels_aux, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
clt_parameters.corr_magic_scale, // final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
false, // true, // final boolean keep_clt_data,
woi_tops, // final int [][] woi_tops,
null, // final double [][][] ers_delay, // if not null - fill with tile center acquisition delay
threadsMax, // final int threadsMax, // maximal number of threads to launch
debugLevel-2); // final int globalDebugLevel);
return disparity_bimap;
......@@ -5273,11 +5659,11 @@ if (debugLevel > -100) return true; // temporarily !
return ml_data;
}
ArrayList<Integer> selectRigTiles(
EyesisCorrectionParameters.CLTParameters clt_parameters,
boolean select_infinity,
boolean select_noninfinity,
double inf_disparity,
double[][] disparity_bimap,
int tilesX)
{
......@@ -5285,7 +5671,7 @@ if (debugLevel > -100) return true; // temporarily !
int numTiles = disparity_bimap[ImageDtt.BI_STR_FULL_INDEX].length;
if (select_infinity) {
for (int nTile = 0; nTile < numTiles; nTile++) {
if ( (disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile] == 0.0 ) && // expected disparity was 0.0 (infinity)
if ( (disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile] == inf_disparity) && // expected disparity was 0.0 (infinity)
(disparity_bimap[ImageDtt.BI_STR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_main) &&
(disparity_bimap[ImageDtt.BI_ASTR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_aux) &&
(disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_rig) &&
......@@ -5303,7 +5689,58 @@ if (debugLevel > -100) return true; // temporarily !
}
if (select_noninfinity) {
for (int nTile = 0; nTile < numTiles; nTile++) {
if ( (disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile] > 0.0 ) && // expected disparity was > 0.0 (not infinity)
if ( (disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile] > inf_disparity ) && // expected disparity was > 0.0 (not infinity)
(disparity_bimap[ImageDtt.BI_STR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_main)&&
(disparity_bimap[ImageDtt.BI_ASTR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_aux)&&
(disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_rig)&&
(Math.abs(disparity_bimap[ImageDtt.BI_DISP_FULL_INDEX][nTile]) <= clt_parameters.rig.near_max_disp_main)&&
(Math.abs(disparity_bimap[ImageDtt.BI_ADISP_FULL_INDEX][nTile]) <= clt_parameters.rig.near_max_disp_aux)&&
(Math.abs(disparity_bimap[ImageDtt.BI_DISP_CROSS_INDEX][nTile]) <= clt_parameters.rig.near_max_disp_rig)) {
tilesList.add(nTile);
}
}
}
return tilesList;
}
ArrayList<Integer> selectRigTiles_new(
EyesisCorrectionParameters.CLTParameters clt_parameters,
boolean ignore_target, // to select non-zero "infinity"
boolean [] disabled,
boolean select_infinity,
boolean select_noninfinity,
double[][] disparity_bimap,
int tilesX)
{
ArrayList<Integer> tilesList = new ArrayList<Integer>();
int numTiles = disparity_bimap[ImageDtt.BI_STR_FULL_INDEX].length;
if (select_infinity) {
for (int nTile = 0; nTile < numTiles; nTile++) {
if ( ((disabled == null) || !disabled[nTile]) &&
!Double.isNaN(disparity_bimap[ImageDtt.BI_DISP_CROSS_DX_INDEX][nTile]) &&
!Double.isNaN(disparity_bimap[ImageDtt.BI_DISP_CROSS_DY_INDEX][nTile]) &&
((disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile] == 0.0 ) || ignore_target)&& // expected disparity was 0.0 (infinity)
(disparity_bimap[ImageDtt.BI_STR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_main) &&
(disparity_bimap[ImageDtt.BI_ASTR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_aux) &&
(disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_rig) &&
(disparity_bimap[ImageDtt.BI_DISP_FULL_INDEX][nTile] <= clt_parameters.rig.inf_max_disp_main) &&
(disparity_bimap[ImageDtt.BI_ADISP_FULL_INDEX][nTile] <= clt_parameters.rig.inf_max_disp_aux) &&
(disparity_bimap[ImageDtt.BI_DISP_CROSS_INDEX][nTile] <= clt_parameters.rig.inf_max_disp_rig) &&
(disparity_bimap[ImageDtt.BI_DISP_FULL_INDEX][nTile] >= -clt_parameters.rig.inf_max_disp_main) &&
(disparity_bimap[ImageDtt.BI_ADISP_FULL_INDEX][nTile] >= -clt_parameters.rig.inf_max_disp_aux) &&
(disparity_bimap[ImageDtt.BI_DISP_CROSS_INDEX][nTile] >= -clt_parameters.rig.inf_max_disp_rig * clt_parameters.rig.inf_neg_tolerance)) {
tilesList.add(nTile);
}
}
}
if (select_noninfinity) {
for (int nTile = 0; nTile < numTiles; nTile++) {
if ( ((disabled == null) || !disabled[nTile]) &&
!Double.isNaN(disparity_bimap[ImageDtt.BI_DISP_CROSS_DX_INDEX][nTile]) &&
!Double.isNaN(disparity_bimap[ImageDtt.BI_DISP_CROSS_DY_INDEX][nTile]) &&
(disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile] > 0.0 ) && // expected disparity was > 0.0 (not infinity)
(disparity_bimap[ImageDtt.BI_STR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_main)&&
(disparity_bimap[ImageDtt.BI_ASTR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_aux)&&
(disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_rig)&&
......@@ -5772,6 +6209,24 @@ if (debugLevel > -100) return true; // temporarily !
// TODO use assignments_dbg
} else continue; // if (correctionsParameters.clt_batch_assign)
// generate ML data if enabled
if (quadCLT_main.correctionsParameters.clt_batch_genMl) { // rig.ml_generate) { //clt_batch_genMl
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)
}
}
if (quadCLT_main.correctionsParameters.clt_batch_gen3d) {
if (updateStatus) IJ.showStatus("Generating and exporting 3D scene model "+quadCLT_main.image_name);
......
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