Commit 2a11eb19 authored by Andrey Filippov's avatar Andrey Filippov

Debugging LMA-based LY measurement, added initial LY estimation, more

model functions
parent 6293946d
...@@ -301,6 +301,13 @@ public class CLTParameters { ...@@ -301,6 +301,13 @@ public class CLTParameters {
private double lym_change_aux = 1e-4; // same for aux camera (currntly)lwir private double lym_change_aux = 1e-4; // same for aux camera (currntly)lwir
public double lym_poly_change = 0.002; // Parameter vector difference to exit from polynomial correction public double lym_poly_change = 0.002; // Parameter vector difference to exit from polynomial correction
public boolean lym_mod_map = true; // Modify preliminary disparity map before running LY
public boolean lym_top_bg = true; // All above found BG is also BG (valid for most, but not all scenes)
public int lym_fill_gaps_bg = 0; // fill small gaps in found background
public int lym_fill_gaps_combo = 2; // 1 - in 4 directions by 1, 2 - in 8 directions by 1,
public boolean lym_use_strength = true; // Use strength when averaging disparity from neighbors
public double lym_scale_deriv_str=0.5; // Scale strength of the interpolated tiles from average neighbors strength
public boolean lyf_filter = false; // Filter lazy eye pairs by their values public boolean lyf_filter = false; // Filter lazy eye pairs by their values
public int lyf_smpl_side = 3; // 8 x8 masked, 16x16 sampled public int lyf_smpl_side = 3; // 8 x8 masked, 16x16 sampled
public double lyf_rms_max = 0.1; // Maximal RMS (all components to components average) public double lyf_rms_max = 0.1; // Maximal RMS (all components to components average)
...@@ -1190,15 +1197,20 @@ public class CLTParameters { ...@@ -1190,15 +1197,20 @@ public class CLTParameters {
properties.setProperty(prefix+"ly_disp_rvar_gt", this.ly_disp_rvar_gt +""); properties.setProperty(prefix+"ly_disp_rvar_gt", this.ly_disp_rvar_gt +"");
properties.setProperty(prefix+"ly_norm_disp", this.ly_norm_disp +""); properties.setProperty(prefix+"ly_norm_disp", this.ly_norm_disp +"");
properties.setProperty(prefix+"lym_overexp", this.lym_overexp +""); properties.setProperty(prefix+"lym_overexp", this.lym_overexp +"");
properties.setProperty(prefix+"lym_dbg_path", this.lym_dbg_path +""); properties.setProperty(prefix+"lym_dbg_path", this.lym_dbg_path +"");
properties.setProperty(prefix+"lym_update_disp", this.lym_update_disp+""); properties.setProperty(prefix+"lym_update_disp", this.lym_update_disp+"");
properties.setProperty(prefix+"lym_iter", this.lym_iter+""); properties.setProperty(prefix+"lym_iter", this.lym_iter+"");
properties.setProperty(prefix+"lym_change", this.lym_change +""); properties.setProperty(prefix+"lym_change", this.lym_change +"");
properties.setProperty(prefix+"lym_change_aux", this.lym_change_aux +""); properties.setProperty(prefix+"lym_change_aux", this.lym_change_aux +"");
properties.setProperty(prefix+"lym_poly_change", this.lym_poly_change +""); properties.setProperty(prefix+"lym_poly_change", this.lym_poly_change +"");
properties.setProperty(prefix+"lym_mod_map", this.lym_mod_map +"");
properties.setProperty(prefix+"lym_top_bg", this.lym_top_bg +"");
properties.setProperty(prefix+"lym_fill_gaps_bg", this.lym_fill_gaps_bg +"");
properties.setProperty(prefix+"lym_fill_gaps_combo", this.lym_fill_gaps_combo +"");
properties.setProperty(prefix+"lym_use_strength", this.lym_use_strength +"");
properties.setProperty(prefix+"lym_scale_deriv_str", this.lym_scale_deriv_str +"");
properties.setProperty(prefix+"lyf_filter", this.lyf_filter+""); properties.setProperty(prefix+"lyf_filter", this.lyf_filter+"");
properties.setProperty(prefix+"lyf_smpl_side", this.lyf_smpl_side+""); properties.setProperty(prefix+"lyf_smpl_side", this.lyf_smpl_side+"");
properties.setProperty(prefix+"lyf_rms_max", this.lyf_rms_max +""); properties.setProperty(prefix+"lyf_rms_max", this.lyf_rms_max +"");
...@@ -2007,9 +2019,15 @@ public class CLTParameters { ...@@ -2007,9 +2019,15 @@ public class CLTParameters {
if (properties.getProperty(prefix+"lym_iter")!=null) this.lym_iter=Integer.parseInt(properties.getProperty(prefix+"lym_iter")); if (properties.getProperty(prefix+"lym_iter")!=null) this.lym_iter=Integer.parseInt(properties.getProperty(prefix+"lym_iter"));
if (properties.getProperty(prefix+"lym_change")!=null) this.lym_change=Double.parseDouble(properties.getProperty(prefix+"lym_change")); if (properties.getProperty(prefix+"lym_change")!=null) this.lym_change=Double.parseDouble(properties.getProperty(prefix+"lym_change"));
if (properties.getProperty(prefix+"lym_change_aux")!=null) this.lym_change_aux=Double.parseDouble(properties.getProperty(prefix+"lym_change_aux")); if (properties.getProperty(prefix+"lym_change_aux")!=null) this.lym_change_aux=Double.parseDouble(properties.getProperty(prefix+"lym_change_aux"));
if (properties.getProperty(prefix+"lym_poly_change")!=null) this.lym_poly_change=Double.parseDouble(properties.getProperty(prefix+"lym_poly_change")); if (properties.getProperty(prefix+"lym_poly_change")!=null) this.lym_poly_change=Double.parseDouble(properties.getProperty(prefix+"lym_poly_change"));
if (properties.getProperty(prefix+"lym_mod_map")!=null) this.lym_mod_map=Boolean.parseBoolean(properties.getProperty(prefix+"lym_mod_map"));
if (properties.getProperty(prefix+"lym_top_bg")!=null) this.lym_top_bg=Boolean.parseBoolean(properties.getProperty(prefix+"lym_top_bg"));
if (properties.getProperty(prefix+"lym_fill_gaps_bg")!=null) this.lym_fill_gaps_bg=Integer.parseInt(properties.getProperty(prefix+"lym_fill_gaps_bg"));
if (properties.getProperty(prefix+"lym_fill_gaps_combo")!=null) this.lym_fill_gaps_combo=Integer.parseInt(properties.getProperty(prefix+"lym_fill_gaps_combo"));
if (properties.getProperty(prefix+"lym_use_strength")!=null) this.lym_use_strength=Boolean.parseBoolean(properties.getProperty(prefix+"lym_use_strength"));
if (properties.getProperty(prefix+"lym_scale_deriv_str")!=null) this.lym_scale_deriv_str=Double.parseDouble(properties.getProperty(prefix+"lym_scale_deriv_str"));
if (properties.getProperty(prefix+"lyf_filter")!=null) this.lyf_filter=Boolean.parseBoolean(properties.getProperty(prefix+"lyf_filter")); if (properties.getProperty(prefix+"lyf_filter")!=null) this.lyf_filter=Boolean.parseBoolean(properties.getProperty(prefix+"lyf_filter"));
if (properties.getProperty(prefix+"lyf_smpl_side")!=null) this.lyf_smpl_side=Integer.parseInt(properties.getProperty(prefix+"lyf_smpl_side")); if (properties.getProperty(prefix+"lyf_smpl_side")!=null) this.lyf_smpl_side=Integer.parseInt(properties.getProperty(prefix+"lyf_smpl_side"));
if (properties.getProperty(prefix+"lyf_rms_max")!=null) this.lyf_rms_max=Double.parseDouble(properties.getProperty(prefix+"lyf_rms_max")); if (properties.getProperty(prefix+"lyf_rms_max")!=null) this.lyf_rms_max=Double.parseDouble(properties.getProperty(prefix+"lyf_rms_max"));
...@@ -2908,9 +2926,23 @@ public class CLTParameters { ...@@ -2908,9 +2926,23 @@ public class CLTParameters {
gd.addNumericField("Maximal number of iterations", this.lym_iter, 0); gd.addNumericField("Maximal number of iterations", this.lym_iter, 0);
gd.addNumericField("Parameter vector difference to exit (main camera)", this.lym_change, 10,12,""); gd.addNumericField("Parameter vector difference to exit (main camera)", this.lym_change, 10,12,"");
gd.addNumericField("Parameter vector difference to exit (aux camera)", this.lym_change_aux, 10,12,""); gd.addNumericField("Parameter vector difference to exit (aux camera)", this.lym_change_aux, 10,12,"");
gd.addNumericField("Parameter vector difference to exit from polynomial correction", this.lym_poly_change, 10); gd.addNumericField("Parameter vector difference to exit from polynomial correction", this.lym_poly_change, 10);
gd.addMessage ("--- Lazy eye data preparation ---");
gd.addCheckbox ("Modify preliminary disparity map before running LY", this.lym_mod_map,
"LY may tolerate some disparity errors when just pure LY is needed");
gd.addCheckbox ("Consider all above infinity to be infinity", this.lym_top_bg,
"Valid for many, but not all scenes, such as tree branches over sky background");
gd.addNumericField("Fill gaps in background selection", this.lym_fill_gaps_bg, 0, 2, "pix",
"1 - 1 pixel in 4 directions, 2 - 1 step in 8 directions, ...");
gd.addNumericField("Fill gaps in combo selection", this.lym_fill_gaps_combo, 0, 2, "pix",
"1 - 1 pixel in 4 directions, 2 - 1 step in 8 directions, ...");
gd.addCheckbox ("Use strength when averaging disparity from neighbors", this.lym_use_strength,
"Weight by strength when averaging missing disparity tiles, false - use equal weights");
gd.addNumericField("Scale strength of the interpolated tiles from average neighbors strength", this.lym_scale_deriv_str, 3, 6, "",
"Multiply average strength of neighbors when assigning to a missing tile");
gd.addMessage ("--- Lazy eye samples filter ---"); gd.addMessage ("--- Lazy eye samples filter ---");
gd.addCheckbox ("Filter lazy eye pairs by their values", this.lyf_filter); gd.addCheckbox ("Filter lazy eye pairs by their values", this.lyf_filter);
gd.addNumericField("Fileter sample side (if 8, 8 x8 masked, 16x16 sampled)", this.lyf_smpl_side, 0); gd.addNumericField("Fileter sample side (if 8, 8 x8 masked, 16x16 sampled)", this.lyf_smpl_side, 0);
...@@ -3851,6 +3883,13 @@ public class CLTParameters { ...@@ -3851,6 +3883,13 @@ public class CLTParameters {
this.lym_poly_change= gd.getNextNumber(); this.lym_poly_change= gd.getNextNumber();
this.lym_mod_map= gd.getNextBoolean();
this.lym_top_bg= gd.getNextBoolean();
this.lym_fill_gaps_bg = (int) gd.getNextNumber();
this.lym_fill_gaps_combo = (int) gd.getNextNumber();
this.lym_use_strength= gd.getNextBoolean();
this.lym_scale_deriv_str = gd.getNextNumber();
this.lyf_filter= gd.getNextBoolean(); this.lyf_filter= gd.getNextBoolean();
this.lyf_smpl_side= (int) gd.getNextNumber(); this.lyf_smpl_side= (int) gd.getNextNumber();
this.lyf_rms_max= gd.getNextNumber(); this.lyf_rms_max= gd.getNextNumber();
......
...@@ -504,6 +504,11 @@ public class CLTPass3d{ ...@@ -504,6 +504,11 @@ public class CLTPass3d{
} }
return strength; return strength;
} }
public void setStrength(double [] strength) {
this.strength = strength;
}
/** /**
* Get four pairs (original) correlation strength. Not a copy * Get four pairs (original) correlation strength. Not a copy
* @return line-scan array of per-tile horizontal pairs correlation strength by reference (not a copy) * @return line-scan array of per-tile horizontal pairs correlation strength by reference (not a copy)
......
...@@ -597,8 +597,11 @@ public class CorrVector{ // TODO: Update to non-quad (extract to a file first)? ...@@ -597,8 +597,11 @@ public class CorrVector{ // TODO: Update to non-quad (extract to a file first)?
} }
@Override @Override
public String toString() // USED in lwir public String toString() { // USED in lwir
{ return toString(false);
}
public String toString(boolean short_out) {
String s; String s;
double [] sym_vect = toSymArray(null); double [] sym_vect = toSymArray(null);
double [] v = new double [vector.length]; double [] v = new double [vector.length];
...@@ -649,6 +652,9 @@ public class CorrVector{ // TODO: Update to non-quad (extract to a file first)? ...@@ -649,6 +652,9 @@ public class CorrVector{ // TODO: Update to non-quad (extract to a file first)?
s+= "azimuth (right):"; for (int i = 0; i < n; i++) s += String.format(" %8.4fpx", azimuths[i]); s+=" (shift of the image center)\n"; s+= "azimuth (right):"; for (int i = 0; i < n; i++) s += String.format(" %8.4fpx", azimuths[i]); s+=" (shift of the image center)\n";
s+= "roll (CW): "; for (int i = 0; i < n; i++) s += String.format(" %8.4fpx", rolls[i]); s+=" (shift at the image half-width from the center)\n"; s+= "roll (CW): "; for (int i = 0; i < n; i++) s += String.format(" %8.4fpx", rolls[i]); s+=" (shift at the image half-width from the center)\n";
s+= "diff zoom (in): "; for (int i = 0; i < n; i++) s += String.format(" %8.4fpx", zooms[i]); s+=" (shift at the image half-width from the center)\n"; s+= "diff zoom (in): "; for (int i = 0; i < n; i++) s += String.format(" %8.4fpx", zooms[i]); s+=" (shift at the image half-width from the center)\n";
if (short_out) {
return s;
}
s += "Symmetrical vector:\n"; s += "Symmetrical vector:\n";
if (getNumSensors() == 4) { // Use arrows for quad camera only (but update to match new if (getNumSensors() == 4) { // Use arrows for quad camera only (but update to match new
// ← → ↑ ↓ ⇖ ⇗ ⇘ ⇙ ↔ ↺ ↻ // ← → ↑ ↓ ⇖ ⇗ ⇘ ⇙ ↔ ↺ ↻
......
...@@ -200,19 +200,12 @@ public class ExtrinsicAdjustment { ...@@ -200,19 +200,12 @@ public class ExtrinsicAdjustment {
public void showInput(double[][] data, String title) { public void showInput(double[][] data, String title) {
int clusters = clustersX * clustersY; int clusters = clustersX * clustersY;
// double [][] pixels = new double [ExtrinsicAdjustment.INDX_LENGTH+4][clusters];
// String [] titles = new String[ExtrinsicAdjustment.INDX_LENGTH+4];
// for (int i = 0; i < ExtrinsicAdjustment.INDX_LENGTH; i++) {
double [][] pixels = new double [indx_length + 4][clusters]; double [][] pixels = new double [indx_length + 4][clusters];
String [] titles = new String[indx_length + 4]; String [] titles = new String[indx_length + 4];
for (int i = 0; i < indx_length; i++) { for (int i = 0; i < indx_length; i++) {
// titles[i] = ExtrinsicAdjustment.DATA_TITLES[i]; // titles[i] = ExtrinsicAdjustment.DATA_TITLES[i];
titles[i] = data_titles[i]; titles[i] = data_titles[i];
} }
// titles[ExtrinsicAdjustment.INDX_LENGTH+0]="Force_disparity";
// titles[ExtrinsicAdjustment.INDX_LENGTH+1]="dx-sum";
// titles[ExtrinsicAdjustment.INDX_LENGTH+2]="dy_sum";
// titles[ExtrinsicAdjustment.INDX_LENGTH+3]="dd_sum";
titles[indx_length+0]="Force_disparity"; titles[indx_length+0]="Force_disparity";
titles[indx_length+1]="dx-sum"; titles[indx_length+1]="dx-sum";
titles[indx_length+2]="dy_sum"; titles[indx_length+2]="dy_sum";
...@@ -223,13 +216,10 @@ public class ExtrinsicAdjustment { ...@@ -223,13 +216,10 @@ public class ExtrinsicAdjustment {
for (int c = 0; c < data[cluster].length; c++) { for (int c = 0; c < data[cluster].length; c++) {
pixels[c][cluster] = data[cluster][c]; pixels[c][cluster] = data[cluster][c];
} }
for (int i = 0;i <4; i++) { for (int i = 0;i < num_sensors; i++) {
// pixels[ExtrinsicAdjustment.INDX_LENGTH+1][cluster] += 0.25 * data[cluster][ExtrinsicAdjustment.INDX_X0 + 2 * i]; pixels[indx_length+1][cluster] += data[cluster][INDX_X0 + 2 * i]/num_sensors;
// pixels[ExtrinsicAdjustment.INDX_LENGTH+2][cluster] += 0.25 * data[cluster][ExtrinsicAdjustment.INDX_X0 + 2 * i + 1]; pixels[indx_length+2][cluster] += data[cluster][INDX_X0 + 2 * i + 1]/num_sensors;
// pixels[ExtrinsicAdjustment.INDX_LENGTH+3][cluster] += 0.25 * data[cluster][ExtrinsicAdjustment.INDX_DD0 + i]; pixels[indx_length+3][cluster] += data[cluster][indx_dd0 + i]/num_sensors;
pixels[indx_length+1][cluster] += 0.25 * data[cluster][INDX_X0 + 2 * i];
pixels[indx_length+2][cluster] += 0.25 * data[cluster][INDX_X0 + 2 * i + 1];
pixels[indx_length+3][cluster] += 0.25 * data[cluster][indx_dd0 + i];
} }
} else { } else {
for (int c = 0; c < pixels.length; c++) { for (int c = 0; c < pixels.length; c++) {
...@@ -238,7 +228,6 @@ public class ExtrinsicAdjustment { ...@@ -238,7 +228,6 @@ public class ExtrinsicAdjustment {
} }
} }
if (force_disparity!=null) { if (force_disparity!=null) {
// pixels[ExtrinsicAdjustment.INDX_LENGTH][cluster] = force_disparity[cluster]?1.0:0.0;
pixels[indx_length][cluster] = force_disparity[cluster]?1.0:0.0; pixels[indx_length][cluster] = force_disparity[cluster]?1.0:0.0;
} }
} }
...@@ -250,6 +239,67 @@ public class ExtrinsicAdjustment { ...@@ -250,6 +239,67 @@ public class ExtrinsicAdjustment {
title, title,
titles); //ExtrinsicAdjustment.DATA_TITLES); titles); //ExtrinsicAdjustment.DATA_TITLES);
} }
public double [] weightedLY (
double [][] data, // may be difference between two LY
double [][] ref_data, // to use strength from it (or the same as data)
double min_strength) {
if (ref_data == null) ref_data = data;
double [] avg = new double [indx_length];
double [] weights = new double [data.length];
double sw = 0;
for (int cluster = 0; cluster < weights.length; cluster++) if ((ref_data[cluster] != null) && (data[cluster] != null) && !Double.isNaN (ref_data[cluster][INDX_STRENGTH])){
double w = ref_data[cluster][INDX_STRENGTH] - min_strength;
if (w < 0.0) w = 0.0;
weights[cluster] = w;
sw += w;
}
if (sw <= 0.0) {
return null;
}
for (int cluster = 0; cluster < weights.length; cluster++) {
weights[cluster] /= sw;
}
for (int n = 0; n < avg.length; n ++ ) {
for (int cluster = 0; cluster < weights.length; cluster++) {
if ((weights[cluster] > 0.0) && !Double.isNaN(data[cluster][n])){
avg[n] += weights[cluster] * data[cluster][n];
}
}
}
return avg;
}
public String stringWeightedLY(
double [][] data, // may be difference between two LY
double [][] ref_data, // to use strength from it
double min_strength,
int [] format,
String suffix)
{
String dfmt = "%"+format[0]+"."+format[1]+"f,";
String dfmta = "%"+format[0]+"."+(2*format[1])+"f";
String hfmt = "%"+(format[0]/2)+"d%"+(format[0]-format[0]/2)+"s,";
double [] avg = weightedLY (data, ref_data, min_strength);
String s = "";
double avg_dd = 0.0, avg_nd = 0.0, avg_x = 0.0, avg_y = 0.0;
for (int p = 0; p < num_sensors; p++) avg_dd += avg[indx_dd0 + p]/ num_sensors;
for (int p = 0; p < num_sensors; p++) avg_nd += avg[indx_nd0 + p]/ num_sensors;
for (int p = 0; p < num_sensors; p++) avg_x += avg[INDX_X0 + 2 * p + 0]/ num_sensors;
for (int p = 0; p < num_sensors; p++) avg_y += avg[INDX_X0 + 2 * p + 1]/ num_sensors;
s +="diff_disparity = "+String.format(dfmt, avg[INDX_DIFF])+"\n";
s += "Port"+suffix+": [";
for (int p = 0; p < num_sensors; p++) s += String.format(hfmt, p, "");s+="]\n";
s += "DD"+suffix+"= [";
for (int p = 0; p < num_sensors; p++) s += String.format(dfmt, avg[indx_dd0 + p]);s+="]" + String.format(" # avg = "+dfmta+"\n", avg_dd);
s += "ND"+suffix+"= [";
for (int p = 0; p < num_sensors; p++) s += String.format(dfmt, avg[indx_nd0 + p]);s+="]" + String.format(" # avg = "+dfmta+"\n", avg_nd);
s += "DX"+suffix+"= [";
for (int p = 0; p < num_sensors; p++) s += String.format(dfmt, avg[INDX_X0 + 2 * p + 0]);s+="]" + String.format(" # avg = "+dfmta+"\n", avg_x);
s += "DY"+suffix+"= [";
for (int p = 0; p < num_sensors; p++) s += String.format(dfmt, avg[INDX_X0 + 2 * p + 1]);s+="]" + String.format(" # avg = "+dfmta+"\n", avg_y);
return s;
}
/* /*
public static void showLYInput( public static void showLYInput(
double[][] data, double[][] data,
......
...@@ -5035,6 +5035,12 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -5035,6 +5035,12 @@ public class QuadCLT extends QuadCLTCPU {
clt_parameters.shift_y, // final double shiftY, // shift image vertically (positive - down) clt_parameters.shift_y, // final double shiftY, // shift image vertically (positive - down)
clt_parameters.tileStep, // final int tileStep, // process tileStep x tileStep cluster of tiles when adjusting lazy eye parameters clt_parameters.tileStep, // final int tileStep, // process tileStep x tileStep cluster of tiles when adjusting lazy eye parameters
clt_parameters.img_dtt.getMcorrSelLY(getNumSensors()), // final int mcorr_sel, // +1 - all, +2 - dia, +4 - sq, +8 - neibs, +16 - hor + 32 - vert clt_parameters.img_dtt.getMcorrSelLY(getNumSensors()), // final int mcorr_sel, // +1 - all, +2 - dia, +4 - sq, +8 - neibs, +16 - hor + 32 - vert
clt_parameters.img_dtt.mcorr_comb_width, // final int mcorr_comb_width, // combined correlation tile width
clt_parameters.img_dtt.mcorr_comb_height, // final int mcorr_comb_height, // combined correlation tile full height
clt_parameters.img_dtt.mcorr_comb_offset, // final int mcorr_comb_offset, // combined correlation tile height offset: 0 - centered (-height/2 to height/2), height/2 - only positive (0 to height)
clt_parameters.img_dtt.mcorr_comb_disp, // final double mcorr_comb_disp, // Combined tile per-pixel disparity for baseline == side of a square
clt_parameters.tileX, // final int debug_tileX, clt_parameters.tileX, // final int debug_tileX,
clt_parameters.tileY, // final int debug_tileY, clt_parameters.tileY, // final int debug_tileY,
threadsMax, // final int threadsMax, // maximal number of threads to launch threadsMax, // final int threadsMax, // maximal number of threads to launch
......
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