Commit 8d033226 authored by Andrey Filippov's avatar Andrey Filippov

Optional common gains for all pairs

parent c3ee5b3f
......@@ -4410,14 +4410,7 @@ public class Correlation2d {
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) ;
// TODO: Remove me
debug_graphic |= true;
/*
String dbg_title = null;
if (debug_graphic) {
dbg_title = String.format("tX%d_tY%d",tileX,tileY);
}
*/
double [][] dbg_corr = debug_graphic ? new double [corrs.length][] : null;
DoubleGaussianBlur gb = null;
if (imgdtt_params.lma_sigma > 0) gb = new DoubleGaussianBlur();
......@@ -4449,50 +4442,69 @@ public class Correlation2d {
double [][] disp_str_all;
double [][][] own_masks;
double [][][] pair_offsets;
boolean [] common_scale; // = {false,false}; // true}; {true,true}; // // TODO: implement
if (lma_corr_weights0.length < 2) {
pair_offsets = pair_offsets0;
lma_corr_weights = lma_corr_weights0;
disp_str_all = disp_str_dual;
own_masks = own_masks0;
} else {
int nearest_max = (Math.abs(disp_str_dual[0][0]) < Math.abs(disp_str_dual[0][0]))? 0 : 1;
int fg_max = (disp_str_dual[0][0] > disp_str_dual[0][0]) ? 0 : 1;
common_scale = new boolean[] {imgdtt_params.bimax_common_fg};
} else { // only 2 max are supported
if (lma_corr_weights0.length > 2) {
System.out.println("corrLMA2DualMax(): 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 0: // keep both
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;
}
break;
case 1: // keep strongest
pair_offsets = new double [][][] {pair_offsets0 [0]};
lma_corr_weights = new double [][][] {lma_corr_weights0[0]};
disp_str_all = new double [][] {disp_str_dual [0]};
own_masks = new double [][][] {own_masks0 [0]};
common_scale = new boolean[] {(0 == fg_max) ? imgdtt_params.bimax_common_fg : imgdtt_params.bimax_common_bg};
break;
case 2: // keep nearest
pair_offsets = new double [][][] {pair_offsets0 [nearest_max]};
lma_corr_weights = new double [][][] {lma_corr_weights0[nearest_max]};
disp_str_all = new double [][] {disp_str_dual [nearest_max]};
own_masks = new double [][][] {own_masks0 [nearest_max]};
common_scale = new boolean[] {(nearest_max == fg_max) ? imgdtt_params.bimax_common_fg : imgdtt_params.bimax_common_bg};
break;
case 3: // keep foreground
pair_offsets = new double [][][] {pair_offsets0 [fg_max]};
lma_corr_weights = new double [][][] {lma_corr_weights0[fg_max]};
disp_str_all = new double [][] {disp_str_dual [fg_max]};
own_masks = new double [][][] {own_masks0 [fg_max]};
common_scale = new boolean[] {imgdtt_params.bimax_common_fg};
break;
case 4: // keep background
pair_offsets = new double [][][] {pair_offsets0 [1-fg_max]};
lma_corr_weights = new double [][][] {lma_corr_weights0[1-fg_max]};
disp_str_all = new double [][] {disp_str_dual [1-fg_max]};
own_masks = new double [][][] {own_masks0 [1-fg_max]};
common_scale = new boolean[] {imgdtt_params.bimax_common_bg};
break;
default: // keep both
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;
}
}
}
......@@ -4505,9 +4517,6 @@ public class Correlation2d {
int num_used_pairs = 0;
for (int npair = 0; npair < pair_mask.length; npair++) if ((corrs[npair] != null) && (pair_mask[npair])){
double [] corr_blur = null;
// if (npair == 65) {
// System.out.println("---npair == "+npair);
// }
if (imgdtt_params.cnvx_en) { // || (pair_shape_masks == null)) {
corr_blur = corrs[npair].clone();
if (corr_wnd_inv_limited != null) {
......@@ -4655,16 +4664,12 @@ public class Correlation2d {
for (int i = 0; i <disp_str_all.length; i++) if (disp_str_all[i] != null){
disp_str2[i][0] = disp_str_all[i];
}
// double [][] disp_str2 = {disp_str_all[0]}; // temporary // will be calculated/set later
boolean lmaSuccess = false;
// int num_lma_retries = 0;
// When running LMA - first do not touch disparity?
// int lma_pass = imgdtt_params.bimax_dual_pass? 0 : 1; // pass0 - w/o disparity, pass 1 - with
boolean [] adjust_disparities = new boolean [disp_str_all.length]; // all false;
boolean needprep = true; //t npass = 0;
for (int npass = (imgdtt_params.bimax_dual_pass? 00 : 1); npass < 2; npass++) { // may break while (!lmaSuccess) {
// num_lma_retries ++; // debug
for (int npass = (imgdtt_params.bimax_dual_pass? 0 : 1); npass < 2; npass++) { // may break while (!lmaSuccess) {
if (needprep) {
lma.preparePars(
disp_str2, // double [][][] disp_str_all, initial value of disparity [max][tile]{disp, strength}
......@@ -4679,8 +4684,10 @@ public class Correlation2d {
if (npass > 0) {
adjust_disparities = null;
}
// boolean [] common_scale = {false,false}; // true}; {true,true}; // // TODO: implement
lma.setParMask( // USED in lwir
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
imgdtt_params.lmas_adjust_ag, // boolean adjust_scales, // adjust 2D correlation scales - lma_adjust_ag
imgdtt_params.lmas_adjust_wy, // boolean adjust_ellipse, // allow non-circular correlation maximums lma_adjust_wy
......@@ -4713,6 +4720,7 @@ public class Correlation2d {
lma.updateFromVector();
double [][][] dispStrs = lma.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)
......@@ -4721,7 +4729,7 @@ 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
);
for (int nmax = 0; nmax < dispStrs.length; nmax++) if (dispStrs[nmax][0][1] <= 0) {
for (int nmax = 00; nmax < dispStrs.length; nmax++) if (dispStrs[nmax][0][1] <= 0) {
lmaSuccess = false;
break;
}
......@@ -4876,7 +4884,7 @@ public class Correlation2d {
int tileX, // just for debug output
int tileY){
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) || true;
debug_graphic |= imgdtt_params.lmamask_dbg && (debug_level > 0); // || true;
String dbg_title = null;
if (debug_graphic) {
dbg_title = String.format("tX%d_tY%d",tileX,tileY);
......
......@@ -2624,14 +2624,14 @@ public class ImageDtt extends ImageDttCPU {
}
if (debugTile1) {
System.out.println("clt_process_tl_correlations() maxes=");
for (int i = 0; i < maxes.length; i++) {
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]));
}
}
if (debugTile1) {
Corr2dLMA lma_dual = correlation2d.corrLMA2DualMax( // null pointer
imgdtt_params, // ImageDttParameters imgdtt_params,
0, // 3, // 0, // 1, // int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
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)
......
......@@ -85,6 +85,9 @@ public class ImageDttParameters {
public int bimax_min_num_samples = 4; // minimal number of samples per pair per maximum
public int bimax_min_num_pairs = 8; // minimal number of used pairs
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
//lmamask_
public boolean lmamask_dbg = false; // show LMA images, exit after single BG
......@@ -188,6 +191,9 @@ public class ImageDttParameters {
public boolean lmas_adjust_wm = true; // used in new for width
public boolean lmas_adjust_wy = true; // adjust non-circular
public boolean lmas_adjust_ag = true; // adjust gains gains
// Pre-lma poly
public double lmas_poly_str_scale = 1.0; // scale pre-lma poly strength
public double lmas_poly_str_min = 0.05; // ignore tiles with poly strength (scaled) below
......@@ -202,7 +208,8 @@ public class ImageDttParameters {
// Filtering and strength calculation
// High ratio of amplitudes may be caused by "neighbors" correlations when the same object disappears from the tile
// for small disparities 0.5...0.7 is OK, for larger, and small objects on uniform background, may need 0.2
public double lmas_min_amp = 0.25; // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
public double lmas_min_amp = 0.1; // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
public double lmas_min_amp_bg = 0.01; // same for background objects (all but fg)
public double lmas_max_rel_rms = 0.3; // LWIR16: 0.5 maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
public double lmas_min_strength = 0.7; // LWIR16: 0.4 minimal composite strength (sqrt(average amp squared over absolute RMS)
public double lmas_min_ac = 0.02; // LWIR16: 0.01 minimal of a and C coefficients maximum (measures sharpest point/line)
......@@ -475,6 +482,10 @@ public class ImageDttParameters {
"Do not use LMA if total number of used pairs is lower");
gd.addCheckbox ("Dual-pass LMA", this.bimax_dual_pass,
"First adjust other parameters (keeping disparities), then add disparities");
gd.addCheckbox ("Common gains for foreground/single correlation maximum", this.bimax_common_fg,
"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.addMessage("LMA samples filter based on estimated disparity");
gd.addCheckbox ("Debug LMA", this.lmamask_dbg,
......@@ -698,6 +709,8 @@ public class ImageDttParameters {
gd.addMessage("LMA (single) results filtering");
gd.addNumericField("Minimal weakest pair to strongest pair correlation amplitude ratio",this.lmas_min_amp, 6, 8, "",
"Discard tile if ratio of the weakest correlation pair amplitude to that of the strongest one is lower than this");
gd.addNumericField("Same for BG objects (dual max)", this.lmas_min_amp_bg, 6, 8, "",
"Discard tile if ratio of the weakest correlation pair amplitude to that of the strongest one is lower than this (BG objects, far maximum)");
gd.addNumericField("Maximal relative RMS ", this.lmas_max_rel_rms, 6, 8, "",
"Discard tile if ratio of RMS to average of min and max amplitude exceeds this value");
gd.addNumericField("Minimal composite strength", this.lmas_min_strength, 6, 8, "",
......@@ -892,6 +905,8 @@ public class ImageDttParameters {
this.bimax_min_num_samples= (int) gd.getNextNumber();
this.bimax_min_num_pairs= (int) gd.getNextNumber();
this.bimax_dual_pass = gd.getNextBoolean();
this.bimax_common_fg = gd.getNextBoolean();
this.bimax_common_bg = gd.getNextBoolean();
this.lmamask_dbg = gd.getNextBoolean();
this.lmamask_en = gd.getNextBoolean();
......@@ -1002,6 +1017,7 @@ public class ImageDttParameters {
this.lmas_rms_diff = gd.getNextNumber();
this.lmas_num_iter= (int) gd.getNextNumber();
this.lmas_min_amp = gd.getNextNumber();
this.lmas_min_amp_bg = gd.getNextNumber();
this.lmas_max_rel_rms = gd.getNextNumber();
this.lmas_min_strength = gd.getNextNumber();
this.lmas_min_ac = gd.getNextNumber();
......@@ -1119,6 +1135,8 @@ public class ImageDttParameters {
properties.setProperty(prefix+"bimax_min_num_samples", this.bimax_min_num_samples +"");
properties.setProperty(prefix+"bimax_min_num_pairs", this.bimax_min_num_pairs +"");
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+"lmamask_dbg", this.lmamask_dbg +"");
properties.setProperty(prefix+"lmamask_en", this.lmamask_en +"");
......@@ -1228,6 +1246,7 @@ public class ImageDttParameters {
properties.setProperty(prefix+"lmas_rms_diff", this.lmas_rms_diff +"");
properties.setProperty(prefix+"lmas_num_iter", this.lmas_num_iter +"");
properties.setProperty(prefix+"lmas_min_amp", this.lmas_min_amp +"");
properties.setProperty(prefix+"lmas_min_amp_bg", this.lmas_min_amp_bg +"");
properties.setProperty(prefix+"lmas_max_rel_rms", this.lmas_max_rel_rms +"");
properties.setProperty(prefix+"lmas_min_strength", this.lmas_min_strength +"");
properties.setProperty(prefix+"lmas_min_ac", this.lmas_min_ac +"");
......@@ -1350,6 +1369,8 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"bimax_min_num_samples")!=null) this.bimax_min_num_samples=Integer.parseInt(properties.getProperty(prefix+"bimax_min_num_samples"));
if (properties.getProperty(prefix+"bimax_min_num_pairs")!=null) this.bimax_min_num_pairs=Integer.parseInt(properties.getProperty(prefix+"bimax_min_num_pairs"));
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+"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"));
......@@ -1466,6 +1487,7 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"lmas_rms_diff")!=null) this.lmas_rms_diff=Double.parseDouble(properties.getProperty(prefix+"lmas_rms_diff"));
if (properties.getProperty(prefix+"lmas_num_iter")!=null) this.lmas_num_iter=Integer.parseInt(properties.getProperty(prefix+"lmas_num_iter"));
if (properties.getProperty(prefix+"lmas_min_amp")!=null) this.lmas_min_amp=Double.parseDouble(properties.getProperty(prefix+"lmas_min_amp"));
if (properties.getProperty(prefix+"lmas_min_amp_bg")!=null) this.lmas_min_amp_bg=Double.parseDouble(properties.getProperty(prefix+"lmas_min_amp_bg"));
if (properties.getProperty(prefix+"lmas_max_rel_rms")!=null) this.lmas_max_rel_rms=Double.parseDouble(properties.getProperty(prefix+"lmas_max_rel_rms"));
if (properties.getProperty(prefix+"lmas_min_strength")!=null) this.lmas_min_strength=Double.parseDouble(properties.getProperty(prefix+"lmas_min_strength"));
if (properties.getProperty(prefix+"lmas_min_ac")!=null) this.lmas_min_ac=Double.parseDouble(properties.getProperty(prefix+"lmas_min_ac"));
......@@ -1598,6 +1620,8 @@ public class ImageDttParameters {
idp.bimax_min_num_samples= this.bimax_min_num_samples;
idp.bimax_min_num_pairs= this.bimax_min_num_pairs;
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.lmamask_dbg= this.lmamask_dbg;
idp.lmamask_en= this.lmamask_en;
......@@ -1705,6 +1729,7 @@ public class ImageDttParameters {
idp.lmas_rms_diff = this.lmas_rms_diff;
idp.lmas_num_iter = this.lmas_num_iter;
idp.lmas_min_amp= this.lmas_min_amp;
idp.lmas_min_amp_bg= this.lmas_min_amp_bg;
idp.lmas_max_rel_rms= this.lmas_max_rel_rms;
idp.lmas_min_strength= this.lmas_min_strength;
idp.lmas_min_ac= this.lmas_min_ac;
......
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