Commit 2f3efffd authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Working snapshot

parent 80a76a64
Loading
Loading
Loading
Loading
+12 −2
Original line number Original line Diff line number Diff line
@@ -524,6 +524,7 @@ public class CLTParameters {
	
	
	public boolean       lre_use_min_max =         true;  // when trimming by tone, use min/max of the FG/BG instead of weighted averages 
	public boolean       lre_use_min_max =         true;  // when trimming by tone, use min/max of the FG/BG instead of weighted averages 
	public double        lre_temp_radius =         11.5;  // How far to look around for FG trimming by temperature
	public double        lre_temp_radius =         11.5;  // How far to look around for FG trimming by temperature
	public int           lre_temp_same_radius =     1;    // new opaque/transparent pixel should have same within +/- this radius from it (<=0 - disable)
	public int           lre_temp_min =             2;    // Minimal number of each of FG/BG while trimming by temperature
	public int           lre_temp_min =             2;    // Minimal number of each of FG/BG while trimming by temperature
	public double        lre_temp_weight =         20.0;  // Multiply -1.0..+1.0 range of the current pixel between average BG(-1) and FG(+1)
	public double        lre_temp_weight =         20.0;  // Multiply -1.0..+1.0 range of the current pixel between average BG(-1) and FG(+1)
	public double        lre_min_use_occl =         1.5;  // Minimal FG/BG difference to use trimming by occlusions. For lower use only temperature/tone
	public double        lre_min_use_occl =         1.5;  // Minimal FG/BG difference to use trimming by occlusions. For lower use only temperature/tone
@@ -1644,6 +1645,8 @@ public class CLTParameters {
		
		
		properties.setProperty(prefix+"lre_use_min_max",            this.lre_use_min_max+"");            // boolean 
		properties.setProperty(prefix+"lre_use_min_max",            this.lre_use_min_max+"");            // boolean 
		properties.setProperty(prefix+"lre_temp_radius",            this.lre_temp_radius+"");            // double
		properties.setProperty(prefix+"lre_temp_radius",            this.lre_temp_radius+"");            // double
		properties.setProperty(prefix+"lre_temp_same_radius",       this.lre_temp_same_radius+"");       // int     
		
		properties.setProperty(prefix+"lre_temp_min",               this.lre_temp_min+"");               // int     
		properties.setProperty(prefix+"lre_temp_min",               this.lre_temp_min+"");               // int     
		properties.setProperty(prefix+"lre_temp_weight",            this.lre_temp_weight+"");            // double
		properties.setProperty(prefix+"lre_temp_weight",            this.lre_temp_weight+"");            // double
		properties.setProperty(prefix+"lre_min_use_occl",           this.lre_min_use_occl+"");           // double
		properties.setProperty(prefix+"lre_min_use_occl",           this.lre_min_use_occl+"");           // double
@@ -2641,6 +2644,8 @@ public class CLTParameters {
		
		
		if (properties.getProperty(prefix+"lre_use_min_max")!=null)            this.lre_use_min_max=Boolean.parseBoolean(properties.getProperty(prefix+"lre_use_min_max"));// boolean 
		if (properties.getProperty(prefix+"lre_use_min_max")!=null)            this.lre_use_min_max=Boolean.parseBoolean(properties.getProperty(prefix+"lre_use_min_max"));// boolean 
		if (properties.getProperty(prefix+"lre_temp_radius")!=null)            this.lre_temp_radius=Double.parseDouble(properties.getProperty(prefix+"lre_temp_radius"));// double
		if (properties.getProperty(prefix+"lre_temp_radius")!=null)            this.lre_temp_radius=Double.parseDouble(properties.getProperty(prefix+"lre_temp_radius"));// double
		if (properties.getProperty(prefix+"lre_temp_same_radius")!=null)       this.lre_temp_same_radius=Integer.parseInt(properties.getProperty(prefix+"lre_temp_same_radius"));// int     
		
		if (properties.getProperty(prefix+"lre_temp_min")!=null)               this.lre_temp_min=Integer.parseInt(properties.getProperty(prefix+"lre_temp_min"));// int     
		if (properties.getProperty(prefix+"lre_temp_min")!=null)               this.lre_temp_min=Integer.parseInt(properties.getProperty(prefix+"lre_temp_min"));// int     
		if (properties.getProperty(prefix+"lre_temp_weight")!=null)            this.lre_temp_weight=Double.parseDouble(properties.getProperty(prefix+"lre_temp_weight"));// double
		if (properties.getProperty(prefix+"lre_temp_weight")!=null)            this.lre_temp_weight=Double.parseDouble(properties.getProperty(prefix+"lre_temp_weight"));// double
		if (properties.getProperty(prefix+"lre_min_use_occl")!=null)           this.lre_min_use_occl=Double.parseDouble(properties.getProperty(prefix+"lre_min_use_occl"));// double
		if (properties.getProperty(prefix+"lre_min_use_occl")!=null)           this.lre_min_use_occl=Double.parseDouble(properties.getProperty(prefix+"lre_min_use_occl"));// double
@@ -3909,8 +3914,11 @@ public class CLTParameters {
		
		
		gd.addCheckbox ("Use min/max instead of averages",        this.lre_use_min_max, // true
		gd.addCheckbox ("Use min/max instead of averages",        this.lre_use_min_max, // true
				"when trimming by tone, use min/max of the FG/BG instead of weighted averages.");
				"when trimming by tone, use min/max of the FG/BG instead of weighted averages.");
		gd.addNumericField("Trim by temperature radius",          this.lre_temp_radius, 5,7,"",
		gd.addNumericField("Trim by temperature radius",          this.lre_temp_radius, 5,7,"pix",
				"How far to look around for FG trimming by temperature.");
				"How far to look around for FG trimming by temperature.");
		gd.addNumericField("Old same transparency within radius", this.lre_temp_same_radius, 0,3,"pix", // 10
				"New opaque/transparent pixel should have same within +/- this radius from it (<=0 - disable).");
		
		gd.addNumericField("Min FG and BG neibs within radius",   this.lre_temp_min, 0,3,"", // 10
		gd.addNumericField("Min FG and BG neibs within radius",   this.lre_temp_min, 0,3,"", // 10
				"Minimal number of each of FG/BG while trimming by temperature.");
				"Minimal number of each of FG/BG while trimming by temperature.");
		gd.addNumericField("Cost weight of temperature",          this.lre_temp_weight, 5,7,"",
		gd.addNumericField("Cost weight of temperature",          this.lre_temp_weight, 5,7,"",
@@ -5056,6 +5064,8 @@ public class CLTParameters {
		
		
		this.lre_use_min_max=              gd.getNextBoolean(); // boolean 
		this.lre_use_min_max=              gd.getNextBoolean(); // boolean 
		this.lre_temp_radius=              gd.getNextNumber();  // double
		this.lre_temp_radius=              gd.getNextNumber();  // double
		this.lre_temp_same_radius=   (int) gd.getNextNumber();  // int     
		
		this.lre_temp_min=           (int) gd.getNextNumber();  // int     
		this.lre_temp_min=           (int) gd.getNextNumber();  // int     
		this.lre_temp_weight=              gd.getNextNumber();  // double  
		this.lre_temp_weight=              gd.getNextNumber();  // double  
		this.lre_min_use_occl=             gd.getNextNumber();  // double  
		this.lre_min_use_occl=             gd.getNextNumber();  // double  
+83 −57
Original line number Original line Diff line number Diff line
@@ -2397,7 +2397,7 @@ public class TexturedModel {
				int    max_border =        tileClusters[nslice].getBorderIntMax();
				int    max_border =        tileClusters[nslice].getBorderIntMax();
				boolean is_sky =           tileClusters[nslice].isSky(sub_i);
				boolean is_sky =           tileClusters[nslice].isSky(sub_i);
				double min_disparity = is_sky? infinity_disparity : min_obj_disparity;
				double min_disparity = is_sky? infinity_disparity : min_obj_disparity;
				if (debugLevel > -2){
				if (debugLevel > -1){
					System.out.println("nslice="+nslice+" cluster #"+cluster_index+ " is_sky="+is_sky+" min_disparity="+min_disparity);
					System.out.println("nslice="+nslice+" cluster #"+cluster_index+ " is_sky="+is_sky+" min_disparity="+min_disparity);
				}
				}


@@ -4821,6 +4821,7 @@ public class TexturedModel {
			//"Trimming by temperature (tone)
			//"Trimming by temperature (tone)
			final boolean         use_min_max, // when trimming by tone, use min/max of the FG/BG instead of weighted averages
			final boolean         use_min_max, // when trimming by tone, use min/max of the FG/BG instead of weighted averages
			final double          temp_radius, //  =   11.5;  // How far to look around for FG trimming by temperature
			final double          temp_radius, //  =   11.5;  // How far to look around for FG trimming by temperature
			final int             temp_same_radius, // = 2; New opaque/transparent pixel should have same within +/- his radius			
			final int             temp_min, //  =       2;  // Minimal number of each of FG/BG while trimming by temperature
			final int             temp_min, //  =       2;  // Minimal number of each of FG/BG while trimming by temperature
			final double          temp_weight, //  =   20.0;  // Multiply -1.0..+1.0 range of the current pixel between average BG(-1) and FG(+1)
			final double          temp_weight, //  =   20.0;  // Multiply -1.0..+1.0 range of the current pixel between average BG(-1) and FG(+1)
			final double          min_use_occl,// =     1.5;  // Minimal FG/BG difference to use trimming by occlusions. For lower use only
			final double          min_use_occl,// =     1.5;  // Minimal FG/BG difference to use trimming by occlusions. For lower use only
@@ -4840,7 +4841,7 @@ public class TexturedModel {
		final int tilesY =        img_size/width/transform_size;
		final int tilesY =        img_size/width/transform_size;
		final int tiles =         tilesX * tilesY;
		final int tiles =         tilesX * tilesY;
		final int dbg_tile =      1820; // -1; // 4123;
		final int dbg_tile =      1820; // -1; // 4123;
		final int dbg_slice =     3; //0;
		final int dbg_slice =     -3; //0; Negative - disable
		
		
		final int      iradius = (int) Math.floor(temp_radius); // 1 - 3x3, 2 - 5x5
		final int      iradius = (int) Math.floor(temp_radius); // 1 - 3x3, 2 - 5x5
		final double [][] rad_weights = new double [2 * iradius + 1][2 * iradius + 1];
		final double [][] rad_weights = new double [2 * iradius + 1][2 * iradius + 1];
@@ -4858,7 +4859,7 @@ public class TexturedModel {
		final AtomicInteger aminus =  new AtomicInteger(0); // number of removed opaque pixels
		final AtomicInteger aminus =  new AtomicInteger(0); // number of removed opaque pixels
		final TileNeibs pn = new TileNeibs(width,height);
		final TileNeibs pn = new TileNeibs(width,height);
		int num_modified_pixels = 0;
		int num_modified_pixels = 0;
		final int dbg_pix = 115680;
		final int dbg_pix = 1115680;
		final boolean [][] new_alpha = new boolean[num_slices][img_size];
		final boolean [][] new_alpha = new boolean[num_slices][img_size];
		for (int nslice = 0; nslice < num_slices; nslice++) {
		for (int nslice = 0; nslice < num_slices; nslice++) {
			int fnslice = nslice;
			int fnslice = nslice;
@@ -5077,6 +5078,29 @@ public class TexturedModel {
													double cost_temp = Double.NaN;
													double cost_temp = Double.NaN;
													double ddisp = disparity_fg - disparity_bg; // FG disparity minus largest BG one;
													double ddisp = disparity_fg - disparity_bg; // FG disparity minus largest BG one;
													if ((iradius > 0) && !Double.isNaN(disparity_bg)) {
													if ((iradius > 0) && !Double.isNaN(disparity_bg)) {
														boolean ok_to_switch = true;
														// See if opposite transparency pixel exists near the current one.
														// If there are none - do not use temp-based cost to prevent inversion
														// of FG/BG temperature difference. Only add opaque pixels near opaque onws,
														// transparent - near transparent ones.
														if (temp_same_radius > 0) {
															ok_to_switch = false;
															boolean opaque = alpha_pix[fnslice][pix];
															search_same:
															{
																for (int tdy = -temp_same_radius; tdy <= temp_same_radius; tdy++) {
																	// skip center
																	for (int tdx = -temp_same_radius; tdx <= temp_same_radius; tdx++) {
																		int tpix = pn.getNeibIndex(pix, tdx, tdy);
																		if ((tpix >= 0) && (alpha_pix[fnslice][tpix] != opaque)){
																			ok_to_switch = true;
																			break search_same;
																		}																		
																	}
																}
															}
														}
														if (ok_to_switch) {
															double sw_bg = 0.0, swd_bg = 0.0, sw_fg = 0.0, swd_fg = 0.0;
															double sw_bg = 0.0, swd_bg = 0.0, sw_fg = 0.0, swd_fg = 0.0;
															int num_tfg = 0, num_tbg=0; // number of defined
															int num_tfg = 0, num_tbg=0; // number of defined
															double fg_min = Double.NaN, fg_max = Double.NaN;
															double fg_min = Double.NaN, fg_max = Double.NaN;
@@ -5133,7 +5157,7 @@ public class TexturedModel {


															cost_temp = 2* (textures[fnslice][pix] - avg_bg)/(avg_fg - avg_bg) - 1; // -1..+1
															cost_temp = 2* (textures[fnslice][pix] - avg_bg)/(avg_fg - avg_bg) - 1; // -1..+1
														}
														}
													
													} // if (ok_to_switch) {


													
													
													// calculate costs
													// calculate costs
@@ -5705,6 +5729,7 @@ public class TexturedModel {
		//"Trimming by temperature (tone)
		//"Trimming by temperature (tone)
		final boolean         temp_use_min_max = clt_parameters.lre_use_min_max; //  =         true;  // when trimming by tone, use min/max of the FG/BG instead of weighted averages 
		final boolean         temp_use_min_max = clt_parameters.lre_use_min_max; //  =         true;  // when trimming by tone, use min/max of the FG/BG instead of weighted averages 
		final double          temp_radius =   clt_parameters.lre_temp_radius;   // 11.5;  // How far to look around for FG trimming by temperature
		final double          temp_radius =   clt_parameters.lre_temp_radius;   // 11.5;  // How far to look around for FG trimming by temperature
		final int             temp_same_radius = clt_parameters.lre_temp_same_radius; // 2;  // New opaque/transparent pixel should have same within +/- this radius from it (<=0 - disable)
		final int             temp_min =      clt_parameters.lre_temp_min;      // 2;  // Minimal number of each of FG/BG while trimming by temperature
		final int             temp_min =      clt_parameters.lre_temp_min;      // 2;  // Minimal number of each of FG/BG while trimming by temperature
		final double          temp_weight =   clt_parameters.lre_temp_weight;   //20.0;  // Multiply -1.0..+1.0 range of the current pixel between average BG(-1) and FG(+1)   
		final double          temp_weight =   clt_parameters.lre_temp_weight;   //20.0;  // Multiply -1.0..+1.0 range of the current pixel between average BG(-1) and FG(+1)   
		final double          min_use_occl=   clt_parameters.lre_min_use_occl; //  1.5;  // Minimal FG/BG difference to use trimming by occlusions. For lower use only   
		final double          min_use_occl=   clt_parameters.lre_min_use_occl; //  1.5;  // Minimal FG/BG difference to use trimming by occlusions. For lower use only   
@@ -6079,6 +6104,7 @@ public class TexturedModel {
						//"Trimming by temperature (tone)
						//"Trimming by temperature (tone)
						temp_use_min_max,           // final boolean         use_min_max, // when trimming by tone, use min/max of the FG/BG instead of weighted averages
						temp_use_min_max,           // final boolean         use_min_max, // when trimming by tone, use min/max of the FG/BG instead of weighted averages
						temp_radius,                // final double          temp_radius, //  =          5.0;  // How far to look around for FG trimming by temperature
						temp_radius,                // final double          temp_radius, //  =          5.0;  // How far to look around for FG trimming by temperature
						temp_same_radius,           // final int             temp_same_radius, // = 2; New opaque/transparent pixel should have same within +/- his radius
						temp_min,                   // final int             temp_min, //  =               2;  // Minimal number of each of FG/BG while trimming by temperature
						temp_min,                   // final int             temp_min, //  =               2;  // Minimal number of each of FG/BG while trimming by temperature
						temp_weight,                // final double          temp_weight, //  =          5.0;  // Multiply -1.0..+1.0 range of the current pixel between average BG(-1) and FG(+1)
						temp_weight,                // final double          temp_weight, //  =          5.0;  // Multiply -1.0..+1.0 range of the current pixel between average BG(-1) and FG(+1)
						min_use_occl,               // final double          min_use_occl,// =     1.5;  // Minimal FG/BG difference to use trimming by occlusions. For lower use only
						min_use_occl,               // final double          min_use_occl,// =     1.5;  // Minimal FG/BG difference to use trimming by occlusions. For lower use only
@@ -6830,7 +6856,7 @@ public class TexturedModel {
					THREADS_MAX); // final int threadsMax)      // maximal number of threads to launch 
					THREADS_MAX); // final int threadsMax)      // maximal number of threads to launch 
		}
		}


		if (debugLevel > -2) {
		if (debugLevel > -1) {
			double [][] dbg_textures = new double [faded_textures.length * faded_textures[0].length][faded_textures[0][0].length];
			double [][] dbg_textures = new double [faded_textures.length * faded_textures[0].length][faded_textures[0][0].length];
			String [] dbg_titles = new String[dbg_textures.length];
			String [] dbg_titles = new String[dbg_textures.length];
			String [] dbg_subtitles = new String [faded_textures[0].length];
			String [] dbg_subtitles = new String [faded_textures[0].length];
@@ -6864,7 +6890,7 @@ public class TexturedModel {
					tex_um_weight);          // final double um_weight)
					tex_um_weight);          // final double um_weight)
		}
		}


		if (debugLevel > -2) {
		if (debugLevel > -1) {
			double [][] dbg_textures = new double [faded_textures.length * faded_textures[0].length][faded_textures[0][0].length];
			double [][] dbg_textures = new double [faded_textures.length * faded_textures[0].length][faded_textures[0][0].length];
			String [] dbg_titles = new String[dbg_textures.length];
			String [] dbg_titles = new String[dbg_textures.length];
			String [] dbg_subtitles = new String [faded_textures[0].length];
			String [] dbg_subtitles = new String [faded_textures[0].length];