Commit 883c0212 authored by Andrey Filippov's avatar Andrey Filippov

intermediate, before changing alpha pull

parent 1893ac24
......@@ -5802,11 +5802,11 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
} else if (label.equals("Process Merged")) {
OrangeTest.processMerged();
} else if (label.equals("Vegetation LMA")) {
VegetationModel.processVegetationLMA(
VegetationModel.processVegetation(
CLT_PARAMETERS, //CLTParameters clt_parameters,
false); //boolean combine_segments);
} else if (label.equals("Combine LMA Segments")) {
VegetationModel.processVegetationLMA(
VegetationModel.processVegetation(
CLT_PARAMETERS, //CLTParameters clt_parameters,
true); //boolean combine_segments);
}
......
......@@ -786,6 +786,12 @@ min_str_neib_fpn 0.35
public double terr_elevation_radius = 1.5; // Radius of elevation/vegetation influence
public double terr_alpha_contrast = 1.0; // initial alpha contrast (>=1.0)
public double terr_alpha_dflt = 0.5; // now unused
public double terr_alpha_sigma = 8.0; // Initial alpha: Gaussian blur sigma to find local average for vegetation temperature.
public double terr_alpha_init_min = 0.7; // Initial alpha: fraction for transparent
public double terr_alpha_init_max = 0.95; // Initial alpha: fraction for opaque
public double terr_alpha_init_offs = 0.01; // Initial alpha: opaque/transparent offset from 1.0/0.0
public double terr_alpha_loss = 100.0;
public double terr_alpha_offset = 0.0;
public double terr_alpha_lpf = 2.5; // pull to average of 4 neighbors
......@@ -802,6 +808,10 @@ min_str_neib_fpn 0.35
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 boolean terr_elev_alpha_en = false;// Enable loss for low vegetation with high opacity
public double terr_elev_alpha = 1.0; // multiply alpha by under-low elevation for loss
public double terr_elev_alpha_pwr = 2.0; // raise alpha to this power (when alpha > 0)
public double terr_low_veget = 2.0; // (pix) Elevation considered low (lower loss for high alpha)
public double terr_scenes_pull0 = 1.0; // pull average scene offset to zero
// LMA parameters
......@@ -2083,6 +2093,12 @@ min_str_neib_fpn 0.35
gd.addNumericField("Alpha initial contrast",terr_alpha_contrast, 5,7,"","Initial alpha contrast (>= 1.0).");
gd.addNumericField("Defalt alpha", terr_alpha_dflt, 5,7,"", "Default vegetation alpha.");
gd.addNumericField("Initial alpha sigma", terr_alpha_sigma, 5,7,"", "Initial alpha: Gaussian blur sigma to find local average for vegetation temperature..");
gd.addNumericField("Initial alpha min frac",terr_alpha_init_min,5,7,"", "Initial alpha: fraction for transparent.");
gd.addNumericField("Initial alpha max frac",terr_alpha_init_max,5,7,"", "Initial alpha: fraction for opaque.");
gd.addNumericField("Initial alpha offset", terr_alpha_init_offs, 5,7,"","Initial alpha: opaque/transparent offset from 1.0/0.0.");
gd.addNumericField("Alpha loss", terr_alpha_loss, 5,7,"", "Alpha quadratic growing loss for when out of [0,1] range");
gd.addNumericField("Alpha offset", terr_alpha_offset, 5,7,"", "Start alpha losses above 0.0 and below 1.0 by this value.");
......@@ -2100,6 +2116,12 @@ min_str_neib_fpn 0.35
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.addCheckbox ("Enable low vegetation",terr_elev_alpha_en, "Enable loss for low vegetation with high opacity.");
gd.addNumericField("Low vegetation loss", terr_elev_alpha, 5,7,"", "Multiply alpha by under-low elevation for loss.");
gd.addNumericField("Low vegetation power", terr_elev_alpha_pwr, 5,7,"", "Raise alpha to this power for low vegetation loss.");
gd.addNumericField("Low elevation", terr_low_veget, 5,7,"pix", "Elevation considered low (lower loss for high alpha.");
gd.addNumericField("Pull scene offset", terr_scenes_pull0, 5,7,"", "Pull average scene offset to zero.");
gd.addMessage ("LMA parameters");
......@@ -2817,6 +2839,12 @@ min_str_neib_fpn 0.35
terr_elevation_radius = gd.getNextNumber();// double
terr_alpha_contrast = gd.getNextNumber();// double
terr_alpha_dflt = gd.getNextNumber();// double
terr_alpha_sigma = gd.getNextNumber();// double
terr_alpha_init_min = gd.getNextNumber();// double
terr_alpha_init_max = gd.getNextNumber();// double
terr_alpha_init_offs = gd.getNextNumber();// double
terr_alpha_loss = gd.getNextNumber();// double
terr_alpha_offset = gd.getNextNumber();// double
terr_alpha_lpf = gd.getNextNumber();// double
......@@ -2834,6 +2862,10 @@ min_str_neib_fpn 0.35
terr_terr_pull0 = gd.getNextNumber();// double
terr_veget_pull0 = gd.getNextNumber();// double
terr_elev_pull0 = gd.getNextNumber();// double
terr_elev_alpha_en = gd.getNextBoolean();// boolean
terr_elev_alpha = gd.getNextNumber();// double
terr_elev_alpha_pwr = gd.getNextNumber();// double
terr_low_veget = gd.getNextNumber();// double
terr_scenes_pull0 = gd.getNextNumber();// double
terr_boost_parallax = gd.getNextNumber();// double
terr_max_parallax = gd.getNextNumber();// double
......@@ -3517,6 +3549,12 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"terr_elevation_radius", terr_elevation_radius+""); // double
properties.setProperty(prefix+"terr_alpha_contrast", terr_alpha_contrast+""); // double
properties.setProperty(prefix+"terr_alpha_dflt", terr_alpha_dflt+""); // double
properties.setProperty(prefix+"terr_alpha_sigma", terr_alpha_sigma+""); // double
properties.setProperty(prefix+"terr_alpha_init_min", terr_alpha_init_min+""); // double
properties.setProperty(prefix+"terr_alpha_init_max", terr_alpha_init_max+""); // double
properties.setProperty(prefix+"terr_alpha_init_offs", terr_alpha_init_offs+""); // double
properties.setProperty(prefix+"terr_alpha_loss", terr_alpha_loss+""); // double
properties.setProperty(prefix+"terr_alpha_offset", terr_alpha_offset+""); // double
properties.setProperty(prefix+"terr_alpha_lpf", terr_alpha_lpf+""); // double
......@@ -3532,6 +3570,10 @@ min_str_neib_fpn 0.35
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_elev_alpha_en", terr_elev_alpha_en+""); // boolean
properties.setProperty(prefix+"terr_elev_alpha", terr_elev_alpha+""); // double
properties.setProperty(prefix+"terr_elev_alpha_pwr", terr_elev_alpha_pwr+""); // double
properties.setProperty(prefix+"terr_low_veget", terr_low_veget+""); // double
properties.setProperty(prefix+"terr_scenes_pull0", terr_scenes_pull0+""); // double
properties.setProperty(prefix+"terr_boost_parallax", terr_boost_parallax+""); // double
......@@ -4234,6 +4276,12 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"terr_elevation_radius")!= null) terr_elevation_radius=Double.parseDouble(properties.getProperty(prefix+"terr_elevation_radius"));
if (properties.getProperty(prefix+"terr_alpha_contrast")!= null) terr_alpha_contrast=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_contrast"));
if (properties.getProperty(prefix+"terr_alpha_dflt")!= null) terr_alpha_dflt=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_dflt"));
if (properties.getProperty(prefix+"terr_alpha_sigma")!= null) terr_alpha_sigma=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_sigma"));
if (properties.getProperty(prefix+"terr_alpha_init_min")!= null) terr_alpha_init_min=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_init_min"));
if (properties.getProperty(prefix+"terr_alpha_init_max")!= null) terr_alpha_init_max=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_init_max"));
if (properties.getProperty(prefix+"terr_alpha_init_offs")!= null) terr_alpha_init_offs=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_init_offs"));
if (properties.getProperty(prefix+"terr_alpha_loss")!= null) terr_alpha_loss=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_loss"));
if (properties.getProperty(prefix+"terr_alpha_offset")!= null) terr_alpha_offset=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_offset"));
if (properties.getProperty(prefix+"terr_alpha_lpf")!= null) terr_alpha_lpf=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_lpf"));
......@@ -4250,6 +4298,10 @@ min_str_neib_fpn 0.35
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_elev_alpha_en")!= null) terr_elev_alpha_en=Boolean.parseBoolean(properties.getProperty(prefix+"terr_elev_alpha_en"));
if (properties.getProperty(prefix+"terr_elev_alpha")!= null) terr_elev_alpha=Double.parseDouble(properties.getProperty(prefix+"terr_elev_alpha"));
if (properties.getProperty(prefix+"terr_elev_alpha_pwr")!= null) terr_elev_alpha_pwr=Double.parseDouble(properties.getProperty(prefix+"terr_elev_alpha_pwr"));
if (properties.getProperty(prefix+"terr_low_veget")!= null) terr_low_veget=Double.parseDouble(properties.getProperty(prefix+"terr_low_veget"));
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"));
......@@ -4917,6 +4969,12 @@ min_str_neib_fpn 0.35
imp.terr_elevation_radius = this.terr_elevation_radius;
imp.terr_alpha_contrast = this.terr_alpha_contrast;
imp.terr_alpha_dflt = this.terr_alpha_dflt;
imp.terr_alpha_sigma = this.terr_alpha_sigma;
imp.terr_alpha_init_min = this.terr_alpha_init_min;
imp.terr_alpha_init_max = this.terr_alpha_init_max;
imp.terr_alpha_init_offs = this.terr_alpha_init_offs;
imp.terr_alpha_loss = this.terr_alpha_loss;
imp.terr_alpha_offset = this.terr_alpha_offset;
imp.terr_alpha_lpf = this.terr_alpha_lpf;
......@@ -4933,6 +4991,10 @@ min_str_neib_fpn 0.35
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_elev_alpha_en = this.terr_elev_alpha_en;
imp.terr_elev_alpha = this.terr_elev_alpha;
imp.terr_elev_alpha_pwr = this.terr_elev_alpha_pwr;
imp.terr_low_veget = this.terr_low_veget;
imp.terr_scenes_pull0 = this.terr_scenes_pull0;
imp.terr_boost_parallax = this.terr_boost_parallax;
......
......@@ -19,6 +19,7 @@ import com.elphel.imagej.jp4.JP46_Reader_camera;
import com.elphel.imagej.tileprocessor.ImageDtt;
import com.elphel.imagej.tileprocessor.QuadCLT;
import com.elphel.imagej.tileprocessor.TileNeibs;
import com.elphel.imagej.tileprocessor.TileProcessor;
import Jama.Matrix;
import ij.ImagePlus;
......@@ -55,7 +56,8 @@ public class VegetationLMA {
public static final int SAMPLES_VEGETATION_LPF = 9;
public static final int SAMPLES_ELEVATION_PULL = 10;
public static final int SAMPLES_ELEVATION_LPF = 11;
public static final int SAMPLES_TOTAL = 12; // {total samples, extra_samples}
public static final int SAMPLES_ELEVATION_ALPHA =12; // loss for low elevation * high alpha
public static final int SAMPLES_TOTAL = 13; // {total samples, extra_samples}
public static final int SAMPLES_SIZE = SAMPLES_TOTAL+1;
public static final int SAMPLES_EXTRA = SAMPLES_SCENES; // start of "extra" samples
......@@ -171,12 +173,16 @@ public class VegetationLMA {
private double terr_pull0 = 0; // (+) now - pull to filled terrain - terrain_average
private double veget_pull0 = 0; // (+) now - pull to vegetation_pull (extended vegetation)
public double elevation_pull0 = 0; // (*) now - pull to initial elevation
public boolean elev_alpha_en = false;// (+) false; // Enable loss for low vegetation with high opacity
public double elev_alpha = 1.0; // (+) multiply alpha by under-low elevation for loss
public double elev_alpha_pwr = 2.0; // raise alpha to this power (when alpha > 0)
public double low_veget = 2.0; // (+) (pix) Elevation considered low (lower loss for high alpha)
private double scenes_pull0 = 0; // (*) pull average scene offset to 0;
private double scale_scenes_pull = 0; // (*) used in getFxDerivs to scale scene offsets as their weight will be reg_weights / extra_samples
public double boost_parallax = 1; // (+)
// data used to calculate lpf pull of the alpha pixel to average of four neighbors. Below similar (weaker pull) for terrain and vegetation
// to smooth areas where there is no data from available images.
public int [][] alpha_neibs; // corresponds to parameters for alpha (num_pars[TVAO_VEGETATION]_alpha), each has 4 ortho neibs, -1 - border, >= 0
......@@ -233,7 +239,11 @@ public class VegetationLMA {
public VegetationLMA (
VegetationModel vegetationModel,
double alpha_initial_contrast) {
double alpha_offs,
double alpha_min,
double alpha_max,
double alpha_sigma,
int debugLevel) {
// this.alpha_initial_contrast = alpha_initial_contrast;
full = vegetationModel.full;
image_length = full.width * full.height;
......@@ -245,25 +255,44 @@ public class VegetationLMA {
vegetation_offsets =vegetationModel.vegetation_warp;
tvao = new double[TVAO_TYPES][];
tvao[TVAO_TERRAIN] = this.terrain_average.clone();
tvao[TVAO_VEGETATION] = this.vegetation_average.clone();
// tvao[TVAO_VEGETATION] = this.vegetation_average.clone(); // set inside setupInitialTerrainVegetationAlpha()
tvao[TVAO_SCENE_OFFSET] = new double [num_scenes];
setupInitialTerrainVegetationAlpha(
alpha_initial_contrast, // double alpha_contrast,
true, // boolean blur_vegetation,
alpha_offs, // double alpha_offs,
alpha_min, // double alpha_min,
alpha_max, // double alpha_max,
alpha_sigma, // double alpha_sigma,
vegetationModel.terrain_filled, // double [] terrain_filled,
vegetationModel.vegetation_pull, // double [] vegetation_extended,
vegetationModel.vegetation_full); // double [] vegetation) { // best guess
vegetationModel.vegetation_full, // double [] vegetation) { // best guess
vegetationModel.elevations, //double [] elevation,
debugLevel); // int debugLevel) {
setupLaplacians(0.0); // double weight_diag)
this.vegetationModel = vegetationModel; // to access scene names, directories, reference index
scene_weights = new double [num_scenes];
scales_xy = getScalesXY(vegetationModel.scale_dirs);
tvao[TVAO_ELEVATION] = vegetationModel.elevations.clone();
if (debugLevel > -2) {
String [] titles = {"TVAO_TERRAIN", "TVAO_VEGETATION", "vegetation_pull", "vegetation_full", "elevations", "TVAO_ALPHA"};
double [][] dbg_img = {tvao[TVAO_TERRAIN],tvao[TVAO_VEGETATION],vegetationModel.vegetation_pull,vegetationModel.vegetation_full,vegetationModel.elevations,tvao[TVAO_ALPHA]};
ShowDoubleFloatArrays.showArrays(
dbg_img,
full.width,
full.height,
true,
"ALPHA",
titles);
}
return;
}
public VegetationLMA (
@Deprecated
public VegetationLMA ( // unused
String path,
VegetationModel vegetationModel,
double alpha_initial_contrast) {
double alpha_initial_contrast,
int debugLevel) {
full = vegetationModel.full;
image_length = full.width * full.height;
num_scenes = vegetationModel.terrain_scenes_render.length;
......@@ -280,7 +309,9 @@ public class VegetationLMA {
alpha_initial_contrast, // double alpha_contrast,
vegetationModel.terrain_filled, // double [] terrain_filled,
vegetationModel.vegetation_pull, // double [] vegetation_extended,
vegetationModel.vegetation_full); // double [] vegetation) { // best guess
vegetationModel.vegetation_full, // double [] vegetation) { // best guess
debugLevel); // int debugLevel) {
setupLaplacians(0.0); // double weight_diag)
this.vegetationModel = vegetationModel; // to access scene names, directories, reference index
scene_weights = new double [num_scenes];
......@@ -337,7 +368,8 @@ public class VegetationLMA {
double alpha_contrast,
double [] terrain_filled,
double [] vegetation_extended,
double [] vegetation) { // best guess
double [] vegetation, // best guess
int debugLevel) {
double dbg_lim = 0.01;
tvao[TVAO_TERRAIN] = terrain_filled.clone(); // == vegetationModel.terrain_filled
tvao[TVAO_VEGETATION] = vegetation_extended.clone();
......@@ -370,6 +402,75 @@ public class VegetationLMA {
}
}
private void setupInitialTerrainVegetationAlpha(
boolean blur_vegetation,
double alpha_offs,
double alpha_min,
double alpha_max,
double alpha_sigma,
double [] terrain_filled,
double [] vegetation_extended,
double [] vegetation, // best guess
double [] elevation,
int debugLevel) {
int dbg_pix = 90337;
// double dbg_lim = 0.01;
tvao[TVAO_TERRAIN] = terrain_filled.clone(); // == vegetationModel.terrain_filled
tvao[TVAO_VEGETATION] = vegetation_extended.clone();
tvao[TVAO_ALPHA] = new double [image_length];
double [] vegetation_blur = vegetation_extended.clone(); // .clone();
double scale_sigma = 5.0; // non-NaN - 5 pixels from original NaN for each sigma
int grow = 2* Math.min((int) Math.ceil(alpha_sigma * scale_sigma), full.width);
vegetation_blur = TileProcessor.fillNaNs(
vegetation_blur, // final double [] data,
null, // final boolean [] prohibit,
full.width, // int width,
// CAREFUL ! Remaining NaN is grown by unsharp mask filter ************* !
grow, // 100, // 2*width, // 16, // final int grow,
0.7, // double diagonal_weight, // relative to ortho
100, // int num_passes,
0.03); // final double max_rchange, // = 0.01 - does not need to be accurate
(new DoubleGaussianBlur()).blurDouble(
vegetation_blur, //
full.width,
full.height,
alpha_sigma, // double sigmaX,
alpha_sigma, // double sigmaY,
0.01); // double accuracy)
for (int npix = 0; npix < image_length; npix++) {
if (npix==dbg_pix) {
System.out.println("setupInitialTerrainVegetationAlpha(): npix="+npix);
}
double t = terrain_filled[npix];
double v = vegetation[npix];
// double vp = vegetation_extended[npix];
double bp = vegetation_blur[npix];
double ep = elevation[npix];
double a = 0; // Double.NaN; // .isNaN(vegetation_filtered[npix])? 0.0:1.0; // not needed
if (!Double.isNaN(t) && !Double.isNaN(v) && !Double.isNaN(bp) && !Double.isNaN(ep)) {
if ((v > t) && (bp > t)) {
double f = (v-t)/(bp-t);
if (f > alpha_min) {
if ( f > alpha_max) {
a = 1.0;
} else {
a = (f-alpha_min) / (alpha_max - alpha_min);
}
}
}
}
a = alpha_offs + (1 - 2 * alpha_offs) * a;
tvao[TVAO_ALPHA][npix] = a;
if (blur_vegetation) {
tvao[TVAO_VEGETATION][npix] = bp;
}
}
return;
}
@SuppressWarnings("unused")
......@@ -429,6 +530,10 @@ public class VegetationLMA {
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 boolean elev_alpha_en, // false; // Enable loss for low vegetation with high opacity
final double elev_alpha, // 1.0; // multiply alpha by under-low elevation for loss
final double elev_alpha_pwr, // 2.0; // raise alpha to this power (when alpha > 0)
final double low_veget, // 2.0; // (pix) Elevation considered low (lower loss for high alpha)
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)
......@@ -463,6 +568,10 @@ public class VegetationLMA {
this.terr_pull0 = terr_pull0;
this.veget_pull0 = veget_pull0;
this.elevation_pull0 = elev_pull0;
this.elev_alpha_en = elev_alpha_en;
this.elev_alpha = elev_alpha;
this.elev_alpha_pwr = elev_alpha_pwr;
this.low_veget = low_veget;
this.scenes_pull0 = scenes_pull0;
this.boost_parallax = boost_parallax;
// this.um_sigma = um_sigma; // just use in debug image names
......@@ -1168,6 +1277,9 @@ public class VegetationLMA {
debug_title += "-al"+alpha_loss+"-alo"+alpha_offset+"-alp"+alpha_lpf+"-als"+alpha_scale_avg+(alpha_piece_linear?"-alin":"-acos");
debug_title += "-ap"+alpha_push+"-apn"+alpha_push_neutral+"-apc"+alpha_push_center+(alpha_en_holes?("-amm"+alpha_mm_hole):"");
debug_title += "-tl"+terr_lpf+"-vl"+veget_lpf+"-el"+elevation_lpf+"-tp"+terr_pull0+"-vp"+veget_pull0+"-ep"+elevation_pull0;
if (elev_alpha_en) {
debug_title += "-ea"+elev_alpha+"-ep"+elev_alpha_pwr+"-lv"+low_veget;
}
debug_title += "-sp"+scenes_pull0+"-ss"+scale_scenes_pull+"-bp"+boost_parallax;
debug_title += from_file?"-file":"-new";
return debug_title;
......@@ -2209,7 +2321,7 @@ public class VegetationLMA {
continue;
}
} else {
vegetation = tvao[TVAO_ELEVATION][npix];
vegetation = tvao[TVAO_VEGETATION][npix];
}
if (alpha_parameters) {
napar = par_index[TVAO_ALPHA][npix];
......@@ -3114,6 +3226,41 @@ public class VegetationLMA {
}
ImageDtt.startAndJoin(threads);
}
// loss for low elevation (interfering with the terrain) and high alpha
if ((samples_pointers[SAMPLES_ELEVATION_ALPHA][1]>0) && elev_alpha_en) { // fits[TVAO_ELEVATION] && (elevation_lpf >= 0)) { // should be positive for pull0 and terr_pull_cold (difference between vegetation and terrain)
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int n = ai.getAndIncrement(); n < num_pars[TVAO_ELEVATION]; n = ai.getAndIncrement()) {
int np = n + samples_pointers[SAMPLES_ELEVATION_ALPHA][2];
int nx = n + samples_pointers[SAMPLES_ELEVATION_ALPHA][0];
if (elev_alpha > 0) {
int findx = par_rindex[np][1];
int ap = par_index[TVAO_ALPHA][findx];
if (ap >= 0) { // normally always
double elev = vector[np];
if (elev < low_veget) {
double alpha = vector[ap];
if (alpha > 0) {
double alpha_pwr = Math.pow(alpha, elev_alpha_pwr);
fX[nx] += elev_alpha * (low_veget - elev) * alpha_pwr;
if (jt != null) {
jt[np][nx] += -elev_alpha * alpha_pwr;
jt[ap][nx] += elev_alpha * (low_veget - elev) * elev_alpha_pwr * alpha_pwr/alpha;
}
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
// create pivot table
if (need_derivs) {
param_lists = new int [par_rindex.length][];
......@@ -3367,7 +3514,7 @@ public class VegetationLMA {
// terrain, vegetation, alpha, elevation lpf
int [][] sample_types = {
{SAMPLES_TERRAIN_PULL, SAMPLES_VEGETATION_PULL, SAMPLES_ALPHA_PULL,SAMPLES_ELEVATION_PULL, SAMPLES_Y_AVG},
{SAMPLES_TERRAIN_LPF, SAMPLES_VEGETATION_LPF, SAMPLES_ALPHA_LPF, SAMPLES_ELEVATION_LPF, -1}};
{SAMPLES_TERRAIN_LPF, SAMPLES_VEGETATION_LPF, SAMPLES_ALPHA_LPF, SAMPLES_ELEVATION_LPF, SAMPLES_ELEVATION_ALPHA}}; // -1}};
if (extra) {
for (int pull_lpf = 0; pull_lpf < 2; pull_lpf++) {
int row0 = extra_start + pull_lpf * (woi_veg.height + gap);
......@@ -3406,7 +3553,9 @@ public class VegetationLMA {
if (vector == null) {
vector = parameters_vector;
}
final boolean use_hf = y_vector.length > y_src.length; // twice longer
// final boolean use_hf = y_vector.length > y_src.length; // twice longer
final boolean use_hf = samples_pointers[SAMPLES_Y_HF][1] > 0 ;// y_vector.length > y_src.length; // twice longer
//samples_pointers[SAMPLES_Y_HF][1]
final int index_combo = num_scenes;
final int index_weighted = num_scenes+1;
final int ext_scenes = index_weighted+1; // number of scenes and averages
......@@ -3559,11 +3708,7 @@ public class VegetationLMA {
extra, // boolean extra,
gap);
int num_img_cols = 5; // 4;
// int num_first_row_cols = 4;
int woi_width= woi_veg.width * num_img_cols + (num_img_cols-1) * gap;
// int woi_width3=woi.width*3 + 2 * gap;
// int woi_width4=woi_veg.width*4 + 3 * gap;
// int woi_width5=woi_veg.width*5 + 4 * gap;
int height = indices.length / woi_width;
int num_extra_rows = extra ? (2 *woi_veg.height + 3 * gap) : 0;
int extra_start_row = height - num_extra_rows;
......@@ -3740,6 +3885,10 @@ public class VegetationLMA {
imp.setProperty("TERR_PULL0", ""+terr_pull0);
imp.setProperty("VEGET_PULL0", ""+veget_pull0);
imp.setProperty("ELEVATION_PULL0", ""+elevation_pull0);
imp.setProperty("ELEV_ALPHA_EN", ""+elev_alpha_en);
imp.setProperty("ELEV_ALPHA", ""+elev_alpha);
imp.setProperty("ELEV_ALPHA_PWR", ""+elev_alpha_pwr);
imp.setProperty("ELEV_LOW_VEGET", ""+low_veget);
imp.setProperty("SCENES_PULL0", ""+scenes_pull0);
imp.setProperty("SCALE_SCENES_PULL", ""+scale_scenes_pull);
imp.setProperty("BOOST_PARALLAX", ""+boost_parallax);
......@@ -3902,6 +4051,10 @@ public class VegetationLMA {
terr_pull0 = Double.parseDouble((String) imp_pars.getProperty("TERR_PULL0"));
veget_pull0 = Double.parseDouble((String) imp_pars.getProperty("VEGET_PULL0"));
elevation_pull0 = Double.parseDouble((String) imp_pars.getProperty("ELEVATION_PULL0"));
if (imp_pars.getProperty("ELEV_ALPHA_EN") != null) elev_alpha_en = Boolean.parseBoolean((String) imp_pars.getProperty("ELEV_ALPHA_EN"));
if (imp_pars.getProperty("ELEV_ALPHA") != null) elev_alpha = Double.parseDouble((String) imp_pars.getProperty("ELEV_ALPHA"));
if (imp_pars.getProperty("ELEV_ALPHA_PWR") != null) elev_alpha_pwr =Double.parseDouble((String) imp_pars.getProperty("ELEV_ALPHA_PWR"));
if (imp_pars.getProperty("ELEV_LOW_VEGET") != null) low_veget = Double.parseDouble((String) imp_pars.getProperty("ELEV_LOW_VEGET"));
scenes_pull0 = Double.parseDouble((String) imp_pars.getProperty("SCENES_PULL0"));
scale_scenes_pull = Double.parseDouble((String) imp_pars.getProperty("SCALE_SCENES_PULL"));
boost_parallax = Double.parseDouble((String) imp_pars.getProperty("BOOST_PARALLAX"));
......@@ -3944,11 +4097,19 @@ public class VegetationLMA {
par_index[TVAO_ELEVATION] = new int [num_pars[TVAO_ELEVATION]];
par_index[TVAO_SCENE_OFFSET] = new int [num_pars[TVAO_SCENE_OFFSET]];
*/
samples_pointers = new int [SAMPLES_SIZE][3];
// samples_pointers = new int [SAMPLES_SIZE][3];
int [][] samples_pointers_tmp = new int [SAMPLES_SIZE][3];
update_samples_pointers: {
for (int nsp = 0; nsp < SAMPLES_SIZE; nsp++) {
for (int i = 0; i < samples_pointers[nsp].length; i++) {
samples_pointers[nsp][i] = Integer.parseInt((String) imp_pars.getProperty("SAMPLES_POINTERS_"+nsp+"_"+i));
for (int i = 0; i < samples_pointers_tmp[nsp].length; i++) {
if (imp_pars.getProperty("SAMPLES_POINTERS_"+nsp+"_"+i) == null) {
System.out.println("restoreParametersFile(): Incompatible samples_pointers[][], will not update");
break update_samples_pointers;
}
samples_pointers_tmp[nsp][i] = Integer.parseInt((String) imp_pars.getProperty("SAMPLES_POINTERS_"+nsp+"_"+i));
}
}
samples_pointers = samples_pointers_tmp;
}
// samples_pointers[SAMPLES_TOTAL][0] = total number of parameters
int num_pars = 0;
......@@ -4642,14 +4803,19 @@ public class VegetationLMA {
samples_pointers[SAMPLES_VEGETATION_LPF][1] = num_pars[TVAO_VEGETATION];
samples_pointers[SAMPLES_VEGETATION_LPF][2] = ind_pars[TVAO_VEGETATION];
}
if (fits[TVAO_ELEVATION] && (veget_pull0 >= 0)) {
if (fits[TVAO_ELEVATION] && (elevation_pull0 >= 0)) {
samples_pointers[SAMPLES_ELEVATION_PULL][1] = num_pars[TVAO_ELEVATION];
samples_pointers[SAMPLES_ELEVATION_PULL][2] = ind_pars[TVAO_ELEVATION];
}
if (fits[TVAO_ELEVATION] && (veget_lpf >= 0)) {
if (fits[TVAO_ELEVATION] && (elevation_lpf >= 0)) {
samples_pointers[SAMPLES_ELEVATION_LPF][1] = num_pars[TVAO_ELEVATION];
samples_pointers[SAMPLES_ELEVATION_LPF][2] = ind_pars[TVAO_ELEVATION];
}
if (fits[TVAO_ELEVATION] && fits[TVAO_ALPHA] && (elev_alpha_en)) {
samples_pointers[SAMPLES_ELEVATION_ALPHA][1] = num_pars[TVAO_ELEVATION];
samples_pointers[SAMPLES_ELEVATION_ALPHA][2] = ind_pars[TVAO_ELEVATION];
}
for (int i = 1; i < samples_pointers.length; i++) {
samples_pointers[i][0] = samples_pointers[i-1][0] + samples_pointers[i-1][1];
}
......@@ -5015,7 +5181,7 @@ public class VegetationLMA {
int nscene = y_src[ny][YSRC_SCENE];
int indx = y_src[ny][YSRC_FINDEX];
int windx = getWindexFromFindex(indx);
double d =y_vector[ny] * scene_weights[nscene];
double d =y_vector[ny] * scene_weights[nscene] * terrain_correction;
if (Double.isNaN(d)) {
System.out.println("y_vector["+ny+"]*scene_weights["+nscene+"]=NaN");
}
......
......@@ -1277,7 +1277,7 @@ public class VegetationModel {
public static void processVegetationLMA(
public static void processVegetation(
CLTParameters clt_parameters,
boolean combine_segments)
{
......@@ -1296,7 +1296,7 @@ public class VegetationModel {
VegetationModel vegetationModel = new VegetationModel(
model_directory, // String dir,
model_state_file); // String title)
vegetationModel.testVegetationLMA(
vegetationModel.processVegetationLMA(
combine_segments, // boolean combine_segments,
clt_parameters, // CLTParameters clt_parameters,
-1); // int debugLevel) {
......@@ -1369,7 +1369,7 @@ public class VegetationModel {
}
}
public void testVegetationLMA(
public void processVegetationLMA(
boolean combine_segments,
CLTParameters clt_parameters,
int debugLevel) {
......@@ -1418,7 +1418,13 @@ public class VegetationModel {
// double terr_difference = clt_parameters.imp.terr_difference; // Pull vegetation to be this warmer
// double terr_pull_cold = clt_parameters.imp.terr_pull_cold; // pull vegetations to warm, terrain to cold
double elevation_radius = clt_parameters.imp.terr_elevation_radius; // Radius of elevation/vegetation influence
double alpha_initial_contrast = clt_parameters.imp.terr_alpha_contrast; // initial alpha contrast (>=1.0)
// double alpha_initial_contrast = clt_parameters.imp.terr_alpha_contrast; // initial alpha contrast (>=1.0)
double alpha_sigma = clt_parameters.imp.terr_alpha_sigma; // 8.0; // Initial alpha: Gaussian blur sigma to find local average for vegetation temperature.
double alpha_init_min= clt_parameters.imp.terr_alpha_init_min; // 0.7; // Initial alpha: fraction for transparent
double alpha_init_max= clt_parameters.imp.terr_alpha_init_max; // 0.9; // Initial alpha: fraction for opaque
double alpha_init_offs= clt_parameters.imp.terr_alpha_init_offs; // 0.01; // Initial alpha: opaque/transparent offset from 1.0/0.0
double default_alpha = clt_parameters.imp.terr_alpha_dflt; // 0.5; // 0.8;
double alpha_loss = clt_parameters.imp.terr_alpha_loss; //100.0; // 10.0; /// 100.0; // 10.0; // 10000.0; // 1000.0; // 100.; // 10.0; // quadratic loss when alpha reaches -1.0 or 2.0
double alpha_offset = clt_parameters.imp.terr_alpha_offset; // 0.0; // 0.02; // 0.03; // if >0, start losses above 0.0 and below 1.0;
......@@ -1436,6 +1442,10 @@ public class VegetationModel {
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;
boolean elev_alpha_en= clt_parameters.imp.terr_elev_alpha_en; // false;// Enable loss for low vegetation with high opacity
double elev_alpha = clt_parameters.imp.terr_elev_alpha; // 1.0; // multiply alpha by under-low elevation for loss
double elev_alpha_pwr = clt_parameters.imp.terr_elev_alpha_pwr; // 1.0; // multiply alpha by under-low elevation for loss
double low_veget = clt_parameters.imp.terr_low_veget; // 2.0; // (pix) Elevation considered low (lower loss for high alpha)
double scenes_pull0 = clt_parameters.imp.terr_scenes_pull0; // 1.0
// LMA parameters
......@@ -1488,29 +1498,11 @@ public class VegetationModel {
double transparency_frac = clt_parameters.imp.terr_recalc_frac ; // 1.0; // increase weight for far pixels (double if scale differece == this)
double transparency_dist = clt_parameters.imp.terr_recalc_dist ; // 0.05; // weight of opaque tiles
boolean recalc_average = clt_parameters.imp.terr_recalc_average ; //false; // apply transparency to average mismatch
//clt_parameters.imp.; //
boolean restore_mode = false;
boolean save_par_files = true; // false;
// boolean diff_mode = true;
// String segments_dir = "/media/elphel/SSD3-4GB/lwir16-proc/berdich3/debug/vegetation/segments_new/";
String segments_dir = getSegmentsDir(segments_sub);
// boolean next_run = false;
boolean read_pars = false; // true; /// false; /// true; // false; // true;
// combine parameters
// debug feature to read to continue - needs to be cleaned up/replaced
String parameters_path = "/media/elphel/SSD3-4GB/lwir16-proc/berdich3/debug/vegetation/essential/parameters_vector_data_x143-y317-w35-h35-al100.0-alo0.0-alp10.0-alin-tl0.2-vl0.01-tp0.01-vp0.01-bp5.0-um1.0_0.8.tiff";
......@@ -1552,7 +1544,6 @@ public class VegetationModel {
titles_laplacian, // String [] titles, // all slices*frames titles or just slice titles or null
new String[] {"source","laplacian"}, // String [] frame_titles, // frame titles or null
true); // boolean show)
}
}
......@@ -1933,21 +1924,21 @@ public class VegetationModel {
} // if ((elevations == null) || (scale_dirs == null)){
// directions should not be averaged over scenes as the flight direction may change
// if (debugLevel < 1000) {
// return; //
// }
// initial_transparent = initial_split;
// initial_opaque = 1.0 - initial_split;
/*
VegetationLMA vegetationLMA = new VegetationLMA (
this,
alpha_initial_contrast); // double alpha_initial_contrast)
alpha_initial_contrast, // double alpha_initial_contrast)
debugLevel); // int debugLevel)
*/
VegetationLMA vegetationLMA = new VegetationLMA (
this,
alpha_init_offs, // 0.01; // double alpha_offs,
alpha_init_min, // 0.7; // double alpha_min,
alpha_init_max, // 0.9; // double alpha_max,
alpha_sigma, // 8.0; // double alpha_sigma,
debugLevel); // int debugLevel)
if (debugLevel > -2) {
double [][] dbg_img = {
vegetationLMA.tvao[VegetationLMA.TVAO_TERRAIN],
......@@ -2030,6 +2021,10 @@ public class VegetationModel {
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
elev_alpha_en, // final boolean elev_alpha_en, // false; // Enable loss for low vegetation with high opacity
elev_alpha, // final double elev_alpha, // 1.0; // multiply alpha by under-low elevation for loss
elev_alpha_pwr, // final double elev_alpha_pwr, // 2.0; // raise alpha to this power (when alpha > 0)
low_veget, // final double low_veget, // 2.0; // (pix) Elevation considered low (lower loss for high alpha)
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