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();
......
......@@ -67,6 +67,10 @@ public class LinkPlanes {
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 only 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
......@@ -147,6 +151,10 @@ public class LinkPlanes {
plConflSngl = clt_parameters.plConflSngl;
plConflSnglPair = clt_parameters.plConflSnglPair;
plWeakFgStrength = clt_parameters.plWeakFgStrength;
plWeakFgOutliers = clt_parameters.plWeakFgOutliers;
plWeakFgRelax = clt_parameters.plWeakFgRelax;
plThickWorld = clt_parameters.plThickWorld;
plThickWorldConfl = clt_parameters.plThickWorldConfl;
plRelaxComplete = clt_parameters.plRelaxComplete;
......@@ -1976,7 +1984,7 @@ public class LinkPlanes {
if ((dl > 1) && (nsTile == debug_stile)){
System.out.println("filterMergeSameTileCandidates().2: nsTile="+nsTile);
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
sdfa_instance.showArrays(plane_strengths, 2 * superTileSize, 2* superTileSize, true, "planes_"+nsTile);
sdfa_instance.showArrays(plane_strengths, 2 * superTileSize, 2* superTileSize, true, "filterMergeSameTileCandidates_"+nsTile);
}
......@@ -2103,7 +2111,7 @@ public class LinkPlanes {
if ((dl > 1) && (nsTile == debug_stile)){
System.out.println("overlapSameTileCandidates().2: nsTile="+nsTile);
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
sdfa_instance.showArrays(plane_strengths, 2 * superTileSize, 2* superTileSize, true, "planes_"+nsTile);
sdfa_instance.showArrays(plane_strengths, 2 * superTileSize, 2* superTileSize, true, "overlapSameTileCandidates_"+nsTile);
}
for (int np1 = 0; np1 < planes[nsTile].length; np1++) if (planes[nsTile][np1] != null){
for (int np2 = np1 + 1; np2 < planes[nsTile].length; np2++) if (planes[nsTile][np2] != null){
......@@ -2372,6 +2380,73 @@ public class LinkPlanes {
return valid_candidates;
}
// TODO: also evaluate background hiding behind hole in the with no edge?
public boolean[][] weakForeground(
final TilePlanes.PlaneData [][] planes,
final int [][][] merge_candidates,
final boolean [][][] valid_candidates, // will be updated
// final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
final double min_fg_strength,
final int outliers, // remove any glitches?
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final int tilesX = st.tileProcessor.getTilesX();
final int tilesY = st.tileProcessor.getTilesY();
final int superTileSize = st.tileProcessor.getSuperTileSize();
// final int tileSize = tileProcessor.getTileSize();
final int stilesX = (tilesX + superTileSize -1)/superTileSize;
final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final int nStiles = stilesX * stilesY;
// final double [][][][][][] merged_neib_ev = new double [nStiles][][][][][];
final int debug_stile = dbg_Y * stilesX + dbg_X;
final Thread[] threads = ImageDtt.newThreadArray((debugLevel > 1)? 1 : st.tileProcessor.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final boolean [][] weak_fgnd = new boolean [valid_candidates.length][];
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nsTile = ai.getAndIncrement(); nsTile < nStiles; nsTile = ai.getAndIncrement()) if ( merge_candidates[nsTile] != null) {
int dl = ((debugLevel > 1) && (nsTile == debug_stile)) ? 3: debugLevel;
if (dl > 2){
System.out.println("weakForeground(): nsTile="+nsTile);
}
int n_planes = planes[nsTile].length;
weak_fgnd[nsTile] = new boolean [merge_candidates[nsTile].length];
for (int nPair = 0; nPair < merge_candidates[nsTile].length; nPair++) {
int [] pair = merge_candidates[nsTile][nPair];
if (valid_candidates[nsTile][pair[0]][pair[1]]){
boolean weakfg = planes[nsTile][pair[0]].isWeakForeground(
planes[nsTile][pair[1]], // final PlaneData fg_plane,
//stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
outliers, // final int outliers, // remove any glitches?
min_fg_strength, // double min_fg_strength);
dl);
weakfg |= planes[nsTile][pair[1]].isWeakForeground(
planes[nsTile][pair[0]], // final PlaneData fg_plane,
//stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
outliers, // final int outliers, // remove any glitches?
min_fg_strength, // double min_fg_strength);
dl);
weak_fgnd[nsTile][nPair] = weakfg;
if (debugLevel > 0) {
if (weakfg && (debugLevel > 0)) {
System.out.println(nsTile+":"+pair[0]+":"+pair[1]+" is a WEAK foreground pair");
}else if (debugLevel > 1) {
System.out.println(nsTile+":"+pair[0]+":"+pair[1]+" is NOT a weak foreground pair");
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return weak_fgnd;
}
/**
* Possible problem is that "normalizing" merge quality for low weights is not applicable for "star" plane that include neighbors
......@@ -2391,7 +2466,9 @@ public class LinkPlanes {
final TilePlanes.PlaneData [][] planes,
final int [][][] merge_candidates,
final boolean [][][] valid_candidates, // will be updated
final boolean [][] weak_fg_pairs,
final double relax,
final double relax_weak_fg,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -2418,17 +2495,28 @@ public class LinkPlanes {
System.out.println("costSameTileConnections(): nsTile="+nsTile0);
}
int n_planes = planes[nsTile0].length;
boolean [][] weak_fg = new boolean [n_planes][n_planes];
if ((weak_fg_pairs != null) && (weak_fg_pairs[nsTile0] != null)) {
for (int i = 0; i < merge_candidates[nsTile0].length; i++) {
weak_fg[merge_candidates[nsTile0][i][0]][merge_candidates[nsTile0][i][1]] = true;
weak_fg[merge_candidates[nsTile0][i][1]][merge_candidates[nsTile0][i][0]] = true;
}
}
// overlap_merge_candidates[nsTile] = new boolean [n_planes][n_planes];
merged_neib_ev[nsTile0] = new double [n_planes][n_planes][4][][];
// get original directions
for (int np1 = 0; np1 < planes[nsTile0].length; np1++) if (planes[nsTile0][np1] != null){
for (int np2 = np1 + 1; np2 < planes[nsTile0].length; np2++) if (planes[nsTile0][np2] != null){
if (valid_candidates[nsTile0][np1][np2]) { // only check pair considered valid
double var_relax = relax;
if (weak_fg[np1][np2]){
var_relax *= relax_weak_fg;
}
String prefix = "costSameTileConnections() fit weighted: nsTile0="+nsTile0+" np1="+np1+" np2="+np2;
boolean fit1 = planesFit(
planes[nsTile0][np1].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane2,
relax, // double relax,
var_relax, //relax, // double relax,
true, // boolean merge_weak, // use for same supertile merge
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
......@@ -2440,7 +2528,7 @@ public class LinkPlanes {
boolean fit2 = planesFit(
planes[nsTile0][np1].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane2,
relax, // double relax,
var_relax, // relax, // double relax,
true, // boolean merge_weak, // use for same supertile merge
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
......@@ -2454,12 +2542,14 @@ public class LinkPlanes {
valid_candidates[nsTile0][np2][np1] = false;
if (dl > 0){
System.out.println("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+
(weak_fg[np1][np2]? " WEAK_FG_PAIR":"") +
" REMOVING PAIR, fit1="+fit1+" fit2="+fit2);
}
} else {
if (dl > 0){
System.out.println("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+
(weak_fg[np1][np2]? " WEAK_FG_PAIR":"") +
" KEEPING PAIR, fit1="+fit1+" fit2="+fit2);
}
......@@ -2665,6 +2755,8 @@ public class LinkPlanes {
final TilePlanes.PlaneData [][] planes,
final int [][][] merge_candidates,
final boolean [][][] valid_candidates, // will be updated
final boolean [][] weak_fg_pairs,
final double relax_weak_fg,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -2691,7 +2783,13 @@ public class LinkPlanes {
System.out.println("costSameTileConnectionsAlt(): nsTile="+nsTile0);
}
int n_planes = planes[nsTile0].length;
// overlap_merge_candidates[nsTile] = new boolean [n_planes][n_planes];
boolean [][] weak_fg = new boolean [n_planes][n_planes];
if ((weak_fg_pairs != null) && (weak_fg_pairs[nsTile0] != null)) {
for (int i = 0; i < merge_candidates[nsTile0].length; i++) {
weak_fg[merge_candidates[nsTile0][i][0]][merge_candidates[nsTile0][i][1]] = true;
weak_fg[merge_candidates[nsTile0][i][1]][merge_candidates[nsTile0][i][0]] = true;
}
}
merged_neib_ev[nsTile0] = new double [n_planes][n_planes][4][][];
// get original directions
for (int np1 = 0; np1 < planes[nsTile0].length; np1++) if (planes[nsTile0][np1] != null){
......@@ -2725,19 +2823,31 @@ public class LinkPlanes {
dl - 1); // int debugLevel)
boolean star1 = (planes[nsTile0][np1].getNonexclusiveStar() != null) && (planes[nsTile0][np2].getNonexclusiveStar() != null);
boolean star2 = (planes[nsTile0][np1].getNonexclusiveStarEq() != null) && (planes[nsTile0][np2].getNonexclusiveStarEq() != null);
boolean fit1 = costs[0] < (star1 ? threshold : threshold_nostar);
boolean fit2 = costs[1] < (star2 ? threshold : threshold_nostar);
double ts = threshold;
double tns = threshold_nostar;
if (weak_fg[np1][np2]){
ts *= relax_weak_fg;
tns *= relax_weak_fg;
}
// boolean fit1 = costs[0] < (star1 ? threshold : threshold_nostar);
// boolean fit2 = costs[1] < (star2 ? threshold : threshold_nostar);
boolean fit1 = costs[0] < (star1 ? ts : tns);
boolean fit2 = costs[1] < (star2 ? ts : tns);
// if (!fit1 || !fit2){
if (!fit1 && !fit2){
valid_candidates[nsTile0][np1][np2] = false;
valid_candidates[nsTile0][np2][np1] = false;
if (dl > 0){
System.out.println("costSameTileConnectionsAlt(): nsTile="+nsTile0+":"+np1+":"+np2+
(weak_fg[np1][np2]? " WEAK_FG_PAIR":"") +
" REMOVING PAIR, fit1="+fit1+" fit2="+fit2+ " (star1="+star1+", star2="+star2+")");
}
} else {
if (dl > 0){
System.out.println("costSameTileConnectionsAlt(): nsTile="+nsTile0+":"+np1+":"+np2+
(weak_fg[np1][np2]? " WEAK_FG_PAIR":"") +
" KEEPING PAIR, fit1="+fit1+" fit2="+fit2+ " (star1="+star1+", star2="+star2+")");
}
}
......@@ -3685,6 +3795,18 @@ public class LinkPlanes {
dbg_tileX,
dbg_tileY);
boolean[][] weak_pairs = weakForeground(
planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
valid_candidates, // final boolean [][][] valid_candidates,
// final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plWeakFgStrength, // final double min_fg_strength,
plWeakFgOutliers, // final int outliers, // remove any glitches?
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
// * Possible problem is that "normalizing" merge quality for low weights is not applicable for "star" plane that includes neighhbors
// * Switch to a single "cost" function (costSameTileConnectionsAlt())
// Still - how to merge stray tiles that do not have neighbors/star? Still merge them "old way" (costSameTileConnections()) if at least 1 does not
......@@ -3695,9 +3817,11 @@ public class LinkPlanes {
// TODO: Switch to a single "cost" function (costSameTileConnectionsAlt())
costSameTileConnections(
planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
merge_candidates, // final int [][][] merge_candidates,
valid_candidates, // final boolean [][][] valid_candidates, // will be updated
1.0, // double relax,
weak_pairs, // final boolean [][] weak_fg_pairs,
1.0, // double relax,
plWeakFgRelax, // final double relax_weak_fg,
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
......@@ -3712,6 +3836,8 @@ public class LinkPlanes {
planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
valid_candidates, // final boolean [][][] valid_candidates, // will be updated
weak_pairs, // final boolean [][] weak_fg_pairs,
plWeakFgRelax, // final double relax_weak_fg,
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
......@@ -4208,6 +4334,17 @@ public class LinkPlanes {
merge_candidates, // final int [][][] merge_candidates,
conflicts0); // final int [][][] conflicts)
boolean[][] weak_pairs = weakForeground(
planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
valid_candidates, // final boolean [][][] valid_candidates,
// final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plWeakFgStrength, // final double min_fg_strength,
plWeakFgOutliers, // final int outliers, // remove any glitches?
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
// * Possible problem is that "normalizing" merge quality for low weights is not applicable for "star" plane that include neighhbors
// * Switch to a single "cost" function (costSameTileConnectionsAlt())
......@@ -4217,7 +4354,9 @@ public class LinkPlanes {
planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
valid_candidates, // final boolean [][][] valid_candidates, // will be updated
weak_pairs, // final boolean [][] weak_fg_pairs,
1.0, // final double relax,
plWeakFgRelax, // final double relax_weak_fg,
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
......@@ -4225,10 +4364,12 @@ public class LinkPlanes {
costSameTileConnectionsAlt(
getMergeCostStar(), // relax_for_conflicts * 5.0, // final double threshold, //
getMergeCostNoStar(), //relax_for_conflicts * 10.0, // final double threshold_nostar,
planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
valid_candidates, // final boolean [][][] valid_candidates, // will be updated
debugLevel, // final int debugLevel)
planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
valid_candidates, // final boolean [][][] valid_candidates, // will be updated
weak_pairs, // final boolean [][] weak_fg_pairs,
plWeakFgRelax, // final double relax_weak_fg,
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
......@@ -4288,13 +4429,25 @@ public class LinkPlanes {
dbg_tileY);
// again same sequence
boolean [][] confl_weak_pairs = weakForeground(
planes, // final TilePlanes.PlaneData [][] planes,
conflicting_candidates, // final int [][][] merge_candidates,
valid_candidates, // final boolean [][][] valid_candidates,
// final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plWeakFgStrength, // final double min_fg_strength,
plWeakFgOutliers, // final int outliers, // remove any glitches?
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
// try to merge original (measured) planes, not smoothed ones ??
costSameTileConnections(
planes, // final TilePlanes.PlaneData [][] planes,
conflicting_candidates, // final int [][][] merge_candidates,
valid_candidates, // final boolean [][][] valid_candidates, // will be updated
getConflRelax(), //relax_for_conflicts, // final double relax,
confl_weak_pairs, // final boolean [][] weak_fg_pairs,
getConflRelax(), // relax_for_conflicts, // final double relax,
plWeakFgRelax, // final double relax_weak_fg,
debugLevel, // 2, // -1, // debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
......@@ -4304,8 +4457,10 @@ public class LinkPlanes {
getConflRelax() * getMergeCostNoStar(), //relax_for_conflicts * 10.0, // final double threshold_nostar,
planes, // final TilePlanes.PlaneData [][] planes,
conflicting_candidates, // final int [][][] merge_candidates,
valid_candidates, // final boolean [][][] valid_candidates, // will be updated
conflicting_candidates, // final int [][][] merge_candidates,
valid_candidates, // final boolean [][][] valid_candidates, // will be updated
confl_weak_pairs, // final boolean [][] weak_fg_pairs,
plWeakFgRelax, // final double relax_weak_fg,
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
......
......@@ -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
......@@ -876,7 +898,11 @@ 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;
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