Commit 413cd545 authored by Andrey Filippov's avatar Andrey Filippov

continue with eigen

parent c8d3d7d9
......@@ -2348,14 +2348,17 @@ public class ImageDtt extends ImageDttCPU {
final double td_weight, // mix correlations accumulated in TD with
final double td_neib_weight, // mix correlations accumulated in TD (neibs)
final double pd_weight, // correlations (post) accumulated in PD
final boolean td_nopd_only, // only use TD accumulated data if no safe PD is available for the tile.
final boolean eig_use_neibs, // use correlation from 9 tiles with neibs, if single-tile fails
final int eig_min_weaks, // = 4; minimal weak neighbors for a weak tile (too few - no averaging)
final int eig_min_strongs, // minimal strong neighbors for strong tiles
final double eig_disp_diff, // maximal disparity difference from the closest (by disparity) neighbor
final boolean eig_remove_neibs, //remove weak (by-neibs) tiles if they have strong (by-single) neighbor
final boolean eig_filt_other, // apply other before-eigen filters
// final double min_str_nofpn, // = 0.25;
final double eig_str_sum_nofpn,// = 0.8; // 5;
final double eig_str_neib_nofpn,// = 0.8; // 5;
// final double min_str_fpn, // = 0.25;
final double eig_str_sum_fpn, // = 0.8; // 5;
final double eig_str_neib_fpn, // = 0.8; // 5;
final int min_neibs, // 2; // minimal number of strong neighbors (> min_str)
......@@ -2365,7 +2368,7 @@ public class ImageDtt extends ImageDttCPU {
final boolean neibs_nofpn_only, // consolidate neighbors for non-fpn tiles only!
final boolean redo_both, // use average of neighbors for both pd,td if any of the center tile tests (td, pd) fails
final int min_num_neibs, // plus center, total number >= (min_num_neibs+1)
final double scale_neibs_pd, // scale threshold for the pixel-domain average maximums
final double scale_neibs_td, // scale threshold for the transform-domain average maximums
final double scale_avg_weight, // reduce influence of the averaged correlations compared to the single-tile ones
......@@ -2379,7 +2382,6 @@ public class ImageDtt extends ImageDttCPU {
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
// final boolean
// final boolean eigen_sub_min = false; // when calculating eigenvectors, subtract min from data, false - just skip
if (this.gpuQuad == null) {
System.out.println("clt_process_tl_interscene(): this.gpuQuad is null, bailing out");
......@@ -2497,6 +2499,7 @@ public class ImageDtt extends ImageDttCPU {
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final boolean [] used_td = new boolean [tilesX*tilesY]; // this tile had strong enough TD w/o neibs
final boolean [] weak_tile = new boolean [tilesX*tilesY]; // this is a weak tile (only through consolidating neighbors)
// all neibs with strong TD around them will be removed
// not using PD at all? always TD, then neibs?
for (int ithread = 0; ithread < threads.length; ithread++) {
......@@ -2537,10 +2540,7 @@ public class ImageDtt extends ImageDttCPU {
is_fpn = true;
}
// double [][] corrs = new double [corrs_len + extra_len + extra_len_eig][]; // 1/17/2/18 +(0/1)
double [][] corrs = new double [corrs_len + extra_len][]; // 1/17/2/18 +(0/1)
// int eigen_indx = (extra_len_eig > 0) ? (corrs_len + extra_len + extra_len_eig -1):-1;
// int eigen_indx = (extra_len_eig > 0) ? (corrs_len + extra_len):-1;
// copy correlation tiles from the GPU's floating point arrays
double scale = 1.0/getNumSensors();
if (extra_sum) {
......@@ -2654,6 +2654,13 @@ public class ImageDtt extends ImageDttCPU {
false, // boolean ignore_border, // only if fpn_mask != null - ignore tile if maximum touches fpn_mask
debug_data, // double [][] debug_data, // null or double [1]
false); // boolean debug)
weak_tile[nTile] = stats_mv != null;
if (stats_mv != null) {
stats_mv[2] -= eig_str_neib * scale_neibs_td;
if (stats_mv[2] <= 0) {
stats_mv = null;
}
}
}
if ((debug_data != null) && (debug_data[0] != null)) {
iCorrTile_index[nTile] = iCorrTile;
......@@ -2698,28 +2705,94 @@ public class ImageDtt extends ImageDttCPU {
public void run() {
TileNeibs tn = new TileNeibs(tilesX,tilesY);
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) {
if ((mv[nTile] != null) && !used_td[nTile]) { // is weak (by neibs)
boolean remove_tile = false;
if (weak_tile[nTile]){
int num_weak = 0;
boolean has_strong = false;
for (int dir = 0; dir < TileNeibs.DIRS; dir++) {
int nTile1 = tn.getNeibIndex(nTile, dir);
if ((nTile1 >= 0) && used_td[nTile1]) {
mv[nTile] = null;
if (pxd != null) {
pxd[nTile] = null;
}
if (iCorrTile_index != null) {
int iCorrTile = iCorrTile_index[nTile];
dcorr_tiles[iCorrTile][eigen_indx+1] = null;
dcorr_tiles[iCorrTile][eigen_indx+3] = null;
if (nTile1 >= 0) {
if (used_td[nTile1]) {
has_strong = true;
break;
} else if (weak_tile[nTile1]) {
num_weak++;
}
break;
}
}
remove_tile |= (has_strong || (num_weak < eig_min_weaks));
} else if (used_td[nTile]) {
int num_strong = 0;
for (int dir = 0; dir < TileNeibs.DIRS; dir++) {
int nTile1 = tn.getNeibIndex(nTile, dir);
if ((nTile1 >= 0) && (used_td[nTile1])) {
num_strong++;
}
}
remove_tile |= (num_strong < eig_min_strongs);
}
if (remove_tile) { // any of 3 reasons above
mv[nTile] = null;
if (pxd != null) {
pxd[nTile] = null;
}
if (iCorrTile_index != null) {
int iCorrTile = iCorrTile_index[nTile];
dcorr_tiles[iCorrTile][eigen_indx+1] = null;
dcorr_tiles[iCorrTile][eigen_indx+3] = null;
}
}
}
}
};
}
startAndJoin(threads);
if (eig_disp_diff > 0) {
final boolean [] remove_tiles = new boolean[tilesX*tilesY];
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
TileNeibs tn = new TileNeibs(tilesX,tilesY);
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) if ((mv[nTile] != null) && (pXpYD[nTile] != null)) {
double min_diff = eig_disp_diff + 1.0;
double disp_c = pxd[nTile][2];
for (int dir = 0; dir < TileNeibs.DIRS; dir++) {
int nTile1 = tn.getNeibIndex(nTile, dir);
if ((nTile1 >= 0) && (pxd[nTile1]!= null) && !Double.isNaN(pxd[nTile1][2])) {
min_diff = Math.min(Math.abs(pxd[nTile1][2]-disp_c), min_diff);
}
}
remove_tiles[nTile] |= (min_diff > eig_disp_diff);
}
}
};
}
startAndJoin(threads);
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) if (remove_tiles[nTile]) {
mv[nTile] = null;
if (pxd != null) {
pxd[nTile] = null;
}
if (iCorrTile_index != null) {
int iCorrTile = iCorrTile_index[nTile];
dcorr_tiles[iCorrTile][eigen_indx+1] = null;
dcorr_tiles[iCorrTile][eigen_indx+3] = null;
}
}
}
};
}
startAndJoin(threads);
}
}
// Reduce weight if differs much from average of 8 neighbors, large disparity, remove too few neibs
final double scale_num_neib = ((weight_zero_neibs >= 0) && (weight_zero_neibs < 1.0)) ? (weight_zero_neibs * 8/(1.0 - weight_zero_neibs)): 0.0;
......@@ -2792,6 +2865,8 @@ public class ImageDtt extends ImageDttCPU {
startAndJoin(threads);
return coord_motion;
}
// using most of the ImageDttCPU.clt_process_tl_correlations
public void clt_process_tl_correlations( // convert to pixel domain and process correlations already prepared in fcorr_td and/or fcorr_combo_td
final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
......
......@@ -50,7 +50,9 @@ public class IntersceneLma {
private double [] s_vector = null; // strength component - just for debug images
private double [] last_ymfx = null;
private double [][] last_jt = null;
private double [] weights; // normalized so sum is 1.0 for all - samples and extra regularization
private double [] weights; // normalized so sum is 1.0 for all - samples and extra regularization
private double sum_weights = 0;
private int num_defined = 0;
private double pure_weight; // weight of samples only
private boolean [] par_mask = null;
private int [] par_indices = null;
......@@ -91,6 +93,14 @@ public class IntersceneLma {
public double [][] getLastJT(){
return last_jt;
}
public double getSumWeights() {
return sum_weights;
}
public int getNumDefined() {
return num_defined;
}
public double[] getLastRms() {
......@@ -830,6 +840,7 @@ public class IntersceneLma {
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger ati = new AtomicInteger(0);
final AtomicInteger anum_defined = new AtomicInteger(0);
final double [] sw_arr = new double [threads.length];
double sum_weights;
final int num_types = (num_components > 2) ? 2 : 1;
......@@ -842,17 +853,20 @@ public class IntersceneLma {
if (Double.isNaN(w)) {
w = 0;
}
weights[num_components * iMTile] = w;
sw_arr[thread_num] += 2*w;
//disparity_weight
if (num_types > 1) {
w = vector_XYSDS[iMTile][4] * disparity_weight;
if (Double.isNaN(w) || Double.isNaN(vector_XYSDS[iMTile][3])) {
w = 0;
vector_XYSDS[iMTile][3] = 0.0; // disparity
if (w > 0) {
anum_defined.getAndIncrement();
weights[num_components * iMTile] = w;
sw_arr[thread_num] += 2*w;
//disparity_weight
if (num_types > 1) {
w = vector_XYSDS[iMTile][4] * disparity_weight;
if (Double.isNaN(w) || Double.isNaN(vector_XYSDS[iMTile][3])) {
w = 0;
vector_XYSDS[iMTile][3] = 0.0; // disparity
}
weights[num_components * iMTile + 2] = w;
sw_arr[thread_num] += w;
}
weights[num_components * iMTile + 2] = w;
sw_arr[thread_num] += w;
}
}
}
......@@ -863,6 +877,9 @@ public class IntersceneLma {
for (double w:sw_arr) {
sum_weights += w;
}
num_defined = anum_defined.get();
this.sum_weights = sum_weights;
if (sum_weights <= 1E-8) {
System.out.println("!!!!!! setSamplesWeights(): sum_weights=="+sum_weights+" <= 1E-8");
}
......
......@@ -64,8 +64,8 @@ public class IntersceneMatchParameters {
public boolean sfm_use = true; // use SfM to improve depth map
public double sfm_min_base = 2.0; // use SfM if baseline exceeds this
public double sfm_min_gain = 5.0; // Minimal SfM gain to apply SfM to the depth map
public double sfm_min_base = 0.6; // 2.0; // use SfM if baseline exceeds this
public double sfm_min_gain = 3.0; // 5.0; // Minimal SfM gain to apply SfM to the depth map
public double sfm_min_frac = 0.5; // Minimal fraction of defined tiles to have SfM correction
public int sfm_num_pairs = 32; // desired number of SfM pairs to average
......@@ -450,6 +450,9 @@ public class IntersceneMatchParameters {
public double eig_max_sqrt = 6.0; // for sqrt(lambda) - consider infinity (infinite linear feature, a line)
public double eig_min_sqrt = 1.0; // for sqrt(lambda) - limit minimal sqrt(lambda) - can be sharp for very small max
public boolean eig_use_neibs = true; // use correlation from 9 tiles with neibs, if single-tile fails
public int eig_min_weaks = 4; // Minimal number of weak neighbors to keep center weak tile
public int eig_min_strongs = 2; // Minimal number of strong neighbors for stron tiles
public double eig_disp_diff = 1.0; // maximal disparity difference from the closest (by disparity) neighbor
public boolean eig_remove_neibs = true; // remove weak (by-neibs) tiles if they have strong (by-single) neighbor
public boolean eig_filt_other = false; // apply other before-eigen filters
public double eig_max_rms = 2.0; // eigen-normalized maximal RMS to consider adjustment to be a failure
......@@ -473,7 +476,7 @@ min_str_neib_fpn 0.35
public double min_ref_frac = 0.2; // 0.22; if fraction number of reliable tiles is less than this, use best possible
// SfM-related filtering (remove tiles without SfM)
public boolean sfm_filter = true; // use SfM filtering if available
public double sfm_minmax = 10.0; // minimal value of the SfM gain maximum to consider available
public double sfm_minmax = 3.0; // 10.0 // minimal value of the SfM gain maximum to consider available
public double sfm_fracmax = 0.75; // minimal fraction of the SfM maximal gain
public double sfm_fracall = 0.3; // minimal relative area of the SfM-enabled tiles (do not apply filter if less)
......@@ -1355,12 +1358,19 @@ min_str_neib_fpn 0.35
"1.0 - subract threshold value before centroid and covariance, 0.0 - keep original correlation values.");
gd.addNumericField("Infinity radius", this.eig_max_sqrt, 5,7,"",
"For sqrt(egenvalue)==radius - consider infinity (infinite linear feature, a line).");
gd.addNumericField("Minimal radius", this.eig_min_sqrt, 5,7,"",
gd.addNumericField("Minimal radius", this.eig_min_sqrt, 5,7,"",
"For sqrt(egenvalue)==radius - do not trust too sharp (caused by small spot over threshold).");
gd.addCheckbox ("Use neighbors if single fails", this.eig_use_neibs,
"Use correlation from 9 tiles with neibs, if single-tile fails");
gd.addCheckbox ("Remove weak by strong neighbors", this.eig_remove_neibs,
"Remove weak (by-neibs) tiles if they have strong (by-single) neighbor");
gd.addNumericField("Min weak neighbors", this.eig_min_weaks, 0,3,"",
"Minimal number of weak neighbors to keep center weak tile. Too few will not reduce noise by averaging");
gd.addNumericField("Min strong neighbors of strong tiles", this.eig_min_strongs, 0,3,"",
"Minimal number of strong (w/o averaging with neighbors) tiles.");
gd.addNumericField("Maximal disparity difference to neighbors",this.eig_disp_diff, 5,7,"pix",
"Maximal disparity difference from the closest (by disparity) neighbor.");
gd.addCheckbox ("Remove weak by strong and too few weak neighbors", this.eig_remove_neibs,
"Remove weak (by-neibs) tiles if they have strong (by-single) neighbor. Or if they have too few weak ones");
gd.addCheckbox ("Apply other filters", this.eig_filt_other,
"Apply other (before-eigen) filters");
gd.addNumericField("Maximal eigen-normalized RMS", this.eig_max_rms, 5,7,"",
......@@ -2052,6 +2062,10 @@ min_str_neib_fpn 0.35
this.eig_max_sqrt = gd.getNextNumber();
this.eig_min_sqrt = gd.getNextNumber();
this.eig_use_neibs = gd.getNextBoolean();
this.eig_min_weaks = (int) gd.getNextNumber();
this.eig_min_strongs = (int) gd.getNextNumber();
this.eig_disp_diff = gd.getNextNumber();
this.eig_remove_neibs = gd.getNextBoolean();
this.eig_filt_other = gd.getNextBoolean();
this.eig_max_rms = gd.getNextNumber();
......@@ -2608,6 +2622,10 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"eig_max_sqrt", this.eig_max_sqrt+""); // double
properties.setProperty(prefix+"eig_min_sqrt", this.eig_min_sqrt+""); // double
properties.setProperty(prefix+"eig_use_neibs", this.eig_use_neibs+""); // boolean
properties.setProperty(prefix+"eig_min_weaks", this.eig_min_weaks+""); // int
properties.setProperty(prefix+"eig_min_strongs", this.eig_min_strongs+""); // int
properties.setProperty(prefix+"eig_disp_diff", this.eig_disp_diff+""); // double
properties.setProperty(prefix+"eig_remove_neibs", this.eig_remove_neibs+""); // boolean
properties.setProperty(prefix+"eig_filt_other", this.eig_filt_other+""); // boolean
properties.setProperty(prefix+"eig_max_rms", this.eig_max_rms+""); // double
......@@ -3127,7 +3145,10 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"eig_max_sqrt")!=null) this.eig_max_sqrt=Double.parseDouble(properties.getProperty(prefix+"eig_max_sqrt"));
if (properties.getProperty(prefix+"eig_min_sqrt")!=null) this.eig_min_sqrt=Double.parseDouble(properties.getProperty(prefix+"eig_min_sqrt"));
if (properties.getProperty(prefix+"eig_use_neibs")!=null) this.eig_use_neibs=Boolean.parseBoolean(properties.getProperty(prefix+"eig_use_neibs"));
if (properties.getProperty(prefix+"eig_remove_neibs")!=null) this.eig_remove_neibs=Boolean.parseBoolean(properties.getProperty(prefix+"eig_remove_neibs"));
if (properties.getProperty(prefix+"eig_min_weaks")!=null) this.eig_min_weaks=Integer.parseInt(properties.getProperty(prefix+"eig_min_weaks"));
if (properties.getProperty(prefix+"eig_min_strongs")!=null) this.eig_min_strongs=Integer.parseInt(properties.getProperty(prefix+"eig_min_strongs"));
if (properties.getProperty(prefix+"eig_disp_diff")!=null) this.eig_disp_diff=Double.parseDouble(properties.getProperty(prefix+"eig_disp_diff"));
if (properties.getProperty(prefix+"eig_remove_neibs")!=null) this.eig_remove_neibs=Boolean.parseBoolean(properties.getProperty(prefix+"eig_remove_neibs"));
if (properties.getProperty(prefix+"eig_filt_other")!=null) this.eig_filt_other=Boolean.parseBoolean(properties.getProperty(prefix+"eig_filt_other"));
if (properties.getProperty(prefix+"eig_max_rms")!=null) this.eig_max_rms=Double.parseDouble(properties.getProperty(prefix+"eig_max_rms"));
......@@ -3654,6 +3675,11 @@ min_str_neib_fpn 0.35
imp.eig_max_sqrt = this.eig_max_sqrt;
imp.eig_min_sqrt = this.eig_min_sqrt;
imp.eig_use_neibs = this.eig_use_neibs;
imp.eig_min_weaks = this.eig_min_weaks;
imp.eig_min_strongs = this.eig_min_strongs;
imp.eig_disp_diff = this.eig_disp_diff;
imp.eig_remove_neibs = this.eig_remove_neibs;
imp.eig_filt_other = this.eig_filt_other;
imp.eig_max_rms = this.eig_max_rms;
......
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