Commit 98f8ebea authored by Andrey Filippov's avatar Andrey Filippov

Debugging polynomial fitting as initial for LMA

parent d1ddd6b3
......@@ -65,6 +65,10 @@ Fx=A(i)*W(x,y)*(pa*(x-x0j)^2+2*pb*(x-x0j)*(y-y0j)+pc*(y-y0j)^2)
*/
import java.util.ArrayList;
import com.elphel.imagej.common.DoubleGaussianBlur;
import com.elphel.imagej.common.PolynomialApproximation;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import Jama.Matrix;
......@@ -90,6 +94,7 @@ public class Corr2dLMA {
private int [] par_map;
private double [] vector;
private ArrayList<Sample> samples = new ArrayList<Sample>();
// private ArrayList<Sample> norm_samples = new ArrayList<Sample>(); // to calculate
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;
......@@ -116,6 +121,7 @@ public class Corr2dLMA {
private int last_cam; // index of the last camera (special treatment for disparity correction)
private int pre_last_cam; // index of the pre-last camera (special treatment for disparity correction)
private Matrix [][][] m_pairs;
private Matrix [][][] m_pairs_inv; // inverted m_pairs to calculate x,y -> dd,nd for initial disparity calculation
private final int [][] pindx = new int [NUM_CAMS][NUM_CAMS];
private int numTiles = 1;
private Matrix mddnd; // Matrix to calculate 2 last corrections in disparity direction and 1 ortho from the first ones (normally 2+3=5)
......@@ -124,6 +130,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 class Sample{ // USED in lwir
int tile; // tile in a cluster
......@@ -133,6 +142,7 @@ 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
......@@ -140,7 +150,8 @@ 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 w,
double bv)
{
this.tile = tile;
this.fcam = fcam;
......@@ -149,7 +160,12 @@ 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);
}
}
......@@ -174,53 +190,33 @@ public class Corr2dLMA {
ndisp_index = ddisp_index + NUM_CAMS; // disparity offset per camera - none should be disable
num_all_pars = ndisp_index+ NUM_CAMS; // maximal number of parameters
boolean sq = false;
// boolean sq = true; // false;
this.transform_size = ts;
if (corr_wnd != null) {
this.corr_wnd = corr_wnd;
} else {
this.corr_wnd = new double[2 * transform_size - 1][2 * transform_size - 1];
int tsm1 = transform_size - 1; // 7
int dtsm1 = 2 * transform_size - 1; // 15
this.corr_wnd[tsm1][tsm1] = 1.0;
for (int i = 1; i < transform_size; i++) {
this.corr_wnd[tsm1 + i][tsm1 ] = Math.cos(Math.PI*i/(2 * transform_size));
this.corr_wnd[tsm1 - i][tsm1 ] = Math.cos(Math.PI*i/(2 * transform_size));
this.corr_wnd[tsm1 ][tsm1 + i] = Math.cos(Math.PI*i/(2 * transform_size));
this.corr_wnd[tsm1 ][tsm1 - i] = Math.cos(Math.PI*i/(2 * transform_size));
}
for (int i = 1; i < transform_size; i++) {
for (int j = 1; j < transform_size; j++) {
double d = this.corr_wnd[tsm1 + i][tsm1] * this.corr_wnd[tsm1 + j][tsm1];
this.corr_wnd[tsm1 + i][tsm1 + j] = d;
this.corr_wnd[tsm1 + i][tsm1 - j] = d;
this.corr_wnd[tsm1 - i][tsm1 + j] = d;
this.corr_wnd[tsm1 - i][tsm1 - j] = d;
}
}
if (sq) {
for (int i = 0; i < dtsm1; i++) {
for (int j = 0; j < dtsm1; j++) {
this.corr_wnd[i][j] *=this.corr_wnd[i][j];
}
}
}
}
this.corr_wnd = corr_wnd;
}
/*
public static double [][] getCorrWnd(int transform_size){
return getCorrWnd(transform_size, false);
return getCorrWnd(transform_size, true);// false);
}
public static double [][] getCorrWnd(int transform_size, boolean sq){ // sq = false
*/
public static double [][] getCorrWnd(int transform_size, double pwr){ // sq = false
// double pwr = 1.3;
double [][] corr_wnd = new double[2 * transform_size - 1][2 * transform_size - 1];
int tsm1 = transform_size - 1; // 7
int dtsm1 = 2 * transform_size - 1; // 15
corr_wnd[tsm1][tsm1] = 1.0;
for (int i = 1; i < transform_size; i++) {
corr_wnd[tsm1 + i][tsm1 ] = Math.cos(Math.PI*i/(2 * transform_size));
corr_wnd[tsm1 - i][tsm1 ] = Math.cos(Math.PI*i/(2 * transform_size));
corr_wnd[tsm1 ][tsm1 + i] = Math.cos(Math.PI*i/(2 * transform_size));
corr_wnd[tsm1 ][tsm1 - i] = Math.cos(Math.PI*i/(2 * transform_size));
if (pwr != 1.0) {
corr_wnd[tsm1 + i][tsm1 ] = Math.pow(Math.cos(Math.PI*i/(2 * transform_size)),pwr);
corr_wnd[tsm1 - i][tsm1 ] = Math.pow(Math.cos(Math.PI*i/(2 * transform_size)),pwr);
corr_wnd[tsm1 ][tsm1 + i] = Math.pow(Math.cos(Math.PI*i/(2 * transform_size)),pwr);
corr_wnd[tsm1 ][tsm1 - i] = Math.pow(Math.cos(Math.PI*i/(2 * transform_size)),pwr);
} else {
corr_wnd[tsm1 + i][tsm1 ] = Math.cos(Math.PI*i/(2 * transform_size));
corr_wnd[tsm1 - i][tsm1 ] = Math.cos(Math.PI*i/(2 * transform_size));
corr_wnd[tsm1 ][tsm1 + i] = Math.cos(Math.PI*i/(2 * transform_size));
corr_wnd[tsm1 ][tsm1 - i] = Math.cos(Math.PI*i/(2 * transform_size));
}
}
for (int i = 1; i < transform_size; i++) {
for (int j = 1; j < transform_size; j++) {
......@@ -231,13 +227,6 @@ public class Corr2dLMA {
corr_wnd[tsm1 - i][tsm1 - j] = d;
}
}
if (sq) {
for (int i = 0; i < dtsm1; i++) {
for (int j = 0; j < dtsm1; j++) {
corr_wnd[i][j] *= corr_wnd[i][j];
}
}
}
return corr_wnd;
}
......@@ -252,11 +241,33 @@ 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
if ((w > 0) && !Double.isNaN(v)) samples.add(new Sample(tile,fcam,scam,x,y,v,w));
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));
}
public ArrayList<Sample> filterSamples(
double [][] disparity_strength) {
ArrayList<Sample> filtered_samples = new ArrayList<Sample>();
for (Sample s:samples) {
if (disparity_strength[s.tile][1] > 0.0) {
filtered_samples.add(s);
}
}
samples = filtered_samples;
return samples;
}
public double [][][] dbgGetSamples(int mode){
boolean samplesExist() {
return ((samples !=null) && !samples.isEmpty());
}
void setSamples(ArrayList<Sample> samples) {
this.samples = samples;
}
public double [][][] dbgGetSamples(double [][] ds, int mode){
int [][] comb_map = getCombMap();
int numPairs = comb_map[0][0];
comb_map[0][0] = -1;
......@@ -279,28 +290,20 @@ public class Corr2dLMA {
}
for (int ns = 0; ns < samples.size(); ns++) {
Sample s = samples.get(ns);
if ((ds != null) && Double.isNaN(ds[s.tile][0])) {
continue;
}
double d = Double.NaN;
if (mode == 0) d = s.v;
else if (mode == 1) d = s.w;
else if (mode == 2) d = fx[ns];
// int np = used_pairs_map[0][s.fcam][s.scam]; ////////////////////
int np = comb_map[s.fcam][s.scam]; ////////////////////
rslt[s.tile][np][s.iy*size + s.ix] = d;
}
return rslt;
}
/*
public String [] dbgGetSliceTiles(int ntile) {
String [] srslt = new String [npairs[ntile]];
for (int f = 0; f < NUM_CAMS; f++) for (int s = 0; s < NUM_CAMS; s++) {
if (used_pairs_map[ntile][f][s] >= 0) {
srslt[used_pairs_map[ntile][f][s]] = ""+f+"->"+s;
}
}
return srslt;
}
*/
public String [] dbgGetSliceTiles() {
int [][] comb_map = getCombMap();
int np = comb_map[0][0];
......@@ -373,60 +376,29 @@ public class Corr2dLMA {
* 2: dd, nd offsets keep average x,y ot zero
*/
private void setOffsetMatrices() {
boolean invert_ortho = true;
Matrix A33;
Matrix A35;
if (invert_ortho) {
double [][] aA33 =
{ {rXY[pre_last_cam][0], rXY[last_cam][0], -rXY[last_cam][1]}, // sum(x) = d
{rXY[pre_last_cam][1], rXY[last_cam][1], rXY[last_cam][0]}, // sum(y) = 0
{1.0, 1.0, 0.0 }}; // sum(dd) = 0
A33 = new Matrix(aA33);
double [][] aA35 = new double [3][2 * ncam-3];
for (int i = 0; i < (ncam-2); i++) { // coefficients for dd[i]
int n = used_cams_rmap[i];
aA35[0][i] = -rXY[n][0];
aA35[1][i] = -rXY[n][1];
aA35[2][i] = -1.0;
}
for (int i = 0; i < (ncam-1); i++) { // coefficients for nd[i]
int n = used_cams_rmap[i];
int i1 = ncam - 2 + i;
aA35[0][i1] = rXY[n][1];
aA35[1][i1] = -rXY[n][0];
// aA35[2][i] = 0.0; // already 0.0
}
A35 = new Matrix(aA35);
} else {
double [][] aA33 =
{ {rXY[pre_last_cam][0], rXY[last_cam][0], rXY[last_cam][1]}, // sum(x) = d
{rXY[pre_last_cam][1], rXY[last_cam][1], -rXY[last_cam][0]}, // sum(y) = 0
{1.0, 1.0, 0.0 }}; // sum(dd) = 0
A33 = new Matrix(aA33);
double [][] aA35 = new double [3][2 * ncam-3];
for (int i = 0; i < (ncam-2); i++) { // coefficients for dd[i]
int n = used_cams_rmap[i];
aA35[0][i] = -rXY[n][0];
aA35[1][i] = -rXY[n][1];
aA35[2][i] = -1.0;
}
for (int i = 0; i < (ncam-1); i++) { // coefficients for nd[i]
int n = used_cams_rmap[i];
int i1 = ncam - 2 + i;
aA35[0][i1] = -rXY[n][1];
aA35[1][i1] = rXY[n][0];
// aA35[2][i] = 0.0; // already 0.0
}
A35 = new Matrix(aA35);
double [][] aA33 =
{ {rXY[pre_last_cam][0], rXY[last_cam][0], -rXY[last_cam][1]}, // sum(x) = d
{rXY[pre_last_cam][1], rXY[last_cam][1], rXY[last_cam][0]}, // sum(y) = 0
{1.0, 1.0, 0.0 }}; // sum(dd) = 0
A33 = new Matrix(aA33);
double [][] aA35 = new double [3][2 * ncam-3];
for (int i = 0; i < (ncam-2); i++) { // coefficients for dd[i]
int n = used_cams_rmap[i];
aA35[0][i] = -rXY[n][0];
aA35[1][i] = -rXY[n][1];
aA35[2][i] = -1.0;
}
// Matrix A33_inv = A33.inverse();
for (int i = 0; i < (ncam-1); i++) { // coefficients for nd[i]
int n = used_cams_rmap[i];
int i1 = ncam - 2 + i;
aA35[0][i1] = rXY[n][1];
aA35[1][i1] = -rXY[n][0];
// aA35[2][i] = 0.0; // already 0.0
}
A35 = new Matrix(aA35);
mddnd = A33.inverse().times(A35);
// mddnd . times (({dd0},{dd1},{nd0},{nd1},{nd2}}) -> {{dd2},{dd3},{nd3}} if all 4 cameras are used
// mddnd itself provides derivatives
}
......@@ -437,7 +409,6 @@ public class Corr2dLMA {
boolean adjust_lazyeye_par, // adjust disparity corrections parallel to disparities lma_adjust_wxy
boolean adjust_lazyeye_ortho, // obsolete - make == adjust_lazyeye_par adjust disparity corrections orthogonal to disparities lma_adjust_ly1
double [][] disp_str, // initial value of disparity
// double disp0, // initial value of disparity
double half_width, // A=1/(half_widh)^2 lma_half_width
double cost_lazyeye_par, // cost for each of the non-zero disparity corrections lma_cost_wy
double cost_lazyeye_odtho // cost for each of the non-zero ortho disparity corrections lma_cost_wxy
......@@ -445,7 +416,6 @@ public class Corr2dLMA {
adjust_lazyeye_ortho = adjust_lazyeye_par; // simplify relations for the calculated/dependent parameters
lazy_eye = adjust_lazyeye_par | adjust_lazyeye_ortho;
// int [][] pindx = new int [NUM_CAMS][NUM_CAMS];
used_pairs_map = new int [numTiles][NUM_CAMS][NUM_CAMS];
used_cameras = new boolean[NUM_CAMS];
boolean [][] used_pairs = new boolean[numTiles][NUM_PAIRS];
......@@ -454,9 +424,11 @@ 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];
for (Sample s:samples) { // ignore zero-weight samples
used_cameras[s.fcam]=true;
used_cameras[s.scam]=true;
used_tiles[s.tile] = true;
used_pairs[s.tile][pindx[s.fcam][s.scam]]=true; // throws < 0 - wrong pair, f==s
used_pairs_dir[s.tile][s.fcam][s.scam] = true;
}
......@@ -497,8 +469,9 @@ public class Corr2dLMA {
this.all_pars = new double[num_all_pars];
this.par_mask = new boolean[num_all_pars];
// per-tile parameters
for (int nTile = 0; nTile < numTiles; nTile++) {
this.all_pars[DISP_INDEX + nTile*TILE_PARAMS] = disp_str[nTile][0]; // disp0;
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;
this.all_pars[CMA_INDEX + nTile*TILE_PARAMS] = 0.0; // C-A
......@@ -530,7 +503,6 @@ public class Corr2dLMA {
}
double sw = 0;
//// this.pair_weights = new double[NUM_PAIRS];
for (int i = 0; i < np; i++) {
Sample s = samples.get(i);
weights[i] = s.w;
......@@ -543,6 +515,8 @@ 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];
......@@ -559,7 +533,6 @@ public class Corr2dLMA {
if (par_mask[i]) par_map[i] = par_indx++;
else par_map[i] = -1;
}
// private int [] dd_indices; //normally 5-long (2 * ncam -3), absolute parameter indices for dd_pre_last, dd_last and nd_last
dd_indices = lazy_eye? new int [2 * ncam -3] : null;
if (dd_indices != null) {
int pi = 0;
......@@ -570,7 +543,6 @@ public class Corr2dLMA {
if (par_map[ndisp_index + i] >=0) dd_indices[pi++] = par_map[ndisp_index + i];
}
}
toVector();
}
......@@ -578,16 +550,163 @@ 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 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;
if (used_pairs_map[nTile][f][s] >= 0) {
m_pairs[nTile][f][s] = m_disp[nTile][f].minus(m_disp[nTile][s]);
m_pairs[nTile][f][s] = m_disp[nTile][f].minus(m_disp[nTile][s]);
m_pairs_inv[nTile][f][s] = m_pairs[nTile][f][s].inverse();
}
}
}
}
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 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) {
m_pairs_inv[nTile][f][s] = m_pairs[nTile][f][s].inverse();
}
}
}
}
/**
* 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
*/
public double [] polyDisparity() {
return polyDisparity(null);
}
public double [] polyDisparity( String dbg_title) {
int center = transform_size -1;
// int corr_size = 2 * transform_size -1;
initInvertMatrices();
int nSamples = samples.size();
double [][][] mdata = new double [2 * nSamples][3][];
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];
//corr_wnd
int indx = 2 * ns;
mdata[indx ][0] = new double [2];
mdata[indx+1][0] = new double [2];
mdata[indx ][1] = new double [1];
mdata[indx+1][1] = new double [1];
mdata[indx ][2] = new double [1];
mdata[indx+1][2] = new double [1];
double [] aXY = {s.ix - center, s.iy - center};
Matrix mXY = new Matrix(aXY,2);
Matrix mDDND = m_pairs_inv[s.tile][s.fcam][s.scam].times(mXY);
mdata[indx ][0][0] = mDDND.get(0, 0); // dd
mdata[indx+1][0][0] = mdata[indx ][0][0];
mdata[indx ][0][1] = mDDND.get(1, 0); // nd
mdata[indx+1][0][1] = -mdata[indx ][0][1];
mdata[indx ][1][0] = bv;
mdata[indx+1][1][0] = bv;
mdata[indx ][2][0] = s.w;
mdata[indx+1][2][0] = s.w;
}
double[] approx2d =(new PolynomialApproximation()).quadraticMaxV2dX2Y2XY( // 9 elements - Xc, Yx, f(x,y), A, B, C, D, E, F (from A*x^2 + B*y^2 +C*x*y+...)
mdata,
1.0E-30,//25, // 1.0E-15,
0);
if ((approx2d == null) || (approx2d[2] < 0.0) || // negative strength
(approx2d[3] >= 0.0) || // x: min, not max
(approx2d[4] >= 0.0)) { // y: min, not max
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};
if (dbg_title != null) {
polyDisparityDebug(
dbg_title,
mdata,
10.0, // double scale,
100, // int irad,
10.0);//sigma);
}
return rslt; // [0];
}
double [][] polyDisparityDebug(
String title,
double [][][] mdata,
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];
int size = 2 * irad+1;
int nSamples = samples.size();
DoubleGaussianBlur gb = new DoubleGaussianBlur();
for (int ns = 0; ns < nSamples; ns++) {
int indx = 2 * ns;
Sample s = samples.get(ns);
int np = s.fcam* NUM_CAMS + s.scam;
if (dbg_img[np] == null) {
dbg_img[np] = new double [size*size];
dbg_weights[np] = new double [size*size];
titles[np]=String.format("%d->%d", s.fcam,s.scam);
}
double d = mdata[indx][1][0];
double w = mdata[indx][2][0];
if (w <= 0) {
System.out.println("w==0, should not happen");
continue;
}
int ix = (int) Math.round(mdata[indx ][0][0] * scale + irad);
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;
}
}
for (int np = 0; np < dbg_img.length; np++) if (dbg_img[np] != null) {
gb.blurDouble(dbg_img[np], size, size, sigma, sigma, 0.01);
gb.blurDouble(dbg_weights[np], size, size, sigma, sigma, 0.01);
for (int i = 0; i < dbg_img[np].length; i++) {
dbg_img[np][i] /= dbg_weights[np][i];
}
}
if (title != null) {
(new ShowDoubleFloatArrays()).showArrays(
dbg_img,
size,
size,
true,
title,
titles);
/*
(new ShowDoubleFloatArrays()).showArrays(
dbg_weights,
size,
size,
true,
title+"-weights",
titles);
*/
}
return dbg_img;
}
public double [] getFxJt( // USED in lwir
double [] vector,
double [][] jt) { // should be either [vector.length][samples.size()] or null - then only fx is calculated
......@@ -658,7 +777,6 @@ public class Corr2dLMA {
for (int p = 0; p < npairs[s.tile]; p++) { // par_mask[G0_INDEX + p] as all pairs either used, or not - then npairs == 0
if (par_map[G0_INDEX + p + s.tile*TILE_PARAMS] >= 0) jt[par_map[G0_INDEX + p + s.tile*TILE_PARAMS]][ns] = (p== pair)? d : 0.0; // (par_mask[G0_INDEX + pair])? d;
}
// obsolete: process ddisp (last camera not used, is equal to minus sum of others to make a sum == 0)
if (lazy_eye) {
for (int f = 0; f < NUM_CAMS; f++) { // -1 for the last_cam and pre_last_cam
if (par_map[ddisp_index + f] >= 0) jt[par_map[ddisp_index + f]][ns] = 0.0;
......@@ -720,61 +838,6 @@ public class Corr2dLMA {
jt[dd_indices[i]][ns] += dd_deriv[ddn] * mddnd.get(ddn, i);
}
}
/*
// private Matrix mddnd; // Matrix to calculate 2 last corrections in disparity direction and 1 ortho from the first ones (normally 2+3=5)
if (par_map[ddisp_index + s.fcam] >= 0){ // par_map[ddisp_index + last_cam] always <0
jt[par_map[ddisp_index + s.fcam]][ns] += 2 * WGp *
((A * xmxp + B * ymyp) * m_disp[s.tile][s.fcam].get(0, 0)+
(B * xmxp + C * ymyp) * m_disp[s.tile][s.fcam].get(1, 0));
} else if (s.fcam == pre_last_cam) {
for (int c = 0; c < NUM_CAMS; c++) if ((c != last_cam) && (par_map[ddisp_index + c] >=0)) {
jt[par_map[ddisp_index + c]][ns] -= 2 * WGp *
( (A * xmxp + B * ymyp) * m_disp[s.tile][s.fcam].get(0, 0)+
(B * xmxp + C * ymyp) * m_disp[s.tile][s.fcam].get(1, 0));
}
} else if (s.fcam == last_cam) {
for (int c = 0; c < NUM_CAMS; c++) if ((c != last_cam) && (par_map[ddisp_index + c] >=0)) {
jt[par_map[ddisp_index + c]][ns] -= 2 * WGp *
( (A * xmxp + B * ymyp) * m_disp[s.tile][s.fcam].get(0, 0)+
(B * xmxp + C * ymyp) * m_disp[s.tile][s.fcam].get(1, 0));
}
}
if (par_map[ddisp_index + s.scam]>= 0){ // par_map[ddisp_index + last_cam] always <0
jt[par_map[ddisp_index + s.scam]][ns] -= 2 * WGp *
((A * xmxp + B * ymyp) * m_disp[s.tile][s.scam].get(0, 0)+
(B * xmxp + C * ymyp) * m_disp[s.tile][s.scam].get(1, 0));
} else if (s.scam == last_cam) {
for (int c = 0; c < NUM_CAMS; c++) if ((c != last_cam) && (par_map[ddisp_index + c] >= 0)) {
jt[par_map[ddisp_index + c]][ns] += 2 * WGp *
((A * xmxp + B * ymyp) * m_disp[s.tile][s.scam].get(0, 0)+
(B * xmxp + C * ymyp) * m_disp[s.tile][s.scam].get(1, 0));
}
}
// process ndisp
// for (int f = 0; f < ncam; f++) if (par_map[ndisp_index + f] >= 0) {
// jt[par_map[ndisp_index + f]][ns] = 0.0;
// }
if (par_map[ndisp_index + s.fcam] >=0){
jt[par_map[ndisp_index + s.fcam]][ns] += 2 * WGp *
( (A * xmxp + B * ymyp) * m_disp[s.tile][s.fcam].get(0, 1)+
(B * xmxp + C * ymyp) * m_disp[s.tile][s.fcam].get(1, 1));
}
if (par_map[ndisp_index + s.scam] >= 0) {
jt[par_map[ndisp_index + s.scam]][ns] -= 2 * WGp *
( (A * xmxp + B * ymyp) * m_disp[s.tile][s.scam].get(0, 1)+
(B * xmxp + C * ymyp) * m_disp[s.tile][s.scam].get(1, 1));
}
*/
}
}
}
......@@ -801,28 +864,6 @@ public class Corr2dLMA {
}
}
}
/*
if (jt != null) {
for (int i = 0; i < NUM_CAMS; i++) {
if ((i != last_cam) && (par_map[ddisp_index + i] >= 0)) {
for (int j = 0; j < NUM_CAMS; j++) { // j - column
jt[par_map[ddisp_index + i]][num_samples + j] = (i==j)? 1.0 : 0.0;
}
jt[par_map[ddisp_index + i]][num_samples + last_cam] = -1.0;
}
}
for (int i = 0; i < NUM_CAMS; i++) {
if (par_map[ndisp_index + i] >= 0) {
for (int j = 0; j < NUM_CAMS; j++) { // j - column
jt[par_map[ndisp_index + i] ][num_samples + NUM_CAMS + j] = (i==j)? 1.0 : 0.0;
}
}
}
}
*/
return fx;
}
......@@ -991,14 +1032,8 @@ public class Corr2dLMA {
public void printParams() { // not used in lwir
// to make sure it is updated
System.out.println();
// all_pars = fromVector(vector);
for (int np = 0; np < all_pars.length; np++) {
String parname;
// if (np < G0_INDEX) parname = PAR_NAMES[np];
// else if (np < ddisp_index) parname = PAR_NAME_SCALE;
// else if (np < ndisp_index) parname = PAR_NAME_CORRDISP;
// else parname = PAR_NAME_CORRNDISP;
if (np >= ndisp_index) parname = PAR_NAME_CORRNDISP + (np - ndisp_index);
else if (np >= ddisp_index) parname = PAR_NAME_CORRDISP + (np - ddisp_index);
else {
......@@ -1016,15 +1051,54 @@ public class Corr2dLMA {
}
}
public void printStats(
double [][] ds,
int clust_width) {
String form_head, form_line;
boolean scv = true;
if (scv) {
form_head = "%4s,%9s,%9s,%9s,%9s,%9s,%9s,%9s,%9s,%9s,%9s,%9s";
form_line= "%4d,%9.4f,%9.4f,%9.4f,%9.4f,%9.4f,%9.4f,%9.4f,%9.4f,%9.4f,%9.4f,%9.4f";
}else {
form_head = "%4s%9s%9s%9s%9s%9s%9s%9s%9s%9s%9s%9s";
form_line= "%4d%9.4f%9.4f%9.4f%9.4f%9.4f%9.4f%9.4f%9.4f%9.4f%9.4f%9.4f";
}
double [] rmstile = getRmsTile();
double [][] maxmin_amp = getMaxMinAmpTile();
double [][] maxmin_val = getMaxMinValTile();
double [][] abc = getABCTile();
System.out.println(String.format(form_head,
"Tile","RMS","disparity","strength","max amp","min amp","diff_amp","max val","min val","diff_val",
"max_ac","size"));
for (int tile = 0; tile < ds.length; tile++) {
double max_ac = Math.max(abc[tile][0], abc[tile][2]);
double area = Double.NaN;
if ((abc[tile][0] > 0.0) && (abc[tile][2] > 0.0)) {
area = 1.0/abc[tile][0] + 1.0/abc[tile][2]; // area of a maximum
}
System.out.println(String.format(form_line,
tile, rmstile[tile] / ((maxmin_amp[tile][0] + maxmin_amp[tile][1])/2), // normalize to average
ds[tile][0], ds[tile][1],
maxmin_amp[tile][0], maxmin_amp[tile][1],
(maxmin_amp[tile][0] - maxmin_amp[tile][1]) / ((maxmin_amp[tile][0] + maxmin_amp[tile][1])/2), // normalize to average
maxmin_val[tile][0], maxmin_val[tile][1],
(maxmin_val[tile][0] - maxmin_val[tile][1])/((maxmin_val[tile][0] + maxmin_val[tile][1])/2),
max_ac, Math.sqrt(area)));
if ((clust_width > 1) && (((tile+1)%clust_width) == 0)) {
System.out.println();
}
}
}
public void printInputDataFx(boolean show_fx){ // not used in lwir
if (show_fx) {
Sample s = null;
// double [] fx = getPolyFx();
// if (fx == null) fx = getFx();
double [] fx = getFx();
if (fx == null) return;
for (int i = 0; i < fx.length; i++) {
// double fx_pos = (fx[i] >= 0)? fx[i]: Double.NaN;
double fx_pos = fx[i];
if (i < samples.size()) {
s = samples.get(i);
......@@ -1054,11 +1128,9 @@ public class Corr2dLMA {
}
public double [] getDisparityStrength(int nTile) { // USED in lwir
//// if (pair_weights == null) return null;
double disparity = -all_pars[DISP_INDEX];
double disparity = -all_pars[DISP_INDEX + nTile*TILE_PARAMS];
double sum_amp = 0.0;
for (int i = 0; i < NUM_PAIRS; i++) {
//// sum_amp += pair_weights[i] * all_pars[G0_INDEX + i]; // group_weights is normalized
sum_amp += all_pars[G0_INDEX + i + TILE_PARAMS * nTile]; // group_weights is normalized
}
// protect from weird fitting results
......@@ -1069,6 +1141,16 @@ public class Corr2dLMA {
return ds;
}
public double [][] getDisparityStrength() { // USED in lwir
double [][] ds = new double [numTiles][];
for (int tile = 0; tile < numTiles; tile++) {
ds[tile] = getDisparityStrength(tile);
}
return ds;
}
public double [] getDisparityStrengthABC(int nTile) {// width = 1/sqrt(all_pars[A_INDEX])
double [] ds = getDisparityStrength(nTile);
if (ds == null) return null;
......@@ -1274,6 +1356,126 @@ public class Corr2dLMA {
return rslt;
}
public double [][] disparityStrength(
double lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
double lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
double lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
double lma_str_scale, // convert lma-generated strength to match previous ones - scale
double lma_str_offset // convert lma-generated strength to match previous ones - add to result
){
double [][] ds = new double[numTiles][2];
double [] rms = getRmsTile();
double [][] maxmin_amp = getMaxMinAmpTile();
double [][] abc = getABCTile();
for (int tile = 0; tile < numTiles; tile++) {
if (Double.isNaN(maxmin_amp[tile][0])) {
ds[tile][0] = Double.NaN;
continue;
}
double avg = 0.5*(maxmin_amp[tile][0]+maxmin_amp[tile][1]);
double rrms = rms[tile]/avg;
if (((lma_max_rel_rms > 0.0) && (rrms > lma_max_rel_rms)) ||
(Math.max(abc[tile][0], abc[tile][2]) < lma_min_ac)) {
ds[tile][0] = Double.NaN;
continue;
}
double strength = Math.sqrt(avg/rrms);
double disparity = -all_pars[DISP_INDEX + tile*TILE_PARAMS];
if ((strength < lma_min_strength) || Double.isNaN(disparity)) {
ds[tile][0] = Double.NaN;
continue;
}
ds[tile][0] = disparity;
ds[tile][1] = (strength * lma_str_scale) + lma_str_offset;
}
return ds;
}
public double [] getRmsTile() { //
double [] tile_rms = new double[numTiles];
double [] tile_weights = new double[numTiles];
int num_samples = samples.size();
for (int i = 0; i < num_samples; i++) {
int tile = samples.get(i).tile;
double wd = last_ymfx[i];
tile_rms[tile] += wd*wd/weights[i];
tile_weights[tile] += weights[i];
}
for (int tile = 0; tile < numTiles; tile++) {
if (tile_weights[tile] > 0) {
tile_rms[tile] = Math.sqrt(tile_rms[tile]/tile_weights[tile]);
} else {
tile_rms[tile] = Double.NaN;
}
}
return tile_rms;
}
/**
* Get maximal/minimal (per pair) amplitudes and values for each tile
* @return array [tile][{amax, amin}]
*/
public double [][] getMaxMinAmpTile(){
double [][] maxmins = new double[numTiles][2];
for (int tile = 0; tile < numTiles; tile++) {
maxmins[tile][0] = Double.NaN;
maxmins[tile][1] = Double.NaN;
for (int i = 0; i <NUM_PAIRS; i++) {
if (par_mask[G0_INDEX + i + tile * TILE_PARAMS]) {
if (!(all_pars[G0_INDEX + i + tile*TILE_PARAMS] <= maxmins[tile][0])) { // NaN will trigger true
maxmins[tile][0] = all_pars[G0_INDEX + i + tile*TILE_PARAMS];
}
if (!(all_pars[G0_INDEX + i + tile*TILE_PARAMS] >= maxmins[tile][1])) {
maxmins[tile][1] = all_pars[G0_INDEX + i + tile*TILE_PARAMS];
}
}
}
}
return maxmins;
}
/**
* Get maximal/minimal (per pair) amplitudes and values for each tile
* @return array [tile][{vmax, vmin}]
*/
public double [][] getMaxMinValTile(){
double [][] tile_pair_max = new double[numTiles][NUM_PAIRS];
int num_samples = samples.size();
for (int i = 0; i < num_samples; i++) {
Sample s = samples.get(i);
int tile = s.tile;
int pair = pindx[s.fcam][s.scam];
if (s.v > tile_pair_max[tile][pair]) tile_pair_max[tile][pair] = s.v;
}
double [][] maxmins = new double[numTiles][2];
for (int tile = 0; tile < numTiles; tile++) {
maxmins[tile][0] = Double.NaN;
maxmins[tile][1] = Double.NaN;
for (int i = 0; i <NUM_PAIRS; i++) {
if (tile_pair_max[tile][i] > 0) {
if (!(tile_pair_max[tile][i] <= maxmins[tile][0])) { // NaN will trigger true
maxmins[tile][0] = tile_pair_max[tile][i];
}
if (!(tile_pair_max[tile][i] >= maxmins[tile][1])) {
maxmins[tile][1] = tile_pair_max[tile][i];
}
}
}
}
return maxmins;
}
public double [][] getABCTile(){
double [][] abc = new double[numTiles][3];
for (int tile = 0; tile < numTiles; tile++) {
abc[tile][0] = (par_mask[A_INDEX+ tile * TILE_PARAMS])? all_pars[A_INDEX+ tile * TILE_PARAMS] :Double.NaN;
abc[tile][1] = (par_mask[B_INDEX+ tile * TILE_PARAMS])? all_pars[B_INDEX+ tile * TILE_PARAMS] :Double.NaN;
abc[tile][2] = abc[tile][0] + ( (par_mask[CMA_INDEX+ tile * TILE_PARAMS])? all_pars[CMA_INDEX+ tile * TILE_PARAMS] :Double.NaN);
}
return abc;
}
public double [] getJtWdiff( // not used in lwir
double [] wdiff,
double [][] jt){
......@@ -1306,7 +1508,7 @@ public class Corr2dLMA {
rms_diff,
debug_level);
if (debug_level > 1) {
System.out.println("LMA step "+iter+": {"+rslt[0]+","+rslt[1]+"} full RMS="+good_or_bad_rms[0]+
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);
}
if (rslt[1]) {
......@@ -1381,7 +1583,7 @@ public class Corr2dLMA {
} catch (RuntimeException e) {
rslt[1] = true;
if (debug_level > 0) {
System.out.println("Singular Matrix");
System.out.println("Singular Matrix!");
}
return rslt;
......
......@@ -4,6 +4,7 @@ import java.util.ArrayList;
import com.elphel.imagej.common.DoubleGaussianBlur;
import com.elphel.imagej.common.PolynomialApproximation;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.tileprocessor.Corr2dLMA.Sample;
/**
**
......@@ -1812,8 +1813,8 @@ 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[][] xcenter_str, // preliminary center x in pixels for largest baseline
// 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
......@@ -1822,14 +1823,15 @@ 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; // alse; // true;
boolean debug_graphic = imgdtt_params.lma_debug_graphic; // (debug_level > -1) ;
// boolean debug_second_all = false; // true; // alse; // true;
int clust_height = corrs.length/clust_width;
int ntiles = corrs.length;
DoubleGaussianBlur gb = null;
if (imgdtt_params.lma_sigma > 0) gb = new DoubleGaussianBlur();
int center = transform_size - 1;
int corr_size = 2 * transform_size - 1;
// double [][] blur_max = new double [corrs.length][];
Corr2dLMA lma = new Corr2dLMA(
corrs.length,
transform_size,
......@@ -1860,6 +1862,7 @@ public class Correlation2d {
for (int ntile = 0; ntile < ntiles; ntile++) if (corrs[ntile] != null){
double[][] corr = new double[corrs[ntile].length][];
double [][] filtWeight = new double [corrs[ntile].length][];
// blur_max[ntile] = new double [corrs[ntile].length];
for (int npair = 0; npair < corrs[ntile].length; npair++) if ((corrs[ntile][npair] != null) && (((pair_mask >> npair) & 1) !=0)){
corr[npair] = corrs[ntile][npair].clone();
if (corr_wnd_inv_limited != null) {
......@@ -1935,7 +1938,8 @@ 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
w, //double w){ // sample weight
0.0); // double bv); // blurred/ normalized by window;
}
}
}
......@@ -1973,8 +1977,7 @@ public class Correlation2d {
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
xcenter_str, // double [][] disp_str, // initial value of disparity/strength/?
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
......@@ -2001,9 +2004,21 @@ public class Correlation2d {
lma.updateFromVector();
double [] rms = lma.getRMS();
if (debug_level > 0) {
System.out.println("LMA -> "+lmaSuccess+" RMS="+rms[0]+", pure RMS="+rms[1]);
System.out.println("LMA -> "+lmaSuccess+" RMS= "+rms[0]+", pure RMS= "+rms[1]);
lma.printParams();
}
double [][] ds = null;
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 > 0) lma.printStats(ds,clust_width);
}
if (debug_level > 1) {
System.out.println("Input data and approximation:");
......@@ -2011,8 +2026,27 @@ public class Correlation2d {
}
// boolean debug_second_all = true;
if (debug_second_all) {
double [] all_pars_save = lma.all_pars.clone();
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;
}
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
......@@ -2020,14 +2054,15 @@ public class Correlation2d {
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
xcenter_str, // double [][] disp_str, // initial value of disparity/strength/?
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
);
lma.all_pars = all_pars_save;
lma.toVector();
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
......@@ -2047,7 +2082,7 @@ public class Correlation2d {
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
debug_level); // 2); //4); // debug_level); // int debug_level) // > 3
lma.updateFromVector();
//double []
......@@ -2061,6 +2096,19 @@ public class Correlation2d {
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);
}
}
}
......@@ -2070,26 +2118,26 @@ public class Correlation2d {
String [] sliceTitles = lma.dbgGetSliceTiles();
if (corrs.length == 1) {
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(0)[0],
lma.dbgGetSamples(ds, 0)[0],
corr_size,
corr_size,
true,
"corr_values"+"_x"+tileX+"_y"+tileY, sliceTitles);
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(1)[0],
lma.dbgGetSamples(ds, 1)[0],
corr_size,
corr_size,
true,
"corr_weights"+"_x"+tileX+"_y"+tileY, sliceTitles);
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(2)[0],
lma.dbgGetSamples(ds, 2)[0],
corr_size,
corr_size,
true,
"corr_fx"+"_x"+tileX+"_y"+tileY, sliceTitles);
} else {
double [][] repacked_y = repackCluster(lma.dbgGetSamples(0),clust_width);
double [][] repacked_fx = repackCluster(lma.dbgGetSamples(2),clust_width);
double [][] repacked_y = repackCluster(lma.dbgGetSamples(ds, 0),clust_width);
double [][] repacked_fx = repackCluster(lma.dbgGetSamples(ds, 2),clust_width);
double [][] y_minux_fx = new double [repacked_y.length][];
for (int i = 0; i < repacked_y.length; i++) if ((repacked_y[i] != null) && (repacked_fx[i] != null)){
y_minux_fx[i] = new double [repacked_y[i].length];
......@@ -2114,7 +2162,7 @@ public class Correlation2d {
true,
"y-fx"+"_x"+tileX+"_y"+tileY, sliceTitles);
(new ShowDoubleFloatArrays()).showArrays(
repackCluster(lma.dbgGetSamples(1),clust_width),
repackCluster(lma.dbgGetSamples(ds, 1),clust_width),
dbg_out_width,
dbg_out_height,
true,
......@@ -2125,7 +2173,7 @@ public class Correlation2d {
return lmaSuccess? lma: null;
}
public Corr2dLMA corrLMA2( // single tile ************* Will be obsolete ????
public Corr2dLMA corrLMA2( // single tile
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)
......@@ -2133,8 +2181,7 @@ public class Correlation2d {
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 xcenter, // preliminary center x in pixels for largest baseline
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
......@@ -2143,7 +2190,13 @@ 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 need_poly = 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) {
if (imgdtt_params.lma_debug_graphic) {
dbg_title = String.format("tX%d_tY%d",tileX,tileY);
}
DoubleGaussianBlur gb = null;
if (imgdtt_params.lma_sigma > 0) gb = new DoubleGaussianBlur();
int center = transform_size - 1;
......@@ -2157,7 +2210,7 @@ public class Correlation2d {
);
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(
......@@ -2169,23 +2222,25 @@ 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();
// double[] corr = corrs[npair].clone();
corr_blur[npair] = corrs[npair].clone();
if (corr_wnd_inv_limited != null) {
for (int i = 0; i < corr.length; i++) {
corr[i] *= corr_wnd_inv_limited[i];
for (int i = 0; i < corr_blur[npair].length; i++) {
corr_blur[npair][i] *= corr_wnd_inv_limited[i];
}
}
if (imgdtt_params.lma_sigma > 0) {
gb.blurDouble(corr, corr_size, corr_size, imgdtt_params.lma_sigma, imgdtt_params.lma_sigma, 0.01);
gb.blurDouble(corr_blur[npair], 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[indx] > corr[imx]) imx = indx;
if (corr_blur[npair][indx] > corr_blur[npair][imx]) imx = indx;
}
}
......@@ -2194,14 +2249,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, // double [] corr_data,
corr_blur[npair], // 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;
// if (dbg_corr != null) dbg_corr [npair] = corr_blur[npair];
if (dbg_weights != null) dbg_weights[npair] = filtWeight;
// Normalize weight for each pair to compensate for different number of convex samples?
......@@ -2216,20 +2271,23 @@ public class Correlation2d {
if (vasw_pwr != 0) {
w *= Math.pow(Math.abs(v), vasw_pwr);
}
// if (v > blur_max[npair]) blur_max[npair] = v;
lma.addSample( // x = 0, y=0 - center
0, // tile
fcam, // int fcam, // first camera index
scam, // int scam, // second camera index
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
fcam, // int fcam, // first camera index
scam, // int scam, // second camera index
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;
}
}
if (debug_graphic) {
(new ShowDoubleFloatArrays()).showArrays(
dbg_corr,
corr_blur,
corr_size,
corr_size,
true,
......@@ -2243,22 +2301,34 @@ public class Correlation2d {
"corr_weights"+"_x"+tileX+"_y"+tileY);
}
double [][] disp_str = {{xcenter, 1.0}}; // temporary
// 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
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, // double disp0, // initial value of disparity
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]);
}
}
boolean lmaSuccess = false;
if (debug_level > 1) {
System.out.println("Input data:");
......@@ -2274,9 +2344,20 @@ public class Correlation2d {
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
4); // debug_level); // int debug_level) // > 3
debug_level); // imgdtt_params.lma_debug_level1); // 4); // int debug_level) // > 3
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 [] rms = lma.getRMS();
if (debug_level > 0) {
System.out.println("LMA -> "+lmaSuccess+" RMS="+rms[0]+", pure RMS="+rms[1]);
......@@ -2287,27 +2368,28 @@ public class Correlation2d {
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(0)[0],
lma.dbgGetSamples(null,0)[0],
corr_size,
corr_size,
true,
"corr_values"+"_x"+tileX+"_y"+tileY, sliceTitles);
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(1)[0],
lma.dbgGetSamples(null,2)[0],
corr_size,
corr_size,
true,
"corr_weights"+"_x"+tileX+"_y"+tileY, sliceTitles);
"corr_fx"+"_x"+tileX+"_y"+tileY, sliceTitles);
(new ShowDoubleFloatArrays()).showArrays(
lma.dbgGetSamples(2)[0],
lma.dbgGetSamples(null,1)[0],
corr_size,
corr_size,
true,
"corr_fx"+"_x"+tileX+"_y"+tileY, sliceTitles);
"corr_weights"+"_x"+tileX+"_y"+tileY, sliceTitles);
}
}
......
......@@ -1576,7 +1576,7 @@ public class ImageDtt {
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final boolean debug_distort= true;
final boolean debug_distort= (globalDebugLevel >0); // .false; // true;
// final double [][] debug_offsets = null;
//lma_dbg_scale
final double [][] debug_offsets = new double[imgdtt_params.lma_dbg_offset.length][2];
......@@ -1606,12 +1606,17 @@ 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 = Corr2dLMA.getCorrWnd(
transform_size,
imgdtt_params.lma_wnd);
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) {
double inv_pwr = imgdtt_params.lma_wnd_pwr - (imgdtt_params.lma_wnd - 1.0); // compensate for lma_wnd
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);
corr_wnd_inv_limited[i * (corr_wnd.length) + j] = 1.0/Math.max(Math.pow(corr_wnd[i][j],
inv_pwr),
imgdtt_params.lma_min_wnd);
}
}
}
......@@ -1756,18 +1761,6 @@ public class ImageDtt {
double centerX; // center of aberration-corrected (common model) tile, X
double centerY; //
double [][] fract_shiftsXY = new double[quad][];
// 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];
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);
}
}
}
*/
Correlation2d corr2d = new Correlation2d(
imgdtt_params, // ImageDttParameters imgdtt_params,
transform_size, // int transform_size,
......@@ -1795,7 +1788,8 @@ public class ImageDtt {
double [][][] corrs = new double [clustSize][][];
double [][] corr_stat = new double [clustSize][];
double [] strength = new double [clustSize];
double [] disparity = new double [clustSize];
// double [] disparity = new double [clustSize];
double [][] disp_str = new double [clustSize][];
boolean debugCluster = (clustX == (debug_tileX / tileStep)) && (clustY == (debug_tileY / tileStep));
int clust_lma_debug_level = debugCluster? imgdtt_params.lma_debug_level : -5;
......@@ -1901,11 +1895,13 @@ public class ImageDtt {
centersXY[cTile][ip][1] -= shiftXY[ip][1];
}
// save disparity distortions for visualization:
for (int cam = 0; cam <quad; cam++) {
dbg_distort[cam * 4 + 0 ][nTile] = disp_dist[cTile][cam][0];
dbg_distort[cam * 4 + 1 ][nTile] = disp_dist[cTile][cam][1];
dbg_distort[cam * 4 + 2 ][nTile] = disp_dist[cTile][cam][2];
dbg_distort[cam * 4 + 3 ][nTile] = disp_dist[cTile][cam][3];
if (dbg_distort != null) {
for (int cam = 0; cam <quad; cam++) {
dbg_distort[cam * 4 + 0 ][nTile] = disp_dist[cTile][cam][0];
dbg_distort[cam * 4 + 1 ][nTile] = disp_dist[cTile][cam][1];
dbg_distort[cam * 4 + 2 ][nTile] = disp_dist[cTile][cam][2];
dbg_distort[cam * 4 + 3 ][nTile] = disp_dist[cTile][cam][3];
}
}
......@@ -2069,32 +2065,49 @@ 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) {
disparity[cTile] = -corr_stat[cTile][0];
disparity_map[DISPARITY_INDEX_CM][tIndex] = disparity[cTile]; // 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
// 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);
}
// debug new LMA correlations
if (debugTile) {
System.out.println("Will run new LMA for tileX="+tileX+", tileY="+tileY);
/*
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_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
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
*/
if (debugCluster) {
if (globalDebugLevel > -2) {
System.out.println("Will run new LMA for tileX="+tileX+", tileY="+tileY);
}
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);
}
}
}
......@@ -2106,7 +2119,9 @@ public class ImageDtt {
}
}
if (debugCluster) {
System.out.println("Will run new LMA for clustX="+clustX+", clustY="+clustY);
if (globalDebugLevel > 0) {
System.out.println("Will run new LMA for clustX="+clustX+", clustY="+clustY);
}
Corr2dLMA lma2 = corr2d.corrLMA2(
imgdtt_params, // ImageDttParameters imgdtt_params,
......@@ -2117,10 +2132,9 @@ public class ImageDtt {
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
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 + 1, // 2, // int debug_level,
clust_lma_debug_level + 0, // 2, // int debug_level,
clustX, // int tileX, // just for debug output
clustY ); // int tileY
......@@ -2250,12 +2264,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 = Corr2dLMA.getCorrWnd(
transform_size,
imgdtt_params.lma_wnd);
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) {
double inv_pwr = imgdtt_params.lma_wnd_pwr - (imgdtt_params.lma_wnd - 1.0); // compensate for lma_wnd
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);
corr_wnd_inv_limited[i * (corr_wnd.length) + j] = 1.0/Math.max(Math.pow(corr_wnd[i][j],inv_pwr), imgdtt_params.lma_min_wnd);
}
}
}
......@@ -2459,18 +2476,6 @@ 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 = 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];
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);
}
}
}
*/
double [][] rXY;
if (use_main) {
......@@ -2951,13 +2956,14 @@ public class ImageDtt {
// 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;
double [] disp_str = new double[2];
if (ixy != null) {
strength = strip_combo[ixy[0]+transform_size-1]; // strength at integer max on axis
disp_str[1] = strip_combo[ixy[0]+transform_size-1]; // strength at integer max on axis
disparity_map[DISPARITY_INDEX_INT][tIndex] = -ixy[0];
// disparity_map[DISPARITY_INDEX_INT + 1][tIndex] =
disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] = strength;
disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] = disp_str[1];
if (Double.isNaN(disparity_map[DISPARITY_STRENGTH_INDEX][tIndex])) {
System.out.println("BUG: 1. disparity_map[DISPARITY_STRENGTH_INDEX]["+tIndex+"] should not be NaN");
}
......@@ -2998,8 +3004,8 @@ 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 != null) {
// skipping DISPARITY_VARIATIONS_INDEX - it was not used
disparity = -corr_stat[0];
disparity_map[DISPARITY_INDEX_CM][tIndex] = disparity; // disparity is negative X
disp_str[0] = -corr_stat[0];
disparity_map[DISPARITY_INDEX_CM][tIndex] = disp_str[0]; // disparity is negative X
if (tile_lma_debug_level > 0) {
System.out.println("Will run getMaxXSOrtho( ) for tileX="+tileX+", tileY="+tileY);
}
......@@ -3008,6 +3014,7 @@ public class ImageDtt {
if (debugTile) {
System.out.println("Will run new LMA for tileX="+tileX+", tileY="+tileY);
Corr2dLMA lma2 = corr2d.corrLMA2(
imgdtt_params, // ImageDttParameters imgdtt_params,
corr_wnd, // double [][] corr_wnd, // correlation window to save on re-calculation of the window
......@@ -3016,13 +3023,23 @@ 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
corr_stat[0], // double xcenter, // preliminary center x in pixels for largest baseline
// 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
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
double [][] ds = null;
if (lma2 != null) {
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
);
lma2.printStats(ds,1);
}
}
// disparity_map[DISPARITY_INDEX_CM + 1][tIndex] = // y not available here
......@@ -3030,7 +3047,7 @@ public class ImageDtt {
// convert to multi-baseline combining results from several integer scales
// see if strength is enough to proceed with LMA/poly (otherwise keep disp/strength
if (strength > imgdtt_params.min_poly_strength) {
if (disp_str[1] > imgdtt_params.min_poly_strength) {
// create LMA instance, calculate LMA composite argmax
// Create 2 groups: ortho & diag
Correlations2dLMA lma = corr2d.corrLMA(
......@@ -3047,9 +3064,9 @@ public class ImageDtt {
double max_disp_diff_lma = 3.0;
if (lma != null) {
lma_disparity_strength = lma.getDisparityStrength();
if (Math.abs(lma_disparity_strength[0] - disparity ) > max_disp_diff_lma) {
if (Math.abs(lma_disparity_strength[0] - disp_str[0] ) > max_disp_diff_lma) {
if (globalDebugLevel > -1) {
System.out.println("Crazy LMA for tileX="+tileX+", tileY="+tileY+": disparity="+disparity+",lma_disparity_strength[0]="+lma_disparity_strength[0]);
System.out.println("Crazy LMA for tileX="+tileX+", tileY="+tileY+": disparity="+disp_str[0]+",lma_disparity_strength[0]="+lma_disparity_strength[0]);
}
lma = null;
}
......@@ -3067,10 +3084,10 @@ public class ImageDtt {
// if enabled overwrite - replace DISPARITY_INDEX_CM and DISPARITY_STRENGTH_INDEX
if (imgdtt_params.mix_corr_poly) {
disparity = lma_disparity_strength[0];
strength = lma_disparity_strength[1];
disparity_map[DISPARITY_INDEX_CM] [tIndex] = disparity;
disparity_map[DISPARITY_STRENGTH_INDEX] [tIndex] = strength;
disp_str[0] = lma_disparity_strength[0];
disp_str[1] = lma_disparity_strength[1];
disparity_map[DISPARITY_INDEX_CM] [tIndex] = disp_str[0];
disparity_map[DISPARITY_STRENGTH_INDEX] [tIndex] = disp_str[1];
if (Double.isNaN(disparity_map[DISPARITY_STRENGTH_INDEX][tIndex])) {
System.out.println("BUG: 2. disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] should not be NaN");
}
......@@ -3080,13 +3097,13 @@ public class ImageDtt {
// temporarily removed strength requirement for debugging, restore later to make faster
/// if ((imgdtt_params.fo_correct && (strength > imgdtt_params.fo_min_strength)) || (clt_mismatch != null)) {
if ((imgdtt_params.fo_correct && (strength > 0 * imgdtt_params.fo_min_strength)) || (clt_mismatch != null)) {
if ((imgdtt_params.fo_correct && (disp_str[1] > 0 * imgdtt_params.fo_min_strength)) || (clt_mismatch != null)) {
// try all dirs:
dir_corr_strength = corr2d.corr4dirsLMA(
imgdtt_params, // ImageDttParameters imgdtt_params,
corrs, // double [][] corrs,
imgdtt_params.dbg_pair_mask, // int pair_mask, // which pairs to process
-disparity, // double xcenter, // preliminary center x in pixels for largest baseline
-disp_str[0], // double xcenter, // preliminary center x in pixels for largest baseline
imgdtt_params.ortho_vasw_pwr, // double vasw_pwr, // value as weight to this power,
tile_lma_debug_level, // int debug_level,
tileX, // int tileX, // just for debug output
......@@ -3105,7 +3122,7 @@ public class ImageDtt {
imgdtt_params.fo_far, // boolean bg,
imgdtt_params.fo_ortho, // boolean ortho,
dir_corr_strength, // double [] dir_disp,
disparity, // double full_disp,
disp_str[0], // double full_disp,
imgdtt_params.fo_min_strength, // double min_strength,
imgdtt_params.fo_min_eff, // double min_eff,
imgdtt_params.fo_min_eff_ratio, // double min_eff_ratio,
......@@ -3116,10 +3133,10 @@ public class ImageDtt {
(tile_lma_debug_level > 0) ); // boolean debug);
// Do not use modified far object distance when mismatch is measured
if ((mod_disparity_diff[0] != disparity) && (clt_mismatch == null)){ // if it changed
if (imgdtt_params.fo_correct && (strength > imgdtt_params.fo_min_strength)) { // always
disparity = mod_disparity_diff[0];
disparity_map[DISPARITY_INDEX_CM] [tIndex] = disparity;
if ((mod_disparity_diff[0] != disp_str[0]) && (clt_mismatch == null)){ // if it changed
if (imgdtt_params.fo_correct && (disp_str[1] > imgdtt_params.fo_min_strength)) { // always
disp_str[0] = mod_disparity_diff[0];
disparity_map[DISPARITY_INDEX_CM] [tIndex] = disp_str[0];
}
}
}
......@@ -3140,7 +3157,7 @@ public class ImageDtt {
imgdtt_params, // ImageDttParameters imgdtt_params,
corrs, // double [][] corrs,
all_pairs, // int pair_mask, // which pairs to process
-disparity, // double xcenter, // preliminary center x in pixels for largest baseline
-disp_str[0], // double xcenter, // preliminary center x in pixels for largest baseline
max_corr_radius, // double vasw_pwr, // value as weight to this power,
tile_lma_debug_level,// int debug_level,
tileX, // int tileX, // just for debug output
......@@ -3174,7 +3191,7 @@ public class ImageDtt {
imgdtt_params, // ImageDttParameters imgdtt_params,
corrs, // double [][] corrs,
all_pairs, // int pair_mask, // which pairs to process
-disparity, // double xcenter, // preliminary center x in pixels for largest baseline
-disp_str[0], // double xcenter, // preliminary center x in pixels for largest baseline
max_corr_radius, // imgdtt_params.ortho_vasw_pwr, // radius, // positive - within that distance, negative - within 2*(-radius)+1 square
tile_lma_debug_level,// int debug_level,
tileX, // int tileX, // just for debug output
......
......@@ -99,7 +99,9 @@ public class ImageDttParameters {
public double corr_wndx_blur = 5.0; // 100% to 0 % vertical transition range
// LMA parameters
public boolean lma_gaussian = true; // model correlation maximum as a Gaussian (false - as a parabola)
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_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
......@@ -107,6 +109,7 @@ public class ImageDttParameters {
public boolean lma_adjust_ag = true; // used in new for gains
// new LMA parameters
public double lma_wnd = 1.5; // raise cosine window to this power (1.0 - just 2D cosine)
public double lma_min_wnd = 0.4; // divide values by the 2D correlation window if it is >= this value for finding maximums and convex areas
public double lma_wnd_pwr = 0.8; // Raise window for finding a maximum and a convex region to this power
public int lma_hard_marg = 1; // Zero out this width margins before blurring
......@@ -121,14 +124,27 @@ public class ImageDttParameters {
public double lma_cost_wy = 0.003; // cost of parallel-to-disparity correction
public double lma_cost_wxy = 0.003; // cost of ortho-to-disparity correction
public double lma_lambda_initial = 0.1; //
public double lma_lambda_initial = 0.03; //
public double lma_lambda_scale_good = 0.5; //
public double lma_lambda_scale_bad = 8.0; //
public double lma_lambda_max = 100.0; //
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; //
// Filtering and strength calculation
public double lma_max_rel_rms = 0.2; // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
public double lma_min_strength = 1.0; // minimal composite strength (sqrt(average amp squared over absolute RMS)
public double lma_min_ac = 0.03; // minimal of a and C coefficients maximum (measures sharpest point/line)
public double lma_str_scale = 0.2; // convert lma-generated strength to match previous ones - scale
public double lma_str_offset = 0.05; // convert lma-generated strength to match previous ones - add to result
public int lma_debug_level = 0; //
public int lma_debug_level1 = 0; //
public boolean lma_debug_graphic = false; //
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_scale = 0.0; // scale lma_dbg_offset
......@@ -174,10 +190,14 @@ public class ImageDttParameters {
gd.addNumericField("Use data as weights when fitting parabola for ortho mode", this.ortho_vasw_pwr,3,6,"",
"Raise value to this power and apply as weight. Reduce width to 3 samples if false, 5 OK when true");
gd.addNumericField("Reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center) - main camera", this.enhortho_width, 0);
gd.addNumericField("Reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center) - aux camera", this.enhortho_width_aux, 0);
gd.addNumericField("Multiply center correlation pixels (inside enhortho_width) (1.0 - disables enh_ortho) - main camera", this.enhortho_scale, 3);
gd.addNumericField("Multiply center correlation pixels (inside enhortho_width) (1.0 - disables enh_ortho) - aux camera", this.enhortho_scale_aux, 3);
gd.addNumericField("Reduce weight of center correlation pixels from center for the main camera",this.enhortho_width, 0, 3, "pix",
"Reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)");
gd.addNumericField("Reduce weight of center correlation pixels from center for the aux camera", this.enhortho_width_aux, 0, 3, "pix",
"Reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)");
gd.addNumericField("Multiply center correlation pixels for the main camera", this.enhortho_scale, 0,3, "pix",
"Multiply center correlation pixels (inside enhortho_width) (1.0 - disables enh_ortho) - main camera");
gd.addNumericField("Multiply center correlation pixels for the aux camera", this.enhortho_scale_aux, 0,3, "pix",
"Multiply center correlation pixels (inside enhortho_width) (1.0 - disables enh_ortho) - aux camera");
gd.addCheckbox ("Use polynomial when measuring mismatch (false - use center of mass)", this.ly_poly);
gd.addNumericField("Maximal allowed mismatch difference calculated as polynomial maximum", this.ly_crazy_poly,3,6,"px",
......@@ -272,22 +292,28 @@ public class ImageDttParameters {
gd.addTab("Corr LMA","Parameters for LMA fitting of the correlation maximum parameters");
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,
"Re-run LMA with filtered tiles (see Correlation strength calculation section below)");
gd.addCheckbox ("Gaussian mode during LMA re-run", this.lma_second_gaussian,
"Parabola is more stable when using with un-filtered tiles, so it makes sense to use Gaussina only on filtered tiles");
gd.addCheckbox ("Fit correlation defined half-width", this.lma_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.lma_adjust_wy,
"Adjust ellipse (non-circular) of the correlation maximum (was Fit extra perpendicular to disparity half-width (not used? and only possible with multi-baseline cameras))");
gd.addCheckbox ("Adjust \"lazy eye\" parameters parallel to disparity (was Fit extra half-width along disparity)", this.lma_adjust_wxy,
"Increased width in disparity direction caused by multi-distance objects in the tile");
gd.addCheckbox ("Adjust \"lazy eye\" parameters orthogonal CW to disparity", this.lma_adjust_ly1,
gd.addCheckbox ("Adjust \"lazy eye\" parameters parallel to disparity", this.lma_adjust_wxy,
"(was Fit extra half-width along disparity) Increased width in disparity direction caused by multi-distance objects in the tile");
gd.addCheckbox ("Adjust \"lazy eye\" parameters orthogonal CW to disparity", this.lma_adjust_ly1,
"Increased width in disparity direction caused by multi-distance objects in the tile");
gd.addCheckbox ("Adjust per-pair scale (was Adjust per-group amplitudes)", this.lma_adjust_ag,
"Each correlation pair gain (was Each correlation type's amplitude (now always needed))");
gd.addNumericField("Minimal window value for normalization during max/convex", this.lma_min_wnd, 3, 6, "",
gd.addNumericField("LMA window power", this.lma_wnd, 3, 6, "",
"Raise cosine window to this power (1.0 - plane 2D cosine");
gd.addNumericField("Minimal window value for normalization during max/convex", this.lma_min_wnd, 3, 6, "",
"divide values by the 2D correlation window if it is >= this value for finding maximums and convex areas");
gd.addNumericField("LMA window power", this.lma_wnd_pwr, 3, 6, "",
gd.addNumericField("LMA window power for convex region", this.lma_wnd_pwr, 3, 6, "",
"Raise window for finding a maximum and a convex region to this power");
gd.addNumericField("LMA hard margin", this.lma_hard_marg, 0, 3, "",
"Zero out this width margins before blurring");
......@@ -316,14 +342,33 @@ public class ImageDttParameters {
gd.addNumericField("LMA maximal iterations", this.lma_num_iter, 0, 3, "",
"Limit LMA cycles, so it will exit after certain number of small improvements");
gd.addMessage("LMA results filtering");
gd.addNumericField("Maximal relative RMS ", this.lma_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.lma_min_strength, 6, 8, "",
"Discard tile if composite strength (average amplitude over SQRT of RMS) is below");
gd.addNumericField("Minimal max (A,C)", this.lma_min_ac, 6, 8, "",
"Minimal value of max (A,C) coefficients to keep the tile (measures sharpest point/line correlation maximum)");
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, "",
"Add to scaled composite correlation strength to match older CM value");
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");
gd.addNumericField("LMA debug level1", this.lma_debug_level1, 0, 3, "",
gd.addNumericField("LMA debug level1", this.lma_debug_level1, 0, 3, "",
"Debug/verbosity level for the new LMA correaltion maximum fitting");
gd.addCheckbox ("Enable LMA debug images", this.lma_debug_graphic,
"If false, no debug images generated regardless of debug levels");
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, "",
gd.addNumericField("Normalization for the CM correlation strength (old)", 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, "",
......@@ -421,14 +466,16 @@ public class ImageDttParameters {
//LMA tab
this.lma_gaussian= gd.getNextBoolean();
this.lma_second= gd.getNextBoolean();
this.lma_second_gaussian= gd.getNextBoolean();
this.lma_adjust_wm= gd.getNextBoolean();
this.lma_adjust_wy= gd.getNextBoolean();
this.lma_adjust_wxy= gd.getNextBoolean();
this.lma_adjust_ly1= gd.getNextBoolean();
this.lma_adjust_ag= gd.getNextBoolean();
this.lma_wnd = gd.getNextNumber();
this.lma_min_wnd = gd.getNextNumber();
this.lma_wnd_pwr = gd.getNextNumber();
this.lma_hard_marg= (int) gd.getNextNumber();
this.lma_soft_marg= (int) gd.getNextNumber();
......@@ -443,10 +490,17 @@ public class ImageDttParameters {
this.lma_lambda_scale_bad = gd.getNextNumber();
this.lma_lambda_max = gd.getNextNumber();
this.lma_rms_diff = gd.getNextNumber();
this.lma_num_iter= (int) gd.getNextNumber();
this.lma_max_rel_rms = gd.getNextNumber();
this.lma_min_strength = gd.getNextNumber();
this.lma_min_ac = gd.getNextNumber();
this.lma_str_scale = gd.getNextNumber();
this.lma_str_offset = gd.getNextNumber();
this.lma_debug_level= (int) gd.getNextNumber();
this.lma_debug_level1= (int) gd.getNextNumber();
this.lma_debug_graphic = gd.getNextBoolean();
this.corr_var_cam = gd.getNextBoolean();
this.cm_max_normalization= gd.getNextNumber();
this.lma_dbg_scale= gd.getNextNumber();
......@@ -454,7 +508,6 @@ public class ImageDttParameters {
for (int i = 0; i < 4; i++) for (int j=0; j < 2; j++) {
this.lma_dbg_offset[i][j]= gd.getNextNumber();
}
}
......@@ -526,6 +579,8 @@ public class ImageDttParameters {
properties.setProperty(prefix+"corr_wndx_blur", this.corr_wndx_blur +"");
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 +"");
properties.setProperty(prefix+"lma_adjust_wm", this.lma_adjust_wm +"");
properties.setProperty(prefix+"lma_adjust_wy", this.lma_adjust_wy +"");
properties.setProperty(prefix+"lma_adjust_wxy", this.lma_adjust_wxy +"");
......@@ -533,8 +588,8 @@ public class ImageDttParameters {
properties.setProperty(prefix+"lma_adjust_ag", this.lma_adjust_ag +"");
properties.setProperty(prefix+"lma_wnd", this.lma_wnd +"");
properties.setProperty(prefix+"lma_min_wnd", this.lma_min_wnd +"");
properties.setProperty(prefix+"lma_wnd_pwr", this.lma_wnd_pwr +"");
properties.setProperty(prefix+"lma_hard_marg", this.lma_hard_marg +"");
properties.setProperty(prefix+"lma_soft_marg", this.lma_soft_marg +"");
......@@ -549,10 +604,18 @@ public class ImageDttParameters {
properties.setProperty(prefix+"lma_lambda_scale_bad", this.lma_lambda_scale_bad +"");
properties.setProperty(prefix+"lma_lambda_max", this.lma_lambda_max +"");
properties.setProperty(prefix+"lma_rms_diff", this.lma_rms_diff +"");
properties.setProperty(prefix+"lma_num_iter", this.lma_num_iter +"");
properties.setProperty(prefix+"lma_max_rel_rms", this.lma_max_rel_rms +"");
properties.setProperty(prefix+"lma_min_strength", this.lma_min_strength +"");
properties.setProperty(prefix+"lma_min_ac", this.lma_min_ac +"");
properties.setProperty(prefix+"lma_str_scale", this.lma_str_scale +"");
properties.setProperty(prefix+"lma_str_offset", this.lma_str_offset +"");
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 +"");
properties.setProperty(prefix+"corr_var_cam", this.corr_var_cam +"");
properties.setProperty(prefix+"cm_max_normalization", this.cm_max_normalization +"");
......@@ -635,7 +698,9 @@ 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+"lma_gaussian")!=null) this.lma_gaussian=Boolean.parseBoolean(properties.getProperty(prefix+"lma_gaussian"));
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"));
if (properties.getProperty(prefix+"lma_adjust_wm")!=null) this.lma_adjust_wm=Boolean.parseBoolean(properties.getProperty(prefix+"lma_adjust_wm"));
if (properties.getProperty(prefix+"lma_adjust_wy")!=null) this.lma_adjust_wy=Boolean.parseBoolean(properties.getProperty(prefix+"lma_adjust_wy"));
if (properties.getProperty(prefix+"lma_adjust_wxy")!=null) this.lma_adjust_wxy=Boolean.parseBoolean(properties.getProperty(prefix+"lma_adjust_wxy"));
......@@ -644,9 +709,8 @@ public class ImageDttParameters {
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"));
if (properties.getProperty(prefix+"lma_min_wnd")!=null) this.lma_min_wnd=Double.parseDouble(properties.getProperty(prefix+"lma_min_wnd"));
if (properties.getProperty(prefix+"lma_wnd_pwr")!=null) this.lma_wnd_pwr=Double.parseDouble(properties.getProperty(prefix+"lma_wnd_pwr"));
if (properties.getProperty(prefix+"lma_hard_marg")!=null) this.lma_hard_marg=Integer.parseInt(properties.getProperty(prefix+"lma_hard_marg"));
if (properties.getProperty(prefix+"lma_soft_marg")!=null) this.lma_soft_marg=Integer.parseInt(properties.getProperty(prefix+"lma_soft_marg"));
......@@ -662,10 +726,18 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"lma_lambda_scale_bad")!=null) this.lma_lambda_scale_bad=Double.parseDouble(properties.getProperty(prefix+"lma_lambda_scale_bad"));
if (properties.getProperty(prefix+"lma_lambda_max")!=null) this.lma_lambda_max=Double.parseDouble(properties.getProperty(prefix+"lma_lambda_max"));
if (properties.getProperty(prefix+"lma_rms_diff")!=null) this.lma_rms_diff=Double.parseDouble(properties.getProperty(prefix+"lma_rms_diff"));
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_max_rel_rms")!=null) this.lma_max_rel_rms=Double.parseDouble(properties.getProperty(prefix+"lma_max_rel_rms"));
if (properties.getProperty(prefix+"lma_min_strength")!=null) this.lma_min_strength=Double.parseDouble(properties.getProperty(prefix+"lma_min_strength"));
if (properties.getProperty(prefix+"lma_min_ac")!=null) this.lma_min_ac=Double.parseDouble(properties.getProperty(prefix+"lma_min_ac"));
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_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"));
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"));
......@@ -673,10 +745,6 @@ public class ImageDttParameters {
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));
}
}
@Override
......@@ -750,6 +818,8 @@ public class ImageDttParameters {
idp.corr_wndx_blur = this.corr_wndx_blur;
idp.lma_gaussian = this.lma_gaussian;
idp.lma_second = this.lma_second;
idp.lma_second_gaussian = this.lma_second_gaussian;
idp.lma_adjust_wm = this.lma_adjust_wm;
idp.lma_adjust_wy = this.lma_adjust_wy;
idp.lma_adjust_wxy = this.lma_adjust_wxy;
......@@ -757,8 +827,8 @@ public class ImageDttParameters {
idp.lma_adjust_ag = this.lma_adjust_ag;
idp.lma_wnd = this.lma_wnd;
idp.lma_min_wnd = this.lma_min_wnd;
idp.lma_wnd_pwr = this.lma_wnd_pwr;
idp.lma_hard_marg = this.lma_hard_marg;
idp.lma_soft_marg = this.lma_soft_marg;
......@@ -773,10 +843,18 @@ public class ImageDttParameters {
idp.lma_lambda_scale_bad = this.lma_lambda_scale_bad;
idp.lma_lambda_max = this.lma_lambda_max;
idp.lma_rms_diff = this.lma_rms_diff;
idp.lma_num_iter = this.lma_num_iter;
idp.lma_max_rel_rms= this.lma_max_rel_rms;
idp.lma_min_strength= this.lma_min_strength;
idp.lma_min_ac= this.lma_min_ac;
idp.lma_str_scale= this.lma_str_scale;
idp.lma_str_offset= this.lma_str_offset;
idp.lma_debug_level = this.lma_debug_level;
idp.lma_debug_level1 = this.lma_debug_level1;
idp.lma_debug_graphic = this.lma_debug_graphic;
idp.corr_var_cam = this.corr_var_cam;
idp.cm_max_normalization= this.cm_max_normalization;
......
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