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

Working snapshot

parent 80a76a64
...@@ -524,6 +524,7 @@ public class CLTParameters { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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,"",
...@@ -5055,7 +5063,9 @@ public class CLTParameters { ...@@ -5055,7 +5063,9 @@ public class CLTParameters {
this.lre_best_dir_frac= gd.getNextNumber(); // double this.lre_best_dir_frac= gd.getNextNumber(); // double
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
......
...@@ -2397,7 +2397,7 @@ public class TexturedModel { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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,64 +5078,87 @@ public class TexturedModel { ...@@ -5077,64 +5078,87 @@ 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)) {
double sw_bg = 0.0, swd_bg = 0.0, sw_fg = 0.0, swd_fg = 0.0; boolean ok_to_switch = true;
int num_tfg = 0, num_tbg=0; // number of defined // See if opposite transparency pixel exists near the current one.
double fg_min = Double.NaN, fg_max = Double.NaN; // If there are none - do not use temp-based cost to prevent inversion
double bg_min = Double.NaN, bg_max = Double.NaN; // of FG/BG temperature difference. Only add opaque pixels near opaque onws,
for (int tdy = -iradius; tdy <= iradius; tdy++) { // transparent - near transparent ones.
// skip center if (temp_same_radius > 0) {
for (int tdx = -iradius; tdx <= iradius; tdx++) if ((tdy != 0) || (tdx != 0)){ ok_to_switch = false;
int tpix = pn.getNeibIndex(pix, tdx, tdy); boolean opaque = alpha_pix[fnslice][pix];
if ((tpix >= 0) && !Double.isNaN(textures[fnslice][tpix])){ search_same:
// check it is the same cluster {
int ttileX = (tpix % width) / transform_size; for (int tdy = -temp_same_radius; tdy <= temp_same_radius; tdy++) {
int ttileY = (tpix / width) / transform_size; // skip center
if (slice_clusters[fnslice][ttileX + ttileY * tilesX] != this_clust) { for (int tdx = -temp_same_radius; tdx <= temp_same_radius; tdx++) {
continue; int tpix = pn.getNeibIndex(pix, tdx, tdy);
} if ((tpix >= 0) && (alpha_pix[fnslice][tpix] != opaque)){
double w = rad_weights[tdy + iradius][tdx + iradius]; ok_to_switch = true;
double d = textures[fnslice][tpix]; break search_same;
if (alpha_pix[fnslice][tpix]) { }
sw_fg += w;
swd_fg += w * d;
num_tfg ++;
if (!(d <= fg_max)) fg_max = d;
if (!(d >= fg_min)) fg_min = d;
} else {
sw_bg += w;
swd_bg += w * d;
num_tbg ++;
if (!(d <= bg_max)) bg_max = d;
if (!(d >= bg_min)) bg_min = d;
} }
} }
} }
} // for (int tdy = -iradius; tdy <= iradius; tdy++)
if ((num_tfg < temp_min) || (num_tbg < temp_min)) {
continue; // too few pixels to calculate
} }
double avg_fg = swd_fg / sw_fg; // weighted average of the foreground neighbors if (ok_to_switch) {
double avg_bg = swd_bg / sw_bg; // weighted average of the background neighbors double sw_bg = 0.0, swd_bg = 0.0, sw_fg = 0.0, swd_fg = 0.0;
if (use_min_max) { int num_tfg = 0, num_tbg=0; // number of defined
if (avg_fg > avg_bg) { double fg_min = Double.NaN, fg_max = Double.NaN;
avg_fg = fg_max; double bg_min = Double.NaN, bg_max = Double.NaN;
avg_bg = bg_min; for (int tdy = -iradius; tdy <= iradius; tdy++) {
} else { // skip center
avg_fg = fg_min; for (int tdx = -iradius; tdx <= iradius; tdx++) if ((tdy != 0) || (tdx != 0)){
avg_bg = bg_max; int tpix = pn.getNeibIndex(pix, tdx, tdy);
if ((tpix >= 0) && !Double.isNaN(textures[fnslice][tpix])){
// check it is the same cluster
int ttileX = (tpix % width) / transform_size;
int ttileY = (tpix / width) / transform_size;
if (slice_clusters[fnslice][ttileX + ttileY * tilesX] != this_clust) {
continue;
}
double w = rad_weights[tdy + iradius][tdx + iradius];
double d = textures[fnslice][tpix];
if (alpha_pix[fnslice][tpix]) {
sw_fg += w;
swd_fg += w * d;
num_tfg ++;
if (!(d <= fg_max)) fg_max = d;
if (!(d >= fg_min)) fg_min = d;
} else {
sw_bg += w;
swd_bg += w * d;
num_tbg ++;
if (!(d <= bg_max)) bg_max = d;
if (!(d >= bg_min)) bg_min = d;
}
}
}
} // for (int tdy = -iradius; tdy <= iradius; tdy++)
if ((num_tfg < temp_min) || (num_tbg < temp_min)) {
continue; // too few pixels to calculate
} }
double avg_fg = swd_fg / sw_fg; // weighted average of the foreground neighbors
double avg_bg = swd_bg / sw_bg; // weighted average of the background neighbors
if (use_min_max) {
if (avg_fg > avg_bg) {
avg_fg = fg_max;
avg_bg = bg_min;
} else {
avg_fg = fg_min;
avg_bg = bg_max;
}
}
if (avg_bg == avg_fg) {
continue; // all the same pixels?
}
//
cost_temp = 2* (textures[fnslice][pix] - avg_bg)/(avg_fg - avg_bg) - 1; // -1..+1
} }
if (avg_bg == avg_fg) { } // if (ok_to_switch) {
continue; // all the same pixels?
}
//
cost_temp = 2* (textures[fnslice][pix] - avg_bg)/(avg_fg - avg_bg) - 1; // -1..+1
}
// calculate costs // calculate costs
// maybe multiple backgrounds? Then combine them all // maybe multiple backgrounds? Then combine them all
...@@ -5705,6 +5729,7 @@ public class TexturedModel { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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];
......
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