Commit b771650e authored by Andrey Filippov's avatar Andrey Filippov

testing/bug fixing

parent 046d8eb3
......@@ -4,4 +4,5 @@
/target/
*.backup
NC393I
attic
\ No newline at end of file
attic
*.log
\ No newline at end of file
......@@ -53,11 +53,11 @@ public class AlignmentCorrection {
}
public double [][][] infinityCorrection(
final double min_strength_in,
final double max_diff,
final int max_iterations,
final double max_coeff_diff,
final double far_pull, // = 0.2; // 1; // 0.5;
final double min_strength_in,
final double max_diff,
final int max_iterations,
final double max_coeff_diff,
final double far_pull, // = 0.2; // 1; // 0.5;
final double strength_pow,
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst (should be >1)
......
......@@ -27,9 +27,11 @@ import java.awt.Rectangle;
import java.util.concurrent.atomic.AtomicInteger;
public class CLTPass3d{
public double [][] disparity; // per-tile disparity set for the pass[tileY][tileX]
public int [][] tile_op; // what was done in the current pass
public double [][] disparity_map = null; // add 4 layers - worst difference for the port
public double [][] disparity; // per-tile disparity set for the pass[tileY][tileX]
public int [][] tile_op; // what was done in the current pass
private double [][] disparity_sav; // saved disaprity
private int [][] tile_op_sav; // saved tile_op
public double [][] disparity_map = null; // add 4 layers - worst difference for the port
double [] calc_disparity = null; // composite disparity, calculated from "disparity", and "disparity_map" fields
// using horizontal features and corr_magic_scale
// used directly in TileProcessor.compositeScan()
......@@ -55,7 +57,7 @@ public class CLTPass3d{
public boolean is_combo = false;
public boolean is_measured = false;
public String texture = null; // relative (to x3d) path
public Rectangle bounds;
public Rectangle texture_bounds;
public int dbg_index;
public int disparity_index = ImageDtt.DISPARITY_INDEX_CM; // may also be ImageDtt.DISPARITY_INDEX_POLY
......@@ -133,6 +135,9 @@ public class CLTPass3d{
return "null-texture-name";
}
}
// Will not work if texture is disabled
public void updateSelection(){ // add updating border tiles?
int tilesX = tileProcessor.getTilesX();
int tilesY = tileProcessor.getTilesY();
......@@ -149,7 +154,11 @@ public class CLTPass3d{
selected[ty * tilesX + tx] = false; // may be omitted
}
}
bounds = new Rectangle(minX, minY, maxX - minX +1, maxY - minY +1 );
texture_bounds = new Rectangle(minX, minY, maxX - minX +1, maxY - minY +1 );
}
public Rectangle getTextureBounds(){
return texture_bounds;
}
public boolean isProcessed(){
......@@ -219,7 +228,11 @@ public class CLTPass3d{
public void setSelected (boolean [] selected) {
this.selected = selected;
}
public void setBorderTiles (boolean [] border_tiles) {
this.border_tiles = border_tiles;
}
public void fixNaNDisparity()
{
fixNaNDisparity(
......@@ -648,6 +661,65 @@ public class CLTPass3d{
return measured;
}
public void saveTileOpDisparity()
{
disparity_sav =disparity.clone();
for (int i = 0; i < disparity.length; i++ ) if (disparity[i]!= null) disparity_sav[i] = disparity[i].clone();
tile_op_sav =tile_op.clone();
for (int i = 0; i < tile_op.length; i++ ) if (tile_op[i]!= null) tile_op_sav[i] = tile_op[i].clone();
}
public void restoreTileOpDisparity()
{
disparity = disparity_sav;
tile_op = tile_op_sav;
}
public void restoreKeepTileOpDisparity()
{
restoreTileOpDisparity();
saveTileOpDisparity();
}
public int setTileOpDisparity(
boolean [] selection,
double [] disparity)
{
int op = ImageDtt.setImgMask(0, 0xf);
op = ImageDtt.setPairMask(op,0xf);
op = ImageDtt.setForcedDisparity(op,true);
return setTileOpDisparity(
op, // int tile_op,
selection, // boolean [] selection,
disparity); // double [] disparity)
}
public int setTileOpDisparity(
int tile_op,
boolean [] selection,
double [] disparity)
{
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
this.disparity = new double [tilesY][tilesX];
this.tile_op = new int [tilesY][tilesX];
int num_op_tiles = 0;
for (int ty = 0; ty < tilesY; ty++) for (int tx = 0; tx <tilesX; tx++){
int indx = tilesX * ty + tx;
if (this.selected[indx]) {
this.disparity[ty][tx] = disparity[indx];
this.tile_op[ty][tx] = tile_op;
num_op_tiles ++;
} else {
this.disparity[ty][tx] = 0.0;
this.tile_op[ty][tx] = 0;
}
}
return num_op_tiles;
}
public double [] getSecondMaxDiff (
final boolean averaged)
......
import java.util.concurrent.atomic.AtomicInteger;
/**
**
** ExtendSurfaces predict disparity in the unknown areas
......@@ -24,6 +22,10 @@ import java.util.concurrent.atomic.AtomicInteger;
**
*/
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;
public class ExtendSurfaces {
TileProcessor tp;
public ExtendSurfaces(TileProcessor tp){
......@@ -37,16 +39,21 @@ public class ExtendSurfaces {
final boolean [] known, // cells with known values (will not be modified)
final boolean [] new_cells, // cells that need to be calculated
final int smpl_size, // == 5
final int min_points, // == 3
final boolean use_wnd, // use window function fro the neighbors
final double tilt_cost,
final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
final double same_range, // modify
final double diff_continue, // maximal difference from the old value (for previously defined tiles
final double max_abs_tilt, // = 2.0; // pix per tile
final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
final boolean en_normal, // expand sngle-range cells (that have all neighbors within split_threshold)
final boolean en_far, // expand background - use neighbors cells within same_range from the lowest
// en_near is only valid if !en_far
final boolean en_near, // expand foreground - use neighbors cells within same_range from the highest
final int max_tries, // maximal number of smoothing steps
final double final_diff, // maximal change to finish iterations
final double final_diff, // maximal change to finish iterations
final boolean new_only, // expand only Double.NaN cells (not yet assigned), use for first passes
final int dbg_x,
final int dbg_y,
final int debugLevel)
......@@ -59,15 +66,21 @@ public class ExtendSurfaces {
// should first be initialized with all not known = Double.NaN
values, // final double [] values, // will be modified, Double.NaN is not yet assigned
new_cells, // final boolean [] new_cells, // cells that need to be calculated
smpl_size, // final int smpl_size, // == 5
use_wnd, // final boolean use_wnd, // use window function fro the neighbors
smpl_size, // final int smpl_size, // == 5
min_points, // final int min_points, // == 3
use_wnd, // final boolean use_wnd, // use window function fro the neighbors
tilt_cost, // final double tilt_cost,
split_threshold, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
same_range, // final double same_range, // modify
en_normal, // final boolean en_normal, // expand sngle-range cells (that have all neighbors within split_threshold)
en_far, // final boolean en_far, // expand background - use neighbors cells within same_range from the lowest
diff_continue, // final double diff_continue, // maximal difference from the old value (for previously defined tiles
max_abs_tilt, // final double max_abs_tilt, // = 2.0; // pix per tile
max_rel_tilt, // final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
en_normal, // final boolean en_normal, // expand sngle-range cells (that have all neighbors within split_threshold)
en_far, // final boolean en_far, // expand background - use neighbors cells within same_range from the lowest
// en_near is only valid if !en_far
en_near, // final boolean en_near, // expand foreground - use neighbors cells within same_range from the highest
en_near, // final boolean en_near, // expand foreground - use neighbors cells within same_range from the highest
new_only, // final boolean new_only, // expand only Double.NaN cells (not yet assigned), use for first passes
true, // final boolean no_zero, // do not use values[i] == 0.0, exact 0.0 is only background
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel); // final int debugLevel);
......@@ -84,22 +97,41 @@ public class ExtendSurfaces {
return num_new;
}
private int [] getNeibIndices(
int size)
{
final int [] neib_indices = new int [8]; // indices of the sample array immediately around the center;
int ni = 0;
for (int sy = -1; sy <= 1; sy++) {
for (int sx = -1; sx <= 1; sx++) {
if ((sy != 0) || (sx != 0)){
neib_indices[ni++] = (size/2 + sx) + (size/2 + sy) * size;
}
}
}
return neib_indices;
}
public double smoothNewStep( // return maximal correction value
private double smoothNewStep( // return maximal correction value
// should first be initialized with all not known = Double.NaN
final double [] values, // will be modified, Double.NaN is not yet assigned
final boolean [] new_cells, // cells that need to be calculated
final int smpl_size, // == 5
final boolean use_wnd, // use window function fro the neighbors
final int min_points, // == 3
final boolean use_wnd, // use window function for the neighbors
final double tilt_cost,
final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
final double same_range, // modify
final boolean en_normal, // expand sngle-range cells (that have all neighbors within split_threshold)
final double same_range, // modify for old - +/- 0.5?
final double diff_continue, // maximal difference from the old value (for previously defined tiles
final double max_abs_tilt, // = 2.0; // pix per tile
final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
final boolean en_normal, // expand single-range cells (that have all neighbors within split_threshold)
final boolean en_far, // expand background - use neighbors cells within same_range from the lowest
// en_near is only valid if !en_far
final boolean en_near, // expand foreground - use neighbors cells within same_range from the highest
final boolean new_only, // expand only Double.NaN cells (not yet assigned), use for first passes
final boolean no_zero, // do not use values[i] == 0.0, exact 0.0 is only background
final int dbg_x,
final int dbg_y,
final int debugLevel)
......@@ -120,30 +152,23 @@ public class ExtendSurfaces {
final AtomicInteger ai_thread = new AtomicInteger(0);
final AtomicInteger ai = new AtomicInteger(0);
final double [] new_vals = values.clone();
final int [] neib_indices = new int [8]; // indices of the sample array immediately around the center;
int ni = 0;
for (int sy = -1; sy < 1; sy++) {
for (int sx = -1; sx < 1; sx++) {
if ((sy != 0) || (sx != 0)){
neib_indices[ni++] = (smpl_half + sx) + (smpl_half + sy) * smpl_size;
}
}
}
final int [] neib_indices = getNeibIndices(smpl_size);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
PolynomialApproximation pa = new PolynomialApproximation();
int this_thread = ai_thread.getAndIncrement();
for (int nTile = ai.getAndIncrement(); nTile < new_vals.length; nTile = ai.getAndIncrement()) {
if (new_cells[nTile]) {
if (new_cells[nTile] && (!new_only || Double.isNaN(values[nTile]))) {
int dl = (nTile == dbg_tile) ? debugLevel : -1;
int tileX = nTile % tilesX;
int tileY = nTile / tilesX;
// boolean [] smpl_new = new boolean [smpl_len];
boolean [] smpl_sel = new boolean [smpl_len];
double [] smpl_d = new double [smpl_len];
// double [] smpl_p = new double [smpl_len];
double [] smpl_w = new double [smpl_len];
// double [] smpl_w = new double [smpl_len];
int num_in_sample = 0;
for (int sy = 0; sy < smpl_size; sy++) {
int y = tileY + sy - smpl_half;
......@@ -152,7 +177,8 @@ public class ExtendSurfaces {
int x = tileX + sx - smpl_half;
if ((x >= 0) && (x < tilesX)) {
int indx = x + y * tilesX;
if (!Double.isNaN(values[indx]) && (indx != center_index)){
// if (!Double.isNaN(values[indx]) && (indx != center_index)){
if (!Double.isNaN(values[indx]) && (!no_zero || (values[indx] != 0.0))){
int indxs = sx + sy * smpl_size;
// double w = smpl_weights[indxs];
smpl_sel[indxs] = true;
......@@ -163,58 +189,107 @@ public class ExtendSurfaces {
}
}
}
if (num_in_sample > 0) {
// add starting from the known cells. When using 5x5 samples, having immediate neighbor
// to the center usually means that likely there is enough data to determine the tilt.
boolean has_neib = false;
for (int i = 0; i < neib_indices.length; i++) if (smpl_sel[neib_indices[i]]) {
has_neib = true;
break;
if (dl > 1){
System.out.println("smoothNewStep(): tileX="+tileX+", tileY="+tileY+", nTile="+nTile+" num_in_sample="+num_in_sample);
for (int sy = 0; sy < smpl_size; sy++) {
int y = tileY + sy - smpl_half;
if ((y >= 0) && (y < tilesY)) {
for (int sx = 0; sx < smpl_size; sx++) {
int x = tileX + sx - smpl_half;
if ((x >= 0) && (x < tilesX)) {
int indx = x + y * tilesX;
if (!Double.isNaN(values[indx])){
int indxs = sx + sy * smpl_size;
System.out.print(String.format("%8.3f ", smpl_d[indxs]));
} else {
System.out.print(String.format("%8s ", "--NaN--"));
}
}
}
}
System.out.println();
}
}
if (num_in_sample >= min_points) {
// if center was NaN - diff is the absolute value.
// Two branches - for existing and new cells.
// New cells may stick to the far/near, already defined - only to similar,
// otherwise they can all switch from some distant cell during many iteration steps
boolean process_sample = false;
if (has_neib) { // all conditions met, find linear 2-d damped approximation for the center
// if center was NaN - diff is the absolute value.
int imin = -1, imax = -1;
if (smpl_sel[center_index]) {
// Keep only cells within +/- diff_continue from the center value
for (int indxs = 0; indxs < smpl_len; indxs ++ ) if (smpl_sel[indxs]){
if ((imin < 0) || (smpl_d[indxs] < smpl_d[imin])) imin = indxs ;
if ((imax < 0) || (smpl_d[indxs] > smpl_d[imax])) imax = indxs ;
if (Math.abs(smpl_d[indxs] - smpl_d[center_index]) > diff_continue){
smpl_sel[indxs] = false;
num_in_sample--;
}
}
// does it all fit
if ((smpl_d[imax] - smpl_d[imin]) <= split_threshold){
process_sample = en_normal;
} else {
if (en_far) {
double threshold = smpl_d[imax] - smpl_d[imax];
for (int indxs = 0; indxs < smpl_len; indxs ++ ) if (smpl_sel[indxs]){
if (smpl_d[indxs] < threshold) {
smpl_sel[indxs] = false;
num_in_sample--;
process_sample = (num_in_sample > 1);
} else {
// add starting from the known cells. When using 5x5 samples, having immediate neighbor
// to the center usually means that likely there is enough data to determine the tilt.
boolean has_neib = false;
for (int i = 0; i < neib_indices.length; i++) if (smpl_sel[neib_indices[i]]) {
has_neib = true;
break;
}
// process_sample = false;
if (has_neib) { // all conditions met, find linear 2-d damped approximation for the center
int imin = -1, imax = -1;
for (int indxs = 0; indxs < smpl_len; indxs ++ ) if (smpl_sel[indxs]){
if ((imin < 0) || (smpl_d[indxs] < smpl_d[imin])) imin = indxs ;
if ((imax < 0) || (smpl_d[indxs] > smpl_d[imax])) imax = indxs ;
}
// does it all fit
if ((smpl_d[imax] - smpl_d[imin]) <= split_threshold){
process_sample = en_normal;
} else {
if (en_far) {
double threshold = smpl_d[imin] + same_range;
for (int indxs = 0; indxs < smpl_len; indxs ++ ) if (smpl_sel[indxs]){
if (smpl_d[indxs] > threshold) {
smpl_sel[indxs] = false;
num_in_sample--;
}
}
process_sample = true;
} else if (en_near){
double threshold = smpl_d[imax] - same_range;
for (int indxs = 0; indxs < smpl_len; indxs ++ ) if (smpl_sel[indxs]){
if (smpl_d[indxs] < threshold) {
smpl_sel[indxs] = false;
num_in_sample--;
}
}
process_sample = true;
}
// removed some points - recheck neighbors
if (process_sample){
has_neib = false;
for (int i = 0; i < neib_indices.length; i++) if (smpl_sel[neib_indices[i]]) {
has_neib = true;
break;
}
}
process_sample = true;
} else if (en_near){
double threshold = smpl_d[imin] + smpl_d[imax];
for (int indxs = 0; indxs < smpl_len; indxs ++ ) if (smpl_sel[indxs]){
if (smpl_d[indxs] > threshold) {
smpl_sel[indxs] = false;
num_in_sample--;
if (!has_neib) process_sample = false; // neighbor was removed, will process
if (dl > 1){
System.out.println("smoothNewStep(): tileX="+tileX+", tileY="+tileY+", nTile="+nTile+
" num_in_sample="+num_in_sample+" has_neib="+has_neib+ " process_sample="+process_sample);
}
}
process_sample = true;
}
// removed some points - recheck neighbors
if (process_sample){
has_neib = false;
for (int i = 0; i < neib_indices.length; i++) if (smpl_sel[neib_indices[i]]) {
has_neib = true;
break;
// with other direction
}
if (!has_neib) process_sample = false; // neighbor was removed, will process
// with other direction
}
}
}
if (dl > 1){
System.out.println("smoothNewStep(): tileX="+tileX+", tileY="+tileY+", nTile="+nTile+
" num_in_sample="+num_in_sample+" process_sample="+process_sample);
}
if (num_in_sample < min_points) {
process_sample = false;
}
if (process_sample) {
// build linear 2d approximation, damped as there could be co-linear cells
// or even a single cell
......@@ -233,7 +308,10 @@ public class ExtendSurfaces {
mdata[mindx][1] = new double [1];
mdata[mindx][1][0] = smpl_d[indxs];
mdata[mindx][2] = new double [1];
mdata[mindx][2][0] = smpl_w[indxs];
mdata[mindx][2][0] = smpl_weights[indxs];
if (mdata[mindx][1][0] == 0.0){
System.out.println("zero!!!");
}
mindx ++;
}
}
......@@ -244,12 +322,22 @@ public class ExtendSurfaces {
damping, // double [] damping,
thresholdLin, // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
0.0, // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
dl); // int debugLevel;
dl-1); // int debugLevel;
if (approx2d == null) {
System.out.println("A BUG in smoothNewStep() - failed quadraticApproximation()");
continue;
}
double new_center_val = approx2d[0][0]; // Last coefficient, F (of 6)
double tilt2 = approx2d[0][0]*approx2d[0][0] + approx2d[0][1]*approx2d[0][1];
if (dl > 1){
System.out.println("smoothNewStep(): tileX="+tileX+" coeffs: D="+
approx2d[0][0]+" E="+approx2d[0][1]+" F="+approx2d[0][2]+
", tilt = "+Math.sqrt(tilt2));
}
double max_tilt = Math.min(max_abs_tilt, max_rel_tilt * approx2d[0][2]);
if (tilt2 > (max_tilt * max_tilt)){
continue;
}
double new_center_val = approx2d[0][2]; // Last coefficient, F (of 6)
double this_corr;
if (Double.isNaN(values[nTile])) this_corr = Math.abs(new_center_val);
else this_corr = Math.abs(new_center_val - values[nTile]);
......@@ -262,30 +350,524 @@ public class ExtendSurfaces {
}
};
}
ImageDtt.startAndJoin(threads);
System.arraycopy(new_vals, 0, values, 0, new_vals.length);
double max_corr = 0;
for (int i = 0; i < max_corrs.length; i++) max_corr = Math.max(max_corr,max_corrs[i]);
return max_corr;
}
private boolean [] startDiscontinuity(
final double [] values, // will be modified, Double.NaN is not yet assigned
final boolean [] known, // cells with new values (will be modified)
final int smpl_size, // == 5
final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
final boolean extend_far, // extend far (false - extend near)
final boolean no_zero, // do not use values[i] == 0.0, exact 0.0 is only background
final int dbg_x,
final int dbg_y,
final int debugLevel)
{
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
final int smpl_half = smpl_size / 2; // 2
final boolean [] discont_cells = new boolean [tilesX * tilesY];
final Thread[] threads = ImageDtt.newThreadArray(tp.threadsMax);
final int [] num_new = new int [threads.length];
final AtomicInteger ai_thread = new AtomicInteger(0);
final AtomicInteger ai = new AtomicInteger(0);
final int dbg_tile = dbg_x + tilesX * dbg_y;
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int this_thread = ai_thread.getAndIncrement();
for (int nTile = ai.getAndIncrement(); nTile < known.length; nTile = ai.getAndIncrement()) if (known[nTile]){
double threshold = extend_far ? (values[nTile] - split_threshold): (values[nTile] + split_threshold);
int dl = (nTile == dbg_tile) ? debugLevel : -1;
// int dl = (nTile == dbg_tile) ? debugLevel : -1;
int tileX = nTile % tilesX;
int tileY = nTile / tilesX;
label_tile:
{
for (int sy = 0; sy < smpl_size; sy++) {
int y = tileY + sy - smpl_half;
if ((y >= 0) && (y < tilesY)) {
for (int sx = 0; sx < smpl_size; sx++) {
int x = tileX + sx - smpl_half;
if ((x >= 0) && (x < tilesX)) {
int indx = x + y * tilesX;
if (known[indx] && (!no_zero || (values[indx] != 0.0))) {
if ( (extend_far && (values[indx] < threshold)) ||
(!extend_far && (values[indx] > threshold))){
discont_cells[nTile] = true;
num_new[this_thread] ++;
break label_tile;
}
}
}
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int this_thread = ai_thread.getAndIncrement();
for (int nTile = ai.getAndIncrement(); nTile < known.length; nTile = ai.getAndIncrement()){
if (discont_cells[nTile]){
// values[nTile] = Double.NaN;
known[nTile] = false;
}
if (!known[nTile]){
values[nTile] = Double.NaN;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
for (int i = 0; i < num_new.length; i++) if (num_new[i] > 0){
return discont_cells;
}
return null; // nothing found
}
private boolean [] startExpanding(
final double [] values, // will be modified, Double.NaN is not yet assigned
final boolean [] known, // cells with new values (will not be modified)
final int smpl_size, // == 5
final boolean no_zero, // do not use values[i] == 0.0, exact 0.0 is only background
final int dbg_x,
final int dbg_y,
final int debugLevel)
{
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
final boolean [] expanding = new boolean [tilesX * tilesY];
final Thread[] threads = ImageDtt.newThreadArray(tp.threadsMax);
final int [] num_new = new int [threads.length];
final AtomicInteger ai_thread = new AtomicInteger(0);
final AtomicInteger ai = new AtomicInteger(0);
final int dbg_tile = dbg_x + tilesX * dbg_y;
final TileNeibs tnSurface = new TileNeibs(tilesX, tilesY);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int this_thread = ai_thread.getAndIncrement();
for (int nTile = ai.getAndIncrement(); nTile < known.length; nTile = ai.getAndIncrement()) if (!known[nTile]){
int dl = (nTile == dbg_tile) ? debugLevel : -1;
boolean has_exp_neib = false;
for (int dir = 0; dir <8; dir++){
int nTile1 = tnSurface.getNeibIndex(nTile, dir);
if ((nTile1 >= 0) && known[nTile1] && !Double.isNaN(values[nTile1]) && (!no_zero || (values[nTile1] != 0.0))){
has_exp_neib = true;
break;
}
}
if (has_exp_neib) {
expanding[nTile] = true;
num_new[this_thread] ++;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < known.length; nTile = ai.getAndIncrement()){
if (expanding[nTile] || !known[nTile]){
values[nTile] = Double.NaN;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
if (debugLevel > 2){
String [] titles = {"values","known", "expanding"};
double [][] dbg_img = new double [titles.length][];
dbg_img[0] = values;
dbg_img[1] = new double [tilesX*tilesY];
dbg_img[2] = new double [tilesX*tilesY];
for (int i = 0; i < dbg_img[1].length; i++){
dbg_img[1][i] = known[i] ? 50.0: 0.0;
dbg_img[2][i] = expanding[i] ? 50.0: 0.0;
}
(new showDoubleFloatArrays()).showArrays(dbg_img, tilesX, tilesY, true, "startExpanding",titles);
}
/*
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) {
// int dl = (nTile == dbg_tile) ? debugLevel : -1;
int tileX = nTile % tilesX;
int tileY = nTile / tilesX;
measured[nTile] = measured_scan.tile_op[tileY][tileX] != 0;
if (!measured[nTile]) disp_strength[1][nTile] = -1.0;
}
}
};
}
ImageDtt.startAndJoin(threads);
*/
\ No newline at end of file
for (int i = 0; i < num_new.length; i++) if (num_new[i] > 0){
return expanding;
}
return null; // nothing found
}
private int expandDiscontinuityStep(
final double [] values, // will be modified, Double.NaN is not yet assigned
final boolean [] known, // cells with known values (will be modified)
final boolean [] prohibited, // cells that can not be used (tried before with similar disparity)
final boolean [] expanding, // cells with new values (will be modified)
final int smpl_size, // == 5
final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
final boolean extend_far, // extend far (false - extend near)
final boolean unknown_only, // pure expanding, not over previously found values
final int dbg_x,
final int dbg_y,
final int debugLevel)
{
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
final int smpl_half = smpl_size / 2; // 2
final boolean [] expanding_prev = expanding.clone();
final Thread[] threads = ImageDtt.newThreadArray(tp.threadsMax);
final int [] num_new = new int [threads.length];
final AtomicInteger ai_thread = new AtomicInteger(0);
final AtomicInteger ai = new AtomicInteger(0);
final int dbg_tile = dbg_x + tilesX * dbg_y;
final TileNeibs tnSurface = new TileNeibs(tilesX, tilesY);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int this_thread = ai_thread.getAndIncrement();
for (int nTile = ai.getAndIncrement(); nTile < known.length; nTile = ai.getAndIncrement()){
if (!expanding_prev[nTile] && ((prohibited == null) || !prohibited[nTile])) {
int dl = (nTile == dbg_tile) ? debugLevel : -1;
boolean has_exp_neib = false;
for (int dir = 0; dir <8; dir++){
int nTile1 = tnSurface.getNeibIndex(nTile, dir);
if ((nTile1 >= 0) && expanding_prev[nTile1] && !Double.isNaN(values[nTile1])){
has_exp_neib = true;
break;
}
}
if (has_exp_neib) {
if (!known[nTile]){
expanding[nTile] = true;
num_new[this_thread] ++;
} else if (!unknown_only){
double threshold = extend_far ? (values[nTile] - split_threshold): (values[nTile] + split_threshold);
int tileX = nTile % tilesX;
int tileY = nTile / tilesX;
label_tile:
{
for (int sy = 0; sy < smpl_size; sy++) {
int y = tileY + sy - smpl_half;
if ((y >= 0) && (y < tilesY)) {
for (int sx = 0; sx < smpl_size; sx++) {
int x = tileX + sx - smpl_half;
if ((x >= 0) && (x < tilesX)) {
int indx = x + y * tilesX;
if ((known[indx] || (expanding_prev[indx]) && !Double.isNaN(values[indx]))) {
if ( (extend_far && (values[indx] < threshold)) ||
(!extend_far && (values[indx] > threshold))){
expanding[nTile] = true;
num_new[this_thread] ++;
break label_tile;
}
}
}
}
}
}
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
// int this_thread = ai_thread.getAndIncrement();
for (int nTile = ai.getAndIncrement(); nTile < known.length; nTile = ai.getAndIncrement()){
if (expanding[nTile] && !expanding_prev[nTile]){
values[nTile] = Double.NaN;
known[nTile] = false;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
int total_new = 0;
for (int i = 0; i < num_new.length; i++){
total_new +=num_new[i];
}
return total_new;
}
public boolean [] expandDiscontinuity( // return maximal correction value
final ArrayList <CLTPass3d> passes,
final int firstPass,
final int lastPassPlus1,
final double [] values, // will be modified, Double.NaN is not yet assigned
final boolean [] known, // cells with known values (will not be modified)
final int num_steps, // how far to extend
// final boolean [] new_cells, // cells that need to be calculated
final int smpl_size, // == 5
final int min_points, // == 3
final boolean use_wnd, // use window function for the neighbors
final double tilt_cost,
final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
final double same_range, // modify
final double diff_continue, // maximal difference from the old value (for previously defined tiles
final double max_abs_tilt, // = 2.0; // pix per tile
final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
final boolean extend_far, // extend far (false - extend near)
final int max_tries, // maximal number of smoothing steps
final double final_diff, // maximal change to finish iterations
final double grow_disp_max,
final double unique_pre_tolerance, // usually larger than clt_parameters.unique_tolerance
final int dbg_x,
final int dbg_y,
final int debugLevel)
{
boolean [] expanding = startDiscontinuity(
values, // final double [] values, // will be modified, Double.NaN is not yet assigned
known, // final boolean [] known, // cells with known values (will not be modified)
smpl_size, // final int smpl_size, // == 5
split_threshold, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
extend_far, // final boolean extend_far, // extend far (false - extend near)
true, // final boolean no_zero, // do not use values[i] == 0.0, exact 0.0 is only background
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel); // final int debugLevel)
if (expanding == null){
return null; // no discontinuity seeds
}
boolean [] prohibited = tp.getTriedBefore(
passes, // final ArrayList <CLTPass3d> passes,
firstPass, // final int firstPass,
lastPassPlus1, // final int lastPassPlus1,
expanding, // final boolean [] selected,
null, // final boolean [] prohibited,
values, // final double [] disparity,
true, // final boolean mod_selected,
true, // final boolean mod_disparity,
grow_disp_max, // final double grow_disp_max,
unique_pre_tolerance); // final double unique_pre_tolerance)
for (int nstep = 0; nstep < num_steps; nstep++){
int num_new_cells = 0;
if (nstep > 0){
num_new_cells = expandDiscontinuityStep(
values, // final double [] values, // will be modified, Double.NaN is not yet assigned
known, // final boolean [] known, // cells with known values (will not be modified)
prohibited, // final boolean [] prohibited, // cells that can not be used (tried before with similar disparity)
expanding, // final boolean [] expanding, // cells with known values (will not be modified)
smpl_size, //final int smpl_size, // == 5
split_threshold, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
extend_far, // final boolean extend_far, // extend far (false - extend near)
false, // inal boolean unknown_only, // pure expanding, not over previously found values
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel); // final int debugLevel)
tp.getTriedBefore(
passes, // final ArrayList <CLTPass3d> passes,
firstPass, // final int firstPass,
lastPassPlus1, // final int lastPassPlus1,
expanding, // final boolean [] selected,
prohibited, // final boolean [] prohibited,
values, // final double [] disparity,
true, // final boolean mod_selected,
true, // final boolean mod_disparity,
grow_disp_max, // final double grow_disp_max,
unique_pre_tolerance); // final double unique_pre_tolerance)
}
int mt = 2 * (nstep + 1); // max_tries; // or use k * nstep ???
// increase tries last iteration?
if (((num_new_cells == 0) && (nstep > 0)) || (nstep == (num_steps -1))) {
mt = max_tries; // last time smooth more
}
for (int num_try = 0; num_try < mt; num_try ++){
if (debugLevel > 1){
System.out.print("expandDiscontinuity(): nstep="+nstep+" num_try="+num_try+" ");
if (num_try == (mt - 1)){
System.out.print("expandDiscontinuity(): LAST try ");
}
}
double max_diff = smoothNewStep( // return maximal correction value
// should first be initialized with all not known = Double.NaN
values, // final double [] values, // will be modified, Double.NaN is not yet assigned
expanding, // final boolean [] new_cells, // cells that need to be calculated
smpl_size, // final int smpl_size, // == 5
min_points, // final int min_points, // == 3
use_wnd, // final boolean use_wnd, // use window function fro the neighbors
tilt_cost, // final double tilt_cost,
split_threshold, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
same_range, // final double same_range, // modify
diff_continue, // final double diff_continue, // maximal difference from the old value (for previously defined tiles
max_abs_tilt, // final double max_abs_tilt, // = 2.0; // pix per tile
max_rel_tilt, // final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
true, // final boolean en_normal, // expand sngle-range cells (that have all neighbors within split_threshold)
extend_far, // final boolean en_far, // expand background - use neighbors cells within same_range from the lowest
// en_near is only valid if !en_far
!extend_far, // final boolean en_near, // expand foreground - use neighbors cells within same_range from the highest
(num_try == 0), // new_only, // first run - set new cells, later - smooth all
true, // final boolean no_zero, // do not use values[i] == 0.0, exact 0.0 is only background
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel); // final int debugLevel);
if (debugLevel > 1){
System.out.println("expandDiscontinuity() -> max_diff="+max_diff);
}
if (max_diff <= final_diff) break;
}
if (debugLevel > 1){
System.out.println("expandDiscontinuity(): nstep="+nstep+" mt="+mt);
}
}
return expanding;
}
public boolean[] expandKnown( // return maximal correction value
// should first be initialized with all not known = Double.NaN
final ArrayList <CLTPass3d> passes,
final int firstPass,
final int lastPassPlus1,
final double [] values, // will be modified, Double.NaN is not yet assigned
final boolean [] known, // cells with known values (will not be modified)
final int num_steps, // how far to extend
final int smpl_size, // == 5
final int min_points, // == 3
final boolean use_wnd, // use window function fro the neighbors
final double tilt_cost,
final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
final double same_range, // modify
final double diff_continue, // maximal difference from the old value (for previously defined tiles
final double max_abs_tilt, // = 2.0; // pix per tile
final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
final boolean smooth_only, // Do not expand ambiguous cells (with discontinuity)
final boolean extend_far, // extend far (false - extend near)
final int max_tries, // maximal number of smoothing steps
final double final_diff, // maximal change to finish iterations
final double grow_disp_max,
final double unique_pre_tolerance, // usually larger than clt_parameters.unique_tolerance
final int dbg_x,
final int dbg_y,
final int debugLevel)
{
boolean [] expanding = startExpanding(
values, // final double [] values, // will be modified, Double.NaN is not yet assigned
known, // final boolean [] known, // cells with known values (will not be modified)
smpl_size, // final int smpl_size, // == 5
true, // final boolean no_zero, // do not use values[i] == 0.0, exact 0.0 is only background
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel+0); // final int debugLevel) // +2 for image
if (expanding == null){
return null; // no discontinuity seeds
}
boolean [] prohibited = tp.getTriedBefore(
passes, // final ArrayList <CLTPass3d> passes,
firstPass, // final int firstPass,
lastPassPlus1, // final int lastPassPlus1,
expanding, // final boolean [] selected,
null, // final boolean [] prohibited,
values, // final double [] disparity,
true, // final boolean mod_selected,
true, // final boolean mod_disparity,
grow_disp_max, // final double grow_disp_max,
unique_pre_tolerance); // final double unique_pre_tolerance)
for (int nstep = 0; nstep < num_steps; nstep++){
int num_new_cells = 0;
if (nstep > 0){
num_new_cells = expandDiscontinuityStep(
values, // final double [] values, // will be modified, Double.NaN is not yet assigned
known, // final boolean [] known, // cells with known values (will not be modified)
prohibited, // final boolean [] prohibited, // cells that can not be used (tried before with similar disparity)
expanding, // final boolean [] expanding, // cells with known values (will not be modified)
smpl_size, //final int smpl_size, // == 5
split_threshold, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
extend_far, // final boolean extend_far, // extend far (false - extend near)
true, // final boolean unknown_only, // pure expanding, not over previously found values
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel); // final int debugLevel)
tp.getTriedBefore(
passes, // final ArrayList <CLTPass3d> passes,
firstPass, // final int firstPass,
lastPassPlus1, // final int lastPassPlus1,
expanding, // final boolean [] selected,
prohibited, // final boolean [] prohibited,
values, // final double [] disparity,
true, // final boolean mod_selected,
true, // final boolean mod_disparity,
grow_disp_max, // final double grow_disp_max,
unique_pre_tolerance); // final double unique_pre_tolerance)
}
int mt = 2 * (nstep + 1); // max_tries; // or use k * nstep ???
// increase tries last iteration?
if (((num_new_cells == 0) && (nstep > 0)) || (nstep == (num_steps -1))) {
mt = max_tries; // last time smooth more
}
for (int num_try = 0; num_try < mt; num_try ++){
if (debugLevel >1){
System.out.print("expandKnown(): nstep="+nstep+" num_try="+num_try+" ");
if (num_try == (mt - 1)){
System.out.print("expandKnown(): LAST try ");
}
}
double max_diff = smoothNewStep( // return maximal correction value
// should first be initialized with all not known = Double.NaN
values, // final double [] values, // will be modified, Double.NaN is not yet assigned
expanding, // final boolean [] new_cells, // cells that need to be calculated
smpl_size, // final int smpl_size, // == 5
min_points, // final int min_points, // == 3
use_wnd, // final boolean use_wnd, // use window function fro the neighbors
tilt_cost, // final double tilt_cost,
split_threshold, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
same_range, // final double same_range, // modify
diff_continue, // final double diff_continue, // maximal difference from the old value (for previously defined tiles
max_abs_tilt, // final double max_abs_tilt, // = 2.0; // pix per tile
max_rel_tilt, // final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
true, // final boolean en_normal, // expand sngle-range cells (that have all neighbors within split_threshold)
!smooth_only && extend_far, // final boolean en_far, // expand background - use neighbors cells within same_range from the lowest
// en_near is only valid if !en_far
!smooth_only && !extend_far, // final boolean en_near, // expand foreground - use neighbors cells within same_range from the highest
(num_try == 0), // new_only, // first run - set new cells, later - smooth all
true, // final boolean no_zero, // do not use values[i] == 0.0, exact 0.0 is only background
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel); // final int debugLevel);
if (debugLevel > 1){
System.out.println("expandKnown() -> max_diff="+max_diff);
}
if (max_diff <= final_diff) break;
}
if (debugLevel > 1){
System.out.println("expandKnown(): nstep="+nstep+" mt="+mt);
}
}
return expanding;
}
}
......@@ -1935,6 +1935,7 @@ public class EyesisCorrectionParameters {
public double vignetting_range = 5.0; // do not try to correct vignetting less than vignetting_max/vignetting_range
public int kernel_step = 16; // source kernels step in pixels (have 1 kernel margin on each side)
public double disparity = 0.0; // nominal disparity between side of square cameras (pix)
public double z_correction = 0.0; // Inverse distance to infinity (misalignment cortrection)
public boolean correlate = true; // calculate correlation
public int corr_mask = 15; // bitmask of pairs to combine in the composite
public boolean corr_sym = false; // combine correlation with mirrored around disparity direction
......@@ -2123,7 +2124,7 @@ public class EyesisCorrectionParameters {
public double poles_min_strength = 0.1; // Set new pole segment strength to max of horizontal correlation and this value
public boolean poles_force_disp = true; // Set disparity to that of the bottom of existing segment (false - use hor. disparity)
public int max_clusters = 300; // Maximal number of clusters to generate for one run
public int max_clusters = 500; // Maximal number of clusters to generate for one run
public boolean remove_scans = true; // Remove all unneeded scans when generating x3d output to save memory
......@@ -2209,7 +2210,9 @@ public class EyesisCorrectionParameters {
public double combine_min_strength = 0.12; // Disregard weaker tiles when combining scans
public double combine_min_hor = 0.12; // Disregard weaker tiles when combining scans for horizontal correlation
public double combine_min_vert = 0.12; // Disregard weaker tiles when combining scans for vertical correlation
public double unique_tolerance = 0.1; // Do not re-measure correlation if target disparity differs from some previous by this
// TODO: Move together with similar parameters
// public double unique_tolerance = 0.1; // Do not re-measure correlation if target disparity differs from some previous by this
// Multi-pass growing disparity
public int grow_sweep = 8; // Try these number of tiles around known ones
......@@ -2222,6 +2225,46 @@ public class EyesisCorrectionParameters {
public boolean grow_pedantic = false; // Scan full range between max_tried_disparity of the background and known foreground
public boolean grow_retry_inf = false; // Retry border tiles that were identified as infinity earlier
// New for initial growing
public boolean gr_new_expand = true;
public int gr_max_expand = 500; // 150; // 30;
public double gr_strength_floor = 0.9; // Should be normally less than combine_min_strength
public double gr_comboMinStrength = 0.3; // 0.3;
public double gr_comboMinStrengthHor = 0.3; // 0.3;
public double gr_comboMinStrengthVert = 0.3; // 0.3;
public double gr_filterMinStrength = 0.3; // 0.3;
public double gr_strength_pow = 1.0;
public int gr_smplSide = 5; // 3; // Sample size (side of a square)
public int gr_smplNum = 13; // 13; // 5; // Number after removing worst (should be >1)
public double gr_smplRms = 0.15; // Maximal RMS of the remaining tiles in a sample
public double gr_smplRelRms = 0.01; // 05; // Maximal RMS/disparity in addition to smplRms
public boolean gr_smplWnd = true; //
public double gr_max_abs_tilt = 2.0; // pix per tile
public double gr_max_rel_tilt = 0.2; // (pix / disparity) per tile
// 0x1e, // 0x1f, // final int variants_mask,
public int gr_min_new = 20; // Discard variant if it requests too few tiles
public boolean gr_var_new_sngl = false;// Expand only unambiguous tiles over previously undefined
public boolean gr_var_new_fg = true; // Expand unambiguous and foreground tiles over previously undefined
public boolean gr_var_all_fg = true;
public boolean gr_var_new_bg = true;
public boolean gr_var_all_bg = true;
public int gr_num_steps = 8; // How far to extend over previously undefined disparity tiles
public int gr_steps_over = 4; // How far to extend over previously determined disparity tiles
public int gr_smpl_size = 5; // Extend sample square side
public int gr_min_pnts = 3; // Extend at least this number of the seed tiles
public boolean gr_use_wnd = true; // Use window function for square sample
public double gr_tilt_damp = 0.001;// Tilt cost for damping insufficient plane data
public double gr_split_rng = 5.0; // When growing, range of disparities to be extended without far/near division
public double gr_same_rng = 3.0; // consider far/near tiles within that range from the farthest/closest
public double gr_diff_cont = 2.0; // Maximal difference from the old value when smoothing
public double gr_abs_tilt = 2.0; // Maximal filter disparity absolute tilt (pix per tile)
public double gr_rel_tilt = 0.2; // Maximal filter disparity tilt (pix / disparity) per tile
public int gr_smooth = 50; // Maximal number of smoothing steps (reduce if long?)
public double gr_fin_diff = 0.01; // Maximal change to finish smoothing iterations
public double gr_unique_tol = 0.15; // Do not re-measure correlation if target disparity differs from some previous by this
public double gr_unique_pretol = 0.5; // Larger tolerance for expanding (not refining)
public boolean plPreferDisparity = false;// Always start with disparity-most axis (false - lowest eigenvalue)
public double plDispNorm = 5.0; // Normalize disparities to the average if above (now only for eigenvalue comparison)
......@@ -2512,6 +2555,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"vignetting_range", this.vignetting_range+"");
properties.setProperty(prefix+"kernel_step", this.kernel_step+"");
properties.setProperty(prefix+"disparity", this.disparity +"");
properties.setProperty(prefix+"z_correction", this.z_correction +"");
properties.setProperty(prefix+"correlate", this.correlate+"");
properties.setProperty(prefix+"corr_mask", this.corr_mask+"");
properties.setProperty(prefix+"corr_sym", this.corr_sym+"");
......@@ -2758,7 +2802,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"combine_min_strength", this.combine_min_strength +"");
properties.setProperty(prefix+"combine_min_hor", this.combine_min_hor +"");
properties.setProperty(prefix+"combine_min_vert", this.combine_min_vert +"");
properties.setProperty(prefix+"unique_tolerance", this.unique_tolerance +"");
// properties.setProperty(prefix+"unique_tolerance", this.unique_tolerance +"");
properties.setProperty(prefix+"grow_sweep", this.grow_sweep+"");
properties.setProperty(prefix+"grow_disp_max", this.grow_disp_max +"");
properties.setProperty(prefix+"grow_disp_trust", this.grow_disp_trust +"");
......@@ -2767,6 +2811,43 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"grow_retry_far", this.grow_retry_far+"");
properties.setProperty(prefix+"grow_pedantic", this.grow_pedantic+"");
properties.setProperty(prefix+"grow_retry_inf", this.grow_retry_inf+"");
properties.setProperty(prefix+"gr_new_expand", this.gr_new_expand+"");
properties.setProperty(prefix+"gr_max_expand", this.gr_max_expand+"");
properties.setProperty(prefix+"gr_strength_floor",this.gr_strength_floor +"");
properties.setProperty(prefix+"gr_comboMinStrength", this.gr_comboMinStrength +"");
properties.setProperty(prefix+"gr_comboMinStrengthHor", this.gr_comboMinStrengthHor +"");
properties.setProperty(prefix+"gr_comboMinStrengthVert",this.gr_comboMinStrengthVert +"");
properties.setProperty(prefix+"gr_filterMinStrength", this.gr_filterMinStrength +"");
properties.setProperty(prefix+"gr_strength_pow", this.gr_strength_pow +"");
properties.setProperty(prefix+"gr_smplSide", this.gr_smplSide+"");
properties.setProperty(prefix+"gr_smplNum", this.gr_smplNum+"");
properties.setProperty(prefix+"gr_smplRms", this.gr_smplRms +"");
properties.setProperty(prefix+"gr_smplRelRms", this.gr_smplRelRms +"");
properties.setProperty(prefix+"gr_smplWnd", this.gr_smplWnd+"");
properties.setProperty(prefix+"gr_max_abs_tilt", this.gr_max_abs_tilt +"");
properties.setProperty(prefix+"gr_max_rel_tilt", this.gr_max_rel_tilt +"");
properties.setProperty(prefix+"gr_min_new", this.gr_min_new+"");
properties.setProperty(prefix+"gr_var_new_sngl", this.gr_var_new_sngl+"");
properties.setProperty(prefix+"gr_var_new_fg", this.gr_var_new_fg+"");
properties.setProperty(prefix+"gr_var_all_fg", this.gr_var_all_fg+"");
properties.setProperty(prefix+"gr_var_new_bg", this.gr_var_new_bg+"");
properties.setProperty(prefix+"gr_var_all_bg", this.gr_var_all_bg+"");
properties.setProperty(prefix+"gr_num_steps", this.gr_num_steps+"");
properties.setProperty(prefix+"gr_steps_over", this.gr_steps_over+"");
properties.setProperty(prefix+"gr_smpl_size", this.gr_smpl_size+"");
properties.setProperty(prefix+"gr_min_pnts", this.gr_min_pnts+"");
properties.setProperty(prefix+"gr_use_wnd", this.gr_use_wnd+"");
properties.setProperty(prefix+"gr_tilt_damp", this.gr_tilt_damp +"");
properties.setProperty(prefix+"gr_split_rng", this.gr_split_rng +"");
properties.setProperty(prefix+"gr_same_rng", this.gr_same_rng +"");
properties.setProperty(prefix+"gr_diff_cont", this.gr_diff_cont +"");
properties.setProperty(prefix+"gr_abs_tilt", this.gr_abs_tilt +"");
properties.setProperty(prefix+"gr_rel_tilt", this.gr_rel_tilt +"");
properties.setProperty(prefix+"gr_smooth", this.gr_smooth+"");
properties.setProperty(prefix+"gr_fin_diff", this.gr_fin_diff +"");
properties.setProperty(prefix+"gr_unique_tol", this.gr_unique_tol +"");
properties.setProperty(prefix+"gr_unique_pretol", this.gr_unique_pretol +"");
properties.setProperty(prefix+"plPreferDisparity",this.plPreferDisparity+"");
properties.setProperty(prefix+"plDispNorm", this.plDispNorm +"");
......@@ -3032,6 +3113,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"vignetting_range")!=null) this.vignetting_range=Double.parseDouble(properties.getProperty(prefix+"vignetting_range"));
if (properties.getProperty(prefix+"kernel_step")!=null) this.kernel_step=Integer.parseInt(properties.getProperty(prefix+"kernel_step"));
if (properties.getProperty(prefix+"disparity")!=null) this.disparity=Double.parseDouble(properties.getProperty(prefix+"disparity"));
if (properties.getProperty(prefix+"z_correction")!=null) this.z_correction=Double.parseDouble(properties.getProperty(prefix+"z_correction"));
if (properties.getProperty(prefix+"correlate")!=null) this.correlate=Boolean.parseBoolean(properties.getProperty(prefix+"correlate"));
if (properties.getProperty(prefix+"corr_mask")!=null) this.corr_mask=Integer.parseInt(properties.getProperty(prefix+"corr_mask"));
if (properties.getProperty(prefix+"corr_sym")!=null) this.corr_sym=Boolean.parseBoolean(properties.getProperty(prefix+"corr_sym"));
......@@ -3275,7 +3357,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"combine_min_strength")!=null) this.combine_min_strength=Double.parseDouble(properties.getProperty(prefix+"combine_min_strength"));
if (properties.getProperty(prefix+"combine_min_hor")!=null) this.combine_min_hor=Double.parseDouble(properties.getProperty(prefix+"combine_min_hor"));
if (properties.getProperty(prefix+"combine_min_vert")!=null) this.combine_min_vert=Double.parseDouble(properties.getProperty(prefix+"combine_min_vert"));
if (properties.getProperty(prefix+"unique_tolerance")!=null) this.unique_tolerance=Double.parseDouble(properties.getProperty(prefix+"unique_tolerance"));
// if (properties.getProperty(prefix+"unique_tolerance")!=null) this.unique_tolerance=Double.parseDouble(properties.getProperty(prefix+"unique_tolerance"));
if (properties.getProperty(prefix+"grow_sweep")!=null) this.grow_sweep=Integer.parseInt(properties.getProperty(prefix+"grow_sweep"));
if (properties.getProperty(prefix+"grow_disp_max")!=null) this.grow_disp_max=Double.parseDouble(properties.getProperty(prefix+"grow_disp_max"));
if (properties.getProperty(prefix+"grow_disp_trust")!=null) this.grow_disp_trust=Double.parseDouble(properties.getProperty(prefix+"grow_disp_trust"));
......@@ -3284,7 +3366,44 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"grow_retry_far")!=null) this.grow_retry_far=Boolean.parseBoolean(properties.getProperty(prefix+"grow_retry_far"));
if (properties.getProperty(prefix+"grow_pedantic")!=null) this.grow_pedantic=Boolean.parseBoolean(properties.getProperty(prefix+"grow_pedantic"));
if (properties.getProperty(prefix+"grow_retry_inf")!=null) this.grow_retry_inf=Boolean.parseBoolean(properties.getProperty(prefix+"grow_retry_inf"));
if (properties.getProperty(prefix+"gr_new_expand")!=null) this.gr_new_expand=Boolean.parseBoolean(properties.getProperty(prefix+"gr_new_expand"));
if (properties.getProperty(prefix+"gr_max_expand")!=null) this.gr_max_expand=Integer.parseInt(properties.getProperty(prefix+"gr_max_expand"));
if (properties.getProperty(prefix+"gr_strength_floor")!=null) this.gr_strength_floor=Double.parseDouble(properties.getProperty(prefix+"gr_strength_floor"));
if (properties.getProperty(prefix+"gr_comboMinStrength")!=null) this.gr_comboMinStrength=Double.parseDouble(properties.getProperty(prefix+"gr_comboMinStrength"));
if (properties.getProperty(prefix+"gr_comboMinStrengthHor")!=null) this.gr_comboMinStrengthHor=Double.parseDouble(properties.getProperty(prefix+"gr_comboMinStrengthHor"));
if (properties.getProperty(prefix+"gr_comboMinStrengthVert")!=null) this.gr_comboMinStrengthVert=Double.parseDouble(properties.getProperty(prefix+"gr_comboMinStrengthVert"));
if (properties.getProperty(prefix+"gr_filterMinStrength")!=null) this.gr_filterMinStrength=Double.parseDouble(properties.getProperty(prefix+"gr_filterMinStrength"));
if (properties.getProperty(prefix+"gr_strength_pow")!=null) this.gr_strength_pow=Double.parseDouble(properties.getProperty(prefix+"gr_strength_pow"));
if (properties.getProperty(prefix+"gr_smplSide")!=null) this.gr_smplSide=Integer.parseInt(properties.getProperty(prefix+"gr_smplSide"));
if (properties.getProperty(prefix+"gr_smplNum")!=null) this.gr_smplNum=Integer.parseInt(properties.getProperty(prefix+"gr_smplNum"));
if (properties.getProperty(prefix+"gr_smplRms")!=null) this.gr_smplRms=Double.parseDouble(properties.getProperty(prefix+"gr_smplRms"));
if (properties.getProperty(prefix+"gr_smplRelRms")!=null) this.gr_smplRelRms=Double.parseDouble(properties.getProperty(prefix+"gr_smplRelRms"));
if (properties.getProperty(prefix+"gr_smplWnd")!=null) this.gr_smplWnd=Boolean.parseBoolean(properties.getProperty(prefix+"gr_smplWnd"));
if (properties.getProperty(prefix+"gr_max_abs_tilt")!=null) this.gr_max_abs_tilt=Double.parseDouble(properties.getProperty(prefix+"gr_max_abs_tilt"));
if (properties.getProperty(prefix+"gr_max_rel_tilt")!=null) this.gr_max_rel_tilt=Double.parseDouble(properties.getProperty(prefix+"gr_max_rel_tilt"));
if (properties.getProperty(prefix+"gr_min_new")!=null) this.gr_min_new=Integer.parseInt(properties.getProperty(prefix+"gr_min_new"));
if (properties.getProperty(prefix+"gr_var_new_sngl")!=null) this.gr_var_new_sngl=Boolean.parseBoolean(properties.getProperty(prefix+"gr_var_new_sngl"));
if (properties.getProperty(prefix+"gr_var_new_fg")!=null) this.gr_var_new_fg=Boolean.parseBoolean(properties.getProperty(prefix+"gr_var_new_fg"));
if (properties.getProperty(prefix+"gr_var_all_fg")!=null) this.gr_var_all_fg=Boolean.parseBoolean(properties.getProperty(prefix+"gr_var_all_fg"));
if (properties.getProperty(prefix+"gr_var_new_bg")!=null) this.gr_var_new_bg=Boolean.parseBoolean(properties.getProperty(prefix+"gr_var_new_bg"));
if (properties.getProperty(prefix+"gr_var_all_bg")!=null) this.gr_var_all_bg=Boolean.parseBoolean(properties.getProperty(prefix+"gr_var_all_bg"));
if (properties.getProperty(prefix+"gr_num_steps")!=null) this.gr_num_steps=Integer.parseInt(properties.getProperty(prefix+"gr_num_steps"));
if (properties.getProperty(prefix+"gr_steps_over")!=null) this.gr_steps_over=Integer.parseInt(properties.getProperty(prefix+"gr_steps_over"));
if (properties.getProperty(prefix+"gr_smpl_size")!=null) this.gr_smpl_size=Integer.parseInt(properties.getProperty(prefix+"gr_smpl_size"));
if (properties.getProperty(prefix+"gr_min_pnts")!=null) this.gr_min_pnts=Integer.parseInt(properties.getProperty(prefix+"gr_min_pnts"));
if (properties.getProperty(prefix+"gr_use_wnd")!=null) this.gr_use_wnd=Boolean.parseBoolean(properties.getProperty(prefix+"gr_use_wnd"));
if (properties.getProperty(prefix+"gr_tilt_damp")!=null) this.gr_tilt_damp=Double.parseDouble(properties.getProperty(prefix+"gr_tilt_damp"));
if (properties.getProperty(prefix+"gr_split_rng")!=null) this.gr_split_rng=Double.parseDouble(properties.getProperty(prefix+"gr_split_rng"));
if (properties.getProperty(prefix+"gr_same_rng")!=null) this.gr_same_rng=Double.parseDouble(properties.getProperty(prefix+"gr_same_rng"));
if (properties.getProperty(prefix+"gr_diff_cont")!=null) this.gr_diff_cont=Double.parseDouble(properties.getProperty(prefix+"gr_diff_cont"));
if (properties.getProperty(prefix+"gr_abs_tilt")!=null) this.gr_abs_tilt=Double.parseDouble(properties.getProperty(prefix+"gr_abs_tilt"));
if (properties.getProperty(prefix+"gr_rel_tilt")!=null) this.gr_rel_tilt=Double.parseDouble(properties.getProperty(prefix+"gr_rel_tilt"));
if (properties.getProperty(prefix+"gr_smooth")!=null) this.gr_smooth=Integer.parseInt(properties.getProperty(prefix+"gr_smooth"));
if (properties.getProperty(prefix+"gr_fin_diff")!=null) this.gr_fin_diff=Double.parseDouble(properties.getProperty(prefix+"gr_fin_diff"));
if (properties.getProperty(prefix+"gr_unique_tol")!=null) this.gr_unique_tol=Double.parseDouble(properties.getProperty(prefix+"gr_unique_tol"));
if (properties.getProperty(prefix+"gr_unique_pretol")!=null) this.gr_unique_pretol=Double.parseDouble(properties.getProperty(prefix+"gr_unique_pretol"));
if (properties.getProperty(prefix+"plPreferDisparity")!=null) this.plPreferDisparity=Boolean.parseBoolean(properties.getProperty(prefix+"plPreferDisparity"));
if (properties.getProperty(prefix+"plDispNorm")!=null) this.plDispNorm=Double.parseDouble(properties.getProperty(prefix+"plDispNorm"));
......@@ -3556,8 +3675,9 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Do not try to correct vignetting smaller than this fraction of max", this.vignetting_range, 3);
gd.addNumericField("Kernel step in pixels (has 1 kernel margin on each side)", this.kernel_step, 0);
gd.addNumericField("Nominal (rectilinear) disparity between side of square cameras (pix)", this.disparity, 3);
gd.addNumericField("Inverse distance to infinity (misalignment cortrection)", this.z_correction, 6);
gd.addCheckbox ("Perform correlation", this.correlate);
gd.addNumericField("itmask of pairs to combine in the composite (top, bottom, left,righth)", this.corr_mask, 0);
gd.addNumericField("Bitmask of pairs to combine in the composite (top, bottom, left,righth)", this.corr_mask, 0);
gd.addCheckbox ("Combine correlation with mirrored around disparity direction", this.corr_sym);
gd.addCheckbox ("Keep all partial correlations (otherwise - only combined one)", this.corr_keep);
gd.addCheckbox ("Show combined correlations", this.corr_show);
......@@ -3824,9 +3944,9 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Disregard weaker tiles when combining scans", this.combine_min_strength, 6);
gd.addNumericField("Disregard weaker tiles when combining scans for horizontal correlation", this.combine_min_hor, 6);
gd.addNumericField("Disregard weaker tiles when combining scans for vertical correlation", this.combine_min_vert, 6);
gd.addNumericField("Do not re-measure correlation if target disparity differs from some previous by this",this.unique_tolerance, 6);
// gd.addNumericField("Do not re-measure correlation if target disparity differs from some previous by this",this.unique_tolerance, 6);
gd.addMessage ("--- Growing disparity range to scan ---");
gd.addMessage ("========= Growing disparity range to scan ========");
gd.addNumericField("Try these number of tiles around known ones", this.grow_sweep, 0);
gd.addNumericField("Maximal disparity to try", this.grow_disp_max, 6);
gd.addNumericField("Trust measured disparity within +/- this value", this.grow_disp_trust, 6);
......@@ -3836,6 +3956,46 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Scan full range between max_tried_disparity of the background and known foreground", this.grow_pedantic);
gd.addCheckbox ("Retry border tiles that were identified as infinity earlier", this.grow_retry_inf);
gd.addMessage ("--- more growing parameters ---");
gd.addCheckbox ("New expansion mode", this.gr_new_expand);
gd.addNumericField("Expansion steps limit", this.gr_max_expand, 0);
gd.addNumericField("Strength floor for multi-tile (now 5x5) samples (normally < combine_min_strength) ", this.gr_strength_floor, 6);
gd.addNumericField("Over background extra reliable strength", this.gr_comboMinStrength, 6);
gd.addNumericField("Over background extra reliable strength horizontal", this.gr_comboMinStrengthHor, 6);
gd.addNumericField("Over background extra reliable strength vertical", this.gr_comboMinStrengthVert, 6);
gd.addNumericField("Over background filtered extra reliable strength", this.gr_filterMinStrength, 6);
gd.addNumericField("Strength power exponent for tilted plates growing", this.gr_strength_pow, 6);
gd.addNumericField("Sample size (side of a square) for tilted plates growing", this.gr_smplSide, 0);
gd.addNumericField("Number of tiles in a square tilted plate (should be >1)", this.gr_smplNum, 0);
gd.addNumericField("Maximal RMS for the tiles to the tilted plate", this.gr_smplRms, 6);
gd.addNumericField("Maximal relative RMS for the tiles to the tilted plate - multiply by disparity and add", this.gr_smplRelRms, 6);
gd.addCheckbox ("Use window function for the square sample plates", this.gr_smplWnd);
gd.addNumericField("Maximal growing plate tilt in disparity pix per tile", this.gr_max_abs_tilt, 6);
gd.addNumericField("Maximal relative growing plate tilt in disparity pix per tile per disaprity pixel", this.gr_max_rel_tilt, 6);
gd.addNumericField("Discard variant if it requests too few tiles", this.gr_min_new, 0);
gd.addCheckbox ("Retry tiles around known foreground that have low max_tried_disparity", this.gr_var_new_sngl);
gd.addCheckbox ("Retry tiles around known foreground that have low max_tried_disparity", this.gr_var_new_fg);
gd.addCheckbox ("Retry tiles around known foreground that have low max_tried_disparity", this.gr_var_all_fg);
gd.addCheckbox ("Retry tiles around known foreground that have low max_tried_disparity", this.gr_var_new_bg);
gd.addCheckbox ("Retry tiles around known foreground that have low max_tried_disparity", this.gr_var_all_bg);
gd.addNumericField("Try these number of tiles around known ones", this.gr_num_steps, 0);
gd.addNumericField("Try these number of tiles around known ones", this.gr_steps_over, 0);
gd.addNumericField("Try these number of tiles around known ones", this.gr_smpl_size, 0);
gd.addNumericField("Try these number of tiles around known ones", this.gr_min_pnts, 0);
gd.addCheckbox ("Retry tiles around known foreground that have low max_tried_disparity", this.gr_use_wnd);
gd.addNumericField("Maximal disparity to try", this.gr_tilt_damp, 6);
gd.addNumericField("Maximal disparity to try", this.gr_split_rng, 6);
gd.addNumericField("Maximal disparity to try", this.gr_same_rng, 6);
gd.addNumericField("Maximal disparity to try", this.gr_diff_cont, 6);
gd.addNumericField("Maximal disparity to try", this.gr_abs_tilt, 6);
gd.addNumericField("Maximal disparity to try", this.gr_rel_tilt, 6);
gd.addNumericField("Try these number of tiles around known ones", this.gr_smooth, 0);
gd.addNumericField("Maximal disparity to try", this.gr_fin_diff, 6);
gd.addNumericField("Maximal disparity to try", this.gr_unique_tol, 6);
gd.addNumericField("Maximal disparity to try", this.gr_unique_pretol, 6);
gd.addMessage ("--- Planes detection ---");
gd.addCheckbox ("Always start with disparity-most axis (false - lowest eigenvalue)", this.plPreferDisparity);
gd.addNumericField("Normalize disparities to the average if above", this.plDispNorm, 6);
......@@ -4112,6 +4272,7 @@ public class EyesisCorrectionParameters {
this.vignetting_range= gd.getNextNumber();
this.kernel_step= (int) gd.getNextNumber();
this.disparity= gd.getNextNumber();
this.z_correction= gd.getNextNumber();
this.correlate= gd.getNextBoolean();
this.corr_mask= (int) gd.getNextNumber();
this.corr_sym= gd.getNextBoolean();
......@@ -4362,8 +4523,7 @@ public class EyesisCorrectionParameters {
this.combine_min_strength= gd.getNextNumber();
this.combine_min_hor= gd.getNextNumber();
this.combine_min_vert= gd.getNextNumber();
this.unique_tolerance= gd.getNextNumber();
// this.unique_tolerance= gd.getNextNumber();
this.grow_sweep= (int) gd.getNextNumber();
this.grow_disp_max= gd.getNextNumber();
this.grow_disp_trust= gd.getNextNumber();
......@@ -4372,6 +4532,43 @@ public class EyesisCorrectionParameters {
this.grow_retry_far= gd.getNextBoolean();
this.grow_pedantic= gd.getNextBoolean();
this.grow_retry_inf= gd.getNextBoolean();
this.gr_new_expand= gd.getNextBoolean();
this.gr_max_expand= (int) gd.getNextNumber();
this.gr_strength_floor= gd.getNextNumber();
this.gr_comboMinStrength= gd.getNextNumber();
this.gr_comboMinStrengthHor= gd.getNextNumber();
this.gr_comboMinStrengthVert= gd.getNextNumber();
this.gr_filterMinStrength= gd.getNextNumber();
this.gr_strength_pow= gd.getNextNumber();
this.gr_smplSide= (int) gd.getNextNumber();
this.gr_smplNum= (int) gd.getNextNumber();
this.gr_smplRms= gd.getNextNumber();
this.gr_smplRelRms= gd.getNextNumber();
this.gr_smplWnd= gd.getNextBoolean();
this.gr_max_abs_tilt= gd.getNextNumber();
this.gr_max_rel_tilt= gd.getNextNumber();
this.gr_min_new= (int) gd.getNextNumber();
this.gr_var_new_sngl= gd.getNextBoolean();
this.gr_var_new_fg= gd.getNextBoolean();
this.gr_var_all_fg= gd.getNextBoolean();
this.gr_var_new_bg= gd.getNextBoolean();
this.gr_var_all_bg= gd.getNextBoolean();
this.gr_num_steps= (int) gd.getNextNumber();
this.gr_steps_over= (int) gd.getNextNumber();
this.gr_smpl_size= (int) gd.getNextNumber();
this.gr_min_pnts= (int) gd.getNextNumber();
this.gr_use_wnd= gd.getNextBoolean();
this.gr_tilt_damp= gd.getNextNumber();
this.gr_split_rng= gd.getNextNumber();
this.gr_same_rng= gd.getNextNumber();
this.gr_diff_cont= gd.getNextNumber();
this.gr_abs_tilt= gd.getNextNumber();
this.gr_rel_tilt= gd.getNextNumber();
this.gr_smooth= (int) gd.getNextNumber();
this.gr_fin_diff= gd.getNextNumber();
this.gr_unique_tol= gd.getNextNumber();
this.gr_unique_pretol= gd.getNextNumber();
this.plPreferDisparity= gd.getNextBoolean();
this.plDispNorm= gd.getNextNumber();
......
......@@ -1002,7 +1002,8 @@ public class ImageDtt {
final int transform_size,
final int window_type,
final double [][] shiftXY, // [port]{shiftX,shiftY}
final double [][][] fine_corr, // quadratic cofficients for fine correction (or null)
final double disparity_corr, // disparity at infinity
final double [][][] fine_corr, // quadratic coefficients for fine correction (or null)
final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
final double shiftX, // shift image horizontally (positive - right) - just for testing
final double shiftY, // shift image vertically (positive - down)
......@@ -1030,6 +1031,9 @@ public class ImageDtt {
final int corr_size = transform_size * 2 -1;
final int [][] transpose_indices = new int [corr_size*(corr_size-1)/2][2];
int indx = 0;
if (disparity_corr != 0.0){
System.out.println(String.format("Using manual infinity disparity correction of %8.5f pixels",disparity_corr));
}
for (int i =0; i < corr_size-1; i++){
for (int j = i+1; j < corr_size; j++){
transpose_indices[indx ][0] = i * corr_size + j;
......@@ -1183,7 +1187,7 @@ public class ImageDtt {
double [][] centersXY = geometryCorrection.getPortsCoordinates(
centerX,
centerY,
disparity_array[tileY][tileX]);
disparity_array[tileY][tileX] + disparity_corr);
if ((globalDebugLevel > 0) && (tileX == debug_tileX) && (tileY == debug_tileY)) {
for (int i = 0; i < quad; i++) {
System.out.println("clt_aberrations_quad_corr(): color="+chn+", tileX="+tileX+", tileY="+tileY+
......
......@@ -2674,33 +2674,33 @@ public class LinkPlanes {
System.out.println("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs:");
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs weighted: ");
for (int i = 0; i < costs[0].length;i++) {
if ( costs[0] != null) for (int i = 0; i < costs[0].length;i++) {
System.out.print(costs[0][i]+" ");
}
System.out.println();
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs equalized: ");
for (int i = 0; i < costs[1].length;i++) {
if ( costs[1] != null) for (int i = 0; i < costs[1].length;i++) {
System.out.print(costs[1][i]+" ");
}
System.out.println();
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs weighted, 1-st star, 2-nd measured: ");
for (int i = 0; i < costs[2].length;i++) {
if ( costs[2] != null) for (int i = 0; i < costs[2].length;i++) {
System.out.print(costs[2][i]+" ");
}
System.out.println();
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs equalized, 1-st star, 2-nd measured: ");
for (int i = 0; i < costs[3].length;i++) {
if ( costs[3] != null) for (int i = 0; i < costs[3].length;i++) {
System.out.print(costs[3][i]+" ");
}
System.out.println();
System.out.println();
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs weighted, 1-st measured, 2-nd star: ");
for (int i = 0; i < costs[4].length;i++) {
if ( costs[4] != null) for (int i = 0; i < costs[4].length;i++) {
System.out.print(costs[4][i]+" ");
}
System.out.println();
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs equalized, 1-st measured, 2-nd star: ");
for (int i = 0; i < costs[5].length;i++) {
if ( costs[5] != null) for (int i = 0; i < costs[5].length;i++) {
System.out.print(costs[5][i]+" ");
}
System.out.println();
......
......@@ -584,7 +584,7 @@ public class MeasuredLayers {
* @return double [2][4*superTileSize] {disparity[4*superTileSize], strength [4*superTileSize]}
*/
public double[][] getDisparityStrength (
public double[][] getDisparityStrengthML (
int num_layer,
int stX,
int stY,
......@@ -638,7 +638,7 @@ public class MeasuredLayers {
* @return double {disparity[tilesX * tilesY], strength[tilesX * tilesY]}
*/
public double[][] getDisparityStrength (
public double[][] getDisparityStrengthML (
int num_layer,
double strength_floor,
double strength_pow)
......@@ -750,7 +750,7 @@ public class MeasuredLayers {
for (int dx = 0; dx < st2; dx ++){
int indx = dy * st2 + dx;
if (indx == dbg_tile){
System.out.println("getDisparityStrength(): stX="+stX+" stY="+stY+" dx="+dx+" dy="+dy);
System.out.println("getDisparityStrengthML(): stX="+stX+" stY="+stY+" dx="+dx+" dy="+dy);
}
if (((sel_in == null) || sel_in[indx])){
int num_in_sample = 0;
......@@ -796,7 +796,7 @@ public class MeasuredLayers {
}
}
if (iworst < 0){
System.out.println("**** this is a BUG in getDisparityStrength() ****");
System.out.println("**** this is a BUG in getDisparityStrengthML() ****");
break;
}
// remove worst sample
......@@ -820,7 +820,7 @@ public class MeasuredLayers {
}
} else {
num_in_sample = 0;
System.out.println("**** this is a BUG in getDisparityStrength(), shoud not happen ? ****");
System.out.println("**** this is a BUG in getDisparityStrengthML(), shoud not happen ? ****");
}
}
}
......@@ -884,7 +884,7 @@ public class MeasuredLayers {
}
// testing - redirecting all existing requests to this one with floating planes
public double[][] getDisparityStrength (
public double[][] getDisparityStrengthMLTilted (
int num_layer,
int stX,
int stY,
......@@ -895,13 +895,14 @@ public class MeasuredLayers {
int smplNum, // = 3; // Number after removing worst (should be >1)
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, //
double damp_tilt, //
boolean null_if_none,
int debugLevel)
{
boolean use_new = true; // false;
if (use_new) {
return getDisparityStrength (
return getDisparityStrengthMLTilted (
num_layer, // int num_layer,
stX, // int stX,
stY, // int stY,
......@@ -915,6 +916,7 @@ public class MeasuredLayers {
smplWnd, // boolean smplWnd, //
2.0, // double max_abs_tilt, // = 2.0; // pix per tile
0.2, // double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
damp_tilt, // double damp_tilt, //
null_if_none, // boolean null_if_none,
debugLevel); // int debugLevel)
} else {
......@@ -938,7 +940,7 @@ public class MeasuredLayers {
}
}
public double[][] getDisparityStrength (
public double[][] getDisparityStrengthMLTilted (
int num_layer,
int stX,
int stY,
......@@ -954,6 +956,7 @@ public class MeasuredLayers {
boolean smplWnd, //
double max_abs_tilt, // = 2.0; // pix per tile
double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
double damp_tilt, //
boolean null_if_none,
int debugLevel)
{
......@@ -961,6 +964,8 @@ public class MeasuredLayers {
if ((layers[num_layer] == null) && null_if_none){
return null;
}
final double [] damping = {damp_tilt, damp_tilt, 0.0}; // 0.0 will be applied to average value, tilt_cost - to both tilts
int st2 = 2 * superTileSize;
int st_half = superTileSize/2;
double [][] ds = new double [2][st2*st2];
......@@ -1015,7 +1020,7 @@ public class MeasuredLayers {
for (int dx = 0; dx < st2; dx ++){
int indx = dy * st2 + dx;
if (indx == dbg_tile){
System.out.println("getDisparityStrength(): stX="+stX+" stY="+stY+" dx="+dx+" dy="+dy);
System.out.println("getDisparityStrengthML(): stX="+stX+" stY="+stY+" dx="+dx+" dy="+dy);
}
if (((sel_in == null) || sel_in[indx])){
int num_in_sample = 0;
......@@ -1044,7 +1049,7 @@ public class MeasuredLayers {
{
boolean en_tilt = (atiltXY == null);
if (en_tilt) { // make sure there are enough samples and not all of them are on the same line
if (!notColinear(smpl_sel,smplSide)){
if ((damp_tilt == 0.0) && !notColinear(smpl_sel,smplSide)){
en_tilt = false;
}
}
......@@ -1077,12 +1082,13 @@ public class MeasuredLayers {
double[][] approx2d = pa.quadraticApproximation(
mdata,
true, // boolean forceLinear, // use linear approximation
damping, // double [] damping,
thresholdLin, // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
thresholdQuad, // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
debugLevel);
if (approx2d == null){
if (debugLevel > -1){
System.out.println("getDisparityStrength(): can not find linear approximation");
System.out.println("getDisparityStrengthML(): can not find linear approximation");
}
break sample_loop;
}
......@@ -1142,7 +1148,7 @@ public class MeasuredLayers {
double d2 = smpl_d[indxs] - smpl_p[indxs];
d2 *=d2;
if (d2 > dworst2) {
if (notColinearWithout (
if ((damp_tilt !=0.0) || notColinearWithout (
indxs, // int indx,
smpl_sel, // boolean [] sel,
smplSide)) { // int side))
......@@ -1153,7 +1159,7 @@ public class MeasuredLayers {
}
if (iworst < 0){
if (debugLevel > 0) {
System.out.println("**** this may be BUG in getDisparityStrength() can not find the worst sample - all tiles fit perfectly ****");
System.out.println("**** this may be BUG in getDisparityStrengthML() can not find the worst sample - all tiles fit perfectly ****");
}
// this can happen if some samples are the same and all the pixels fit exactly - use all of them
break;
......@@ -1228,7 +1234,7 @@ public class MeasuredLayers {
}
}
if (iworst < 0){
System.out.println("**** this is a BUG in getDisparityStrength() ****");
System.out.println("**** this is a BUG in getDisparityStrengthML() ****");
break;
}
// remove worst sample
......@@ -1252,7 +1258,7 @@ public class MeasuredLayers {
}
} else {
num_in_sample = 0;
System.out.println("**** this is a BUG in getDisparityStrength(), shoud not happen ? ****");
System.out.println("**** this is a BUG in getDisparityStrengthML(), shoud not happen ? ****");
}
}
}
......
......@@ -2850,6 +2850,14 @@ public class QuadCLT {
final boolean updateStatus,
final int debugLevel)
{
if (infinity_corr && (clt_parameters.z_correction != 0.0)){
System.out.println(
"****************************************\n"+
"* Resetting manual infinity correction *\n"+
"****************************************\n");
clt_parameters.z_correction = 0.0;
}
this.startTime=System.nanoTime();
String [] sourceFiles=correctionsParameters.getSourcePaths();
boolean [] enabledFiles=new boolean[sourceFiles.length];
......@@ -3246,6 +3254,7 @@ public class QuadCLT {
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}};
final double disparity_corr = (clt_parameters.z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/clt_parameters.z_correction);
double [][][][][][] clt_data = image_dtt.clt_aberrations_quad_corr(
tile_op, // per-tile operation bit codes
disparity_array, // final double disparity,
......@@ -3286,6 +3295,8 @@ public class QuadCLT {
clt_parameters.transform_size,
clt_parameters.clt_window,
shiftXY, //
disparity_corr, // final double disparity_corr, // disparity at infinity
(clt_parameters.fcorr_ignore? null: this.fine_corr),
clt_parameters.corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
......@@ -4545,6 +4556,8 @@ public class QuadCLT {
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}};
final double disparity_corr = (clt_parameters.z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/clt_parameters.z_correction);
image_dtt.clt_aberrations_quad_corr(
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
......@@ -4586,6 +4599,7 @@ public class QuadCLT {
clt_parameters.transform_size,
clt_parameters.clt_window,
shiftXY, //
disparity_corr, // final double disparity_corr, // disparity at infinity
(clt_parameters.fcorr_ignore? null: this.fine_corr),
clt_parameters.corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing
......@@ -5702,36 +5716,38 @@ public class QuadCLT {
final boolean updateStatus,
final int debugLevel)
{
final boolean new_expand = clt_parameters.gr_new_expand;
final int max_expand = 500; // 150; // 30;
// Temporary assign here
final int disp_index = ImageDtt.DISPARITY_INDEX_CM;
final int str_index = ImageDtt.DISPARITY_STRENGTH_INDEX;
final double strength_floor = 0.8* clt_parameters.combine_min_strength;
final double strength_floor = clt_parameters.gr_strength_floor; // 0.6* clt_parameters.combine_min_strength;
// final double strength_floor = 0.8* clt_parameters.combine_min_strength;
// TODO: define, make parameters
final double comboMinStrength = 0.3; // 0.3;
final double comboMinStrengthHor = 0.3; // 0.3;
final double comboMinStrengthVert = 0.3; // 0.3;
final double filterMinStrength = 0.3; // 0.3;
final double comboMinStrength = clt_parameters.gr_comboMinStrength; // 0.3; // 0.3;
final double comboMinStrengthHor = clt_parameters.gr_comboMinStrengthHor ; // 0.3; // 0.3;
final double comboMinStrengthVert =clt_parameters.gr_comboMinStrengthVert ; // 0.3; // 0.3;
final double filterMinStrength = clt_parameters.gr_filterMinStrength ; // 0.3; // 0.3;
// TODO: make parameters
final double strength_pow = 1.0;
final int smplSide = 5; // 3; // Sample size (side of a square)
final int smplNum = 13; // 5; // Number after removing worst (should be >1)
final double smplRms = 0.15; // 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd = true; //
final double max_abs_tilt = 2.0; // pix per tile
final double max_rel_tilt = 0.2; // (pix / disparity) per tile
final double strength_pow = clt_parameters.gr_strength_pow ; // 1.0;
final int smplSide = clt_parameters.gr_smplSide ; // 5; // 3; // Sample size (side of a square)
final int smplNum = clt_parameters.gr_smplNum ; // 10; // 13; // 5; // Number after removing worst (should be >1)
final double smplRms = clt_parameters.gr_smplRms ; // 0.15; // Maximal RMS of the remaining tiles in a sample
final double smplRelRms = clt_parameters.gr_smplRelRms ; // 0.01; // 05; // Maximal RMS/disparity in addition to smplRms
final boolean smplWnd = clt_parameters.gr_smplWnd ; // true; //
final double max_abs_tilt = clt_parameters.gr_max_abs_tilt ; // 2.0; // pix per tile
final double max_rel_tilt = clt_parameters.gr_max_rel_tilt ; // 0.2; // (pix / disparity) per tile
final int dbg_x = 0;
final int dbg_y = 0;
// final double scale_filtered_strength = 2.5;
// final double reliable_raw_strength=0.25;
final boolean show_init_refine = clt_parameters.show_init_refine;
boolean show_expand = clt_parameters.show_expand && (max_expand <= 10);
final boolean show_retry_far = clt_parameters.show_retry_far && (max_expand <= 10);
final boolean show_init_refine = clt_parameters.show_init_refine;
final boolean show_retry_far = clt_parameters.show_retry_far && (max_expand <= 10);
boolean show_expand = false; // clt_parameters.show_expand && (max_expand <= 10);
//max_expand
String name = (String) imp_quad[0].getProperty("name");
double [][][] image_data = new double [imp_quad.length][][];
......@@ -5789,6 +5805,8 @@ public class QuadCLT {
smplSide, // final int smplSide, // = 2; // Sample size (side of a square)
smplNum, // final int smplNum, // = 3; // Number after removing worst (should be >1)
smplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplRelRms, // final double smplRelRms, // = 0.005; // Maximal RMS/disparity in addition to smplRms
smplWnd, // final boolean smplWnd, //
max_abs_tilt, // final double max_abs_tilt, // = 2.0; // pix per tile
max_rel_tilt, // final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
......@@ -5901,7 +5919,8 @@ public class QuadCLT {
0, // final int firstPass,
refine_pass, // - 1, // final int lastPassPlus1,
tp.clt_3d_passes.get(refine_pass), // final CLTPass3d new_scan,
clt_parameters.unique_tolerance, // final double unique_tolerance,
clt_parameters.grow_disp_max, // final double grow_disp_max,
clt_parameters.gr_unique_tol, // final double unique_tolerance,
clt_parameters.show_unique); // final boolean show_unique)
if (debugLevel > -1){
System.out.println("cycle makeUnique("+refine_pass+") -> left: "+numLeftRemoved[0]+", removed:" + numLeftRemoved[1]);
......@@ -5963,8 +5982,8 @@ public class QuadCLT {
boolean last_pass = false;
// for (int num_expand = 0; (num_expand < 4) && (num_extended != 0); num_expand++) {
boolean over_infinity = false;
int dbg_start_pass = -20;
int dbg_end_pass = -29;
int dbg_start_pass = 4; // 10; // 20;
int dbg_end_pass = -8; // 12; // -29;
for (int num_expand = 0; num_expand < max_expand; num_expand++) {
boolean dbg_pass = (num_expand >= dbg_start_pass) && (num_expand <= dbg_end_pass);
......@@ -5990,12 +6009,13 @@ public class QuadCLT {
smplSide, // final int smplSide, // = 2; // Sample size (side of a square)
smplNum, // final int smplNum, // = 3; // Number after removing worst (should be >1)
smplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplRelRms, // final double smplRelRms, // = 0.005; // Maximal RMS/disparity in addition to smplRms
smplWnd, // final boolean smplWnd, //
max_abs_tilt, // final double max_abs_tilt, // = 2.0; // pix per tile
max_rel_tilt, // final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel); // final int debugLevel)
295, // 295, // dbg_x, // final int dbg_x,
160, // 161, // 160, // 157, // dbg_y, // final int dbg_y,
debugLevel+1); // final int debugLevel)
if (over_infinity) {
tp.filterOverBackground(
filtered_disp_strength, // final double [][] ds,
......@@ -6075,9 +6095,9 @@ public class QuadCLT {
debugLevel);
if (over_infinity) {
tp.filterOverBackground(
extended_pass, // final CLTPass3d pass,
comboMinStrength, // final double minStrength,
comboMinStrengthHor, // final double minStrengthHor,
extended_pass, // final CLTPass3d pass,
comboMinStrength, // final double minStrength,
comboMinStrengthHor, // final double minStrengthHor,
comboMinStrengthVert, //final double minStrengthVert,
tp.clt_3d_passes.get(bg_pass).getSelected(), // selected , // final boolean [] bg_tiles, // get from selected in clt_3d_passes.get(0);
clt_parameters.ex_min_over,// final double ex_min_over, // when expanding over previously detected (by error) background, disregard far tiles
......@@ -6117,54 +6137,131 @@ public class QuadCLT {
(new showDoubleFloatArrays()).showArrays(dbg_img, tilesX, tilesY, true, title,titles);
}
boolean show_ex_debug = show_retry_far || (clt_parameters.show_retry_far && last_pass) || dbg_pass;
num_extended = tp.setupExtendDisparity(
extended_pass, // final CLTPass3d scan, // combined scan with max_tried_disparity, will be modified to re-scan
tp.clt_3d_passes.get(refine_pass), // final CLTPass3d last_scan, // last prepared tile - can use last_scan.disparity, .border_tiles and .selected
over_infinity? null: tp.clt_3d_passes.get(bg_pass), // final CLTPass3d bg_scan, // background scan data
clt_parameters.grow_sweep, // 8; // Try these number of tiles around known ones
clt_parameters.grow_disp_max, // = 50.0; // Maximal disparity to try
0.5 * clt_parameters.grow_disp_trust, // = 4.0; // Trust measured disparity within +/- this value
clt_parameters.grow_disp_step, // = 6.0; // Increase disparity (from maximal tried) if nothing found in that tile // TODO: handle enclosed dips?
clt_parameters.grow_min_diff, // = 0.5; // Grow more only if at least one channel has higher variance from others for the tile
clt_parameters.grow_retry_far, // final boolean grow_retry_far, // Retry tiles around known foreground that have low max_tried_disparity
clt_parameters.grow_pedantic, // final boolean grow_pedantic, // Scan full range between max_tried_disparity of the background and known foreground
clt_parameters.grow_retry_inf, // final boolean grow_retry_inf, // Retry border tiles that were identified as infinity earlier
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
geometryCorrection, // GeometryCorrection geometryCorrection,
show_ex_debug, // true, // final boolean show_debug,
if (new_expand) { // show_expand){ // use new mode
if (last_pass){
System.out.println("+++++++++++ Last pass ++++++++++++");
}
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
//TODO: break if nothing wanted? - no, there are some left to be refined
if (debugLevel > -1){
System.out.println("=== setupExtendDisparity() pass:"+num_expand+" added "+num_extended+" new tiles to scan");
}
// public boolean []
tp.dbg_filtered_disp_strength = filtered_disp_strength; // to be shown inside
boolean [] variants_flags = {
clt_parameters.gr_var_new_sngl,
clt_parameters.gr_var_new_fg,
clt_parameters.gr_var_all_fg,
clt_parameters.gr_var_new_bg,
clt_parameters.gr_var_all_bg };
numLeftRemoved = tp.prepareExpandVariant(
extended_pass, // final CLTPass3d scan, // combined scan with max_tried_disparity, will be modified to re-scan
tp.clt_3d_passes.get(refine_pass), // final CLTPass3d last_scan, // last prepared tile - can use last_scan.disparity, .border_tiles and .selected
/*null, // */ tp.clt_3d_passes.get(bg_pass), // final CLTPass3d bg_scan, // background scan data
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,// List, first, last - to search for the already tried disparity
0, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
clt_parameters.gr_min_new , // 20, // final int min_new, // discard variant if there are less new tiles
variants_flags, // 0x1e, // 0x1f, // final int variants_mask,
clt_parameters.gr_num_steps , // 8, // final int num_steps, // how far to extend
clt_parameters.gr_steps_over , // 8, // 4, // final int num_steps_disc, // how far to extend
clt_parameters.gr_smpl_size , // 5, // final int smpl_size, // == 5
clt_parameters.gr_min_pnts , // 5, // 4, // 3, // final int min_points, // == 3
clt_parameters.gr_use_wnd , // true, // final boolean use_wnd, // use window function fro the neighbors
clt_parameters.gr_tilt_damp , // 0.001, // final double tilt_cost,
clt_parameters.gr_split_rng , // 5.0, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
clt_parameters.gr_same_rng , // 3.0, // final double same_range, // modify
clt_parameters.gr_diff_cont , // 2.0, // final double diff_continue, // maximal difference from the old value (for previously defined tiles
clt_parameters.gr_abs_tilt , // 2.0, // final double max_abs_tilt, // = 2.0; // pix per tile
clt_parameters.gr_rel_tilt , // 0.2, // final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
clt_parameters.gr_smooth , // 50, // final int max_tries, // maximal number of smoothing steps
clt_parameters.gr_fin_diff , // 0.01, // final double final_diff, // maximal change to finish iterations
clt_parameters.grow_disp_max, // final double grow_disp_max,
clt_parameters.gr_unique_pretol , // 1.0, // final double unique_pre_tolerance, // usually larger than clt_parameters.unique_tolerance
last_pass? clt_parameters.gr_unique_tol : clt_parameters.gr_unique_pretol, // final double unique_tolerance,
clt_parameters. show_expand, // final boolean show_expand,
clt_parameters. show_unique, // final boolean show_unique,
//show_expand
138, // 216, // 214, // 210, // 206, // 204, // 202, // 200, // 198, // final int dbg_x,
149, // 138, // 140, // 142, // 143, // 142, // final int dbg_y,
1); // 2); // 1); // final int debugLevel)
/*
tp.setupExpand(
extended_pass, // final CLTPass3d scan, // combined scan with max_tried_disparity, will be modified to re-scan
tp.clt_3d_passes.get(refine_pass), // final CLTPass3d last_scan, // last prepared tile - can use last_scan.disparity, .border_tiles and .selected
tp.clt_3d_passes.get(bg_pass), // null, // final CLTPass3d bg_scan, // background scan data
true, // false, // final boolean expand_discontinuity, // true - expand discontinuity over known tiles
false, // true, // false, // final boolean smooth_only, // Do not expand ambiguous cells (with discontinuity) (only valid for expand_discontinuity = false)
false, // true, // false, // final boolean extend_far, // extend far (false - extend near)
8, // 3,//8, // final int num_steps, // how far to extend
5, // final int smpl_size, // == 5
true, // final boolean use_wnd, // use window function fro the neighbors
0.001, // final double tilt_cost,
5.0, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
3.0, // final double same_range, // modify
2.0, // final double diff_continue, // maximal difference from the old value (for previously defined tiles
50, // final int max_tries, // maximal number of smoothing steps
0.01, // final double final_diff, // maximal change to finish iterations
216, // 214, // 210, // 206, // 204, // 202, // 200, // 198, // final int dbg_x,
138, // 140, // 142, // 143, // 142, // final int dbg_y,
1); // final int debugLevel)
*/
refine_pass = tp.clt_3d_passes.size(); // now points to the extended_pass !!
tp.clt_3d_passes.add(extended_pass);
// if (show_expand) tp.showScan(
if (clt_parameters. show_expand) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"prepareExpandVariant-"+refine_pass); //String title)
} else { // old way
boolean show_ex_debug = show_retry_far || (clt_parameters.show_retry_far && last_pass) || dbg_pass;
num_extended = tp.setupExtendDisparity(
extended_pass, // final CLTPass3d scan, // combined scan with max_tried_disparity, will be modified to re-scan
tp.clt_3d_passes.get(refine_pass), // final CLTPass3d last_scan, // last prepared tile - can use last_scan.disparity, .border_tiles and .selected
over_infinity? null: tp.clt_3d_passes.get(bg_pass), // final CLTPass3d bg_scan, // background scan data
clt_parameters.grow_sweep, // 8; // Try these number of tiles around known ones
clt_parameters.grow_disp_max, // = 50.0; // Maximal disparity to try
0.5 * clt_parameters.grow_disp_trust, // = 4.0; // Trust measured disparity within +/- this value
clt_parameters.grow_disp_step, // = 6.0; // Increase disparity (from maximal tried) if nothing found in that tile // TODO: handle enclosed dips?
clt_parameters.grow_min_diff, // = 0.5; // Grow more only if at least one channel has higher variance from others for the tile
clt_parameters.grow_retry_far, // final boolean grow_retry_far, // Retry tiles around known foreground that have low max_tried_disparity
clt_parameters.grow_pedantic, // final boolean grow_pedantic, // Scan full range between max_tried_disparity of the background and known foreground
clt_parameters.grow_retry_inf, // final boolean grow_retry_inf, // Retry border tiles that were identified as infinity earlier
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
geometryCorrection, // GeometryCorrection geometryCorrection,
show_ex_debug, // true, // final boolean show_debug,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
//TODO: break if nothing wanted? - no, there are some left to be refined
if (debugLevel > -1){
System.out.println("=== setupExtendDisparity() pass:"+num_expand+" added "+num_extended+" new tiles to scan");
}
refine_pass = tp.clt_3d_passes.size(); // 1
refine_pass = tp.clt_3d_passes.size(); // 1
tp.clt_3d_passes.add(extended_pass);
tp.clt_3d_passes.add(extended_pass);
numLeftRemoved = tp.makeUnique(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
0, // final int firstPass,
refine_pass, // - 1, // final int lastPassPlus1,
tp.clt_3d_passes.get(refine_pass), // final CLTPass3d new_scan,
clt_parameters.unique_tolerance, // final double unique_tolerance,
clt_parameters.show_unique); // final boolean show_unique)
if (show_expand) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"before_measure-"+refine_pass); //String title)
numLeftRemoved = tp.makeUnique(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
0, // final int firstPass,
refine_pass, // - 1, // final int lastPassPlus1,
tp.clt_3d_passes.get(refine_pass), // final CLTPass3d new_scan,
clt_parameters.grow_disp_max, // final double grow_disp_max,
clt_parameters.gr_unique_tol, // final double unique_tolerance,
clt_parameters.show_unique); // final boolean show_unique)
if (show_expand) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"before_measure-"+refine_pass); //String title)
if (debugLevel > -1){
System.out.println("last makeUnique("+refine_pass+") -> left: "+numLeftRemoved[0]+", removed:" + numLeftRemoved[1]);
}
num_extended = numLeftRemoved[0];
//TODO: break if nothing wanted? - here yes, will make sens
if (debugLevel > -1){
System.out.println("last makeUnique("+refine_pass+") -> left: "+numLeftRemoved[0]+", removed:" + numLeftRemoved[1]);
}
// num_extended = numLeftRemoved[0];
//TODO: break if nothing wanted? - here yes, will make sense
}
num_extended = numLeftRemoved[0];
// refine_pass = tp.clt_3d_passes.size(); //
CLTMeasure( // perform single pass according to prepared tiles operations and disparity
......@@ -6230,7 +6327,7 @@ public class QuadCLT {
if (last_pass) {
break;
} else if (numLeftRemoved[0] == 0){
System.out.println("**** processCLTQuad3d(): nothing to sxpand ***");
System.out.println("**** processCLTQuad3d(): nothing to expand ***");
System.out.println("!clt_parameters.ex_over_bgnd="+clt_parameters.ex_over_bgnd+" over_infinity="+over_infinity);
if (!clt_parameters.ex_over_bgnd || over_infinity) last_pass = true;
else {
......@@ -6375,7 +6472,7 @@ public class QuadCLT {
x3dOutput,
texturePath,
"shape_id-"+(scanIndex - next_pass), // id
scan.bounds,
scan.getTextureBounds(),
scan.selected,
scan_disparity, // scan.disparity_map[ImageDtt.DISPARITY_INDEX_CM],
clt_parameters.transform_size,
......@@ -6541,7 +6638,7 @@ public class QuadCLT {
x3dOutput,
texturePath,
"shape_id-"+(scanIndex - next_pass), // id
scan.bounds,
scan.getTextureBounds(),
scan.selected,
scan_disparity, // scan.disparity_map[ImageDtt.DISPARITY_INDEX_CM],
clt_parameters.transform_size,
......@@ -6929,15 +7026,15 @@ public class QuadCLT {
clt_parameters.transform_size,
tilesX,
tilesY,
scan.bounds);
scan.getTextureBounds());
}
// int width = resize ? (clt_parameters.transform_size * scan.bounds.width + 1): (clt_parameters.transform_size * tp.tilesX);
// int height = resize ? (clt_parameters.transform_size * scan.bounds.height + 1): (clt_parameters.transform_size * tp.tilesY);
int width = resize ? (clt_parameters.transform_size * scan.bounds.width): (clt_parameters.transform_size * tilesX);
int height = resize ? (clt_parameters.transform_size * scan.bounds.height): (clt_parameters.transform_size * tilesY);
int width = resize ? (clt_parameters.transform_size * scan.getTextureBounds().width): (clt_parameters.transform_size * tilesX);
int height = resize ? (clt_parameters.transform_size * scan.getTextureBounds().height): (clt_parameters.transform_size * tilesY);
// sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
// sdfa_instance.showArrays(texture_rgbx, width, height, true, "texture_rgbx");
......@@ -7073,6 +7170,7 @@ public class QuadCLT {
double [][][][] texture_tiles = new double [tilesY][tilesX][][]; // ["RGBA".length()][];
ImageDtt image_dtt = new ImageDtt();
final double disparity_corr = (clt_parameters.z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/clt_parameters.z_correction);
image_dtt.clt_aberrations_quad_corr(
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
......@@ -7113,6 +7211,7 @@ public class QuadCLT {
clt_parameters.transform_size,
clt_parameters.clt_window,
shiftXY, //
disparity_corr, // final double disparity_corr, // disparity at infinity
(clt_parameters.fcorr_ignore? null: this.fine_corr),
clt_parameters.corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing
......@@ -7145,6 +7244,8 @@ public class QuadCLT {
final boolean updateStatus,
final int debugLevel)
{
final int dbg_x = 295;
final int dbg_y = 160;
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
CLTPass3d scan = tp.clt_3d_passes.get(scanIndex);
......@@ -7160,6 +7261,9 @@ public class QuadCLT {
if (tile_op[ty][tx] != 0) numTiles ++;
}
System.out.println("CLTMeasure("+scanIndex+"): numTiles = "+numTiles);
if (tile_op[dbg_y][dbg_x] != 0){
System.out.println("CLTMeasure("+scanIndex+"): tile_op["+dbg_y+"]["+dbg_x+"] = "+tile_op[dbg_y][dbg_x]);
}
}
double min_corr_selected = clt_parameters.min_corr;
......@@ -7173,6 +7277,7 @@ public class QuadCLT {
double [][][][] texture_tiles = save_textures ? new double [tilesY][tilesX][][] : null; // ["RGBA".length()][];
ImageDtt image_dtt = new ImageDtt();
final double disparity_corr = (clt_parameters.z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/clt_parameters.z_correction);
image_dtt.clt_aberrations_quad_corr(
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
......@@ -7213,6 +7318,7 @@ public class QuadCLT {
clt_parameters.transform_size,
clt_parameters.clt_window,
shiftXY, //
disparity_corr, // final double disparity_corr, // disparity at infinity
(clt_parameters.fcorr_ignore? null: this.fine_corr),
clt_parameters.corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing
......
......@@ -442,7 +442,7 @@ public class SuperTiles{
double [][] disp_strength;
if (disparity_strength == null) {
if (smplMode) {
disp_strength = measuredLayers.getDisparityStrength(
disp_strength = measuredLayers.getDisparityStrengthMLTilted(
nl, // int num_layer,
stileX, // int stX,
stileY, // int stY,
......@@ -454,10 +454,11 @@ public class SuperTiles{
smplNum, //int smplNum, // = 3; // Number after removing worst (should be >1)
smplRms, //double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd,
0.001, // double damp_tilt, //
true, // boolean null_if_none);
-1); // int debugLevel
} else {
disp_strength = measuredLayers.getDisparityStrength(
disp_strength = measuredLayers.getDisparityStrengthML(
nl, // int num_layer,
stileX, // int stX,
stileY, // int stY,
......@@ -1403,8 +1404,8 @@ public class SuperTiles{
// calculate "tilted" disparity, so planes parallel to the same world plane would have the same disparity
// also produces non-tilted, if world_plane_norm == null
// Protecting from behind the horizon - set strength of all tiles in the negative disparity area to 0
public double [][][][] getPlaneDispStrengths(
final double [] world_plane_norm, // real world normal vector to a suggested plane family (0,1,0) for horizontal planes
public double [][][][] getPlaneDispStrengthsST(
final double [] world_plane_norm, // real world normal vector to a suggested plane family (0,1,0) for horizontal planes, (0,0,1) const disparity, null - floating
final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
final boolean plPreferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
......@@ -1420,6 +1421,8 @@ public class SuperTiles{
final int dbg_X,
final int dbg_Y)
{
final boolean const_disparity = (world_plane_norm != null) && (world_plane_norm[0] == 0.0) && (world_plane_norm[1] == 0.0);
final boolean floating = (world_plane_norm == null);
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
final int superTileSize = tileProcessor.getSuperTileSize();
......@@ -1461,42 +1464,46 @@ public class SuperTiles{
measuredLayers, // MeasuredLayers measuredLayers,
plPreferDisparity); // boolean preferDisparity)
if (smplMode && (world_plane_norm != null)) {
// if (smplMode && (world_plane_norm != null)) {
if (smplMode && !floating) {
plane_tilts = new double [measuredLayers.getNumLayers()][][];
for (int ml = 0; ml < plane_tilts.length; ml++) if ((stMeasSel & ( 1 << ml)) != 0){
double [][] tile_disp_strengths = measuredLayers.getDisparityStrength(
ml, // int num_layer,
stileX, // int stX,
stileY, // int stY,
null, // boolean [] sel_in,
strength_floor, // double strength_floor,
strength_pow, // double strength_pow,
true); // boolean null_if_none);
if (tile_disp_strengths == null){
plane_tilts[ml] = zero_tilts;
} else {
plane_tilts[ml] = pd0.getDisparityTilts(
world_plane_norm, // double [] world_normal_xyz,
tile_disp_strengths, // double [][] tile_disp_strengths,
debugLevel); // int debugLevel);
if(dl > 2){
if (plane_tilts[ml] != null){
for (int k = 0; k < 2; k++) {
System.out.println((k > 0) ? "tilt Y, pix/tile" : "tilt X, pix/tile");
for (int i = 0; i < 2 * superTileSize; i++){
System.out.print(i+",");
for (int j = 0; j < 2 * superTileSize; j++){
int it = j + 2 * superTileSize * i;
if (plane_tilts[ml][it] !=null){
System.out.print(String.format("%f7.4", plane_tilts[ml][it][k]));
}
if (j < (2 * superTileSize - 1)){
System.out.print(", ");
plane_tilts[ml] = zero_tilts;
if (!const_disparity) {
double [][] tile_disp_strengths = measuredLayers.getDisparityStrengthML(
ml, // int num_layer,
stileX, // int stX,
stileY, // int stY,
null, // boolean [] sel_in,
strength_floor, // double strength_floor,
strength_pow, // double strength_pow,
true); // boolean null_if_none);
// if failed - keep constant disparity (plane_tilts[ml] = zero_tilts)
if (tile_disp_strengths != null){
plane_tilts[ml] = pd0.getDisparityTilts(
world_plane_norm, // double [] world_normal_xyz,
tile_disp_strengths, // double [][] tile_disp_strengths,
debugLevel); // int debugLevel);
if(dl > 2){
if (plane_tilts[ml] != null){
for (int k = 0; k < 2; k++) {
System.out.println((k > 0) ? "tilt Y, pix/tile" : "tilt X, pix/tile");
for (int i = 0; i < 2 * superTileSize; i++){
System.out.print(i+",");
for (int j = 0; j < 2 * superTileSize; j++){
int it = j + 2 * superTileSize * i;
if (plane_tilts[ml][it] !=null){
System.out.print(String.format("%f7.4", plane_tilts[ml][it][k]));
}
if (j < (2 * superTileSize - 1)){
System.out.print(", ");
}
}
System.out.println();
}
System.out.println();
}
System.out.println();
}
}
}
......@@ -1509,13 +1516,13 @@ public class SuperTiles{
for (int ml = 0; ml < plane_disp_strength[nsTile].length; ml++) if ((stMeasSel & ( 1 << ml)) != 0){
// TODO": apply tilt before/with getDisparityStrength()
if (smplMode) {
plane_disp_strength[nsTile][ml] = measuredLayers.getDisparityStrength(
plane_disp_strength[nsTile][ml] = measuredLayers.getDisparityStrengthMLTilted(
ml, // int num_layer,
stileX, // int stX,
stileY, // int stY,
null, // boolean [] sel_in,
// ((world_plane_norm == null)? zero_tilts: null), // double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
((world_plane_norm == null)? zero_tilts: plane_tilts[ml]), // double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
// ((world_plane_norm == null)? zero_tilts: plane_tilts[ml]), // double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
(floating? null: plane_tilts[ml]), // double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
strength_floor, // double strength_floor,
strength_pow, // double strength_pow,
smplSide, // int smplSide, // = 2; // Sample size (side of a square)
......@@ -1525,10 +1532,11 @@ public class SuperTiles{
smplWnd, // boolean smplWnd, //
2.0, // double max_abs_tilt, // = 2.0; // pix per tile
0.2, // double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
0.001, // double damp_tilt, //
true, // boolean null_if_none);
dl);
} else {
plane_disp_strength[nsTile][ml] = measuredLayers.getDisparityStrength(
plane_disp_strength[nsTile][ml] = measuredLayers.getDisparityStrengthML(
ml, // int num_layer,
stileX, // int stX,
stileY, // int stY,
......@@ -1687,7 +1695,7 @@ public class SuperTiles{
}
// compare closest to be able to use tilted planes later
for (int ml = 0; ml < num_ml; ml++) if (tile_en[ml] != null) {
if ( dl >1) {
if ( dl >2) {
System.out.println("dispClusterize(), nsTile="+nsTile+", tile_en["+ml+"] + iter = "+iter);
for (int i = 0; i < 2 * superTileSize; i ++){
for (int j = 0; j < 2 * superTileSize; j ++){
......@@ -1721,7 +1729,7 @@ public class SuperTiles{
}
}
}
if ( dl >1) {
if ( dl > 2) {
System.out.println("dispClusterize(), nsTile="+nsTile+", plane_sels[?]["+ml+"] ,iter = "+iter);
for (int i = 0; i < 2 * superTileSize; i ++){
for (int j = 0; j < 2 * superTileSize; j ++){
......@@ -1757,7 +1765,7 @@ public class SuperTiles{
if (sw > 0) {
sd /= sw;
}
if (dl > 0) {
if (dl > 2) {
System.out.println("plane num_sel["+np+"] = "+num_sel[np]+" disp "+max_only[np][0]+"->"+sd+
", weight "+max_only[np][1]+"->"+sw);
}
......@@ -1991,8 +1999,9 @@ public class SuperTiles{
}
// double [] world_hor = {0.0, 1.0, 0.0};
double [] const_disp = {0.0, 0.0, 1.0}; // constant z in world coordinates, same as constant disparity
final double [][][][] hor_disp_strength = getPlaneDispStrengths(
final double [][][][] hor_disp_strength = getPlaneDispStrengthsST(
world_hor, // final double [] world_plane_norm, // real world normal vector to a suggested plane family (0,1,0) for horizontal planes
stMeasSel, //final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plPreferDisparity, // final boolean plPreferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
......@@ -2007,8 +2016,8 @@ public class SuperTiles{
dbg_X,
dbg_Y);
final double [][][][] vert_disp_strength = getPlaneDispStrengths(
null, // final double [] world_plane_norm, // real world normal vector to a suggested plane family (0,1,0) for horizontal planes
final double [][][][] vert_disp_strength = getPlaneDispStrengthsST(
const_disp, // final double [] world_plane_norm, // real world normal vector to a suggested plane family (0,1,0) for horizontal planes
stMeasSel, //final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plPreferDisparity, // final boolean plPreferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
geometryCorrection, // final GeometryCorrection geometryCorrection,
......@@ -2191,7 +2200,7 @@ public class SuperTiles{
}
}
planes_selections[nsTile] = new_planes_selections;
if (dl > 1){
if (dl > 2){
System.out.println("initialDiscriminateTiles() new_planes_selections.length= "+new_planes_selections.length);
}
}
......@@ -2673,14 +2682,15 @@ public class SuperTiles{
highMix, //final double highMix, // stHighMix = 0.4; // Consider merging initial planes if jumps between ratio above
world_hor, // final double [] world_hor, // horizontal plane normal (default [0.0, 1.0, 0.0])
show_histograms, // final boolean show_histograms,
debugLevel+1, // final int debugLevel,
debugLevel+0, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y)
// get per-tile disparity strength again (may consider using non-filtered data here)
double [][][][] disp_strength = getPlaneDispStrengths( // here use actual disparity, not tilted
null, // final double [] world_plane_norm, // real world normal vector to a suggested plane family (0,1,0) for horizontal planes
double [][][][] disp_strength = getPlaneDispStrengthsST( // here use actual disparity, not tilted
null, // final double [] world_plane_norm, // null - floating, (0,0,1) - const disparity, (0,1,0) - horizontal
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plPreferDisparity, // final boolean plPreferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
......@@ -2716,7 +2726,7 @@ public class SuperTiles{
smplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // final boolean smplWnd, // use window functions for the samples
debugLevel + 2, // + 2, // 1, // final int debugLevel,
debugLevel + 1, // + 2, // 1, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y)
this.planes = new_planes; // save as "measured" (as opposed to "smoothed" by neighbors) planes
......@@ -2839,8 +2849,8 @@ public class SuperTiles{
// get per-tile disparity strength again (may consider using non-filtered data here) ?
double [][][][] disp_strength = getPlaneDispStrengths( // here use actual disparity, not tilted
null, // final double [] world_plane_norm, // real world normal vector to a suggested plane family (0,1,0) for horizontal planes
double [][][][] disp_strength = getPlaneDispStrengthsST( // here use actual disparity, not tilted
null, // final double [] world_plane_norm, // null - floating, (0,0,1) - constant disparity, (0,1,0) for horizontal planes
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plPreferDisparity, // final boolean plPreferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
......@@ -5637,7 +5647,11 @@ public class SuperTiles{
}
}
for (int y = 0; y < superTileSize; y++) {
System.arraycopy(plane, superTileSize * y, data[ns], indx + width * y, superTileSize);
if (data.length < (ns+1)){
System.out.println("BUG in getShowPlanes()!, ns = "+ns+", data.length="+data.length);
} else {
System.arraycopy(plane, superTileSize * y, data[ns], indx + width * y, superTileSize); //java.lang.ArrayIndexOutOfBoundsException: 5
}
}
ns ++;
}
......@@ -6435,7 +6449,7 @@ public class SuperTiles{
}
// show disparity (all and masked for this plane) and strength
for (int ml = 0; ml < num_meas_layers; ml++) {
double [][] dbg_disp_str = planes[nsTile][np].getMeasuredLayers().getDisparityStrength(
double [][] dbg_disp_str = planes[nsTile][np].getMeasuredLayers().getDisparityStrengthML(
ml, // int num_layer,
stx, // int stX,
sty, // int stY,
......@@ -7610,7 +7624,7 @@ public class SuperTiles{
int numMeasLayers = measuredLayers.getNumLayers();
double [][][] ds = new double[numMeasLayers][][];
for (int ml = 0; ml < numMeasLayers; ml++) if ((stMeasSel & ( 1 << ml)) != 0) {
ds[ml] = measuredLayers.getDisparityStrength (
ds[ml] = measuredLayers.getDisparityStrengthML (
ml, // int num_layer,
this.strength_floor, // double strength_floor,
this.strength_pow); // double strength_pow)
......
......@@ -780,7 +780,7 @@ public class TilePlanes {
for (int nl = 0; nl < measuredLayers.getNumLayers(); nl ++){
if ((measuredSelection[nl] != null) && ((measSel & (1 << nl)) !=0)) {
if (smplMode) {
disp_strength[nl] = measuredLayers.getDisparityStrength( // expensive to calculate (improve removing outlayers
disp_strength[nl] = measuredLayers.getDisparityStrengthMLTilted( // expensive to calculate (improve removing outlayers
nl, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
......@@ -791,10 +791,11 @@ public class TilePlanes {
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // use window functions for the samples
0.001, // double damp_tilt, //
true, // boolean null_if_none)
debugLevel);
} else {
disp_strength[nl] = measuredLayers.getDisparityStrength(
disp_strength[nl] = measuredLayers.getDisparityStrengthML(
nl, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
......@@ -906,7 +907,7 @@ public class TilePlanes {
if ((measuredSelection[nl] != null) && ((measSel & (1 << nl)) !=0)) {
// recalculate for all measure tiles, not just selected in the original PD
if (smplMode) {
disp_strength[nl] = measuredLayers.getDisparityStrength( // expensive to calculate (improve removing outlayers
disp_strength[nl] = measuredLayers.getDisparityStrengthMLTilted( // expensive to calculate (improve removing outlayers
nl, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
......@@ -917,10 +918,11 @@ public class TilePlanes {
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // use window functions for the samples
0.001, // double damp_tilt, //
true, // boolean null_if_none)
debugLevel);
} else {
disp_strength[nl] = measuredLayers.getDisparityStrength(
disp_strength[nl] = measuredLayers.getDisparityStrengthML(
nl, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
......@@ -929,7 +931,7 @@ public class TilePlanes {
measured_strength_pow, // double strength_pow,
true); // boolean null_if_none);
}
//disp_strength[nl] = measuredLayers.getDisparityStrength(
//disp_strength[nl] = measuredLayers.getDisparityStrengthML(
for (int indx = 0; indx < disp_strength[nl][1].length; indx++){
double w = disp_strength[nl][1][indx];
if (w > 0.0){
......@@ -1157,7 +1159,7 @@ public class TilePlanes {
if (measuredSelection[nl] != null){
if (smplMode) {
if (need_disp_str) {
disp_str[nl] = measuredLayers.getDisparityStrength( // expensive to calculate (improve removing outlayers
disp_str[nl] = measuredLayers.getDisparityStrengthMLTilted( // expensive to calculate (improve removing outlayers
nl, // int num_layer,
sTileXY[0], // int stX,
sTileXY[1], // int stY,
......@@ -1168,11 +1170,12 @@ public class TilePlanes {
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // use window functions for the samples
0.001, // double damp_tilt, //
true, // boolean null_if_none)
debugLevel);
}
} else {
disp_str[nl] = measuredLayers.getDisparityStrength(
disp_str[nl] = measuredLayers.getDisparityStrengthML(
nl, // int num_layer,
sTileXY[0], // int stX,
sTileXY[1], // int stY,
......@@ -1354,7 +1357,7 @@ public class TilePlanes {
if (tile_sel[nl] != null){
if (smplMode) {
if (need_disp_str) {
disp_str[nl] = measuredLayers.getDisparityStrength( // expensive to calculate (improve removing outlayers
disp_str[nl] = measuredLayers.getDisparityStrengthMLTilted( // expensive to calculate (improve removing outlayers
nl, // int num_layer,
sTileXY[0], // int stX,
sTileXY[1], // int stY,
......@@ -1366,6 +1369,7 @@ public class TilePlanes {
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // final boolean smplWnd, // use window functions fro the samples
0.001, // double damp_tilt, //
true, // boolean null_if_none)
debugLevel);
}
......@@ -1409,7 +1413,7 @@ public class TilePlanes {
}
num_tiles += MeasuredLayers.getNumSelected(tile_sel[nl]);
if (tile_sel[nl] != null){
disp_str[nl] = measuredLayers.getDisparityStrength(
disp_str[nl] = measuredLayers.getDisparityStrengthML(
nl, // int num_layer,
sTileXY[0], // int stX,
sTileXY[1], // int stY,
......@@ -1663,7 +1667,7 @@ public class TilePlanes {
if (tile_sel[nl] != null){
if (smplMode) {
if (need_disp_str) {
disp_str[nl] = measuredLayers.getDisparityStrength( // expensive to calculate (improve removing outlayers
disp_str[nl] = measuredLayers.getDisparityStrengthMLTilted( // expensive to calculate (improve removing outlayers
nl, // int num_layer,
sTileXY[0], // int stX,
sTileXY[1], // int stY,
......@@ -1675,6 +1679,7 @@ public class TilePlanes {
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // use window functions for the samples
0.001, // double damp_tilt, //
true, // boolean null_if_none)
debugLevel);
}
......@@ -1718,7 +1723,7 @@ public class TilePlanes {
}
num_tiles += MeasuredLayers.getNumSelected(tile_sel[nl]);
if (tile_sel[nl] != null){
disp_str[nl] = measuredLayers.getDisparityStrength(
disp_str[nl] = measuredLayers.getDisparityStrengthML(
nl, // int num_layer,
sTileXY[0], // int stX,
sTileXY[1], // int stY,
......@@ -4106,7 +4111,7 @@ public class TilePlanes {
double [][][] disp_strength = new double[measuredLayers.getNumLayers()][][];
for (int ml = 0; ml < disp_strength.length; ml++) if ((stMeasSel & ( 1 << ml)) != 0){
if (smplMode) {
disp_strength[ml] = measuredLayers.getDisparityStrength( // expensive to calculate (improve removing outlayers
disp_strength[ml] = measuredLayers.getDisparityStrengthMLTilted( // expensive to calculate (improve removing outlayers
ml, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
......@@ -4117,10 +4122,11 @@ public class TilePlanes {
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // use window functions for the samples
0.001, // double damp_tilt, //
true, // boolean null_if_none)
debugLevel);
} else {
disp_strength[ml] = measuredLayers.getDisparityStrength(
disp_strength[ml] = measuredLayers.getDisparityStrengthML(
ml, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
......@@ -4533,7 +4539,7 @@ public class TilePlanes {
double [][][] disp_strength = new double[measuredLayers.getNumLayers()][][];
for (int ml = 0; ml < disp_strength.length; ml++) if ((stMeasSel & ( 1 << ml)) != 0){
if (smplMode) {
disp_strength[ml] = measuredLayers.getDisparityStrength( // expensive to calculate (improve removing outlayers
disp_strength[ml] = measuredLayers.getDisparityStrengthMLTilted( // expensive to calculate (improve removing outlayers
ml, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
......@@ -4544,10 +4550,11 @@ public class TilePlanes {
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // use window functions for the samples
0.001, // double damp_tilt, //
true, // boolean null_if_none)
debugLevel);
} else {
disp_strength[ml] = measuredLayers.getDisparityStrength(
disp_strength[ml] = measuredLayers.getDisparityStrengthML(
ml, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
......@@ -5321,7 +5328,7 @@ public class TilePlanes {
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
disp_strength[ml] = measuredLayers.getDisparityStrengthMLTilted( // expensive to calculate (improve removing outlayers
ml, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
......@@ -5332,10 +5339,11 @@ public class TilePlanes {
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // use window functions for the samples
0.001, // double damp_tilt, //
true, // boolean null_if_none)
debugLevel);
} else {
disp_strength[ml] = measuredLayers.getDisparityStrength(
disp_strength[ml] = measuredLayers.getDisparityStrengthML(
ml, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
......
......@@ -42,6 +42,8 @@ public class TileProcessor {
public int threadsMax = 100; // maximal number of frames to run
public int globalDebugLevel = 0;
public double [][] dbg_filtered_disp_strength;
// All parameters are set only once, during instantiation
public TileProcessor(
......@@ -687,6 +689,7 @@ public class TileProcessor {
* @param smplSide side of tyhe sample square
* @param smplNum number of the best fit neighbors to keep
* @param smplRms maximal disparity RMS of the best remaining tiles to keep sample
* @param smplRelRms relative RMS to add to smplRms: effective RMS = smplRms + disparity * smplRelRms
* @param smplWnd use sample window function (false - all set to 1.0)
* @param max_abs_tilt maximal disparity tilt in disparity difference (pix) per tile;
* @param max_rel_tilt same as max_abs_tilt, but divided by disparity
......@@ -711,6 +714,7 @@ public class TileProcessor {
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst (should be >1)
final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
final double smplRelRms, // = 0.005; // Maximal RMS/disparity in addition to smplRms
final boolean smplWnd, //
final double max_abs_tilt, // = 2.0; // pix per tile
final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
......@@ -727,7 +731,7 @@ public class TileProcessor {
// final TileNeibs tnSurface = new TileNeibs(tilesX, tilesY);
final int tiles = tilesX * tilesY;
final boolean [] measured = new boolean [tiles];
final double smplVar = smplRms * smplRms; // maximal variance (weighted average of the squared difference from the mean)
// final double smplVar = smplRms * smplRms; // maximal variance (weighted average of the squared difference from the mean)
final double thresholdLin = 1.0E-20; // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
final double thresholdQuad = 1.0E-30; // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
final double [][] disp_strength = new double [2][tiles]; // strength < 0 - not measured!
......@@ -773,6 +777,10 @@ public class TileProcessor {
int tileY = nTile / tilesX;
// check that the tile is strong enough and fractional disparity is in the trusted range
double w = measured_scan.disparity_map[str_index][nTile] - strength_floor;
// if ((dl > 0) && (measured_scan.disparity_map[str_index][nTile] != 0)){
if ((dl > 0) && (measured_scan.tile_op[tileY][tileX] != 0)){
System.out.println("getFilteredDisparityStrength(): tileX="+tileX+", tileY="+tileY+" w="+w);
}
if (w > 0) {
if (strength_pow != 1.0){
if (strength_pow == 0.0) {
......@@ -848,7 +856,9 @@ public class TileProcessor {
// filled all neighbor tiles data. See if sufficient to proceed, then remove extra tiles
// and process the remaining ones
if ((dl > 0) && (measured_scan.tile_op[tileY][tileX] != 0)){
System.out.println("getFilteredDisparityStrength() 1: tileX="+tileX+", tileY="+tileY+" num_in_sample="+num_in_sample);
}
if (num_in_sample >= smplNum){ // try, remove worst
sample_loop:
{
......@@ -930,6 +940,7 @@ public class TileProcessor {
smpl_p[indxs] += sd;
}
approx2d[0][2] += sd;
}
d_center = approx2d[0][2];
sw = 0.0;
......@@ -983,11 +994,16 @@ public class TileProcessor {
// sd /= sw;
// sd2 /= sw;
double var = sd2/sw; // - sd * sd;
double smplVar = smplRms + d_center * smplRelRms;
smplVar *= smplVar;
if (var < smplVar) { // good, save in the result array
disp_strength[0][nTile] = d_center;
// ds[1][indx] = sw * lapWeight[dy][dx] /num_in_sample; // average weights, multiply by window //** TODO: change
disp_strength[1][nTile] = sw /sum_wnd; // average weights, multiply by window //** TODO: change
}
if (dl > 0){
System.out.println("getFilteredDisparityStrength() 2: tileX="+tileX+", tileY="+tileY+" num_in_sample="+num_in_sample+" var="+var);
}
}
} else { // fixed tilt
......@@ -1043,6 +1059,8 @@ public class TileProcessor {
sd /= sw;
sd2 /= sw;
double var = sd2 - sd * sd;
double smplVar = smplRms + sd * smplRelRms;
smplVar *= smplVar;
if (var < smplVar) { // good, save in the result array
disp_strength[0][nTile] = sd;
// ds[1][indx] = sw * lapWeight[dy][dx] /num_in_sample; // average weights, multiply by window //** TODO: change
......@@ -1113,6 +1131,7 @@ public class TileProcessor {
final int firstPass,
final int lastPassPlus1,
final CLTPass3d new_scan,
final double grow_disp_max,
final double unique_tolerance,
final boolean show_unique)
{
......@@ -1124,6 +1143,7 @@ public class TileProcessor {
}
}
int removed = 0, total = 0;
int dbg_remain = 0;
for (int ty = 0; ty < tilesY; ty ++) {
for (int tx = 0; tx < tilesX; tx ++){
if (new_scan.tile_op[ty][tx] != 0){
......@@ -1131,13 +1151,20 @@ public class TileProcessor {
for (int ipass = firstPass; ipass <lastPassPlus1; ipass++ ){
CLTPass3d pass = passes.get(ipass);
if ((pass.tile_op[ty][tx] != 0) && pass.isMeasured()){
if (Math.abs(new_scan.disparity[ty][tx] - pass.disparity[ty][tx]) < unique_tolerance){
// Double.isNaN should not happen
if ( Double.isNaN(pass.disparity[ty][tx]) ||
(Math.abs(new_scan.disparity[ty][tx] - pass.disparity[ty][tx]) < unique_tolerance) ||
(new_scan.disparity[ty][tx] > grow_disp_max) ||
(new_scan.disparity[ty][tx] <= 0.0)){
new_scan.tile_op[ty][tx] = 0;
removed++;
break;
}
}
}
if (new_scan.tile_op[ty][tx] != 0){
dbg_remain++;
}
}
}
}
......@@ -1152,6 +1179,406 @@ public class TileProcessor {
int [] rslt = {total-removed, removed};
return rslt;
}
/**
* Get selection of the tiles that were tried before among selected
* @param passes ArrayList of scan passes
* @param firstPass index of the first pass to compare against
* @param lastPassPlus1 index of the last pass + 1to compare against
* @param selected tiles to process
* @param prohibited tiles already marked as "bad" (already tried or out of range), may be null. If not null - will be modified
* @param disparity array of disparity values to compare with already tried. Double.NaN values will be skipped (not marked)
* @param mod_selected if true, selected array will be modified to exclude tried before cells
* @param mod_disparity if true, disparity array will be modified to have Double.NaN for the tried before cells
* @param grow_disp_max maximal valid disparity (all above or <= 0 will be marked as "bad" (as if they were already tried)
* @param unique_pre_tolerance mark tiles that have disparity within +/- this values from already tried
* @return array of the tiles that should not be used
*/
public boolean [] getTriedBefore(
final ArrayList <CLTPass3d> scan_list,
final int start_scan_index, // firstPass,
final int finish_scan_index, // lastPassPlus1,
final boolean [] selected,
final boolean [] prohibited,
final double [] disparity,
final boolean mod_selected,
final boolean mod_disparity,
final double grow_disp_max,
final double unique_pre_tolerance)
{
final int tilesX = getTilesX();
final int tilesY = getTilesY();
final int tlen = tilesX * tilesY;
final boolean [] tried_before = (prohibited != null)? prohibited : (new boolean [tlen]);
final ArrayList<CLTPass3d> measured_list = new ArrayList<CLTPass3d> ();
for (int ipass = start_scan_index; ipass < finish_scan_index; ipass++){
CLTPass3d pass = clt_3d_passes.get(ipass);
if ((pass != null) && pass.isMeasured()){
measured_list.add(pass);
}
}
final int firstPass = 0;
final int lastPassPlus1 = measured_list.size();
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < tlen; nTile = ai.getAndIncrement()) if (selected[nTile]){
if (!Double.isNaN(disparity[nTile])) {
if ((disparity[nTile] <= 0.0) || (disparity[nTile] > grow_disp_max)){
tried_before[nTile] = true;
if (mod_selected) selected[nTile] = false;
if (mod_disparity) disparity[nTile] = Double.NaN;
} else {
int ty = nTile / tilesX;
int tx = nTile % tilesX;
for (int i = firstPass; i < lastPassPlus1; i++) {
if (Math.abs(disparity[nTile] - measured_list.get(i).disparity[ty][tx]) < unique_pre_tolerance){
tried_before[nTile] = true;
if (mod_selected) selected[nTile] = false;
if (mod_disparity) disparity[nTile] = Double.NaN;
break;
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return tried_before;
}
public int [] prepareExpandVariant(
final CLTPass3d scan, // combined scan with max_tried_disparity, will be modified to re-scan
final CLTPass3d last_scan, // last prepared tile - can use last_scan.disparity, .border_tiles and .selected
final CLTPass3d bg_scan, // background scan data, null - ignore background
final ArrayList <CLTPass3d> passes,// List, first, last - to search for the already tried disparity
final int firstPass,
final int lastPassPlus1,
final int min_new, // discard variant if there are less new tiles
final boolean [] variants_flags,
final int num_steps, // how far to extend
final int num_steps_disc, // how far to extend
final int smpl_size, // == 5
final int min_points, // == 3
final boolean use_wnd, // use window function fro the neighbors
final double tilt_cost,
final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
final double same_range, // modify
final double diff_continue, // maximal difference from the old value (for previously defined tiles
final double max_abs_tilt, // = 2.0; // pix per tile
final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
final int max_tries, // maximal number of smoothing steps
final double final_diff, // maximal change to finish iterations
final double grow_disp_max, // = 50.0; // Maximal disparity to try
final double unique_pre_tolerance, // usually larger than clt_parameters.unique_tolerance
final double unique_tolerance,
final boolean show_expand,
final boolean show_unique,
final int dbg_x,
final int dbg_y,
final int debugLevel)
{
class Variant{
boolean expand_discontinuity; // true - expand discontinuity over known tiles
boolean smooth_only; // Do not expand ambiguous cells (with discontinuity) (only valid for expand_discontinuity = false)
boolean extend_far; // extend far (false - extend near)
int num_steps; // how far to extend
double split_threshold; // if full range of the values around the cell higher, need separate fg, bg
double same_range; // modify
double diff_continue; // maximal difference from the old value (for previously defined tiles
Variant (
boolean expand_discontinuity, // true - expand discontinuity over known tiles
boolean smooth_only, // Do not expand ambiguous cells (with discontinuity) (only valid for expand_discontinuity = false)
boolean extend_far, // extend far (false - extend near)
int num_steps, // how far to extend
double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
double same_range, // modify
double diff_continue)
{
this.expand_discontinuity = expand_discontinuity; // true - expand discontinuity over known tiles
this.smooth_only = smooth_only; // Do not expand ambiguous cells (with discontinuity) (only valid for expand_discontinuity = false)
this.extend_far = extend_far; // extend far (false - extend near)
this.num_steps = num_steps; // how far to extend
this.split_threshold = split_threshold; // if full range of the values around the cell higher, need separate fg, bg
this.same_range = same_range;
this.diff_continue = diff_continue;
}
}
Variant [] variants = {
// disc smooth far
new Variant(false, true, false, num_steps, split_threshold, same_range, diff_continue), // +1
new Variant(false, false, false, num_steps, split_threshold, same_range, diff_continue), // +2
new Variant(true, false, false, num_steps_disc, split_threshold, same_range, diff_continue), // +4
new Variant(false, false, true, num_steps, split_threshold, same_range, diff_continue), // +8
new Variant(true, false, true, num_steps_disc, split_threshold, same_range, diff_continue) // +16
};
for (int num_var = 0; num_var < variants.length; num_var++){
if (variants_flags[num_var]) { // (variants_mask & (1 << num_var)) != 0) {
// scan.saveTileOpDisparity(); // it is not used from this scan, but from last_scan
int num_op = setupExpand(
scan, // final CLTPass3d scan, // combined scan with max_tried_disparity, will be modified to re-scan
last_scan, // final CLTPass3d last_scan, // last prepared tile - can use last_scan.disparity, .border_tiles and .selected
bg_scan, // final CLTPass3d bg_scan, // background scan data, null - ignore background
passes, // final ArrayList <CLTPass3d> passes,// List, first, last - to search for the already tried disparity
firstPass, // final int firstPass,
lastPassPlus1, // final int lastPassPlus1,
variants[num_var].expand_discontinuity, // final boolean expand_discontinuity, // true - expand discontinuity over known tiles
variants[num_var].smooth_only, // final boolean smooth_only, // Do not expand ambiguous cells (with discontinuity) (only valid for expand_discontinuity = false)
variants[num_var].extend_far, // final boolean extend_far, // extend far (false - extend near)
variants[num_var].num_steps, // final int num_steps, // how far to extend
smpl_size, // final int smpl_size, // == 5
min_points, // final int min_points, // == 3
use_wnd, // final boolean use_wnd, // use window function fro the neighbors
tilt_cost, // final double tilt_cost,
variants[num_var].split_threshold, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
variants[num_var].same_range, // final double same_range, // modify
variants[num_var].diff_continue, // final double diff_continue, // maximal difference from the old value (for previously defined tiles
max_abs_tilt, // final double max_abs_tilt, // = 2.0; // pix per tile
max_rel_tilt, // final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
max_tries, // final int max_tries, // maximal number of smoothing steps
final_diff, // final double final_diff, // maximal change to finish iterations
grow_disp_max, // final double grow_disp_max,
unique_pre_tolerance, // final double unique_pre_tolerance, // usually larger than clt_parameters.unique_tolerance
show_expand, // final boolean show_expand,
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel); // final int debugLevel)
if (num_op < min_new) {
// scan.restoreKeepTileOpDisparity(); // it is not used from this scan, but from last_scan
continue;
}
// Remove tiles that were already tried, see if anything is left
int [] unique_stats = makeUnique(
passes, // clt_3d_passes, // final ArrayList <CLTPass3d> passes,
firstPass, // final int firstPass,
lastPassPlus1, // clt_3d_passes.size(),// last_scan, // - 1, // final int lastPassPlus1,
scan, //clt_3d_passes.get(refine_pass), // final CLTPass3d new_scan,
grow_disp_max, // final double grow_disp_max,
unique_tolerance, // final double unique_tolerance,
show_unique); // final boolean show_unique)
int num_left = unique_stats[0];
if (num_left < min_new) {
if (debugLevel > 0){
System.out.println("prepareExpandVariants(): discarding variant "+num_var+ " as remaining "+num_left+" < "+min_new);
}
// scan.restoreKeepTileOpDisparity();// it is not used from this scan, but from last_scan
continue;
}
if (debugLevel > 0){
System.out.println("prepareExpandVariants(): remaining "+num_left+" tiles to be processed, used variant "+num_var);
}
int [] rslt = {num_left, num_var};
return rslt;
}
}
return new int [2]; // nothing found
}
public int setupExpand(
final CLTPass3d scan, // combined scan with max_tried_disparity, will be modified to re-scan
final CLTPass3d last_scan, // last prepared tile - can use last_scan.disparity, .border_tiles and .selected
final CLTPass3d bg_scan, // background scan data, null - ignore background
final ArrayList <CLTPass3d> passes,// List, first, last - to search for the already tried disparity
final int firstPass,
final int lastPassPlus1,
final boolean expand_discontinuity, // true - expand discontinuity over known tiles
final boolean smooth_only, // Do not expand ambiguous cells (with discontinuity) (only valid for expand_discontinuity = false)
final boolean extend_far, // extend far (false - extend near)
final int num_steps, // how far to extend
final int smpl_size, // == 5
final int min_points, // == 3
final boolean use_wnd, // use window function fro the neighbors
final double tilt_cost,
final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
final double same_range, // modify
final double diff_continue, // maximal difference from the old value (for previously defined tiles
final double max_abs_tilt, // = 2.0; // pix per tile
final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
final int max_tries, // maximal number of smoothing steps
final double final_diff, // maximal change to finish iterations
final double grow_disp_max,
final double unique_pre_tolerance, // usually larger than clt_parameters.unique_tolerance
final boolean show_expand,
final int dbg_x,
final int dbg_y,
final int debugLevel)
{
final int tlen = tilesY * tilesX;
double [] disparity = scan.getDisparity().clone(); // to modify in-place **** remove clone after debugged ****
// double [] dbg_disparity = scan.getDisparity().clone(); // to modify in-place **** remove clone after debugged ****
boolean [] these_no_border = new boolean [tlen];
for (int i = 0; i < these_no_border.length; i++) {
these_no_border[i] = last_scan.selected[i] && !last_scan.border_tiles[i];
}
boolean [] dbg_last_selected = last_scan.selected.clone();
boolean [] dbg_last_border = last_scan.border_tiles.clone();
boolean [] dbg_no_border = these_no_border.clone();
boolean [] known_tiles = these_no_border.clone();
// known are background or these tiles
if (bg_scan != null) {
for (int i = 0; i < known_tiles.length; i++) {
known_tiles[i] |= bg_scan.selected[i];
}
}
// set combo disparity from last prepared
for (int nt = 0; nt < known_tiles.length; nt++){
int ty = nt / tilesX;
int tx = nt % tilesX;
disparity[nt] = 0.0;
if (these_no_border[nt]) disparity[nt] = last_scan.disparity[ty][tx];
}
double [] dbg_disparity = disparity.clone();
boolean [] expanded;
ExtendSurfaces es = new ExtendSurfaces(this);
if (expand_discontinuity) {
expanded = es.expandDiscontinuity( // return maximal correction value
passes, // final ArrayList <CLTPass3d> passes,
firstPass, // final int firstPass,
lastPassPlus1, // final int lastPassPlus1,
disparity, // final double [] values, // will be modified, Double.NaN is not yet assigned
known_tiles, // final boolean [] known, // cells with known values (will not be modified)
num_steps, // final int num_steps, // how far to extend
smpl_size, // final int smpl_size, // == 5
min_points, // final int min_points, // == 3
use_wnd, // final boolean use_wnd, // use window function fro the neighbors
tilt_cost, // final double tilt_cost,
split_threshold, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
same_range, // final double same_range, // modify
diff_continue, // final double diff_continue, // maximal difference from the old value (for previously defined tiles
max_abs_tilt, // final double max_abs_tilt, // = 2.0; // pix per tile
max_rel_tilt, // final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
extend_far, // final boolean extend_far, // extend far (false - extend near)
max_tries, // final int max_tries, // maximal number of smoothing steps
final_diff, // final double final_diff, // maximal change to finish iterations
grow_disp_max, // final double grow_disp_max,
unique_pre_tolerance, // final double unique_pre_tolerance, // usually larger than clt_parameters.unique_tolerance
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel); // final int debugLevel)
} else {
expanded = es.expandKnown( // return maximal correction value
passes, // final ArrayList <CLTPass3d> passes,
firstPass, // final int firstPass,
lastPassPlus1, // final int lastPassPlus1,
disparity, // final double [] values, // will be modified, Double.NaN is not yet assigned
known_tiles, // final boolean [] known, // cells with known values (will not be modified)
num_steps, // final int num_steps, // how far to extend
smpl_size, // final int smpl_size, // == 5
min_points, // final int min_points, // == 3
use_wnd, // final boolean use_wnd, // use window function fro the neighbors
tilt_cost, // final double tilt_cost,
split_threshold, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg
same_range, // final double same_range, // modify
diff_continue, // final double diff_continue, // maximal difference from the old value (for previously defined tiles
max_abs_tilt, // final double max_abs_tilt, // = 2.0; // pix per tile
max_rel_tilt, // final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
smooth_only, // final boolean smooth_only, // Do not expand ambiguous cells (with discontinuity)
extend_far, // final boolean extend_far, // extend far (false - extend near)
max_tries, // final int max_tries, // maximal number of smoothing steps
final_diff, // final double final_diff, // maximal change to finish iterations
grow_disp_max, // final double grow_disp_max,
unique_pre_tolerance, // final double unique_pre_tolerance, // usually larger than clt_parameters.unique_tolerance
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel); // final int debugLevel)
}
// combine what was prepared by refine and here
if (expanded == null) return 0;
boolean [] selected = new boolean[tlen];
boolean [] border = new boolean[tlen];
for (int nTile = 0; nTile < tlen; nTile++){
// selected[nTile] = known_tiles[nTile] || last_scan.selected[nTile] || expanded[nTile];
// if ((last_scan.selected == null) || (expanded == null) || (disparity == null)) {
// System.out.println( " BUG in setupExpand()");
// } else {
selected[nTile] = (last_scan.selected[nTile] || expanded[nTile]) && !Double.isNaN(disparity[nTile]); // selected by refine and new java.lang.NullPointerException
border[nTile] = selected[nTile] && !known_tiles[nTile];
// }
}
scan.setSelected(selected);
scan.setBorderTiles(border);
int num_op = scan.setTileOpDisparity(
selected, // boolean [] selection,
disparity); // double [] disparity)
if (debugLevel > 0){
System.out.println("setupExpand(): set "+num_op+" tiles to be processed (some will be removed)");
}
// show debug images
if (show_expand){
String [] titles = {"disp_prev", "disparity", "masked", "sel_border","expanded","tile_op","pre-disparity", "this_tile_op", "this_pre-disparity","filt_disp","filt_str"};
double [][] dbg_img = new double [titles.length][];
dbg_img[0] = dbg_disparity;
dbg_img[1] = disparity;
dbg_img[2] = disparity.clone();
dbg_img[3] = new double[tlen];
dbg_img[4] = new double[tlen];
dbg_img[5] = new double[tlen];
dbg_img[6] = new double[tlen];
dbg_img[7] = new double[tlen];
dbg_img[8] = new double[tlen];
if (this.dbg_filtered_disp_strength != null) {
dbg_img[ 9] = this.dbg_filtered_disp_strength[0];
dbg_img[10] = this.dbg_filtered_disp_strength[1];
}
for (int i = 0; i < tlen; i++) {
dbg_img[3][i] = (dbg_last_selected[i]? 1.0:0.0)+ (dbg_last_border[i]? 2.0:0.0);
if (expanded != null) {
dbg_img[4][i] = (expanded[i]? 1.0:0.0);
if (!expanded[i]) dbg_img[2][i] = Double.NaN;
}
}
if (last_scan.tile_op!= null){
for (int ty = 0; ty < tilesY; ty++){
for (int tx = 0; tx < tilesX; tx++){
if (last_scan.tile_op[ty] != null) dbg_img[5][ty*tilesX + tx] = last_scan.tile_op[ty][tx];
}
}
}
if (last_scan.disparity!= null){
for (int ty = 0; ty < tilesY; ty++){
for (int tx = 0; tx < tilesX; tx++){
if (last_scan.disparity[ty] != null) dbg_img[6][ty*tilesX + tx] = last_scan.disparity[ty][tx];
}
}
}
if (scan.tile_op!= null){
for (int ty = 0; ty < tilesY; ty++){
for (int tx = 0; tx < tilesX; tx++){
if (scan.tile_op[ty] != null) dbg_img[7][ty*tilesX + tx] = scan.tile_op[ty][tx];
}
}
}
if (scan.disparity!= null){
for (int ty = 0; ty < tilesY; ty++){
for (int tx = 0; tx < tilesX; tx++){
if (scan.disparity[ty] != null) dbg_img[8][ty*tilesX + tx] = scan.disparity[ty][tx];
}
}
}
(new showDoubleFloatArrays()).showArrays(dbg_img, tilesX, tilesY, true, "setupExpand",titles);
}
return num_op;
}
public int setupExtendDisparity( // returns number of new tiles to try
final CLTPass3d scan, // combined scan with max_tried_disparity, will be modified to re-scan
......@@ -4601,7 +5028,7 @@ public class TileProcessor {
clt_parameters.stHighMix, // stHighMix = 0.4; // Consider merging initial planes if jumps between ratio above
world_hor, // final double [] world_hor, // horizontal plane normal (default [0.0, 1.0, 0.0])
clt_parameters.show_histograms, // final boolean show_histograms,
0, // -1, // debugLevel, // final int debugLevel)
1, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// showDoubleFloatArrays sdfa_instance = null;
......
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