Commit b3ad74ea authored by Andrey Filippov's avatar Andrey Filippov

restored loading initial LMA parameters from the previously saved ones

parent a8718162
......@@ -723,6 +723,9 @@ min_str_neib_fpn 0.35
public String terr_model_path = "/media/elphel/SSD3-4GB/lwir16-proc/berdich3/models/models_1697875868-1697879449-b/1697877487_245877/v35";
public String terr_model_state = "1697877487_245877-TERR-VEG-STATE";
public String terr_segments_dir = "sections";
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
// terrain/vegetation parameters
public boolean terr_um_en = true;
public double terr_um_sigma = 1.0;
......@@ -1993,9 +1996,13 @@ min_str_neib_fpn 0.35
gd.addTab("Vegetation","See through foliage parameters");
gd.addStringField ("Model path", terr_model_path, 120, "Model directory path with version.");
gd.addStringField ("Model state file", terr_model_state, 50, "Model vegetation source data (w/o extension).");
gd.addStringField ("Segments subdir", terr_segments_dir, 50, "Model vegetation source data (w/o extension).");
gd.addStringField ("Model path", terr_model_path, 120, "Model directory path with version.");
gd.addStringField ("Model state file", terr_model_state, 50, "Model vegetation source data (w/o extension).");
gd.addStringField ("Segments subdir", terr_segments_dir, 50,"Model vegetation source data (w/o extension).");
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.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.");
......@@ -2717,19 +2724,24 @@ min_str_neib_fpn 0.35
terr_model_path = gd.getNextString();
terr_model_state = gd.getNextString();
terr_segments_dir = gd.getNextString();
terr_um_en = gd.getNextBoolean();// boolean
terr_um_sigma = gd.getNextNumber();// double
terr_um_weight = gd.getNextNumber();// double
terr_nan_tolerance = gd.getNextNumber();// double
terr_nan_grow = (int) gd.getNextNumber();// int
terr_shrink_veget = (int) gd.getNextNumber();// int
terr_shrink_terrain =(int) gd.getNextNumber();// int
terr_vegetation_over = gd.getNextNumber();// double
terr_filter_veget = (int) gd.getNextNumber();// int
terr_tile_woi = gd.getNextBoolean();// boolean
terr_continue = gd.getNextBoolean();// boolean
terr_par_dir = gd.getNextString();
terr_par_file = gd.getNextString();
terr_par_restore = gd.getNextBoolean(); // boolean
terr_um_en = gd.getNextBoolean(); // boolean
terr_um_sigma = gd.getNextNumber(); // double
terr_um_weight = gd.getNextNumber(); // double
terr_nan_tolerance = gd.getNextNumber(); // double
terr_nan_grow = (int) gd.getNextNumber(); // int
terr_shrink_veget = (int) gd.getNextNumber(); // int
terr_shrink_terrain =(int) gd.getNextNumber(); // int
terr_vegetation_over = gd.getNextNumber(); // double
terr_filter_veget = (int) gd.getNextNumber(); // int
terr_tile_woi = gd.getNextBoolean(); // boolean
terr_continue = gd.getNextBoolean(); // boolean
terr_woi_enclos = stringToRectangle(gd.getNextString());// Rectangle
terr_woi_step = stringToRectangle(gd.getNextString());// Rectangle
terr_woi_last = stringToRectangle(gd.getNextString());// Rectangle
......@@ -3395,6 +3407,10 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"terr_model_state", terr_model_state+""); // String
properties.setProperty(prefix+"terr_segments_dir", terr_segments_dir+""); // String
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_um_en", terr_um_en+""); // boolean
properties.setProperty(prefix+"terr_um_sigma", terr_um_sigma+""); // double
properties.setProperty(prefix+"terr_um_weight", terr_um_weight+""); // double
......@@ -4094,6 +4110,10 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"terr_model_path")!= null) terr_model_path=(String) properties.getProperty(prefix+"terr_model_path");
if (properties.getProperty(prefix+"terr_model_state")!= null) terr_model_state=(String) properties.getProperty(prefix+"terr_model_state");
if (properties.getProperty(prefix+"terr_segments_dir")!= null) terr_segments_dir=(String) properties.getProperty(prefix+"terr_segments_dir");
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_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"));
......@@ -4762,6 +4782,10 @@ min_str_neib_fpn 0.35
imp.terr_model_state = this. terr_model_state;
imp.terr_segments_dir = this. terr_segments_dir;
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_um_en = this.terr_um_en;
imp.terr_um_sigma = this.terr_um_sigma;
imp.terr_um_weight = this.terr_um_weight;
......
......@@ -58,48 +58,21 @@ public class VegetationLMA {
public static final int SAMPLES_SIZE = SAMPLES_TOTAL+1;
public static final int SAMPLES_EXTRA = SAMPLES_SCENES; // start of "extra" samples
public static final int DATA_SOURCE_HEAD = 0; // header row with { scene, full_indx, terr_indx, scale_indx}, always present
public static final int DATA_SOURCE_CORN_VEGET =1; // [4]/null Z-shape 4 corners vegetation, either >= as parameter index or -1 - (x + image_width*y) of the unmodified full index
public static final int DATA_SOURCE_CORN_ALPHA =2; // [4]/null Z-shape 4 corners vegetation alpha, either >= as parameter index or -1 - (x + image_width*y) of the unmodified full index
public static final int DATA_SOURCE_NEIB = 3; // [4]/null or 4 neighbors (CW), either y_vector index or -1 -(x + image_width*y) of the unmodified terrain
public static final int DATA_SOURCE_HEAD_SCENE = 0; // header row scene's subindex
public static final int DATA_SOURCE_HEAD_FINDEX =1; // header row full frame index's subindex
public static final int DATA_SOURCE_HEAD_TINDEX =2; // header row texture parameter subindex
public static final int DATA_SOURCE_HEAD_SINDEX =3; // header row frame offset subindex
public static final int DATA_SOURCE_ITEMS = DATA_SOURCE_NEIB + 1; // == 4 number or rows in data source element
public static final int DATA_SOURCE_HEAD_SIZE = DATA_SOURCE_HEAD_SINDEX+1;
public static final int [] EMPTY4= {-1,-1,-1,-1};
// public static final int [] SAVE_TYPES = {TVAO_TERRAIN, TVAO_VEGETATION, TVAO_ALPHA, TVAO_SCENE_OFFSET};
public static final int [] SAVE_TYPES = {TVAO_TERRAIN, TVAO_VEGETATION, TVAO_ALPHA, TVAO_ELEVATION, TVAO_SCENE_OFFSET};
private final Rectangle full;
private final int image_length;
private final int num_scenes;
private Rectangle woi = null;
private Rectangle woi_veg = null; // extended woi to include offset vegetation
// should be non-null everywhere where elevation is defined?
private double [] vegetation_average; // full image average vegetation (with nulls)
private double [] vegetation_filtered; // same as vegetation_average, but has more NaN to be used to select initial terrain
private double [] vegetation_pull; // have nan far from vegetation, use to pull LMA to this
private double [] terrain_average; // full image average terrain (no nulls)
private double [][] terrain_rendered; // terrain rendered for scenes (has nulls)
private double [][] terrain_rendered_hf; // terrain rendered for scenes (has nulls)
private double [][][] vegetation_offsets; // [num_scenes][pixle]{dx,dy} differential offsets of vegetation to terrain grid
private boolean diff_offsets;
// next 3 arrays are full [image_width*image_height], but will be modified only inside woi
public double [][] tvao; // [0][image_length] - terrain, [1][image_length] - vegetation,
private double [][][] scales_xy; // [scene][pixel{scale_x,scale_y}
private VegetationModel vegetationModel = null;
// public int min_dependent_scenes = 1;
private double max_warp = 1.8;
private int max_offset = 22;
//[2][image_length] - alpha, [3][num_scenes] - per-scene offset (mostly for vignetting. MAYBE add per-scene pair of tilts
private int [][] par_index; // indices - [0..4][full_pixel] - same as for tvao, value - parameter index
private int [][] par_rindex; // parameter -> pair of type (0..4) and full window pixel index
private int num_pars_terrain;
......@@ -137,24 +110,11 @@ public class VegetationLMA {
private boolean [][] param_pivot; // [all_pars][all_pars] which parameters parameters have common dependents
private int [][] param_lists; // [all_pars][related] - for each parameter - null or integer array of related (by JtJ) parameters
// TODO: Compare with/without pivot to verify/troubleshoot.
@Deprecated
private int [][][] data_source; // [index][windx][DATA_SOURCE_ITEMS]:
// 0:{ scene, full_indx, terr_indx, scale_indx} - always present as parameters
// 1: [4]/null Z-shape 4 corners vegetation, either >= as parameter index or -1 - (x + image_width*y) of the unmodified full index
// 2: [4]/null Z-shape 4 corners vegetation alpha, either >= as parameter index or -1 - (x + image_width*y) of the unmodified full index
// 3: [4]/null or 4 neighbors (CW), either y_vector index or -1 -(x + image_width*y) of the unmodified terrain
@Deprecated
private double [][] corners_weights; // matches data_source, non-nulls specify Z-shape 4 corners of vegetation/alpha weights
private boolean [] valid_terrain = null; // [woi.width*woi.height] valid terrain and y_vector pixels
private boolean [] overlaid = null; // [woi.width*woi.height] this valid terrain pixel is overlaid by vegetation (in all valid scenes)
private boolean [] valid_vegetation = null;
private double [][][] warps = null; // measure of horizontal and vertical distances between the vegetation projections - use to filter scenes
// private int [] used_scenes_indices;
private final double [] scene_weights;
private boolean [] valid_scenes;
......@@ -167,66 +127,54 @@ public class VegetationLMA {
// private double terrain_warmest = 90; // pull vegetations to warm, terrain to cold
// private double initial_split = 0.1; // pull vegetations to warm, terrain to cold
// private double min_split_frac = 0.15; // minimal modality fraction to use split by temperature
private double terr_difference = 100; // pull vegetation to be this warmer
@Deprecated
private double terr_pull_cold = 0; // pull vegetations to warm, terrain to cold
// next two just for saving?
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_initial_contrast = 1.0; // >=1.0
private double alpha_loss = 0; // not used with cosine alpha
private double alpha_offset = 0; // if >0, start losses above 0.0 and below 1.0;
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
private double alpha_push = 12.0; // push from alpha==0.5
private double alpha_push_neutral = 0.8; // alpha point from which push (closer to opaque)
private double alpha_push_center = 1.5; // weight of center alpha pixel relative to each of the 4 ortho ones
private double 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
private boolean alpha_en_holes = true; // Search for small semi-transparent holes, disable diffusion of local alpha minimums
private double alpha_diff_hole = 0.01; // minimal alpha difference between min and max neighbor to be considered a hole
private double w_alpha_neib = 0.7; // weight of each of the neighbors relative to the center when calculating average alpha
private double holes_pwr = 2.0; // Raise alpha (0..1) to this power when replacing vegetation cold spots with holes
private boolean from_file = false;
private double terr_lpf = 0;
private double veget_lpf = 0;
private double elevation_lpf = 0;
private boolean [] lpf_fixed = {true, true,true, true, true}; // using Laplacian to lpf parameters, pull to fixed ones too
// private double terr_difference = 100; // pull vegetation to be this warmer
// @Deprecated
// private double terr_pull_cold = 0; // pull vegetations to warm, terrain to cold
// Parameters saved/resored in a file
private final int num_scenes; // (+)
private Rectangle woi = null; // (+)
private Rectangle woi_veg = null; // (*) extended woi to include offset vegetation
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_offset = 0; // (+) if >0, start losses above 0.0 and below 1.0;
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
private double alpha_push = 12.0; // (+) push from alpha==0.5
private double alpha_push_neutral = 0.8; // (+) alpha point from which push (closer to opaque)
private double alpha_push_center = 1.5; // (+) weight of center alpha pixel relative to each of the 4 ortho ones
private double 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
private boolean alpha_en_holes = true; // (+) Search for small semi-transparent holes, disable diffusion of local alpha minimums
private double alpha_diff_hole = 0.01; // (+) minimal alpha difference between min and max neighbor to be considered a hole
private double w_alpha_neib = 0.7; // (*) weight of each of the neighbors relative to the center when calculating average alpha
private double holes_pwr = 2.0; // (*) Raise alpha (0..1) to this power when replacing vegetation cold spots with holes
private double terr_lpf = 0; // (+)
private double veget_lpf = 0; // (+)
private double elevation_lpf = 0; // (*)
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 veget_pull0 = 0; // now - pull to vegetation_pull (extended vegetation)
public double elevation_pull0 = 0; // now - pull to initial elevation
private double scenes_pull0 = 0; // pull average scene offset to 0;
private boolean use_scenes_pull0 = true; // derivative, set in setWeights
// private boolean use_y_avg = true; // derivative, set in setWeights
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;
public double um_sigma = 0; // just use in debug image names
public double um_weight = 0;
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
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_vegetation_alpha), each has 4 ortho neibs, -1 - border, >= 0
// - parameter index, <=-2 -2-full_pixel_index
public int [][] terr_neibs; // corresponds to parameters for terrain, for smoothing undefined terrain, similar to alpha_neibs
public int [][] veget_neibs; // corresponds to parameters for vegetation, for smoothing undefined vegetation, similar to alpha_neibs
public int [][] elevation_neibs; // corresponds to parameters for elevation, for smoothing undefined elevations, similar to alpha_neibs
public int [][] neibs_neibs;
public double delta= 1e-5; // 7;
private boolean from_file = false;
public boolean show_extra = true; // show extra samples
public int debug_index;
public int debug_iter; // LMA iteration for images
......@@ -242,12 +190,6 @@ public class VegetationLMA {
private double [] initial_rms = null; // {rms, rms_pure}, first-calcualted rms
private double [] last_ymfx = null;
private double [][] last_jt = null;
public boolean skip_ref_scene = false;
public boolean debug_deriv = true;
public int debug_width = 12;
public int debug_decimals = 9;
public VegetationLMA (
int width,
......@@ -259,10 +201,10 @@ public class VegetationLMA {
) {
full = new Rectangle(0,0,width, terrain_average.length/width);
image_length = terrain_average.length;
diff_offsets = diff_mode;
// diff_offsets = diff_mode;
num_scenes = vegetation_offsets.length;
this.vegetation_average = vegetation_average;
this.vegetation_filtered= vegetation_average; // obsolete
// this.vegetation_filtered= vegetation_average; // obsolete
this.terrain_average = terrain_average;
this.terrain_rendered = terrain_rendered;
this.vegetation_offsets = vegetation_offsets;
......@@ -280,12 +222,11 @@ public class VegetationLMA {
public VegetationLMA (
VegetationModel vegetationModel,
double alpha_initial_contrast) {
this.alpha_initial_contrast = alpha_initial_contrast;
// this.alpha_initial_contrast = alpha_initial_contrast;
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_filtered=vegetationModel.vegetation_filtered; // same with more NaNs for initial selection
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;
......@@ -300,13 +241,48 @@ public class VegetationLMA {
vegetationModel.vegetation_pull, // double [] vegetation_extended,
vegetationModel.vegetation_full); // double [] vegetation) { // best guess
setupLaplacians(0.0); // double weight_diag)
diff_offsets = vegetationModel.diff_mode;
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();
return;
}
public VegetationLMA (
String path,
VegetationModel vegetationModel,
double alpha_initial_contrast) {
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
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) {
final int num_scenes = scales_mag_dir.length;
......@@ -414,15 +390,6 @@ public class VegetationLMA {
final Rectangle woi,
final double max_warp, // 1.8 - do not use scenes where distance between vegetation projection exceeds this
final int max_offset, // maximal "elevation" to consider
// final int min_total_scenes,
// final int min_samples_scene, // 10
// final int min_valid_pixels,
// final boolean start_warm_veget, // start with vegetation warmer than terrain -> USED now by vegetation_filtered
// final double terrain_warmest, // warmest terrain (above is initially vegetation) NOT USED
// final double initial_split, // initial alpha: terrain 0.0+, vegetation 1.0-. USED
// final double min_split_frac, // minimal modality fraction to use split by temperature NOT USED?
final double terr_difference, // pull vegetation to be this warmer
final double terr_pull_cold, // pull vegetation to warm, terrain to cold
final double elevation_radius, //Radius of elevation/vegetation influence.
final double default_alpha,
final double hifreq_weight, // 22.5 0 - do not use high-freq. Relative weight of laplacian components
......@@ -458,16 +425,6 @@ public class VegetationLMA {
String parameters_read_path,
final int debugLevel) {
this.woi = woi;
this.max_warp = max_warp;
// this.min_dependent_scenes = min_dependent_scenes;
this.max_offset = max_offset;
// double alpha_contrast = 1.0;
// this.start_warm_veget = start_warm_veget;
// this.terrain_warmest = terrain_warmest;
// this.initial_split = initial_split;
// this.min_split_frac = min_split_frac;
this.terr_difference = terr_difference;
this.terr_pull_cold = terr_pull_cold;
this.hifreq_weight = hifreq_weight; // 22.5 0 - do not use high-freq. Relative weight of laplacian components
this.terrain_correction = terrain_correction;
fits = new boolean[TVAO_TYPES];
......@@ -496,8 +453,8 @@ public class VegetationLMA {
this.elevation_pull0 = elev_pull0;
this.scenes_pull0 = scenes_pull0;
this.boost_parallax = boost_parallax;
this.um_sigma = um_sigma; // just use in debug image names
this.um_weight = um_weight;
// this.um_sigma = um_sigma; // just use in debug image names
// this.um_weight = um_weight;
this.elev_radius = new double[full.width*full.height];
Arrays.fill(elev_radius, elevation_radius); // 5);
......@@ -1168,15 +1125,12 @@ public class VegetationLMA {
// alpha_en_holes -> alpha_mm_hole = NaN;
// hifreq_weight
String debug_title = "parameters_vector-x"+woi.x+"-y"+woi.y+"-w"+woi.width+"-h"+woi.height;
debug_title += "-hf"+hifreq_weight;
debug_title += "-hf"+hifreq_weight+"-tc"+terrain_correction;
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+"-tp"+terr_pull0+"-vp"+veget_pull0;
debug_title += "-bp"+boost_parallax;
debug_title += "-tl"+terr_lpf+"-vl"+veget_lpf+"-el"+elevation_lpf+"-tp"+terr_pull0+"-vp"+veget_pull0+"-ep"+elevation_pull0;
debug_title += "-sp"+scenes_pull0+"-ss"+scale_scenes_pull+"-bp"+boost_parallax;
debug_title += from_file?"-file":"-new";
if (um_weight > 0) {
debug_title +="-um"+um_sigma+"_"+um_weight;
}
return debug_title;
}
......@@ -1380,15 +1334,15 @@ public class VegetationLMA {
vector); // final double [] vector)
double [][] terrain_weights_max;
if (tvas== null) { // just temporary
terrain_weights_max = getTerrainWeights(
threshold_terrain, // final double alpha_threshold, // discard images with too low transparency
vector); // final double [] vector)
} else {
// if (tvas== null) { // just temporary
// terrain_weights_max = getTerrainWeights(
// threshold_terrain, // final double alpha_threshold, // discard images with too low transparency
// vector); // final double [] vector)
// } else {
terrain_weights_max = new double [2][woi_veg.width * woi_veg.height];
Arrays.fill(terrain_weights_max[0],0.1);
Arrays.fill(terrain_weights_max[1],0.9);
}
// }
double [] terrain_masked = tvas[0].clone();
double [] vegetation_masked = tvas[1].clone();
......@@ -1504,7 +1458,7 @@ public class VegetationLMA {
}
/*
@Deprecated
private double [][] getTerrainWeights( // FIXME !
final double alpha_threshold, // discard images with too low transparency
......@@ -1522,8 +1476,8 @@ public class VegetationLMA {
public void run() {
double [] alpha = new double [4];
for (int n = ai.getAndIncrement(); n < y_vector.length; n = ai.getAndIncrement()) {
int nscene = data_source[n][0][0];
int indx = data_source[n][0][1];
int nscene = y_src[n][YSRC_SCENE];
int indx = y_src[n][YSRC_FINDEX];
int x = indx % full.width - woi_veg.x;
int y = indx / full.width - woi_veg.y;
int windx = x + y * woi_veg.width;
......@@ -1575,6 +1529,7 @@ public class VegetationLMA {
// regularization weights and derivatives
return terrain_weights;
}
*/
private void setupElevationLMA( // return pivot?
final double [] vector,
......@@ -2544,16 +2499,6 @@ public class VegetationLMA {
if (samples_pointers[SAMPLES_Y_AVG][1]>0) { //
final double [][] fX_avg_thread = new double [threads.length][woi_length];
final double [][][] jt_avg_thread = (jt != null) ? new double [threads.length][jt.length][woi_length] : null;
/*
final double [] norm_scene_weights = new double [num_scenes];
double sw = 0;
for (int nscene = 0; nscene < num_scenes; nscene++) if (valid_scenes[nscene]) {
sw += scene_weights[nscene];
}
for (int nscene = 0; nscene < num_scenes; nscene++) if (valid_scenes[nscene]) {
norm_scene_weights[nscene] = scene_weights[nscene]/sw;
}
*/
final boolean debug_print = (debug_level >100);
ai.set(0);
ati.set(0);
......@@ -3602,20 +3547,18 @@ public class VegetationLMA {
String dir,
String title, // no .par-tiff
double [] vector) {
int woi_length = woi.width*woi.height;
int woi_length = woi_veg.width*woi_veg.height;
int ext_length = woi_length;
if (vector == null) {
vector = parameters_vector;
}
int height = woi.height;
int height = woi_veg.height;
if (num_scenes > woi_length) { // very unlikely but still may happen
height = (num_scenes + woi.width - 1) / woi.width;
ext_length = woi.width * height;
height = (num_scenes + woi_veg.width - 1) / woi_veg.width;
ext_length = woi_veg.width * height;
}
// assuming
// int [] save_types = {TVAO_TERRAIN, TVAO_VEGETATION, TVAO_ALPHA, TVAO_SCENE_OFFSET};
String [] titles = {"terrain","vegetation","alpha","elevation", "offset","terrain-index","vegetation-index","alpha-index","elevation-index", "offset-index"};
double [][] data = new double [titles.length][ext_length];
for (int i = 0; i < TVAO_TYPES; i++) Arrays.fill(data[i],Double.NaN);
......@@ -3624,31 +3567,18 @@ public class VegetationLMA {
for (int i = 0; (i < indices[n].length) && (i < par_index[n].length); i++) {
int indx = i;
if (n < TVAO_SCENE_OFFSET) {
int w = i % woi.width;
int h = i / woi.width;
indx = (h + woi.y) * full.width + (w + woi.x);
int w = i % woi_veg.width;
int h = i / woi_veg.width;
indx = (h + woi_veg.y) * full.width + (w + woi_veg.x);
}
int pindx = par_index[n][indx];
indices[n][i] = pindx;
if (pindx < 0) {
// if (n == TVAO_SCENE_OFFSET) {
// data[n][i] = Double.NaN;
// } else {
if (tvao[n] == null) {
data[n][i] = Double.NaN;
} else {
data[n][i] = tvao[n][indx];
}
/*
if (data[n] == null) {
System.out.println("data["+n+"] == null");
}
if (tvao[n] == null) {
System.out.println("tvao["+n+"] == null");
}
data[n][i] = tvao[n][indx];
// }
*/
} else {
data[n][i] = vector[pindx];
}
......@@ -3658,10 +3588,15 @@ public class VegetationLMA {
}
ImagePlus imp = ShowDoubleFloatArrays.makeArrays(
data,
woi.width,
woi_veg.width,
height,
title, // +"-objects_"+scene_num,
titles); // test_titles,
imp.setProperty("NUM_SCENES", ""+num_scenes);
imp.setProperty("WOI_VEG_X", ""+woi_veg.x);
imp.setProperty("WOI_VEG_Y", ""+woi_veg.y);
imp.setProperty("WOI_VEG_WIDTH", ""+woi_veg.width);
imp.setProperty("WOI_VEG_HEIGHT", ""+woi_veg.height);
imp.setProperty("WOI_X", ""+woi.x);
imp.setProperty("WOI_Y", ""+woi.y);
imp.setProperty("WOI_WIDTH", ""+woi.width);
......@@ -3669,20 +3604,13 @@ public class VegetationLMA {
imp.setProperty("FULL_WIDTH", ""+full.width);
imp.setProperty("FULL_HEIGHT", ""+full.height);
imp.setProperty("NUM_SCENES", ""+num_scenes);
imp.setProperty("DIFF_OFFSETS", ""+diff_offsets);
imp.setProperty("NUM_PARS_TERRAIN", ""+num_pars_terrain);
imp.setProperty("NUM_PARS_VEGETATION", ""+num_pars_vegetation);
imp.setProperty("NUM_PARS_VEGETATION_ALPHA", ""+num_pars_alpha);
imp.setProperty("NUM_PARS_SCENES", ""+num_pars_scenes);
imp.setProperty("IND_PARS_TERRAIN", ""+ind_pars_terrain);
imp.setProperty("IND_PARS_VEGETATION", ""+ind_pars_vegetation);
imp.setProperty("IND_PARS_VEGETATION_ALPHA", ""+ind_pars_alpha);
imp.setProperty("IND_PARS_SCENES", ""+ind_pars_scenes);
imp.setProperty("HIGHFREQ_WEIGHT", ""+hifreq_weight);
imp.setProperty("REG_WEIGHTS", ""+reg_weights);
imp.setProperty("FIT_TERRAIN", ""+fits[TVAO_TERRAIN]);
imp.setProperty("FIT_VEGETATION", ""+fits[TVAO_VEGETATION]);
imp.setProperty("FIT_ALPHA", ""+fits[TVAO_ALPHA]);
imp.setProperty("FIT_ELEVATION", ""+fits[TVAO_ELEVATION]);
imp.setProperty("FIT_SCENE_OFFSET", ""+fits[TVAO_SCENE_OFFSET]);
imp.setProperty("ALPHA_LOSS", ""+alpha_loss);
imp.setProperty("ALPHA_OFFSET", ""+alpha_offset);
imp.setProperty("ALPHA_LPF", ""+alpha_lpf);
......@@ -3691,16 +3619,45 @@ public class VegetationLMA {
imp.setProperty("ALPHA_PUSH", ""+alpha_push);
imp.setProperty("ALPHA_PUSH_NEUTRAL", ""+alpha_push_neutral);
imp.setProperty("ALPHA_PUSH_CENTER", ""+alpha_push_center );
imp.setProperty("ALPHA_EN_HOLES", ""+alpha_en_holes );
imp.setProperty("ALPHA_MM_HOLE", ""+alpha_mm_hole);
imp.setProperty("ALPHA_EN_HOLES", ""+alpha_en_holes );
imp.setProperty("ALPHA_DIFF_HOLE", ""+alpha_diff_hole);
imp.setProperty("W_ALPHA_NEIB", ""+w_alpha_neib);
imp.setProperty("HOLES_PWR", ""+holes_pwr);
imp.setProperty("TERR_LPF", ""+terr_lpf);
imp.setProperty("VEGET_LPF", ""+veget_lpf);
imp.setProperty("ELEVATION_LPF", ""+elevation_lpf);
imp.setProperty("LPF_FIXED_TERRAIN", ""+lpf_fixed[TVAO_TERRAIN]);
imp.setProperty("LPF_FIXED_VEGETATION", ""+lpf_fixed[TVAO_VEGETATION]);
imp.setProperty("LPF_FIXED_ALPHA", ""+lpf_fixed[TVAO_ALPHA]);
imp.setProperty("LPF_FIXED_ELEVATION", ""+lpf_fixed[TVAO_ELEVATION]);
imp.setProperty("LPF_FIXED_SCENE_OFFSET", ""+lpf_fixed[TVAO_SCENE_OFFSET]);
imp.setProperty("TERR_PULL0", ""+terr_pull0);
imp.setProperty("VEGET_PULL0", ""+veget_pull0);
imp.setProperty("ELEVATION_PULL0", ""+elevation_pull0);
imp.setProperty("SCENES_PULL0", ""+scenes_pull0);
imp.setProperty("SCALE_SCENES_PULL", ""+scale_scenes_pull);
imp.setProperty("BOOST_PARALLAX", ""+boost_parallax);
imp.setProperty("UM_SIGMA", ""+um_sigma);
imp.setProperty("UM_WEIGHT", ""+um_weight);
imp.setProperty("NUM_PARS_TERRAIN", ""+num_pars_terrain);
imp.setProperty("NUM_PARS_VEGETATION", ""+num_pars_vegetation);
imp.setProperty("NUM_PARS_ALPHA", ""+num_pars_alpha);
imp.setProperty("NUM_PARS_ELEVATION", ""+num_pars_elevation);
imp.setProperty("NUM_PARS_SCENES", ""+num_pars_scenes);
imp.setProperty("IND_PARS_TERRAIN", ""+ind_pars_terrain);
imp.setProperty("IND_PARS_VEGETATION", ""+ind_pars_vegetation);
imp.setProperty("IND_PARS_ALPHA", ""+ind_pars_alpha);
imp.setProperty("IND_PARS_ELEVATION", ""+ind_pars_elevation);
imp.setProperty("IND_PARS_SCENES", ""+ind_pars_scenes);
// samples_pointers
for (int nsp = 0; nsp < SAMPLES_SIZE; nsp++) {
for (int i = 0; i < samples_pointers[nsp].length; i++) {
imp.setProperty("SAMPLES_POINTERS_"+nsp+"_"+i, ""+samples_pointers[nsp][i]);
}
}
String path = getSavePath(
dir, // String dir,
title); // String title)
......@@ -3711,7 +3668,7 @@ public class VegetationLMA {
return;
}
public int getSaveIndex(int tvao_type) {
public static int getSaveIndex(int tvao_type) {
for (int i = 0; i < SAVE_TYPES.length; i++) {
if (SAVE_TYPES[i] == tvao_type) return i;
......@@ -3721,43 +3678,34 @@ public class VegetationLMA {
public double [][] restoreParametersFile( //FIXME: Not finished for real import !
String path,
Rectangle file_woi) {// if not null, will return woi data and not input parameters to this instance
String path,
boolean keep_settings,
Rectangle [] file_wois){ // if not null, should be Rectangle[2] {woi_veg,woi} - will return woi data and not input parameters to this instance
ImagePlus imp_pars = new ImagePlus (path);
if (imp_pars.getWidth()==0) {
throw new IllegalArgumentException("Could not read "+path);
}
int num_slices = imp_pars.getStack().getSize();
boolean no_elevation = num_slices == 8;
boolean has_elevation = num_slices == 10;
if (!no_elevation && !has_elevation) {
throw new IllegalArgumentException("Expecting an 10- or 8-slice file, got "+num_slices);
if (num_slices != 10) {
throw new IllegalArgumentException("Expecting an 10-slice file, got "+num_slices);
}
int num_types = has_elevation? 5 : 4;
int width = imp_pars.getWidth();
int height = imp_pars.getHeight();
int width = imp_pars