Commit 27498290 authored by Andrey Filippov's avatar Andrey Filippov

Low texture areas - debugging averaging correlation with surface

approximation with planes
parent 58970e5a
...@@ -156,11 +156,12 @@ public class BiQuadParameters { ...@@ -156,11 +156,12 @@ public class BiQuadParameters {
// filtering lt candidates // filtering lt candidates
public double ltavg_min_disparity = -1.0; // any public double ltavg_min_disparity = -1.0; // any
public double ltavg_max_density = 0.1; public double ltavg_max_density = 0.1;
public int ltavg_grow = 4; // each 2 add 8 directions step. Odd have last step in 4 ortho directions only. public int ltavg_gap_hwidth = 2; // maximal radius of a void to be filled
public int ltavg_shrink = 2; // shrink after expanding. Combination of both fills small gaps public int ltavg_clust_hwidth = 5; // minimal radius of a cluster to keep
public int ltavg_extra_grow = 1; // additionally grow low-textured areas selections
// smoothing parameters // smoothing parameters
public boolean ltavg_smooth_strength = false; // provide tile strength when smoothing target disparity public boolean ltavg_smooth_strength = false; // provide tile strength when smoothing target disparity
public double ltavg_neib_pull = 0.2; // pull to weighted average relative to pull to the original disparity value. If 0.0 - will only update former NaN-s public double ltavg_neib_pull = 1.0; // pull to weighted average relative to pull to the original disparity value. If 0.0 - will only update former NaN-s
public int ltavg_max_iter = 20; // public int ltavg_max_iter = 20; //
public double ltavg_min_change = 0.01; // public double ltavg_min_change = 0.01; //
...@@ -461,10 +462,12 @@ public class BiQuadParameters { ...@@ -461,10 +462,12 @@ public class BiQuadParameters {
"May be used to mask out infinity background"); "May be used to mask out infinity background");
gd.addNumericField("Maximal density to consider it to be low textured area", this.ltavg_max_density, 4,6,"", gd.addNumericField("Maximal density to consider it to be low textured area", this.ltavg_max_density, 4,6,"",
"Select areas with lower density"); "Select areas with lower density");
gd.addNumericField("Grow selection, each two units get expanion in 8 directions", this.ltavg_grow, 0,3,"", gd.addNumericField("Maximal radius of a void in low-texture selection to fill" , this.ltavg_gap_hwidth, 0,3,"",
"Two steps give one-tile expansion in 8 directions, odd numbers expand only in 4 ortho directions on the last expansion"); "Low textured selection may have gaps that will be filled");
gd.addNumericField("Shrink selection after growing", this.ltavg_shrink, 0,3,"", gd.addNumericField("Minimal radius of a low-textured cluster to process", this.ltavg_clust_hwidth, 0,3,"",
"Grow followed by shring fill small gaps"); "Remove low-textured areas smaller that twice this size in each orthogonal directions");
gd.addNumericField("Additionally grow low-textured areas selections", this.ltavg_extra_grow, 0,3,"",
"Low textured areas will be grown by the radius of correlation averaging plus this value");
gd.addCheckbox ("Use tile strengths when filling gaps/smoothing", this.ltavg_smooth_strength, gd.addCheckbox ("Use tile strengths when filling gaps/smoothing", this.ltavg_smooth_strength,
"Unchecked - consider all tiles to have the same strength"); "Unchecked - consider all tiles to have the same strength");
gd.addNumericField("Relative pull of the nieghbor tiles compared to the original disparity" , this.ltavg_neib_pull, 4,6,"", gd.addNumericField("Relative pull of the nieghbor tiles compared to the original disparity" , this.ltavg_neib_pull, 4,6,"",
...@@ -678,8 +681,9 @@ public class BiQuadParameters { ...@@ -678,8 +681,9 @@ public class BiQuadParameters {
this.ltavg_dens_radius= (int) gd.getNextNumber(); this.ltavg_dens_radius= (int) gd.getNextNumber();
this.ltavg_min_disparity= gd.getNextNumber(); this.ltavg_min_disparity= gd.getNextNumber();
this.ltavg_max_density= gd.getNextNumber(); this.ltavg_max_density= gd.getNextNumber();
this.ltavg_grow= (int) gd.getNextNumber(); this.ltavg_gap_hwidth= (int) gd.getNextNumber();
this.ltavg_shrink= (int) gd.getNextNumber(); this.ltavg_clust_hwidth= (int) gd.getNextNumber();
this.ltavg_extra_grow= (int) gd.getNextNumber();
this.ltavg_smooth_strength= gd.getNextBoolean(); this.ltavg_smooth_strength= gd.getNextBoolean();
this.ltavg_neib_pull= gd.getNextNumber(); this.ltavg_neib_pull= gd.getNextNumber();
this.ltavg_max_iter= (int) gd.getNextNumber(); this.ltavg_max_iter= (int) gd.getNextNumber();
...@@ -846,8 +850,10 @@ public class BiQuadParameters { ...@@ -846,8 +850,10 @@ public class BiQuadParameters {
properties.setProperty(prefix+"ltavg_dens_radius", this.ltavg_dens_radius+""); properties.setProperty(prefix+"ltavg_dens_radius", this.ltavg_dens_radius+"");
properties.setProperty(prefix+"ltavg_min_disparity", this.ltavg_min_disparity+""); properties.setProperty(prefix+"ltavg_min_disparity", this.ltavg_min_disparity+"");
properties.setProperty(prefix+"ltavg_max_density", this.ltavg_max_density+""); properties.setProperty(prefix+"ltavg_max_density", this.ltavg_max_density+"");
properties.setProperty(prefix+"ltavg_grow", this.ltavg_grow+""); properties.setProperty(prefix+"ltavg_gap_hwidth", this.ltavg_gap_hwidth+"");
properties.setProperty(prefix+"ltavg_shrink", this.ltavg_shrink+""); properties.setProperty(prefix+"ltavg_clust_hwidth", this.ltavg_clust_hwidth+"");
properties.setProperty(prefix+"ltavg_extra_grow", this.ltavg_extra_grow+"");
properties.setProperty(prefix+"ltavg_smooth_strength", this.ltavg_smooth_strength+""); properties.setProperty(prefix+"ltavg_smooth_strength", this.ltavg_smooth_strength+"");
properties.setProperty(prefix+"ltavg_neib_pull", this.ltavg_neib_pull+""); properties.setProperty(prefix+"ltavg_neib_pull", this.ltavg_neib_pull+"");
properties.setProperty(prefix+"ltavg_max_iter", this.ltavg_max_iter+""); properties.setProperty(prefix+"ltavg_max_iter", this.ltavg_max_iter+"");
...@@ -1015,8 +1021,10 @@ public class BiQuadParameters { ...@@ -1015,8 +1021,10 @@ public class BiQuadParameters {
if (properties.getProperty(prefix+"ltavg_dens_radius")!=null) this.ltavg_dens_radius=Integer.parseInt(properties.getProperty(prefix+"ltavg_dens_radius")); if (properties.getProperty(prefix+"ltavg_dens_radius")!=null) this.ltavg_dens_radius=Integer.parseInt(properties.getProperty(prefix+"ltavg_dens_radius"));
if (properties.getProperty(prefix+"ltavg_min_disparity")!=null) this.ltavg_min_disparity=Double.parseDouble(properties.getProperty(prefix+"ltavg_min_disparity")); if (properties.getProperty(prefix+"ltavg_min_disparity")!=null) this.ltavg_min_disparity=Double.parseDouble(properties.getProperty(prefix+"ltavg_min_disparity"));
if (properties.getProperty(prefix+"ltavg_max_density")!=null) this.ltavg_max_density=Double.parseDouble(properties.getProperty(prefix+"ltavg_max_density")); if (properties.getProperty(prefix+"ltavg_max_density")!=null) this.ltavg_max_density=Double.parseDouble(properties.getProperty(prefix+"ltavg_max_density"));
if (properties.getProperty(prefix+"ltavg_grow")!=null) this.ltavg_grow=Integer.parseInt(properties.getProperty(prefix+"ltavg_grow")); if (properties.getProperty(prefix+"ltavg_gap_hwidth")!=null) this.ltavg_gap_hwidth=Integer.parseInt(properties.getProperty(prefix+"ltavg_gap_hwidth"));
if (properties.getProperty(prefix+"ltavg_shrink")!=null) this.ltavg_shrink=Integer.parseInt(properties.getProperty(prefix+"ltavg_shrink")); if (properties.getProperty(prefix+"ltavg_clust_hwidth")!=null) this.ltavg_clust_hwidth=Integer.parseInt(properties.getProperty(prefix+"ltavg_clust_hwidth"));
if (properties.getProperty(prefix+"ltavg_extra_grow")!=null) this.ltavg_extra_grow=Integer.parseInt(properties.getProperty(prefix+"ltavg_extra_grow"));
if (properties.getProperty(prefix+"ltavg_smooth_strength")!=null) this.ltavg_smooth_strength=Boolean.parseBoolean(properties.getProperty(prefix+"ltavg_smooth_strength")); if (properties.getProperty(prefix+"ltavg_smooth_strength")!=null) this.ltavg_smooth_strength=Boolean.parseBoolean(properties.getProperty(prefix+"ltavg_smooth_strength"));
if (properties.getProperty(prefix+"ltavg_neib_pull")!=null) this.ltavg_neib_pull=Double.parseDouble(properties.getProperty(prefix+"ltavg_neib_pull")); if (properties.getProperty(prefix+"ltavg_neib_pull")!=null) this.ltavg_neib_pull=Double.parseDouble(properties.getProperty(prefix+"ltavg_neib_pull"));
if (properties.getProperty(prefix+"ltavg_max_iter")!=null) this.ltavg_max_iter=Integer.parseInt(properties.getProperty(prefix+"ltavg_max_iter")); if (properties.getProperty(prefix+"ltavg_max_iter")!=null) this.ltavg_max_iter=Integer.parseInt(properties.getProperty(prefix+"ltavg_max_iter"));
...@@ -1182,8 +1190,9 @@ public class BiQuadParameters { ...@@ -1182,8 +1190,9 @@ public class BiQuadParameters {
bqp.ltavg_dens_radius= this.ltavg_dens_radius; bqp.ltavg_dens_radius= this.ltavg_dens_radius;
bqp.ltavg_min_disparity= this.ltavg_min_disparity; bqp.ltavg_min_disparity= this.ltavg_min_disparity;
bqp.ltavg_max_density= this.ltavg_max_density; bqp.ltavg_max_density= this.ltavg_max_density;
bqp.ltavg_grow= this.ltavg_grow; bqp.ltavg_gap_hwidth= this.ltavg_gap_hwidth;
bqp.ltavg_shrink= this.ltavg_shrink; bqp.ltavg_clust_hwidth= this.ltavg_clust_hwidth;
bqp.ltavg_extra_grow= this.ltavg_extra_grow;
bqp.ltavg_smooth_strength= this.ltavg_smooth_strength; bqp.ltavg_smooth_strength= this.ltavg_smooth_strength;
bqp.ltavg_neib_pull= this.ltavg_neib_pull; bqp.ltavg_neib_pull= this.ltavg_neib_pull;
bqp.ltavg_max_iter= this.ltavg_max_iter; bqp.ltavg_max_iter= this.ltavg_max_iter;
......
...@@ -150,6 +150,7 @@ public class BiScan { ...@@ -150,6 +150,7 @@ public class BiScan {
// trusted should be set, copied and replaced as needed // trusted should be set, copied and replaced as needed
public double [][] getFilteredDisparityStrength( // FIXME public double [][] getFilteredDisparityStrength( // FIXME
final boolean [] area_of_interest,
final double [][] disparityStrength, final double [][] disparityStrength,
final double min_disparity, // keep original disparity far tiles final double min_disparity, // keep original disparity far tiles
final double trusted_strength, // trusted correlation strength final double trusted_strength, // trusted correlation strength
...@@ -193,6 +194,7 @@ public class BiScan { ...@@ -193,6 +194,7 @@ public class BiScan {
for (int i = 0; i < num_tiles; i++) ds[0][i] = Double.NaN; for (int i = 0; i < num_tiles; i++) ds[0][i] = Double.NaN;
// double boost_low_density = 0.8; // 1.0; //0.2; // double boost_low_density = 0.8; // 1.0; //0.2;
suggestNewScan( suggestNewScan(
area_of_interest, // final boolean [] area_of_interest,
disparityStrength, // final double [][] disparityStrength, disparityStrength, // final double [][] disparityStrength,
trusted_strength, // final double trusted_strength, // trusted correlation strength trusted_strength, // final double trusted_strength, // trusted correlation strength
strength_rfloor, // final double strength_rfloor, // strength floor - relative to trusted strength_rfloor, // final double strength_rfloor, // strength floor - relative to trusted
...@@ -480,14 +482,15 @@ public class BiScan { ...@@ -480,14 +482,15 @@ public class BiScan {
* 2) target disaprity that lead to the current measurement after refinement * 2) target disaprity that lead to the current measurement after refinement
* 3) any other disable measurement * 3) any other disable measurement
* 4) any target disparity that lead to the disabled measurement * 4) any target disparity that lead to the disabled measurement
* @param area_of_interest - limit results to these tiles (if provided)
* @param disparityStrength - a pair of array or null. If null, will calculate fro the current scan * @param disparityStrength - a pair of array or null. If null, will calculate fro the current scan
* if not null - use as is * if not null - use as is
* @param trusted_strength strength to trust unconditionally * @param trusted_strength strength to trust unconditionally
* @param strength_rfloor strength floor to subrtact as a fraction of the trusted strength * @param strength_rfloor strength floor to subtract as a fraction of the trusted strength
* @param discard_cond if true may suggest new disparities for conditionally trusted tiles * @param discard_cond if true may suggest new disparities for conditionally trusted tiles
* @param discard_weak if true may suggest new disparities over trusted weak tiles * @param discard_weak if true may suggest new disparities over trusted weak tiles
* @param discard_stron if true may suggest new disparities over any tile * @param discard_stron if true may suggest new disparities over any tile
* @param strength_pow raise strength to thyis power (normally just 1.0) * @param strength_pow raise strength to this power (normally just 1.0)
* @param smpl_radius sample "radius", square side is 2 * smpl_radius + 1 * @param smpl_radius sample "radius", square side is 2 * smpl_radius + 1
* @param smpl_num minimal absolute number of samples required to try fit a plane and validate a tile * @param smpl_num minimal absolute number of samples required to try fit a plane and validate a tile
* If smpl_num == 0, faster calculation (single pass) using only *_narrow settings * If smpl_num == 0, faster calculation (single pass) using only *_narrow settings
...@@ -501,7 +504,7 @@ public class BiScan { ...@@ -501,7 +504,7 @@ public class BiScan {
* @param smpl_rrms maximal relative (additional)rms of the weighted remaining samples for the successful plane fitting * @param smpl_rrms maximal relative (additional)rms of the weighted remaining samples for the successful plane fitting
* @param damp_tilt regularization value to handle planes if the remaining samples are co-linear (or just a single tile) * @param damp_tilt regularization value to handle planes if the remaining samples are co-linear (or just a single tile)
* @param rwsigma weight Gaussian sigma to reduce influence of far tiles relative to smpl_radius * @param rwsigma weight Gaussian sigma to reduce influence of far tiles relative to smpl_radius
* @param rwsigma_narrow Gaussian sigma for the preliminary plain fitting using the closesttiles ~= 1/smpl_radius * @param rwsigma_narrow Gaussian sigma for the preliminary plain fitting using the closest tiles ~= 1/smpl_radius
* @param new_diff minimal difference between the new suggested and the already tried/measured one * @param new_diff minimal difference between the new suggested and the already tried/measured one
* @param remove_all_tried remove from suggested - not only disabled, but all tried * @param remove_all_tried remove from suggested - not only disabled, but all tried
* @param center_weight weight of the tile itself (0.0 - do not use). Should be set to 0.0 for suggesting, >0 - for "smoothing" * @param center_weight weight of the tile itself (0.0 - do not use). Should be set to 0.0 for suggesting, >0 - for "smoothing"
...@@ -519,6 +522,7 @@ public class BiScan { ...@@ -519,6 +522,7 @@ public class BiScan {
*/ */
int suggestNewScan( int suggestNewScan(
final boolean [] area_of_interest,
final double [][] disparityStrength, final double [][] disparityStrength,
final double trusted_strength, // trusted correlation strength final double trusted_strength, // trusted correlation strength
final double strength_rfloor, // strength floor - relative to trusted final double strength_rfloor, // strength floor - relative to trusted
...@@ -545,7 +549,7 @@ public class BiScan { ...@@ -545,7 +549,7 @@ public class BiScan {
final boolean use_alt, // use tiles from other scans if they fit better final boolean use_alt, // use tiles from other scans if they fit better
final double goal_fraction_rms, // Try to make rms to be this fraction of maximal acceptable by removing outliers final double goal_fraction_rms, // Try to make rms to be this fraction of maximal acceptable by removing outliers
final double boost_low_density, // 0 - strength is proportional to 1/density, 1.0 - same as remaining tiles final double boost_low_density, // 0 - strength is proportional to 1/density, 1.0 - same as remaining tiles
final double [][] smooth_ds, // optionally fill disaprity/strength instead of the target_disparity final double [][] smooth_ds, // optionally fill disparity/strength instead of the target_disparity
final int fourq_min, // each of the 4 corners should have at least this number of tiles. final int fourq_min, // each of the 4 corners should have at least this number of tiles.
final int fourq_gap, // symmetrical vertical and horizontal center areas that do not belong to any corner final int fourq_gap, // symmetrical vertical and horizontal center areas that do not belong to any corner
final int dbg_x, final int dbg_x,
...@@ -627,7 +631,8 @@ public class BiScan { ...@@ -627,7 +631,8 @@ public class BiScan {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
@Override @Override
public void run() { public void run() {
for (int nTile = ai.getAndIncrement(); nTile < num_tiles; nTile = ai.getAndIncrement()) if (discard_strong || !trusted_sw[nTile]){ for (int nTile = ai.getAndIncrement(); nTile < num_tiles; nTile = ai.getAndIncrement()) if (
((area_of_interest == null) || area_of_interest[nTile]) && (discard_strong || !trusted_sw[nTile])){
boolean debug = nTile == dbg_tile; boolean debug = nTile == dbg_tile;
if (debug) { if (debug) {
System.out.println("suggestNewScan(): debbugging nTile="+nTile); System.out.println("suggestNewScan(): debbugging nTile="+nTile);
...@@ -864,6 +869,8 @@ public class BiScan { ...@@ -864,6 +869,8 @@ public class BiScan {
return num_new.get(); return num_new.get();
} }
private int findBetterFitToPlane( private int findBetterFitToPlane(
int smpl_radius, int smpl_radius,
int nTile, int nTile,
...@@ -1948,32 +1955,49 @@ public class BiScan { ...@@ -1948,32 +1955,49 @@ public class BiScan {
* Select low-textured tiles for averaging measurements * Select low-textured tiles for averaging measurements
* @param min_disparity minimal disparity to accept * @param min_disparity minimal disparity to accept
* @param max_density maximal trusted tile density (density varies from 0.0 to 1.0) * @param max_density maximal trusted tile density (density varies from 0.0 to 1.0)
* @param grow grow selection. When combined with shrink, fills small gaps. Both grow and shrink step * @param grow how many layers of tiles should be added after filling gaps and removing small clusters
* advances either horizontally or vertically (alternating), so to expand by 1 pixel in all directions * @param max_gap_radius maximal radius of a void to be filled
* the value should be set to 2, * @param min_clust_radius minimal original cluster radius to survive
* @param shrink shrink selection after expanding to fill small gaps
* @param density per-tile values of the density of trusted tiles around it. * @param density per-tile values of the density of trusted tiles around it.
* @param src_disparity - source disparity array * @param src_disparity - source disparity array. If null will only use density (that should be > 0)
* @return selection of the low-textured tiles to be processed with averaging correlation (3x3 or 5x5 tiles) * @return selection of the low-textured tiles to be processed with averaging correlation (3x3 or 5x5 tiles)
*/ */
public boolean [] selectLowTextures( public boolean [] selectLowTextures(
double min_disparity, double min_disparity,
double max_density, double max_density,
int grow, int grow,
int shrink, int max_gap_radius,
int min_clust_radius,
double [] density, double [] density,
double [] src_disparity) double [] src_disparity)
{ {
boolean [] selection = new boolean [density.length]; boolean [] selection = new boolean [density.length];
for (int nTile = 0; nTile < selection.length; nTile++) { if (src_disparity == null) {
if ((src_disparity[nTile] >= min_disparity) && (density[nTile] <= max_density)) { // disparity has NaN-s, they will fail comparisons for (int nTile = 0; nTile < selection.length; nTile++) {
selection[nTile] = true; if ((density[nTile] <= max_density) && (density[nTile] <= max_density)) { // disparity has NaN-s, they will fail comparisons
selection[nTile] = true;
}
}
} else {
for (int nTile = 0; nTile < selection.length; nTile++) {
if ((src_disparity[nTile] >= min_disparity) && (density[nTile] <= max_density)) { // disparity has NaN-s, they will fail comparisons
selection[nTile] = true;
}
} }
} }
final TileNeibs tnImage = biCamDSI.tnImage; final TileNeibs tnImage = biCamDSI.tnImage;
tnImage.growSelection( tnImage.growSelection(
grow, // int grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more 2* max_gap_radius, // int grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
selection, // boolean [] tiles,
null); // boolean [] prohibit)
tnImage.shrinkSelection(
2*(max_gap_radius + min_clust_radius), // int grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
selection, // boolean [] tiles,
null); // boolean [] prohibit)
tnImage.growSelection(
2 * (min_clust_radius + grow), // int grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
selection, // boolean [] tiles, selection, // boolean [] tiles,
null); // boolean [] prohibit) null); // boolean [] prohibit)
return selection; return selection;
...@@ -2023,6 +2047,7 @@ public class BiScan { ...@@ -2023,6 +2047,7 @@ public class BiScan {
for (int num_iter = 0; num_iter < max_iterations; num_iter++) { for (int num_iter = 0; num_iter < max_iterations; num_iter++) {
ai.set(0); ai.set(0);
ai_numThread.set(0); ai_numThread.set(0);
final AtomicInteger ai_count=new AtomicInteger(0);
for (int i = 0; i < max_changes.length; i++) max_changes[i] = 0.0; for (int i = 0; i < max_changes.length; i++) max_changes[i] = 0.0;
final int fnum_iter = num_iter; final int fnum_iter = num_iter;
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
...@@ -2070,6 +2095,7 @@ public class BiScan { ...@@ -2070,6 +2095,7 @@ public class BiScan {
new_strength[nTile] = (w_mean * neib_pull + src_strength[nTile])/(neib_pull + 1); new_strength[nTile] = (w_mean * neib_pull + src_strength[nTile])/(neib_pull + 1);
} }
} }
ai_count.getAndIncrement();
double adiff = Math.abs(new_disparity[nTile] - disparity[nTile]); // disparity[nTile] may be NaN then adiff will be NaN as intended double adiff = Math.abs(new_disparity[nTile] - disparity[nTile]); // disparity[nTile] may be NaN then adiff will be NaN as intended
if (!(adiff < max_changes[numThread])) { if (!(adiff < max_changes[numThread])) {
max_changes[numThread] = adiff; // NaN will be copied max_changes[numThread] = adiff; // NaN will be copied
...@@ -2098,7 +2124,7 @@ public class BiScan { ...@@ -2098,7 +2124,7 @@ public class BiScan {
} }
} }
if (debugLevel > -2) { if (debugLevel > -2) {
System.out.println("fillAndSmooth(): iteration "+fnum_iter+" change="+change+" (min_change="+min_change+")"); System.out.println("fillAndSmooth(): iteration "+fnum_iter+" change="+change+" (min_change="+min_change+")+ tiles updated="+ai_count.get());
} }
if (change <= min_change) { // change may be NaN if (change <= min_change) { // change may be NaN
break; // from the main loop break; // from the main loop
......
This diff is collapsed.
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