Commit c14405c9 authored by Andrey Filippov's avatar Andrey Filippov

Working on new LMA correlation

parent 2fab35c1
This diff is collapsed.
package com.elphel.imagej.tileprocessor;
/**
**
** Correlation2dLMA - Fit multi - baseline correaltion pairs to the model
** Correlation2dLMA - Fit multi - baseline correlation pairs to the model
**
** Copyright (C) 2018 Elphel, Inc.
**
......@@ -84,7 +84,7 @@ public class Correlations2dLMA {
double [] poly_coeff = null; // 6 elements - Xc, Yx, f(x,y), A, B, C (from A*x^2 + B*y^2 +C*x*y+...)
double [] poly_xyvwh = null; // result of 2-d polynomial approximation instead of the LMA - used for lazy eye correction
public class NumDiag{
public class NumDiag{ // USED in lwir
int num;
boolean diag;
public NumDiag(int num, boolean diag) {
......@@ -93,7 +93,7 @@ public class Correlations2dLMA {
}
}
public class Sample{
public class Sample{ // USED in lwir
double x; // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis
double y; // y coordinate (0 - disparity axis)
double v; // correlation value at that point
......@@ -117,7 +117,7 @@ public class Correlations2dLMA {
}
}
public void printParams() {
public void printParams() { // not used in lwir
for (int np = 0; np < all_pars.length; np++) {
System.out.println(String.format("%2d%1s %22s %f",
np,
......@@ -127,7 +127,7 @@ public class Correlations2dLMA {
}
}
public void printInputDataFx(boolean show_fx){
public void printInputDataFx(boolean show_fx){ // not used in lwir
if (show_fx) {
Sample s = null;
double [] fx = getPolyFx();
......@@ -151,18 +151,18 @@ public class Correlations2dLMA {
}
}
public double [] getRMS() {
public double [] getRMS() { // USED in lwir
return last_rms;
}
public double [] getGoodOrBadRMS() {
public double [] getGoodOrBadRMS() { // not used in lwir
return good_or_bad_rms;
}
public double [] getAllPars() {
public double [] getAllPars() { // not used in lwir
return all_pars;
}
public double [] getDisparityStrength() {
public double [] getDisparityStrength() { // USED in lwir
if (group_weights == null) return null;
double disparity = -all_pars[X0_INDEX];
double sum_amp = 0.0;
......@@ -176,7 +176,7 @@ public class Correlations2dLMA {
double [] ds = {disparity, sum_amp};
return ds;
}
public double [] getDisparityStrengthWidth() {
public double [] getDisparityStrengthWidth() { // USED in lwir
double [] ds = getDisparityStrength();
if (ds == null) return null;
double [] dsw = {ds[0], ds[1], all_pars[WM_INDEX], all_pars[WXY_INDEX]}; // asymmetry
......@@ -184,16 +184,16 @@ public class Correlations2dLMA {
}
public Correlations2dLMA (
public Correlations2dLMA ( // USED in lwir
double [] scales // null - use default table
) {
if (scales != null) this.scales = scales.clone();
}
public void setDiag(boolean diag_in) {
public void setDiag(boolean diag_in) { // USED in lwir
this.input_diag = diag_in;
}
public void addSample(
public void addSample( // USED in lwir
double x, // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis
double y, // y coordinate (0 - disparity axis)
double v, // correlation value at that point
......@@ -209,7 +209,7 @@ public class Correlations2dLMA {
//NumDiag
// TODO: add auto x0, half-width?
// should be called ater all samples are entered (to list groups)
public void initVector(
public void initVector( // USED in lwir
boolean adjust_wm,
boolean adjust_wy,
boolean adjust_wxy,
......@@ -242,7 +242,7 @@ public class Correlations2dLMA {
toVector();
}
public void setWeightsValues(
public void setWeightsValues( // USED in lwir
double half_width, // expected width
double cost_wm, // cost of non-zero this.all_pars[WYD_INDEX]
double cost_wxy) { // cost of non-zero this.all_pars[WXY_INDEX]
......@@ -260,7 +260,7 @@ public class Correlations2dLMA {
weights[i] = s.w;
values[i] = s.v;
group_weights[groups.get(s.gi).num] += s.w;
if (Double.isNaN(values[i]) || Double.isNaN(weights[i])) {
if (Double.isNaN(values[i]) || Double.isNaN(weights[i])) { // not used in lwir
weights[i] = 0.0;
values[i] = 0.0;
}
......@@ -277,7 +277,7 @@ public class Correlations2dLMA {
pure_weight *= sw;
}
public void toVector() {
public void toVector() { // USED in lwir
int np = 0;
for (int i = 0; i < par_mask.length; i++) if (par_mask[i]) np++;
vector = new double[np];
......@@ -285,12 +285,12 @@ public class Correlations2dLMA {
for (int i = 0; i < par_mask.length; i++) if (par_mask[i]) vector[np++] = all_pars[i];
}
public void updateFromVector() {
public void updateFromVector() { // USED in lwir
int np = 0;
for (int i = 0; i < par_mask.length; i++) if (par_mask[i]) all_pars[i] = vector[np++];
}
public double [] fromVector(double [] vector) { // mix fixed and variable parameters
public double [] fromVector(double [] vector) { // mix fixed and variable parameters // USED in lwir
if ( all_pars == null) return null;
double [] ap = all_pars.clone();
int np = 0;
......@@ -298,7 +298,7 @@ public class Correlations2dLMA {
return ap;
}
public void debugJt(
public void debugJt( // not used in lwir
double delta,
double [] vector) {
int num_points = this.values.length;
......@@ -338,7 +338,7 @@ public class Correlations2dLMA {
}
public double [] getFxJt(
public double [] getFxJt( // not used in lwir
double delta, // for testing derivatives: calculates as delta-F/delta_x
double [] vector,
double [][] jt) { // should be either [vector.length][samples.size()] or null - then only fx is calculated
......@@ -361,11 +361,11 @@ public class Correlations2dLMA {
public double [] getFx() {
public double [] getFx() { // not used in lwir
return getFxJt(this.vector, null);
}
public double [] getFxJt(
public double [] getFxJt( // 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;
......@@ -415,7 +415,7 @@ public class Correlations2dLMA {
return fx;
}
public double [][] getWJtJlambda(
public double [][] getWJtJlambda( // USED in lwir
double lambda,
double [][] jt){
int num_pars = jt.length;
......@@ -439,7 +439,7 @@ public class Correlations2dLMA {
}
// returns {rms, rms_pure}
public double [] getWYmFxRms(
public double [] getWYmFxRms( // USED in lwir
double [] fx) { // will be replaced with y-fx
int num_samples = samples.size();
int num_points = fx.length; // includes 2 extra for regularization
......@@ -460,7 +460,7 @@ public class Correlations2dLMA {
return rslt;
}
public double [] getJtWdiff(
public double [] getJtWdiff( // not used in lwir
double [] wdiff,
double [][] jt){
int num_pars = jt.length;
......@@ -474,7 +474,7 @@ public class Correlations2dLMA {
return wjtymfx;
}
public boolean runLma(
public boolean runLma( // USED in lwir
double lambda, // 0.1
double lambda_scale_good,// 0.5
double lambda_scale_bad, // 8.0
......@@ -502,7 +502,7 @@ public class Correlations2dLMA {
} else {
lambda *= lambda_scale_bad;
if (lambda > lambda_max) {
break;
break; // not used in lwir
}
}
}
......@@ -530,7 +530,7 @@ public class Correlations2dLMA {
// returns {success, done}
public boolean [] lmaStep(
public boolean [] lmaStep( // USED in lwir
double lambda,
double rms_diff,
int debug_level) {
......@@ -640,7 +640,7 @@ public class Correlations2dLMA {
}
// modify to reuse Samples and apply polynomial approximation to resolve x0,y0 and strength?
public double [] getMaxXYPoly( // get interpolated maximum coordinates using 2-nd degree polynomial
public double [] getMaxXYPoly( // get interpolated maximum coordinates using 2-nd degree polynomial // not used in lwir
/// double outside, // how much solution may be outside of the samples
boolean debug
) {
......@@ -703,11 +703,11 @@ public class Correlations2dLMA {
this.poly_xyvwh = xyvwh;
return xyvwh; // rslt;
}
public double [] getPoly() {
public double [] getPoly() { // not used in lwir
return poly_xyvwh;
}
public double [] getPolyFx() {return getPolyFx(this.poly_coeff);}
public double [] getPolyFx(
public double [] getPolyFx() {return getPolyFx(this.poly_coeff);} // not used in lwir
public double [] getPolyFx( // not used in lwir
double [] coeff) { // 6 elements - Xc, Yx, f(x,y), A, B, C (from A*x^2 + B*y^2 +C*x*y+...)
if (coeff == null) {
return null;
......
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