Commit 37760e8c authored by Andrey Filippov's avatar Andrey Filippov

before redoing neighbor processing for pivots

parent ca780c7c
......@@ -785,11 +785,12 @@ min_str_neib_fpn 0.35
public double terr_alpha_weight_center =1.5; // weight of center alpha pixel relative to each of the 4 ortho ones
public boolean terr_en_holes = true; // enable small holes // maybe second pass after good fit with vegetation and search for correct offset?
public double terr_alpha_mm_hole = 0.1; // NaN to disable. Local "almost minimum" (lower than this fraction between min and max neighbor) is not subject to alpha_lpf
public double terr_terr_lpf = 0.1; // pull terrain to average of 4 neighbors (very small)
public double terr_veget_lpf = 0.2; // pull vegetation to average of 4 neighbors (very small - maybe not needed)
public double terr_elev_lpf = 0.1; // pull elevation to average of 4 neighbors (very small - maybe not needed)
public double terr_terr_pull0 = 0.05; // pull terrain to zero (makes sense with UM
public double terr_veget_pull0 = 0.05; // pull vegetation to zero (makes sense with UM
public double terr_terr_lpf = 0.1; // pull terrain to average of 4 neighbors
public double terr_veget_lpf = 0.2; // pull vegetation to average of 4 neighbors
public double terr_elev_lpf = 0.1; // pull elevation to average of 4 neighbors
public double terr_terr_pull0 = 0.05; // pull terrain to initial (pre-adjustment) values
public double terr_veget_pull0 = 0.05; // pull vegetation initial (pre-adjustment) values
public double terr_elev_pull0 = 0.1; // pull elevation to initial (pre-adjustment) values
public double terr_scenes_pull0 = 1.0; // pull average scene offset to zero
// LMA parameters
......@@ -2057,8 +2058,9 @@ min_str_neib_fpn 0.35
gd.addNumericField("Terrain diffusion", terr_terr_lpf, 5,7,"", "LPF for terrain pixels (diffusion to 4 neighbors).");
gd.addNumericField("Vegetation diffusion", terr_veget_lpf, 5,7,"", "LPF for vegetation pixels (diffusion to 4 neighbors).");
gd.addNumericField("Elevation diffusion", terr_elev_lpf, 5,7,"", "LPF for elevation pixels (diffusion to 4 neighbors).");
gd.addNumericField("Terrain pull zero", terr_terr_pull0, 5,7,"", "Terrain pixels pull to 0 (makes sense with UM).");
gd.addNumericField("Vegetation pull zero", terr_veget_pull0, 5,7,"", "Vegetation pixels pull to 0 (makes sense with UM).");
gd.addNumericField("Terrain pull", terr_terr_pull0, 5,7,"", "Terrain pixels pull to initial (pre-adjustment) values.");
gd.addNumericField("Vegetation pull", terr_veget_pull0, 5,7,"", "Vegetation pixels pull initial (pre-adjustment) values.");
gd.addNumericField("Elevation pull", terr_elev_pull0, 5,7,"", "Elevation pixels pull to initial (pre-adjustment) values.");
gd.addNumericField("Pull scene offset", terr_scenes_pull0, 5,7,"", "Pull average scene offset to zero.");
gd.addMessage ("LMA parameters");
......@@ -2766,7 +2768,8 @@ min_str_neib_fpn 0.35
terr_veget_lpf = gd.getNextNumber();// double
terr_elev_lpf = gd.getNextNumber();// double
terr_terr_pull0 = gd.getNextNumber();// double
terr_veget_pull0 = gd.getNextNumber();// double
terr_veget_pull0 = gd.getNextNumber();// double
terr_elev_pull0 = gd.getNextNumber();// double
terr_scenes_pull0 = gd.getNextNumber();// double
terr_boost_parallax = gd.getNextNumber();// double
terr_max_parallax = gd.getNextNumber();// double
......@@ -3441,6 +3444,7 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"terr_elev_lpf", terr_elev_lpf+""); // double
properties.setProperty(prefix+"terr_terr_pull0", terr_terr_pull0+""); // double
properties.setProperty(prefix+"terr_veget_pull0", terr_veget_pull0+""); // double
properties.setProperty(prefix+"terr_elev_pull0", terr_elev_pull0+""); // double
properties.setProperty(prefix+"terr_scenes_pull0", terr_scenes_pull0+""); // double
properties.setProperty(prefix+"terr_boost_parallax", terr_boost_parallax+""); // double
......@@ -4139,6 +4143,7 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"terr_elev_lpf")!= null) terr_elev_lpf=Double.parseDouble(properties.getProperty(prefix+"terr_elev_lpf"));
if (properties.getProperty(prefix+"terr_terr_pull0")!= null) terr_terr_pull0=Double.parseDouble(properties.getProperty(prefix+"terr_terr_pull0"));
if (properties.getProperty(prefix+"terr_veget_pull0")!= null) terr_veget_pull0=Double.parseDouble(properties.getProperty(prefix+"terr_veget_pull0"));
if (properties.getProperty(prefix+"terr_elev_pull0")!= null) terr_elev_pull0=Double.parseDouble(properties.getProperty(prefix+"terr_elev_pull0"));
if (properties.getProperty(prefix+"terr_scenes_pull0")!= null) terr_scenes_pull0=Double.parseDouble(properties.getProperty(prefix+"terr_scenes_pull0"));
if (properties.getProperty(prefix+"terr_boost_parallax")!= null) terr_boost_parallax=Double.parseDouble(properties.getProperty(prefix+"terr_boost_parallax"));
......@@ -4803,6 +4808,7 @@ min_str_neib_fpn 0.35
imp.terr_elev_lpf = this.terr_elev_lpf;
imp.terr_terr_pull0 = this.terr_terr_pull0;
imp.terr_veget_pull0 = this.terr_veget_pull0;
imp.terr_elev_pull0 = this.terr_elev_pull0;
imp.terr_scenes_pull0 = this.terr_scenes_pull0;
imp.terr_boost_parallax = this.terr_boost_parallax;
......
......@@ -413,8 +413,9 @@ public class VegetationLMA {
final double terr_lpf, // pull terrain to average of 4 neighbors (very small)
final double veget_lpf, // pull vegetation to average of 4 neighbors (very small - maybe not needed)
final double elevation_lpf,
final double terr_pull0, // pull terrain to zero (makes sense with UM
final double veget_pull0, // pull vegetation to zero (makes sense with UM
final double terr_pull0, // pull terrain to initial (pre-adjustment) values
final double veget_pull0, // pull vegetation to initial (pre-adjustment) values
final double elev_pull0, // pull elevation to initial (pre-adjustment) values
final double scenes_pull0,
final double boost_parallax, // increase weight of scene with maximal parallax relative to the reference scene
final double max_parallax, // do not consider maximal parallax above this (consider it a glitch)
......@@ -458,6 +459,7 @@ public class VegetationLMA {
this.elevation_lpf = elevation_lpf;
this.terr_pull0 = terr_pull0;
this.veget_pull0 = veget_pull0;
this.elevation_pull0 = elev_pull0;
this.scenes_pull0 = scenes_pull0;
this.boost_parallax = boost_parallax;
this.um_sigma = um_sigma; // just use in debug image names
......@@ -871,14 +873,6 @@ public class VegetationLMA {
this.initial_rms = this.last_rms.clone();
this.good_or_bad_rms = this.last_rms.clone();
if (debug_level > -1) { // temporary
/*
dbgYminusFxWeight(
this.last_ymfx,
this.weights,
"Initial_y-fX_after_moving_objects");
*/
}
if (last_ymfx == null) {
return null; // need to re-init/restart LMA
}
......@@ -932,12 +926,12 @@ public class VegetationLMA {
Matrix y_minus_fx_weighted = new Matrix(this.last_ymfx, this.last_ymfx.length);
boolean debug_jtj = debug_level>4;
Matrix wjtjlambda = new Matrix(getWJtJlambda(
lambda, // *10, // temporary
this.last_jt, // double [][] jt) // null
null)); // final boolean [][] pivot)));
param_pivot, // final boolean [][] pivot)));
debug_jtj)); // final boolean debug));
if (debug_level>4) {
System.out.println("JtJ + lambda*diag(JtJ");
wjtjlambda.print(18, 6);
......@@ -1111,14 +1105,61 @@ public class VegetationLMA {
System.out.println("saveDoubleArrayInModelDirectory(): saved "+file_path);
}
}
return;
}
private double [][] getWJtJlambdaDebug(
final double lambda,
final double [][] jt,
final boolean [][] pivot) {
long startTime = System.nanoTime();
double [][] jtj_full = getWJtJlambda(
lambda, // final double lambda,
jt, // final double [][] jt,
null, // final boolean [][] pivot,
false);
long fullTime = System.nanoTime();
double full_run_time = (fullTime - startTime) * 1E-9;
System.out.println("getWJtJlambdaDebug(): full run time: "+full_run_time+"s.");
double [][] jtj = getWJtJlambda(
lambda, // final double lambda,
jt, // final double [][] jt,
pivot, // final boolean [][] pivot,
false);
long endTime = System.nanoTime();
double pivot_run_time = (endTime - fullTime) * 1E-9;
System.out.println("getWJtJlambdaDebug():with pivot array: "+pivot_run_time+"s.");
double max_err = 0;
for (int par0 = 0; par0 < jtj_full.length; par0++) {
for (int par1 = par0; par1 < jtj_full[par0].length; par1++) {
double diff= jtj[par0][par1] - jtj_full[par0][par1];
double adiff = Math.abs(diff);
if (adiff > max_err) {
System.out.println("getWJtJlambdaDebug(): par0="+par0+", par1="+par1+" diff="+diff+
", jtj="+jtj[par0][par1]+", jtj_full="+jtj_full[par0][par1]);
max_err = adiff;
}
}
}
System.out.println("getWJtJlambdaDebug(): max_err="+max_err);
return jtj_full; // old version
}
private double [][] getWJtJlambda(
final double lambda,
final double [][] jt,
final boolean [][] pivot)
final boolean [][] pivot,
final boolean debug)
{
if (debug && (pivot != null)) {
return getWJtJlambdaDebug(
lambda, // final double lambda,
jt, // final double [][] jt,
pivot); // final boolean [][] pivot,
}
final int num_pars = jt.length;
final int num_pars2 = num_pars * num_pars;
final int nup_points = jt[0].length;
......@@ -1192,9 +1233,18 @@ public class VegetationLMA {
double min_vegetation) { // 0.5
double [][] tvas = getTVASWoi(
vector); // final double [] vector)
double [][] terrain_weights_max = getTerrainWeights(
threshold_terrain, // final double alpha_threshold, // discard images with too low transparency
vector); // final double [] vector)
double [][] terrain_weights_max;
if (tvas== null) { // just temporary
terrain_weights_max = getTerrainWeights(
threshold_terrain, // final double alpha_threshold, // discard images with too low transparency
vector); // final double [] vector)
} else {
terrain_weights_max = new double [2][woi_veg.width * woi_veg.height];
Arrays.fill(terrain_weights_max[0],0.1);
Arrays.fill(terrain_weights_max[1],0.9);
}
double [] terrain_masked = tvas[0].clone();
double [] vegetation_masked = tvas[1].clone();
for (int i = 0; i < terrain_masked.length; i++) {
......@@ -1202,13 +1252,13 @@ public class VegetationLMA {
if (!(terrain_weights_max[1][i] >= min_max_terrain)) terrain_masked[i] = Double.NaN;
if (!(tvas[2][i] >= min_vegetation)) vegetation_masked[i] = Double.NaN;
}
double [][] tvww = {terrain_masked, vegetation_masked, tvas[0], tvas[1], terrain_weights_max[0], terrain_weights_max[1],tvas[2]}; // no scene offsets
String [] titles = {"terr>"+min_terrain,"veget>"+min_vegetation,"terr","veget","terr_str","terr_max","alpha"};
double [][] tvww = {terrain_masked, vegetation_masked, tvas[0], tvas[1], terrain_weights_max[0], terrain_weights_max[1],tvas[2],tvas[3]}; // no scene offsets
String [] titles = {"terr>"+min_terrain,"veget>"+min_vegetation,"terr","veget","terr_str","terr_max","alpha","elevation"};
ShowDoubleFloatArrays.showArrays(
tvww,
woi.width,
woi.height,
woi_veg.width,
woi_veg.height,
true,
title,
titles);
......@@ -1217,18 +1267,18 @@ public class VegetationLMA {
public double [][] getTVASWoi(
final double [] vector){
final int woi_length = woi.width*woi.height;
double [][] tvas = new double [4][];
for (int i = 0; i < 3; i++) tvas[i] = new double [woi_length];
tvas[3] = new double [num_scenes];
final int woi_length = woi_veg.width*woi_veg.height;
double [][] tvas = new double [TVAO_TYPES][];
for (int i = 0; i < TVAO_SCENE_OFFSET; i++) tvas[i] = new double [woi_length];
tvas[TVAO_SCENE_OFFSET] = new double [num_scenes];
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int windx = ai.getAndIncrement(); windx < woi_length; windx = ai.getAndIncrement()) {
int x = windx % woi.width + woi.x;
int y = windx / woi.width + woi.y;
int x = windx % woi_veg.width + woi_veg.x;
int y = windx / woi_veg.width + woi_veg.y;
int indx = x + y * full.width;
for (int i = 0; i < 3; i++) {
tvas[i][windx] = tvao[i][indx]; // non-adjusted parameters
......@@ -1246,10 +1296,10 @@ public class VegetationLMA {
public void run() {
for (int pindx = ai.getAndIncrement(); pindx < vector.length; pindx = ai.getAndIncrement()) {
int [] indices = par_rindex[pindx];
if (indices[0] <3) {
int wx = indices[1] % full.width - woi.x;
int wy = indices[1] / full.width - woi.y;
int windx = wx + wy * woi.width;
if (indices[0] < TVAO_SCENE_OFFSET) {
int wx = indices[1] % full.width - woi_veg.x;
int wy = indices[1] / full.width - woi_veg.y;
int windx = wx + wy * woi_veg.width;
tvas[indices[0]][windx] = vector[pindx]; // all adjusted parameters, including offsets
} else {
tvas[indices[0]][ indices[1]] = vector[pindx]; // all adjusted parameters, including offsets
......@@ -1310,12 +1360,12 @@ public class VegetationLMA {
}
private double [][] getTerrainWeights(
@Deprecated
private double [][] getTerrainWeights( // FIXME !
final double alpha_threshold, // discard images with too low transparency
final double [] vector)
{
final int woi_length = woi.width*woi.height;
final int woi_length = woi_veg.width*woi_veg.height;
final double [][] terrain_scene_weights = new double [num_scenes][woi_length];
final double [][] terrain_scene_max = new double [num_scenes][woi_length];
final double [][] full_scene_weights = new double [num_scenes][woi_length];
......@@ -1329,9 +1379,9 @@ public class VegetationLMA {
for (int n = ai.getAndIncrement(); n < y_vector.length; n = ai.getAndIncrement()) {
int nscene = data_source[n][0][0];
int indx = data_source[n][0][1];
int x = indx % full.width - woi.x;
int y = indx / full.width - woi.y;
int windx = x + y * woi.width;
int x = indx % full.width - woi_veg.x;
int y = indx / full.width - woi_veg.y;
int windx = x + y * woi_veg.width;
double [] cw = corners_weights[n];
int [] indx_alpha = data_source[n][2];
double sum_a =0;
......@@ -1651,6 +1701,52 @@ public class VegetationLMA {
* @param neibs array of the 4 neighbors for each parameter (only non-negative count)
* @param start_index start parameter index in the neibs[][] array
*/
private static void pivotAddNeighbors0(
final boolean [][] pivot,
final int [][] neibs,
final int start_index) {
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nPar = ai.getAndIncrement(); nPar < neibs.length; nPar = ai.getAndIncrement()){
int full_par = nPar+start_index;
int [] this_neibs = neibs[nPar];
for (int dir = 0; dir < this_neibs.length; dir ++) {
int neib = this_neibs[dir];
if (neib >=0) {
pivot[full_par][neib] = true;
}
}
pivot[full_par][full_par] = true;
}
}
};
}
ImageDtt.startAndJoin(threads);
// transposed
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nPar = ai.getAndIncrement(); nPar < neibs.length; nPar = ai.getAndIncrement()){
int full_par = nPar+start_index;
int [] this_neibs = neibs[nPar];
for (int dir = 0; dir < this_neibs.length; dir ++) {
int neib = this_neibs[dir];
if (neib >=0) {
pivot[neib][full_par] = true;
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
private static void pivotAddNeighbors(
final boolean [][] pivot,
final int [][] neibs,
......@@ -1667,6 +1763,16 @@ public class VegetationLMA {
int neib = this_neibs[dir];
if (neib >=0) {
pivot[full_par][neib] = true;
int neib_rel = neib - start_index;
if ((neib_rel >= 0) && (neib_rel < neibs.length)) {
int [] this_neib_neibs = neibs[neib_rel];
for (int dir_neib = 0; dir_neib < this_neib_neibs.length; dir_neib ++) {
int neib_neib = this_neib_neibs[dir_neib];
if (neib_neib >= 0) {
pivot[full_par][neib_neib] = true;
}
}
}
}
}
pivot[full_par][full_par] = true;
......@@ -1687,6 +1793,16 @@ public class VegetationLMA {
int neib = this_neibs[dir];
if (neib >=0) {
pivot[neib][full_par] = true;
int neib_rel = neib - start_index;
if ((neib_rel >= 0) && (neib_rel < neibs.length)) {
int [] this_neib_neibs = neibs[neib_rel];
for (int dir_neib = 0; dir_neib < this_neib_neibs.length; dir_neib ++) {
int neib_neib = this_neib_neibs[dir_neib];
if (neib_neib >= 0) {
pivot[neib_neib][full_par] = true;
}
}
}
}
}
}
......@@ -1697,6 +1813,9 @@ public class VegetationLMA {
}
private double [] getFxDerivs(
final double [] vector,
final double [][] jt, // should be null or initialized with [vector.length][]
......@@ -2547,7 +2666,6 @@ public class VegetationLMA {
if (debug_level>4) showPivot(param_pivot, "pivot-elevation");
}
}
return fX;
}
......@@ -3297,7 +3415,7 @@ public class VegetationLMA {
// scale alpha for the same image
int w = i % woi_width4;
int h = i / woi_width4;
int nsub = w % (woi_veg.width + gap);
int nsub = w / (woi_veg.width + gap);
if (nsub == 2) { // alpha
dbg_img[i] = debug_alpha_scales[0] + (debug_alpha_scales[1] - debug_alpha_scales[0]) * dbg_img[i];
} else if (nsub== 3) { // elevation
......@@ -4141,7 +4259,7 @@ public class VegetationLMA {
int w = i % woi_width4;
int h = i / woi_width4;
int nsub = w % (woi_veg.width + gap);
int nsub = w / (woi_veg.width + gap);
if (nsub == 2) { // alpha
d = (d- debug_alpha_scales[0])/(debug_alpha_scales[1] - debug_alpha_scales[0]);
} else if (nsub== 3) { // elevation
......
......@@ -1409,9 +1409,10 @@ public class VegetationModel {
double alpha_mm_hole = clt_parameters.imp.terr_alpha_mm_hole; // 0.1; // NaN to disable. Local "almost minimum" (lower than this fraction between min and max neighbor) is not subject to alpha_lpf
double terr_lpf = clt_parameters.imp.terr_terr_lpf; // 0.1; // 0.15; /// 0.2; /// 0.1; // pull terrain to average of 4 neighbors (very small)
double veget_lpf = clt_parameters.imp.terr_veget_lpf; // 0.2; //0.15; /// 0.2; //// 0.01; /// 0.1; // pull vegetation to average of 4 neighbors (very small - maybe not needed)
double elevation_lpf = 0;
double elevation_lpf = clt_parameters.imp.terr_elev_lpf;
double terr_pull0 = clt_parameters.imp.terr_terr_pull0; // 0.05; //0.03; ////// 0.05; ///// 0.1; //// 0.01; /// 0.2; /// 0.1; //pull terrain to zero (makes sense with UM
double veget_pull0 = clt_parameters.imp.terr_veget_pull0; // 0.05; //0.1; // 0.03; ////// 0.05; ///// 0.1; //// 0.01; /// 0.1; // pull vegetation to zero (makes sense with UM
double elev_pull0 = clt_parameters.imp.terr_elev_pull0;
double scenes_pull0 = clt_parameters.imp.terr_scenes_pull0; // 1.0
// LMA parameters
......@@ -1953,8 +1954,9 @@ public class VegetationModel {
terr_lpf, // final double terr_lpf, // pull terrain to average of 4 neighbors (very small)
veget_lpf, // final double veget_lpf, // pull vegetation to average of 4 neighbors (very small - maybe not needed)
elevation_lpf, // final double elevation_lpf,
terr_pull0, // final double terr_pull0, // pull terrain to zero (makes sense with UM
veget_pull0, // final double veget_pull0, // pull vegetation to zero (makes sense with UM
terr_pull0, // final double terr_pull0, // pull terrain to initial (pre-adjustment) values
veget_pull0, // final double veget_pull0, // pull vegetation to initial (pre-adjustment) values
elev_pull0, // final double elev_pull0, // pull elevation to initial (pre-adjustment) values
scenes_pull0, // final double scenes_pull0,
boost_parallax,// final double boost_parallax, // increase weight of scene with maximal parallax relative to the reference scene
max_parallax, //final double max_parallax, // do not consider maximal parallax above this (consider it a glitch)
......
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