Commit e72b18ee authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Before converting to dual-band comparison

parent d152fbaa
Loading
Loading
Loading
Loading
+33 −3
Original line number Diff line number Diff line
@@ -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;                           
+247 −24

File changed.

Preview size limit exceeded, changes collapsed.

+88 −16
Original line number Diff line number Diff line
@@ -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