Commit c44613be authored by Andrey Filippov's avatar Andrey Filippov

changing connection costs calculation

parent 67228555
......@@ -2022,7 +2022,7 @@ public class EyesisCorrectionParameters {
public double bgnd_sure = 0.18; // minimal strength to be considered definitely background
public double bgnd_maybe = 0.1; // maximal strength to ignore as non-background
// public double bgnd_2diff = 0.005; // maximal strength to ignore as non-background
public int min_clstr_seed = 2; // number of tiles in a cluster to seed (just background?)
public int min_clstr_seed = 4; //2; // number of tiles in a cluster to seed (just background?)
public int min_clstr_lone = 4; // number of tiles in a cluster not close to other clusters (more than 2 tiles apart)
public double min_clstr_weight = 0.0; // Minimal total strength of the cluster
public double min_clstr_max = 0.25; // Minimal maximal strength of the cluster
......@@ -2149,7 +2149,7 @@ public class EyesisCorrectionParameters {
// Multi-pass growing disparity
public int grow_sweep = 8; // Try these number of tiles around known ones
public double grow_disp_max = 50.0; // Maximal disparity to try
public double grow_disp_max = 100.0; // Maximal disparity to try
public double grow_disp_trust = 4.0; // Trust measured disparity within +/- this value
public double grow_disp_step = 6.0; // Increase disparity (from maximal tried) if nothing found in that tile // TODO: handle enclosed dips?
public double grow_min_diff = 0.5; // Grow more only if at least one channel has higher variance from others for the tile
......@@ -2170,6 +2170,8 @@ public class EyesisCorrectionParameters {
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
public double plEigenStick = 25.0; // Consider plane to be a "stick" if second eigenvalue is below
public double plBadPlate = 0.2; // Not a plate if sin^2 between normals from disparity and world exceeds this
public boolean plDbgMerge = true; // Combine 'other' plane with current
public double plWorstWorsening = 2.0; // Worst case worsening after merge
public double plWorstWorsening2 = 5.0; // Worst case worsening for thin planes
......@@ -2583,6 +2585,8 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plMinStrength", this.plMinStrength +"");
properties.setProperty(prefix+"plMaxEigen", this.plMaxEigen +"");
properties.setProperty(prefix+"plEigenFloor", this.plEigenFloor +"");
properties.setProperty(prefix+"plEigenStick", this.plEigenStick +"");
properties.setProperty(prefix+"plBadPlate", this.plBadPlate +"");
properties.setProperty(prefix+"plDbgMerge", this.plDbgMerge+"");
properties.setProperty(prefix+"plWorstWorsening", this.plWorstWorsening +"");
properties.setProperty(prefix+"plWorstWorsening2",this.plWorstWorsening2 +"");
......@@ -2971,6 +2975,8 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plMinStrength")!=null) this.plMinStrength=Double.parseDouble(properties.getProperty(prefix+"plMinStrength"));
if (properties.getProperty(prefix+"plMaxEigen")!=null) this.plMaxEigen=Double.parseDouble(properties.getProperty(prefix+"plMaxEigen"));
if (properties.getProperty(prefix+"plEigenFloor")!=null) this.plEigenFloor=Double.parseDouble(properties.getProperty(prefix+"plEigenFloor"));
if (properties.getProperty(prefix+"plEigenStick")!=null) this.plEigenStick=Double.parseDouble(properties.getProperty(prefix+"plEigenStick"));
if (properties.getProperty(prefix+"plBadPlate")!=null) this.plBadPlate=Double.parseDouble(properties.getProperty(prefix+"plBadPlate"));
if (properties.getProperty(prefix+"plDbgMerge")!=null) this.plDbgMerge=Boolean.parseBoolean(properties.getProperty(prefix+"plDbgMerge"));
if (properties.getProperty(prefix+"plWorstWorsening")!=null) this.plWorstWorsening=Double.parseDouble(properties.getProperty(prefix+"plWorstWorsening"));
if (properties.getProperty(prefix+"plWorstWorsening2")!=null) this.plWorstWorsening2=Double.parseDouble(properties.getProperty(prefix+"plWorstWorsening2"));
......@@ -3157,7 +3163,7 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Do not try to correct vignetting smaller than this fraction of max", this.vignetting_range, 3);
gd.addNumericField("Kernel step in pixels (has 1 kernel margin on each side)", this.kernel_step, 0);
gd.addNumericField("Nominal (rectilinear) disparity between side of square cameras (pix)", this.disparity, 3);
gd.addCheckbox ("Perfcorm coorrelation", this.correlate);
gd.addCheckbox ("Perform correlation", this.correlate);
gd.addNumericField("itmask of pairs to combine in the composite (top, bottom, left,righth)", this.corr_mask, 0);
gd.addCheckbox ("Combine correlation with mirrored around disparity direction", this.corr_sym);
gd.addCheckbox ("Keep all partial correlations (otherwise - only combined one)", this.corr_keep);
......@@ -3387,6 +3393,8 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Minimal total strength of a plane", this.plMinStrength, 6);
gd.addNumericField("Maximal eigenvalue of a plane", this.plMaxEigen, 6);
gd.addNumericField("Add to eigenvalues of each participating plane and result to validate connections",this.plEigenFloor, 6);
gd.addNumericField("Consider plane to be a \"stick\" if second eigenvalue is below", this.plEigenStick, 6);
gd.addNumericField("Not a plate if sin^2 between normals from disparity and world exceeds this", this.plBadPlate, 6);
gd.addCheckbox ("Combine 'other' plane with the current (unused)", this.plDbgMerge);
gd.addNumericField("Worst case worsening after merge", this.plWorstWorsening, 6);
gd.addNumericField("Worst case worsening for thin planes", this.plWorstWorsening2, 6);
......@@ -3792,6 +3800,8 @@ public class EyesisCorrectionParameters {
this.plMinStrength= gd.getNextNumber();
this.plMaxEigen= gd.getNextNumber();
this.plEigenFloor= gd.getNextNumber();
this.plEigenStick= gd.getNextNumber();
this.plBadPlate= gd.getNextNumber();
this.plDbgMerge= gd.getNextBoolean();
this.plWorstWorsening= gd.getNextNumber();
this.plWorstWorsening2= gd.getNextNumber();
......@@ -4484,7 +4494,7 @@ public class EyesisCorrectionParameters {
public double projectionYaw= 0.0;
public double projectionRoll= 0.0;
public boolean matchPixelSize= true; // disregard next value, calculate projectionPixelSize from teh equirectangular map
public boolean matchPixelSize= true; // disregard next value, calculate projectionPixelSize from the equirectangular map
public double projectionPixelSize=0.00044036902;
public int projectionWidth= 2920;
public int projectionHeight= 2220;
......
......@@ -499,7 +499,7 @@ private Panel panel1,
addButton("CLT process files", panelClt1, color_process);
addButton("CLT process sets", panelClt1, color_process);
addButton("CLT process quads", panelClt1, color_process);
addButton("CLT process corr", panelClt1, color_process);
addButton("CLT process corr", panelClt1, color_conf_process);
addButton("CLT disparity scan", panelClt1, color_conf_process);
addButton("CLT reset fine corr", panelClt1, color_stop);
addButton("CLT show fine corr", panelClt1, color_configure);
......
......@@ -35,7 +35,8 @@ public class LinkPlanes {
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; // = 20.0; // Consider plane to be a "stick" if second eigenvalue is below
public double plEigenStick; // = 25.0; // Consider plane to be a "stick" if second eigenvalue is below
public double plBadPlate; // = 0.2; // Not a plate if sin^2 between normals from disparity and world exceeds this
public double plWorstWorsening; // = 2.0; // Worst case worsening after merge
public double plWorstWorsening2; // = 5.0; // Worst case worsening for thin planes
......@@ -95,6 +96,7 @@ public class LinkPlanes {
plMaxEigen = clt_parameters.plMaxEigen;
plEigenFloor = clt_parameters.plEigenFloor;
plEigenStick = clt_parameters.plEigenStick;
plBadPlate = clt_parameters.plBadPlate;
plMinStrength = clt_parameters.plMinStrength;
plMaxOverlap = clt_parameters.plMaxOverlap;
......@@ -473,6 +475,7 @@ public class LinkPlanes {
// 2 - composite
// 3..7 contribution of each of the factor to the overall cost
public double getLinkCost(
boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
TilePlanes.PlaneData plane2,
double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -484,6 +487,7 @@ public class LinkPlanes {
int cost_index = 2;
double [] costs = getFitQualities(
en_sticks, // boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
plane1, // should belong to the same supertile (or be converted for one)
plane2,
merged_ev, // if NaN will calculate assuming the same supertile
......@@ -496,6 +500,7 @@ public class LinkPlanes {
else return costs[cost_index];
}
public double [] getFitQualities(
boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
TilePlanes.PlaneData plane2,
double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -506,6 +511,18 @@ public class LinkPlanes {
int debugLevel)
{
if ((plane1 == null) || (plane2 == null)) return null;
boolean plate1 = true;
boolean plate2 = true;
if (en_sticks) {
plate1 &= (plane1.getValues()[1] >= plEigenStick);
plate2 &= (plane1.getValues()[1] >= plEigenStick);
plate1 &= (plane1.checkBadPlate(true) < plBadPlate);
plate2 &= (plane2.checkBadPlate(true) < plBadPlate);
}
if ((debugLevel > 0) && (!plate1 || !plate2)) {
System.out.println(prefix+ " plate1="+plate1+", plate1="+plate2+" ("+(plane1.getValues()[1])+", "+plane2.getValues()[1]+" < "+plEigenStick+")"+
" or bad_plate1="+plane1.checkBadPlate(true)+" bad_plate2="+plane2.checkBadPlate(true)+" >= plBadPlate="+plBadPlate);
}
TilePlanes.PlaneData merged_pd = null;
TilePlanes.PlaneData merged_pd_eq = null;
if (Double.isNaN(merged_ev) || Double.isNaN(merged_wev)) {
......@@ -579,14 +596,25 @@ public class LinkPlanes {
// if (this_wrq_eq == 0.01) System.out.println("getFitQualities(): this_wrq_eq was negative");
double sin2 = plane1.getWorldSin2(plane2);
double rdist2 = plane1.getWorldPlaneRDist2(plane2) + plane2.getWorldPlaneRDist2(plane1);
if (!plate2 && plate1){
rdist2 = 2 * plane2.getWorldPlaneRDist2(plane1);
} else if (plate2 && plate1){
rdist2 = 2 * plane1.getWorldPlaneRDist2(plane2);
}
double [] costs = {
this_rq * plCostKrq,
this_rq_eq * plCostKrqEq,
this_wrq * plCostWrq,
this_wrq_eq * plCostWrqEq,
Math.sqrt(this_rq * this_rq_eq) * plCostKrq,
0.5 * (this_rq + this_rq_eq) * plCostKrqEq,
Math.sqrt(this_wrq * this_wrq_eq) * plCostWrq,
0.5 * (this_wrq + this_wrq_eq) * plCostWrqEq,
sin2 * plCostSin2,
rdist2 * plCostRdist2};
double cost = costs[0]+costs[1]+costs[2]+costs[3]+costs[4]+costs[5];
double cost = costs[0]+costs[1]+costs[2]+costs[3];
if (plate1 && plate2){
cost += costs[4]; // sin
}
if (plate1 || plate2){
cost += costs[5]; // distance
}
double [] qualities = {
this_rq,
this_rq_eq,
......@@ -610,13 +638,13 @@ public class LinkPlanes {
((int)(100*qualities[8]))+"%");
System.out.println(prefix+
" this_rq=" + this_rq+
" this_wrq=" + (this_wrq) +
" this_wrq_eq=" + (this_wrq_eq) +
" this_wrq_raw=" + (this_wrq * (w1+w2)) +
" this_wrq_eq_raw=" + (this_wrq_eq * (w1+w2)) +
" this_rq_raw="+(this_rq * (w1+w2)) +
" this_rq_eq="+(this_rq_eq) +
" this_rq_nofloor="+(this_rq_nofloor) +
" this_wrq=" + (this_wrq) +
" this_wrq_eq=" + (this_wrq_eq) +
// " this_wrq_raw=" + (this_wrq * (w1+w2)) +
// " this_wrq_eq_raw=" + (this_wrq_eq * (w1+w2)) +
// " this_rq_raw="+(this_rq * (w1+w2)) +
" w1="+w1+" w2="+w2+
" L1="+plane1.getValue()+" L2="+plane2.getValue()+" L="+merged_ev+
" L_eq="+merged_ev_eq+
......@@ -824,6 +852,7 @@ public class LinkPlanes {
*/
public void interPlaneCosts(
final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
final TilePlanes.PlaneData [][] planes,
final int debugLevel,
final int dbg_X,
......@@ -871,6 +900,7 @@ public class LinkPlanes {
dl-1); // debugLevel);
if (other_plane !=null) { // now always, but may add later
double link_cost = getLinkCost(
en_sticks, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
this_plane, // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
other_plane, // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -1385,6 +1415,7 @@ public class LinkPlanes {
}
public void setNonExclusive(
final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
final TilePlanes.PlaneData [][] planes,
// final double center_weight,
final int debugLevel,
......@@ -1437,6 +1468,7 @@ public class LinkPlanes {
debugLevel - 2); // debugLevel);
if (other_plane != null) {
costs_dir[np] = getFitQualities(
en_sticks, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np0], // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
other_plane, // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -1537,6 +1569,7 @@ public class LinkPlanes {
this_new_plane.setWeight(0.0); //
double num_merged = 0.0; // double to add fractional pull weight of the center
double true_num_merged = 0.0;
for (int dir = 0; dir < neibs_pd.length; dir++){
if (neibs_pd[dir] != null) {
TilePlanes.PlaneData other_plane = this_new_plane.getPlaneToThis(
......@@ -1561,6 +1594,7 @@ public class LinkPlanes {
}
if (this_new_plane != null){
num_merged += 1.0;
true_num_merged += 1.0;
// just for debug / calculate
this_new_plane.getWorldXYZ(0);
}
......@@ -1580,6 +1614,7 @@ public class LinkPlanes {
double scale = Math.pow(num_merged, normPow);
this_new_plane.scaleWeight(1.0/scale);
num_merged /=scale;
true_num_merged /= scale;
}
......@@ -1599,10 +1634,12 @@ public class LinkPlanes {
debugLevel - 2); // int debugLevel)
if (this_new_plane != null){
num_merged += center_weight; // num_merged was 1.0 and weight is averaged over all neighbors
true_num_merged += 1.0;
}
} else {
this_new_plane = center_pd.clone();
num_merged = 1.0;
true_num_merged = 1.0;
}
// if (dl > 0) dbg_img[18] = this_new_plane.getSinglePlaneDisparity(false);
}
......@@ -1611,8 +1648,8 @@ public class LinkPlanes {
// just for debug / calculate
this_new_plane.getWorldXYZ(0);
this_new_plane.scaleWeight(1.0/num_merged);
double true_num_merged = num_merged - center_weight + 1;
this_new_plane.setNumPoints((int) (this_new_plane.getNumPoints()/true_num_merged));
// double true_num_merged = num_merged - center_weight + 1;
this_new_plane.setNumPoints((int) Math.round(this_new_plane.getNumPoints()/true_num_merged));
}
return this_new_plane;
......@@ -1628,6 +1665,7 @@ public class LinkPlanes {
* @param dbg_Y debug supertile Y coordinate
*/
public double [][] selectNeighborPlanesMutual(
final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
final TilePlanes.PlaneData [][] planes,
final int debugLevel,
final int dbg_X,
......@@ -1644,8 +1682,6 @@ public class LinkPlanes {
for (int i = 0; i < nan_plane.length; i++) nan_plane[i] = Double.NaN;
final int [][] dirsYX = {{-1, 0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};
final int debug_stile = dbg_Y * stilesX + dbg_X;
final Thread[] threads = ImageDtt.newThreadArray(st.tileProcessor.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger ai_numThread = new AtomicInteger(0);
......@@ -1722,6 +1758,7 @@ public class LinkPlanes {
if (!other_matched[np] && merge_valid[np]) {
String prefix = "selectNeighborPlanesMutual(): nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np;
qualities[np0][np] = getFitQualities( // {this_rq, this_rq_eq};
en_sticks, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np0], //TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile][np], //TilePlanes.PlaneData plane2,
merge_ev[np], // double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -2397,7 +2434,8 @@ public class LinkPlanes {
Double.NaN, // double merged_wev_eq, // if NaN will calculate assuming the same supertile - for world
prefix, // String prefix,
dl -1); // int debugLevel)
if (!fit1 || !fit2){
// if (!fit1 || !fit2){
if (!fit1 && !fit2){
valid_candidates[nsTile0][np1][np2] = false;
valid_candidates[nsTile0][np2][np1] = false;
if (dl > -1){
......@@ -2413,8 +2451,9 @@ public class LinkPlanes {
}
if (dl>0){
double [][] costs = new double[2][];
double [][] costs = new double[6][];
costs[0] = getFitQualities(
true, // en_sticks, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -2422,8 +2461,9 @@ 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
nsTile0+":"+np1+":"+np2, // String prefix,
0); // int debugLevel)
dl); // 0); // int debugLevel)
costs[1] = getFitQualities(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -2431,7 +2471,48 @@ 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
nsTile0+":"+np1+":"+np2, // String prefix,
0); // int debugLevel)
dl); // 0); // int debugLevel)
costs[2] = getFitQualities(
true, // en_sticks, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2], // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
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
nsTile0+":"+np1+":"+np2, // String prefix,
dl); // 0); // int debugLevel)
costs[3] = getFitQualities(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2], // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
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
nsTile0+":"+np1+":"+np2, // String prefix,
dl); // 0); // int debugLevel)
costs[4] = getFitQualities(
true, // en_sticks, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1], // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
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
nsTile0+":"+np1+":"+np2, // String prefix,
dl); // 0); // int debugLevel)
costs[5] = getFitQualities(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1], // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
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
nsTile0+":"+np1+":"+np2, // String prefix,
dl); // 0); // int debugLevel)
System.out.println("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs:");
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs weighted: ");
for (int i = 0; i < costs[0].length;i++) {
......@@ -2443,6 +2524,27 @@ public class LinkPlanes {
System.out.print(costs[1][i]+" ");
}
System.out.println();
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs weighted, 1-st star, 2-nd measured: ");
for (int i = 0; i < costs[2].length;i++) {
System.out.print(costs[2][i]+" ");
}
System.out.println();
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs equalized, 1-st star, 2-nd measured: ");
for (int i = 0; i < costs[3].length;i++) {
System.out.print(costs[3][i]+" ");
}
System.out.println();
System.out.println();
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs weighted, 1-st measured, 2-nd star: ");
for (int i = 0; i < costs[4].length;i++) {
System.out.print(costs[4][i]+" ");
}
System.out.println();
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs equalized, 1-st measured, 2-nd star: ");
for (int i = 0; i < costs[5].length;i++) {
System.out.print(costs[5][i]+" ");
}
System.out.println();
}
}
}
......@@ -2492,6 +2594,7 @@ public class LinkPlanes {
String prefix = "costSameTileConnectionsAlt() fit weighted: nsTile0="+nsTile0+" np1="+np1+" np2="+np2;
double [] costs = new double[2];
costs[0] = getLinkCost(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -2499,9 +2602,10 @@ 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,
0); // int debugLevel)
dl); // int debugLevel)
prefix = "costSameTileConnectionsAlt() fit equal weight: nsTile0="+nsTile0+" np1="+np1+" np2="+np2;
costs[1] = getLinkCost(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -2509,12 +2613,13 @@ 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,
0); // int debugLevel)
dl); // int debugLevel)
boolean star1 = (planes[nsTile0][np1].getNonexclusiveStar() != null) && (planes[nsTile0][np2].getNonexclusiveStar() != null);
boolean star2 = (planes[nsTile0][np1].getNonexclusiveStarEq() != null) && (planes[nsTile0][np2].getNonexclusiveStarEq() != null);
boolean fit1 = costs[0] < (star1 ? threshold : threshold_nostar);
boolean fit2 = costs[1] < (star2 ? threshold : threshold_nostar);
if (!fit1 || !fit2){
// if (!fit1 || !fit2){
if (!fit1 && !fit2){
valid_candidates[nsTile0][np1][np2] = false;
valid_candidates[nsTile0][np2][np1] = false;
if (dl > -1){
......@@ -2528,8 +2633,9 @@ public class LinkPlanes {
}
}
if (dl>0){
double [][] costs0 = new double[2][];
double [][] costs0 = new double[6][];
costs0[0] = getFitQualities(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -2537,8 +2643,9 @@ 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
nsTile0+":"+np1+":"+np2, // String prefix,
0); // int debugLevel)
dl); // int debugLevel)
costs0[1] = getFitQualities(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -2546,7 +2653,85 @@ 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
nsTile0+":"+np1+":"+np2, // String prefix,
0); // int debugLevel)
dl); // int debugLevel)
costs0[2] = getFitQualities(
true, // en_sticks, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2], // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
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
nsTile0+":"+np1+":"+np2, // String prefix,
dl); // 0); // int debugLevel)
costs0[3] = getFitQualities(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2], // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
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
nsTile0+":"+np1+":"+np2, // String prefix,
dl); // 0); // int debugLevel)
costs0[4] = getFitQualities(
true, // en_sticks, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1], // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
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
nsTile0+":"+np1+":"+np2, // String prefix,
dl); // 0); // int debugLevel)
costs0[5] = getFitQualities(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile0][np1], // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
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
nsTile0+":"+np1+":"+np2, // String prefix,
dl); // 0); // int debugLevel)
System.out.println("costSameTileConnectionsAlt(): nsTile="+nsTile0+":"+np1+":"+np2+" costs:");
System.out.print("costSameTileConnectionsAlt(): nsTile="+nsTile0+":"+np1+":"+np2+" costs weighted: ");
for (int i = 0; i < costs0[0].length;i++) {
System.out.print(costs0[0][i]+" ");
}
System.out.println();
System.out.print("costSameTileConnectionsAlt(): nsTile="+nsTile0+":"+np1+":"+np2+" costs equalized: ");
for (int i = 0; i < costs0[1].length;i++) {
System.out.print(costs0[1][i]+" ");
}
System.out.println();
System.out.print("costSameTileConnectionsAlt(): nsTile="+nsTile0+":"+np1+":"+np2+" costs weighted, 1-st star, 2-nd measured: ");
for (int i = 0; i < costs0[2].length;i++) {
System.out.print(costs0[2][i]+" ");
}
System.out.println();
System.out.print("costSameTileConnectionsAlt(): nsTile="+nsTile0+":"+np1+":"+np2+" costs equalized, 1-st star, 2-nd measured: ");
for (int i = 0; i < costs0[3].length;i++) {
System.out.print(costs0[3][i]+" ");
}
System.out.println();
System.out.println();
System.out.print("costSameTileConnectionsAlt(): nsTile="+nsTile0+":"+np1+":"+np2+" costs weighted, 1-st measured, 2-nd star: ");
for (int i = 0; i < costs0[4].length;i++) {
System.out.print(costs0[4][i]+" ");
}
System.out.println();
System.out.print("costSameTileConnectionsAlt(): nsTile="+nsTile0+":"+np1+":"+np2+" costs equalized, 1-st measured, 2-nd star: ");
for (int i = 0; i < costs0[5].length;i++) {
System.out.print(costs0[5][i]+" ");
}
System.out.println();
System.out.println("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs:");
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs weighted: ");
for (int i = 0; i < costs0[0].length;i++) {
......@@ -2966,6 +3151,7 @@ public class LinkPlanes {
if ((np2 > np1) && merge_pairs[np1][np2]){
String prefix = "extractMergeSameTileGroups() nsTile="+nsTile+" np1="+np1+" np2="+np2;
double [] qualities = getFitQualities( // {this_rq, this_rq_eq};
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
planes[nsTile][np1], //TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile][np2], //TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -3020,6 +3206,7 @@ public class LinkPlanes {
if (nooverlap){
String prefix = "extractMergeSameTileGroups().2 nsTile="+nsTile+" np="+np;
double [] qualities = getFitQualities( // {this_rq, this_rq_eq};
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
merged_pd, //TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile][np], //TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
......
......@@ -5526,7 +5526,7 @@ public class QuadCLT {
clt_parameters.min_clstr_block,// number of tiles in a cluster to block (just non-background?)
disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
clt_parameters.show_bgnd_nonbgnd,
(clt_parameters.debug_filters ? debugLevel : -1));
(clt_parameters.debug_filters ? (debugLevel) : -1));
boolean [] bgnd_strict = bgnd_tiles.clone(); // only these have non 0 alpha
tp.growTiles(
clt_parameters.bgnd_grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
......@@ -5568,8 +5568,6 @@ public class QuadCLT {
texture_tiles_bgnd[tileY][tileX]= texture_tiles[tileY][tileX].clone();
texture_tiles_bgnd[tileY][tileX][alpha_index] = alpha_zero;
}
}
}
}
......
......@@ -1122,7 +1122,7 @@ public class SuperTiles{
int num_p = (selections == null) ? 0: selections.length;
int num_pm = num_ml * num_p;
int num_pd = (planes != null) ? (planes.length - LOWEST_PLANE(planes.length)) : 0;
String [] titles = new String [num_pm + 3 * num_ml + 4 * num_pd];
String [] titles = new String [num_pm + 3 * num_ml + 8 * num_pd];
for (int np = 0; np < num_p; np++){
for (int ml = 0; ml < num_ml; ml++){
titles [np * num_ml + ml] = "p"+np+"_l"+ml;
......@@ -1137,7 +1137,11 @@ public class SuperTiles{
titles [num_pm + 3 * num_ml + 0 * num_pd + npd] = "pd_"+npd;
titles [num_pm + 3 * num_ml + 1 * num_pd + npd] = "pdm_"+npd;
titles [num_pm + 3 * num_ml + 2 * num_pd + npd] = "pdd_"+npd;
titles [num_pm + 3 * num_ml + 3 * num_pd + npd] = "pds_"+npd;
titles [num_pm + 3 * num_ml + 3 * num_pd + npd] = "pwd_"+npd;
titles [num_pm + 3 * num_ml + 4 * num_pd + npd] = "pds_"+npd;
titles [num_pm + 3 * num_ml + 5 * num_pd + npd] = "pws_"+npd;
titles [num_pm + 3 * num_ml + 6 * num_pd + npd] = "-pdd_"+npd;
titles [num_pm + 3 * num_ml + 7 * num_pd + npd] = "-pwd_"+npd;
}
// TilePlanes.PlaneData
......@@ -1157,7 +1161,7 @@ public class SuperTiles{
int num_pm = num_ml * num_p;
int num_pd = (planes != null) ? (planes.length - LOWEST_PLANE(planes.length)) : 0;
final double [][] lapWeight = getLapWeights();
double [][] data = new double [num_pm + 3 * num_ml + 4 * num_pd ][]; // 4* superTileSize*superTileSize];
double [][] data = new double [num_pm + 3 * num_ml + 8 * num_pd ][]; // 4* superTileSize*superTileSize];
for (int np = 0; np < num_p; np++) if (selections [np] != null){
for (int ml = 0; ml < num_ml; ml++) if ((disp_strength[ml]!=null) && (selections[np][ml] != null)){
int nd = np * num_ml + ml;
......@@ -1196,14 +1200,30 @@ public class SuperTiles{
}
for (int npd = 0; npd < num_pd; npd++) if (planes[npd +LOWEST_PLANE(planes.length)] != null){
/* double [][] ellipsoids = planes[npd +LOWEST_PLANE(planes.length)].getDoublePlaneDisparityStrength(
useWorld,
null, // double [] window,
true, // boolean use_sel,
true, // boolean divide_by_area,
1.5, // double scale_projection,
1); // int debugLevel) */
double [][] ellipsoids = planes[npd +LOWEST_PLANE(planes.length)].getDoublePlaneDisparityStrength(
useWorld,
null, // double [] window,
-1, //
true, // boolean use_sel,
true, // boolean divide_by_area,
1.5, // double scale_projection,
0.0, // double fraction_uni,
1); // int debugLevel)
double [][] ellipsoidsW = planes[npd +LOWEST_PLANE(planes.length)].getDoublePlaneWorldDisparityStrength(
null, // double [] window,
-1, //
true, // boolean use_sel,
true, // boolean divide_by_area,
1.5, // double scale_projection,
0.0, // double fraction_uni,
1); // int debugLevel)
data [num_pm + 3 * num_ml + 0 * num_pd + npd] = planes[npd +LOWEST_PLANE(planes.length)].getDoublePlaneDisparity(
useWorld,
false);
......@@ -1219,13 +1239,151 @@ public class SuperTiles{
}
}
}
if (ellipsoids != null) {
data [num_pm + 3 * num_ml + 2 * num_pd + npd] = ellipsoids[0];
data [num_pm + 3 * num_ml + 3 * num_pd + npd] = ellipsoids[1];
data [num_pm + 3 * num_ml + 4 * num_pd + npd] = ellipsoids[1];
data [num_pm + 3 * num_ml + 6 * num_pd + npd] = new double[ntiles];
for (int i = 0; i < ntiles; i++) {
for (int ml = 0; ml < num_ml; ml++) if ((disp_strength[ml]!=null) && (msel[ml] != null)){
if (msel[ml][i] && (disp_strength[ml][1][i] > 0.0)){
data [num_pm + 3 * num_ml + 6 * num_pd + npd][i] = disp_strength[ml][0][i] - ellipsoids[0][i];
} else {
data [num_pm + 3 * num_ml + 6 * num_pd + npd][i] = Double.NaN;
}
break;
}
}
}
if (ellipsoidsW != null) {
data [num_pm + 3 * num_ml + 3 * num_pd + npd] = ellipsoidsW[0];
data [num_pm + 3 * num_ml + 5 * num_pd + npd] = ellipsoidsW[1];
data [num_pm + 3 * num_ml + 7 * num_pd + npd] = new double[ntiles];
for (int i = 0; i < ntiles; i++) {
for (int ml = 0; ml < num_ml; ml++) if ((disp_strength[ml]!=null) && (msel[ml] != null)){
if (msel[ml][i] && (disp_strength[ml][1][i] > 0.0)){
data [num_pm + 3 * num_ml + 7 * num_pd + npd][i] = disp_strength[ml][0][i] - ellipsoidsW[0][i];
} else {
data [num_pm + 3 * num_ml + 7 * num_pd + npd][i] = Double.NaN;
}
break;
}
}
}
}
return data;
}
// public boolean [] getMeasSelection(int nl){
public String [] showSupertileWorldTitles(
double [][][] disp_strength,
boolean [][][] selections,
TilePlanes.PlaneData [] planes)
{
int num_p = selections.length;
int num_pd = (planes != null) ? (planes.length - LOWEST_PLANE(planes.length)) : 0;
String [] titles = new String [9 * num_pd];
for (int npd = 0; npd < num_pd; npd++){
titles [0 * num_pd + npd] = "tile_x_"+npd;
titles [1 * num_pd + npd] = "tile_y_"+npd;
titles [2 * num_pd + npd] = "tile_z_"+npd;
titles [3 * num_pd + npd] = "plane_x_"+npd;
titles [4 * num_pd + npd] = "plane_y_"+npd;
titles [5 * num_pd + npd] = "plane_z_"+npd;
titles [6 * num_pd + npd] = "diff_x_"+npd;
titles [7 * num_pd + npd] = "diff_y_"+npd;
titles [8 * num_pd + npd] = "diff_z_"+npd;
}
// TilePlanes.PlaneData
return titles;
}
/*
public double [][] showSupertileWorld(
double [][][] disp_strength,
boolean [][][] selections,
TilePlanes.PlaneData [] planes
)
{
int superTileSize = tileProcessor.getSuperTileSize();
int num_ml = disp_strength.length;
int num_p = (selections == null) ? 0: selections.length;
int num_pm = num_ml * num_p;
int num_pd = (planes != null) ? (planes.length - LOWEST_PLANE(planes.length)) : 0;
int ml = 0;
for (ml = 0; ml < num_ml; ml++) if (disp_strength[ml]!=null){
break;
}
double [][] data = new double [num_pd][];
for (int npd = 0; npd < num_pd; npd++) if (planes[npd +LOWEST_PLANE(planes.length)] != null){
double [][] ellipsoids = planes[npd +LOWEST_PLANE(planes.length)].getDoublePlaneDisparityStrength(
useWorld,
null, // double [] window,
-1, //
true, // boolean use_sel,
true, // boolean divide_by_area,
1.5, // double scale_projection,
0.0, // double fraction_uni,
1); // int debugLevel)
double [][] ellipsoidsW = planes[npd +LOWEST_PLANE(planes.length)].getDoublePlaneWorldDisparityStrength(
null, // double [] window,
-1, //
true, // boolean use_sel,
true, // boolean divide_by_area,
1.5, // double scale_projection,
0.0, // double fraction_uni,
1); // int debugLevel)
data [num_pm + 3 * num_ml + 0 * num_pd + npd] = planes[npd +LOWEST_PLANE(planes.length)].getDoublePlaneDisparity(
useWorld,
false);
boolean [][] msel = planes[npd +LOWEST_PLANE(planes.length)].getMeasSelection();
int ntiles = data [num_pm + 3 * num_ml + 0 * num_pd + npd].length;
data [num_pm + 3 * num_ml + 1 * num_pd + npd] = new double [ntiles];
for (int i = 0; i < ntiles; i++) {
data [num_pm + 3 * num_ml + 1 * num_pd + npd][i] = Double.NaN;
for (int ml = 0; ml < num_ml; ml++) if ((disp_strength[ml]!=null) && (msel[ml] != null)){
if (msel[ml][i] && (disp_strength[ml][1][i] > 0.0)){
data [num_pm + 3 * num_ml + 1 * num_pd + npd][i] = data [num_pm + 3 * num_ml + 0 * num_pd + npd][i];
}
}
}
if (ellipsoids != null) {
data [num_pm + 3 * num_ml + 2 * num_pd + npd] = ellipsoids[0];
data [num_pm + 3 * num_ml + 4 * num_pd + npd] = ellipsoids[1];
data [num_pm + 3 * num_ml + 6 * num_pd + npd] = new double[ntiles];
for (int i = 0; i < ntiles; i++) {
for (int ml = 0; ml < num_ml; ml++) if ((disp_strength[ml]!=null) && (msel[ml] != null)){
if (msel[ml][i] && (disp_strength[ml][1][i] > 0.0)){
data [num_pm + 3 * num_ml + 6 * num_pd + npd][i] = disp_strength[ml][0][i] - ellipsoids[0][i];
} else {
data [num_pm + 3 * num_ml + 6 * num_pd + npd][i] = Double.NaN;
}
break;
}
}
}
if (ellipsoidsW != null) {
data [num_pm + 3 * num_ml + 3 * num_pd + npd] = ellipsoidsW[0];
data [num_pm + 3 * num_ml + 5 * num_pd + npd] = ellipsoidsW[1];
data [num_pm + 3 * num_ml + 7 * num_pd + npd] = new double[ntiles];
for (int i = 0; i < ntiles; i++) {
for (int ml = 0; ml < num_ml; ml++) if ((disp_strength[ml]!=null) && (msel[ml] != null)){
if (msel[ml][i] && (disp_strength[ml][1][i] > 0.0)){
data [num_pm + 3 * num_ml + 7 * num_pd + npd][i] = disp_strength[ml][0][i] - ellipsoidsW[0][i];
} else {
data [num_pm + 3 * num_ml + 7 * num_pd + npd][i] = Double.NaN;
}
break;
}
}
}
}
return data;
}
*/
// calculate "tilted" disparity, so planes parallel to the same world plane would have the same disparity
// also produces non-tilted, if world_plane_norm == null
......@@ -2279,6 +2437,14 @@ public class SuperTiles{
}
if ((st_planes != null) && (!st_planes.isEmpty())){
if (dl > 2) {
for (TilePlanes.PlaneData plane:st_planes){
plane.getWorldXYZ(0);
System.out.println(plane.toString());
}
// Calculate planes and print results
}
// this_new_plane.getWorldXYZ(0);
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] );
......@@ -5831,6 +5997,8 @@ public class SuperTiles{
mod_planes[nsTile][neibs[dir]], // neighbor, previous value
dl - 1); // debugLevel);
costs[dir] = lp.getFitQualities(
// there probably be no sticks here after merging
false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
this_new_plane, // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
other_plane, // TilePlanes.PlaneData plane2,
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -5863,6 +6031,7 @@ public class SuperTiles{
this_new_plane =this_new_plane.clone(); // not to change weight!
this_new_plane.setWeight(0.0); //
double num_merged = 0.0; // double to add fractional pull weight of the center
double true_num_merged = 0.0;
for (int dir = 0; dir < neibs.length; dir++){
if (neibs[dir] >= 0) {
int stx = stx0 + dirsYX[dir][1];
......@@ -5885,11 +6054,16 @@ public class SuperTiles{
dl - 1); // int debugLevel)
} else {
this_new_plane.copyNeib(this_new_plane, other_plane); // keep neighbors of the original center plane
this_new_plane.copyStar(this_new_plane, other_plane);
this_new_plane = other_plane; // should increment num_merged
this_new_plane.scaleWeight(weights[dir]);
this_new_plane.invalidateCalculated();
}
if (this_new_plane != null){
num_merged += 1.0;
true_num_merged += 1.0;
// just for debug / calculate
this_new_plane.getWorldXYZ(0);
}
......@@ -5908,6 +6082,8 @@ public class SuperTiles{
double scale = Math.pow(num_merged, normPow);
this_new_plane.scaleWeight(1.0/scale);
num_merged /=scale;
true_num_merged /= scale;
}
if ( (meas_pull > 0.0) &&
......@@ -5930,24 +6106,33 @@ public class SuperTiles{
dl - 1); // int debugLevel)
if (this_new_plane != null){
num_merged += meas_pull; // num_merged was 1.0 and weight is averaged over all neighbors
true_num_merged += 1.0;
}
} else {
this_new_plane = measured_planes[nsTile0][np0].clone();
num_merged = 1.0;
true_num_merged = 1.0;
}
new_planes[nsTile0][np0] = this_new_plane;
if (dl > 0) dbg_img[18] = this_new_plane.getSinglePlaneDisparity(false);
}
if ((num_merged > 0.0) && (this_new_plane != null)){
this_new_plane.scaleWeight(1.0/num_merged);
double true_num_merged = num_merged - meas_pull + 1;
// double true_num_merged = num_merged - meas_pull + 1;
this_new_plane.setNumPoints((int) (this_new_plane.getNumPoints()/true_num_merged));
}
// Revert if the result value is higher than imposed maximum
if ((this_new_plane.getValue() > maxValue) && (maxValue != 0)){ // TODO: Set more relaxed here?
if (dl > -1){
System.out.println("planesSmoothStep nsTile0="+nsTile0+" smoothed plane is too thick, using previous one");
dbg_img = new double [titles.length][];
}
this_new_plane = mod_planes[nsTile0][np0].clone();
new_planes[nsTile0][np0] = this_new_plane;
}
// Use non-exclusive
// just for debug / calculate
this_new_plane.getWorldXYZ(0);
// calculate largest disparity difference between old and new plane
......@@ -6908,6 +7093,7 @@ public class SuperTiles{
final double dispNorm,
final double maxEigen, // maximal eigenvalue of planes to consider
final double minWeight, // minimal pain weight to consider
final boolean weak_connected, // select connected planes even if they are weak/thick
TilePlanes.PlaneData [][] planes)
{
final int tilesX = tileProcessor.getTilesX();
......@@ -6923,7 +7109,18 @@ public class SuperTiles{
if (planes[nsTile] != null) {
selection[nsTile] = new boolean [planes[nsTile].length];
for (int np = 0; np < planes[nsTile].length; np++){
if ((planes[nsTile][np] != null) && (planes[nsTile][np].getWeight() >= minWeight)){
// if ((planes[nsTile][np] != null) && (planes[nsTile][np].getWeight() >= minWeight)){
if (planes[nsTile][np] != null){
boolean has_conn = false;
for (int dir = 0; dir < 8; dir++){
if (planes[nsTile][np].getNeibBest(dir) >= 0){
has_conn = true;
break;
}
}
if (weak_connected && has_conn) {
selection[nsTile][np] = true;
} else if (planes[nsTile][np].getWeight() >= minWeight) {
//&& (planes[nsTile][np].getValue() < maxEigen)){
double eigVal = planes[nsTile][np].getValue();
double disp = planes[nsTile][np].getZxy()[0];
......@@ -6936,6 +7133,7 @@ public class SuperTiles{
}
}
}
}
return selection;
}
......
......@@ -160,6 +160,19 @@ public class TileNeibs{
}
return -1; // should not happen
}
public void shrinkSelection(
int shrink, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
boolean [] tiles,
boolean [] prohibit)
{
boolean [] itiles = new boolean [tiles.length];
for (int i = 0; i < tiles.length; i++) itiles[i] = !tiles[i];
growSelection(
shrink, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
itiles,
prohibit);
for (int i = 0; i < tiles.length; i++) tiles[i] = !itiles[i];
}
public void growSelection(
int grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
......
......@@ -63,7 +63,7 @@ public class TilePlanes {
double [] center_xyz = null; // center of this this "plane" (ellipsoid) center in world coordinates
double [] world_xyz = null; // world coordinates of the nearest point of the plane, in meters
double [] world_v1 = null; // world in-plane vector, corresponding to vectors[1]
double [] world_v2 = null; // world in-plane vector, corresponding to vectors[1]
double [] world_v2 = null; // world in-plane vector, corresponding to vectors[2]
// double [] daxy = null; // disparity and 2 relative angles (ax and ay) corresponding to fisheye view, near (0,0) scale is pixel size
// for now keeping both weighted and equal weight merged value - later remove less useful
double [][] merged_eig_val = null; // for each of the directions (N, NE, .. NW) quality match for each layer
......@@ -161,15 +161,17 @@ public class TilePlanes {
pd.preferDisparity = this.preferDisparity;
copyNeib(this,pd);
copyStar(this,pd);
/*
if (starValueWeight != null){
pd.starValueWeight = starValueWeight.clone();
}
if (this.starPlane != null) pd.starPlane = this.starPlane;
if (this.nonexclusiveStar != null) pd.nonexclusiveStar = this.nonexclusiveStar;
if (this.nonexclusiveStarEq != null) pd.nonexclusiveStarEq = this.nonexclusiveStarEq;
pd.conn_density = this.conn_density;
*/
pd.num_points = this.num_points; // restore, maybe remove from copy_neib?
//
if (this.wxyz != null) pd.wxyz = this.wxyz.clone();
......@@ -211,16 +213,57 @@ public class TilePlanes {
return s;
}
public boolean isHorizontal(){
/*
public boolean isHorizontalW(){
if (wvectors != null){
return (Math.abs(wvectors[0][1]) > 0.99);
return (Math.abs(wvectors[0][1]) > 0.99) && (checkBadPlate(false) < 0.2);
}
return false;
}
*/
public boolean isHorizontal(){
if (world_xyz != null){
double norm = world_xyz[1] / Math.sqrt(world_xyz[0]*world_xyz[0] + world_xyz[1]*world_xyz[1] + world_xyz[2]*world_xyz[2]);
return (Math.abs(norm) > 0.99) && (checkBadPlate(false) < 0.2);
}
return false;
}
public double get2dRatio(){
if (wvalues != null) return Math.sqrt(wvalues[1]/wvalues[0]);
return Double.NaN;
}
/**
* Verify plane normal in real world and calculated from pixels/disparity
* Use to check consistency
* @return sin squared of the angle between 2 normals, or NaN if there is no data to calculate it
*/
public double checkBadPlate(boolean force)
{
if (!force && (world_xyz == null)) return Double.NaN;
if (wvectors == null) return Double.NaN;
Matrix norm_disp = new Matrix(this.getWorldXYZ(this.correctDistortions, 0),3); // normal to plane from disparity space
Matrix norm_world = new Matrix(wvectors[0],3); // normal to plane from disparity space
Matrix cp = cross3d(norm_disp, norm_world);
double cp2 = cp.transpose().times(cp).get(0, 0);
double this_wv2 = norm_disp.transpose().times(norm_disp).get(0, 0);
double other_wv2 = norm_world.transpose().times(norm_world).get(0, 0);
return cp2/(this_wv2 * other_wv2);
}
public double checkBadStick(boolean force)
{
if (!force && (world_xyz == null)) return Double.NaN;
if (wvectors == null) return Double.NaN;
Matrix long_disp = new Matrix(this.getWorldV12(true,this.correctDistortions, 0),3); // normal to plane from disparity space
Matrix long_world = new Matrix(wvectors[2],3); // normal to plane from disparity space
Matrix cp = cross3d(long_disp, long_world);
double cp2 = cp.transpose().times(cp).get(0, 0);
double this_wv2 = long_disp.transpose().times(long_disp).get(0, 0);
double other_wv2 = long_world.transpose().times(long_world).get(0, 0);
return cp2/(this_wv2 * other_wv2);
}
public String toString()
{
......@@ -243,8 +286,21 @@ public class TilePlanes {
vectors[0][0],vectors[0][1],vectors[0][2], vectors[1][0],vectors[1][1],vectors[1][2], vectors[2][0],vectors[2][1],vectors[2][2]);
if (center_xyz != null) s += String.format("\ncenter = [%8.2f, %8.2f, %8.2f]",center_xyz[0],center_xyz[1],center_xyz[2]);
else s += "\ncenter = null";
if (world_xyz != null) s += String.format(" normal = [%8.2f, %8.2f, %8.2f] (m)",world_xyz[0],world_xyz[1],world_xyz[2]);
else s += " normal = null";
double bad_plate = checkBadPlate(false);
if (!Double.isNaN(bad_plate)){
s+=String.format(" bad_plate=%6.4f", bad_plate);
}
double bad_stick = checkBadStick(false);
if (!Double.isNaN(bad_plate)){
s+=String.format(" bad_stick=%6.4f", bad_stick);
}
double [] world_xyz_w = getWorldXYZFromWorld();
if (world_xyz_w != null) s += String.format("\n%34s world normal = [%8.2f, %8.2f, %8.2f] (m)","",world_xyz_w[0],world_xyz_w[1],world_xyz_w[2]);
if (wxyz != null) s += String.format("\nwxyz = [%8.2f, %8.2f, %8.2f] (m)",wxyz[0],wxyz[1],wxyz[2]);
else s += "\nwxyz = null";
if (wvalues != null) s += String.format(" wvals = [%8.4f, %8.3f, %8.2f] (m^2)",wvalues[0],wvalues[1],wvalues[2]);
......@@ -268,6 +324,15 @@ public class TilePlanes {
if (nonexclusiveStar.world_xyz != null) s += String.format(" normal = [%8.2f, %8.2f, %8.2f] (m)",
nonexclusiveStar.world_xyz[0],nonexclusiveStar.world_xyz[1],nonexclusiveStar.world_xyz[2]);
else s += " normal = null";
bad_plate = nonexclusiveStar.checkBadPlate(false);
if (!Double.isNaN(bad_plate)){
s+=String.format(" bad_plate=%6.4f", bad_plate);
}
bad_stick = nonexclusiveStar.checkBadStick(false);
if (!Double.isNaN(bad_plate)){
s+=String.format(" bad_stick=%6.4f", bad_stick);
}
}
if (nonexclusiveStarEq != null){
s+= "\nequalized:";
......@@ -286,6 +351,14 @@ public class TilePlanes {
if (nonexclusiveStarEq.world_xyz != null) s += String.format(" normal = [%8.2f, %8.2f, %8.2f] (m)",
nonexclusiveStarEq.world_xyz[0],nonexclusiveStarEq.world_xyz[1],nonexclusiveStarEq.world_xyz[2]);
else s += " normal = null";
bad_plate = nonexclusiveStarEq.checkBadPlate(false);
if (!Double.isNaN(bad_plate)){
s+=String.format(" bad_plate=%6.4f", bad_plate);
}
bad_stick = nonexclusiveStarEq.checkBadStick(false);
if (!Double.isNaN(bad_plate)){
s+=String.format(" bad_stick=%6.4f", bad_stick);
}
}
s+="\n";
if (link_costs != null){
......@@ -310,7 +383,7 @@ public class TilePlanes {
s+="\n";
}
}
s+="\n";
// s+="\n";
return s;
}
......@@ -446,6 +519,21 @@ public class TilePlanes {
return this.measuredLayers;
}
public void copyStar(
PlaneData src,
PlaneData dst)
{
if (src.starValueWeight != null){
dst.starValueWeight = src.starValueWeight.clone();
}
if (src.starPlane != null) dst.starPlane = src.starPlane;
if (src.nonexclusiveStar != null) dst.nonexclusiveStar = src.nonexclusiveStar;
if (src.nonexclusiveStarEq != null) dst.nonexclusiveStarEq = src.nonexclusiveStarEq;
dst.conn_density = src.conn_density;
}
public void copyNeib(
PlaneData src,
PlaneData dst)
......@@ -518,7 +606,7 @@ public class TilePlanes {
// also copy original plane parameters - tile selection and number of points
dst.num_points = src.num_points;
// dst.num_points = src.num_points;
if (src.plane_sel != null) dst.plane_sel = src.plane_sel.clone();
}
......@@ -1542,7 +1630,7 @@ public class TilePlanes {
}
if ((debugLevel > 3) && (disp_str[nl] != null)){
if ((debugLevel > 2) && (disp_str[nl] != null)){
// if ((debugLevel > 1) && (disp_str[nl] != null)){
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays();
double [][] dbg_img = new double [3][];
......@@ -1558,6 +1646,7 @@ public class TilePlanes {
}
this.measuredSelection = tile_sel; // it may be modified
if ((sw < min_weight) || (num_tiles < min_tiles)) {
if (debugLevel > 1){
System.out.println("getWorldPlaneFromMeas():return false");
......@@ -1603,6 +1692,24 @@ public class TilePlanes {
}
}
}
if ((debugLevel > 3) && (disp_str[nl] != null)){
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays();
double [][] dbg_img = new double [4][stSize2*stSize2];
for (int indx = 0; indx < dbg_img[0].length; indx++){
if (tiles_xyzw[nl][indx] != null) {
dbg_img[0][indx] = tiles_xyzw[nl][indx][0];
dbg_img[1][indx] = tiles_xyzw[nl][indx][1];
dbg_img[2][indx] = tiles_xyzw[nl][indx][2];
dbg_img[3][indx] = tiles_xyzw[nl][indx][3];
} else {
dbg_img[0][indx] = Double.NaN;
dbg_img[1][indx] = Double.NaN;
dbg_img[2][indx] = Double.NaN;
dbg_img[3][indx] = Double.NaN;
}
}
sdfa_instance.showArrays(dbg_img, stSize2, stSize2, true, "world_x"+sTileXY[0]+"_y"+sTileXY[1]+"_"+nl);
}
}
}
if (sw == 0.0) {
......@@ -2173,6 +2280,9 @@ public class TilePlanes {
return num_points;
}
public void setNumPoints(int num_points) {
if (num_points < 0){
System.out.println("setNumPoints(): Setting negative number of tiles in a plane: "+num_points);
}
this.num_points = num_points;
}
public double getWeight() {
......@@ -2376,13 +2486,13 @@ public class TilePlanes {
return plane;
}
public double[][] getDoublePlaneDisparityStrength(
public double[][] getDoublePlaneDisparityStrengthOld(
double [] window,
boolean use_sel,
boolean divide_by_area,
double scale_projection,
int debugLevel)
{ return getDoublePlaneDisparityStrength(
{ return getDoublePlaneDisparityStrengthOld(
true,
window,
use_sel,
......@@ -2425,7 +2535,7 @@ public class TilePlanes {
* @return a pair of arrays {disparity, strength}, each [2*superTileSize * 2*superTileSize]
*/
// obsolete, convert to another version ?
public double[][] getDoublePlaneDisparityStrength(
public double[][] getDoublePlaneDisparityStrengthOld(
boolean useWorld,
double [] window,
boolean use_sel,
......@@ -2544,6 +2654,16 @@ public class TilePlanes {
double fraction_uni,
int debugLevel)
{
return getDoublePlaneDisparityStrength(
useWorld ? getWorldXYZ(this.correctDistortions) : null, // will calculate if not yet done so. Should it use otherPd, not pd? and then clone later?
window,
dir,
use_sel,
divide_by_area,
scale_projection,
fraction_uni,
debugLevel);
/*
double [][] disp_strength = new double[2][4*superTileSize*superTileSize];
double [] normal = getVector();
double [] zxy = getZxy(); // {disparity, x center in pixels, y center in pixels (relative to a supertile center)
......@@ -2615,8 +2735,151 @@ public class TilePlanes {
}
}
return disp_strength;
*/
}
public double [] getWorldXYZFromWorld()
{
double [] wxyz = getWxyz();
double [][] wvectors = getWVectors();
if ((wxyz == null) || (wvectors == null) || (wvectors[0] == null)) return null;
double normal_dot_normal = 0.0; // supposed to be unit length, but we'll still re-normalize it
double center_dot_normal = 0.0;
for (int i = 0; i < 3; i++){
normal_dot_normal += wvectors[0][i] * wvectors[0][i];
center_dot_normal += wxyz[i] * wvectors[0][i];
}
double scale = center_dot_normal / normal_dot_normal;
double [] rslt = wvectors[0].clone();
for (int i = 0; i < 3; i++){
rslt[i] *= scale;
}
return rslt;
}
public double[][] getDoublePlaneWorldDisparityStrength(
double [] window,
int dir,
boolean use_sel,
boolean divide_by_area,
double scale_projection,
double fraction_uni,
int debugLevel)
{
return getDoublePlaneDisparityStrength(
getWorldXYZFromWorld(),
window,
dir,
use_sel,
divide_by_area,
scale_projection,
fraction_uni,
debugLevel);
}
/**
* Get disparity values for the tiles of this overlapping supertile as [2*superTileSize * 2*superTileSize] array
* and weights combined from provided window function, optional selection and using ellipsoid projection on the
* px, py plane (constant disparity
* Sharp weights - when selecting the best match - use exponent of (delta_disp) ^2 ?
* Or divide weight by ellipse area?
* @param world_normal Noral vector to the plane from the origin, or null to stay in pixel/disparity space.
* @param window null or window function as [2*superTileSize * 2*superTileSize] array
* @param dir - source tile shift from the target: -1 center, 0 - N, 1 - NE
* @param use_sel use plane selection (this.sel_mask) to select only some part of the plane
* @param divide_by_area divide weights by ellipsoid area
* @param scale_projection use plane ellipsoid projection for weight: 0 - do not use, > 0 linearly scale ellipsoid
* @param fraction_uni add fraction of the total weight to each tile
* @return a pair of arrays {disparity, strength}, each [2 * superTileSize * 2 * superTileSize], only 1/2 or 1/4 used for offset tiles\
* TODO: add a combination of the ellipses and infinite planes?
*
*/
public double[][] getDoublePlaneDisparityStrength(
double [] world_normal, // either real world normal vector from (0,0,0) to the plane or null, in that case will stay n disparity space
double [] window,
int dir,
boolean use_sel,
boolean divide_by_area,
double scale_projection,
double fraction_uni,
int debugLevel)
{
double [][] disp_strength = new double[2][4*superTileSize*superTileSize];
double [] normal = getVector();
double [] zxy = getZxy(); // {disparity, x center in pixels, y center in pixels (relative to a supertile center)
double weight = getWeight();
double k_gauss = 0;
Matrix val2d = null, vect2d = null;
if (scale_projection > 0.0){
EigenvalueDecomposition eig = get2dDecomposition();
val2d = eig.getD();
vect2d = eig.getV().transpose();
k_gauss = 0.5/(scale_projection*scale_projection);
if (divide_by_area) {
double area = Math.sqrt(val2d.get(0, 0)*val2d.get(1, 1));
if (area > 0){
weight /= area;
}
}
}
int ss2 = superTileSize;
int ss4 = 2 * superTileSize;
int [][] offsets = {
// ymin, ymax, xmin,xmax, offsy, offsx
{ 0, ss4, 0, ss4, 0, 0 }, // center
{ss2, ss4, 0, ss4, -ss2, 0 }, // N
{ss2, ss4, 0, ss2, -ss2, ss2 }, // NE
{ 0, ss4, 0, ss2, 0, ss2 }, // E
{ 0, ss2, 0, ss2, ss2, ss2 }, // SE
{ 0, ss2, 0, ss4, ss2, 0 }, // S
{ 0, ss2, ss2, ss4, ss2, -ss2 }, // SW
{ 0, ss4, ss2, ss4, 0, -ss2 }, // W
{ss2, ss4, ss2, ss4, -ss2, -ss2 }}; // NW
int dir1 = dir + 1;
double [] pxyc = getCenterPxPy(); // center of this supertile, not plane center
for (int iy = offsets[dir1][0]; iy < offsets[dir1][1]; iy++){
// adding half-tile and half-pixel to match the center of the pixel. Supertile center is between
// pixel 31 and pixel 32 (counting from 0) in both directions
double y = tileSize * (iy - ss2 + 0.5) + 0.5 - zxy[2];
int oy = iy + offsets[dir1][4]; //vert index in the result tile
for (int ix = offsets[dir1][2]; ix < offsets[dir1][3]; ix++){
double x = tileSize * (ix - ss2 + 0.5) + 0.5 - zxy[1];
int indx = ss4 * oy + ix + offsets[dir1][5];
int indx_i = iy * ss4 + ix; // input index
if (world_normal != null) {
disp_strength[0][indx] = geometryCorrection.getPlaneDisparity( // disparity (at this center) for crossing other supertile plane
world_normal,
x + pxyc[0] + zxy[1],
y + pxyc[1] + zxy[2],
this.correctDistortions);
} else {
disp_strength[0][indx] = zxy[0] - (normal[1] * x + normal[2] * y)/normal[0];
}
double w = weight;
if ((w > 0.0) && (scale_projection > 0.0)){
double [] xy = {x,y};
Matrix vxy = vect2d.times(new Matrix(xy,2)); // verify if it is correct
double r2 = 0;
for (int i = 0; i <2; i++){
double d = vxy.get(i,0);
r2 += d * d / val2d.get(i, i);
}
w *= ((1.0 - fraction_uni) * Math.exp(-k_gauss*r2) + fraction_uni);
if (window != null) w *= window[indx_i];
if (use_sel && (sel_mask != null) && !(sel_mask[indx_i])) w = 0.0;
}
disp_strength[1][indx] = w;
}
}
return disp_strength;
}
public double[][] getSinglePlaneDisparityStrength(
double [] window,
int dir,
......@@ -3583,7 +3846,7 @@ public class TilePlanes {
continue;
}
if (debugLevel > 0) {
if (pd.getWeight() > 1.0) {
if (pd.getWeight() > 0.0) { // 1.0) {
System.out.println("Removed outliers "+ suffix +
", numPoints="+ pd.getNumPoints()+
", swc = "+pd.getWeight()+
......@@ -3603,7 +3866,8 @@ public class TilePlanes {
}
// calculate the world planes too
pd.getWorldPlaneFromMeas(
plane_selections[ps], // tile_sel, // boolean [][] tile_sel, // null - do not use, {} use all (will be modified)
// use current selection, possibly reduced after removeOutliers()
null, // plane_selections[ps], // tile_sel, // boolean [][] tile_sel, // null - do not use, {} use all (will be modified)
disp_strength,
Double.NaN, // double disp_far, // minimal disparity to select (or NaN)
Double.NaN, // double disp_near, // maximal disparity to select (or NaN)
......
......@@ -881,6 +881,9 @@ public class TileProcessor {
CLTPass3d bgnd_data = clt_3d_passes.get(0);
// double [][][][] texture_tiles = bgnd_data.texture_tiles;
double [][] disparity_map= bgnd_data.disparity_map;
double [] dbg_worst2 = new double [disparity_map[ImageDtt.IMG_DIFF0_INDEX].length];
final TileNeibs tnSurface = new TileNeibs(tilesX, tilesY);
for (int tileY = 0; tileY < tilesY; tileY++){
for (int tileX = 0; tileX < tilesX; tileX++){
int tindx = tileY * tilesX + tileX;
......@@ -898,16 +901,42 @@ public class TileProcessor {
}
// see if the second worst variation exceeds sure_smth (like a window), really close object
int imax1 = 0;
double worst1 = 0.0;
// modified to look around for the 1-st maximum
for (int i = 1; i< quad; i++){
if (disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx] > disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax1][tindx]) imax1 = i;
// if (disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx] > disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax1][tindx]){
if (disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx] > worst1){
imax1 = i;
worst1 = disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx];
}
for (int dir =0; dir < 8; dir++){
int dtindx = tnSurface.getNeibIndex(tindx, dir);
if (dtindx >= 0){
if (disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][dtindx] > worst1){
imax1 = i;
worst1 = disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][dtindx];
}
}
}
}
int imax2 = (imax1 == 0)? 1 : 0;
for (int i = 0; i< quad; i++) if (i != imax1) {
if (disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx] > disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax2][tindx]) imax2 = i;
}
dbg_worst2[tindx] = disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax2][tindx];
block_propagate[tindx] = (disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax2][tindx] > sure_smth);
}
}
// grow block by 1 ?
tnSurface.growSelection(
2, // grow,
block_propagate, // tiles,
null); // prohibit);
if ((debugLevel > -1) && show_bgnd_nonbgnd){
new showDoubleFloatArrays().showArrays(bgnd_data.disparity_map, tilesX, tilesY, true, "bgnd_map",ImageDtt.DISPARITY_TITLES);
new showDoubleFloatArrays().showArrays(dbg_worst2, tilesX, tilesY, "worst2");
}
// TODO: check if minimal cluster strengh should be limited here
if (min_clstr_seed > 1){
removeSmallClusters(
......@@ -3251,7 +3280,8 @@ public class TileProcessor {
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.interPlaneCosts( // not used yet, just for testing
lp.interPlaneCosts( //
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
......@@ -3266,13 +3296,28 @@ public class TileProcessor {
// calculate it here - use results to keep some planes from merging
double [][] quality_stats1 = lp.selectNeighborPlanesMutual(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
if (debugLevel>100) System.out.println(quality_stats1.length);
System.out.println("Testing - overwriting selectNeighborPlanesMutual() results with setExclusiveLinks()");
// Just overwrite results of the previous method
lp.setExclusiveLinks(
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.setNonExclusive(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
......@@ -3307,7 +3352,7 @@ public class TileProcessor {
clt_parameters.tileY);
// remove merge candidates that break connections to neighbors
lp.keepSameTileConnections(
if (debugLevel>100) lp.keepSameTileConnections(
st.planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
......@@ -3589,12 +3634,23 @@ public class TileProcessor {
debugLevel); // final int debugLevel);
}
double [][] quality_stats1 = lp.selectNeighborPlanesMutual(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
if (debugLevel>100) System.out.println(quality_stats1.length);
System.out.println("Testing - overwriting selectNeighborPlanesMutual() results with setExclusiveLinks()");
//Just overwrite results of the previous method
lp.setExclusiveLinks(
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
st.resolveConflicts(
lp, // LinkPlanes lp,
clt_parameters.plMaxEigen,
......@@ -3718,6 +3774,7 @@ public class TileProcessor {
clt_parameters.tileY);
lp.interPlaneCosts( // not used yet, just for testing
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
......@@ -3730,13 +3787,26 @@ public class TileProcessor {
clt_parameters.tileX,
clt_parameters.tileY);
// Try replacing lp.selectNeighborPlanesMutual with
// lp.setExclusiveLinks()
double [][] quality_stats2 = lp.selectNeighborPlanesMutual(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
if (debugLevel>100) System.out.println(quality_stats2.length);
System.out.println("Testing - overwriting selectNeighborPlanesMutual() results with setExclusiveLinks()");
// Just overwrite results of the previous method
lp.setExclusiveLinks(
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
st.resolveConflicts(
lp, // LinkPlanes lp,
clt_parameters.plMaxEigen,
......@@ -3782,6 +3852,7 @@ public class TileProcessor {
// smooth planes (by averaging with neighbors and the "measured" one with variable "pull")
if (clt_parameters.plIterations > 0) {
for (int num_merge_try = 0; num_merge_try < 10; num_merge_try ++ ) { // smooth and merge
st.resetPlanesMod(); // clean start
planes_mod = st.planesSmooth(
lp, // LinkPlanes lp,
......@@ -3797,6 +3868,7 @@ public class TileProcessor {
clt_parameters.tileY);
// create costs for the modified planes
lp.interPlaneCosts(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
......@@ -3820,11 +3892,212 @@ public class TileProcessor {
clt_parameters.tileX,
clt_parameters.tileY);
lp.interPlaneCosts(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// recalculate links? more smooth?
lp.setExclusiveLinks(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// just in case? Not yet needed
lp.setNonExclusive(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// see if some modified planes need to be merged (but merge originals)
// TODO: Stricter requirements for merging here than for original planes?
int [][][] merge_candidates = lp.getMergeSameTileCandidates(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
boolean [][][] plane_nooverlaps = lp.overlapSameTileCandidates (
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// remove merge candidates that break connections to neighbors
if (debugLevel>100) lp.keepSameTileConnections(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
true, // final boolean merge_low_eigen, here it should be true
true, // final boolean useNonExcl, // consider only directions available for non-exclusive merges
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// * Possible problem is that "normalizing" merge quality for low weights is not applicable for "star" plane that include neighhbors
// * Switch to a single "cost" function (costSameTileConnectionsAlt())
// Still - how to merge stray tiles that do not have neighbors/star? Still merge them "old way" (costSameTileConnections()) if at least 1 does not
// have a "star"
lp.costSameTileConnections(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// System.out.println("merge_cost_data.length = " + merge_cost_data.length);
lp.costSameTileConnectionsAlt(
5.0, // final double threshold,
10.0, // final double threshold_nostar,
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
int [][][] merge_groups = lp.extractMergeSameTileGroups(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // boolean [][][] plane_overlaps,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
int num_removed_by_merging = st.applyMergePlanes(
st.planes, // final TilePlanes.PlaneData[][] planes,
merge_groups, // final int [][][] merge_groups,
// parameters to generate ellipsoids
0.0, // 3, // final double disp_far, // minimal disparity to select (or NaN)
Double.NaN, // final double disp_near, // maximal disparity to select (or NaN)
clt_parameters.plDispNorm, // final double dispNorm, // Normalize disparities to the average if above
0.0, // final double min_weight,
clt_parameters.plMinPoints, // final int min_tiles,
// parameters to reduce outliers
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
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
System.out.println("Try "+num_merge_try+ ": removed "+num_removed_by_merging+" planes by merging, recalculating connections");
if (num_removed_by_merging == 0){ // re-calculate all links
break;
}
// Do the same as in conditionSuperTiles before smoothing again
lp.matchPlanes(
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.interPlaneCosts( //
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.filterNeighborPlanes(
st.planes, // final TilePlanes.PlaneData [][] planes,
true, // final boolean merge_low_eigen,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// calculate it here - use results to keep some planes from merging
double [][] quality_stats2 = lp.selectNeighborPlanesMutual(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
if (debugLevel>100) System.out.println(quality_stats2.length);
System.out.println("Testing - overwriting selectNeighborPlanesMutual() results with setExclusiveLinks()");
// Just overwrite results of the previous method
lp.setExclusiveLinks(
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.setNonExclusive(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.calcStarValueStrength(
true, // boolean set_start_planes,
clt_parameters.plStarOrtho, // orthoWeight, // final double orthoWeight,
clt_parameters.plStarDiag, // diagonalWeight, // final double diagonalWeight,
clt_parameters.plStarPwr, // starPwr, // final double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarWeightPwr,// starWeightPwr, // final double starWeightPwr, // Use this power of tile weight when calculating connection cost
clt_parameters.plWeightToDens, // weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
clt_parameters.plStarValPwr, // starValPwr, //double starValPwr, // Raise value of each tile before averaging
2, // starSteps, // final int steps,
st.planes, // final TilePlanes.PlaneData [][] planes,
clt_parameters.plPreferDisparity, // preferDisparity, // final boolean preferDisparity)
0); // debugLevel);
// end of possible merge, can try smoothing again
// just to show them, not currently processed
/*
* will not work - hard-wired to use planes, not planes_mod!
st.resolveConflicts(
lp, // LinkPlanes lp,
clt_parameters.plMaxEigen,
clt_parameters.plConflDualTri, // boolean conflDualTri, // Resolve dual triangles conflict (odoodo)
clt_parameters.plConflMulti, // boolean conflMulti, // Resolve multiple odo triangles conflicts
clt_parameters.plConflDiag, // boolean conflDiag, // Resolve diagonal (ood) conflicts
clt_parameters.plConflStar, // boolean conflStar, // Resolve all conflicts around a supertile
clt_parameters.plStarSteps, // int starSteps, // How far to look around when calculationg connection cost
clt_parameters.plStarOrtho, // double orthoWeight,
clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarWeightPwr, // double starWeightPwr, // Use this power of tile weight when calculating connection cost
clt_parameters.plWeightToDens, // double weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
clt_parameters.plStarValPwr, // double starValPwr, // Raise value of each tile before averaging
clt_parameters.plDblTriLoss, // double diagonalWeight,
clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced
clt_parameters.plMaxChanges, // int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
clt_parameters.plPreferDisparity,
1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
*/
}
} else {
st.planes_mod = st.planes; // just use the measured ones
......@@ -3834,6 +4107,7 @@ public class TileProcessor {
clt_parameters.plDispNorm,
clt_parameters.plMaxEigen, // maxEigen,
clt_parameters.plMinStrength, // minWeight,
true, // final boolean weak_connected, // select connected planes even if they are weak/thick
st.getPlanesMod());
if (clt_parameters.show_planes){
......
......@@ -3170,8 +3170,11 @@ public class TileSurface {
if (grown_cluster[neTile1] == null) {
int nSurfTile1 = surf_indices[neTile1];
// should never be null as it is connected from nSurfTile0
grown_cluster[neTile1] = new boolean [tileData[nSurfTile1].length];
if (nSurfTile1 >=0) {
grown_cluster[neTile1] = new boolean [tileData[nSurfTile1].length]; // out_of_bounds
}
}
if(grown_cluster[neTile1] != null){
grown_cluster[neTile1][nl1] = true;
}
}
......@@ -3180,6 +3183,7 @@ public class TileSurface {
}
}
}
}
if (debugLevel > 0) {
int dbg_ntiles2 = 0;
for (int neTile = 0; neTile < num_tiles; neTile++){
......
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