Commit 79689dc1 authored by Andrey Filippov's avatar Andrey Filippov

testing/olptimizing tile assignment

parent 22b9ceaa
......@@ -2202,6 +2202,11 @@ public class EyesisCorrectionParameters {
public boolean plConflSngl = true; // Only merge conflicting planes if this is the only conflicting pair in the supertile
public boolean plConflSnglPair = true; // Only merge conflicting planes only if there are just two planes in the supertile
public double plWeakFgStrength = 0.15; // Consider merging plane if it is foreground and maximal strength below this
public int plWeakFgOutliers = 1; // Remove these strongest from foreground when determining the maximal strength
public double plWeakFgRelax = 2.0; // Relax cost requirements when merging with weak foreground
public double plThickWorld = 0.2; // Maximal real-world thickness of merged overlapping planes (meters)
public double plThickWorldConfl = 0.4; // Maximal real-world merged thickness for conflicting planes
public double plRelaxComplete = 1.5; // Relax cost requirements when adding exclusive links to complete squares and triangles
......@@ -2212,6 +2217,8 @@ public class EyesisCorrectionParameters {
public double plMaxDisp = 0.6; // Maximal disparity of one of the planes to apply maximal ratio
public double plCutTail = 1.4; // When merging with neighbors cut the tail that is worse than scaled best
public double plMinTail = 0.015;// Set cutoff value level not less than
// parameters to recreate planes from tiles disparity/strengths using determined plane connections to neighbors
public boolean plDiscrEn = true; // Enable planes tiles selection regeneration hinted by supertile neighbors
public double plDiscrTolerance = 0.4; // Maximal disparity difference from the plane to consider tile
......@@ -2679,6 +2686,11 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plConflRelax", this.plConflRelax +"");
properties.setProperty(prefix+"plConflSngl", this.plConflSngl+"");
properties.setProperty(prefix+"plConflSnglPair", this.plConflSnglPair+"");
properties.setProperty(prefix+"plWeakFgStrength", this.plWeakFgStrength +"");
properties.setProperty(prefix+"plWeakFgOutliers", this.plWeakFgOutliers+"");
properties.setProperty(prefix+"plWeakFgRelax", this.plWeakFgRelax +"");
properties.setProperty(prefix+"plThickWorld", this.plThickWorld +"");
properties.setProperty(prefix+"plThickWorldConfl",this.plThickWorldConfl +"");
properties.setProperty(prefix+"plRelaxComplete", this.plRelaxComplete +"");
......@@ -3128,6 +3140,11 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plConflRelax")!=null) this.plConflRelax=Double.parseDouble(properties.getProperty(prefix+"plConflRelax"));
if (properties.getProperty(prefix+"plConflSngl")!=null) this.plConflSngl=Boolean.parseBoolean(properties.getProperty(prefix+"plConflSngl"));
if (properties.getProperty(prefix+"plConflSnglPair")!=null) this.plConflSnglPair=Boolean.parseBoolean(properties.getProperty(prefix+"plConflSnglPair"));
if (properties.getProperty(prefix+"plWeakFgStrength")!=null) this.plWeakFgStrength=Double.parseDouble(properties.getProperty(prefix+"plWeakFgStrength"));
if (properties.getProperty(prefix+"plWeakFgOutliers")!=null) this.plWeakFgOutliers=Integer.parseInt(properties.getProperty(prefix+"plWeakFgOutliers"));
if (properties.getProperty(prefix+"plWeakFgRelax")!=null) this.plWeakFgRelax=Double.parseDouble(properties.getProperty(prefix+"plWeakFgRelax"));
if (properties.getProperty(prefix+"plThickWorld")!=null) this.plThickWorld=Double.parseDouble(properties.getProperty(prefix+"plThickWorld"));
if (properties.getProperty(prefix+"plThickWorldConfl")!=null) this.plThickWorldConfl=Double.parseDouble(properties.getProperty(prefix+"plThickWorldConfl"));
if (properties.getProperty(prefix+"plRelaxComplete")!=null) this.plRelaxComplete=Double.parseDouble(properties.getProperty(prefix+"plRelaxComplete"));
......@@ -3605,6 +3622,11 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Scale parameters to relax planes fit for merging conflicting planes", this.plConflRelax, 6);
gd.addCheckbox ("Only merge conflicting planes if this is the only conflicting pair in the supertile", this.plConflSngl);
gd.addCheckbox ("Only merge conflicting planes only if there are just two planes in the supertile", this.plConflSnglPair);
gd.addNumericField("Consider merging plane if it is foreground and maximal strength below this", this.plWeakFgStrength, 6);
gd.addNumericField("Remove these strongest from foreground when determining the maximal strength", this.plWeakFgOutliers, 0);
gd.addNumericField("Relax cost requirements when merging with weak foreground", this.plWeakFgRelax, 6);
gd.addNumericField("Maximal real-world thickness of merged overlapping planes (meters)", this.plThickWorld, 6);
gd.addNumericField("Maximal real-world merged thickness for conflicting planes", this.plThickWorldConfl, 6);
gd.addNumericField("Relax cost requirements when adding exclusive links to complete squares and triangles",this.plRelaxComplete, 6);
......@@ -4070,6 +4092,11 @@ public class EyesisCorrectionParameters {
this.plConflRelax= gd.getNextNumber();
this.plConflSngl= gd.getNextBoolean();
this.plConflSnglPair= gd.getNextBoolean();
this.plWeakFgStrength= gd.getNextNumber();
this.plWeakFgOutliers=(int) gd.getNextNumber();
this.plWeakFgRelax= gd.getNextNumber();
this.plThickWorld= gd.getNextNumber();
this.plThickWorldConfl= gd.getNextNumber();
this.plRelaxComplete= gd.getNextNumber();
......
This diff is collapsed.
......@@ -319,6 +319,19 @@ public class MeasuredLayers {
return lapWeight;
}
public double [] getLapWeights1d(){
int indx = 0;
final int superTileSize2 = 2 * superTileSize;
double [] weights = new double [superTileSize2 * superTileSize2];
for (int i = 0; i < superTileSize2; i++){
for (int j = 0; j < superTileSize2; j++){
weights[indx++] = lapWeight[i][j];
}
}
return weights;
}
/**
* Get selection for the specific measurement layer and supertile X,Y coordinates
* in the image. Combined with input selection
......
......@@ -61,6 +61,9 @@ public class TileAssignment {
private double strengthBestPwr; // = 0.0; // Strength power when calculating disparity error over best
private double strengthDiff9Pwr; // = 0.5; // Strength power when calculating disparity error for group of 9
private double shrinkWeakFgnd = 0.5; // 0.5; //reduce cost of multiple weak_fgnd links of the same tile
private double shrinkColor = 0.5; // 0.0; //reduce cost of surface transitions w/o color change
static double [] NEIB_WEIGHTS = {0.5,0.25, 0.5, 0.25, 0.5,0.25, 0.5, 0.25, 1.0};
static int INDEX_R = 0;
......@@ -720,8 +723,10 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
HashMap<Point,Integer> replacements)
{
TACosts costs = new TACosts();
if (nSurfTile == 47459){
int debugLevel = 0;
if (nSurfTile == 51360) { // 44831) { // 47459){
System.out.println("getTileCosts() nSurfTile="+nSurfTile);
debugLevel = 1;
}
int [][] around = new int [valid_ml.length][]; // contains layer + 1
for (int ml = 0; ml < valid_ml.length; ml++) if(valid_ml[ml]) {
......@@ -754,6 +759,9 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
}
// public double nolink; // Cost of a tile not having any neighbor in particular direction
int num_weak_fgnd = 0; // to reduce multiple for teh same tile
int num_color_sep = 0; // to reduce multiple for teh same tile
for (int ml = 0; ml < around.length; ml++) if ((around[ml] != null) && (around[ml][8] > 0)){
if ((around[ml][8] - 1) >= ts.getTileData()[nSurfTile].length){
System.out.println("getTileCosts() BUG: nSurfTile="+nSurfTile);
......@@ -799,16 +807,19 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
double strength = dispStrength[ml][nSurfTile][1];
strength = Math.max(strength, minFgEdge);
costs.weak_fgnd += minFgEdge / strength;
num_weak_fgnd++;
} else if (mutual_weak_fgnd && (disp_diff < -minFgBg)) {
double [] dsmeas_other = dispStrength[ml][nSurfTiles[dir]];
double strength = (dsmeas_other != null)? dsmeas_other[1]: 0.0; // measured strength on the other end or 0.0 if nothing there
strength = Math.max(strength, minFgEdge);
costs.weak_fgnd += minFgEdge / strength;
num_weak_fgnd++;
}
if (Math.abs(disp_diff) > minColSep){
double col_diff = tone_diff_weight[nSurfTile][dir][0];
col_diff= Math.max(col_diff,minColDiff);
costs.color += tone_diff_weight[nSurfTile][dir][1] * minColSep/col_diff;
num_color_sep++;
}
} else { // v, both can not coexist
......@@ -818,9 +829,18 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
// if (around[ml][8] == 0) costs.empty +=1.0; // each existing measurement layer that is not assigned
} //for (int ml = 0; ml < around.length; ml++) if ((around[ml] != null) && (around[ml][8] > 0))
if ((num_weak_fgnd > 0) && (shrinkWeakFgnd > 0.0)){
costs.weak_fgnd /= Math.pow(num_weak_fgnd, shrinkWeakFgnd);
}
if ((num_color_sep > 0) && (shrinkColor > 0.0)){
costs.color /= Math.pow(num_color_sep, shrinkColor);
}
double disp_diff_lpf = 0.0, disp_diff_weight = 0.0; // calculate LPF of the disparity signed error over all ML and 9 cells
double disp_diff2 = 0.0, disp_weight = 0.0; // calculate disparity error in the center, weighted
double disp_diff_over_best = 0.0, disp_weight_best = 0.0; // calculate disparity error in the center, weighted
double disp_diff_over_best = 0.0; // , disp_weight_best = 0.0; // calculate disparity error in the center, weighted
for (int ml = 0; ml < around.length; ml++) if (around[ml] != null){
double diff=0.0, weight=0.0;
for (int dir = 0; dir < 9; dir++){
......@@ -846,8 +866,10 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
weight *= NEIB_WEIGHTS[dir];
disp_diff_lpf += diff * weight;
disp_diff_weight += weight;
// } else {
// System.out.println("getTileCosts() BUG, nSurfTile="+nSurfTile);
if (debugLevel > 0){
System.out.println("getTileCosts() nSurfTile = "+nSurfTile+"->"+dir+" disp_diff_lpf="+disp_diff_lpf+
" disp_diff_weight="+disp_diff_weight+" weight="+weight+ " diff="+diff+" around["+ml+"]["+dir+"]="+around[ml][dir]);
}
}
}
// now diff is for the center, weight needs to be re-calculated
......@@ -877,6 +899,10 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
if (disp_diff_weight > 0.0) {
disp_diff_lpf /= disp_diff_weight;
costs.diff9 += disp_diff_lpf * disp_diff_lpf;
if (debugLevel > 0){
System.out.println("getTileCosts() nSurfTile = "+nSurfTile+" disp_diff_lpf="+disp_diff_lpf+
" disp_diff_weight="+disp_diff_weight+" costs.diff9="+costs.diff9);
}
}
if (disp_weight > 0.0) {
costs.diff += disp_diff2 / disp_weight;
......@@ -1155,7 +1181,7 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
mutual_weak_fgnd = false;
final int tries = 1000;
// final int dbg_tile = dbg_X + dbg_Y * surfTilesX;
final int dbg_tile = 47779; // 27083; // 44493;
final int dbg_tile = 51360; // 51; // 44831; // 27083; // 44493;
final int num_tiles = surfTilesX * surfTilesY;
final int [][] tile_indices = new int [step*step][];
for (int sty = 0; sty < step; sty ++){
......@@ -1244,13 +1270,32 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
continue; // no valid surfaces at this location
}
double best_cost = 0.0;
for (int dir = 0; dir <9; dir++) {
if (dl > 2) {
System.out.println("optimizeAssignment25(), tileLayers[0]["+nSurfTile+"] = " + tileLayers[0][nSurfTile]);
// int [] dbg_layers = new int [tileLayers.length];
// for (int ml = 0; ml < tileLayers.length; ml++){
// dbg_layers[ml] = (tileLayers[ml] == null) ? -0: tileLayers[ml][nSurfTile];
// }
// System.out.println("optimizeAssignment25(), tileLayers["+nSurfTile+"] = " + dbg_layers);
}
for (int dir = 0; dir < 9; dir++) {
int nSurfTile1 = tnSurface.getNeibIndex(nSurfTile, dir);
if (nSurfTile1 >= 0){
best_cost += cost_coeff.dotProd(getTileCosts(
// best_cost += cost_coeff.dotProd(getTileCosts(
// nSurfTile1, // int nSurfTile,
// tileLayers, // int [][] tileLayers,
// null)); // HashMap<Point,Integer> replacements);
TACosts ta_costs = getTileCosts(
nSurfTile1, // int nSurfTile,
tileLayers, // int [][] tileLayers,
null)); // HashMap<Point,Integer> replacements);
null); // HashMap<Point,Integer> replacements);
double ccost = cost_coeff.dotProd(ta_costs);
best_cost += ccost;
if (dl > 2){
System.out.println("optimizeAssignment25(), nSurfTile = "+nSurfTile+" dir = "+dir +
" nSurfTile1="+nSurfTile1+" ccost = "+ccost+" best_cost="+best_cost);
System.out.println("ta_costs["+nSurfTile1+"]="+ta_costs.toString());
}
}
}
// int [] initial_indices = tileLayers[nSurfTile].clone();
......@@ -1299,13 +1344,23 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
}
}
double cost = 0.0;
for (int dir = 0; dir <9; dir++) {
if (dl > 2) {
System.out.println("optimizeAssignment25(), surfaces[0]= " + surfaces[0]);
}
for (int dir = 0; dir < 9; dir++) {
int nSurfTile1 = tnSurface.getNeibIndex(nSurfTile, dir);
if (nSurfTile1 >= 0){
cost += cost_coeff.dotProd(getTileCosts(
TACosts ta_costs = getTileCosts(
nSurfTile1, // int nSurfTile,
tileLayers, // int [][] tileLayers,
null)); // HashMap<Point,Integer> replacements);
null); // HashMap<Point,Integer> replacements);
double ccost = cost_coeff.dotProd(ta_costs);
cost+=ccost;
if (dl > 2){
System.out.println("optimizeAssignment25(), nSurfTile = "+nSurfTile+" dir = "+dir +
" nSurfTile1="+nSurfTile1+" ccost = "+ccost+" cost="+cost);
System.out.println("ta_costs["+nSurfTile1+"]="+ta_costs.toString());
}
}
}
if (cost < best_cost) {
......
......@@ -5189,10 +5189,88 @@ public class TilePlanes {
return wnd;
}
public boolean isWeakForeground(
final PlaneData fg_plane,
// final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
final int outliers, // remove any glitches?
double min_fg_strength,
final int debugLevel)
{
double [][] bg_ds = getDoublePlaneDisparityStrength(
false, // boolean useWorld,
null, // double [] window,
-1, // int dir,
false, // boolean use_sel,
false, // boolean divide_by_area,
1.0, // double scale_projection,
0.0, // double fraction_uni,
0); // int debugLevel)
double [][] fg_ds = fg_plane.getDoublePlaneDisparityStrength(
false, // boolean useWorld,
null, // double [] window,
-1, // int dir,
false, // boolean use_sel,
false, // boolean divide_by_area,
1.0, // double scale_projection,
0.0, // double fraction_uni,
0); // int debugLevel)
boolean [][] fg_sel = fg_plane.getMeasSelection();
for (int ml = 0; ml < fg_sel.length; ml++) if (fg_sel[ml] != null){ // if ((stMeasSel & ( 1 << ml)) != 0){
for (int indx = 0; indx < bg_ds[0].length; indx++) if (fg_sel[ml][indx]) {
if (fg_ds[0][indx] < bg_ds[0][indx]) {
return false; // not a foreground
}
}
}
// it is foreground, now get measured data and find maximal strength (remove outlayers?
double [] lap_weights = measuredLayers.getLapWeights1d();
double [][][] disp_strength = new double[measuredLayers.getNumLayers()][][];
for (int ml = 0; ml < disp_strength.length; ml++) if (fg_sel[ml] != null){ // if ((stMeasSel & ( 1 << ml)) != 0) {
if (smplMode) {
disp_strength[ml] = measuredLayers.getDisparityStrength( // expensive to calculate (improve removing outlayers
ml, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
null, // boolean [] sel_in, - use all
strength_floor,
measured_strength_pow, //
smplSide, // = 2; // Sample size (side of a square)
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
true); // boolean null_if_none)
} else {
disp_strength[ml] = measuredLayers.getDisparityStrength(
ml, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
null, // boolean [] sel_in, - use all
strength_floor, // double strength_floor,
measured_strength_pow, // double strength_pow,
true); // boolean null_if_none);
}
}
ArrayList<Double> fg_strengths = new ArrayList<Double>();
for (int ml = 0; ml < disp_strength.length; ml++) if (fg_sel[ml] != null){ // if ((stMeasSel & ( 1 << ml)) != 0) {
double [] strength = disp_strength[ml][1];
for (int indx = 0; indx < strength.length; indx ++) if (fg_sel[ml][indx]) {
fg_strengths.add(strength[indx]/lap_weights[indx]); // strengths were already masked by a window
}
}
if (fg_strengths.isEmpty()){
return true; // should not happen, but it is OK to merge empty plane
}
Collections.sort(fg_strengths);
int indx = fg_strengths.size() - outliers -1;
if (indx < 0) indx = 0;
if (debugLevel > 0) {
if (fg_strengths.get(indx) >= min_fg_strength) {
System.out.println("strong pair: "+fg_strengths.get(indx)+" >= "+min_fg_strength);
} else {
System.out.println("weak pair: "+fg_strengths.get(indx)+" < "+min_fg_strength);
}
}
return (fg_strengths.get(indx) < min_fg_strength);
}
}
}
......@@ -3839,7 +3839,7 @@ public class TileProcessor {
lp.conditionSuperTiles(
st.planes, // final TilePlanes.PlaneData [][] planes,
10, // final int max_num_merge_try,
0); // debugLevel); // final int debugLevel);
1); // debugLevel); // final int debugLevel);
// Used only by conflicts (not processed currently)
lp.calcStarValueStrength(
true, // boolean set_start_planes,
......@@ -3912,7 +3912,7 @@ public class TileProcessor {
2, // starSteps, // final int steps,
st.planes, // final TilePlanes.PlaneData [][] planes,
clt_parameters.plPreferDisparity, // preferDisparity, // final boolean preferDisparity)
debugLevel - 2);
debugLevel); // - 2);
}
......
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