Commit ad220366 authored by Andrey Filippov's avatar Andrey Filippov

debugging tiles with dual-maximums in correlation (FG/BG)

parent 8d033226
......@@ -254,6 +254,9 @@ public class BiQuadParameters {
public int mll_max_refines_pre = 5;
public double mll_min_disp_change_lma = 0.003; // stop re-measure when difference is below, LMA, 120 pairs
public int mll_max_refines_lma = 4;
public int mll_max_refines_bg = 5;
public boolean mll_generate_scene_outlines = false; // Uses 2 GB - change format, add dimensions (separate color for ref)
// Exporting ML files
......@@ -689,12 +692,14 @@ public class BiQuadParameters {
gd.addMessage("Calculating GT Disparity");
gd.addNumericField("Min change of disparity (preliminary, 40 pairs/no LMA)", this.mll_min_disp_change_pre, 3,6,"pix",
"Refine tile until disparity change falls below");
gd.addNumericField("Number of disparity refine passes (preliminary, 40 pairs/no LMA)", this.mll_max_refines_pre, 0,3,"",
gd.addNumericField("Number of FG disparity refine passes (preliminary, 40 pairs/no LMA)", this.mll_max_refines_pre, 0,3,"",
"Abandon disparity refinement for tiles where disparity does not converge after this number of passes");
gd.addNumericField("Min change of disparity (final, 120 pairs with LMA)", this.mll_min_disp_change_lma, 3,6,"pix",
"Refine tile until disparity change falls below");
gd.addNumericField("Number of disparity refine passes (final, 120 pairs with LMA)", this.mll_max_refines_lma, 0,3,"",
gd.addNumericField("Number of FG disparity refine passes (final, 120 pairs with LMA)", this.mll_max_refines_lma, 0,3,"",
"Abandon disparity refinement for tiles where disparity does not converge after this number of passes");
gd.addNumericField("Number of BG disparity refine passes (final, 120 pairs with LMA)", this.mll_max_refines_bg, 0,3,"",
"Measure BG disparity for the tiles that have dual correlation maximums");
gd.addCheckbox ("Generate scene outlines", this.mll_generate_scene_outlines,
"Generate and save scene outlines for scene series (need to change format, it is 2GB with uncompressed Tiff)");
......@@ -997,6 +1002,7 @@ public class BiQuadParameters {
this.mll_max_refines_pre= (int) gd.getNextNumber();
this.mll_min_disp_change_lma= gd.getNextNumber();
this.mll_max_refines_lma= (int) gd.getNextNumber();
this.mll_max_refines_bg= (int) gd.getNextNumber();
this.mll_generate_scene_outlines= gd.getNextBoolean();
this.mll_add_combo= gd.getNextBoolean();
......@@ -1242,11 +1248,12 @@ public class BiQuadParameters {
properties.setProperty(prefix+"oc_min_disparity", this.oc_min_disparity+"");
properties.setProperty(prefix+"oc_min_strength", this.oc_min_strength+"");
properties.setProperty(prefix+"mll_min_disp_change_pre", this.mll_min_disp_change_pre+"");
properties.setProperty(prefix+"mll_max_refines_pre", this.mll_max_refines_pre+"");
properties.setProperty(prefix+"mll_min_disp_change_lma", this.mll_min_disp_change_lma+"");
properties.setProperty(prefix+"mll_max_refines_lma", this.mll_max_refines_lma+"");
properties.setProperty(prefix+"mll_generate_scene_outlines", this.mll_generate_scene_outlines+"");
properties.setProperty(prefix+"mll_min_disp_change_pre", this.mll_min_disp_change_pre+"");
properties.setProperty(prefix+"mll_max_refines_pre", this.mll_max_refines_pre+"");
properties.setProperty(prefix+"mll_min_disp_change_lma", this.mll_min_disp_change_lma+"");
properties.setProperty(prefix+"mll_max_refines_lma", this.mll_max_refines_lma+"");
properties.setProperty(prefix+"mll_max_refines_bg", this.mll_max_refines_bg+"");
properties.setProperty(prefix+"mll_generate_scene_outlines",this.mll_generate_scene_outlines+"");
properties.setProperty(prefix+"mll_add_combo", this.mll_add_combo+"");
properties.setProperty(prefix+"mll_save_accum", this.mll_save_accum+"");
......@@ -1492,6 +1499,7 @@ public class BiQuadParameters {
if (properties.getProperty(prefix+"mll_max_refines_pre")!=null) this.mll_max_refines_pre=Integer.parseInt(properties.getProperty(prefix+"mll_max_refines_pre"));
if (properties.getProperty(prefix+"mll_min_disp_change_lma")!=null) this.mll_min_disp_change_lma=Double.parseDouble(properties.getProperty(prefix+"mll_min_disp_change_lma"));
if (properties.getProperty(prefix+"mll_max_refines_lma")!=null) this.mll_max_refines_lma=Integer.parseInt(properties.getProperty(prefix+"mll_max_refines_lma"));
if (properties.getProperty(prefix+"mll_max_refines_bg")!=null) this.mll_max_refines_bg=Integer.parseInt(properties.getProperty(prefix+"mll_max_refines_bg"));
if (properties.getProperty(prefix+"mll_generate_scene_outlines")!=null) this.mll_generate_scene_outlines=Boolean.parseBoolean(properties.getProperty(prefix+"mll_generate_scene_outlines"));
if (properties.getProperty(prefix+"mll_add_combo")!=null) this.mll_add_combo=Boolean.parseBoolean(properties.getProperty(prefix+"mll_add_combo"));
......@@ -1738,6 +1746,7 @@ public class BiQuadParameters {
bqp.mll_max_refines_pre = this.mll_max_refines_pre;
bqp.mll_min_disp_change_lma = this.mll_min_disp_change_lma;
bqp.mll_max_refines_lma = this.mll_max_refines_lma;
bqp.mll_max_refines_bg = this.mll_max_refines_bg;
bqp.mll_generate_scene_outlines = this.mll_generate_scene_outlines;
bqp.mll_add_combo = this.mll_add_combo;
......
......@@ -121,7 +121,7 @@ public class Corr2dLMA {
private int [] used_cams_rmap; // variable-length list of used cameras numbers
private int [][] used_pairs_map; // [tile][pair] -1 for unused pairs, >=0 for used ones
private boolean [] last_common_scale = null; //When switching from common to individual the
private boolean [] last_common_scale = null; // new boolean[1]; //When switching from common to individual the
// scale[0] is cloned, reverse - averaged to [0]
private boolean [] used_tiles;
......@@ -599,6 +599,10 @@ public class Corr2dLMA {
adjust_disparities = new boolean[numMax];
Arrays.fill(adjust_disparities, true);
}
if (last_common_scale == null) { // first time - same as it was {false, ...,false}
last_common_scale = new boolean[numMax];
Arrays.fill(last_common_scale, false);
}
/// double [][] disp_str = disp_str_all[0]; //FIXME: ****************
adjust_lazyeye_ortho = adjust_lazyeye_par; // simplify relations for the calculated/dependent parameters
......@@ -2633,7 +2637,7 @@ public class Corr2dLMA {
double [][] abc = getABCTile(nmax); // nmax
for (int tile = 0; tile < numTiles; tile++) {
int offs = (tile * numMax + nmax) * tile_params;
ds[nmax][tile][0] = Double.NaN + 0;
ds[nmax][tile][0] = Double.NaN;
if (Double.isNaN(maxmin_amp[tile][0])) {
continue;
}
......
......@@ -41,6 +41,14 @@ public class Correlation2d {
public final static int PAIR_VERTICAL = 1;
public final static int PAIR_DIAGONAL_MAIN = 2;
public final static int PAIR_DIAGONAL_OTHER = 3;
public final static int CAMEL_BOTH = 0;
public final static int CAMEL_STRONGEST = 1;
public final static int CAMEL_NEAREST = 2;
public final static int CAMEL_FG = 3;
public final static int CAMEL_BG = 4;
private final DttRad2 dtt;
private final int transform_size;
private final int transform_len;
......@@ -4380,10 +4388,157 @@ public class Correlation2d {
return lmaSuccess? lma: null;
}
/**
* Sort array of {disparity,strength} pairs in descending disparity order. Maintain is_lma if not null
* @param disp_str_in array of {disparity, strength} pairs (will not be modified)
* @param is_lma optional array of boolean is_lma elements or null
* @return reordered array of {disparity, strength} pairs. If not null, is_lma will be updated accordingly
*/
public static double [][] sortFgFirst(
double[][] disp_str_in0,
boolean [] is_lma
){
double[][] disp_str_in = disp_str_in0.clone();
boolean [] is_lma1 = (is_lma == null)? null : is_lma.clone();
int nmax = 0;
for (int i = 0; i < disp_str_in.length; i++) if (disp_str_in[i] != null) nmax++;
double [][] disp_str = new double [nmax][];
for (int n = 0; n < nmax; n++) {
int idmx = -1;
for (int i = 0; i < disp_str_in.length; i++) if ((disp_str_in[i] != null) && !Double.isNaN(disp_str_in[i][0])){
if ((idmx < 0) || ( disp_str_in[i][0] > disp_str_in[idmx][0])) {
idmx = i;
}
}
if (idmx < 0) {
// truncate
double [][] disp_str_trunc = new double [n][];
for (int i = 0; i <n; i++) {
disp_str_trunc[i]=disp_str[i];
}
return disp_str_trunc;
}
disp_str[n] = disp_str_in[idmx];
if (is_lma != null) {
is_lma[n] = is_lma1[idmx];
}
disp_str_in[idmx] = null;
}
return disp_str;
}
/**
* Select {disparity, strength} pair from potentially multiple
* @param combine_mode processing mode: 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
* @param disp_str_dual [nmax]{disparity, strength}. One or two pairs of {disparity, strength},
* in descending strength order
* @return selected [nmax]{disparity, strength}. If two are returned, they have the same order as the input one
*/
public static double [][] selDispStr( // single tile
int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
double[][] disp_str_dual) // -preliminary center x in pixels for largest baseline
{
double [][] disp_str_all;
if (disp_str_dual.length < 2) {
disp_str_all = disp_str_dual;
} else { // only 2 max are supported
if (disp_str_dual.length > 2) {
System.out.println("selDispStr(): Only 2 correlation maximums are currently supported, all but 2 strongest are discarded");
}
int nearest_max = (Math.abs(disp_str_dual[0][0]) < Math.abs(disp_str_dual[1][0]))? 0 : 1;
int fg_max = (disp_str_dual[0][0] > disp_str_dual[1][0]) ? 0 : 1;
switch (combine_mode) {
case CAMEL_BOTH: // keep both
disp_str_all = disp_str_dual;
break;
case CAMEL_STRONGEST: // keep strongest
disp_str_all = new double [][] {disp_str_dual [0]};
break;
case CAMEL_NEAREST: // keep nearest
disp_str_all = new double [][] {disp_str_dual [nearest_max]};
break;
case CAMEL_FG: // keep foreground
disp_str_all = new double [][] {disp_str_dual [fg_max]};
break;
case CAMEL_BG: // keep background
disp_str_all = new double [][] {disp_str_dual [1-fg_max]};
break;
default: // keep both
disp_str_all = disp_str_dual;
}
}
return disp_str_all;
}
/**
* Select index of {disparity, strength} pair from potentially multiple
* @param combine_mode processing mode: 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
* @param disp_str_dual [nmax]{disparity, strength}. One or two pairs of {disparity, strength},
* in descending strength order
* @return index of selected pair or -1 if all are selected
*/
public static int selDispStrIndex( // single tile
int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
double[][] disp_str_dual) { // -preliminary center x in pixels for largest baseline
if (disp_str_dual.length < 2) {
return 0;
} else { // only 2 max are supported
if (disp_str_dual.length > 2) {
System.out.println("selDispStr(): Only 2 correlation maximums are currently supported, all but 2 strongest are discarded");
}
int nearest_max = (Math.abs(disp_str_dual[0][0]) < Math.abs(disp_str_dual[1][0]))? 0 : 1;
int fg_max = (disp_str_dual[0][0] > disp_str_dual[1][0]) ? 0 : 1;
switch (combine_mode) {
case CAMEL_BOTH: // keep both
return -1;
case CAMEL_STRONGEST:// keep strongest
return 0;
case CAMEL_NEAREST: // keep nearest
return nearest_max;
case CAMEL_FG: // keep foreground
return fg_max;
case CAMEL_BG: // keep background
return 1-fg_max;
default: // keep both
return -1;
}
}
}
/**
* Process multiple 2D correlation pairs with LMA and extract {disparity,strength} data with
* Levenberg-Marquardt Algorithm (LMA). The data should be pre-processed (e.g. with
* rotation+scaling+accumulation of the correlation pairs followed by the polynomial approximation
* and expected disparity value (or up to 2 values) should be known. In the case of multiple
* (now just 2) disparities that correspond to foreground (FG) and background (BG) objects in the
* same tile, this method may process only one of them (strongest, nearest to 0, FG or BG) or both
* depending on the combine_mode.
* @param imgdtt_params multiple processing parameters
* @param combine_mode processing mode: 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
* @param corr_wnd correlation window to save on re-calculation of the window
* @param corr_wnd_inv_limited correlation window, limited not to be smaller than threshold - used
* to find max/convex areas (or null)
* @param corrs [pair][pixel] correlation data (per pair, per pixel). May have nulls for
* unused pairs as well as extra elements in the end (such as composite "combo" image
* containing result of accumulation of rotated+scaled individual correlation pairs).
* @param disp_dist per camera disparity matrix as a 1d (linescan order))
* @param rXY non-distorted X,Y offset per nominal pixel of disparity
* @param pair_mask per pair boolean array, false elements disable corresponding correlation pairs in corrs
* @param disp_str_dual [nmax]{disparity, strength}. One or two pairs of {disparity, strength},
* in descending strength order
* @param debug_lma_tile array for per-tile debug data or null if not needed
* @param debug_level debug level
* @param tileX debug tile X (just for the debug images titles
* @param tileY debug tile X (just for the debug images titles
* @return Corr2dLMA instance if success, or null in case of failure. Corr2dLMA instance may be
* used to extract result (refined disparity/strength pair(s) and other values to judge
* the quality of LMA fitting
*/
public Corr2dLMA corrLMA2DualMax( // single tile
ImageDttParameters imgdtt_params,
int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
// boolean adjust_ly, // adjust Lazy Eye
double [][] corr_wnd, // correlation window to save on re-calculation of the window
double [] corr_wnd_inv_limited, // correlation window, limited not to be smaller than threshold - used for finding max/convex areas (or null)
double [][] corrs, // may have more elements than pair_mask (corrs may have combo as last elements)
......@@ -4392,21 +4547,14 @@ public class Correlation2d {
boolean [] pair_mask, // which pairs to process
// should never be null
double[][] disp_str_dual, // -preliminary center x in pixels for largest baseline
double[] poly_ds, // null or pair of disparity/strength
double vasw_pwr, // value as weight to this power,
double [] debug_lma_tile,
int debug_level,
int tileX, // just for debug output
int tileY
)
int tileY)
{
// double lpf_neib = 0.5; // if >0, add ortho neibs (corners - squared)
// double notch_pwr = 4.0; //calculating notch filter to suppress input data of the weaker maximum
// double adv_power = 2.0; // reduce weight from overlap with adversarial maximum
// int rad_convex_search = 2; // how far from predicted to search for maximums
// int min_num_samples = 4; // minimal number of samples per pair per maximum
// int min_num_pairs = 8; // minimal number of used pairs
int sel_max = selDispStrIndex( // single tile
imgdtt_params.bimax_combine_mode, // int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
disp_str_dual); // double[][] disp_str_dual) // -preliminary center x in pixels for largest baseline
boolean debug_graphic = imgdtt_params.lma_debug_graphic && (imgdtt_params.lma_debug_level1 > 3) && (debug_level > 0) ;
debug_graphic |= imgdtt_params.lmamask_dbg && (debug_level > 0) ;
......@@ -4424,7 +4572,6 @@ public class Correlation2d {
double [][][] own_masks0 = new double [pair_offsets0.length][][];
double [][][] lma_corr_weights0 = getLmaWeights(
imgdtt_params, // ImageDttParameters imgdtt_params,
// lma, // Corr2dLMA lma,
imgdtt_params.bimax_lpf_neib, // double lpf_neib, // if >0, add ortho neibs (corners - squared)
imgdtt_params.bimax_notch_pwr, // double notch_pwr, // = 4.00;
imgdtt_params.bimax_adv_power, // double adv_power, // reduce weight from overlap with adversarial maximum
......@@ -4443,6 +4590,7 @@ public class Correlation2d {
double [][][] own_masks;
double [][][] pair_offsets;
boolean [] common_scale; // = {false,false}; // true}; {true,true}; // // TODO: implement
// int combine_mode_pre = imgdtt_params.bimax_post_LMA ? 0 : imgdtt_params.bimax_combine_mode;
if (lma_corr_weights0.length < 2) {
pair_offsets = pair_offsets0;
......@@ -4456,6 +4604,27 @@ public class Correlation2d {
}
int nearest_max = (Math.abs(disp_str_dual[0][0]) < Math.abs(disp_str_dual[1][0]))? 0 : 1;
int fg_max = (disp_str_dual[0][0] > disp_str_dual[1][0]) ? 0 : 1;
if (imgdtt_params.bimax_post_LMA || (sel_max < 0)) { // keep multi
pair_offsets = pair_offsets0;
lma_corr_weights = lma_corr_weights0;
disp_str_all = disp_str_dual;
own_masks = own_masks0;
common_scale = new boolean[disp_str_dual.length];
for (int i = 0; i < common_scale.length; i++) {
common_scale[i] = (i == fg_max) ? imgdtt_params.bimax_common_fg : imgdtt_params.bimax_common_bg;
}
} else { // select one max right now
//(sel_max == fg_max)
pair_offsets = new double [][][] {pair_offsets0 [sel_max]};
lma_corr_weights = new double [][][] {lma_corr_weights0[sel_max]};
disp_str_all = new double [][] {disp_str_dual [sel_max]};
own_masks = new double [][][] {own_masks0 [sel_max]};
common_scale = new boolean[] {(sel_max == fg_max) ? imgdtt_params.bimax_common_fg : imgdtt_params.bimax_common_bg};
}
/*
int nearest_max = (Math.abs(disp_str_dual[0][0]) < Math.abs(disp_str_dual[1][0]))? 0 : 1;
int fg_max = (disp_str_dual[0][0] > disp_str_dual[1][0]) ? 0 : 1;
switch (combine_mode) {
case 0: // keep both
......@@ -4506,9 +4675,10 @@ public class Correlation2d {
common_scale[i] = (i == fg_max) ? imgdtt_params.bimax_common_fg : imgdtt_params.bimax_common_bg;
}
}
*/
}
double [][][] filtWeight = new double [lma_corr_weights.length][corrs.length][];
double [][][] filtWeight = new double [lma_corr_weights.length][corrs.length][];
int num_disp_samples = 0;
int num_cnvx_samples = 0;
int num_comb_samples = 0;
......@@ -4592,7 +4762,8 @@ public class Correlation2d {
rXY, //double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.lmas_gaussian //boolean gaussian_mode
);
//imgdtt_params.ortho_vasw_pwr
double vasw_pwr = imgdtt_params.ortho_vasw_pwr; // value as weight to this power,
for (int npair = 0; npair < pair_mask.length; npair++) if ((corrs[npair] != null) && (used_pairs[npair])){
for (int nmax = 0; nmax < lma_corr_weights.length; nmax++) { // use same blurred version for all max-es
for (int i = 1; i < lma_corr_weights[nmax][npair].length; i++) if (lma_corr_weights[nmax][npair][i] > 0.0) {
......@@ -4612,7 +4783,6 @@ public class Correlation2d {
v, // double v, // correlation value at that point
w); //double w) // sample weight
}
}
}
......@@ -4684,8 +4854,7 @@ public class Correlation2d {
if (npass > 0) {
adjust_disparities = null;
}
// boolean [] common_scale = {false,false}; // true}; {true,true}; // // TODO: implement
lma.setParMask( // USED in lwir
lma.setParMask(
adjust_disparities, // null, // boolean [] adjust_disparities, // null - adjust all, otherwise - per maximum
common_scale, //boolean [] common_scale, // per-maximum, if true - common scale for all pairs
imgdtt_params.lmas_adjust_wm, // boolean adjust_width, // adjust width of the maximum - lma_adjust_wm
......@@ -4695,8 +4864,7 @@ public class Correlation2d {
false, // (adjust_ly ? imgdtt_params.lma_adjust_ly1: false), // imgdtt_params.lma_adjust_ly1, // boolean adjust_lazyeye_ortho, // adjust disparity corrections orthogonal to disparities lma_adjust_ly1
0.0, // (adjust_ly ? imgdtt_params.lma_cost_wy : 0.0), // imgdtt_params.lma_cost_wy, // double cost_lazyeye_par, // cost for each of the non-zero disparity corrections lma_cost_wy
0.0); // (adjust_ly ? imgdtt_params.lma_cost_wxy : 0.0) //imgdtt_params.lma_cost_wxy // double cost_lazyeye_odtho // cost for each of the non-zero ortho disparity corrections lma_cost_wxy
if (debug_level > 0) { // 1) {
if (debug_level > 1) { // 1) {
System.out.println("Input data:");
lma.printInputDataFx(false);
lma.printParams();
......@@ -4789,7 +4957,12 @@ public class Correlation2d {
}
return lmaSuccess? lma: null;
}
/**
* Low-pass filtering of correlation data with a 3x3 kernel
* @param data correlation data in scan-line order (will be modified), currently 15x15=225 long
* @param orth_val relative (to the center pixel) weight of the 4 ortho pixels (corner weights
* are orth_val * orth_val
*/
void lpf_neib(
double [] data,
double orth_val) {
......@@ -4865,11 +5038,35 @@ public class Correlation2d {
return xy_offsets;
}
/**
* Generate masks (analog weights) per correlation maximum, per pair taking into account
* other (adversarial) correlation maximum(s) and reducing weigh.
* @param imgdtt_params multiple processing parameters
* @param lpf_neib low pass filtering parameter
* @param notch_pwr power to raise notch filter to generate an accumulated over all pairs
* notch filter that later is shifted according to the expected disparity
* for each individual pair. The higher the power, the wider and sharper
* is the filter.
* @param adv_power power to raise relative (to adversarial maximum) this maximum strength
* for each pixel. Higher power make filtering sharper
* @param corrs [pair][pixel] correlation data (per pair, per pixel). May have nulls for
* unused pairs.
* @param disp_dist per camera disparity matrix as a 1d (linescan order))
* @param rXY non-distorted X,Y offset per nominal pixel of disparity
* @param pair_mask per pair boolean array, false elements disable corresponding correlation pairs in corrs
* @param pair_offsets [nmax][pair]{x,y} per-maximum, per pair X,Y offset of the correlation maximum
* @param own_masks [nmax][pair][pix] per-maximum, per-pair correlation pixel array calculated regardless of
* the adversaries. Should be initialized to double[nmax][][] or null (to skip calculation)
* @param disp_str_dual [nmax]{disparity, strength}. One or two pairs of {disparity, strength},
* in descending strength order
* @param debug_level debug level
* @param tileX debug tile X (just for the debug images titles
* @param tileY debug tile X (just for the debug images titles
* @return [nmax][pair][pixel] corresponding by the first dimension to the input disp_str_dual array
*/
public double[][][] getLmaWeights(
ImageDttParameters imgdtt_params,
// Corr2dLMA lma,
double lpf_neib, // if >0, add ortho neibs (corners - squared)
double notch_pwr, // = 4.00;
double adv_power, // reduce weight from overlap with adversarial maximum
......
......@@ -2420,6 +2420,9 @@ public class ImageDtt extends ImageDttCPU {
// which to use - num_pairs or num_used_pairs? Or set correlation2d to match num_used_pairs
final boolean combine_corrs = (mcorr_comb_width > 0); // use 0 to disable combining (use LMA only)
if (!combine_corrs) {
System.out.println("**** Warning: clt_process_tl_correlations() does not use combine_corrs, new LMA is disbled ****");
}
if (clt_corr_out != null) { // not used so far? REMOVE?
boolean [] calc_corr_pairs = correlation2d.getCorrPairs();
......@@ -2587,7 +2590,6 @@ public class ImageDtt extends ImageDttCPU {
}
}
correlation2d.normalizeAccumulatedPairs(
corr_combo_tile,
sumw);
......@@ -2611,76 +2613,160 @@ public class ImageDtt extends ImageDttCPU {
// calculate 0,1, or 2 maximums
if (debugTile1) {
System.out.println("clt_process_tl_correlations(): debugTile1");
// debugTile0 = true;
}
double [][] maxes = correlation2d.getDoublePoly(
disparity_scale, // double disparity_scale,
((corr_dia_tile != null) ? corr_dia_tile : corr_combo_tile), // double [] combo_corrs,
imgdtt_params.mcorr_dual_fract); //double min_fraction
// TODO: add corr layer - copy of combo with singles as nulls
// if ((maxes.length < 2) && (clt_corr_out != null) && (clt_corr_out.length > num_pairs)) {
if ((maxes.length < 2) && (corr_dia_tile!=null)) { //FIXME: Debug
// corrs[correlation2d.getNumPairs()] = null; // temporarily keep only with pairs
Arrays.fill(corrs[correlation2d.getNumPairs()+1], Double.NaN);
}
if (debugTile1) {
System.out.println("clt_process_tl_correlations() maxes=");
for (int i = 00; i < maxes.length; i++) {
System.out.println(String.format("maxes[%d][0]=%f (quadcam disparity pixels, not combo pixels), maxes[%d][1]=%f", i, maxes[i][0], i, maxes[i][1]));
double [][] disp_str_sel = null;
double [][] disp_str_lma = null;
int [] sel_fg_bg = null;
if (imgdtt_params.bimax_dual_LMA) {
double [][] maxes = correlation2d.getDoublePoly(
disparity_scale, // double disparity_scale,
((corr_dia_tile != null) ? corr_dia_tile : corr_combo_tile), // double [] combo_corrs,
imgdtt_params.mcorr_dual_fract); //double min_fraction
// TODO: add corr layer - copy of combo with singles as nulls
// just for debugging to indicate tiles with dual maximums
if ((maxes.length < 2) && (corr_dia_tile!=null)) { //FIXME: Debug
// corrs[correlation2d.getNumPairs()] = null; // temporarily keep only with pairs
Arrays.fill(corrs[correlation2d.getNumPairs()+1], Double.NaN);
}
}
if (debugTile1) {
Corr2dLMA lma_dual = correlation2d.corrLMA2DualMax( // null pointer
imgdtt_params, // ImageDttParameters imgdtt_params,
00, // 3, // 0, // 1, // int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
// imgdtt_params.lmas_LY_single, // false, // boolean adjust_ly, // adjust Lazy Eye
corr_wnd, // double [][] corr_wnd, // correlation window to save on re-calculation of the window
corr_wnd_inv_limited, // corr_wnd_limited, // correlation window, limited not to be smaller than threshold - used for finding max/convex areas (or null)
corrs, // corrs, // double [][] corrs,
disp_dist,
rXY, // double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
// all that are not null in corr_tiles
correlation2d.selectAll(), // longToArray(imgdtt_params.dbg_pair_mask), // int pair_mask, // which pairs to process
maxes, //double[][] disp_str_dual, // -preliminary center x in pixels for largest baseline
null, // poly_disp, // double[] poly_ds, // null or pair of disparity/strength
imgdtt_params.ortho_vasw_pwr, // double vasw_pwr, // value as weight to this power,
null, // debug_lma_tile, // double [] debug_lma_tile,
(debugTile0 ? 1: -2), // int debug_level,
tileX, // int tileX, // just for debug output
tileY );
System.out.println("clt_process_tl_correlations() corrLMA2DualMax() done, lma_dual="+
((lma_dual== null)? "null": " not null"));
}
if (disparity_map != null) {
int [] ixy = correlation2d.getMaxXYInt( // find integer pair or null if below threshold // USED in lwir
corr_combo_tile, // double [] data, // [data_size * data_size]
null, // disp_str_combo,
correlation2d.getCombWidth(), // data_width,
correlation2d.getCombHeight()/2 - correlation2d.getCombOffset(), // int center_row, ??????????????
true, // boolean axis_only,
-1.0, // imgdtt_params.min_corr, // ???? double minMax, // minimal value to consider (at integer location, not interpolated)
false); // debugCluster); // tile_lma_debug_level > 0); // boolean debug);
double [] corr_stat = correlation2d.getMaxXCm( // get fractional center as a "center of mass" inside circle/square from the integer max
corr_combo_tile, // double [] data, // [data_size * data_size]
correlation2d.getCombWidth(), // int data_width, // = 2 * transform_size - 1;
correlation2d.getCombHeight()/2 - correlation2d.getCombOffset(),// int center_row,
ixy[0], // int ixcenter, // integer center x
false); // debugCluster); // (tile_lma_debug_level > 0)); // boolean debug);
if (corr_stat != null) { // almost always
// FIXME: apply that for non-GPU version (and other variants) !
// convert to disparity for a quad camera (used in pre-shift)
disp_str = new double [] {-corr_stat[0]/Math.sqrt(2), corr_stat[1]};
// disp_str = new double [] {-corr_stat[0], corr_stat[1]};
if (disparity_map!=null) {
if ((maxes.length >= 2) || ! imgdtt_params.bimax_dual_only) {
/// create disparity/strength results w/o LMA. Use it if LMA fails
sel_fg_bg = new int[] { // first - index FG, second - index BG
Correlation2d.selDispStrIndex( // FG
Correlation2d.CAMEL_FG, // int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
maxes), // double[][] disp_str_dual) // -preliminary center x in pixels for largest baseline
Correlation2d.selDispStrIndex( // BG
Correlation2d.CAMEL_BG, // int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
maxes) // double[][] disp_str_dual) // -preliminary center x in pixels for largest baseline
};
int sel_max = Correlation2d.selDispStrIndex( // single tile
imgdtt_params.bimax_combine_mode, // int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
maxes); // double[][] disp_str_dual) // -preliminary center x in pixels for largest baseline
disp_str_sel = Correlation2d.selDispStr( // single tile
imgdtt_params.bimax_combine_mode, // int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
maxes); // double[][] disp_str_dual) // -preliminary center x in pixels for largest baseline
int combine_mode_corrected = imgdtt_params.bimax_combine_mode;
if ( (maxes[sel_fg_bg[0]][1] < imgdtt_params.mcorr_fb_fract * maxes[sel_fg_bg[1]][1]) ||
(maxes[sel_fg_bg[1]][1] < imgdtt_params.mcorr_bf_fract * maxes[sel_fg_bg[0]][1])) {
//maxes = new double [][] {maxes[0]}; // strongest
disp_str_sel = new double [][] {maxes[0]}; // strongest
sel_max = 0;
sel_fg_bg = new int[] {0,0};
combine_mode_corrected = Correlation2d.CAMEL_STRONGEST;
}
if (run_lma) {
if (debugTile1) {
System.out.println("clt_process_tl_correlations() maxes=");
for (int i = 0; i < maxes.length; i++) {
System.out.println(String.format("maxes[%d][0]=%f (quadcam disparity pixels, not combo pixels), maxes[%d][1]=%f", i, maxes[i][0], i, maxes[i][1]));
}
}
int combine_mode_pre = imgdtt_params.bimax_post_LMA ? Correlation2d.CAMEL_BOTH : combine_mode_corrected;
Corr2dLMA lma_dual = correlation2d.corrLMA2DualMax( // null pointer
imgdtt_params, // ImageDttParameters imgdtt_params,
combine_mode_pre, // 3, // 0, // 1,// int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
corr_wnd, // double [][] corr_wnd, // correlation window to save on re-calculation of the window
corr_wnd_inv_limited, // corr_wnd_limited, // correlation window, limited not to be smaller than threshold - used for finding max/convex areas (or null)
corrs, // corrs, // double [][] corrs,
disp_dist,
rXY, // double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
// all that are not null in corr_tiles
correlation2d.selectAll(), // longToArray(imgdtt_params.dbg_pair_mask), // int pair_mask, // which pairs to process
maxes, //double[][] disp_str_dual, // -preliminary center x in pixels for largest baseline
null, // debug_lma_tile, // double [] debug_lma_tile,
(debugTile0 ? 1: -2), // int debug_level,
tileX, // int tileX, // just for debug output
tileY );
if (debugTile1) {
System.out.println("clt_process_tl_correlations() corrLMA2DualMax() done, lma_dual="+
((lma_dual== null)? "null": " not null"));
}
if (lma_dual != null) {
double [][][] dispStrs = lma_dual.lmaDisparityStrengths( //TODO: add parameter to filter out negative minimums ?
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_min_amp_bg, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
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
);
disp_str_lma = new double [dispStrs.length][]; // order matching input ones
for (int nmax = 0;nmax < dispStrs.length; nmax++) {
if ((dispStrs[nmax] != null) && (dispStrs[nmax].length >0)) {
disp_str_lma[nmax] = dispStrs[nmax][0];
}
}
if (imgdtt_params.bimax_post_LMA && (sel_max >=0)) {
disp_str_lma = new double [][] {disp_str_lma[sel_max]}; // was already selected before LMA
}
} // if (lma_dual != null) {
}
}
if (debugTile1) { // FIXME: remove debugTile1!
System.out.println("clt_process_tl_correlations() disp_str_sel=");
for (int nmax = 0; nmax < disp_str_sel.length; nmax++) {
System.out.println(String.format("disp_str_sel[%d][0]=%f, disp_str_sel[%d][1]=%f LMA=%s",
nmax, disp_str_sel[nmax][0], nmax, disp_str_sel[nmax][1], (((disp_str_lma!=null) && (disp_str_lma[nmax]!=null))?"true":"false")));
}
}
if ((disp_str_sel != null) && (disp_str_sel.length > 0)) {
if (disparity_map != null) {
disparity_map[DISPARITY_INDEX_CM ][nTile] = disp_str_sel[0][0]; // disparity non-LMA
disparity_map[DISPARITY_INDEX_CM + 1 ][nTile] = disp_str_sel[0][1]; // strength non-LMA;
disparity_map[DISPARITY_STRENGTH_INDEX][nTile] = disp_str_sel[0][1]; // strength non-LMA;
if ((disp_str_lma!=null) && (disp_str_lma.length>0)) {
if (disp_str_lma.length == 1) {
if (!Double.isNaN(disp_str_lma[0][0])) {
disparity_map[DISPARITY_INDEX_POLY ][nTile] = disp_str_lma[0][0]; // disparity LMA
disparity_map[DISPARITY_INDEX_POLY + 1][nTile] = disp_str_lma[0][2]; // strength LMA
disparity_map[DISPARITY_STRENGTH_INDEX][nTile] = disp_str_lma[0][1]; // overwrite with LMA strength
}
} else {
int indx = sel_fg_bg[0];
if (!Double.isNaN(disp_str_lma[indx][0])) {
disparity_map[DISPARITY_INDEX_POLY ][nTile] = disp_str_lma[indx][0]; // disparity LMA
disparity_map[DISPARITY_INDEX_POLY + 1][nTile] = disp_str_lma[indx][2]; // strength LMA
disparity_map[DISPARITY_STRENGTH_INDEX][nTile] = disp_str_lma[indx][1]; // overwrite with LMA strength
}
}
}
}
}
} else { // if (imgdtt_params.bimax_dual_LMA) else
if (disparity_map != null) {
int [] ixy = correlation2d.getMaxXYInt( // find integer pair or null if below threshold // USED in lwir
corr_combo_tile, // double [] data, // [data_size * data_size]
null, // disp_str_combo,
correlation2d.getCombWidth(), // data_width,
correlation2d.getCombHeight()/2 - correlation2d.getCombOffset(), // int center_row, ??????????????
true, // boolean axis_only,
-1.0, // imgdtt_params.min_corr, // ???? double minMax, // minimal value to consider (at integer location, not interpolated)
false); // debugCluster); // tile_lma_debug_level > 0); // boolean debug);
double [] corr_stat = correlation2d.getMaxXCm( // get fractional center as a "center of mass" inside circle/square from the integer max
corr_combo_tile, // double [] data, // [data_size * data_size]
correlation2d.getCombWidth(), // int data_width, // = 2 * transform_size - 1;
correlation2d.getCombHeight()/2 - correlation2d.getCombOffset(),// int center_row,
ixy[0], // int ixcenter, // integer center x
false); // debugCluster); // (tile_lma_debug_level > 0)); // boolean debug);
if (corr_stat != null) { // almost always
disp_str = new double [] {-corr_stat[0], corr_stat[1]};
disparity_map[DISPARITY_INDEX_CM ][nTile] = disp_str[0];
disparity_map[DISPARITY_INDEX_CM + 1 ][nTile] = disp_str[1];
disparity_map[DISPARITY_STRENGTH_INDEX][nTile] = disp_str[1];
}
}
}
}
if (run_lma && (disparity_map != null)) {
} // if (imgdtt_params.bimax_dual_LMA) else
} // if (combine_corrs) {
// New method depends on combine_corrs, so if it is disabled - use old way
if ((!imgdtt_params.bimax_dual_LMA || !combine_corrs) && run_lma && (disparity_map != null)) { // old way
// debug the LMA correlations
if (debugTile0) { // should be debugTile
System.out.println("Will run new LMA for tileX="+tileX+", tileY="+tileY);
......@@ -2769,7 +2855,7 @@ public class ImageDtt extends ImageDttCPU {
debug_lma[i][nTile] = debug_lma_tile[i];
}
}
}
} // if (run_lma && (disparity_map != null))
}
}
};
......
......@@ -87,7 +87,11 @@ public class ImageDttParameters {
public boolean bimax_dual_pass = true; // First pass - do not adjust disparity
public boolean bimax_common_fg = true; // Common gains for foreground/single correlation maximum
public boolean bimax_common_bg = true; // Common gains for background correlation maximum
public boolean bimax_post_LMA = true; // When dual max, LMA with two maximums, then select. If false,select before LMA
private static final String [] COMBINE_MODES= {"both","strongest","nearest","FG","BG"};
public int bimax_combine_mode = 3; // FG
public boolean bimax_dual_LMA = true; // New LMA capable of FG/BG
public boolean bimax_dual_only = false; // process only tiles with dual maximums (requires bimax_dual_LMA)
//lmamask_
public boolean lmamask_dbg = false; // show LMA images, exit after single BG
......@@ -144,6 +148,8 @@ public class ImageDttParameters {
public double mcorr_weights_power = 2.0; // divide pair by horizontal (disparity) width after rotation/scaling (skip negative when measuring width)
public boolean mcorr_dynamic_weights = true; // Apply weights to pairs dependent on the width in disparity direction
public double mcorr_dual_fract= 0.15; // Minimal relative strength of the second correlation maximum to treat as FG+BG
public double mcorr_fb_fract= 0.5; // Minimal relative strength of FG to BG to keep (final, after LMA if enabled)
public double mcorr_bf_fract= 0.2; // Minimal relative strength of BG to FG to keep (final, after LMA if enabled)
/// these are just for testing, actual will be generated specifically for different applications (LY will use closest pairs)
public int mcorr_comb_width = 15;
......@@ -486,6 +492,14 @@ public class ImageDttParameters {
"Use common gain for all pairs for FG/single correlation (unchecked - use individual gain for each pair)");
gd.addCheckbox ("Common gains for background correlation maximum", this.bimax_common_bg,
"Use common gain for all pairs for BG correlation(s) (unchecked - use individual gain for each pair)");
gd.addCheckbox ("Select after LMA", this.bimax_post_LMA,
"When dual max, LMA with two maximums, then select. If false,select before LMA");
gd. addChoice("Multiple maximums select mode", COMBINE_MODES, COMBINE_MODES[bimax_combine_mode],
"Which maximum to keep after LMA");
gd.addCheckbox ("Use updated LMA capable of FG/BG", this.bimax_dual_LMA,
"When dual max, LMA with two maximums, then select. If false,select before LMA");
gd.addCheckbox ("Process only tiles with dual maximums (requires bimax_dual_LMA)", this.bimax_dual_only,
"May be used to determine BG after refining FG. First refine with false and mode = 3 (FG), then with true and mode = 4 (BG)");
gd.addMessage("LMA samples filter based on estimated disparity");
gd.addCheckbox ("Debug LMA", this.lmamask_dbg,
......@@ -597,7 +611,11 @@ public class ImageDttParameters {
"Calculate each pairs's width (in the disparity direction) after rotation/scaling and apply");
gd.addNumericField("Minimal relative strength of the second maximum (0 - ignore)", this.mcorr_dual_fract, 3,6,"",
"Minimal relative strength of the second correlation maximum to treat as FG+BG (0 - ignore dual maximums, no special treatment)");
gd.addNumericField("Minimal relative strength of FG to BG", this.mcorr_fb_fract, 3,6,"",
"Minimal relative strength of FG to BG to keep weaker (final, after LMA if enabled), <1.0");
gd.addNumericField("Minimal relative strength of BG to FG", this.mcorr_bf_fract, 3,6,"",
"Minimal relative strength of BG to FG to keep weaker (final, after LMA if enabled), <1.0");
gd.addMessage("Generating grid for combining visualization, actual will be provided programmatically");
gd.addNumericField("Width of a combined correlation tile", this.mcorr_comb_width, 0, 3, "pix",
"Width of a tile to combine correlations after rotation/scaling");
......@@ -907,6 +925,10 @@ public class ImageDttParameters {
this.bimax_dual_pass = gd.getNextBoolean();
this.bimax_common_fg = gd.getNextBoolean();
this.bimax_common_bg = gd.getNextBoolean();
this.bimax_post_LMA = gd.getNextBoolean();
this.bimax_combine_mode = gd.getNextChoiceIndex();
this.bimax_dual_LMA = gd.getNextBoolean();
this.bimax_dual_only = gd.getNextBoolean();
this.lmamask_dbg = gd.getNextBoolean();
this.lmamask_en = gd.getNextBoolean();
......@@ -962,6 +984,8 @@ public class ImageDttParameters {
this.mcorr_weights_power= gd.getNextNumber();
this.mcorr_dynamic_weights = gd.getNextBoolean();
this.mcorr_dual_fract= gd.getNextNumber();
this.mcorr_fb_fract= gd.getNextNumber();
this.mcorr_bf_fract= gd.getNextNumber();
this.mcorr_comb_width= (int) gd.getNextNumber();
this.mcorr_comb_height=(int) gd.getNextNumber();
......@@ -1137,7 +1161,11 @@ public class ImageDttParameters {
properties.setProperty(prefix+"bimax_dual_pass", this.bimax_dual_pass +"");
properties.setProperty(prefix+"bimax_common_fg", this.bimax_common_fg +"");
properties.setProperty(prefix+"bimax_common_bg", this.bimax_common_bg +"");
properties.setProperty(prefix+"bimax_post_LMA", this.bimax_post_LMA +"");
properties.setProperty(prefix+"bimax_combine_mode", this.bimax_combine_mode +"");
properties.setProperty(prefix+"bimax_dual_LMA", this.bimax_dual_LMA +"");
properties.setProperty(prefix+"bimax_dual_only", this.bimax_dual_only +"");
properties.setProperty(prefix+"lmamask_dbg", this.lmamask_dbg +"");
properties.setProperty(prefix+"lmamask_en", this.lmamask_en +"");
properties.setProperty(prefix+"lmamask_magic", this.lmamask_magic +"");
......@@ -1191,6 +1219,8 @@ public class ImageDttParameters {
properties.setProperty(prefix+"mcorr_weights_power", this.mcorr_weights_power +"");
properties.setProperty(prefix+"mcorr_dynamic_weights",this.mcorr_dynamic_weights +"");
properties.setProperty(prefix+"mcorr_dual_fract", this.mcorr_dual_fract +"");
properties.setProperty(prefix+"mcorr_fb_fract", this.mcorr_fb_fract +"");
properties.setProperty(prefix+"mcorr_bf_fract", this.mcorr_bf_fract +"");
properties.setProperty(prefix+"mcorr_comb_width", this.mcorr_comb_width +"");
properties.setProperty(prefix+"mcorr_comb_height", this.mcorr_comb_height +"");
......@@ -1371,6 +1401,10 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"bimax_dual_pass")!=null) this.bimax_dual_pass=Boolean.parseBoolean(properties.getProperty(prefix+"bimax_dual_pass"));
if (properties.getProperty(prefix+"bimax_common_fg")!=null) this.bimax_common_fg=Boolean.parseBoolean(properties.getProperty(prefix+"bimax_common_fg"));
if (properties.getProperty(prefix+"bimax_common_bg")!=null) this.bimax_common_bg=Boolean.parseBoolean(properties.getProperty(prefix+"bimax_common_bg"));
if (properties.getProperty(prefix+"bimax_post_LMA")!=null) this.bimax_post_LMA=Boolean.parseBoolean(properties.getProperty(prefix+"bimax_post_LMA"));
if (properties.getProperty(prefix+"bimax_combine_mode")!=null) this.bimax_combine_mode=Integer.parseInt(properties.getProperty(prefix+"bimax_combine_mode"));
if (properties.getProperty(prefix+"bimax_dual_LMA")!=null) this.bimax_dual_LMA=Boolean.parseBoolean(properties.getProperty(prefix+"bimax_dual_LMA"));
if (properties.getProperty(prefix+"bimax_dual_only")!=null) this.bimax_dual_only=Boolean.parseBoolean(properties.getProperty(prefix+"bimax_dual_only"));
if (properties.getProperty(prefix+"lmamask_dbg")!=null) this.lmamask_dbg=Boolean.parseBoolean(properties.getProperty(prefix+"lmamask_dbg"));
if (properties.getProperty(prefix+"lmamask_en")!=null) this.lmamask_en=Boolean.parseBoolean(properties.getProperty(prefix+"lmamask_en"));
......@@ -1425,6 +1459,8 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"mcorr_weights_power")!=null) this.mcorr_weights_power=Double.parseDouble(properties.getProperty(prefix+"mcorr_weights_power"));
if (properties.getProperty(prefix+"mcorr_dynamic_weights")!=null)this.mcorr_dynamic_weights=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_dynamic_weights"));
if (properties.getProperty(prefix+"mcorr_dual_fract")!=null) this.mcorr_dual_fract=Double.parseDouble(properties.getProperty(prefix+"mcorr_dual_fract"));
if (properties.getProperty(prefix+"mcorr_fb_fract")!=null) this.mcorr_fb_fract=Double.parseDouble(properties.getProperty(prefix+"mcorr_fb_fract"));
if (properties.getProperty(prefix+"mcorr_bf_fract")!=null) this.mcorr_bf_fract=Double.parseDouble(properties.getProperty(prefix+"mcorr_bf_fract"));
if (properties.getProperty(prefix+"mcorr_comb_width")!=null) this.mcorr_comb_width=Integer.parseInt(properties.getProperty(prefix+"mcorr_comb_width"));
if (properties.getProperty(prefix+"mcorr_comb_height")!=null) this.mcorr_comb_height=Integer.parseInt(properties.getProperty(prefix+"mcorr_comb_height"));
......@@ -1622,6 +1658,10 @@ public class ImageDttParameters {
idp.bimax_dual_pass= this.bimax_dual_pass;
idp.bimax_common_fg= this.bimax_common_fg;
idp.bimax_common_bg= this.bimax_common_bg;
idp.bimax_post_LMA= this.bimax_post_LMA;
idp.bimax_combine_mode= this.bimax_combine_mode;
idp.bimax_dual_LMA= this.bimax_dual_LMA;
idp.bimax_dual_only= this.bimax_dual_only;
idp.lmamask_dbg= this.lmamask_dbg;
idp.lmamask_en= this.lmamask_en;
......@@ -1675,6 +1715,8 @@ public class ImageDttParameters {
idp.mcorr_weights_power= this.mcorr_weights_power;
idp.mcorr_dynamic_weights= this.mcorr_dynamic_weights;
idp.mcorr_dual_fract= this.mcorr_dual_fract;
idp.mcorr_fb_fract= this.mcorr_fb_fract;
idp.mcorr_bf_fract= this.mcorr_bf_fract;
idp.mcorr_comb_width= this.mcorr_comb_width;
idp.mcorr_comb_height= this.mcorr_comb_height;
......
......@@ -4243,7 +4243,7 @@ public class OpticalFlow {
int debug_level
)
{
// empiric correction for both lma and non-lma step
// empirical correction for both lma and non-lma step
double corr_nonlma = 1.0; // 1.23;
double corr_lma = 1.0; // 1.23;
// reference scene is always added to the end, even is out of timestamp order
......@@ -4252,15 +4252,33 @@ public class OpticalFlow {
boolean generate_outlines = false; // true; // TODO: move to configs
System.out.println("intersceneExport(), scene timestamp="+ref_scene.getImageName());
int num_scenes = scenes.length;
String [] combo_dsn_titles = {"disp", "strength","disp_lma","num_valid","change"};
int combo_dsn_indx_disp = 0; // cumulative disparity (from CM or POLY)
int combo_dsn_indx_strength = 1;
int combo_dsn_indx_lma = 2; // masked copy from 0 - cumulative disparity
int combo_dsn_indx_valid = 3; // initial only
int combo_dsn_indx_change = 4; // increment
String [] combo_dsn_titles_full = {"disp", "strength","disp_lma","num_valid","change",
"disp_bg", "strength_bg","disp_lma_bg","change_bg","disp_fg","disp_bg_all"};
int combo_dsn_indx_disp = 0; // cumulative disparity (from CM or POLY), FG
int combo_dsn_indx_strength = 1; // strength, FG
int combo_dsn_indx_lma = 2; // masked copy from 0 - cumulative disparity
int combo_dsn_indx_valid = 3; // initial only
int combo_dsn_indx_change = 4; // increment
int combo_dsn_indx_disp_bg = 5; // cumulative BG disparity (from CM or POLY)
int combo_dsn_indx_strength_bg = 6; // background strength
int combo_dsn_indx_lma_bg = 7; // masked copy from BG disparity
int combo_dsn_indx_change_bg = 8; // increment, BG
int combo_dsn_indx_disp_fg = 9; // cumulative disparity (from CM or POLY), FG
int combo_dsn_indx_disp_bg_all =10; // cumulative BG disparity (Use FG where no BG is available)
String [] combo_dsn_titles = new String [combo_dsn_indx_disp_bg];
for (int i = 0; i < combo_dsn_titles.length; i++) {
combo_dsn_titles[i] = combo_dsn_titles_full[i];
}
if (clt_parameters.rig.mll_max_refines_bg <= 0) {
combo_dsn_titles_full = combo_dsn_titles;
}
double min_disp_change = clt_parameters.rig.mll_min_disp_change_pre; // 0.001; // stop re-measure when difference is below
final int max_refines = clt_parameters.rig.mll_max_refines_lma + clt_parameters.rig.mll_max_refines_pre;
final int max_refines =
clt_parameters.rig.mll_max_refines_bg +
clt_parameters.rig.mll_max_refines_lma +
clt_parameters.rig.mll_max_refines_pre;
final int [] iter_indices = {
combo_dsn_indx_disp,
......@@ -4353,17 +4371,26 @@ public class OpticalFlow {
}
double [] target_disparity = combo_dsn_change[combo_dsn_indx_disp].clone();
double [] target_disparity_orig = target_disparity.clone(); // will just use NaN/not NaN to restore tasks before second pass with LMA
double [][] combo_dsn_final = new double [combo_dsn_titles.length][combo_dsn[0].length];
combo_dsn_final[0]= combo_dsn[0].clone();
// double [][] combo_dsn_final = new double [combo_dsn_titles.length][combo_dsn[0].length];
double [][] combo_dsn_final =
new double [(clt_parameters.rig.mll_max_refines_bg > 0)? combo_dsn_titles_full.length:combo_dsn_titles.length][combo_dsn[0].length];
combo_dsn_final[combo_dsn_indx_disp]= combo_dsn[combo_dsn_indx_disp].clone();
for (int i = 1; i < combo_dsn_final.length; i++) {
Arrays.fill(combo_dsn_final[i], Double.NaN);
}
// Save pair selection and minimize them for scanning, then restore;
int num_sensors =scenes[indx_ref].getNumSensors();
int save_pairs_selection = clt_parameters.img_dtt.getMcorr(num_sensors);
int save_bimax_combine_mode = clt_parameters.img_dtt.bimax_combine_mode;
boolean save_bimax_dual_only = clt_parameters.img_dtt.bimax_dual_only;
if (clt_parameters.rig.mll_max_refines_bg > 0) {
clt_parameters.img_dtt.bimax_combine_mode = Correlation2d.CAMEL_FG; // initially refine FG
clt_parameters.img_dtt.bimax_dual_only = false; // not just dual only
}
// FIXME: uncomment next
System.out.println ("++++ Uncomment next line ++++");
//// clt_parameters.img_dtt.setMcorr(num_sensors, 0 ); // remove all
System.out.println ("++++ Uncomment next line (Done) ++++");
clt_parameters.img_dtt.setMcorr(num_sensors, 0 ); // remove all
clt_parameters.img_dtt.setMcorrNeib(num_sensors,true);
clt_parameters.img_dtt.setMcorrSq (num_sensors,true); // remove even more?
clt_parameters.img_dtt.setMcorrDia (num_sensors,true); // remove even more?
......@@ -4384,18 +4411,16 @@ public class OpticalFlow {
selection[i] = !Double.isNaN(target_disparity[i]);
}
boolean [] selection_orig = selection.clone();
// Refine disparity map, each time recalculating each scene "projection" pixel X, pixel Y and
// disparity in each scene image set that correspond to the reference scene uniform grid tile.
// First use reduced number of pairs and no LMA, then continue with all pairs and LMA
boolean bg_refine= false;
for (int nrefine = 0; nrefine < max_refines; nrefine++) {
if (nrefine == clt_parameters.rig.mll_max_refines_pre) {
min_disp_change = clt_parameters.rig.mll_min_disp_change_lma;
clt_parameters.img_dtt.setMcorr(num_sensors, save_pairs_selection); // restore
clt_parameters.correlate_lma = save_run_lma; // restore
/*
for (int nt = 0; nt < target_disparity.length; nt++) if (Double.isNaN(target_disparity[nt])){
if (!Double.isNaN(target_disparity_orig[nt])) {
target_disparity[nt] = combo_dsn_change[combo_dsn_indx_disp][nt];
}
}
*/
selection = selection_orig.clone();
if (debug_level > -2) {
int num_tomeas = 0;
......@@ -4404,9 +4429,15 @@ public class OpticalFlow {
}
System.out.println ("nrefine pass = "+nrefine+", remaining "+num_tomeas+" tiles to re-measure");
}
} else if (nrefine == (clt_parameters.rig.mll_max_refines_pre + clt_parameters.rig.mll_max_refines_lma)) {
clt_parameters.img_dtt.bimax_dual_only = true; // Camel-max tiles only
clt_parameters.img_dtt.bimax_combine_mode = Correlation2d.CAMEL_BG;
bg_refine= true;
selection = selection_orig.clone(); // re-select all original tiles
} else if (nrefine == (clt_parameters.rig.mll_max_refines_pre + clt_parameters.rig.mll_max_refines_lma + 1)) {
clt_parameters.img_dtt.bimax_dual_only = false; // not just dual only
}
int mcorr_sel = Correlation2d.corrSelEncode(clt_parameters.img_dtt,num_sensors);
// FIXME: null, // final boolean [] selection, // may be null, if not null do not process unselected tiles
double [][] disparity_map =
correlateInterscene(
clt_parameters, // final CLTParameters clt_parameters,
......@@ -4467,15 +4498,27 @@ public class OpticalFlow {
was_lma[nTile] = is_lma;
combo_dsn_change[combo_dsn_indx_strength][nTile] = map_strength[nTile]; // combine CM/LMA
combo_dsn_final[combo_dsn_indx_disp][nTile] = combo_dsn_change[combo_dsn_indx_disp][nTile];
combo_dsn_final[combo_dsn_indx_strength][nTile] = combo_dsn_change[combo_dsn_indx_strength][nTile];
combo_dsn_final[combo_dsn_indx_lma][nTile] = combo_dsn_change[combo_dsn_indx_strength][nTile];
if (map_disparity_lma != null) {
combo_dsn_final[combo_dsn_indx_lma][nTile] = Double.isNaN(map_disparity_lma[nTile])? Double.NaN : combo_dsn_final[combo_dsn_indx_disp][nTile];
if (bg_refine) {
combo_dsn_final[combo_dsn_indx_disp_bg][nTile] = combo_dsn_change[combo_dsn_indx_disp][nTile];
combo_dsn_final[combo_dsn_indx_strength_bg][nTile] = combo_dsn_change[combo_dsn_indx_strength][nTile];
/// combo_dsn_final[combo_dsn_indx_lma_bg][nTile] = combo_dsn_change[combo_dsn_indx_strength][nTile];
combo_dsn_final[combo_dsn_indx_lma_bg][nTile] = combo_dsn_change[combo_dsn_indx_disp][nTile];
if (map_disparity_lma != null) {
combo_dsn_final[combo_dsn_indx_lma_bg][nTile] = Double.isNaN(map_disparity_lma[nTile])? Double.NaN : combo_dsn_final[combo_dsn_indx_disp_bg][nTile];
}
// combo_dsn_final[combo_dsn_indx_valid][nTile] = combo_dsn[combo_dsn_indx_valid][nTile]; // not much sense
combo_dsn_final[combo_dsn_indx_change_bg][nTile] = combo_dsn_change[combo_dsn_indx_change][nTile];
} else {
combo_dsn_final[combo_dsn_indx_disp][nTile] = combo_dsn_change[combo_dsn_indx_disp][nTile];
combo_dsn_final[combo_dsn_indx_strength][nTile] = combo_dsn_change[combo_dsn_indx_strength][nTile];
/// combo_dsn_final[combo_dsn_indx_lma][nTile] = combo_dsn_change[combo_dsn_indx_strength][nTile];
combo_dsn_final[combo_dsn_indx_lma][nTile] = combo_dsn_change[combo_dsn_indx_disp][nTile];
if (map_disparity_lma != null) {
combo_dsn_final[combo_dsn_indx_lma][nTile] = Double.isNaN(map_disparity_lma[nTile])? Double.NaN : combo_dsn_final[combo_dsn_indx_disp][nTile];
}
combo_dsn_final[combo_dsn_indx_valid][nTile] = combo_dsn[combo_dsn_indx_valid][nTile]; // not much sense
combo_dsn_final[combo_dsn_indx_change][nTile] = combo_dsn_change[combo_dsn_indx_change][nTile];
}
combo_dsn_final[combo_dsn_indx_valid][nTile] = combo_dsn[combo_dsn_indx_valid][nTile]; // not much sense
combo_dsn_final[combo_dsn_indx_change][nTile] = combo_dsn_change[combo_dsn_indx_change][nTile];
}
disp_err[nTile] = combo_dsn_change[combo_dsn_indx_change][nTile];
......@@ -4535,7 +4578,22 @@ public class OpticalFlow {
break;
}
} //for (int nrefine = 0; nrefine < max_refines; nrefine++) {
// Add duplicate of FG disparity and FG+BG disparity (FG where no BG) for visual comparison
if (clt_parameters.rig.mll_max_refines_bg > 0) {
for (int nTile =0; nTile < combo_dsn_change[0].length; nTile++) {
combo_dsn_final[combo_dsn_indx_disp_fg][nTile] = combo_dsn_final[combo_dsn_indx_disp][nTile];
if (Double.isNaN(combo_dsn_final[combo_dsn_indx_disp_bg][nTile])) {
combo_dsn_final[combo_dsn_indx_disp_bg_all][nTile] = combo_dsn_final[combo_dsn_indx_disp][nTile];
} else {
combo_dsn_final[combo_dsn_indx_disp_bg_all][nTile] = combo_dsn_final[combo_dsn_indx_disp_bg][nTile];
}
}
}
// restore modified parameters
clt_parameters.img_dtt.bimax_combine_mode = save_bimax_combine_mode;
clt_parameters.img_dtt.bimax_dual_only = save_bimax_dual_only;
if (dbg_corr_scale != null) {
(new ShowDoubleFloatArrays()).showArrays(
dbg_corr_scale,
......@@ -4562,13 +4620,14 @@ public class OpticalFlow {
true,
"combo_dsn-"+ref_scene.getImageName(),
combo_dsn_titles); // dsrbg_titles);
(new ShowDoubleFloatArrays()).showArrays(
combo_dsn_final,
tilesX,
tilesY,
true,
"combo_dsn-final-"+ref_scene.getImageName(),
combo_dsn_titles); // dsrbg_titles);
combo_dsn_titles_full); // dsrbg_titles);
}
......@@ -4594,12 +4653,12 @@ public class OpticalFlow {
rslt_suffix = "-INTER-INTRA";
rslt_suffix += (clt_parameters.correlate_lma?"-LMA":"-NOLMA");
ref_scene.saveDoubleArrayInModelDirectory(
rslt_suffix, // String suffix,
combo_dsn_titles, // null, // String [] labels, // or null
combo_dsn_final, // dbg_data, // double [][] data,
tilesX, // int width,
tilesY); // int height)
ref_scene.saveDoubleArrayInModelDirectory( // error
rslt_suffix, // String suffix,
combo_dsn_titles_full, // null, // String [] labels, // or null
combo_dsn_final, // dbg_data, // double [][] data,
tilesX, // int width,
tilesY); // int height)
// save combo_dsn_change to model directory
......
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