Commit 214f7e87 authored by Andrey Filippov's avatar Andrey Filippov

Working snapshot before implementing pull to average terrain temperature

parent 7739a5cb
......@@ -474,12 +474,6 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
public ImagePlus CORRELATE_IMP = null;
public TensorflowInferModel TENSORFLOW_INFER_MODEL = null;
public class SyncCommand {
public boolean isRunning = false;
public AtomicInteger stopRequested = new AtomicInteger(0); // 0 - not requested, 1 - ASAP, 2 - gracefully
public String buttonLabel = "";
}
@Override
public void run(String arg) {
String options = Macro.getOptions();
......@@ -5803,10 +5797,12 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
OrangeTest.processMerged();
} else if (label.equals("Vegetation LMA")) {
VegetationModel.processVegetation(
SYNC_COMMAND, // // SyncCommand SYNC_COMMAND,
CLT_PARAMETERS, //CLTParameters clt_parameters,
false); //boolean combine_segments);
} else if (label.equals("Combine LMA Segments")) {
VegetationModel.processVegetation(
SYNC_COMMAND, // // SyncCommand SYNC_COMMAND,
CLT_PARAMETERS, //CLTParameters clt_parameters,
true); //boolean combine_segments);
}
......
package com.elphel.imagej.correction;
import java.util.concurrent.atomic.AtomicInteger;
public class SyncCommand {
public boolean isRunning = false;
public AtomicInteger stopRequested = new AtomicInteger(0); // 0 - not requested, 1 - ASAP, 2 - gracefully
public String buttonLabel = "";
}
\ No newline at end of file
......@@ -2486,7 +2486,7 @@ public class Interscene {
int last_processed_scene = -2; // none
/*
* There is still a problem with a large mismatch at start position for far off-reference scenes,
* especiall those that were not refined after inversion - reversing order of earlier processed "later"
* especially those that were not refined after inversion - reversing order of earlier processed "later"
* half (after the reference in the center) earlier processed as the bottom half of the other sub-sequence.
*
* For mitigation we'll use that both half-sequences start from the center with small mismatches. The
......@@ -3006,7 +3006,7 @@ public class Interscene {
if (ref_disparity == null) {
ref_disparity = quadCLTs[ref_index].getDLS()[use_lma_dsi?1:0];
}
smooth_disparity=true;
if (smooth_disparity) {
double [] dbg_disparity = (debugLevel > 2) ? ref_disparity.clone() : null;
boolean [] dbg_reliable = ((dbg_disparity != null) && (reliable_ref != null)) ? reliable_ref.clone(): null;
......
......@@ -732,6 +732,7 @@ min_str_neib_fpn 0.35
public String terr_par_dir = ""; // directory path to intermediate parameters
public String terr_par_file = ""; // file name of the intermediate parameters
public boolean terr_par_restore = false; // restore parameters from file
public int terr_step_restore = 2; // If restore, start with step after restored
// terrain/vegetation parameters
public boolean terr_um_en = true;
public double terr_um_sigma = 1.0;
......@@ -756,7 +757,10 @@ min_str_neib_fpn 0.35
public boolean terr_fit_alpha = true; // adjust vegetation alpha pixels
public boolean terr_fit_scenes = true; // adjust scene offsets (start from 0 always?)
public boolean terr_fit_elevations = false; // adjust elevation pixels (not yet implemented)
public boolean [] terr_fit_disable = new boolean [VegetationLMA.TVAO_TYPES];
// public boolean [][] terr_fits = {{true},{true},{true},{false},{true}};
// public boolean [] terr_fit_disable = new boolean [VegetationLMA.TVAO_TYPES];
// public boolean [][] terr_fits_disable = new boolean [VegetationLMA.TVAO_TYPES][1];
public boolean [][] terr_fits_disable = {{false},{false},{false},{true,false,true},{false}};
public double terr_max_warp = 1.8;
public int terr_max_elevation = 22; // maximal offset to consider when looking for vegetation influence
......@@ -793,6 +797,7 @@ min_str_neib_fpn 0.35
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_loss_lin = 0.0;
public double terr_alpha_offset = 0.1;
public double terr_alpha_min_veg = -1; // old version 0.5; // Minimal vegetation alpha. If (alpha-alpha_offset)/(1-2*alpha_offset) < alpha_min_veg, pull down to lpha_offset
......@@ -806,11 +811,12 @@ min_str_neib_fpn 0.35
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
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_veget_lpf = 10.0; // pull vegetation to average of 4 neighbors
public double terr_elev_lpf = 50.0; // pull elevation to average of 4 neighbors
public double terr_terr_pull0 = 0.1; // pull terrain to initial (pre-adjustment) values
public double terr_terr_pull_up= 0.25; // pull terrain to initial when it is colder
public double terr_veget_pull0 = 5.0; // pull vegetation initial (pre-adjustment) values
public double terr_elev_pull0 = 1.0; // 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)
......@@ -821,21 +827,27 @@ min_str_neib_fpn 0.35
public double terr_boost_parallax = 3.0; //
public double terr_max_parallax = 10.0; // parallax limit when evaluating boost parallax
public double terr_hifreq_weight = 10.0; // 22.5; // 0 - do not use high-freq. Relative weight of laplacian components differfences to the DC ones
public double terr_terr_corr = 1.0; // relative weight of average mismatch between images and model (terrain corrections)
public double terr_reg_weights = 0.25; // fraction of the total weight used for regularization
public double terr_terr_corr = 1.0; // (~>30- unstable) relative weight of average mismatch between images and model (terrain corrections)
public double terr_reg_weights = 0.2; // fraction of the total weight used for regularization
public double terr_lambda = 5.0; //
public double terr_lambda_scale_good = 0.5;
public double terr_lambda_scale_bad = 8.0;
public double terr_lambda_max = 1000;
public double terr_rms_diff = 1e-8; // 0.0001; virtually forever
public int terr_num_iter = 25; // 100;
public int terr_last_series = -1; // Last LMA adjustment series (<0 - to the terr_num_iters.length -1)
public int [] terr_num_iters = {30}; //sequence on numbers of iterations
// second run
public boolean terr_recalc_weights = false; // recalculate weight depending on terrain visibility
public boolean [] terr_recalc_weights = {false,false,true}; // recalculate weight depending on terrain visibility
public double terr_recalc_opaque = 0.9; // above is opaque
public double terr_recalc_pedestal = 0.05; // weight of opaque tiles
public double terr_recalc_pedestal = 0.05; // weight of opaque tiles - apply after normalization
public double terr_recalc_frac = 0.5; // discard transparency below this fraction of the maximal one
public double terr_recalc_dist = 1.0; // increase weight for far pixels (double if scale differece == this)
public double terr_recalc_dist = 0.0; // increase weight for far pixels (double if scale differece == this)
public double terr_recalc_pwr = 1.0; // raise transparency to this power
public double terr_recalc_gb = 1.5; // blur transparency-based confidence
public double terr_recalc_boost = 3.0; // maximal weight boost for texture with low visibility
public boolean terr_recalc_average = false; // apply transparency to average mismatch
......@@ -849,13 +861,16 @@ min_str_neib_fpn 0.35
public double terr_boost_render = 3.0; // boost parallax during render
public double terr_max_render = 10.0; // maximal parallax during render
public int terr_num_exaggerate = 3; // generate exagerrated rendering
public int terr_num_exaggerate = 3; // generate exaggerated rendering
// Experimental reconstruction
public double terr_threshold_terrain = 0.05;
public double terr_min_max_terrain= 0.1;
public double terr_min_terrain = 0.001;
public double terr_min_vegetation = 0.5;
public int terr_debug = 0;
public boolean terr_debug_improved = true; // Save debug data if LMA step improved
public boolean terr_debug_worsened = true; // Save debug data if LMA step improved
......@@ -2043,6 +2058,7 @@ min_str_neib_fpn 0.35
gd.addStringField ("Restore directory", terr_par_dir, 120, "Directory to resore initial parameters from.");
gd.addStringField ("Restore file", terr_par_file, 120, "Filename to resore initial parameters from.");
gd.addCheckbox ("Restore parameters", terr_par_restore, "Restore initial parameters from file before running LMA.");
gd.addNumericField("Restore step", terr_step_restore, 0,3,"","Go to LMA sequence step after restore.");
gd.addMessage ("Unsharp mask filter of the input data (currently not used as both DC and HF fitting are implemented simultaneously).");
gd.addCheckbox ("Enable UM", terr_um_en, "Enable unsharp mask filter.");
......@@ -2074,8 +2090,10 @@ min_str_neib_fpn 0.35
gd.addCheckbox ("Adjust alpha", terr_fit_alpha, "Adjust vegetation alpha pixels.");
gd.addCheckbox ("Adjust scene offsets", terr_fit_scenes, "Adjust scene offsets (start from 0 always?).");
gd.addCheckbox ("Adjust elevation", terr_fit_elevations,"Adjust elevation pixels.");
for (int i = 0; i < terr_fit_disable.length; i++) {
gd.addCheckbox ("Skip "+VegetationLMA.TVAO_NAMES[i], terr_fit_disable[i],"Skip adjustment of "+VegetationLMA.TVAO_NAMES[i]+".");
for (int i = 0; i < terr_fits_disable.length; i++) {
gd.addStringField ("Skip "+VegetationLMA.TVAO_NAMES[i], booleansToString(terr_fits_disable[i],2), 40,
"Skip adjustment of "+VegetationLMA.TVAO_NAMES[i]+". Use comma/space separated list of true/false, 1/0 or +/-." );
}
gd.addNumericField("Maximal warp", terr_max_warp, 5,7,"pix", "(1.8) Do not use scenes where distance between vegetation projection exceeds this.");
gd.addNumericField("Min elevation/offset", terr_max_elevation, 0,3,"pix","Maximal offset to consider when looking for vegetation influence.");
......@@ -2097,12 +2115,13 @@ 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 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 loss linear", terr_alpha_loss_lin, 5,7,"", "Alpha linear growing loss for when out of [0,1] range and below minimal vegetation alpha.");
gd.addNumericField("Alpha offset", terr_alpha_offset, 5,7,"", "Start alpha losses above 0.0 and below 1.0 by this value.");
gd.addNumericField("Minimal vegetation alpha", terr_alpha_min_veg, 5,7,"","Minimal vegetation alpha. If (alpha-alpha_offset)/(1-2*alpha_offset) < alpha_min_veg, pull down to lpha_offset.");
......@@ -2119,6 +2138,7 @@ min_str_neib_fpn 0.35
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", terr_terr_pull0, 5,7,"", "Terrain pixels pull to initial (pre-adjustment) values.");
gd.addNumericField("Terrain pull up", terr_terr_pull_up, 5,7,"", "Terrain pixels pull to initial (pre-adjustment) values when it is colder than initial.");
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.");
......@@ -2141,14 +2161,22 @@ min_str_neib_fpn 0.35
gd.addNumericField("Lambda scale on bad", terr_lambda_scale_bad, 5,7,"","Scale lambda if RMSE worsened.");
gd.addNumericField("Lambda max to fail", terr_lambda_max, 5,7,"", "Fail if lambda gets larger than that.");
gd.addNumericField("RMSE difference", terr_rms_diff, 10,12,"", "Exit if RMSE improvement is lower.");
gd.addNumericField("Maximal iterations", terr_num_iter, 0,3,"", "Maximal number of LMA iterations.");
gd.addNumericField("Last LMA series", terr_last_series, 0,3,"","Last LMA series, -1 - to last available in the sequence below.");
gd.addStringField ("Maximal iterations", intsToString(terr_num_iters), 40, "Maximal number of LMA iterations per mode, 1 or multiple values.");
gd.addMessage ("Second LMA run");
gd.addCheckbox ("Recalculate weighths", terr_recalc_weights, "Recalculate weights depending on terrain visibility.");
gd.addStringField ("Recalculate weighths", booleansToString(terr_recalc_weights,2), 40,
"Recalculate weights depending on terrain visibility. Use comma/space separated list of true/false, 1/0 or +/-." );
gd.addNumericField("Opaque alpha", terr_recalc_opaque, 5,7,"", "Alpha above his means opaque.");
gd.addNumericField("Opaque weight", terr_recalc_pedestal, 5,7,"","Relative weight of opaque tiles.");
gd.addNumericField("Transparency fraction",terr_recalc_frac, 5,7,"","Discard transparency below this fraction of the maximal one.");
gd.addNumericField("Transparency distance",terr_recalc_dist, 5,7,"","Increase weight for far pixels (double if scale differece == this).");
gd.addNumericField("Transparency fraction",terr_recalc_frac, 5,7,"", "Discard transparency below this fraction of the maximal one.");
gd.addNumericField("Transparency distance",terr_recalc_dist, 5,7,"", "Increase weight for far pixels (double if scale differece == this).");
gd.addNumericField("Transparency power", terr_recalc_pwr, 5,7,"", "Raise transparency to this power when calculating weight.");
gd.addNumericField("Confidence blur", terr_recalc_gb, 5,7,"pix", "Blur transparency-based confidence.");
gd.addNumericField("Maximal boost", terr_recalc_boost, 5,7,"", "Maximal boost while increasing low-confidence pixel weights.");
gd.addCheckbox ("Transparency average", terr_recalc_average, "Apply transparency to average mismatch.");
......@@ -2168,6 +2196,9 @@ min_str_neib_fpn 0.35
gd.addNumericField("Min max terrain", terr_min_max_terrain, 5,7,"", ".");
gd.addNumericField("Minimal terrain", terr_min_terrain, 5,7,"", ".");
gd.addNumericField("Minimal vegetation", terr_min_vegetation, 5,7,"", ".");
gd.addNumericField("LMA debug level", terr_debug, 0,3,"", ".");
gd.addCheckbox ("Debug improved", terr_debug_improved, "Save debug image after successful LMA step.");
gd.addCheckbox ("Debug worsened", terr_debug_worsened, "Save debug image after unsuccessful LMA step.");
}
......@@ -2797,6 +2828,7 @@ min_str_neib_fpn 0.35
terr_par_dir = gd.getNextString();
terr_par_file = gd.getNextString();
terr_par_restore = gd.getNextBoolean(); // boolean
terr_step_restore = (int) gd.getNextNumber(); // int
terr_um_en = gd.getNextBoolean(); // boolean
terr_um_sigma = gd.getNextNumber(); // double
......@@ -2823,10 +2855,9 @@ min_str_neib_fpn 0.35
terr_fit_alpha = gd.getNextBoolean();// boolean
terr_fit_scenes = gd.getNextBoolean();// boolean
terr_fit_elevations = gd.getNextBoolean();// boolean
for (int i = 0; i < terr_fit_disable.length; i++) {
terr_fit_disable[i] = gd.getNextBoolean();// boolean
for (int i = 0; i < terr_fits_disable.length; i++) {
terr_fits_disable[i] = StringToBooleans(gd.getNextString());// booleans
}
terr_max_warp = gd.getNextNumber();// double
terr_max_elevation = (int) gd.getNextNumber();// int
......@@ -2850,6 +2881,7 @@ min_str_neib_fpn 0.35
terr_alpha_init_offs = gd.getNextNumber();// double
terr_alpha_loss = gd.getNextNumber();// double
terr_alpha_loss_lin = gd.getNextNumber();// double
terr_alpha_offset = gd.getNextNumber();// double
terr_alpha_min_veg = gd.getNextNumber();// double
terr_alpha_lpf = gd.getNextNumber();// double
......@@ -2865,6 +2897,7 @@ 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_terr_pull_up = gd.getNextNumber();// double
terr_veget_pull0 = gd.getNextNumber();// double
terr_elev_pull0 = gd.getNextNumber();// double
terr_elev_alpha_en = gd.getNextBoolean();// boolean
......@@ -2882,13 +2915,16 @@ min_str_neib_fpn 0.35
terr_lambda_scale_bad = gd.getNextNumber();// double
terr_lambda_max = gd.getNextNumber();// double
terr_rms_diff = gd.getNextNumber();// double
terr_num_iter = (int) gd.getNextNumber();// int
terr_recalc_weights = gd.getNextBoolean();// boolean
terr_last_series = (int) gd.getNextNumber();// int
terr_num_iters = StringToInts(gd.getNextString());
terr_recalc_weights = StringToBooleans(gd.getNextString());// booleans
terr_recalc_opaque = gd.getNextNumber(); // double
terr_recalc_pedestal = gd.getNextNumber(); // double
terr_recalc_frac = gd.getNextNumber(); // double
terr_recalc_dist = gd.getNextNumber(); // double
terr_recalc_pwr = gd.getNextNumber(); // double
terr_recalc_gb = gd.getNextNumber(); // double
terr_recalc_boost = gd.getNextNumber(); // double
terr_recalc_average = gd.getNextBoolean();// boolean
terr_border_width = (int) gd.getNextNumber(); // int
......@@ -2905,6 +2941,9 @@ min_str_neib_fpn 0.35
terr_min_max_terrain = gd.getNextNumber();// double
terr_min_terrain = gd.getNextNumber();// double
terr_min_vegetation = gd.getNextNumber();// double
terr_debug = (int) gd.getNextNumber(); // int
terr_debug_improved = gd.getNextBoolean();// boolean
terr_debug_worsened = gd.getNextBoolean();// boolean
// end of vegetation
if (this.weight_zero_neibs > 1.0) this.weight_zero_neibs = 1.0;
......@@ -3506,6 +3545,7 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"terr_par_dir", terr_par_dir+""); // String
properties.setProperty(prefix+"terr_par_file", terr_par_file+""); // String
properties.setProperty(prefix+"terr_par_restore", terr_par_restore+""); // boolean
properties.setProperty(prefix+"terr_step_restore", terr_step_restore+""); // int
properties.setProperty(prefix+"terr_um_en", terr_um_en+""); // boolean
properties.setProperty(prefix+"terr_um_sigma", terr_um_sigma+""); // double
......@@ -3534,9 +3574,9 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"terr_fit_alpha", terr_fit_alpha+""); // boolean
properties.setProperty(prefix+"terr_fit_scenes", terr_fit_scenes+""); // boolean
properties.setProperty(prefix+"terr_fit_elevations", terr_fit_elevations+""); // boolean
for (int i = 0; i < terr_fit_disable.length; i++) {
String prop_name = prefix+"terr_fit_disable_"+VegetationLMA.TVAO_NAMES[i];
properties.setProperty(prop_name, terr_fit_disable[i]+""); // boolean
for (int i = 0; i < terr_fits_disable.length; i++) {
String prop_name = prefix+"terr_fits_disable_"+VegetationLMA.TVAO_NAMES[i];
properties.setProperty(prop_name, booleansToString(terr_fits_disable[i],2)); // boolean
}
properties.setProperty(prefix+"terr_max_warp", terr_max_warp+""); // double
properties.setProperty(prefix+"terr_max_elevation", terr_max_elevation+""); // int
......@@ -3561,6 +3601,7 @@ min_str_neib_fpn 0.35
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_loss_lin", terr_alpha_loss_lin+""); // double
properties.setProperty(prefix+"terr_alpha_offset", terr_alpha_offset+""); // double
properties.setProperty(prefix+"terr_alpha_min_veg", terr_alpha_min_veg+""); // double
properties.setProperty(prefix+"terr_alpha_lpf", terr_alpha_lpf+""); // double
......@@ -3574,6 +3615,7 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"terr_veget_lpf", terr_veget_lpf+""); // double
properties.setProperty(prefix+"terr_elev_lpf", terr_elev_lpf+""); // double
properties.setProperty(prefix+"terr_terr_pull0", terr_terr_pull0+""); // double
properties.setProperty(prefix+"terr_terr_pull_up", terr_terr_pull_up+""); // 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
......@@ -3592,13 +3634,16 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"terr_lambda_scale_bad", terr_lambda_scale_bad+""); // double
properties.setProperty(prefix+"terr_lambda_max", terr_lambda_max+""); // double
properties.setProperty(prefix+"terr_rms_diff", terr_rms_diff+""); // double
properties.setProperty(prefix+"terr_num_iter", terr_num_iter+""); // int
properties.setProperty(prefix+"terr_recalc_weights", terr_recalc_weights+""); // boolean
properties.setProperty(prefix+"terr_last_series", terr_last_series+""); // int
properties.setProperty(prefix+"terr_num_iters", intsToString(terr_num_iters)+""); // int []
properties.setProperty(prefix+"terr_recalc_weights", booleansToString(terr_recalc_weights,2)); // boolean
properties.setProperty(prefix+"terr_recalc_opaque", terr_recalc_opaque+""); // double
properties.setProperty(prefix+"terr_recalc_pedestal", terr_recalc_pedestal+""); // double
properties.setProperty(prefix+"terr_recalc_frac", terr_recalc_frac+""); // double
properties.setProperty(prefix+"terr_recalc_dist", terr_recalc_dist+""); // double
properties.setProperty(prefix+"terr_recalc_pwr", terr_recalc_pwr+""); // double
properties.setProperty(prefix+"terr_recalc_gb", terr_recalc_gb+""); // double
properties.setProperty(prefix+"terr_recalc_boost", terr_recalc_boost+""); // double
properties.setProperty(prefix+"terr_recalc_average", terr_recalc_average+""); // boolean
properties.setProperty(prefix+"terr_border_width", terr_border_width+""); // int
......@@ -3615,7 +3660,9 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"terr_min_max_terrain", terr_min_max_terrain+""); // double
properties.setProperty(prefix+"terr_min_terrain", terr_min_terrain+""); // double
properties.setProperty(prefix+"terr_min_vegetation", terr_min_vegetation+""); // double
properties.setProperty(prefix+"terr_debug", terr_debug+""); // int
properties.setProperty(prefix+"terr_debug_improved", terr_debug_improved+""); // boolean
properties.setProperty(prefix+"terr_debug_worsened", terr_debug_worsened+""); // boolean
// end of vegetation
}
......@@ -4239,6 +4286,7 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"terr_par_dir")!= null) terr_par_dir=(String) properties.getProperty(prefix+"terr_par_dir");
if (properties.getProperty(prefix+"terr_par_file")!= null) terr_par_file=(String) properties.getProperty(prefix+"terr_par_file");
if (properties.getProperty(prefix+"terr_par_restore")!= null) terr_par_restore=Boolean.parseBoolean(properties.getProperty(prefix+"terr_par_restore"));
if (properties.getProperty(prefix+"terr_step_restore")!= null) terr_step_restore=Integer.parseInt(properties.getProperty(prefix+"terr_step_restore"));
if (properties.getProperty(prefix+"terr_um_en")!= null) terr_um_en=Boolean.parseBoolean(properties.getProperty(prefix+"terr_um_en"));
if (properties.getProperty(prefix+"terr_um_sigma")!= null) terr_um_sigma=Double.parseDouble(properties.getProperty(prefix+"terr_um_sigma"));
......@@ -4262,9 +4310,11 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"terr_fit_alpha")!= null) terr_fit_alpha=Boolean.parseBoolean(properties.getProperty(prefix+"terr_fit_alpha"));
if (properties.getProperty(prefix+"terr_fit_scenes")!= null) terr_fit_scenes=Boolean.parseBoolean(properties.getProperty(prefix+"terr_fit_scenes"));
if (properties.getProperty(prefix+"terr_fit_elevations")!= null) terr_fit_elevations=Boolean.parseBoolean(properties.getProperty(prefix+"terr_fit_elevations"));
for (int i = 0; i < terr_fit_disable.length; i++) {
String prop_name = prefix+"terr_fit_disable_"+VegetationLMA.TVAO_NAMES[i];
if (properties.getProperty(prop_name)!= null) terr_fit_disable[i]=Boolean.parseBoolean(properties.getProperty(prop_name));
for (int i = 0; i < terr_fits_disable.length; i++) {
String prop_name_old = prefix+"terr_fit_disable_"+VegetationLMA.TVAO_NAMES[i];
if (properties.getProperty(prop_name_old)!=null) terr_fits_disable[i]= StringToBooleans(properties.getProperty(prop_name_old));// booleans
String prop_name = prefix+"terr_fits_disable_"+VegetationLMA.TVAO_NAMES[i];
if (properties.getProperty(prop_name)!=null) terr_fits_disable[i]= StringToBooleans(properties.getProperty(prop_name));// booleans
}
if (properties.getProperty(prefix+"terr_max_warp")!= null) terr_max_warp=Double.parseDouble(properties.getProperty(prefix+"terr_max_warp"));
if (properties.getProperty(prefix+"terr_max_elevation")!= null) terr_max_elevation=Integer.parseInt(properties.getProperty(prefix+"terr_max_elevation"));
......@@ -4289,6 +4339,7 @@ min_str_neib_fpn 0.35
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_loss_lin")!= null) terr_alpha_loss_lin=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_loss_lin"));
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_min_veg")!= null) terr_alpha_min_veg=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_min_veg"));
if (properties.getProperty(prefix+"terr_alpha_lpf")!= null) terr_alpha_lpf=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_lpf"));
......@@ -4303,6 +4354,7 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"terr_veget_lpf")!= null) terr_veget_lpf=Double.parseDouble(properties.getProperty(prefix+"terr_veget_lpf"));
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_terr_pull_up")!= null) terr_terr_pull_up=Double.parseDouble(properties.getProperty(prefix+"terr_terr_pull_up"));
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"));
......@@ -4321,13 +4373,21 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"terr_lambda_scale_bad")!= null) terr_lambda_scale_bad=Double.parseDouble(properties.getProperty(prefix+"terr_lambda_scale_bad"));
if (properties.getProperty(prefix+"terr_lambda_max")!= null) terr_lambda_max=Double.parseDouble(properties.getProperty(prefix+"terr_lambda_max"));
if (properties.getProperty(prefix+"terr_rms_diff")!= null) terr_rms_diff=Double.parseDouble(properties.getProperty(prefix+"terr_rms_diff"));
if (properties.getProperty(prefix+"terr_num_iter")!= null) terr_num_iter=Integer.parseInt(properties.getProperty(prefix+"terr_num_iter"));
if (properties.getProperty(prefix+"terr_last_series")!= null) terr_last_series=Integer.parseInt(properties.getProperty(prefix+"terr_last_series"));
if (properties.getProperty(prefix+"terr_num_iter")!= null) terr_num_iters=new int[] {Integer.parseInt(properties.getProperty(prefix+"terr_num_iter"))};
if (properties.getProperty(prefix+"terr_num_iters")!= null) terr_num_iters=StringToInts((String) properties.getProperty(prefix+"terr_num_iters"));
if (properties.getProperty(prefix+"terr_recalc_weights")!= null) {
terr_recalc_weights= StringToBooleans(properties.getProperty(prefix+"terr_recalc_weights"));// booleans
}
if (properties.getProperty(prefix+"terr_recalc_weights")!= null) terr_recalc_weights=Boolean.parseBoolean(properties.getProperty(prefix+"terr_recalc_weights"));
if (properties.getProperty(prefix+"terr_recalc_opaque")!= null) terr_recalc_opaque=Double.parseDouble(properties.getProperty(prefix+"terr_recalc_opaque"));
if (properties.getProperty(prefix+"terr_recalc_pedestal")!= null) terr_recalc_pedestal=Double.parseDouble(properties.getProperty(prefix+"terr_recalc_pedestal"));
if (properties.getProperty(prefix+"terr_recalc_frac")!= null) terr_recalc_frac=Double.parseDouble(properties.getProperty(prefix+"terr_recalc_frac"));
if (properties.getProperty(prefix+"terr_recalc_dist")!= null) terr_recalc_dist=Double.parseDouble(properties.getProperty(prefix+"terr_recalc_dist"));
if (properties.getProperty(prefix+"terr_recalc_pwr")!= null) terr_recalc_pwr=Double.parseDouble(properties.getProperty(prefix+"terr_recalc_pwr"));
if (properties.getProperty(prefix+"terr_recalc_gb")!= null) terr_recalc_gb=Double.parseDouble(properties.getProperty(prefix+"terr_recalc_gb"));
if (properties.getProperty(prefix+"terr_recalc_boost")!= null) terr_recalc_boost=Double.parseDouble(properties.getProperty(prefix+"terr_recalc_boost"));
if (properties.getProperty(prefix+"terr_recalc_average")!= null) terr_recalc_average=Boolean.parseBoolean(properties.getProperty(prefix+"terr_recalc_average"));
if (properties.getProperty(prefix+"terr_border_width")!= null) terr_border_width=Integer.parseInt(properties.getProperty(prefix+"terr_border_width"));
......@@ -4344,7 +4404,9 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"terr_min_max_terrain")!= null) terr_min_max_terrain=Double.parseDouble(properties.getProperty(prefix+"terr_min_max_terrain"));
if (properties.getProperty(prefix+"terr_min_terrain")!= null) terr_min_terrain=Double.parseDouble(properties.getProperty(prefix+"terr_min_terrain"));
if (properties.getProperty(prefix+"terr_min_vegetation")!= null) terr_min_vegetation=Double.parseDouble(properties.getProperty(prefix+"terr_min_vegetation"));
if (properties.getProperty(prefix+"terr_debug")!= null) terr_debug=Integer.parseInt(properties.getProperty(prefix+"terr_debug"));
if (properties.getProperty(prefix+"terr_debug_improved")!= null) terr_debug_improved=Boolean.parseBoolean(properties.getProperty(prefix+"terr_debug_improved"));
if (properties.getProperty(prefix+"terr_debug_worsened")!= null) terr_debug_worsened=Boolean.parseBoolean(properties.getProperty(prefix+"terr_debug_worsened"));
// end of vegetation
}
......@@ -4935,6 +4997,7 @@ min_str_neib_fpn 0.35
imp.terr_par_dir = this. terr_par_dir;
imp.terr_par_file = this. terr_par_file;
imp.terr_par_restore = this.terr_par_restore;
imp.terr_step_restore = this.terr_step_restore;
imp.terr_um_en = this.terr_um_en;
imp.terr_um_sigma = this.terr_um_sigma;
......@@ -4960,7 +5023,9 @@ min_str_neib_fpn 0.35
imp.terr_fit_alpha = this.terr_fit_alpha;
imp.terr_fit_scenes = this.terr_fit_scenes;
imp.terr_fit_elevations = this.terr_fit_elevations;
imp.terr_fit_disable = this.terr_fit_disable.clone();
for (int i = 0; i < terr_fits_disable.length; i++) {
imp.terr_fits_disable[i] = this.terr_fits_disable[i].clone();
}
imp.terr_max_warp = this.terr_max_warp;
imp.terr_max_elevation = this.terr_max_elevation;
imp.terr_min_scenes = this.terr_min_scenes;
......@@ -4983,6 +5048,7 @@ min_str_neib_fpn 0.35
imp.terr_alpha_init_offs = this.terr_alpha_init_offs;
imp.terr_alpha_loss = this.terr_alpha_loss;
imp.terr_alpha_loss_lin = this.terr_alpha_loss_lin;
imp.terr_alpha_offset = this.terr_alpha_offset;
imp.terr_alpha_min_veg = this.terr_alpha_min_veg;
imp.terr_alpha_lpf = this.terr_alpha_lpf;
......@@ -4997,6 +5063,7 @@ min_str_neib_fpn 0.35
imp.terr_veget_lpf = this.terr_veget_lpf;
imp.terr_elev_lpf = this.terr_elev_lpf;
imp.terr_terr_pull0 = this.terr_terr_pull0;
imp.terr_terr_pull_up = this.terr_terr_pull_up;
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;
......@@ -5015,13 +5082,17 @@ min_str_neib_fpn 0.35
imp.terr_lambda_scale_bad = this.terr_lambda_scale_bad;
imp.terr_lambda_max = this.terr_lambda_max;
imp.terr_rms_diff = this.terr_rms_diff;
imp.terr_num_iter = this.terr_num_iter;
imp.terr_last_series = this.terr_last_series;
imp.terr_num_iters = this.terr_num_iters.clone();
imp.terr_recalc_weights = this.terr_recalc_weights;
imp.terr_recalc_weights = this.terr_recalc_weights.clone();
imp.terr_recalc_opaque = this.terr_recalc_opaque;
imp.terr_recalc_pedestal = this.terr_recalc_pedestal;
imp.terr_recalc_frac = this.terr_recalc_frac;
imp.terr_recalc_dist = this.terr_recalc_dist;
imp.terr_recalc_pwr = this.terr_recalc_pwr;
imp.terr_recalc_gb = this.terr_recalc_gb;
imp.terr_recalc_boost = this.terr_recalc_boost;
imp.terr_recalc_average = this.terr_recalc_average;
imp.terr_border_width = this.terr_border_width;
......@@ -5038,7 +5109,10 @@ min_str_neib_fpn 0.35
imp.terr_min_max_terrain = this.terr_min_max_terrain;
imp.terr_min_terrain = this.terr_min_terrain;
imp.terr_min_vegetation = this.terr_min_vegetation;
imp.terr_debug = this.terr_debug;
imp.terr_debug_improved = this.terr_debug_improved;
imp.terr_debug_worsened = this.terr_debug_worsened;
// end of vegetation
return imp;
......@@ -5135,6 +5209,45 @@ min_str_neib_fpn 0.35
}
}
public static String booleansToString (boolean [] data, int mode) { // 0 : true/false, 1: 0/1, 2: +/-
String s = "";
for (int i = 0; i < data.length; i++) {
switch (mode) {
case 0: s += data[i]; break;// true/false
case 1: s += data[i] ? 1:0; break;
case 2: s += data[i] ? "+":"-"; break;
default: s += data[i];// true/false
}
if (i < (data.length - 1)) {
s+= ", ";
}
}
return s;
}
public static boolean [] StringToBooleans(String s) {
return StringToBooleans(s, -1);
}
public static boolean [] StringToBooleans(String s, int len) {
StringTokenizer st = new StringTokenizer(s, " \t\n\r\f,");
if (st.countTokens() == 0) {
return null;
}
if (len <= 0) {
len = st.countTokens();
}
boolean [] data = new boolean [len];
int i = 0;
while (st.hasMoreTokens() && (i < len)) {
String tok = st.nextToken();
data[i++] = (tok.equals("true") || tok.equals("1") || tok.equals("+") || tok.equals("=true")); //"+true" - mitigating a bug
}
return data;
}
public static String rectangleToString(Rectangle r) {
return intsToString(new int []{r.x,r.y,r.width, r.height});
}
......@@ -5164,6 +5277,11 @@ min_str_neib_fpn 0.35
return s;
}
public static int [] StringToInts(String s) {
return StringToInts(s, -1);
}
public static int [] StringToInts(String s, int len) {
StringTokenizer st = new StringTokenizer(s, " \t\n\r\f,");
if (st.countTokens() == 0) {
......
......@@ -22,6 +22,7 @@ import com.elphel.imagej.tileprocessor.TileNeibs;
import com.elphel.imagej.tileprocessor.TileProcessor;
import Jama.Matrix;
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.Prefs;
......@@ -31,6 +32,8 @@ public class VegetationLMA {
public static final String PAR_EXT = ".par-tiff";
public static final String [] TVAO_NAMES = {"TERRAIN","VEGETATION","ALPHA","ELEVATION","SCENE_OFFSET"};
public static final String [] TVAO_names = {"terr_fit_terr", "terr_fit_veget", "terr_fit_alpha", "terr_fit_elevations", "terr_fit_scenes"};
public static final int TVAO_TERRAIN = 0;
public static final int TVAO_VEGETATION = 1;
public static final int TVAO_ALPHA = 2;
......@@ -146,7 +149,7 @@ public class VegetationLMA {
// @Deprecated
// private double terr_pull_cold = 0; // pull vegetations to warm, terrain to cold
private boolean [] fits_disable; //
boolean [] fits_disable; //
// Parameters saved/resored in a file
private final int num_scenes; // (+)
......@@ -155,9 +158,11 @@ public class VegetationLMA {
private double hifreq_weight; // (+) 22.5 0 - do not use high-freq. Relative weight of laplacian components
private double reg_weights; // (+) fraction of the total weight used for regularization
private boolean [] fits; // (+)
private double alpha_loss = 0; // (+) not used with cosine alpha
private double alpha_loss = 0; // (+) quadratic loss
private double alpha_loss_lin = 0.5; // (+) linear loss
private double alpha_offset = 0; // (+) if >0, start losses above 0.0 and below 1.0;
private double alpha_min_veg = 0.5; // (+) if (alpha-alpha_offset)/(1-2*alpha_offset) < alpha_min_veg, pull down to lpha_offset
private double alpha_lpf = 0; // (+)
private boolean alpha_piece_linear = true; // (+)
private double alpha_scale_avg = 1.0; // (+) 1.1; // scale average alpha (around 0.5) when pulling to it
......@@ -172,10 +177,16 @@ public class VegetationLMA {
private double terr_lpf = 0; // (+)
private double veget_lpf = 0; // (+)
private double elevation_lpf = 0; // (*)
private double elevation_lpf_transp = 1000; // lpf for transparent areas
private double elevation_lpf_pow = 2; // lpf for transparent areas power
private boolean [] lpf_fixed = {true, true,true, true, true}; // (*) using Laplacian to lpf parameters, pull to fixed ones too
// when unsharp mask is applied , pulling to 0 (when alpha is 0 (for vegetation) or 1.0 (for terrain) makes sense
private double terr_pull0 = 0; // (+) now - pull to filled terrain - terrain_average
private double terr_pull_up = 0; // Terrain pixels pull to initial (pre-adjustment) values when it is colder than initial
private double veget_pull0 = 0; // (+) now - pull to vegetation_pull (extended vegetation)
public double elevation_pull0 = 0; // (*) now - pull to initial elevation
......@@ -203,10 +214,17 @@ public class VegetationLMA {
public int debug_iter; // LMA iteration for images
public double [][] debug_image;
public int [] debug_iters;
public int [] debug_series;
public double [][] debug_rms;
public boolean debug_improved = true; // last LMA run, from rslt[0];
public boolean [] debug_improvements;
public static double [] debug_alpha_scales = {0, 50, 0, 10, 25, 50}; // {100,150};
public static boolean debug_show_iter_results = false; // true;
public String debug_path = "/media/elphel/SSD3-4GB/lwir16-proc/berdich3/debug/vegetation/lma_um/";
public boolean debug_save_improved = true;
public boolean debug_save_worsened = true;
private double [] last_rms = null; // {rms, rms_pure}, matching this.vector
private double [] good_or_bad_rms = null; // just for diagnostics, to read last (failed) rms
......@@ -294,44 +312,6 @@ public class VegetationLMA {
}
return;
}
@Deprecated
public VegetationLMA ( // unused
String path,
VegetationModel vegetationModel,
double alpha_initial_contrast,
int debugLevel) {
full = vegetationModel.full;
image_length = full.width * full.height;
num_scenes = vegetationModel.terrain_scenes_render.length;
vegetation_average =vegetationModel.vegetation_full; // vegetation_average_render;
vegetation_pull = vegetationModel.vegetation_pull; // pull LMA to this level
terrain_average = vegetationModel.terrain_filled; // terrain filled under vegetation, use to pull terrain level to it
terrain_rendered = vegetationModel.terrain_scenes_render;
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_SCENE_OFFSET] = new double [num_scenes];
setupInitialTerrainVegetationAlpha(
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
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();
double [][] params_arr = restoreParametersFile( //FIXME: Not finished for real import !
path, // String path,
false, // boolean keep_settings,
null); // Rectangle [] file_wois); // if not null, should be Rectangle[2] {woi_veg,woi} - will return woi data and not input parameters to this instance
}
private static double [][][] getScalesXY(
final double [][][] scales_mag_dir) {
......@@ -521,7 +501,8 @@ public class VegetationLMA {
final boolean fit_elevations,
final boolean [] fits_disable,
final double reg_weights, // fraction of the total weight used for regularization
final double alpha_loss, // quadratic loss when alpha reaches -1.0 or 2.0
final double alpha_loss, // alpha quadratic growing loss for when out of [0,1] range
final double alpha_loss_lin, // alpha linear growing loss for when out of [0,1] range and below minimal vegetation alpha
final double alpha_offset, // quadratic loss when alpha reaches -1.0 or 2.0
final double alpha_min_veg, // 0.5; // if (alpha-alpha_offset)/(1-2*alpha_offset) < alpha_min_veg, pull down to lpha_offset
final double alpha_lpf, // pull vegetation alpha to average of 4 neighbors
......@@ -536,6 +517,7 @@ public class VegetationLMA {
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 initial (pre-adjustment) values
final double terr_pull_up, // Terrain pixels pull to initial (pre-adjustment) values when it is colder than initial.
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
......@@ -548,7 +530,9 @@ public class VegetationLMA {
final double um_sigma, // just use in debug image names
final double um_weight,
String parameters_read_path,
final int debugLevel) {
final int debugLevel,
final boolean debug_save_improved, // Save debug image after successful LMA step.");
final boolean debug_save_worsened) { // Save debug image after unsuccessful LMA step.");
this.woi = woi;
this.hifreq_weight = hifreq_weight; // 22.5 0 - do not use high-freq. Relative weight of laplacian components
this.terrain_correction = terrain_correction;
......@@ -561,8 +545,9 @@ public class VegetationLMA {
this.fits_disable = fits_disable.clone();
this.reg_weights = reg_weights; // fraction of the total weight used for regularization
this.alpha_loss = alpha_loss;
this.alpha_loss_lin = alpha_loss_lin;
this.alpha_offset = alpha_offset;
this.alpha_min_veg = alpha_min_veg;
this.alpha_min_veg = Math.max(alpha_min_veg,0);
this.alpha_lpf = alpha_lpf;
this.alpha_scale_avg = alpha_scale_avg;
this.alpha_piece_linear= alpha_piece_linear;
......@@ -575,6 +560,7 @@ public class VegetationLMA {
this.veget_lpf = veget_lpf;
this.elevation_lpf = elevation_lpf;
this.terr_pull0 = terr_pull0;
this.terr_pull_up= (terr_pull_up > 0) ? terr_pull_up : terr_pull0;
this.veget_pull0 = veget_pull0;
this.elevation_pull0 = elev_pull0;
this.elev_alpha_en = elev_alpha_en;
......@@ -583,6 +569,9 @@ public class VegetationLMA {
this.low_veget = low_veget;
this.scenes_pull0 = scenes_pull0;
this.boost_parallax = boost_parallax;
this.debug_save_improved =debug_save_improved;
this.debug_save_worsened = debug_save_worsened;
// this.um_sigma = um_sigma; // just use in debug image names
// this.um_weight = um_weight;
......@@ -1021,6 +1010,25 @@ public class VegetationLMA {
// debugStateImage(dbg_prefix+"-initial");
}
for (iter = 0; iter < num_iter; iter++) {
if ((vegetationModel.SYNC_COMMAND != null) && (vegetationModel.SYNC_COMMAND.stopRequested.get()>0)) {
int stop_requested = vegetationModel.SYNC_COMMAND.stopRequested.getAndSet(0);
// IJ.getNumber("Any number", 0);
if (stop_requested > 1) {
String msg= "iter_step="+iter+", num_iter=num_iter. Exit iteretions?";
boolean ok_break= IJ.showMessageWithCancel("Stop Requested", msg);
System.out.println(">>> Stop Requested : ok_break="+ok_break);
break;
} else if (stop_requested > 0) {
String msg= "iter_step="+iter+", num_iter=num_iter. Continue";
IJ.showMessageWithCancel("Pause Requested", msg);
System.out.println(">>> Pause Requested, (in debugger only - put a breakpoint here. Use ABORT button to exit.");
System.out.println();
stop_requested = vegetationModel.SYNC_COMMAND.stopRequested.getAndSet(0);
if (stop_requested > 1) {
break;
}
}
}
debug_iter = iter; // for images
rslt = lmaStep(
lambda,
......@@ -1034,8 +1042,13 @@ public class VegetationLMA {
return -1; // false; // need to check
}
if (debug_level > -2) { // 1) {
String lma_series = "";
if (vegetationModel != null) {
lma_series = " Series " + vegetationModel.step_restore;
}
System.out.println((new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime()))+
" LMA step"+String.format("%3d (of%3d)",iter,num_iter)+": {"+rslt[0]+","+rslt[1]+"} full RMS= "+good_or_bad_rms[0]+
lma_series + " LMA step"+String.format("%3d (of%3d)",iter,num_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]) {
......@@ -1126,7 +1139,7 @@ public class VegetationLMA {
last_rms); // final double [] rms_fp // null or [2]
this.initial_rms = this.last_rms.clone();
this.good_or_bad_rms = this.last_rms.clone();
if (debug_level > 0) {
if (debug_level > -1) {
yMinusFxSummary(
fx, // final double [] fx,
true); // final boolean show)
......@@ -1152,6 +1165,7 @@ public class VegetationLMA {
boolean show_this = debug_level > 3;
boolean show_all = debug_level > 4;
debugImageSaveShow(
parameters_vector, // double [] vector
save_dir, // String save_dir, // save if not null
debug_title, // String title, // not null
save_all, // boolean save_all,
......@@ -1262,7 +1276,7 @@ public class VegetationLMA {
// vector_XYS, // final double [][] vector_XYS,
fx, // final double [] fx,
rms); // final double [] rms_fp // null or [2]
if (debug_level > 0) {
if (debug_level > -1) {
yMinusFxSummary(
fx, // final double [] fx,
true); // final boolean show)
......@@ -1278,6 +1292,7 @@ public class VegetationLMA {
rslt[1] = rms[0] >=(this.last_rms[0] * (1.0 - rms_diff));
this.last_rms = rms.clone();
this.parameters_vector = new_vector.clone();
/*
if (debug_level > -2) { //
String save_dir = debug_path;
String debug_title = getParametersDebugTitle();
......@@ -1297,6 +1312,7 @@ public class VegetationLMA {
dbg_title); // String title)
}
}
*/
} else { // worsened
rslt[0] = false;
......@@ -1314,18 +1330,39 @@ public class VegetationLMA {
fx, // final double [] fx,
true); // final boolean show)
}
if (last_ymfx == null) {
return null; // need to re-init/restart LMA
/// if (last_ymfx == null) {
/// return null; // need to re-init/restart LMA
/// }
}
if (debug_level > 2) {
/*
dbgJacobians(
corr_vector, // GeometryCorrection.CorrVector corr_vector,
1E-5, // double delta,
true); //boolean graphic)
*/
debug_improved = rslt[0];
if (debug_level > -2) {
if (rslt[0] ? debug_save_improved : debug_save_worsened) {
String save_dir = debug_path;
String debug_title = getParametersDebugTitle();
boolean save_all = (debug_image != null);
boolean show_this = debug_level > 3;
boolean show_all = debug_level > 4;
debugImageSaveShow(
new_vector, // double [] vector
save_dir, // String save_dir, // save if not null
debug_title, // String title, // not null
save_all, // boolean save_all,
show_this, // boolean show_this,
show_all); // boolean show_all)
if ((debug_level > 4) && (samples_pointers[SAMPLES_Y_AVG][1] > 0)){
String dbg_title = "terrain_corr_fX"+debug_iter;
debugTerrCorr(
fx, // double [] fx,
dbg_title); // String title)
}
}
}
if (last_ymfx == null) {
return null; // need to re-init/restart LMA
}
return rslt;
}
......@@ -1378,14 +1415,18 @@ public class VegetationLMA {
public void debugImageSaveShow(
double [] vector,
String save_dir, // save if not null
String title, // not null
boolean save_all,
boolean show_this,
boolean show_all) {
int [] wh = new int [2];
if (vector ==null) {
vector = parameters_vector;
}
double [] debug_img = parametersImage (
parameters_vector, // double [] vector,
vector, // double [] vector,
show_extra ? last_ymfx : null, // double [] ymfx,
1, // int gap)
wh,
......@@ -1395,30 +1436,55 @@ public class VegetationLMA {
if (debug_iters == null) {
debug_iters = new int [debug_image.length];
}
if (debug_series == null) {
debug_series = new int [debug_image.length];
}
if (debug_rms == null) {
debug_rms = new double [debug_image.length][];
}
if (debug_improvements == null) {
debug_improvements = new boolean [debug_image.length];
}
debug_iters[debug_index] = debug_iter;
debug_series[debug_index] = (vegetationModel != null) ? vegetationModel.step_restore : -1;
debug_rms[debug_index] = last_rms.clone();
debug_improvements[debug_index] = debug_improved;
title += "-"+debug_iter+ "_"+debug_index+String.format("_rms%8.5f_rms-pure%8.5f", last_rms[0],last_rms[1]);
if (!debug_improved) {
title+="-WORSE";
}
debug_image[debug_index++] = debug_img;
}
if (show_this) {
String this_title = title;
if (vegetationModel != null) {
this_title += "-series"+vegetationModel.step_restore;
}
this_title += "-iter"+debug_iter;
ShowDoubleFloatArrays.showArrays(
debug_img,
wh[0],
wh[1],
title + "-iter"+debug_iter);
this_title);
}
if (save_all || show_all) {
double [][] dbg_img = new double [debug_index][];
String [] titles = new String[debug_index];
for (int i = 0; i < debug_index; i++) {
titles[i] = "iter"+debug_iters[i];
titles[i] ="";
if (debug_series[i] >= 0) {
titles[i] += "series"+debug_series[i]+"-";
}
titles[i] += "iter"+debug_iters[i];
if ((debug_rms != null) && (debug_rms[i] != null)) {
titles[i]+=String.format("_rms%8.5f_rms-pure%8.5f", debug_rms[i][0], debug_rms[i][1]);
}
if (!debug_improvements[i]) {
titles[i]+="-WORSE";
}
dbg_img[i] = debug_image[i];
}
if (show_all) {
......@@ -2345,11 +2411,11 @@ public class VegetationLMA {
}
}
int dbg_scene = -20;
final int dbg_scene = -105; // -20;
final int dbg_windex = -234; // -1;
final int dbg_n = -7402; // -69992;
final int fdbg_scene = dbg_scene;
final int dbg_cols=2,dbg_rows=2;
final int dbg_windex = -1;
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
......@@ -2451,7 +2517,7 @@ public class VegetationLMA {
} // for (int wvindex = 0; wvindex < woi_veg_length; wvindex++) if (valid_vegetation[wvindex]) {
for (int windx = 0; windx < woi_length; windx++) if (valid_terrain[windx]) {
if (windx== dbg_windex) {
if ((windx== dbg_windex) && (nScene ==dbg_scene)) {
System.out.println("getFxDerivs() nScene="+nScene+", windx="+windx);
}
int wx = windx % woi.width; // relative to woi
......@@ -2816,9 +2882,10 @@ public class VegetationLMA {
// splitting alpha_lpf from alpha_loss+alpha_push
// No need here to add contributors as this should not depend on any other parameters
if (samples_pointers[SAMPLES_ALPHA_PULL][1] > 0) { // fits[TVAO_ALPHA] && ((alpha_loss > 0) || (alpha_push > 0))) {
int dbg_nx = -76340;
int dbg_nx = -120155; // 30578; // -120114; // -76340;
final boolean dbg_old = false;
final double alpha_threshold = alpha_offset + alpha_min_veg *(1 - 2*alpha_offset);
final double alpha_plateau = alpha_threshold * alpha_loss;
final double alpha_plateau = alpha_threshold; // * alpha_loss;
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
......@@ -2829,10 +2896,56 @@ public class VegetationLMA {
if (nx == dbg_nx) {
System.out.println("getFxDerivs(): n="+n+", nx="+nx);
}
double d = 0;
double dlin = 0;
double dquad = 0;
double ddlin = 0;
double ddquad = 0;
// double dd = 0;
fX[nx] = 0.0;
if (alpha_loss > 0) {
double alpha = vector[np];
if (alpha < alpha_offset) {
double d = alpha - alpha_offset; // negative
dquad = - d * d; // negative
ddquad = - 2 * d; // positive
dlin = d; // negative
ddlin = 1; // positive
} else if (alpha < alpha_threshold) {
dlin = (alpha - alpha_offset); // positive
ddlin = 1; // positive
} else if (alpha <= (1 - alpha_offset)) {
dlin = alpha_plateau;
} else { // if (alpha > (1 - alpha_offset))
double d = alpha - (1.0 - alpha_offset); // positive
dlin = d + alpha_plateau; // positive
ddlin = 1; // positive
dquad = d * d; // positive
ddquad = 2 * d; // positive
}
fX[nx] = dquad * alpha_loss + dlin * alpha_loss_lin;
if (jt != null) {
jt[np][nx] = ddquad * alpha_loss + ddlin * alpha_loss_lin; // d/dalpha[i]
}
if (dbg_old) {
// old version
double d = 0;
if (alpha < alpha_offset) {
d = alpha- alpha_offset;
} else if (alpha > (1 - alpha_offset)) {
d = alpha - (1.0 - alpha_offset);
}
if (d != 0) {
fX[nx] = d * d * alpha_loss;
if (jt != null) {
jt[np][nx] = 2 * alpha_loss * d; // d/dalpha[i]
}
}
}
/*
if (alpha_min_veg >= 0) {
if (alpha < alpha_threshold) {
fX[nx] = (alpha - alpha_offset) * alpha_loss;
......@@ -2861,6 +2974,7 @@ public class VegetationLMA {
}
}
}
*/
}
if (alpha_push > 0) {
// average including center:
......@@ -2997,16 +3111,18 @@ public class VegetationLMA {
int np = n + samples_pointers[SAMPLES_TERRAIN_PULL][2];
int nx = n + samples_pointers[SAMPLES_TERRAIN_PULL][0];
double d = 0;
if (terr_pull0 > 0) {
boolean pull_up = false;
if ((terr_pull0 > 0) || (terr_pull_up > 0)) {
int findx = par_rindex[np][1];
double terr_pull = terrain_average[findx]; // maybe use tvao[TVAO_TERRAIN][findx] ?
if (Double.isNaN(terr_pull)) {
terr_pull= 0; // should not happen
}
fX[nx] += terr_pull0 * (vector[np] - terr_pull);
pull_up = vector[np] < terr_pull;
fX[nx] += (pull_up ? terr_pull_up : terr_pull0) * (vector[np] - terr_pull);
}
if (jt != null) {
jt[np][nx] += terr_pull0;
jt[np][nx] += pull_up ? terr_pull_up : terr_pull0; // terr_pull0;
}
}
}
......@@ -3195,9 +3311,7 @@ public class VegetationLMA {
} else {
alpha_avg5 = (d < 0)? 0: ((d > 1) ? 1.0: 0.5 * (1.0 - Math.cos(d*Math.PI)));
}
// double alpha_avg5 = vector[npa]; // center alpha, weight = 1.0;
double alpha_w5 = 1.0;
// double [] derivs_neibs = new double [ alpha_neibs[n].length];
for (int i = 0; i < alpha_neibs[n].length; i++) { // now 4, may be increased
int di = alpha_neibs[na][i];
d=0;
......@@ -3301,6 +3415,7 @@ public class VegetationLMA {
for (int n = ai.getAndIncrement(); n < num_pars[TVAO_ELEVATION]; n = ai.getAndIncrement()) {
int np = n + samples_pointers[SAMPLES_ELEVATION_LPF][2];
int nx = n + samples_pointers[SAMPLES_ELEVATION_LPF][0];
int findx = par_rindex[np][1];
double d = 0;
if (elevation_lpf > 0) {
double avg = 0;
......@@ -3318,7 +3433,9 @@ public class VegetationLMA {
nn++;
}
}
avg /= nn; // average
avg /= nn; // average vegetation
// if (elevation_lpf_pow <=0) { // without transparency correction
fX[nx] += elevation_lpf * (vector[np] - avg); // + veget_pull0 * vector[np];
if (jt != null) {
jt[np][nx] += elevation_lpf;
......@@ -3329,6 +3446,39 @@ public class VegetationLMA {
}
}
}
/*
} else {
int npa = par_index[TVAO_ALPHA][findx]; // parameter for same-pixel alpha
int na = npa - ind_pars[TVAO_ALPHA];
if (npa < 0) {
System.out.println("getFxDerivs(): BUG: no alpha for vegetation, n="+n+", np="+np+", nx ="+nx+
" findx="+findx+", npa="+npa);
continue;
}
double alpha_center;
if (alpha_piece_linear) {
alpha_center = (d < 0)? 0: ((d > 1) ? 1.0: d);
} else {
alpha_center = (d < 0)? 0: ((d > 1) ? 1.0: 0.5 * (1.0 - Math.cos(d*Math.PI)));
}
double transparency_pwr = Math.pow(1.0-alpha_center, elevation_lpf_pow); // 0.. 1
double lpf = (1.0 - transparency_pwr) * elevation_lpf + transparency_pwr * elevation_lpf_transp;
fX[nx] += lpf * (vector[np] - avg); // + veget_pull0 * vector[np];
if (jt != null) {
jt[np][nx] += lpf;
for (int i = 0; i < elevation_neibs[n].length; i++) { // now 4, may be increased
int di = elevation_neibs[n][i];
if (di >= 0) {
jt[di][nx] -= lpf/nn;
}
}
// new derivative with respect to alpha
}
}
*/
}
}
}
......@@ -3669,11 +3819,11 @@ public class VegetationLMA {
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
final int woi_length = woi.width*woi.height;
String [] top_titles = use_hf? (
new String[]{"Y_lf", "fX_lf", "Ylf-fXlf","Y_hf", "fX_hf", "Yhf-fXhf", "alpha", "terrain", "terr-scaled","veget","sum_w","weights"}):
new String[]{"Y", "fX", "Y-fX","alpha", "terrain", "terr-scaled","veget","sum_w","weights"};
double [][][] img_data = new double [top_titles.length][ext_scenes][woi.width*woi.height];
double [][][] img_data = new double [top_titles.length][ext_scenes][woi_length];
double [][] extra_data = new double [6][];
int index_alpha = use_hf ? 6:3;
......@@ -3692,7 +3842,7 @@ public class VegetationLMA {
null, // final double [][] jt, // should be null or initialized with [vector.length][]
extra_data, // final double [][] debug_data, // {elev* alpha shifted, terrain *(1-alpha) shifted, elev_sum_weights}
-1); // final int debug_level)
final double [][] sample_weights = new double [num_scenes][woi_length]; //sample weights per scene, per output pixel
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
......@@ -3707,6 +3857,7 @@ public class VegetationLMA {
img_data[0][nscene][windx] = y_vector[n_lf];
img_data[1][nscene][windx] = fX[n_lf];
img_data[2][nscene][windx] = y_vector[n_lf]-fX[n_lf];
sample_weights[nscene][windx] = weights[n_lf];
for (int i = 0; i < extra_data.length; i++) {
double k = (i == index_extra_weight) ? scale_weights : 1.0;
img_data[index_alpha + i][nscene][windx] = k* extra_data[i][n_lf];
......@@ -3774,7 +3925,7 @@ public class VegetationLMA {
for (int nscene = 0; nscene < num_scenes; nscene++) {
// double w = (slice == index_weight)? 1.0: scene_weights[nscene];
for (int npix = 0; npix < img_data[slice][nscene].length; npix++) if (!Double.isNaN(img_data[slice][nscene][npix])){
double w = (slice == index_weight)? 1.0: extra_data[index_extra_weight][npix];
double w = (slice == index_weight)? 1.0: sample_weights[nscene][npix]; // extra_data[index_extra_weight][npix];
if (!Double.isNaN(w)) {
sw[slice][npix] += w;
img_data[slice][index_weighted][npix] += w * img_data[slice][nscene][npix];
......@@ -4872,7 +5023,7 @@ public class VegetationLMA {
private void setupWeights( // after setupParametersIndices
final double [] scene_weights_in,
final double reg_weights,
final double reg_weights, // relative to y_vector samples -> fraction of 1.0
final double hifreq_weight) {
// double terrain_correction_weight = 1.0;
boolean use_hf = (y_src_hf != null);
......@@ -4969,7 +5120,7 @@ public class VegetationLMA {
/// double s_pull_0 = s_scenes * scenes_pull0 * woi.width*woi.height;
final double s0 = s;
s *= (1+ reg_weights);
s /= (1 - reg_weights); // *= (1+ reg_weights);
final double k = 1.0/s;
weight_pure = s0/s;
scale_scenes_pull = scenes_pull0 * extra_samples / s_scenes; // or use extra_samples instead of woi.width*woi.height ?
......@@ -5007,6 +5158,15 @@ public class VegetationLMA {
};
}
ImageDtt.startAndJoin(threads);
double sw = 0;
for (int n = 0; n < (samples_pointers.length -1); n++) {
double swn = 0;
for (int i = samples_pointers[n][0]; i < (samples_pointers[n][0]+samples_pointers[n][1]); i++){
swn+= weights[i];
}
sw += swn;
System.out.println("sum weights["+n+"] = "+swn+", total = "+sw);
}
return;
}
......@@ -5048,15 +5208,16 @@ public class VegetationLMA {
final double transparency_opaque,
final double transparency_pedestal,
final double transparency_frac,
final double transparency_dist){ //0 - do not apply
final double transparency_dist, //0 - do not apply
final double transparency_pow){
final int dbg_windx = 113;
final int woi_length = woi.width*woi.height;
final double [][] transparency_weights = new double [num_scenes][woi_length];
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
for (int nscene = 0; nscene < num_scenes; nscene++) {
Arrays.fill(transparency_weights[nscene], Double.NaN);
}
// for (int nscene = 0; nscene < num_scenes; nscene++) {
// Arrays.fill(transparency_weights[nscene], Double.NaN);
// }
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
......@@ -5097,6 +5258,9 @@ public class VegetationLMA {
} else {
tf = 0;
}
if (transparency_pow != 1.0) {
tf = Math.pow(tf, transparency_pow);
}
transparency_weights[nscene][wPix] = tf + transparency_pedestal; // all those that were not NaN will be at least transparency_pedestal
}
} else {
......@@ -5113,6 +5277,32 @@ public class VegetationLMA {
return transparency_weights;
}
public double [] getTerrainConfidence( // woi.length
double [][] transparency_weights) {
final int woi_length = woi.width*woi.height;
final double [] transparency_confidence = new double [woi_length];
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
Arrays.fill(transparency_confidence, Double.NaN);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int wPix = ai.getAndIncrement(); wPix < woi_length; wPix = ai.getAndIncrement()) {
double sd2 = 0;
for (int nscene = 0; nscene < transparency_weights.length; nscene++) if (transparency_weights[nscene][wPix] > 0){
double d = transparency_weights[nscene][wPix];
sd2 += d * d;
}
transparency_confidence[wPix] = Math.sqrt(sd2);
}
}
};
}
ImageDtt.startAndJoin(threads);
return transparency_confidence;
}
public void applyTransparency(
final double [] vector,
......@@ -5120,25 +5310,120 @@ public class VegetationLMA {
final double transparency_pedestal,
final double transparency_frac,
final double transparency_dist,
final boolean recalc_average) {
final double transparency_pow,
final double transparency_gb,
final double transparency_boost_in,
final boolean recalc_average,
String prefix) {
this.recalc_average = recalc_average;
final int woi_length = woi.width*woi.height;
final double transparency_boost = Math.max(transparency_boost_in, 1.0);
boolean use_hf = (y_src_hf != null);
int y_avg_len = y_vector.length - (y_src.length + ((y_src_hf != null) ? y_src_hf.length : 0));
double [][] transparency = getTransparency((vector==null)? parameters_vector:vector);
double [][] transparency_weights = getTransparenctWeights(
double [][] transparency_weights_preblur = getTransparenctWeights( // should be no NaNs!
transparency, // final double [][] transparency,
transparency_opaque, // final double transparency_opaque,
transparency_pedestal, // final double transparency_pedestal,
transparency_frac, // final double transparency_frac,
transparency_dist); // final double transparency_dist); //0 - do not apply
transparency_dist, // final double transparency_dist); //0 - do not apply
transparency_pow); // final double transparency_pow){
final double [][] transparency_weights = new double [num_scenes][];
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
if (transparency_gb <= 0) {
for (int n = 0; n < transparency_weights.length; n++) {
transparency_weights[n] = transparency_weights_preblur[n];
}
} else {
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
DoubleGaussianBlur gb = new DoubleGaussianBlur();
for (int nScene = ai.getAndIncrement(); nScene < num_scenes; nScene = ai.getAndIncrement()) {
transparency_weights[nScene] = transparency_weights_preblur[nScene].clone();
gb.blurDouble(
transparency_weights[nScene], //
woi.width, // terrain woi
woi.height,
transparency_gb, // double sigmaX,
transparency_gb, // double sigmaY,
0.01); // double accuracy)
}
}
};
}
ImageDtt.startAndJoin(threads);
}
double [] confidence = getTerrainConfidence(transparency_weights); // blurred
double max_confidence = 0;
for (int i = 0; i < confidence.length; i++) if (confidence[i] > max_confidence) {
max_confidence = confidence[i];
}
double max_scaled = max_confidence / transparency_boost;
final double [] scales = new double [confidence.length];
for (int i = 0; i < confidence.length; i++) {
if (confidence[i] >= max_scaled) {
scales[i] = max_confidence / confidence[i];
} else {
scales[i] = transparency_boost;
}
}
final double [][] scaled_weights = new double [num_scenes][woi_length];
// normalize weights for confidence
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nScene = ai.getAndIncrement(); nScene < num_scenes; nScene = ai.getAndIncrement()) {
for (int windx = 0; windx < woi_length; windx++) {
scaled_weights[nScene][windx] = transparency_weights[nScene][windx] * scales[windx];
}
}
}
};
}
ImageDtt.startAndJoin(threads);
if (prefix != null) {
String title =prefix+String.format("-opq%3f-pdst%5f-frac%3f-dst%2f-pwr%4f-gb%4f-boost%4f-avg%1d.tiff",
transparency_opaque,transparency_pedestal,transparency_frac,
transparency_dist,transparency_pow,transparency_gb, transparency_boost, recalc_average?1:0);
int nscenes = transparency.length;
String [] titles_top = {"transparency","pre-blur","weights","normalized"};
String [] titles = new String[nscenes + 1];
double [][][] dbg_img = new double[titles_top.length][titles.length][]; // woi_length];
dbg_img[0][nscenes] = new double[woi_length];
dbg_img[1][nscenes] = getTerrainConfidence(transparency_weights_preblur);
dbg_img[2][nscenes] = getTerrainConfidence(transparency_weights);
dbg_img[3][nscenes] = scales;
for (int nscene = 0; nscene < transparency.length; nscene++) {
titles[nscene] = "scene-"+nscene;
dbg_img[0][nscene] = transparency[nscene];
dbg_img[1][nscene] = transparency_weights_preblur[nscene];
dbg_img[2][nscene] = transparency_weights[nscene];
dbg_img[3][nscene] = scaled_weights[nscene];
for (int wpix = 0;wpix < woi_length; wpix++) {
dbg_img[0][nscenes][wpix] = Math.max(transparency[nscene][wpix],dbg_img[0][nscenes][wpix]);
}
}
titles[nscenes] = "max/conf";
ShowDoubleFloatArrays.showArraysHyperstack(
dbg_img, // double[][][] pixels,
woi.width, // int width,
title, // "terrain_vegetation_render.tiff", // String title, "time_derivs-rt"+diff_time_rt+"-rxy"+diff_time_rxy,
titles, // String [] titles, // all slices*frames titles or just slice titles or null
titles_top, // String [] frame_titles, // frame titles or null
true); // boolean show)
}
double s = 0, ss=0;
for (int ny = 0; ny < y_src.length; ny++) {
int nscene = y_src[ny][YSRC_SCENE];
int findx = y_src[ny][YSRC_FINDEX];
int windx = getWindexFromFindex(findx);
double w = transparency_weights[nscene][windx];
double w = scaled_weights[nscene][windx];
if (Double.isNaN(w)) {
System.out.println("applyTransparency() 1: ny="+ny+", nscene="+nscene+", findx="+findx+", windx="+windx+", w="+w);
} else {
......@@ -5148,12 +5433,12 @@ public class VegetationLMA {
}
// double s_scenes = s; // sum of all scene weight. Maybe skip scenes that do not exist?
double s_to_ss = s/ss;
if (use_hf) { // second pass, repeating for possible future modifications
if (use_hf) {
for (int ny = 0; ny < y_src_hf.length; ny++) {
int nscene = y_src_hf[ny][YSRC_SCENE];
int findx = y_src_hf[ny][YSRC_FINDEX];
int windx = getWindexFromFindex(findx);
double w = transparency_weights[nscene][windx] * hifreq_weight ;
double w = scaled_weights[nscene][windx] * hifreq_weight ;
if (Double.isNaN(w)) {
System.out.println("applyTransparency() 2: ny="+ny+", nscene="+nscene+", findx="+findx+", windx="+windx+", w="+w);
} else {
......@@ -5163,7 +5448,7 @@ public class VegetationLMA {
}
// double s_y_yhf = s; //
// TODO: If using transparency_weights (in setupYVectorTransparency and getFxDerivs),
// TODO: If using scaled_weights (in setupYVectorTransparency and getFxDerivs),
// then calculate following weights differently to keep ~ the same sum
// use recalc_average / this.recalc_average to change weights
......@@ -5174,12 +5459,13 @@ public class VegetationLMA {
}
}
/// final double s0 = s;
s *= (1+ reg_weights);
s /= (1 - reg_weights); // *= (1+ reg_weights);s *= (1+ reg_weights);
final double k = 1.0/s; //corr_transp 10.85811847216958
weight_to_scene_weight = k * s_to_ss;
/// weight_pure = s0/s;
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
// final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
// final AtomicInteger ai = new AtomicInteger(0);
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
......@@ -5189,7 +5475,7 @@ public class VegetationLMA {
int nscene = y_src[ny][YSRC_SCENE];
int findx = y_src[ny][YSRC_FINDEX];
int windx = getWindexFromFindex(findx);
double w = transparency_weights[nscene][windx] * k;
double w = scaled_weights[nscene][windx] * k;
if (!Double.isNaN(w)) {
weights[nw] = w;
} else {
......@@ -5201,7 +5487,7 @@ public class VegetationLMA {
int nscene = y_src_hf[ny][YSRC_SCENE];
int findx = y_src_hf[ny][YSRC_FINDEX];
int windx = getWindexFromFindex(findx);
double w = transparency_weights[nscene][windx] * k * hifreq_weight; // scene_weights[nscene] * k * hifreq_weight;
double w = scaled_weights[nscene][windx] * k * hifreq_weight; // scene_weights[nscene] * k * hifreq_weight;
if (!Double.isNaN(w)) {
weights[nw] = w;
} else {
......@@ -5230,7 +5516,17 @@ public class VegetationLMA {
if (y_src_hf != null) { // set average offset y - either old way with scene_weights[nscene] or new way with weights[ny]
setupYVectorTransparency();
}
if (prefix != null) {
double sw = 0;
for (int n = 0; n < (samples_pointers.length -1); n++) {
double swn = 0;
for (int i = samples_pointers[n][0]; i < (samples_pointers[n][0]+samples_pointers[n][1]); i++){
swn+= weights[i];
}
sw += swn;
System.out.println("sum weights["+n+"] = "+swn+", total = "+sw);
}
}
return;
}
......
......@@ -12,6 +12,7 @@ import org.apache.commons.math3.analysis.interpolation.PiecewiseBicubicSplineInt
import com.elphel.imagej.cameras.CLTParameters;
import com.elphel.imagej.common.DoubleGaussianBlur;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.correction.SyncCommand;
import com.elphel.imagej.jp4.JP46_Reader_camera;
import com.elphel.imagej.orthomosaic.OrthoMap;
import com.elphel.imagej.tileprocessor.ErsCorrection;
......@@ -93,8 +94,9 @@ public class VegetationModel {
public double [][] tva;
int step_restore;
public final SyncCommand SYNC_COMMAND;
public boolean isFailed() {
return failed;
}
......@@ -222,7 +224,9 @@ public class VegetationModel {
public VegetationModel(
String dir,
String title) {
String title,
SyncCommand SYNC_COMMAND) {
this.SYNC_COMMAND = SYNC_COMMAND;
String path = VegetationLMA.getSavePath(
dir, // String dir,
title, // String title)
......@@ -392,7 +396,9 @@ public class VegetationModel {
CLTParameters clt_parameters,
QuadCLT [] quadCLTs,
int ref_index,
SyncCommand SYNC_COMMAND,
int debugLevel) {
this.SYNC_COMMAND = SYNC_COMMAND;
boolean show_debug = false;
TileProcessor tp = quadCLTs[ref_index].getTileProcessor();
int tilesX = tp.getTilesX();
......@@ -809,6 +815,7 @@ public class VegetationModel {
clt_parameters, // CLTParameters clt_parameters,
quadCLTs, // QuadCLT [] quadCLTs,
ref_index, // int ref_index,
null, // SyncCommand SYNC_COMMAND,
debugLevel); // int debugLevel)
if (vegetationModel.isFailed()) {
System.out.println("Creation of VegetationModel failed!");
......@@ -1278,13 +1285,14 @@ public class VegetationModel {
public static void processVegetation(
SyncCommand SYNC_COMMAND,
CLTParameters clt_parameters,
boolean combine_segments)
{
String model_directory = clt_parameters.imp.terr_model_path; // Model directory path with version.
String model_state_file = clt_parameters.imp.terr_model_state; // Model vegetation source data (w/o extension).
int terr_debug= clt_parameters.imp.terr_debug;
// Temporary , it is actually a model directory // 1697877487_245877-TERR-VEG-STATE.terrveg-tiff
// String model_directory = "/media/elphel/SSD3-4GB/lwir16-proc/berdich3/linked/linked_1697875868-1697879449-b/1697877487_245877/v35";
......@@ -1295,11 +1303,13 @@ public class VegetationModel {
}
VegetationModel vegetationModel = new VegetationModel(
model_directory, // String dir,
model_state_file); // String title)
model_state_file, // String title)
SYNC_COMMAND); // SyncCommand SYNC_COMMAND,
vegetationModel.processVegetationLMA(
combine_segments, // boolean combine_segments,
clt_parameters, // CLTParameters clt_parameters,
-1); // int debugLevel) {
terr_debug); // int debugLevel) {
}
......@@ -1369,6 +1379,53 @@ public class VegetationModel {
}
}
public static boolean [] thisOrLast(
int index,
boolean [][] sequence) {
boolean [] selected = new boolean [sequence.length];
for (int i = 0; i <selected.length; i++) {
selected[i] = sequence[i][Math.min(index, sequence[i].length - 1)];
}
return selected;
}
public static boolean thisOrLast(
int index,
boolean [] sequence) {
return sequence[Math.min(index, sequence.length - 1)];
}
public static int thisOrLast(
int index,
int [] sequence) {
return sequence[Math.min(index, sequence.length - 1)];
}
public static double thisOrLast(
int index,
double [] sequence) {
return sequence[Math.min(index, sequence.length - 1)];
}
public static int [] thisOrLast(
int index,
int [][] sequence) {
int [] selected = new int [sequence.length];
for (int i = 0; i <selected.length; i++) {
selected[i] = sequence[i][Math.min(index, sequence[i].length - 1)];
}
return selected;
}
public static double [] thisOrLast(
int index,
double [][] sequence) {
double [] selected = new double [sequence.length];
for (int i = 0; i <selected.length; i++) {
selected[i] = sequence[i][Math.min(index, sequence[i].length - 1)];
}
return selected;
}
public void processVegetationLMA(
boolean combine_segments,
CLTParameters clt_parameters,
......@@ -1381,8 +1438,8 @@ public class VegetationModel {
String parameters_dir = clt_parameters.imp.terr_par_dir; //
String parameters_file = clt_parameters.imp.terr_par_file; //
boolean par_restore = clt_parameters.imp.terr_par_restore; // true;
// int
step_restore= par_restore? clt_parameters.imp.terr_step_restore : 0;
boolean um_en = clt_parameters.imp.terr_um_en; // true;
double um_sigma = clt_parameters.imp.terr_um_sigma; // 1.0;
......@@ -1426,7 +1483,8 @@ public class VegetationModel {
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_loss = clt_parameters.imp.terr_alpha_loss; //100.0; // alpha quadratic growing loss for when out of [0,1] range
double alpha_loss_lin = clt_parameters.imp.terr_alpha_loss_lin; // alpha linear growing loss for when out of [0,1] range and below minimal vegetation alpha
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;
double alpha_min_veg = clt_parameters.imp.terr_alpha_min_veg; // 0.5 // Minimal vegetation alpha. If (alpha-alpha_offset)/(1-2*alpha_offset) < alpha_min_veg, pull down to lpha_offset
......@@ -1441,7 +1499,8 @@ public class VegetationModel {
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 = 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 terr_pull0 = clt_parameters.imp.terr_terr_pull0; // 0.1; //0.03; ////// 0.05; ///// 0.1; //// 0.01; /// 0.2; /// 0.1; //pull terrain to zero (makes sense with UM
double terr_pull_up = clt_parameters.imp.terr_terr_pull_up; // 0.2; //Terrain pixels pull to initial (pre-adjustment) values when it is colder than initial.
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
......@@ -1462,7 +1521,11 @@ public class VegetationModel {
boolean fit_scenes = clt_parameters.imp.terr_fit_scenes; // true; // adjust scene offsets (start from 0 always?)
boolean fit_elevations = clt_parameters.imp.terr_fit_elevations; // false; // adjust elevation pixels (not yet implemented)
boolean [] fit_disable = clt_parameters.imp.terr_fit_disable.clone();
// boolean [] fit_disable = clt_parameters.imp.terr_fit_disable.clone();
boolean [][] fits_disable = new boolean[clt_parameters.imp.terr_fits_disable.length][];
for (int i = 0; i < fits_disable.length; i++) {
fits_disable[i] = clt_parameters.imp.terr_fits_disable[i].clone();
}
double reg_weights = clt_parameters.imp.terr_reg_weights; // 0.25; // fraction of the total weight used for regularization
double lambda = clt_parameters.imp.terr_lambda; // 5.0; // 0.1;
......@@ -1470,8 +1533,9 @@ public class VegetationModel {
double lambda_scale_bad = clt_parameters.imp.terr_lambda_scale_bad; // 8.0;
double lambda_max = clt_parameters.imp.terr_lambda_max; // 1000;
double rms_diff = clt_parameters.imp.terr_rms_diff; // 1e-8; // 0.0001; virtually forever
int num_iter = clt_parameters.imp.terr_num_iter; //25; // 100;
int [] num_iters = clt_parameters.imp.terr_num_iters; // {25}; // 100;
int last_series = clt_parameters.imp.terr_last_series; // -1; // 100;
if (last_series < 0) last_series = num_iters.length - 1;
// Combine parameters
int border_width = clt_parameters.imp.terr_border_width; // 6;
boolean render_open = clt_parameters.imp.terr_render_open; // true; // render open areas (no vegetation offset)
......@@ -1494,12 +1558,17 @@ public class VegetationModel {
boolean show_final_result = !tile_woi; // true; (maybe make saving results in tiled mode?
boolean recalc_weights = clt_parameters.imp.terr_recalc_weights ; //false; // recalculate weight depending on terrain visibility
boolean [] recalc_weights = clt_parameters.imp.terr_recalc_weights ; //false; // recalculate weight depending on terrain visibility
double transparency_opaque = 1.0 - clt_parameters.imp.terr_recalc_opaque ; // 0.9; // above is opaque
double transparency_pedestal = clt_parameters.imp.terr_recalc_pedestal ; // 0.05; // weight of opaque tiles
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
double transparency_dist = clt_parameters.imp.terr_recalc_dist ; // 0.0; // weight of opaque tiles
double transparency_pow = clt_parameters.imp.terr_recalc_pwr ; // 1.0; // Raise transparency to this power when calculating weight
double transparency_gb = clt_parameters.imp.terr_recalc_gb ; // 2.0; // Blur transparency-based confidence
double transparency_boost = clt_parameters.imp.terr_recalc_boost ; // 5.0; // Maximal boost while increasing low-confidence pixel weights
boolean recalc_average = clt_parameters.imp.terr_recalc_average ; //false; // apply transparency to average mismatch
boolean debug_save_improved = clt_parameters.imp.terr_debug_improved;
boolean debug_save_worsened = clt_parameters.imp.terr_debug_worsened;
boolean restore_mode = false;
boolean save_par_files = true; // false;
String segments_dir = getSegmentsDir(segments_sub);
......@@ -1991,6 +2060,15 @@ public class VegetationModel {
} else {
System.out.println("===== Will process a single WOI ("+woi.x+", "+woi.y+", "+woi.width+", "+woi.height+").");
}
/*
boolean [][] fits_disables = new boolean [num_iters.length][];
for (int i = 0; i <fits_disables.length; i++) {
fits_disables[i] = fit_disable.clone();
}
if (!par_restore && (fits_disables.length > 1)) {
fits_disables[0][VegetationLMA.TVAO_ELEVATION] = true; // disable elevation adjustment for the first run
}
*/
int num_samples = vegetationLMA.prepareLMA(
false, // final boolean keep_parameters,
woi, // final Rectangle woi,
......@@ -2005,11 +2083,12 @@ public class VegetationModel {
fit_alpha, // final boolean adjust_alpha,
fit_scenes, // final boolean adjust_scenes,
fit_elevations, // final boolean adjust_elevations,
fit_disable, // final boolean [] fit_disable,
thisOrLast(step_restore, fits_disable), // fits_disables[0], // final boolean [] fit_disable,
reg_weights, // final double reg_weights, // fraction of the total weight used for regularization
alpha_loss, // final double alpha_loss, // quadratic loss when alpha reaches -1.0 or 2.0
alpha_loss, // final double alpha_loss, // alpha quadratic growing loss for when out of [0,1] range
alpha_loss_lin, // final double alpha_loss_lin, // alpha linear growing loss for when out of [0,1] range and below minimal vegetation alpha
alpha_offset, // final double alpha_offset, // quadratic loss when alpha reaches -1.0 or 2.0
alpha_min_veg, //final double alpha_min_veg, // 0.5; // if (alpha-alpha_offset)/(1-2*alpha_offset) < alpha_min_veg, pull down to lpha_offset
alpha_min_veg, // final double alpha_min_veg, // 0.5; // if (alpha-alpha_offset)/(1-2*alpha_offset) < alpha_min_veg, pull down to lpha_offset
alpha_lpf, // final double alpha_lpf, // pull to average of 4 neighbors
alpha_piece_linear, // final boolean alpha_piece_linear, // true - piece-linear, false - half-cosine
alpha_scale_avg, // final double alpha_scale_avg, // = 1.2; // scale average alpha (around 0.5) when pulling to it
......@@ -2022,6 +2101,7 @@ public class VegetationModel {
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 initial (pre-adjustment) values
terr_pull_up, // final double terr_pull_up, // Terrain pixels pull to initial (pre-adjustment) values when it is colder than initial.
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
......@@ -2034,7 +2114,10 @@ public class VegetationModel {
um_sigma, // final double um_sigma, // just use in debug image names
(um_en? um_weight: 0.0), // final double um_weight,
par_path, // final String parameters_read_path,
debugLevel); // final int debugLevel);
debugLevel, // final int debugLevel);
debug_save_improved, // final boolean debug_save_improved, // Save debug image after successful LMA step.");
debug_save_worsened);// final boolean debug_save_worsened) // Save debug image after unsuccessful LMA step.");
if (num_samples <= 0) {
System.out.println("Insufficient data in this segment, skipping it.");
continue;
......@@ -2053,8 +2136,8 @@ public class VegetationModel {
continue;
}
}
if (par_restore) {
int num_iter = num_iters[step_restore];
if (par_restore) { // always use last number of iterations - not anymore
par_path = parameters_dir;
if (!par_path.endsWith(Prefs.getFileSeparator())) {
par_path+=Prefs.getFileSeparator();
......@@ -2065,15 +2148,23 @@ public class VegetationModel {
par_path, // String path,
true, // boolean keep_settings,
null); // Rectangle [] file_wois); // if not null, should be Rectangle[2] {woi_veg,woi} - will return woi data and not input parameters to this instance
if (recalc_weights) {
if (thisOrLast(step_restore,recalc_weights)) {
System.out.println ("---- Recalculating weights from transparency after loading parameters");
String dbg_title= (debugLevel > -2) ?("transparency_"+step_restore): null;
vegetationLMA.applyTransparency(
null, // final double [] vector,
transparency_opaque, // final double transparency_opaque,
transparency_pedestal, // final double transparency_pedestal,
transparency_frac, // final double transparency_frac,
transparency_dist, // final double transparency_dist,
recalc_average); // final boolean recalc_average);
transparency_pow, // final double transparency_pow,
transparency_gb, // final double transparency_gb,
transparency_boost, // final double transparency_boost,
recalc_average, // final boolean recalc_average);
dbg_title); // String title)
}
// num_iter = num_iters[num_iters.length-1]; // use last, may be 3-rd
//num_iters.length
}
// old
if ("RESTORE".equals(par_path)) {
......@@ -2090,7 +2181,7 @@ public class VegetationModel {
}
if ((show_final_result) && (debugLevel > -2)) { // 0)) {
String reconstructed_title = reference_scene+"-reconstructed-initial";
String reconstructed_title = reference_scene+"-reconstructed-pre-step"+step_restore; //
vegetationLMA.showYfX(
null, // double [] vector,
reconstructed_title); // String title)
......@@ -2120,55 +2211,75 @@ public class VegetationModel {
lambda_scale_bad, // double lambda_scale_bad, // 8.0
lambda_max, // double lambda_max, // 100
rms_diff, // double rms_diff, // 0.001
num_iter, // 15, // num_iter, //int num_iter, // 20
num_iter, // num_iters[0], // 15, // num_iter, //int num_iter, // 20
last_run, // boolean last_run,
null, // String dbg_prefix,
debugLevel); // int debug_level)
if (debugLevel > -2) { // 1) {
System.out.println((new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime()))+
" LMA finished - first run");
}
if (!par_restore) { // run second pass (temporarily)
if (save_par_files) {
String restore_dir = segments_dir; // vegetationLMA.debug_path;
String debug_title = vegetationLMA.getParametersDebugTitle();
vegetationLMA.saveParametersFile(
restore_dir, // String dir,
debug_title+"_pre", // String title, // no .par-tiff
debug_title+"_post"+step_restore, // String title, // no .par-tiff
null); // double [] vector)
}
elev_pull0 *= 0.01;
vegetationLMA.elevation_pull0 = elev_pull0;
if (recalc_weights) {
if (debugLevel > -2) { // 1) {
System.out.println((new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime()))+
" LMA finished - first run (step "+step_restore+").");
}
step_restore++;
for (; step_restore <= last_series; step_restore++) {
// vegetationLMA.fits_disable[VegetationLMA.TVAO_ELEVATION] = fits_disable[step_restore][VegetationLMA.TVAO_ELEVATION];
vegetationLMA.fits_disable[VegetationLMA.TVAO_ELEVATION] =thisOrLast(step_restore,fits_disable)[VegetationLMA.TVAO_ELEVATION];
if (thisOrLast(step_restore,recalc_weights)) {
System.out.println ("---- Recalculating weights from transparency");
String dbg_title= (debugLevel > -2) ? ("transparency_"+step_restore) : null;
vegetationLMA.applyTransparency(
null, // final double [] vector,
transparency_opaque, // final double transparency_opaque,
transparency_pedestal, // final double transparency_pedestal,
transparency_frac, // final double transparency_frac,
transparency_dist, // final double transparency_dist,
recalc_average); // final boolean recalc_average); }
transparency_pow, // final double transparency_pow,
transparency_gb, // final double transparency_gb,
transparency_boost, // final double transparency_boost,
recalc_average, // final boolean recalc_average);
dbg_title); // String title)
}
if (save_par_files) {
String restore_dir = segments_dir; // vegetationLMA.debug_path;
String debug_title = vegetationLMA.getParametersDebugTitle();
vegetationLMA.saveParametersFile(
restore_dir, // String dir,
debug_title+"_pre"+step_restore, // String title, // no .par-tiff
null); // double [] vector)
}
if (debugLevel > -3) {
lma_rslt= vegetationLMA.runLma( // <0 - failed, >=0 iteration number (1 - immediately)
lambda, // double lambda, // 0.1
lambda_scale_good,// double lambda_scale_good,// 0.5
lambda_scale_bad, // double lambda_scale_bad, // 8.0
lambda_max, // double lambda_max, // 100
rms_diff, // double rms_diff, // 0.001
num_iter, //int num_iter, // 20
num_iters[step_restore], // num_iter, //int num_iter, // 20
last_run, // boolean last_run,
null, // String dbg_prefix,
debugLevel); // int debug_level)
if (save_par_files) {
String restore_dir = segments_dir; // vegetationLMA.debug_path;
String debug_title = vegetationLMA.getParametersDebugTitle();
vegetationLMA.saveParametersFile(
restore_dir, // String dir,
debug_title+"_post"+step_restore, // String title, // no .par-tiff
null); // double [] vector)
}
if (debugLevel > -2) { // 1) {
System.out.println((new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime()))+
" LMA finished - second run");
}
}
" LMA finished, run " + step_restore);
}
} // for (; step_restore < num_iters.lenggth; step_restore++) {
// save results
if (save_par_files) {
......@@ -2181,7 +2292,7 @@ public class VegetationModel {
// continue;
}
if (show_final_result) {
String reconstructed_title = reference_scene+"-reconstructed-"+vegetationLMA.getParametersDebugTitle();
String reconstructed_title = reference_scene+"-reconstructed-"+vegetationLMA.getParametersDebugTitle()+"-series"+last_series;
vegetationLMA.showYfX(
null, // double [] vector,
reconstructed_title); // String title)
......
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