Commit a8e74029 authored by Andrey Filippov's avatar Andrey Filippov

added some filtereing to tiles-to-surfaces assignment

parent e3a23742
......@@ -2170,6 +2170,7 @@ public class EyesisCorrectionParameters {
public double plMaxEigen = 0.3; // Maximal eigenvalue of a plane
public boolean plDbgMerge = true; // Combine 'other' plane with current
public double plWorstWorsening = 3.0; // Worst case worsening after merge
public double plOKMergeEigen = 0.01; // If result of the merged planes is below, OK to bypass worst worsening
public double plWeakWorsening = 1.0; // Relax merge requirements for weaker planes
public boolean plMutualOnly = true; // keep only mutual links, remove weakest if conflict
public boolean plFillSquares = true; // Add diagonals to full squares
......@@ -2221,14 +2222,28 @@ public class EyesisCorrectionParameters {
public double tsMaxStrength = 10.0; // Maximal tile correlation strength to be assigned
public double tsMinSurface = 0.0001; // Minimal surface strength at the tile location
public int tsMoveDirs = 3; // Allowed tile disparity correction: 1 increase, 2 - decrease, 3 - both directions
public boolean tsEnMulti = false; // Allow assignment when several surfaces fit
public boolean tsLoopMulti = true; // Repeat multi-choice assignment while succeeding
public double tsSurfStrPow = 0.0; // Raise surface strengths ratio to this power when comparing candidates
public double tsAddStrength = 0.01; // Add to strengths when calculating pull of assigned tiles
public double tsSigma = 2.0; // Radius of influence (in tiles) of the previously assigned tiles
public double tsNSigma = 2.0; // Maximal relative to radius distance to calculate influence
public double tsMinPull = 0.001; // Additional pull of each surface
public double tsMinAdvantage = 3.0; // Minimal ratio of the best surface candidate to the next one to make selection
public int tsClustSize = 1; // Minimal size of a cluster to keep
public double tsClustWeight = 0.2; // Minimal total weight of a cluster to keep
public int tsMinNeib = 6; // Minimal number of neighbors of unassigned tile to join (the farthest)
public double tsMaxSurStrength = 0.05; // Maximal strength of the surrounded unassigned tile to join
public boolean tsCountDis = true; // Include disabled tiles/borders when counting assigned neighbors
public boolean tsEnSingle = true; // Allow assignment to the nearest surface with no competitors
public boolean tsEnMulti = true; // Allow assignment when several surfaces fit
public boolean tsRemoveWeak1 = false; // Remove weak clusters before growing
public boolean tsGrowSurround = true; // Assign tiles that have neighbors to the lowest disparity
public boolean tsRemoveWeak2 = true; // Remove weak clusters after growing
public boolean tsLoopMulti = true; // Repeat multi-choice assignment while succeeding
public boolean tsReset = false; // Reset tiles to surfaces assignment
public boolean tsShow = false; // Show results of tiles to surfaces assignment
......@@ -2497,6 +2512,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plMaxEigen", this.plMaxEigen +"");
properties.setProperty(prefix+"plDbgMerge", this.plDbgMerge+"");
properties.setProperty(prefix+"plWorstWorsening", this.plWorstWorsening +"");
properties.setProperty(prefix+"plOKMergeEigen", this.plOKMergeEigen +"");
properties.setProperty(prefix+"plWeakWorsening", this.plWeakWorsening +"");
properties.setProperty(prefix+"plMutualOnly", this.plMutualOnly+"");
properties.setProperty(prefix+"plFillSquares", this.plFillSquares+"");
......@@ -2542,14 +2558,24 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"tsMaxStrength", this.tsMaxStrength +"");
properties.setProperty(prefix+"tsMinSurface", this.tsMinSurface +"");
properties.setProperty(prefix+"tsMoveDirs", this.tsMoveDirs+"");
properties.setProperty(prefix+"tsEnMulti", this.tsEnMulti+"");
properties.setProperty(prefix+"tsLoopMulti", this.tsLoopMulti+"");
properties.setProperty(prefix+"tsSurfStrPow", this.tsSurfStrPow +"");
properties.setProperty(prefix+"tsAddStrength", this.tsAddStrength +"");
properties.setProperty(prefix+"tsSigma", this.tsSigma +"");
properties.setProperty(prefix+"tsNSigma", this.tsNSigma +"");
properties.setProperty(prefix+"tsMinPull", this.tsMinPull +"");
properties.setProperty(prefix+"tsMinAdvantage", this.tsMinAdvantage +"");
properties.setProperty(prefix+"tsClustSize", this.tsClustSize +"");
properties.setProperty(prefix+"tsClustWeight", this.tsClustWeight +"");
properties.setProperty(prefix+"tsMinNeib", this.tsMinNeib +"");
properties.setProperty(prefix+"tsMaxSurStrength", this.tsMaxSurStrength +"");
properties.setProperty(prefix+"tsCountDis", this.tsCountDis +"");
properties.setProperty(prefix+"tsEnSingle", this.tsEnSingle+"");
properties.setProperty(prefix+"tsEnMulti", this.tsEnMulti+"");
properties.setProperty(prefix+"tsRemoveWeak1", this.tsRemoveWeak1+"");
properties.setProperty(prefix+"tsGrowSurround", this.tsGrowSurround+"");
properties.setProperty(prefix+"tsRemoveWeak2", this.tsRemoveWeak2+"");
properties.setProperty(prefix+"tsLoopMulti", this.tsLoopMulti+"");
properties.setProperty(prefix+"tsShow", this.tsShow+"");
properties.setProperty(prefix+"dbg_migrate", this.dbg_migrate+"");
......@@ -2808,6 +2834,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plMaxEigen")!=null) this.plMaxEigen=Double.parseDouble(properties.getProperty(prefix+"plMaxEigen"));
if (properties.getProperty(prefix+"plDbgMerge")!=null) this.plDbgMerge=Boolean.parseBoolean(properties.getProperty(prefix+"plDbgMerge"));
if (properties.getProperty(prefix+"plWorstWorsening")!=null) this.plWorstWorsening=Double.parseDouble(properties.getProperty(prefix+"plWorstWorsening"));
if (properties.getProperty(prefix+"plOKMergeEigen")!=null) this.plOKMergeEigen=Double.parseDouble(properties.getProperty(prefix+"plOKMergeEigen"));
if (properties.getProperty(prefix+"plWeakWorsening")!=null) this.plWeakWorsening=Double.parseDouble(properties.getProperty(prefix+"plWeakWorsening"));
if (properties.getProperty(prefix+"plMutualOnly")!=null) this.plMutualOnly=Boolean.parseBoolean(properties.getProperty(prefix+"plMutualOnly"));
......@@ -2856,17 +2883,26 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"tsMaxStrength")!=null) this.tsMaxStrength=Double.parseDouble(properties.getProperty(prefix+"tsMaxStrength"));
if (properties.getProperty(prefix+"tsMinSurface")!=null) this.tsMinSurface=Double.parseDouble(properties.getProperty(prefix+"tsMinSurface"));
if (properties.getProperty(prefix+"tsMoveDirs")!=null) this.tsMoveDirs=Integer.parseInt(properties.getProperty(prefix+"tsMoveDirs"));
if (properties.getProperty(prefix+"tsEnMulti")!=null) this.tsEnMulti=Boolean.parseBoolean(properties.getProperty(prefix+"tsEnMulti"));
if (properties.getProperty(prefix+"tsLoopMulti")!=null) this.tsLoopMulti=Boolean.parseBoolean(properties.getProperty(prefix+"tsLoopMulti"));
if (properties.getProperty(prefix+"tsSurfStrPow")!=null) this.tsSurfStrPow=Double.parseDouble(properties.getProperty(prefix+"tsSurfStrPow"));
if (properties.getProperty(prefix+"tsAddStrength")!=null) this.tsAddStrength=Double.parseDouble(properties.getProperty(prefix+"tsAddStrength"));
if (properties.getProperty(prefix+"tsSigma")!=null) this.tsSigma=Double.parseDouble(properties.getProperty(prefix+"tsSigma"));
if (properties.getProperty(prefix+"tsNSigma")!=null) this.tsNSigma=Double.parseDouble(properties.getProperty(prefix+"tsNSigma"));
if (properties.getProperty(prefix+"tsMinPull")!=null) this.tsMinPull=Double.parseDouble(properties.getProperty(prefix+"tsMinPull"));
if (properties.getProperty(prefix+"tsMinAdvantage")!=null) this.tsMinAdvantage=Double.parseDouble(properties.getProperty(prefix+"tsMinAdvantage"));
if (properties.getProperty(prefix+"tsShow")!=null) this.tsShow=Boolean.parseBoolean(properties.getProperty(prefix+"tsShow"));
if (properties.getProperty(prefix+"tsClustSize")!=null) this.tsClustSize=Integer.parseInt(properties.getProperty(prefix+"tsClustSize"));
if (properties.getProperty(prefix+"tsClustWeight")!=null) this.tsClustWeight=Double.parseDouble(properties.getProperty(prefix+"tsClustWeight"));
if (properties.getProperty(prefix+"tsMinNeib")!=null) this.tsMinNeib=Integer.parseInt(properties.getProperty(prefix+"tsMinNeib"));
if (properties.getProperty(prefix+"tsMaxSurStrength")!=null) this.tsMaxSurStrength=Double.parseDouble(properties.getProperty(prefix+"tsMaxSurStrength"));
if (properties.getProperty(prefix+"tsCountDis")!=null) this.tsCountDis=Boolean.parseBoolean(properties.getProperty(prefix+"tsCountDis"));
if (properties.getProperty(prefix+"tsEnSingle")!=null) this.tsEnSingle=Boolean.parseBoolean(properties.getProperty(prefix+"tsEnSingle"));
if (properties.getProperty(prefix+"tsEnMulti")!=null) this.tsEnMulti=Boolean.parseBoolean(properties.getProperty(prefix+"tsEnMulti"));
if (properties.getProperty(prefix+"tsRemoveWeak1")!=null) this.tsRemoveWeak1=Boolean.parseBoolean(properties.getProperty(prefix+"tsRemoveWeak1"));
if (properties.getProperty(prefix+"tsGrowSurround")!=null) this.tsGrowSurround=Boolean.parseBoolean(properties.getProperty(prefix+"tsGrowSurround"));
if (properties.getProperty(prefix+"tsRemoveWeak2")!=null) this.tsRemoveWeak2=Boolean.parseBoolean(properties.getProperty(prefix+"tsRemoveWeak2"));
if (properties.getProperty(prefix+"tsLoopMulti")!=null) this.tsLoopMulti=Boolean.parseBoolean(properties.getProperty(prefix+"tsLoopMulti"));
if (properties.getProperty(prefix+"tsShow")!=null) this.tsShow=Boolean.parseBoolean(properties.getProperty(prefix+"tsShow"));
if (properties.getProperty(prefix+"dbg_migrate")!=null) this.dbg_migrate=Boolean.parseBoolean(properties.getProperty(prefix+"dbg_migrate"));
if (properties.getProperty(prefix+"show_ortho_combine")!=null) this.show_ortho_combine=Boolean.parseBoolean(properties.getProperty(prefix+"show_ortho_combine"));
......@@ -3147,6 +3183,7 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Maximal eigenvalue of a plane", this.plMaxEigen, 6);
gd.addCheckbox ("Combine 'other' plane with the current (unused)", this.plDbgMerge);
gd.addNumericField("Worst case worsening after merge", this.plWorstWorsening, 6);
gd.addNumericField("If result of the merged planes is below, OK to bypass worst worsening", this.plOKMergeEigen, 6);
gd.addNumericField("Relax merge requirements for weaker planes", this.plWeakWorsening, 6);
gd.addCheckbox ("Keep only mutual links, remove weakest if conflict", this.plMutualOnly);
......@@ -3188,6 +3225,8 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Divide plane strengths by ellipsoid area", this.msDivideByArea);
gd.addNumericField("Scale projection of the plane ellipsoid", this.msScaleProj, 6);
gd.addNumericField("Spread this fraction of the ellipsoid weight among extended (double) supertile",this.msFractUni, 6);
gd.addMessage ("--- Tiles assignment ---");
gd.addNumericField("Maximal disparity difference when assigning tiles", this.tsMaxDiff, 6);
gd.addNumericField("Minimal disparity difference to be considered as a competitor surface", this.tsMinDiffOther, 6);
......@@ -3195,14 +3234,25 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Maximal tile correlation strength to be assigned", this.tsMaxStrength, 6);
gd.addNumericField("Minimal surface strength at the tile location", this.tsMinSurface, 6);
gd.addNumericField("Allowed tile disparity correction: 1 increase, 2 - decrease, 3 - both directions",this.tsMoveDirs, 0);
gd.addCheckbox ("Allow assignment when several surfaces fit", this.tsEnMulti);
gd.addCheckbox ("Repeat multi-choice assignment while succeeding", this.tsLoopMulti);
gd.addNumericField("Raise surface strengths ratio to this power when comparing candidates", this.tsSurfStrPow, 6);
gd.addNumericField("Add to strengths when calculating pull of assigned tiles", this.tsAddStrength, 6);
gd.addNumericField("Radius of influence (in tiles) of the previously assigned tiles", this.tsSigma, 6);
gd.addNumericField("Maximal relative to radius distance to calculate influence", this.tsNSigma, 6);
gd.addNumericField(" Additional pull of each surface ", this.tsMinPull, 6);
gd.addNumericField("Minimal ratio of the best surface candidate to the next one to make selection", this.tsMinAdvantage, 6);
gd.addNumericField("Minimal size of a cluster to keep", this.tsClustSize, 0);
gd.addNumericField("Minimal total weight of a cluster to keep", this.tsClustWeight, 6);
gd.addNumericField("Minimal number of neighbors of unassigned tile to join (the farthest)", this.tsMinNeib, 0);
gd.addNumericField("Maximal strength of the surrounded unassigned tile to join", this.tsMaxSurStrength, 6);
gd.addCheckbox ("Include disabled tiles/borders when counting assigned neighbors", this.tsCountDis);
gd.addCheckbox ("Allow assignment to the nearest surface with no competitors", this.tsEnSingle);
gd.addCheckbox ("Allow assignment when several surfaces fit", this.tsEnMulti);
gd.addCheckbox ("Remove weak clusters before growing", this.tsRemoveWeak1);
gd.addCheckbox ("Assign tiles that have neighbors to the lowest disparity", this.tsGrowSurround);
gd.addCheckbox ("Remove weak clusters after growing", this.tsRemoveWeak2);
gd.addCheckbox ("Repeat multi-choice assignment while succeeding", this.tsLoopMulti);
gd.addCheckbox ("Show results of tiles to surfaces assignment", this.tsShow);
gd.addCheckbox ("Test new mode after migration", this.dbg_migrate);
......@@ -3468,6 +3518,7 @@ public class EyesisCorrectionParameters {
this.plMaxEigen= gd.getNextNumber();
this.plDbgMerge= gd.getNextBoolean();
this.plWorstWorsening= gd.getNextNumber();
this.plOKMergeEigen= gd.getNextNumber();
this.plWeakWorsening= gd.getNextNumber();
this.plMutualOnly= gd.getNextBoolean();
......@@ -3515,15 +3566,26 @@ public class EyesisCorrectionParameters {
this.tsMaxStrength= gd.getNextNumber();
this.tsMinSurface= gd.getNextNumber();
this.tsMoveDirs= (int) gd.getNextNumber();
this.tsEnMulti= gd.getNextBoolean();
this.tsLoopMulti= gd.getNextBoolean();
this.tsSurfStrPow= gd.getNextNumber();
this.tsAddStrength= gd.getNextNumber();
this.tsSigma= gd.getNextNumber();
this.tsNSigma= gd.getNextNumber();
this.tsMinPull= gd.getNextNumber();
this.tsMinAdvantage= gd.getNextNumber();
this.tsClustSize= (int) gd.getNextNumber();
this.tsClustWeight= gd.getNextNumber();
this.tsMinNeib= (int) gd.getNextNumber();
this.tsMaxSurStrength= gd.getNextNumber();
this.tsCountDis= gd.getNextBoolean();
this.tsReset = false; // Reset tiles to surfaces assignment
this.tsEnSingle= gd.getNextBoolean();
this.tsEnMulti= gd.getNextBoolean();
this.tsRemoveWeak1= gd.getNextBoolean();
this.tsGrowSurround= gd.getNextBoolean();
this.tsRemoveWeak2= gd.getNextBoolean();
this.tsLoopMulti= gd.getNextBoolean();
this.tsShow = gd.getNextBoolean();
this.dbg_migrate= gd.getNextBoolean();
......@@ -3553,15 +3615,25 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Maximal tile correlation strength to be assigned", this.tsMaxStrength, 6);
gd.addNumericField("Minimal surface strength at the tile location", this.tsMinSurface, 6);
gd.addNumericField("Allowed tile disparity correction: 1 increase, 2 - decrease, 3 - both directions",this.tsMoveDirs, 0);
gd.addCheckbox ("Allow assignment when several surfaces fit", this.tsEnMulti);
gd.addCheckbox ("Repeat multi-choice assignment while succeeding", this.tsLoopMulti);
gd.addNumericField("Raise surface strengths ratio to this power when comparing candidates", this.tsSurfStrPow, 6);
gd.addNumericField("Add to strengths when calculating pull of assigned tiles", this.tsAddStrength, 6);
gd.addNumericField("Radius of influence (in tiles) of the previously assigned tiles", this.tsSigma, 6);
gd.addNumericField("Maximal relative to radius distance to calculate influence", this.tsNSigma, 6);
gd.addNumericField(" Additional pull of each surface ", this.tsMinPull, 6);
gd.addNumericField("Minimal ratio of the best surface candidate to the next one to make selection", this.tsMinAdvantage, 6);
gd.addNumericField("Minimal size of a cluster to keep", this.tsClustSize, 0);
gd.addNumericField("Minimal total weight of a cluster to keep", this.tsClustWeight, 6);
gd.addNumericField("Minimal number of neighbors of unassigned tile to join (the farthest)", this.tsMinNeib, 0);
gd.addNumericField("Maximal strength of the surrounded unassigned tile to join", this.tsMaxSurStrength, 6);
gd.addCheckbox ("Include disabled tiles/borders when counting assigned neighbors", this.tsCountDis);
gd.addCheckbox ("Reset tiles to surfaces assignment", false);
gd.addCheckbox ("Allow assignment to the nearest surface with no competitors", this.tsEnSingle);
gd.addCheckbox ("Allow assignment when several surfaces fit", this.tsEnMulti);
gd.addCheckbox ("Remove weak clusters before growing", this.tsRemoveWeak1);
gd.addCheckbox ("Assign tiles that have neighbors to the lowest disparity", this.tsGrowSurround);
gd.addCheckbox ("Remove weak clusters after growing", this.tsRemoveWeak2);
gd.addCheckbox ("Repeat multi-choice assignment while succeeding", this.tsLoopMulti);
gd.addCheckbox ("Show results of tiles to surfaces assignment", this.tsShow);
WindowTools.addScrollBars(gd);
......@@ -3573,15 +3645,26 @@ public class EyesisCorrectionParameters {
this.tsMaxStrength= gd.getNextNumber();
this.tsMinSurface= gd.getNextNumber();
this.tsMoveDirs= (int) gd.getNextNumber();
this.tsEnMulti= gd.getNextBoolean();
this.tsLoopMulti= gd.getNextBoolean();
this.tsSurfStrPow= gd.getNextNumber();
this.tsAddStrength= gd.getNextNumber();
this.tsSigma= gd.getNextNumber();
this.tsNSigma= gd.getNextNumber();
this.tsMinPull= gd.getNextNumber();
this.tsMinAdvantage= gd.getNextNumber();
this.tsClustSize= (int) gd.getNextNumber();
this.tsClustWeight= gd.getNextNumber();
this.tsMinNeib= (int) gd.getNextNumber();
this.tsMaxSurStrength= gd.getNextNumber();
this.tsCountDis= gd.getNextBoolean();
this.tsReset= gd.getNextBoolean();
this.tsEnSingle= gd.getNextBoolean();
this.tsEnMulti= gd.getNextBoolean();
this.tsRemoveWeak1= gd.getNextBoolean();
this.tsGrowSurround= gd.getNextBoolean();
this.tsRemoveWeak2= gd.getNextBoolean();
this.tsLoopMulti= gd.getNextBoolean();
this.tsShow = gd.getNextBoolean();
return true;
}
......
......@@ -3641,6 +3641,7 @@ public class SuperTiles{
* Find mutual links between multi-layer planes for supertiles. requires that for each plane there are calculated smalles eigenvalues
* for merging with each plane for each of 8 neighbors
* @param rquality maximal degradation by merging (does not depend on the total weight)
* @param okMergeEigen if result eigenvalue of the merged planes is below, OK to bypass worst worsening
* @param maxEigen maximal eigenvalue of each of the merged planes
* @param minWeight minimal weight of each of the planes
* @param debugLevel debug level
......@@ -3650,6 +3651,7 @@ public class SuperTiles{
public void selectNeighborPlanesMutual(
final double rquality,
final double weakWorsening,
final double okMergeEigen,
final double dispNorm,
final double maxEigen, // maximal eigenvalue of planes to consider
final double minWeight, // minimal pain weight to consider
......@@ -3759,7 +3761,7 @@ public class SuperTiles{
w2); // double w2)
double this_rq_norm = this_rq;
if ((w1 + w2) < weakWorsening) this_rq_norm *= (w1 + w2) / weakWorsening; // forgive more for weak planes
if (this_rq_norm <= rquality) {
if ((this_rq_norm <= rquality) ||(merge_ev[np] <= okMergeEigen)) {
this_rq /= (w1 + w2); // for comparision reduce this value for stronger planes
if (Double.isNaN(best_rqual) || (this_rq < best_rqual)){ // OK if Double.isNaN(this_rq[np])
best_rqual = this_rq;
......
......@@ -2963,13 +2963,14 @@ public class TileProcessor {
boolean [][] tileSel = st.getMeasurementSelections(
clt_parameters.stMeasSel); // int stMeasSel) // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert)
// Reset/initialize assignments - if not done so yet or specifically requested
tileSurface.InitTilesAssignment(
clt_parameters.tsReset,
dispStrength, // final double [][][] dispStrength,
tileSel, // final boolean [][] tileSel,
debugLevel); // final int debugLevel,
for (int nTry = 0; nTry < 100; nTry++) {
// assign tiles that do not depend on other assigned tiles - single pass
if (clt_parameters.tsEnSingle) {
int [] stats= tileSurface.assignTilesToSurfaces(
clt_parameters.tsMaxDiff, //final double maxDiff,
clt_parameters.tsMinDiffOther, //final double minDiffOther, // should be >= maxDiff
......@@ -2977,7 +2978,7 @@ public class TileProcessor {
clt_parameters.tsMaxStrength, //final double maxStrength,
clt_parameters.tsMinSurface, //final double minSurfStrength, // minimal surface strength at the tile location
clt_parameters.tsMoveDirs, //final int moveDirs, // 1 increase disparity, 2 - decrease disparity, 3 - both directions
clt_parameters.tsEnMulti, //final boolean enMulti,
false, // clt_parameters.tsEnMulti, //final boolean enMulti,
clt_parameters.tsSurfStrPow, //final double surfStrPow, // surface strength power
clt_parameters.tsAddStrength, //final double addStrength,
clt_parameters.tsSigma, //final double sigma,
......@@ -2989,11 +2990,97 @@ public class TileProcessor {
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
System.out.print("Assign to nearest with single candidate :");
tileSurface.printStats(stats);
if (!clt_parameters.tsEnMulti || !clt_parameters.tsLoopMulti || !tileSurface.makesSensToTry(stats)){
break;
}
// assign tiles that depend on other assigned tiles (more neighbors on the same surface - more attractive it is)
// Single pass or until more tiles are assigned
if (clt_parameters.tsEnMulti) {
for (int nTry = 0; nTry < 100; nTry++) {
int [] stats= tileSurface.assignTilesToSurfaces(
clt_parameters.tsMaxDiff, //final double maxDiff,
clt_parameters.tsMinDiffOther, //final double minDiffOther, // should be >= maxDiff
clt_parameters.tsMinStrength, //final double minStrength,
clt_parameters.tsMaxStrength, //final double maxStrength,
clt_parameters.tsMinSurface, //final double minSurfStrength, // minimal surface strength at the tile location
clt_parameters.tsMoveDirs, //final int moveDirs, // 1 increase disparity, 2 - decrease disparity, 3 - both directions
true, // clt_parameters.tsEnMulti, //final boolean enMulti,
clt_parameters.tsSurfStrPow, //final double surfStrPow, // surface strength power
clt_parameters.tsAddStrength, //final double addStrength,
clt_parameters.tsSigma, //final double sigma,
clt_parameters.tsNSigma, //final double nSigma,
clt_parameters.tsMinPull, //final double minPull,
clt_parameters.tsMinAdvantage, //final double minAdvantage,
clt_parameters.plDispNorm, // final double dispNorm, // disparity normalize (proportionally scale down disparity difference if above
dispStrength, // final double [][][] dispStrength,
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
System.out.print("Assign to best fit surface :");
tileSurface.printStats(stats);
if (!clt_parameters.tsLoopMulti || !tileSurface.makesSensToTry(stats)){
break;
}
}
}
// Remove weak clusters that have too few connected tiles or the total weight of the cluster is insufficient.
// Single pass, before growing assigned tiles
if (clt_parameters.tsRemoveWeak1) {
int [] stats= tileSurface.removeSmallClusters(
clt_parameters.tsClustSize , // final int minSize, // **
clt_parameters. tsClustWeight, // final double minStrength, // **
dispStrength, // final double [][][] dispStrength,
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
tileSurface.printStats(stats);
}
// assign tiles that have sufficient neighbors around, run single or multiple times (TODO: Split parameters?)
// new tile is assigned one of the neighbor surfaces, that has the lowest disparity (farthest from the camera)
// in the current location
if (clt_parameters.tsGrowSurround) {
for (int nTry = 0; nTry < 100; nTry++) {
int [] stats= tileSurface.assignFromFarthest(
clt_parameters.tsMinNeib , // final int minNeib, // **
clt_parameters.tsMaxSurStrength , // final double maxStrength, // **
clt_parameters.tsCountDis, // final boolean includeImpossible, // ** // count prohibited neighbors as assigned
dispStrength, // final double [][][] dispStrength,
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
System.out.print("Assign from neighbors :");
tileSurface.printStats(stats);
if (!clt_parameters.tsLoopMulti || (tileSurface.newAssigned(stats) ==0)){
break;
}
}
}
// Remove weak clusters that have too few connected tiles or the total weight of the cluster is insufficient.
// Single pass, after growing assigned tiles
if (clt_parameters.tsRemoveWeak2) {
int [] stats= tileSurface.removeSmallClusters(
clt_parameters.tsClustSize , // final int minSize, // **
clt_parameters. tsClustWeight, // final double minStrength, // **
dispStrength, // final double [][][] dispStrength,
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
tileSurface.printStats(stats);
}
// Just show current state
tileSurface.InitTilesAssignment(
false,
dispStrength, // final double [][][] dispStrength,
tileSel, // final boolean [][] tileSel,
debugLevel); // final int debugLevel,
if (clt_parameters.tsShow){
tileSurface.showAssignment(
"assignments", // String title,
......@@ -3198,6 +3285,7 @@ public class TileProcessor {
st.selectNeighborPlanesMutual(
clt_parameters.plWorstWorsening, // final double worst_worsening,
clt_parameters.plOKMergeEigen, // final double okMergeEigen,
clt_parameters.plWeakWorsening, // final double worst_worsening,
clt_parameters.plDispNorm,
clt_parameters.plMaxEigen,
......@@ -3227,37 +3315,6 @@ public class TileProcessor {
clt_parameters.stMeasSel); // int stMeasSel) // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert)
TileSurface tileSurface = new TileSurface(
st.tileProcessor.getTileSize(), // int tileSize,
st.tileProcessor.getSuperTileSize(), // int superTileSize,
st.tileProcessor.getTilesX(), // int tilesX,
st.tileProcessor.getTilesY(), // int tilesY,
geometryCorrection, // GeometryCorrection geometryCorrection,
st.tileProcessor.threadsMax); // int threadsMax);
st.setTileSurface(tileSurface);
// TileSurface.TileData [][] tileData =
tileSurface.createTileShells (
clt_parameters.msUseSel, // final boolean use_sel,
clt_parameters.msDivideByArea, // final boolean divide_by_area,
clt_parameters.msScaleProj, // final double scale_projection,
clt_parameters.msFractUni, // final double fraction_uni,
st.planes, // final TilePlanes.PlaneData [][] planes,
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
tileSurface.InitTilesAssignment(
true,
dispStrength, // final double [][][] dispStrength,
tileSel, // final boolean [][] tileSel,
debugLevel); // final int debugLevel,
if (debugLevel > -10){
return; // just cut off the rest
}
TilePlanes.PlaneData[][][] split_planes = // use original (measured planes. See if smoothed are needed here)
......@@ -3317,7 +3374,8 @@ public class TileProcessor {
st.selectNeighborPlanesMutual(
clt_parameters.plWorstWorsening, // final double worst_worsening,
clt_parameters.plWeakWorsening, // final double worst_worsening,
clt_parameters.plOKMergeEigen, // final double okMergeEigen,
clt_parameters.plWeakWorsening, // final double worst_worsening,
clt_parameters.plDispNorm,
clt_parameters.plMaxEigen,
clt_parameters.plMinStrength,
......@@ -3369,48 +3427,6 @@ public class TileProcessor {
clt_parameters.plMaxEigen, // maxEigen,
clt_parameters.plMinStrength, // minWeight,
st.getPlanesMod());
// detect connected "shells" by running wave algorithm over multi-plane supertiles, create integer array (same structure as planes and selected_planes
// Each element [per supertile][per disparity plane] is either 0 (not used) or unique shell index (started from 1)
int [][] shells = st.createSupertileShells(
selected_planes, // boolean[][] selection, // may be null
false, // boolean use_all, // use plane 0 even if there are more than 1
clt_parameters.plKeepOrphans, // true, // boolean keep_orphans, // single-cell shells
clt_parameters.plMinOrphan, // orphan_strength // add separate parameter
st.getPlanesMod(), // TilePlanes.PlaneData [][] planes,
1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// save shell indices with SuperTiles instance
st.setShellMap(shells); // persistent
// Create array [per shell][per tile] of shell disparities. tiles of unused supertiles are Double.NaN
double [][] surfaces = st.getShowShells(
0, // int nlayer, // over multi-layer - do not render more than nlayer on top of each other
st.getPlanesMod(), // TilePlanes.PlaneData [][] planes,
st.getShellMap(), // shells, // int [][] shells,
1000, // int max_shells,
clt_parameters.plFuse,// boolean fuse,
false, // boolean show_connections,
false, // boolean use_NaN,
10.0, // double arrow_dark,
10.0); // double arrow_white)
// save surfaces with SuperTiles instance. They can be used to snap to for the per-tile disparity maps.
st.setSurfaces(surfaces);
/*
TilePlanes.PlaneData[][][] split_planes =
st.breakPlanesToPairs(
st.getPlanes(), // Mod(), // final TilePlanes.PlaneData[][] center_planes, // measured_planes,
st.getPlanes(), // Mod(), // final TilePlanes.PlaneData[][] neib_planes, //mod_planes,
clt_parameters.plSplitPull , // final double center_pull,
clt_parameters.plSplitMinNeib , // min_neibs, // 2
clt_parameters.plSplitMinWeight, // final double splitMinWeight, // = 2.0; // Minimal weight of split plains to show
clt_parameters.plSplitMinQuality, // final double splitMinQuality, // = 1.1; // Minimal split quality to show
clt_parameters.plPreferDisparity,
1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
*/
if (clt_parameters.show_planes){
double [] split_lines = st.showSplitLines(
......@@ -3457,6 +3473,67 @@ public class TileProcessor {
sdfa_instance.showArrays(plane_data, wh[0], wh[1], true, "plane_data");
TileSurface tileSurface = new TileSurface(
st.tileProcessor.getTileSize(), // int tileSize,
st.tileProcessor.getSuperTileSize(), // int superTileSize,
st.tileProcessor.getTilesX(), // int tilesX,
st.tileProcessor.getTilesY(), // int tilesY,
geometryCorrection, // GeometryCorrection geometryCorrection,
st.tileProcessor.threadsMax); // int threadsMax);
st.setTileSurface(tileSurface);
tileSurface.createTileShells (
clt_parameters.msUseSel, // final boolean use_sel,
clt_parameters.msDivideByArea, // final boolean divide_by_area,
clt_parameters.msScaleProj, // final double scale_projection,
clt_parameters.msFractUni, // final double fraction_uni,
st.planes_mod, // st.planes, // final TilePlanes.PlaneData [][] planes,
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
tileSurface.InitTilesAssignment(
true,
dispStrength, // final double [][][] dispStrength,
tileSel, // final boolean [][] tileSel,
debugLevel); // final int debugLevel,
if (debugLevel > -10){
return; // just cut off the rest
}
//*******************************************************************************
// detect connected "shells" by running wave algorithm over multi-plane supertiles, create integer array (same structure as planes and selected_planes
// Each element [per supertile][per disparity plane] is either 0 (not used) or unique shell index (started from 1)
int [][] shells = st.createSupertileShells(
selected_planes, // boolean[][] selection, // may be null
false, // boolean use_all, // use plane 0 even if there are more than 1
clt_parameters.plKeepOrphans, // true, // boolean keep_orphans, // single-cell shells
clt_parameters.plMinOrphan, // orphan_strength // add separate parameter
st.getPlanesMod(), // TilePlanes.PlaneData [][] planes,
1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// save shell indices with SuperTiles instance
st.setShellMap(shells); // persistent
// Create array [per shell][per tile] of shell disparities. tiles of unused supertiles are Double.NaN
double [][] surfaces = st.getShowShells(
0, // int nlayer, // over multi-layer - do not render more than nlayer on top of each other
st.getPlanesMod(), // TilePlanes.PlaneData [][] planes,
st.getShellMap(), // shells, // int [][] shells,
1000, // int max_shells,
clt_parameters.plFuse,// boolean fuse,
false, // boolean show_connections,
false, // boolean use_NaN,
10.0, // double arrow_dark,
10.0); // double arrow_white)
// save surfaces with SuperTiles instance. They can be used to snap to for the per-tile disparity maps.
st.setSurfaces(surfaces);
plane_data = st.getShowShells(
0, // int nlayer, // over multi-layer - do not render more than nlayer on top of each other
st.getPlanesMod(), // TilePlanes.PlaneData [][] planes,
......
......@@ -38,7 +38,6 @@ public class TileSurface {
private int stilesY;
private int [] st_dirs8;
private int [] t_dirs8;
private int [] ss_dirs8;
private double [] window;
private int threadsMax = 100;
private int [][] tileLayers = null;
......@@ -55,13 +54,15 @@ public class TileSurface {
static int PROHOBITED = -1; //tile marked as invalid
static int IMPOSSIBLE = -2; // give up on this tile (as no surface for it)
static int NEW_ASSIGNED = 0; // succesfully assigned to a surface
static int NO_SURF = 1; // no surfaces for this tile cell
static int TOO_WEAK = 2; // tile strength is too low
static int TOO_STRONG = 3; // tile strength is too high ( for that disparity difference)
static int TOO_FAR = 4; // no surface candidates within the allowed disparity range
static int NOT_UNIQUE = 5; // multiple surfaces are within range
static int NUM_STATS = 6;
static int NEW_ASSIGNED = 0; // successfully assigned to a surface
static int NO_SURF = 1; // no surfaces for this tile cell
static int TOO_WEAK = 2; // tile strength is too low
static int TOO_STRONG = 3; // tile strength is too high ( for that disparity difference)
static int TOO_FAR = 4; // no surface candidates within the allowed disparity range
static int NOT_UNIQUE = 5; // multiple surfaces are within range
static int REMOVED_TILES = 6; // number of removed tiles in weak clusters
static int REMOVED_CLUSTERS = 7; // number of removed weak clusters
static int NUM_STATS = 8;
// private int nsTilesstSize = 0; // 8;
GeometryCorrection geometryCorrection = null;
......@@ -89,11 +90,6 @@ public class TileSurface {
int [] tdirs = {-tx, -tx + 1, 1, tx + 1, tx, tx - 1, -1, -tx - 1};
this.t_dirs8 = tdirs;
int [] dirs_ss = {-superTileSize, -superTileSize + 1, 1, superTileSize + 1, superTileSize, superTileSize - 1, -1, -superTileSize - 1};
this.ss_dirs8 = dirs_ss;
}
public class TileData{
......@@ -226,9 +222,23 @@ public class TileSurface {
}
public class TileNeibs{
int size;
TileNeibs(int size){
this.size = size;
int sizeX;
int sizeY;
public int dirs = 8;
public TileNeibs(int size){
this.sizeX = size;
this.sizeY = size;
}
public TileNeibs(int sizeX, int sizeY){
this.sizeX = sizeX;
this.sizeY = sizeY;
}
public int numNeibs() // TODO: make configurable to
{
return dirs;
}
public int opposite(int dir){
return (dir + dirs / 2) % dirs;
}
/**
* Get 2d element index after step N, NE, ... NW. Returns -1 if leaving array
......@@ -238,21 +248,22 @@ public class TileSurface {
*/
int getNeibIndex(int indx, int dir)
{
int y = indx / size;
int x = indx % size;
int y = indx / sizeX;
int x = indx % sizeX;
if (dir < 0) return indx;
switch (dir % 8){
case 0: return (y == 0) ? -1 : (indx - size);
case 1: return ((y == 0) || ( x == (size-1))) ? -1 : (indx - size + 1);
case 2: return ( ( x == (size-1))) ? -1 : (indx + 1);
case 3: return ((y == (size -1)) || ( x == (size-1))) ? -1 : (indx + size + 1);
case 4: return ((y == (size -1)) ) ? -1 : (indx + size);
case 5: return ((y == (size -1)) || ( x == 0)) ? -1 : (indx + size - 1);
case 6: return ( ( x == 0)) ? -1 : (indx - 1);
case 7: return ((y == 0) || ( x == 0)) ? -1 : (indx - size - 1);
switch (dir % dirs){
case 0: return (y == 0) ? -1 : (indx - sizeX);
case 1: return ((y == 0) || ( x == (sizeX - 1))) ? -1 : (indx - sizeX + 1);
case 2: return ( ( x == (sizeX - 1))) ? -1 : (indx + 1);
case 3: return ((y == (sizeY - 1)) || ( x == (sizeX - 1))) ? -1 : (indx + sizeX + 1);
case 4: return ((y == (sizeY - 1)) ) ? -1 : (indx + sizeX);
case 5: return ((y == (sizeY - 1)) || ( x == 0)) ? -1 : (indx + sizeX - 1);
case 6: return ( ( x == 0)) ? -1 : (indx - 1);
case 7: return ((y == 0) || ( x == 0)) ? -1 : (indx - sizeX - 1);
default: return indx;
}
}
/**
* Return tile segment for 50% overlap. -1 - center, 0 N, 1 - NE,... 7 - NW
* @param indx element index
......@@ -260,15 +271,16 @@ public class TileSurface {
*/
int getSegment(int indx)
{
int s1 = size / 4;
// int s2 = size /2;
int s3 = 3 * size / 4;
int x = indx % size;
int y = indx / size;
boolean up = y < s1;
boolean down = y >= s3;
boolean left = x < s1;
boolean right = x >= s3;
int s1x = sizeX / 4;
int s3x = 3 * sizeX / 4;
int s1y = sizeY / 4;
int s3y = 3 * sizeY / 4;
int x = indx % sizeX;
int y = indx / sizeX;
boolean up = y < s1y;
boolean down = y >= s3y;
boolean left = x < s1x;
boolean right = x >= s3x;
if (up){
if (left) return 7;
if (right) return 1;
......@@ -1745,7 +1757,7 @@ public class TileSurface {
int surfaceTilesX = stilesX * superTileSize;
int tx = nSurfTile % surfaceTilesX;
int ty = nSurfTile / surfaceTilesX;
if ((tx > imageTilesX) || (ty > imageTilesY)){
if ((tx >= imageTilesX) || (ty >= imageTilesY)){
return -1; // out of image
}
return imageTilesX * ty + tx;
......@@ -1859,20 +1871,33 @@ public class TileSurface {
public void printStats(int []stats)
{
System.out.println("printStats(x):"+
" NEW_ASSIGNED = " + stats[NEW_ASSIGNED] +
" NO_SURF=" + stats[NO_SURF] +
" TOO_WEAK=" + stats[TOO_WEAK] +
" TOO_STRONG=" + stats[TOO_STRONG] +
" TOO_FAR=" + stats[TOO_FAR] +
" NOT_UNIQUE=" + stats[NOT_UNIQUE]);
boolean nothing = true;
for (int i = 0; nothing && (i < stats.length); i++){
nothing &= stats[i] == 0;
}
if (nothing) {
System.out.println(" -- no changes --");
} else {
if (stats[NEW_ASSIGNED] > 0) System.out.print(" NEW_ASSIGNED = " + stats[NEW_ASSIGNED]);
if (stats[NO_SURF] > 0) System.out.print(" NO_SURF = " + stats[NO_SURF]);
if (stats[TOO_WEAK] > 0) System.out.print(" TOO_WEAK = " + stats[TOO_WEAK]);
if (stats[TOO_STRONG] > 0) System.out.print(" TOO_STRONG = " + stats[TOO_STRONG]);
if (stats[TOO_FAR] > 0) System.out.print(" TOO_FAR = " + stats[TOO_FAR]);
if (stats[NOT_UNIQUE] > 0) System.out.print(" NOT_UNIQUE = " + stats[NOT_UNIQUE]);
if (stats[REMOVED_TILES] > 0) System.out.print(" REMOVED_TILES = " + stats[REMOVED_TILES]);
if (stats[REMOVED_CLUSTERS] > 0) System.out.print(" REMOVED_CLUSTERS = " + stats[REMOVED_CLUSTERS]);
}
System.out.println();
}
public boolean makesSensToTry(int [] stats)
{
return ((stats[NEW_ASSIGNED] > 0) && (stats[NOT_UNIQUE] > 0));
}
public int newAssigned(int [] stats)
{
return stats[NEW_ASSIGNED];
}
public void showAssignment(
String title,
......@@ -1917,6 +1942,191 @@ public class TileSurface {
sdfa_instance.showArrays(img_data, imageTilesX, imageTilesY, true, title, titles);
}
/**
* Unassign tiles that have too few connected other tiles (or total weight of the cluster is too small)
* This is a single-threaded method
* @param minSize minimal tiles in the cluster
* @param minStrength minimal total strength of the cluster
* @param dispStrength per measurement layer, combined disparity and strength array ([num_ml][2][])
* @param debugLevel debug level
* @param dbg_X debug tile X coordinate
* @param dbg_Y debug tile Y coordinate
* @return {number of tiles, number of clusters} removed
*/
public int [] removeSmallClusters(
final int minSize,
final double minStrength,
final double [][][] dispStrength,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
boolean [][] wave_conf = new boolean [tileLayers.length][]; // true when wave or if confirmed
int [] stats_new = new int [NUM_STATS];
for (int ml = 0; ml < tileLayers.length; ml ++) if (tileLayers[ml] != null){
wave_conf[ml] = new boolean[tileLayers[ml].length];
}
TileNeibs tnImage = new TileNeibs(imageTilesX, imageTilesY);
// TileNeibs tnSurface = new TileNeibs(stilesX * superTileSize, stilesY * superTileSize);
for (int ml = 0; ml < tileLayers.length; ml ++) if (tileLayers[ml] != null){
for (int nTile0 = 0; nTile0 < tileLayers[ml].length; nTile0++) if ((tileLayers[ml][nTile0] > 0) && !wave_conf[ml][nTile0]){
ArrayList<Point> wave_list = new ArrayList<Point>();
double sum_weight = 0.0;
int tailp = 0; // do not remove elements from the list while building the cluster, just advance tail pointer
Point p = new Point(nTile0, ml);
sum_weight += dispStrength[p.y][1][p.x];
wave_conf[p.y][p.x] = true;
wave_list.add(p);
while (tailp < wave_list.size()){
Point pt = wave_list.get(tailp++);
int nSurfTile1 = getSurfaceTileIndex(pt.x);
int nl1 = tileLayers[pt.y][pt.x] - 1; // zero-based from 1-based
int [] neibs = tileData[nSurfTile1][nl1].getNeighbors();
for (int dir = 0; dir < tnImage.dirs; dir++) if (neibs[dir] >= 0){
int nTile1 = tnImage.getNeibIndex(pt.x, dir);
if (nTile1 >= 0) {
for (int ml1 = 0; ml1 < tileLayers.length; ml1++) {
// may be several ml tiles on the same surface - count them all
if ((tileLayers[ml1] != null) && (tileLayers[ml1][nTile1] == (neibs[dir] +1)) && !wave_conf[ml1][nTile1]){
Point p1 = new Point(nTile1, ml1);
sum_weight += dispStrength[p1.y][1][p1.x];
wave_conf[p1.y][p1.x] = true;
wave_list.add(p1);
}
}
}
}
}
// See if it is a good cluster
if ((wave_list.size() < minSize) || (sum_weight < minStrength)){
while (wave_list.size() > 0){
Point pt = wave_list.remove(0);
tileLayers[pt.y][pt.x] = 0;
wave_conf [pt.y][pt.x] = false; // not necessary
stats_new[REMOVED_TILES]++;
}
stats_new[REMOVED_CLUSTERS]++;
} else { // it is a strong cluster, nothing to do here (it is already marked in wave_conf[][]
}
}
}
return stats_new;
}
/**
* Assign (weak) tile surrounded by assigned one to the disparity of the farthest tile (lowest disparity).
* This is a single-threaded method
* @param minNeib minimal number of occupied directions (of 8), several occupied levels count as one
* @param maxStrength maximal strength of the tile to assign (strong one may make trust its disparity after all)
* @param includeImpossible count impossible (blocked, on the image edge,...) tiles as if assigned towards
* the number of occupied directions
* @param dispStrength per measurement layer, combined disparity and strength array ([num_ml][2][])
* @param debugLevel debug level
* @param dbg_X debug tile X coordinate
* @param dbg_Y debug tile Y coordinate
* @return {number of tiles, number of clusters} removed
*/
public int [] assignFromFarthest(
final int minNeib,
final double maxStrength,
final boolean includeImpossible, // count prohibited neighbors as assigned
final double [][][] dispStrength,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final int [][] tileLayers_src = tileLayers.clone();
for (int i = 0; i < tileLayers_src.length; i++){
if (tileLayers_src[i] != null){
tileLayers_src[i] = tileLayers[i].clone();
}
}
int [] stats_new = new int [NUM_STATS];
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final int numThreads = threads.length;
final int [][] stats_all = new int [numThreads][stats_new.length];
final AtomicInteger ai_numThread = new AtomicInteger(0);
final AtomicInteger ai = new AtomicInteger(0);
final TileNeibs tnImage = new TileNeibs(imageTilesX, imageTilesY);
final TileNeibs tnSurface = new TileNeibs(stilesX * superTileSize, stilesY * superTileSize);
for (int ml = 0; ml < tileLayers.length; ml++) if (tileLayers[ml] != null){
final int fml = ml;
ai_numThread.set(0);
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int numThread = ai_numThread.getAndIncrement(); // unique number of thread to write to rslt_diffs[numThread]
for (int nTile = ai.getAndIncrement(); nTile < tileLayers_src[fml].length; nTile = ai.getAndIncrement()) {
//nTile is in image, not surface coordinates
int dbg_tileX = nTile % imageTilesX;
int dbg_tileY = nTile / imageTilesX;
int dl = ((debugLevel > -1) && (dbg_tileX == dbg_X ) && (dbg_tileY == dbg_Y ))?3:0;
if (dl > 0){
System.out.println("assignFromFarthest, nTile = " + nTile);
}
if (tileLayers_src[fml][nTile] == 0){ // unassigned only
if (dispStrength[fml][1][nTile] > maxStrength){
stats_all[numThread][TOO_STRONG] ++;
} else {
// find number of tiles around (x,y) that have surface connection to this one
// (multiple ml count as one), and which one has the lowest disparity
int nSurfTile = getSurfaceTileIndex(nTile);
double min_disp = Double.NaN;
int best_nSurf = -1;
int numNeibs = 0;
for (int dir = 0; dir < tnImage.dirs; dir++) {
int nTile1 = tnImage.getNeibIndex(nTile,dir);
boolean neib_exists = false;
if (nTile1 >= 0){
for (int ml_other = 0; ml_other < tileLayers_src.length; ml_other++) if (tileLayers_src[ml_other] != null){
if (tileLayers_src[ml_other][nTile1] < 0 ) { //
neib_exists |= includeImpossible;
} else if (tileLayers_src[ml_other][nTile1] > 0 ){
int nSurfTile1 = tnSurface.getNeibIndex(nSurfTile,dir);
int nSurf = tileData[nSurfTile1][tileLayers_src[ml_other][nTile1] - 1].getNeighbor(tnSurface.opposite(dir));
if (nSurf >= 0){
neib_exists = true;
double disp = tileData[nSurfTile][nSurf].getDisparity();
if (!(disp >= min_disp)) {
best_nSurf = nSurf;
min_disp = disp;
}
}
}
}
} else {
neib_exists = includeImpossible;
}
if (neib_exists){
numNeibs++;
}
}
if ((numNeibs >= minNeib) && (best_nSurf >= 0)){
tileLayers[fml][nTile] = best_nSurf + 1;
stats_all[numThread][NEW_ASSIGNED] ++;
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
for (int nt = 0; nt < numThreads; nt ++){
for (int i = 0 ; i < stats_new.length; i++ ){
stats_new[i] += stats_all[nt][i];
}
}
return stats_new;
}
/**
......@@ -1938,11 +2148,11 @@ public class TileSurface {
* @param tileLayers measured tiles assignment (will be modified): -1 - prohibited, 0 - unassigned,
* >0 - number of surface where this tile is assigned plus 1.
* @param tileData per-tile, per layer array of TileData objects specifying surfaces to snap to
* @param dispStrength per measurement layer, combined disparity and strength array ([num_ml [2][])
* @param dispStrength per measurement layer, combined disparity and strength array ([num_ml][2][])
* @param debugLevel debug level
* @param dbg_X debug tile X coordinate
* @param dbg_Y debug tile Y coordinate
* @return
* @return statistics array
*/
public int [] assignTilesToSurfaces(
......@@ -2362,7 +2572,7 @@ public class TileSurface {
}
/*
public int [][] sortTilesToSurfaces(
final double [][][] dispStrength,
final boolean [][] tileSel,
......@@ -2392,6 +2602,7 @@ public class TileSurface {
}
return tileLayers;
}
*/
//getNtileDir
/*
* clt_parameters.plDispNorm, // = 2.0; // Normalize disparities to the average if above
......
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