Commit 0ab422e2 authored by Andrey Filippov's avatar Andrey Filippov

removing foreground bridges

parent 971dd284
......@@ -284,7 +284,7 @@ public class Conflicts {
final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final int nStiles = stilesX * stilesY;
final int [][][] conflicts = new int [st.getPlanes().length][][];
final TileSurface.TileNeibs tnSurface = st.getTileSurface().new TileNeibs(stilesX, stilesY);
final TileNeibs tnSurface = new TileNeibs(stilesX, stilesY);
final Thread[] threads = ImageDtt.newThreadArray(st.getTileProcessor().threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
......@@ -343,7 +343,7 @@ public class Conflicts {
HashMap<Integer,Integer> replacement_tiles, // null is OK
int [][][] replacement_neibs, // null OK if replacement_tiles == null
double [][][] replacement_val_weights,
TileSurface.TileNeibs tnSurface)
TileNeibs tnSurface)
{
TilePlanes.PlaneData [][] planes = st.getPlanes();
// generate conflicts if not provided
......@@ -405,7 +405,7 @@ public class Conflicts {
HashMap<Integer,Integer> replacement_tiles, // null is OK
int [][][] replacement_neibs, // null OK if replacement_tiles == null
ConnectionCosts connectionCosts,
TileSurface.TileNeibs tnSurface)
TileNeibs tnSurface)
{
TilePlanes.PlaneData [][] planes = st.getPlanes();
// generate conflicts if not provided
......@@ -465,7 +465,7 @@ public class Conflicts {
int nsTile0,
HashMap<Integer,Integer> replacement_tiles, // null is OK - will use only planes data
int [][][] replacement_neibs, // null OK if replacement_tiles == null
TileSurface.TileNeibs tnSurface)
TileNeibs tnSurface)
{
TilePlanes.PlaneData [][] planes = st.getPlanes();
ArrayList<Conflict> conflicts_list= new ArrayList<Conflict>();
......
......@@ -28,7 +28,7 @@ import java.util.HashSet;
public class ConnectionCosts {
TilePlanes.PlaneData [][] planes = null;
boolean preferDisparity = false;
TileSurface.TileNeibs tnSurface;
TileNeibs tnSurface;
double orthoWeight;
double diagonalWeight;
double starPwr; // Divide cost by number of connections to this power
......@@ -57,7 +57,7 @@ public class ConnectionCosts {
double starValPwr, // Raise value of each tile before averaging
int steps,
TilePlanes.PlaneData [][] planes,
TileSurface.TileNeibs tnSurface,
TileNeibs tnSurface,
boolean preferDisparity)
{
this.planes = planes;
......@@ -481,7 +481,7 @@ public class ConnectionCosts {
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
TileSurface.TileNeibs tnSurface,
TileNeibs tnSurface,
boolean preferDisparity,
int debugLevel)
{
......@@ -506,7 +506,7 @@ public class ConnectionCosts {
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
TileSurface.TileNeibs tnSurface,
TileNeibs tnSurface,
boolean preferDisparity,
int debugLevel)
{
......@@ -566,7 +566,7 @@ public class ConnectionCosts {
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
TileSurface.TileNeibs tnSurface,
TileNeibs tnSurface,
boolean preferDisparity,
int debugLevel)
{
......@@ -594,7 +594,7 @@ public class ConnectionCosts {
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
TileSurface.TileNeibs tnSurface,
TileNeibs tnSurface,
boolean preferDisparity,
int debugLevel)
{
......
......@@ -813,6 +813,17 @@ public class LinkPlanes {
ImageDtt.startAndJoin(threads);
}
/**
* Merge the supertile planes with agreeing neighbors, non-exclusively (no considering other planes
* of the same supertile. Start with the best fit, then goes to lower quality, until the individual
* merge quality falls below scaled quality of the best, pre-set minimum or the merged plane becomes
* too thick
* Separately calculates merged weighted plane and with equal weights of the neighbors
* @param planes array of plane instances for the same supertile
* @param debugLevel
* @param dbg_X
* @param dbg_Y
*/
public void setNonExclusive(
final TilePlanes.PlaneData [][] planes,
final int debugLevel,
......@@ -834,7 +845,7 @@ public class LinkPlanes {
// final int debug_stile = 9 * stilesX + 26;
final int debug_stile = dbg_Y * stilesX + dbg_X;
final Thread[] threads = ImageDtt.newThreadArray(st.tileProcessor.threadsMax);
final Thread[] threads = ImageDtt.newThreadArray((debugLevel > 1)? 1 : st.tileProcessor.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
......@@ -2426,7 +2437,7 @@ public class LinkPlanes {
final int stilesX = (tilesX + superTileSize -1)/superTileSize;
final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final int nStiles = stilesX * stilesY;
final TileSurface.TileNeibs tnSurface = st.tileSurface.new TileNeibs(stilesX, stilesY);
final TileNeibs tnSurface = new TileNeibs(stilesX, stilesY);
final Thread[] threads = ImageDtt.newThreadArray(st.tileProcessor.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
......@@ -2441,7 +2452,7 @@ public class LinkPlanes {
starValPwr, //double starValPwr, // Raise value of each tile before averaging
steps, // int steps,
planes, // TilePlanes.PlaneData [][] planes,
tnSurface, // TileSurface.TileNeibs tnSurface,
tnSurface, // TileNeibs tnSurface,
preferDisparity); // boolean preferDisparity)
int [] mod_supertiles = new int[1];
for (int nsTile = ai.getAndIncrement(); nsTile < nStiles; nsTile = ai.getAndIncrement()) {
......@@ -2484,7 +2495,7 @@ public class LinkPlanes {
// final int tileSize = tileProcessor.getTileSize();
final int stilesX = (tilesX + superTileSize -1)/superTileSize;
final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final TileSurface.TileNeibs tnSurface = st.tileSurface.new TileNeibs(stilesX, stilesY);
final TileNeibs tnSurface = new TileNeibs(stilesX, stilesY);
final Thread[] threads = ImageDtt.newThreadArray(st.tileProcessor.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
......@@ -2499,7 +2510,7 @@ public class LinkPlanes {
starValPwr, //double starValPwr, // Raise value of each tile before averaging
steps, // int steps,
planes, // TilePlanes.PlaneData [][] planes,
tnSurface, // TileSurface.TileNeibs tnSurface,
tnSurface, // TileNeibs tnSurface,
preferDisparity); // boolean preferDisparity)
int [] supertiles = new int[1];
for (int isTile = ai.getAndIncrement(); isTile < mod_supertiles.length; isTile = ai.getAndIncrement()) {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -3386,7 +3386,7 @@ public class TileProcessor {
LinkPlanes lp = new LinkPlanes (clt_parameters, st);
// try to merge multiple times
int max_num_merge_try = 5;
int max_num_merge_try = 8;
TilePlanes.PlaneData [][][] dbg_orig_planes = new TilePlanes.PlaneData [max_num_merge_try][][];
for (int num_merge_try = 0; num_merge_try < max_num_merge_try; num_merge_try++){
......@@ -3467,20 +3467,6 @@ public class TileProcessor {
clt_parameters.tileX,
clt_parameters.tileY);
// System.out.println("merge_cost_data.length = " + merge_cost_data.length);
/*
// double [][][][][][] merge_cost_data_eq =
lp.costSameTileConnections(
true, // final boolean ignore_weights,
1.8, // final double threshold_worst,
1000.0, //final double threshold_world_worst,
st.planes, // ffinal TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// System.out.println("merge_cost_data_eq.length = " + merge_cost_data_eq.length);
*/
int [][][] merge_groups = lp.extractMergeSameTileGroups(
st.planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
......
......@@ -235,144 +235,6 @@ public class TileSurface {
}
public class TileNeibs{
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 x,y pair from index
* @param indx element index
* @return array of {x,y}
*/
int [] getXY(int indx)
{
int [] xy = {indx % sizeX ,indx / sizeX};
return xy;
}
/**
* Get element index from x and y
* @param x horizontal position
* @param y vertical position
* @return element linescan index
*/
int getIndex(int x, int y){
return y * sizeX + x;
}
/**
* Get 2d element index after step N, NE, ... NW. Returns -1 if leaving array
* @param indx start index
* @param dir step direction (CW from up)
* @return new index or -1 if leaving
*/
int getNeibIndex(int indx, int dir)
{
int y = indx / sizeX;
int x = indx % sizeX;
if (dir < 0) return indx;
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
* @return which of the 9 areas this element belongs
*/
int getSegment(int indx)
{
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;
return 0;
}
if (down){
if (left) return 5;
if (right) return 3;
return 4;
}
if (left) return 6;
if (right) return 2;
return -1;
}
/**
* Find if the step leaves the center half of all area
* @param indx start point
* @param dir direction
* @return direction to the new tile (assuming 50% overlap) or -1 if did not cross the border
*/
int leaveOvderlapedCenter(int indx, int dir)
{
int segm = getSegment(indx);
int indx1 = getNeibIndex(indx, dir);
if (indx1 < 0 ) {
return -1; // should not happen
}
int segm1 = getSegment(indx1);
if (segm1 == segm) return -1;
if (segm == -1) return segm1;
int [][] dxy = {
{ 0, 0},
{-1, 0},
{-1, 1},
{ 0, 1},
{ 1, 1},
{ 1, 0},
{ 1,-1},
{ 0,-1},
{-1,-1}};
int dx = dxy[segm1 + 1][1] - dxy[segm + 1][1];
int dy = dxy[segm1 + 1][0] - dxy[segm + 1][0];
for (int dp1 = 0; dp1 <=8; dp1++) {
int sdx = (dx > 0) ? 1: ( (dx < 0) ? -1 : 0);
int sdy = (dy > 0) ? 1: ( (dy < 0) ? -1 : 0);
if ((dxy[dp1][0] == sdy) && (dxy[dp1][1] == sdx)){
return dp1 -1;
}
}
return -1; // should not happen
}
}
public int getNStileDir(
int nsTile,
int dir)
......
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