Commit 9a8fd5dc authored by Andrey Filippov's avatar Andrey Filippov

Debugging far split, before updating of usage of split FG/BG

parent b6394c1f
......@@ -2605,7 +2605,8 @@ public class Corr2dLMA {
double lma_max_area, // maximal half-area (if > 0.0)
double lma_str_scale, // convert lma-generated strength to match previous ones - scale
double lma_str_offset, // convert lma-generated strength to match previous ones - add to result
double lma_ac_offset // add to a,c coefficients for near-lines where A,C could become negative because of window
double lma_ac_offset, // add to a,c coefficients for near-lines where A,C could become negative because of window
double lma_relax_indiv_max // double relax_indiv_max
){
return lmaDisparityStrengths(
bypass_tests, //boolean bypass_tests, // keep even weak for later analysis. Normally - only in test mode
......@@ -2619,7 +2620,8 @@ public class Corr2dLMA {
lma_str_scale, // convert lma-generated strength to match previous ones - scale
lma_str_offset, // convert lma-generated strength to match previous ones - add to result
false, // boolean dbg_mode
lma_ac_offset // add to a,c coefficients for near-lines where A,C could become negative because of window
lma_ac_offset, // add to a,c coefficients for near-lines where A,C could become negative because of window
lma_relax_indiv_max // double relax_indiv_max
)[0];
}
......@@ -2636,12 +2638,19 @@ public class Corr2dLMA {
double lma_str_scale, // convert lma-generated strength to match previous ones - scale
double lma_str_offset, // convert lma-generated strength to match previous ones - add to result
boolean dbg_mode,
double lma_ac_offset // add to a,c coefficients for near-lines where A,C could become negative because of window
double lma_ac_offset, // add to a,c coefficients for near-lines where A,C could become negative because of window
double relax_indiv_max // = 2.0; // relax lma_max_rel_rms and lma_min_strength for individual maximum
){
// double relax_indiv_max = 2.0; // relax lma_max_rel_rms and lma_min_strength for individual maximum
// from the best one
double [][][] ds = new double[numMax][numTiles][dbg_mode? 14 : 3];
int reason_index = (dbg_mode && bypass_tests)? 13:-1;
double [] rms = getRmsTile();
double [] avg_g = new double [numTiles]; // best avg among all maximums
for (int tile = 0; tile < numTiles; tile++) {
double [][] maxmaxmin_amp = getMaxMaxMinAmpTile();
avg_g[tile] = 0.50*(maxmaxmin_amp[tile][0]+maxmaxmin_amp[tile][1]);
}
for (int nmax = 0; nmax < numMax; nmax++) {
double [][] maxmin_amp = getMaxMinAmpTile(nmax); // nmax
double [][] abc = getABCTile(nmax); // nmax
......@@ -2673,7 +2682,10 @@ public class Corr2dLMA {
}
double avg = 0.50*(maxmin_amp[tile][0]+maxmin_amp[tile][1]); // max_min[1] can be negative - filter it out?
double rrms = rms[tile]/avg;
if ((lma_max_rel_rms > 0.00) && (rrms > lma_max_rel_rms)) {
double rrms_g = rms[tile]/avg_g[tile];
if ((lma_max_rel_rms > 0.0) &&
( (rrms > (lma_max_rel_rms * relax_indiv_max)) || // compare for this maximum
(rrms_g > lma_max_rel_rms) )) { // compare for the best maximum
if (bypass_tests) {
if ((reason_index > 0) && (ds[nmax][tile][reason_index] == 0)) ds[nmax][tile][reason_index] = 1;
} else {
......@@ -2713,8 +2725,10 @@ public class Corr2dLMA {
}
}
double strength = Math.sqrt(avg/rrms);
// double disparity = -all_pars[DISP_INDEX + offs];
if ((strength < lma_min_strength) || Double.isNaN(disparity)) {
double strength_g = Math.sqrt(avg_g[tile]/rrms_g);
if ( (strength < (lma_min_strength/relax_indiv_max)) || // compare for this maximum
(strength_g < lma_min_strength) || // compare for the strongest maximum
Double.isNaN(disparity)) {
if (bypass_tests) {
if ((reason_index > 0) && (ds[nmax][tile][reason_index] == 0)) ds[nmax][tile][reason_index] = 6;
} else {
......@@ -2974,6 +2988,25 @@ public class Corr2dLMA {
}
return maxmins;
}
/**
* Find maximal values for each element of maxmins among all maximums (currently 1 or 2)
* @return
*/
public double [][] getMaxMaxMinAmpTile(){
double [][] maxmaxmins = getMaxMinAmpTile(0);
for (int nmax = 1; nmax < numMax; nmax++) { // compare with all other maximums
double [][] maxmins = getMaxMinAmpTile(nmax);
for (int tile = 0; tile < numTiles; tile++) {
maxmaxmins[tile][0] = Math.max(maxmaxmins[tile][0], maxmins[tile][0]);
maxmaxmins[tile][1] = Math.max(maxmaxmins[tile][1], maxmins[tile][1]);
}
}
return maxmaxmins;
}
/**
* Get maximal/minimal (per pair) amplitudes and values for each tile
* @return array [tile][{vmax, vmin}]
......
......@@ -3838,7 +3838,8 @@ public class Correlation2d {
imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max// double lma_relax_indiv_max // double relax_indiv_max
);
if (debug_level > 0) lma.printStats(ds,clust_width);
......@@ -3943,7 +3944,8 @@ public class Correlation2d {
imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max// double lma_relax_indiv_max // double relax_indiv_max
);
if (debug_level > 0) { // -2) {
lma.printStats(ds,clust_width);
......@@ -4452,8 +4454,8 @@ public class Correlation2d {
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max// double lma_relax_indiv_max // double relax_indiv_max
);
if (dispStr[0][1] <= 0) {
lmaSuccess = false;
......@@ -4985,12 +4987,8 @@ public class Correlation2d {
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
false, // boolean dbg_mode
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max// double lma_relax_indiv_max // double relax_indiv_max
);
for (int nmax = 00; nmax < dispStrs.length; nmax++) if (dispStrs[nmax][0][1] <= 0) {
lmaSuccess = false;
......
......@@ -2110,8 +2110,9 @@ public class ImageDtt extends ImageDttCPU {
if (maxes.length == 1) { // normally should be just one. If 2 - OK, use old splitting (abnormal)
maxes = split_far_max(
maxes[0], // double [] max,
far_fgbg[nTile][0], // double diff,
far_fgbg[nTile][1], // double kfg,
far_fgbg[nTile][0], // double fg_targ,
far_fgbg[nTile][1], // double bg_targ,
far_fgbg[nTile][2], // double kfg,
imgdtt_params.mcorr_dual_fract); // 0.1); // double min_k);
if (maxes == null) {
continue;
......@@ -2202,7 +2203,8 @@ public class ImageDtt extends ImageDttCPU {
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
dbg_dispStrs, // false // boolean dbg_mode
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max// double lma_relax_indiv_max // double relax_indiv_max
);
disp_str_lma = new double [dispStrs.length][]; // order matching input ones
for (int nmax = 0;nmax < dispStrs.length; nmax++) {
......@@ -2245,6 +2247,14 @@ public class ImageDtt extends ImageDttCPU {
// set BG to DISPARITY_INDEX_CM/DISPARITY_INDEX_CM+1
disparity_map[DISPARITY_INDEX_CM ][nTile] = disp_str_lma[1-indx][0]; // disparity LMA
disparity_map[DISPARITY_INDEX_CM + 1][nTile] = disp_str_lma[1-indx][2]; // strength LMA
if (debugTile1) { // FIXME: remove debugTile1!
System.out.println("clt_process_tl_correlations() disp_str_lma:");
for (int nmax = 0; nmax < disp_str_lma.length; nmax++) {
System.out.println(String.format("disp_str_lma[%d][0]=%f, disp_str_lma[%d][1]=%f disp_str_lma[%d][2]=%f",
nmax, disp_str_lma[nmax][0], nmax, disp_str_lma[nmax][1], nmax, disp_str_lma[nmax][2]));
}
}
}
} else {
disparity_map[DISPARITY_INDEX_CM ][nTile] = disp_str_sel[0][0]; // disparity non-LMA
......@@ -2342,7 +2352,8 @@ public class ImageDtt extends ImageDttCPU {
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max// double lma_relax_indiv_max // double relax_indiv_max
);
if (ds != null) { // always true
// if (disparity_map!=null) {
......@@ -2499,9 +2510,59 @@ public class ImageDtt extends ImageDttCPU {
return null; // too large difference between strong and weak;
}
return maxes;
}
/**
* Providing initial 2-max for LMA using provided hints
* There can be 3 cases:
* 1 - initial run where target disparity is a combined (unresolved) maximum (trust only difference and kfg)
* 2 - Refining FG - target_disparity is FG (found after initial run), so fg_targ==0,
* bg_target defined from the first run
* 3 - Refining BG - target_disparity is BG (found in initial run, nut during refining FG), bg_targ=0
* input max[] is accurate only when centered, can not be trusted when target_disparity was offset (either FG or BG)
*
* @param max disparity+strength of a single unresolved maximum using center-of-mass (or poly?) method
* @param fg_targ FG disparity hint relative to target disparity
* @param bg_targ BG disparity hint relative to target disparity
* @param kfg strength fraction of the FG maximum (0.5 - equal FG/BG strength)
* @param min_k do not try to process camel case if one maximum is much weaker than the other
* @return a pair of d/s pairs, starting with a strongest one. Null on failure.
*/
public static double [][] split_far_max(
double [] max,
double fg_targ,
double bg_targ,
double kfg,
double min_k){
if (((kfg < min_k) || ((1.0 - kfg) < min_k))) {
return null; // one of the maximums is too weak with respect to the other
}
double [][] maxes = new double [2][2];
if (kfg <= 0) {
return null; //diff and kfg can not be 0.0 simultaneously (or use this case for something?)
}
if ((fg_targ != 0.0) && (bg_targ != 0.0)) { // initial run that used average
double diff = fg_targ - bg_targ;
maxes[0][0] = max[0] + diff * (1.0 - kfg); // disparity(FG)
maxes[1][0] = max[0] - diff * kfg; // disparity(BG)
} else { // refinement run when target_disparity was either FG or BG, so either fg_targ or bg_targ is 0
maxes[0][0] = fg_targ; // disparity(FG)
maxes[1][0] = bg_targ; // disparity(BG)
}
maxes[0][1] = max[1] * kfg; // strength(FG)
maxes[1][1] = max[1] * (1.0 - kfg); // strength(BG)
if (maxes[1][1] > maxes[0][1]) {
double [] tmp = maxes[0];
maxes[0] = maxes[1];
maxes[1]= tmp;
}
if ((maxes[0][1] / maxes[1][1]) > (1.0 - min_k)/min_k) {
return null; // too large difference between strong and weak;
}
return maxes;
}
public void clt_process_tl_correlations_GPU_DBG( // convert to pixel domain and process correlations already prepared in fcorr_td and/or fcorr_combo_td
......@@ -3877,7 +3938,8 @@ public class ImageDtt extends ImageDttCPU {
imgdtt_params.lmas_max_area, // double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max// double lma_relax_indiv_max // double relax_indiv_max
)[0];
if (tile_lma_debug_level > 0) {
double [][] ds_dbg = {disp_str};
......@@ -4176,7 +4238,8 @@ public class ImageDtt extends ImageDttCPU {
imgdtt_params.lmas_max_area, // double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max// double lma_relax_indiv_max // double relax_indiv_max
)[0];
if (tile_lma_debug_level > 0) {
double [][] ds_dbg = {disp_str};
......
......@@ -2212,7 +2212,8 @@ public class ImageDttCPU {
imgdtt_params.lmas_max_area, // double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max// double lma_relax_indiv_max // double relax_indiv_max
)[0];
if ((disp_str[cTile]!=null) && Double.isNaN(disp_str[cTile][1])) {
System.out.println();
......@@ -2397,7 +2398,8 @@ public class ImageDttCPU {
imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
1.0, // imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
0.0, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset); // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max);// double lma_relax_indiv_max // double relax_indiv_max
// double [][] extra_stats = lma2.getTileStats();
if (debugCluster) {
......@@ -3134,8 +3136,8 @@ public class ImageDttCPU {
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
);
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max);// double lma_relax_indiv_max // double relax_indiv_max
if (ds != null) { // always true
disparity_map[DISPARITY_INDEX_POLY][tIndex] = ds[0][0];
disparity_map[DISPARITY_INDEX_POLY+1][tIndex] = ds[0][1];
......@@ -4232,8 +4234,8 @@ public class ImageDttCPU {
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
);
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max);// double lma_relax_indiv_max // double relax_indiv_max
if (ds != null) { // always true
disp_lma[nTile] = ds[0][0];
str_lma[nTile] = ds[0][1];
......@@ -5150,8 +5152,8 @@ public class ImageDttCPU {
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
);
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max);// double lma_relax_indiv_max // double relax_indiv_max
if (ds != null) { // always true
disparity_map[DISPARITY_INDEX_POLY][nTileC] = ds[0][0];
disparity_map[DISPARITY_INDEX_POLY+1][nTileC] = ds[0][1];
......@@ -15540,8 +15542,8 @@ public class ImageDttCPU {
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
);
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max);// double lma_relax_indiv_max // double relax_indiv_max
lma2.printStats(ds,1);
}
}
......@@ -16550,8 +16552,8 @@ public class ImageDttCPU {
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset, // convert lma-generated strength to match previous ones - add to result
imgdtt_params.lma_ac_offset // Add to A, C coefficients for near-lines where A,C could become negative because of window
);
imgdtt_params.lma_ac_offset, // Add to A, C coefficients for near-lines where A,C could become negative because of window
imgdtt_params.lma_relax_indiv_max);// double lma_relax_indiv_max // double relax_indiv_max
if (ds != null) { // always true
if (disparity_map!=null) {
disparity_map[DISPARITY_INDEX_POLY ][nTile] = ds[0][0];
......
......@@ -268,8 +268,8 @@ public class ImageDttParameters {
public double lma_max_rel_rms = 0.25; // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
public double lma_min_strength = 1.0; // minimal composite strength (sqrt(average amp squared over absolute RMS)
public double lma_relax_indiv_max= 2.0; // relax lma_max_rel_rms and lma_min_strength for individual maximum
public double lma_ac_offset = 0.015; // add to a,c coefficients for near-lines where A,C could become negative because of window
public double lma_min_ac = 0.05; // minimal of a and C coefficients maximum (measures sharpest point/line)
public double lma_min_min_ac = 0.015; // minimal of a and C coefficients minimum (measures sharpest point)
public double lma_max_area = 30.0; //45.0; // maximal half-area (if > 0.0)
......@@ -828,6 +828,8 @@ public class ImageDttParameters {
"Discard tile if ratio of RMS to average of min and max amplitude exceeds this value");
gd.addNumericField("Minimal composite strength", this.lma_min_strength, 6, 8, "",
"Discard tile if composite strength (average amplitude over SQRT of RMS) is below");
gd.addNumericField("Relax individual maximum requirements (for camel case)", this.lma_relax_indiv_max, 6, 8, "",
"Relax lma_max_rel_rms and lma_min_strength for individual maximum compared to that of the strongest one.");
gd.addNumericField("Offset A,C coefficients", this.lma_ac_offset, 6, 8, "",
"Add to A, C coefficients for near-lines where A,C could become negative because of window ");
......@@ -1107,6 +1109,7 @@ public class ImageDttParameters {
this.lma_multi_cons = gd.getNextBoolean();
this.lma_max_rel_rms = gd.getNextNumber();
this.lma_min_strength = gd.getNextNumber();
this.lma_relax_indiv_max = gd.getNextNumber();
this.lma_ac_offset = gd.getNextNumber();
this.lma_min_ac = gd.getNextNumber();
......@@ -1352,6 +1355,7 @@ public class ImageDttParameters {
properties.setProperty(prefix+"lma_multi_cons", this.lma_multi_cons +"");
properties.setProperty(prefix+"lma_max_rel_rms", this.lma_max_rel_rms +"");
properties.setProperty(prefix+"lma_min_strength", this.lma_min_strength +"");
properties.setProperty(prefix+"lma_relax_indiv_max", this.lma_relax_indiv_max +"");
properties.setProperty(prefix+"lma_ac_offset", this.lma_ac_offset +"");
......@@ -1619,6 +1623,7 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"lma_multi_cons")!=null) this.lma_multi_cons=Boolean.parseBoolean(properties.getProperty(prefix+"lma_multi_cons"));
if (properties.getProperty(prefix+"lma_max_rel_rms")!=null) this.lma_max_rel_rms=Double.parseDouble(properties.getProperty(prefix+"lma_max_rel_rms"));
if (properties.getProperty(prefix+"lma_min_strength")!=null) this.lma_min_strength=Double.parseDouble(properties.getProperty(prefix+"lma_min_strength"));
if (properties.getProperty(prefix+"lma_relax_indiv_max")!=null) this.lma_relax_indiv_max=Double.parseDouble(properties.getProperty(prefix+"lma_relax_indiv_max"));
if (properties.getProperty(prefix+"lma_ac_offset")!=null) this.lma_ac_offset=Double.parseDouble(properties.getProperty(prefix+"lma_ac_offset"));
if (properties.getProperty(prefix+"lma_min_ac")!=null) this.lma_min_ac=Double.parseDouble(properties.getProperty(prefix+"lma_min_ac"));
......@@ -1860,6 +1865,7 @@ public class ImageDttParameters {
idp.lma_multi_cons = this.lma_multi_cons;
idp.lma_max_rel_rms= this.lma_max_rel_rms;
idp.lma_min_strength= this.lma_min_strength;
idp.lma_relax_indiv_max= this.lma_relax_indiv_max;
idp.lma_ac_offset= this.lma_ac_offset;
idp.lma_min_ac= this.lma_min_ac;
......
......@@ -8227,7 +8227,7 @@ public class OpticalFlow {
far_bg_ds, // final double [][] bg_ds,
far_split, // null, // final boolean [] selection, // may be null, does not apply to neighbors
tilesX, // final int tilesX,
ref_scene.getImageName()+"-FGBG"); // final String dbg_title);
ref_scene.getImageName()+"-FGBG-"+split_pass); // final String dbg_title);
//far_split
selection = sel_split; // for correlateInterscene()
if (split_src == 0) {
......@@ -8275,6 +8275,12 @@ public class OpticalFlow {
double [] map_far_fg_strength = disparity_map[ImageDtt.DISPARITY_INDEX_POLY+1];
double [] map_far_bg_disparity = disparity_map[ImageDtt.DISPARITY_INDEX_CM];
double [] map_far_bg_strength = disparity_map[ImageDtt.DISPARITY_INDEX_CM+1];
double [][] far_fg_ds_merge = new double[2][];
double [][] far_bg_ds_merge = new double[2][];
far_fg_ds_merge[0] = avg_ds[0].clone();
far_bg_ds_merge[0] = avg_ds[0].clone();
far_fg_ds_merge[1] = avg_ds[1].clone();
far_bg_ds_merge[1] = avg_ds[1].clone();
if (split_pass >= 0) {
if (far_split == null) {
......@@ -8282,12 +8288,12 @@ public class OpticalFlow {
}
// Arrays.fill(far_split, false);
// boolean [] far_split = new boolean [nTiles];
double [][] far_fg_ds_merge = new double[2][];
double [][] far_bg_ds_merge = new double[2][];
far_fg_ds_merge[0] = avg_ds[0].clone();
far_bg_ds_merge[0] = avg_ds[0].clone();
far_fg_ds_merge[1] = avg_ds[1].clone();
far_bg_ds_merge[1] = avg_ds[1].clone();
// double [][] far_fg_ds_merge = new double[2][];
// double [][] far_bg_ds_merge = new double[2][];
// far_fg_ds_merge[0] = avg_ds[0].clone();
// far_bg_ds_merge[0] = avg_ds[0].clone();
// far_fg_ds_merge[1] = avg_ds[1].clone();
// far_bg_ds_merge[1] = avg_ds[1].clone();
// single-threaded
if (split_src == 0) {
for (int tile = 0; tile < nTiles; tile++) {
......@@ -8345,47 +8351,26 @@ public class OpticalFlow {
for (int tile = 0; tile < nTiles; tile++) {
if (far_fgbg[tile] != null) {
double diff = far_fgbg[tile][0];
double kfg = far_fgbg[tile][1];
/*
if (diff == 0) { // target is FG
dbg_img[ 3][tile] = 0.0 + fg_ds[0][tile]; // disparity(FG)
dbg_img[ 4][tile] = (avg_ds[0][tile] - fg_ds[0][tile]) / kfg + fg_ds[0][tile]; // disparity(BG)
dbg_img[10][tile] = avg_ds[1][tile] * kfg; // strength(FG)
dbg_img[11][tile] = avg_ds[1][tile] * (1.0 - kfg); // strength(BG)
} else if (kfg == 0) { // target is BG
dbg_img[ 3][tile] = diff + bg_ds[0][tile]; // disparity(FG)
dbg_img[ 4][tile] = 0.0 + bg_ds[0][tile]; // disparity(BG)
dbg_img[10][tile] = avg_ds[1][tile] * ((avg_ds[0][tile] - bg_ds[0][tile]) / diff); // strength(FG)
dbg_img[11][tile] = avg_ds[1][tile] * ((diff - (avg_ds[0][tile] - bg_ds[0][tile])) / diff); // strength(BG)
} else { // target is unresolved merged maximums
*/
predicted_fg_ds[0][tile] = 0 + diff * (1.0 - kfg) + avg_ds[0][tile]; // disparity(FG)
predicted_bg_ds[0][tile] = 0 - diff * kfg + avg_ds[0][tile]; // disparity(BG)
predicted_fg_ds[1][tile] = avg_ds[1][tile] * kfg; // strength(FG)
predicted_bg_ds[1][tile] = avg_ds[1][tile] * (1.0 - kfg); // strength(BG)
double fg_targ = far_fgbg[tile][0];
double bg_targ = far_fgbg[tile][1];
double kfg = far_fgbg[tile][2];
predicted_fg_ds[0][tile] = fg_targ + target_disparity[tile]; // disparity(FG)
predicted_bg_ds[0][tile] = bg_targ + target_disparity[tile]; // disparity(BG)
predicted_fg_ds[1][tile] = avg_ds[1][tile] * kfg; // strength(FG)
predicted_bg_ds[1][tile] = avg_ds[1][tile] * (1.0 - kfg); // strength(BG)
if (!Double.isNaN(far_fg_ds[0][tile]) && !Double.isNaN(far_fg_ds[0][tile])) {
fg_predicted_err[0][tile] = predicted_fg_ds[0][tile] - far_fg_ds[0][tile];
bg_predicted_err[0][tile] = predicted_bg_ds[0][tile] - far_bg_ds[0][tile];
fg_predicted_err[1][tile] = predicted_fg_ds[1][tile] - far_fg_ds[1][tile];
bg_predicted_err[1][tile] = predicted_bg_ds[1][tile] - far_bg_ds[1][tile];
fg_predicted_err[0][tile] = predicted_fg_ds[0][tile] - far_fg_ds[0][tile];
bg_predicted_err[0][tile] = predicted_bg_ds[0][tile] - far_bg_ds[0][tile];
fg_predicted_err[1][tile] = predicted_fg_ds[1][tile] - far_fg_ds[1][tile];
bg_predicted_err[1][tile] = predicted_bg_ds[1][tile] - far_bg_ds[1][tile];
}
predicted_fg_ds_merge[0][tile] = 0 + diff * (1.0 - kfg) + avg_ds[0][tile]; // disparity(FG)
predicted_bg_ds_merge[0][tile] = 0 - diff * kfg + avg_ds[0][tile]; // disparity(BG)
predicted_fg_ds_merge[0][tile] = predicted_fg_ds[0][tile]; // disparity(FG)
predicted_bg_ds_merge[0][tile] = predicted_bg_ds[0][tile]; // disparity(BG)
predicted_fg_ds_merge[1][tile] = avg_ds[1][tile] * kfg; // strength(FG)
predicted_bg_ds_merge[1][tile] = avg_ds[1][tile] * (1.0 - kfg); // strength(BG)
/*
}
*/
}
}
String [] dbg_far_spit_titles={
"avg_disp", // 0
"fg_disp", // 1
......@@ -8493,7 +8478,6 @@ public class OpticalFlow {
}
}
disp_err[nTile] = combo_dsn_change[COMBO_DSN_INDX_CHANGE][nTile];
if (Math.abs(combo_dsn_change[COMBO_DSN_INDX_CHANGE][nTile]) >= min_disp_change) {
target_disparity[nTile] = combo_dsn_change[COMBO_DSN_INDX_DISP][nTile] ;
selection[nTile] = true;
......@@ -8501,11 +8485,9 @@ public class OpticalFlow {
} else {
num_tomeas+=0;
}
} else { // originally defined, but not re-measured
num_tomeas+=0;
}
}
}
if (dbg_corr_scale != null) {
......@@ -8561,7 +8543,8 @@ public class OpticalFlow {
if (far_fg_ds[0] != null) {
for (int nTile =0; nTile < combo_dsn_change[0].length; nTile++) {
if (!Double.isNaN(far_fg_ds[0][nTile])) {
combo_dsn_final[COMBO_DSN_INDX_DISP_FG][nTile] = far_fg_ds[0][nTile];
combo_dsn_final[COMBO_DSN_INDX_DISP_FG][nTile] = far_fg_ds[0][nTile];
combo_dsn_final[COMBO_DSN_INDX_LMA][nTile] = far_fg_ds[0][nTile];
if (mod_cumul_disp) {
combo_dsn_final[COMBO_DSN_INDX_DISP][nTile] = far_fg_ds[0][nTile];
}
......@@ -8569,6 +8552,7 @@ public class OpticalFlow {
}
if (!Double.isNaN(far_bg_ds[0][nTile])) {
combo_dsn_final[COMBO_DSN_INDX_DISP_BG_ALL][nTile] = far_bg_ds[0][nTile];
combo_dsn_final[COMBO_DSN_INDX_LMA_BG][nTile] = far_bg_ds[0][nTile];
if (mod_cumul_bg_disp) {
combo_dsn_final[COMBO_DSN_INDX_DISP_BG][nTile] = far_bg_ds[0][nTile];
}
......@@ -8841,8 +8825,6 @@ public class OpticalFlow {
if (best_dir >= 0) { // found at least one good direction
// for BG use weighted average among near tiles (of 3x3) from the side which is lower
// find BG weighted-average strength
/// double avg_strength = sw_side[best_dir] / skw; // weighted-average strength of the BG
// double avg_disparity = swd_side[best_dir] / sw_side[best_dir];
double disp_fg = avg_center + (avg_center - avg_disparity) * avg_strength / center_str;
disp_diff = disp_fg - avg_disparity;
kfg = (avg_center - avg_disparity) / disp_diff;
......@@ -8852,7 +8834,6 @@ public class OpticalFlow {
disp_fg = (avg_center - avg_disparity)/kfg + avg_disparity;
disp_diff = disp_fg - avg_disparity;
}
far_fgbg[tile] = new double[] {disp_diff, kfg};
sel_out[tile] = true;
if (dbg_thin_fg != null) {
dbg_thin_fg[tile] = true;
......@@ -8872,7 +8853,6 @@ public class OpticalFlow {
n_max = neib_ds[dir][0];
}
}
double davg = swd / sw;
double adiff = Math.abs(center_disp - davg);
// see if it is concave/convex enough
......@@ -8894,7 +8874,11 @@ public class OpticalFlow {
continue; // not a thin FG and not concave/convex enough
}
}
far_fgbg[tile] = new double[] {disp_diff, kfg};
// assuming avg_ds[0] will be used as target disparity
far_fgbg[tile] = new double[] {
disp_diff * (1.0 - kfg), // FD disparity - target disparity
-disp_diff * kfg, // BG disparity - target disparity
kfg};
sel_out[tile] = true;
}
}
......@@ -8904,15 +8888,18 @@ public class OpticalFlow {
}
ImageDtt.startAndJoin(threads);
} else if (split_src == 1) { // target_disparity is FG, selection[] is defined, avg_ds, fg_ds, bg_ds defined
// assuming fg_ds[0] will be used as target disparity
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int tile = ai.getAndIncrement(); tile < nTiles; tile = ai.getAndIncrement()) {
if (selection[tile] && !Double.isNaN(fg_ds[0][tile]) && !Double.isNaN(bg_ds[0][tile])) { // selection should be defined as well as avg_ds and fg_ds
double disp_diff = fg_ds[0][tile] - bg_ds[0][tile];
double kfg = (avg_ds[0][tile] - bg_ds[0][tile])/disp_diff;
double kfg = fg_ds[1][tile]/ (fg_ds[1][tile] + bg_ds[1][tile]);
if ((kfg >= fsplit_kfg_min) && (kfg <= (1.0 - fsplit_kfg_min))) {
far_fgbg[tile] = new double[] {0.0, kfg};
far_fgbg[tile] = new double[] {
0.0, // FD disparity - target disparity
bg_ds[0][tile] - fg_ds[0][tile], // BG disparity - target disparity
kfg};
sel_out[tile] = true;
}
}
......@@ -8922,15 +8909,18 @@ public class OpticalFlow {
}
ImageDtt.startAndJoin(threads);
} else if (split_src == 2) { // target_disparity is BG, selection[] is defined, avg_ds, fg_ds, bg_ds defined
// assuming fg_ds[0] will be used as target disparity
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int tile = ai.getAndIncrement(); tile < nTiles; tile = ai.getAndIncrement()) {
if (selection[tile] && !Double.isNaN(fg_ds[0][tile]) && !Double.isNaN(bg_ds[0][tile])) { // selection should be defined as well as avg_ds and fg_ds
double disp_diff = fg_ds[0][tile] - bg_ds[0][tile];
double kfg = (avg_ds[0][tile] - bg_ds[0][tile])/disp_diff;
double kfg = fg_ds[1][tile]/ (fg_ds[1][tile] + bg_ds[1][tile]);
if ((kfg >= fsplit_kfg_min) && (kfg <= (1.0 - fsplit_kfg_min))) {
far_fgbg[tile] = new double[] {disp_diff, 0.0};
far_fgbg[tile] = new double[] {
fg_ds[0][tile] - bg_ds[0][tile], // FD disparity - target disparity
0.0, // BG disparity - target disparity
kfg};
sel_out[tile] = true;
}
}
......@@ -8948,14 +8938,15 @@ public class OpticalFlow {
"bg_disp", // 2
"fg_pred", // 3
"bg_pred", // 4
"fgbg_diff", // 5
"fgbg_kfg", // 6
"avg_str", // 7
"fg_str", // 8
"bg_str", // 9
"fg_pred_str",//10
"bg_pred_str",//11
"sel_thin"}; //12
"fg-targ", // 5
"bg-targ", // 6
"kfg", // 7
"avg_str", // 8
"fg_str", // 9
"bg_str", //10
"fg_pred_str",//11
"bg_pred_str",//12
"sel_thin"}; //13
double [][] dbg_img = new double [dbg_titles.length][nTiles];
for (int i = 0; i < dbg_img.length; i++) {
Arrays.fill(dbg_img[i], Double.NaN);
......@@ -8964,37 +8955,39 @@ public class OpticalFlow {
if (fg_ds != null) dbg_img[1] = fg_ds[0];
if (bg_ds != null) dbg_img[2] = bg_ds[0];
dbg_img[7] = avg_ds[1];
if (fg_ds != null) dbg_img[8] = fg_ds[1];
if (bg_ds != null) dbg_img[9] = bg_ds[1];
dbg_img[8] = avg_ds[1];
if (fg_ds != null) dbg_img[9] = fg_ds[1];
if (bg_ds != null) dbg_img[10] = bg_ds[1];
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int tile = ai.getAndIncrement(); tile < nTiles; tile = ai.getAndIncrement()) {
dbg_img[12][tile] = (sel_out[tile] ? 0.5 : 0.0) +
dbg_img[13][tile] = (sel_out[tile] ? 0.5 : 0.0) +
(dbg_thin_fg[tile] ? 0.6 : 0.0);
if (far_fgbg[tile] != null) {
double diff = far_fgbg[tile][0];
double kfg = far_fgbg[tile][1];
dbg_img[5][tile] = diff;
dbg_img[6][tile] = kfg;
if (diff == 0) { // target is FG
dbg_img[ 3][tile] = 0.0 + fg_ds[0][tile]; // disparity(FG)
dbg_img[ 4][tile] = (avg_ds[0][tile] - fg_ds[0][tile]) / kfg + fg_ds[0][tile]; // disparity(BG)
dbg_img[10][tile] = avg_ds[1][tile] * kfg; // strength(FG)
dbg_img[11][tile] = avg_ds[1][tile] * (1.0 - kfg); // strength(BG)
} else if (kfg == 0) { // target is BG
dbg_img[ 3][tile] = diff + bg_ds[0][tile]; // disparity(FG)
dbg_img[ 4][tile] = 0.0 + bg_ds[0][tile]; // disparity(BG)
dbg_img[10][tile] = avg_ds[1][tile] * ((avg_ds[0][tile] - bg_ds[0][tile]) / diff); // strength(FG)
dbg_img[11][tile] = avg_ds[1][tile] * ((diff - (avg_ds[0][tile] - bg_ds[0][tile])) / diff); // strength(BG)
double fg_targ = far_fgbg[tile][0];
double bg_targ = far_fgbg[tile][1];
double kfg = far_fgbg[tile][2];
dbg_img[5][tile] = fg_targ;
dbg_img[6][tile] = bg_targ;
dbg_img[7][tile] = kfg;
if (fg_targ == 0) { // target is FG
dbg_img[ 3][tile] = 0.0 + fg_ds[0][tile]; // disparity(FG)
dbg_img[ 4][tile] = bg_targ + fg_ds[0][tile]; // disparity(BG)
dbg_img[11][tile] = avg_ds[1][tile] * kfg; // strength(FG)
dbg_img[12][tile] = avg_ds[1][tile] * (1.0 - kfg); // strength(BG)
} else if (bg_targ == 0) { // target is BG
dbg_img[ 3][tile] = fg_targ + bg_ds[0][tile]; // disparity(FG)
dbg_img[ 4][tile] = 0.0 + bg_ds[0][tile]; // disparity(BG)
dbg_img[11][tile] = avg_ds[1][tile] * kfg; // strength(FG)
dbg_img[12][tile] = avg_ds[1][tile] * (1.0 - kfg); // strength(BG)
} else { // target is unresolved merged maximums
dbg_img[ 3][tile] = 0 + diff * (1.0 - kfg) + avg_ds[0][tile]; // disparity(FG)
dbg_img[ 4][tile] = 0 - diff * kfg + avg_ds[0][tile]; // disparity(BG)
dbg_img[10][tile] = avg_ds[1][tile] * kfg; // strength(FG)
dbg_img[11][tile] = avg_ds[1][tile] * (1.0 - kfg); // strength(BG)
dbg_img[ 3][tile] = fg_targ + avg_ds[0][tile]; // disparity(FG)
dbg_img[ 4][tile] = bg_targ + avg_ds[0][tile]; // disparity(BG)
dbg_img[11][tile] = avg_ds[1][tile] * kfg; // strength(FG)
dbg_img[12][tile] = avg_ds[1][tile] * (1.0 - kfg); // strength(BG)
}
}
}
......@@ -9010,7 +9003,6 @@ public class OpticalFlow {
true,
dbg_title,
dbg_titles); // dsrbg_titles);
}
return sel_out;
}
......
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