Commit 4ea50500 authored by Andrey Filippov's avatar Andrey Filippov

filtering foreground selection for the rig

parent 857dfbb8
......@@ -35,6 +35,483 @@ public class BiCamDSI {
tnImage = new TileNeibs(tilesX, tilesY);
}
private double [][] get9weightMasks(
int neib_dist, // >=1
double rsigma) {
int sample_size = 2*neib_dist + 1;
int center = neib_dist; //+1;
int last = 2*neib_dist;
double [][] weight_mask = new double [9][sample_size * sample_size];
for (int row = 0; row <= neib_dist; row++) {
int row1 = (last - row);
for (int col = 0; col < sample_size; col++) {
weight_mask[0][row *sample_size + col ] = 1.0;
weight_mask[2][col *sample_size + row1] = 1.0;
weight_mask[4][row1*sample_size + col ] = 1.0;
weight_mask[6][col *sample_size + row ] = 1.0;
}
}
for (int i = 0; i < sample_size; i++) {
for (int j = 0; j <= i; j++) {
int row0 = j;
int col0 = last - i + j;
int row1 = (last - row0);
int col1 = (last - col0);
weight_mask[1][row0*sample_size + col0 ] = 1.0;
weight_mask[3][col0*sample_size + row1 ] = 1.0;
weight_mask[5][row1*sample_size + col1 ] = 1.0;
weight_mask[7][col1*sample_size + row0 ] = 1.0;
}
}
// Fill the center-symmetrical weights
int k =0;
double w4 = 0.0;
double w8 = 0.0;
int n8 = 0;
int left_cells = sample_size * (neib_dist + 1); //number of cells in "halves"
for (; ((2*k + 1)*(2*k + 1)) <= left_cells; k++); // seems that it never equals
k--; // k is the largest square with odd side and area less than for 8 halves above
left_cells -= (2*k + 1)*(2*k + 1);
if (left_cells < 4) {
w4 = left_cells/4.0;
} else {
w4 = 1.0;
left_cells -=4;
n8 = left_cells/8;
left_cells -= 8*n8;
if (n8 == k) {
w8 = left_cells/4.0; // using very corners, so there are only 4, not 8 different cells for w8
} else {
w8 = left_cells/8.0;
}
}
// Fill center square
for (int row = neib_dist-k; row <= (neib_dist+k); row++) {
for (int col = neib_dist-k; col <= (neib_dist+k); col++) {
weight_mask[8][row*sample_size + col ] = 1.0;
}
}
int low = center - k - 1;
int high = center + k + 1;
weight_mask[8][center*sample_size + low ] = w4;
weight_mask[8][low *sample_size + center] = w4;
weight_mask[8][center*sample_size + high ] = w4;
weight_mask[8][high *sample_size + center] = w4;
if (w8 > 0.0) {
n8++;
} else {
w8 = 1.0;
}
if (n8 > 0){
for (int in8 = 1; in8 <= n8; in8++) {
double w = (in8 == n8)? w8: 1.0;
weight_mask[8][(center - in8)*sample_size + low ] = w;
weight_mask[8][(center + in8)*sample_size + low ] = w;
weight_mask[8][low *sample_size + (center - in8)] = w;
weight_mask[8][low *sample_size + (center + in8)] = w;
weight_mask[8][(center - in8)*sample_size + high] = w;
weight_mask[8][(center + in8)*sample_size + high] = w;
weight_mask[8][high *sample_size + (center - in8)] = w;
weight_mask[8][high *sample_size + (center + in8)] = w;
}
}
if (rsigma > 0) {
double sigma = rsigma * center;
double [] w1d = new double [center+1];
for (int i = 0; i < w1d.length; i++) w1d[i] = Math.exp(-i*i/(2*sigma*sigma));
for (int row = 0; row < sample_size; row++) {
int ady = (row > center)? (row - center) : (center - row);
for (int col = 0; col < sample_size; col++) {
int adx = (col > center)? (col - center) : (center - col);
for (int n = 0; n < weight_mask.length; n++) {
weight_mask[n][row*sample_size + col] *= w1d[ady]*w1d[adx];
}
}
}
}
return weight_mask;
}
/**
* Select near tiles (those that are not infinity)
* @param min_strength minimal tile strength (may be 0 as the tiles are already filtered)
* @param infinity_select tile, previously assigned to infinity (or null)
* @param selection existing selection (to add to) or null
* @param disparity array of tile disparity values (may have NaN-s)
* @param strength array of tile strength values
* @return new selection (new or added to existing)
*/
public boolean [] selectNearObjects(
double min_strength,
boolean [] infinity_select,
boolean [] selection,
double [] disparity,
double [] strength) {
int num_tiles = disparity.length;
if (infinity_select == null) {
infinity_select = new boolean [num_tiles];
for (int nTile = 0; nTile < num_tiles; nTile++) infinity_select[nTile] = true;
}
if (selection == null) selection = new boolean [num_tiles];
for (int nTile =0; nTile <num_tiles; nTile++) {
if (!infinity_select[nTile] && (strength[nTile] > 0.0) && (strength[nTile] >= min_strength)) {
selection[nTile] = true;
}
}
return selection;
}
/**
* Select far tiles (even lone) over infinity areas that have sufficient disparity and strength
* @param min_far_strength minimal tile strength (may be 0 as the tiles are already filtered)
* @param min_far_disparity minimal tile disparity to accept lone strong tiles for far objects
* @param infinity_select tile, previously assigned to infinity (or null)
* @param selection existing selection (to add to) or null
* @param disparity array of tile disparity values (may have NaN-s)
* @param strength array of tile strength values
* @return new selection (new or added to existing)
*/
public boolean [] selectLoneFar(
double min_far_strength,
double min_far_disparity,
boolean [] infinity_select,
boolean [] selection,
double [] disparity,
double [] strength) {
int num_tiles = disparity.length;
if (infinity_select == null) {
infinity_select = new boolean [num_tiles];
for (int nTile = 0; nTile < num_tiles; nTile++) infinity_select[nTile] = true;
}
if (selection == null) selection = new boolean [num_tiles];
for (int nTile =0; nTile <num_tiles; nTile++) {
if (infinity_select[nTile] && (strength[nTile] > 0.0) && (strength[nTile] >= min_far_strength) && (disparity[nTile] >= min_far_disparity)) {
selection[nTile] = true;
}
}
return selection;
}
/**
* Filter selection by expending, then shrinking (fills small gaps) shrinking (combined with
* previous step) and expanding again (removes small clusters)
* @param pre_expand number of steps for initial expand (odd last is - only hor/vert, even - last step includes diagonals)
* @param shrink number of shrink steps normally equals to pre_expand+post_expand
* @param post_expand numaber of final expansion steps
* @param selection selection to be modified
* @param prohibit tiles to keep from expansion/shrinking (such as infinity selection to modify only near regions (may be null)
*/
public void expandShrinkExpandFilter(
int pre_expand,
int shrink,
int post_expand,
boolean [] selection,
boolean [] prohibit)
{
tnImage.growSelection(
pre_expand, // int grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
selection, // boolean [] tiles,
prohibit); // boolean [] prohibit)
tnImage.shrinkSelection(
shrink, // int shrink,
selection, // boolean [] tiles,
prohibit); // boolean [] prohibit)
tnImage.growSelection(
post_expand, // int grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
selection, // boolean [] tiles,
prohibit); // boolean [] prohibit)
}
/**
* Combine (OR) two selections
* @param selection1 first selection
* @param selection2 second selection
* @param enable only use second selection if corresponding element in enable is true. May be null
* @param invert_enable make 'enable' 'disable'
* @return OR-ed selections
*/
public boolean [] combineSelections(
boolean [] selection1,
boolean [] selection2,
boolean [] enable,
boolean invert_enable) {
boolean [] selection = selection1.clone();
if (enable == null) {
for (int i = 0; i < selection.length; i++) selection[i] |= selection2[i];
} else if (invert_enable) {
for (int i = 0; i < selection.length; i++) selection[i] |= (selection2[i] && !enable[i]);
} else {
for (int i = 0; i < selection.length; i++) selection[i] |= (selection2[i] && enable[i]);
}
return selection;
}
public boolean [] selectFarObjects(
double strength_floor,
double min_disparity,
double min_mean,
double max_disparity,
double max_mean,
double min_disp_to_rms,
double min_strength,
int neib_dist, // >=1
double rsigma,
double tile_frac,
boolean [] infinity_select,
double [] disparity,
double [] strength,
int tilesX,
int debugLevel) {
int num_tiles = disparity.length;
if (infinity_select == null) {
infinity_select = new boolean [num_tiles];
for (int nTile = 0; nTile < num_tiles; nTile++) infinity_select[nTile] = true;
}
if (Double.isNaN(strength_floor)) {
strength_floor = Double.NaN;
for (int nTile = 0; nTile < num_tiles; nTile++) if (
infinity_select[nTile] &&
!Double.isNaN(disparity[nTile])&&
(strength[nTile] > 0) &&
(Double.isNaN(strength_floor) || (strength[nTile] < strength_floor))){
strength_floor = strength[nTile];
}
}
if (debugLevel >-2) {
System.out.println("selectFarObjects(): strength_floor = "+strength_floor);
}
if (debugLevel > 0) {
double [] rsigmas = {0.0, 1.0, 0.5};
for (double rs:rsigmas) {
for (int nd = 1; nd < 7; nd++) {
double [][] weight_mask = get9weightMasks(
nd, // >=1int neib_dist, // >=1
rs);
(new showDoubleFloatArrays()).showArrays(
weight_mask,
2*nd+1,
2*nd+1,
true,
"w9m_"+rs);
}
}
}
double [][] weight_mask = get9weightMasks(
neib_dist, // >=1int neib_dist, // >=1
rsigma); // int debugLevel
int [] min_tiles = new int [weight_mask.length];
for (int n = 0; n< min_tiles.length; n++) {
int numnz = 0;
for (int i = 0; i < weight_mask[n].length; i++) {
if (weight_mask[n][i] >0.0) numnz++;
}
min_tiles[n] = (int) Math.round(numnz * tile_frac);
}
int sample_size = 2*neib_dist + 1;
// int last = 2*neib_dist; tile_frac
double [][] mean_to_rms = (debugLevel >-2) ?(new double [4][num_tiles]): null;
double [][] dbg_dirs = (debugLevel > 0) ?(new double [3*weight_mask.length][num_tiles]): null;
if (dbg_dirs != null) {
for (int n = 0; n < dbg_dirs.length; n++) {
for (int nTile =0; nTile <num_tiles; nTile++) {
dbg_dirs[n][nTile] = Double.NaN;
}
}
}
boolean [] selection = new boolean [num_tiles];
if (mean_to_rms != null) for (int nTile =0; nTile <num_tiles; nTile++) for (int i = 0; i < mean_to_rms.length; i++) mean_to_rms[i][nTile] = Double.NaN; // only needed for debug?
int [] num_best = new int [weight_mask.length]; //debug feature
for (int nTile =0; nTile <num_tiles; nTile++) {
// disparity[nTile] may be Double.NaN
if (infinity_select[nTile] && (disparity[nTile] >= min_disparity) && (disparity[nTile] <= max_disparity) && (strength[nTile] >= min_strength)) {
double d0 = disparity[nTile];
double [] s0 = new double[weight_mask.length];
double [] s0a = new double[weight_mask.length];
double [] s1 = new double[weight_mask.length];
double [] s2 = new double[weight_mask.length];
int [] num_nz = new int[weight_mask.length];
// calculate weights, means, and rms for each of 9 windows
for (int dy = -neib_dist; dy <= neib_dist; dy++) {
for (int dx = -neib_dist; dx <= neib_dist; dx++) {
int nTile1 = tnImage.getNeibIndex(nTile, dx, dy);
if ( (nTile1 >=0) &&
!Double.isNaN(disparity[nTile1])) {
double w = strength[nTile1] - strength_floor;
if (w > 0.0) {
int tindx = (dy + neib_dist) * sample_size + (dx + neib_dist);
double d = disparity[nTile1];
for (int n = 0; n < weight_mask.length; n++) {
double ww = w * weight_mask[n][tindx];
s0[n] += ww;
s1[n] += ww* d;
if ((dy!=0) || (dx!=0)){
double dd = (d - d0);
s0a[n] +=ww;
s2[n] += ww*dd*dd;
}
if (ww >0.0) {
num_nz[n]++;
}
}
}
}
}
}
//min_tiles[n]
double rm = 0.0;
int best_dir = -1;
for (int n = 0; n < weight_mask.length; n++) {
if (s0[n] > 0) {
s1[n] /= s0[n]; // mean
}
if (num_nz[n] < min_tiles[n]) {
s1[n] =0.0;
}
if (s0a[n] > 0) {
s2[n] = Math.sqrt(s2[n]/s0a[n]);
double r = s1[n]/s2[n]; // denominator - rms (not including itself
if (r > rm) {
rm = r;
best_dir = n;
}
}
}
if (dbg_dirs != null) {
for (int n = 0; n < weight_mask.length; n++) {
dbg_dirs[n + 0 * weight_mask.length][nTile] = s1[n]/s2[n];
dbg_dirs[n + 1 * weight_mask.length][nTile] = s1[n];
dbg_dirs[n + 2 * weight_mask.length][nTile] = s2[n];
}
}
// double [][] dbg_dirs = (debugLevel >-2) ?(new double [3*weight_mask.length][num_tiles]): null;
if ((rm > min_disp_to_rms) && (s1[best_dir] >= min_mean ) && (s1[best_dir] <= max_mean )){
num_best[best_dir]++;
if (mean_to_rms != null) {
mean_to_rms[0][nTile] = rm;
if (best_dir >= 0) {
mean_to_rms[1][nTile] = s1[best_dir];
mean_to_rms[2][nTile] = s2[best_dir];
mean_to_rms[3][nTile] = 0.1 * best_dir;
}
}
selection[nTile] = true;
}
}
}
// double min_mean,
// double max_disparity,
// double max_mean,
if (debugLevel>-2) {
System.out.println("selectFarObjects(): number of wins:");
for (int i = 0; i < num_best.length; i++) {
System.out.println(i+": "+num_best[i]);
}
}
if (debugLevel > 0) {
(new showDoubleFloatArrays()).showArrays(
weight_mask,
2*neib_dist+1,
2*neib_dist+1,
true,
"weight_mask");
}
if (mean_to_rms != null) {
double [][] dbg_img = {disparity, strength, mean_to_rms[0], mean_to_rms[1], mean_to_rms[2], mean_to_rms[3]};
String [] titles = {"disparity", "strength", "mean_to_rms","mean","rms", "dir/10"};
(new showDoubleFloatArrays()).showArrays(
dbg_img,
tilesX,
mean_to_rms[0].length/tilesX,
true,
"mean_to_rms_"+neib_dist,
titles);
}
if (dbg_dirs != null) {
String [] titles = {
"dr0","dr1","dr2","dr3","dr4","dr5","dr6","dr7","dr8",
"m0","m1","m2","m3","m4","m5","m6","m7","m8",
"r0","r1","r2","r3","r4","r5","r6","r7","r8"};
(new showDoubleFloatArrays()).showArrays(
dbg_dirs,
tilesX,
mean_to_rms[0].length/tilesX,
true,
"mean_and_rms_"+neib_dist,
titles);
}
return selection;
}
public int removeFalseMatches(
double [][] disparity_bimap,
double trusted_strength, // = 0.2; // strength sufficient without neighbors
double stray_rstrength, // = 2.0; // Relative to trusted strength - trust above that
double strength_rfloor, // = 0.28; // Relative to trusted strength
int stray_dist, // = 2; // How far to look (and erase) around a potentially falsely matched tile
double stray_over, // = 2.0; // Stray tile should be this stronger than the strongest neighbor to be recognized
int debugLevel)
{
double max_stray_strength = trusted_strength * stray_rstrength;
double strength_floor = trusted_strength * strength_rfloor;
double max_under = 1.0/stray_over;
ArrayList<Integer> stray_list = new ArrayList<Integer>();
final double [] disparity = disparity_bimap[ImageDtt.BI_TARGET_INDEX];
final double [] strength = disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX];
for (int nTile=0; nTile < strength.length; nTile++) {
if (!Double.isNaN(disparity[nTile]) && (strength[nTile] >= trusted_strength) && (strength[nTile] < max_stray_strength)){
double max_stength = 0.0;
for (int dy = -stray_dist; dy <= stray_dist; dy++) {
for (int dx = -stray_dist; dx <= stray_dist; dx++) if ((dy!=0) || (dx!=0)){
int nTile1 = tnImage.getNeibIndex(nTile, dx, dy);
if ( (nTile1 >=0) &&
!Double.isNaN(disparity[nTile1]) &&
(strength[nTile1] > max_stength)) {
max_stength = strength[nTile1];
}
}
}
if (((max_stength - strength_floor)/(strength[nTile] - strength_floor) <= max_under) &&
(max_stength < trusted_strength)){
stray_list.add(nTile);
if (debugLevel > -2) {
System.out.println(String.format("removeFalseMatches(): adding tile %d (%d/%d) ",nTile, nTile%tnImage.sizeX, nTile/tnImage.sizeX));
}
}
}
}
// now erase around tiles in stray_list
for (int nTile: stray_list) {
for (int dy = -stray_dist; dy <= stray_dist; dy++) {
for (int dx = -stray_dist; dx <= stray_dist; dx++) {
int nTile1 = tnImage.getNeibIndex(nTile, dx, dy);
disparity[nTile1] = Double.NaN;
strength[nTile1] = 0.0;
}
}
}
return stray_list.size();
}
public boolean [] getLTTrusted(
double [][] disparity_bimap,
double min_disparity, // = 0.0; // apply low texture to near objects
......@@ -66,7 +543,7 @@ public class BiCamDSI {
label_tile:
{
for (int dy = -friends_dist; dy <= friends_dist; dy++) {
for (int dx = -friends_dist; dx <= friends_dist; dx++) if ((dy!=0) ||(dx !=0)){
for (int dx = -friends_dist; dx <= friends_dist; dx++) if ((dy!=0) || (dx!=0)){
int nTile1 = tnImage.getNeibIndex(nTile, dx, dy);
if ((nTile1 >= 0) && (disparity[nTile1] >= low_friend) && (disparity[nTile1] <= high_friend)){ // disparity[nTile1] may be NaN!
if (cond_trusted[nTile1]) {
......@@ -90,9 +567,10 @@ public class BiCamDSI {
}
}
}
System.out.println("new tiles = "+new_tiles); // find out why second pass always returns 0
if (debugLevel > -2) System.out.print ("new tiles = "+new_tiles); // find out why second pass always returns 0
if (new_tiles == 0) break;
}
if (debugLevel > -2) System.out.println();
return trusted;
}
......@@ -125,24 +603,22 @@ public class BiCamDSI {
num_trusted++;
} else {
disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile] = Double.NaN;
disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX][nTile] = 0.0;
}
}
return num_trusted;
}
public double [] suggestLTTiles(
double [][] disparity_bimap,
boolean [] trusted, // may be null if disparity is alreasdy NaN-ed
double min_disparity, // = 0.0; // apply low texture to near objects
double trusted_strength, // = 0.2; // strength sufficient without neighbors
double strength_rfloor, // = 0.28; // strength floor relative to trusted_strength
double need_friends, // = 0.4; // strength sufficient with neighbors support, fraction of lt_trusted_strength
// double friends_diff, // = 0.15; // pix difference to neighbors to be considered a match (TODO: use tilted)
// double friends_rdiff, // = 0.04; // additional relative pix per pixel of disparity
// int min_friends_any, // = 2; // minimal number of even weak friends
// int min_friends_trusted, // = 2; // minimal number of trusted (strong or already confirmed)
// int friends_dist, // = 3; // how far to look for friends
// boolean replace_lone, // = true; // try to overwrite lone weak
int extend_dist, // = 3; // how far to extend around known tiles (probably should increase this value up to?
// dealing with neighbors variance
double wsigma, // = 1.0; // influence of far neighbors diminish as a Gaussian with this sigma
......@@ -154,8 +630,8 @@ public class BiCamDSI {
final double asigma = max_asigma; // 1.0;
final double [][] weights = new double [extend_dist+1][extend_dist+1];
final double cond_strength = trusted_strength * need_friends;
final double strength_floor = 0.7*cond_strength;
//final double cond_strength = trusted_strength * need_friends;
final double strength_floor = strength_rfloor * trusted_strength;
for (int i = 0; i <weights.length; i++) {
for (int j = i; j <weights[i].length; j++) {
weights[i][j]=Math.exp(-(i*i+j*j)/(2*wsigma*wsigma));
......@@ -168,71 +644,13 @@ public class BiCamDSI {
trusted = new boolean[disparity.length];
for (int nTile = 0; nTile < trusted.length; nTile++) trusted[nTile] = !Double.isNaN(disparity[nTile]);
}
// final boolean [] trusted = new boolean[strength.length];
// final boolean [] cond_trusted = trusted.clone();
// for (int nTile = 0; nTile < trusted.length; nTile ++) if (strength[nTile] >= cond_strength){
// cond_trusted[nTile] = true;
// trusted[nTile] = strength[nTile] >= trusted_strength;
// }
double sigma = asigma;
double sigma2 = sigma*sigma;
final double [] to_measure = new double [disparity.length];
for (int nTile = 0; nTile < to_measure.length; nTile++) {
to_measure[nTile] = Double.NaN;
}
/*
for (int new_tiles = 0; ; new_tiles = 0) {
for (int nTile = 0; nTile < trusted.length; nTile ++) {
if (cond_trusted[nTile] && !trusted[nTile]) {
int num_trusted = 0;
int num_friends = 0;
double low_friend = disparity[nTile] - friends_diff - friends_rdiff*disparity[nTile];
double high_friend = disparity[nTile] + friends_diff + friends_rdiff*disparity[nTile];
label_tile:
{
for (int dy = -friends_dist; dy <= friends_dist; dy++) {
for (int dx = -friends_dist; dx <= friends_dist; dx++) if ((dy!=0) ||(dx !=0)){
int nTile1 = tnImage.getNeibIndex(nTile, dx, dy);
if ((nTile1 >= 0) && (disparity[nTile1] >= low_friend) && (disparity[nTile1] <= high_friend)){
if (cond_trusted[nTile1]) {
num_friends++;
if (num_friends >= min_friends_any){
trusted[nTile] = true;
new_tiles++;
break label_tile;
} else if (trusted[nTile1]) {
num_trusted++;
if (num_trusted >= min_friends_trusted){
trusted[nTile] = true;
new_tiles++;
break label_tile;
}
}
}
}
}
}
}
}
}
System.out.println("new tiles = "+new_tiles);
if (new_tiles == 0) break;
}
boolean [] trusted = getLTTrusted(
disparity_bimap, // double [][] disparity_bimap,
min_disparity, //double min_disparity, // = 0.0; // apply low texture to near objects
trusted_strength, //double trusted_strength, // = 0.2; // strength sufficient without neighbors
need_friends, //double need_friends, // = 0.4; // strength sufficient with neighbors support, fraction of lt_trusted_strength
friends_diff, //double friends_diff, // = 0.15; // pix difference to neighbors to be considered a match (TODO: use tilted)
friends_rdiff, //double friends_rdiff, // = 0.04; // additional relative pix per pixel of disparity
min_friends_any, //int min_friends_any, // = 2; // minimal number of even weak friends
min_friends_trusted, //int min_friends_trusted, // = 2; // minimal number of trusted (strong or already confirmed)
friends_dist, //int friends_dist, // = 3; // how far to look for friends
debugLevel); //int debugLevel
final boolean [] dbg_trusted = trusted.clone();
*/
final boolean [] candidates = new boolean[strength.length];
// can be done faster if jump on empty by square side
for (int nTile = 0; nTile < candidates.length; nTile++) if (!trusted[nTile]){
......@@ -247,35 +665,7 @@ public class BiCamDSI {
}
}
}
/*
if (debugLevel > -2) {
for (int nTile = 0; nTile < trusted.length; nTile ++) {
disparity_bimap[ImageDtt.BI_DBG1_INDEX][nTile] = Double.NaN;
disparity_bimap[ImageDtt.BI_DBG2_INDEX][nTile] = Double.NaN;
disparity_bimap[ImageDtt.BI_DBG3_INDEX][nTile] = Double.NaN;
disparity_bimap[ImageDtt.BI_DBG4_INDEX][nTile] = Double.NaN;
if (trusted[nTile]) {
disparity_bimap[ImageDtt.BI_DBG1_INDEX][nTile] = disparity[nTile];
disparity_bimap[ImageDtt.BI_DBG2_INDEX][nTile] = disparity[nTile];
disparity_bimap[ImageDtt.BI_DBG4_INDEX][nTile] = 2.0;
// if (dbg_trusted[nTile])disparity_bimap[ImageDtt.BI_DBG4_INDEX][nTile] = 3.0;
// } else if (cond_trusted[nTile]) {
// disparity_bimap[ImageDtt.BI_DBG4_INDEX][nTile] = 1.0;
}
}
for (int nTile = 0; nTile < trusted.length; nTile ++) {
if (candidates[nTile]) disparity_bimap[ImageDtt.BI_DBG4_INDEX][nTile] = 0.0;
}
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tnImage.sizeX,
tnImage.sizeY,
true,
"BiCamDSI",
ImageDtt.BIDISPARITY_TITLES);
}
*/
int num_sigma = 0;
for (int nTile = 0; nTile < candidates.length; nTile++) if (candidates[nTile]){
ArrayList<Integer> sample_list = new ArrayList<Integer>();
......@@ -298,18 +688,11 @@ public class BiCamDSI {
}
double s_mean = s1/s0;
double smpl_var = s2/s0 -s_mean*s_mean;
// if (debugLevel > -2) {
// disparity_bimap[ImageDtt.BI_DBG2_INDEX][nTile] = s_mean;
// disparity_bimap[ImageDtt.BI_DBG3_INDEX][nTile] = Math.sqrt(smpl_var);
// }
// final double rsigma = 0.05; //pix/pix
// final double asigma = max_sigma; // 1.0;
sigma = asigma + rsigma * s_mean;
sigma2 = sigma*sigma;
// FIXME: use tilted planes
if (smpl_var > sigma2) {
if (debugLevel > -2) {
// System.out.print ((nTile%tnImage.sizeX)+"/"+(nTile/tnImage.sizeX)+": s_mean = "+s_mean+", smpl_var = "+smpl_var+" ... "+ " ntiles="+(sample_list.size()));
System.out.print (String.format("%3d/%3d mean=%8f sigma2=%f var=%8f tiles=%3d ",nTile%tnImage.sizeX, nTile/tnImage.sizeX, s_mean, sigma2, smpl_var, sample_list.size()));
}
num_sigma++;
......
......@@ -74,6 +74,7 @@ public class BiQuadParameters {
// rig LT (poor textured areas)
public double lt_min_disparity = 0.0; // apply low texture to near objects
public double lt_trusted_strength = 0.2; // strength sufficient without neighbors
public double lt_strength_rfloor = 0.28; // fraction of trusted strength to subtract
public double lt_need_friends = 0.4; // strength sufficient with neighbors support, fraction of lt_trusted_strength
public double lt_friends_diff = 0.15; // pix difference to neighbors to be considered a match (TODO: use tilted)
public double lt_friends_rdiff = 0.04; // Add per each disparity pixel
......@@ -87,6 +88,45 @@ public class BiQuadParameters {
public double lt_max_asigma = .15; // Maximal acceptable standard deviation of the neighbors (remove, then add)
public double lt_max_rsigma = .04; // Additional standard deviation for each pixel of disparity (relative)
public int lt_repeat = 10; // How many times repeat low texture expand
public int lt_min_new = 100; // Minimal new added tiles while repeating texture expand
// removing false matches in low textured areas
public boolean lt_remove_stray = true; // Handle stray matches
public double lt_stray_rstrength = 2.0; // Relative to trusted strength - trust above that
public int lt_stray_dist = 2; // How far to look (and erase) around a potentially falsely matched tile
public double lt_stray_over = 2.0; // stray tile should be this stronger than the strongest neighbor to be recognized
// Rig ltfar - recovering far objects that could not be resolved with just a single quad camera
public boolean ltfar_en = true; // Enable recovering far objects over infinity area
public boolean ltfar_auto_floor = true; // Automatically detect strength floor (false - use (lt_trusted_strength*lt_strength_rfloor)
public double ltfar_min_disparity = 0.04; // Minimal tile disparity (in master camera pixels) to try to recover
public double ltfar_min_mean = 0.04; // Minimal tile neighbors mean disparity (in master camera pixels) to try to recover
public double ltfar_max_disparity = 0.4; // Maximal tile disparity (in master camera pixels) to try to recover
public double ltfar_max_mean = 0.2; // Maximal tile neighbors mean disparity (in master camera pixels) to try to recover
public double ltfar_min_disp_to_rms = 1.8; // Minimal ratio of mean disparity to disparity rms from the center to recover
public double ltfar_min_rstrength = 0.0; // Minimal tile relative (fraction of lt_trusted_strength) strength to recover
public int ltfar_neib_dist = 3; // Analyze this far around tiles when recovering
public double ltfar_rsigma = 0.7; // Reduce weight of far tiles: Gaussian sigma as a fraction of (ltfar_neib_dist+1),
public double ltfar_frac = 0.7; // Fraction of neighbors that should exist
// repeat after filtering to add lone strong tiles back
public double ltfar_trusted_s = 0.4; // Add even single tiles over infinity if strength (and disparity too) is sufficient
public double ltfar_trusted_d = 0.2; // Add even single tiles over infinity if disparity (and strength too) is sufficient
// rig selection filtering
public boolean rf_master_infinity = true; // Combine with master camera selection over infinity
public boolean rf_master_near = false; // Combine with master camera selection over non-infinity
public int rf_pre_expand = 2; // Expand selection before shrinking
public int rf_shrink = 4; // Shrink selection after expanding
public int rf_post_expand = 2; // Expand selection after shrinking
public int rf_pre_expand_near = 4; // Expand selection before shrinking
public int rf_shrink_near = 8; // Shrink selection after expanding
public int rf_post_expand_near = 4; // Expand selection after shrinking
public int ml_hwidth = 2; // Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)
public double ml_disparity_sweep = 2.0; // Disparity sweep around ground truth, each side
......@@ -193,6 +233,8 @@ public class BiQuadParameters {
"Handle low textured objects with disparity (main camera pixels) above this threshold");
gd.addNumericField("Inter-camera correlation strength sufficient without neighbors", this.lt_trusted_strength, 3,6,"",
"Consider such tiles valid regardless of surrounding tiles");
gd.addNumericField("Relative strength floor", this.lt_strength_rfloor, 3,6,"",
"Fraction of tthe rusted strength to subtract from strengths when comparing");
gd.addNumericField("Strength sufficient with neighbors support, fraction of the trusted (above)", this.lt_need_friends, 3,6,"",
"Tiles above theis inter-camera strength may be valid if they have same disparity neighbors");
gd.addNumericField("Maximal disparity difference to neighbors to be considered a match", this.lt_friends_diff, 3,6,"pix",
......@@ -219,6 +261,70 @@ public class BiQuadParameters {
gd.addNumericField("Additional standard deviation for each pixel of disparity (relative)", this.lt_max_rsigma, 4,6,"pix/pix",
"Loosen sigma requirements for high disparity by adding this value for each 1 pixel of disparity");
gd.addNumericField("How many times repeat low texture expand", this.lt_repeat, 0,3,"",
"Try new repeat low texture areas expanding this number of times (or until too few new tiles are added)");
gd.addNumericField("Minimal new added tiles while repeating texture expand", this.lt_min_new, 0,3,"",
"Exit from low textured tiles expand if thenumber of new added tiles falls below this number");
gd.addMessage("Dealing with false matches in low-textured areas");
gd.addCheckbox ("Handle stray matches", this.lt_remove_stray,
"Erase realtively strong single tiles and surrounding ones if all tiles around are sufficiently weaker");
gd.addNumericField("Relative to trusted strength to definitely trust above that any tile", this.lt_stray_rstrength, 4,6,"",
"Do not suspect false match if the tile strength exceeds this times scaled trusted strength (after subtracting strength floor");
gd.addNumericField("How far to look (and erase) around a potentially falsely matched tile", this.lt_stray_dist, 0,3,"tiles",
"Look up to this number of tiles around the suspect for tha maximal neighbor strength, erase this many tiles around if confirmed");
gd.addNumericField("Stray tile should be this stronger than the strongest neighbor to be recognized", this.lt_stray_over, 4,6,"pix/pix",
"Find the maximal strength of the neighbors, and consider a false match if the suspect is this times stronger");
gd.addTab("Rig Far","Parameters related to the ML files generation for the dual-quad camera rig");
gd.addCheckbox ("Enable recovering far objects over infinity area", this.ltfar_en,
"Try to use tiles that were treated as infinity by a single quad camera");
gd.addCheckbox ("Automatically detect strength floor", this.ltfar_auto_floor,
"Use floor as the minimal non-zero strength in the image. I false - use (lt_trusted_strength*lt_strength_rfloor)");
gd.addNumericField("Minimal tile disparity to try to recover", this.ltfar_min_disparity, 4,6,"pix",
"Minimal tile itself disparity (in master camera pixels) to recover over infinity");
gd.addNumericField("Minimal tile neighbors mean disparity (in master camera pixels) to try to recover", this.ltfar_min_mean, 4,6,"pix",
"Minimal weighted average of the tile and its neighbors (in master camera pixels) to recover over infinity");
gd.addNumericField("Maximal tile disparity (in master camera pixels) to try to recover", this.ltfar_max_disparity, 4,6,"pix",
"Maximal tile itself disparity (in master camera pixels) to recover over infinity");
gd.addNumericField("Maximal tile neighbors mean disparity (in master camera pixels) to try to recover", this.ltfar_max_mean, 4,6,"pix",
"Maximal weighted average of the tile and its neighbors (in master camera pixels) to recover over infinity");
gd.addNumericField("Minimal ratio of mean disparity to disparity rms from the center to recover", this.ltfar_min_disp_to_rms, 4,6,"",
"Rationale: disparity should be reliably > 0");
gd.addNumericField("Minimal tile relative (fraction of lt_trusted_strength) strength to recover", this.ltfar_min_rstrength, 4,6,"",
"May be not needed (use 0.0) and process all non-zero strength tiles");
gd.addNumericField("Analyze this far around tiles when recovering", this.ltfar_neib_dist, 0,3,"",
"The square sample processed has side of 2*<this_number> + 1, the best of 8 half-squares and a smaller centered area will be used)");
gd.addNumericField("Reduce weight of far tiles: Gaussian sigma as a fraction of (ltfar_neib_dist+1)", this.ltfar_rsigma, 4,6,"",
"Reduce wight tof far neighbors using Gaussian with sigma as a fraction of teh square half-size");
gd.addNumericField("Fraction of possible neighbors that should exist", this.ltfar_frac, 4,6,"",
"For each of 9 windows calculate number of defined tiles and divide by a number of non-zero in the window");
gd.addMessage("Filtering selection of non-infinity tiles");
gd.addNumericField("Add even single tiles over infinity if STRENGTH (and disparity too) is sufficient", this.ltfar_trusted_s, 4,6,"",
"Add strong tiles over infinity areas that have both strenth and disparity above respective thersholds (re-add them after filtering)");
gd.addNumericField("Add even single tiles over infinity if DISPARITY (and strength too) is sufficient", this.ltfar_trusted_d, 4,6,"pix",
"Add strong tiles over infinity areas that have both strenth and disparity above respective thersholds (re-add them after filtering)");
gd.addCheckbox ("Combine with master camera selection over infinity", this.rf_master_infinity,
"'OR' selection with previos tile selection for master camera over infinity areas");
gd.addCheckbox ("Combine with master camera selection over non-infinity", this.rf_master_near,
"'OR' selection with previos tile selection for master camera over non-infinity areas");
gd.addNumericField("Expand selection before shrinking", this.rf_pre_expand, 0,3,"",
"First step of expand-shrink-expand filtering (1 - only vert/hor, 2 -vert/hor/diagonal)");
gd.addNumericField("Shrink selection after expanding", this.rf_shrink, 0,3,"",
"Second step of expand-shrink-expand filtering (1 - only vert/hor, 2 -vert/hor/diagonal)");
gd.addNumericField("Expand selection after shrinking", this.rf_post_expand, 0,3,"",
"Last step of expand-shrink-expand filtering (1 - only vert/hor, 2 -vert/hor/diagonal)");
gd.addNumericField("Expand selection before shrinking (non-infinity regions only)", this.rf_pre_expand_near, 0,3,"",
"First step of expand-shrink-expand filtering (1 - only vert/hor, 2 -vert/hor/diagonal)");
gd.addNumericField("Shrink selection after expanding (non-infinity regions only)", this.rf_shrink_near, 0,3,"",
"Second step of expand-shrink-expand filtering (1 - only vert/hor, 2 -vert/hor/diagonal)");
gd.addNumericField("Expand selection after shrinking (non-infinity regions only)", this.rf_post_expand_near, 0,3,"",
"Last step of expand-shrink-expand filtering (1 - only vert/hor, 2 -vert/hor/diagonal)");
gd.addTab("ML","Parameters related to the ML files generation for the dual-quad camera rig");
gd.addNumericField("Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)", this.ml_hwidth, 0,3,"",
......@@ -294,6 +400,7 @@ public class BiQuadParameters {
this.lt_min_disparity= gd.getNextNumber();
this.lt_trusted_strength= gd.getNextNumber();
this.lt_strength_rfloor= gd.getNextNumber();
this.lt_need_friends= gd.getNextNumber();
this.lt_friends_diff= gd.getNextNumber();
this.lt_friends_rdiff= gd.getNextNumber();
......@@ -306,6 +413,36 @@ public class BiQuadParameters {
this.lt_max_asigma= gd.getNextNumber();
this.lt_max_rsigma= gd.getNextNumber();
this.lt_repeat= (int) gd.getNextNumber();
this.lt_min_new= (int) gd.getNextNumber();
this.lt_remove_stray= gd.getNextBoolean();
this.lt_stray_rstrength= gd.getNextNumber();
this.lt_stray_dist= (int) gd.getNextNumber();
this.lt_stray_over= gd.getNextNumber();
this.ltfar_en= gd.getNextBoolean();
this.ltfar_auto_floor= gd.getNextBoolean();
this.ltfar_min_disparity= gd.getNextNumber();
this.ltfar_min_mean= gd.getNextNumber();
this.ltfar_max_disparity= gd.getNextNumber();
this.ltfar_max_mean= gd.getNextNumber();
this.ltfar_min_disp_to_rms= gd.getNextNumber();
this.ltfar_min_rstrength= gd.getNextNumber();
this.ltfar_neib_dist= (int) gd.getNextNumber();
this.ltfar_rsigma= gd.getNextNumber();
this.ltfar_frac= gd.getNextNumber();
this.ltfar_trusted_s= gd.getNextNumber();
this.ltfar_trusted_d= gd.getNextNumber();
this.rf_master_infinity= gd.getNextBoolean();
this.rf_master_near= gd.getNextBoolean();
this.rf_pre_expand= (int) gd.getNextNumber();
this.rf_shrink= (int) gd.getNextNumber();
this.rf_post_expand= (int) gd.getNextNumber();
this.rf_pre_expand_near= (int) gd.getNextNumber();
this.rf_shrink_near= (int) gd.getNextNumber();
this.rf_post_expand_near= (int) gd.getNextNumber();
this.ml_hwidth= (int) gd.getNextNumber();
this.ml_disparity_sweep= gd.getNextNumber();
this.ml_sweep_steps= (int) gd.getNextNumber();
......@@ -368,6 +505,7 @@ public class BiQuadParameters {
properties.setProperty(prefix+"lt_min_disparity", this.lt_min_disparity+"");
properties.setProperty(prefix+"lt_trusted_strength", this.lt_trusted_strength+"");
properties.setProperty(prefix+"lt_strength_rfloor", this.lt_strength_rfloor+"");
properties.setProperty(prefix+"lt_need_friends", this.lt_need_friends+"");
properties.setProperty(prefix+"lt_friends_diff", this.lt_friends_diff+"");
properties.setProperty(prefix+"lt_friends_rdiff", this.lt_friends_rdiff+"");
......@@ -380,6 +518,37 @@ public class BiQuadParameters {
properties.setProperty(prefix+"lt_max_asigma", this.lt_max_asigma+"");
properties.setProperty(prefix+"lt_max_rsigma", this.lt_max_rsigma+"");
properties.setProperty(prefix+"lt_repeat", this.lt_repeat+"");
properties.setProperty(prefix+"lt_min_new", this.lt_min_new+"");
properties.setProperty(prefix+"lt_remove_stray", this.lt_remove_stray+"");
properties.setProperty(prefix+"lt_stray_rstrength", this.lt_stray_rstrength+"");
properties.setProperty(prefix+"lt_stray_dist", this.lt_stray_dist+"");
properties.setProperty(prefix+"lt_stray_over", this.lt_stray_over+"");
properties.setProperty(prefix+"ltfar_en", this.ltfar_en+"");
properties.setProperty(prefix+"ltfar_auto_floor", this.ltfar_auto_floor+"");
properties.setProperty(prefix+"ltfar_min_disparity", this.ltfar_min_disparity+"");
properties.setProperty(prefix+"ltfar_min_mean", this.ltfar_min_mean+"");
properties.setProperty(prefix+"ltfar_max_disparity", this.ltfar_max_disparity+"");
properties.setProperty(prefix+"ltfar_max_mean", this.ltfar_max_mean+"");
properties.setProperty(prefix+"ltfar_min_disp_to_rms", this.ltfar_min_disp_to_rms+"");
properties.setProperty(prefix+"ltfar_min_rstrength", this.ltfar_min_rstrength+"");
properties.setProperty(prefix+"ltfar_neib_dist", this.ltfar_neib_dist+"");
properties.setProperty(prefix+"ltfar_rsigma", this.ltfar_rsigma+"");
properties.setProperty(prefix+"ltfar_frac", this.ltfar_frac+"");
properties.setProperty(prefix+"ltfar_trusted_s", this.ltfar_trusted_s+"");
properties.setProperty(prefix+"ltfar_trusted_d", this.ltfar_trusted_d+"");
properties.setProperty(prefix+"rf_master_infinity", this.rf_master_infinity+"");
properties.setProperty(prefix+"rf_master_near", this.rf_master_near+"");
properties.setProperty(prefix+"rf_pre_expand", this.rf_pre_expand+"");
properties.setProperty(prefix+"rf_shrink", this.rf_shrink+"");
properties.setProperty(prefix+"rf_post_expand", this.rf_post_expand+"");
properties.setProperty(prefix+"rf_pre_expand_near", this.rf_pre_expand_near+"");
properties.setProperty(prefix+"rf_shrink_near", this.rf_shrink_near+"");
properties.setProperty(prefix+"rf_post_expand_near", this.rf_post_expand_near+"");
properties.setProperty(prefix+"ml_hwidth", this.ml_hwidth+"");
properties.setProperty(prefix+"ml_disparity_sweep", this.ml_disparity_sweep+"");
properties.setProperty(prefix+"ml_sweep_steps", this.ml_sweep_steps+"");
......@@ -439,6 +608,7 @@ public class BiQuadParameters {
if (properties.getProperty(prefix+"lt_min_disparity")!=null) this.lt_min_disparity=Double.parseDouble(properties.getProperty(prefix+"lt_min_disparity"));
if (properties.getProperty(prefix+"lt_trusted_strength")!=null) this.lt_trusted_strength=Double.parseDouble(properties.getProperty(prefix+"lt_trusted_strength"));
if (properties.getProperty(prefix+"lt_strength_rfloor")!=null) this.lt_strength_rfloor=Double.parseDouble(properties.getProperty(prefix+"lt_strength_rfloor"));
if (properties.getProperty(prefix+"lt_need_friends")!=null) this.lt_need_friends=Double.parseDouble(properties.getProperty(prefix+"lt_need_friends"));
if (properties.getProperty(prefix+"lt_friends_diff")!=null) this.lt_friends_diff=Double.parseDouble(properties.getProperty(prefix+"lt_friends_diff"));
if (properties.getProperty(prefix+"lt_friends_rdiff")!=null) this.lt_friends_rdiff=Double.parseDouble(properties.getProperty(prefix+"lt_friends_rdiff"));
......@@ -451,6 +621,39 @@ public class BiQuadParameters {
if (properties.getProperty(prefix+"lt_max_asigma")!=null) this.lt_max_asigma=Double.parseDouble(properties.getProperty(prefix+"lt_max_sigma"));
if (properties.getProperty(prefix+"lt_max_rsigma")!=null) this.lt_max_rsigma=Double.parseDouble(properties.getProperty(prefix+"lt_max_sigma"));
if (properties.getProperty(prefix+"lt_repeat")!=null) this.lt_repeat=Integer.parseInt(properties.getProperty(prefix+"lt_repeat"));
if (properties.getProperty(prefix+"lt_min_new")!=null) this.lt_min_new=Integer.parseInt(properties.getProperty(prefix+"lt_min_new"));
if (properties.getProperty(prefix+"lt_remove_stray")!=null) this.lt_remove_stray=Boolean.parseBoolean(properties.getProperty(prefix+"lt_remove_stray"));
if (properties.getProperty(prefix+"lt_stray_rstrength")!=null) this.lt_stray_rstrength=Double.parseDouble(properties.getProperty(prefix+"lt_stray_rstrength"));
if (properties.getProperty(prefix+"lt_stray_dist")!=null) this.lt_stray_dist=Integer.parseInt(properties.getProperty(prefix+"lt_stray_dist"));
if (properties.getProperty(prefix+"lt_stray_over")!=null) this.lt_stray_over=Double.parseDouble(properties.getProperty(prefix+"lt_stray_over"));
if (properties.getProperty(prefix+"ltfar_en")!=null) this.ltfar_en=Boolean.parseBoolean(properties.getProperty(prefix+"ltfar_en"));
if (properties.getProperty(prefix+"ltfar_auto_floor")!=null) this.ltfar_auto_floor=Boolean.parseBoolean(properties.getProperty(prefix+"ltfar_auto_floor"));
if (properties.getProperty(prefix+"ltfar_min_disparity")!=null) this.ltfar_min_disparity=Double.parseDouble(properties.getProperty(prefix+"ltfar_min_disparity"));
if (properties.getProperty(prefix+"ltfar_min_mean")!=null) this.ltfar_min_mean=Double.parseDouble(properties.getProperty(prefix+"ltfar_min_mean"));
if (properties.getProperty(prefix+"ltfar_max_disparity")!=null) this.ltfar_max_disparity=Double.parseDouble(properties.getProperty(prefix+"ltfar_max_disparity"));
if (properties.getProperty(prefix+"ltfar_max_mean")!=null) this.ltfar_max_mean=Double.parseDouble(properties.getProperty(prefix+"ltfar_max_mean"));
if (properties.getProperty(prefix+"ltfar_min_disp_to_rms")!=null) this.ltfar_min_disp_to_rms=Double.parseDouble(properties.getProperty(prefix+"ltfar_min_disp_to_rms"));
if (properties.getProperty(prefix+"ltfar_min_rstrength")!=null) this.ltfar_min_rstrength=Double.parseDouble(properties.getProperty(prefix+"ltfar_min_rstrength"));
if (properties.getProperty(prefix+"ltfar_neib_dist")!=null) this.ltfar_neib_dist=Integer.parseInt(properties.getProperty(prefix+"ltfar_neib_dist"));
if (properties.getProperty(prefix+"ltfar_rsigma")!=null) this.ltfar_rsigma=Double.parseDouble(properties.getProperty(prefix+"ltfar_rsigma"));
if (properties.getProperty(prefix+"ltfar_frac")!=null) this.ltfar_frac=Double.parseDouble(properties.getProperty(prefix+"ltfar_frac"));
if (properties.getProperty(prefix+"ltfar_trusted_s")!=null) this.ltfar_trusted_s=Double.parseDouble(properties.getProperty(prefix+"ltfar_trusted_s"));
if (properties.getProperty(prefix+"ltfar_trusted_d")!=null) this.ltfar_trusted_d=Double.parseDouble(properties.getProperty(prefix+"ltfar_trusted_d"));
if (properties.getProperty(prefix+"rf_master_infinity")!=null) this.rf_master_infinity=Boolean.parseBoolean(properties.getProperty(prefix+"rf_master_infinity"));
if (properties.getProperty(prefix+"rf_master_near")!=null) this.rf_master_near=Boolean.parseBoolean(properties.getProperty(prefix+"rf_master_near"));
if (properties.getProperty(prefix+"rf_pre_expand")!=null) this.rf_pre_expand=Integer.parseInt(properties.getProperty(prefix+"rf_pre_expand"));
if (properties.getProperty(prefix+"rf_shrink")!=null) this.rf_shrink=Integer.parseInt(properties.getProperty(prefix+"rf_shrink"));
if (properties.getProperty(prefix+"rf_post_expand")!=null) this.rf_post_expand=Integer.parseInt(properties.getProperty(prefix+"rf_post_expand"));
if (properties.getProperty(prefix+"rf_pre_expand_near")!=null) this.rf_pre_expand_near=Integer.parseInt(properties.getProperty(prefix+"rf_pre_expand_near"));
if (properties.getProperty(prefix+"rf_shrink_near")!=null) this.rf_shrink_near=Integer.parseInt(properties.getProperty(prefix+"rf_shrink_near"));
if (properties.getProperty(prefix+"rf_post_expand_near")!=null) this.rf_post_expand_near=Integer.parseInt(properties.getProperty(prefix+"rf_post_expand_near"));
if (properties.getProperty(prefix+"ml_disparity_sweep")!=null) this.ml_disparity_sweep=Double.parseDouble(properties.getProperty(prefix+"ml_disparity_sweep"));
if (properties.getProperty(prefix+"ml_sweep_steps")!=null) this.ml_sweep_steps=Integer.parseInt(properties.getProperty(prefix+"ml_sweep_steps"));
if (properties.getProperty(prefix+"ml_keep_aux")!=null) this.ml_keep_aux=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_aux"));
......@@ -510,6 +713,7 @@ public class BiQuadParameters {
bqp.lt_min_disparity= this.lt_min_disparity;
bqp.lt_trusted_strength= this.lt_trusted_strength;
bqp.lt_strength_rfloor= this.lt_strength_rfloor;
bqp.lt_need_friends= this.lt_need_friends;
bqp.lt_friends_diff= this.lt_friends_diff;
bqp.lt_friends_rdiff= this.lt_friends_rdiff;
......@@ -522,6 +726,37 @@ public class BiQuadParameters {
bqp.lt_max_asigma= this.lt_max_asigma;
bqp.lt_max_rsigma= this.lt_max_rsigma;
bqp.lt_repeat= this.lt_repeat;
bqp.lt_min_new= this.lt_min_new;
bqp.lt_remove_stray= this.lt_remove_stray;
bqp.lt_stray_rstrength= this.lt_stray_rstrength;
bqp.lt_stray_dist= this.lt_stray_dist;
bqp.lt_stray_over= this.lt_stray_over;
bqp.ltfar_en= this.ltfar_en;
bqp.ltfar_auto_floor= this.ltfar_auto_floor;
bqp.ltfar_min_disparity= this.ltfar_min_disparity;
bqp.ltfar_min_mean= this.ltfar_min_mean;
bqp.ltfar_max_disparity= this.ltfar_max_disparity;
bqp.ltfar_max_mean= this.ltfar_max_mean;
bqp.ltfar_min_disp_to_rms= this.ltfar_min_disp_to_rms;
bqp.ltfar_min_rstrength= this.ltfar_min_rstrength;
bqp.ltfar_neib_dist= this.ltfar_neib_dist;
bqp.ltfar_rsigma= this.ltfar_rsigma;
bqp.ltfar_frac= this.ltfar_frac;
bqp.ltfar_trusted_s= this.ltfar_trusted_s;
bqp.ltfar_trusted_d= this.ltfar_trusted_d;
bqp.rf_master_infinity= this.rf_master_infinity;
bqp.rf_master_near= this.rf_master_near;
bqp.rf_pre_expand= this.rf_pre_expand;
bqp.rf_shrink= this.rf_shrink;
bqp.rf_post_expand= this.rf_post_expand;
bqp.rf_pre_expand_near= this.rf_pre_expand_near;
bqp.rf_shrink_near= this.rf_shrink_near;
bqp.rf_post_expand_near= this.rf_post_expand_near;
bqp.ml_hwidth= this.ml_hwidth;
bqp.ml_disparity_sweep= this.ml_disparity_sweep;
bqp.ml_sweep_steps= this.ml_sweep_steps;
......
......@@ -569,6 +569,7 @@ private Panel panel1,
addButton("Setup CLT Batch parameters", panelClt3, color_configure);
addButton("CLT batch process", panelClt3, color_process);
addButton("CM Test", panelClt3, color_stop);
addButton("Show scan", panelClt3, color_configure);
add(panelClt3);
}
......@@ -579,13 +580,16 @@ private Panel panel1,
addButton("Import Aux", panelClt4, color_restore);
addButton("Setup CLT Batch parameters", panelClt4, color_configure);
addButton("CLT rig edit", panelClt4, color_configure);
addButton("CLT 2*4 images", panelClt4, color_conf_process);
addButton("CLT 2*4 images - 2", panelClt4, color_conf_process);
addButton("CLT 2*4 images - 3", panelClt4, color_conf_process);
// addButton("CLT 2*4 images", panelClt4, color_conf_process);
// addButton("CLT 2*4 images - 2", panelClt4, color_conf_process);
// addButton("CLT 2*4 images - 3", panelClt4, color_conf_process);
addButton("Rig8 images", panelClt4, color_conf_process);
addButton("Rig infinity calibration", panelClt4, color_conf_process);
addButton("AUX Extrinsics", panelClt4, color_process);
addButton("AUX show fine", panelClt4, color_configure);
addButton("Rig enhance", panelClt4, color_conf_process);
// addButton("Rig enhance", panelClt4, color_conf_process);
addButton("Ground truth", panelClt4, color_conf_process);
addButton("ML export", panelClt4, color_conf_process);
add(panelClt4);
}
......@@ -4519,10 +4523,15 @@ private Panel panel1,
PROPERTIES);
}
return;
/* ======================================================================== */
} else if (label.equals("CM Test")) {
cm_test();
return;
/* ======================================================================== */
} else if (label.equals("Show scan")) {
showScan();
return;
/* ======================================================================== */
} else if (label.equals("Import Aux")) {
importAux();
......@@ -4540,7 +4549,7 @@ private Panel panel1,
getPairImages2(false);
return;
/* ======================================================================== */
} else if (label.equals("CLT 2*4 images - 3")) {
} else if (label.equals("Rig8 images")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
getPairImages2(true);
......@@ -4583,12 +4592,18 @@ private Panel panel1,
return;
/* ======================================================================== */
} else if (label.equals("Rig enhance")) {
} else if (label.equals("Ground truth")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
enhanceByRig();
return;
/* ======================================================================== */
} else if (label.equals("ML export")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
exportMLData();
return;
/* ======================================================================== */
} else if (label.equals("CLT rig edit")) {
......@@ -5007,6 +5022,12 @@ private Panel panel1,
public boolean enhanceByRig() {
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
String msg = "DSI data is not available. Please run \"CLT 3D\" first";
IJ.showMessage("Error",msg);
System.out.println(msg);
return false;
}
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
......@@ -5037,6 +5058,43 @@ private Panel panel1,
return true;
}
public boolean exportMLData() {
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
String msg = "DSI data is not available. Please run \"CLT 3D\" first";
IJ.showMessage("Error",msg);
System.out.println(msg);
return false;
}
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Generating ML datasets ++++++++++++++");
}
try {
TWO_QUAD_CLT.outputMLData( // actually there is no sense to process multiple image sets. Combine with other processing?
QUAD_CLT, // QuadCLT quadCLT_main,
QUAD_CLT_AUX, // QuadCLT quadCLT_aux,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
DEBUG_LEVEL);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //final int debugLevel);
if (configPath!=null) {
saveTimestampedProperties( // save config again
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
}
return true;
}
public boolean infinityRig() {
if (!prepareRigImages()) return false;
......@@ -5044,7 +5102,7 @@ private Panel panel1,
if (configPath.equals("ABORT")) return false;
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Processing Infinity rig calibration ++++++++++++++");
System.out.println("++++++++++++++ Processing infinity rig calibration ++++++++++++++");
}
try {
TWO_QUAD_CLT.processInfinityRigs( // actually there is no sense to process multiple image sets. Combine with other processing?
......@@ -5473,6 +5531,27 @@ private Panel panel1,
return true;
}
public boolean showScan() {
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
String msg = "DSI data is not available. Please run \"CLT 3D\" first";
IJ.showMessage("Error",msg);
System.out.println(msg);
return false;
}
int scan_index = 0;
GenericJTabbedDialog gd = new GenericJTabbedDialog("Set CLT parameters",400,100);
gd.addNumericField("Scan index (0..."+(QUAD_CLT.tp.clt_3d_passes.size()-1), scan_index, 0, 2, "",
"Display scan by index");
gd.showDialog();
if (gd.wasCanceled()) return false;
scan_index = (int) gd.getNextNumber();
QUAD_CLT.tp.showScan(QUAD_CLT.tp.clt_3d_passes.get(scan_index),"Scan-"+scan_index);
return true;
}
public boolean cm_test() {
double hsize_x = 1.5;
double hsize_y = 1.5;
......
......@@ -73,7 +73,10 @@ public class QuadCLT {
// magic scale should be set before using TileProcessor (calculated disparities depend on it)
public double [][] getGroundTruthByRig(){
if (tp == null) return null;
return tp.rig_disparity_strength;
}
public void setTiles (ImagePlus imp, // set tp.tilesX, tp.tilesY
EyesisCorrectionParameters.CLTParameters clt_parameters,
int threadsMax
......
......@@ -31,6 +31,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class TileProcessor {
public ArrayList <CLTPass3d> clt_3d_passes = null;
public double [][] rig_disparity_strength = null; // Disparity and strength created by a two-camera rig, with disparity scale and distortions of the main camera
public int clt_3d_passes_size = 0; //clt_3d_passes size after initial processing
private int tilesX;
private int tilesY;
......@@ -2218,11 +2219,11 @@ public class TileProcessor {
block_propagate[tindx] = (disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax2][tindx] > sure_smth);
}
}
// TODO: check if minimal cluster strengh should be limited here
// TODO: check if minimal cluster strength should be limited here
if (min_clstr_seed > 1){
removeSmallClusters(
true, // boolean diag_en, // enable diagonal directions, false only up, dowm, right,left
bgnd_tiles, // boolean [] tiles_src, // selected tiles, will modified
bgnd_tiles, // boolean [] tiles_src, // selected tiles, will be modified
null, // double [] weights_src, // or null
min_clstr_seed, // int min_area, // minimal number of pixels
0.0, //clt_parameters.min_clstr_weight, // double min_weight // minimal total weight of the cluster
......
......@@ -1184,7 +1184,8 @@ if (debugLevel > -100) return true; // temporarily !
// improve DSI acquired for a single camera by use of a pair
// Run this after "CLT 3D"
public double [][] enhanceByRig(
public void enhanceByRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
EyesisCorrectionParameters.CLTParameters clt_parameters,
......@@ -1192,6 +1193,261 @@ if (debugLevel > -100) return true; // temporarily !
final boolean updateStatus,
final int debugLevel) throws Exception
{
// boolean combine_oldsel_far = clt_parameters.rig.rf_master_infinity; // = true;
// boolean combine_oldsel_near = clt_parameters.rig.rf_master_near; // = false; //
if ((quadCLT_main.tp == null) || (quadCLT_main.tp.clt_3d_passes == null)) {
String msg = "DSI data not available. Please run\"CLT 3D\" first";
IJ.showMessage(msg);
System.out.println(msg);
return;
}
double [][] rig_disparity_strength = quadCLT_main.getGroundTruthByRig();
if (rig_disparity_strength == null) {
rig_disparity_strength = groundTruthByRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
if (rig_disparity_strength != null) {
quadCLT_main.tp.rig_disparity_strength = rig_disparity_strength;
}
}
CLTPass3d scan_bg = quadCLT_main.tp.clt_3d_passes.get( 0); // get bg scan
CLTPass3d scan_last = quadCLT_main.tp.clt_3d_passes.get(quadCLT_main.tp.clt_3d_passes.size()-1); // get last scan
// TODO: combine in a single function to always call after groundTruthByRig. Or before use?
boolean [] infinity_select = scan_bg.getSelected(); // null;
boolean [] was_select = scan_last.getSelected(); // null;
boolean[] selection = null;
final int tilesX = quadCLT_main.tp.getTilesX();
final int tilesY = quadCLT_main.tp.getTilesY();
BiCamDSI biCamDSI = new BiCamDSI( tilesX, tilesY);
boolean [][] dbg_sel = (debugLevel > -2)? new boolean [8][]:null;// was 4
if (dbg_sel!=null) dbg_sel[0] = infinity_select;
if (dbg_sel!=null) dbg_sel[1] = was_select;
if (clt_parameters.rig.ltfar_en) {
double strength_floor = (clt_parameters.rig.ltfar_auto_floor)? Double.NaN: (clt_parameters.rig.lt_trusted_strength*clt_parameters.rig.lt_strength_rfloor);
double ltfar_min_strength = clt_parameters.rig.ltfar_min_rstrength * clt_parameters.rig.lt_trusted_strength;
selection = biCamDSI.selectFarObjects(
strength_floor, //double strength_floor,
clt_parameters.rig.ltfar_min_disparity , // double min_disparity,
clt_parameters.rig.ltfar_min_mean , // double min_mean,
clt_parameters.rig.ltfar_max_disparity , //double max_disparity,
clt_parameters.rig.ltfar_max_mean , //double max_mean,
clt_parameters.rig.ltfar_min_disp_to_rms , //double min_disp_to_rms,
ltfar_min_strength , //double min_strength,
clt_parameters.rig.ltfar_neib_dist , //int neib_dist, // >=1
clt_parameters.rig.ltfar_rsigma , //double rsigma,
clt_parameters.rig.ltfar_frac, // double tile_frac,
//ltfar_frac
infinity_select, // null, // TODO: add real after debug boolean [] infinity_select,
rig_disparity_strength[0], // double [] disparity,
rig_disparity_strength[1], // double [] strength,
tilesX, // int tilesX, debug only
debugLevel); // int debugLevel);
if (dbg_sel!=null) dbg_sel[2] = selection.clone();
}
selection=biCamDSI.selectNearObjects(
0.0, // double min_strength,
infinity_select, // boolean [] infinity_select,
selection, // boolean [] selection,
rig_disparity_strength[0], // double [] disparity,
rig_disparity_strength[1]); // double [] strength,
if (dbg_sel!=null) dbg_sel[3] = selection.clone();
if (clt_parameters.rig.rf_master_infinity) {
selection = biCamDSI.combineSelections(
selection, // boolean [] selection1,
was_select, // boolean [] selection2,
infinity_select, // boolean [] enable,
false); // boolean invert_enable)
}
if (clt_parameters.rig.rf_master_near) {
selection = biCamDSI.combineSelections(
selection, // boolean [] selection1,
was_select, // boolean [] selection2,
infinity_select, // boolean [] enable,
true); // boolean invert_enable)
}
if (dbg_sel!=null) dbg_sel[4] = selection.clone(); // far+near+old
// if ((combine_oldsel_far || combine_oldsel_near) && (was_select != null) ) {
// for (int nTile=0; nTile < selection.length; nTile++) {
// selection[nTile] |= was_select[nTile] && (infinity_select[nTile]? combine_oldsel_far : combine_oldsel_near) ;
// }
// }
boolean [] selection_lone = biCamDSI.selectLoneFar(
clt_parameters.rig.ltfar_trusted_s, // double min_far_strength,
clt_parameters.rig.ltfar_trusted_d, // double min_far_disparity,
infinity_select, // boolean [] infinity_select,
null, // boolean [] selection,
rig_disparity_strength[0], // double [] disparity,
rig_disparity_strength[1]); // double [] strength)
// add this selection, but keep it too till after filtering
selection = biCamDSI.combineSelections(
selection, // boolean [] selection1,
selection_lone, // boolean [] selection2,
null, // boolean [] enable,
false); // boolean invert_enable)
if (dbg_sel!=null) dbg_sel[5] = selection.clone(); // far+near+old+lone
// filter only near objects
biCamDSI.expandShrinkExpandFilter(
clt_parameters.rig.rf_pre_expand_near, // int pre_expand,
clt_parameters.rig.rf_shrink_near, // int shrink,
clt_parameters.rig.rf_post_expand_near, // int post_expand,
selection, // boolean [] selection,
infinity_select); // boolean [] prohibit)
// filter all - infinity and near (less aggressive)
if (dbg_sel!=null) dbg_sel[6] = selection.clone(); // far+near+old+lone- filtered near
biCamDSI.expandShrinkExpandFilter(
clt_parameters.rig.rf_pre_expand, // int pre_expand,
clt_parameters.rig.rf_shrink, // int shrink,
clt_parameters.rig.rf_post_expand, // int post_expand,
selection, // boolean [] selection,
null); // boolean [] prohibit)
if (dbg_sel!=null) dbg_sel[7] = selection.clone(); // far+near+old+lone- filtered near-filtered far
// restore lone tile selections (may be removed by filter)
selection = biCamDSI.combineSelections(
selection, // boolean [] selection1,
selection_lone, // boolean [] selection2,
null, // boolean [] enable,
false); // boolean invert_enable)
// restore master camera selections (poles may be remode by a filter
if (clt_parameters.rig.rf_master_infinity) {
selection = biCamDSI.combineSelections(
selection, // boolean [] selection1,
was_select, // boolean [] selection2,
infinity_select, // boolean [] enable,
false); // boolean invert_enable)
}
if (clt_parameters.rig.rf_master_near) {
selection = biCamDSI.combineSelections(
selection, // boolean [] selection1,
was_select, // boolean [] selection2,
infinity_select, // boolean [] enable,
true); // boolean invert_enable)
}
if (dbg_sel != null) {
double [][] dbg_img = new double[7][selection.length];
for (int nTile = 0; nTile < selection.length;nTile++) {
dbg_img[0][nTile] = (dbg_sel[0][nTile]? 1.0:0.0) + (dbg_sel[1][nTile]?2.0:0.0);
dbg_img[1][nTile] = (dbg_sel[2][nTile]? 1.0:0.0) + (dbg_sel[3][nTile]?1.0:0.0);
dbg_img[2][nTile] = (dbg_sel[4][nTile]? 1.0:0.0) + (dbg_sel[5][nTile]?1.0:0.0);
dbg_img[3][nTile] = (dbg_sel[6][nTile]? 1.0:0.0);
dbg_img[4][nTile] = (dbg_sel[7][nTile]? 1.0:0.0);
dbg_img[5][nTile] = (selection[nTile]? 1.0:0.0);
dbg_img[6][nTile] = (selection_lone[nTile]? 1.0:0.0);
}
String [] titles = {"old_sel","new_sel","combo-lone", "f-near", "f-far","final","lone"};
(new showDoubleFloatArrays()).showArrays(
dbg_img,
tilesX,
dbg_img[0].length/tilesX,
true,
"Selections",
titles);
}
}
public void outputMLData(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel) // throws Exception
{
if ((quadCLT_main.tp == null) || (quadCLT_main.tp.clt_3d_passes == null)) {
String msg = "DSI data not available. Please run \"CLT 3D\" first";
IJ.showMessage("Error",msg);
System.out.println(msg);
return;
}
double [][] rig_disparity_strength = quadCLT_main.getGroundTruthByRig();
if (rig_disparity_strength == null) {
rig_disparity_strength = groundTruthByRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel-2); // final int debugLevel);
if (rig_disparity_strength != null) {
quadCLT_main.tp.rig_disparity_strength = rig_disparity_strength;
} else {
System.out.println("outputMLData(): failed to get ground truth data, aborting");
return;
}
}
String ml_directory= quadCLT_main.correctionsParameters.selectMlDirectory(
true, // smart,
true); //newAllowed, // save
Correlation2d corr2d = new Correlation2d(
clt_parameters.img_dtt, // ImageDttParameters imgdtt_params,
clt_parameters.transform_size, // int transform_size,
2.0, // double wndx_scale, // (wndy scale is always 1.0)
(debugLevel > -1)); // boolean debug)
for (int sweep_step = 0; sweep_step < clt_parameters.rig.ml_sweep_steps; sweep_step++){
double disparity_offset = 0; // clt_parameters.rig.ml_disparity_sweep * (2.0 * sweep_step/(clt_parameters.rig.ml_sweep_steps - 1.0) -1.0);
if (clt_parameters.rig.ml_sweep_steps > 1) {
disparity_offset = clt_parameters.rig.ml_disparity_sweep * (2.0 * sweep_step/(clt_parameters.rig.ml_sweep_steps - 1.0) -1.0);
}
double [][] ml_data = remeasureRigML(
disparity_offset, // double disparity_offset,
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
// disparity_bimap, // double [][] src_bimap,
rig_disparity_strength[0], // double [] disparity,
rig_disparity_strength[1], // double [] strength,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_parameters.rig.ml_hwidth, // int ml_hwidth
clt_parameters.rig.ml_fatzero, // double fatzero,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
saveMlFile(
quadCLT_main.image_name+"-ML_DATA-", // String ml_title,
ml_directory, // String ml_directory,
disparity_offset, // double disp_offset,
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
corr2d, //Correlation2d corr2d, // to access "other" layer
clt_parameters.rig.ml_8bit, // boolean use8bpp,
clt_parameters.rig.ml_limit_extrim, // double limit_extrim,
clt_parameters.rig.ml_keep_aux, // boolean keep_aux,
clt_parameters.rig.ml_keep_inter, // boolean keep_inter,
clt_parameters.rig.ml_keep_hor_vert, // boolean keep_hor_vert,
clt_parameters.rig.ml_keep_tbrl, // boolean ml_keep_tbrl,
clt_parameters.rig.ml_keep_debug, // boolean keep_debug,
clt_parameters.rig.ml_fatzero, // double ml_fatzero,
clt_parameters.rig.ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
clt_parameters.rig.ml_show_ml, // boolean show,
debugLevel); // int debugLevel
}
}
public double [][] groundTruthByRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel) // throws Exception
{
int refine_inter = 2; // 3; // 3 - dx, 2 - disparity
System.out.println("enhanceByRig()");
if ((quadCLT_main == null) || (quadCLT_aux == null)) {
......@@ -1505,9 +1761,8 @@ if (debugLevel > -100) return true; // temporarily !
// final int tilesY = quadCLT_main.tp.getTilesY();
// grow around using all camera and inter-camera correlations (try to get low-textured,like our street pavement)
BiCamDSI biCamDSI = new BiCamDSI( tilesX, tilesY);
int min_added_tiles = 100;
for (int num_fill = 0; num_fill < 10; num_fill++) {
int min_added_tiles = clt_parameters.rig.lt_min_new;
for (int num_fill = 0; num_fill < clt_parameters.rig.lt_repeat; num_fill++) {
int num_new_trusted = biCamDSI.removeLTUntrusted(
disparity_bimap, // double [][] disparity_bimap,
clt_parameters.rig.lt_min_disparity, // double min_disparity, // = 0.0; // apply low texture to near objects
......@@ -1541,7 +1796,7 @@ if (debugLevel > -100) return true; // temporarily !
debugLevel-2); // final int debugLevel)// throws Exception
if (clt_parameters.show_map && (debugLevel > -2) && clt_parameters.rig.rig_mode_debug){ //OK
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){ //OK
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
......@@ -1549,26 +1804,6 @@ if (debugLevel > -100) return true; // temporarily !
true,
quadCLT_main.image_name+"DSI_LT-N"+num_fill,
ImageDtt.BIDISPARITY_TITLES);
/*
for (int layer = 0; layer < disparity_bimap.length; layer ++) if (disparity_bimap[layer] != null){
for (int nTile = 0; nTile < disparity_bimap[layer].length; nTile++) {
if (!trusted_near[nTile]) disparity_bimap[layer][nTile] = Double.NaN;
}
}
for (int layer:ImageDtt.BIDISPARITY_STRENGTHS) if (disparity_bimap[layer] != null){
for (int nTile = 0; nTile < disparity_bimap[layer].length; nTile++) {
if (!trusted_near[nTile]) disparity_bimap[layer][nTile] = 0.0;
}
}
(new showDoubleFloatArrays()).showArrays( //wrong
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"-DSI-LT-TRUSTED-N"+num_fill,
ImageDtt.BIDISPARITY_TITLES);
*/
}
}
int num_new_trusted = biCamDSI.removeLTUntrusted(
......@@ -1584,7 +1819,7 @@ if (debugLevel > -100) return true; // temporarily !
debugLevel); // int debugLevel
if (clt_parameters.show_map && (debugLevel > -2) && clt_parameters.rig.rig_mode_debug){ //OK
System.out.println("There are total "+num_new_trusted+" trusted tiles in ground truthe data");
System.out.println("There are total "+num_new_trusted+" trusted tiles in ground truth data");
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
......@@ -1593,61 +1828,71 @@ if (debugLevel > -100) return true; // temporarily !
quadCLT_main.image_name+"DSI_LT-FINAL",
ImageDtt.BIDISPARITY_TITLES);
}
if (clt_parameters.rig.lt_remove_stray) {
int num_stray_removed = biCamDSI.removeFalseMatches(
disparity_bimap, // double [][] disparity_bimap,
clt_parameters.rig.lt_trusted_strength, //double trusted_strength, // = 0.2; // strength sufficient without neighbors
clt_parameters.rig.lt_stray_rstrength, // double stray_rstrength, // = 2.0; // Relative to trusted strength - trust above that
clt_parameters.rig.lt_strength_rfloor, // double strength_rfloor, // = 0.28; // Relative to trusted strength
clt_parameters.rig.lt_stray_dist , // int stray_dist, // = 2; // How far to look (and erase) around a potentially falsely matched tile
clt_parameters.rig.lt_stray_over , // double stray_over, // = 2.0; // Stray tile should be this stronger than the strongest neighbor to be recognized
debugLevel); // int debugLevel
if (debugLevel > -2) {
System.out.println("removeFalseMatches() found ="+num_stray_removed+" false matches and erased those tiles and tiles around");
}
if (num_stray_removed > 0) {
// refine again:
num_trusted = 0;
for (int num_fill = 0; num_fill < clt_parameters.rig.lt_repeat; num_fill++) {
num_new_trusted = biCamDSI.removeLTUntrusted(
disparity_bimap, // double [][] disparity_bimap,
clt_parameters.rig.lt_min_disparity, // double min_disparity, // = 0.0; // apply low texture to near objects
clt_parameters.rig.lt_trusted_strength, // double trusted_strength, // = 0.2; // strength sufficient without neighbors
clt_parameters.rig.lt_need_friends, // double need_friends, // = 0.4; // strength sufficient with neighbors support, fraction of lt_trusted_strength
clt_parameters.rig.lt_friends_diff, // double friends_diff, // = 0.2; // pix difference to neighbors to be considered a match (TODO: use tilted)
clt_parameters.rig.lt_friends_rdiff, // double friends_rdiff, // = 0.04; // additional relative pix per pixel of disparity
clt_parameters.rig.lt_min_friends_any, // int min_friends_any, // = 2; // minimal number of even weak friends
clt_parameters.rig.lt_min_friends_trusted, // int min_friends_trusted, // = 2; // minimal number of trusted (strong or already confirmed)
clt_parameters.rig.lt_friends_dist, // int friends_dist, // = 3; // how far to look for friends
debugLevel); // int debugLevel
if ((num_new_trusted - num_trusted) < min_added_tiles) {
if (debugLevel > -2) {
System.out.println("enhanceByRig(): pass="+num_fill+", number of added tiles = "+(num_new_trusted - num_trusted)+" < " +min_added_tiles+", done adding");
break;
}
} else {
if (debugLevel > -2) {
System.out.println("enhanceByRig(): pass="+num_fill+", number of added tiles = "+(num_new_trusted - num_trusted));
}
}
num_trusted = num_new_trusted;
disparity_bimap = fillPoorTextureByInter(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
disparity_bimap, //double [][] disparity_bimap,
biCamDSI, // BiCamDSI biCamDSI,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel-2); // final int debugLevel)// throws Exception
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){ //OK
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"DSI_LT-N"+num_fill,
ImageDtt.BIDISPARITY_TITLES);
}
}
}
}
double [][] rig_disparity_strength = {disparity_bimap[ImageDtt.BI_TARGET_INDEX],disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX]};
// if (debugLevel > -100) return null; // temporarily
// re-measure with ML data output
// int ml_hwidth = 2; // move to clt_parameters
// int ml_width = 2 * clt_parameters.rig.ml_hwidth + 1;
String ml_directory= quadCLT_main.correctionsParameters.selectMlDirectory(
true, // smart,
true); //newAllowed, // save
Correlation2d corr2d = new Correlation2d(
clt_parameters.img_dtt, // ImageDttParameters imgdtt_params,
clt_parameters.transform_size, // int transform_size,
2.0, // double wndx_scale, // (wndy scale is always 1.0)
(debugLevel > -1)); // boolean debug)
for (int sweep_step = 0; sweep_step < clt_parameters.rig.ml_sweep_steps; sweep_step++){
double disparity_offset = 0; // clt_parameters.rig.ml_disparity_sweep * (2.0 * sweep_step/(clt_parameters.rig.ml_sweep_steps - 1.0) -1.0);
if (clt_parameters.rig.ml_sweep_steps > 1) {
disparity_offset = clt_parameters.rig.ml_disparity_sweep * (2.0 * sweep_step/(clt_parameters.rig.ml_sweep_steps - 1.0) -1.0);
}
double [][] ml_data = remeasureRigML(
disparity_offset, // double disparity_offset,
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
disparity_bimap, // double [][] src_bimap,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_parameters.rig.ml_hwidth, // int ml_hwidth
clt_parameters.rig.ml_fatzero, // double fatzero,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
saveMlFile(
quadCLT_main.image_name+"-ML_DATA-", // String ml_title,
ml_directory, // String ml_directory,
disparity_offset, // double disp_offset,
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
corr2d, //Correlation2d corr2d, // to access "other" layer
clt_parameters.rig.ml_8bit, // boolean use8bpp,
clt_parameters.rig.ml_limit_extrim, // double limit_extrim,
clt_parameters.rig.ml_keep_aux, // boolean keep_aux,
clt_parameters.rig.ml_keep_inter, // boolean keep_inter,
clt_parameters.rig.ml_keep_hor_vert, // boolean keep_hor_vert,
clt_parameters.rig.ml_keep_tbrl, // boolean ml_keep_tbrl,
clt_parameters.rig.ml_keep_debug, // boolean keep_debug,
clt_parameters.rig.ml_fatzero, // double ml_fatzero,
clt_parameters.rig.ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
clt_parameters.rig.ml_show_ml, // boolean show,
debugLevel); // int debugLevel
}
return null;
//clt_3d_passes
return rig_disparity_strength;
}
public double [][] fillPoorTextureByInter(
......@@ -1662,21 +1907,14 @@ if (debugLevel > -100) return true; // temporarily !
{
final int refine_inter = 2; // use inter-cam disparity for refinement
final int tilesX = quadCLT_main.tp.getTilesX();
final int tilesY = quadCLT_main.tp.getTilesY();
// grow around using all camera and inter-camera correlations (try to get low-textured,like our street pavement)
// BiCamDSI biCamDSI = new BiCamDSI( tilesX, tilesY);
// final int tilesY = quadCLT_main.tp.getTilesY();
double [] suggestedLTMeasurements = biCamDSI.suggestLTTiles(
disparity_bimap, // double [][] disparity_bimap,
null, // boolean [] trusted, // may be null if disparity is alreasdy NaN-ed
clt_parameters.rig.lt_min_disparity, // double min_disparity, // = 0.0; // apply low texture to near objects
clt_parameters.rig.lt_min_disparity, // double min_disparity, // = 0.0; // apply low texture to near objects
clt_parameters.rig.lt_trusted_strength, // double trusted_strength, // = 0.2; // strength sufficient without neighbors
clt_parameters.rig.lt_strength_rfloor, // double strength_rfloor, // = 0.28; // strength floor relative to trusted_strength
clt_parameters.rig.lt_need_friends, // double need_friends, // = 0.4; // strength sufficient with neighbors support, fraction of lt_trusted_strength
// clt_parameters.rig.lt_friends_diff, // double friends_diff, // = 0.2; // pix difference to neighbors to be considered a match (TODO: use tilted)
// clt_parameters.rig.lt_friends_rdiff, // double friends_rdiff, // = 0.04; // additional relative pix per pixel of disparity
// clt_parameters.rig.lt_min_friends_any, // int min_friends_any, // = 2; // minimal number of even weak friends
// clt_parameters.rig.lt_min_friends_trusted, // int min_friends_trusted, // = 2; // minimal number of trusted (strong or already confirmed)
// clt_parameters.rig.lt_friends_dist, // int friends_dist, // = 3; // how far to look for friends
// clt_parameters.rig.lt_replace_lone, // boolean replace_lone, // = true; // try to overwrite lone weak
clt_parameters.rig.lt_extend_dist, // int extend_dist, // = 3; // how far to extend around known tiles (probably should increase this value up to?
// dealing with neighbors variance
clt_parameters.rig.lt_wsigma, // double wsigma, // = 1.0; // influence of far neighbors diminish as a Gaussian with this sigma
......@@ -2035,6 +2273,9 @@ if (debugLevel > -100) return true; // temporarily !
String path = ml_directory+=Prefs.getFileSeparator()+imp_ml.getTitle();
FileSaver fs=new FileSaver(imp_ml);
fs.saveAsTiff(path+".tiff");
if (debugLevel > -2) {
System.out.println("Saved ML data to "+path+".tiff");
}
}
......@@ -2461,7 +2702,7 @@ if (debugLevel > -100) return true; // temporarily !
int tileY,
int nTile) {
boolean debug_this = nTile==40661; // 61924;
boolean debug_this = false; // nTile==40661; // 61924;
// check if it was measured (skip NAN)
if (Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) return false;
// check if it is infinity and change is prohibited
......@@ -2594,7 +2835,9 @@ if (debugLevel > -100) return true; // temporarily !
double disparity_offset,
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][] src_bimap,
// double [][] src_bimap,
double [] disparity,
double [] strength,
EyesisCorrectionParameters.CLTParameters clt_parameters,
int ml_hwidth,
double fatzero,
......@@ -2617,8 +2860,8 @@ if (debugLevel > -100) return true; // temporarily !
int [][] tile_op = new int[tilesY][tilesX]; // common for both main and aux
double [][] disparity_array = new double[tilesY][tilesX];
double [] disparity = src_bimap[ImageDtt.BI_TARGET_INDEX];
double [] strength = src_bimap[ImageDtt.BI_STR_ALL_INDEX];
// double [] disparity = src_bimap[ImageDtt.BI_TARGET_INDEX];
// double [] strength = src_bimap[ImageDtt.BI_STR_CROSS_INDEX];
boolean [] selection = new boolean [strength.length];
for (int nTile = 0; nTile < selection.length; nTile++) {
selection[nTile] = strength[nTile] > 0.0;
......
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