Commit b3afa1ab authored by Andrey Filippov's avatar Andrey Filippov

Working on fronto objects at long distances in the model

parent c2de0cdf
......@@ -276,7 +276,7 @@ public class BiCamDSI {
/**
* Filter selection by expending, then shrinking (fills small gaps) shrinking (combined with
* Filter selection by expanding, then shrinking (fills small gaps) shrinking (combined with
* previous step) and expanding again (removes small clusters)
* @param pre_expand number of steps for initial expand (odd last is - only hor/vert, even - last step includes diagonals)
* @param shrink number of shrink steps normally equals to pre_expand+post_expand
......
......@@ -20,6 +20,9 @@
** -----------------------------------------------------------------------------**
**
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.concurrent.atomic.AtomicInteger;
public class BiScan {
......@@ -155,6 +158,59 @@ public class BiScan {
return ds;
}
class DSIndex{
double disparity;
double strength;
int scan_index;
DSIndex (
double disparity,
double strength,
int scan_index)
{
this.disparity = disparity;
this.strength = strength;
this.scan_index = scan_index;
}
}
ArrayList<DSIndex> getTileDSList(
int nTile,
final boolean only_strong,
final boolean only_trusted,
final boolean only_enabled)
{
ArrayList<DSIndex> ds_list = new ArrayList<DSIndex>();
for (int indx = list_index; indx >= 0; indx--) { // include the latest measurement
BiScan scan = biCamDSI.getBiScan(indx);
if (only_enabled && scan.disabled_measurement[nTile]) { // || (scan.src_index[nTile] != indx)){ // skip all but enabled
continue;
}
if (only_strong && !scan.strong_trusted[nTile]) {
continue;
}
if (only_trusted && !scan.trusted[nTile]) {
continue;
}
if ((scan.strength_measured[nTile] > 0.0) && !Double.isNaN(scan.disparity_measured[nTile])) {
ds_list.add(new DSIndex(scan.disparity_measured[nTile],scan.strength_measured[nTile],indx));
}
}
Collections.sort(ds_list, new Comparator<DSIndex>() {
@Override
public int compare(DSIndex lhs, DSIndex rhs) {
// -1 - less than, 1 - greater than, 0 - equal, all inverted for descending disparity
return lhs.disparity > rhs.disparity ? -1 : (lhs.disparity < rhs.disparity ) ? 1 : 0;
}
});
return ds_list;
}
// trusted should be set, copied and replaced as needed
public double [][] getFilteredDisparityStrength( // FIXME
final boolean [] area_of_interest,
......@@ -425,6 +481,127 @@ public class BiScan {
return num_changes.get();
}
/**
* Prefer thin FG (like thin poles) over textured BG (at first not directional), just prefer "good enough" FG over even stronger BG
* @param str_good_enough minimal strength for the FG tiles and neighbors
* @param min_FGtoBG minimal FG to BG disparity difference
* @param disp_atolerance absolute disparity difference for qualifying neighbors (in master camera pixels)
* @param disp_rtolerance add to tolerance for each pixel of disparity
* @param min_neib minimal number of neighbors that promoted tiles should have
* @return number of promoted FG tiles
*/
public int copyStrongFGEnabled(
final double str_good_enough, // absolute strength floor for good enough
final double min_FGtoBG, // minimal disparity difference over
final double disp_atolerance, // = 0.1; // Maximal absolute disparity difference to qualifying neighbor
final double disp_rtolerance, // = 0.02; // Maximal relative (to absolute disparity) disparity difference to qualifying neighbor
final int min_neib) // minimal number of qualifying neighbors to promote FG tile
{
final TileNeibs tnImage = biCamDSI.tnImage;
final int num_tiles = biCamDSI.tnImage.getSizeX()*biCamDSI.tnImage.getSizeY();
final double [][] ds = getDisparityStrength( // used to comapre to see if re-arrangement is needed
false, // final boolean only_strong,
false, // final boolean only_trusted,
true) ; // final boolean only_enabled);
final Thread[] threads = ImageDtt.newThreadArray(biCamDSI.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final int [] new_src = new int[num_tiles];
final AtomicInteger num_changes = new AtomicInteger(0); // number of tiles modified to FG
int dbg_x = 193;
int dbg_y = 162;
int debugLevel = -1;
final int dbg_tile = (debugLevel>-2)?(dbg_x + tnImage.sizeX*dbg_y):-1;
ai.set(0);
// find definitely trusted and conditionally trusted tiles
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 (nTile == dbg_tile) {
System.out.println("copyStrongFGEnabled(): nTile="+nTile);
}
if (ds[1][nTile] < 0) { // no good d/s for this tile
continue;
}
// get list in descending disparity order
ArrayList<DSIndex> ds_list = getTileDSList(
nTile, // int nTile,
false, // final boolean only_strong,
false, // final boolean only_trusted,
true); // final boolean only_enabled)
if (ds_list.size() < 1) {
continue;
}
// find strongest tile closer than default disparity
for (int indx = 0; indx < ds_list.size(); indx++) {
DSIndex dsi = ds_list.get(indx);
if (dsi.disparity < (ds[0][nTile] + min_FGtoBG)){
break; // not sufficiently closer than default;
}
if (dsi.strength > str_good_enough){
double disp_tolerance = disp_atolerance + dsi.disparity * disp_rtolerance; // disparity tolerance
// see if it has strong enough neighbors with close disparity
int num_neib = 0;
for (int dir = 0; dir < 8; dir++) {
int nTile1 = tnImage.getNeibIndex(nTile, dir);
if (nTile1 > 0) {
ArrayList<DSIndex> ds_neib = getTileDSList(
nTile1, // int nTile,
false, // final boolean only_strong,
false, // final boolean only_trusted,
true); // final boolean only_enabled)
for (DSIndex dsi_neib: ds_neib) {
if ((dsi_neib.strength > str_good_enough) &&
(Math.abs(dsi_neib.disparity - dsi.disparity ) <= disp_tolerance)) {
num_neib++;
break;
}
}
}
}
if (num_neib > 0) {
new_src[nTile] = dsi.scan_index + 1;
num_changes.getAndIncrement();
break; // for (int indx = 0; indx < ds_list.size(); indx++)
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
if (num_changes.get() > 0) {
ai.set(0);
// find definitely trusted and conditionally trusted tiles
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 (nTile == dbg_tile) {
System.out.println("copyStrongFGEnabled() 2 : nTile="+nTile);
}
if (new_src[nTile] > 0){
int best_indx = new_src[nTile]-1;
src_index[nTile] = best_indx;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
// will need trusted* recalculated
return num_changes.get();
}
/**
* Copy data (if the current was not measured) from one of the previous scans - strongest that is not disabled. If last_priority is true
* the latest not disabled scan will be used, even if it is not the strongest
......@@ -970,6 +1147,11 @@ public class BiScan {
final int dbg_y,
final int debugLevel
) {
// int dbg_x = 193;
// int dbg_y = 162;
// int debugLevel = -1;
// final int dbg_tile = (debugLevel>-2)?(dbg_x + tnImage.sizeX*dbg_y):-1;
final TileNeibs tnImage = biCamDSI.tnImage;
final double [][] ds = getDisparityStrength( // FIXME
false, // final boolean only_strong,
......@@ -993,8 +1175,13 @@ public class BiScan {
@Override
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < num_tiles; nTile = ai.getAndIncrement()) if (discard_strong || !trusted_sw[nTile]){
if (nTile == 52681) {
System.out.println("suggestNewScan(), nTIle="+nTile+", dxy={"+dxy[0]+","+dxy[1]+"}");
}
int nTile1 = tnImage.getNeibIndex(nTile, dxy[0], dxy[1]);
if ((nTile1 >= 0) && trusted_weak[nTile1]) { // weak trusted OK, maybe even any measured
// if ((nTile1 >= 0) && trusted_weak[nTile1]) { // weak trusted OK, maybe even any measured
if ((nTile1 >= 0) && (ds[0][nTile1] > 0)) { // weak trusted OK, maybe even any measured
double new_disp = ds[0][nTile1];
if (Math.abs(new_disp - ds[0][nTile]) < new_diff) { // suggested is too close to already measured
continue; // already measured for this tile
......@@ -1331,8 +1518,8 @@ public class BiScan {
if ((max_disp <= d_lim) && ((w < max_disp_w) || (w < min_strength))) {
disableTile(nTile);
ai_trimmed.getAndIncrement();
if (debugLevel > -4) {
System.out.println("trimWeakLoneFG: removing tile "+nTile+" ("+(nTile%tnImage.sizeX)+":"+(nTile/tnImage.sizeX));
if (debugLevel > -1) {
System.out.println("trimWeakLoneFG: removing tile "+nTile+" ("+(nTile%tnImage.sizeX)+":"+(nTile/tnImage.sizeX)+")");
}
}
}
......
......@@ -2858,7 +2858,9 @@ public class EyesisCorrectionParameters {
public boolean plPreferDisparity = false;// Always start with disparity-most axis (false - lowest eigenvalue)
public double plDispNorm = 5.0; // Normalize disparities to the average if above (now only for eigenvalue comparison)
public double plFrontoTol = 0.0; // for compatibility with old //0.1; // Fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable
public double plFrontoRms = 0.05; // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
public double plFrontoOffs = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
public double plBlurBinVert = 1.2; // Blur disparity histograms for constant disparity clusters by this sigma (in bins)
public double plBlurBinHor = 0.8; // Blur disparity histograms for horizontal clusters by this sigma (in bins)
public double plMaxDiffVert = 0.4; // Maximal normalized disparity difference when initially assigning to vertical plane
......@@ -2868,7 +2870,7 @@ public class EyesisCorrectionParameters {
public int plMinPoints = 5; // Minimal number of points for plane detection
public double plTargetEigen = 0.02; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
public double plFractOutliers = 0.3; // Maximal fraction of outliers to remove
public int plMaxOutliers = 20; // Maximal number of outliers to remove
public int plMaxOutliers = 200; // Maximal number of outliers to remove
public double plMinStrength = 0.01; // Minimal total strength of a plane
public double plMaxEigen = 0.06; // Maximal eigenvalue of a plane
public double plEigenFloor = 0.005;// Add to eigenvalues of each participating plane and result to validate connections
......@@ -3522,6 +3524,9 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plPreferDisparity",this.plPreferDisparity+"");
properties.setProperty(prefix+"plDispNorm", this.plDispNorm +"");
properties.setProperty(prefix+"plFrontoTol", this.plFrontoTol +"");
properties.setProperty(prefix+"plFrontoRms", this.plFrontoRms +"");
properties.setProperty(prefix+"plFrontoOffs", this.plFrontoOffs +"");
properties.setProperty(prefix+"plBlurBinVert", this.plBlurBinVert +"");
properties.setProperty(prefix+"plBlurBinHor", this.plBlurBinHor +"");
......@@ -4165,6 +4170,9 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plPreferDisparity")!=null) this.plPreferDisparity=Boolean.parseBoolean(properties.getProperty(prefix+"plPreferDisparity"));
if (properties.getProperty(prefix+"plDispNorm")!=null) this.plDispNorm=Double.parseDouble(properties.getProperty(prefix+"plDispNorm"));
if (properties.getProperty(prefix+"plFrontoTol")!=null) this.plFrontoTol=Double.parseDouble(properties.getProperty(prefix+"plFrontoTol"));
if (properties.getProperty(prefix+"plFrontoRms")!=null) this.plFrontoRms=Double.parseDouble(properties.getProperty(prefix+"plFrontoRms"));
if (properties.getProperty(prefix+"plFrontoOffs")!=null) this.plFrontoOffs=Double.parseDouble(properties.getProperty(prefix+"plFrontoOffs"));
if (properties.getProperty(prefix+"plBlurBinVert")!=null) this.plBlurBinVert=Double.parseDouble(properties.getProperty(prefix+"plBlurBinVert"));
if (properties.getProperty(prefix+"plBlurBinHor")!=null) this.plBlurBinHor=Double.parseDouble(properties.getProperty(prefix+"plBlurBinHor"));
......@@ -4707,7 +4715,7 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Set new pole segment strength to max of horizontal correlation and this value", this.poles_min_strength, 3);
gd.addCheckbox ("Set disparity to that of the bottom of existing segment (false - use hor. disparity)",this.poles_force_disp);
gd.addNumericField("Maximal number of output meshes to generate", this.max_clusters, 0);
gd.addNumericField("Maximal number of output meshes to generate", this.max_clusters, 0);
gd.addCheckbox ("Remove all unneeded scans when generating x3d output to save memory", this.remove_scans);
gd.addCheckbox ("Generate x3d output", this.output_x3d);
gd.addCheckbox ("Generate Wavefront obj output", this.output_obj);
......@@ -4818,7 +4826,7 @@ public class EyesisCorrectionParameters {
"", "Allows to find plane when there are not enough tiles to process");
gd.addNumericField("Disparity switch between filtering modes", this.mlfp.min_tilt_disp, 4,6,
"pix","Objects that are closer (larger disparity) use tilted plane model, far objects use maximal amon neighbors disparity");
"pix","Objects that are closer (larger disparity) use tilted plane model, far objects use maximal among neighbors disparity");
gd.addNumericField("Mode transition range (between tilted and maximal disparity)", this.mlfp.transition, 4,6,
"pix","Disparity range to gradually switch between maximal and tilted modes");
gd.addNumericField("Far objects filtering mode (0 - off, 1,2 - power of disparity)", this. mlfp.far_mode, 0,3,
......@@ -4900,8 +4908,13 @@ public class EyesisCorrectionParameters {
gd.addTab ("Plane Det", "Planes detection");
gd.addMessage ("--- Planes detection ---");
gd.addCheckbox ("Always start with disparity-most axis (false - lowest eigenvalue)", this.plPreferDisparity);
gd.addNumericField("Normalize disparities to the average if above", this.plDispNorm, 6);
gd.addNumericField("Normalize disparities to the average if above", this.plDispNorm, 4,6, "pix");
gd.addNumericField("Fronto tolerance", this.plFrontoTol, 4,6,"pix",
"Fronto tolerance (pix) - treat almost fronto planes as fronto (constant disparity). If <= 0 - disable this feature");
gd.addNumericField("Fronto RMS", this.plFrontoRms, 4,6,"pix",
"Target half-thikness of the fronto planes. Similar to sqrt(plMaxEigen) for other planes");
gd.addNumericField("Fronto offset", this.plFrontoOffs, 4,6,"pix",
"Increasing weights of the near tiles by using difference between tile disparity and reduced by this value average as weight. If <= 0 - disable feature");
gd.addNumericField("Blur disparity histograms for constant disparity clusters by this sigma (in bins)", this.plBlurBinVert, 6);
gd.addNumericField("Blur disparity histograms for horizontal clusters by this sigma (in bins)", this.plBlurBinHor, 6);
gd.addNumericField("Maximal normalized disparity difference when initially assigning to vertical plane", this.plMaxDiffVert, 6);
......@@ -5556,6 +5569,9 @@ public class EyesisCorrectionParameters {
this.plPreferDisparity= gd.getNextBoolean();
this.plDispNorm= gd.getNextNumber();
this.plFrontoTol = gd.getNextNumber();
this.plFrontoRms = gd.getNextNumber();
this.plFrontoOffs = gd.getNextNumber();
this.plBlurBinVert= gd.getNextNumber();
this.plBlurBinHor= gd.getNextNumber();
......
......@@ -31,8 +31,11 @@ import java.util.concurrent.atomic.AtomicInteger;
public class LinkPlanes {
SuperTiles st;
public boolean plPreferDisparity; // = false;// Always start with disparity-most axis (false - lowest eigenvalue)
public double plDispNorm; // = 3.0; // Normalize disparities to the average if above (now only for eigenvalue comparison)
public double plMinStrength; // = 0.1; // Minimal total strength of a plane
public double plDispNorm; // = 3.0; // Normalize disparities to the average if above (now only for eigenvalue comparison)
public double plFrontoTol; // = 0.2; plFrontoTol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable
public double plFrontoRms; // = 0.05; // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
public double plFrontoOffs; // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
public double plMinStrength; // = 0.1; // Minimal total strength of a plane
public double plMaxEigen; // = 0.05; // Maximal eigenvalue of a plane
public double plEigenFloor; // = 0.01; // Add to eigenvalues of each participating plane and result to validate connections
public double plEigenStick; // = 25.0; // Consider plane to be a "stick" if second eigenvalue is below
......@@ -132,6 +135,11 @@ public class LinkPlanes {
plEigenStick = clt_parameters.plEigenStick;
plBadPlate = clt_parameters.plBadPlate;
plMinStrength = clt_parameters.plMinStrength;
plFrontoTol = clt_parameters.plFrontoTol;
plFrontoRms = clt_parameters.plFrontoRms;
plFrontoOffs = clt_parameters.plFrontoOffs;
plMaxOverlap = clt_parameters.plMaxOverlap;
plWeakWeight = clt_parameters.plWeakWeight;
......@@ -282,13 +290,14 @@ public class LinkPlanes {
String prefix,
int debugLevel)
{
double plFrontoDiff = 0.02; // FIXME- make a parameter
double plSumThick = this.plSumThick * relax;
double plWeakEigen = this.plWeakEigen * relax;
double plWeakEigen2 = this.plWeakEigen2 * relax;
merge_weak |= check_is_weak_only;
if ((plane1 == null) || (plane2 == null)) return false;
boolean dbg = debugLevel > 1;
if (debugLevel > 1){
if (debugLevel > 2){
System.out.println("planesFit() debug:");
}
TilePlanes.PlaneData merged_pd = null;
......@@ -296,6 +305,23 @@ public class LinkPlanes {
double disp1 = plane1.getZxy()[0];
double disp2 = plane2.getZxy()[0];
if (plane1.fronto && plane2.fronto) {
if (Math.abs(disp1-disp2) > plFrontoDiff) {
if (debugLevel > 0) System.out.println(prefix+" both planes are fronto and disparity difference Math.abs("+disp1+"-"+disp2+") > plFrontoDiff="+plFrontoDiff);
return false;
}
}
if (plane1.fronto && !plane2.fronto) {
if (debugLevel > 0) System.out.println(prefix+" at plane1 is fronto and plane2 is not");
return false;
}
if (plane2.fronto && !plane1.fronto) {
if (debugLevel > 0) System.out.println(prefix+" at plane2 is fronto and plane1 is not");
return false;
}
if ((disp1 <= 0) || (disp2 <= 0) || (((disp1 <= plMaxDisp) || (disp2 <= plMaxDisp)) && ((disp1/disp2 > plMaxZRatio) || (disp2/disp1 > plMaxZRatio)))){
if (debugLevel > 0) System.out.println(prefix+" planes have too high disparity ratio ("+disp1+":"+disp2+" > plMaxZRatio="+plMaxZRatio+
", at least one of them < plMaxDisp="+plMaxDisp);
......@@ -795,9 +821,9 @@ public class LinkPlanes {
costs[4]/cost,
costs[5]/cost};
if (debugLevel > 0){
if (debugLevel > 1){
System.out.println(prefix+" cost="+cost);
if (debugLevel > 1){
if (debugLevel > 2){
System.out.println(prefix+ " cost contributions: "+
((int)(100*qualities[3]))+"%, "+
((int)(100*qualities[4]))+"%, "+
......@@ -2544,7 +2570,7 @@ public class LinkPlanes {
final int dbg_Y)
{
if (debugLevel > 0) {
System.out.println("Debug debugLevel");
System.out.println("costSameTileConnections(): debugLevel="+debugLevel);
}
final int tilesX = st.tileProcessor.getTilesX();
final int tilesY = st.tileProcessor.getTilesY();
......@@ -2563,7 +2589,7 @@ public class LinkPlanes {
public void run() {
for (int nsTile0 = ai.getAndIncrement(); nsTile0 < nStiles; nsTile0 = ai.getAndIncrement()) if ( merge_candidates[nsTile0] != null) {
// int dl = ((debugLevel > 0) && (nsTile0 == debug_stile)) ? 3: ((debugLevel > 1) ? 2:0);
int dl = ((debugLevel > 1) && (nsTile0 == debug_stile)) ? 3: debugLevel;
int dl = ((debugLevel > 1) && (nsTile0 == debug_stile)) ? 3: (debugLevel - 2);
if (dl > 2){
System.out.println("costSameTileConnections(): nsTile="+nsTile0);
......@@ -2597,7 +2623,7 @@ public class LinkPlanes {
Double.NaN, // double merged_wev, // if NaN will calculate assuming the same supertile - for world
Double.NaN, // double merged_wev_eq, // if NaN will calculate assuming the same supertile - for world
prefix, // String prefix,
dl - 2); // int debugLevel)
dl); // - 2); // int debugLevel)
prefix = "costSameTileConnections() fit equal weight: nsTile0="+nsTile0+" np1="+np1+" np2="+np2;
boolean fit2 = planesFit(
planes[nsTile0][np1].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
......@@ -2609,19 +2635,19 @@ public class LinkPlanes {
Double.NaN, // double merged_wev, // if NaN will calculate assuming the same supertile - for world
Double.NaN, // double merged_wev_eq, // if NaN will calculate assuming the same supertile - for world
prefix, // String prefix,
dl - 2); // int debugLevel)
dl); // - 2); // int debugLevel)
// if (!fit1 || !fit2){
if (!fit1 && !fit2){
valid_candidates[nsTile0][np1][np2] = false;
valid_candidates[nsTile0][np2][np1] = false;
if (dl > 0){
if (dl > 2) { //0){
System.out.println("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+
(weak_fg[np1][np2]? " WEAK_FG_PAIR":"") +
" REMOVING PAIR, fit1="+fit1+" fit2="+fit2);
}
} else {
if (dl > 0){
if (dl >2) { //0){
System.out.println("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+
(weak_fg[np1][np2]? " WEAK_FG_PAIR":"") +
" KEEPING PAIR, fit1="+fit1+" fit2="+fit2);
......@@ -3863,7 +3889,7 @@ public class LinkPlanes {
dbg_tileX,
dbg_tileY);
// Verify merge candidates by evaluating overlaps. Close planes that have significant overlap on the image are mofre likely
// Verify merge candidates by evaluating overlaps. Close planes that have significant overlap on the image are more likely
// to be actually different planes, if they do not overlap it is likely to be the same one, just multiple separate parts of
// it mistakenly discriminated during initial plane generation from the tiles data.
//
......@@ -3905,7 +3931,7 @@ public class LinkPlanes {
weak_pairs, // final boolean [][] weak_fg_pairs,
1.0, // double relax,
plWeakFgRelax, // final double relax_weak_fg,
1+ debugLevel, // final int debugLevel)
2+ debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
// Calculate costs of merging planes of the same supertile and remove those that are exceed threshold
......@@ -3965,7 +3991,10 @@ public class LinkPlanes {
plTargetEigen, // final double targetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
plFractOutliers, // final double fractOutliers, // = 0.3; // Maximal fraction of outliers to remove
plMaxOutliers, // final int maxOutliers, // = 20; // Maximal number of outliers to remove
debugLevel, // final int debugLevel)
plFrontoTol, // final double fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
plFrontoRms, // final double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
plFrontoOffs, // final double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
if ( debugLevel > -1) {
......@@ -4487,6 +4516,9 @@ public class LinkPlanes {
plTargetEigen, // final double targetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
plFractOutliers, // final double fractOutliers, // = 0.3; // Maximal fraction of outliers to remove
plMaxOutliers, // final int maxOutliers, // = 20; // Maximal number of outliers to remove
plFrontoTol, // final double fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
plFrontoRms, // final double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
plFrontoOffs, // final double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
......@@ -4578,6 +4610,9 @@ public class LinkPlanes {
plTargetEigen, // final double targetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
plFractOutliers, // final double fractOutliers, // = 0.3; // Maximal fraction of outliers to remove
plMaxOutliers, // final int maxOutliers, // = 20; // Maximal number of outliers to remove
plFrontoTol, // final double fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
plFrontoRms, // final double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
plFrontoOffs, // final double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
......
......@@ -7190,6 +7190,7 @@ public class QuadCLT {
if (this.image_data == null){
return false;
}
double infinity_disparity = geometryCorrection.getDisparityFromZ(clt_parameters.infinityDistance);
X3dOutput x3dOutput = null;
WavefrontExport wfOutput = null;
if (clt_parameters.remove_scans){
......@@ -7202,7 +7203,8 @@ public class QuadCLT {
int next_pass = tp.clt_3d_passes.size(); //
tp.thirdPassSetupSurf( // prepare tile tasks for the second pass based on the previous one(s) // needs last scan
clt_parameters,
clt_parameters.bgnd_range, // double disparity_far,
//FIXME: make a special parameter?
infinity_disparity, //0.25 * clt_parameters.bgnd_range, // double disparity_far,
clt_parameters.grow_disp_max, // other_range, //double disparity_near, //
geometryCorrection,
threadsMax, // maximal number of threads to launch
......@@ -7253,9 +7255,9 @@ public class QuadCLT {
// int num_bgnd = 0;
// for (int i = 0; i < bgnd_sel.length; i++) if (bgnd_sel[i]) num_bgnd++;
// if (num_bgnd >= clt_parameters.min_bgnd_tiles) { // TODO: same for the backdrop too
// double infinity_disparity = geometryCorrection.getDisparityFromZ(clt_parameters.infinityDistance);
if (bgndScan.texture != null) { // TODO: same for the backdrop too
if (clt_parameters.infinityDistance > 0.0){ // generate background as a billboard
double infinity_disparity = geometryCorrection.getDisparityFromZ(clt_parameters.infinityDistance);
// grow selection, then grow once more and create border_tiles
// create/rstore, probably not needed
boolean [] bg_sel_backup = bgndScan.getSelected().clone();
......@@ -7434,7 +7436,8 @@ public class QuadCLT {
clt_parameters.transform_size,
clt_parameters.correct_distortions, // requires backdrop image to be corrected also
showTri, // (scanIndex < next_pass + 1) && clt_parameters.show_triangles,
clt_parameters.bgnd_range, // 0.3
// FIXME: make a separate parameter:
infinity_disparity, // 0.25 * clt_parameters.bgnd_range, // 0.3
clt_parameters.grow_disp_max, // other_range, // 2.0 'other_range - difference from the specified (*_CM)
clt_parameters.maxDispTriangle);
} catch (IOException e) {
......
......@@ -1713,6 +1713,424 @@ public class SuperTiles{
return plane_disp_strength;
}
public boolean [][][][] dispClusterizeHighest(
final double [][][][] disparity_strengths, // either normal or tilted disparity/strengths
final boolean [][][] selected, // tiles OK to be assigned [supertile][measurement layer] [tile index] or null (or null or per-measurement layer)
final boolean [][][] prohibited, // already assigned tiles [supertile][measurement layer] [tile index] or null
final boolean search_min,
final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
final double plDispNorm, // to increase weight of nearer planes
final double sigma,
final double disp_arange,
final double disp_rrange,
final double tolerance_above,
final double tolerance_below,
final int plMinPoints, // = 5; // Minimal number of points for plane detection
final String suffix,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
final int superTileSize = tileProcessor.getSuperTileSize();
final int stSize2 = 2 * superTileSize;
final int stLen2 = stSize2 * stSize2;
final int stilesX = (tilesX + superTileSize -1)/superTileSize;
final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final int nStiles = stilesX * stilesY;
final Thread[] threads = ImageDtt.newThreadArray((debugLevel > 1)? 1 :tileProcessor.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
this.planes = new TilePlanes.PlaneData[nStiles][];
final int debug_stile = (debugLevel > -1)? (dbg_Y * stilesX + dbg_X):-1;
// final boolean [][][] enabled = (selected == null) ? (new boolean [nStiles][][]) : selected;
final boolean [][][][] plane_selections = new boolean [nStiles][][][]; // [supertile] [ plane number] [measurement layer] [tile index]
class Selections2{
boolean [][] sel;
Selections2(boolean [][] sel) {
this.sel = sel;
}
boolean [][] getSel(){
return this.sel;
}
}
// final double max_diff2 = Double.isNaN(max_diff)? Double.NaN: (max_diff*max_diff);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nsTile = ai.getAndIncrement(); nsTile < nStiles; nsTile = ai.getAndIncrement()) {
if (disparity_strengths[nsTile] != null){
int dl = ((debugLevel > 0) && (nsTile == debug_stile)) ? (debugLevel + 2) : debugLevel;
if (dl > 2){
System.out.println("dispClusterizeHighest(): nsTile="+nsTile);
}
// int stileY = nsTile / stilesX;
// int stileX = nsTile % stilesX;
double[][][] disp_strength = new double[measuredLayers.getNumLayers()][][];
for (int ml = 0; ml < disp_strength.length; ml++) if ((stMeasSel & ( 1 << ml)) != 0){
disp_strength[ml] = disparity_strengths[nsTile][ml]; // will we change it - no, no need to clone
}
boolean [][] enabled = (selected == null) ? (new boolean [disp_strength.length][]) : selected[nsTile];
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null) {
if (selected != null) {
enabled[ml] = selected[nsTile][ml].clone();
}else {
enabled[ml] = new boolean [stLen2];
for (int i = 0; i < stLen2; i++) {
enabled[ml][i] = true;
}
}
if ((prohibited != null) && (prohibited[nsTile] != null) && (prohibited[nsTile][ml] != null)) {
for (int i = 0; i < stLen2; i++) {
enabled[ml][i] &= !prohibited[nsTile][ml][i];
}
}
}
ArrayList<Selections2> sel_list = new ArrayList<Selections2>();
for (int ntry = 0; ntry < 20; ntry++) {
boolean [][] new_sel = getHighestPlaneSelection(
enabled, //boolean [][] enabled, // will not be modified
disp_strength, // double [][][] disp_str,
//FIXME: use this argument
search_min, // boolean search_min,
2, // int grow,
sigma, // double sigma,
disp_arange, // double disp_arange,
disp_rrange, // double disp_rrange,
tolerance_above, // double tolerance_above,
tolerance_below, // double tolerance_below,
dl); // int debugLevel)
int num_tiles = 0;
for (int ml = 0; ml < enabled.length; ml++) if (new_sel[ml] != null) {
for (int i = 0; i < new_sel[ml].length; i++) {
if (new_sel[ml][i]) {
num_tiles++;
enabled[ml][i]=false;
}
}
}
if (num_tiles < plMinPoints) {
break;
}
sel_list.add(new Selections2(new_sel));
}
plane_selections[nsTile] = new boolean [sel_list.size()][][]; //plane_sels;
for (int np = 0; np < plane_selections[nsTile].length; np++) {
plane_selections[nsTile][np] = sel_list.get(np).getSel();
}
if (dl > 2){
System.out.println("dispClusterizeHighest(): nsTile="+nsTile);
double [][] dbg_img = new double [plane_selections[nsTile].length + 2][];
String [] dbg_titles = new String [plane_selections[nsTile].length + 2];
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
dbg_img[0] = disp_strength[ml][0];
dbg_img[dbg_img.length-1] = disp_strength[ml][1];
break;
}
dbg_titles[0] = "disparity";
dbg_titles[dbg_img.length-1] = "strength";
for (int np = 0; np < plane_selections[nsTile].length; np++) {
double plane_strength = getSelectionStrength(
true, // mod_strength, // boolean mod_strength,
plDispNorm, // double plDispNorm,
plane_selections[nsTile][np], // boolean [][] sels,
disp_strength); // double [][][] ds);
dbg_titles[1 + np] = ""+plane_strength;
dbg_img[1 + np] = new double [stLen2];
for (int i = 0; i < stLen2; i++) {
boolean has_tile = false;
for (int ml = 0; ml < plane_selections[nsTile][np].length; ml++) if (plane_selections[nsTile][np][ml] != null){
if (plane_selections[nsTile][np][ml][i]) {
dbg_img[1 + np][i] += disp_strength[ml][0][i];
has_tile = true;
}
if (!has_tile) {
dbg_img[1 + np][i] = Double.NaN;
}
}
}
}
(new showDoubleFloatArrays()).showArrays(dbg_img, stSize2, stSize2, true,
"sel-"+nsTile+"-"+suffix,dbg_titles);
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return plane_selections;
}
public boolean [][] getHighestPlaneSelection(
boolean [][] enabled_ml, // will not be modified
double [][][] disp_str,
boolean search_min,
int grow,
double sigma,
double disp_arange,
double disp_rrange,
double tolerance_above,
double tolerance_below,
int debugLevel){
final int min_en_neib = 4;
final boolean [][] plane_selection = new boolean[disp_str.length][];
final double min_weight = 1.0E-20;
final int stSize2 = 2 * tileProcessor.getSuperTileSize();
final int stLen2 = stSize2 * stSize2;
DoubleGaussianBlur gb=new DoubleGaussianBlur();
TileNeibs tileNeibs = new TileNeibs(stSize2, stSize2);
int expand = (grow + 1) & (~1);
for (int ml = 0; ml < disp_str.length; ml++) if (disp_str[ml] != null) {
double [] disparity = disp_str[ml][0].clone();
double [] strength = disp_str[ml][1].clone();
boolean [] enabled = enabled_ml[ml].clone();
for (int i = 0; i < stLen2; i++) {
if ((strength [i] > 0.0) && enabled[i]) {
if (min_en_neib > 0) {
int nn = 0;
for (int dir = 0; dir < 8; dir++) {
int i1 = tileNeibs.getNeibIndex(i, dir);
if ((i1 >=0) && enabled_ml[ml][i1]) {
nn++;
}
}
if (nn < min_en_neib) {
enabled[i] = false;
strength[i] = 0.0;
disparity[i] = 0.0;
}
}
disparity[i] *= strength[i];
} else {
strength[i] = 0.0;
disparity[i] = 0.0;
}
}
gb.blurDouble(disparity, stSize2, stSize2, sigma, sigma, 0.01);
gb.blurDouble(strength, stSize2, stSize2, sigma, sigma, 0.01);
// TODO: handle large gaps with two sigmas?
for (int i = 0; i < stLen2; i++) {
if (strength [i] > min_weight) {
disparity[i] /= strength [i];
} else {
strength [i] = 0.0;
disparity[i] = 0.0;
}
}
if (debugLevel > 2){
System.out.println("getHighestPlaneSelection() debugLevel="+debugLevel);
}
boolean [] best_sel = null;
double best_weight = 0.0;
int best_height = 0;
// int best_bottom;
int bottom = stSize2 - 1;
for (; bottom >= (best_height - 1); bottom --) {
double line_max_max = 0.0, line_min_max= 0.0;
int [] tops = new int [stSize2];
int [][] line_se = new int [stSize2][2];
int top;
double disp_range = disp_arange;
for (top = bottom; top >= 0; top--) {
// find argmax for the top line;
tops[top] = -1; //top * stSize2;
for (int ix = 0; ix < stSize2; ix++) {
int indx = top * stSize2 + ix;
if (search_min) {
if ((strength[indx] > 0.0) && ((tops[top] < 0) || (disparity[indx] < disparity[tops[top]]))){
tops[top] = indx;
}
} else {
if ((strength[indx] > 0.0) && ((tops[top] < 0) || (disparity[indx] > disparity[tops[top]]))){
tops[top] = indx;
}
}
}
if (tops[top] > 0) {
if (line_max_max == 0.0) {
line_max_max = disparity[tops[top]]; // for search_min it will be line_max_min
line_min_max = disparity[tops[top]]; // for search_min it will be line_min_min
disp_range = disp_arange + 0.5 *(line_max_max + line_min_max) * disp_rrange;
} else {
if (disparity[tops[top]] > line_max_max) {
if (disparity[tops[top]] > (line_min_max + disp_range)) {
break; // difference more than allowed range
}
line_max_max = disparity[tops[top]];
disp_range = disp_arange + 0.5 *(line_max_max + line_min_max) * disp_rrange;
} else if (disparity[tops[top]] < line_min_max) {
if (disparity[tops[top]] < (line_max_max - disp_range)) {
break; // difference more than allowed range
}
line_min_max = disparity[tops[top]];
disp_range = disp_arange + 0.5 *(line_max_max + line_min_max) * disp_rrange;
}
}
} else { // no valid cells in a line (too far from enabled)
break;
}
}
if ((bottom - top) < (best_height - 2 - expand)) { //
continue; // no sense even to try
}
disp_range = disp_arange + 0.5 *(line_max_max + line_min_max) * disp_rrange;
double min_disp = line_max_max - disp_range; // used when looking for maximums
double max_disp = line_min_max + disp_range; // used when looking for minimums
// for each line set start and end, verify lines overlap
int line = bottom;
for (; line > top; line --) {
// do not check first in the row
for (line_se[line][0] = tops[line] ; line_se[line][0] > stSize2 * line; line_se[line][0]--) {
if (search_min) {
if ((strength[line_se[line][0]] > 0.0) && (disparity[line_se[line][0]] > max_disp)) {
//line_se[line][0]++; allow one extra
break;
}
} else {
if ((strength[line_se[line][0]] > 0.0) && (disparity[line_se[line][0]] < min_disp)) {
//line_se[line][0]++; allow one extra
break;
}
}
}
// do not check last in the row
for (line_se[line][1] = tops[line] ; line_se[line][1] < (stSize2 * (line + 1) -1); line_se[line][1]++) {
if (search_min) {
if ((strength[line_se[line][1]] > 0.0) && (disparity[line_se[line][1]] > max_disp)) {
//line_se[line][1]--;
break;
}
} else {
if ((strength[line_se[line][1]] > 0.0) && (disparity[line_se[line][1]] < min_disp)) {
//line_se[line][1]--;
break;
}
}
}
// verify the lines overlap with previous
if ((line < bottom) && (
(line_se[line][0] >= (line_se[line + 1][1] - stSize2)) ||
(line_se[line][1] <= (line_se[line + 1][0] - stSize2)))) {
break;
}
}
// now line - first invalid line
// calculate actual selection and weight
// duplicate first and last line to mitigate Gaussian blur - there may be some FG tiles cut off
int bottom_ext = bottom;
if (bottom_ext < (stSize2 - 1)) {
bottom_ext++;
line_se[bottom_ext][0] = line_se[bottom][0] + stSize2;
line_se[bottom_ext][1] = line_se[bottom][1] + stSize2;
}
if ((line >= 0) && (line < (stSize2 - 1))) {
line_se[line][0] = line_se[line + 1][0] - stSize2 ;
line_se[line][1] = line_se[line + 1][1] - stSize2 ;
line--;
}
if ((bottom_ext - line) < (best_height - expand)) {
continue; // no sense even to try
}
boolean [] this_sel = new boolean [stLen2];
double sw = 0.0;
double min_tile_disp = search_min ? (line_min_max - tolerance_below): (min_disp - tolerance_below);
double max_tile_disp = search_min ? (max_disp + tolerance_above) : (line_max_max + tolerance_above);
int first = -1, last = -1;
for (int i = bottom_ext; i > line; i--) {
for (int j = line_se[i][0]; j <= line_se[i][1]; j++) {
if ( enabled[j] &&
(disp_str[ml][1][j] > 0.0) &&
(disp_str[ml][0][j] >= min_tile_disp) &&
(disp_str[ml][0][j] <= max_tile_disp)) {
sw += disp_str[ml][1][j];
this_sel[j] = true;
if (last < 0) last = i;
first = i;
}
}
}
int sel_height = last - first + 1;
if (sel_height < (best_height - expand)) {
continue;
}
if (expand > 0) {
boolean [] prohibit = new boolean [enabled.length];
for (int i = 0; i < prohibit.length; i++) {
prohibit[i] = !enabled[i];
}
boolean [] exp_sel = this_sel.clone();
tileNeibs.growSelection(
grow,
exp_sel,
prohibit);
int i0 = -1, i1 = -1;
for (int i = 0; i < stLen2; i++) if (exp_sel[i]){
if (!this_sel[i]) {
if ((disp_str[ml][1][i] > 0.0) &&
(disp_str[ml][0][i] >= min_tile_disp) &&
(disp_str[ml][0][i] <= max_tile_disp)) {
this_sel[i] = true;
}
}
if (this_sel[i]) {
sw += disp_str[ml][1][i];
if (i0 < 0) i0 = i;
i1 = i;
}
}
first = i0 / stSize2;
last = i1 / stSize2;
sel_height = last - first + 1;
if (sel_height < (best_height - expand)) {
continue;
}
}
if ((sel_height > best_height) ||
(sw > best_weight)) {
best_sel = this_sel;
best_weight = sw;
best_height = sel_height;
}
} // bottom
plane_selection[ml] = best_sel;
// add debug image here
if ((debugLevel > 2) && (best_sel != null)) {
double [] disp_sel = disp_str[ml][0].clone();
for (int i = 0; i < plane_selection[ml].length; i++) {
if (!plane_selection[ml][i]) {
disp_sel[i] = Double.NaN;
}
}
String [] dbg_titles = {"disp_blur","disp_sel","disp","str_blur","str"};
double [][] dbg_img =
{ disparity,
disp_sel,
disp_str[ml][0],
strength,
disp_str[ml][1]};
(new showDoubleFloatArrays()).showArrays(dbg_img, stSize2, stSize2, true, "disp_blured",dbg_titles);
System.out.println("getHighestPlaneSelection() done");
}
} // ml
return plane_selection;
}
// use histogram data (min/max/strength) assign tiles to clusters
// returns [supertile] [ plane number] [measurement layer] [tile index]
public boolean [][][][] dispClusterize(
......@@ -1864,10 +2282,7 @@ public class SuperTiles{
System.out.println();
}
}
}
} //for (int ml = 0; ml < num_ml; ml++) if (tile_en[ml] != null) {
// recalculate average disparities for each plane and show number of tiles in each in debug mode
for (int np = 0; np < num_p; np++) {
double sd = 0.0, sw = 0.0;
......@@ -1917,7 +2332,7 @@ public class SuperTiles{
int remove_indx = -1;
for (int i = 1; i < num_p; i++) if (num_sel[i] < num_sel[windx]) windx = i;
if (num_sel[windx] < plMinPoints) {
if ((debugLevel > 2) || (dl > 0)){
if ((debugLevel > 2) || (dl > 2)){
System.out.println ("dispClusterize(): stileX = "+stileX+" stileY="+stileY+
": removing plane "+windx+" with "+num_sel[windx]+" tiles ( <"+plMinPoints+")");
}
......@@ -1941,7 +2356,7 @@ public class SuperTiles{
}
}
if (windx >=0 ) {
if ((debugLevel > 2) || (dl > 0)) {
if ((debugLevel > 2) || (dl > 2)) {
System.out.println ("dispClusterize(): stileX = "+stileX+" stileY="+stileY+
": merging plane "+windx+" with " + (windx + 1)+": "+
num_sel[windx] + " and "+num_sel[windx+1]+" tiles, "+
......@@ -1982,7 +2397,7 @@ public class SuperTiles{
}
}
}
}
} // for (int iter = 0; iter < 2; iter ++){
if (dl > 3) {
String [] dbg_titles = showSupertileSeparationTitles( disp_strength, plane_sels);
......@@ -2002,6 +2417,56 @@ public class SuperTiles{
return plane_selections;
}
private double getSelectionStrength(
boolean mod_strength,
double plDispNorm,
boolean [][] sels,
double [][][] ds)
{
int num_layers = ds.length;
int superTileSize = tileProcessor.getSuperTileSize();
if (sels == null) return 0.0;
double sw = 0.0;
int num_tiles = 0;
if (mod_strength) {
TileNeibs tileNeibs = new TileNeibs(2 * superTileSize, 2 * superTileSize);
for (int ml = 0; ml < num_layers; ml++) if (sels[ml] != null) {
for (int i = 0; i < sels[ml].length; i++) {
if (sels[ml][i]) {
int nn = 0;
for (int dir = 0; dir < 8; dir++) {
int i1 = tileNeibs.getNeibIndex(i, dir);
if ((i1 >=0) && sels[ml][i1]) {
nn++;
}
}
double w = ds[ml][1][i];
double d = ds[ml][0][i];
if ((plDispNorm > 0.0) && (d > 0.0) && (d < plDispNorm)) {
w *= d / plDispNorm;
}
sw += w * nn;
}
}
}
// increasing weight of strong compact clusters - see if it improves results
if (num_tiles > 0) {
sw /= Math.sqrt(num_tiles);
}
} else { // old way
for (int ml = 0; ml < num_layers; ml++) if (sels[ml] != null) {
for (int i = 0; i < sels[ml].length; i++) {
if (sels[ml][i]) {
sw += ds[ml][1][i];
}
}
}
}
return sw;
}
/**
* Use both horizontal and const disparity tiles to create tile clusters
* Add max_diff (maximal disparity difference while extracting initial tile selection) and max_tries (2..3) parameters
......@@ -2059,10 +2524,24 @@ public class SuperTiles{
final double highMix, //stHighMix = 0.4; // Consider merging initial planes if jumps between ratio above
final double [] world_hor, // horizontal plane normal (default [0.0, 1.0, 0.0])
final boolean show_histograms,
final boolean [][] hor_planes, // returns plane types (hor/vert)
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final int used_companions = 5; // cell that has this many new used companions is considered used (borders and already use3d are considered used too)
final int used_true_companions = 1; // there should be at least this many new selected tiles among neighbors.,
final double clust_sigma = 0.7;
final double disp_arange = 0.07;
final double disp_rrange = 0.01;
final double tolerance_above_near = 100.0; // 0.07; any?
final double tolerance_below_near = -0.01;
final double tolerance_above_far = 0.07;
final double tolerance_below_far = 0.1; // 100.0; // any farther
final int hor_vert_overlap = 2;
final boolean clusterize_by_highest = true;
final boolean mod_strength = true; // FIXME: make a parameter. when set, multiply each tile strength by the number of selected neighbors
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
final int superTileSize = tileProcessor.getSuperTileSize();
......@@ -2140,7 +2619,8 @@ public class SuperTiles{
String [] dbg_hist_titles = {"all","hor","mm_vert","mm_hor"};
double [][] dbg_hist = new double [dbg_hist_titles.length][];
final boolean [][][] used = new boolean [nStiles][num_layers][]; // num_tiles
final boolean [][][] used_hor = new boolean [nStiles][num_layers][]; // num_tiles
final boolean [][][] used_vert = (hor_vert_overlap == 0) ? used_hor : (new boolean [nStiles][num_layers][]);
final boolean [][][][] planes_selections = new boolean [nStiles][][][]; // num_tiles
for (int pass = 0; pass < max_tries; pass ++) {
// final int fpass = pass;
......@@ -2174,43 +2654,80 @@ public class SuperTiles{
if (debugLevel > 0){
System.out.println("initialDiscriminateTiles(): before new_planes_hor, pass =" + (pass + 1) + " ( of "+max_tries+" )");
}
final boolean [][][][] new_planes_hor = dispClusterize(
hor_disp_strength, // final double [][][][] disparity_strengths, // either normal or tilted disparity/strengths
mmm_hor, // final double [][][] hist_max_min_max, // histogram data: per tile array of odd number of disparity/strengths pairs, starting with first maximum
null, // final boolean [][][] selected, // tiles OK to be assigned [supertile][measurement layer] [tile index] or null (or null or per-measurement layer)
used, // final boolean [][][] prohibited, // already assigned tiles [supertile][measurement layer] [tile index] or null
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
((pass < (max_tries - 1)) ? max_diff_hor : Double.NaN), // final double max_diff, // maximal disparity difference (to assign to a cluster (of Double.NaN)
plMinPoints, // final int plMinPoints, // = 5; // Minimal number of points for plane detection
smallDiff, // final double smallDiff, // = 0.4; // Consider merging initial planes if disparity difference below
highMix, // final double highMix, //stHighMix = 0.4; // Consider merging initial planes if jumps between ratio above
true, // final boolean norm_max_diff, // scale max_diff for large (> dispNorm) average disparities
true, // final boolean norm_small_diff, // scale max_diff for large (> dispNorm) average disparities
plDispNorm, // final double dispNorm, // TODO: make a separate variable?
debugLevel, // 1, // debugLevel,
dbg_X,
dbg_Y);
// if (clusterize_by_highest) {
final boolean [][][][] new_planes_hor = clusterize_by_highest ?
dispClusterizeHighest(
hor_disp_strength, // final double [][][][] disparity_strengths, // either normal or tilted disparity/strengths
null, // final boolean [][][] selected, // tiles OK to be assigned [supertile][measurement layer] [tile index] or null (or null or per-measurement layer)
used_hor, // final boolean [][][] prohibited, // already assigned tiles [supertile][measurement layer] [tile index] or null
true, // final boolean search_min,
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plDispNorm, // final double plDispNorm, // to increase weight of nearer planes
clust_sigma, // final double sigma,
0.5 * disp_arange, // final double disp_arange,
0.5 * disp_rrange, // final double disp_rrange,
tolerance_above_far,// final double tolerance_above,
tolerance_below_far,// final double tolerance_below,
plMinPoints, // final int plMinPoints, // = 5; // Minimal number of points for plane detection
"hor", // final String suffix,
debugLevel + 0, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y): // final int dbg_Y);
dispClusterize(
hor_disp_strength, // final double [][][][] disparity_strengths, // either normal or tilted disparity/strengths
mmm_hor, // final double [][][] hist_max_min_max, // histogram data: per tile array of odd number of disparity/strengths pairs, starting with first maximum
null, // final boolean [][][] selected, // tiles OK to be assigned [supertile][measurement layer] [tile index] or null (or null or per-measurement layer)
used_hor, // final boolean [][][] prohibited, // already assigned tiles [supertile][measurement layer] [tile index] or null
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
((pass < (max_tries - 1)) ? max_diff_hor : Double.NaN), // final double max_diff, // maximal disparity difference (to assign to a cluster (of Double.NaN)
plMinPoints, // final int plMinPoints, // = 5; // Minimal number of points for plane detection
smallDiff, // final double smallDiff, // = 0.4; // Consider merging initial planes if disparity difference below
highMix, // final double highMix, //stHighMix = 0.4; // Consider merging initial planes if jumps between ratio above
true, // final boolean norm_max_diff, // scale max_diff for large (> dispNorm) average disparities
true, // final boolean norm_small_diff, // scale max_diff for large (> dispNorm) average disparities
plDispNorm, // final double dispNorm, // TODO: make a separate variable?
debugLevel, // 1, // debugLevel,
dbg_X,
dbg_Y);
if (debugLevel > 0){
System.out.println("initialDiscriminateTiles(): before new_planes_vert, pass =" + (pass + 1) + " ( of "+max_tries+" )");
}
final boolean [][][][] new_planes_vert = dispClusterize(
vert_disp_strength, // final double [][][][] disparity_strengths, // either normal or tilted disparity/strengths
mmm_vert, // final double [][][] hist_max_min_max, // histogram data: per tile array of odd number of disparity/strengths pairs, starting with first maximum
null, // final boolean [][][] selected, // tiles OK to be assigned [supertile][measurement layer] [tile index] or null (or null or per-measurement layer)
used, // final boolean [][][] prohibited, // already assigned tiles [supertile][measurement layer] [tile index] or null
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
((pass < (max_tries - 1)) ? max_diff_vert : Double.NaN), // final double max_diff, // maximal disparity difference (to assign to a cluster (of Double.NaN)
plMinPoints, // final int plMinPoints, // = 5; // Minimal number of points for plane detection
smallDiff, // final double smallDiff, // = 0.4; // Consider merging initial planes if disparity difference below
highMix, // final double highMix, //stHighMix = 0.4; // Consider merging initial planes if jumps between ratio above
true, // final boolean norm_max_diff, // scale max_diff for large (> dispNorm) average disparities
true, // final boolean norm_small_diff, // scale max_diff for large (> dispNorm) average disparities
plDispNorm, // final double dispNorm, // TODO: make a separate variable?
debugLevel, // 2, // debugLevel,
dbg_X,
dbg_Y);
final boolean [][][][] new_planes_vert = clusterize_by_highest ?
dispClusterizeHighest(
vert_disp_strength, // final double [][][][] disparity_strengths, // either normal or tilted disparity/strengths
null, // final boolean [][][] selected, // tiles OK to be assigned [supertile][measurement layer] [tile index] or null (or null or per-measurement layer)
used_vert, // final boolean [][][] prohibited, // already assigned tiles [supertile][measurement layer] [tile index] or null
false, // final boolean search_min,
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plDispNorm, // final double plDispNorm, // to increase weight of nearer planes
clust_sigma, // final double sigma,
disp_arange, // final double disp_arange,
disp_rrange, // final double disp_rrange,
tolerance_above_near, // final double tolerance_above,
tolerance_below_near, // final double tolerance_below,
plMinPoints, // final int plMinPoints, // = 5; // Minimal number of points for plane detection
"vert", // final String suffix,
debugLevel + 0, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y): // final int dbg_Y)
dispClusterize(
vert_disp_strength, // final double [][][][] disparity_strengths, // either normal or tilted disparity/strengths
mmm_vert, // final double [][][] hist_max_min_max, // histogram data: per tile array of odd number of disparity/strengths pairs, starting with first maximum
null, // final boolean [][][] selected, // tiles OK to be assigned [supertile][measurement layer] [tile index] or null (or null or per-measurement layer)
used_vert, // final boolean [][][] prohibited, // already assigned tiles [supertile][measurement layer] [tile index] or null
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
((pass < (max_tries - 1)) ? max_diff_vert : Double.NaN), // final double max_diff, // maximal disparity difference (to assign to a cluster (of Double.NaN)
plMinPoints, // final int plMinPoints, // = 5; // Minimal number of points for plane detection
smallDiff, // final double smallDiff, // = 0.4; // Consider merging initial planes if disparity difference below
highMix, // final double highMix, //stHighMix = 0.4; // Consider merging initial planes if jumps between ratio above
true, // final boolean norm_max_diff, // scale max_diff for large (> dispNorm) average disparities
true, // final boolean norm_small_diff, // scale max_diff for large (> dispNorm) average disparities
plDispNorm, // final double dispNorm, // TODO: make a separate variable?
debugLevel, // 2, // debugLevel,
dbg_X,
dbg_Y);
// compare which vert or hor provide stronger clusters, add them to selections, recalculate "used"
ai.set(0);
......@@ -2218,8 +2735,9 @@ public class SuperTiles{
threads[ithread] = new Thread() {
@Override
public void run() {
TileNeibs tnStile = new TileNeibs(2 * superTileSize, 2* superTileSize);
for (int nsTile = ai.getAndIncrement(); nsTile < nStiles; nsTile = ai.getAndIncrement()) {
int dl = ((debugLevel > 0) && (nsTile == debug_stile)) ? 3: debugLevel;
int dl = ((debugLevel > 0) && (nsTile == debug_stile)) ? (debugLevel + 2) : debugLevel;
if (dl > 2){
System.out.println("initialDiscriminateTiles() selecting: nsTile="+nsTile);
}
......@@ -2240,18 +2758,17 @@ public class SuperTiles{
if (sels_all[pType] == null) sels_all[pType] = new boolean[0][][];
// calculate strength of each selection;
for (int np = 0; np < sels_all[pType].length; np ++) {
double sw = 0.0;
for (int ml = 0; ml < num_layers; ml++) if ((sels_all[pType][np] != null) && (sels_all[pType][np][ml] != null)){
for (int i = 0; i < num_tiles; i++) {
if (sels_all[pType][np][ml][i]) {
sw += ds[pType][ml][1][i];
}
}
}
double sw = getSelectionStrength(
mod_strength, // boolean mod_strength,
plDispNorm, // double plDispNorm,
sels_all[pType][np], // boolean [][] sels,
ds[pType]); // double [][][] ds);
selStrengthList.add(new SelStrength(pType, np, sw));
}
}
if (dl > 1){
if (dl > 2){
System.out.println("initialDiscriminateTiles() got list of clusters for "+nsTile);
for (int i = 0; i < selStrengthList.size(); i++){
System.out.println(i+": type = "+selStrengthList.get(i).type+
......@@ -2288,23 +2805,80 @@ public class SuperTiles{
System.out.println("initialDiscriminateTiles() num_old_planes= "+num_old_planes);
}
boolean [][][] new_planes_selections = new boolean [num_old_planes + num_planes][][];
boolean [] new_plane_types = new boolean [num_old_planes + num_planes];
int np = 0;
for (; np < num_old_planes; np++){
new_planes_selections[np] = planes_selections[nsTile][np];
new_plane_types[np] = hor_planes[nsTile][np];
}
for (int nnp = 0; nnp < num_planes; nnp++) { // SelStrength ss:selStrengthList){
SelStrength ss = selStrengthList.get(nnp);
new_planes_selections[np++] = sels_all[ss.type][ss.indx];
new_plane_types[np] = ss.type != 0; // 0 - vert, 1 - hor;
new_planes_selections[np] = sels_all[ss.type][ss.indx];
for (int ml = 0; ml < num_layers; ml++) if (sels_all[ss.type][ss.indx][ml] != null){
if (used[nsTile][ml] == null){
used[nsTile][ml] = new boolean[num_tiles];
if (used_hor[nsTile][ml] == null){
used_hor[nsTile][ml] = new boolean[num_tiles];
}
// used_vert may be the same array as used_hor
if (used_vert[nsTile][ml] == null){
used_vert[nsTile][ml] = new boolean[num_tiles];
}
// Filling small gaps in new selections before marking them as "used"
boolean [] used_before = (ss.type == 0) ? used_vert[nsTile][ml] : used_hor[nsTile][ml];
boolean [] this_used = sels_all[ss.type][ss.indx][ml].clone();
boolean [] this_used_expanded = this_used.clone();
tnStile.growSelection(
2,
this_used_expanded,
null);
for (int i = 0; i < num_tiles; i++) if (this_used_expanded[i] && !this_used[i]) {
int n_new_used = 0, n_blocked = 0;
for (int dir = 0; dir < 8; dir++) {
int i1 = tnStile.getNeibIndex(i, dir);
if (i1 < 0) {
n_blocked++;
} else if (sels_all[ss.type][ss.indx][ml][i1]) { // this_used is modified
n_new_used++;
} else if (used_before[i1]) {
n_blocked++;
}
}
if (((n_new_used + n_blocked) >= used_companions) && (n_new_used >= used_true_companions)) {
this_used[i] = true;
}
}
// first apply to the same direction (or both if it is the same array)
if (ss.type == 0) {
for (int i = 0; i < num_tiles; i++){
used_vert[nsTile][ml][i] |= this_used[i]; // sels_all[ss.type][ss.indx][ml][i];
}
} else {
for (int i = 0; i < num_tiles; i++){
used_hor[nsTile][ml][i] |= this_used[i]; // sels_all[ss.type][ss.indx][ml][i];
}
}
for (int i = 0; i < num_tiles; i++){
used[nsTile][ml][i] |= sels_all[ss.type][ss.indx][ml][i];
if (hor_vert_overlap > 0) { // shrink selection and apply to the other direction
// boolean [] newsel = sels_all[ss.type][ss.indx][ml].clone();
tnStile.shrinkSelection(
hor_vert_overlap,
this_used,
null);
if (ss.type != 0) {
for (int i = 0; i < num_tiles; i++){
used_vert[nsTile][ml][i] |= this_used[i];
}
} else {
for (int i = 0; i < num_tiles; i++){
used_hor[nsTile][ml][i] |= this_used[i];
}
}
}
}
np++;
}
planes_selections[nsTile] = new_planes_selections;
hor_planes[nsTile] = new_plane_types;
if (dl > 2){
System.out.println("initialDiscriminateTiles() new_planes_selections.length= "+new_planes_selections.length);
}
......@@ -2549,6 +3123,12 @@ public class SuperTiles{
final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
final MeasuredLayersFilterParameters mlfp,
final double fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
//FIXME: use following 2 parameters
final double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
final double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
// now for regenerated planes - just null as it is not known if it is hor or vert
final boolean [][] hor_planes, // plane types (hor/vert)
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -2598,6 +3178,7 @@ public class SuperTiles{
ArrayList<TilePlanes.PlaneData> st_planes = pd0.createTilePlanesFromSelections(
"" + nsTile, // String suffix,
plane_selections[nsTile], // boolean [][][] plane_selections, // = new boolean [nStiles][][][]; // num_tiles
((hor_planes == null)? null:hor_planes[nsTile]), // boolean [] hor_planes,
disp_strength[nsTile], // double [][][] disp_strength,
plDispNorm, // double dispNorm, // Normalize disparities to the average if above
plMinPoints, // int min_tiles,
......@@ -2607,19 +3188,27 @@ public class SuperTiles{
correct_distortions, // boolean correct_distortions,
smplMode, // boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
mlfp,
dl); // int debugLevel);
fronto_tol, // double fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
fronto_rms, // double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes. May be tighter
fronto_offs, // double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
dl); // int debugLevel);
if ((st_planes != null) && (!st_planes.isEmpty())){
if (dl > 1){
if (dl > 2){
System.out.println("======= createPlanesFromSelections(): nsTile="+nsTile+" detecting bridges ==========");
}
boolean [][] hs = new boolean [1][];
boolean [][][] split_sels = pd0.filterBridges(
st_planes, // ArrayList<PlaneData> tilePlanes,
hs, // ((hor_planes == null)? null:hor_planes[nsTile]), // boolean [] hor_planes,
3, // int max_grow, // make configurable?
3, // int max_grow_far,
dl); // int debugLevel)
if (split_sels !=null){
if (dl > 1){
if (hor_planes != null) {
hor_planes[nsTile] = hs[0];
}
if (dl > 2){
System.out.println("======= createPlanesFromSelections(): nsTile="+nsTile+" removing bridges ==========");
}
if (dl > 2) {
......@@ -2634,6 +3223,9 @@ public class SuperTiles{
st_planes = pd0.createTilePlanesFromSelections(
"" + nsTile+" bridges ", // String suffix,
split_sels, // boolean [][][] plane_selections, // = new boolean [nStiles][][][]; // num_tiles
// FIXME: replace null (from what type it was before detecting bridges)
((hor_planes == null)? null:hor_planes[nsTile]), // boolean [] hor_planes,
// null, // boolean [] hor_planes,
disp_strength[nsTile], // double [][][] disp_strength,
plDispNorm, // double dispNorm, // Normalize disparities to the average if above
plMinPoints, // int min_tiles,
......@@ -2643,7 +3235,10 @@ public class SuperTiles{
correct_distortions, // boolean correct_distortions,
smplMode, // boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
mlfp,
dl - 1); // int debugLevel);
fronto_tol, // double fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
fronto_rms, // double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes. May be tighter
fronto_offs, // double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
dl - 1); // int debugLevel);
}
}
......@@ -2661,10 +3256,10 @@ public class SuperTiles{
if (LOWEST_PLANE(2) > 0) st_planes.add(0, st_planes.get(0)); // insert dummy at pos 0;
result_planes[nsTile] = st_planes.toArray(new TilePlanes.PlaneData[0] );
if (LOWEST_PLANE(2) > 0) result_planes[nsTile][0] = null; // remove dummy
if (dl >1){
if (dl > 2){
System.out.println("createPlanesFromSelections(): nsTile="+nsTile);
}
if (dl > 2) {
if (dl > 3) { // 2) {
String [] dbg_titles = showSupertileSeparationTitles( disp_strength[nsTile], plane_selections[nsTile], result_planes[nsTile]);
double [][] dbg_img = showSupertileSeparation(false, disp_strength[nsTile], plane_selections[nsTile], result_planes[nsTile]);
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays();
......@@ -2715,6 +3310,10 @@ public class SuperTiles{
final double plFractOutliers, // = 0.3; // Maximal fraction of outliers to remove
final int plMaxOutliers, // = 20; // Maximal number of outliers to remove
final boolean plPreferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
final double plFrontoTol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable
final double plFrontoRms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
final double plFrontoOffs, // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
final GeometryCorrection geometryCorrection,
final boolean correct_distortions,
......@@ -2740,12 +3339,17 @@ public class SuperTiles{
final int dbg_X,
final int dbg_Y)
{
final boolean debug_initial_discriminate = true; // false; // true;
// use both horizontal and const disparity tiles to create tile clusters
// Add max_diff (maximal disparity difference while extracting initial tile selection) and max_tries (2..3) parameters
// Add separate method to create + remove outliers from all planes (2 different ones)?
// TODO later re-assign pixels according to existing plane parameters
// Sort plane data by center (plane or supertile) disparity
final int superTileSize = tileProcessor.getSuperTileSize();
final int nStiles = ((tileProcessor.getTilesX() + superTileSize -1)/superTileSize) * ((tileProcessor.getTilesY() + superTileSize -1)/superTileSize);
boolean [][] hor_planes = new boolean [nStiles][];
boolean [][][][] plane_selections = initialDiscriminateTiles(
growSelection, // final int growSelection, // grow initial selection before processing
......@@ -2767,7 +3371,9 @@ public class SuperTiles{
highMix, //final double highMix, // stHighMix = 0.4; // Consider merging initial planes if jumps between ratio above
world_hor, // final double [] world_hor, // horizontal plane normal (default [0.0, 1.0, 0.0])
show_histograms, // final boolean show_histograms,
debugLevel+0, // final int debugLevel,
hor_planes, // final boolean [][] hor_planes,
debugLevel+(debug_initial_discriminate? 2:0), // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y)
......@@ -2804,7 +3410,11 @@ public class SuperTiles{
smplMode, // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
mlfp,
debugLevel + 0, // 1, // + 2, // 1, // final int debugLevel,
plFrontoTol, // final double plFrontoTol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable
plFrontoRms, // final double plFrontoRms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
plFrontoOffs, // final double plFrontoOffs, // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
hor_planes, // final boolean [][] hor_planes, // returns plane types (hor/vert)
debugLevel + 1, // 0, // 1, // + 2, // 1, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y)
this.planes = new_planes; // save as "measured" (as opposed to "smoothed" by neighbors) planes
......@@ -2859,7 +3469,10 @@ public class SuperTiles{
final double plTargetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
final double plFractOutliers, // = 0.3; // Maximal fraction of outliers to remove
final int plMaxOutliers, // = 20; // Maximal number of outliers to remove
final boolean plPreferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
final boolean plPreferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
final double plFrontoTol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable
final double plFrontoRms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
final double plFrontoOffs, // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
final GeometryCorrection geometryCorrection,
final boolean correct_distortions,
......@@ -2960,6 +3573,10 @@ public class SuperTiles{
smplMode, // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
mlfp,
plFrontoTol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable
plFrontoRms, // final double plFrontoRms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
plFrontoOffs, // final double plFrontoOffs, // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0
null, // final boolean [][] hor_planes, // plane types (hor/vert)
debugLevel, // + 2, // 1, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y)
......@@ -5723,6 +6340,19 @@ public class SuperTiles{
}
}
}
//superTileSize
// mark fronto tiles with NaN - center 3x3 tiles
//superTileSize
if (planes[nsTile][np].fronto) {
plane[centerIndex + 0] = Double.NaN;
plane[centerIndex + superTileSize] = Double.NaN;
plane[centerIndex - superTileSize] = Double.NaN;
}
if (planes[nsTile][np].horizontal) {
plane[centerIndex + 0] = Double.NaN;
plane[centerIndex + 1] = Double.NaN;
plane[centerIndex - 1] = Double.NaN;
}
for (int y = 0; y < superTileSize; y++) {
if (data.length < (ns+1)){
System.out.println("BUG in getShowPlanes()!, ns = "+ns+", data.length="+data.length);
......@@ -5733,6 +6363,7 @@ public class SuperTiles{
ns ++;
}
}
}
}
// fill same (nearest) plane or NaN if none was available
......@@ -6199,7 +6830,6 @@ public class SuperTiles{
public int applyMergePlanes(
final TilePlanes.PlaneData[][] planes,
final int [][][] merge_groups,
// parameters to generate ellipsoids
final double disp_far, // minimal disparity to select (or NaN)
final double disp_near, // maximal disparity to select (or NaN)
......@@ -6208,8 +6838,12 @@ public class SuperTiles{
final int min_tiles,
// parameters to reduce outliers
final double targetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
final double fractOutliers, // = 0.3; // Maximal fraction of outliers to remove
final double inFractOutliers, // = 0.3; // Maximal fraction of outliers to remove
final int maxOutliers, // = 20; // Maximal number of outliers to remove
final double fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
// FIXME: the following 2 parameters are not yet used
final double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
final double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -6248,24 +6882,9 @@ public class SuperTiles{
dispNorm, // double dispNorm, // Normalize disparities to the average if above
min_weight, // double min_weight,
min_tiles, // int min_tiles,
// strength_floor, // double strength_floor,
// strength_pow, // double strength_pow,
//OK?
smplMode,
mlfp,
// smplSide,
// smplNum,
// smplRms,
// smplWnd,
// max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// far_power, // 1.0; // Raise disparity to this power before averaging for far objects
dl - 2); // int debugLevel)
if (disp_strength == null) {
System.out.println("=== BUG in applyMergePlanes(): failed to getPlaneFromMeas() for merged planes");
......@@ -6280,41 +6899,46 @@ public class SuperTiles{
dispNorm, // double dispNorm, // Normalize disparities to the average if above
min_weight, // double min_weight,
min_tiles, // int min_tiles,
// strength_floor, // double strength_floor,
// strength_pow, // double strength_pow,
//OK?
smplMode,
mlfp,
// smplSide,
// smplNum,
// smplRms,
// smplWnd, // was not here
// max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// far_power, // 1.0; // Raise disparity to this power before averaging for far objects
dl - 2); // int debugLevel)
// remove outliers //removeOutliers
// now try to remove outliers
int max_outliers = (int) Math.round(this_pd.getNumPoints() * fractOutliers);
if (max_outliers > maxOutliers) max_outliers = maxOutliers;
double targetV = corrMaxEigen(
targetEigen,
dispNorm,
planes[nsTile][np0]);
boolean almost_fronto = this_pd.isFronto(
fronto_tol, // double fronto_tol,
disp_strength, // double [][][] disp_str,
debugLevel); // int debugLevel);
// seems it is OK not to normalize fronto_rms, as it is only needed for far surfaces
double targetEigen = almost_fronto ? (fronto_rms*fronto_rms): targetV;
// if (this_pd.getValue() > targetV) {
if (this_pd.getNormValue() > targetV) {
// FIXME: temporary - make a configurable parameter
double fronto_fract_outliers = 0.8; // 2 * inFractOutliers;
double fractOutliers = almost_fronto ? (fronto_fract_outliers) : inFractOutliers;
int max_outliers = (int) Math.round(this_pd.getNumPoints() * fractOutliers);
if (max_outliers > maxOutliers) max_outliers = maxOutliers;
// in fronto mode - run at least once
if (almost_fronto) {
this_pd.growFrontoSelection(
5, // int min_neib,
0.1, // double max_over_avg,
0.00, // double max_under_avg,
disp_strength); // double [][][] disp_str)
}
if ((this_pd.getNormValue() > targetEigen) || almost_fronto) { // targetV) {
boolean OK = this_pd.removeOutliers( // getPlaneFromMeas should already have run
fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
fronto_rms, // double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes. May be tighter
fronto_offs, //double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight.
disp_strength,
targetV, // double targetEigen, // target eigenvalue for primary axis (is disparity-dependent, so is non-constant)
max_outliers, // int maxRemoved, // maximal number of tiles to remove (not a constant)
......@@ -6324,6 +6948,9 @@ public class SuperTiles{
break;
}
}
if (this_pd.fronto) {
//?
}
}
// remove all null planes (but number zero - it may be null for historical reasons)
ArrayList<Integer> remaining_planes = new ArrayList<Integer>();
......@@ -6425,25 +7052,14 @@ public class SuperTiles{
final int min_tiles,
// parameters to reduce outliers
final double targetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
final double fractOutliers, // = 0.3; // Maximal fraction of outliers to remove
final double inFractOutliers, // = 0.3; // Maximal fraction of outliers to remove
final int maxOutliers, // = 20; // Maximal number of outliers to remove
// final double strength_floor,
// final double strength_pow,
final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
final MeasuredLayersFilterParameters mlfp,
// final int smplSide, // = 2; // Sample size (side of a square)
// final int smplNum, // = 3; // Number after removing worst
// final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
// final boolean smplWnd, // use window functions for the samples
// final double max_abs_tilt, // 2.0; // pix per tile
// final double max_rel_tilt, // 0.2; // (pix / disparity) per tile
// final double damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// final double min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// final double transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// final int far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// final double far_power, // 3.0; // Raise disparity to this power before averaging for far objects
final double fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
//FIXME: use following 2 parameters
final double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
final double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
final int debugLevel,
final int dbg_X,
......@@ -6598,19 +7214,6 @@ public class SuperTiles{
use_other_planes, // boolean use_other_planes,
smplMode,
mlfp,
// smplSide,
// smplNum,
// smplRms,
// smplWnd, // final boolean smplWnd, // use window functions for the samples
// max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// far_power, // 1.0; // Raise disparity to this power before averaging for far objects
measSel, // int measSel, // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
allow_parallel, //boolean allow_parallel,
dl); // int debugLevel)
......@@ -6642,37 +7245,46 @@ public class SuperTiles{
dispNorm, // double dispNorm, // Normalize disparities to the average if above
min_weight, // double min_weight,
min_tiles, // int min_tiles,
// strength_floor, // double strength_floor,
// strength_pow, // double strength_pow,
// OK?
smplMode,
mlfp,
// smplSide,
// smplNum,
// smplRms,
// smplWnd, // final boolean smplWnd, // use window functions for the samples
// max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// far_power, // 1.0; // Raise disparity to this power before averaging for far objects
dl); // int debugLevel)
if (disp_strength == null) break;
// remove outliers //removeOutliers
// now try to remove outliers
int max_outliers = (int) Math.round(bpd[np][npip].getNumPoints() * fractOutliers);
if (max_outliers > maxOutliers) max_outliers = maxOutliers;
double targetV = corrMaxEigen(
targetEigen,
dispNorm,
bpd[np][npip]);
// if (bpd[np][npip].getValue() > targetV) {
if (bpd[np][npip].getNormValue() > targetV) {
boolean almost_fronto = bpd[np][npip].isFronto(
fronto_tol, // double fronto_tol,
disp_strength, // double [][][] disp_str,
debugLevel); // int debugLevel);
// seems it is OK not to normalize fronto_rms, as it is only needed for far surfaces
double targetEigen = almost_fronto ? (fronto_rms*fronto_rms): targetV;
// FIXME: temporary - make a configurable parameter
double fronto_fract_outliers = 0.8; // 2 * inFractOutliers;
double fractOutliers = almost_fronto ? (fronto_fract_outliers) : inFractOutliers;
int max_outliers = (int) Math.round(bpd[np][npip].getNumPoints() * fractOutliers);
if (max_outliers > maxOutliers) max_outliers = maxOutliers;
// if (bpd[np][npip].getNormValue() > targetV) {
// in fronto mode - run at least once
if (almost_fronto) {
bpd[np][npip].growFrontoSelection(
4, // int min_neib,
0.1, // double max_over_avg,
0.00, // double max_under_avg,
disp_strength); // double [][][] disp_str)
}
if ((bpd[np][npip].getNormValue() > targetEigen) || almost_fronto) { // targetV) {
OK = bpd[np][npip].removeOutliers( // getPlaneFromMeas should already have run
fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
fronto_rms, // double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes. May be tighter
fronto_offs, //double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced
disp_strength,
targetV, // double targetEigen, // target eigenvalue for primary axis (is disparity-dependent, so is non-constant)
max_outliers, // int maxRemoved, // maximal number of tiles to remove (not a constant)
......
......@@ -87,7 +87,9 @@ public class TilePlanes {
int min_tiles = 10;
double dispNorm = 5.0; // Normalize disparities to the average if above
boolean smplMode = true; // Use sample mode (false - regular tile mode)
boolean fronto = false; // this plane is almost fronto
boolean horizontal = false; // plane created as horizontal, can not be fronto
double fronto_rms = Double.NaN; // temporary, for debugging
MeasuredLayersFilterParameters mlfp = new MeasuredLayersFilterParameters(); // filter parameters
// double measured_strength_pow = 1.0;
......@@ -207,7 +209,9 @@ public class TilePlanes {
pd.wvectors[1] = this.wvectors[1].clone();
pd.wvectors[2] = this.wvectors[2].clone();
}
pd.mark0 = this.mark0;
pd.mark0 = this.mark0;
pd.fronto = this.fronto;
pd.horizontal = this.horizontal;
return pd;
}
......@@ -297,6 +301,9 @@ public class TilePlanes {
if (isHorizontal()){
s+= "HORIZONTAL ";
}
if (fronto){
s+= String.format("FRONTO (%6.4f)",fronto_rms);
}
s += String.format("2d=%4.1f ", get2dRatio());
s += String.format( "np=%3d weight= %8.5f", num_points, weight);
if (starValueWeight != null) s += String.format(" star=[%8.5f, %8.5f]", starValueWeight[0], starValueWeight[1]);
......@@ -1192,9 +1199,144 @@ public class TilePlanes {
return eff_disp_str;
}
public boolean isFronto(
double fronto_tol,
double [][][] disp_str,
int debugLevel)
{
if (horizontal || isHorizontal()) {
this.fronto = false;
return this.fronto;
}
boolean almost_fronto = false;
double [] zxy0 = getZxy();
if (disp_str == null) {
disp_str = new double [measuredSelection.length][][];
for (int nl = 0; nl < measuredSelection.length; nl++){
if (measuredSelection[nl] != null){
if (smplMode) {
disp_str[nl] = measuredLayers.getDisparityStrengthMLTilted( // expensive to calculate (improve removing outlayers
nl, // int num_layer,
sTileXY[0], // int stX,
sTileXY[1], // int stY,
null, // measuredSelection[nl], // boolean [] sel_in,
this.mlfp,
true, // boolean null_if_none)
debugLevel);
} else {
disp_str[nl] = measuredLayers.getDisparityStrengthML(
nl, // int num_layer,
sTileXY[0], // int stX,
sTileXY[1], // int stY,
null, // measuredSelection[nl], // boolean [] sel_in,
this.mlfp,
true); // boolean null_if_none)
}
}
}
}
if (fronto_tol > 0) {
// see if the plane is almost fronto
double fronto_tol2 = fronto_tol*fronto_tol;
// do not use fronto for near tiles - at least do not increase tolerance
// if ((dispNorm > 0.0) && (zxy[0] > dispNorm)){
// fronto_tol2 *= zxy[0]/dispNorm;
// }
double sw = 0.0, swd2 = 0.0;
for (int nl = 0; nl < measuredSelection.length; nl++){
if (measuredSelection[nl] != null){
// already calculated, but not masked by selection!
if (disp_str[nl] != null) {
for (int indx = 0; indx < disp_str[nl][0].length; indx++){
double w = disp_str[nl][1][indx];
if (measuredSelection[nl][indx] && (w > 0.0)){
double d = disp_str[nl][0][indx]-zxy0[0];
double wd2 = w*d*d;
sw+=w;
swd2 += wd2;
}
}
}
}
}
if (sw> 0.0) {
// swd2 /= sw;
almost_fronto = (swd2 / sw) <= (getValue() + fronto_tol2);
}
if (debugLevel > 2){
System.out.println("isFronto("+sTileXY[0]+":"+sTileXY[1]+"): "+
" eigenValue = " + getValue()+" (swd2 / sw) = " + (swd2 / sw)+" fronto_tol2 = "+fronto_tol2+
" almost_fronto="+almost_fronto);
}
this.fronto_rms = Math.sqrt(swd2 / sw);
}
if ((dispNorm > 0.0) && (zxy[0] > dispNorm)) {
almost_fronto = false; // disable fronto for near objects completely
}
this.fronto = almost_fronto;
return almost_fronto;
}
/**
* Grow measured selection (mostly fill gaps) for fronto planes
* @param min_neib minimal number of previously selected neighbors
* @param max_over_avg only add if new tile disparity is not higher than average of the neighbors plus this.
* @param max_under_avg only add if new tile disparity is not lower than average of the neighbors minus this.
*/
public int growFrontoSelection(
int min_neib,
double max_over_avg,
double max_under_avg,
double [][][] disp_str)
{
TileNeibs tn = new TileNeibs(2*superTileSize,2*superTileSize);
int num_new=0;
for (int nl = 0; nl < measuredSelection.length; nl++) if (measuredSelection[nl] != null){
boolean [] sel = measuredSelection[nl].clone();
boolean [] was_sel = measuredSelection[nl].clone();
tn.growSelection(2, sel, null);
double sw0=0.0, swd0=0.0;
for (int indx = 0; indx < sel.length; indx++) if (was_sel[indx] && (disp_str[nl][1][indx] > 0.0)) {
sw0+= disp_str[nl][1][indx];
swd0+=disp_str[nl][1][indx]*disp_str[nl][0][indx];
}
if (sw0 <=0.0) continue;
swd0 /= sw0; // average disparity for all tiles
for (int indx = 0; indx < sel.length; indx++) if (sel[indx] && !was_sel[indx] && (disp_str[nl][1][indx] > 0.0)) {
int num_neibs = 0;
double sw = 0.0, swd = 0.0;
for (int dir = 0; dir <8; dir++) {
int neib = tn.getNeibIndex(indx, dir);
if ((neib >= 0) && was_sel[neib] && (disp_str[nl][1][neib] > 0.0) ) {
num_neibs++;
sw += disp_str[nl][1][neib];
swd += disp_str[nl][1][neib] * disp_str[nl][0][neib];
}
}
if (num_neibs >= min_neib) {
swd /= sw;
}
if ( (disp_str[nl][0][indx] >= swd0) && // more than average
(disp_str[nl][0][indx] >= (swd - max_under_avg)) &&
(disp_str[nl][0][indx] <= (swd + max_over_avg)) ){
measuredSelection[nl][indx] = true;
num_new++;
}
}
}
return num_new;
}
/**
* Remove outliers from the set of tiles contributing to a single plane ellipsoid
* Should run after getPlaneFromMeas as some parameter4s will be copied from that run
* @param fronto_tol parameter to treat almost fronto planes as fronto (worst tiles are have extreme disparities,
* not distance from the tilted planes). Tolerance is measured in disparity pixel and is scaled for high disparities
* @param fronto_rms target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes. May be tighter
* @param fronto_offs increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
* @param disp_str - pre-calculated array or null (will be calculated). disp_str
* has the same format as the output of getPlaneFromMeas - [measurement layer][2][tile index],
* so it can be used for input.
......@@ -1205,20 +1347,24 @@ public class TilePlanes {
*/
public boolean removeOutliers( // getPlaneFromMeas should already have run
double [][][] disp_str, // calculate just once when removing outliers (null - OK, will generate it)
double targetEigen, // target eigenvalue for primary axis (is disparity-dependent, so is non-constant)
int maxRemoved, // maximal number of tiles to remove (not a constant)
int debugLevel)
double fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes. May be tighter
double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
double [][][] disp_str, // calculate just once when removing outliers (null - OK, will generate it)
double inTargetEigen, // target eigenvalue for primary axis (is disparity-dependent, so is non-constant)
int maxRemoved, // maximal number of tiles to remove (not a constant)
int debugLevel)
{
int stSize2 = 2 * stSize;
double fronto_bonus_near = 3.0;
if (maxRemoved > (getNumPoints() - this.min_tiles)) maxRemoved = getNumPoints() - this.min_tiles;
boolean need_disp_str = false;
// boolean need_disp_str = false;
if (disp_str == null) {
disp_str = new double [measuredSelection.length][][];
for (int nl = 0; nl < measuredSelection.length; nl++){
if (measuredSelection[nl] != null){
if (smplMode) {
if (need_disp_str) {
// if (need_disp_str) {
disp_str[nl] = measuredLayers.getDisparityStrengthMLTilted( // expensive to calculate (improve removing outlayers
nl, // int num_layer,
sTileXY[0], // int stX,
......@@ -1227,7 +1373,7 @@ public class TilePlanes {
this.mlfp,
true, // boolean null_if_none)
debugLevel);
}
// }
} else {
disp_str[nl] = measuredLayers.getDisparityStrengthML(
nl, // int num_layer,
......@@ -1242,19 +1388,38 @@ public class TilePlanes {
}
int numRemoved = 0;
boolean no_bugs = true;
// calculate if it is fronto, check after each pass if it was not
boolean almost_fronto = isFronto(
fronto_tol, // double fronto_tol,
disp_str, // double [][][] disp_str,
debugLevel); // int debugLevel);
double targetEigen = almost_fronto ? (fronto_rms*fronto_rms): inTargetEigen;
for (; (getNormValue() > targetEigen) && (numRemoved < maxRemoved); numRemoved++){
if (debugLevel > 2){
System.out.println("removePlaneOutliers("+sTileXY[0]+":"+sTileXY[1]+"): numRemoved = "+numRemoved+
" eigenValue = " + getValue()+" norm eigenValue = " + getNormValue()+" target = "+targetEigen);
}
// make a plane and find the worst (largest disparity difference) tile
// z = -(x*Vx + y*Vy)/Vz
// may become fronto after removing some tiles
double worst_d2 = 0.0;
int [] worst_layer_index = {-1,-1};
// TODO: Add vertical planes here set v[1] = 0.0;
double [] v = getVector();
double [] zxy0 = getZxy();
if (!almost_fronto ) {
almost_fronto = isFronto(
fronto_tol, // double fronto_tol,
disp_str, // double [][][] disp_str,
debugLevel); // int debugLevel);
if (almost_fronto) {
targetEigen = fronto_rms*fronto_rms;
}
}
if (debugLevel > 2){
System.out.println("removePlaneOutliers("+sTileXY[0]+":"+sTileXY[1]+"): numRemoved = "+numRemoved+
" eigenValue = " + getValue()+" norm eigenValue = " + getNormValue()+" target = "+targetEigen+
" almost_fronto="+almost_fronto);
}
for (int nl = 0; nl < measuredSelection.length; nl++){
if (measuredSelection[nl] != null){
// already calculated, but not masked by selection!
......@@ -1262,12 +1427,17 @@ public class TilePlanes {
for (int indx = 0; indx < disp_str[nl][0].length; indx++){
double w = disp_str[nl][1][indx];
if (measuredSelection[nl][indx] && (w > 0.0)){
double x = ((indx % stSize2) - stSize) - zxy0[1];
double y = ((indx / stSize2) - stSize) - zxy0[2];
double d = disp_str[nl][0][indx];
d -= zxy0[0];
d += (x * v[1]+y*v[2])/v[0];
if (!almost_fronto) { // compare to a distance from a tilted plane or to a constant disparity (almost_fronto)
double x = ((indx % stSize2) - stSize) - zxy0[1];
double y = ((indx / stSize2) - stSize) - zxy0[2];
d += (x * v[1]+y*v[2])/v[0];
}
double d2 = d*d;
if (almost_fronto && (d > 0)) {
d2 /= fronto_bonus_near; // if tile is nearer, decrease effective error
}
if (d2 > worst_d2){
worst_d2 = d2;
worst_layer_index[0] = nl;
......@@ -1297,6 +1467,10 @@ public class TilePlanes {
this.min_weight, // double min_weight,
this.min_tiles, // int min_tiles,
this.smplMode,
almost_fronto, // boolean fronto_mode,
fronto_offs, // double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
this.mlfp,
debugLevel-1) != null);
......@@ -1320,9 +1494,78 @@ public class TilePlanes {
break;
}
}
if (debugLevel > 2){
System.out.println("removePlaneOutliers("+sTileXY[0]+":"+sTileXY[1]+"): numRemoved = "+numRemoved+
" eigenValue = " + getValue()+" norm eigenValue = " + getNormValue()+" target = "+targetEigen+
" almost_fronto="+almost_fronto);
}
// FIXME: May be removed, just to update fronto_rms:
almost_fronto = isFronto(
fronto_tol, // double fronto_tol,
disp_str, // double [][][] disp_str,
debugLevel); // int debugLevel);
if (almost_fronto) {
boolean OK = (getPlaneFromMeas(
measuredSelection, // null, // boolean [][] tile_sel, // null - do not use, {} use all (will be modified)
disp_str,
Double.NaN, // double disp_far, // minimal disparity to select (or NaN)
Double.NaN, // double disp_near, // maximal disparity to select (or NaN)
this.dispNorm, // double dispNorm, // Normalize disparities to the average if above
this.min_weight, // double min_weight,
this.min_tiles, // int min_tiles,
this.smplMode,
almost_fronto, // boolean fronto_mode,
fronto_offs, // double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
this.mlfp,
debugLevel-0) != null); // will show image
if (!OK) { // restore how it was
getPlaneFromMeas(
measuredSelection, // null, // boolean [][] tile_sel, // null - do not use, {} use all (will be modified)
disp_str,
Double.NaN, // double disp_far, // minimal disparity to select (or NaN)
Double.NaN, // double disp_near, // maximal disparity to select (or NaN)
this.dispNorm, // double dispNorm, // Normalize disparities to the average if above
this.min_weight, // double min_weight,
this.min_tiles, // int min_tiles,
this.smplMode,
this.mlfp,
debugLevel-0);
}
}
return no_bugs;
}
public double [][][] getPlaneFromMeas(
boolean [][] tile_sel, // null - do not use, {} use all (will be modified)
double [][][] disp_str, // calculate just once when removing outliers
double disp_far, // minimal disparity to select (or NaN)
double disp_near, // maximal disparity to select (or NaN)
double dispNorm, // Normalize disparities to the average if above
double min_weight,
int min_tiles,
boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
// boolean fronto_mode,
// double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
MeasuredLayersFilterParameters mlfp,
int debugLevel)
{
return getPlaneFromMeas(
tile_sel, // null - do not use, {} use all (will be modified)
disp_str, // calculate just once when removing outliers
disp_far, // minimal disparity to select (or NaN)
disp_near, // maximal disparity to select (or NaN)
dispNorm, // Normalize disparities to the average if above
min_weight,
min_tiles,
smplMode, // = true; // Use sample mode (false - regular tile mode)
false, // boolean fronto_mode,
0.0, //double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
mlfp,
debugLevel);
}
/**
* Get "plane" - ellipsoid from covariance matrix of measured data
* @param tile_sel multi-layer selection of the tiles to use (first dimension should
......@@ -1345,7 +1588,8 @@ public class TilePlanes {
* @param smplNum number of averaged samples (should be <= smplSide * smplSide and > 1)
* @param smplRms maximal square root of variance (in disparity pixels) to accept the result
* @param smplWnd use window functions for the samples
*
* @param fronto_mode enforce plane orthogonal to disparity axis
* @param fronto_offs increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
* @param debugLevel debug level
* @return per measurement layer : x,y,z, weight, or null if failed. This
* value may be re-used in subsequent refinements (as removing outliers)
......@@ -1359,6 +1603,10 @@ public class TilePlanes {
double min_weight,
int min_tiles,
boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
boolean fronto_mode,
double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
MeasuredLayersFilterParameters mlfp,
int debugLevel)
{
......@@ -1380,7 +1628,7 @@ public class TilePlanes {
if (debugLevel > 2){
System.out.println("getPlaneFromMeas()");
System.out.println("getPlaneFromMeas(): fronto_mode="+fronto_mode+", fronto_offs="+fronto_offs);
}
boolean need_disp_str = false;
if (disp_str == null) {
......@@ -1447,8 +1695,6 @@ public class TilePlanes {
sTileXY[1], // int stY,
tile_sel[nl], // boolean [] sel_in,
mlfp,
// strength_floor,
// strength_pow, //
true); // boolean null_if_none)
sw += MeasuredLayers.getSumStrength(disp_str[nl]);
}
......@@ -1480,6 +1726,42 @@ public class TilePlanes {
return null; // too weak plane or too few tiles selected
}
double fronto_near_diff = 0.02; // edge tile has to have neib with disparity higher by this
double fronto_far_diff = 0.1; // edge tile has to have neib with disparity lower by this
double fronto_edge_weight = 0.1; // weight of edge tiles
boolean [][] edge_tiles = null; // new boolean[]
if (fronto_mode) {
edge_tiles = new boolean[disp_str.length][];
TileNeibs tileNeibs = new TileNeibs(stSize2, stSize2);
for (int nl = 0; nl < edge_tiles.length; nl++) if (disp_str[nl] != null){
edge_tiles[nl] = new boolean [disp_str[nl][0].length];
for (int indx = 0; indx < edge_tiles[nl].length; indx++) if (disp_str[nl][1][indx] > 0.0){
boolean has_near = false, has_far = false;
double high = disp_str[nl][0][indx];
double low = high - fronto_far_diff;
high += fronto_near_diff;
for (int dir = 0; dir < 8; dir++){
int indx1 = tileNeibs.getNeibIndex(indx, dir);
if ((indx1 >= 0) && (disp_str[nl][1][indx1] >0)) {
if (disp_str[nl][0][indx1] > high) {
has_near = true;
if (has_far) {
edge_tiles[nl][indx] = true;
break;
}
} else if (disp_str[nl][0][indx1] < low) {
has_far = true;
if (has_near) {
edge_tiles[nl][indx] = true;
break;
}
}
}
}
}
}
}
double [][] acovar = new double [3][3];
double swz = 0.0, swx = 0.0, swy = 0.0;
......@@ -1489,6 +1771,9 @@ public class TilePlanes {
for (int indx = 0; indx < disp_str[nl][0].length; indx++){
if (tile_sel[nl][indx]) {
double w = disp_str[nl][1][indx];
if (fronto_mode && edge_tiles[nl][indx]) {
w *= fronto_edge_weight;
}
if (w > 0.0){
double d = disp_str[nl][0][indx];
// referencing samples to centers of pixels
......@@ -1510,8 +1795,86 @@ public class TilePlanes {
swx /= sw;
swy /= sw;
if (debugLevel > 0){
System.out.println("getPlaneFromMeas(): num_tiles="+num_tiles+", sw = "+sw +", swz = "+swz +", swx = "+swx +", swy = "+swy); // +", kz="+kz);
if (fronto_mode && (fronto_offs > 0.0)) {
// recalculate offset swz, set modified tiles weights
double [][][] disp_str_actual = disp_str;
disp_str = new double [disp_str_actual.length][][];
for (int nl = 0; nl < disp_str.length; nl++) {
if (disp_str_actual[nl] != null) {
disp_str[nl] = new double [2][];
disp_str[nl][0] = disp_str_actual[nl][0].clone();
disp_str[nl][1] = new double [disp_str_actual[nl][1].length];
}
}
double swz0 = swz;
double sw0 = sw;
swz = 0.0;
sw = 0.0;
double d0 = swz - fronto_offs;
for (int nl = 0; nl < tile_sel.length; nl++){
if (disp_str[nl] != null) {
for (int indx = 0; indx < disp_str[nl][0].length; indx++){
if (tile_sel[nl][indx]) {
double w = disp_str_actual[nl][1][indx];
if (fronto_mode && edge_tiles[nl][indx]) {
w *= fronto_edge_weight;
}
if (w > 0.0){
double d = disp_str[nl][0][indx];
if (d > d0) {
w *= (d-d0)/fronto_offs; // more weight of the near pixels, same weight of the centre pixels
disp_str[nl][1][indx] = w;
sw += w;
swz += w * d;
}
}
}
}
if ((debugLevel > 2) && (disp_str[nl] != null)){
// if ((debugLevel > 1) && (disp_str[nl] != null)){
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays();
double [][] dbg_img = new double [4][];
dbg_img[0] = disp_str[nl][0];
dbg_img[1] = disp_str[nl][1];
dbg_img[2] = disp_str_actual[nl][1];
dbg_img[3] = new double [stSize2*stSize2];
if (tile_sel[nl] != null) {
for (int i = 0; i < dbg_img[3].length; i++){
dbg_img[3][i] = tile_sel[nl][i]?(edge_tiles[nl][i]?0.5:1.0):0.0; // exception here?
}
}
sdfa_instance.showArrays(dbg_img, stSize2, stSize2, true, "fronto-disp_str_x"+sTileXY[0]+"_y"+sTileXY[1]+"_"+nl);
}
}
}
if (sw == 0.0) {
return null;
}
swz /= sw; // new center (higher than older swz
if (debugLevel > 0){
System.out.println("getPlaneFromMeas(): Using fronto mode, num_tiles="+num_tiles+", sw0 = "+sw0 +", swz0 = "+swz0 +", swz = "+swz);
}
} else {
if (debugLevel > 2){
for (int nl = 0; nl < tile_sel.length; nl++) if (disp_str[nl] != null) {
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays();
double [][] dbg_img = new double [3][];
dbg_img[0] = disp_str[nl][0];
dbg_img[1] = disp_str[nl][1];
dbg_img[2] = new double [stSize2*stSize2];
if (tile_sel[nl] != null) {
for (int i = 0; i < dbg_img[2].length; i++){
dbg_img[2][i] = tile_sel[nl][i]?1.0:0.0;
}
}
sdfa_instance.showArrays(dbg_img, stSize2, stSize2, true, "non-fronto-disp_str_x"+sTileXY[0]+"_y"+sTileXY[1]+"_"+nl);
}
}
if (debugLevel > 2){
System.out.println("getPlaneFromMeas(): num_tiles="+num_tiles+", sw = "+sw +", swz = "+swz +", swx = "+swx +", swy = "+swy); // +", kz="+kz);
}
}
// TODO: scale disparity to make same scale for 3 axes?
......@@ -1521,6 +1884,9 @@ public class TilePlanes {
for (int indx = 0; indx < disp_str[nl][0].length; indx++){
if (tile_sel[nl][indx]) {
double w = disp_str[nl][1][indx] / sw;
if (fronto_mode && edge_tiles[nl][indx]) {
w *= fronto_edge_weight;
}
if (w > 0.0){
double d = disp_str[nl][0][indx] - swz;
double wd = w*d;
......@@ -1537,6 +1903,11 @@ public class TilePlanes {
}
}
}
if (fronto_mode) { // enforce fronto
acovar [0][1] = 0.0; // wdx
acovar [0][2] = 0.0; // wdy
}
acovar [1][0] = acovar [0][1];
acovar [2][0] = acovar [0][2];
acovar [2][1] = acovar [1][2];
......@@ -1740,8 +2111,8 @@ public class TilePlanes {
}
}
if ((debugLevel > 2) && (disp_str[nl] != null)){
// if ((debugLevel > 2) && (disp_str[nl] != null)){
if ((debugLevel > 3) && (disp_str[nl] != null)){
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays();
double [][] dbg_img = new double [3][];
dbg_img[0] = disp_str[nl][0];
......@@ -3276,8 +3647,9 @@ public class TilePlanes {
covar.print(8, 6);
}
if (Double.isNaN(covar.get(0, 0))){
System.out.println("covar is NaN !");
System.out.println("covar is NaN 1 !");
covar.print(8, 6);
return null;
}
// extract new eigenvalues, eigenvectors
EigenvalueDecomposition eig = covar.eig(); // verify NaN - it gets stuck
......@@ -3387,7 +3759,7 @@ public class TilePlanes {
boolean preferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
int debugLevel)
{
if (debugLevel > 0) {
if (debugLevel > 1) {
System.out.println("mergePlaneToThisWorld()");
}
if (wvalues == null ) {
......@@ -3480,8 +3852,9 @@ public class TilePlanes {
covar.print(8, 6);
}
if (Double.isNaN(covar.get(0, 0))){
System.out.println("covar is NaN !");
System.out.println("covar is NaN 2!");
covar.print(8, 6);
return null;
}
// extract new eigenvalues, eigenvectors
EigenvalueDecomposition eig = covar.eig(); // verify NaN - it gets stuck
......@@ -3894,6 +4267,7 @@ public class TilePlanes {
public ArrayList<PlaneData> createTilePlanesFromSelections(
String suffix,
boolean [][][] plane_selections, // = new boolean [nStiles][][][]; // num_tiles
boolean [] hor_planes,
double [][][] disp_strength,
double dispNorm, // Normalize disparities to the average if above
int min_tiles,
......@@ -3903,17 +4277,32 @@ public class TilePlanes {
boolean correct_distortions,
boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
MeasuredLayersFilterParameters mlfp,
double fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes. May be tighter
double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
int debugLevel)
{
if (debugLevel > 2) {
debugLevel += 0; // +=1 // no show all eigen stuff (debugLevel > 3)
}
if (debugLevel > 0) {
System.out.println("Debug debugLevel"); // +=1 // no show all eigen stuff (debugLevel > 3)
System.out.println("createTilePlanesFromSelections(): debugLevel="+debugLevel); // +=1 // no show all eigen stuff (debugLevel > 3)
}
// first make a plane from all tiles
ArrayList<PlaneData> st_planes = new ArrayList<PlaneData>();
if (debugLevel > 2) {
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays();
double [][] dbg_img = new double [plane_selections.length][];
for (int ps = 0; ps < plane_selections.length; ps++) {
dbg_img[ps] = new double [plane_selections[ps][0].length];
for (int i = 0; i < dbg_img[ps].length; i++) {
dbg_img[ps][i] = plane_selections[ps][0][i]? 1.0: 0.0;
}
}
sdfa_instance.showArrays(dbg_img, stSize * 2, stSize * 2, true, "selections_x"+sTileXY[0]+"_y"+sTileXY[1]+"-"+suffix);
}
// iterate through all plane selections
for (int ps = 0; ps < plane_selections.length; ps++) {
......@@ -3933,6 +4322,7 @@ public class TilePlanes {
if (debugLevel > 0) {
if (pd.getWeight() > 1.0) {
System.out.println("Processing subplane "+ suffix+
(((hor_planes == null) || !hor_planes[ps])?"(horizontal) ":"(vertical) ")+
", numPoints="+ pd.getNumPoints()+
", swc = "+pd.getWeight()+
", center=["+pd.getZxy()[0]+","+pd.getZxy()[1]+","+pd.getZxy()[2]+"]"+
......@@ -3940,10 +4330,8 @@ public class TilePlanes {
", eig_vect[0] = {"+pd.getVector()[0]+","+pd.getVector()[1]+","+pd.getVector()[2]+"}");
}
}
// now try to remove outliers
int max_outliers = (int) Math.round(pd.getNumPoints() * plFractOutliers);
if (max_outliers > plMaxOutliers) max_outliers = plMaxOutliers;
double targetV = plTargetEigen;
// double targetV = plTargetEigen;
/* Does it needs to be twice?
double z0 = pd.getZxy()[0];
......@@ -3952,10 +4340,39 @@ public class TilePlanes {
targetV *= dd * dd; // > original
}
*/
if (pd.getNormValue() > targetV) {
if ((hor_planes != null) && hor_planes[ps]) {
pd.horizontal = true;
}
boolean almost_fronto = pd.isFronto(
fronto_tol, // double fronto_tol,
disp_strength, // double [][][] disp_str,
debugLevel); // int debugLevel);
double targetEigen = almost_fronto ? (fronto_rms*fronto_rms): plTargetEigen;
// now try to remove outliers
// FIXME: temporary - make a configurable parameter
double fronto_fract_outliers = 0.8; // 2 * inFractOutliers;
double fractOutliers = almost_fronto ? (fronto_fract_outliers) : plFractOutliers;
int max_outliers = (int) Math.round(pd.getNumPoints() * fractOutliers); // plFractOutliers);
if (max_outliers > plMaxOutliers) max_outliers = plMaxOutliers;
// in fronto mode - run at least once
// if ((this_pd.getNormValue() > targetEigen) || almost_fronto) { // targetV) {
if (almost_fronto) {
pd.growFrontoSelection(
5, // 4, // int min_neib,
0.1, // double max_over_avg,
0.00, // double max_under_avg,
disp_strength); // double [][][] disp_str)
}
if ((pd.getNormValue() > targetEigen) || almost_fronto) { // targetV) {
OK = pd.removeOutliers( // getPlaneFromMeas should already have run
fronto_tol, // double fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
fronto_rms, // double fronto_rms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes. May be tighter
fronto_offs, //double fronto_offs, // = 0.2; // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0 - disable
disp_strength,
targetV, // double targetEigen, // target eigenvalue for primary axis (is disparity-dependent, so is non-constant)
plTargetEigen, // targetV, // double targetEigen, // target eigenvalue for primary axis (is disparity-dependent, so is non-constant)
max_outliers, // int maxRemoved, // maximal number of tiles to remove (not a constant)
debugLevel); // int debugLevel)
if (!OK) {
......@@ -5117,6 +5534,7 @@ public class TilePlanes {
// return planes/selections (no remove outliers!)
boolean[][][] filterBridges(
ArrayList<PlaneData> tilePlanes,
boolean [][] hor_planes, // specify which selections correspond to horizontal planes
int max_grow_these,
int max_grow_far,
int debugLevel)
......@@ -5265,10 +5683,17 @@ public class TilePlanes {
}
if (!split_planes.isEmpty()){
boolean [][][] split_selections = new boolean [old_planes.size() + split_planes.size()][][];
if (hor_planes != null) {
hor_planes[0] = new boolean[old_planes.size() + split_planes.size()];
}
int ns = 0;
for (Integer np: old_planes){
if (hor_planes != null) {
hor_planes[0][ns] = tilePlanes.get(np).horizontal || tilePlanes.get(np).isHorizontal();
}
split_selections[ns++] = tilePlanes.get(np).getMeasSelection();
}
// Split planes have unknown horizontal status
for (TileSelections ts: split_planes){
// PlaneData pd = tilePlanes.get(ts.np);
boolean [][] ms = tilePlanes.get(ts.np).getMeasSelection().clone();
......
......@@ -5341,23 +5341,14 @@ public class TileProcessor {
clt_parameters.plFractOutliers, // = 0.3; // Maximal fraction of outliers to remove
clt_parameters.plMaxOutliers, // = 20; // Maximal number of outliers to remove\
clt_parameters.plPreferDisparity,
clt_parameters.plFrontoTol, // final double plFrontoTol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable
clt_parameters.plFrontoRms, // final double plFrontoRms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
clt_parameters.plFrontoOffs, // final double plFrontoOffs, // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0
geometryCorrection,
clt_parameters.correct_distortions,
clt_parameters.stSmplMode , // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
clt_parameters.mlfp, // Filter parameters
// clt_parameters.stSmplSide , // final int smplSide, // = 2; // Sample size (side of a square)
// clt_parameters.stSmplNum , // final int smplNum, // = 3; // Number after removing worst
// clt_parameters.stSmplRms , // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
// clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
// clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.plBlurBinHor, // final double bin_blur_hor, // Blur disparity histograms for horizontal clusters by this sigma (in bins)
clt_parameters.plBlurBinVert, // final double bin_blur_vert, // Blur disparity histograms for constant disparity clusters by this sigma (in bins)
......@@ -5374,7 +5365,7 @@ public class TileProcessor {
clt_parameters.stHighMix, // stHighMix = 0.4; // Consider merging initial planes if jumps between ratio above
world_hor, // final double [] world_hor, // horizontal plane normal (default [0.0, 1.0, 0.0])
clt_parameters.show_histograms, // final boolean show_histograms,
clt_parameters.batch_run?-1:1, // -1, // debugLevel, // final int debugLevel)
clt_parameters.batch_run?-3:debugLevel, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// showDoubleFloatArrays sdfa_instance = null; - already no state capitol plane
......@@ -5385,7 +5376,7 @@ public class TileProcessor {
// Trying new class
LinkPlanes lp = new LinkPlanes (clt_parameters, st);
if (!batch_mode && clt_parameters.show_planes && (debugLevel > -1)){
if (!batch_mode && clt_parameters.show_planes && (debugLevel > -2)){
showPlaneData(
"initial",
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
......@@ -5412,7 +5403,7 @@ public class TileProcessor {
clt_parameters.plPreferDisparity, // preferDisparity, // final boolean preferDisparity)
debugLevel-2);
// re-generate planes in the supertiles using previously calculated planes (for tghe tiles and their neighbors)
// re-generate planes in the supertiles using previously calculated planes (for the tiles and their neighbors)
// as hints, new planes will be assumed parallel to the known and possibly slightly offset in disparity
if (clt_parameters.plDiscrEn) {
st.regeneratePlanes(
......@@ -5424,30 +5415,17 @@ public class TileProcessor {
clt_parameters.plFractOutliers, // = 0.3; // Maximal fraction of outliers to remove
clt_parameters.plMaxOutliers, // = 20; // Maximal number of outliers to remove\
clt_parameters.plPreferDisparity,
clt_parameters.plFrontoTol, // final double plFrontoTol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable
clt_parameters.plFrontoRms, // final double plFrontoRms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
clt_parameters.plFrontoOffs, // final double plFrontoOffs, // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0
geometryCorrection,
clt_parameters.correct_distortions,
clt_parameters.stSmplMode, // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
clt_parameters.mlfp, // Filter parameters
// clt_parameters.stSmplSide, // final int smplSide, // = 2; // Sample size (side of a square)
// clt_parameters.stSmplNum, // final int smplNum, // = 3; // Number after removing worst
// clt_parameters.stSmplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
// clt_parameters.stSmplWnd, // final boolean smplWnd, // use window functions for the samples
// clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.mlfp, // Filter parameters
clt_parameters.plDiscrTolerance, // final double plDiscrTolerance, // = 0.4; // Maximal disparity difference from the plane to consider tile
clt_parameters.plDiscrDispRange, // final double plDiscrDispRange, // = 0.6; // Parallel move known planes around original know value for the best overall fit
clt_parameters.plDiscrSteps, // final int plDiscrSteps, // = 3; // Number of steps (each direction) for each plane to search for the best fit (0 - single, 1 - 1 each side)
// clt_parameters.plDiscrVariants, // final int plDiscrVariants, // = 100; // Total number of variants to try (protect from too many planes)
clt_parameters.plDiscrMode, // final int plDiscrMode, // = 3; // What plane to use as a hint: 0 - weighted, 1 - equalized, 2 - best, 3 - combined
clt_parameters.plDiscrVarFloor, // final double plDiscrVarFloor, // = 0.03; // Squared add to variance to calculate reverse flatness (used mostly for single-cell clusters)
clt_parameters.plDiscrSigma, // final double plDiscrSigma, // = 0.05; // Gaussian sigma to compare how measured data is attracted to planes
clt_parameters.plDiscrBlur, // final double plDiscrBlur, // = 0.1; // Sigma to blur histograms while re-discriminating
......@@ -5548,24 +5526,11 @@ public class TileProcessor {
clt_parameters.plTargetEigen, // final double targetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
clt_parameters.plFractOutliers, // final double fractOutliers, // = 0.3; // Maximal fraction of outliers to remove
clt_parameters.plMaxOutliers, // final int maxOutliers, // = 20; // Maximal number of outliers to remove
// clt_parameters.stFloor, // final double strength_floor,
// clt_parameters.stPow, // final double strength_pow,
// clt_parameters.dbg_migrate && clt_parameters.stSmplMode , // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
clt_parameters.stSmplMode , // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
clt_parameters.mlfp, // Filter parameters
// clt_parameters.stSmplSide , // final int smplSide, // = 2; // Sample size (side of a square)
// clt_parameters.stSmplNum , // final int smplNum, // = 3; // Number after removing worst
// clt_parameters.stSmplRms , // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
// clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
// clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stSmplMode , // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
clt_parameters.mlfp, // Filter parameters
clt_parameters.plFrontoTol, //final double fronto_tol, // fronto tolerance (pix) - treat almost fronto as fronto (constant disparity). <= 0 - disable this feature
clt_parameters.plFrontoRms, // final double plFrontoRms, // Target rms for the fronto planes - same as sqrt(plMaxEigen) for other planes
clt_parameters.plFrontoOffs, // final double plFrontoOffs, // increasing weight of the near tiles by using difference between the reduced average as weight. <= 0
debugLevel, // 1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......
......@@ -535,7 +535,8 @@ public class TwoQuadCLT {
ImageDtt.BIDISPARITY_TITLES);
boolean [] trusted = getTrustedDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, //QuadCLT quadCLT_aux,
quadCLT_aux, // QuadCLT quadCLT_aux,
true, // boolean use_individual,
0.14, // double min_combo_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity, // 4.0 -> change to rig_trust
1.0, // double trusted_tolerance,
......@@ -1912,6 +1913,7 @@ if (debugLevel > -100) return true; // temporarily !
boolean [] trusted_infinity = getTrustedDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
true, // boolean use_individual,
clt_parameters.rig.min_trusted_strength, // double min_combo_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity, // 4.0 -> change to rig_trust
clt_parameters.rig.trusted_tolerance, // double trusted_tolerance,
......@@ -1958,6 +1960,7 @@ if (debugLevel > -100) return true; // temporarily !
trusted_infinity = getTrustedDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
true, // boolean use_individual,
clt_parameters.rig.min_trusted_strength, // double min_combo_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity, // 4.0 -> change to rig_trust
clt_parameters.rig.trusted_tolerance, // double trusted_tolerance,
......@@ -2024,6 +2027,7 @@ if (debugLevel > -100) return true; // temporarily !
boolean [] trusted_near = getTrustedDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
true, // boolean use_individual,
0.5*clt_parameters.rig.min_trusted_strength, // double min_combo_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity, // 4.0 -> change to rig_trust
clt_parameters.rig.trusted_tolerance, // double trusted_tolerance,
......@@ -2069,6 +2073,7 @@ if (debugLevel > -100) return true; // temporarily !
trusted_near = getTrustedDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
true, // boolean use_individual,
clt_parameters.rig.min_trusted_strength, // double min_combo_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity, // 4.0 -> change to rig_trust
clt_parameters.rig.trusted_tolerance, // double trusted_tolerance,
......@@ -2206,6 +2211,7 @@ if (debugLevel > -100) return true; // temporarily !
trusted_near = getTrustedDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
true, // boolean use_individual,
clt_parameters.rig.min_trusted_strength, // double min_combo_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity, // 4.0 -> change to rig_trust
clt_parameters.rig.trusted_tolerance, // double trusted_tolerance,
......@@ -2261,7 +2267,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; // maximal number of adding new tiles cycles while "crossing the gaps)
// final int num_cross_gaps_cycles = 12+ (num_simple_expand_cysles * dxy.length); // 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();
......@@ -2289,6 +2295,8 @@ if (debugLevel > -100) return true; // temporarily !
quadCLT_main.image_name+"-BISCAN_initial");
}
int [][] dxy = {{0, -1},{0,1},{-1,0},{1,0}};
int num_simple_expand_cysles = 8;
final int num_cross_gaps_cycles = 12 + (num_simple_expand_cysles * dxy.length); // maximal number of adding new tiles cycles while "crossing the gaps)
for (int num_fcycle = 0; num_fcycle < num_full_cycles; num_fcycle++) {
// Grow tiles, cross gaps (do not trim yet
//
......@@ -2332,12 +2340,12 @@ if (debugLevel > -100) return true; // temporarily !
* @return array of 3 numbers: number of trusted strong tiles, number of additional trusted by plane fitting, and number of all
* somewhat strong tiles
*/
if (debugLevel > -2) {
if (debugLevel > -4) {
System.out.println("groundTruthByRigPlanes() grow pass "+num_cycle+" of "+ num_cross_gaps_cycles+
" strong trusted: "+trusted_stats[0]+ " neib trusted: "+trusted_stats[1]+" weak trusted: " + trusted_stats[2]);
}
int num_added_tiles =0;
if (num_cycle < 2*dxy.length) {
if (num_cycle < num_simple_expand_cysles * dxy.length) {
// simple duplicating one step in 4 directions
num_added_tiles = last_scan.suggestNewScan(
dxy[num_cycle % dxy.length], // final int [] dxy, //up,down,right,left
......@@ -2349,6 +2357,8 @@ if (debugLevel > -100) return true; // temporarily !
clt_parameters.tileX, // final int dbg_x,
clt_parameters.tileY, // final int dbg_y,
debugLevel); // final int debugLevel);
//TODO: add expanding FG over existing BG. Use "Strong enough" for FG to beat BG. Maybe expand by multiple steps?
} else {
// suggest new disparities, using plane surfaces (extending around that may cause false surfaces)
......@@ -2399,28 +2409,29 @@ if (debugLevel > -100) return true; // temporarily !
clt_parameters.tileY, // final int dbg_y,
debugLevel); // final int debugLevel);
}
if (debugLevel > -2) {
if (debugLevel > -4) {
System.out.println("groundTruthByRigPlanes() full cycle = "+num_fcycle+", grow pass "+num_cycle+" of "+ num_cross_gaps_cycles+
" suggestNewScan() -> "+num_added_tiles);
}
//num_cycle < num_cross_gaps_cycles;
boolean last_cycle = (num_added_tiles < min_cross_gaps_new) || (num_cycle >= (num_cross_gaps_cycles-1));
// boolean last_cycle = (num_added_tiles < min_cross_gaps_new) || (num_cycle >= (num_cross_gaps_cycles-1));
boolean last_cycle = ((num_added_tiles < min_cross_gaps_new) && (num_cycle >= num_simple_expand_cysles * dxy.length)) || (num_cycle >= (num_cross_gaps_cycles-1));
if (clt_parameters.show_map && (debugLevel > -2) && clt_parameters.rig.rig_mode_debug){
if (last_cycle) // || (num_cycle < 2 * dxy.length))
biCamDSI.getLastBiScan(BiScan.BISCAN_SINGLECORR).showScan(
quadCLT_main.image_name+"-BISCAN_SUGGESTED"+num_fcycle+"-"+num_cycle);
if (last_cycle) // || (num_cycle < 2 * dxy.length))
biCamDSI.getLastBiScan(BiScan.BISCAN_SINGLECORR).showScan(
quadCLT_main.image_name+"-BISCAN_SUGGESTED"+num_fcycle+"-"+num_cycle);
}
if (last_cycle && clt_parameters.rig.pf_en_trim_fg) { // last cycle and trimming enabled
if (debugLevel > -2) {
if (debugLevel > -4) {
// System.out.println("groundTruthByRigPlanes(): num_added_tiles= "+num_added_tiles+" > "+min_cross_gaps_new+", done growing over gaps");
System.out.println("groundTruthByRigPlanes(): that was the last growing over gaps cycle, performing trimming hanging weak FG over BG");
}
/*
* Disable low-textured tiles are not between strong tiles, but on one side of it.
* This method relies on the assumption that FG edge should bave strong correlation, so it tries multiple directions
* from the weak (not trusted strong) tiles and trims tiles that eithre do not have anything in that direction or have
* This method relies on the assumption that FG edge should have strong correlation, so it tries multiple directions
* from the weak (not trusted strong) tiles and trims tiles that either do not have anything in that direction or have
* farther tiles.
* Trimming(disabling) weak (trusted but not strong_trusted) tiles if on any one side:
* a) there are no same plane or closer tiles
......@@ -2455,7 +2466,7 @@ if (debugLevel > -100) return true; // temporarily !
clt_parameters.tileX, // final int dbg_x,
clt_parameters.tileY, // final int dbg_y,
debugLevel); // final int debugLevel);
if (debugLevel > -2) {
if (debugLevel > -4) {
System.out.println("groundTruthByRigPlanes(): full cycle="+num_fcycle+" num_trimmed= "+num_trimmed+" tiles");
}
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){
......@@ -2498,7 +2509,7 @@ if (debugLevel > -100) return true; // temporarily !
clt_parameters.tileX, // final int dbg_x,
clt_parameters.tileY, // final int dbg_y,
debugLevel); // final int debugLevel);
if (debugLevel > -2) {
if (debugLevel > -4) {
System.out.println("groundTruthByRigPlanes() full cycle = "+num_fcycle+", grow pass "+num_cycle+" of "+ num_cross_gaps_cycles+
" suggestNewScan() -> "+num_added_tiles_trimmed+"( after trimming)");
}
......@@ -2529,10 +2540,13 @@ if (debugLevel > -100) return true; // temporarily !
// refine measurements
int [] num_new = new int[1];
// at least for small separation FG/BG individual cameras may not provide trusted results - ignore them only use rig
boolean [] trusted_measurements = getTrustedDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters.rig.min_trusted_strength, // double min_combo_strength, // check correlation strength combined for all 3 correlations
// false, // boolean use_individual,
true, // boolean use_individual,
0.8*clt_parameters.rig.min_trusted_strength, // double min_combo_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity, // 4.0 -> change to rig_trust
clt_parameters.rig.trusted_tolerance, // double trusted_tolerance,
null, // boolean [] was_trusted,
......@@ -2576,15 +2590,17 @@ if (debugLevel > -100) return true; // temporarily !
prev_bimap = disparity_bimap;
disparity_bimap = disparity_bimap_new;
trusted_measurements = getTrustedDisparityInter(
0.0, // clt_parameters.rig.lt_trusted_strength*clt_parameters.rig.lt_need_friends, // double min_inter_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity,
trusted_measurements, // boolean [] was_trusted,
disparity_bimap ); // double [][] bimap // current state of measurements
0.0, // clt_parameters.rig.lt_trusted_strength*clt_parameters.rig.lt_need_friends, // double min_inter_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity,
trusted_measurements, // boolean [] was_trusted,
disparity_bimap ); // double [][] bimap // current state of measurements
if (debugLevel > -2) {
System.out.println("groundTruthByRigPlanes(): cycle="+num_cycle+", refinement step="+nref+" num_new= "+num_new[0]+" tiles");
}
if (num_new[0] < clt_parameters.rig.pf_min_new) break;
if (num_new[0] < clt_parameters.rig.pf_min_new) {
break;
}
}
......@@ -2627,7 +2643,7 @@ if (debugLevel > -100) return true; // temporarily !
// add refined data
biCamDSI.addBiScan(disparity_bimap, BiScan.BISCAN_SINGLECORR);
// find strongest
// find strongest if FG over BG - not the strongest, but either strongest or just strong and nearer
biCamDSI.getLastBiScan(BiScan.BISCAN_SINGLECORR).copyLastStrongestEnabled(
clt_parameters.rig.pf_last_priority); // final boolean last_priority)
......@@ -2645,7 +2661,25 @@ if (debugLevel > -100) return true; // temporarily !
if (num_replaced == 0) {
break;
}
}
}
double fg_str_good_enough = clt_parameters.rig.pf_trusted_strength * 0.6; // 4; // absolute strength floor for good enough
double fg_min_FGtoBG = 1.0; // minimal disparity difference over
double fg_disp_atolerance = 0.1; // Maximal absolute disparity difference to qualifying neighbor
double fg_disp_rtolerance = 0.02; // Maximal relative (to absolute disparity) disparity difference to qualifying neighbor
int fg_min_neib = 2; // minimal number of qualifying neighbors to promote FG tile
// promote thin FG objects over even stronger BG ones (as thin stick in FG over textured BG)
int num_replaced_fg = biCamDSI.getLastBiScan(BiScan.BISCAN_SINGLECORR).copyStrongFGEnabled(
fg_str_good_enough, // final double str_good_enough, // absolute strength floor for good enough
fg_min_FGtoBG, // final double min_FGtoBG, // minimal disparity difference over
fg_disp_atolerance, // final double disp_atolerance, // = 0.1; // Maximal absolute disparity difference to qualifying neighbor
fg_disp_rtolerance, // final double disp_rtolerance, // = 0.02; // Maximal relative (to absolute disparity) disparity difference to qualifying neighbor
fg_min_neib); // final int min_neib) // minimal number of qualifying neighbors to promote FG tile
// if ((debugLevel > -2) && clt_parameters.rig.rig_mode_debug){
if ((debugLevel > -4)){
System.out.println("groundTruthByRigPlanes(): Replacing BG with FG tiles, replaced "+num_replaced_fg+" tiles");
}
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){
biCamDSI.getLastBiScan(BiScan.BISCAN_SINGLECORR).showScan(
......@@ -2657,8 +2691,14 @@ if (debugLevel > -100) return true; // temporarily !
}
break;
}
// public void showScan(String title) {
// public void showScan(String title) {
if (debugLevel > -2){
System.out.println("groundTruthByRigPlanes(): num_cycle="+num_cycle);
}
} // for (int num_cycle = 0; num_cycle < num_cross_gaps_cycles; num_cycle++) {
if (debugLevel > -2){
System.out.println("groundTruthByRigPlanes(): num_fcycle="+num_fcycle);
}
}// for (int num_fcycle = 0; num_fcycle < num_full_cycles; num_fcycle++) {
......@@ -3248,6 +3288,27 @@ if (debugLevel > -100) return true; // temporarily !
}
}
double fg_str_good_enough = trusted_strength * 0.4; // absolute strength floor for good enough
double fg_min_FGtoBG = 1.0; // minimal disparity difference over
double fg_disp_atolerance = 0.1; // Maximal absolute disparity difference to qualifying neighbor
double fg_disp_rtolerance = 0.02; // Maximal relative (to absolute disparity) disparity difference to qualifying neighbor
int fg_min_neib = 2; // minimal number of qualifying neighbors to promote FG tile
// promote thin FG objects over even stronger BG ones (as thin stick in FG over textured BG)
int num_replaced_fg = biCamDSI_persistent.getLastBiScan(BiScan.BISCAN_SINGLECORR).copyStrongFGEnabled(
fg_str_good_enough, // final double str_good_enough, // absolute strength floor for good enough
fg_min_FGtoBG, // final double min_FGtoBG, // minimal disparity difference over
fg_disp_atolerance, // final double disp_atolerance, // = 0.1; // Maximal absolute disparity difference to qualifying neighbor
fg_disp_rtolerance, // final double disp_rtolerance, // = 0.02; // Maximal relative (to absolute disparity) disparity difference to qualifying neighbor
fg_min_neib); // final int min_neib) // minimal number of qualifying neighbors to promote FG tile
// if ((debugLevel > -2) && clt_parameters.rig.rig_mode_debug){
if ((debugLevel > -2)){
System.out.println("groundTruthByRigPlanes(): Replacing BG with FG tiles, replaced "+num_replaced_fg+" tiles");
}
biScan.calcTrusted( // finds strong trusted and validates week ones if they fit planes
trusted_strength, // final double trusted_strength, // trusted correlation strength
strength_rfloor, // final double strength_rfloor, // strength floor - relative to trusted
......@@ -4393,6 +4454,7 @@ if (debugLevel > -100) return true; // temporarily !
boolean [] getTrustedDisparity(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
boolean use_individual,
double min_combo_strength, // check correlation strength combined for all 3 correlations
double max_trusted_disparity,
double trusted_tolerance,
......@@ -4405,12 +4467,20 @@ if (debugLevel > -100) return true; // temporarily !
if (trusted_main < trusted_tolerance) trusted_main = trusted_tolerance;
if (trusted_aux < trusted_tolerance) trusted_aux = trusted_tolerance;
boolean [] trusted = new boolean [bimap[ImageDtt.BI_DISP_CROSS_INDEX].length];
for (int i = 0; i < trusted.length; i++) {
trusted[i] = (Math.abs(bimap[ImageDtt.BI_DISP_CROSS_INDEX][i]) <= trusted_inter) &&
(Math.abs(bimap[ImageDtt.BI_DISP_FULL_INDEX][i]) <= trusted_main) &&
(Math.abs(bimap[ImageDtt.BI_ADISP_FULL_INDEX][i]) <= trusted_aux) &&
(bimap[ImageDtt.BI_STR_ALL_INDEX][i] >= min_combo_strength) &&
((was_trusted == null) || was_trusted[i]);
if (use_individual) {
for (int i = 0; i < trusted.length; i++) {
trusted[i] = (Math.abs(bimap[ImageDtt.BI_DISP_CROSS_INDEX][i]) <= trusted_inter) &&
(Math.abs(bimap[ImageDtt.BI_DISP_FULL_INDEX][i]) <= trusted_main) &&
(Math.abs(bimap[ImageDtt.BI_ADISP_FULL_INDEX][i]) <= trusted_aux) &&
(bimap[ImageDtt.BI_STR_ALL_INDEX][i] >= min_combo_strength) &&
((was_trusted == null) || was_trusted[i]);
}
} else {
for (int i = 0; i < trusted.length; i++) {
trusted[i] = (Math.abs(bimap[ImageDtt.BI_DISP_CROSS_INDEX][i]) <= trusted_inter) &&
(bimap[ImageDtt.BI_STR_CROSS_INDEX][i] >= min_combo_strength) &&
((was_trusted == null) || was_trusted[i]);
}
}
return trusted;
}
......
......@@ -224,7 +224,8 @@ public class X3dOutput {
public double [][] getBBox() // center: x,y,z, size:x,y,z
{
double depth = geometry_correction.getZFromDisparity(clt_parameters.bgnd_range);
// double depth = geometry_correction.getZFromDisparity(clt_parameters.bgnd_range);
double depth = clt_parameters.infinityDistance;
double width = depth * geometry_correction.getFOVWidth();
double height = depth * geometry_correction.getFOVHeight();
double [][] bbox = {{0, 0, -depth/2},{width,height,depth}};
......
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