Commit 30937781 authored by Andrey Filippov's avatar Andrey Filippov

more debugging LMA lazy eye

parent 98f8ebea
......@@ -95,6 +95,8 @@ public class Corr2dLMA {
private double [] vector;
private ArrayList<Sample> samples = new ArrayList<Sample>();
// private ArrayList<Sample> norm_samples = new ArrayList<Sample>(); // to calculate
private double total_weight;
private int total_tiles;
private double [] weights; // normalized so sum is 1.0 for all - samples and extra regularization terms
private double pure_weight; // weight of samples only
private double [] values;
......@@ -111,6 +113,7 @@ public class Corr2dLMA {
private int [] used_cams_map = new int[NUM_CAMS]; // for each camera index return used index ???
private int [] used_cams_rmap; // variable-length list of used cameras numbers
private int [][][] used_pairs_map; // for each camera index return used index ??
private boolean [] used_tiles;
private final int transform_size;
private final double [][] corr_wnd;
......@@ -130,9 +133,9 @@ public class Corr2dLMA {
private boolean lazy_eye; // calculate parameters/derivatives for the "lazy eye" parameters
private double [][] rXY;
private int [] dd_indices; //normally 5-long (2 * ncam -3), absolute parameter indices for dd_pre_last, dd_last and nd_last
private double thresholdLin = 1.0E-20; // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
private double thresholdQuad = 1.0E-30; // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
public int bad_tile=-1; // bad tile - exponent got infinite, remove the tile and start over again
// happens in gaussian mode with the convex area around wrong maximum
public class Sample{ // USED in lwir
int tile; // tile in a cluster
......@@ -142,7 +145,6 @@ public class Corr2dLMA {
int iy; // y coordinate in 2D correlation (0.. 2*transform_size-2, center: (transform_size-1)
double v; // correlation value at that point
double w; // weight
double bv; // blurred value
Sample (
int tile,
int fcam, // first camera index
......@@ -150,8 +152,7 @@ public class Corr2dLMA {
int x, // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis
int y, // coordinate in 2D correlation (0.. 2*transform_size-2, center: (transform_size-1)
double v, // correlation value at that point
double w,
double bv)
double w)
{
this.tile = tile;
this.fcam = fcam;
......@@ -160,11 +161,10 @@ public class Corr2dLMA {
this.iy = y;
this.v = v;
this.w = w;
this.bv = bv;
}
@Override
public String toString() {
return String.format("tile=%d, f=%d s=%d x=%d y=%d v=%f w=%f bv=%f", tile, fcam, scam, ix, iy, v, w, bv);
return String.format("tile=%d, f=%d, s=%d, x=%d, y=%d, v=%f, w=%f", tile, fcam, scam, ix, iy, v, w);
}
}
......@@ -241,9 +241,8 @@ public class Corr2dLMA {
int x, // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis
int y, // y coordinate (0 - disparity axis)
double v, // correlation value at that point
double w, // sample weight
double bv) { // blurred/ normalized by window;
if ((w > 0) && !Double.isNaN(v)) samples.add(new Sample(tile,fcam,scam,x,y,v,w,bv));
double w) { // sample weight
if ((w > 0) && !Double.isNaN(v)) samples.add(new Sample(tile,fcam,scam,x,y,v,w));
}
public ArrayList<Sample> filterSamples(
......@@ -258,6 +257,27 @@ public class Corr2dLMA {
return samples;
}
// maybe in the future - just remove a pad pair?
private void removeBadTile(
int ntile,
int fcam, // not yet used, maybe try removing just a pair, not all tile?
int scam) {
bad_tile = ntile;
ArrayList<Sample> filtered_samples = new ArrayList<Sample>();
for (Sample s:samples) {
if (s.tile != ntile) {
// if (s.tile != ntile || (s.fcam!= fcam) || (s.scam !=scam)) {
filtered_samples.add(s);
}
}
samples = filtered_samples;
}
public int getBadTile() { // after failed LMA check bad_tile. If >=0 - reinit/restart LMA, samples have already removed bad_tile
return bad_tile;
}
boolean samplesExist() {
return ((samples !=null) && !samples.isEmpty());
......@@ -360,7 +380,7 @@ public class Corr2dLMA {
public void setMatrices(double [][][] am_disp) {
m_disp = new Matrix[am_disp.length][NUM_CAMS];
for (int nt = 0; nt < numTiles; nt++) {
for (int nt = 0; nt < numTiles; nt++) if (used_tiles[nt]){
for (int n = 0; n < NUM_CAMS; n++) {
double [][] am = {
{am_disp[nt][n][0], am_disp[nt][n][1]},
......@@ -401,8 +421,19 @@ public class Corr2dLMA {
mddnd = A33.inverse().times(A35);
}
public void initDisparity ( // USED in lwir
double [][] disp_str // initial value of disparity
) {
for (int nTile = 0; nTile < numTiles; nTile++) {
if ((disp_str[nTile] != null) && (disp_str[nTile][1] > 0.0) && used_tiles[nTile]) {
this.all_pars[DISP_INDEX + nTile*TILE_PARAMS] = -disp_str[nTile][0]; // disp0;
} else {
this.all_pars[DISP_INDEX + nTile*TILE_PARAMS] = 0.0; // disp0;
}
}
}
public void initVector( // USED in lwir
public boolean initVector( // USED in lwir
boolean adjust_width, // adjust width of the maximum - lma_adjust_wm
boolean adjust_scales, // adjust 2D correlation scales - lma_adjust_ag
boolean adjust_ellipse, // allow non-circular correlation maximums lma_adjust_wy
......@@ -415,7 +446,7 @@ public class Corr2dLMA {
) {
adjust_lazyeye_ortho = adjust_lazyeye_par; // simplify relations for the calculated/dependent parameters
lazy_eye = adjust_lazyeye_par | adjust_lazyeye_ortho;
bad_tile = -1;
used_pairs_map = new int [numTiles][NUM_CAMS][NUM_CAMS];
used_cameras = new boolean[NUM_CAMS];
boolean [][] used_pairs = new boolean[numTiles][NUM_PAIRS];
......@@ -424,7 +455,7 @@ public class Corr2dLMA {
used_pairs_map[t][f][s] = -1;
}
boolean [][][] used_pairs_dir = new boolean [numTiles][NUM_CAMS][NUM_CAMS];
boolean [] used_tiles = new boolean[numTiles];
used_tiles = new boolean[numTiles];
for (Sample s:samples) { // ignore zero-weight samples
used_cameras[s.fcam]=true;
used_cameras[s.scam]=true;
......@@ -447,8 +478,12 @@ public class Corr2dLMA {
used_cams_rmap[ncam++] = i;
}
}
if (ncam < 2) {
return false;
}
last_cam = (ncam > 1)? used_cams_rmap[ncam - 1] :-1;
pre_last_cam = (ncam > 2)? used_cams_rmap[ncam - 2] :-1;
setOffsetMatrices();
for (int nTile = 0; nTile < numTiles; nTile++) {
......@@ -468,9 +503,9 @@ public class Corr2dLMA {
this.all_pars = new double[num_all_pars];
this.par_mask = new boolean[num_all_pars];
total_tiles = 0;
// per-tile parameters
for (int nTile = 0; nTile < numTiles; nTile++) if ((disp_str[nTile] != null) && (disp_str[nTile][1] > 0.0) && used_tiles[nTile]){
// this.all_pars[DISP_INDEX + nTile*TILE_PARAMS] = disp_str[nTile][0]; // disp0;
this.all_pars[DISP_INDEX + nTile*TILE_PARAMS] = -disp_str[nTile][0]; // disp0;
this.all_pars[A_INDEX + nTile*TILE_PARAMS] = 1.0/(half_width * half_width);
this.all_pars[B_INDEX + nTile*TILE_PARAMS] = 0.0;
......@@ -483,6 +518,7 @@ public class Corr2dLMA {
this.par_mask[G0_INDEX + i + nTile*TILE_PARAMS] = used_pairs[nTile][i] & adjust_scales;
this.all_pars[G0_INDEX + i + nTile*TILE_PARAMS] = Double.NaN; // will be assigned later for used - should be for all !
}
total_tiles++;
}
// common for all tiles parameters
for (int i = 0; i <NUM_CAMS; i++) {
......@@ -503,9 +539,12 @@ public class Corr2dLMA {
}
double sw = 0;
total_weight = 0.0;
for (int i = 0; i < np; i++) {
Sample s = samples.get(i);
weights[i] = s.w;
total_weight += s.w;
values[i] = s.v;
sw += weights[i];
int indx = G0_INDEX + pindx[s.fcam][s.scam] + s.tile * TILE_PARAMS;
......@@ -516,7 +555,6 @@ public class Corr2dLMA {
if (!(d <= this.all_pars[indx])) this.all_pars[indx] = d; // to include Double.isNaN()
}
pure_weight = sw;
for (int i = 0; i < 2 * NUM_CAMS; i++) { // weight of the regularization terms (twice number of cameras, some may be disabled by a mask)
sw += weights[np + i];
......@@ -544,6 +582,7 @@ public class Corr2dLMA {
}
}
toVector();
return true;
}
......@@ -551,7 +590,7 @@ public class Corr2dLMA {
public void initMatrices() { // should be called after initVector and after setMatrices
m_pairs = new Matrix[used_pairs_map.length][NUM_CAMS][NUM_CAMS];
m_pairs_inv = new Matrix[used_pairs_map.length][NUM_CAMS][NUM_CAMS];
for (int nTile = 0; nTile < used_pairs_map.length; nTile++) {
for (int nTile = 0; nTile < used_pairs_map.length; nTile++) if (used_tiles[nTile]){
for (int f = 0; f < NUM_CAMS; f++) for (int s = 0; s < NUM_CAMS; s++) {
m_pairs[nTile][f][s] = null;
// m_pairs_last[f][s] = null;
......@@ -567,7 +606,7 @@ public class Corr2dLMA {
public void initInvertMatrices() { // should be called after initMatrices only if m_pairs_inv are needed
m_pairs_inv = new Matrix[used_pairs_map.length][NUM_CAMS][NUM_CAMS];
for (int nTile = 0; nTile < used_pairs_map.length; nTile++) {
for (int nTile = 0; nTile < used_pairs_map.length; nTile++) if (used_tiles[nTile]){
for (int f = 0; f < NUM_CAMS; f++) for (int s = 0; s < NUM_CAMS; s++) {
m_pairs_inv[nTile][f][s] = null;
if (used_pairs_map[nTile][f][s] >= 0) {
......@@ -579,22 +618,29 @@ public class Corr2dLMA {
/**
* Calculate initial disparity by polynomial approximation. Only works with a single tile now
* @param corr_blur blurred and normalized by window correlation data matching this.samples
* @return estimated disparity
* @param corr_wnd_inv_limited window (same as for finding convex) to boost gain in peripheral areas, but not the very marginal ones
* @param max_offset maximal abs(disparity) value to trust
* @param dgg_title if !=null - generate debug image with this title
* @return estimated disparity, strength and half-window sizes
*/
public double [] polyDisparity() {
return polyDisparity(null);
}
public double [] polyDisparity( String dbg_title) {
public double [] polyDisparity(
double [] corr_wnd_inv_limited,
double max_offset, // 5?
String dbg_title) {
int center = transform_size -1;
// int corr_size = 2 * transform_size -1;
int corr_size = 2 * transform_size -1;
initInvertMatrices();
int nSamples = samples.size();
double [][][] mdata = new double [2 * nSamples][3][];
double bv;
for (int ns = 0; ns < nSamples; ns++) {
Sample s = samples.get(ns);
// double bv = s.bv/this.all_pars[G0_INDEX + pindx[s.fcam][s.scam] + s.tile * TILE_PARAMS];
double bv = s.v/corr_wnd[s.iy][s.ix]/this.all_pars[G0_INDEX + pindx[s.fcam][s.scam] + s.tile * TILE_PARAMS];
if (corr_wnd_inv_limited != null) {
bv = s.v * corr_wnd_inv_limited[corr_size * s.iy +s.ix];
} else {
bv = s.v / corr_wnd[s.iy][s.ix];
}
bv /=this.all_pars[G0_INDEX + pindx[s.fcam][s.scam] + s.tile * TILE_PARAMS];
//corr_wnd
int indx = 2 * ns;
mdata[indx ][0] = new double [2];
......@@ -626,10 +672,16 @@ public class Corr2dLMA {
(approx2d[4] >= 0.0)) { // y: min, not max
return null; // Double.NaN;
}
if (Math.abs(approx2d[0]) > max_offset) { // > 6 - too far for the maximum
return null; // Double.NaN;
}
// calculate width_x and width_y
double hwx = Math.sqrt(-approx2d[2]/approx2d[3]);
double hwy = Math.sqrt(-approx2d[2]/approx2d[4]);
double [] rslt = {-approx2d[0], approx2d[2], hwx, hwy};
double [] rslt = {
-approx2d[0],
approx2d[2] / Math.sqrt(hwx * hwy)};
// hwx, hwy};
if (dbg_title != null) {
polyDisparityDebug(
......@@ -639,7 +691,6 @@ public class Corr2dLMA {
100, // int irad,
10.0);//sigma);
}
return rslt; // [0];
}
......@@ -649,17 +700,20 @@ public class Corr2dLMA {
double scale,
int irad,
double sigma){
double [][] dbg_img = new double [NUM_CAMS*NUM_CAMS][];
double [][] dbg_weights = new double [NUM_CAMS*NUM_CAMS][];
String [] titles = new String [NUM_CAMS*NUM_CAMS];
double [][] dbg_img = new double [NUM_CAMS*NUM_CAMS+1][];
double [][] dbg_weights = new double [NUM_CAMS*NUM_CAMS+1][];
String [] titles = new String [NUM_CAMS*NUM_CAMS+1];
int size = 2 * irad+1;
int nSamples = samples.size();
DoubleGaussianBlur gb = new DoubleGaussianBlur();
titles[0] = "combined";
dbg_img[0] = new double [size*size];
dbg_weights[0] = new double [size*size];
for (int ns = 0; ns < nSamples; ns++) {
int indx = 2 * ns;
Sample s = samples.get(ns);
int np = s.fcam* NUM_CAMS + s.scam;
int np = s.fcam* NUM_CAMS + s.scam +1;
if (dbg_img[np] == null) {
dbg_img[np] = new double [size*size];
dbg_weights[np] = new double [size*size];
......@@ -675,8 +729,10 @@ public class Corr2dLMA {
int iy = (int) Math.round(mdata[indx ][0][1] * scale + irad);
if ((ix >= 0) && (iy >= 0) && (ix < size) && (iy <size)) {
int offs = iy * size + ix;
dbg_img[np][offs] = w * d;
dbg_weights[np][offs] = w;
dbg_img[np][offs] += w * d;
dbg_weights[np][offs] += w;
dbg_img[0][offs] += w * d;
dbg_weights[0][offs] += w;
}
}
for (int np = 0; np < dbg_img.length; np++) if (dbg_img[np] != null) {
......@@ -707,14 +763,14 @@ public class Corr2dLMA {
return dbg_img;
}
public double [] getFxJt( // USED in lwir
private double [] getFxJt( // USED in lwir
double [] vector,
double [][] jt) { // should be either [vector.length][samples.size()] or null - then only fx is calculated
if (this.gaussian_mode) return getFxJt_gaussian(vector, jt);
else return getFxJt_parabola(vector, jt);
}
public double [] getFxJt_parabola( // USED in lwir
private double [] getFxJt_parabola( // USED in lwir
double [] vector,
double [][] jt) { // should be either [vector.length][samples.size()] or null - then only fx is calculated
if (vector == null) return null;
......@@ -726,7 +782,7 @@ public class Corr2dLMA {
double [] AT = new double [numTiles]; // av[A_INDEX];
double [] BT = new double [numTiles]; // av[B_INDEX];
double [] CT = new double [numTiles]; // A + av[CMA_INDEX];
for (int nTile = 0; nTile < numTiles; nTile++) {
for (int nTile = 0; nTile < numTiles; nTile++) if (used_tiles[nTile]){
for (int i = 0; i < NUM_CAMS; i++) if (used_cameras[i]) {
double [] add_dnd = {av[DISP_INDEX+ nTile * TILE_PARAMS]+ av[ddisp_index + i], av[ndisp_index + i]};
xcam_ycam[nTile][i] = m_disp[nTile][i].times(new Matrix(add_dnd,2));
......@@ -836,6 +892,9 @@ public class Corr2dLMA {
for (int ddn = 0; ddn < 3; ddn++) if (dd_deriv[ddn] != 0.0) {
for (int i = 0; i < dd_indices.length; i++) {
jt[dd_indices[i]][ns] += dd_deriv[ddn] * mddnd.get(ddn, i);
// if (Double.isNaN(jt[dd_indices[i]][ns])){
// System.out.println("getFxJt_parabola(): jt[dd_indices["+i+"]]["+ns+"] == NaN, dd_indices["+i+"]="+dd_indices[i]);
// }
}
}
}
......@@ -867,7 +926,7 @@ public class Corr2dLMA {
return fx;
}
public double [] getFxJt_gaussian( // USED in lwir
private double [] getFxJt_gaussian( // USED in lwir
double [] vector,
double [][] jt) { // should be either [vector.length][samples.size()] or null - then only fx is calculated
if (vector == null) return null;
......@@ -879,7 +938,7 @@ public class Corr2dLMA {
double [] AT = new double [numTiles]; // av[A_INDEX];
double [] BT = new double [numTiles]; // av[B_INDEX];
double [] CT = new double [numTiles]; // A + av[CMA_INDEX];
for (int nTile = 0; nTile < numTiles; nTile++) {
for (int nTile = 0; nTile < numTiles; nTile++) if (used_tiles[nTile]){
for (int i = 0; i < NUM_CAMS; i++) if (used_cameras[i]) {
double [] add_dnd = {av[DISP_INDEX+ nTile * TILE_PARAMS]+ av[ddisp_index + i], av[ndisp_index + i]};
xcam_ycam[nTile][i] = m_disp[nTile][i].times(new Matrix(add_dnd,2));
......@@ -914,6 +973,18 @@ public class Corr2dLMA {
double xmxp_ymyp = xmxp * ymyp;
//// double comm = Wp*(1.0 - (A*xmxp2 + 2 * B * xmxp_ymyp + C * ymyp2));
double exp = Math.exp(-(A*xmxp2 + 2 * B * xmxp_ymyp + C * ymyp2));
// if ((exp > 1000.0) || (exp < 0.0000001)) {
if (exp > 1000.0) {
// System.out.println("Unreasonable exp = "+exp);
removeBadTile(s.tile, s.fcam, s.scam);
return null; // should re-start LMA
}
if (Double.isInfinite(exp)) {
removeBadTile(s.tile, s.fcam, s.scam);
return null; // should re-start LMA
}
double comm = exp * Wp;
double WGpexp = WGp*exp;
......@@ -997,6 +1068,9 @@ public class Corr2dLMA {
for (int ddn = 0; ddn < 3; ddn++) if (dd_deriv[ddn] != 0.0) {
for (int i = 0; i < dd_indices.length; i++) {
jt[dd_indices[i]][ns] += dd_deriv[ddn] * mddnd.get(ddn, i);
// if (Double.isNaN(jt[dd_indices[i]][ns])){
// System.out.println("getFxJt_gaussian(): jt[dd_indices["+i+"]]["+ns+"] == NaN, dd_indices["+i+"]="+dd_indices[i]);
// }
}
}
}
......@@ -1029,6 +1103,7 @@ public class Corr2dLMA {
return fx;
}
public void printParams() { // not used in lwir
// to make sure it is updated
System.out.println();
......@@ -1219,7 +1294,7 @@ public class Corr2dLMA {
////////////////////////////////////////////////////////////////////////
public void debugJt( // not used in lwir
private boolean debugJt( // not used in lwir
double delta,
double [] vector) {
int num_points = this.values.length;
......@@ -1231,7 +1306,8 @@ public class Corr2dLMA {
double [][] jt = new double [num_pars][num_points];
double [][] jt_delta = new double [num_pars][num_points];
double [] fx = getFxJt( vector,jt);
getFxJt(delta, vector,jt_delta);
if (fx == null) return false;
if (getFxJt(delta, vector,jt_delta) == null) return false;
System.out.println("Test of jt-jt_delta difference, delta = "+delta+ ":");
System.out.print(String.format("Til P %3s: %10s ", "#", "fx"));
for (int anp = 0; anp< all_pars.length; anp++) if(par_mask[anp]){
......@@ -1280,6 +1356,7 @@ public class Corr2dLMA {
System.out.print(String.format("|%8s %8.5f ", "1/1000×", 1000*max_diff[np]));
}
System.out.println();
return true;
}
......@@ -1288,14 +1365,16 @@ public class Corr2dLMA {
double [] vector,
double [][] jt) { // should be either [vector.length][samples.size()] or null - then only fx is calculated
double [] fx0=getFxJt(vector,null);
if (fx0 == null) return null;
for (int np = 0; np < vector.length; np++) {
double [] vector1 = vector.clone();
vector1[np]+= delta;
double [] fxp=getFxJt(vector1,null);
if (fxp == null) return null;
vector1 = vector.clone();
vector1[np]-= delta;
double [] fxm=getFxJt(vector1,null);
if (fxm == null) return null;
jt[np] = new double [fxp.length];
for (int i = 0; i < fxp.length; i++) {
jt[np][i] = (fxp[i] - fxm[i])/delta/2;
......@@ -1391,6 +1470,49 @@ public class Corr2dLMA {
return ds;
}
public double [][] getDdNd(){ // this.all_pars should be current
double [][] ddnd = new double [NUM_CAMS][2];
for (int nc = 0; nc < NUM_CAMS; nc++) {
ddnd[nc][0] = all_pars[ddisp_index + nc];
ddnd[nc][1] = all_pars[ndisp_index + nc];
}
return ddnd;
}
public double [] getStats(){
double [] stats = {total_weight/numTiles, 1.0*total_tiles/numTiles, last_rms[0]};
return stats;
}
public void getDdNd(double [][] ddnd){ // this.all_pars should be current
if (ddnd != null) {
for (int nc = 0; nc < NUM_CAMS; nc++) {
ddnd[nc] = new double [2];
ddnd[nc][0] = all_pars[ddisp_index + nc];
ddnd[nc][1] = all_pars[ndisp_index + nc];
}
}
}
public void getStats(double [] stats){
if ((stats != null) && (stats.length > 0)) {
stats[0] = total_weight;
if (stats.length > 1) {
stats[1] = total_tiles;
if (stats.length > 2) {
stats[2] = last_rms[0];
}
}
}
}
public void getStats(double [][] stats){
double [] stats0 = {total_weight, total_tiles, last_rms[0]};
stats[0] = stats0;
}
public double [] getRmsTile() { //
double [] tile_rms = new double[numTiles];
double [] tile_weights = new double[numTiles];
......@@ -1507,6 +1629,9 @@ public class Corr2dLMA {
lambda,
rms_diff,
debug_level);
if (rslt == null) {
return false; // need to check
}
if (debug_level > 1) {
System.out.println("LMA step "+iter+": {"+rslt[0]+","+rslt[1]+"} full RMS= "+good_or_bad_rms[0]+
" ("+initial_rms[0]+"), pure RMS="+good_or_bad_rms[1]+" ("+initial_rms[1]+") + lambda="+lambda);
......@@ -1559,6 +1684,9 @@ public class Corr2dLMA {
this.last_ymfx = getFxJt(
this.vector, // double [] vector,
this.last_jt); // double [][] jt) { // should be either [vector.length][samples.size()] or null - then only fx is calculated
if (last_ymfx == null) {
return null; // need to re-init/restart LMA
}
this.last_rms = getWYmFxRms(this.last_ymfx); // modifies this.last_ymfx
this.initial_rms = this.last_rms.clone();
this.good_or_bad_rms = this.last_rms.clone();
......@@ -1601,7 +1729,7 @@ public class Corr2dLMA {
System.out.println("(JtJ + lambda*diag(JtJ).inv()");
jtjl_inv.print(18, 6);
}
//last_jt has NaNs
Matrix jty = (new Matrix(this.last_jt)).times(y_minus_fx_weighted);
if (debug_level>2) {
System.out.println("Jt * (y-fx)");
......@@ -1622,6 +1750,9 @@ public class Corr2dLMA {
this.last_ymfx = getFxJt(
new_vector, // double [] vector,
this.last_jt); // double [][] jt) { // should be either [vector.length][samples.size()] or null - then only fx is calculated
if (last_ymfx == null) {
return null; // need to re-init/restart LMA
}
double [] rms = getWYmFxRms(this.last_ymfx); // modifies this.last_ymfx
this.good_or_bad_rms = rms.clone();
if (rms[0] < this.last_rms[0]) { // improved
......@@ -1644,6 +1775,9 @@ public class Corr2dLMA {
this.last_ymfx = getFxJt( // recalculate fx
this.vector, // double [] vector,
this.last_jt); // double [][] jt) { // should be either [vector.length][samples.size()] or null - then only fx is calculated
if (last_ymfx == null) {
return null; // need to re-init/restart LMA
}
this.last_rms = getWYmFxRms(this.last_ymfx); // modifies this.last_ymfx
if (debug_level > 2) {
debugJt(
......
......@@ -1813,17 +1813,16 @@ public class Correlation2d {
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[][] disp_str, // -preliminary center x in pixels for largest baseline
double vasw_pwr, // value as weight to this power,
int debug_level,
int tileX, // just for debug output
int tileY
)
int tileY)
{
// 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 = imgdtt_params.lma_debug_graphic; // (debug_level > -1) ;
// boolean debug_graphic = true;
// boolean debug_second_all = false; // true; // alse; // true;
int clust_height = corrs.length/clust_width;
int ntiles = corrs.length;
......@@ -1859,7 +1858,8 @@ public class Correlation2d {
}
int numpairs = 0;
for (int ntile = 0; ntile < ntiles; ntile++) if (corrs[ntile] != null){
for (int ntile = 0; ntile < ntiles; ntile++) if ((corrs[ntile] != null) &&
((disp_str == null) || ((disp_str[ntile] != null) && (disp_str[ntile][1] > 0.0)))){
double[][] corr = new double[corrs[ntile].length][];
double [][] filtWeight = new double [corrs[ntile].length][];
// blur_max[ntile] = new double [corrs[ntile].length];
......@@ -1938,8 +1938,7 @@ public class Correlation2d {
ix, // int x, // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis
iy, // int y, // y coordinate (0 - disparity axis)
v, // double v, // correlation value at that point
w, //double w){ // sample weight
0.0); // double bv); // blurred/ normalized by window;
w); //double w){ // sample weight
}
}
}
......@@ -1971,45 +1970,60 @@ public class Correlation2d {
"corr_weights"+"_x"+tileX+"_y"+tileY);
}
lma.initVector( // USED in lwir
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_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
disp_str, // xcenter_str, // double [][] disp_str, // initial value of disparity/strength/?
imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width
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
boolean lmaSuccess = false;
if (debug_level > 1) {
System.out.println("Input data:");
lma.printInputDataFx(false);
lma.printParams();
while (!lmaSuccess) {
boolean OK = lma.initVector( // USED in lwir
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_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
disp_str, // xcenter_str, // double [][] disp_str, // initial value of disparity/strength/?
imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width
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
);
if (!OK) {
return null; // empty cluster
}
lma.setMatrices(disp_dist);
lma.initMatrices(); // should be called after initVector and after setMatrices
// boolean lmaSuccess = false;
if (debug_level > 1) {
System.out.println("Input data:");
lma.printInputDataFx(false);
lma.printParams();
}
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_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
imgdtt_params.lma_debug_level1); //4); // debug_level); // int debug_level) // > 3
if (!lmaSuccess && (lma.getBadTile() >= 0)) {
if (debug_level > -1) { // -20) {
System.out.println("Found bad tile/pair (probably wrong initial maximum - try around preliminary? "+lma.getBadTile());
}
} else {
break;
}
}
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_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
imgdtt_params.lma_debug_level1); //4); // debug_level); // int debug_level) // > 3
lma.updateFromVector();
double [] rms = lma.getRMS();
if (debug_level > 0) {
System.out.println("LMA -> "+lmaSuccess+" RMS= "+rms[0]+", pure RMS= "+rms[1]);
lma.printParams();
}
double [][] ds = null;
if (lmaSuccess) {
// double [][] ds = lma.getDisparityStrength();
lma.updateFromVector();
double [] rms = lma.getRMS();
if (debug_level > 0) {
System.out.println("LMA -> "+lmaSuccess+" RMS= "+rms[0]+", pure RMS= "+rms[1]);
lma.printParams();
}
// double [][] ds = lma.getDisparityStrength();
ds = lma.disparityStrength(
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
......@@ -2017,99 +2031,108 @@ 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
);
if (debug_level > 0) lma.printStats(ds,clust_width);
}
if (debug_level > -1) lma.printStats(ds,clust_width);
if (debug_level > 1) {
System.out.println("Input data and approximation:");
lma.printInputDataFx(true);
}
// boolean debug_second_all = true;
if (lmaSuccess && imgdtt_params.lma_second) {
double [] all_pars_save = null;
ArrayList<Sample> samples = lma.filterSamples(ds);
if (!lma.samplesExist()) {
if (debug_level > 1) {
System.out.println("No tiles left in a cluster!");
if (debug_level > 1) {
System.out.println("Input data and approximation:");
lma.printInputDataFx(true);
}
// boolean debug_second_all = true;
if (lmaSuccess && imgdtt_params.lma_second) {
double [] all_pars_save = null;
ArrayList<Sample> samples = lma.filterSamples(ds);
if (!lma.samplesExist()) {
if (debug_level > 1) {
System.out.println("No tiles left in a cluster!");
}
return null;
}
return null;
}
if (imgdtt_params.lma_gaussian == imgdtt_params.lma_second_gaussian) {
all_pars_save = lma.all_pars.clone();
} else { // have to restart LMA initialization
lma = new Corr2dLMA(
corrs.length,
transform_size,
corr_wnd,
rXY, //double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.lma_second_gaussian//boolean gaussian_mode
);
lma.setSamples(samples); // restore samples
}
lma.initVector( // USED in lwir
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
true, // imgdtt_params.lma_adjust_wxy, // boolean adjust_lazyeye_par, // adjust disparity corrections parallel to disparities lma_adjust_wxy
true, // imgdtt_params.lma_adjust_ly1, // boolean adjust_lazyeye_ortho, // adjust disparity corrections orthogonal to disparities lma_adjust_ly1
ds, // disp_str, // xcenter_str, // double [][] disp_str, // initial value of disparity/strength/?
imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width
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
);
if (all_pars_save != null) {
lma.all_pars = all_pars_save;
lma.toVector();
}
lma.setMatrices(disp_dist);
lma.initMatrices(); // should be called after initVector and after setMatrices
//boolean
lmaSuccess = false;
if (debug_level > 1) {
System.out.println("Input data:");
lma.printInputDataFx(false);
lma.printParams();
lmaSuccess = false;
while (!lmaSuccess ) {
if (imgdtt_params.lma_gaussian == imgdtt_params.lma_second_gaussian) {
all_pars_save = lma.all_pars.clone();
} else { // have to restart LMA initialization
lma = new Corr2dLMA(
corrs.length,
transform_size,
corr_wnd,
rXY, //double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.lma_second_gaussian//boolean gaussian_mode
);
lma.setSamples(samples); // restore samples
}
lma.initVector( // USED in lwir
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
true, // imgdtt_params.lma_adjust_wxy, // boolean adjust_lazyeye_par, // adjust disparity corrections parallel to disparities lma_adjust_wxy
true, // imgdtt_params.lma_adjust_ly1, // boolean adjust_lazyeye_ortho, // adjust disparity corrections orthogonal to disparities lma_adjust_ly1
ds, // disp_str, // xcenter_str, // double [][] disp_str, // initial value of disparity/strength/?
imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width
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
);
if (all_pars_save != null) {
lma.all_pars = all_pars_save;
lma.toVector();
}
}
lma.setMatrices(disp_dist);
lma.initMatrices(); // should be called after initVector and after setMatrices
//boolean
if (debug_level > 1) {
System.out.println("Input data:");
lma.printInputDataFx(false);
lma.printParams();
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_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
debug_level); // 2); //4); // debug_level); // int debug_level) // > 3
}
lma.updateFromVector();
//double []
rms = lma.getRMS();
if (debug_level > 0) {
System.out.println("LMA -> "+lmaSuccess+" RMS="+rms[0]+", pure RMS="+rms[1]);
lma.printParams();
}
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_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
debug_level); // 2); //4); // debug_level); // int debug_level) // > 3
if (!lmaSuccess && (lma.getBadTile() >= 0)) {
if (debug_level > -2) {
System.out.println("Found bad tile/pair in a second pass (probably wrong initial maximum - try around preliminary? "+lma.getBadTile());
}
} else {
break;
}
}
if (debug_level > 1) {
System.out.println("Input data and approximation:");
lma.printInputDataFx(true);
}
if (lmaSuccess) {
// double [][] ds = lma.getDisparityStrength();
ds = lma.disparityStrength(
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
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
);
if (debug_level > -1) {
lma.printStats(ds,clust_width);
}
}
//double []
rms = lma.getRMS();
if (debug_level > 0) {
System.out.println("LMA -> "+lmaSuccess+" RMS="+rms[0]+", pure RMS="+rms[1]);
lma.printParams();
}
if (lmaSuccess) {
lma.updateFromVector();
if (debug_level > 1) {
System.out.println("Input data and approximation:");
lma.printInputDataFx(true);
}
// double [][] ds = lma.getDisparityStrength();
ds = lma.disparityStrength(
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
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
);
if (debug_level > -2) {
lma.printStats(ds,clust_width);
}
}
}
}
......@@ -2182,6 +2205,7 @@ public class Correlation2d {
double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
int pair_mask, // which pairs to process
double[] disp_str, // -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,
int debug_level,
int tileX, // just for debug output
......@@ -2190,7 +2214,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 need_poly = true; // find initial disparity by polynomial approximation
boolean need_poly = (disp_str == null); // true; // find initial disparity by polynomial approximation
boolean debug_graphic = imgdtt_params.lma_debug_graphic && (imgdtt_params.lma_debug_level1 > 3) && (debug_level > 0) ;
String dbg_title = null;
// if (debug_graphic) {
......@@ -2206,11 +2230,11 @@ public class Correlation2d {
transform_size,
corr_wnd,
rXY, //double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.lma_gaussian //boolean gaussian_mode
imgdtt_params.lmas_gaussian //boolean gaussian_mode
);
// double [][] dbg_corr = debug_graphic ? new double [corrs.length][] : null;
double [][] dbg_corr = debug_graphic ? new double [corrs.length][] : null;
double [][] dbg_weights = debug_graphic ? new double [corrs.length][] : null;
if (debug_graphic) {
(new ShowDoubleFloatArrays()).showArrays(
......@@ -2222,25 +2246,23 @@ public class Correlation2d {
}
double[][] corr_blur = new double[corrs.length][];
// double [] blur_max = new double[corrs.length];
for (int npair = 0; npair < corrs.length; npair++) if ((corrs[npair] != null) && (((pair_mask >> npair) & 1) !=0)){
// double[] corr = corrs[npair].clone();
corr_blur[npair] = corrs[npair].clone();
double [] corr_blur = corrs[npair].clone();
if (corr_wnd_inv_limited != null) {
for (int i = 0; i < corr_blur[npair].length; i++) {
corr_blur[npair][i] *= corr_wnd_inv_limited[i];
for (int i = 0; i < corr_blur.length; i++) {
corr_blur[i] *= corr_wnd_inv_limited[i];
}
}
if (imgdtt_params.lma_sigma > 0) {
gb.blurDouble(corr_blur[npair], corr_size, corr_size, imgdtt_params.lma_sigma, imgdtt_params.lma_sigma, 0.01);
gb.blurDouble(corr_blur, corr_size, corr_size, imgdtt_params.lma_sigma, imgdtt_params.lma_sigma, 0.01);
}
int imx = imgdtt_params.lma_soft_marg * (corr_size + 1);
for (int iy = imgdtt_params.lma_soft_marg; iy < (corr_size - imgdtt_params.lma_soft_marg); iy++) {
for (int ix = imgdtt_params.lma_soft_marg; ix < (corr_size - imgdtt_params.lma_soft_marg); ix++) {
int indx = iy * corr_size + ix;
if (corr_blur[npair][indx] > corr_blur[npair][imx]) imx = indx;
if (corr_blur[indx] > corr_blur[imx]) imx = indx;
}
}
......@@ -2249,14 +2271,14 @@ public class Correlation2d {
int ix0 = (imx % corr_size) - center; // signed, around center to match filterConvex
int iy0 = (imx / corr_size) - center; // signed, around center to match filterConvex
double [] filtWeight = filterConvex(
corr_blur[npair], // double [] corr_data,
corr_blur, // double [] corr_data,
imgdtt_params.cnvx_hwnd_size, // int hwin,
ix0, // int x0,
iy0, // int y0,
imgdtt_params.cnvx_add3x3, // boolean add3x3,
imgdtt_params.cnvx_weight, // double nc_cost,
(debug_level > 2)); // boolean debug);
// if (dbg_corr != null) dbg_corr [npair] = corr_blur[npair];
if (dbg_corr != null) dbg_corr [npair] = corr_blur;
if (dbg_weights != null) dbg_weights[npair] = filtWeight;
// Normalize weight for each pair to compensate for different number of convex samples?
......@@ -2279,15 +2301,14 @@ public class Correlation2d {
ix, // int x, // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis
iy, // int y, // y coordinate (0 - disparity axis)
v, // double v, // correlation value at that point
w, //double w){ // sample weight
corr_blur[npair][i]); // double bv) { // blurred/ normalized by window;
w); //double w) // sample weight
}
}
if (debug_graphic) {
(new ShowDoubleFloatArrays()).showArrays(
corr_blur,
dbg_corr,
corr_size,
corr_size,
true,
......@@ -2302,97 +2323,153 @@ public class Correlation2d {
}
// double [][] disp_str = {{xcenter, 1.0}}; // temporary
double [][] disp_str2 = {disp_str}; // temporary
lma.initVector( // USED in lwir
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
false, //imgdtt_params.lma_adjust_wxy, // boolean adjust_lazyeye_par, // adjust disparity corrections parallel to disparities lma_adjust_wxy
false, // imgdtt_params.lma_adjust_ly1, // boolean adjust_lazyeye_ortho, // adjust disparity corrections orthogonal to disparities lma_adjust_ly1
disp_str2, // 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_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
//center
double [] disp;
if (need_poly) {
disp = lma.polyDisparity(dbg_title); // double [] rslt = {-approx2d[0], approx2d[2], hwx, hwy};
if (disp == null) {
System.out.println("Poly disparity=NULL");
} else {
System.out.println("Poly disparity="+(disp[0])+", str="+disp[1]+", hwx="+disp[2]+", hwy="+disp[3]+
", disp_str2[0][0]="+disp_str2[0][0]+", disp_str2[0][1]="+disp_str2[0][1]);
}
}
double [][] disp_str2 = {{0.0, 1.0}}; // temporary // will be calculated/set later
if (disp_str != null) {
disp_str2[0] = disp_str;
}
// double [][] disp_str2 = {{0.0, 1.0}}; // temporary // will be calculated/set later
boolean lmaSuccess = false;
if (debug_level > 1) {
System.out.println("Input data:");
lma.printInputDataFx(false);
lma.printParams();
double [] disp = null;
while (!lmaSuccess) {
lma.initVector( // USED in lwir
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
false, //imgdtt_params.lma_adjust_wxy, // boolean adjust_lazyeye_par, // adjust disparity corrections parallel to disparities lma_adjust_wxy
false, // imgdtt_params.lma_adjust_ly1, // boolean adjust_lazyeye_ortho, // adjust disparity corrections orthogonal to disparities lma_adjust_ly1
disp_str2, // xcenter, // double disp0, // initial value of disparity
imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width
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 //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
//center
disp = null;
if (need_poly) {
disp = lma.polyDisparity(
corr_wnd_inv_limited,
transform_size-1-imgdtt_params.lma_soft_marg,//double max_offset, // 5?
dbg_title); // double [] rslt = {-approx2d[0], approx2d[2], hwx, hwy};
if (disp == null) {
if (debug_level > 0) {
System.out.println("Poly disparity=NULL");
}
} else {
disp[1] *= imgdtt_params.lmas_poly_str_scale;
if (debug_level > 0) {
System.out.println(String.format("Poly disparity=%8.5f , str=%8.5f, disp_str2[0][0]=%8.5f, disp_str2[0][1]=%8.5f",
disp[0],disp[1],disp_str2[0][0],disp_str2[0][1]));
}
if (disp[1] < imgdtt_params.lmas_poly_str_min) {
if (debug_level > 0) {
System.out.println("Poly strength too low ("+disp[1]+" < "+imgdtt_params.lmas_poly_str_min+")");
}
disp = null;
}
}
// double[] poly_ds, // null or pair of disparity/strength
if (poly_ds != null) {
poly_ds[0] = (disp==null) ? Double.NaN: disp[0];
poly_ds[1] = (disp==null) ? 0.0: disp[1];
}
} else {
disp = disp_str;
}
if (disp != null) {
disp_str2[0] = disp;
lma.initDisparity( // USED in lwir
disp_str2); // double [][] disp_str // initial value of disparity
if (debug_level > 1) {
System.out.println("Input data:");
lma.printInputDataFx(false);
lma.printParams();
}
lmaSuccess = lma.runLma(
imgdtt_params.lmas_lambda_initial, // double lambda, // 0.1
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.lmas_rms_diff, // double rms_diff, // 0.001
imgdtt_params.lmas_num_iter, // int num_iter, // 20
debug_level); // imgdtt_params.lma_debug_level1); // 4); // int debug_level) // > 3
if (!lmaSuccess && (lma.getBadTile() >= 0)) {
if (debug_level > -2) {
System.out.println("Found bad tile/pair during single (probably wrong initial maximum - try around preliminary? "+lma.getBadTile());
}
} else {
break;
}
} else {
break;
}
}
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_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
debug_level); // imgdtt_params.lma_debug_level1); // 4); // int debug_level) // > 3
if (lmaSuccess) {
lma.updateFromVector();
lma.updateFromVector();
double [][] dispStr = lma.disparityStrength(
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
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
);
System.out.println("dispStr[0][0]="+dispStr[0][0]+" dispStr[0][1]="+dispStr[0][1]);
double [][] dispStr = lma.disparityStrength(
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.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
);
if (dispStr[0][1] <= 0) {
lmaSuccess = false;
if (debug_level > -2) { // 0
System.out.println(String.format("Poly disparity=%8.5f , str=%8.5f", disp[0],disp[1]));
}
} else {
if (debug_level > -2) {
System.out.println(String.format("Poly disparity=%8.5f , str=%8.5f, LMA disparity=%8.5f, str=%8.5f",
disp[0],disp[1],dispStr[0][0],dispStr[0][1]));
}
// System.out.println("dispStr[0][0]="+dispStr[0][0]+" dispStr[0][1]="+dispStr[0][1]);
double [] rms = lma.getRMS();
if (debug_level > 0) {
System.out.println("LMA -> "+lmaSuccess+" RMS="+rms[0]+", pure RMS="+rms[1]);
lma.printParams();
}
double [] rms = lma.getRMS();
if (debug_level > 0) {
System.out.println("LMA -> "+lmaSuccess+" RMS="+rms[0]+", pure RMS="+rms[1]);
lma.printParams();
}
if (debug_level > 1) {
System.out.println("Input data and approximation:");
lma.printInputDataFx(true);
}
double [][] ds = null;
if (debug_graphic && lmaSuccess) {
String [] sliceTitles = lma.dbgGetSliceTiles();
if (corrs.length == 1) { // only for single-tile cluster
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(null,0)[0],
corr_size,
corr_size,
true,
"corr_values"+"_x"+tileX+"_y"+tileY, sliceTitles);
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(null,2)[0],
corr_size,
corr_size,
true,
"corr_fx"+"_x"+tileX+"_y"+tileY, sliceTitles);
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(null,1)[0],
corr_size,
corr_size,
true,
"corr_weights"+"_x"+tileX+"_y"+tileY, sliceTitles);
if (debug_level > 1) {
System.out.println("Input data and approximation:");
lma.printInputDataFx(true);
}
// double [][] ds = null;
if (debug_graphic && lmaSuccess) {
String [] sliceTitles = lma.dbgGetSliceTiles();
if (corrs.length == 1) { // only for single-tile cluster
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(null,0)[0],
corr_size,
corr_size,
true,
"corr_values"+"_x"+tileX+"_y"+tileY, sliceTitles);
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(null,2)[0],
corr_size,
corr_size,
true,
"corr_fx"+"_x"+tileX+"_y"+tileY, sliceTitles);
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(null,1)[0],
corr_size,
corr_size,
true,
"corr_weights"+"_x"+tileX+"_y"+tileY, sliceTitles);
}
}
}
}
}
return lmaSuccess? lma: null;
}
......
......@@ -1528,7 +1528,7 @@ public class ImageDtt {
// final double [][][][][] clt_corr_partial,// [tilesY][tilesX][quad]color][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [tilesY][tilesX] should be set by caller
// When clt_mismatch is non-zero, no far objects extraction will be attempted
// final double [][] clt_mismatch, // [12][tilesY * tilesX] // ***** transpose unapplied ***** ?. null - do not calculate
final double [][] clt_mismatch, // [12][tilesY * tilesX] // ***** transpose unapplied ***** ?. null - do not calculate
// values in the "main" directions have disparity (*_CM) subtracted, in the perpendicular - as is
final double [][] disparity_map, // [8][tilesY][tilesX], only [6][] is needed on input or null - do not calculate
......@@ -1598,6 +1598,8 @@ public class ImageDtt {
final int nClustersInChn=clustersX * clustersY;
final int clustSize = tileStep*tileStep;
final int debug_clustX = debug_tileX / tileStep;
final int debug_clustY = debug_tileY / tileStep;
///tileStep
final double [][][][][][] clt_data = new double[quad][numcol][tilesY][tilesX][][];
......@@ -1620,6 +1622,14 @@ public class ImageDtt {
}
}
}
if (clt_mismatch != null){
for (int i = 0; i<clt_mismatch.length;i++){
clt_mismatch[i] = new double [tilesY*tilesX]; // will use only "center of mass" centers
for (int j = 0; j < clt_mismatch[i].length; j++) {
clt_mismatch[i][j] = Double.NaN;
}
}
}
// keep for now for mono, find out what do they mean for macro mode
if (isMonochrome()) {
......@@ -1791,7 +1801,10 @@ public class ImageDtt {
// double [] disparity = new double [clustSize];
double [][] disp_str = new double [clustSize][];
boolean debugCluster = (clustX == (debug_tileX / tileStep)) && (clustY == (debug_tileY / tileStep));
boolean debugCluster = (clustX == debug_clustX) && (clustY == debug_clustY);
boolean debugCluster1 = (Math.abs(clustX - debug_clustX) < 10) && (Math.abs(clustY - debug_clustY) < 10);
int clust_lma_debug_level = debugCluster? imgdtt_params.lma_debug_level : -5;
......@@ -1861,24 +1874,26 @@ public class ImageDtt {
" centersXY["+cTile+"]["+i+"][0]="+centersXY[0][i][0]+" centersXY["+cTile+"]["+i+"][1]="+centersXY[cTile][i][1]);
}
}
if (debug_distort && debugCluster && (debug_offsets != null)) {
if (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[cTile][i][0] * debug_offsets[i][0] + disp_dist[cTile][i][1] * debug_offsets[i][1];
debug_offsets_xy[i][1] = disp_dist[cTile][i][2] * debug_offsets[i][0] + disp_dist[cTile][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[cTile][i][0] += debug_offsets_xy[i][0];
centersXY[cTile][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["+cTile+"]["+i+"][0]="+centersXY[cTile][i][0]+" centersXY["+cTile+"]["+i+"][1]="+centersXY[cTile][i][1]);
if (debug_distort && debugCluster) {
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 < quad; i++) {
System.out.println("Corrected clt_aberrations_quad_corr(): tileX="+tileX+", tileY="+tileY+
" centerX="+centerX+" centerY="+centerY+" disparity="+disparity_array[tileY][tileX]+
" centersXY["+cTile+"]["+i+"][0]="+centersXY[cTile][i][0]+" centersXY["+cTile+"]["+i+"][1]="+centersXY[cTile][i][1]);
}
}
}
......@@ -2041,13 +2056,13 @@ public class ImageDtt {
imgdtt_params.min_corr, // double minMax, // minimal value to consider (at integer location, not interpolated)
tile_lma_debug_level > 0); // boolean debug);
// double [] corr_stat = null;
// double [] corr_stat = null;
// if integer argmax was strong enough, calculate CM argmax
// will not fill out DISPARITY_INDEX_INT+1, DISPARITY_INDEX_CM+1, DISPARITY_INDEX_POLY+1
// use clt_mismatch for that
// double strength = 0.0;
// double disparity = 0.0;
// double strength = 0.0;
// double disparity = 0.0;
if (ixy != null) {
strength[cTile] = strip_combo[ixy[0]+transform_size-1]; // strength at integer max on axis
disparity_map[DISPARITY_INDEX_INT][tIndex] = -ixy[0];
......@@ -2065,64 +2080,72 @@ public class ImageDtt {
// proceed only if CM correlation result is non-null // for compatibility with old code we need it to run regardless of the strength of the normal correlation
if (corr_stat[cTile] != null) {
disp_str[cTile] = new double[2];
disp_str[cTile][0] = -corr_stat[cTile][0];
disp_str[cTile][1] = corr_stat[cTile][1]; // strength
// disparity[cTile] = -corr_stat[cTile][0];
// disparity_map[DISPARITY_INDEX_CM][tIndex] = disparity[cTile]; // disparity is negative X
disparity_map[DISPARITY_INDEX_CM][tIndex] = disp_str[cTile][0]; // disparity is negative X
if (tile_lma_debug_level > 0) {
System.out.println("Will run getMaxXSOrtho( ) for tileX="+tileX+", tileY="+tileY);
}
disparity_map[DISPARITY_INDEX_CM][tIndex] = -corr_stat[cTile][0]; // disp_str[cTile][0]; // disparity is negative X
}
disp_str[cTile] = new double[2];
// disp_str[cTile][0] = -corr_stat[cTile][0];
// disp_str[cTile][1] = corr_stat[cTile][1]; // strength
if (tile_lma_debug_level > 0) {
System.out.println("Will run getMaxXSOrtho( ) for tileX="+tileX+", tileY="+tileY);
}
// debug new LMA correlations
if (debugCluster) {
if (globalDebugLevel > -2) {
System.out.println("Will run new LMA for tileX="+tileX+", tileY="+tileY);
// debug new LMA correlations
int tdl = debugCluster ? tile_lma_debug_level : -3;
if (true) { // debugCluster1) {
if (debugCluster && (globalDebugLevel > -1)) { // -2)) {
System.out.println("Will run new LMA for tileX="+tileX+", tileY="+tileY);
}
double [] poly_disp = {Double.NaN, 0.0};
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_inv_limited, // corr_wnd_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
null, // disp_str[cTile], //corr_stat[0], // double xcenter, // preliminary center x in pixels for largest baseline
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,
tdl, // tile_lma_debug_level, //+2, // int debug_level,
tileX, // int tileX, // just for debug output
tileY); // int tileY
disp_str[cTile] = null;
disparity_map[DISPARITY_INDEX_HOR][tIndex] = poly_disp[0];
disparity_map[DISPARITY_INDEX_HOR_STRENGTH][tIndex] = poly_disp[1];
if (lma2 != null) {
disp_str[cTile] = lma2.disparityStrength(
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.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
)[0];
if (tile_lma_debug_level > 0) {
double [][] ds_dbg = {disp_str[cTile]};
lma2.printStats(ds_dbg,1);
}
if (disp_str[cTile] != null) {
disparity_map[DISPARITY_INDEX_POLY][tIndex] = disp_str[cTile][0];
disparity_map[DISPARITY_INDEX_POLY+1][tIndex] = disp_str[cTile][1];
}
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_inv_limited, // corr_wnd_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
disp_str[cTile], //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, //+2, // int debug_level,
tileX, // int tileX, // just for debug output
tileY); // int tileY
disp_str[cTile] = null;
if (lma2 != null) {
disp_str[cTile] = lma2.disparityStrength(
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
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
)[0];
if (tile_lma_debug_level > 0) {
double [][] ds_dbg = {disp_str[cTile]};
lma2.printStats(ds_dbg,1);
}
}
}
} // end of if (corr_stat != null)
}
//} // end of if (corr_stat != null)
} // if (disparity_map != null){ // not null - calculate correlations
// only debug is left
}
}
}
}
if (debugCluster) {
if (true) { //debugCluster1) {
if (globalDebugLevel > 0) {
System.out.println("Will run new LMA for clustX="+clustX+", clustY="+clustY);
}
@SuppressWarnings("unused")
Corr2dLMA lma2 = corr2d.corrLMA2(
imgdtt_params, // ImageDttParameters imgdtt_params,
tileStep, // int clust_width,
......@@ -2130,37 +2153,56 @@ 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
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
disp_str, // corr_stat, // double[][] xcenter_str, // preliminary center x in pixels for largest baseline
imgdtt_params.ortho_vasw_pwr, // double vasw_pwr, // value as weight to this power,
clust_lma_debug_level + 0, // 2, // int debug_level,
// ddnd, // double [][] ddnd, // should provide [4][]
// stats, // double [][] stats, // should provide [1][]
clust_lma_debug_level + 0, // 2, // int debug_level, // for a single cluster
clustX, // int tileX, // just for debug output
clustY ); // int tileY
if (lma2 != null) {
double [][] ddnd = lma2.getDdNd();
double [] stats = lma2.getStats();
double [][] lma2_ds = lma2.disparityStrength(
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
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 cTileY = 0; cTileY < tileStep; cTileY++) {
tileY = clustY * tileStep + cTileY ;
if (tileY < tilesY) {
for (int cTileX = 0; cTileX < tileStep; cTileX++) {
tileX = clustX * tileStep + cTileX ;
if (tileX < tilesX) {
cTile = cTileY * tileStep + cTileX;
tIndex = tileY * tilesX + tileX;
// int nTile = tileY * tilesX + tileX; // how is it different from tIndex?
for (int cam = 0; cam < ddnd.length; cam++) {
if (ddnd[cam] != null) {
clt_mismatch[3*cam + 0][tIndex] = ddnd[cam][0];
clt_mismatch[3*cam + 1][tIndex] = ddnd[cam][1];
}
if (stats != null) {
disparity_map[IMG_DIFF0_INDEX+0][tIndex] = stats[0];
disparity_map[IMG_DIFF0_INDEX+1][tIndex] = stats[1];
disparity_map[IMG_DIFF0_INDEX+2][tIndex] = stats[2];
// disparity_map[IMG_DIFF0_INDEX+3][tIndex] = stats[3];
}
if ((lma2_ds != null) && ((lma2_ds[cTile] != null))) {
disparity_map[DISPARITY_INDEX_VERT][tIndex] = lma2_ds[cTile][0];
disparity_map[DISPARITY_INDEX_VERT_STRENGTH][tIndex] = lma2_ds[cTile][1];
}
}
}
}
}
}
}
}
/*
public Corr2dLMA corrLMA2( // multi-tile
ImageDttParameters imgdtt_params,
int clust_width,
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, // per tile, per pair, 2 correlation in line-scan order
double [][][] disp_dist, // per tile, per camera disparity matrix as a 1d (linescan order)
int pair_mask, // which pairs to process
boolean run_poly_instead, // true - run LMA, false - run 2d polynomial approximation
double xcenter, // preliminary center x in pixels for largest baseline
double vasw_pwr, // value as weight to this power,
int debug_level,
int tileX, // just for debug output
int tileY
)
*/
}
}
......@@ -3014,7 +3056,7 @@ public class ImageDtt {
if (debugTile) {
System.out.println("Will run new LMA for tileX="+tileX+", tileY="+tileY);
double [] poly_disp = {Double.NaN, 0.0};
Corr2dLMA lma2 = corr2d.corrLMA2(
imgdtt_params, // ImageDttParameters imgdtt_params,
corr_wnd, // double [][] corr_wnd, // correlation window to save on re-calculation of the window
......@@ -3023,8 +3065,8 @@ public class ImageDtt {
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
disp_str, //corr_stat[0], // double xcenter, // preliminary center x in pixels for largest baseline
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,
tile_lma_debug_level+2, // int debug_level,
tileX, // int tileX, // just for debug output
......
......@@ -99,9 +99,26 @@ public class ImageDttParameters {
public double corr_wndx_blur = 5.0; // 100% to 0 % vertical transition range
// LMA parameters
// LMA single parameters
public boolean lmas_gaussian = false; // model correlation maximum as a Gaussian (false - as a parabola)
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
public double lmas_lambda_initial = 0.03; //
public double lmas_rms_diff = 0.001; //
public int lmas_num_iter = 20; //
// Filtering and strength calculation
public double lmas_max_rel_rms = 0.2; // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
public double lmas_min_strength = 1.0; // minimal composite strength (sqrt(average amp squared over absolute RMS)
public double lmas_min_ac = 0.03; // minimal of a and C coefficients maximum (measures sharpest point/line)
public boolean lma_gaussian = false; // model correlation maximum as a Gaussian (false - as a parabola)
public boolean lma_second = true; // re-run LMA after removing weak/failed tiles
public boolean lma_second_gaussian = true; // re-run after removing weal/failed in Gaussian mode
public boolean lma_second = false; // re-run LMA after removing weak/failed tiles
public boolean lma_second_gaussian = false; // re-run after removing weal/failed in Gaussian mode
public boolean lma_adjust_wm = true; // used in new for width
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
......@@ -117,12 +134,13 @@ public class ImageDttParameters {
public double lma_sigma = 0.7; // Blur correlation before finding maximum and convex region
// maybe try using sqrt (corr_wnd) ? or variable power?
public double lma_half_width = 2.0; //
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_cost_wy = 0.0; // cost of parallel-to-disparity correction
public double lma_cost_wxy = 0.0; // cost of ortho-to-disparity correction
public double lma_lambda_initial = 0.03; //
public double lma_lambda_scale_good = 0.5; //
......@@ -139,8 +157,10 @@ public class ImageDttParameters {
public double lma_str_offset = 0.05; // convert lma-generated strength to match previous ones - add to result
// Lazy eye results interpretation
public boolean lma_diff_xy = true; // convert dd/nd to x,y
public double lma_diff_minw = 0.5; // minimal weight to keep
public double lma_diff_sigma = 1.0; // blur differential data (relative to the cluster linear size)
public int lma_debug_level = 0; //
public int lma_debug_level1 = 0; //
......@@ -290,6 +310,38 @@ public class ImageDttParameters {
"Transition range, shifted sine is used");
gd.addTab("Corr LMA","Parameters for LMA fitting of the correlation maximum parameters");
gd.addMessage("Single-tile (no lazy eye) only parameters (some are common");
gd.addCheckbox ("Correlation maximum as gaussian", this.lmas_gaussian,
"Model correlation maximum as a Gaussian exp(-r^2) (false - as a parabola - 1-r^2)");
gd.addCheckbox ("Fit correlation defined half-width", this.lmas_adjust_wm,
"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.lmas_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 per-pair scale (was Adjust per-group amplitudes)", this.lmas_adjust_ag,
"Each correlation pair gain (was Each correlation type's amplitude (now always needed))");
gd.addMessage("pre-LMA (polynomial) filtering");
gd.addNumericField("Scale pre-LMA poly strength", this.lmas_poly_str_scale, 3, 6, "",
"Calculated as maximal value over average radius");
gd.addNumericField("Minimal pre-LMA poly strength (scaled)", this.lmas_poly_str_min, 3, 6, "",
"Ignore tiles with pre-LMA poly strength (scaled with above) below this value");
gd.addMessage("LMA (single) LMA fitting parameters");
gd.addNumericField("Initial value of LMA lambda", this.lmas_lambda_initial, 3, 6, "",
"The higher the lambda the more close it will be to the gradient descent (slower/safer)");
gd.addNumericField("Relative RMS improvement to exit LMA", this.lmas_rms_diff, 6, 8, "",
"LMA will report success when realtive RMS improvements fall below this value");
gd.addNumericField("LMA maximal iterations", this.lmas_num_iter, 0, 3, "",
"Limit LMA cycles, so it will exit after certain number of small improvements");
gd.addMessage("LMA (single) results filtering");
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, "",
"Discard tile if composite strength (average amplitude over SQRT of RMS) is below");
gd.addNumericField("Minimal max (A,C)", this.lmas_min_ac, 6, 8, "",
"Minimal value of max (A,C) coefficients to keep the tile (measures sharpest point/line correlation maximum)");
gd.addMessage("Multi-tile (for lazy eye) LMA (some are used for with single-tile mode too)");
gd.addCheckbox ("Correlation maximum as gaussian", this.lma_gaussian,
"Model correlation maximum as a Gaussian exp(-r^2) (false - as a parabola - 1-r^2)");
gd.addCheckbox ("Re-run LMA after removing weak/failed tiles", this.lma_second,
......@@ -322,6 +374,7 @@ public class ImageDttParameters {
gd.addNumericField("LMA blur sigma", this.lma_sigma, 3, 6, "",
"Blur correlation before finding maximum and convex region");
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("Lazy eye cost parallel to disparity (was Cost of the difference of the actual half-width...)", this.lma_cost_wy, 5, 8, "",
......@@ -354,9 +407,18 @@ public class ImageDttParameters {
gd.addMessage("Correlation strength calculation (match legacy)");
gd.addNumericField("Composite correlation strength scale", this.lma_str_scale, 6, 8, "",
"Multiply LMA composite correlation strength to match older CM value");
gd.addNumericField("Composite correlation strength offset", this.lma_str_offset, 6, 8, "",
gd.addNumericField("Composite correlation strength offset", this.lma_str_offset, 6, 8, "",
"Add to scaled composite correlation strength to match older CM value");
gd.addMessage("Lazy eye results interpretation");
gd.addCheckbox ("Convert dd, nd -> dx, dx", this.lma_diff_xy,
"Convert per camera disparity correction (and orthogonal to disparity) to X,Y correction");
gd.addNumericField("Minimal per-tile weight for lazy eye correction", this.lma_diff_minw, 6, 8, "",
"Minimal average per-tile weight to use this tile cluster for lazy eye correction");
gd.addNumericField("Lazy eye data blur sigma", this.lma_diff_sigma, 6, 8, "",
"Lazy eye data blur sigma relative to tile cluster side");
gd.addMessage("Debug LMA parameters");
gd.addNumericField("LMA debug level", this.lma_debug_level, 0, 3, "",
"Debug/verbosity level for the LMA correaltion maximum fitting");
......@@ -465,6 +527,21 @@ public class ImageDttParameters {
this.corr_wndx_blur = gd.getNextNumber();
//LMA tab
this.lmas_gaussian= gd.getNextBoolean();
this.lmas_adjust_wm= gd.getNextBoolean();
this.lmas_adjust_wy= gd.getNextBoolean();
this.lmas_adjust_ag= gd.getNextBoolean();
this.lmas_poly_str_scale = gd.getNextNumber();
this.lmas_poly_str_min = gd.getNextNumber();
this.lmas_lambda_initial = gd.getNextNumber();
this.lmas_rms_diff = gd.getNextNumber();
this.lmas_num_iter= (int) gd.getNextNumber();
this.lmas_max_rel_rms = gd.getNextNumber();
this.lmas_min_strength = gd.getNextNumber();
this.lmas_min_ac = gd.getNextNumber();
this.lma_gaussian= gd.getNextBoolean();
this.lma_second= gd.getNextBoolean();
this.lma_second_gaussian= gd.getNextBoolean();
......@@ -481,6 +558,7 @@ public class ImageDttParameters {
this.lma_soft_marg= (int) gd.getNextNumber();
this.lma_sigma = gd.getNextNumber();
this.lma_half_width = gd.getNextNumber();
this.lma_cost_wy = gd.getNextNumber();
this.lma_cost_wxy = gd.getNextNumber();
......@@ -498,6 +576,10 @@ public class ImageDttParameters {
this.lma_str_scale = gd.getNextNumber();
this.lma_str_offset = gd.getNextNumber();
this.lma_diff_xy = gd.getNextBoolean();
this.lma_diff_minw= gd.getNextNumber();
this.lma_diff_sigma= gd.getNextNumber();
this.lma_debug_level= (int) gd.getNextNumber();
this.lma_debug_level1= (int) gd.getNextNumber();
this.lma_debug_graphic = gd.getNextBoolean();
......@@ -578,6 +660,21 @@ public class ImageDttParameters {
properties.setProperty(prefix+"corr_wndx_hwidth", this.corr_wndx_hwidth +"");
properties.setProperty(prefix+"corr_wndx_blur", this.corr_wndx_blur +"");
properties.setProperty(prefix+"lmas_gaussian", this.lmas_gaussian +"");
properties.setProperty(prefix+"lmas_adjust_wm", this.lmas_adjust_wm +"");
properties.setProperty(prefix+"lmas_adjust_wy", this.lmas_adjust_wy +"");
properties.setProperty(prefix+"lmas_adjust_ag", this.lmas_adjust_ag +"");
properties.setProperty(prefix+"lmas_poly_str_scale", this.lmas_poly_str_scale +"");
properties.setProperty(prefix+"lmas_poly_str_min", this.lmas_poly_str_min +"");
properties.setProperty(prefix+"lmas_lambda_initial", this.lmas_lambda_initial +"");
properties.setProperty(prefix+"lmas_rms_diff", this.lmas_rms_diff +"");
properties.setProperty(prefix+"lmas_num_iter", this.lmas_num_iter +"");
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 +"");
properties.setProperty(prefix+"lma_gaussian", this.lma_gaussian +"");
properties.setProperty(prefix+"lma_second", this.lma_second +"");
properties.setProperty(prefix+"lma_second_gaussian", this.lma_second_gaussian +"");
......@@ -595,6 +692,7 @@ public class ImageDttParameters {
properties.setProperty(prefix+"lma_soft_marg", this.lma_soft_marg +"");
properties.setProperty(prefix+"lma_sigma", this.lma_sigma +"");
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 +"");
......@@ -612,6 +710,10 @@ public class ImageDttParameters {
properties.setProperty(prefix+"lma_str_scale", this.lma_str_scale +"");
properties.setProperty(prefix+"lma_str_offset", this.lma_str_offset +"");
properties.setProperty(prefix+"lma_diff_xy", this.lma_diff_xy +"");
properties.setProperty(prefix+"lma_diff_minw", this.lma_diff_minw +"");
properties.setProperty(prefix+"lma_diff_sigma", this.lma_diff_sigma +"");
properties.setProperty(prefix+"lma_debug_level", this.lma_debug_level +"");
properties.setProperty(prefix+"lma_debug_level1", this.lma_debug_level1 +"");
properties.setProperty(prefix+"lma_debug_graphic", this.lma_debug_graphic +"");
......@@ -698,6 +800,21 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"corr_wndx_hwidth")!=null) this.corr_wndx_hwidth=Double.parseDouble(properties.getProperty(prefix+"corr_wndx_hwidth"));
if (properties.getProperty(prefix+"corr_wndx_blur")!=null) this.corr_wndx_blur=Double.parseDouble(properties.getProperty(prefix+"corr_wndx_blur"));
if (properties.getProperty(prefix+"lmas_gaussian")!=null) this.lmas_gaussian=Boolean.parseBoolean(properties.getProperty(prefix+"lmas_gaussian"));
if (properties.getProperty(prefix+"lmas_adjust_wm")!=null) this.lmas_adjust_wm=Boolean.parseBoolean(properties.getProperty(prefix+"lmas_adjust_wm"));
if (properties.getProperty(prefix+"lmas_adjust_wy")!=null) this.lmas_adjust_wy=Boolean.parseBoolean(properties.getProperty(prefix+"lmas_adjust_wy"));
if (properties.getProperty(prefix+"lmas_adjust_ag")!=null) this.lmas_adjust_ag=Boolean.parseBoolean(properties.getProperty(prefix+"lmas_adjust_ag"));
if (properties.getProperty(prefix+"lmas_poly_str_scale")!=null) this.lmas_poly_str_scale=Double.parseDouble(properties.getProperty(prefix+"lmas_poly_str_scale"));
if (properties.getProperty(prefix+"lmas_poly_str_min")!=null) this.lmas_poly_str_min=Double.parseDouble(properties.getProperty(prefix+"lmas_poly_str_min"));
if (properties.getProperty(prefix+"lmas_lambda_initial")!=null) this.lmas_lambda_initial=Double.parseDouble(properties.getProperty(prefix+"lmas_lambda_initial"));
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_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"));
if (properties.getProperty(prefix+"lma_gaussian")!=null) this.lma_gaussian=Boolean.parseBoolean(properties.getProperty(prefix+"lma_gaussian"));
if (properties.getProperty(prefix+"lma_second")!=null) this.lma_second=Boolean.parseBoolean(properties.getProperty(prefix+"lma_second"));
if (properties.getProperty(prefix+"lma_second_gaussian")!=null) this.lma_second_gaussian=Boolean.parseBoolean(properties.getProperty(prefix+"lma_second_gaussian"));
......@@ -705,8 +822,6 @@ public class ImageDttParameters {
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_wnd")!=null) this.lma_wnd=Double.parseDouble(properties.getProperty(prefix+"lma_wnd"));
......@@ -716,7 +831,6 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"lma_soft_marg")!=null) this.lma_soft_marg=Integer.parseInt(properties.getProperty(prefix+"lma_soft_marg"));
if (properties.getProperty(prefix+"lma_sigma")!=null) this.lma_sigma=Double.parseDouble(properties.getProperty(prefix+"lma_sigma"));
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"));
......@@ -734,6 +848,10 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"lma_str_scale")!=null) this.lma_str_scale=Double.parseDouble(properties.getProperty(prefix+"lma_str_scale"));
if (properties.getProperty(prefix+"lma_str_offset")!=null) this.lma_str_offset=Double.parseDouble(properties.getProperty(prefix+"lma_str_offset"));
if (properties.getProperty(prefix+"lma_diff_xy")!=null) this.lma_diff_xy=Boolean.parseBoolean(properties.getProperty(prefix+"lma_diff_xy"));
if (properties.getProperty(prefix+"lma_diff_minw")!=null) this.lma_diff_minw=Double.parseDouble(properties.getProperty(prefix+"lma_diff_minw"));
if (properties.getProperty(prefix+"lma_diff_sigma")!=null) this.lma_diff_sigma=Double.parseDouble(properties.getProperty(prefix+"lma_diff_sigma"));
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+"lma_debug_graphic")!=null) this.lma_debug_graphic=Boolean.parseBoolean(properties.getProperty(prefix+"lma_debug_graphic"));
......@@ -817,6 +935,21 @@ public class ImageDttParameters {
idp.corr_wndx_hwidth = this.corr_wndx_hwidth;
idp.corr_wndx_blur = this.corr_wndx_blur;
idp.lmas_gaussian = this.lmas_gaussian;
idp.lmas_adjust_wm = this.lmas_adjust_wm;
idp.lmas_adjust_wy = this.lmas_adjust_wy;
idp.lmas_adjust_ag = this.lmas_adjust_ag;
idp.lmas_poly_str_scale = this.lmas_poly_str_scale;
idp.lmas_poly_str_min = this.lmas_poly_str_min;
idp.lmas_lambda_initial = this.lma_lambda_initial;
idp.lmas_rms_diff = this.lma_rms_diff;
idp.lmas_num_iter = this.lma_num_iter;
idp.lmas_max_rel_rms= this.lma_max_rel_rms;
idp.lmas_min_strength= this.lma_min_strength;
idp.lmas_min_ac= this.lma_min_ac;
idp.lma_gaussian = this.lma_gaussian;
idp.lma_second = this.lma_second;
idp.lma_second_gaussian = this.lma_second_gaussian;
......@@ -824,7 +957,6 @@ public class ImageDttParameters {
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_wnd = this.lma_wnd;
......@@ -851,6 +983,10 @@ public class ImageDttParameters {
idp.lma_str_scale= this.lma_str_scale;
idp.lma_str_offset= this.lma_str_offset;
idp.lma_diff_xy = this.lma_diff_xy;
idp.lma_diff_minw = this.lma_diff_minw;
idp.lma_diff_sigma = this.lma_diff_sigma;
idp.lma_debug_level = this.lma_debug_level;
idp.lma_debug_level1 = this.lma_debug_level1;
idp.lma_debug_graphic = this.lma_debug_graphic;
......
......@@ -4703,7 +4703,7 @@ public class QuadCLT {
// correlation results - final and partial
// clt_corr_combo, // [tp.tilesY][tp.tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// clt_corr_partial, // [tp.tilesY][tp.tilesX][pair][color][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// clt_mismatch, // [12][tp.tilesY * tp.tilesX] // transpose unapplied. null - do not calculate
clt_mismatch, // [12][tp.tilesY * tp.tilesX] // transpose unapplied. null - do not calculate
disparity_map, // [2][tp.tilesY * tp.tilesX]
// texture_tiles, // [tp.tilesY][tp.tilesX]["RGBA".length()][];
imp_quad[0].getWidth(), // final int width,
......@@ -4750,6 +4750,108 @@ public class QuadCLT {
// (clt_parameters.dbg_mode & 256) != 0, // transpose convolve
threadsMax,
debugLevel);
if (disparity_map != null){
if (!batch_mode && clt_parameters.show_map && (debugLevel > -2)){
sdfa_instance.showArrays(
disparity_map,
tilesX,
tilesY,
true,
name+sAux()+"-DISP_MAP-D"+clt_parameters.disparity,
ImageDtt.DISPARITY_TITLES);
}
if (clt_mismatch != null) {
sdfa_instance.showArrays(
clt_mismatch,
tilesX,
tilesY,
true,
name+sAux()+"-CLT_MISMATCH-D"+clt_parameters.disparity);
// ImageDtt.DISPARITY_TITLES);
double min_bw = 0.005;
// double [][] mismatch_w = new double [clt_mismatch.length][tilesX*tilesY];
double mismatch_sigma = clt_parameters.tileStep * clt_parameters.img_dtt.lma_diff_sigma;
DoubleGaussianBlur gb = new DoubleGaussianBlur();
for (int ntile = 0; ntile < clt_mismatch[0].length; ntile++) {
double w = disparity_map[ImageDtt.IMG_DIFF0_INDEX+0][ntile];
if ( !(w >= clt_parameters.img_dtt.lma_diff_minw)) {
w = 0.0;
}
for (int n = 0; n < clt_mismatch.length/3; n++) {
if (w <= 0.0) {
clt_mismatch[3*n+0][ntile] = Double.NaN;
clt_mismatch[3*n+1][ntile] = Double.NaN;
clt_mismatch[3*n+2][ntile] = 0.0;
} else {
clt_mismatch[3*n+2][ntile] = w;
}
}
}
sdfa_instance.showArrays(
clt_mismatch,
tilesX,
tilesY,
true,
name+sAux()+"-CLT_MISMATCH-FILTERED-D"+clt_parameters.disparity);
for (int ntile = 0; ntile < clt_mismatch[0].length; ntile++) {
double w = disparity_map[ImageDtt.IMG_DIFF0_INDEX+0][ntile];
if ( !(w >= clt_parameters.img_dtt.lma_diff_minw)) {
w = 0.0;
}
for (int n = 0; n < clt_mismatch.length/3; n++) {
if (w <= 0.0) {
clt_mismatch[3*n+0][ntile] = 0.0;
clt_mismatch[3*n+1][ntile] = 0.0;
clt_mismatch[3*n+2][ntile] = 0.0;
} else {
clt_mismatch[3*n+0][ntile] *= w;
clt_mismatch[3*n+1][ntile] *= w;
clt_mismatch[3*n+2][ntile] = w;
}
}
}
for (int n = 0; n < clt_mismatch.length/3; n++) {
gb.blurDouble(clt_mismatch[3*n+0] , tilesX, tilesY, mismatch_sigma, mismatch_sigma, 0.01);
gb.blurDouble(clt_mismatch[3*n+1] , tilesX, tilesY, mismatch_sigma, mismatch_sigma, 0.01);
gb.blurDouble(clt_mismatch[3*n+2] , tilesX, tilesY, mismatch_sigma, mismatch_sigma, 0.01);
for (int ntile = 0; ntile < clt_mismatch[0].length; ntile++) {
if (clt_mismatch[3*n+2][ntile] >= min_bw) {
clt_mismatch[3*n+0][ntile] /= clt_mismatch[3*n+2][ntile];
clt_mismatch[3*n+1][ntile] /= clt_mismatch[3*n+2][ntile];
if (n>0) {
double w = disparity_map[ImageDtt.IMG_DIFF0_INDEX+0][ntile];
if ( w < clt_parameters.img_dtt.lma_diff_minw) {
w = 0.0;
}
clt_mismatch[3*n+2][ntile] = w;
}
} else {
clt_mismatch[3*n+0][ntile] = Double.NaN;
clt_mismatch[3*n+1][ntile] = Double.NaN;
clt_mismatch[3*n+2][ntile] = 0.0;
}
}
}
sdfa_instance.showArrays(
clt_mismatch,
tilesX,
tilesY,
true,
name+sAux()+"-CLT_MISMATCH-BLUR-D"+clt_parameters.disparity);
}
/*
public boolean lma_diff_xy = true; // convert dd/nd to x,y
public double lma_diff_minw = 0.5; // minimal weight to keep
public double lma_diff_sigma = 2.0; // blur differential data (relative to the cluster linear size)
*/
}
return results;
}
......
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