Commit b3cf8b8a authored by Andrey Filippov's avatar Andrey Filippov

building models from bi-quad data

parent 4ea50500
...@@ -197,6 +197,24 @@ public class BiCamDSI { ...@@ -197,6 +197,24 @@ public class BiCamDSI {
return selection; return selection;
} }
public double [][] filterDisparityStrength(
double min_disparity,
double [] disparity,
double [] strength,
boolean [] selected){
int num_tiles = disparity.length;
double [][] fds = new double [2][num_tiles];
for (int nTile = 0; nTile < num_tiles; nTile++) {
fds[0][nTile] = Double.NaN;
if ((strength[nTile] > 0.0) && (disparity[nTile] >= min_disparity) && ((selected == null) || selected[nTile])) {
fds[0][nTile] = disparity[nTile];
fds[1][nTile] = strength[nTile];
}
}
return fds;
}
/** /**
* Filter selection by expending, then shrinking (fills small gaps) shrinking (combined with * Filter selection by expending, then shrinking (fills small gaps) shrinking (combined with
* previous step) and expanding again (removes small clusters) * previous step) and expanding again (removes small clusters)
......
...@@ -128,6 +128,9 @@ public class BiQuadParameters { ...@@ -128,6 +128,9 @@ public class BiQuadParameters {
public int rf_shrink_near = 8; // Shrink selection after expanding public int rf_shrink_near = 8; // Shrink selection after expanding
public int rf_post_expand_near = 4; // Expand selection after shrinking public int rf_post_expand_near = 4; // Expand selection after shrinking
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 int ml_hwidth = 2; // Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5) public int ml_hwidth = 2; // Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)
public double ml_disparity_sweep = 2.0; // Disparity sweep around ground truth, each side public double ml_disparity_sweep = 2.0; // Disparity sweep around ground truth, each side
public int ml_sweep_steps = 5; // Number of disparity sweep steps public int ml_sweep_steps = 5; // Number of disparity sweep steps
...@@ -325,6 +328,11 @@ public class BiQuadParameters { ...@@ -325,6 +328,11 @@ public class BiQuadParameters {
gd.addNumericField("Expand selection after shrinking (non-infinity regions only)", this.rf_post_expand_near, 0,3,"", gd.addNumericField("Expand selection after shrinking (non-infinity regions only)", this.rf_post_expand_near, 0,3,"",
"Last step of expand-shrink-expand filtering (1 - only vert/hor, 2 -vert/hor/diagonal)"); "Last step of expand-shrink-expand filtering (1 - only vert/hor, 2 -vert/hor/diagonal)");
gd.addNumericField("Minimal usable disparity for tile to be preserved", this.rf_min_disp, 4,6,"pix",
"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.addTab("ML","Parameters related to the ML files generation for the dual-quad camera rig"); gd.addTab("ML","Parameters related to the ML files generation for the dual-quad camera rig");
gd.addNumericField("Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)", this.ml_hwidth, 0,3,"", gd.addNumericField("Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)", this.ml_hwidth, 0,3,"",
...@@ -443,6 +451,9 @@ public class BiQuadParameters { ...@@ -443,6 +451,9 @@ public class BiQuadParameters {
this.rf_shrink_near= (int) gd.getNextNumber(); this.rf_shrink_near= (int) gd.getNextNumber();
this.rf_post_expand_near= (int) gd.getNextNumber(); this.rf_post_expand_near= (int) gd.getNextNumber();
this.rf_min_disp= gd.getNextNumber();
this.rf_remove_unselected= gd.getNextBoolean();
this.ml_hwidth= (int) gd.getNextNumber(); this.ml_hwidth= (int) gd.getNextNumber();
this.ml_disparity_sweep= gd.getNextNumber(); this.ml_disparity_sweep= gd.getNextNumber();
this.ml_sweep_steps= (int) gd.getNextNumber(); this.ml_sweep_steps= (int) gd.getNextNumber();
...@@ -549,6 +560,9 @@ public class BiQuadParameters { ...@@ -549,6 +560,9 @@ public class BiQuadParameters {
properties.setProperty(prefix+"rf_shrink_near", this.rf_shrink_near+""); properties.setProperty(prefix+"rf_shrink_near", this.rf_shrink_near+"");
properties.setProperty(prefix+"rf_post_expand_near", this.rf_post_expand_near+""); properties.setProperty(prefix+"rf_post_expand_near", this.rf_post_expand_near+"");
properties.setProperty(prefix+"rf_min_disp", this.rf_min_disp+"");
properties.setProperty(prefix+"rf_remove_unselected", this.rf_remove_unselected+"");
properties.setProperty(prefix+"ml_hwidth", this.ml_hwidth+""); properties.setProperty(prefix+"ml_hwidth", this.ml_hwidth+"");
properties.setProperty(prefix+"ml_disparity_sweep", this.ml_disparity_sweep+""); properties.setProperty(prefix+"ml_disparity_sweep", this.ml_disparity_sweep+"");
properties.setProperty(prefix+"ml_sweep_steps", this.ml_sweep_steps+""); properties.setProperty(prefix+"ml_sweep_steps", this.ml_sweep_steps+"");
...@@ -654,6 +668,9 @@ public class BiQuadParameters { ...@@ -654,6 +668,9 @@ public class BiQuadParameters {
if (properties.getProperty(prefix+"rf_shrink_near")!=null) this.rf_shrink_near=Integer.parseInt(properties.getProperty(prefix+"rf_shrink_near")); if (properties.getProperty(prefix+"rf_shrink_near")!=null) this.rf_shrink_near=Integer.parseInt(properties.getProperty(prefix+"rf_shrink_near"));
if (properties.getProperty(prefix+"rf_post_expand_near")!=null) this.rf_post_expand_near=Integer.parseInt(properties.getProperty(prefix+"rf_post_expand_near")); if (properties.getProperty(prefix+"rf_post_expand_near")!=null) this.rf_post_expand_near=Integer.parseInt(properties.getProperty(prefix+"rf_post_expand_near"));
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_disparity_sweep")!=null) this.ml_disparity_sweep=Double.parseDouble(properties.getProperty(prefix+"ml_disparity_sweep")); if (properties.getProperty(prefix+"ml_disparity_sweep")!=null) this.ml_disparity_sweep=Double.parseDouble(properties.getProperty(prefix+"ml_disparity_sweep"));
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_sweep_steps")!=null) this.ml_sweep_steps=Integer.parseInt(properties.getProperty(prefix+"ml_sweep_steps"));
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_aux")!=null) this.ml_keep_aux=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_aux"));
...@@ -757,6 +774,9 @@ public class BiQuadParameters { ...@@ -757,6 +774,9 @@ public class BiQuadParameters {
bqp.rf_shrink_near= this.rf_shrink_near; bqp.rf_shrink_near= this.rf_shrink_near;
bqp.rf_post_expand_near= this.rf_post_expand_near; bqp.rf_post_expand_near= this.rf_post_expand_near;
bqp.rf_min_disp= this.rf_min_disp;
bqp.rf_remove_unselected= this.rf_remove_unselected;
bqp.ml_hwidth= this.ml_hwidth; bqp.ml_hwidth= this.ml_hwidth;
bqp.ml_disparity_sweep= this.ml_disparity_sweep; bqp.ml_disparity_sweep= this.ml_disparity_sweep;
bqp.ml_sweep_steps= this.ml_sweep_steps; bqp.ml_sweep_steps= this.ml_sweep_steps;
......
...@@ -392,7 +392,8 @@ public class CLTPass3d{ ...@@ -392,7 +392,8 @@ public class CLTPass3d{
* @return line-scan array of per-tile horizontal pairs correlation strength by reference (not a copy) * @return line-scan array of per-tile horizontal pairs correlation strength by reference (not a copy)
*/ */
public double [] getOriginalStrength(){ public double [] getOriginalStrength(){
return disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX]; if (disparity_map != null) return disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX];
else return getStrength(); // after replacing with rig data
} }
/** /**
* Get horizontal pairs correlation strength for vertical features. Not a copy * Get horizontal pairs correlation strength for vertical features. Not a copy
......
...@@ -590,6 +590,8 @@ private Panel panel1, ...@@ -590,6 +590,8 @@ private Panel panel1,
// addButton("Rig enhance", panelClt4, color_conf_process); // addButton("Rig enhance", panelClt4, color_conf_process);
addButton("Ground truth", panelClt4, color_conf_process); addButton("Ground truth", panelClt4, color_conf_process);
addButton("ML export", panelClt4, color_conf_process); addButton("ML export", panelClt4, color_conf_process);
addButton("Rig planes", panelClt4, color_conf_process);
add(panelClt4); add(panelClt4);
} }
...@@ -4598,6 +4600,14 @@ private Panel panel1, ...@@ -4598,6 +4600,14 @@ private Panel panel1,
enhanceByRig(); enhanceByRig();
return; return;
/* ======================================================================== */
} else if (label.equals("CLT planes")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
rigPlanes();
return;
/* ======================================================================== */ /* ======================================================================== */
} else if (label.equals("ML export")) { } else if (label.equals("ML export")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL; DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
...@@ -5020,8 +5030,32 @@ private Panel panel1, ...@@ -5020,8 +5030,32 @@ private Panel panel1,
return true; return true;
} }
public boolean rigPlanes() {
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
String msg = "DSI data is not available. Please run \"CLT 3D\" first";
IJ.showMessage("Error",msg);
System.out.println(msg);
return false;
}
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Extracting planes using a dual-quad camera rig DSI data ++++++++++++++");
}
QUAD_CLT.showCLTPlanes(
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
DEBUG_LEVEL); //final int debugLevel);
return true;
}
public boolean enhanceByRig() { public boolean enhanceByRig() {
long startTime=System.nanoTime();
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) { if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
String msg = "DSI data is not available. Please run \"CLT 3D\" first"; String msg = "DSI data is not available. Please run \"CLT 3D\" first";
IJ.showMessage("Error",msg); IJ.showMessage("Error",msg);
...@@ -5055,10 +5089,15 @@ private Panel panel1, ...@@ -5055,10 +5089,15 @@ private Panel panel1,
true, true,
PROPERTIES); PROPERTIES);
} }
System.out.println("enhanceByRig(): Processing finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+" sec, --- Free memory="+
Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
return true; return true;
} }
public boolean exportMLData() { public boolean exportMLData() {
long startTime=System.nanoTime();
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) { if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
String msg = "DSI data is not available. Please run \"CLT 3D\" first"; String msg = "DSI data is not available. Please run \"CLT 3D\" first";
IJ.showMessage("Error",msg); IJ.showMessage("Error",msg);
...@@ -5092,10 +5131,13 @@ private Panel panel1, ...@@ -5092,10 +5131,13 @@ private Panel panel1,
true, true,
PROPERTIES); PROPERTIES);
} }
System.out.println("exportMLData(): Processing finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+" sec, --- Free memory="+
Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
return true; return true;
} }
public boolean infinityRig() { public boolean infinityRig() {
if (!prepareRigImages()) return false; if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath(); String configPath=getSaveCongigPath();
......
...@@ -1101,7 +1101,10 @@ public class MeasuredLayers { ...@@ -1101,7 +1101,10 @@ public class MeasuredLayers {
if (weight[indxe_center] >= mlfp.strength_sure) { // tile does not need filtering if (weight[indxe_center] >= mlfp.strength_sure) { // tile does not need filtering
ds[0][indx] = disp[indxe_center]; ds[0][indx] = disp[indxe_center];
ds[1][indx] = weight[indxe_center]; ds[1][indx] = weight[indxe_center];
if (Double.isNaN(ds[0][indx])){
System.out.println("**** this is a BUG6 in getDisparityStrengthML() ****"); // all smpl_d are NaNs
// break;
}
} else { } else {
int num_in_sample = 0; int num_in_sample = 0;
double sum_wnd = 0.0; double sum_wnd = 0.0;
...@@ -1124,6 +1127,10 @@ public class MeasuredLayers { ...@@ -1124,6 +1127,10 @@ public class MeasuredLayers {
int indxs = sy * mlfp.smplSide + sx; int indxs = sy * mlfp.smplSide + sx;
smpl_sel[indxs] = true; smpl_sel[indxs] = true;
smpl_d[indxs] = disp[indxe]; smpl_d[indxs] = disp[indxe];
if (Double.isNaN(smpl_d[indxs])){
System.out.println("**** this is a BUG5 in getDisparityStrengthML() ****"); // all smpl_d are NaNs
// break;
}
smpl_w[indxs] = weight[indxe] * smpl_weights[indxs]; smpl_w[indxs] = weight[indxe] * smpl_weights[indxs];
sum_wnd += smpl_weights[indxs]; sum_wnd += smpl_weights[indxs];
num_in_sample ++; num_in_sample ++;
...@@ -1292,15 +1299,27 @@ public class MeasuredLayers { ...@@ -1292,15 +1299,27 @@ public class MeasuredLayers {
tiltXY = atiltXY[0]; // common for all tiles (such as constant disparity) tiltXY = atiltXY[0]; // common for all tiles (such as constant disparity)
} else if (atiltXY[indx] != null){ } else if (atiltXY[indx] != null){
tiltXY = atiltXY[indx]; tiltXY = atiltXY[indx];
if (Double.isNaN(tiltXY[0]) || Double.isNaN(tiltXY[1])){
System.out.println("**** this is a BUG4A in getDisparityStrengthML() ****");
System.out.println("atilt["+indx+"]= {"+tiltXY[0]+","+tiltXY[1]+"}");
tiltXY[0] = 0.0;
tiltXY[1] = 0.0;
}
} }
} }
if ((tiltXY != null) && (tiltXY[0] != 0.0) && (tiltXY[1] != 0.0)){ if ((tiltXY != null) && (tiltXY[0] != 0.0) && (tiltXY[1] != 0.0)){ // {NaN,NaN}
for (int sy = 0; sy < mlfp.smplSide; sy++){ for (int sy = 0; sy < mlfp.smplSide; sy++){
for (int sx = 0; sx < mlfp.smplSide; sx++){ for (int sx = 0; sx < mlfp.smplSide; sx++){
int indxs = sy * mlfp.smplSide + sx; int indxs = sy * mlfp.smplSide + sx;
if (smpl_w[indxs] > 0.0) { if (smpl_w[indxs] > 0.0) {
smpl_d[indxs] -= tiltXY[0]* (sx - smpl_dcenter) + tiltXY[1]* (sy - smpl_dcenter); smpl_d[indxs] -= tiltXY[0]* (sx - smpl_dcenter) + tiltXY[1]* (sy - smpl_dcenter);
if (Double.isNaN(smpl_d[indxs])){
System.out.println("**** this is a BUG4 in getDisparityStrengthML() ****"); // all smpl_d are NaNs
// break;
}
} }
} }
} }
...@@ -1310,6 +1329,11 @@ public class MeasuredLayers { ...@@ -1310,6 +1329,11 @@ public class MeasuredLayers {
// calculate // calculate
double sd=0.0, sd2 = 0.0, sw = 0.0; double sd=0.0, sd2 = 0.0, sw = 0.0;
for (int i = 0; i < smplLen; i++) if (smpl_sel[i]) { for (int i = 0; i < smplLen; i++) if (smpl_sel[i]) {
if (Double.isNaN(smpl_d[i])){
System.out.println("**** this is a BUG3 in getDisparityStrengthML() ****"); // all smpl_d are NaNs
// break;
}
double dw = smpl_d[i] * smpl_w[i]; double dw = smpl_d[i] * smpl_w[i];
sd += dw; sd += dw;
sd2 += dw * smpl_d[i]; sd2 += dw * smpl_d[i];
...@@ -1330,7 +1354,7 @@ public class MeasuredLayers { ...@@ -1330,7 +1354,7 @@ public class MeasuredLayers {
//remove_far_only //remove_far_only
} }
if (iworst < 0){ if (iworst < 0){
System.out.println("**** this is a BUG2 in getDisparityStrengthML() ****"); System.out.println("**** this is a BUG2 in getDisparityStrengthML() ****"); // all smpl_d are NaNs
break; break;
} }
// remove worst sample // remove worst sample
......
...@@ -6926,7 +6926,7 @@ public class QuadCLT { ...@@ -6926,7 +6926,7 @@ public class QuadCLT {
debugLevelInner); debugLevelInner);
// Save tp.clt_3d_passes.size() to roll back without restarting the program // Save tp.clt_3d_passes.size() to roll back without restarting the program
tp.saveCLTPasses(); tp.saveCLTPasses(false); // not rig, and reset rig data
Runtime runtime = Runtime.getRuntime(); Runtime runtime = Runtime.getRuntime();
runtime.gc(); runtime.gc();
System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")"); System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
......
...@@ -1587,7 +1587,7 @@ public class SuperTiles{ ...@@ -1587,7 +1587,7 @@ public class SuperTiles{
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
@Override @Override
public void run() { public void run() {
double [][][] plane_tilts = null; // used only forworld_plane_norm != null double [][][] plane_tilts = null; // used only for world_plane_norm != null
// to get tile disparities needed to calculate tilts // to get tile disparities needed to calculate tilts
for (int nsTile = ai.getAndIncrement(); nsTile < nStiles; nsTile = ai.getAndIncrement()) { for (int nsTile = ai.getAndIncrement(); nsTile < nStiles; nsTile = ai.getAndIncrement()) {
// int dl = (nsTile == debug_stile) ? 3 : 0; // int dl = (nsTile == debug_stile) ? 3 : 0;
......
...@@ -1054,7 +1054,8 @@ public class TilePlanes { ...@@ -1054,7 +1054,8 @@ public class TilePlanes {
Matrix normal_col = new Matrix(world_normal_xyz,3); // 3x1 Matrix normal_col = new Matrix(world_normal_xyz,3); // 3x1
// find world coordinates of the center of tile intersection with the plane // find world coordinates of the center of tile intersection with the plane
for (int lTile = 0; lTile < tile_disp_strengths[1].length; lTile++) if (tile_disp_strengths[1][lTile] > 0.0){ // disparity 0.0 is invalid, but it somehow got here
for (int lTile = 0; lTile < tile_disp_strengths[1].length; lTile++) if ((tile_disp_strengths[1][lTile] > 0.0) && (tile_disp_strengths[0][lTile] > 0.0)){
int tY = lTile / stSize2; int tY = lTile / stSize2;
int tX = lTile % stSize2; int tX = lTile % stSize2;
double px = px_py[0] + tX - stCenter; double px = px_py[0] + tX - stCenter;
...@@ -1092,7 +1093,15 @@ public class TilePlanes { ...@@ -1092,7 +1093,15 @@ public class TilePlanes {
double [] txty = { double [] txty = {
-pn.get(1, 0)/pn.get(0, 0)*stSize, -pn.get(1, 0)/pn.get(0, 0)*stSize,
-pn.get(2, 0)/pn.get(0, 0)*stSize}; -pn.get(2, 0)/pn.get(0, 0)*stSize};
tile_tilts[lTile] = txty;
if (Double.isNaN(txty[0]) || Double.isNaN(txty[1])){
System.out.println("**** this is a BUG in getDisparityTilts() ****");
System.out.println("txty= {"+txty[0]+","+txty[1]+"}");
jacobian.print(10, 5);
txty = null;
}
tile_tilts[lTile] = txty; // some are nulls?
} }
// if (debugLevel > 1) { // if (debugLevel > 1) {
......
...@@ -32,7 +32,8 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -32,7 +32,8 @@ import java.util.concurrent.atomic.AtomicInteger;
public class TileProcessor { public class TileProcessor {
public ArrayList <CLTPass3d> clt_3d_passes = null; public ArrayList <CLTPass3d> clt_3d_passes = null;
public double [][] rig_disparity_strength = null; // Disparity and strength created by a two-camera rig, with disparity scale and distortions of the main camera public double [][] rig_disparity_strength = null; // Disparity and strength created by a two-camera rig, with disparity scale and distortions of the main camera
public int clt_3d_passes_size = 0; //clt_3d_passes size after initial processing public int clt_3d_passes_size = 0; //clt_3d_passes size after initial processing
public int clt_3d_passes_rig_size = 0; //clt_3d_passes size after initial processing and rig processing
private int tilesX; private int tilesX;
private int tilesY; private int tilesY;
private double corr_magic_scale = 0.85; // reported correlation offset vs. actual one (not yet understood) private double corr_magic_scale = 0.85; // reported correlation offset vs. actual one (not yet understood)
...@@ -103,23 +104,51 @@ public class TileProcessor { ...@@ -103,23 +104,51 @@ public class TileProcessor {
public void resetCLTPasses(){ public void resetCLTPasses(){
clt_3d_passes = new ArrayList<CLTPass3d>(); clt_3d_passes = new ArrayList<CLTPass3d>();
clt_3d_passes_size = 0; clt_3d_passes_size = 0;
clt_3d_passes_rig_size = 0;
Runtime runtime = Runtime.getRuntime(); Runtime runtime = Runtime.getRuntime();
runtime.gc(); runtime.gc();
System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")"); System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
} }
public void saveCLTPasses(){ public void saveCLTPasses(boolean rig){
clt_3d_passes_size = clt_3d_passes.size(); if (rig) clt_3d_passes_rig_size = clt_3d_passes.size();
else {
rig_disparity_strength = null; // invalidate
clt_3d_passes_rig_size = 0;
clt_3d_passes_size = clt_3d_passes.size();
}
} }
public void trimCLTPasses(int keep){ public void trimCLTPasses(int keep){
if (keep < clt_3d_passes_size) { // keep rig data if only rig scan is removed
rig_disparity_strength = null; // invalidate
clt_3d_passes_rig_size = 0;
}
clt_3d_passes_size = keep; clt_3d_passes_size = keep;
trimCLTPasses(); trimCLTPasses();
} }
public void trimCLTPasses(boolean rig){
if (!rig) {
// rig_disparity_strength = null; // invalidate
clt_3d_passes_rig_size = 0;
}
trimCLTPasses();
}
public void trimCLTPasses(){ public void trimCLTPasses(){
while (clt_3d_passes.size() > clt_3d_passes_size){ int keep_size = clt_3d_passes_size;
if (clt_3d_passes_rig_size > keep_size) {
keep_size = clt_3d_passes_rig_size;
System.out.println("trimCLTPasses(): using dual-quad camera rig data");
} else {
// rig_disparity_strength = null; // invalidate
// clt_3d_passes_rig_size = 0;
System.out.println("trimCLTPasses(): using master camera data");
}
while (clt_3d_passes.size() > keep_size){
clt_3d_passes.remove(clt_3d_passes_size); clt_3d_passes.remove(clt_3d_passes_size);
} }
Runtime runtime = Runtime.getRuntime(); Runtime runtime = Runtime.getRuntime();
...@@ -127,10 +156,13 @@ public class TileProcessor { ...@@ -127,10 +156,13 @@ public class TileProcessor {
System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")"); System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
} }
public void removeNonMeasurement(){ public void removeNonMeasurement(){ // executed during expansion (CLT 3D)
for (int i = clt_3d_passes.size()-1; i > 0; i--) if (!clt_3d_passes.get(i).isMeasured()){ for (int i = clt_3d_passes.size()-1; i > 0; i--) if (!clt_3d_passes.get(i).isMeasured()){
clt_3d_passes.remove(i); clt_3d_passes.remove(i);
} }
// just in case - invalidate (should be done anyway)
rig_disparity_strength = null; // invalidate
clt_3d_passes_rig_size = 0;
} }
...@@ -628,6 +660,46 @@ public class TileProcessor { ...@@ -628,6 +660,46 @@ public class TileProcessor {
return combo_pass; return combo_pass;
} }
/**
* Create a minimal composite scan from provided data (dual-quad rig. So no Hor/Vert
* @param disparity target disparity from the rig
* @param strength correlation strength from the rig
* @param selected filtered selected
* @param debugLevel debug level
* @return an instance of CLTPass3d to be added to the list and used instead of the master camera DSI
*/
public CLTPass3d compositeScan(
final double [] disparity,
final double [] strength,
final boolean [] selected,
final int debugLevel)
{
CLTPass3d combo_pass =new CLTPass3d(this);
final int tlen = tilesX * tilesY;
// final int disparity_index = usePoly ? ImageDtt.DISPARITY_INDEX_POLY : ImageDtt.DISPARITY_INDEX_CM;
// combo_pass.tile_op = new int [tilesY][tilesX]; // for just non-zero
// combo_pass.disparity_map = new double [ImageDtt.DISPARITY_TITLES.length][];
// for (int i = 0; i< ImageDtt.QUAD; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i] = new double[tlen];
// for now - will copy from the best full correlation measurement
// combo_pass.texture_tiles = new double [tilesY][tilesX][][];
// combo_pass.max_tried_disparity = new double [tilesY][tilesX];
combo_pass.is_combo = true;
combo_pass.calc_disparity = disparity.clone(); //new double [tlen];
combo_pass.calc_disparity_combo = disparity.clone(); //new double [tlen];
combo_pass.calc_disparity_hor = new double [tlen];
combo_pass.calc_disparity_vert = new double [tlen];
combo_pass.strength = strength.clone(); // new double [tlen];
combo_pass.strength_hor = new double [tlen];
combo_pass.strength_vert = new double [tlen];
combo_pass.setSelected(selected);
return combo_pass;
}
/** /**
* Create next measurement scan that can handle multiple disparities, using quad correlations only * Create next measurement scan that can handle multiple disparities, using quad correlations only
* @param passes * @param passes
......
...@@ -1215,7 +1215,9 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -1215,7 +1215,9 @@ if (debugLevel > -100) return true; // temporarily !
} }
} }
CLTPass3d scan_bg = quadCLT_main.tp.clt_3d_passes.get( 0); // get bg scan CLTPass3d scan_bg = quadCLT_main.tp.clt_3d_passes.get( 0); // get bg scan
CLTPass3d scan_last = quadCLT_main.tp.clt_3d_passes.get(quadCLT_main.tp.clt_3d_passes.size()-1); // get last scan // quadCLT_main.tp.trimCLTPasses(false); // remove rig composite scan if any
// last but not including any rid data
CLTPass3d scan_last = quadCLT_main.tp.clt_3d_passes.get( quadCLT_main.tp.clt_3d_passes_size -1); // get last one
// TODO: combine in a single function to always call after groundTruthByRig. Or before use? // TODO: combine in a single function to always call after groundTruthByRig. Or before use?
boolean [] infinity_select = scan_bg.getSelected(); // null; boolean [] infinity_select = scan_bg.getSelected(); // null;
...@@ -1357,6 +1359,110 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -1357,6 +1359,110 @@ if (debugLevel > -100) return true; // temporarily !
"Selections", "Selections",
titles); titles);
} }
// set composite scan
boolean [] cond_sel = (clt_parameters.rig.rf_remove_unselected)? selection:null;
double [][] f_rig_disparity_strength = biCamDSI.filterDisparityStrength(
clt_parameters.rig.rf_min_disp, // double min_disparity,
rig_disparity_strength[0], // double [] disparity,
rig_disparity_strength[1], // double [] strength)
cond_sel); // boolean [] selected)
// CLT ASSIGN needs best texture for each tile. Initially will just copy from teh previous master
// composite scan, later - fill disparity gaps and re-measure
/*
* TODO: interpolate disaprities before measuring to fill gaps?
public double [][][][][] getRigTextures(
boolean need_master,
boolean need_aux,
double [] disparity, // non-nan - measure
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel) // throws Exception
*/
quadCLT_main.tp.trimCLTPasses(false); // remove rig composite scan if any
CLTPass3d rig_scan = quadCLT_main.tp.compositeScan(
f_rig_disparity_strength[0], // final double [] disparity,
f_rig_disparity_strength[1], // final double [] strength,
selection, // final boolean [] selected,
debugLevel); // final int debugLevel)
rig_scan.texture_tiles = scan_last.texture_tiles;
// scan_last
quadCLT_main.tp.clt_3d_passes.add(rig_scan);
quadCLT_main.tp.saveCLTPasses(true); // rig pass
}
public double [][][][][] getRigTextures(
boolean need_master,
boolean need_aux,
double [] disparity, // non-nan - measure
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel) // throws Exception
{
final int tile_op_all = clt_parameters.tile_task_op; //FIXME Use some constant?
final int tilesX = quadCLT_main.tp.getTilesX();
final int tilesY = quadCLT_main.tp.getTilesY();
final int [][] tile_op = new int [tilesY][tilesX];
final double [][] disparity_array = new double [tilesY][tilesX];
boolean [] need_textures = {need_master, need_aux};
final double [][][][][] texture_tiles = new double [need_textures.length][][][][];
for (int ncam = 0; ncam < need_textures.length; ncam++) if (need_textures[ncam]) {
texture_tiles[ncam] = new double [tilesY][tilesX][][];
for (int tileY = 0; tileY < tilesY; tileY++){
for (int tileX = 0; tileX < tilesX; tileX++){
texture_tiles[ncam][tileY][tileX] = null;
int nTile = tileY*tilesX + tileX;
if (!Double.isNaN(disparity[nTile])) {
tile_op[tileY][tileX] = tile_op_all;
disparity_array[tileY][tileX] = disparity[nTile];
}
}
}
}
ImageDtt image_dtt = new ImageDtt();
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
tile_op, // final int [][] tile_op_main, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
disparity_array, // final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
quadCLT_main.image_data, // final double [][][] image_data_main, // first index - number of image in a quad
quadCLT_aux.image_data, // final double [][][] image_data_aux, // first index - number of image in a quad
quadCLT_main.saturation_imp, // final boolean [][] saturation_main, // (near) saturated pixels or null
quadCLT_aux.saturation_imp, // final boolean [][] saturation_aux, // (near) saturated pixels or null
// correlation results - combo will be for the correation between two quad cameras
null, // final double [][][][] clt_corr_combo, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
null, // disparity_bimap, // final double [][] disparity_bimap, // [23][tilesY][tilesX]
null, // ml_data, // final 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)
texture_tiles[0], // final double [][][][] texture_tiles_main, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
texture_tiles[1], // final double [][][][] texture_tiles_aux, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
quadCLT_main.tp.getTilesX()*clt_parameters.transform_size, // final int width,
quadCLT_main.getGeometryCorrection(), // final GeometryCorrection geometryCorrection_main,
quadCLT_aux.getGeometryCorrection(), // final GeometryCorrection geometryCorrection_aux,
quadCLT_main.getCLTKernels(), // final double [][][][][][] clt_kernels_main, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
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,
threadsMax, // final int threadsMax, // maximal number of threads to launch
debugLevel-2); // final int globalDebugLevel);
return texture_tiles;
} }
public void outputMLData( public void outputMLData(
...@@ -1615,7 +1721,9 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -1615,7 +1721,9 @@ if (debugLevel > -100) return true; // temporarily !
} }
// Get DSI from the main camera // Get DSI from the main camera
CLTPass3d scan_last = quadCLT_main.tp.clt_3d_passes.get( quadCLT_main.tp.clt_3d_passes.size() -1); // get last one quadCLT_main.tp.trimCLTPasses(false); // remove rig composite scan if any
// last but not including any rid data
CLTPass3d scan_last = quadCLT_main.tp.clt_3d_passes.get( quadCLT_main.tp.clt_3d_passes_size -1); // get last one
double [][] disparity_bimap = setBimapFromCLTPass3d( double [][] disparity_bimap = setBimapFromCLTPass3d(
scan_last, // CLTPass3d scan, scan_last, // CLTPass3d scan,
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
......
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