Commit 73772bcb authored by Andrey Filippov's avatar Andrey Filippov

Testing/debugging

parent a398d330
......@@ -1755,6 +1755,7 @@ public class Correlation2d {
public Corr2dLMA corrLMA2( // USED in lwir
ImageDttParameters imgdtt_params,
double [][] corr_wnd, // correlation window to save on re-calculation of the window
double [] corr_wnd_limited, // correlation window, limited not to be smaller than threshold - used for finding max/convex areas (or null)
double [][] corrs,
double [][] disp_dist, // per camera disparity matrix as a 1d (linescan order)
int pair_mask, // which pairs to process
......@@ -1791,6 +1792,11 @@ public class Correlation2d {
for (int npair = 0; npair < corrs.length; npair++) if ((corrs[npair] != null) && (((pair_mask >> npair) & 1) !=0)){
double[] corr = corrs[npair].clone();
if (corr_wnd_limited != null) {
for (int i = 0; i < corr.length; i++) {
corr[i] /= corr_wnd_limited[i];
}
}
if (sigma > 0) {
gb.blurDouble(corr, corr_size, corr_size, sigma, sigma, 0.01);
}
......@@ -1853,10 +1859,13 @@ public class Correlation2d {
imgdtt_params.lma_adjust_wm, // boolean adjust_width, // adjust width of the maximum - lma_adjust_wm
imgdtt_params.lma_adjust_ag, // boolean adjust_scales, // adjust 2D correlation scales - lma_adjust_ag
imgdtt_params.lma_adjust_wy, // boolean adjust_ellipse, // allow non-circular correlation maximums lma_adjust_wy
imgdtt_params.lma_adjust_wxy, // boolean adjust_lazyeye, // adjust disparity corrections and orthogonal disparities lma_adjust_wxy
imgdtt_params.lma_adjust_wxy, // boolean adjust_lazyeye_par, // adjust disparity corrections parallel to disparities lma_adjust_wxy
imgdtt_params.lma_adjust_ly1, // boolean adjust_lazyeye_ortho, // adjust disparity corrections orthogonal to disparities lma_adjust_ly1
xcenter, // double disp0, // initial value of disparity
imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width
imgdtt_params.lma_cost_wy // double cost_lazyeye // cost for each of the non-zero disparity corrections and ortho disparity lma_cost_wy
imgdtt_params.lma_cost_wy, // double cost_lazyeye_par, // cost for each of the non-zero disparity corrections lma_cost_wy
imgdtt_params.lma_cost_wxy // double cost_lazyeye_odtho // cost for each of the non-zero ortho disparity corrections lma_cost_wxy
);
lma.setMatrices(disp_dist);
lma.initMatrices(); // should be called after initVector and after setMatrices
......@@ -1864,6 +1873,8 @@ public class Correlation2d {
if (debug_level > 1) {
System.out.println("Input data:");
lma.printInputDataFx(false);
lma.printParams();
}
lmaSuccess = lma.runLma(
......@@ -1878,7 +1889,7 @@ public class Correlation2d {
lma.updateFromVector();
double [] rms = lma.getRMS();
if (debug_level > 0) {
System.out.println("LMA ->"+lmaSuccess+" RMS="+rms[0]+", pure RMS="+rms[1]);
System.out.println("LMA -> "+lmaSuccess+" RMS="+rms[0]+", pure RMS="+rms[1]);
lma.printParams();
}
......@@ -1886,6 +1897,31 @@ public class Correlation2d {
System.out.println("Input data and approximation:");
lma.printInputDataFx(true);
}
if (debug_graphic && lmaSuccess) {
String [] sliceTitles = lma.dbgGetSliceTiles();
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(0),
corr_size,
corr_size,
true,
"corr_values"+"_x"+tileX+"_y"+tileY, sliceTitles);
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(1),
corr_size,
corr_size,
true,
"corr_weights"+"_x"+tileX+"_y"+tileY, sliceTitles);
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(2),
corr_size,
corr_size,
true,
"corr_fx"+"_x"+tileX+"_y"+tileY, sliceTitles);
}
return lmaSuccess? lma: null;
}
......@@ -2314,6 +2350,7 @@ public class Correlation2d {
* @return cost packed array, corresponding to the input. selected convex points have weight
* 1.0, other selected - nc_cost
*/
public double [] filterConvex(// USED in lwir
double [] corr_data,
int hwin,
......
......@@ -1576,6 +1576,12 @@ public class ImageDtt {
final int globalDebugLevel)
{
final boolean debug_distort= true;
// final double [][] debug_offsets = null;
// final double [][] debug_offsets = {{0.5, 0.5},{0.0,0.0},{0.0,0.0},{-0.5,-0.5}}; // add to calculated CenterXY for evaluating new LMA
// final double [][] debug_offsets = {{ 0.5, 0.5},{ 0.5,-0.5},{-0.5, 0.5},{-0.5,-0.5}}; // add to calculated CenterXY for evaluating new LMA
// final double [][] debug_offsets = {{ 0.5, 0.0},{ -0.5, 0.0},{-0.5, 0.0},{ 0.5, 0.0}}; // add to calculated CenterXY for evaluating new LMA
// final double [][] debug_offsets = {{ 1.0, 0.0},{ -1.0, 0.0},{-1.0, 0.0},{ 1.0, 0.0}}; // add to calculated CenterXY for evaluating new LMA
final double [][] debug_offsets = {{ 0.0, 1.0},{ 0.0, -1.0},{ 0.0, -1.0},{ 0.0, 1.0}}; // add to calculated CenterXY for evaluating new LMA
final boolean macro_mode = macro_scale != 1; // correlate tile data instead of the pixel data
final int quad = 4; // number of subcameras
final int numcol = 3; // number of colors // keep the same, just do not use [0] and [1], [2] - green
......@@ -1792,6 +1798,18 @@ public class ImageDtt {
double [][][][] tcorr_tpartial = null; // [quad][numcol+1][4][8*8]
double [] ports_rgb = null;
double [][] corr_wnd = (new Corr2dLMA(transform_size, null)).getCorrWnd();
double [] corr_wnd_limited = null;
if (imgdtt_params.lma_min_wnd <= 1.0) {
corr_wnd_limited = new double [corr_wnd.length * corr_wnd[0].length];
int indx = 0;
for (int i = 0; i < corr_wnd.length; i++) {
for (int j = 0; j < corr_wnd[i].length; j++) {
corr_wnd_limited[indx++] = Math.max(corr_wnd[i][j], imgdtt_params.lma_min_wnd);
}
}
}
Correlation2d corr2d = new Correlation2d(
imgdtt_params, // ImageDttParameters imgdtt_params,
transform_size, // int transform_size,
......@@ -1834,7 +1852,7 @@ public class ImageDtt {
}
if (macro_mode){
if ((globalDebugLevel > -1) && (tileX == debug_tileX) && (tileY == debug_tileY)) { // before correction
if ((globalDebugLevel > -1) && debugTile) { // before correction
System.out.println("\nUsing MACRO mode, centerX="+centerX+", centerY="+centerY);
}
centersXY = geometryCorrection.getPortsCoordinatesIdeal(
......@@ -1870,13 +1888,33 @@ public class ImageDtt {
disparity_array[tileY][tileX] + disparity_corr);
}
if ((globalDebugLevel > 0) && (tileX == debug_tileX) && (tileY == debug_tileY)) {
if (((globalDebugLevel > 0) || debug_distort) && debugTile) {
for (int i = 0; i < quad; i++) {
System.out.println("clt_aberrations_quad_corr(): tileX="+tileX+", tileY="+tileY+
" centerX="+centerX+" centerY="+centerY+" disparity="+disparity_array[tileY][tileX]+
" centersXY["+i+"][0]="+centersXY[i][0]+" centersXY["+i+"][1]="+centersXY[i][1]);
}
}
if (debug_distort && debugTile && (debug_offsets != null)) {
double [][] debug_offsets_xy = new double [debug_offsets.length][2];
for (int i = 0; i < debug_offsets.length; i++) {
debug_offsets_xy[i][0] = disp_dist[i][0] * debug_offsets[i][0] + disp_dist[i][1] * debug_offsets[i][1];
debug_offsets_xy[i][1] = disp_dist[i][2] * debug_offsets[i][0] + disp_dist[i][3] * debug_offsets[i][1];
}
for (int i = 0; i < quad; i++) {
System.out.println(String.format("%d: {%8.3f, %8.3f}",i,debug_offsets_xy[i][0],debug_offsets_xy[i][1]));
}
for (int i = 0; i < debug_offsets.length; i++) {
centersXY[i][0] += debug_offsets_xy[i][0];
centersXY[i][1] += debug_offsets_xy[i][1];
}
for (int i = 0; i < quad; i++) {
System.out.println("Corrected clt_aberrations_quad_corr(): tileX="+tileX+", tileY="+tileY+
" centerX="+centerX+" centerY="+centerY+" disparity="+disparity_array[tileY][tileX]+
" centersXY["+i+"][0]="+centersXY[i][0]+" centersXY["+i+"][1]="+centersXY[i][1]);
}
}
if ((globalDebugLevel > -1) && (tileX == debug_tileX) && (tileY == debug_tileY)) { // before correction
System.out.print(disparity_array[tileY][tileX]+"\t"+
......@@ -2305,6 +2343,7 @@ public class ImageDtt {
Corr2dLMA lma2 = corr2d.corrLMA2(
imgdtt_params, // ImageDttParameters imgdtt_params,
corr_wnd, // double [][] corr_wnd, // correlation window to save on re-calculation of the window
corr_wnd_limited, // corr_wnd_limited, // correlation window, limited not to be smaller than threshold - used for finding max/convex areas (or null)
corrs, // double [][] corrs,
disp_dist,
imgdtt_params.dbg_pair_mask, // int pair_mask, // which pairs to process
......@@ -2312,7 +2351,7 @@ public class ImageDtt {
0.5, // double sigma, // low-pass sigma to find maximum (and convex too
corr_stat[0], // double xcenter, // preliminary center x in pixels for largest baseline
imgdtt_params.ortho_vasw_pwr, // double vasw_pwr, // value as weight to this power,
tile_lma_debug_level, // int debug_level,
tile_lma_debug_level+2, // int debug_level,
tileX, // int tileX, // just for debug output
tileY ); // int tileY
......@@ -2337,6 +2376,16 @@ public class ImageDtt {
tileX, // int tileX, // just for debug output
tileY ); // int tileY
double [] lma_disparity_strength = null;
double max_disp_diff_lma = 3.0;
if (lma != null) {
lma_disparity_strength = lma.getDisparityStrength();
if (Math.abs(lma_disparity_strength[0] - disparity ) > max_disp_diff_lma) {
if (globalDebugLevel > -1) {
System.out.println("Crazy LMA for tileX="+tileX+", tileY="+tileY+": disparity="+disparity+",lma_disparity_strength[0]="+lma_disparity_strength[0]);
}
lma = null;
}
}
if (lma != null) {
double [] mod_disparity_diff = null;
double [][] dir_corr_strength = null;
......
......@@ -95,16 +95,18 @@ public class ImageDttParameters {
// LMA parameters
public boolean lma_adjust_wm = true; // used in new for width
public boolean lma_adjust_wy = false; // used in new for ellipse
public boolean lma_adjust_wxy = true; // used in new for lazy eye
public boolean lma_adjust_ag = true;// used in new for gains
public boolean lma_adjust_wy = true; // false; // used in new for ellipse
public boolean lma_adjust_wxy = true; // used in new for lazy eye adjust parallel-to-disparity correction
public boolean lma_adjust_ly1 = true; // adjust ortho-to-disparity correction
public boolean lma_adjust_ag = true; // used in new for gains
// new LMA parameters
public double lma_min_wnd = 0.4; // divide values by the 2D correlation window if it is >= this value for finding maximums and convex areas
// maybe try using sqrt (corr_wnd) ? or variable power?
public double lma_half_width = 2.0; //
public double lma_cost_wy = 0.1; //
public double lma_cost_wxy = 0.1; //
public double lma_cost_wy = 0.003; // cost of parallel-to-disparity correction
public double lma_cost_wxy = 0.003; // cost of ortho-to-disparity correction
public double lma_lambda_initial = 0.1; //
public double lma_lambda_scale_good = 0.5; //
......@@ -246,16 +248,23 @@ public class ImageDttParameters {
"Allow fitting of the half-width common for all pairs, defined by the LPF filter of the phase correlation");
gd.addCheckbox ("Adjust ellipse parameters (was Fit extra vertical half-width)", this.lma_adjust_wy,
"Adjust ellipse (non-circular) of the correlation maximum (was Fit extra perpendicular to disparity half-width (not used? and only possible with multi-baseline cameras))");
gd.addCheckbox ("Adjust \"lazy eye\" paramdeters (was Fit extra half-width along disparity direction)", this.lma_adjust_wxy,
gd.addCheckbox ("Adjust \"lazy eye\" parameters parallel to disparity (was Fit extra half-width along disparity)", this.lma_adjust_wxy,
"Increased width in disparity direction caused by multi-distance objects in the tile");
gd.addCheckbox ("Adjust \"lazy eye\" parameters orthogonal CW to disparity", this.lma_adjust_ly1,
"Increased width in disparity direction caused by multi-distance objects in the tile");
gd.addCheckbox ("Adjust per-pair scale (was Adjust per-group amplitudes)", this.lma_adjust_ag,
"Each correlation pair gain (was Each correlation type's amplitude (now always needed))");
gd.addNumericField("Minimal window value for normalization during max/convex", this.lma_min_wnd, 3, 6, "",
"divide values by the 2D correlation window if it is >= this value for finding maximums and convex areas");
gd.addNumericField("Initial/expected half-width of the correlation maximum in both directions", this.lma_half_width, 3, 6, "pix",
"With LPF sigma = 0.9 it seems to be ~= 2.0. Used both as initial parameter and the fitted value difference from this may be penalized");
gd.addNumericField("Cost of the difference of the actual half-width from the expected one", this.lma_cost_wy, 5, 8, "",
gd.addNumericField("Lazy eye cost parallel to disparity (was Cost of the difference of the actual half-width...)", this.lma_cost_wy, 5, 8, "",
"The higher this cost, the more close the fitted half-width will be to the expected one");
gd.addNumericField("Cost of the difference between horizontal and vertical widths", this.lma_cost_wxy, 5, 8, "",
gd.addNumericField("Lazy eye cost ortho to disparity (was Cost of hor / vert widths difference)", this.lma_cost_wxy, 5, 8, "",
"Tries to enforce equal width and hight of the correlation maximum");
gd.addNumericField("Initial value of LMA lambda", this.lma_lambda_initial, 3, 6, "",
......@@ -351,8 +360,11 @@ public class ImageDttParameters {
this.lma_adjust_wm= gd.getNextBoolean();
this.lma_adjust_wy= gd.getNextBoolean();
this.lma_adjust_wxy= gd.getNextBoolean();
this.lma_adjust_ly1= gd.getNextBoolean();
this.lma_adjust_ag= gd.getNextBoolean();
this.lma_min_wnd = gd.getNextNumber();
this.lma_half_width = gd.getNextNumber();
this.lma_cost_wy = gd.getNextNumber();
this.lma_cost_wxy = gd.getNextNumber();
......@@ -440,8 +452,12 @@ public class ImageDttParameters {
properties.setProperty(prefix+"lma_adjust_wm", this.lma_adjust_wm +"");
properties.setProperty(prefix+"lma_adjust_wy", this.lma_adjust_wy +"");
properties.setProperty(prefix+"lma_adjust_wxy", this.lma_adjust_wxy +"");
properties.setProperty(prefix+"lma_adjust_ly1", this.lma_adjust_ly1 +"");
properties.setProperty(prefix+"lma_adjust_ag", this.lma_adjust_ag +"");
properties.setProperty(prefix+"lma_min_wnd", this.lma_min_wnd +"");
properties.setProperty(prefix+"lma_half_width", this.lma_half_width +"");
properties.setProperty(prefix+"lma_cost_wy", this.lma_cost_wy +"");
properties.setProperty(prefix+"lma_cost_wxy", this.lma_cost_wxy +"");
......@@ -533,8 +549,13 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"lma_adjust_wm")!=null) this.lma_adjust_wm=Boolean.parseBoolean(properties.getProperty(prefix+"lma_adjust_wm"));
if (properties.getProperty(prefix+"lma_adjust_wy")!=null) this.lma_adjust_wy=Boolean.parseBoolean(properties.getProperty(prefix+"lma_adjust_wy"));
if (properties.getProperty(prefix+"lma_adjust_wxy")!=null) this.lma_adjust_wxy=Boolean.parseBoolean(properties.getProperty(prefix+"lma_adjust_wxy"));
if (properties.getProperty(prefix+"lma_adjust_ly1")!=null) this.lma_adjust_ly1=Boolean.parseBoolean(properties.getProperty(prefix+"lma_adjust_ly1"));
if (properties.getProperty(prefix+"lma_adjust_ag")!=null) this.lma_adjust_ag=Boolean.parseBoolean(properties.getProperty(prefix+"lma_adjust_ag"));
if (properties.getProperty(prefix+"lma_min_wnd")!=null) this.lma_min_wnd=Double.parseDouble(properties.getProperty(prefix+"lma_min_wnd"));
if (properties.getProperty(prefix+"lma_half_width")!=null) this.lma_half_width=Double.parseDouble(properties.getProperty(prefix+"lma_half_width"));
if (properties.getProperty(prefix+"lma_cost_wy")!=null) this.lma_cost_wy=Double.parseDouble(properties.getProperty(prefix+"lma_cost_wy"));
if (properties.getProperty(prefix+"lma_cost_wxy")!=null) this.lma_cost_wxy=Double.parseDouble(properties.getProperty(prefix+"lma_cost_wxy"));
......@@ -621,8 +642,12 @@ public class ImageDttParameters {
idp.lma_adjust_wm = this.lma_adjust_wm;
idp.lma_adjust_wy = this.lma_adjust_wy;
idp.lma_adjust_wxy = this.lma_adjust_wxy;
idp.lma_adjust_ly1 = this.lma_adjust_ly1;
idp.lma_adjust_ag = this.lma_adjust_ag;
idp.lma_min_wnd = this.lma_min_wnd;
idp.lma_half_width = this.lma_half_width;
idp.lma_cost_wy = this.lma_cost_wy;
idp.lma_cost_wxy = this.lma_cost_wxy;
......
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