Commit 2b8dc001 authored by Andrey Filippov's avatar Andrey Filippov

removing conflicts from extracted clusters

parent a8e74029
......@@ -781,4 +781,55 @@ public class MeasuredLayers {
}
return ds;
}
public void growSelection(
int grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
boolean [] tiles,
boolean [] prohibit)
{
boolean [] src_tiles = tiles.clone(); // just in case
// grow
boolean hor = true;
for (; grow > 0; grow--){
boolean single = (grow ==1) && hor;
src_tiles = tiles.clone();
if (hor){
for (int tileY = 0; tileY < tilesY; tileY++){
for (int tileX = 0; tileX < (tilesX - 1); tileX++){
int tindx = tileY * tilesX + tileX;
if ((prohibit == null) || (!prohibit[tindx] && !prohibit[tindx + 1])) {
tiles[tindx + 1] |= src_tiles[tindx];
}
}
for (int tileX = 1; tileX < tilesX; tileX++){
int tindx = tileY * tilesX + tileX;
if ((prohibit == null) || (!prohibit[tindx] && !prohibit[tindx - 1])) {
tiles[tindx - 1] |= src_tiles[tindx];
}
}
}
}
if (!hor || single){ // do vertically, but from previous state
for (int tileX = 0; tileX < tilesX; tileX++){
for (int tileY = 0; tileY < (tilesY - 1); tileY++){
int tindx = tileY * tilesX + tileX;
if ((prohibit == null) || (!prohibit[tindx] && !prohibit[tindx + tilesX])) {
tiles[tindx + tilesX] |= src_tiles[tindx];
}
}
for (int tileY = 1; tileY < tilesY; tileY++){
int tindx = tileY * tilesX + tileX;
if ((prohibit == null) || (!prohibit[tindx] && !prohibit[tindx - tilesX])) {
tiles[tindx - tilesX] |= src_tiles[tindx];
}
}
}
}
hor = !hor;
}
}
}
......@@ -1699,6 +1699,7 @@ public class SuperTiles{
// find average disparity for the supertile (improve?)
double sd = 0.0, sw = 0.0;
for (int ml = 0; ml < plane_disp_strength[nsTile].length; ml++) if ((stMeasSel & ( 1 << ml)) != 0){
if ((plane_disp_strength[nsTile] !=null) && (plane_disp_strength[nsTile][ml] !=null) && (plane_disp_strength[nsTile][ml][1] !=null)) {
for (int i = 0; i < plane_disp_strength[nsTile][ml][1].length; i++){
double w = plane_disp_strength[nsTile][ml][1][i];
double d = plane_disp_strength[nsTile][ml][0][i];
......@@ -1706,6 +1707,7 @@ public class SuperTiles{
sw += w;
}
}
}
if (sw > 0) {
if (dl > 0) {
System.out.println("Plane tilted disparity for stileX = "+stileX+" stileY="+stileY+", average disparity "+(sd/sw));
......@@ -2008,6 +2010,7 @@ public class SuperTiles{
// Sort plane data by center (plane or supertile) disparity
public boolean [][][][] initialDiscriminateTiles(
final int growSelection, // grow initial selection before processing
final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
final double plDispNorm,
final int plMinPoints, // = 5; // Minimal number of points for plane detection
......@@ -2049,14 +2052,25 @@ public class SuperTiles{
// final TilePlanes tpl = new TilePlanes(tileSize,superTileSize, geometryCorrection);
final int num_layers = measuredLayers.getNumLayers();
final int num_tiles = 4 * superTileSize * superTileSize;
measuredLayers.setLayer (
boolean [] grown_selection = null;
if (growSelection >= 0) {
grown_selection = cltPass3d.getSelected();
if (growSelection > 0) {
grown_selection = grown_selection.clone();
measuredLayers.growSelection(
growSelection, // grow,
grown_selection, // tiles,
null); // prohibit);
}
}
measuredLayers.setLayer ( // overwrite?
0, // int num_layer,
cltPass3d.getDisparity(), // double [] disparity,
cltPass3d.getStrength(), // double [] strength,
null); // boolean [] selection) // may be null
grown_selection); // null); // boolean [] selection) // may be null
if (debugLevel > -1) {
String [] titles = {"d0","s0","d1","s1","d2","s2","d3","s3","s","d"};
String [] titles = {"d0","s0","d1","s1","d2","s2","d3","s3","s","d","selection"};
boolean [] dbg_sel= grown_selection; // cltPass3d.getSelected();
double [][] dbg_img = new double [titles.length][];
for (int i = 0; i < measuredLayers.getNumLayers(); i++){
dbg_img[2 * i] = measuredLayers.getDisparity(i);
......@@ -2064,6 +2078,10 @@ public class SuperTiles{
}
dbg_img[8] = cltPass3d.getDisparity();
dbg_img[9] = cltPass3d.getStrength();
dbg_img[10]= new double [dbg_sel.length];
for (int i = 0; i < dbg_sel.length; i++){
dbg_img[10][i] = ((dbg_sel == null) || dbg_sel[i])? 1.0:0.0;
}
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays();
sdfa_instance.showArrays(dbg_img, tileProcessor.getTilesX(), tileProcessor.getTilesY(), true, "measuredLayers",titles);
}
......@@ -2442,6 +2460,7 @@ public class SuperTiles{
public void processPlanes5(
final int growSelection, // grow initial selection before processing
final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
final double plDispNorm,
final int plMinPoints, // = 5; // Minimal number of points for plane detection
......@@ -2461,7 +2480,7 @@ public class SuperTiles{
final double bin_blur_vert, // Blur disparity histograms for constant disparity clusters by this sigma (in bins)
final double max_diff_hor, // maximal disparity difference (to assign to a cluster (of Double.NaN) at first run for horizontal planes
final double max_diff_vert, // maximal disparity difference (to assign to a cluster (of Double.NaN) at first run for vertical plane
final int max_tries, // on last run - assign all rfemaining pixels to some cluster (disregard max_diff)
final int max_tries, // on last run - assign all remaining pixels to some cluster (disregard max_diff)
final boolean msUseSel, // final boolean use_sel,
final boolean msDivideByArea, // final boolean divide_by_area,
......@@ -2482,6 +2501,7 @@ public class SuperTiles{
// Sort plane data by center (plane or supertile) disparity
boolean [][][][] plane_selections = initialDiscriminateTiles(
growSelection, // final int growSelection, // grow initial selection before processing
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plDispNorm, // final double plDispNorm,
plMinPoints, // final int plMinPoints, // = 5; // Minimal number of points for plane detection
......
......@@ -2972,6 +2972,7 @@ public class TileProcessor {
// assign tiles that do not depend on other assigned tiles - single pass
if (clt_parameters.tsEnSingle) {
int [] stats= tileSurface.assignTilesToSurfaces(
clt_parameters.tsNoEdge , // final boolean noEdge,
clt_parameters.tsMaxDiff, //final double maxDiff,
clt_parameters.tsMinDiffOther, //final double minDiffOther, // should be >= maxDiff
clt_parameters.tsMinStrength, //final double minStrength,
......@@ -2999,6 +3000,7 @@ public class TileProcessor {
if (clt_parameters.tsEnMulti) {
for (int nTry = 0; nTry < 100; nTry++) {
int [] stats= tileSurface.assignTilesToSurfaces(
clt_parameters.tsNoEdge , // final boolean noEdge,
clt_parameters.tsMaxDiff, //final double maxDiff,
clt_parameters.tsMinDiffOther, //final double minDiffOther, // should be >= maxDiff
clt_parameters.tsMinStrength, //final double minStrength,
......@@ -3044,6 +3046,7 @@ public class TileProcessor {
if (clt_parameters.tsGrowSurround) {
for (int nTry = 0; nTry < 100; nTry++) {
int [] stats= tileSurface.assignFromFarthest(
clt_parameters.tsNoEdge , // final boolean noEdge,
clt_parameters.tsMinNeib , // final int minNeib, // **
clt_parameters.tsMaxSurStrength , // final double maxStrength, // **
clt_parameters.tsCountDis, // final boolean includeImpossible, // ** // count prohibited neighbors as assigned
......@@ -3086,6 +3089,111 @@ public class TileProcessor {
"assignments", // String title,
dispStrength); // final double [][][] dispStrength)
}
boolean [][] assigned_sel = tileSurface.extractSelection(
0, // final int debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
int [][] clusters1 = tileSurface.enumerateClusters(
assigned_sel, //final boolean [][] selection,
0, // final int debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
int [][] cluster_stats1 = tileSurface.clusterStats(
clusters1, // int [][] clusters,
0, // final int debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
tileSurface.showClusterStats(
cluster_stats1, // int [][] cluster_stats,
clt_parameters.tsNumClust); // int max_clusters){
if (clt_parameters.tsShow){
tileSurface.showClusters(
"clusters_individual", // String title,
cluster_stats1, // int [][] cluster_stats,
clt_parameters.tsNumClust, // int max_clusters
clusters1); // int [][] clusters); // final double [][][] dispStrength)
}
// Try splitting (currently no initial conflicts):
int [][] clusters1a = tileSurface.spitConflictClusters(
clusters1, // final int [][] clusters,
0, // final int debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
int [][] cluster_stats1a = tileSurface.clusterStats(
clusters1a, // int [][] clusters,
0, // final int debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
tileSurface.showClusterStats(
cluster_stats1a, // int [][] cluster_stats,
clt_parameters.tsNumClust); // int max_clusters){
boolean [][] grown_sel = tileSurface.growSelection(
2, // int grow,
assigned_sel, // final boolean [][] sel_in,
0, // final int debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
int [][] clusters2 = tileSurface.enumerateClusters(
grown_sel, // final boolean [][] selection,
0, // final int debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
int [][] cluster_stats2 = tileSurface.clusterStats(
clusters2, // int [][] clusters,
0, // final int debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
tileSurface.showClusterStats(
cluster_stats2, // int [][] cluster_stats,
clt_parameters.tsNumClust); // int max_clusters){
if (clt_parameters.tsShow){
tileSurface.showClusters(
"clusters_merged", // String title,
cluster_stats2, // int [][] cluster_stats,
clt_parameters.tsNumClust, // int max_clusters
clusters2); // int [][] clusters); // final double [][][] dispStrength)
}
// Just for testing: splitting combined clusters
int [][] clusters2a = tileSurface.spitConflictClusters(
clusters2, // final int [][] clusters,
0, // final int debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
int [][] cluster_stats2a = tileSurface.clusterStats(
clusters2a, // int [][] clusters,
0, // final int debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
tileSurface.showClusterStats(
cluster_stats2a, // int [][] cluster_stats,
clt_parameters.tsNumClust); // int max_clusters){
if (clt_parameters.tsShow){
tileSurface.showClusters(
"clusters_merged_split", // String title,
cluster_stats2a, // int [][] cluster_stats,
clt_parameters.tsNumClust, // int max_clusters
clusters2a); // int [][] clusters); // final double [][][] dispStrength)
}
return true;
}
......@@ -3192,6 +3300,7 @@ public class TileProcessor {
// separate each supertile data into clusters, trying both horizontal and perpendicular to view planes
double [] world_hor = {0.0, 1.0, 0.0};
st.processPlanes5(
clt_parameters.stGrowSel, // = 2; // = -1; //Grow initial selection before processing supertiles, odd - ortho. <0 - use all tiles
clt_parameters.stMeasSel, // = 1 //Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
clt_parameters.plDispNorm, // = 2.0; // Normalize disparities to the average if above
clt_parameters.plMinPoints, // = 5; // Minimal number of points for plane detection
......
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