Commit 38475568 authored by Andrey Filippov's avatar Andrey Filippov

filtering supertiles connections

parent be191b98
...@@ -72,7 +72,29 @@ public class ConnectionCosts { ...@@ -72,7 +72,29 @@ public class ConnectionCosts {
this.steps = steps; this.steps = steps;
} }
public int [][][] setStarValues( // also initConnectionCosts()
int [] nsTiles,
int debugLevel)
{
return initConnectionCosts(
true, // boolean set_start_planes,
nsTiles,
debugLevel);
}
public int [][][] initConnectionCosts(
int [] nsTiles,
int debugLevel)
{
return initConnectionCosts(
false, // boolean set_start_planes,
nsTiles,
debugLevel);
}
public int [][][] initConnectionCosts( public int [][][] initConnectionCosts(
boolean set_start_planes,
int [] nsTiles, int [] nsTiles,
int debugLevel) int debugLevel)
{ {
...@@ -115,16 +137,19 @@ public class ConnectionCosts { ...@@ -115,16 +137,19 @@ public class ConnectionCosts {
switch (steps){ switch (steps){
case 1: case 1:
val_weights = getConnectionsCostSingleStep ( val_weights = getConnectionsCostSingleStep (
set_start_planes,
null, null,
debugLevel - 1); // int debugLevel) debugLevel - 1); // int debugLevel)
break; break;
case 2: case 2:
val_weights = getConnectionsCostDualStep ( val_weights = getConnectionsCostDualStep (
set_start_planes,
null, null,
debugLevel - 1); // int debugLevel) debugLevel - 1); // int debugLevel)
break; break;
default: default:
val_weights = getConnectionsCostSingleStep ( val_weights = getConnectionsCostSingleStep (
set_start_planes,
null, null,
debugLevel - 1); // int debugLevel) debugLevel - 1); // int debugLevel)
} }
...@@ -155,6 +180,9 @@ public class ConnectionCosts { ...@@ -155,6 +180,9 @@ public class ConnectionCosts {
return neibs_init; // neighbors to clone return neibs_init; // neighbors to clone
} }
public double [] getValWeightLast( public double [] getValWeightLast(
int nsTile, int nsTile,
int nl, int nl,
...@@ -186,6 +214,7 @@ public class ConnectionCosts { ...@@ -186,6 +214,7 @@ public class ConnectionCosts {
} }
public double [][][] getConnectionsCostSingleStep ( public double [][][] getConnectionsCostSingleStep (
boolean set_start_planes,
int [][][] neibs, int [][][] neibs,
int debugLevel) int debugLevel)
{ {
...@@ -211,6 +240,23 @@ public class ConnectionCosts { ...@@ -211,6 +240,23 @@ public class ConnectionCosts {
} }
} }
if (neibs_changed){ if (neibs_changed){
TilePlanes.PlaneData star_plane = getStarPlane(
nsTile,
nl,
neibs[isTile][nl],
orthoWeight,
diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
starWeightPwr,
tnSurface,
preferDisparity,
-1); // debugLevel);
if (set_start_planes){
planes[nsTile][nl].setStarPlane(star_plane);
}
vw[isTile][nl] = star_plane.getStarValueWeightDensity();
/*
vw[isTile][nl] = getStarValueWeight( vw[isTile][nl] = getStarValueWeight(
nsTile, nsTile,
nl, nl,
...@@ -222,6 +268,7 @@ public class ConnectionCosts { ...@@ -222,6 +268,7 @@ public class ConnectionCosts {
tnSurface, tnSurface,
preferDisparity, preferDisparity,
-1); // debugLevel); -1); // debugLevel);
*/
} else { } else {
vw[isTile][nl] = val_weights[isTile][nl]; vw[isTile][nl] = val_weights[isTile][nl];
} }
...@@ -238,6 +285,7 @@ public class ConnectionCosts { ...@@ -238,6 +285,7 @@ public class ConnectionCosts {
} }
public double [][][] getConnectionsCostDualStep ( public double [][][] getConnectionsCostDualStep (
boolean set_start_planes,
int [][][] neibs, int [][][] neibs,
int debugLevel) int debugLevel)
{ {
...@@ -270,17 +318,6 @@ public class ConnectionCosts { ...@@ -270,17 +318,6 @@ public class ConnectionCosts {
int ineib1 = (tile_map.containsKey(nsTile1))? tile_map.get(nsTile1) : -1; int ineib1 = (tile_map.containsKey(nsTile1))? tile_map.get(nsTile1) : -1;
neibs2[dir] = (ineib1 >=0) ? neibs[tile_map.get(nsTile1)][nl1] : planes[nsTile1][nl1].getNeibBest(); neibs2[dir] = (ineib1 >=0) ? neibs[tile_map.get(nsTile1)][nl1] : planes[nsTile1][nl1].getNeibBest();
if (!neibs_changed && (ineib1 >= 0)) { if (!neibs_changed && (ineib1 >= 0)) {
/*
if ((neibs_init[ineib1] == null) || (neibs_init[ineib1][nl1] == null)) {
neibs_changed = true;
} else {
for (int dir1 = 0; dir1 < 8; dir1++) if (neibs[ineib1][nl1][dir1] != neibs_init[ineib1][nl1][dir1]){
neibs_changed = true;
break;
}
}
*/
if ((neibs_init[ineib1] == null) || (neibs[ineib1][nl1] == null)) { if ((neibs_init[ineib1] == null) || (neibs[ineib1][nl1] == null)) {
neibs_changed = true; neibs_changed = true;
} else { } else {
...@@ -294,6 +331,23 @@ public class ConnectionCosts { ...@@ -294,6 +331,23 @@ public class ConnectionCosts {
} }
if (neibs_changed){ if (neibs_changed){
TilePlanes.PlaneData star_plane = getStarPlane2(
nsTile,
nl,
neibs0,
neibs2,
orthoWeight,
diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
starWeightPwr, //
tnSurface,
preferDisparity,
-1); // debugLevel);
if (set_start_planes){
planes[nsTile][nl].setStarPlane(star_plane);
}
vw[isTile][nl] = star_plane.getStarValueWeightDensity();
/*
vw[isTile][nl] = getStarValueWeight2( vw[isTile][nl] = getStarValueWeight2(
nsTile, nsTile,
nl, nl,
...@@ -306,6 +360,7 @@ public class ConnectionCosts { ...@@ -306,6 +360,7 @@ public class ConnectionCosts {
tnSurface, tnSurface,
preferDisparity, preferDisparity,
-1); // debugLevel); -1); // debugLevel);
*/
} else { } else {
vw[isTile][nl] = val_weights[isTile][nl]; vw[isTile][nl] = val_weights[isTile][nl];
} }
...@@ -360,16 +415,19 @@ public class ConnectionCosts { ...@@ -360,16 +415,19 @@ public class ConnectionCosts {
switch (steps){ switch (steps){
case 1: case 1:
vw = getConnectionsCostSingleStep ( vw = getConnectionsCostSingleStep (
false,
neibs, neibs,
debugLevel-1); // int debugLevel) debugLevel-1); // int debugLevel)
break; break;
case 2: case 2:
vw = getConnectionsCostDualStep ( vw = getConnectionsCostDualStep (
false,
neibs, neibs,
debugLevel-1); // int debugLevel) debugLevel-1); // int debugLevel)
break; break;
default: default:
vw = getConnectionsCostSingleStep ( vw = getConnectionsCostSingleStep (
false,
neibs, neibs,
debugLevel-1); // int debugLevel) debugLevel-1); // int debugLevel)
} }
...@@ -426,6 +484,31 @@ public class ConnectionCosts { ...@@ -426,6 +484,31 @@ public class ConnectionCosts {
TileSurface.TileNeibs tnSurface, TileSurface.TileNeibs tnSurface,
boolean preferDisparity, boolean preferDisparity,
int debugLevel) int debugLevel)
{
return getStarPlane(
nsTile,
nl,
neibs,
orthoWeight,
diagonalWeight,
starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
tnSurface,
preferDisparity,
debugLevel).getStarValueWeightDensity();
}
TilePlanes.PlaneData getStarPlane(
int nsTile,
int nl,
int [] neibs,
double orthoWeight,
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
TileSurface.TileNeibs tnSurface,
boolean preferDisparity,
int debugLevel)
{ {
TilePlanes.PlaneData merged_plane = planes[nsTile][nl]; // add weight TilePlanes.PlaneData merged_plane = planes[nsTile][nl]; // add weight
double conn_weight = 1.0; // center weight double conn_weight = 1.0; // center weight
...@@ -450,9 +533,11 @@ public class ConnectionCosts { ...@@ -450,9 +533,11 @@ public class ConnectionCosts {
if (starPwr != 0){ if (starPwr != 0){
value_weight[0] /= (Math.pow((planes[nsTile][nl].getNumNeibBest() + 1.0), starPwr)); value_weight[0] /= (Math.pow((planes[nsTile][nl].getNumNeibBest() + 1.0), starPwr));
} }
return value_weight; merged_plane.setStarValueWeight(value_weight);
return merged_plane;
} }
/** /**
* Calculate main eigenvalue of the current plane and all connected ones - used to estimate advantage of connection swap * Calculate main eigenvalue of the current plane and all connected ones - used to estimate advantage of connection swap
* This version uses two steps - not only directly connected, but neighbors' neighbors also, multiple paths to the same * This version uses two steps - not only directly connected, but neighbors' neighbors also, multiple paths to the same
...@@ -484,6 +569,34 @@ public class ConnectionCosts { ...@@ -484,6 +569,34 @@ public class ConnectionCosts {
TileSurface.TileNeibs tnSurface, TileSurface.TileNeibs tnSurface,
boolean preferDisparity, boolean preferDisparity,
int debugLevel) int debugLevel)
{
return getStarPlane2(
nsTile,
nl,
neibs,
neibs2, // neighbors' neighbors
orthoWeight,
diagonalWeight,
starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
tnSurface,
preferDisparity,
debugLevel).getStarValueWeightDensity();
}
TilePlanes.PlaneData getStarPlane2(
int nsTile,
int nl,
int [] neibs,
int [][] neibs2, // neighbors' neighbors
double orthoWeight,
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
TileSurface.TileNeibs tnSurface,
boolean preferDisparity,
int debugLevel)
{ {
double [] dir_weight = {orthoWeight, diagonalWeight, orthoWeight, diagonalWeight, orthoWeight, diagonalWeight, orthoWeight, diagonalWeight}; double [] dir_weight = {orthoWeight, diagonalWeight, orthoWeight, diagonalWeight, orthoWeight, diagonalWeight, orthoWeight, diagonalWeight};
HashMap<Point, Double> tile_weights = new HashMap<Point, Double>(); HashMap<Point, Double> tile_weights = new HashMap<Point, Double>();
...@@ -529,9 +642,13 @@ public class ConnectionCosts { ...@@ -529,9 +642,13 @@ public class ConnectionCosts {
if (starPwr != 0){ if (starPwr != 0){
value_weight[0] /= (Math.pow(tile_weights.size() + 1.0, starPwr)); value_weight[0] /= (Math.pow(tile_weights.size() + 1.0, starPwr));
} }
return value_weight; merged_plane.setStarValueWeight(value_weight);
return merged_plane;
} }
/** /**
* Calculate array of supertile indices that need to have connection cost recalculated when they are updated * Calculate array of supertile indices that need to have connection cost recalculated when they are updated
* first entries of the result will be the same in input array * first entries of the result will be the same in input array
......
...@@ -2179,10 +2179,22 @@ public class EyesisCorrectionParameters { ...@@ -2179,10 +2179,22 @@ public class EyesisCorrectionParameters {
public double plMaxWorldSin2 = 0.1; // Maximal sine squared of the world angle between planes to merge. Set to >= 1.0 to disable public double plMaxWorldSin2 = 0.1; // Maximal sine squared of the world angle between planes to merge. Set to >= 1.0 to disable
public double plWeakWorsening = 1.0; // Relax merge requirements for weaker planes public double plWeakWorsening = 1.0; // Relax merge requirements for weaker planes
public double plMaxOverlap = 0.1; // Maximal overlap between the same supertile planes to merge public double plMaxOverlap = 0.1; // Maximal overlap between the same supertile planes to merge
// Merge same supetile planes if at least one is weak and they do not differ much
public double plWeakWeight = 0.2 ; // Maximal weight of the weak plane to merge
public double plWeakEigen = 0.1; // Maximal eigenvalue of the result of non-weighted merge
public double plWeakWeight2 = 10.0 ; // Maximal weight of the weak plane to merge (second variant)
public double plWeakEigen2 = 0.05; // Maximal eigenvalue of the result of non-weighted merge (second variant)
public double plMaxZRatio = 2.0; // Maximal ratio of Z to allow plane merging
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 livel not less than
// comparing merge quality for plane pairs // comparing merge quality for plane pairs
public double plCostKrq = 0.8; // cost of merge quality weighted public double plCostKrq = 0.8; // cost of merge quality weighted in disparity space
public double plCostKrqEq = 0.2; // cost of merge quality equal weight public double plCostKrqEq = 0.2; // cost of merge quality equal weight in disparity space
public double plCostWrq = 0.8; // cost of merge quality weighted in world space
public double plCostWrqEq = 0.2; // cost of merge quality equal weight in world space
public double plCostSin2 = 10.0; // cost of sin squared between normals public double plCostSin2 = 10.0; // cost of sin squared between normals
public double plCostRdist2 =1000.0; // cost of squared relative distances public double plCostRdist2 =1000.0; // cost of squared relative distances
...@@ -2556,8 +2568,20 @@ public class EyesisCorrectionParameters { ...@@ -2556,8 +2568,20 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plWeakWorsening", this.plWeakWorsening +""); properties.setProperty(prefix+"plWeakWorsening", this.plWeakWorsening +"");
properties.setProperty(prefix+"plMaxOverlap", this.plMaxOverlap +""); properties.setProperty(prefix+"plMaxOverlap", this.plMaxOverlap +"");
properties.setProperty(prefix+"plWeakWeight", this.plWeakWeight +"");
properties.setProperty(prefix+"plWeakEigen", this.plWeakEigen +"");
properties.setProperty(prefix+"plWeakWeight2", this.plWeakWeight2 +"");
properties.setProperty(prefix+"plWeakEigen2", this.plWeakEigen2 +"");
properties.setProperty(prefix+"plMaxZRatio", this.plMaxZRatio +"");
properties.setProperty(prefix+"plMaxDisp", this.plMaxDisp +"");
properties.setProperty(prefix+"plCutTail", this.plCutTail +"");
properties.setProperty(prefix+"plMinTail", this.plMinTail +"");
properties.setProperty(prefix+"plCostKrq", this.plCostKrq +""); properties.setProperty(prefix+"plCostKrq", this.plCostKrq +"");
properties.setProperty(prefix+"plCostKrqEq", this.plCostKrqEq +""); properties.setProperty(prefix+"plCostKrqEq", this.plCostKrqEq +"");
properties.setProperty(prefix+"plCostWrq", this.plCostWrq +"");
properties.setProperty(prefix+"plCostWrqEq", this.plCostWrqEq +"");
properties.setProperty(prefix+"plCostSin2", this.plCostSin2 +""); properties.setProperty(prefix+"plCostSin2", this.plCostSin2 +"");
properties.setProperty(prefix+"plCostRdist2", this.plCostRdist2 +""); properties.setProperty(prefix+"plCostRdist2", this.plCostRdist2 +"");
...@@ -2909,8 +2933,20 @@ public class EyesisCorrectionParameters { ...@@ -2909,8 +2933,20 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plWeakWorsening")!=null) this.plWeakWorsening=Double.parseDouble(properties.getProperty(prefix+"plWeakWorsening")); if (properties.getProperty(prefix+"plWeakWorsening")!=null) this.plWeakWorsening=Double.parseDouble(properties.getProperty(prefix+"plWeakWorsening"));
if (properties.getProperty(prefix+"plMaxOverlap")!=null) this.plMaxOverlap=Double.parseDouble(properties.getProperty(prefix+"plMaxOverlap")); if (properties.getProperty(prefix+"plMaxOverlap")!=null) this.plMaxOverlap=Double.parseDouble(properties.getProperty(prefix+"plMaxOverlap"));
if (properties.getProperty(prefix+"plWeakWeight")!=null) this.plWeakWeight=Double.parseDouble(properties.getProperty(prefix+"plWeakWeight"));
if (properties.getProperty(prefix+"plWeakEigen")!=null) this.plWeakEigen=Double.parseDouble(properties.getProperty(prefix+"plWeakEigen"));
if (properties.getProperty(prefix+"plWeakWeight2")!=null) this.plWeakWeight2=Double.parseDouble(properties.getProperty(prefix+"plWeakWeight2"));
if (properties.getProperty(prefix+"plWeakEigen2")!=null) this.plWeakEigen2=Double.parseDouble(properties.getProperty(prefix+"plWeakEigen2"));
if (properties.getProperty(prefix+"plMaxZRatio")!=null) this.plMaxZRatio=Double.parseDouble(properties.getProperty(prefix+"plMaxZRatio"));
if (properties.getProperty(prefix+"plMaxDisp")!=null) this.plMaxDisp=Double.parseDouble(properties.getProperty(prefix+"plMaxDisp"));
if (properties.getProperty(prefix+"plCutTail")!=null) this.plCutTail=Double.parseDouble(properties.getProperty(prefix+"plCutTail"));
if (properties.getProperty(prefix+"plMinTail")!=null) this.plMinTail=Double.parseDouble(properties.getProperty(prefix+"plMinTail"));
if (properties.getProperty(prefix+"plCostKrq")!=null) this.plCostKrq=Double.parseDouble(properties.getProperty(prefix+"plCostKrq")); if (properties.getProperty(prefix+"plCostKrq")!=null) this.plCostKrq=Double.parseDouble(properties.getProperty(prefix+"plCostKrq"));
if (properties.getProperty(prefix+"plCostKrqEq")!=null) this.plCostKrqEq=Double.parseDouble(properties.getProperty(prefix+"plCostKrqEq")); if (properties.getProperty(prefix+"plCostKrqEq")!=null) this.plCostKrqEq=Double.parseDouble(properties.getProperty(prefix+"plCostKrqEq"));
if (properties.getProperty(prefix+"plCostWrq")!=null) this.plCostWrq=Double.parseDouble(properties.getProperty(prefix+"plCostWrq"));
if (properties.getProperty(prefix+"plCostWrqEq")!=null) this.plCostWrqEq=Double.parseDouble(properties.getProperty(prefix+"plCostWrqEq"));
if (properties.getProperty(prefix+"plCostSin2")!=null) this.plCostSin2=Double.parseDouble(properties.getProperty(prefix+"plCostSin2")); if (properties.getProperty(prefix+"plCostSin2")!=null) this.plCostSin2=Double.parseDouble(properties.getProperty(prefix+"plCostSin2"));
if (properties.getProperty(prefix+"plCostRdist2")!=null) this.plCostRdist2=Double.parseDouble(properties.getProperty(prefix+"plCostRdist2")); if (properties.getProperty(prefix+"plCostRdist2")!=null) this.plCostRdist2=Double.parseDouble(properties.getProperty(prefix+"plCostRdist2"));
...@@ -3290,9 +3326,23 @@ public class EyesisCorrectionParameters { ...@@ -3290,9 +3326,23 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Relax merge requirements for weaker planes", this.plWeakWorsening, 6); gd.addNumericField("Relax merge requirements for weaker planes", this.plWeakWorsening, 6);
gd.addNumericField("Maximal overlap between the same supertile planes to merge", this.plMaxOverlap, 6); gd.addNumericField("Maximal overlap between the same supertile planes to merge", this.plMaxOverlap, 6);
gd.addMessage ("--- Merge same supetile planes if at least one is weak and they do not differ much ---");
gd.addNumericField("Maximal weight of the weak plane to merge (first variant)", this.plWeakWeight, 6);
gd.addNumericField("Maximal eigenvalue of the result of non-weighted merge (first variant)", this.plWeakEigen, 6);
gd.addNumericField("Maximal weight of the weak plane to merge (second variant)", this.plWeakWeight2, 6);
gd.addNumericField("Maximal eigenvalue of the result of non-weighted merge (second variant)", this.plWeakEigen2, 6);
gd.addMessage ("--- ---");
gd.addNumericField("Maximal ratio of Z to allow plane merging", this.plMaxZRatio, 6);
gd.addNumericField("Maximal disparity of one of the planes to apply maximal ratio", this.plMaxDisp, 6);
gd.addNumericField("When merging with neighbors cut the tail that is worse than scaled best", this.plCutTail, 6);
gd.addNumericField("Set cutoff value livel not less than this", this.plMinTail, 6);
gd.addMessage ("--- Planes merge costs ---"); gd.addMessage ("--- Planes merge costs ---");
gd.addNumericField("Cost of merge quality weighted", this.plCostKrq, 6); gd.addNumericField("Cost of merge quality weighted in disparity space", this.plCostKrq, 6);
gd.addNumericField("Cost of merge quality equal weight", this.plCostKrqEq, 6); gd.addNumericField("Cost of merge quality equal weight in disparity space", this.plCostKrqEq, 6);
gd.addNumericField("Cost of merge quality weighted in world space", this.plCostWrq, 6);
gd.addNumericField("Cost of merge quality equal weight in world space", this.plCostWrqEq, 6);
gd.addNumericField("Cost of sin squared between normals", this.plCostSin2, 6); gd.addNumericField("Cost of sin squared between normals", this.plCostSin2, 6);
gd.addNumericField("Cost of squared relative plane-to-other-center distances", this.plCostRdist2, 6); gd.addNumericField("Cost of squared relative plane-to-other-center distances", this.plCostRdist2, 6);
...@@ -3657,8 +3707,20 @@ public class EyesisCorrectionParameters { ...@@ -3657,8 +3707,20 @@ public class EyesisCorrectionParameters {
this.plWeakWorsening= gd.getNextNumber(); this.plWeakWorsening= gd.getNextNumber();
this.plMaxOverlap= gd.getNextNumber(); this.plMaxOverlap= gd.getNextNumber();
this.plWeakWeight= gd.getNextNumber();
this.plWeakEigen= gd.getNextNumber();
this.plWeakWeight2= gd.getNextNumber();
this.plWeakEigen2= gd.getNextNumber();
this.plMaxZRatio= gd.getNextNumber();
this.plMaxDisp= gd.getNextNumber();
this.plCutTail= gd.getNextNumber();
this.plMinTail= gd.getNextNumber();
this.plCostKrq= gd.getNextNumber(); this.plCostKrq= gd.getNextNumber();
this.plCostKrqEq= gd.getNextNumber(); this.plCostKrqEq= gd.getNextNumber();
this.plCostWrq= gd.getNextNumber();
this.plCostWrqEq= gd.getNextNumber();
this.plCostSin2= gd.getNextNumber(); this.plCostSin2= gd.getNextNumber();
this.plCostRdist2= gd.getNextNumber(); this.plCostRdist2= gd.getNextNumber();
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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