Commit 9c02927a authored by Andrey Filippov's avatar Andrey Filippov

refactoring, fighting small bugs

parent 204eba2c
......@@ -650,6 +650,9 @@ public class BiScan {
double [] smpl_w = new double [smpl_len];
double [] smpl_w_narrow = new double [smpl_len];
double [] smpl_p = new double [smpl_len]; // plane disparity,
double [] smpl_wsw= smpl_w_narrow;
double [][] weights_sw = weights_narrow;
int nall = 0;
double sw = 0, swd = 0;
for (int dy = -smpl_radius; dy <= smpl_radius; dy++) {
......@@ -796,6 +799,8 @@ public class BiScan {
fourq_min, // int fourq_min, // each of the 4 corners should have at least this number of tiles.
fourq_corner, // int [] fourq_corner, // array specifying corner number (0..3), -1 - gap. null when not used
debugLevel); // int debugLevel)
smpl_wsw = smpl_w;
weights_sw = weights;
// if ( (fit_rslt == null) || (fit_rslt[0] > (smpl_arms + smpl_rrms * fit_rslt[1]))){
if ( (fit_rslt == null) || (fit_rslt[0] > max_rms)){
continue; // narrow selection - too high rms
......@@ -845,17 +850,18 @@ public class BiScan {
for (int dx = -smpl_radius; dx <= smpl_radius; dx++) { // if ((dx != 0) || (dy != 0)){
int adx = (dx > 0)? dx:(-dx);
int smpl_indx = smpl_center + dy*smpl_side + dx;
if (smpl_w[smpl_indx] > 0.0) {
s0+= weights[ady][adx];
s1+= weights[ady][adx] * smpl_w[smpl_indx];
if (smpl_wsw[smpl_indx] > 0.0) { // either smpl_w_narrow or smpl_w
s0+= weights_sw[ady][adx];
// s1+= weights[ady][adx] * smpl_w[smpl_indx];
s1+= smpl_wsw[smpl_indx]; // already was multiplied by weights[ady][adx]
}
}
}
//boost_low_density, // false weight of low density tiles is reduced, true - boosted
double w = s1;
if (boost_low_density > 0.0) {
w/= Math.pow(s0, boost_low_density);
}
double w = s1/s0;
// if (boost_low_density > 0.0) {
// w/= Math.pow(s0, boost_low_density);
// }
if (strength_pow != 1.0) {
w = Math.pow(w, 1.0 / strength_pow);
}
......@@ -865,6 +871,11 @@ public class BiScan {
System.out.println("suggestNewScan(): nTile="+nTile+" w="+w);
System.out.println("suggestNewScan(): nTile="+nTile+" w="+w);
}
if (nTile == 66945) {
System.out.println("suggestNewScan(): nTile="+nTile+" w="+w);
System.out.println("suggestNewScan(): nTile="+nTile+" w="+w);
}
}
}
}
......@@ -2206,7 +2217,17 @@ public class BiScan {
double [][] ds = {disparity,strength}; // strength may be null
return ds;
}
/**
* Extend low texture areas horizontally if both ends are OK: either belong to the low texture areas selection (lt_sel)
* or are trusted and closer or the same (to the provided tolerance)
* @param tolerance strong limit should not have disparity lower by more than tolerance than low textured area
* @param ds_lt disparity/strength for the low textured area
* @param d_single disparity measured for the single-tile correlation
* @param lt_sel low -textured selection
* @param exp_sel expanded selection (does not intersect with lt_sel
* @param trusted trusted tiles selection
* @return extended disparity/strength data
*/
public double [][] getLTExpanded(
final double tolerance,
final double [][] ds_lt,
......
......@@ -32,6 +32,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class PoleProcessor {
final static double THRESHOLD_LIN = 1.0E-20; // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
final static double THRESHOLD_QUAD = 1.0E-30; // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
TwoQuadCLT twoQuadCLT; // to call caller methods
BiCamDSI biCamDSI;
ArrayList<PoleCluster> pole_clusters = new ArrayList<PoleCluster>();
int tilesX;
......@@ -92,27 +93,27 @@ public class PoleProcessor {
return String.format("{%3d, %3d, %2d, %2d}: %7.5f", eBox.x, eBox.y, eBox.width,eBox.height, target_disparity);
}
//-1 - definitely not,+1 - definitely yes, 0 - uncertain
public int poleFilter() {
// int min_mask = 10; // good - min 12
int min_height = 10; // good - min 12
boolean headlessOK = false;
double min_fraction = 0.5; // worst 0.3478 , next - 0.57
double min_frac_height = 0.5; // worst 0.25 , next - 0.556
double min_frac_box = 0.7; // worst 0.75 , next - 0.556
double min_disparity = 0.3;
double max_disparity = 3.05; // (2.95 - 3.15)
// if (!disabled) return 0;
if (disabled) return -1;
if (eBox.height < min_height) return -1;
if (!headlessOK && (getNumTiles() == 0)) return -1; // skip headless clusters
if (getFractSelected() < min_fraction) return -1;
if (getFractHeight() < min_frac_height) return -1;
if (getFractBoxHeight() < min_frac_box) return -1;
if (getTargetDisparity() < min_disparity)return -1;
if (getTargetDisparity() > max_disparity)return -1;
public int poleFilter(
PoleProcessorParameters poleProcessorParameters
) {
// int min_height = 10; // good - min 12
// boolean headlessOK = false;
// double min_fraction = 0.5; // worst 0.3478 , next - 0.57
// double min_frac_height = 0.5; // worst 0.25 , next - 0.556
// double min_frac_box = 0.7; // worst 0.75 , next - 0.556
// double min_disparity = 0.3;
// double max_disparity = 3.05; // (2.95 - 3.15)
if (disabled) return -1;
if (!poleProcessorParameters.filter_headlessOK && (getNumTiles() == 0)) return -1; // skip headless clusters
if (eBox.height < poleProcessorParameters.filter_min_height) return -1;
if (getFractSelected() < poleProcessorParameters.filter_min_fraction) return -1;
if (getFractHeight() < poleProcessorParameters.filter_min_frac_height) return -1;
if (getFractBoxHeight() < poleProcessorParameters.filter_min_frac_box) return -1;
if (getTargetDisparity() < poleProcessorParameters.filter_min_disparity) return -1;
if (getTargetDisparity() > poleProcessorParameters.filter_max_disparity) return -1;
return 0;
}
......@@ -902,14 +903,16 @@ public class PoleProcessor {
public PoleProcessor (
BiCamDSI biCamDSI,
TwoQuadCLT twoQuadCLT,
int tilesX,
int tilesY)
{
this.biCamDSI = biCamDSI;
this.tilesX = tilesX;
this.tilesY = tilesY;
this.twoQuadCLT = twoQuadCLT;
}
/*
public double [][] conditionDisparityStrength(
final BiScan biScan,
final double trusted_strength, // trusted correlation strength
......@@ -951,7 +954,44 @@ public class PoleProcessor {
ImageDtt.startAndJoin(threads);
return cond_ds;
}
*/
public double [][] conditionDisparityStrength(
final double [][] disparity_strength,
final double trusted_strength, // trusted correlation strength
final double strength_rfloor,
final double strength_pow
) {
final double strength_floor = trusted_strength * strength_rfloor;
final TileNeibs tnImage = biCamDSI.tnImage;
final int num_tiles = tnImage.sizeX * tnImage.sizeY;
final Thread[] threads = ImageDtt.newThreadArray(biCamDSI.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final double [][] cond_ds = new double [2] [num_tiles];
// final AtomicInteger ai_num_seeds = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < num_tiles; nTile = ai.getAndIncrement()) {
if (!Double.isNaN(disparity_strength[0][nTile]) &&(disparity_strength[1][nTile] > strength_floor)){
double w = disparity_strength[1][nTile] - strength_floor;
if (strength_pow != 1.0) {
w = Math.pow(w, strength_pow);
}
cond_ds[0][nTile] = disparity_strength[0][nTile];
cond_ds[1][nTile] = w;
} else {
cond_ds[0][nTile] = Double.NaN;
cond_ds[1][nTile] = 0.0;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return cond_ds;
}
......@@ -1109,13 +1149,14 @@ public class PoleProcessor {
public int removeFilteredClusters(
PoleProcessorParameters poleProcessorParameters,
ArrayList<PoleCluster> clusters,
int debugLevel)
{
int original_size = clusters.size();
for (int nClust = 0; nClust < clusters.size(); nClust++) {
PoleCluster cluster = clusters.get(nClust);
if (cluster.poleFilter() < 0) {
if (cluster.poleFilter(poleProcessorParameters) < 0) {
if (debugLevel > -2) {
System.out.println("Removing filtered out cluster: "+cluster.toString());
}
......@@ -1240,6 +1281,7 @@ public class PoleProcessor {
}
double [][] exportPoleDisparityStrength(
PoleProcessorParameters poleProcessorParameters,
int filter_value,
ArrayList<PoleCluster> clusters)
{
......@@ -1248,7 +1290,7 @@ public class PoleProcessor {
double [][] ds = new double [2][num_tiles];
for (int i = 0; i < num_tiles; i++) ds[0][i]=Double.NaN;
for (PoleCluster cluster: clusters) {
if ((filter_value >= 0) && (cluster.poleFilter() < filter_value)) continue;
if ((filter_value >= 0) && (cluster.poleFilter(poleProcessorParameters) < filter_value)) continue;
double disparity = cluster.getTargetDisparity(); // getMeanDisp();
double strength = cluster.getAverageStrength(true);
......@@ -1273,6 +1315,7 @@ public class PoleProcessor {
double [][] dbgClusterLayers( // layer and eBox should be set
PoleProcessorParameters poleProcessorParameters,
boolean show_bbox,
boolean show_ebox,
boolean show_lines,
......@@ -1302,7 +1345,7 @@ public class PoleProcessor {
}
for (PoleCluster cluster: clusters) if (headlessOK ||(cluster.getNumTiles() > 0)){ // skip headless clusters
int layer = cluster.getLayer();
if (filter && (cluster.poleFilter() <0)) continue;
if (filter && (cluster.poleFilter(poleProcessorParameters) <0)) continue;
double disp = cluster.getTargetDisparity(); // getMeanDisparity();
Rectangle [] rectangles = {show_bbox?cluster.getBBox():null,show_ebox?cluster.getEBox():null};
for (int nbox = 0; nbox< rectangles.length; nbox++) if (rectangles[nbox] != null) {
......@@ -1338,7 +1381,7 @@ public class PoleProcessor {
if (show_lines) {
int ends = 1;
for (PoleCluster cluster: clusters) if (headlessOK ||(cluster.getNumTiles() > 0)){
if (filter && (cluster.poleFilter() <0)) continue;
if (filter && (cluster.poleFilter(poleProcessorParameters) <0)) continue;
double [] pole_line = cluster.getPoleLine();
if (pole_line != null) {
int layer = cluster.getLayer();
......@@ -1360,7 +1403,7 @@ public class PoleProcessor {
}
if (show_masks) {
for (PoleCluster cluster: clusters) if (headlessOK ||(cluster.getNumTiles() > 0)){
if (filter && (cluster.poleFilter() <0)) continue;
if (filter && (cluster.poleFilter(poleProcessorParameters) <0)) continue;
double [] pole_line = cluster.getPoleLine();
if (pole_line != null) {
int layer = cluster.getLayer();
......@@ -1394,7 +1437,7 @@ public class PoleProcessor {
if (show_rdisparity || show_strength) {
int offs_strength = show_rdisparity ? num_layers:0;
for (PoleCluster cluster: clusters) if (headlessOK ||(cluster.getNumTiles() > 0)){
if (filter && (cluster.poleFilter() <0)) continue;
if (filter && (cluster.poleFilter(poleProcessorParameters) <0)) continue;
int layer = cluster.getLayer();
double [][] ds = cluster.getDsPairs(selected_only);
int [] nTiles = cluster.getDsTiles(selected_only);
......@@ -1655,10 +1698,11 @@ public class PoleProcessor {
}
public void printClusterStats(
PoleProcessorParameters poleProcessorParameters,
final int min_filter,
final ArrayList<PoleCluster> clusters)
{
int [][] real_poles = {
int [][] real_poles = { // just for the specific image set - 1526905730_462795
{232,109},
{233,109},
{226,109},
......@@ -1674,7 +1718,7 @@ public class PoleProcessor {
for (int nClust = 0; nClust < clusters.size(); nClust++) {
PoleCluster cluster = clusters.get(nClust);
if (cluster.poleFilter() >= min_filter) {
if (cluster.poleFilter(poleProcessorParameters) >= min_filter) {
boolean real_pole = false;
for (int i = 0; i < real_poles.length; i++) {
if ((real_poles[i][0] == cluster.eBox.x) && (real_poles[i][1] == cluster.eBox.y)) {
......@@ -1691,7 +1735,7 @@ public class PoleProcessor {
System.out.println(String.format("%1s %1s: %3d {%3d,%3d,%3d,%3d} %6.4f %3d (%3d) frac=%6.4f str=%7.5f str_mask=%7.5f frac_height=%5.3f fract_box =%5.3f gap=%2d x0=%6.3f/%6.3f rms=%8.6f, rstrength=%7.4f",
((cluster.poleFilter() > 0)?"*":" "),
((cluster.poleFilter(poleProcessorParameters) > 0)?"*":" "),
(real_pole?"#":"-"),
nClust, box.x, box.y, box.width, box.height, cluster.getTargetDisparity(), cluster.getSelectionSize(), cluster.getMaskSize(),cluster.getFractSelected(),
meas_strength, mask_strength,cluster.getFractHeight() , cluster.getFractBoxHeight(), cluster.getFreeStemGap(),
......@@ -1702,13 +1746,6 @@ public class PoleProcessor {
}
}
public void sortClustersByDisparity(
ArrayList<PoleCluster> clusters)
{
......@@ -1722,4 +1759,920 @@ public class PoleProcessor {
}
public double [][] processPoles(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
// BiScan biScan,
double [][] src_ds, // source disparity, strength pair
boolean [] selection, // source tile selection, will be modified
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int globalDebugLevel)
{
final int debugLevel = globalDebugLevel; // (globalDebugLevel > -2) ? clt_parameters.poles.poles_debug_level:globalDebugLevel;
double [][] norm_ds = conditionDisparityStrength(
// biScan, // final BiScan biScan,
src_ds, //
clt_parameters.rig.pf_trusted_strength, // final double trusted_strength, // trusted correlation strength
clt_parameters.rig.pf_strength_rfloor, // final double strength_rfloor,
clt_parameters.rig.pf_strength_pow); // final double strength_pow,
double seed_min_strength = clt_parameters.rig.pf_trusted_strength* (1.0 - clt_parameters.rig.pf_strength_rfloor) * clt_parameters.poles.seed_rsrength;
if (clt_parameters.rig.pf_strength_pow != 1.0) {
seed_min_strength = Math.pow(seed_min_strength, clt_parameters.rig.pf_strength_pow);
}
boolean [] seeds = findSeeds(
norm_ds, // final double [][] norm_ds,
seed_min_strength, // final double min_strength, // after subtracting floor and possible applying pow
clt_parameters.poles.seed_down, // final int seed_down,
clt_parameters.poles.seed_aover, // final double seed_aover,
clt_parameters.poles.seed_rover, // final double seed_rover,
clt_parameters.poles.max_disparity); // final double max_disparity);
ArrayList<PoleProcessor.PoleCluster> pole_clusters= initPoleClusters(
clt_parameters.poles.max_dx, // final double max_dx,
clt_parameters.poles.max_dy, // final double max_dy,
clt_parameters.poles.max_dd, // final double max_dd,
seeds, // boolean [] bseeds,
norm_ds, // double [][] norm_ds,
debugLevel); //final int debugLevel)
extendClusters(
clt_parameters.poles.ext_side, // int ext_left,
clt_parameters.poles.ext_side, // int ext_right,
clt_parameters.poles.ext_up, // int ext_up,
clt_parameters.poles.ext_down, // int ext_down,
pole_clusters); // ArrayList<PoleCluster> clusters)
cutClusterBottoms(
norm_ds, // final double [][] norm_ds,
clt_parameters.poles.pedestal_strength, // final double pedestal_strength, // bottom tiles should be at least this strong (normalized strength)
clt_parameters.poles.pedestal_disp_over, // final double pedestal_disp_over, // bottom tiles should have disparity at least by this above cluster
pole_clusters); // final ArrayList<PoleCluster> clusters)
int num_merged=mergeOverlappingClusters(
clt_parameters.poles.merge_extended, // boolean extended,
clt_parameters.poles.merge_rtolerance, // double disp_tolerance,
norm_ds, // double [][] norm_ds,
pole_clusters, // ArrayList<PoleCluster> clusters,
debugLevel); // int debugLevel)
if (debugLevel > -2) {
System.out.println("Merged "+num_merged+" clusters");
}
int num_layers = assignClustersToLayers(
pole_clusters); // ArrayList<PoleCluster> clusters)
measurePoles(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
// BiCamDSI biCamDSI,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
pole_clusters, // ArrayList<PoleProcessor.PoleCluster> pole_clusters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); //final int debugLevel)
if (debugLevel > -2) {
double [][] dbg_layers = dbgClusterLayers( // layer and eBox should be set
clt_parameters.poles, //PoleProcessorParameters poleProcessorParameters
true, // boolean show_bbox,
true, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
false, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [dbg_layers.length+2][];
for (int i = 0; i <dbg_layers.length; i++) {
dbg_layers1[i] = dbg_layers[i];
}
dbg_layers1[dbg_layers.length + 0] = norm_ds[0];
dbg_layers1[dbg_layers.length + 1] = norm_ds[1];
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers[0].length/quadCLT_main.tp.getTilesX(),
true,
"CLUSTER-BOX-MEAS");
}
// split clusters if measurements horizontal profile has multiple maximums
for (int nTry = 0; nTry < 10; nTry++) {
int num_split = splitClusters(
norm_ds, // double [][] norm_ds,
clt_parameters.poles.split_min_dist, // int min_dist, // minimal distance between local maximums
clt_parameters.poles.split_must_zero, // boolean must_zero, // zero histogram should exist between local maximum to split
pole_clusters, // ArrayList<PoleCluster> clusters,
debugLevel); // int debugLevel)
if (debugLevel > -2) {
System.out.println("splitClusters() -> "+num_split+" clusters split in two");
}
if (num_split == 0) { // one pass splits only in two, what if there are more (unlikely, but still)
break;
}
}
calcPoleLines(
clt_parameters.poles.max_diff, // final double max_diff,
clt_parameters.poles.max_tilt, // final double max_tilt,
clt_parameters.poles.max_rms, // final double max_rms,
clt_parameters.poles.min_tiles, // final int min_tiles,
clt_parameters.poles.damp_tilt, // final double damp_tilt,
pole_clusters, // final ArrayList<PoleCluster> clusters,
debugLevel); // final int debugLevel)
createPoleMasks(
norm_ds, // final double [][] norm_ds,
clt_parameters.poles.min_neibs, // final int min_neibs,
clt_parameters.poles.use_seed, // final boolean use_seed,
clt_parameters.poles.hwidth, // final double width,
clt_parameters.poles.disp_aover, // final double disp_aover,
clt_parameters.poles.disp_rover, // final double disp_rover,
pole_clusters, // final ArrayList<PoleCluster> clusters,
debugLevel); // final int debugLevel)
final boolean trim_bottoms = true; // false; // true;
filterByMask(
trim_bottoms, // final boolean trim_bottoms,
pole_clusters); // final ArrayList<PoleCluster> clusters)
if (debugLevel > -2) {
System.out.println(" === unfiltered \"pole\" clusters ===");
printClusterStats(
clt_parameters.poles, //PoleProcessorParameters poleProcessorParameters
-1, // minimal filter value
pole_clusters);
}
filterByRightLeftSeparation(
clt_parameters.poles.sep_min_strength, // final double min_strength,
clt_parameters.poles.sep_disp_adiff, // final double disp_adiff,
clt_parameters.poles.sep_disp_rdiff, // final double disp_rdiff,
norm_ds, // final double [][] norn_ds,
pole_clusters); // final ArrayList<PoleCluster> clusters)
int num_removed =removeFilteredClusters(
clt_parameters.poles, //PoleProcessorParameters poleProcessorParameters
pole_clusters, // ArrayList<PoleCluster> clusters,
debugLevel); // int debugLevel)
if (debugLevel > -2) {
System.out.println("Removed "+num_removed+" filtered out pole clusters");
}
sortClustersByDisparity(pole_clusters);
// re-assign layers
num_layers = assignClustersToLayers(
pole_clusters); // ArrayList<PoleCluster> clusters)
if (debugLevel > -2) {
System.out.println("Reassigned layers: "+num_layers);
}
double max_target_diff = applyMeasuredDisparity(
clt_parameters.poles.disparity_scale, // final double disparity_scale, // target disparity to differential disparity scale (baseline ratio)
clt_parameters.poles.diff_power, // final double diff_power, // bias towards higher disparities - (disparity+offset) is raised to this power and applied to weight
// if 0.0 - do not apply value to weight
clt_parameters.poles.diff_offset, // final double diff_offset, // add to measured differential disparity before raising to specified power
clt_parameters.poles.cut_bottom, // final int cut_bottom, // cut few tile rows from the very bottom - they may be influenced by ground objects
clt_parameters.poles.keep_bottom, //final double keep_bottom, // do not cut more that this fraction of the bounding box height
pole_clusters, // final ArrayList<PoleCluster> clusters,
debugLevel); // final int debugLevel) // debug level
if (debugLevel > -2) {
System.out.println("applyMeasuredDisparity() -> "+max_target_diff+" (max_diff)");
}
if (debugLevel > -2) {
debugClusterImages(
clt_parameters.poles , // PoleProcessorParameters poleProcessorParameters,
quadCLT_main, // QuadCLT quadCLT_main, //
pole_clusters, // ArrayList<PoleProcessor.PoleCluster> pole_clusters,
norm_ds, // double [][] norm_ds
debugLevel); // int debugLevel
}
for (int nRefine = 0; nRefine < clt_parameters.poles.max_refines; nRefine ++) {
measurePoles(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
// BiCamDSI biCamDSI,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
pole_clusters, // ArrayList<PoleProcessor.PoleCluster> pole_clusters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel + 0); //final int debugLevel)
max_target_diff = applyMeasuredDisparity(
clt_parameters.poles.disparity_scale, // final double disparity_scale, // target disparity to differential disparity scale (baseline ratio)
clt_parameters.poles.diff_power, // final double diff_power, // bias towards higher disparities - (disparity+offset) is raised to this power and applied to weight
// if 0.0 - do not apply value to weight
clt_parameters.poles.diff_offset, // final double diff_offset, // add to measured differential disparity before raising to specified power
clt_parameters.poles.cut_bottom, // final int cut_bottom, // cut few tile rows from the very bottom - they may be influenced by ground objects
clt_parameters.poles.keep_bottom, // final double keep_bottom, // do not cut more that this fraction of the bounding box height
pole_clusters, // final ArrayList<PoleCluster> clusters,
debugLevel); // final int debugLevel) // debug level
if (debugLevel > -2) {
System.out.println("applyMeasuredDisparity() -> "+max_target_diff+" (max_diff)");
}
if (debugLevel > 0) {
double [][] dbg_layers = dbgClusterLayers( // layer and eBox should be set
clt_parameters.poles, //PoleProcessorParameters poleProcessorParameters
true, // boolean show_bbox,
true, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
false, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [dbg_layers.length+2][];
for (int i = 0; i <dbg_layers.length; i++) {
dbg_layers1[i] = dbg_layers[i];
}
dbg_layers1[dbg_layers.length + 0] = norm_ds[0];
dbg_layers1[dbg_layers.length + 1] = norm_ds[1];
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers[0].length/quadCLT_main.tp.getTilesX(),
true,
"CLUSTER-BOX-MEAS-REFINE_"+nRefine);
// select measured:
filterByMask(
false, // trim_bottoms, // final boolean trim_bottoms,
pole_clusters); // final ArrayList<PoleCluster> clusters)
}
if ((debugLevel > -2) && ((nRefine >= ( clt_parameters.poles.max_refines -1)) || (debugLevel > -1))){
debugClusterRefineImages(
nRefine, // int nRefine,
clt_parameters.poles , // PoleProcessorParameters poleProcessorParameters,
quadCLT_main, // QuadCLT quadCLT_main, //
pole_clusters, // ArrayList<PoleProcessor.PoleCluster> pole_clusters,
norm_ds); // double [][] norm_ds
}
} // for (int nRefine = 0; nRefine < max_refines; nRefine ++) {
double [][] poleDisparityStrength = exportPoleDisparityStrength(
clt_parameters.poles, //PoleProcessorParameters poleProcessorParameters
0, // -1, // int filter_value,
pole_clusters); // ArrayList<PoleCluster> clusters)
/* double [][] all_ds = biScan.getDisparityStrength(
false, // only_strong,
false, // only_trusted,
false); // true); // only_enabled);
*/
double [][] all_ds = {src_ds[0].clone(),src_ds[1].clone()};
for (int nTile = 0; nTile < all_ds[0].length; nTile++) {
if ( !Double.isNaN(poleDisparityStrength[0][nTile]) &&
!(poleDisparityStrength[0][nTile] < all_ds[0][nTile]) &&
(poleDisparityStrength[0][nTile] > 0.0)) {
all_ds[0][nTile] = poleDisparityStrength[0][nTile]; // should not be 0.0 - eigenvalues will get NaN and get stuck
all_ds[1][nTile] = poleDisparityStrength[1][nTile];
}
}
// for (int nTile = 0; nTile < all_ds[0].length; nTile++) {
// if (Double.isNaN(all_ds[0][nTile]) || (all_ds[0][nTile] < 0.001)) {
// all_ds[0][nTile] = Double.NaN;
// all_ds[1][nTile] = 0.0;
// }
// }
// if (debugLevel> -2) {
// biScan.showScan(quadCLT_main.image_name+"-POLES", poleDisparityStrength);
// biScan.showScan(quadCLT_main.image_name+"-ALL-AND-POLES", all_ds);
// }
// System.out.println("quadCLT_main.tp.clt_3d_passes_size="+quadCLT_main.tp.clt_3d_passes_size+", quadCLT_main.tp.clt_3d_passes.size()="+quadCLT_main.tp.clt_3d_passes.size());
// CLTPass3d scan_last = quadCLT_main.tp.clt_3d_passes.get( quadCLT_main.tp.clt_3d_passes.size() -1); // get really last one
// boolean [] selection = scan_last.getSelected();
for (int nTile = 0; nTile < all_ds[0].length; nTile++) {
if (!Double.isNaN(poleDisparityStrength[0][nTile])) {
selection[nTile] = true; // add to source selection
}
}
return all_ds;
/*
quadCLT_main.tp.trimCLTPasses(false); // remove rig composite scan if any
CLTPass3d rig_scan = quadCLT_main.tp.compositeScan(
all_ds[0], // final double [] disparity,
all_ds[1], // final double [] strength,
selection, // final boolean [] selected,
debugLevel); // final int debugLevel)
rig_scan.texture_tiles = scan_last.texture_tiles;
// scan_last
quadCLT_main.tp.clt_3d_passes.add(rig_scan);
quadCLT_main.tp.saveCLTPasses(true); // rig pass
return true;
*/
}
public void debugClusterRefineImages(
int nRefine,
PoleProcessorParameters poleProcessorParameters,
QuadCLT quadCLT_main, // tiles should be set
ArrayList<PoleProcessor.PoleCluster> pole_clusters,
double [][] norm_ds )
{
boolean filter_poles = true;
double [][] dbg_layers_meas = dbgClusterLayers( // layer and eBox should be set
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers_selected = dbgClusterLayers( // layer and eBox should be set
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
true, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers_masks = dbgClusterLayers( // layer and eBox should be set
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
true, // boolean show_masks,
false, // boolean selected_only,
false, // boolean show_rdisparity,
false, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers_frames = dbgClusterLayers( // layer and eBox should be set
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
true, // boolean show_bbox,
true, // boolean show_ebox,
true, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
false, // boolean show_rdisparity,
false, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [4 * dbg_layers_meas.length+2][];
String [] titles = new String [4 * dbg_layers_meas.length+2];
int nl = dbg_layers_meas.length/2;
for (int i = 0; i < dbg_layers_meas.length; i++) {
dbg_layers1[4* i + 0] = dbg_layers_meas[i];
dbg_layers1[4* i + 1] = dbg_layers_selected[i];
dbg_layers1[4* i + 2] = dbg_layers_masks [i % dbg_layers_frames.length];
dbg_layers1[4* i + 3] = dbg_layers_frames[i % dbg_layers_frames.length];
if ( i < nl) {
titles[4* i + 0] ="d_full-"+i;
titles[4* i + 1] ="d_sel-"+i;
titles[4* i + 2] ="sel-"+i;
titles[4* i + 3] ="frames-"+i;
} else {
titles[4* i + 0] ="s_full-"+ (i%nl);
titles[4* i + 1] ="s_sel-"+ (i%nl);
titles[4* i + 2] ="sel-"+ (i%nl);
titles[4* i + 3] ="frames-"+ (i%nl);
}
}
dbg_layers1[4 * dbg_layers_meas.length + 0] = norm_ds[0];
dbg_layers1[4 * dbg_layers_meas.length + 1] = norm_ds[1];
titles[4 * dbg_layers_meas.length + 0] = "disparity";
titles[4 * dbg_layers_meas.length + 1] = "str-norm";
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers1[0].length/quadCLT_main.tp.getTilesX(),
true,
"MEAS-COMBO-REFINE_"+nRefine,
titles);
printClusterStats(
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
0, // minimal filter value
pole_clusters);
}
public void debugClusterImages(
PoleProcessorParameters poleProcessorParameters,
QuadCLT quadCLT_main, // tiles should be set
ArrayList<PoleProcessor.PoleCluster> pole_clusters,
double [][] norm_ds,
int debugLevel)
{
if (debugLevel > -1) {
{
double [][] dbg_layers = dbgClusterLayers( // layer and eBox should be set
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
true, // boolean show_bbox,
true, // boolean show_ebox,
true, // boolean show_lines,
false, // boolean show_masks,
true, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
false, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [dbg_layers.length+2][];
for (int i = 0; i <dbg_layers.length; i++) {
dbg_layers1[i] = dbg_layers[i];
}
dbg_layers1[dbg_layers.length + 0] = norm_ds[0];
dbg_layers1[dbg_layers.length + 1] = norm_ds[1];
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers[0].length/quadCLT_main.tp.getTilesX(),
true,
"LINES-BOX-MEAS");
}
{
double [][] dbg_layers = dbgClusterLayers( // layer and eBox should be set
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
false, // boolean show_bbox,
false, // boolean show_ebox,
true, // boolean show_lines,
false, // boolean show_masks,
true, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
false, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [dbg_layers.length+2][];
for (int i = 0; i <dbg_layers.length; i++) {
dbg_layers1[i] = dbg_layers[i];
}
dbg_layers1[dbg_layers.length + 0] = norm_ds[0];
dbg_layers1[dbg_layers.length + 1] = norm_ds[1];
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers[0].length/quadCLT_main.tp.getTilesX(),
true,
"LINES-MEAS");
}
{
double [][] dbg_layers = dbgClusterLayers( // layer and eBox should be set
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
true, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
false, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [dbg_layers.length+2][];
for (int i = 0; i <dbg_layers.length; i++) {
dbg_layers1[i] = dbg_layers[i];
}
dbg_layers1[dbg_layers.length + 0] = norm_ds[0];
dbg_layers1[dbg_layers.length + 1] = norm_ds[1];
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers[0].length/quadCLT_main.tp.getTilesX(),
true,
"MEAS-SEL");
}
}
{
boolean filter_poles = true;
double [][] dbg_layers_meas = dbgClusterLayers( // layer and eBox should be set
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers_selected = dbgClusterLayers( // layer and eBox should be set
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
true, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers_masks = dbgClusterLayers( // layer and eBox should be set
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
true, // boolean show_masks,
false, // boolean selected_only,
false, // boolean show_rdisparity,
false, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers_frames = dbgClusterLayers( // layer and eBox should be set
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
true, // boolean show_bbox,
true, // boolean show_ebox,
true, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
false, // boolean show_rdisparity,
false, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [4 * dbg_layers_meas.length+2][];
String [] titles = new String [4 * dbg_layers_meas.length+2];
int nl = dbg_layers_meas.length/2;
for (int i = 0; i < dbg_layers_meas.length; i++) {
dbg_layers1[4* i + 0] = dbg_layers_meas[i];
dbg_layers1[4* i + 1] = dbg_layers_selected[i];
dbg_layers1[4* i + 2] = dbg_layers_masks [i % dbg_layers_frames.length];
dbg_layers1[4* i + 3] = dbg_layers_frames[i % dbg_layers_frames.length];
if ( i < nl) {
titles[4* i + 0] ="d_full-"+i;
titles[4* i + 1] ="d_sel-"+i;
titles[4* i + 2] ="sel-"+i;
titles[4* i + 3] ="frames-"+i;
} else {
titles[4* i + 0] ="s_full-"+ (i%nl);
titles[4* i + 1] ="s_sel-"+ (i%nl);
titles[4* i + 2] ="sel-"+ (i%nl);
titles[4* i + 3] ="frames-"+ (i%nl);
}
}
dbg_layers1[4 * dbg_layers_meas.length + 0] = norm_ds[0];
dbg_layers1[4 * dbg_layers_meas.length + 1] = norm_ds[1];
titles[4 * dbg_layers_meas.length + 0] = "disparity";
titles[4 * dbg_layers_meas.length + 1] = "str-norm";
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers1[0].length/quadCLT_main.tp.getTilesX(),
true,
"MEAS-COMBO",
titles);
System.out.println(" === filtered \"pole\" clusters ===");
printClusterStats(
poleProcessorParameters, //PoleProcessorParameters poleProcessorParameters
0, // minimal filter value
pole_clusters);
}
}
public void measurePoles(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
EyesisCorrectionParameters.CLTParameters clt_parameters,
ArrayList<PoleProcessor.PoleCluster> pole_clusters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
double [][] layers_to_measure = getClusterLayers(
pole_clusters); // ArrayList<PoleCluster> clusters)
/*
if (debugLevel > -1) {
double [][] disparity_strength = biScan.getDisparityStrength(
false, // only_strong,
false, // only_trusted,
true); // only_enabled);
double [][] dbg_seeds = new double [2][seeds.length];
int num_seeds = 0;
for (int i = 0; i < dbg_seeds[0].length; i++ ) {
if (seeds[i]){
dbg_seeds[0][i] = disparity_strength[0][i];
dbg_seeds[1][i] = 1.0; // same contrast
num_seeds++;
} else {
dbg_seeds[0][i] = Double.NaN;
}
}
double [][] dbg_clust = new double [2][seeds.length];
for (int i = 0; i < dbg_seeds[0].length; i++ ) {
dbg_clust[0][i] = Double.NaN;
dbg_clust[1][i] = Double.NaN;
}
for (int nclust = 0; nclust < pole_clusters.size(); nclust++) {
PoleProcessor.PoleCluster cluster = pole_clusters.get(nclust);
double d = cluster.getTargetDisparity();
ArrayList<Integer> tiles = cluster.getTiles();
for (int i: tiles) {
dbg_clust[0][i] = d;
dbg_clust[1][i] = 0.01*nclust;
}
}
biScan.showScan(quadCLT_main.image_name+"-Seeds-"+scan_index, dbg_seeds);
biScan.showScan(quadCLT_main.image_name+"-Clusters-"+scan_index, dbg_clust);
biScan.showScan(quadCLT_main.image_name+"-norm_ds-"+scan_index, norm_ds);
System.out.println("findSeeds() detected "+num_seeds+" tiles as poles seeds");
System.out.println("initPoleClusters() detected "+pole_clusters.size()+" clusters as poles seeds");
System.out.println("assignClustersToLayers() detected "+num_layers+" layers to probe poles seeds");
int tilesX = quadCLT_main.tp.getTilesX();
double [][] dbg_layers = dbgClusterLayers( // layer and eBox should be set
true, // boolean show_bbox,
true, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
false, // boolean show_rdisparity,
false, // boolean show_strength,
false, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [dbg_layers.length+2][];
for (int i = 0; i <dbg_layers.length; i++) {
dbg_layers1[i] = dbg_layers[i];
}
dbg_layers1[dbg_layers.length + 0] = norm_ds[0];
dbg_layers1[dbg_layers.length + 1] = norm_ds[1];
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
tilesX,
dbg_layers[0].length/tilesX,
true,
"CLUSTER-BOXES");
(new showDoubleFloatArrays()).showArrays(
layers_to_measure,
tilesX,
layers_to_measure[0].length/tilesX,
true,
"LAYERS_TO_MEASURE");
}
*/
// Just measuring poles with different averaging
double high_disp_tolerance = 0.3;
double low_disp_tolerance = 0.3;
double min_strength = 0.15;
double [][][] measured_poles = measurePoles(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
layers_to_measure, // double [][] poles_ds,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
false, // boolean notch_mode, // use pole-detection mode for inter-camera correlation
0, // int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
measured_poles = removeDisparityMismatch(
measured_poles, // double [][][] ds_src,
high_disp_tolerance, // double high_disp_tolerance,
low_disp_tolerance, //double low_disp_tolerance );
min_strength); //double min_strength);//
if (debugLevel > -1) {
showMeasuredPoles(
"MEASURED_POLES-CENTER", // String title,
quadCLT_main.tp.getTilesX(), // tilesX, // int tilesX,
measured_poles); // double [][][] measured_poles);
}
double [][][] measured_poles_strongest = poleAddStrongest(
measured_poles, // double [][][] ds_src,
null); // double [][][] ds_other)
double [][][] measured_poles_fittest = poleAddFittest(
measured_poles, // double [][][] ds_src,
null); // double [][][] ds_other)
for (int num_avg = 0; num_avg < 5; num_avg++) {
measured_poles = measurePoles(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
layers_to_measure, // double [][] poles_ds,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
true, // boolean notch_mode, // use pole-detection mode for inter-camera correlation
num_avg, // int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
measured_poles = removeDisparityMismatch(
measured_poles, // double [][][] ds_src,
high_disp_tolerance, // double high_disp_tolerance,
low_disp_tolerance, //double low_disp_tolerance );
min_strength); //double min_strength);//
measured_poles_strongest = poleAddStrongest(
measured_poles_strongest, // double [][][] ds_src,
measured_poles); // double [][][] ds_other)
measured_poles_fittest = poleAddFittest(
measured_poles_fittest, // double [][][] ds_src,
measured_poles); // double [][][] ds_other)
if (debugLevel > 0) {
showMeasuredPoles(
"MEASURED_POLES-AVG"+num_avg, // String title,
quadCLT_main.tp.getTilesX(), // tilesX, // int tilesX,
measured_poles); // double [][][] measured_poles);
}
}
if (debugLevel > -1) {
showMeasuredPoles(
"MEASURED_POLES-STRONGEST", // String title,
quadCLT_main.tp.getTilesX(), // tilesX, // int tilesX,
measured_poles_strongest); // double [][][] measured_poles);
showMeasuredPoles(
"MEASURED_POLES-FITTEST", // String title,
quadCLT_main.tp.getTilesX(), // tilesX, // int tilesX,
measured_poles_fittest); // double [][][] measured_poles);
}
addMeasuredTiles(
true, // final boolean reset_data,
measured_poles_fittest, // final double [][][] measured_layers,
pole_clusters); // final ArrayList<PoleCluster> clusters
}
public double [][][] removeDisparityMismatch(
double [][][] ds_src,
double high_disp_tolerance,
double low_disp_tolerance,
double min_strength)
{
double [][][] ds = new double [ds_src.length][2][];
for (int i =0; i <ds.length; i++) {
ds[i][0] = ds_src[i][0].clone();
ds[i][1] = ds_src[i][1].clone();
for (int nTile = 0; nTile < ds[i][0].length; nTile++) {
if ( (ds_src[i][1][nTile] < min_strength) ||
(ds_src[i][0][nTile] > high_disp_tolerance) ||
(ds_src[i][0][nTile] < -low_disp_tolerance)) {
ds[i][0][nTile] = Double.NaN;
ds[i][1][nTile] = 0.0;
}
}
}
return ds;
}
public double [][][] poleAddStrongest(
double [][][] ds_src,
double [][][] ds_other)
{
int num_layers = (ds_src == null) ? ds_other.length : ds_src.length;
double [][][] ds = new double [num_layers][2][];
boolean just_clone = (ds_src == null) || (ds_other == null);
if (ds_src == null) {
ds_src = ds_other;
}
for (int i =0; i <ds.length; i++) {
ds[i][0] = ds_src[i][0].clone();
ds[i][1] = ds_src[i][1].clone();
if (!just_clone) {
for (int nTile = 0; nTile < ds[i][0].length; nTile++) {
if (ds_other[i][1][nTile] > ds[i][1][nTile]) {
ds[i][0][nTile] = ds_other[i][0][nTile];
ds[i][1][nTile] = ds_other[i][1][nTile];
}
}
}
}
return ds;
}
public double [][][] poleAddFittest(
double [][][] ds_src,
double [][][] ds_other)
{
int num_layers = (ds_src == null) ? ds_other.length : ds_src.length;
double [][][] ds = new double [num_layers][2][];
boolean just_clone = (ds_src == null) || (ds_other == null);
if (ds_src == null) {
ds_src = ds_other;
}
for (int i =0; i <ds.length; i++) {
ds[i][0] = ds_src[i][0].clone();
ds[i][1] = ds_src[i][1].clone();
if (!just_clone) {
for (int nTile = 0; nTile < ds[i][0].length; nTile++) {
if (Double.isNaN(ds[i][0][nTile]) || (Math.abs(ds_other[i][0][nTile]) < Math.abs(ds[i][0][nTile]))) {
ds[i][0][nTile] = ds_other[i][0][nTile];
ds[i][1][nTile] = ds_other[i][1][nTile];
}
}
}
}
return ds;
}
private void showMeasuredPoles(
String title,
int tilesX,
double [][][] measured_poles) {
int num_layers = measured_poles.length;
String [] titles = new String[2 * num_layers];
double [][] dbg_img = new double[2 * num_layers][];
for (int i = 0; i < num_layers; i++) {
titles[i] = "disparity_"+i;
titles[i+num_layers] = "strength_"+i;
dbg_img[i] = measured_poles[i][0];
dbg_img[i+num_layers] = measured_poles[i][1];
}
(new showDoubleFloatArrays()).showArrays(
dbg_img,
tilesX,
dbg_img[0].length/tilesX,
true,
title,
titles);
}
private double [][][] measurePoles(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][] poles_ds,
EyesisCorrectionParameters.CLTParameters clt_parameters,
boolean notch_mode, // use pole-detection mode for inter-camera correlation
int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
int num_layers = poles_ds.length;
int tile_op_all = clt_parameters.tile_task_op; //FIXME Use some constant?
int tilesX =quadCLT_main.tp.getTilesX();
int tilesY =quadCLT_main.tp.getTilesY();
double [][][] measuredDisparityStrength = new double [num_layers][2][]; // num_tiles];
for (int layer = 0; layer < num_layers; layer++) {
int [][] tile_op = new int [tilesY][tilesX];
double [][] disparity_array = new double [tilesY][tilesX];
for (int tileY = 0; tileY<tilesY;tileY++) {
for (int tileX = 0; tileX<tilesX;tileX++) {
int nTile = tileY * tilesX + tileX;
disparity_array[tileY][tileX] = poles_ds[layer][nTile];
if (!Double.isNaN(poles_ds[layer][nTile])) {
tile_op[tileY][tileX] = tile_op_all;
}
}
}
double [][] disparity_bimap = twoQuadCLT.measureRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
null, // double [][] ml_data, // data for ML - 10 layers - 4 center areas (3x3, 5x5,..) per camera-per direction, 1 - composite, and 1 with just 1 data (target disparity)
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_parameters.fat_zero, // double fatzero,
notch_mode, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
lt_rad, // final int // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
true, // boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
measuredDisparityStrength[layer][0] = disparity_bimap[ImageDtt.BI_DISP_CROSS_INDEX];
measuredDisparityStrength[layer][1] = disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX];
}
return measuredDisparityStrength;
}
}
......@@ -94,7 +94,8 @@ public class PoleProcessorParameters {
public void dialogQuestions(GenericJTabbedDialog gd) {
gd.addCheckbox ("Enable poles detection and usage", this.poles_en,"Enable poles detection and usege to improve DSI");
gd.addCheckbox ("Enable poles detection and usage", this.poles_en,
"Run automatically when creating ground truth data. If disable you may run it with \"Poles GT\" command button");
gd.addMessage("Creating initial pole seeds (tops need to be detected and available in the available DSI");
gd.addNumericField("Pole relative (to trusted tiles strength) to qualify for the pole seed", this.seed_rsrength, 3,6,"",
"Pole top seed relative strength (fraction of the strong trusted value that may change with correlation fat zero or other parameters");
......
......@@ -32,6 +32,11 @@ import java.util.concurrent.atomic.AtomicInteger;
public class TileProcessor {
public ArrayList <CLTPass3d> clt_3d_passes = null;
public double [][] rig_disparity_strength = null; // Disparity and strength created by a two-camera rig, with disparity scale and distortions of the main camera
public double [][] rig_pre_poles_ds = null; // Rig disparity and strength before processing poles
public double [][] rig_post_poles_ds = null; // Rig disparity and strength after processing poles
public boolean [] rig_pre_poles_sel = null; // Rig tile selection before processing poles
public boolean [] rig_post_poles_sel = null; // Rig tile selection after processing poles
public int clt_3d_passes_size = 0; //clt_3d_passes size after initial processing
public int clt_3d_passes_rig_size = 0; //clt_3d_passes size after initial processing and rig processing
private int tilesX;
......@@ -114,6 +119,11 @@ public class TileProcessor {
if (rig) clt_3d_passes_rig_size = clt_3d_passes.size();
else {
rig_disparity_strength = null; // invalidate
rig_pre_poles_ds = null;
rig_post_poles_ds = null;
rig_pre_poles_sel = null;
rig_post_poles_sel = null;
clt_3d_passes_rig_size = 0;
clt_3d_passes_size = clt_3d_passes.size();
}
......@@ -122,6 +132,10 @@ public class TileProcessor {
public void trimCLTPasses(int keep){
if (keep < clt_3d_passes_size) { // keep rig data if only rig scan is removed
rig_disparity_strength = null; // invalidate
rig_pre_poles_ds = null;
rig_post_poles_ds = null;
rig_pre_poles_sel = null;
rig_post_poles_sel = null;
clt_3d_passes_rig_size = 0;
}
clt_3d_passes_size = keep;
......@@ -162,6 +176,11 @@ public class TileProcessor {
}
// just in case - invalidate (should be done anyway)
rig_disparity_strength = null; // invalidate
rig_pre_poles_ds = null;
rig_post_poles_ds = null;
rig_pre_poles_sel = null;
rig_post_poles_sel = null;
clt_3d_passes_rig_size = 0;
}
......
......@@ -1217,13 +1217,17 @@ if (debugLevel > -100) return true; // temporarily !
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
final int globalDebugLevel)
{
// -1 and above - follow clt_parameters.poles.poles_debug_level, -2 and below - follow global debug level
final int debugLevel = (globalDebugLevel > -2) ? clt_parameters.poles.poles_debug_level:globalDebugLevel;
if ((quadCLT_main == null) ||
(quadCLT_main.tp == null) ||
(quadCLT_main.tp.clt_3d_passes == null) ||
(biCamDSI_persistent== null) ||
(biCamDSI_persistent.biScans== null)) {
(biCamDSI_persistent.biScans== null) ||
(quadCLT_main.tp.rig_pre_poles_ds == null)
) {
String msg = "Data is not available. Please run \"Ground truth\" first";
IJ.showMessage("Error",msg);
System.out.println(msg);
......@@ -1237,587 +1241,38 @@ if (debugLevel > -100) return true; // temporarily !
if (poleProcessor_persistent == null) {
poleProcessor_persistent = new PoleProcessor(
biCamDSI_persistent,
this, // TwoQuadCLT twoQuadCLT,
quadCLT_main.tp.getTilesX(),
quadCLT_main.tp.getTilesY());
}
PoleProcessor pp = poleProcessor_persistent;
final double seed_rsrength = 0.8;
final int seed_down = 5;
final double seed_aover = 0.2;
final double seed_rover = 0.05;
final double max_disparity = 5.0;
double [][] norm_ds = pp.conditionDisparityStrength(
biScan, // final BiScan biScan,
clt_parameters.rig.pf_trusted_strength, // final double trusted_strength, // trusted correlation strength
clt_parameters.rig.pf_strength_rfloor, // final double strength_rfloor,
clt_parameters.rig.pf_strength_pow); // final double strength_pow,
double seed_min_strength = clt_parameters.rig.pf_trusted_strength* (1.0 - clt_parameters.rig.pf_strength_rfloor) * seed_rsrength;
if (clt_parameters.rig.pf_strength_pow != 1.0) {
seed_min_strength = Math.pow(seed_min_strength, clt_parameters.rig.pf_strength_pow);
}
boolean [] seeds = pp.findSeeds(
norm_ds, // final double [][] norm_ds,
seed_min_strength, // final double min_strength, // after subtracting floor and possible applying pow
seed_down, // final int seed_down,
seed_aover, // final double seed_aover,
seed_rover, // final double seed_rover,
max_disparity); // final double max_disparity);
double max_dd = 0.1;
double max_dx = 5;
double max_dy = Double.NaN;
int ext_side = 2;
int ext_up = 2;
int ext_down = 30;
double pedestal_strength = 0.15;
double pedestal_disp_over = 0.3;
ArrayList<PoleProcessor.PoleCluster> pole_clusters= pp.initPoleClusters(
max_dx, // final double max_dx,
max_dy, // final double max_dy,
max_dd, // final double max_dd,
seeds, // boolean [] bseeds,
norm_ds, // double [][] norm_ds,
debugLevel); //final int debugLevel)
pp.extendClusters(
ext_side, // int ext_left,
ext_side, // int ext_right,
ext_up, // int ext_up,
ext_down, // int ext_down,
pole_clusters); // ArrayList<PoleCluster> clusters)
pp.cutClusterBottoms(
norm_ds, // final double [][] norm_ds,
pedestal_strength, // final double pedestal_strength, // bottom tiles should be at least this strong (normalized strength)
pedestal_disp_over, // final double pedestal_disp_over, // bottom tiles should have disparity at least by this above cluster
pole_clusters); // final ArrayList<PoleCluster> clusters)
boolean extended = false; // merge if only original clusters intersect
double disp_tolerance = 1.5; // max_dd;
int num_merged=pp.mergeOverlappingClusters(
extended, // boolean extended,
disp_tolerance, // double disp_tolerance,
norm_ds, // double [][] norm_ds,
pole_clusters, // ArrayList<PoleCluster> clusters,
debugLevel); // int debugLevel)
if (debugLevel > -2) {
System.out.println("Merged "+num_merged+" clusters");
}
int num_layers = pp.assignClustersToLayers(
pole_clusters); // ArrayList<PoleCluster> clusters)
measurePoles(
boolean [] selection = quadCLT_main.tp.rig_pre_poles_sel.clone();
double [][] poles_ds = pp.processPoles(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
// BiCamDSI biCamDSI,
quadCLT_aux, //QuadCLT quadCLT_aux,
// biScan, // BiScan biScan,
quadCLT_main.tp.rig_pre_poles_ds, // double [][] src_ds, // source disparity, strength pair
selection, // boolean [] selection, // source tile selection, will be modified
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
pole_clusters, // ArrayList<PoleProcessor.PoleCluster> pole_clusters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); //final int debugLevel)
if (debugLevel > -2) {
double [][] dbg_layers = pp.dbgClusterLayers( // layer and eBox should be set
true, // boolean show_bbox,
true, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
false, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [dbg_layers.length+2][];
for (int i = 0; i <dbg_layers.length; i++) {
dbg_layers1[i] = dbg_layers[i];
}
dbg_layers1[dbg_layers.length + 0] = norm_ds[0];
dbg_layers1[dbg_layers.length + 1] = norm_ds[1];
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers[0].length/quadCLT_main.tp.getTilesX(),
true,
"CLUSTER-BOX-MEAS");
}
// split clusters if measurements horizontal profile has multiple maximums
final int split_min_dist = 3; // minimal distance between local maximums to split
final boolean must_zero = false; // true; // false; // there should be complete zero-strength on the profile to enable split
for (int nTry = 0; nTry < 10; nTry++) {
int num_split = pp.splitClusters(
norm_ds, // double [][] norm_ds,
split_min_dist, // int min_dist, // minimal distance between local maximums
must_zero, // boolean must_zero, // zero histogram should exist between local maximum to split
pole_clusters, // ArrayList<PoleCluster> clusters,
debugLevel); // int debugLevel)
if (debugLevel > -2) {
System.out.println("splitClusters() -> "+num_split+" clusters split in two");
}
if (num_split == 0) { // one pass splits only in two, what if there are more (unlikely, but still)
break;
}
}
final double max_diff = 2.0;
final double max_tilt = 0.1;
final double max_rms = 1.0;
final int min_tiles = 3;
final double damp_tilt = 0.1;
pp.calcPoleLines(
max_diff, // final double max_diff,
max_tilt, // final double max_tilt,
max_rms, // final double max_rms,
min_tiles, // final int min_tiles,
damp_tilt, // final double damp_tilt,
pole_clusters, // final ArrayList<PoleCluster> clusters,
debugLevel); // final int debugLevel)
final boolean use_seed = true;
final double hwidth = 0.75;
final double disp_aover = 0.2;
final double disp_rover = 0.05;
final int min_neibs = 3; // minimal number of neighbors to keep tile in the pole mask
pp.createPoleMasks(
norm_ds, // final double [][] norm_ds,
min_neibs, // final int min_neibs,
use_seed, // final boolean use_seed,
hwidth, // final double width,
disp_aover, // final double disp_aover,
disp_rover, // final double disp_rover,
pole_clusters, // final ArrayList<PoleCluster> clusters,
debugLevel); // final int debugLevel)
final boolean trim_bottoms = true; // false; // true;
pp.filterByMask(
trim_bottoms, // final boolean trim_bottoms,
pole_clusters); // final ArrayList<PoleCluster> clusters)
if (debugLevel > -2) {
System.out.println(" === unfiltered \"pole\" clusters ===");
pp.printClusterStats(
-1, // minimal filter value
pole_clusters);
}
final double sep_min_strength = 0.07;
final double sep_disp_adiff = 0.15;
final double sep_disp_rdiff = 0.05;
pp.filterByRightLeftSeparation(
sep_min_strength, // final double min_strength,
sep_disp_adiff, // final double disp_adiff,
sep_disp_rdiff, // final double disp_rdiff,
norm_ds, // final double [][] norn_ds,
pole_clusters); // final ArrayList<PoleCluster> clusters)
int num_removed =pp.removeFilteredClusters(
pole_clusters, // ArrayList<PoleCluster> clusters,
debugLevel); // int debugLevel)
if (debugLevel > -2) {
System.out.println("Removed "+num_removed+" filtered out pole clusters");
}
pp.sortClustersByDisparity(pole_clusters);
// re-assign layers
num_layers = pp.assignClustersToLayers(
pole_clusters); // ArrayList<PoleCluster> clusters)
if (debugLevel > -2) {
System.out.println("Reaasigned layers: "+num_layers);
}
final double disparity_scale = 0.3; // 2; // target disparity to differential disparity scale (baseline ratio)
final double diff_power = 1.0; // bias towards higher disparities - (disparity+offset) is raised to this power and applied to weight
// if 0.0 - do not apply value to weight
final double diff_offset = 0.5; // add to measured differential disparity before raising to specified power
final int cut_bottom = 2; // cut few tile rows from the very bottom - they may be influenced by ground objects
final double keep_bottom = 0.1; // do not cut more that this fraction of the bounding box height
double max_target_diff = pp.applyMeasuredDisparity(
disparity_scale, // final double disparity_scale, // target disparity to differential disparity scale (baseline ratio)
diff_power, // final double diff_power, // bias towards higher disparities - (disparity+offset) is raised to this power and applied to weight
// if 0.0 - do not apply value to weight
diff_offset, // final double diff_offset, // add to measured differential disparity before raising to specified power
cut_bottom, // final int cut_bottom, // cut few tile rows from the very bottom - they may be influenced by ground objects
keep_bottom, //final double keep_bottom, // do not cut more that this fraction of the bounding box height
pole_clusters, // final ArrayList<PoleCluster> clusters,
debugLevel); // final int debugLevel) // debug level
if (debugLevel > -2) {
System.out.println("applyMeasuredDisparity() -> "+max_target_diff+" (max_diff)");
}
if (debugLevel > -2) {
if (debugLevel > -1) {
{
double [][] dbg_layers = pp.dbgClusterLayers( // layer and eBox should be set
true, // boolean show_bbox,
true, // boolean show_ebox,
true, // boolean show_lines,
false, // boolean show_masks,
true, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
false, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [dbg_layers.length+2][];
for (int i = 0; i <dbg_layers.length; i++) {
dbg_layers1[i] = dbg_layers[i];
}
dbg_layers1[dbg_layers.length + 0] = norm_ds[0];
dbg_layers1[dbg_layers.length + 1] = norm_ds[1];
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers[0].length/quadCLT_main.tp.getTilesX(),
true,
"LINES-BOX-MEAS");
}
{
double [][] dbg_layers = pp.dbgClusterLayers( // layer and eBox should be set
false, // boolean show_bbox,
false, // boolean show_ebox,
true, // boolean show_lines,
false, // boolean show_masks,
true, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
false, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [dbg_layers.length+2][];
for (int i = 0; i <dbg_layers.length; i++) {
dbg_layers1[i] = dbg_layers[i];
}
dbg_layers1[dbg_layers.length + 0] = norm_ds[0];
dbg_layers1[dbg_layers.length + 1] = norm_ds[1];
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers[0].length/quadCLT_main.tp.getTilesX(),
true,
"LINES-MEAS");
}
{
double [][] dbg_layers = pp.dbgClusterLayers( // layer and eBox should be set
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
true, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
false, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [dbg_layers.length+2][];
for (int i = 0; i <dbg_layers.length; i++) {
dbg_layers1[i] = dbg_layers[i];
}
dbg_layers1[dbg_layers.length + 0] = norm_ds[0];
dbg_layers1[dbg_layers.length + 1] = norm_ds[1];
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers[0].length/quadCLT_main.tp.getTilesX(),
true,
"MEAS-SEL");
}
}
{
boolean filter_poles = true;
double [][] dbg_layers_meas = pp.dbgClusterLayers( // layer and eBox should be set
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers_selected = pp.dbgClusterLayers( // layer and eBox should be set
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
true, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers_masks = pp.dbgClusterLayers( // layer and eBox should be set
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
true, // boolean show_masks,
false, // boolean selected_only,
false, // boolean show_rdisparity,
false, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers_frames = pp.dbgClusterLayers( // layer and eBox should be set
true, // boolean show_bbox,
true, // boolean show_ebox,
true, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
false, // boolean show_rdisparity,
false, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [4 * dbg_layers_meas.length+2][];
String [] titles = new String [4 * dbg_layers_meas.length+2];
int nl = dbg_layers_meas.length/2;
for (int i = 0; i < dbg_layers_meas.length; i++) {
dbg_layers1[4* i + 0] = dbg_layers_meas[i];
dbg_layers1[4* i + 1] = dbg_layers_selected[i];
dbg_layers1[4* i + 2] = dbg_layers_masks [i % dbg_layers_frames.length];
dbg_layers1[4* i + 3] = dbg_layers_frames[i % dbg_layers_frames.length];
if ( i < nl) {
titles[4* i + 0] ="d_full-"+i;
titles[4* i + 1] ="d_sel-"+i;
titles[4* i + 2] ="sel-"+i;
titles[4* i + 3] ="frames-"+i;
} else {
titles[4* i + 0] ="s_full-"+ (i%nl);
titles[4* i + 1] ="s_sel-"+ (i%nl);
titles[4* i + 2] ="sel-"+ (i%nl);
titles[4* i + 3] ="frames-"+ (i%nl);
}
}
dbg_layers1[4 * dbg_layers_meas.length + 0] = norm_ds[0];
dbg_layers1[4 * dbg_layers_meas.length + 1] = norm_ds[1];
titles[4 * dbg_layers_meas.length + 0] = "disparity";
titles[4 * dbg_layers_meas.length + 1] = "str-norm";
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers1[0].length/quadCLT_main.tp.getTilesX(),
true,
"MEAS-COMBO",
titles);
System.out.println(" === filtered \"pole\" clusters ===");
pp.printClusterStats(
0, // minimal filter value
pole_clusters);
}
}
final int max_refines = 20;
for (int nRefine = 0; nRefine < max_refines; nRefine ++) {
measurePoles(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
// BiCamDSI biCamDSI,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
pole_clusters, // ArrayList<PoleProcessor.PoleCluster> pole_clusters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel + 0); //final int debugLevel)
max_target_diff = pp.applyMeasuredDisparity(
disparity_scale, // final double disparity_scale, // target disparity to differential disparity scale (baseline ratio)
diff_power, // final double diff_power, // bias towards higher disparities - (disparity+offset) is raised to this power and applied to weight
// if 0.0 - do not apply value to weight
diff_offset, // final double diff_offset, // add to measured differential disparity before raising to specified power
cut_bottom, // final int cut_bottom, // cut few tile rows from the very bottom - they may be influenced by ground objects
keep_bottom, //final double keep_bottom, // do not cut more that this fraction of the bounding box height
pole_clusters, // final ArrayList<PoleCluster> clusters,
debugLevel); // final int debugLevel) // debug level
if (debugLevel > -2) {
System.out.println("applyMeasuredDisparity() -> "+max_target_diff+" (max_diff)");
}
if (debugLevel > 0) {
double [][] dbg_layers = pp.dbgClusterLayers( // layer and eBox should be set
true, // boolean show_bbox,
true, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
false, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [dbg_layers.length+2][];
for (int i = 0; i <dbg_layers.length; i++) {
dbg_layers1[i] = dbg_layers[i];
}
dbg_layers1[dbg_layers.length + 0] = norm_ds[0];
dbg_layers1[dbg_layers.length + 1] = norm_ds[1];
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers[0].length/quadCLT_main.tp.getTilesX(),
true,
"CLUSTER-BOX-MEAS-REFINE_"+nRefine);
// select measured:
pp.filterByMask(
false, // trim_bottoms, // final boolean trim_bottoms,
pole_clusters); // final ArrayList<PoleCluster> clusters)
}
if ((debugLevel > -2) && ((nRefine >= (max_refines -1)) || (debugLevel > -1))){
boolean filter_poles = true;
double [][] dbg_layers_meas = pp.dbgClusterLayers( // layer and eBox should be set
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers_selected = pp.dbgClusterLayers( // layer and eBox should be set
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
true, // boolean selected_only,
true, // boolean show_rdisparity,
true, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers_masks = pp.dbgClusterLayers( // layer and eBox should be set
false, // boolean show_bbox,
false, // boolean show_ebox,
false, // boolean show_lines,
true, // boolean show_masks,
false, // boolean selected_only,
false, // boolean show_rdisparity,
false, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers_frames = pp.dbgClusterLayers( // layer and eBox should be set
true, // boolean show_bbox,
true, // boolean show_ebox,
true, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
false, // boolean show_rdisparity,
false, // boolean show_strength,
filter_poles, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [4 * dbg_layers_meas.length+2][];
String [] titles = new String [4 * dbg_layers_meas.length+2];
int nl = dbg_layers_meas.length/2;
for (int i = 0; i < dbg_layers_meas.length; i++) {
dbg_layers1[4* i + 0] = dbg_layers_meas[i];
dbg_layers1[4* i + 1] = dbg_layers_selected[i];
dbg_layers1[4* i + 2] = dbg_layers_masks [i % dbg_layers_frames.length];
dbg_layers1[4* i + 3] = dbg_layers_frames[i % dbg_layers_frames.length];
if ( i < nl) {
titles[4* i + 0] ="d_full-"+i;
titles[4* i + 1] ="d_sel-"+i;
titles[4* i + 2] ="sel-"+i;
titles[4* i + 3] ="frames-"+i;
} else {
titles[4* i + 0] ="s_full-"+ (i%nl);
titles[4* i + 1] ="s_sel-"+ (i%nl);
titles[4* i + 2] ="sel-"+ (i%nl);
titles[4* i + 3] ="frames-"+ (i%nl);
}
}
dbg_layers1[4 * dbg_layers_meas.length + 0] = norm_ds[0];
dbg_layers1[4 * dbg_layers_meas.length + 1] = norm_ds[1];
titles[4 * dbg_layers_meas.length + 0] = "disparity";
titles[4 * dbg_layers_meas.length + 1] = "str-norm";
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
quadCLT_main.tp.getTilesX(),
dbg_layers1[0].length/quadCLT_main.tp.getTilesX(),
true,
"MEAS-COMBO-REFINE_"+nRefine,
titles);
pp.printClusterStats(
0, // minimal filter value
pole_clusters);
}
} // for (int nRefine = 0; nRefine < max_refines; nRefine ++) {
double [][] poleDisparityStrength = pp.exportPoleDisparityStrength(
-1, // int filter_value,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] all_ds = biScan.getDisparityStrength(
false, // only_strong,
false, // only_trusted,
true); // only_enabled);
/* Random rand = new Random();
for (int nTile = 0; nTile < all_ds[0].length; nTile++) {
if (!Double.isNaN(poleDisparityStrength[0][nTile]) && !(poleDisparityStrength[0][nTile] < all_ds[0][nTile])) {
all_ds[0][nTile] = poleDisparityStrength[0][nTile] + 0.001*rand.nextDouble();
all_ds[1][nTile] = poleDisparityStrength[1][nTile] + 0.001*rand.nextDouble();
}
}
*/
for (int nTile = 0; nTile < all_ds[0].length; nTile++) {
if (!Double.isNaN(poleDisparityStrength[0][nTile]) && !(poleDisparityStrength[0][nTile] < all_ds[0][nTile])) {
all_ds[0][nTile] = poleDisparityStrength[0][nTile];
all_ds[1][nTile] = poleDisparityStrength[1][nTile];
}
}
for (int nTile = 0; nTile < all_ds[0].length; nTile++) {
if (Double.isNaN(all_ds[0][nTile]) || (all_ds[0][nTile] < 0.001)) {
all_ds[0][nTile] = Double.NaN;
all_ds[1][nTile] = 0.0;
}
}
debugLevel); // final int globalDebugLevel)
if (debugLevel> -2) {
biScan.showScan(quadCLT_main.image_name+"-POLES-"+scan_index, poleDisparityStrength);
biScan.showScan(quadCLT_main.image_name+"-ALL-AND-POLES-"+scan_index, all_ds);
}
System.out.println("quadCLT_main.tp.clt_3d_passes_size="+quadCLT_main.tp.clt_3d_passes_size+", quadCLT_main.tp.clt_3d_passes.size()="+quadCLT_main.tp.clt_3d_passes.size());
// CLTPass3d scan_last = quadCLT_main.tp.clt_3d_passes.get( quadCLT_main.tp.clt_3d_passes_size -1); // get last one
// System.out.println("quadCLT_main.tp.clt_3d_passes_size="+quadCLT_main.tp.clt_3d_passes_size+", quadCLT_main.tp.clt_3d_passes.size()="+quadCLT_main.tp.clt_3d_passes.size());
CLTPass3d scan_last = quadCLT_main.tp.clt_3d_passes.get( quadCLT_main.tp.clt_3d_passes.size() -1); // get really last one
boolean [] selection = scan_last.getSelected();
for (int nTile = 0; nTile < all_ds[0].length; nTile++) {
if (!Double.isNaN(poleDisparityStrength[0][nTile])) {
selection[nTile] = true;
}
}
//
//
// boolean [] selection = scan_last.getSelected();
// for (int nTile = 0; nTile < all_ds[0].length; nTile++) {
// if (!Double.isNaN(poleDisparityStrength[0][nTile])) {
// selection[nTile] = true;
// }
// }
quadCLT_main.tp.trimCLTPasses(false); // remove rig composite scan if any
CLTPass3d rig_scan = quadCLT_main.tp.compositeScan(
all_ds[0], // final double [] disparity,
all_ds[1], // final double [] strength,
poles_ds[0], // final double [] disparity,
poles_ds[1], // final double [] strength,
selection, // final boolean [] selected,
debugLevel); // final int debugLevel)
rig_scan.texture_tiles = scan_last.texture_tiles;
......@@ -1827,256 +1282,6 @@ if (debugLevel > -100) return true; // temporarily !
return true;
}
public void measurePoles(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
// BiCamDSI biCamDSI,
EyesisCorrectionParameters.CLTParameters clt_parameters,
ArrayList<PoleProcessor.PoleCluster> pole_clusters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
PoleProcessor pp = poleProcessor_persistent;
double [][] layers_to_measure = pp.getClusterLayers(
pole_clusters); // ArrayList<PoleCluster> clusters)
/*
if (debugLevel > -1) {
double [][] disparity_strength = biScan.getDisparityStrength(
false, // only_strong,
false, // only_trusted,
true); // only_enabled);
double [][] dbg_seeds = new double [2][seeds.length];
int num_seeds = 0;
for (int i = 0; i < dbg_seeds[0].length; i++ ) {
if (seeds[i]){
dbg_seeds[0][i] = disparity_strength[0][i];
dbg_seeds[1][i] = 1.0; // same contrast
num_seeds++;
} else {
dbg_seeds[0][i] = Double.NaN;
}
}
double [][] dbg_clust = new double [2][seeds.length];
for (int i = 0; i < dbg_seeds[0].length; i++ ) {
dbg_clust[0][i] = Double.NaN;
dbg_clust[1][i] = Double.NaN;
}
for (int nclust = 0; nclust < pole_clusters.size(); nclust++) {
PoleProcessor.PoleCluster cluster = pole_clusters.get(nclust);
double d = cluster.getTargetDisparity();
ArrayList<Integer> tiles = cluster.getTiles();
for (int i: tiles) {
dbg_clust[0][i] = d;
dbg_clust[1][i] = 0.01*nclust;
}
}
biScan.showScan(quadCLT_main.image_name+"-Seeds-"+scan_index, dbg_seeds);
biScan.showScan(quadCLT_main.image_name+"-Clusters-"+scan_index, dbg_clust);
biScan.showScan(quadCLT_main.image_name+"-norm_ds-"+scan_index, norm_ds);
System.out.println("findSeeds() detected "+num_seeds+" tiles as poles seeds");
System.out.println("initPoleClusters() detected "+pole_clusters.size()+" clusters as poles seeds");
System.out.println("assignClustersToLayers() detected "+num_layers+" layers to probe poles seeds");
int tilesX = quadCLT_main.tp.getTilesX();
double [][] dbg_layers = pp.dbgClusterLayers( // layer and eBox should be set
true, // boolean show_bbox,
true, // boolean show_ebox,
false, // boolean show_lines,
false, // boolean show_masks,
false, // boolean selected_only,
false, // boolean show_rdisparity,
false, // boolean show_strength,
false, // boolean filter,
pole_clusters); // ArrayList<PoleCluster> clusters)
double [][] dbg_layers1 = new double [dbg_layers.length+2][];
for (int i = 0; i <dbg_layers.length; i++) {
dbg_layers1[i] = dbg_layers[i];
}
dbg_layers1[dbg_layers.length + 0] = norm_ds[0];
dbg_layers1[dbg_layers.length + 1] = norm_ds[1];
(new showDoubleFloatArrays()).showArrays(
dbg_layers1,
tilesX,
dbg_layers[0].length/tilesX,
true,
"CLUSTER-BOXES");
(new showDoubleFloatArrays()).showArrays(
layers_to_measure,
tilesX,
layers_to_measure[0].length/tilesX,
true,
"LAYERS_TO_MEASURE");
}
*/
// Just measuring poles with different averaging
double high_disp_tolerance = 0.3;
double low_disp_tolerance = 0.3;
double min_strength = 0.15;
double [][][] measured_poles = measurePoles(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
layers_to_measure, // double [][] poles_ds,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
false, // boolean notch_mode, // use pole-detection mode for inter-camera correlation
0, // int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
measured_poles = removeDisparityMismatch(
measured_poles, // double [][][] ds_src,
high_disp_tolerance, // double high_disp_tolerance,
low_disp_tolerance, //double low_disp_tolerance );
min_strength); //double min_strength);//
if (debugLevel > -1) {
showMeasuredPoles(
"MEASURED_POLES-CENTER", // String title,
quadCLT_main.tp.getTilesX(), // tilesX, // int tilesX,
measured_poles); // double [][][] measured_poles);
}
double [][][] measured_poles_strongest = poleAddStrongest(
measured_poles, // double [][][] ds_src,
null); // double [][][] ds_other)
double [][][] measured_poles_fittest = poleAddFittest(
measured_poles, // double [][][] ds_src,
null); // double [][][] ds_other)
for (int num_avg = 0; num_avg < 5; num_avg++) {
measured_poles = measurePoles(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
layers_to_measure, // double [][] poles_ds,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
true, // boolean notch_mode, // use pole-detection mode for inter-camera correlation
num_avg, // int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
measured_poles = removeDisparityMismatch(
measured_poles, // double [][][] ds_src,
high_disp_tolerance, // double high_disp_tolerance,
low_disp_tolerance, //double low_disp_tolerance );
min_strength); //double min_strength);//
measured_poles_strongest = poleAddStrongest(
measured_poles_strongest, // double [][][] ds_src,
measured_poles); // double [][][] ds_other)
measured_poles_fittest = poleAddFittest(
measured_poles_fittest, // double [][][] ds_src,
measured_poles); // double [][][] ds_other)
if (debugLevel > 0) {
showMeasuredPoles(
"MEASURED_POLES-AVG"+num_avg, // String title,
quadCLT_main.tp.getTilesX(), // tilesX, // int tilesX,
measured_poles); // double [][][] measured_poles);
}
}
if (debugLevel > -1) {
showMeasuredPoles(
"MEASURED_POLES-STRONGEST", // String title,
quadCLT_main.tp.getTilesX(), // tilesX, // int tilesX,
measured_poles_strongest); // double [][][] measured_poles);
showMeasuredPoles(
"MEASURED_POLES-FITTEST", // String title,
quadCLT_main.tp.getTilesX(), // tilesX, // int tilesX,
measured_poles_fittest); // double [][][] measured_poles);
}
pp.addMeasuredTiles(
true, // final boolean reset_data,
measured_poles_fittest, // final double [][][] measured_layers,
pole_clusters); // final ArrayList<PoleCluster> clusters
}
public double [][][] removeDisparityMismatch(
double [][][] ds_src,
double high_disp_tolerance,
double low_disp_tolerance,
double min_strength)
{
double [][][] ds = new double [ds_src.length][2][];
for (int i =0; i <ds.length; i++) {
ds[i][0] = ds_src[i][0].clone();
ds[i][1] = ds_src[i][1].clone();
for (int nTile = 0; nTile < ds[i][0].length; nTile++) {
if ( (ds_src[i][1][nTile] < min_strength) ||
(ds_src[i][0][nTile] > high_disp_tolerance) ||
(ds_src[i][0][nTile] < -low_disp_tolerance)) {
ds[i][0][nTile] = Double.NaN;
ds[i][1][nTile] = 0.0;
}
}
}
return ds;
}
public double [][][] poleAddStrongest(
double [][][] ds_src,
double [][][] ds_other)
{
int num_layers = (ds_src == null) ? ds_other.length : ds_src.length;
double [][][] ds = new double [num_layers][2][];
boolean just_clone = (ds_src == null) || (ds_other == null);
if (ds_src == null) {
ds_src = ds_other;
}
for (int i =0; i <ds.length; i++) {
ds[i][0] = ds_src[i][0].clone();
ds[i][1] = ds_src[i][1].clone();
if (!just_clone) {
for (int nTile = 0; nTile < ds[i][0].length; nTile++) {
if (ds_other[i][1][nTile] > ds[i][1][nTile]) {
ds[i][0][nTile] = ds_other[i][0][nTile];
ds[i][1][nTile] = ds_other[i][1][nTile];
}
}
}
}
return ds;
}
public double [][][] poleAddFittest(
double [][][] ds_src,
double [][][] ds_other)
{
int num_layers = (ds_src == null) ? ds_other.length : ds_src.length;
double [][][] ds = new double [num_layers][2][];
boolean just_clone = (ds_src == null) || (ds_other == null);
if (ds_src == null) {
ds_src = ds_other;
}
for (int i =0; i <ds.length; i++) {
ds[i][0] = ds_src[i][0].clone();
ds[i][1] = ds_src[i][1].clone();
if (!just_clone) {
for (int nTile = 0; nTile < ds[i][0].length; nTile++) {
if (Double.isNaN(ds[i][0][nTile]) || (Math.abs(ds_other[i][0][nTile]) < Math.abs(ds[i][0][nTile]))) {
ds[i][0][nTile] = ds_other[i][0][nTile];
ds[i][1][nTile] = ds_other[i][1][nTile];
}
}
}
}
return ds;
}
// improve DSI acquired for a single camera by use of a pair
// Run this after "CLT 3D"
......@@ -2098,7 +1303,7 @@ if (debugLevel > -100) return true; // temporarily !
return;
}
double [][] rig_disparity_strength = quadCLT_main.getGroundTruthByRig();
double [][] rig_disparity_strength = quadCLT_main.getGroundTruthByRig(); // saved pair
if (rig_disparity_strength == null) {
if (use_planes) {
......@@ -2128,16 +1333,16 @@ if (debugLevel > -100) return true; // temporarily !
CLTPass3d scan_last = quadCLT_main.tp.clt_3d_passes.get( quadCLT_main.tp.clt_3d_passes_size -1); // get last one
// TODO: combine in a single function to always call after groundTruthByRig. Or before use?
boolean [] infinity_select = scan_bg.getSelected(); // null;
boolean [] was_select = scan_last.getSelected(); // null;
boolean[] selection = null;
final int tilesX = quadCLT_main.tp.getTilesX();
final int tilesY = quadCLT_main.tp.getTilesY();
BiCamDSI biCamDSI = new BiCamDSI( tilesX, tilesY, threadsMax);
boolean [][] dbg_sel = (debugLevel > -2)? new boolean [8][]:null;// was 4
if (dbg_sel!=null) dbg_sel[0] = infinity_select;
if (dbg_sel!=null) dbg_sel[1] = was_select;
if (clt_parameters.rig.ltfar_en) {
boolean [] infinity_select = scan_bg.getSelected(); // null;
boolean [] was_select = scan_last.getSelected(); // null;
boolean[] selection = null;
final int tilesX = quadCLT_main.tp.getTilesX();
final int tilesY = quadCLT_main.tp.getTilesY();
BiCamDSI biCamDSI = new BiCamDSI( tilesX, tilesY, threadsMax);
boolean [][] dbg_sel = (debugLevel > -4)? new boolean [8][]:null;// was 4
if (dbg_sel!=null) dbg_sel[0] = infinity_select;
if (dbg_sel!=null) dbg_sel[1] = was_select;
if (clt_parameters.rig.ltfar_en) {
double strength_floor = (clt_parameters.rig.ltfar_auto_floor)? Double.NaN: (clt_parameters.rig.lt_trusted_strength*clt_parameters.rig.lt_strength_rfloor);
double ltfar_min_strength = clt_parameters.rig.ltfar_min_rstrength * clt_parameters.rig.lt_trusted_strength;
......@@ -2231,7 +1436,7 @@ if (debugLevel > -100) return true; // temporarily !
selection_lone, // boolean [] selection2,
null, // boolean [] enable,
false); // boolean invert_enable)
// restore master camera selections (poles may be remode by a filter
// restore master camera selections (poles may be removed by a filter
if (clt_parameters.rig.rf_master_infinity) {
selection = biCamDSI.combineSelections(
selection, // boolean [] selection1,
......@@ -2251,8 +1456,8 @@ if (debugLevel > -100) return true; // temporarily !
double [][] dbg_img = new double[7][selection.length];
for (int nTile = 0; nTile < selection.length;nTile++) {
dbg_img[0][nTile] = (dbg_sel[0][nTile]? 1.0:0.0) + (dbg_sel[1][nTile]?2.0:0.0);
dbg_img[1][nTile] = (dbg_sel[2][nTile]? 1.0:0.0) + (dbg_sel[3][nTile]?1.0:0.0);
dbg_img[2][nTile] = (dbg_sel[4][nTile]? 1.0:0.0) + (dbg_sel[5][nTile]?1.0:0.0);
dbg_img[1][nTile] = (dbg_sel[2][nTile]? 1.0:0.0) + (dbg_sel[3][nTile]?2.0:0.0);
dbg_img[2][nTile] = (dbg_sel[4][nTile]? 1.0:0.0) + (dbg_sel[5][nTile]?2.0:0.0);
dbg_img[3][nTile] = (dbg_sel[6][nTile]? 1.0:0.0);
dbg_img[4][nTile] = (dbg_sel[7][nTile]? 1.0:0.0);
dbg_img[5][nTile] = (selection[nTile]? 1.0:0.0);
......@@ -2280,7 +1485,7 @@ if (debugLevel > -100) return true; // temporarily !
/*
* TODO: interpolate disaprities before measuring to fill gaps?
* TODO: interpolate disparities before measuring to fill gaps?
public double [][][][][] getRigTextures(
boolean need_master,
boolean need_aux,
......@@ -2294,10 +1499,53 @@ if (debugLevel > -100) return true; // temporarily !
*/
quadCLT_main.tp.trimCLTPasses(false); // remove rig composite scan if any
// quadCLT_main.tp.rig_pre_poles_ds = f_rig_disparity_strength; // Rig disparity and strength before processing poles
// quadCLT_main.tp.rig_pre_poles_sel = selection; // Rig tile selection before processing poles
quadCLT_main.tp.rig_pre_poles_ds = rig_disparity_strength; // Rig disparity and strength before processing poles
quadCLT_main.tp.rig_pre_poles_sel = selection; // Rig tile selection before processing poles
if (debugLevel > -4) {
System.out.println("Saved quadCLT_main.tp.rig_pre_poles_ds and quadCLT_main.tp.rig_pre_poles_sel");
}
// process poles if enabled
if (clt_parameters.poles.poles_en) {
if (debugLevel > -4) {
System.out.println("Processing poles");
}
if (poleProcessor_persistent == null) {
poleProcessor_persistent = new PoleProcessor(
biCamDSI_persistent,
this, // TwoQuadCLT twoQuadCLT,
quadCLT_main.tp.getTilesX(),
quadCLT_main.tp.getTilesY());
}
PoleProcessor pp = poleProcessor_persistent;
selection = quadCLT_main.tp.rig_pre_poles_sel.clone();
double [][] poles_ds = pp.processPoles(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, //QuadCLT quadCLT_aux,
// biScan, // BiScan biScan,
quadCLT_main.tp.rig_pre_poles_ds, // double [][] src_ds, // source disparity, strength pair
selection, // boolean [] selection, // source tile selection, will be modified
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int globalDebugLevel)
quadCLT_main.tp.rig_post_poles_ds = poles_ds; // Rig disparity and strength before processing poles
quadCLT_main.tp.rig_post_poles_sel = selection; // Rig tile selection before processing poles
if (debugLevel > -4) {
System.out.println("Saved quadCLT_main.tp.rig_post_poles_ds and quadCLT_main.tp.rig_post_poles_sel");
}
f_rig_disparity_strength = poles_ds;
} else {
if (debugLevel > -4) {
System.out.println("Skipped processing poles");
}
}
quadCLT_main.tp.trimCLTPasses(false); // remove rig composite scan if any
CLTPass3d rig_scan = quadCLT_main.tp.compositeScan(
f_rig_disparity_strength[0], // final double [] disparity,
f_rig_disparity_strength[1], // final double [] strength,
......@@ -2863,7 +2111,7 @@ if (debugLevel > -100) return true; // temporarily !
{
final int num_tries_strongest_by_fittest = 5;
final int num_full_cycles = clt_parameters.rig.pf_en_trim_fg? 3 : 1; // Number of full low-texture cycles that include growing flat LT and trimmin weak FG over BG
final int num_cross_gaps_cycles = 20; // maximalnumger of adding new tiles cycles while "crossing the gaps)
final int num_cross_gaps_cycles = 20; // maximal number of adding new tiles cycles while "crossing the gaps)
final int min_cross_gaps_new = 20; // minimal number of the new added tiles
final int refine_inter = 2; // 3; // 3 - dx, 2 - disparity
final int tilesX = quadCLT_main.tp.getTilesX();
......@@ -3190,7 +2438,7 @@ if (debugLevel > -100) return true; // temporarily !
}
//FIXME: show only for last_cycle
//FIXME: show only for the last_cycle
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){
double [][] dbg_img = new double[disparity_bimap.length][];
for (int layer = 0; layer < disparity_bimap.length; layer ++) if (disparity_bimap[layer] != null){
......@@ -3270,7 +2518,7 @@ if (debugLevel > -100) return true; // temporarily !
biCamDSI_persistent = biCamDSI; // save for pole detection
if (clt_parameters.rig.ltavg_en) {
if (debugLevel > -2) {
System.out.println("groundTruthByRigPlanes(): Pprocessing low-textured areas with multi-tile correlation averaging");
System.out.println("groundTruthByRigPlanes(): Processing low-textured areas with multi-tile correlation averaging");
}
// next method adds to the list of BiScans
// double [][] ds_avg =
......@@ -4174,7 +3422,7 @@ if (debugLevel > -100) return true; // temporarily !
clt_parameters.tileX, // final int dbg_x,
clt_parameters.tileY, // final int dbg_y,
debugLevel+0); // final int debugLevel
if (debugLevel > 0) {
if (debugLevel > -4) {
biScan.showScan(quadCLT_main.image_name+"-preexpand"+biScan.list_index, ds_preexpanded);
}
......@@ -4185,8 +3433,8 @@ if (debugLevel > -100) return true; // temporarily !
}
}
if (debugLevel > 0) {
biScan.showScan(quadCLT_main.image_name+"-combo-expand"+biScan.list_index, ds_preexpanded);
if (debugLevel > -4) {// 0) {
biScan.showScan(quadCLT_main.image_name+"-combo-expand"+biScan.list_index, ds_preexpanded); // already wrong strength
}
// double [][] ds_expanded =
......@@ -4198,7 +3446,21 @@ if (debugLevel > -100) return true; // temporarily !
expanded_lt, // final boolean [] exp_sel,
weak); // final boolean [] trusted);
// TODO use fillAndSmooth() to calculate new weights (keeping disparity as it was)
if (debugLevel > -2) {
/*
double [][] avg_ds_strength = biScan.fillAndSmooth(
ds_preexpanded[0], // final double [] src_disparity,
ds_preexpanded[1], // final double [] src_strength, // if not null will be used for weighted pull
lt_select, // final boolean [] selection,
0.0, // only gaps neib_pull, // final double neib_pull, // pull to weighted average relative to pull to the original disparity value. If 0.0 - will only update former NaN-s
max_iter, // final int max_iterations,
min_change, // final double min_change,
clt_parameters.tileX, // final int dbg_x,
clt_parameters.tileY, // final int dbg_y,
debugLevel+0); // final int debugLevel
avg_ds[1] = avg_ds_strength[1];
*/
if (debugLevel > -4) { //-2) {
biScan.showScan(quadCLT_main.image_name+"-lt-expanded"+biScan.list_index, avg_ds);
}
......@@ -5997,7 +5259,7 @@ if (debugLevel > -100) return true; // temporarily !
}
private double [][] measureRig(
double [][] measureRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
int [][] tile_op, // common for both amin and aux
......
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