Commit d1ddd6b3 authored by Andrey Filippov's avatar Andrey Filippov

fixed LMA for offsets of the multi-tile clusters

parent fb44bc1a
......@@ -1810,9 +1810,9 @@ public class Correlation2d {
double [] corr_wnd_inv_limited, // correlation window, limited not to be smaller than threshold - used for finding max/convex areas (or null)
double [][][] corrs, // per tile, per pair, 2 correlation in line-scan order
double [][][] disp_dist, // per tile, per camera disparity matrix as a 1d (linescan order)
double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
int pair_mask, // which pairs to process
boolean run_poly_instead, // true - run LMA, false - run 2d polynomial approximation
// double sigma, // low-pass sigma to find maximum (and convex too
double[][] xcenter_str, // preliminary center x in pixels for largest baseline
double vasw_pwr, // value as weight to this power,
int debug_level,
......@@ -1823,7 +1823,7 @@ public class Correlation2d {
// corrs are organized as PAIRS, some are null if not used
// for each enabled and available pair find a maximum, filter convex and create sample list
boolean debug_graphic = (debug_level > -1);
boolean debug_second_all = false; // true;
boolean debug_second_all = false; // true; // alse; // true;
int clust_height = corrs.length/clust_width;
int ntiles = corrs.length;
DoubleGaussianBlur gb = null;
......@@ -1834,6 +1834,7 @@ public class Correlation2d {
corrs.length,
transform_size,
corr_wnd,
rXY, //double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.lma_gaussian//boolean gaussian_mode
);
......@@ -1990,12 +1991,12 @@ public class Correlation2d {
lmaSuccess = lma.runLma(
imgdtt_params.lma_lambda_initial, // double lambda, // 0.1
imgdtt_params.lma_lambda_scale_good, // double lambda_scale_good,// 0.5
imgdtt_params.lma_lambda_scale_good, // double lambda_scale_good, // 0.5
imgdtt_params.lma_lambda_scale_bad, // double lambda_scale_bad, // 8.0
imgdtt_params.lma_lambda_max, // double lambda_max, // 100
imgdtt_params.lma_rms_diff, // double rms_diff, // 0.001
imgdtt_params.lma_num_iter, // int num_iter, // 20
2); //4); // debug_level); // int debug_level) // > 3
imgdtt_params.lma_debug_level1); //4); // debug_level); // int debug_level) // > 3
lma.updateFromVector();
double [] rms = lma.getRMS();
......@@ -2124,15 +2125,15 @@ public class Correlation2d {
return lmaSuccess? lma: null;
}
public Corr2dLMA corrLMA2( // single tile
public Corr2dLMA corrLMA2( // single tile ************* Will be obsolete ????
ImageDttParameters imgdtt_params,
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,
double [][] disp_dist, // per camera disparity matrix as a 1d (linescan order)
double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
int pair_mask, // which pairs to process
boolean run_poly_instead, // true - run LMA, false - run 2d polynomial approximation
// double sigma, // low-pass sigma to find maximum (and convex too
double xcenter, // preliminary center x in pixels for largest baseline
double vasw_pwr, // value as weight to this power,
int debug_level,
......@@ -2151,7 +2152,8 @@ public class Correlation2d {
1,
transform_size,
corr_wnd,
imgdtt_params.lma_gaussian//boolean gaussian_mode
rXY, //double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.lma_gaussian //boolean gaussian_mode
);
......@@ -2312,19 +2314,6 @@ public class Correlation2d {
return lmaSuccess? lma: null;
}
/*
double [][] dbg_w = repackCluster(
dbg_weights,
clust_width);
(new ShowDoubleFloatArrays()).showArrays(
dbg_w,
dbg_out_width,
dbg_out_height,
true,
"corr_weights"+"_x"+tileX+"_y"+tileY);
*/
public Correlations2dLMA corrLMA( // USED in lwir
ImageDttParameters imgdtt_params,
......
......@@ -1577,12 +1577,13 @@ public class ImageDtt {
final int globalDebugLevel)
{
final boolean debug_distort= true;
// final double [][] debug_offsets = null;
final double [][] debug_offsets = imgdtt_params.lma_dbg_offset;
// 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
//lma_dbg_scale
final double [][] debug_offsets = new double[imgdtt_params.lma_dbg_offset.length][2];
for (int i = 0; i < debug_offsets.length; i++) for (int j = 0; j < debug_offsets[i].length; j++) {
debug_offsets[i][j] = imgdtt_params.lma_dbg_offset[i][j]*imgdtt_params.lma_dbg_scale;
}
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
......@@ -1605,6 +1606,15 @@ public class ImageDtt {
final double [] col_weights= new double [numcol]; // colors are RBG
final double [][] dbg_distort = debug_distort? (new double [4*quad][tilesX*tilesY]) : null;
final double [][] corr_wnd = Corr2dLMA.getCorrWnd(transform_size);
final double [] corr_wnd_inv_limited = (imgdtt_params.lma_min_wnd <= 1.0)? new double [corr_wnd.length * corr_wnd[0].length]: null;
if (corr_wnd_inv_limited != null) {
for (int i = imgdtt_params.lma_hard_marg; i < (corr_wnd.length - imgdtt_params.lma_hard_marg); i++) {
for (int j = imgdtt_params.lma_hard_marg; j < (corr_wnd.length - imgdtt_params.lma_hard_marg); j++) {
corr_wnd_inv_limited[i * (corr_wnd.length) + j] = 1.0/Math.max(Math.pow(corr_wnd[i][j],imgdtt_params.lma_wnd_pwr), imgdtt_params.lma_min_wnd);
}
}
}
// keep for now for mono, find out what do they mean for macro mode
if (isMonochrome()) {
......@@ -1746,7 +1756,8 @@ public class ImageDtt {
double centerX; // center of aberration-corrected (common model) tile, X
double centerY; //
double [][] fract_shiftsXY = new double[quad][];
double [][] corr_wnd = (new Corr2dLMA(1, transform_size, null,imgdtt_params.lma_gaussian)).getCorrWnd();
// double [][] corr_wnd = Corr2dLMA.getCorrWnd(transform_size);
/*
double [] corr_wnd_inv_limited = null;
if (imgdtt_params.lma_min_wnd <= 1.0) {
corr_wnd_inv_limited = new double [corr_wnd.length * corr_wnd[0].length];
......@@ -1756,7 +1767,7 @@ public class ImageDtt {
}
}
}
*/
Correlation2d corr2d = new Correlation2d(
imgdtt_params, // ImageDttParameters imgdtt_params,
transform_size, // int transform_size,
......@@ -1768,6 +1779,13 @@ public class ImageDtt {
imgdtt_params.getEnhOrthoScale(isAux()), //double getEnhOrthoScale(isAux()),
(imgdtt_params.lma_debug_level > 1)); // boolean debug);
double [][] rXY;
if (use_main) {
rXY = geometryCorrection.getRXY(true); // boolean use_rig_offsets,
} else {
rXY = geometryCorrection.getRXY(false); // boolean use_rig_offsets,
}
// for (int nTile = ai.getAndIncrement(); nTile < nTilesInChn; nTile = ai.getAndIncrement()) {
for (int nCluster = ai.getAndIncrement(); nCluster < nClustersInChn; nCluster = ai.getAndIncrement()) {
clustY = nCluster / clustersX;
......@@ -2068,6 +2086,7 @@ public class ImageDtt {
corr_wnd_inv_limited, // corr_wnd_inv_limited, // correlation window, limited not to be smaller than threshold - used for finding max/convex areas (or null)
corrs[cTile], // double [][] corrs,
disp_dist[cTile],
rXY, // double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.dbg_pair_mask, // int pair_mask, // which pairs to process
false, // boolean run_poly_instead, // true - run LMA, false - run 2d polynomial approximation
corr_stat[cTile][0], // double xcenter, // preliminary center x in pixels for largest baseline
......@@ -2096,6 +2115,7 @@ public class ImageDtt {
corr_wnd_inv_limited, // corr_wnd_inv_limited, // correlation window, limited not to be smaller than threshold - used for finding max/convex areas (or null)
corrs, // [tIndex], // double [][] corrs,
disp_dist, // [tIndex],
rXY, // double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.dbg_pair_mask, // int pair_mask, // which pairs to process
false, // boolean run_poly_instead, // true - run LMA, false - run 2d polynomial approximation
corr_stat, // double[][] xcenter_str, // preliminary center x in pixels for largest baseline
......@@ -2230,7 +2250,15 @@ public class ImageDtt {
final AtomicInteger ai = new AtomicInteger(0);
final double [] col_weights= new double [numcol]; // colors are RBG
final double [][] dbg_distort = debug_distort? (new double [4*quad][tilesX*tilesY]) : null;
final double [][] corr_wnd = Corr2dLMA.getCorrWnd(transform_size);
final double [] corr_wnd_inv_limited = (imgdtt_params.lma_min_wnd <= 1.0)? new double [corr_wnd.length * corr_wnd[0].length]: null;
if (corr_wnd_inv_limited != null) {
for (int i = imgdtt_params.lma_hard_marg; i < (corr_wnd.length - imgdtt_params.lma_hard_marg); i++) {
for (int j = imgdtt_params.lma_hard_marg; j < (corr_wnd.length - imgdtt_params.lma_hard_marg); j++) {
corr_wnd_inv_limited[i * (corr_wnd.length) + j] = 1.0/Math.max(Math.pow(corr_wnd[i][j],imgdtt_params.lma_wnd_pwr), imgdtt_params.lma_min_wnd);
}
}
}
// keep for now for mono, find out what do they mean for macro mode
if (macro_mode) { // all the same as they now mean different
......@@ -2431,7 +2459,8 @@ public class ImageDtt {
double [][][] tcorr_partial = null; // [quad][numcol+1][15*15]
double [][][][] tcorr_tpartial = null; // [quad][numcol+1][4][8*8]
double [] ports_rgb = null;
double [][] corr_wnd = (new Corr2dLMA(1, transform_size, null,imgdtt_params.lma_gaussian)).getCorrWnd();
// double [][] corr_wnd = Corr2dLMA.getCorrWnd(transform_size);
/*
double [] corr_wnd_inv_limited = null;
if (imgdtt_params.lma_min_wnd <= 1.0) {
corr_wnd_inv_limited = new double [corr_wnd.length * corr_wnd[0].length];
......@@ -2441,7 +2470,14 @@ public class ImageDtt {
}
}
}
*/
double [][] rXY;
if (use_main) {
rXY = geometryCorrection.getRXY(true); // boolean use_rig_offsets,
} else {
rXY = geometryCorrection.getRXY(false); // boolean use_rig_offsets,
}
Correlation2d corr2d = new Correlation2d(
imgdtt_params, // ImageDttParameters imgdtt_params,
transform_size, // int transform_size,
......@@ -2978,6 +3014,7 @@ public class ImageDtt {
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, // double [][] corrs,
disp_dist,
rXY, // double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.dbg_pair_mask, // int pair_mask, // which pairs to process
false, // boolean run_poly_instead, // true - run LMA, false - run 2d polynomial approximation
corr_stat[0], // double xcenter, // preliminary center x in pixels for largest baseline
......
......@@ -128,9 +128,11 @@ public class ImageDttParameters {
public double lma_rms_diff = 0.001; //
public int lma_num_iter = 20; //
public int lma_debug_level = 3; //
public int lma_debug_level1 = 2; //
public boolean corr_var_cam = true; // New correlation mode compatible with 8 subcameras
public double cm_max_normalization = 0.55; // fraction of correlation maximum radius, being squared multiplied by maximum to have the same total mass
public double [][] lma_dbg_offset = new double [4][2]; //{{ 1.0, 0.0},{ -1.0, 0.0},{-1.0, 0.0},{ 1.0, 0.0}}; // new double [4][2];
public double lma_dbg_scale = 0.0; // scale lma_dbg_offset
public double [][] lma_dbg_offset = {{ 1.0, 0.0},{ -1.0, 0.0},{-1.0, 0.0},{ 1.0, 0.0}}; // new double [4][2];
public int getEnhOrthoWidth(boolean aux) {
return aux ? enhortho_width_aux : enhortho_width;
......@@ -316,13 +318,16 @@ public class ImageDttParameters {
"Limit LMA cycles, so it will exit after certain number of small improvements");
gd.addNumericField("LMA debug level", this.lma_debug_level, 0, 3, "",
"Debug/verbosity level for the LMA correaltion maximum fitting");
gd.addNumericField("LMA debug level1", this.lma_debug_level1, 0, 3, "",
"Debug/verbosity level for the new LMA correaltion maximum fitting");
gd.addCheckbox ("Use new correlation methods compatible with x8 camera", this.corr_var_cam,
"Debug feature to compare old/new methods");
gd.addNumericField("Normalization for the CM correlation strength", this.cm_max_normalization, 6, 8, "",
"Fraction of correlation maximum radius, being squared multiplied by maximum to have the same total mass. ~= 0.5, the lower the value, the higher strength reported by the CM");
gd.addMessage("Cameras offsets in the disparity direction and orthogonal to disparity (debugging LMA)");
gd.addNumericField("LMA debug offsets scale", this.lma_dbg_scale, 6, 8, "",
"Scale the following offsets by this value");
gd.addNumericField("LMA debug offset: camera0, parallel", this.lma_dbg_offset[0][0], 6, 8, "pix",
"Add camera offset in the direction of disparity (to/from center)");
gd.addNumericField("LMA debug offset: camera0, ortho", this.lma_dbg_offset[0][1], 6, 8, "pix",
......@@ -441,8 +446,10 @@ public class ImageDttParameters {
this.lma_num_iter= (int) gd.getNextNumber();
this.lma_debug_level= (int) gd.getNextNumber();
this.lma_debug_level1= (int) gd.getNextNumber();
this.corr_var_cam = gd.getNextBoolean();
this.cm_max_normalization= gd.getNextNumber();
this.lma_dbg_scale= gd.getNextNumber();
for (int i = 0; i < 4; i++) for (int j=0; j < 2; j++) {
this.lma_dbg_offset[i][j]= gd.getNextNumber();
......@@ -459,14 +466,14 @@ public class ImageDttParameters {
properties.setProperty(prefix+"poly_corr_scale", this.poly_corr_scale+"");
properties.setProperty(prefix+"poly_pwr", this.poly_pwr+"");
properties.setProperty(prefix+"poly_value_to_weight", this.poly_vasw_pwr+"");
properties.setProperty(prefix+"poly_vasw_pwr", this.poly_vasw_pwr+"");
properties.setProperty(prefix+"corr_magic_scale_cm", this.corr_magic_scale_cm+"");
properties.setProperty(prefix+"corr_magic_scale_poly",this.corr_magic_scale_poly+"");
properties.setProperty(prefix+"ortho_height", this.ortho_height+"");
properties.setProperty(prefix+"ortho_eff_height", this.ortho_eff_height+"");
properties.setProperty(prefix+"ortho_nsamples", this.ortho_nsamples+"");
properties.setProperty(prefix+"ortho_vasw", this.ortho_vasw_pwr+"");
properties.setProperty(prefix+"ortho_vasw_pwr", this.ortho_vasw_pwr+"");
properties.setProperty(prefix+"enhortho_width", this.enhortho_width +"");
properties.setProperty(prefix+"enhortho_width_aux", this.enhortho_width_aux +"");
......@@ -545,9 +552,12 @@ public class ImageDttParameters {
properties.setProperty(prefix+"lma_num_iter", this.lma_num_iter +"");
properties.setProperty(prefix+"lma_debug_level", this.lma_debug_level +"");
properties.setProperty(prefix+"lma_debug_level1", this.lma_debug_level1 +"");
properties.setProperty(prefix+"corr_var_cam", this.corr_var_cam +"");
properties.setProperty(prefix+"cm_max_normalization", this.cm_max_normalization +"");
properties.setProperty(prefix+"lma_dbg_scale", this.lma_dbg_scale +"");
for (int i = 0; i < 4; i++) for (int j=0; j < 2; j++) {
properties.setProperty(prefix+"lma_dbg_offset_"+i+"_"+j, this.lma_dbg_offset[i][j] +"");
}
......@@ -655,10 +665,11 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"lma_num_iter")!=null) this.lma_num_iter=Integer.parseInt(properties.getProperty(prefix+"lma_num_iter"));
if (properties.getProperty(prefix+"lma_debug_level")!=null) this.lma_debug_level=Integer.parseInt(properties.getProperty(prefix+"lma_debug_level"));
if (properties.getProperty(prefix+"lma_debug_level1")!=null) this.lma_debug_level1=Integer.parseInt(properties.getProperty(prefix+"lma_debug_level1"));
if (properties.getProperty(prefix+"corr_var_cam")!=null) this.corr_var_cam=Boolean.parseBoolean(properties.getProperty(prefix+"corr_var_cam"));
if (properties.getProperty(prefix+"cm_max_normalization")!=null) this.cm_max_normalization=Double.parseDouble(properties.getProperty(prefix+"cm_max_normalization"));
if (properties.getProperty(prefix+"lma_dbg_scale")!=null) this.lma_dbg_scale=Double.parseDouble(properties.getProperty(prefix+"lma_dbg_scale"));
for (int i = 0; i < 4; i++) for (int j=0; j < 2; j++) {
if (properties.getProperty(prefix+"lma_dbg_offset_"+i+"_"+j)!=null) this.lma_dbg_offset[i][j]=Double.parseDouble(properties.getProperty(prefix+"lma_dbg_offset_"+i+"_"+j));
}
......@@ -765,9 +776,11 @@ public class ImageDttParameters {
idp.lma_num_iter = this.lma_num_iter;
idp.lma_debug_level = this.lma_debug_level;
idp.lma_debug_level1 = this.lma_debug_level1;
idp.corr_var_cam = this.corr_var_cam;
idp.cm_max_normalization= this.cm_max_normalization;
idp.lma_dbg_scale= this.lma_dbg_scale;
idp.lma_dbg_offset= new double [this.lma_dbg_offset.length][];
for (int i = 0; i < idp.lma_dbg_offset.length; i++) {
idp.lma_dbg_offset[i] = this.lma_dbg_offset[i].clone();
......
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