Commit e5d30e06 authored by Andrey Filippov's avatar Andrey Filippov

working on re-discriminating, some bug fixes

parent 0ab422e2
......@@ -2188,7 +2188,20 @@ public class EyesisCorrectionParameters {
public double plMaxZRatio = 2.0; // Maximal ratio of Z to allow plane merging
public double plMaxDisp = 0.6; // Maximal disparity of one of the planes to apply maximal ratio
public double plCutTail = 1.4; // When merging with neighbors cut the tail that is worse than scaled best
public double plMinTail = 0.015;// Set cutoff value livel not less than
public double plMinTail = 0.015;// Set cutoff value level not less than
// parameters to recreate planes from tiles disparity/strengths using determined plane connections to neighbors
public double plDiscrTolerance = 0.4; // Maximal disparity difference from the plane to consider tile
public double plDiscrDispRange = 1.0; // Parallel move known planes around original know value for the best overall fit
public int plDiscrSteps = 10; // Number of steps (each direction) for each plane to search for the best fit (0 - single, 1 - 1 each side)
public int plDiscrVariants = 100; // total number of variants to try (protect from too many planes)
public int plDiscrMode = 3; // 0 - weighted, 1 - equalized, 2 - best, 3 - combined
public double plDiscrVarFloor = 0.03; // Squared add to variance to calculate reverse flatness (used mostly for single-cell clusters)
public double plDiscrSigma = 0.05; // Gaussian sigma to compare how measured data is attracted to planes
public double plDiscrBlur = 0.05; // Sigma to blur histograms while re-discriminating
public double plDiscrExclusivity = 1.5; // Tile exclusivity: 1.0 - tile belongs to one plane only, 0.0 - regardless of others
public double plDiscrExclus2 = 0.8; // For second pass if exclusivity > 1.0 - will assign only around strong neighbors
public boolean plDiscrStrict = false; // When growing selection do not allow any offenders around (false - more these than others)
// comparing merge quality for plane pairs
public double plCostKrq = 0.8; // cost of merge quality weighted in disparity space
......@@ -2578,6 +2591,18 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plCutTail", this.plCutTail +"");
properties.setProperty(prefix+"plMinTail", this.plMinTail +"");
properties.setProperty(prefix+"plDiscrTolerance", this.plDiscrTolerance +"");
properties.setProperty(prefix+"plDiscrDispRange", this.plDiscrDispRange +"");
properties.setProperty(prefix+"plDiscrSteps", this.plDiscrSteps+"");
properties.setProperty(prefix+"plDiscrVariants", this.plDiscrVariants+"");
properties.setProperty(prefix+"plDiscrMode", this.plDiscrMode+"");
properties.setProperty(prefix+"plDiscrVarFloor", this.plDiscrVarFloor +"");
properties.setProperty(prefix+"plDiscrSigma", this.plDiscrSigma +"");
properties.setProperty(prefix+"plDiscrBlur", this.plDiscrBlur +"");
properties.setProperty(prefix+"plDiscrExclusivity",this.plDiscrExclusivity +"");
properties.setProperty(prefix+"plDiscrExclus2", this.plDiscrExclus2 +"");
properties.setProperty(prefix+"plDiscrStrict", this.plDiscrStrict+"");
properties.setProperty(prefix+"plCostKrq", this.plCostKrq +"");
properties.setProperty(prefix+"plCostKrqEq", this.plCostKrqEq +"");
properties.setProperty(prefix+"plCostWrq", this.plCostWrq +"");
......@@ -2943,6 +2968,18 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plCutTail")!=null) this.plCutTail=Double.parseDouble(properties.getProperty(prefix+"plCutTail"));
if (properties.getProperty(prefix+"plMinTail")!=null) this.plMinTail=Double.parseDouble(properties.getProperty(prefix+"plMinTail"));
if (properties.getProperty(prefix+"plDiscrTolerance")!=null) this.plDiscrTolerance=Double.parseDouble(properties.getProperty(prefix+"plDiscrTolerance"));
if (properties.getProperty(prefix+"plDiscrDispRange")!=null) this.plDiscrDispRange=Double.parseDouble(properties.getProperty(prefix+"plDiscrDispRange"));
if (properties.getProperty(prefix+"plDiscrSteps")!=null) this.plDiscrSteps=Integer.parseInt(properties.getProperty(prefix+"plDiscrSteps"));
if (properties.getProperty(prefix+"plDiscrVariants")!=null) this.plDiscrVariants=Integer.parseInt(properties.getProperty(prefix+"plDiscrVariants"));
if (properties.getProperty(prefix+"plDiscrMode")!=null) this.plDiscrMode=Integer.parseInt(properties.getProperty(prefix+"plDiscrMode"));
if (properties.getProperty(prefix+"plDiscrVarFloor")!=null) this.plDiscrVarFloor=Double.parseDouble(properties.getProperty(prefix+"plDiscrVarFloor"));
if (properties.getProperty(prefix+"plDiscrSigma")!=null) this.plDiscrSigma=Double.parseDouble(properties.getProperty(prefix+"plDiscrSigma"));
if (properties.getProperty(prefix+"plDiscrBlur")!=null) this.plDiscrBlur=Double.parseDouble(properties.getProperty(prefix+"plDiscrBlur"));
if (properties.getProperty(prefix+"plDiscrExclusivity")!=null)this.plDiscrExclusivity=Double.parseDouble(properties.getProperty(prefix+"plDiscrExclusivity"));
if (properties.getProperty(prefix+"plDiscrExclus2")!=null) this.plDiscrExclus2=Double.parseDouble(properties.getProperty(prefix+"plDiscrExclus2"));
if (properties.getProperty(prefix+"plDiscrStrict")!=null) this.plDiscrStrict=Boolean.parseBoolean(properties.getProperty(prefix+"plDiscrStrict"));
if (properties.getProperty(prefix+"plCostKrq")!=null) this.plCostKrq=Double.parseDouble(properties.getProperty(prefix+"plCostKrq"));
if (properties.getProperty(prefix+"plCostKrqEq")!=null) this.plCostKrqEq=Double.parseDouble(properties.getProperty(prefix+"plCostKrqEq"));
if (properties.getProperty(prefix+"plCostWrq")!=null) this.plCostWrq=Double.parseDouble(properties.getProperty(prefix+"plCostWrq"));
......@@ -3338,6 +3375,19 @@ public class EyesisCorrectionParameters {
gd.addNumericField("When merging with neighbors cut the tail that is worse than scaled best", this.plCutTail, 6);
gd.addNumericField("Set cutoff value livel not less than this", this.plMinTail, 6);
gd.addMessage ("--- Parameters to regenerate planes using preliminary tile connections ---");
gd.addNumericField("Maximal disparity difference from the plane to consider tile", this.plDiscrTolerance, 6);
gd.addNumericField("Parallel move known planes around original know value for the best overall fit",this.plDiscrDispRange, 6);
gd.addNumericField("Number of steps (each direction) for each plane to search for the best fit (0 - single, 1 - 1 each side)",this.plDiscrSteps, 0);
gd.addNumericField("Total number of variants to try (protect from too many planes)", this.plDiscrVariants, 0);
gd.addNumericField("What plane to use as a hint: 0 - weighted, 1 - equalized, 2 - best, 3 - combined", this.plDiscrMode, 0);
gd.addNumericField("Squared add to variance to calculate reverse flatness (used mostly for single-cell clusters)",this.plDiscrVarFloor, 6);
gd.addNumericField("Gaussian sigma to compare how measured data is attracted to planes", this.plDiscrSigma, 6);
gd.addNumericField("Sigma to blur histograms while re-discriminating", this.plDiscrBlur, 6);
gd.addNumericField("Tile exclusivity: 1.0 - tile belongs to one plane only, 0.0 - regardless of others",this.plDiscrExclusivity, 6);
gd.addNumericField("For second pass if exclusivity > 1.0 - will assign only around strong neighbors",this.plDiscrExclus2, 6);
gd.addCheckbox ("When growing selection do not allow any offenders around (false - more these than others)", this.plDiscrStrict);
gd.addMessage ("--- Planes merge costs ---");
gd.addNumericField("Cost of merge quality weighted in disparity space", this.plCostKrq, 6);
gd.addNumericField("Cost of merge quality equal weight in disparity space", this.plCostKrqEq, 6);
......@@ -3717,6 +3767,18 @@ public class EyesisCorrectionParameters {
this.plCutTail= gd.getNextNumber();
this.plMinTail= gd.getNextNumber();
this.plDiscrTolerance= gd.getNextNumber();
this.plDiscrDispRange= gd.getNextNumber();
this.plDiscrSteps= (int) gd.getNextNumber();
this.plDiscrVariants= (int) gd.getNextNumber();
this.plDiscrMode= (int) gd.getNextNumber();
this.plDiscrVarFloor= gd.getNextNumber();
this.plDiscrSigma= gd.getNextNumber();
this.plDiscrBlur= gd.getNextNumber();
this.plDiscrExclusivity= gd.getNextNumber();
this.plDiscrExclus2= gd.getNextNumber();
this.plDiscrStrict= gd.getNextBoolean();
this.plCostKrq= gd.getNextNumber();
this.plCostKrqEq= gd.getNextNumber();
this.plCostWrq= gd.getNextNumber();
......
......@@ -282,7 +282,7 @@ public class LinkPlanes {
w2, // double w2)
0.0);// double eigen_floor)
double this_wrq_norm = this_rq;
double this_wrq_norm = this_wrq;
if ((w1 + w2) < plWeakWorsening) this_wrq_norm *= (w1 + w2) / plWeakWorsening; // forgive more for weak planes
double this_wrq_eq = mergeRQuality(
......@@ -293,7 +293,7 @@ public class LinkPlanes {
1.0, // double w2)
0.0);// double eigen_floor)
this_wrq_eq /= (w1 + w2); // for comparison reduce this value for stronger planes
double this_wrq_eq_norm = this_rq_eq;
double this_wrq_eq_norm = this_wrq_eq;
if ((w1 + w2) < plWeakWorsening) this_wrq_eq_norm *= (w1 + w2) / plWeakWorsening; // forgive more for weak planes
boolean OK_to_merge = false;
......@@ -395,9 +395,13 @@ public class LinkPlanes {
if (debugLevel > 1){
System.out.println(prefix+" (do not fit) this_rq="+this_rq+
", this_rq_eq="+this_rq_eq+
" this_wrq=" + (this_wrq) +
" this_wrq_eq=" + (this_wrq_eq) +
" w1="+w1+" w2="+w2+
" L1="+plane1.getValue()+" L2="+plane2.getValue()+
" L="+merged_ev+" L_eq="+merged_ev_eq);
" L="+merged_ev+" L_eq="+merged_ev_eq+
" L1W="+plane1.getWValue()+" L2W="+plane2.getWValue()+" LW="+merged_wev+
" L_eqW="+merged_wev_eq);
System.out.println(prefix+" (do not fit) world sin2 ="+
plane1.getWorldSin2(plane2));
System.out.println(prefix+" (do not fit)"+
......
......@@ -1182,11 +1182,14 @@ public class SuperTiles{
int nd = num_pm + 2 * num_ml + ml;
data [nd] = new double [4* superTileSize*superTileSize];
int [] multi_sel = new int [4* superTileSize*superTileSize];
for (int i = 0; i < data[nd].length; i++){
data [nd][i] = Double.NaN;
for (int np = 0; np < num_p; np++) if ((selections [np] != null) && (selections [np][ml] != null) && selections [np][ml][i]){
data [nd][i] = np + 1;
break;
// data [nd][i] = np + 1;
multi_sel[i] |= (1 << np);
data [nd][i] = multi_sel[i];
// break;
}
}
data [num_pm + 0 * num_ml + ml] = disp_strength[ml][0];
......@@ -1633,7 +1636,7 @@ public class SuperTiles{
* Sort plane data by center (plane or supertile) disparity
*
* @param growSelection
* @param stMeasSel
* @param stMeasSel Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
* @param plDispNorm
* @param plMinPoints
* @param plPreferDisparity
......@@ -1844,8 +1847,8 @@ public class SuperTiles{
if (dl > 0){
System.out.println("initialDiscriminateTiles() selecting: nsTile="+nsTile);
}
int stileY = nsTile / stilesX;
int stileX = nsTile % stilesX;
// int stileY = nsTile / stilesX;
// int stileX = nsTile % stilesX;
// int [] sTiles = {stileX, stileY};
double [][][][] ds = {vert_disp_strength[nsTile],hor_disp_strength[nsTile]};
boolean [][][][] sels_all = {new_planes_vert[nsTile],new_planes_hor[nsTile]}; // make possible to iterate
......@@ -1948,9 +1951,9 @@ public class SuperTiles{
* Total weight of the fitted tiles? RMS?
* @param planes per-supertile, per plane array of plane data instances. Should have
* nonexclusiveStar and nonexclusiveStarEq calculated
* @param stMeasSel - select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
* @param plDispNorm - normalization of the measured disparity precision - closer objects will have disparity
* difference proportionally reduced
* @param plMinPoints minimal number of points in a plane
* difference proportionally reduced
* @param plPreferDisparity kept for historical reasons - when true, select disparity-most vector even if it has higher eigenvalue
* @param geometryCorrection GeometryCorrection instance to use
* @param correct_distortions correct geometrical distortions when converting to/from world coordinates
......@@ -1958,45 +1961,135 @@ public class SuperTiles{
* @param smplSide sample side for averaging/filtering tile disparities
* @param smplNum number of best samples used fro averaging
* @param smplRms maximal sample disparity rms to consider sample valid
* @param max_disp_diff maximal disparity difference from the planes
* @param disp_step disparity scan step when searching for optimal fit
* @param steps_per_plane number of disparity steps to try around initial plane
* @param mode which of the calculated planes to use - 0 - weighted, 1 - equalized, 2 heaviest of the two, weighted combination
* @param plDiscrTolerance maximal disparity difference from the plane to consider tile
* @param plDiscrDispRange parallel move known planes around original know value for the best overall fit
* @param plDiscrSteps number of steps (each direction) for each plane to search for the best fit (0 - single, 1 - 1 each side)
* @param plDiscrVariants total number of variants to try (protect from too many planes)
* @param plDiscrMode what plane to use as a hint: 0 - weighted, 1 - equalized, 2 - best, 3 - combined
* @param plDiscrVarFloor squared add to variance to calculate reverse flatness (used mostly for single-cell clusters)
* @param plDiscrSigma Gaussian sigma to compare how measured data is attracted to planes
* @param plDiscrBlur sigma to blur histograms while re-discriminating
* @param plDiscrExclusivity tile exclusivity: 1.0 - tile belongs to one plane only, 0.0 - regardless of others
* @param debugLevel debug level
* @param dbg_X supertile X for elevated debug level
* @param dbg_Y supertile X for elevated debug level
* @return per-tile, per plane, per measurement layer (type of correlation - combo, 4, hor, vert), per tile selections of
* filtered tiles
*/
public boolean [][][][] refineDiscriminateTiles(
final TilePlanes.PlaneData [][] planes,
final TilePlanes.PlaneData [][] planes,
final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
final double plDispNorm,
final int plMinPoints, // = 5; // Minimal number of points for plane detection
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 GeometryCorrection geometryCorrection,
final boolean correct_distortions,
final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
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 smplMode, // = true; // Use sample mode (false - regular tile mode)
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 double max_disp_diff, // maximal disparity difference from the plane to consider tile
final double disp_step, // parallel move known planes around original know value for the best overall fit
final int steps_per_plane, // number of steps for each plane to search for the best fit
final int mode, // 0 - weighted, 1 - equalized, 2 - best, 3 - combined
final double plDiscrTolerance, // = 0.4; // Maximal disparity difference from the plane to consider tile
final double plDiscrDispRange, // = 0.6; // Parallel move known planes around original know value for the best overall fit
final int plDiscrSteps, // = 3; // Number of steps (each direction) for each plane to search for the best fit (0 - single, 1 - 1 each side)
final int plDiscrVariants, // = 100; // Total number of variants to try (protect from too many planes)
final int plDiscrMode, // = 3; // What plane to use as a hint: 0 - weighted, 1 - equalized, 2 - best, 3 - combined
final double plDiscrVarFloor, // = 0.03; // Squared add to variance to calculate reverse flatness (used mostly for single-cell clusters)
final double plDiscrSigma, // = 0.05; // Gaussian sigma to compare how measured data is attracted to planes
final double plDiscrBlur, // = 0.1; // Sigma to blur histograms while re-discriminating
final double plDiscrExclusivity, // = 1.5; // Tile exclusivity: 1.0 - tile belongs to one plane only, 0.0 - regardless of others
final double plDiscrExclus2, // = 0.8; // For second pass if exclusivity > 1.0 - will assign only around strong neighbors
final boolean plDiscrStrict, // = true; // When growing selection do not allow any offenders around (false - more these than others)
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
// create a list of usable planes according to the mode
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
final int superTileSize = tileProcessor.getSuperTileSize();
final int tileSize = tileProcessor.getTileSize();
final int stilesX = (tilesX + superTileSize -1)/superTileSize;
final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final int nStiles = stilesX * stilesY;
final TilePlanes tpl = new TilePlanes(tileSize,superTileSize, geometryCorrection);
final Thread[] threads = ImageDtt.newThreadArray((debugLevel > 1)? 1 : tileProcessor.threadsMax);
return null;
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 [][][][] planes_selections = new boolean [nStiles][][][]; // num_tiles
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nsTile = ai.getAndIncrement(); nsTile < nStiles; nsTile = ai.getAndIncrement()) {
int dl = ((debugLevel > -1) && (nsTile == debug_stile)) ? 3 : 1;
if (dl > 1){
System.out.println("refineDiscriminateTiles() selecting: nsTile="+nsTile);
}
int stileY = nsTile / stilesX;
int stileX = nsTile % stilesX;
int [] sTiles = {stileX, stileY};
TilePlanes.PlaneData pd0 = tpl.new PlaneData (
sTiles, // int [] sTileXY,
tileSize, // int tileSize,
geometryCorrection, // GeometryCorrection geometryCorrection,
correct_distortions,
measuredLayers, // MeasuredLayers measuredLayers,
plPreferDisparity); // boolean preferDisparity)
/*
planes_selections[nsTile] = pd0.reDiscriminateTiles_0(
""+nsTile, // String prefix,
planes[nsTile], // final PlaneData [] planes,
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
smplMode, // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
smplSide, // final int smplSide, // = 2; // Sample size (side of a square)
smplNum, // final int smplNum, // = 3; // Number after removing worst
smplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
plDiscrTolerance, // final double max_disp_diff, // maximal disparity difference from the plane to consider tile
plDiscrDispRange, // final double disp_range, // parallel move known planes around original know value for the best overall fit
plDiscrSteps, // final int amplitude_steps, // number of steps (each direction) for each plane to search for the best fit (0 - single, 1 - 1 each side)
plDiscrVariants, // final int num_variants, // total number of variants to try (protect from too many planes)
plDiscrMode, // final int mode, // 0 - weighted, 1 - equalized, 2 - best, 3 - combined
dl); // debugLevel); // final int debugLevel)
*/
planes_selections[nsTile] = pd0.reDiscriminateTiles(
""+nsTile, // String prefix,
planes[nsTile], // final PlaneData [] planes,
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plDispNorm, // final double dispNorm, // Normalize disparities to the average if above
smplMode, // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
smplSide, // final int smplSide, // = 2; // Sample size (side of a square)
smplNum, // final int smplNum, // = 3; // Number after removing worst
smplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
plDiscrTolerance, // final double disp_tolerance, // maximal disparity difference from the plane to consider tile
plDiscrVarFloor, // final double disp_var_floor, // squared add to variance to calculate reverse flatness (used mostly for single-cell clusters)
plDiscrSigma, // final double disp_sigma, // G.sigma to compare how measured data is attracted to planes
plDiscrDispRange, // final double disp_range, // parallel move known planes around original know value for the best overall fit
plDiscrSteps, // final int amplitude_steps, // number of steps (each direction) for each plane to search for the best fit (0 - single, 1 - 1 each side)
plDiscrBlur, // final double hist_blur, // Sigma to blur histogram
plDiscrExclusivity, // final double exclusivity, // 1.0 - tile belongs to one plane only, 0.0 - regardless of others
plDiscrExclus2, // final double excluisivity2, // = 0.8; // For second pass if exclusivity > 1.0 - will assign only around strong neighbors
plDiscrStrict, // final boolean exclusivity_strict// = true; // When growing selection do not allow any offenders around (false - more these than others)
plDiscrMode, // final int mode, // 0 - weighted, 1 - equalized, 2 - best, 3 - combined
dl); // debugLevel); // final int debugLevel)
}
}
};
}
ImageDtt.startAndJoin(threads);
return planes_selections;
}
public TilePlanes.PlaneData [][] createPlanesFromSelections(
final boolean [][][][] plane_selections, // = new boolean [nStiles][][][]; // num_tiles
final double [][][][] disp_strength,
......@@ -2177,7 +2270,7 @@ public class SuperTiles{
final boolean msUseSel, // final boolean use_sel,
final boolean msDivideByArea, // final boolean divide_by_area,
final double msScaleProj, // final double scale_projection,
final double smallDiff, // = 0.4; // Consider merging initial planes if disparity difference below
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])
......@@ -2187,11 +2280,11 @@ public class SuperTiles{
{
// 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
boolean [][][][] plane_selections = initialDiscriminateTiles(
growSelection, // final int growSelection, // grow initial selection before processing
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
......@@ -2219,6 +2312,152 @@ public class SuperTiles{
dbg_Y); // final int dbg_Y)
// get per-tile disparity strength again (may consider using non-filtered data here)
double [][][][] disp_strength = getPlaneDispStrengths( // here use actual disparity, not tilted
null, // final double [] world_plane_norm, // real world normal vector to a suggested plane family (0,1,0) for horizontal planes
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plPreferDisparity, // final boolean plPreferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
geometryCorrection, // final GeometryCorrection geometryCorrection,
correct_distortions, // final boolean correct_distortions,
smplMode, // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
smplSide, // final int smplSide, // = 2; // Sample size (side of a square)
smplNum, // final int smplNum, // = 3; // Number after removing worst
smplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
debugLevel, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y)
// Create plane data (ellipsoids) from the disparity/strength data and tile selections,
// remove outliers, order each supertile result in ascending disparity (from far to near)
// TODO: consider 1) assigning of the non-assigned tiles to clusters and 2) re-assigning all clusters one by one to the "best" plane
TilePlanes.PlaneData [][] new_planes = createPlanesFromSelections(
plane_selections, // final boolean [][][][] plane_selections, // = new boolean [nStiles][][][]; // num_tiles
disp_strength, // final double [][][][] disp_strength,
plDispNorm, // final double plDispNorm,
plMinPoints, // final int plMinPoints, // = 5; // Minimal number of points for plane detection
plTargetEigen, // final double plTargetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
plFractOutliers, // final double plFractOutliers, // = 0.3; // Maximal fraction of outliers to remove
plMaxOutliers, // final int plMaxOutliers, // = 20; // Maximal number of outliers to remove
plPreferDisparity, // final boolean plPreferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
geometryCorrection, // final GeometryCorrection geometryCorrection,
correct_distortions, // final boolean correct_distortions,
smplMode, // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
smplSide, // final int smplSide, // = 2; // Sample size (side of a square)
smplNum, // final int smplNum, // = 3; // Number after removing worst
smplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
debugLevel + 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
}
/**
* Re-assign tiles to the planes according to fitted planes. Scans each known plane parallel with specified
* size steps and specified number of steps, maximizing overall fit quality.
* Total weight of the fitted tiles? RMS? (now using number of fitted planes, if the same - than rms)
* @param stMeasSel - select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
* @param plDispNorm - normalization of the measured disparity precision - closer objects will have disparity
* difference proportionally reduced
* @param plMinPoints Minimal number of plane tiles to remain
* @param plTargetEigen target smallest eigenvalue (try to remove outliers if above)
* @param plFractOutliers maximal fraction of all tiles to remove as outliers
* @param plMaxOutliers maximal absolute number of tiles to remove as outliers
* @param plPreferDisparity kept for historical reasons - when true, select disparity-most vector even if it has higher eigenvalue
* @param geometryCorrection GeometryCorrection instance to use
* @param correct_distortions correct geometrical distortions when converting to/from world coordinates
* @param smplMode sample mode
* @param smplSide sample side for averaging/filtering tile disparities
* @param smplNum number of best samples used fro averaging
* @param smplRms maximal sample disparity rms to consider sample valid
* @param plDiscrTolerance maximal disparity difference from the plane to consider tile
* @param plDiscrDispRange parallel move known planes around original know value for the best overall fit
* @param plDiscrSteps number of steps (each direction) for each plane to search for the best fit (0 - single, 1 - 1 each side)
* @param plDiscrVariants total number of variants to try (protect from too many planes)
* @param plDiscrMode what plane to use as a hint: 0 - weighted, 1 - equalized, 2 - best, 3 - combined
* @param plDiscrVarFloor squared add to variance to calculate reverse flatness (used mostly for single-cell clusters)
* @param plDiscrSigma Gaussian sigma to compare how measured data is attracted to planes
* @param plDiscrBlur sigma to blur histograms while re-discriminating
* @param plDiscrExclusivity tile exclusivity: 1.0 - tile belongs to one plane only, 0.0 - regardless of others
* @param debugLevel debug level
* @param dbg_X supertile X for elevated debug level
* @param dbg_Y supertile X for elevated debug level
*/
public void regeneratePlanes(
final TilePlanes.PlaneData [][] planes,
final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
final double plDispNorm,
final int plMinPoints, // = 5; // Minimal number of points for plane detection
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 GeometryCorrection geometryCorrection,
final boolean correct_distortions,
final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
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 double plDiscrTolerance, // = 0.4; // Maximal disparity difference from the plane to consider tile
final double plDiscrDispRange, // = 0.6; // Parallel move known planes around original know value for the best overall fit
final int plDiscrSteps, // = 3; // Number of steps (each direction) for each plane to search for the best fit (0 - single, 1 - 1 each side)
final int plDiscrVariants, // = 100; // Total number of variants to try (protect from too many planes)
final int plDiscrMode, // = 3; // What plane to use as a hint: 0 - weighted, 1 - equalized, 2 - best, 3 - combined
final double plDiscrVarFloor, // = 0.03; // Squared add to variance to calculate reverse flatness (used mostly for single-cell clusters)
final double plDiscrSigma, // = 0.05; // Gaussian sigma to compare how measured data is attracted to planes
final double plDiscrBlur, // = 0.1; // Sigma to blur histograms while re-discriminating
final double plDiscrExclusivity, // = 1.5; // Tile exclusivity: 1.0 - tile belongs to one plane only, 0.0 - regardless of others
final double plDiscrExclus2, // = 0.8; // For second pass if exclusivity > 1.0 - will assign only around strong neighbors
final boolean plDiscrStrict, // = true; // When growing selection do not allow any offenders around (false - more these than others)
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
// 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
boolean [][][][] plane_selections = refineDiscriminateTiles(
planes, // final TilePlanes.PlaneData [][] planes,
stMeasSel, // final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
plDispNorm, // final double plDispNorm,
plPreferDisparity, // final boolean plPreferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
geometryCorrection, // final GeometryCorrection geometryCorrection,
correct_distortions, // final boolean correct_distortions,
smplMode, // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
smplSide, // final int smplSide, // = 2; // Sample size (side of a square)
smplNum, // final int smplNum, // = 3; // Number after removing worst
smplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
plDiscrTolerance, //final double plDiscrTolerance, // = 0.4; // Maximal disparity difference from the plane to consider tile
plDiscrDispRange, // final double plDiscrDispRange, // = 0.6; // Parallel move known planes around original know value for the best overall fit
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)
plDiscrVariants, // final int plDiscrVariants, // = 100; // Total number of variants to try (protect from too many planes)
plDiscrMode, // final int plDiscrMode, // = 3; // What plane to use as a hint: 0 - weighted, 1 - equalized, 2 - best, 3 - combined
plDiscrVarFloor, // final double plDiscrVarFloor, // = 0.03; // Squared add to variance to calculate reverse flatness (used mostly for single-cell clusters)
plDiscrSigma, // final double plDiscrSigma, // = 0.05; // Gaussian sigma to compare how measured data is attracted to planes
plDiscrBlur, // final double plDiscrBlur, // = 0.1; // Sigma to blur histograms while re-discriminating
plDiscrExclusivity,// final double plDiscrExclusivity, // = 0.5; // Tile exclusivity: 1.0 - tile belongs to one plane only, 0.0 - regardless of others
plDiscrExclus2, // final double plDiscrExclus2, // = 0.5; // For second pass if exclusivity > 1.0 - will assign only around strong neighbors
plDiscrStrict, // final boolean plDiscrStrict, // = true; // When growing selection do not allow any offenders around (false - more these than others)
2, // debugLevel, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y)
// get per-tile disparity strength again (may consider using non-filtered data here) ?
double [][][][] disp_strength = getPlaneDispStrengths( // here use actual disparity, not tilted
null, // final double [] world_plane_norm, // real world normal vector to a suggested plane family (0,1,0) for horizontal planes
......@@ -5648,25 +5887,6 @@ public class SuperTiles{
return diff; // return maximal difference
}
public double [][] planesGetDiff(
final TilePlanes.PlaneData[][] measured_planes,
final TilePlanes.PlaneData[][] mod_planes,
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 stilesX = (tilesX + superTileSize -1)/superTileSize;
final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final int debug_stile = dbg_Y * stilesX + dbg_X;
final TilePlanes.PlaneData[][] new_planes = copyPlanes(mod_planes);
final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.threadsMax);
final double [][] diffs = null;
return diffs;
}
/**
* Prepare visualization of the plane separation lines
......
......@@ -2212,13 +2212,13 @@ public class TilePlanes {
return plane;
}
public double[][] getDoublePlaneDisparityStrength_old(
public double[][] getDoublePlaneDisparityStrength(
double [] window,
boolean use_sel,
boolean divide_by_area,
double scale_projection,
int debugLevel)
{ return getDoublePlaneDisparityStrength_old(
{ return getDoublePlaneDisparityStrength(
true,
window,
use_sel,
......@@ -2261,7 +2261,7 @@ public class TilePlanes {
* @return a pair of arrays {disparity, strength}, each [2*superTileSize * 2*superTileSize]
*/
// obsolete, convert to another version ?
public double[][] getDoublePlaneDisparityStrength_old(
public double[][] getDoublePlaneDisparityStrength(
boolean useWorld,
double [] window,
boolean use_sel,
......@@ -3211,7 +3211,7 @@ public class TilePlanes {
boolean correct_distortions,
int debugLevel)
{
double delta = 0.0001;
// double delta = 0.0001;
if (center_xyz != null) return center_xyz;
setCorrectDistortions(correct_distortions);
// get pixel coordinates of the plane origin point
......@@ -3457,13 +3457,10 @@ public class TilePlanes {
return null;
}
public boolean [][][] refineDiscriminateTiles(
public boolean [][][] reDiscriminateTiles_0(
String prefix,
final PlaneData [] planes,
final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
final double plDispNorm,
final int plMinPoints, // = 5; // Minimal number of points for plane detection
final GeometryCorrection geometryCorrection,
final boolean correct_distortions,
final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
final int smplSide, // = 2; // Sample size (side of a square)
......@@ -3477,6 +3474,9 @@ public class TilePlanes {
final int mode, // 0 - weighted, 1 - equalized, 2 - best, 3 - combined
final int debugLevel)
{
final int size2 = 4 * superTileSize*superTileSize;
final double max_disp_diff2 = max_disp_diff*max_disp_diff;
TileNeibs tileNeibs = new TileNeibs(2 * stSize, 2 * stSize);
if (planes == null) return null;
// create a list of usable planes according to the mode
ArrayList<PlaneData> tilePlanes = new ArrayList<PlaneData>();
......@@ -3485,22 +3485,68 @@ public class TilePlanes {
PlaneData equal_pd = planes[np].getNonexclusiveStarEq();
switch (mode){
case 0:
if (weighted_pd == null)throw new IllegalArgumentException ("refineDiscriminateTiles(): getNonexclusiveStar() retgurned null");
tilePlanes.add(weighted_pd);
if (weighted_pd == null){
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStar() returned null, trying getNonexclusiveStarEq");
if (equal_pd == null) {
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null, using plane itself");
tilePlanes.add(planes[np]);
} else {
tilePlanes.add(equal_pd);
}
// throw new IllegalArgumentException ("refineDiscriminateTiles(): getNonexclusiveStar() returned null");
} else {
tilePlanes.add(weighted_pd);
}
break;
case 1:
if (equal_pd == null)throw new IllegalArgumentException ("refineDiscriminateTiles(): getNonexclusiveStarEq() retgurned null");
tilePlanes.add(equal_pd);
if (equal_pd == null) { //throw new IllegalArgumentException ("refineDiscriminateTiles(): getNonexclusiveStarEq() returned null");
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null, trying getNonexclusiveStar");
if (weighted_pd == null) {
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStar() returned null, using plane itself");
tilePlanes.add(planes[np]);
} else {
tilePlanes.add(weighted_pd);
}
} else {
tilePlanes.add(equal_pd);
}
break;
case 2:
if (weighted_pd == null)throw new IllegalArgumentException ("refineDiscriminateTiles(): getNonexclusiveStar() retgurned null");
if (equal_pd == null)throw new IllegalArgumentException ("refineDiscriminateTiles(): getNonexclusiveStarEq() retgurned null");
if (weighted_pd == null) { //throw new IllegalArgumentException ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStar() returned null");
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStar() returned null, trying getNonexclusiveStarEq");
if (equal_pd == null) {
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null, using plane itself");
tilePlanes.add(planes[np]);
} else {
tilePlanes.add(equal_pd);
}
break;
}
if (equal_pd == null) { //throw new IllegalArgumentException ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null");
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null, trying getNonexclusiveStar");
tilePlanes.add(weighted_pd);
break;
}
if (weighted_pd.getWeight() > equal_pd.getWeight()) tilePlanes.add(weighted_pd);
else tilePlanes.add(equal_pd);
break;
case 3:
if (weighted_pd == null)throw new IllegalArgumentException ("refineDiscriminateTiles(): getNonexclusiveStar() retgurned null");
if (equal_pd == null)throw new IllegalArgumentException ("refineDiscriminateTiles(): getNonexclusiveStarEq() retgurned null");
if (weighted_pd == null) { //throw new IllegalArgumentException ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStar() returned null");
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStar() returned null, trying getNonexclusiveStarEq");
if (equal_pd == null) {
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null, using plane itself");
tilePlanes.add(planes[np]);
} else {
tilePlanes.add(equal_pd);
}
break;
}
if (equal_pd == null) { //throw new IllegalArgumentException ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null");
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null, trying getNonexclusiveStar");
tilePlanes.add(weighted_pd);
break;
}
PlaneData combo_pd = weighted_pd.mergePlaneToThis(
equal_pd, // PlaneData otherPd,
1.0, // double scale_other,
......@@ -3508,15 +3554,20 @@ public class TilePlanes {
false, // boolean ignore_weights,
true, // boolean sum_weights,
preferDisparity, // boolean preferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
debugLevel - 2); // int debugLevel)
debugLevel - 3); // int debugLevel)
tilePlanes.add(combo_pd);
break;
default:
throw new IllegalArgumentException ("refineDiscriminateTiles(): invalid mode="+mode);
throw new IllegalArgumentException ("refineDiscriminateTiles() "+prefix+":"+np+": invalid mode="+mode);
}
}
if (tilePlanes.isEmpty()){
return null;
}
if (debugLevel > 1) {
System.out.println ("refineDiscriminateTiles() "+prefix+" - step 1");
}
// get measured disparity/strength data, filtered, not tilted
double [][][] disp_strength = new double[measuredLayers.getNumLayers()][][];
for (int ml = 0; ml < disp_strength.length; ml++) if ((stMeasSel & ( 1 << ml)) != 0){
......@@ -3543,8 +3594,10 @@ public class TilePlanes {
true); // boolean null_if_none);
}
}
double [] window = getWindow (2 * superTileSize);
// double [] window = getWindow (2 * superTileSize);
if (debugLevel > 1) {
System.out.println ("refineDiscriminateTiles() "+prefix+" - step 2");
}
// get all original planes
int num_planes = tilePlanes.size();
double [][][] pds = new double [num_planes][][];
......@@ -3559,7 +3612,80 @@ public class TilePlanes {
1.0, // double scale_projection,
0.0, // double fraction_uni,
0); // int debugLevel)
}
double [][][] flatness = new double [num_planes][disp_strength.length][];
int [][][] num_cells = new int [num_planes][disp_strength.length][];
for (int np = 0; np < pds.length; np++){
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
flatness[np][ml] = new double[size2];
num_cells[np][ml] = new int[size2];
for (int indx = 0; indx < size2; indx++) if (disp_strength[ml][1][indx] > 0.0){
double d0 = pds[np][0][indx]; // disp_strength[ml][0][indx];
double sw = disp_strength[ml][1][indx], sd = 0.0, sd2 = 0.0;
num_cells[np][ml][indx]++;
for (int dir = 0; dir<8; dir++){
int indx1 = tileNeibs.getNeibIndex(indx, dir);
if (indx1 >= 0){
double w = disp_strength[ml][1][indx1];
if (w > 0.0){
double d = disp_strength[ml][0][indx1] - d0;
sw += w;
sd += w * d;
sd2 += w * d * d;
num_cells[np][ml][indx]++;
}
}
}
if (sw > 0.0) {
sd /= sw;
sd2 /= sw;
sd2 -= sd * sd;
}
flatness[np][ml][indx] = sd2;
}
}
}
if (debugLevel > 2){
int dbg_ml = 0; // to protect from different layer configuration
for (; dbg_ml < disp_strength.length; dbg_ml++){
if (disp_strength[dbg_ml] != null) break;
}
//disp_strength[dbg_ml][0], disp_strength[dbg_ml][1] * 10, disp_strength[dbg_ml][0] - pds[np][0], pds[np][0]
String [] dbg_titles = new String[2 + 5 * num_planes];
double [][] dbg_img = new double [dbg_titles.length][];
dbg_titles[0] = "disp_"+dbg_ml;
dbg_titles[1] = "str_"+dbg_ml;
dbg_img[0] = disp_strength[dbg_ml][0];
dbg_img[1] = disp_strength[dbg_ml][1];
for (int np = 0; np < num_planes; np++){
dbg_titles[2 + 0 * num_planes + np] = "pln_"+np;
dbg_titles[2 + 1 * num_planes + np] = "diff_"+np;
dbg_titles[2 + 2 * num_planes + np] = "flat_"+np;
dbg_titles[2 + 3 * num_planes + np] = "rflat_"+np;
dbg_titles[2 + 3 * num_planes + np] = "nrflat_"+np;
dbg_img[2 + 0 * num_planes + np] = pds[np][0];
dbg_img[2 + 1 * num_planes + np] = disp_strength[dbg_ml][0].clone();
dbg_img[2 + 2 * num_planes + np] = flatness[np][dbg_ml];
dbg_img[2 + 3 * num_planes + np] = new double[size2];
dbg_img[2 + 4 * num_planes + np] = new double[size2];
for (int i = 0; i < size2; i++) {
dbg_img[2 + 1 * num_planes + np][i] -= pds[np][0][i];
dbg_img[2 + 3 * num_planes + np][i] = 1.0 / (flatness[np][dbg_ml][i] + 0.001);
dbg_img[2 + 4 * num_planes + np][i] = num_cells[np][dbg_ml][i] * 1.0 / (flatness[np][dbg_ml][i] + 0.001);
if (disp_strength[dbg_ml][1][i] == 0.0){
dbg_img[2 + 1 * num_planes + np][i] = Double.NaN;
dbg_img[2 + 2 * num_planes + np][i] = Double.NaN;
dbg_img[2 + 3 * num_planes + np][i] = Double.NaN;
dbg_img[2 + 4 * num_planes + np][i] = Double.NaN;
}
}
}
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays();
sdfa_instance.showArrays(dbg_img, 2 * superTileSize, 2 * superTileSize, true, "refine-"+prefix,dbg_titles);
}
// calculate number of the variants for each plane
int extra_vars = (((int) Math.pow(num_variants, 1.0/num_planes)) - 1) / 2; // 0 - single, 1 - 3 (1 each direction), ...
......@@ -3572,15 +3698,123 @@ public class TilePlanes {
disps[2 * i + 2] = -disps[2 * i + 1];
}
int [] state = new int [num_planes]; // variants counter
// for (int variant = 0; i < num_variants; variant++ )
boolean [][][] best_selections = null;
// int best_num_tiles = 0;
double best_cost = Double.NaN;
if (debugLevel > 1) {
System.out.println ("refineDiscriminateTiles() "+prefix+" - step 3");
}
while (true){
if (debugLevel > 1) {
System.out.print ("refineDiscriminateTiles() "+prefix+" - state:");
for (int np = 0; np < num_planes; np++){
System.out.print(" "+state[np]);
}
System.out.println();
}
// evaluate current variant
double [] weights = new double [num_planes];
double [] err2 = new double [num_planes];
boolean
double [] diffs0 = new double [num_planes];
boolean [][][] var_sels = new boolean [num_planes][disp_strength.length][];
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
for (int nTile = 0; nTile < size2; nTile++) if (disp_strength[ml][1][nTile] != 0){
// find best fit
int best_np = -1;
double best_err2 = max_disp_diff2;
for (int np = 0; np < num_planes; np++){
double e2 = disp_strength[ml][0][nTile] - (pds[np][0][nTile] + disps[state[np]]);
e2 *= e2;
if (e2 < best_err2){
best_np = np;
best_err2 = e2;
}
}
if (best_np >= 0) { // found acceptable assignment
double w = disp_strength[ml][1][nTile]; // * window[nTile];
double d = disp_strength[ml][0][nTile] - (pds[best_np][0][nTile] + disps[state[best_np]]);
weights[best_np] += w;
diffs0[best_np] += w*d;
}
}
}
if (debugLevel > 1) {
System.out.println ("refineDiscriminateTiles() "+prefix+" - pass1 DONE");
}
// second pass - use new averages disparity offsets, that may change assignments
for (int np = 0; np < num_planes; np++){
if (weights[np] > 0.0) diffs0[np] /= weights[np];
}
weights = new double [num_planes];
double [] diffs = new double [num_planes];
double [] diffs2 = new double [num_planes];
int [] ntiles = new int [num_planes];
int num_tiles = 0;
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
for (int np = 0; np < num_planes; np++){
var_sels[np][ml] = new boolean [size2];
}
for (int nTile = 0; nTile < size2; nTile++) if (disp_strength[ml][1][nTile] != 0){
// find best fit
int best_np = -1;
double best_err2 = max_disp_diff2;
for (int np = 0; np < num_planes; np++){
double e2 = disp_strength[ml][0][nTile] - (pds[np][0][nTile] + disps[state[np]]+ diffs0[np]);
e2 *= e2;
if (e2 < best_err2){
best_np = np;
best_err2 = e2;
}
}
if (best_np >= 0) { // found acceptable assignment
double w = disp_strength[ml][1][nTile]; // * window[nTile];
double d = disp_strength[ml][0][nTile] - (pds[best_np][0][nTile] + disps[state[best_np]]);
weights[best_np] += w;
diffs[best_np] += w*d;
diffs2[best_np] += w*d*d;
ntiles[best_np]++;
var_sels[best_np][ml][nTile] = true;
num_tiles ++;
}
}
}
for (int np = 0; np < num_planes; np++) if (weights[np] > 0.0){
diffs[np] /= weights[np];
diffs2[np] /= weights[np];
diffs2[np] -= diffs[np]*diffs[np];
}
// How to decide if this variant is better? Have number of tiles that fit, per-plane weights and per-plane rms=sqrt(diffs2)
// start with just number of tiles fit
double cost = 0;
double weight = 0.0;
for (int np = 0; np < num_planes; np++) {
weight += weights[np];
cost += weights[np]*diffs2[np];
}
if ((weight > 0.0) && (num_tiles > 0)){
double corr_cost = cost/num_tiles;
if (debugLevel > 1) {
System.out.print ("refineDiscriminateTiles() "+prefix+": [");
for (int np = 0; np < num_planes; np++){
System.out.print (" "+state[np]);
}
System.out.println ("] num_tiles = "+num_tiles+" weight="+weight+" corr_cost="+corr_cost+" cost="+cost);
}
if (Double.isNaN(best_cost) || (best_cost > corr_cost)) {
best_cost = corr_cost;
best_selections = var_sels;
}
}
// if (num_tiles > best_num_tiles) {
// best_num_tiles = num_tiles;
// best_selections = var_sels;
// }
if (debugLevel > 1) {
System.out.println ("refineDiscriminateTiles() "+prefix+" - pass2 DONE");
}
// calculate next variant
boolean all_done = true;
for (int i = 0; i < num_planes; i ++){
......@@ -3598,11 +3832,552 @@ public class TilePlanes {
}
}
return best_selections;
}
/**
* re-discriminate tiles between supertiles in the list using hints from the already calculated planes and their neighbors
* @param prefix text to be used in debug output (such as supertile number)
* @param planes array of PlaneData instances of the current supertile to be used as hints
* @param stMeasSel select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
* @param dispNorm normalize disparities to the average if above
* @param smplMode use sample mode (false - each tile independent)
* @param smplSide sample size (side of a square)
* @param smplNum number after removing worst
* @param smplRms maximal RMS of the remaining tiles in a sample
* @param disp_tolerance maximal disparity difference from the plane to consider tile
* @param disp_var_floor squared add to variance to calculate reverse flatness (used mostly for single-cell clusters) (reuse disp_sigma)?
* @param disp_sigma Gaussian sigma to compare how measured data is attracted to planes
* @param disp_range full range of the parallel plane shifts to evaluate (histograms full range)
* @param amplitude_steps numer of histogram steps in each direction from the center
* @param hist_blur histogram LPF sigma
* @param exclusivity 1.0 - tile belongs to one plane only, 0.0 - regardless of others
* @param mode what neighbor-dependent pre-calculated plane to use as hints: 0 - weighted, 1 - equalized, 2 - best, 3 - combined
* @param debugLevel debug level
* @return per-plane, per-measurement layer, per tile index - use this tile.
*/
public boolean [][][] reDiscriminateTiles(
String prefix,
final PlaneData [] planes,
final int stMeasSel, // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
final double dispNorm, // Normalize disparities to the average if above
final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
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 double disp_tolerance, // maximal disparity difference from the plane to consider tile
final double disp_var_floor, // squared add to variance to calculate reverse flatness (used mostly for single-cell clusters)
final double disp_sigma, // G.sigma to compare how measured data is attracted to planes
final double disp_range, // parallel move known planes around original know value for the best overall fit
final int amplitude_steps, // number of steps (each direction) for each plane to search for the best fit (0 - single, 1 - 1 each side)
final double hist_blur, // Sigma to blur histogram
final double exclusivity, // 1.0 - tile belongs to one plane only, 0.0 - regardless of others
final double exclusivity2, // = 0.8; // For second pass if exclusivity > 1.0 - will assign only around strong neighbors
final boolean exclusivity_strict, // = true; // When growing selection do not allow any offenders around (false - more these than others)
final int mode, // 0 - weighted, 1 - equalized, 2 - best, 3 - combined
final int debugLevel)
{
final int size2 = 4 * superTileSize*superTileSize;
final double disp_tolerance2 = disp_tolerance * disp_tolerance;
final double floor2 = disp_var_floor * disp_var_floor;
final double ksigma = 0.5/(disp_sigma * disp_sigma);
TileNeibs tileNeibs = new TileNeibs(2 * stSize, 2 * stSize);
if (planes == null) return null;
// create a list of usable planes according to the mode
ArrayList<PlaneData> tilePlanes = new ArrayList<PlaneData>();
for (int np = 0; np < planes.length; np++) if (planes[np] != null){
PlaneData weighted_pd = planes[np].getNonexclusiveStar();
PlaneData equal_pd = planes[np].getNonexclusiveStarEq();
switch (mode){
case 0:
if (weighted_pd == null){
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStar() returned null, trying getNonexclusiveStarEq");
if (equal_pd == null) {
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null, using plane itself");
tilePlanes.add(planes[np]);
} else {
tilePlanes.add(equal_pd);
}
// throw new IllegalArgumentException ("refineDiscriminateTiles(): getNonexclusiveStar() returned null");
} else {
tilePlanes.add(weighted_pd);
}
break;
case 1:
if (equal_pd == null) { //throw new IllegalArgumentException ("refineDiscriminateTiles(): getNonexclusiveStarEq() returned null");
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null, trying getNonexclusiveStar");
if (weighted_pd == null) {
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStar() returned null, using plane itself");
tilePlanes.add(planes[np]);
} else {
tilePlanes.add(weighted_pd);
}
} else {
tilePlanes.add(equal_pd);
}
break;
case 2:
if (weighted_pd == null) { //throw new IllegalArgumentException ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStar() returned null");
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStar() returned null, trying getNonexclusiveStarEq");
if (equal_pd == null) {
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null, using plane itself");
tilePlanes.add(planes[np]);
} else {
tilePlanes.add(equal_pd);
}
break;
}
if (equal_pd == null) { //throw new IllegalArgumentException ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null");
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null, trying getNonexclusiveStar");
tilePlanes.add(weighted_pd);
break;
}
if (weighted_pd.getWeight() > equal_pd.getWeight()) tilePlanes.add(weighted_pd);
else tilePlanes.add(equal_pd);
break;
case 3:
if (weighted_pd == null) { //throw new IllegalArgumentException ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStar() returned null");
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStar() returned null, trying getNonexclusiveStarEq");
if (equal_pd == null) {
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null, using plane itself");
tilePlanes.add(planes[np]);
} else {
tilePlanes.add(equal_pd);
}
break;
}
if (equal_pd == null) { //throw new IllegalArgumentException ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null");
if (debugLevel > 0) System.out.println ("refineDiscriminateTiles() "+prefix+":"+np+": getNonexclusiveStarEq() returned null, trying getNonexclusiveStar");
tilePlanes.add(weighted_pd);
break;
}
PlaneData combo_pd = weighted_pd.mergePlaneToThis(
equal_pd, // PlaneData otherPd,
1.0, // double scale_other,
1.0, // double starWeightPwr, // Use this power of tile weight when calculating connection cost
false, // boolean ignore_weights,
true, // boolean sum_weights,
preferDisparity, // boolean preferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
debugLevel - 3); // int debugLevel)
tilePlanes.add(combo_pd);
break;
default:
throw new IllegalArgumentException ("refineDiscriminateTiles() "+prefix+":"+np+": invalid mode="+mode);
}
}
if (tilePlanes.isEmpty()){
return null;
}
if (debugLevel > 1) {
System.out.println ("refineDiscriminateTiles() "+prefix+" - step 1");
}
// get measured disparity/strength data, filtered, not tilted
double [][][] disp_strength = new double[measuredLayers.getNumLayers()][][];
for (int ml = 0; ml < disp_strength.length; ml++) if ((stMeasSel & ( 1 << ml)) != 0){
if (smplMode) {
disp_strength[ml] = measuredLayers.getDisparityStrength( // expensive to calculate (improve removing outlayers
ml, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
null, // boolean [] sel_in, - use all
strength_floor,
measured_strength_pow, //
smplSide, // = 2; // Sample size (side of a square)
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
true); // boolean null_if_none)
} else {
disp_strength[ml] = measuredLayers.getDisparityStrength(
ml, // int num_layer,
getSTileXY()[0], // int stX,
getSTileXY()[1], // int stY,
null, // boolean [] sel_in, - use all
strength_floor, // double strength_floor,
measured_strength_pow, // double strength_pow,
true); // boolean null_if_none);
}
}
double [] window = getWindow (2 * superTileSize);
if (debugLevel > 1) {
System.out.println ("refineDiscriminateTiles() "+prefix+" - step 2");
}
// get all original planes
int num_planes = tilePlanes.size();
double [][][] pds = new double [num_planes][][];
for (int np = 0; np < pds.length; np++){
PlaneData pd = tilePlanes.get(np);
pds[np] = pd.getDoublePlaneDisparityStrength(
false, // boolean useWorld,
null, // double [] window,
-1, // int dir,
false, // boolean use_sel,
false, // boolean divide_by_area,
1.0, // double scale_projection,
0.0, // double fraction_uni,
0); // int debugLevel)
}
double [][][] flatness = new double [num_planes][disp_strength.length][];
double [][][] norm_flatness = new double [num_planes][disp_strength.length][];
int [][][] num_cells = new int [num_planes][disp_strength.length][];
for (int np = 0; np < pds.length; np++){
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
flatness[np][ml] = new double[size2];
norm_flatness[np][ml] = new double[size2];
num_cells[np][ml] = new int[size2];
for (int indx = 0; indx < size2; indx++) if (disp_strength[ml][1][indx] > 0.0){
double d0 = pds[np][0][indx]; // disp_strength[ml][0][indx];
// double sw = disp_strength[ml][1][indx], sd = 0.0, sd2 = 0.0;
double sw = disp_strength[ml][1][indx]/window[indx], sd = 0.0, sd2 = 0.0;
num_cells[np][ml][indx]++;
for (int dir = 0; dir<8; dir++){
int indx1 = tileNeibs.getNeibIndex(indx, dir);
if (indx1 >= 0){
// double w = disp_strength[ml][1][indx1];
double w = disp_strength[ml][1][indx1]/window[indx1];
if (w > 0.0){
double d = disp_strength[ml][0][indx1] - d0;
sw += w;
sd += w * d;
sd2 += w * d * d;
num_cells[np][ml][indx]++;
}
}
}
if (sw > 0.0) {
sd /= sw;
sd2 /= sw;
sd2 -= sd * sd;
}
double rms = Math.sqrt(sd2);
flatness[np][ml][indx] = rms; // sd2; // will not be used
// norm_flatness[np][ml][indx] = num_cells[np][ml][indx]/(sd2 + floor2);
// norm_flatness[np][ml][indx] = (num_cells[np][ml][indx] > 1) ? (1.0/sd2): (1.0/floor2);
norm_flatness[np][ml][indx] = (num_cells[np][ml][indx] > 1) ? (1.0/rms): (1.0/disp_var_floor);
}
}
}
// calculate histograms for each plane, combining weight with flatness
final int steps = amplitude_steps * 2 + 1;
double bin_size = disp_range/(2 * amplitude_steps);
double k_bin = 2 * amplitude_steps / disp_range; // 1/bin_size
double [][] histograms = new double [num_planes][steps];
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
for (int indx = 0; indx < size2; indx++){
double weight = disp_strength[ml][1][indx];
if (weight > 0.0) {
double disp = disp_strength[ml][0][indx];
for (int np = 0; np < num_planes; np++){
double d = disp - pds[np][0][indx];
double db = d * k_bin + amplitude_steps;
int bin = (int) Math.round (db);
if ((bin >= 0) && (bin < steps)) {
// combine correlation weight, variance between valid neighbors and number of valid neighbors
// double w = weight /(flatness[np][ml][indx] + floor2) * num_cells[np][ml][indx]; // TODO: tweak?
double w = weight * norm_flatness[np][ml][indx]; // TODO: tweak?
histograms[np][bin] += w;
}
}
}
}
}
// Raise weight of the center part of the histogram - there can be originally distinct parallel planes
// alternatively - use planes_mod or star* and no histograms at all?
final double initial_trust_sigma = 0.3*disp_tolerance; // TODO: use dispNorm !
for (int np = 0; np < num_planes; np++) {
double k_sigma = 0.5/(initial_trust_sigma*initial_trust_sigma);
for (int nb = 0; nb < steps; nb++) {
double offs = bin_size * (nb - amplitude_steps);
histograms[np][nb] *= Math.exp(-k_sigma*offs*offs);
}
}
// normalize histograms
for (int np = 0; np < num_planes; np++) {
double s = 0.0;
for (int nb = 0; nb < steps; nb++)
s += histograms[np][nb];
if (s > 0.0) {
for (int nb = 0; nb < steps; nb++)
histograms[np][nb] /= s;
}
}
if (debugLevel > 2) {
System.out.println("refineDiscriminateTiles() histograms raw:");
System.out.print("disparity: ");
for (int nb = 0; nb < steps; nb++) {
System.out.print(bin_size * (nb - amplitude_steps));
if (nb < (steps - 1))
System.out.print(", ");
}
System.out.println();
for (int np = 0; np < num_planes; np++) {
System.out.print(np + ": ");
for (int nb = 0; nb < steps; nb++) {
System.out.print(histograms[np][nb]);
if (nb < (steps - 1))
System.out.print(", ");
}
System.out.println();
}
System.out.println();
System.out.println();
}
// Add LPF here?
if (hist_blur > 0.0) {
DoubleGaussianBlur gb=new DoubleGaussianBlur();
for (int np = 0; np < num_planes; np++) {
gb.blur1Direction(histograms[np], steps, 1, hist_blur/bin_size, 0.01,true);
}
if (debugLevel > 2) {
System.out.println("refineDiscriminateTiles() histograms blured:");
System.out.print("disparity: ");
for (int nb = 0; nb < steps; nb++) {
System.out.print(bin_size * (nb - amplitude_steps));
if (nb < (steps - 1))
System.out.print(", ");
}
System.out.println();
for (int np = 0; np < num_planes; np++) {
System.out.print(np + ": ");
for (int nb = 0; nb < steps; nb++) {
System.out.print(histograms[np][nb]);
if (nb < (steps - 1))
System.out.print(", ");
}
System.out.println();
}
System.out.println();
}
}
// For each plane, regardless of others
double [] offsets = new double [num_planes];
for (int np = 0; np < num_planes; np++) {
int max_bin = 0;
for (int nb = 1; nb < steps; nb++){
if (histograms[np][nb] > histograms[np][max_bin]){
max_bin = nb;
}
}
// improve max by second degree polynomial
offsets[np] = bin_size * (max_bin - amplitude_steps);
if ((max_bin > 0) && (max_bin < (steps-1))){
offsets[np] += bin_size * 0.5 *(histograms[np][max_bin + 1] - histograms[np][max_bin - 1]) /
(histograms[np][max_bin + 1] + histograms[np][max_bin - 1] - 2 * histograms[np][max_bin]);
}
}
// for each tile, each plane calculate "attraction" of the tile to each plane, where attraction is defined by Gaussian
// of normalized disparity difference and "flatness" for each plane. Then, if the attraction exceeds "exclusivity" times
// best competitor - include this tile for that plane
double [][][] attractions = new double[num_planes][disp_strength.length][];
for (int np = 0; np < num_planes; np++) {
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
attractions[np][ml] = new double[size2];
}
}
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
for (int indx = 0; indx < size2; indx++) if (disp_strength[ml][1][indx] > 0){
for (int np = 0; np < num_planes; np++) {
double d1 = pds[np][0][indx] + offsets[np]; // shifted plane
double d2 = disp_strength[ml][0][indx];
double dav = 0.5 * (d1 + d2);
double diff = d2 - d1;
if (dav > dispNorm) diff *= dispNorm/dav;
double diff2 = diff * diff;
if (diff2 <= disp_tolerance2) {
attractions[np][ml][indx] = Math.exp(-ksigma*diff2) * norm_flatness[np][ml][indx];
}
}
}
}
double [][] attr_corr = new double [num_planes][num_planes];
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
for (int indx = 0; indx < size2; indx++) if (disp_strength[ml][1][indx] > 0){
for (int np = 0; np < num_planes; np++) {
for (int np1 = np; np1 < num_planes; np1++) {
attr_corr[np][np1] += attractions[np][ml][indx] * attractions[np1][ml][indx];
if (np1 > np){
attr_corr[np1][np] = attr_corr[np][np1];
}
}
}
}
}
for (int np = 0; np < num_planes; np++) {
for (int np1 = np+1; np1 < num_planes; np1++) {
if ((attr_corr[np][np] > 0.0) && (attr_corr[np1][np1] > 0.0)){
attr_corr[np][np1] /= Math.sqrt(attr_corr[np][np] * attr_corr[np1][np1]);
attr_corr[np1][np] = attr_corr[np][np1];
}
}
attr_corr[np][np] = 1.0;
}
if ((debugLevel > 0) && (num_planes > 1)){
String dbg_s = "refineDiscriminateTiles() plane attraction correlation for "+prefix+":";
for (int np = 0; np < num_planes; np++) {
for (int np1 = np + 1; np1 < num_planes; np1++) {
dbg_s += String.format(" %d-%d:%6.3f",np,np1,attr_corr[np][np1]);
}
}
System.out.println(dbg_s);
}
// discriminate
boolean [][][] best_selections = new boolean[num_planes][disp_strength.length][];
for (int np = 0; np < num_planes; np++) {
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
best_selections[np][ml] = new boolean[size2];
}
}
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
for (int indx = 0; indx < size2; indx++) if (disp_strength[ml][1][indx] > 0){
if (num_planes == 1){
best_selections[0][ml][indx] = attractions[0][ml][indx] > 0.0;
} else { // find to best candidates
int best_np = 0;
for (int np = 1; np < num_planes; np++) if (attractions[np][ml][indx] > attractions[best_np][ml][indx]){
best_np = np;
}
int best_np2 = (best_np ==0) ? 1:0;
for (int np = 1; np < num_planes; np++) if ((np != best_np ) && (attractions[np][ml][indx] > attractions[best_np2][ml][indx])){
best_np2 = np;
}
for (int np = 0; np < num_planes; np++){
int np_other = (np == best_np) ? best_np2 : best_np;
best_selections[np][ml][indx] = attractions[np][ml][indx] > exclusivity * attractions[np_other][ml][indx];
}
}
}
}
if ((exclusivity > 1.0) && (exclusivity2 > 0.0) && (num_planes > 1)) { // second pass - lower threshold but depend on neighbors
boolean changed = true;
while (changed) {
changed = false;
boolean [][][] best_selections_prev = best_selections.clone();
for (int np = 0; np < num_planes; np++) {
best_selections_prev[np] = best_selections[np].clone();
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
best_selections_prev[np][ml] = best_selections[np][ml].clone();
}
}
for (int ml = 0; ml < disp_strength.length; ml++) if (disp_strength[ml] != null){
for (int indx = 0; indx < size2; indx++) if (disp_strength[ml][1][indx] > 0){
int best_np = 0;
for (int np = 1; np < num_planes; np++) if (attractions[np][ml][indx] > attractions[best_np][ml][indx]){
best_np = np;
}
int best_np2 = (best_np ==0) ? 1:0;
for (int np = 1; np < num_planes; np++) if ((np != best_np ) && (attractions[np][ml][indx] > attractions[best_np2][ml][indx])){
best_np2 = np;
}
for (int np = 0; np < num_planes; np++) if (!best_selections_prev[np][ml][indx]){ // only new
int np_other = (np == best_np) ? best_np2 : best_np;
if (attractions[np][ml][indx] > exclusivity2 * attractions[np_other][ml][indx]) {
int num_this = 0;
int num_other = 0;
boolean used_by_other = false;
for (int np1 = 0; np1 < num_planes; np1++) if (np1 != np){
if (best_selections_prev[np1][ml][indx]) {
used_by_other = true;
break;
}
}
if (! used_by_other) {
for (int dir = 0; dir < 8; dir++){
int indx1 = tileNeibs.getNeibIndex(indx, dir);
if (indx1 >= 0){
if (best_selections_prev[np][ml][indx1]) num_this ++;
for (int np1 = 0; np1 < num_planes; np1++) if (np1 != np){
if (best_selections_prev[np1][ml][indx1]) {
num_other ++;
break;
}
}
}
}
if ((num_this > num_other) && (!exclusivity_strict || (num_other == 0))){ // make it stricter and require num_other==0 ?
best_selections[np][ml][indx] = true;
changed = true;
}
}
}
}
}
}
}
}
if (debugLevel > 2){
int dbg_ml = 0; // to protect from different layer configuration
for (; dbg_ml < disp_strength.length; dbg_ml++){
if (disp_strength[dbg_ml] != null) break;
}
//disp_strength[dbg_ml][0], disp_strength[dbg_ml][1] * 10, disp_strength[dbg_ml][0] - pds[np][0], pds[np][0]
String [] dbg_titles = new String[2 + 8 * num_planes];
double [][] dbg_img = new double [dbg_titles.length][];
dbg_titles[0] = "disp_"+dbg_ml;
dbg_titles[1] = "str_"+dbg_ml;
dbg_img[0] = disp_strength[dbg_ml][0];
dbg_img[1] = disp_strength[dbg_ml][1];
for (int np = 0; np < num_planes; np++){
dbg_titles[2 + 0 * num_planes + np] = "pln_"+np;
dbg_titles[2 + 1 * num_planes + np] = "diff_"+np;
dbg_titles[2 + 2 * num_planes + np] = "flat_"+np;
dbg_titles[2 + 3 * num_planes + np] = "rflat_"+np;
dbg_titles[2 + 4 * num_planes + np] = "nrflat_"+np;
dbg_titles[2 + 5 * num_planes + np] = "attr_"+np;
dbg_titles[2 + 6 * num_planes + np] = "sel_"+np; // add also old selection?
dbg_titles[2 + 7 * num_planes + np] = "oldsel_"+np; // add also old selection?
dbg_img[2 + 0 * num_planes + np] = pds[np][0];
dbg_img[2 + 1 * num_planes + np] = disp_strength[dbg_ml][0].clone();
dbg_img[2 + 2 * num_planes + np] = flatness[np][dbg_ml];
dbg_img[2 + 3 * num_planes + np] = new double[size2];
dbg_img[2 + 4 * num_planes + np] = norm_flatness[np][dbg_ml];
dbg_img[2 + 5 * num_planes + np] = attractions[np][dbg_ml];
dbg_img[2 + 6 * num_planes + np] = new double[size2];
dbg_img[2 + 7 * num_planes + np] = new double[size2];
for (int i = 0; i < size2; i++) {
dbg_img[2 + 1 * num_planes + np][i] -= pds[np][0][i];
// dbg_img[2 + 3 * num_planes + np][i] = 1.0 / (flatness[np][dbg_ml][i] + 0.001);
dbg_img[2 + 3 * num_planes + np][i] = (num_cells[np][dbg_ml][i] > 1) ? (1.0/flatness[np][dbg_ml][i]): (1.0/disp_var_floor); // floor2);
// dbg_img[2 + 4 * num_planes + np][i] = num_cells[np][dbg_ml][i] * 1.0 / (flatness[np][dbg_ml][i] + 0.001);
dbg_img[2 + 6 * num_planes + np][i] = best_selections[np][dbg_ml][i] ? 1.0 : 0.0;
dbg_img[2 + 7 * num_planes + np][i] = planes[np+1].measuredSelection[dbg_ml][i]? 1.0:0.0; // temporarily
if (disp_strength[dbg_ml][1][i] == 0.0){
dbg_img[2 + 1 * num_planes + np][i] = Double.NaN;
dbg_img[2 + 2 * num_planes + np][i] = Double.NaN;
dbg_img[2 + 3 * num_planes + np][i] = Double.NaN;
dbg_img[2 + 4 * num_planes + np][i] = Double.NaN;
dbg_img[2 + 5 * num_planes + np][i] = Double.NaN;
}
}
}
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays();
sdfa_instance.showArrays(dbg_img, 2 * superTileSize, 2 * superTileSize, true, "refine-"+prefix,dbg_titles);
}
if (debugLevel > 1) {
System.out.println ("refineDiscriminateTiles() "+prefix+" - step 3");
}
return null;
return best_selections;
}
......@@ -3764,7 +4539,7 @@ public class TilePlanes {
split_selections[ns++] = tilePlanes.get(np).getMeasSelection();
}
for (TileSelections ts: split_planes){
PlaneData pd = tilePlanes.get(ts.np);
// PlaneData pd = tilePlanes.get(ts.np);
boolean [][] ms = tilePlanes.get(ts.np).getMeasSelection().clone();
for (int ml = 0; ml < ms.length; ml++) if (ms[ml] != null){
ms[ml] = ms[ml].clone();
......
......@@ -1460,8 +1460,8 @@ public class TileProcessor {
int [] clusters_in,
int debugLevel)
{
showDoubleFloatArrays sdfa_instance = null;
if (debugLevel > -1) sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
// showDoubleFloatArrays sdfa_instance = null;
// if (debugLevel > -1) sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
// adding 1-tile frame around to avoid checking for the borders
int tilesX4 = tilesX + 4;
......@@ -3233,6 +3233,142 @@ public class TileProcessor {
return true;
}
public void conditionSuperTiles(
EyesisCorrectionParameters.CLTParameters clt_parameters,
GeometryCorrection geometryCorrection,
SuperTiles st,
LinkPlanes lp,
final int debugLevel)
{
// try to merge multiple times
int max_num_merge_try = 8;
TilePlanes.PlaneData [][][] dbg_orig_planes = new TilePlanes.PlaneData [max_num_merge_try][][];
for (int num_merge_try = 0; num_merge_try < max_num_merge_try; num_merge_try++){
lp.matchPlanes(
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_stats1 = lp.selectNeighborPlanesMutual(
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);
lp.setNonExclusive(
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);
int [][][] merge_candidates = lp.getMergeSameTileCandidates(
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
boolean [][][] plane_nooverlaps = lp.overlapSameTileCandidates (
st.planes, // 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
lp.keepSameTileConnections(
st.planes, // 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,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// double [][][][][][] merge_cost_data =
lp.costSameTileConnections(
false, // final boolean ignore_weights,
1000.0, // final double threshold_worst,
1000.0, //final double threshold_world_worst,
st.planes, // ffinal 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);
int [][][] merge_groups = lp.extractMergeSameTileGroups(
st.planes, // 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);
dbg_orig_planes[num_merge_try] = st.planes.clone();
for (int nsTile=0; nsTile < st.planes.length; nsTile++) if (st.planes[nsTile] != null){
dbg_orig_planes[num_merge_try][nsTile] = st.planes[nsTile].clone();
for (int np = 0; np < st.planes[nsTile].length; np++ ) if (st.planes[nsTile][np] != null){
dbg_orig_planes[num_merge_try][nsTile][np] = st.planes[nsTile][np].clone();
}
}
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;
}
}
}
//======================
public void showPlanes(
EyesisCorrectionParameters.CLTParameters clt_parameters,
......@@ -3327,206 +3463,110 @@ public class TileProcessor {
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
}
SuperTiles st = scan_prev.getSuperTiles();
/*
TileSurface tileSurface = new TileSurface(
st.tileProcessor.getTileSize(), // int tileSize,
st.tileProcessor.getSuperTileSize(), // int superTileSize,
st.tileProcessor.getTilesX(), // int tilesX,
st.tileProcessor.getTilesY(), // int tilesY,
geometryCorrection, // GeometryCorrection geometryCorrection,
st.tileProcessor.threadsMax); // int threadsMax);
*/
st.setTileSurface(geometryCorrection); // tileSurface);
// moved here
// if (clt_parameters.dbg_migrate) {
// separate each supertile data into clusters, trying both horizontal and perpendicular to view planes
double [] world_hor = {0.0, 1.0, 0.0};
st.processPlanes5(
clt_parameters.stGrowSel, // = 2; // = -1; //Grow initial selection before processing supertiles, odd - ortho. <0 - use all tiles
clt_parameters.stMeasSel, // = 1 //Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
clt_parameters.plDispNorm, // = 2.0; // Normalize disparities to the average if above
clt_parameters.plMinPoints, // = 5; // Minimal number of points for plane detection
clt_parameters.plTargetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
clt_parameters.plFractOutliers, // = 0.3; // Maximal fraction of outliers to remove
clt_parameters.plMaxOutliers, // = 20; // Maximal number of outliers to remove\
clt_parameters.plPreferDisparity,
geometryCorrection,
clt_parameters.correct_distortions,
clt_parameters.stSmplMode , // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
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.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)
clt_parameters.plMaxDiffHor, // final double max_diff_hor, // maximal disparity difference (to assign to a cluster (of Double.NaN) at first run for horizontal planes
clt_parameters.plMaxDiffVert, // final double max_diff_vert, // maximal disparity difference (to assign to a cluster (of Double.NaN) at first run for vertical plane
clt_parameters.plInitPasses, // final int max_tries, // on last run - assign all rfemaining pixels to some cluster (disregard max_diff)
clt_parameters.msUseSel, // final boolean msUseSel, // final boolean use_sel,
clt_parameters.msDivideByArea, // final boolean msDivideByArea, // final boolean divide_by_area,
clt_parameters.msScaleProj, //final double msScaleProj, // final double scale_projection,
clt_parameters.stSmallDiff, // = 0.4; // Consider merging initial planes if disparity difference below
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])
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
showDoubleFloatArrays sdfa_instance = null;
if (debugLevel > -1) sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
// Trying new class
LinkPlanes lp = new LinkPlanes (clt_parameters, st);
// try to merge multiple times
int max_num_merge_try = 8;
TilePlanes.PlaneData [][][] dbg_orig_planes = new TilePlanes.PlaneData [max_num_merge_try][][];
for (int num_merge_try = 0; num_merge_try < max_num_merge_try; num_merge_try++){
lp.matchPlanes(
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_stats1 = lp.selectNeighborPlanesMutual(
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.setNonExclusive(
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);
int [][][] merge_candidates = lp.getMergeSameTileCandidates(
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
double [] world_hor = {0.0, 1.0, 0.0};
st.processPlanes5(
clt_parameters.stGrowSel, // = 2; // = -1; //Grow initial selection before processing supertiles, odd - ortho. <0 - use all tiles
clt_parameters.stMeasSel, // = 1 //Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
clt_parameters.plDispNorm, // = 2.0; // Normalize disparities to the average if above
clt_parameters.plMinPoints, // = 5; // Minimal number of points for plane detection
clt_parameters.plTargetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
clt_parameters.plFractOutliers, // = 0.3; // Maximal fraction of outliers to remove
clt_parameters.plMaxOutliers, // = 20; // Maximal number of outliers to remove\
clt_parameters.plPreferDisparity,
geometryCorrection,
clt_parameters.correct_distortions,
boolean [][][] plane_nooverlaps = lp.overlapSameTileCandidates (
st.planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
clt_parameters.stSmplMode , // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
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
// remove merge candidates that break connections to neighbors
lp.keepSameTileConnections(
st.planes, // 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,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
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)
clt_parameters.plMaxDiffHor, // final double max_diff_hor, // maximal disparity difference (to assign to a cluster (of Double.NaN) at first run for horizontal planes
clt_parameters.plMaxDiffVert, // final double max_diff_vert, // maximal disparity difference (to assign to a cluster (of Double.NaN) at first run for vertical plane
clt_parameters.plInitPasses, // final int max_tries, // on last run - assign all remaining pixels to some cluster (disregard max_diff)
clt_parameters.msUseSel, // final boolean msUseSel, // final boolean use_sel,
clt_parameters.msDivideByArea, // final boolean msDivideByArea, // final boolean divide_by_area,
clt_parameters.msScaleProj, //final double msScaleProj, // final double scale_projection,
// double [][][][][][] merge_cost_data =
lp.costSameTileConnections(
false, // final boolean ignore_weights,
1000.0, // final double threshold_worst,
1000.0, //final double threshold_world_worst,
st.planes, // ffinal 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);
int [][][] merge_groups = lp.extractMergeSameTileGroups(
st.planes, // 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);
dbg_orig_planes[num_merge_try] = st.planes.clone();
for (int nsTile=0; nsTile < st.planes.length; nsTile++) if (st.planes[nsTile] != null){
dbg_orig_planes[num_merge_try][nsTile] = st.planes[nsTile].clone();
for (int np = 0; np < st.planes[nsTile].length; np++ ) if (st.planes[nsTile][np] != null){
dbg_orig_planes[num_merge_try][nsTile][np] = st.planes[nsTile][np].clone();
}
}
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);
clt_parameters.stSmallDiff, // = 0.4; // Consider merging initial planes if disparity difference below
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])
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
showDoubleFloatArrays sdfa_instance = null;
if (debugLevel > -1) sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
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;
}
}
/*
if (num_removed_by_merging > 0){ // re-calculate all links
lp.matchPlanes(
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
//==========================
// Trying new class
LinkPlanes lp = new LinkPlanes (clt_parameters, st);
// condition supertiles (create and manage links, merge)
conditionSuperTiles(
clt_parameters, //EyesisCorrectionParameters.CLTParameters clt_parameters,
geometryCorrection, // GeometryCorrection geometryCorrection,
st, // SuperTiles st,
lp, // LinkPlanes lp,
debugLevel); // final int debugLevel);
// re-generate planes in the supertiles using previously calculated planes (for tghe tiles and their neighbors)
// as hints, new planes will be assumed parallel to the known and possibly slightly offset in disparity
st.regeneratePlanes(
st.planes, // final TilePlanes.PlaneData [][] planes,
clt_parameters.stMeasSel, // = 1 //Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
clt_parameters.plDispNorm, // = 2.0; // Normalize disparities to the average if above
clt_parameters.plMinPoints, // = 5; // Minimal number of points for plane detection
clt_parameters.plTargetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
clt_parameters.plFractOutliers, // = 0.3; // Maximal fraction of outliers to remove
clt_parameters.plMaxOutliers, // = 20; // Maximal number of outliers to remove\
clt_parameters.plPreferDisparity,
geometryCorrection,
clt_parameters.correct_distortions,
clt_parameters.stSmplMode, // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
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.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
clt_parameters.plDiscrExclusivity,// final double plDiscrExclusivity, // = 0.5; // Tile exclusivity: 1.0 - tile belongs to one plane only, 0.0 - regardless of others
clt_parameters.plDiscrExclus2,// final double plDiscrExclus2, // = 0.5; // For second pass if exclusivity > 1.0 - will assign only around strong neighbors
clt_parameters.plDiscrStrict, // final boolean plDiscrStrict, // = true; // When growing selection do not allow any offenders around (false - more these than others)
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// condition the redcefined planes
conditionSuperTiles(
clt_parameters, //EyesisCorrectionParameters.CLTParameters clt_parameters,
geometryCorrection, // GeometryCorrection geometryCorrection,
st, // SuperTiles st,
lp, // LinkPlanes lp,
debugLevel); // final int debugLevel);
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);
}
*/
double [][] quality_stats1 = lp.selectNeighborPlanesMutual(
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);
st.resolveConflicts(
lp, // LinkPlanes lp,
......@@ -3549,7 +3589,7 @@ public class TileProcessor {
1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
/*
/*
st.resolveConflicts(
clt_parameters.plMaxEigen,
clt_parameters.plConflDualTri, // boolean conflDualTri, // Resolve dual triangles conflict (odoodo)
......@@ -3567,9 +3607,9 @@ public class TileProcessor {
1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
*/
*/
if (clt_parameters.plSplitApply) {
while (true) {
int num_added = 0;
......@@ -3631,7 +3671,7 @@ public class TileProcessor {
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.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.stSmplSide , // final int smplSide, // = 2; // Sample size (side of a square)
clt_parameters.stSmplNum , // final int smplNum, // = 3; // Number after removing worst
......@@ -3662,6 +3702,7 @@ public class TileProcessor {
0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
if (debugLevel>100) System.out.println(quality_stats2.length);
st.resolveConflicts(
lp, // LinkPlanes lp,
......@@ -3787,12 +3828,12 @@ public class TileProcessor {
}
plane_data[indx][i] = dbg_nl;
}
}
sdfa_instance.showArrays(plane_data, wh[0], wh[1], true, "plane_data");
/*
/*
TileSurface tileSurface = new TileSurface(
st.tileProcessor.getTileSize(), // int tileSize,
st.tileProcessor.getSuperTileSize(), // int superTileSize,
......@@ -3801,7 +3842,7 @@ public class TileProcessor {
geometryCorrection, // GeometryCorrection geometryCorrection,
st.tileProcessor.threadsMax); // int threadsMax);
st.setTileSurface(tileSurface);
*/
*/
st.tileSurface.createTileShells (
clt_parameters.msUseSel, // final boolean use_sel,
clt_parameters.msDivideByArea, // final boolean divide_by_area,
......@@ -4059,7 +4100,7 @@ public class TileProcessor {
boolean [] these_tiles;
int [] replaced = null; // +1 - hor, +2 - vert
int [] replaced0 = null; // +1 - hor, +2 - vert
// int [] replaced0 = null; // +1 - hor, +2 - vert
if (!clt_parameters.ortho_old) {
replaced = combineOrthoDisparity(
......@@ -4096,7 +4137,7 @@ public class TileProcessor {
if (debugLevel > -1){
System.out.println("fixVerticalPoles() replaced "+ numFixed+ " tiles.");
}
replaced0 = replaced.clone();
// replaced0 = replaced.clone();
for (int i = 0; i < replaced.length; i++){
if (tilesHor[i]) replaced[i] |= 1;
}
......
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