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 ...@@ -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_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_model_state = "1697877487_245877-TERR-VEG-STATE";
public String terr_segments_dir = "sections"; 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 // terrain/vegetation parameters
public boolean terr_um_en = true; public boolean terr_um_en = true;
public double terr_um_sigma = 1.0; public double terr_um_sigma = 1.0;
...@@ -1995,7 +1998,11 @@ min_str_neib_fpn 0.35 ...@@ -1995,7 +1998,11 @@ min_str_neib_fpn 0.35
gd.addTab("Vegetation","See through foliage parameters"); gd.addTab("Vegetation","See through foliage parameters");
gd.addStringField ("Model path", terr_model_path, 120, "Model directory path with version."); 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 ("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 ("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.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."); gd.addCheckbox ("Enable UM", terr_um_en, "Enable unsharp mask filter.");
...@@ -2717,19 +2724,24 @@ min_str_neib_fpn 0.35 ...@@ -2717,19 +2724,24 @@ min_str_neib_fpn 0.35
terr_model_path = gd.getNextString(); terr_model_path = gd.getNextString();
terr_model_state = gd.getNextString(); terr_model_state = gd.getNextString();
terr_segments_dir = gd.getNextString(); terr_segments_dir = gd.getNextString();
terr_um_en = gd.getNextBoolean();// boolean
terr_um_sigma = gd.getNextNumber();// double terr_par_dir = gd.getNextString();
terr_um_weight = gd.getNextNumber();// double terr_par_file = gd.getNextString();
terr_nan_tolerance = gd.getNextNumber();// double terr_par_restore = gd.getNextBoolean(); // boolean
terr_nan_grow = (int) gd.getNextNumber();// int
terr_um_en = gd.getNextBoolean(); // boolean
terr_shrink_veget = (int) gd.getNextNumber();// int terr_um_sigma = gd.getNextNumber(); // double
terr_shrink_terrain =(int) gd.getNextNumber();// int terr_um_weight = gd.getNextNumber(); // double
terr_vegetation_over = gd.getNextNumber();// double terr_nan_tolerance = gd.getNextNumber(); // double
terr_filter_veget = (int) gd.getNextNumber();// int terr_nan_grow = (int) gd.getNextNumber(); // int
terr_tile_woi = gd.getNextBoolean();// boolean terr_shrink_veget = (int) gd.getNextNumber(); // int
terr_continue = gd.getNextBoolean();// boolean 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_enclos = stringToRectangle(gd.getNextString());// Rectangle
terr_woi_step = stringToRectangle(gd.getNextString());// Rectangle terr_woi_step = stringToRectangle(gd.getNextString());// Rectangle
terr_woi_last = stringToRectangle(gd.getNextString());// Rectangle terr_woi_last = stringToRectangle(gd.getNextString());// Rectangle
...@@ -3395,6 +3407,10 @@ min_str_neib_fpn 0.35 ...@@ -3395,6 +3407,10 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"terr_model_state", terr_model_state+""); // String properties.setProperty(prefix+"terr_model_state", terr_model_state+""); // String
properties.setProperty(prefix+"terr_segments_dir", terr_segments_dir+""); // 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_en", terr_um_en+""); // boolean
properties.setProperty(prefix+"terr_um_sigma", terr_um_sigma+""); // double properties.setProperty(prefix+"terr_um_sigma", terr_um_sigma+""); // double
properties.setProperty(prefix+"terr_um_weight", terr_um_weight+""); // double properties.setProperty(prefix+"terr_um_weight", terr_um_weight+""); // double
...@@ -4095,6 +4111,10 @@ min_str_neib_fpn 0.35 ...@@ -4095,6 +4111,10 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"terr_model_state")!= null) terr_model_state=(String) properties.getProperty(prefix+"terr_model_state"); 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_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_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")); if (properties.getProperty(prefix+"terr_um_sigma")!= null) terr_um_sigma=Double.parseDouble(properties.getProperty(prefix+"terr_um_sigma"));
if (properties.getProperty(prefix+"terr_um_weight")!= null) terr_um_weight=Double.parseDouble(properties.getProperty(prefix+"terr_um_weight")); if (properties.getProperty(prefix+"terr_um_weight")!= null) terr_um_weight=Double.parseDouble(properties.getProperty(prefix+"terr_um_weight"));
...@@ -4762,6 +4782,10 @@ min_str_neib_fpn 0.35 ...@@ -4762,6 +4782,10 @@ min_str_neib_fpn 0.35
imp.terr_model_state = this. terr_model_state; imp.terr_model_state = this. terr_model_state;
imp.terr_segments_dir = this. terr_segments_dir; 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_en = this.terr_um_en;
imp.terr_um_sigma = this.terr_um_sigma; imp.terr_um_sigma = this.terr_um_sigma;
imp.terr_um_weight = this.terr_um_weight; imp.terr_um_weight = this.terr_um_weight;
......
...@@ -58,48 +58,21 @@ public class VegetationLMA { ...@@ -58,48 +58,21 @@ public class VegetationLMA {
public static final int SAMPLES_SIZE = SAMPLES_TOTAL+1; 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 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}; public static final int [] SAVE_TYPES = {TVAO_TERRAIN, TVAO_VEGETATION, TVAO_ALPHA, TVAO_ELEVATION, TVAO_SCENE_OFFSET};
private final Rectangle full; private final Rectangle full;
private final int image_length; 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? // should be non-null everywhere where elevation is defined?
private double [] vegetation_average; // full image average vegetation (with nulls) 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 [] 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_average; // full image average terrain (no nulls)
private double [][] terrain_rendered; // terrain rendered for scenes (has nulls) private double [][] terrain_rendered; // terrain rendered for scenes (has nulls)
private double [][] terrain_rendered_hf; // 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 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 // 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, public double [][] tvao; // [0][image_length] - terrain, [1][image_length] - vegetation,
private double [][][] scales_xy; // [scene][pixel{scale_x,scale_y} private double [][][] scales_xy; // [scene][pixel{scale_x,scale_y}
private VegetationModel vegetationModel = null; 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_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 [][] par_rindex; // parameter -> pair of type (0..4) and full window pixel index
private int num_pars_terrain; private int num_pars_terrain;
...@@ -137,24 +110,11 @@ public class VegetationLMA { ...@@ -137,24 +110,11 @@ public class VegetationLMA {
private boolean [][] param_pivot; // [all_pars][all_pars] which parameters parameters have common dependents 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 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 [] 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 [] overlaid = null; // [woi.width*woi.height] this valid terrain pixel is overlaid by vegetation (in all valid scenes)
private boolean [] valid_vegetation = null; private boolean [] valid_vegetation = null;
private double [][][] warps = null; // measure of horizontal and vertical distances between the vegetation projections - use to filter scenes 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 final double [] scene_weights;
private boolean [] valid_scenes; private boolean [] valid_scenes;
...@@ -167,66 +127,54 @@ public class VegetationLMA { ...@@ -167,66 +127,54 @@ public class VegetationLMA {
// private double terrain_warmest = 90; // pull vegetations to warm, terrain to cold // 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 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 min_split_frac = 0.15; // minimal modality fraction to use split by temperature
private double terr_difference = 100; // pull vegetation to be this warmer // private double terr_difference = 100; // pull vegetation to be this warmer
@Deprecated // @Deprecated
private double terr_pull_cold = 0; // pull vegetations to warm, terrain to cold // 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 // Parameters saved/resored in a file
private double reg_weights; // fraction of the total weight used for regularization private final int num_scenes; // (+)
private Rectangle woi = null; // (+)
private boolean [] fits; 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 alpha_initial_contrast = 1.0; // >=1.0 private double reg_weights; // (+) fraction of the total weight used for regularization
private double alpha_loss = 0; // not used with cosine alpha private boolean [] fits; // (+)
private double alpha_offset = 0; // if >0, start losses above 0.0 and below 1.0; private double alpha_loss = 0; // (+) not used with cosine alpha
private double alpha_lpf = 0; private double alpha_offset = 0; // (+) if >0, start losses above 0.0 and below 1.0;
private boolean alpha_piece_linear = true; private double alpha_lpf = 0; // (+)
private double alpha_scale_avg = 1.0; // 1.1; // scale average alpha (around 0.5) when pulling to it private boolean alpha_piece_linear = true; // (+)
private double alpha_push = 12.0; // push from alpha==0.5 private double alpha_scale_avg = 1.0; // (+) 1.1; // scale average alpha (around 0.5) when pulling to it
private double alpha_push_neutral = 0.8; // alpha point from which push (closer to opaque) private double alpha_push = 12.0; // (+) push from alpha==0.5
private double alpha_push_center = 1.5; // weight of center alpha pixel relative to each of the 4 ortho ones private double alpha_push_neutral = 0.8; // (+) alpha point from which push (closer to opaque)
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 double alpha_push_center = 1.5; // (+) weight of center alpha pixel relative to each of the 4 ortho ones
private boolean alpha_en_holes = true; // Search for small semi-transparent holes, disable diffusion of local alpha minimums 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 double alpha_diff_hole = 0.01; // minimal alpha difference between min and max neighbor to be considered a hole 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 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 holes_pwr = 2.0; // (*) Raise alpha (0..1) to this power when replacing vegetation cold spots with holes
private double terr_lpf = 0; // (+)
private boolean from_file = false; 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_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 // 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_pull0 = 0; // (+) now - pull to filled terrain - terrain_average
private double veget_pull0 = 0; // now - pull to vegetation_pull (extended vegetation) private double veget_pull0 = 0; // (+) now - pull to vegetation_pull (extended vegetation)
public double elevation_pull0 = 0; // now - pull to initial elevation public double elevation_pull0 = 0; // (*) now - pull to initial elevation
private double scenes_pull0 = 0; // pull average scene offset to 0; private double scenes_pull0 = 0; // (*) pull average scene offset to 0;
private boolean use_scenes_pull0 = 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
// private boolean use_y_avg = true; // derivative, set in setWeights public double boost_parallax = 1; // (+)
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;
// data used to calculate lpf pull of the alpha pixel to average of four neighbors. Below similar (weaker pull) for terrain and vegetation // 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. // 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 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 [][] 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 [][] 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 [][] elevation_neibs; // corresponds to parameters for elevation, for smoothing undefined elevations, similar to alpha_neibs
public int [][] neibs_neibs; public int [][] neibs_neibs;
public double delta= 1e-5; // 7; public double delta= 1e-5; // 7;
private boolean from_file = false;
public boolean show_extra = true; // show extra samples public boolean show_extra = true; // show extra samples
public int debug_index; public int debug_index;
public int debug_iter; // LMA iteration for images public int debug_iter; // LMA iteration for images
...@@ -243,12 +191,6 @@ public class VegetationLMA { ...@@ -243,12 +191,6 @@ public class VegetationLMA {
private double [] last_ymfx = null; private double [] last_ymfx = null;
private double [][] last_jt = 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 ( public VegetationLMA (
int width, int width,
boolean diff_mode, boolean diff_mode,
...@@ -259,10 +201,10 @@ public class VegetationLMA { ...@@ -259,10 +201,10 @@ public class VegetationLMA {
) { ) {
full = new Rectangle(0,0,width, terrain_average.length/width); full = new Rectangle(0,0,width, terrain_average.length/width);
image_length = terrain_average.length; image_length = terrain_average.length;
diff_offsets = diff_mode; // diff_offsets = diff_mode;
num_scenes = vegetation_offsets.length; num_scenes = vegetation_offsets.length;
this.vegetation_average = vegetation_average; this.vegetation_average = vegetation_average;
this.vegetation_filtered= vegetation_average; // obsolete // this.vegetation_filtered= vegetation_average; // obsolete
this.terrain_average = terrain_average; this.terrain_average = terrain_average;
this.terrain_rendered = terrain_rendered; this.terrain_rendered = terrain_rendered;
this.vegetation_offsets = vegetation_offsets; this.vegetation_offsets = vegetation_offsets;
...@@ -280,12 +222,11 @@ public class VegetationLMA { ...@@ -280,12 +222,11 @@ public class VegetationLMA {
public VegetationLMA ( public VegetationLMA (
VegetationModel vegetationModel, VegetationModel vegetationModel,
double alpha_initial_contrast) { double alpha_initial_contrast) {
this.alpha_initial_contrast = alpha_initial_contrast; // this.alpha_initial_contrast = alpha_initial_contrast;
full = vegetationModel.full; full = vegetationModel.full;
image_length = full.width * full.height; image_length = full.width * full.height;
num_scenes = vegetationModel.terrain_scenes_render.length; num_scenes = vegetationModel.terrain_scenes_render.length;
vegetation_average =vegetationModel.vegetation_full; // vegetation_average_render; 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 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_average = vegetationModel.terrain_filled; // terrain filled under vegetation, use to pull terrain level to it
terrain_rendered = vegetationModel.terrain_scenes_render; terrain_rendered = vegetationModel.terrain_scenes_render;
...@@ -300,13 +241,48 @@ public class VegetationLMA { ...@@ -300,13 +241,48 @@ public class VegetationLMA {
vegetationModel.vegetation_pull, // double [] vegetation_extended, vegetationModel.vegetation_pull, // double [] vegetation_extended,
vegetationModel.vegetation_full); // double [] vegetation) { // best guess vegetationModel.vegetation_full); // double [] vegetation) { // best guess
setupLaplacians(0.0); // double weight_diag) setupLaplacians(0.0); // double weight_diag)
diff_offsets = vegetationModel.diff_mode;
this.vegetationModel = vegetationModel; // to access scene names, directories, reference index this.vegetationModel = vegetationModel; // to access scene names, directories, reference index
scene_weights = new double [num_scenes]; scene_weights = new double [num_scenes];
scales_xy = getScalesXY(vegetationModel.scale_dirs); scales_xy = getScalesXY(vegetationModel.scale_dirs);
tvao[TVAO_ELEVATION] = vegetationModel.elevations.clone(); tvao[TVAO_ELEVATION] = vegetationModel.elevations.clone();
return; 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( private static double [][][] getScalesXY(
final double [][][] scales_mag_dir) { final double [][][] scales_mag_dir) {
final int num_scenes = scales_mag_dir.length; final int num_scenes = scales_mag_dir.length;
...@@ -414,15 +390,6 @@ public class VegetationLMA { ...@@ -414,15 +390,6 @@ public class VegetationLMA {
final Rectangle woi, final Rectangle woi,
final double max_warp, // 1.8 - do not use scenes where distance between vegetation projection exceeds this 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 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 elevation_radius, //Radius of elevation/vegetation influence.
final double default_alpha, final double default_alpha,
final double hifreq_weight, // 22.5 0 - do not use high-freq. Relative weight of laplacian components final double hifreq_weight, // 22.5 0 - do not use high-freq. Relative weight of laplacian components
...@@ -458,16 +425,6 @@ public class VegetationLMA { ...@@ -458,16 +425,6 @@ public class VegetationLMA {
String parameters_read_path, String parameters_read_path,
final int debugLevel) { final int debugLevel) {
this.woi = woi; 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.hifreq_weight = hifreq_weight; // 22.5 0 - do not use high-freq. Relative weight of laplacian components
this.terrain_correction = terrain_correction; this.terrain_correction = terrain_correction;
fits = new boolean[TVAO_TYPES]; fits = new boolean[TVAO_TYPES];
...@@ -496,8 +453,8 @@ public class VegetationLMA { ...@@ -496,8 +453,8 @@ public class VegetationLMA {
this.elevation_pull0 = elev_pull0; this.elevation_pull0 = elev_pull0;
this.scenes_pull0 = scenes_pull0; this.scenes_pull0 = scenes_pull0;
this.boost_parallax = boost_parallax; this.boost_parallax = boost_parallax;
this.um_sigma = um_sigma; // just use in debug image names // this.um_sigma = um_sigma; // just use in debug image names
this.um_weight = um_weight; // this.um_weight = um_weight;
this.elev_radius = new double[full.width*full.height]; this.elev_radius = new double[full.width*full.height];
Arrays.fill(elev_radius, elevation_radius); // 5); Arrays.fill(elev_radius, elevation_radius); // 5);
...@@ -1168,15 +1125,12 @@ public class VegetationLMA { ...@@ -1168,15 +1125,12 @@ public class VegetationLMA {
// alpha_en_holes -> alpha_mm_hole = NaN; // alpha_en_holes -> alpha_mm_hole = NaN;
// hifreq_weight // hifreq_weight
String debug_title = "parameters_vector-x"+woi.x+"-y"+woi.y+"-w"+woi.width+"-h"+woi.height; 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 += "-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 += "-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 += "-tl"+terr_lpf+"-vl"+veget_lpf+"-el"+elevation_lpf+"-tp"+terr_pull0+"-vp"+veget_pull0+"-ep"+elevation_pull0;
debug_title += "-bp"+boost_parallax; debug_title += "-sp"+scenes_pull0+"-ss"+scale_scenes_pull+"-bp"+boost_parallax;
debug_title += from_file?"-file":"-new"; debug_title += from_file?"-file":"-new";
if (um_weight > 0) {
debug_title +="-um"+um_sigma+"_"+um_weight;
}
return debug_title; return debug_title;
} }
...@@ -1380,15 +1334,15 @@ public class VegetationLMA { ...@@ -1380,15 +1334,15 @@ public class VegetationLMA {
vector); // final double [] vector) vector); // final double [] vector)
double [][] terrain_weights_max; double [][] terrain_weights_max;
if (tvas== null) { // just temporary // if (tvas== null) { // just temporary
terrain_weights_max = getTerrainWeights( // terrain_weights_max = getTerrainWeights(
threshold_terrain, // final double alpha_threshold, // discard images with too low transparency // threshold_terrain, // final double alpha_threshold, // discard images with too low transparency
vector); // final double [] vector) // vector); // final double [] vector)
} else { // } else {
terrain_weights_max = new double [2][woi_veg.width * woi_veg.height]; 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[0],0.1);
Arrays.fill(terrain_weights_max[1],0.9); Arrays.fill(terrain_weights_max[1],0.9);
} // }
double [] terrain_masked = tvas[0].clone(); double [] terrain_masked = tvas[0].clone();
double [] vegetation_masked = tvas[1].clone(); double [] vegetation_masked = tvas[1].clone();
...@@ -1504,7 +1458,7 @@ public class VegetationLMA { ...@@ -1504,7 +1458,7 @@ public class VegetationLMA {
} }
/*
@Deprecated @Deprecated
private double [][] getTerrainWeights( // FIXME ! private double [][] getTerrainWeights( // FIXME !
final double alpha_threshold, // discard images with too low transparency final double alpha_threshold, // discard images with too low transparency
...@@ -1522,8 +1476,8 @@ public class VegetationLMA { ...@@ -1522,8 +1476,8 @@ public class VegetationLMA {
public void run() { public void run() {
double [] alpha = new double [4]; double [] alpha = new double [4];
for (int n = ai.getAndIncrement(); n < y_vector.length; n = ai.getAndIncrement()) { for (int n = ai.getAndIncrement(); n < y_vector.length; n = ai.getAndIncrement()) {
int nscene = data_source[n][0][0]; int nscene = y_src[n][YSRC_SCENE];
int indx = data_source[n][0][1]; int indx = y_src[n][YSRC_FINDEX];
int x = indx % full.width - woi_veg.x; int x = indx % full.width - woi_veg.x;
int y = indx / full.width - woi_veg.y; int y = indx / full.width - woi_veg.y;
int windx = x + y * woi_veg.width; int windx = x + y * woi_veg.width;
...@@ -1575,6 +1529,7 @@ public class VegetationLMA { ...@@ -1575,6 +1529,7 @@ public class VegetationLMA {
// regularization weights and derivatives // regularization weights and derivatives
return terrain_weights; return terrain_weights;
} }
*/
private void setupElevationLMA( // return pivot? private void setupElevationLMA( // return pivot?
final double [] vector, final double [] vector,
...@@ -2544,16 +2499,6 @@ public class VegetationLMA { ...@@ -2544,16 +2499,6 @@ public class VegetationLMA {
if (samples_pointers[SAMPLES_Y_AVG][1]>0) { // if (samples_pointers[SAMPLES_Y_AVG][1]>0) { //
final double [][] fX_avg_thread = new double [threads.length][woi_length]; 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 [][][] 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); final boolean debug_print = (debug_level >100);
ai.set(0); ai.set(0);
ati.set(0); ati.set(0);
...@@ -3602,20 +3547,18 @@ public class VegetationLMA { ...@@ -3602,20 +3547,18 @@ public class VegetationLMA {
String dir, String dir,
String title, // no .par-tiff String title, // no .par-tiff
double [] vector) { double [] vector) {
int woi_length = woi.width*woi.height; int woi_length = woi_veg.width*woi_veg.height;
int ext_length = woi_length; int ext_length = woi_length;
if (vector == null) { if (vector == null) {
vector = parameters_vector; vector = parameters_vector;
} }
int height = woi.height; int height = woi_veg.height;
if (num_scenes > woi_length) { // very unlikely but still may happen if (num_scenes > woi_length) { // very unlikely but still may happen
height = (num_scenes + woi.width - 1) / woi.width; height = (num_scenes + woi_veg.width - 1) / woi_veg.width;
ext_length = woi.width * height; 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"}; 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]; double [][] data = new double [titles.length][ext_length];
for (int i = 0; i < TVAO_TYPES; i++) Arrays.fill(data[i],Double.NaN); for (int i = 0; i < TVAO_TYPES; i++) Arrays.fill(data[i],Double.NaN);
...@@ -3624,31 +3567,18 @@ public class VegetationLMA { ...@@ -3624,31 +3567,18 @@ public class VegetationLMA {
for (int i = 0; (i < indices[n].length) && (i < par_index[n].length); i++) { for (int i = 0; (i < indices[n].length) && (i < par_index[n].length); i++) {
int indx = i; int indx = i;
if (n < TVAO_SCENE_OFFSET) { if (n < TVAO_SCENE_OFFSET) {
int w = i % woi.width; int w = i % woi_veg.width;
int h = i / woi.width; int h = i / woi_veg.width;
indx = (h + woi.y) * full.width + (w + woi.x); indx = (h + woi_veg.y) * full.width + (w + woi_veg.x);
} }
int pindx = par_index[n][indx]; int pindx = par_index[n][indx];
indices[n][i] = pindx; indices[n][i] = pindx;
if (pindx < 0) { if (pindx < 0) {
// if (n == TVAO_SCENE_OFFSET) {
// data[n][i] = Double.NaN;
// } else {
if (tvao[n] == null) { if (tvao[n] == null) {
data[n][i] = Double.NaN; data[n][i] = Double.NaN;
} else { } else {
data[n][i] = tvao[n][indx]; 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 { } else {
data[n][i] = vector[pindx]; data[n][i] = vector[pindx];
} }
...@@ -3658,10 +3588,15 @@ public class VegetationLMA { ...@@ -3658,10 +3588,15 @@ public class VegetationLMA {
} }
ImagePlus imp = ShowDoubleFloatArrays.makeArrays( ImagePlus imp = ShowDoubleFloatArrays.makeArrays(
data, data,
woi.width, woi_veg.width,
height, height,
title, // +"-objects_"+scene_num, title, // +"-objects_"+scene_num,
titles); // test_titles, 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_X", ""+woi.x);
imp.setProperty("WOI_Y", ""+woi.y); imp.setProperty("WOI_Y", ""+woi.y);
imp.setProperty("WOI_WIDTH", ""+woi.width); imp.setProperty("WOI_WIDTH", ""+woi.width);
...@@ -3669,20 +3604,13 @@ public class VegetationLMA { ...@@ -3669,20 +3604,13 @@ public class VegetationLMA {
imp.setProperty("FULL_WIDTH", ""+full.width); imp.setProperty("FULL_WIDTH", ""+full.width);
imp.setProperty("FULL_HEIGHT", ""+full.height); 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("HIGHFREQ_WEIGHT", ""+hifreq_weight);
imp.setProperty("REG_WEIGHTS", ""+reg_weights); 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_LOSS", ""+alpha_loss);
imp.setProperty("ALPHA_OFFSET", ""+alpha_offset); imp.setProperty("ALPHA_OFFSET", ""+alpha_offset);
imp.setProperty("ALPHA_LPF", ""+alpha_lpf); imp.setProperty("ALPHA_LPF", ""+alpha_lpf);
...@@ -3691,16 +3619,45 @@ public class VegetationLMA { ...@@ -3691,16 +3619,45 @@ public class VegetationLMA {
imp.setProperty("ALPHA_PUSH", ""+alpha_push); imp.setProperty("ALPHA_PUSH", ""+alpha_push);
imp.setProperty("ALPHA_PUSH_NEUTRAL", ""+alpha_push_neutral); imp.setProperty("ALPHA_PUSH_NEUTRAL", ""+alpha_push_neutral);
imp.setProperty("ALPHA_PUSH_CENTER", ""+alpha_push_center ); 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_MM_HOLE", ""+alpha_mm_hole);
imp.setProperty("ALPHA_EN_HOLES", ""+alpha_en_holes );
imp.setProperty("ALPHA_DIFF_HOLE", ""+alpha_diff_hole); 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("TERR_LPF", ""+terr_lpf);
imp.setProperty("VEGET_LPF", ""+veget_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("TERR_PULL0", ""+terr_pull0);
imp.setProperty("VEGET_PULL0", ""+veget_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("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( String path = getSavePath(
dir, // String dir, dir, // String dir,
title); // String title) title); // String title)
...@@ -3711,7 +3668,7 @@ public class VegetationLMA { ...@@ -3711,7 +3668,7 @@ public class VegetationLMA {
return; return;
} }
public int getSaveIndex(int tvao_type) { public static int getSaveIndex(int tvao_type) {
for (int i = 0; i < SAVE_TYPES.length; i++) { for (int i = 0; i < SAVE_TYPES.length; i++) {
if (SAVE_TYPES[i] == tvao_type) return i; if (SAVE_TYPES[i] == tvao_type) return i;
...@@ -3722,41 +3679,32 @@ public class VegetationLMA { ...@@ -3722,41 +3679,32 @@ public class VegetationLMA {
public double [][] restoreParametersFile( //FIXME: Not finished for real import ! public double [][] restoreParametersFile( //FIXME: Not finished for real import !
String path, String path,
Rectangle file_woi) {// if not null, will return woi data and not input parameters to this instance 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); ImagePlus imp_pars = new ImagePlus (path);
if (imp_pars.getWidth()==0) { if (imp_pars.getWidth()==0) {
throw new IllegalArgumentException("Could not read "+path); throw new IllegalArgumentException("Could not read "+path);
} }
int num_slices = imp_pars.getStack().getSize(); int num_slices = imp_pars.getStack().getSize();
boolean no_elevation = num_slices == 8; if (num_slices != 10) {
boolean has_elevation = num_slices == 10; throw new IllegalArgumentException("Expecting an 10-slice file, got "+num_slices);
if (!no_elevation && !has_elevation) {
throw new IllegalArgumentException("Expecting an 10- or 8-slice file, got "+num_slices);
} }
int num_types = has_elevation? 5 : 4; int width = imp_pars.getWidth(); // woi_veg.width
int width = imp_pars.getWidth(); int height = imp_pars.getHeight(); // woi_veg.height
int height = imp_pars.getHeight();
double [][] data = new double[TVAO_TYPES][width*height]; double [][] data = new double[TVAO_TYPES][width*height];
int [][] indices = new int[TVAO_TYPES][width*height]; int [][] indices = new int[TVAO_TYPES][width*height];
for (int n = 0; n < num_types; n++) { for (int n = 0; n < TVAO_TYPES; n++) {
int nt = has_elevation ? n : SAVE_TYPES[n];
float [] pixels = (float[]) imp_pars.getStack().getPixels(n+1); float [] pixels = (float[]) imp_pars.getStack().getPixels(n+1);
for (int i = 0; i < data[n].length; i++) { for (int i = 0; i < data[n].length; i++) {
data[nt][i] = pixels[i]; data[n][i] = pixels[i];
} }
} }
for (int n = 0; n < num_types; n++) { for (int n = 0; n < TVAO_TYPES; n++) {
float [] pixels = (float[]) imp_pars.getStack().getPixels(n+1+ num_types); float [] pixels = (float[]) imp_pars.getStack().getPixels(n+1+ TVAO_TYPES);
int nt = has_elevation ? n : SAVE_TYPES[n];
for (int i = 0; i < data[n].length; i++) { for (int i = 0; i < data[n].length; i++) {
indices[nt][i] = (int) pixels[i]; indices[n][i] = (int) pixels[i];
} }
} }
if (!has_elevation) {
Arrays.fill(indices[TVAO_ELEVATION],-1);
Arrays.fill(data[TVAO_ELEVATION],Double.NaN);
}
JP46_Reader_camera.decodeProperiesFromInfo(imp_pars); JP46_Reader_camera.decodeProperiesFromInfo(imp_pars);
Rectangle full = new Rectangle ( Rectangle full = new Rectangle (
...@@ -3780,13 +3728,15 @@ public class VegetationLMA { ...@@ -3780,13 +3728,15 @@ public class VegetationLMA {
Integer.parseInt((String) imp_pars.getProperty("WOI_Y")), Integer.parseInt((String) imp_pars.getProperty("WOI_Y")),
Integer.parseInt((String) imp_pars.getProperty("WOI_WIDTH")), Integer.parseInt((String) imp_pars.getProperty("WOI_WIDTH")),
Integer.parseInt((String) imp_pars.getProperty("WOI_HEIGHT"))); Integer.parseInt((String) imp_pars.getProperty("WOI_HEIGHT")));
Rectangle woi_veg = new Rectangle (
if (file_woi != null) { Integer.parseInt((String) imp_pars.getProperty("WOI_VEG_X")),
file_woi.x = woi.x; Integer.parseInt((String) imp_pars.getProperty("WOI_VEG_Y")),
file_woi.y = woi.y; Integer.parseInt((String) imp_pars.getProperty("WOI_VEG_WIDTH")),
file_woi.width = woi.width; Integer.parseInt((String) imp_pars.getProperty("WOI_VEG_HEIGHT")));
file_woi.height = woi.height; if (file_wois != null) {
// Remove undefined values that were not adjusted for this woi file_wois[0] = woi_veg;
file_wois[1] = woi;
// Remove undefined values that were not adjusted for this woi
for (int n = 0; n < TVAO_TYPES; n++) { for (int n = 0; n < TVAO_TYPES; n++) {
for (int i = 0; i < data[n].length; i++) { for (int i = 0; i < data[n].length; i++) {
if (indices[n][i] < 0) { if (indices[n][i] < 0) {
...@@ -3794,12 +3744,9 @@ public class VegetationLMA { ...@@ -3794,12 +3744,9 @@ public class VegetationLMA {
} }
} }
} }
// Trim data to actiual // Trim data to actual
// int num_pars_scenes = Integer.parseInt((String) imp_pars.getProperty("NUM_PARS_SCENES"));
// double [] scene_offsets = new double [num_pars_scenes];
double [] scene_offsets = new double [num_scenes]; double [] scene_offsets = new double [num_scenes];
System.arraycopy(data[getSaveIndex(TVAO_SCENE_OFFSET)], 0, scene_offsets, 0, scene_offsets.length); System.arraycopy(data[getSaveIndex(TVAO_SCENE_OFFSET)], 0, scene_offsets, 0, scene_offsets.length);
// temporary patch, later they will be NaNs already - Already done !
for (int i = 0; i < scene_offsets.length; i++) { for (int i = 0; i < scene_offsets.length; i++) {
if (indices[TVAO_SCENE_OFFSET][i] < 0) { if (indices[TVAO_SCENE_OFFSET][i] < 0) {
data[TVAO_SCENE_OFFSET][i] = Double.NaN; data[TVAO_SCENE_OFFSET][i] = Double.NaN;
...@@ -3807,51 +3754,123 @@ public class VegetationLMA { ...@@ -3807,51 +3754,123 @@ public class VegetationLMA {
} }
for (int n = 0; n < SAVE_TYPES.length; n++) if (SAVE_TYPES[n] != TVAO_SCENE_OFFSET){ for (int n = 0; n < SAVE_TYPES.length; n++) if (SAVE_TYPES[n] != TVAO_SCENE_OFFSET){
if (woi.width * woi.height < data[n].length ) { if (woi_veg.width * woi_veg.height < data[n].length ) {
double [] d = new double [woi.width * woi.height]; double [] d = new double [woi_veg.width * woi_veg.height];
System.arraycopy(data[n], 0, d, 0, d.length); System.arraycopy(data[n], 0, d, 0, d.length);
data[n] = d; data[n] = d;
} }
} }
data[3] = scene_offsets; data[TVAO_SCENE_OFFSET] = scene_offsets;
} else { } else {
this.woi_veg = woi_veg;
this.woi = woi; this.woi = woi;
diff_offsets = Boolean.parseBoolean((String) imp_pars.getProperty("DIFF_OFFSETS")); if (!keep_settings) {
alpha_piece_linear = Boolean.parseBoolean((String) imp_pars.getProperty("ALPHA_PIECE_LINEAR")); hifreq_weight = Double.parseDouble((String) imp_pars.getProperty("HIGHFREQ_WEIGHT"));
num_pars_terrain = Integer.parseInt((String) imp_pars.getProperty("NUM_PARS_TERRAIN")); reg_weights = Double.parseDouble((String) imp_pars.getProperty("REG_WEIGHTS"));
num_pars_vegetation = Integer.parseInt((String) imp_pars.getProperty("NUM_PARS_VEGETATION")); fits = new boolean[TVAO_TYPES];
num_pars_alpha = Integer.parseInt((String) imp_pars.getProperty("NUM_PARS_VEGETATION_ALPHA")); fits[TVAO_TERRAIN] = Boolean.parseBoolean((String) imp_pars.getProperty("FIT_TERRAIN"));
num_pars_scenes = Integer.parseInt((String) imp_pars.getProperty("NUM_PARS_SCENES")); fits[TVAO_VEGETATION] = Boolean.parseBoolean((String) imp_pars.getProperty("FIT_VEGETATION"));
ind_pars_terrain = Integer.parseInt((String) imp_pars.getProperty("IND_PARS_TERRAIN")); fits[TVAO_ALPHA] = Boolean.parseBoolean((String) imp_pars.getProperty("FIT_ALPHA"));
ind_pars_vegetation = Integer.parseInt((String) imp_pars.getProperty("IND_PARS_VEGETATION")); fits[TVAO_ELEVATION] = Boolean.parseBoolean((String) imp_pars.getProperty("FIT_ELEVATION"));
ind_pars_alpha = Integer.parseInt((String) imp_pars.getProperty("IND_PARS_VEGETATION_ALPHA")); fits[TVAO_SCENE_OFFSET] = Boolean.parseBoolean((String) imp_pars.getProperty("FIT_SCENE_OFFSET"));
ind_pars_scenes = Integer.parseInt((String) imp_pars.getProperty("IND_PARS_SCENES"));
if (imp_pars.getProperty("HIGHFREQ_WEIGHT") != null) hifreq_weight = Double.parseDouble((String) imp_pars.getProperty("HIGHFREQ_WEIGHT"));
if (imp_pars.getProperty("REG_WEIGHTS") != null) reg_weights = Double.parseDouble((String) imp_pars.getProperty("REG_WEIGHTS"));
alpha_loss = Double.parseDouble((String) imp_pars.getProperty("ALPHA_LOSS")); alpha_loss = Double.parseDouble((String) imp_pars.getProperty("ALPHA_LOSS"));
alpha_offset = Double.parseDouble((String) imp_pars.getProperty("ALPHA_OFFSET")); alpha_offset = Double.parseDouble((String) imp_pars.getProperty("ALPHA_OFFSET"));
alpha_lpf = Double.parseDouble((String) imp_pars.getProperty("ALPHA_LPF")); alpha_lpf = Double.parseDouble((String) imp_pars.getProperty("ALPHA_LPF"));
alpha_piece_linear = Boolean.parseBoolean((String) imp_pars.getProperty("ALPHA_PIECE_LINEAR"));
alpha_scale_avg = Double.parseDouble((String) imp_pars.getProperty("ALPHA_SCALE_AVG")); alpha_scale_avg = Double.parseDouble((String) imp_pars.getProperty("ALPHA_SCALE_AVG"));
alpha_push = Double.parseDouble((String) imp_pars.getProperty("ALPHA_PUSH")); alpha_push = Double.parseDouble((String) imp_pars.getProperty("ALPHA_PUSH"));
alpha_push_neutral = Double.parseDouble((String) imp_pars.getProperty("ALPHA_PUSH_NEUTRAL")); alpha_push_neutral = Double.parseDouble((String) imp_pars.getProperty("ALPHA_PUSH_NEUTRAL"));
alpha_push_center = Double.parseDouble((String) imp_pars.getProperty("ALPHA_PUSH_CENTER")); alpha_push_center = Double.parseDouble((String) imp_pars.getProperty("ALPHA_PUSH_CENTER"));
if (imp_pars.getProperty("ALPHA_EN_HOLES") != null) alpha_en_holes = Boolean.parseBoolean((String) imp_pars.getProperty("ALPHA_EN_HOLES"));
alpha_mm_hole = Double.parseDouble((String) imp_pars.getProperty("ALPHA_MM_HOLE")); alpha_mm_hole = Double.parseDouble((String) imp_pars.getProperty("ALPHA_MM_HOLE"));
alpha_en_holes = Boolean.parseBoolean((String) imp_pars.getProperty("ALPHA_EN_HOLES"));
alpha_diff_hole = Double.parseDouble((String) imp_pars.getProperty("ALPHA_DIFF_HOLE")); alpha_diff_hole = Double.parseDouble((String) imp_pars.getProperty("ALPHA_DIFF_HOLE"));
w_alpha_neib = Double.parseDouble((String) imp_pars.getProperty("W_ALPHA_NEIB"));
holes_pwr = Double.parseDouble((String) imp_pars.getProperty("HOLES_PWR"));
terr_lpf = Double.parseDouble((String) imp_pars.getProperty("TERR_LPF")); terr_lpf = Double.parseDouble((String) imp_pars.getProperty("TERR_LPF"));
veget_lpf = Double.parseDouble((String) imp_pars.getProperty("VEGET_LPF")); veget_lpf = Double.parseDouble((String) imp_pars.getProperty("VEGET_LPF"));
elevation_lpf = Double.parseDouble((String) imp_pars.getProperty("ELEVATION_LPF"));
lpf_fixed = new boolean[TVAO_TYPES];
lpf_fixed[TVAO_TERRAIN] = Boolean.parseBoolean((String) imp_pars.getProperty("LPF_FIXED_TERRAIN"));
lpf_fixed[TVAO_VEGETATION] =Boolean.parseBoolean((String) imp_pars.getProperty("LPF_FIXED_VEGETATION"));
lpf_fixed[TVAO_ALPHA] = Boolean.parseBoolean((String) imp_pars.getProperty("LPF_FIXED_ALPHA"));
lpf_fixed[TVAO_ELEVATION] = Boolean.parseBoolean((String) imp_pars.getProperty("LPF_FIXED_ELEVATION"));
lpf_fixed[TVAO_SCENE_OFFSET]=Boolean.parseBoolean((String)imp_pars.getProperty("LPF_FIXED_SCENE_OFFSET"));
terr_pull0 = Double.parseDouble((String) imp_pars.getProperty("TERR_PULL0")); terr_pull0 = Double.parseDouble((String) imp_pars.getProperty("TERR_PULL0"));
veget_pull0 = Double.parseDouble((String) imp_pars.getProperty("VEGET_PULL0")); veget_pull0 = Double.parseDouble((String) imp_pars.getProperty("VEGET_PULL0"));
elevation_pull0 = Double.parseDouble((String) imp_pars.getProperty("ELEVATION_PULL0"));
scenes_pull0 = Double.parseDouble((String) imp_pars.getProperty("SCENES_PULL0"));
scale_scenes_pull = Double.parseDouble((String) imp_pars.getProperty("SCALE_SCENES_PULL"));
boost_parallax = Double.parseDouble((String) imp_pars.getProperty("BOOST_PARALLAX")); boost_parallax = Double.parseDouble((String) imp_pars.getProperty("BOOST_PARALLAX"));
um_sigma = Double.parseDouble((String) imp_pars.getProperty("UM_SIGMA")); }
um_weight = Double.parseDouble((String) imp_pars.getProperty("UM_WEIGHT")); num_pars_terrain = Integer.parseInt((String) imp_pars.getProperty("NUM_PARS_TERRAIN"));
// TODO: build other data structures and make instance consistent, without it this does not allow reading from file num_pars_vegetation = Integer.parseInt((String) imp_pars.getProperty("NUM_PARS_VEGETATION"));
num_pars_alpha = Integer.parseInt((String) imp_pars.getProperty("NUM_PARS_ALPHA"));
num_pars_elevation = Integer.parseInt((String) imp_pars.getProperty("NUM_PARS_ELEVATION"));
num_pars_scenes = Integer.parseInt((String) imp_pars.getProperty("NUM_PARS_SCENES"));
ind_pars_terrain = Integer.parseInt((String) imp_pars.getProperty("IND_PARS_TERRAIN"));
ind_pars_vegetation = Integer.parseInt((String) imp_pars.getProperty("IND_PARS_VEGETATION"));
ind_pars_alpha = Integer.parseInt((String) imp_pars.getProperty("IND_PARS_ALPHA"));
ind_pars_elevation = Integer.parseInt((String) imp_pars.getProperty("IND_PARS_ELEVATION"));
ind_pars_scenes = Integer.parseInt((String) imp_pars.getProperty("IND_PARS_SCENES"));
par_index = new int[TVAO_TYPES][];
for (int n = 0; n < par_index.length; n++) {
if (n < TVAO_SCENE_OFFSET) {
par_index[n] = new int[image_length];
} else {
par_index[n] = new int[num_scenes]; // same as when creating original
}
Arrays.fill(par_index[n], -1);
}
// 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
int [] par_nums = {
num_pars_terrain,
num_pars_vegetation,
num_pars_alpha,
num_pars_elevation,
num_pars_scenes};
/*
par_index[TVAO_TERRAIN] = new int [num_pars_terrain];
par_index[TVAO_VEGETATION] = new int [num_pars_vegetation];
par_index[TVAO_ALPHA] = new int [num_pars_alpha];
par_index[TVAO_ELEVATION] = new int [num_pars_elevation];
par_index[TVAO_SCENE_OFFSET] = new int [num_pars_scenes];
*/
samples_pointers = new int [SAMPLES_SIZE][3];
for (int nsp = 0; nsp < SAMPLES_SIZE; nsp++) {
for (int i = 0; i < samples_pointers[nsp].length; i++) {
samples_pointers[nsp][i] = Integer.parseInt((String) imp_pars.getProperty("SAMPLES_POINTERS_"+nsp+"_"+i));
}
}
// samples_pointers[SAMPLES_TOTAL][0] = total number of parameters
int num_pars = 0;
for (int n = 0; n < TVAO_TYPES; n++) {
num_pars += par_nums[n];
}
parameters_vector = new double [num_pars];
par_rindex = new int [num_pars][2];
for (int n = 0; n < TVAO_TYPES; n++) {
for (int indx = 0; ((indx < indices[n].length) && (indx < par_index[n].length)); indx++) { // woi_veg
int findx = indx;
int pindx = indices[n][indx];
if (n < TVAO_SCENE_OFFSET) {
int x = (indx % woi_veg.width) + woi_veg.x;
int y = (indx / woi_veg.width) + woi_veg.y;
findx = x + y * full.width;
}
par_index[n][findx] = pindx;
if (pindx >= 0) { // always? - not!
parameters_vector[pindx] = data[n][indx];
par_rindex[pindx][0] = n;
par_rindex[pindx][1] = findx;
}
}
}
// TODO: build other data structures and make instance consistent, without it this does not allow reading from file
} }
return data; return data;
} }
...@@ -3867,6 +3886,8 @@ public class VegetationLMA { ...@@ -3867,6 +3886,8 @@ public class VegetationLMA {
final double boost_parallax, // increase weights of scenes with high parallax relative to the reference one final double boost_parallax, // increase weights of scenes with high parallax relative to the reference one
final double max_parallax, final double max_parallax,
final int num_exaggerate) { // show amplified difference from filtering final int num_exaggerate) { // show amplified difference from filtering
//FIXME: Handle woi separately!
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX); final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0);
double ksigma = 1.0; double ksigma = 1.0;
...@@ -3877,15 +3898,15 @@ public class VegetationLMA { ...@@ -3877,15 +3898,15 @@ public class VegetationLMA {
String [] top_titles = {"terrain","vegetation","alpha"}; String [] top_titles = {"terrain","vegetation","alpha"};
String [] titles = new String[accum_indx+1]; String [] titles = new String[accum_indx+1];
for (int ns = 0; ns < segments.length; ns++) { for (int ns = 0; ns < segments.length; ns++) {
Rectangle woi = segments[ns].woi; Rectangle woi_veg = segments[ns].woi_veg;
titles[ns] = woi.toString(); titles[ns] = woi_veg.toString();
int woi_length = woi.width * woi.height; int woi_length = woi_veg.width * woi_veg.height;
double [][] woi_tva = segments[ns].tva; double [][] woi_tva = segments[ns].tva;
for (int t = 0; t < 3; t++) { for (int t = 0; t < 3; t++) {
Arrays.fill(preview_data[t][ns], Double.NaN); Arrays.fill(preview_data[t][ns], Double.NaN);
for (int windx = 0; windx < woi_length; windx++) { for (int windx = 0; windx < woi_length; windx++) {
int x = windx % woi.width + woi.x; int x = windx % woi_veg.width + woi_veg.x;
int y = windx / woi.width + woi.y; int y = windx / woi_veg.width + woi_veg.y;
int indx = x + y * full.width; int indx = x + y * full.width;
preview_data[t][ns][indx] = woi_tva[t][windx]; preview_data[t][ns][indx] = woi_tva[t][windx];
} }
...@@ -3895,13 +3916,13 @@ public class VegetationLMA { ...@@ -3895,13 +3916,13 @@ public class VegetationLMA {
double [][] sum_w = new double [preview_data.length][full_length]; double [][] sum_w = new double [preview_data.length][full_length];
double [][] sum_wd = new double [preview_data.length][full_length]; double [][] sum_wd = new double [preview_data.length][full_length];
for (int ns = 0; ns < segments.length; ns++) { for (int ns = 0; ns < segments.length; ns++) {
Rectangle woi = segments[ns].woi; Rectangle woi_veg = segments[ns].woi_veg;
int woi_length = woi.width*woi.height; int woi_length = woi_veg.width*woi_veg.height;
double [][] woi_tva = segments[ns].tva; double [][] woi_tva = segments[ns].tva;
double [] wnd = overlapCosineWindow (woi, width); double [] wnd = overlapCosineWindow (woi, width);
for (int windx = 0; windx < woi_length; windx++) { for (int windx = 0; windx < woi_length; windx++) {
int x = windx % woi.width + woi.x; int x = windx % woi_veg.width + woi_veg.x;
int y = windx / woi.width + woi.y; int y = windx / woi_veg.width + woi_veg.y;
int indx = x + y * full.width; int indx = x + y * full.width;
for (int t = 0; t < preview_data.length; t++) { for (int t = 0; t < preview_data.length; t++) {
if (!Double.isNaN(woi_tva[t][windx])) { if (!Double.isNaN(woi_tva[t][windx])) {
...@@ -3935,14 +3956,14 @@ public class VegetationLMA { ...@@ -3935,14 +3956,14 @@ public class VegetationLMA {
double [] swd = combined_offsets[nscene]; double [] swd = combined_offsets[nscene];
Arrays.fill(sw, 0); Arrays.fill(sw, 0);
for (int ns = 0; ns < segments.length; ns++) { for (int ns = 0; ns < segments.length; ns++) {
Rectangle woi = segments[ns].woi; Rectangle woi_veg = segments[ns].woi;
int woi_length = woi.width*woi.height; int woi_length = woi_veg.width*woi_veg.height;
double scene_offset = segments[ns].scene_offsets[nscene]; double scene_offset = segments[ns].scene_offsets[nscene];
if (!Double.isNaN(scene_offset)) { if (!Double.isNaN(scene_offset)) {
double [] wnd = overlapCosineWindow (woi, width); double [] wnd = overlapCosineWindow (woi, width);
for (int windx = 0; windx < woi_length; windx++) { for (int windx = 0; windx < woi_length; windx++) {
int x = windx % woi.width + woi.x; int x = windx % woi_veg.width + woi_veg.x;
int y = windx / woi.width + woi.y; int y = windx / woi_veg.width + woi_veg.y;
int indx = x + y * full.width; int indx = x + y * full.width;
for (int t = 0; t < preview_data.length; t++) { for (int t = 0; t < preview_data.length; t++) {
double w = wnd[windx]; double w = wnd[windx];
...@@ -4145,10 +4166,10 @@ public class VegetationLMA { ...@@ -4145,10 +4166,10 @@ public class VegetationLMA {
synthetic_terrain[nScene][npix] = terrain_pix; synthetic_terrain[nScene][npix] = terrain_pix;
} else { } else {
veg_xy = veg_xy.clone(); veg_xy = veg_xy.clone();
if (diff_offsets) { // if (diff_offsets) {
veg_xy[0] += x; veg_xy[0] += x;
veg_xy[1] += y; veg_xy[1] += y;
} // }
int x0 = (int) Math.floor(veg_xy[0]); int x0 = (int) Math.floor(veg_xy[0]);
int y0 = (int) Math.floor(veg_xy[1]); int y0 = (int) Math.floor(veg_xy[1]);
if ( full.contains(x0, y0) && if ( full.contains(x0, y0) &&
...@@ -4241,10 +4262,10 @@ public class VegetationLMA { ...@@ -4241,10 +4262,10 @@ public class VegetationLMA {
} }
} else { // veg_xy !== null } else { // veg_xy !== null
veg_xy = veg_xy.clone(); veg_xy = veg_xy.clone();
if (diff_offsets) { // if (diff_offsets) {
veg_xy[0] += x; veg_xy[0] += x;
veg_xy[1] += y; veg_xy[1] += y;
} // }
int x0 = (int) Math.floor(veg_xy[0]); int x0 = (int) Math.floor(veg_xy[0]);
int y0 = (int) Math.floor(veg_xy[1]); int y0 = (int) Math.floor(veg_xy[1]);
if ( full.contains(x0, y0) && if ( full.contains(x0, y0) &&
...@@ -4347,11 +4368,17 @@ public class VegetationLMA { ...@@ -4347,11 +4368,17 @@ public class VegetationLMA {
File [] par_files = dir.listFiles(parFileFilter); File [] par_files = dir.listFiles(parFileFilter);
VegetationSegment [] segments = new VegetationSegment [par_files.length]; VegetationSegment [] segments = new VegetationSegment [par_files.length];
for (int n = 0; n < par_files.length; n++) { for (int n = 0; n < par_files.length; n++) {
Rectangle woi = new Rectangle(); Rectangle [] wois = new Rectangle[2];
double [][] tvao = restoreParametersFile( // already trimmed to actual lengths FIXME: Not finished for real import ! double [][] tvao = restoreParametersFile( // already trimmed to actual lengths FIXME: Not finished for real import !
par_files[n].getPath(), // String path, par_files[n].getPath(), // String path,
woi); // Rectangle file_woi) false, // boolean keep_settings,
wois); // Rectangle file_woi)
Rectangle woi_veg = wois[0];
Rectangle woi = wois[1];
segments[n] = new VegetationSegment( segments[n] = new VegetationSegment(
woi_veg, // Rectangle woi_veg,
woi, // Rectangle woi, woi, // Rectangle woi,
tvao[TVAO_SCENE_OFFSET], // datadouble [] scene_offsets, tvao[TVAO_SCENE_OFFSET], // datadouble [] scene_offsets,
new double [][] {tvao[0],tvao[1],tvao[2]}); // double [][] tva) {} {} new double [][] {tvao[0],tvao[1],tvao[2]}); // double [][] tva) {} {}
...@@ -4360,8 +4387,8 @@ public class VegetationLMA { ...@@ -4360,8 +4387,8 @@ public class VegetationLMA {
Arrays.sort(segments, new Comparator<VegetationSegment>() { Arrays.sort(segments, new Comparator<VegetationSegment>() {
@Override @Override
public int compare(VegetationSegment lhs, VegetationSegment rhs) { public int compare(VegetationSegment lhs, VegetationSegment rhs) {
return (rhs.woi.y > lhs.woi.y) ? -1 : (rhs.woi.y < lhs.woi.y) ? 1 : return (rhs.woi_veg.y > lhs.woi_veg.y) ? -1 : (rhs.woi_veg.y < lhs.woi_veg.y) ? 1 :
((rhs.woi.x > lhs.woi.x) ? -1 : (rhs.woi.x < lhs.woi.x) ? 1 : 0); // increasing ((rhs.woi_veg.x > lhs.woi_veg.x) ? -1 : (rhs.woi_veg.x < lhs.woi_veg.x) ? 1 : 0); // increasing
} }
}); });
...@@ -4475,7 +4502,7 @@ public class VegetationLMA { ...@@ -4475,7 +4502,7 @@ public class VegetationLMA {
// boolean use_terr_corr = y_vector.length > y_lf_hf_len; // boolean use_terr_corr = y_vector.length > y_lf_hf_len;
use_scenes_pull0 = (scenes_pull0 >=0); boolean use_scenes_pull0 = (scenes_pull0 >=0);
// using >=0 no use 0 as NOP but reserve space, <0 - do not reserve space // using >=0 no use 0 as NOP but reserve space, <0 - do not reserve space
samples_pointers = new int [SAMPLES_SIZE][3]; // {start, length} samples_pointers = new int [SAMPLES_SIZE][3]; // {start, length}
samples_pointers[SAMPLES_Y][1] = y_src.length; samples_pointers[SAMPLES_Y][1] = y_src.length;
......
...@@ -24,6 +24,7 @@ import com.elphel.imagej.tileprocessor.TileProcessor; ...@@ -24,6 +24,7 @@ import com.elphel.imagej.tileprocessor.TileProcessor;
import ij.IJ; import ij.IJ;
import ij.ImagePlus; import ij.ImagePlus;
import ij.ImageStack; import ij.ImageStack;
import ij.Prefs;
import ij.io.FileSaver; import ij.io.FileSaver;
/* /*
...@@ -1359,10 +1360,14 @@ public class VegetationModel { ...@@ -1359,10 +1360,14 @@ public class VegetationModel {
boolean run_combine = combine_segments; // true; // if true, run combining instead of LMA boolean run_combine = combine_segments; // true; // if true, run combining instead of LMA
// String model_path = clt_parameters.imp.terr_model_path; // Model directory path with version.
// String model_state = clt_parameters.imp.terr_model_state; // Model vegetation source data (w/o extension).
String segments_sub = clt_parameters.imp.terr_segments_dir; // String segments_sub = clt_parameters.imp.terr_segments_dir; //
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;
boolean um_en = clt_parameters.imp.terr_um_en; // true; boolean um_en = clt_parameters.imp.terr_um_en; // true;
double um_sigma = clt_parameters.imp.terr_um_sigma; // 1.0; double um_sigma = clt_parameters.imp.terr_um_sigma; // 1.0;
double um_weight = clt_parameters.imp.terr_um_weight; // 0.8; double um_weight = clt_parameters.imp.terr_um_weight; // 0.8;
...@@ -1394,8 +1399,8 @@ public class VegetationModel { ...@@ -1394,8 +1399,8 @@ public class VegetationModel {
// double terrain_warmest = clt_parameters.imp.terr_warmest; // pull vegetations to warm, terrain to cold // double terrain_warmest = clt_parameters.imp.terr_warmest; // pull vegetations to warm, terrain to cold
// double initial_split = clt_parameters.imp.terr_initial_split; // pull vegetations to warm, terrain to cold // double initial_split = clt_parameters.imp.terr_initial_split; // pull vegetations to warm, terrain to cold
// double min_split_frac = clt_parameters.imp.terr_min_split_frac;// 0.15; // double min_split_frac = clt_parameters.imp.terr_min_split_frac;// 0.15;
double terr_difference = clt_parameters.imp.terr_difference; // Pull vegetation to be this warmer // double terr_difference = clt_parameters.imp.terr_difference; // Pull vegetation to be this warmer
double terr_pull_cold = clt_parameters.imp.terr_pull_cold; // pull vegetations to warm, terrain to cold // double terr_pull_cold = clt_parameters.imp.terr_pull_cold; // pull vegetations to warm, terrain to cold
double elevation_radius = clt_parameters.imp.terr_elevation_radius; // Radius of elevation/vegetation influence double elevation_radius = clt_parameters.imp.terr_elevation_radius; // Radius of elevation/vegetation influence
double alpha_initial_contrast = clt_parameters.imp.terr_alpha_contrast; // initial alpha contrast (>=1.0) double alpha_initial_contrast = clt_parameters.imp.terr_alpha_contrast; // initial alpha contrast (>=1.0)
double default_alpha = clt_parameters.imp.terr_alpha_dflt; // 0.5; // 0.8; double default_alpha = clt_parameters.imp.terr_alpha_dflt; // 0.5; // 0.8;
...@@ -1612,6 +1617,101 @@ public class VegetationModel { ...@@ -1612,6 +1617,101 @@ public class VegetationModel {
if ((elevations == null) || (scale_dirs == null)){ if ((elevations == null) || (scale_dirs == null)){
//Moving it here to generate needed vegetation_inv_warp_md
if (debugLevel > -3) { // 3) { //-2) {
// probably will not use these, but as optional
vegetation_warp_md = new double [vegetation_warp.length][][];
for (int nscene = 0; nscene < vegetation_warp.length; nscene++) {
// if (nscene == reference_index) {
// vegetation_warp_md[nscene] = new double [full.width * full.height][];
// } else {
boolean after_ref = (nscene > reference_index);
vegetation_warp_md[nscene ]= warpMagnitudeDirection(
vegetation_warp[nscene], // final double [][] warp_dxy,
full.width, // final int width,
dir_sigma, // final double dir_sigma,// Gaussian blur sigma to smooth direction variations
after_ref); // final boolean after_ref);
// }
}
vegetation_inv_warp_md = new double [vegetation_warp.length][][];
for (int nscene = 0; nscene < vegetation_warp.length; nscene++) {
// if (nscene == reference_index) {
// vegetation_inv_warp_md[nscene] = new double [full.width * full.height][];
// } else {
boolean after_ref = (nscene > reference_index);
vegetation_inv_warp_md[nscene ]= warpMagnitudeDirection(
vegetation_inv_warp[nscene], // final double [][] warp_dxy,
full.width, // final int width,
dir_sigma, // final double dir_sigma,// Gaussian blur sigma to smooth direction variations
after_ref); // final boolean after_ref);
// }
}
double [][][] dbg_img = new double[12][vegetation_warp.length][vegetation_warp[0].length];
for (int n = 0; n < dbg_img.length; n++) {
for (int nscene = 0; nscene < vegetation_warp.length; nscene++) {
Arrays.fill(dbg_img[n][nscene], Double.NaN);
}
}
for (int nscene = 0; nscene < vegetation_warp.length; nscene++) {
for (int npix = 0; npix < vegetation_warp[0].length; npix++) {
if (vegetation_warp[nscene][npix] != null) {
double dx =vegetation_warp[nscene][npix][0];
double dy =vegetation_warp[nscene][npix][1];
dbg_img[0][nscene][npix] = Math.sqrt(dx*dx + dy*dy);
dbg_img[1][nscene][npix] = Math.atan2(dy, dx);
dbg_img[2][nscene][npix] = dx;
dbg_img[3][nscene][npix] = dy;
}
if (vegetation_warp_md[nscene][npix] != null) {
dbg_img[4][nscene][npix] = vegetation_warp_md[nscene][npix][0]; // magnitude
dbg_img[5][nscene][npix] = vegetation_warp_md[nscene][npix][1]; // direction
}
if (vegetation_inv_warp[nscene][npix] != null) {
double dx =vegetation_inv_warp[nscene][npix][0];
double dy =vegetation_inv_warp[nscene][npix][1];
dbg_img[6][nscene][npix] = Math.sqrt(dx*dx + dy*dy);
dbg_img[7][nscene][npix] = Math.atan2(dy, dx);
dbg_img[8][nscene][npix] = dx;
dbg_img[9][nscene][npix] = dy;
}
if (vegetation_inv_warp_md[nscene][npix] != null) {
dbg_img[10][nscene][npix] = vegetation_inv_warp_md[nscene][npix][0]; // magnitude
dbg_img[11][nscene][npix] = vegetation_inv_warp_md[nscene][npix][1]; // direction
}
}
}
ShowDoubleFloatArrays.showArraysHyperstack(
dbg_img, // double[][][] pixels,
full.width, // int width,
reference_scene+"-vegetation_offsets.tiff", // String title, "time_derivs-rt"+diff_time_rt+"-rxy"+diff_time_rxy,
scene_names, // String [] titles, // all slices*frames titles or just slice titles or null
new String[] {"dist","angle","dx","dy","mag","dir","inv-dist","inv-angle","inv-dx","inv-dy","inv-mag","inv-dir"}, // String [] frame_titles, // frame titles or null
true); // boolean show)
ShowDoubleFloatArrays.showArrays(
terrain_scenes_render,
full.width,
full.height,
true,
reference_scene+"-terrain_rendered.tiff",
scene_names);
ShowDoubleFloatArrays.showArrays(
new double [][] {terrain_average_render,vegetation_average_render},
full.width,
full.height,
true,
reference_scene+"-terrain_vegetation_averages.tiff",
new String[] {"terrain","vegetation"});
}
// boolean use_min = false; // boolean use_min = false;
...@@ -1668,53 +1768,7 @@ public class VegetationModel { ...@@ -1668,53 +1768,7 @@ public class VegetationModel {
this.elevations = elevations; this.elevations = elevations;
this.scale_dirs = elevation_scale_dirs; this.scale_dirs = elevation_scale_dirs;
/*
double [] elevations2 = enhanceElevations(
elevations, // final double [] elevations,
vegetation_inv_warp_md, // final double [][][] mag_dirs,
reliable_scene_pix, // final boolean [][] reliable, // or null
full.width, // final int width,
elevations1_grow, // final int grow,
min_elevation, // final double min_elevation,
dir_sigma_scales, // final double dir_sigma,// Gaussian blur sigma to smooth direction variations
radius_outliers, // final int radius,
min_frac, // final double min_frac, // minimal fraction of the full square to keep (0.25 for the corners
remove_frac_hi, // final double remove_frac_hi,
remove_frac_lo, // final double remove_frac_lo, // total,
elevation_scales, // final double [][] elevation_scales,
debug_enhance_elevations);
double [] elevations3 = enhanceElevations(
elevations2, // final double [] elevations,
vegetation_inv_warp_md, // final double [][][] mag_dirs,
reliable_scene_pix, // final boolean [][] reliable, // or null
full.width, // final int width,
elevations1_grow, // final int grow,
min_elevation, // final double min_elevation,
dir_sigma_scales, // final double dir_sigma,// Gaussian blur sigma to smooth direction variations
radius_outliers, // final int radius,
min_frac, // final double min_frac, // minimal fraction of the full square to keep (0.25 for the corners
remove_frac_hi, // final double remove_frac_hi,
remove_frac_lo, // final double remove_frac_lo, // total,
elevation_scales, // final double [][] elevation_scales,
debug_enhance_elevations);
double [] elevations4 = enhanceElevations(
elevations3, // final double [] elevations,
vegetation_inv_warp_md, // final double [][][] mag_dirs,
reliable_scene_pix, // final boolean [][] reliable, // or null
full.width, // final int width,
elevations1_grow, // final int grow,
min_elevation, // final double min_elevation,
dir_sigma_scales, // final double dir_sigma,// Gaussian blur sigma to smooth direction variations
radius_outliers, // final int radius,
min_frac, // final double min_frac, // minimal fraction of the full square to keep (0.25 for the corners
remove_frac_hi, // final double remove_frac_hi,
remove_frac_lo, // final double remove_frac_lo, // total,
elevation_scales, // final double [][] elevation_scales,
debug_enhance_elevations);
// final boolean debug)
*
*/
//
if (debugLevel > -2) { if (debugLevel > -2) {
ShowDoubleFloatArrays.showArrays( ShowDoubleFloatArrays.showArrays(
new double [][] {max_offsets, elevations},// elevations2, elevations3, elevations4}, new double [][] {max_offsets, elevations},// elevations2, elevations3, elevations4},
...@@ -1925,17 +1979,7 @@ public class VegetationModel { ...@@ -1925,17 +1979,7 @@ public class VegetationModel {
false, // final boolean keep_parameters, false, // final boolean keep_parameters,
woi, // final Rectangle woi, woi, // final Rectangle woi,
max_warp, // final double max_warp, // 1.8 - do not use scenes where distance between vegetation projection exceeds this max_warp, // final double max_warp, // 1.8 - do not use scenes where distance between vegetation projection exceeds this
// min_scenes, // final int min_dependent_scenes, // minimal number of scenes (inside woi) vegetation pixel must influence
max_offset, // final int max_offset, // maximal "elevation" to consider max_offset, // final int max_offset, // maximal "elevation" to consider
// min_total_scenes, // final int min_total_scenes,
// min_samples_scene, //final int min_samples_scene, // 10
// min_pixels, // final int min_pixels,
// start_warm_veget, // final boolean start_warm_veget, // start with vegetation warmer than terrain
// terrain_warmest, // final double terrain_warmest, // warmest terrain (above is initially vegetation)
// initial_split, // final double initial_split, // initial alpha: terrain 0.0+, vegetation 1.0-.
// min_split_frac, // final double min_frac, // minimal modality fraction to use split by temperature
terr_difference, // final double terr_difference, // pull vegetation to be this warmer
terr_pull_cold, // final double terr_pull_cold, // pull vegetations to warm, terrain to cold
elevation_radius, // final double elevation_radius, // Radius of elevation/vegetation influence. elevation_radius, // final double elevation_radius, // Radius of elevation/vegetation influence.
default_alpha, // final double default_alpha, default_alpha, // final double default_alpha,
hifreq_weight, //final double hifreq_weight, // 22.5 0 - do not use high-freq. Relative weight of laplacian components hifreq_weight, //final double hifreq_weight, // 22.5 0 - do not use high-freq. Relative weight of laplacian components
...@@ -1988,6 +2032,19 @@ public class VegetationModel { ...@@ -1988,6 +2032,19 @@ public class VegetationModel {
} }
} }
if (par_restore) {
par_path = parameters_dir;
if (!par_path.endsWith(Prefs.getFileSeparator())) {
par_path+=Prefs.getFileSeparator();
}
par_path+=parameters_file;
System.out.println("Restoring parameters from "+par_path);
vegetationLMA.restoreParametersFile( //FIXME: Not finished for real import !
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
}
// old
if ("RESTORE".equals(par_path)) { if ("RESTORE".equals(par_path)) {
System.out.println("Reading fitted parameters from file"); System.out.println("Reading fitted parameters from file");
if (save_par_files) { if (save_par_files) {
...@@ -2038,12 +2095,23 @@ public class VegetationModel { ...@@ -2038,12 +2095,23 @@ public class VegetationModel {
debugLevel); // int debug_level) debugLevel); // int debug_level)
if (debugLevel > -2) { // 1) { if (debugLevel > -2) { // 1) {
System.out.println((new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime()))+ System.out.println((new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime()))+
" LMA finished"); " 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
null); // double [] vector)
} }
elev_pull0 *= 0.01; elev_pull0 *= 0.01;
vegetationLMA.elevation_pull0 = elev_pull0; vegetationLMA.elevation_pull0 = elev_pull0;
if (debugLevel > -3) {
lma_rslt= vegetationLMA.runLma( // <0 - failed, >=0 iteration number (1 - immediately) lma_rslt= vegetationLMA.runLma( // <0 - failed, >=0 iteration number (1 - immediately)
lambda, // double lambda, // 0.1 lambda, // double lambda, // 0.1
lambda_scale_good,// double lambda_scale_good,// 0.5 lambda_scale_good,// double lambda_scale_good,// 0.5
...@@ -2056,9 +2124,10 @@ public class VegetationModel { ...@@ -2056,9 +2124,10 @@ public class VegetationModel {
debugLevel); // int debug_level) debugLevel); // int debug_level)
if (debugLevel > -2) { // 1) { if (debugLevel > -2) { // 1) {
System.out.println((new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime()))+ System.out.println((new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime()))+
" LMA finished"); " LMA finished - second run");
}
}
} }
// save results // save results
if (save_par_files) { if (save_par_files) {
......
...@@ -3,10 +3,12 @@ package com.elphel.imagej.vegetation; ...@@ -3,10 +3,12 @@ package com.elphel.imagej.vegetation;
import java.awt.Rectangle; import java.awt.Rectangle;
public class VegetationSegment { public class VegetationSegment {
public Rectangle woi_veg;
public Rectangle woi; public Rectangle woi;
public double [] scene_offsets; public double [] scene_offsets;
public double [][] tva; public double [][] tva;
public VegetationSegment( public VegetationSegment(
Rectangle woi_veg,
Rectangle woi, Rectangle woi,
double [] scene_offsets, // has NaNs double [] scene_offsets, // has NaNs
double [][] tva) { double [][] tva) {
......
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