Commit e72b18ee authored by Andrey Filippov's avatar Andrey Filippov

Before converting to dual-band comparison

parent d152fbaa
......@@ -720,6 +720,9 @@ min_str_neib_fpn 0.35
public Color annotate_color_mono = new Color( 255, 180, 50); // reddish over grey
public boolean annotate_transparent_mono = false; // // black if not transparent
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";
// terrain/vegetation parameters
public boolean terr_um_en = true;
public double terr_um_sigma = 1.0;
......@@ -748,6 +751,7 @@ min_str_neib_fpn 0.35
public double terr_alpha_push = 12; // push from alpha==0.5
public double terr_alpha_push_neutral = 0.5; // alpha point from which push (closer to opaque)
public double terr_alpha_weight_center =1.5; // weight of center alpha pixel relative to each of the 4 ortho ones
public boolean terr_en_holes = true; // enable small holes // maybe second pass after good fit with vegetation and search for correct offset?
public double terr_alpha_mm_hole = 0.1; // NaN to disable. Local "almost minimum" (lower than this fraction between min and max neighbor) is not subject to alpha_lpf
public double terr_terr_lpf = 0.1; // pull terrain to average of 4 neighbors (very small)
public double terr_veget_lpf = 0.2; // pull vegetation to average of 4 neighbors (very small - maybe not needed)
......@@ -1950,7 +1954,13 @@ min_str_neib_fpn 0.35
"Put monochrome timestamp over image (unchecked - use black background). Color - always black.");
// vegetation
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.addCheckbox ("Enable UM", terr_um_en, "Enable unsharp mask filter.");
gd.addNumericField("UM sigma", terr_um_sigma, 5,7, "pix", "Unsharp mask sigma.");
gd.addNumericField("UM weight", terr_um_weight, 5,7, "", "Unsharp mask weight.");
......@@ -1979,6 +1989,7 @@ min_str_neib_fpn 0.35
gd.addNumericField("Push alpha", terr_alpha_push, 5,7,"", "Quadratic loss for middle alpha (push to 0.0 or 1.0.");
gd.addNumericField("Neutral alpha", terr_alpha_push_neutral, 5,7,"", "Alpha point from which to push (default 0.5).");
gd.addNumericField("Alpha center weight", terr_alpha_weight_center, 5,7,"","Weight of center alpha pixel relative to each of the 4 ortho ones.");
gd.addCheckbox ("Hole search enable", terr_en_holes, "Search for small semi-transparent holes, disable diffusion of local alpha minimums.");
gd.addNumericField("Alpha MM fraction", terr_alpha_mm_hole, 5,7,"", "Disable diffusion for local \"almost minimum\" (lower than this fraction between min and max neighbors).");
gd.addNumericField("Terrain diffusion", terr_terr_lpf, 5,7,"", "LPF for terrain pixels (diffusion to 4 neighbors).");
gd.addNumericField("Vegetation diffusion", terr_veget_lpf, 5,7,"", "LPF for vegetation pixels (diffusion to 4 neighbors).");
......@@ -2631,6 +2642,9 @@ min_str_neib_fpn 0.35
this.annotate_transparent_mono= gd.getNextBoolean();
// vegetation
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
......@@ -2659,6 +2673,8 @@ min_str_neib_fpn 0.35
terr_alpha_push = gd.getNextNumber();// double
terr_alpha_push_neutral = gd.getNextNumber();// double
terr_alpha_weight_center = gd.getNextNumber();// double
terr_en_holes = gd.getNextBoolean();// boolean
terr_alpha_mm_hole = gd.getNextNumber();// double
terr_terr_lpf = gd.getNextNumber();// double
terr_veget_lpf = gd.getNextNumber();// double
......@@ -3279,6 +3295,10 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"annotate_transparent_mono",this.annotate_transparent_mono+"");// boolean
// vegetation
properties.setProperty(prefix+"terr_model_path", terr_model_path+""); // 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_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
......@@ -3305,7 +3325,7 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"terr_alpha_push", terr_alpha_push+""); // double
properties.setProperty(prefix+"terr_alpha_push_neutral", terr_alpha_push_neutral+""); // double
properties.setProperty(prefix+"terr_alpha_weight_center", terr_alpha_weight_center+"");// double
properties.setProperty(prefix+"terr_alpha_mm_hole", terr_alpha_mm_hole+""); // double
properties.setProperty(prefix+"terr_en_holes", terr_en_holes+""); // boolean
properties.setProperty(prefix+"terr_terr_lpf", terr_terr_lpf+""); // double
properties.setProperty(prefix+"terr_veget_lpf", terr_veget_lpf+""); // double
properties.setProperty(prefix+"terr_terr_pull0", terr_terr_pull0+""); // double
......@@ -3948,6 +3968,10 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"annotate_transparent_mono")!=null) this.annotate_transparent_mono=Boolean.parseBoolean(properties.getProperty(prefix+"annotate_transparent_mono"));
// vegetation
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_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_weight")!= null) terr_um_weight=Double.parseDouble(properties.getProperty(prefix+"terr_um_weight"));
......@@ -3974,6 +3998,7 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"terr_alpha_push")!= null) terr_alpha_push=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_push"));
if (properties.getProperty(prefix+"terr_alpha_push_neutral")!= null) terr_alpha_push_neutral=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_push_neutral"));
if (properties.getProperty(prefix+"terr_alpha_weight_center")!=null) terr_alpha_weight_center=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_weight_center"));
if (properties.getProperty(prefix+"terr_en_holes")!= null) terr_en_holes=Boolean.parseBoolean(properties.getProperty(prefix+"terr_en_holes"));
if (properties.getProperty(prefix+"terr_alpha_mm_hole")!= null) terr_alpha_mm_hole=Double.parseDouble(properties.getProperty(prefix+"terr_alpha_mm_hole"));
if (properties.getProperty(prefix+"terr_terr_lpf")!= null) terr_terr_lpf=Double.parseDouble(properties.getProperty(prefix+"terr_terr_lpf"));
if (properties.getProperty(prefix+"terr_veget_lpf")!= null) terr_veget_lpf=Double.parseDouble(properties.getProperty(prefix+"terr_veget_lpf"));
......@@ -4584,6 +4609,10 @@ min_str_neib_fpn 0.35
imp.annotate_transparent_mono = this. annotate_transparent_mono;
// vegetation
imp.terr_model_path = this. terr_model_path;
imp.terr_model_state = this. terr_model_state;
imp.terr_segments_dir = this. terr_segments_dir;
imp.terr_um_en = this.terr_um_en;
imp.terr_um_sigma = this.terr_um_sigma;
imp.terr_um_weight = this.terr_um_weight;
......@@ -4610,6 +4639,7 @@ min_str_neib_fpn 0.35
imp.terr_alpha_push = this.terr_alpha_push;
imp.terr_alpha_push_neutral = this.terr_alpha_push_neutral;
imp.terr_alpha_weight_center = this.terr_alpha_weight_center;
imp.terr_en_holes = this.terr_en_holes;
imp.terr_alpha_mm_hole = this.terr_alpha_mm_hole;
imp.terr_terr_lpf = this.terr_terr_lpf;
imp.terr_veget_lpf = this.terr_veget_lpf;
......
......@@ -39,6 +39,20 @@ public class VegetationLMA {
public 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,
public VegetationModel vegetationModel = null;
/*
// copy from Vegetation model
public String [] scene_names = null; // TODO: Implement!
public String model_directory;
public String model_top_directory;
public String reference_scene; // timestamp
public int reference_index; // timestamp
*/
//[2][image_length] - alpha, [3][num_scenes] - per-scene offset (mostly for vignetting. MAYBE add per-scene pair of tilts
public int [][] par_index; // indices - [0..3][full_pixel] - same as for tvao, value - parameter index
public int [][] par_rindex; // parameter -> pair of type (0..3) and full window pixel index
......@@ -75,6 +89,7 @@ public class VegetationLMA {
public double alpha_push_neutral = 0.8; // alpha point from which push (closer to opaque)
public double alpha_push_center = 1.5; // weight of center alpha pixel relative to each of the 4 ortho ones
public 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
public boolean alpha_en_holes = true; // Search for small semi-transparent holes, disable diffusion of local alpha minimums
public double alpha_diff_hole = 0.01; // minimal alpha difference between min and max neighbor to be considered a hole
......@@ -157,6 +172,8 @@ public class VegetationLMA {
tvao[TVAO_VEGETATION_ALPHA] = new double [image_length]; // 0 - use terrain
tvao[TVAO_SCENE_OFFSET] = new double [num_scenes];
diff_offsets = vegetationModel.diff_mode;
this.vegetationModel = vegetationModel; // to access scene names, directories, reference index
return;
}
......@@ -177,6 +194,7 @@ public class VegetationLMA {
final double alpha_push, // 5.0; // push from alpha==0.5
final double alpha_push_neutral, // = 0.8; // alpha point from which push (closer to opaque)
final double alpha_push_center,// 1.5; // weight of center alpha pixel relative to each of the 4 ortho ones
final boolean alpha_en_holes, // Search for small semi-transparent holes, disable diffusion of local alpha minimums
final 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
final double terr_lpf, // pull terrain to average of 4 neighbors (very small)
final double veget_lpf, // pull vegetation to average of 4 neighbors (very small - maybe not needed)
......@@ -197,6 +215,7 @@ public class VegetationLMA {
this.alpha_push = alpha_push; // 5.0; // push from alpha==0.5
this.alpha_push_neutral = alpha_push_neutral; // 0.8; // alpha point from which push (closer to opaque)
this.alpha_push_center = alpha_push_center; // 1.5; // weight of center alpha pixel relative to each of the 4 ortho ones
this.alpha_en_holes = alpha_en_holes;
this.alpha_mm_hole = alpha_mm_hole;
this.terr_lpf = terr_lpf;
this.veget_lpf = veget_lpf;
......@@ -518,6 +537,20 @@ public class VegetationLMA {
false); // boolean show_img)
System.out.println("\nMaximal error = "+delta_err);
}
if (debug_level > -2) { //
String save_dir = debug_path;
String debug_title = getParametersDebugTitle();
boolean save_all = (debug_image != null);
boolean show_this = debug_level > 3;
boolean show_all = debug_level > 4;
debugImageSaveShow(
save_dir, // String save_dir, // save if not null
debug_title, // String title, // not null
save_all, // boolean save_all,
show_this, // boolean show_this,
show_all); // boolean show_all)
}
}
if (debug_level > 3) { // 0) {
double delta = this.delta; // 1E-3;
......@@ -618,19 +651,6 @@ public class VegetationLMA {
if (debug_level > -2) { //
String save_dir = debug_path;
String debug_title = getParametersDebugTitle();
/*
String debug_title = "parameters_vector-x"+woi.x+"-y"+woi.y+"-w"+woi.width+"-h"+woi.height;
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+"-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 += from_file?"-file":"-new";
if (um_weight > 0) {
debug_title +="-um"+um_sigma+"_"+um_weight;
}
*/
boolean save_all = (debug_image != null);
boolean show_this = debug_level > 3;
boolean show_all = debug_level > 4;
......@@ -640,11 +660,6 @@ public class VegetationLMA {
save_all, // boolean save_all,
show_this, // boolean show_this,
show_all); // boolean show_all)
/*
System.out.print("delta: "+corr_delta.toString()+"\n");
System.out.print("New vector: "+new_vector.toString()+"\n");
System.out.println();
*/
}
} else { // worsened
rslt[0] = false;
......@@ -673,6 +688,7 @@ public class VegetationLMA {
}
public String getParametersDebugTitle() {
// alpha_en_holes -> alpha_mm_hole = NaN;
String debug_title = "parameters_vector-x"+woi.x+"-y"+woi.y+"-w"+woi.width+"-h"+woi.height;
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+"-amm"+alpha_mm_hole;
......@@ -885,6 +901,51 @@ public class VegetationLMA {
return tvas;
}
public static double [] laplacian(
final boolean gaussian,
final double [] data_in,
final int width,
final double weight_diag) {
final int height = data_in.length/width;
final double [] data_out = new double [data_in.length];
Arrays.fill(data_out, Double.NaN);
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
final double [] weights8 = new double [8];
weights8[0] = 0.25/(weight_diag+1);
weights8[1] = weights8[0]*weight_diag;
for (int i = 2; i < 8;i++) {
weights8[i] = weights8[i % 2];
}
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
TileNeibs tn = new TileNeibs(width,height);
for (int nPix = ai.getAndIncrement(); nPix < data_in.length; nPix = ai.getAndIncrement()) if(!Double.isNaN(data_in[nPix])){
double sw = 0, swd = 0;
for (int dir = 0; dir < 8; dir++) {
int nPix1= tn.getNeibIndex(nPix, dir);
if ((nPix1 >= 0) && !Double.isNaN(data_in[nPix1])) {
sw += weights8[dir];
swd += data_in[nPix1]*weights8[dir];
}
}
if (sw != 0) {
swd /= sw;
data_out[nPix] = gaussian? swd : (data_in[nPix] - swd);
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return data_out;
}
public double [][] getTerrainWeights(
final double alpha_threshold, // discard images with too low transparency
......@@ -1189,7 +1250,7 @@ public class VegetationLMA {
//alpha_scale_avg
double mm = neib_min + (neib_max-neib_min) * alpha_mm_hole;
double effective_alpha_lpf = alpha_lpf;
if (!Double.isNaN(alpha_mm_hole) && (vector[np] <= mm) && ((neib_max-neib_min) >= alpha_diff_hole)) {
if (alpha_en_holes && !Double.isNaN(alpha_mm_hole) && (vector[np] <= mm) && ((neib_max-neib_min) >= alpha_diff_hole)) {
effective_alpha_lpf = 0.0; // disable alpha_lpf
}
// disable pull to average of neighbors for small holes in vegetation (local "almost minimum")
......@@ -1563,6 +1624,7 @@ 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_DIFF_HOLE", ""+alpha_diff_hole);
imp.setProperty("TERR_LPF", ""+terr_lpf);
......@@ -1686,6 +1748,9 @@ public class VegetationLMA {
alpha_push = Double.parseDouble((String) imp_pars.getProperty("ALPHA_PUSH"));
alpha_push_neutral = Double.parseDouble((String) imp_pars.getProperty("ALPHA_PUSH_NEUTRAL"));
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_diff_hole = Double.parseDouble((String) imp_pars.getProperty("ALPHA_DIFF_HOLE"));
terr_lpf = Double.parseDouble((String) imp_pars.getProperty("TERR_LPF"));
......@@ -1825,10 +1890,13 @@ public class VegetationLMA {
}
ImageDtt.startAndJoin(threads);
// new String[] {"full average", "filtered average"});
double [][] tva = {preview_data[0][accum_indx],preview_data[1][accum_indx],preview_data[2][accum_indx]};
vegetationModel.setTVA(tva);
// new String[] {"full average", "filtered average"});
String render_title = "render-ro"+render_open+"-rna"+render_no_alpha+"-amn"+alpha_min+"-amx"+alpha_max+"-wo"+weight_opaque+"-bp"+boost_parallax+".tiff";
String ref_scene = vegetationModel.reference_scene;
String render_title = "render-ro_"+render_open+"-rna_"+render_no_alpha+"-amn"+alpha_min+"-amx"+alpha_max+"-wo"+weight_opaque+"-bp"+boost_parallax+".tiff";
double [] render = renderWithAlpha(
......@@ -1862,13 +1930,13 @@ public class VegetationLMA {
full.width,
full.height,
true,
"scene_offsets",
ref_scene+"-scene_offsets",
titles_scenes);
ShowDoubleFloatArrays.showArraysHyperstack(
preview_data, // double[][][] pixels,
full.width, // int width,
"preview_segments", // String title, "time_derivs-rt"+diff_time_rt+"-rxy"+diff_time_rxy,
ref_scene+"-preview_segments", // String title, "time_derivs-rt"+diff_time_rt+"-rxy"+diff_time_rxy,
titles, // String [] titles, // all slices*frames titles or just slice titles or null
top_titles, // String [] frame_titles, // frame titles or null
true); // boolean show)
......@@ -1878,12 +1946,167 @@ public class VegetationLMA {
full.width,
full.height,
true,
render_title,
ref_scene+"-"+render_title,
result_titles);
String [] synt_titles = {"render","synthetic", "synt_terrain", "synt vegetation","masked render", "render"};
final double [][][] synt_data = new double [synt_titles.length][num_scenes][];
final double terrain_max = alpha_min;
final double vegetation_min = 0.5; // alpha_max;
String synt_name = "synthetic-terr"+terrain_max+"-veg"+vegetation_min;
synt_data[0] = terrain_rendered;
synt_data[5] = terrain_rendered;
double [][][] synt_tv= renderSynthetic(
preview_data[2][accum_indx], // final double [] alpha,
combined_offsets, // final double [][] scene_offsets, // subtract if not null
terrain_max, // final double terrain_max, // below - terrain is visible
vegetation_min, // final double vegetation_min, // above - vegetation is visible
boost_parallax, // final double boost_parallax, // increase weights of scenes with high parallax relative to the reference one
max_parallax); //final double max_parallax) {
synt_data[2] = synt_tv[0];
synt_data[3] = synt_tv[1];
/*
for (int nscene = 0; nscene < num_scenes; nscene++) { // use threads
synt_data[1][nscene] = synt_tv[0][nscene].clone();
synt_data[4][nscene] = terrain_rendered[nscene].clone();
double [] veg_scene = synt_tv[1][nscene];
for (int i = 0; i < veg_scene.length; i++) {
if (!Double.isNaN(veg_scene[i])) {
synt_data[1][nscene][i] = veg_scene[i];
synt_data[4][nscene][i] = Double.NaN;
}
}
}
*/
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nscene = ai.getAndIncrement(); nscene < num_scenes; nscene = ai.getAndIncrement()) {
synt_data[1][nscene] = synt_tv[0][nscene].clone();
synt_data[4][nscene] = terrain_rendered[nscene].clone();
double [] veg_scene = synt_tv[1][nscene];
for (int i = 0; i < veg_scene.length; i++) {
if (!Double.isNaN(veg_scene[i])) {
synt_data[1][nscene][i] = veg_scene[i];
synt_data[4][nscene][i] = Double.NaN;
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
ShowDoubleFloatArrays.showArraysHyperstack(
synt_data, // double[][][] pixels,
full.width, // int width,
ref_scene+"-"+synt_name, // String title, "time_derivs-rt"+diff_time_rt+"-rxy"+diff_time_rxy,
titles_scenes, // String [] titles, // all slices*frames titles or just slice titles or null
synt_titles, // String [] frame_titles, // frame titles or null
true); // boolean show)
return;
}
public double [][][] renderSynthetic(
final double [] alpha,
final double [][] scene_offsets, // subtract if not null
final double terrain_max, // below - terrain is visible
final double vegetation_min, // above - vegetation is visible
final double boost_parallax, // increase weights of scenes with high parallax relative to the reference one
final double max_parallax) {
final int full_length = full.width*full.height;
final double [][] tva = vegetationModel.getTVA();
final double [] terrain_dflt = vegetationModel.terrain_average_render;
final double [] vegetation_dflt = vegetationModel.vegetation_average_render;
final int INDX_TERR = 0, INDX_VEG=1;
final double [][][] synthetic = new double [2][num_scenes][full_length];
for (int t = 0; t < synthetic.length; t++) {
for (int nscene = 0; nscene < synthetic[t].length; nscene++) {
Arrays.fill(synthetic[t][nscene], Double.NaN);
}
}
final double [][] synthetic_terrain = synthetic[INDX_TERR];
final double [][] synthetic_vegetation = synthetic[INDX_VEG];
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nScene = ai.getAndIncrement(); nScene < num_scenes; nScene = ai.getAndIncrement()) {
for (int npix = 0; npix < full_length; npix++) {
int x = npix % full.width;
int y = npix / full.width;
double d0= 0;
if (scene_offsets != null) {
double offs = scene_offsets[nScene][npix];
if (!Double.isNaN(offs)) d0 = offs;
}
double [] veg_xy = vegetation_offsets[nScene][npix];
double terrain_pix = (Double.isNaN(tva[TVAO_TERRAIN][npix])) ? terrain_dflt[npix] : (tva[TVAO_TERRAIN][npix] + d0); // added offset to adjusted only
if (veg_xy == null) {
synthetic_terrain[nScene][npix] = terrain_pix;
} else {
veg_xy = veg_xy.clone();
if (diff_offsets) {
veg_xy[0] += x;
veg_xy[1] += y;
}
int x0 = (int) Math.floor(veg_xy[0]);
int y0 = (int) Math.floor(veg_xy[1]);
if ( full.contains(x0, y0) &&
full.contains(x0+1,y0) &&
full.contains(x0, y0+1) &&
full.contains(x0+1,y0+1)) {
double fx = veg_xy[0] - x0;
double fy = veg_xy[1] - y0;
double [] corn_w = {(1-fx)*(1-fy), fx*(1-fy), (1-fx)*fy, fx*fy};
int veg_indx = x0+full.width*y0;
int [] veg_indx4 = {veg_indx, veg_indx+1, veg_indx+full.width, veg_indx+full.width+1};
double saw = 0, sawd = 0, sawv = 0;
for (int i = 0; i < 4; i++) {
double a = alpha[veg_indx4[i]];
double v = tva[TVAO_VEGETATION][veg_indx4[i]];//vegetation_dflt
if (Double.isNaN(v)) v = vegetation_dflt[veg_indx4[i]];
if (!Double.isNaN(a)) {
saw += corn_w[i];
sawd += corn_w[i] * a;
sawv += corn_w[i] * v;
}
}
if (saw > 0) {
sawd /= saw; // here it is interpolated alpha
sawv /= saw;
if (sawd <= terrain_max) {
synthetic_terrain[nScene][npix] = terrain_pix;
}
if (sawd >= vegetation_min) {
synthetic_vegetation[nScene][npix] = sawv + d0; // added offset
}
} else { // no alpha
synthetic_terrain[nScene][npix] =terrain_pix;
}
} else { // offset points outside of the image - unlikely
synthetic_terrain[nScene][npix] = terrain_pix;
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return synthetic;
}
public double [] renderWithAlpha(
final double [] alpha,
final double [][] scene_offsets, // subtract if not null
......
......@@ -64,6 +64,9 @@ public class VegetationModel {
public String reference_scene; // timestamp
public int reference_index; // timestamp
public double [][] tva;
public boolean isFailed() {
return failed;
}
......@@ -137,6 +140,16 @@ public class VegetationModel {
System.out.println("VegetationModel.saveState(): saved "+path); // dir+title+PAR_EXT);
}
public String getSegmentsDir(String sub_dir) {
//model_directory
String segments_path = VegetationLMA.getSavePath(model_directory,sub_dir,"");
// create if it does not exist
File segments_dir = new File(segments_path);
segments_dir.mkdirs();
return segments_path;
}
public VegetationModel(
String dir,
String title) {
......@@ -213,7 +226,12 @@ public class VegetationModel {
return;
}
public void setTVA(double [][] tva) {
this.tva = tva;
}
public double [][] getTVA(){
return this.tva;
}
/**
* Prepare terrain rendered, terrain average, vegetation average and vegetation offset. Created from test_vegetation
......@@ -1075,9 +1093,13 @@ public class VegetationModel {
boolean combine_segments)
{
String model_directory = clt_parameters.imp.terr_model_path; // Model directory path with version.
String model_state_file = clt_parameters.imp.terr_model_state; // Model vegetation source data (w/o extension).
// Temporary , it is actually a model directory // 1697877487_245877-TERR-VEG-STATE.terrveg-tiff
String model_directory = "/media/elphel/SSD3-4GB/lwir16-proc/berdich3/linked/linked_1697875868-1697879449-b/1697877487_245877/v35";
String model_state_file = "1697877487_245877-TERR-VEG-STATE";
// String model_directory = "/media/elphel/SSD3-4GB/lwir16-proc/berdich3/linked/linked_1697875868-1697879449-b/1697877487_245877/v35";
// String model_state_file = "1697877487_245877-TERR-VEG-STATE";
if (model_state_file != null) {
VegetationModel vegetationModel = new VegetationModel(
......@@ -1090,6 +1112,7 @@ public class VegetationModel {
return;
}
// old version below
final int dx_slice = 1;
final int dy_slice = 2;
......@@ -1278,6 +1301,7 @@ public class VegetationModel {
double alpha_push = 12; // 10.0; // 15.0; // push from alpha==0.5
double alpha_push_neutral = 0.5; // 0.6; // 0.8; // alpha point from which push (closer to opaque)
double alpha_push_center = 1.5; // weight of center alpha pixel relative to each of the 4 ortho ones
boolean alpha_en_holes = true;
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
double terr_lpf = 0.1; // 0.15; /// 0.2; /// 0.1; // pull terrain to average of 4 neighbors (very small)
......@@ -1399,6 +1423,7 @@ public class VegetationModel {
true,
"terrain_vegetation_averages.tiff",
new String[] {"terrain","vegetation"});
}
VegetationLMA vegetationLMA = new VegetationLMA (
width, // int width,
......@@ -1463,8 +1488,8 @@ public class VegetationModel {
alpha_push, // final double alpha_push, // 5.0; // push from alpha==0.5
alpha_push_neutral, // double alpha_push_neutral = 0.8; // alpha point from which push (closer to opaque)
alpha_push_center,// final double alpha_push_center,// 1.5; // weight of center alpha pixel relative to each of the 4 ortho ones
alpha_en_holes, // final boolean alpha_en_holes, // Search for small semi-transparent holes, disable diffusion of local alpha minimums
alpha_mm_hole, // 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
terr_lpf, // final double terr_lpf, // pull terrain to average of 4 neighbors (very small)
veget_lpf, // final double veget_lpf, // pull vegetation to average of 4 neighbors (very small - maybe not needed)
terr_pull0, // final double terr_pull0, // pull terrain to zero (makes sense with UM
......@@ -1570,14 +1595,17 @@ public class VegetationModel {
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; //
boolean um_en = clt_parameters.imp.terr_um_en; // true;
double um_sigma = clt_parameters.imp.terr_um_sigma; // 1.0;
double um_weight = clt_parameters.imp.terr_um_weight; // 0.8;
double nan_tolerance = clt_parameters.imp.terr_nan_tolerance; // 0.001;
int nan_grow = clt_parameters.imp.terr_nan_grow; // 20;
boolean tile_woi = clt_parameters.imp.terr_um_en; // enable EM filter
boolean tile_woi = clt_parameters.imp.terr_tile_woi; // scan woi_enclosing, false - run a single woi_last
Rectangle woi_enclosing = clt_parameters.imp.terr_woi_enclos; // new Rectangle(0, 0, 200, 160); // will be tiled, using width/height from woi_step;
Rectangle woi_step = clt_parameters.imp.terr_woi_step; // new Rectangle(10,10,20,20);
Rectangle woi_last = clt_parameters.imp.terr_woi_last; // new Rectangle(160,310,20,20); // 170
......@@ -1598,6 +1626,7 @@ public class VegetationModel {
double alpha_push = clt_parameters.imp.terr_alpha_push; // 12; // 10.0; // 15.0; // push from alpha==0.5
double alpha_push_neutral =clt_parameters.imp.terr_alpha_push_neutral; // 0.5; // 0.6; // 0.8; // alpha point from which push (closer to opaque)
double alpha_push_center = clt_parameters.imp.terr_alpha_weight_center; // 1.5; // weight of center alpha pixel relative to each of the 4 ortho ones
boolean alpha_en_holes = clt_parameters.imp.terr_en_holes; // true; // false; // true;
double alpha_mm_hole = clt_parameters.imp.terr_alpha_mm_hole; // 0.1; // NaN to disable. Local "almost minimum" (lower than this fraction between min and max neighbor) is not subject to alpha_lpf
double terr_lpf = clt_parameters.imp.terr_terr_lpf; // 0.1; // 0.15; /// 0.2; /// 0.1; // pull terrain to average of 4 neighbors (very small)
double veget_lpf = clt_parameters.imp.terr_veget_lpf; // 0.2; //0.15; /// 0.2; //// 0.01; /// 0.1; // pull vegetation to average of 4 neighbors (very small - maybe not needed)
......@@ -1641,11 +1670,10 @@ public class VegetationModel {
boolean restore_mode = false;
boolean save_par_files = true; // false;
boolean diff_mode = true;
String segments_dir = "/media/elphel/SSD3-4GB/lwir16-proc/berdich3/debug/vegetation/segments_new/";
// boolean diff_mode = true;
// String segments_dir = "/media/elphel/SSD3-4GB/lwir16-proc/berdich3/debug/vegetation/segments_new/";
String segments_dir = getSegmentsDir(segments_sub);
// boolean next_run = false;
boolean read_pars = false; // true; /// false; /// true; // false; // true;
......@@ -1659,12 +1687,48 @@ public class VegetationModel {
// debug feature to read to continue - needs to be cleaned up/replaced
String parameters_path = "/media/elphel/SSD3-4GB/lwir16-proc/berdich3/debug/vegetation/essential/parameters_vector_data_x143-y317-w35-h35-al100.0-alo0.0-alp10.0-alin-tl0.2-vl0.01-tp0.01-vp0.01-bp5.0-um1.0_0.8.tiff";
boolean last_run = false;
double [][] laplacian_in = new double [2 + terrain_scenes_render.length][];
double [][] laplacian_all = new double [2 + terrain_scenes_render.length][];
String [] titles_laplacian = new String[laplacian_in.length];
System.arraycopy(terrain_scenes_render, 0, laplacian_in, 0, terrain_scenes_render.length);
laplacian_in[terrain_scenes_render.length + 0] = terrain_average_render;
laplacian_in[terrain_scenes_render.length + 1] = vegetation_average_render;
titles_laplacian[terrain_scenes_render.length + 0] = "terrain_average";
titles_laplacian[terrain_scenes_render.length + 1] = "vegetation_average";
double weight_diag = .7;
for (int n = 0; n < laplacian_all.length; n++) {
if (n < terrain_scenes_render.length) {
titles_laplacian[n]=scene_names[n];
}
laplacian_in[n] = laplacian_in[n].clone(); // isolate from UM
zerosToNans (
laplacian_in[n], // final double [][] data,
full.width, // final int width,
nan_tolerance, // final double tolerance,
nan_grow); // final int grow)
laplacian_all[n] = VegetationLMA.laplacian(
false, // final boolean gaussian,
laplacian_in[n], // final double [] data_in,
full.width, // final int width,
weight_diag); // final double weight_diag);
}
if (debugLevel > -2){
ShowDoubleFloatArrays.showArraysHyperstack(
new double [][][]{laplacian_in, laplacian_all}, // double[][][] pixels,
full.width, // int width,
reference_scene+"-laplacian-"+weight_diag+".tiff", // String title, "time_derivs-rt"+diff_time_rt+"-rxy"+diff_time_rxy,
titles_laplacian, // String [] titles, // all slices*frames titles or just slice titles or null
new String[] {"source","laplacian"}, // String [] frame_titles, // frame titles or null
true); // boolean show)
}
if (um_en) {
double [][] um_data = new double [terrain_scenes_render.length+2][];
......@@ -1685,6 +1749,10 @@ public class VegetationModel {
nan_tolerance, // final double tolerance,
nan_grow); // final int grow)
if ((debugLevel > 3) || um_en) {
double [][][] dbg_img = new double[3][vegetation_warp.length][vegetation_warp[0].length];
for (int n = 0; n < dbg_img.length; n++) {
......@@ -1707,7 +1775,7 @@ public class VegetationModel {
ShowDoubleFloatArrays.showArraysHyperstack(
dbg_img, // double[][][] pixels,
full.width, // int width,
"vegetation_offsets.tiff", // String title, "time_derivs-rt"+diff_time_rt+"-rxy"+diff_time_rxy,
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","dx","dy"}, // String [] frame_titles, // frame titles or null
true); // boolean show)
......@@ -1717,7 +1785,7 @@ public class VegetationModel {
full.width,
full.height,
true,
"terrain_rendered.tiff",
reference_scene+"-terrain_rendered.tiff",
scene_names);
ShowDoubleFloatArrays.showArrays(
......@@ -1725,7 +1793,7 @@ public class VegetationModel {
full.width,
full.height,
true,
"terrain_vegetation_averages.tiff",
reference_scene+"-terrain_vegetation_averages.tiff",
new String[] {"terrain","vegetation"});
}
VegetationLMA vegetationLMA = new VegetationLMA (this);
......@@ -1760,8 +1828,12 @@ public class VegetationModel {
break;
}
String par_path = restore_mode? "RESTORE": (read_pars ? parameters_path : null);
if (tile_woi) {
System.out.println("===== Will process WOI ("+woi.x+", "+woi.y+", "+woi.width+", "+woi.height+") of the enclosing WOI ("+
+woi_enclosing.x+", "+woi_enclosing.y+", "+woi_enclosing.width+", "+woi_enclosing.height+").");
} else {
System.out.println("===== Will process a single WOI ("+woi.x+", "+woi.y+", "+woi.width+", "+woi.height+").");
}
int num_samples = vegetationLMA.prepareLMA(
false, // final boolean keep_parameters,
woi, // final Rectangle woi,
......@@ -1781,8 +1853,8 @@ public class VegetationModel {
alpha_push, // final double alpha_push, // 5.0; // push from alpha==0.5
alpha_push_neutral, // double alpha_push_neutral = 0.8; // alpha point from which push (closer to opaque)
alpha_push_center,// final double alpha_push_center,// 1.5; // weight of center alpha pixel relative to each of the 4 ortho ones
alpha_en_holes, // final boolean alpha_en_holes, // Search for small semi-transparent holes, disable diffusion of local alpha minimums
alpha_mm_hole, // 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
terr_lpf, // final double terr_lpf, // pull terrain to average of 4 neighbors (very small)
veget_lpf, // final double veget_lpf, // pull vegetation to average of 4 neighbors (very small - maybe not needed)
terr_pull0, // final double terr_pull0, // pull terrain to zero (makes sense with UM
......
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