Commit 1893ac24 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Working, before adding low-elevation*alpha losses

parent 9a499c0a
Loading
Loading
Loading
Loading
+77 −16
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import java.util.StringTokenizer;

import com.elphel.imagej.common.GenericJTabbedDialog;
import com.elphel.imagej.orthomosaic.ComboMatch;
import com.elphel.imagej.vegetation.VegetationLMA;

public class IntersceneMatchParameters {
	public static String [] MODES3D = {"RAW", "INF", "FG", "BG"}; // RAW:-1
@@ -755,6 +756,8 @@ min_str_neib_fpn 0.35
	public boolean   terr_fit_alpha =         true;  // adjust vegetation alpha pixels
	public boolean   terr_fit_scenes =        true;  // adjust scene offsets (start from 0 always?)
	public boolean   terr_fit_elevations =    false; // adjust elevation pixels (not yet implemented)
	public boolean [] terr_fit_disable = new boolean [VegetationLMA.TVAO_TYPES];
	
	public double    terr_max_warp =          1.8;
	public int       terr_max_elevation =     22;    // maximal offset to consider when looking for vegetation influence

@@ -807,12 +810,21 @@ min_str_neib_fpn 0.35
	public double    terr_hifreq_weight =     10.0; // 22.5; //  0 - do not use high-freq. Relative weight of laplacian components differfences to the DC ones
	public double    terr_terr_corr =          1.0; // relative weight of average mismatch between images and model (terrain corrections)
	public double    terr_reg_weights =        0.25; // fraction of the total weight used for regularization
	
	public double    terr_lambda =             5.0;  // 
	public double    terr_lambda_scale_good =  0.5;
	public double    terr_lambda_scale_bad =   8.0;
	public double    terr_lambda_max =      1000;
	public double    terr_rms_diff =           1e-8; // 0.0001; virtually forever
	public int       terr_num_iter =          25;    // 100;
// second run
	public boolean   terr_recalc_weights =    false; // recalculate weight depending on terrain visibility
	public double    terr_recalc_opaque =      0.9;  // above is opaque  
	public double    terr_recalc_pedestal =    0.05; // weight of opaque tiles
	public double    terr_recalc_frac =        0.5;  // discard transparency below this fraction of the maximal one
	public double    terr_recalc_dist =        1.0;  // increase weight for far pixels (double if scale differece == this)
	public boolean   terr_recalc_average =    false; // apply transparency to average mismatch
	
	
	// combine  parameters
	public int       terr_border_width =       6;
@@ -2048,8 +2060,10 @@ min_str_neib_fpn 0.35
		gd.addCheckbox    ("Adjust vegetation",    terr_fit_veget,     "Adjust vegetation pixels.");
		gd.addCheckbox    ("Adjust alpha",         terr_fit_alpha,     "Adjust vegetation alpha pixels.");
		gd.addCheckbox    ("Adjust scene offsets", terr_fit_scenes,    "Adjust scene offsets (start from 0 always?).");
		gd.addCheckbox    ("Adjust elevation",     terr_fit_elevations,"Adjust elevation pixels (not yet implemented).");
		
		gd.addCheckbox    ("Adjust elevation",     terr_fit_elevations,"Adjust elevation pixels.");
		for (int i = 0; i < terr_fit_disable.length; i++) {
			gd.addCheckbox    ("Skip "+VegetationLMA.TVAO_NAMES[i],   terr_fit_disable[i],"Skip adjustment of "+VegetationLMA.TVAO_NAMES[i]+".");
		}
		gd.addNumericField("Maximal warp",         terr_max_warp, 5,7,"pix", 	"(1.8) Do not use scenes where distance between vegetation projection exceeds this.");
		gd.addNumericField("Min elevation/offset", terr_max_elevation, 0,3,"pix","Maximal offset to consider when looking for vegetation influence.");
		
@@ -2100,7 +2114,16 @@ min_str_neib_fpn 0.35
		gd.addNumericField("Lambda scale on bad",  terr_lambda_scale_bad, 5,7,"","Scale lambda if RMSE worsened.");
		gd.addNumericField("Lambda max to fail",   terr_lambda_max, 5,7,"",     "Fail if lambda gets larger than that.");
		gd.addNumericField("RMSE difference",      terr_rms_diff, 10,12,"",     "Exit if RMSE improvement is lower.");
		gd.addNumericField("(Maximal) iterations", terr_num_iter, 0,3,"", 	    "Maximal number of LMA iterations.");
		gd.addNumericField("Maximal iterations",   terr_num_iter, 0,3,"", 	    "Maximal number of LMA iterations.");
		
		gd.addMessage     ("Second LMA run");
		gd.addCheckbox    ("Recalculate weighths", terr_recalc_weights,         "Recalculate weights depending on terrain visibility.");
		gd.addNumericField("Opaque alpha",         terr_recalc_opaque, 5,7,"", "Alpha above his means opaque.");
		gd.addNumericField("Opaque weight",        terr_recalc_pedestal, 5,7,"","Relative weight of opaque tiles.");
		gd.addNumericField("Transparency fraction",terr_recalc_frac, 5,7,"","Discard transparency below this fraction of the maximal one.");
		gd.addNumericField("Transparency distance",terr_recalc_dist, 5,7,"","Increase weight for far pixels (double if scale differece == this).");
		gd.addCheckbox    ("Transparency average", terr_recalc_average,         "Apply transparency to average mismatch.");
		
		
		gd.addMessage     ("Combining LMA results segments");
		gd.addNumericField("Overlap width",        terr_border_width, 0,3,"","Width of the inter-tile oiverlap border.");
@@ -2774,6 +2797,10 @@ min_str_neib_fpn 0.35
		terr_fit_scenes =          gd.getNextBoolean();// boolean
		terr_fit_elevations =      gd.getNextBoolean();// boolean
		
		for (int i = 0; i < terr_fit_disable.length; i++) {
			terr_fit_disable[i] =      gd.getNextBoolean();// boolean
		}
		
		terr_max_warp =            gd.getNextNumber();// double 
		terr_max_elevation = (int) gd.getNextNumber();// int
		
@@ -2820,6 +2847,13 @@ min_str_neib_fpn 0.35
		terr_rms_diff =            gd.getNextNumber();// double 
		terr_num_iter =      (int) gd.getNextNumber();// int    

		terr_recalc_weights =      gd.getNextBoolean();// boolean
		terr_recalc_opaque =       gd.getNextNumber(); // double 
		terr_recalc_pedestal =     gd.getNextNumber(); // double 
		terr_recalc_frac =         gd.getNextNumber(); // double 
		terr_recalc_dist =         gd.getNextNumber(); // double 
		terr_recalc_average =      gd.getNextBoolean();// boolean
		
		terr_border_width =  (int) gd.getNextNumber(); // int    
		terr_render_open =         gd.getNextBoolean();// boolean
		terr_render_no_alpha =     gd.getNextBoolean();// boolean
@@ -3463,7 +3497,10 @@ min_str_neib_fpn 0.35
		properties.setProperty(prefix+"terr_fit_alpha",              terr_fit_alpha+"");          // boolean
		properties.setProperty(prefix+"terr_fit_scenes",             terr_fit_scenes+"");         // boolean
		properties.setProperty(prefix+"terr_fit_elevations",         terr_fit_elevations+"");     // boolean

		for (int i = 0; i < terr_fit_disable.length; i++) {
			String prop_name = prefix+"terr_fit_disable_"+VegetationLMA.TVAO_NAMES[i];
			properties.setProperty(prop_name,                        terr_fit_disable[i]+"");     // boolean
		}
		properties.setProperty(prefix+"terr_max_warp",               terr_max_warp+"");           // double 
		properties.setProperty(prefix+"terr_max_elevation",          terr_max_elevation+"");      // int
		properties.setProperty(prefix+"terr_min_scenes",             terr_min_scenes+"");         // int
@@ -3509,6 +3546,13 @@ min_str_neib_fpn 0.35
		properties.setProperty(prefix+"terr_rms_diff",               terr_rms_diff+"");           // double 
		properties.setProperty(prefix+"terr_num_iter",               terr_num_iter+"");           // int
		
		properties.setProperty(prefix+"terr_recalc_weights",         terr_recalc_weights+"");     // boolean
		properties.setProperty(prefix+"terr_recalc_opaque",          terr_recalc_opaque+"");      // double 
		properties.setProperty(prefix+"terr_recalc_pedestal",        terr_recalc_pedestal+"");    // double 
		properties.setProperty(prefix+"terr_recalc_frac",            terr_recalc_frac+"");        // double 
		properties.setProperty(prefix+"terr_recalc_dist",            terr_recalc_dist+"");        // double 
		properties.setProperty(prefix+"terr_recalc_average",         terr_recalc_average+"");     // boolean

		properties.setProperty(prefix+"terr_border_width",           terr_border_width+"");       // int    
		properties.setProperty(prefix+"terr_render_open",            terr_render_open+"");        // boolean
		properties.setProperty(prefix+"terr_render_no_alpha",        terr_render_no_alpha+"");    // boolean
@@ -4170,7 +4214,10 @@ min_str_neib_fpn 0.35
		if (properties.getProperty(prefix+"terr_fit_alpha")!=          null) terr_fit_alpha=Boolean.parseBoolean(properties.getProperty(prefix+"terr_fit_alpha"));
		if (properties.getProperty(prefix+"terr_fit_scenes")!=         null) terr_fit_scenes=Boolean.parseBoolean(properties.getProperty(prefix+"terr_fit_scenes"));
		if (properties.getProperty(prefix+"terr_fit_elevations")!=     null) terr_fit_elevations=Boolean.parseBoolean(properties.getProperty(prefix+"terr_fit_elevations"));
		
		for (int i = 0; i < terr_fit_disable.length; i++) {
			String prop_name = prefix+"terr_fit_disable_"+VegetationLMA.TVAO_NAMES[i];
			if (properties.getProperty(prop_name)!=                    null) terr_fit_disable[i]=Boolean.parseBoolean(properties.getProperty(prop_name));
		}
		if (properties.getProperty(prefix+"terr_max_warp")!=           null) terr_max_warp=Double.parseDouble(properties.getProperty(prefix+"terr_max_warp"));
		if (properties.getProperty(prefix+"terr_max_elevation")!=      null) terr_max_elevation=Integer.parseInt(properties.getProperty(prefix+"terr_max_elevation"));
		if (properties.getProperty(prefix+"terr_min_scenes")!=         null) terr_min_scenes=Integer.parseInt(properties.getProperty(prefix+"terr_min_scenes"));
@@ -4217,6 +4264,13 @@ min_str_neib_fpn 0.35
		if (properties.getProperty(prefix+"terr_rms_diff")!=           null) terr_rms_diff=Double.parseDouble(properties.getProperty(prefix+"terr_rms_diff"));
		if (properties.getProperty(prefix+"terr_num_iter")!=           null) terr_num_iter=Integer.parseInt(properties.getProperty(prefix+"terr_num_iter"));

		if (properties.getProperty(prefix+"terr_recalc_weights")!=     null) terr_recalc_weights=Boolean.parseBoolean(properties.getProperty(prefix+"terr_recalc_weights"));
		if (properties.getProperty(prefix+"terr_recalc_opaque")!=      null) terr_recalc_opaque=Double.parseDouble(properties.getProperty(prefix+"terr_recalc_opaque"));
		if (properties.getProperty(prefix+"terr_recalc_pedestal")!=    null) terr_recalc_pedestal=Double.parseDouble(properties.getProperty(prefix+"terr_recalc_pedestal"));
		if (properties.getProperty(prefix+"terr_recalc_frac")!=        null) terr_recalc_frac=Double.parseDouble(properties.getProperty(prefix+"terr_recalc_frac"));
		if (properties.getProperty(prefix+"terr_recalc_dist")!=        null) terr_recalc_dist=Double.parseDouble(properties.getProperty(prefix+"terr_recalc_dist"));
		if (properties.getProperty(prefix+"terr_recalc_average")!=     null) terr_recalc_average=Boolean.parseBoolean(properties.getProperty(prefix+"terr_recalc_average"));
		
		if (properties.getProperty(prefix+"terr_border_width")!=       null) terr_border_width=Integer.parseInt(properties.getProperty(prefix+"terr_border_width"));
		if (properties.getProperty(prefix+"terr_render_open")!=        null) terr_render_open=Boolean.parseBoolean(properties.getProperty(prefix+"terr_render_open"));
		if (properties.getProperty(prefix+"terr_render_no_alpha")!=    null) terr_render_no_alpha=Boolean.parseBoolean(properties.getProperty(prefix+"terr_render_no_alpha"));
@@ -4847,7 +4901,7 @@ min_str_neib_fpn 0.35
		imp.terr_fit_alpha =                     this.terr_fit_alpha;                           
		imp.terr_fit_scenes =                    this.terr_fit_scenes;                           
		imp.terr_fit_elevations =                this.terr_fit_elevations;
		
		imp.terr_fit_disable =                   this.terr_fit_disable.clone();
		imp.terr_max_warp =                      this.terr_max_warp;
		imp.terr_max_elevation =                 this.terr_max_elevation;
		imp.terr_min_scenes =                    this.terr_min_scenes;
@@ -4893,6 +4947,13 @@ min_str_neib_fpn 0.35
		imp.terr_rms_diff =                      this.terr_rms_diff;                           
		imp.terr_num_iter =                      this.terr_num_iter;                           

		imp.terr_recalc_weights =                this.terr_recalc_weights;                           
		imp.terr_recalc_opaque =                 this.terr_recalc_opaque;                           
		imp.terr_recalc_pedestal =               this.terr_recalc_pedestal;
		imp.terr_recalc_frac =                   this.terr_recalc_frac;
		imp.terr_recalc_dist =                   this.terr_recalc_dist;
		imp.terr_recalc_average =                this.terr_recalc_average;
		
		imp.terr_border_width =                  this.terr_border_width;                           
		imp.terr_render_open =                   this.terr_render_open;                           
		imp.terr_render_no_alpha =               this.terr_render_no_alpha;                           
+661 −193

File changed.

Preview size limit exceeded, changes collapsed.

+29 −2
Original line number Diff line number Diff line
@@ -1450,6 +1450,8 @@ public class VegetationModel {
		boolean   fit_scenes =        clt_parameters.imp.terr_fit_scenes;     // true;  // adjust scene offsets (start from 0 always?)
		boolean   fit_elevations =    clt_parameters.imp.terr_fit_elevations; // false; // adjust elevation pixels (not yet implemented)
		
		boolean [] fit_disable =      clt_parameters.imp.terr_fit_disable.clone();  
		
		double    reg_weights =       clt_parameters.imp.terr_reg_weights;         // 0.25;        // fraction of the total weight used for regularization
		double    lambda =            clt_parameters.imp.terr_lambda;              // 5.0; // 0.1;
		double    lambda_scale_good = clt_parameters.imp.terr_lambda_scale_good;   // 0.5;
@@ -1480,7 +1482,12 @@ public class VegetationModel {
		
		boolean     show_final_result = !tile_woi; // true; (maybe make saving results in tiled mode?

		
		boolean   recalc_weights =        clt_parameters.imp.terr_recalc_weights ;      //false; // recalculate weight depending on terrain visibility
		double    transparency_opaque =   1.0 - clt_parameters.imp.terr_recalc_opaque ; // 0.9;  // above is opaque  
		double    transparency_pedestal = clt_parameters.imp.terr_recalc_pedestal ;     // 0.05; // weight of opaque tiles  
		double    transparency_frac =     clt_parameters.imp.terr_recalc_frac ;         // 1.0;  // increase weight for far pixels (double if scale differece == this)  
		double    transparency_dist =     clt_parameters.imp.terr_recalc_dist ;         // 0.05; // weight of opaque tiles  
		boolean   recalc_average =        clt_parameters.imp.terr_recalc_average ;      //false; // apply transparency to average mismatch
		
//clt_parameters.imp.; // 		
		
@@ -2005,6 +2012,7 @@ public class VegetationModel {
					fit_alpha,      // final boolean            adjust_alpha,
					fit_scenes,     // final boolean            adjust_scenes,
					fit_elevations, // final boolean            adjust_elevations,
					fit_disable,    // final boolean []         fit_disable,  
					reg_weights,   // final double             reg_weights,        // fraction of the total weight used for regularization
					alpha_loss,    // final double             alpha_loss,         // quadratic loss when alpha reaches -1.0 or 2.0 
					alpha_offset,  // final double             alpha_offset,       // quadratic loss when alpha reaches -1.0 or 2.0
@@ -2059,6 +2067,15 @@ public class VegetationModel {
						par_path, // String        path,
						true,     // boolean       keep_settings,
						null);    // Rectangle [] file_wois);      //  if not null, should be Rectangle[2] {woi_veg,woi} - will return woi data and not input parameters to this instance
				if (recalc_weights) {
					vegetationLMA.applyTransparency(
							null,                  // final double []   vector,
							transparency_opaque,   // final double      transparency_opaque,
							transparency_pedestal, // final double      transparency_pedestal,
							transparency_frac,     // final double      transparency_frac,
							transparency_dist,     // final double      transparency_dist,			
							recalc_average);       // final boolean     recalc_average);
				}
			}
			// old 
			if ("RESTORE".equals(par_path)) {
@@ -2074,7 +2091,7 @@ public class VegetationModel {
				}
			}
			
			if ((show_final_result) && (debugLevel > 0)) {
			if ((show_final_result) && (debugLevel > -2)) { // 0)) {
				String reconstructed_title = reference_scene+"-reconstructed-initial";
				vegetationLMA.showYfX(
						null, // double [] vector,
@@ -2127,6 +2144,16 @@ public class VegetationModel {

	  			elev_pull0 *= 0.01;
	  			vegetationLMA.elevation_pull0 = elev_pull0;
	  			
				if (recalc_weights) {
					vegetationLMA.applyTransparency(
							null,                  // final double []   vector,
							transparency_opaque,   // final double      transparency_opaque,
							transparency_pedestal, // final double      transparency_pedestal,
							transparency_frac,     // final double      transparency_frac,
							transparency_dist,     // final double      transparency_dist,			
							recalc_average);       // final boolean     recalc_average);				}
				}
	  			if (debugLevel > -3) {
	  				lma_rslt= vegetationLMA.runLma( // <0 - failed, >=0 iteration number (1 - immediately)
	  						lambda,           // double lambda,           // 0.1