Commit 92f321f5 authored by Andrey Filippov's avatar Andrey Filippov

fixed old bug, used macro correlation

parent d67d3674
......@@ -141,6 +141,7 @@ public class AlignmentCorrection {
}
ArrayList<Sample> samples_list = selectInfinityTiles(
clt_parameters.fcorr_radius, // final double fcorr_radius,
clt_parameters.fcorr_inf_vert,// final boolean use_vertical,
min_strength,
max_diff,
......@@ -195,33 +196,44 @@ public class AlignmentCorrection {
mismatch_corr_coefficiants, // double [][][] corr,
"");// String prefix)
}
/*
if (disparity_corr_coefficiants == null) {
disparity_corr_coefficiants = mismatch_corr_coefficiants;
if (debugLevel > -1){
System.out.println("infinityCorrection(): using only coefficient increments from infinityMismatchCorrection");
return mismatch_corr_coefficiants;
}
} else {
for (int i = 0; i < disparity_corr_coefficiants.length; i++){
for (int j = 0; j < disparity_corr_coefficiants[i].length; j++){
for (int k = 0; k < disparity_corr_coefficiants[i][j].length; k++){
disparity_corr_coefficiants[i][j][k] += mismatch_corr_coefficiants[i][j][k];
}
}
}
if (debugLevel > -1){
System.out.println("infinityCorrection(): combining coefficient increments from infinityCorrection and infinityMismatchCorrection");
/**
* Discard correction data outside of the center image area
* @param fcorr_radius fraction of the image to use (1.0 - 100%)
* @param tilesX width in tiles
* @param tilesY height in tiles
* @return boolean array in linescan order
*/
public boolean[] getCenterMask(
double fcorr_radius,
int tilesX,
int tilesY)
{
boolean [] mask = new boolean [tilesX * tilesY];
int y0 = (int) (0.5 * tilesY*(1.0 - fcorr_radius));
int y1 = (int) (0.5 * tilesY*(1.0 + fcorr_radius));
int x0 = (int) (0.5 * tilesX*(1.0 - fcorr_radius));
int x1 = (int) (0.5 * tilesX*(1.0 + fcorr_radius));
if (y0 < 0) y0 = 0;
if (y1 > tilesY) y1 = tilesY;
if (x0 < 0) x0 = 0;
if (x1 > tilesX) x1 = tilesX;
for (int ty = y0; ty < y1; ty++){
for (int tx = x0; tx < x1; tx++){
mask[tx + tilesX * ty] = true;
}
}
*/
// }
return mismatch_corr_coefficiants;
return mask;
}
/**
* Select infinity tiles from a single or multiple image sets
* Next parameters are made separate to be able to modify them between different runs keeping clt_parameters
* @param fcorr_radius do not use peripheral tiles
* @param min_strength minimal correlation strength to use tile
* @param max_diff maximal disparity difference between tiles and previous approximation to use tiles
* @param max_iterations maximal number of iterations to find disparity surface
......@@ -236,6 +248,7 @@ public class AlignmentCorrection {
* @return per sub-camera, per direction (x,y) 6 quadratic polynomial coefficients, same format as fine_geometry_correction()
*/
public ArrayList<Sample> selectInfinityTiles(
final double fcorr_radius,
final boolean use_vertical,
final double min_strength,
final double max_diff,
......@@ -250,6 +263,7 @@ public class AlignmentCorrection {
{
final int numTiles = disp_strength[0].length;
final int tilesY = numTiles/tilesX;
final boolean [] center_mask = getCenterMask(fcorr_radius, tilesX, tilesY);
double [] disparity_poly = new double[6];
PolynomialApproximation pa = new PolynomialApproximation();
double thresholdLin = 1.0E-20; // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
......@@ -275,7 +289,7 @@ public class AlignmentCorrection {
for (int num_set = 0; num_set < disp_strength.length/NUM_SLICES; num_set++){
int disp_index = NUM_SLICES * num_set;
int str_index = NUM_SLICES * num_set + 1;
for (int nTile = 0; nTile < numTiles; nTile++){
for (int nTile = 0; nTile < numTiles; nTile++) if (center_mask[nTile]){
if ((disp_strength[str_index][nTile] > min_strength) &&
// (Math.abs(disp_strength[disp_index][nTile] - disp_surface[nTile]) < max_diff)){
((disp_strength[disp_index][nTile] - disp_surface[nTile]) < max_diff)){
......@@ -1505,6 +1519,7 @@ public class AlignmentCorrection {
public double [][][] lazyEyeCorrection(
final double fcorr_radius,
final double min_strength_in,
final double max_diff,
// final double comp_strength_var,
......@@ -1538,6 +1553,7 @@ public class AlignmentCorrection {
final int num_scans = scans_14.length/NUM_ALL_SLICES;
final int num_tiles = scans_14[0].length;
final int tilesY = num_tiles/tilesX;
final boolean [] center_mask = getCenterMask(fcorr_radius, tilesX, tilesY);
final double [][] scans = new double [num_scans * NUM_SLICES][];
final int [] indices_14_10 = {0,1,2,3,5,6,8,9,11,12};
final double [][] comp_strength_rms = new double [num_scans][num_tiles];
......@@ -1546,9 +1562,6 @@ public class AlignmentCorrection {
scans[ns * NUM_SLICES + i] = scans_14[ns * NUM_ALL_SLICES + indices_14_10[i]];
}
}
// (new showDoubleFloatArrays()).showArrays(scans_14, tilesX, tilesY, true, "scans14");
// (new showDoubleFloatArrays()).showArrays(scans, tilesX, tilesY, true, "scans10");
for (int ns = 0; ns < num_scans; ns++){
for (int nTile = 0; nTile < num_tiles; nTile++){
......@@ -1563,24 +1576,6 @@ public class AlignmentCorrection {
comp_strength_rms[ns][nTile] = Math.sqrt(s2 - s1*s1);
}
}
/*
for (int ns = 0; ns < num_scans; ns++){
for (int nTile = 0; nTile < num_tiles; nTile++){
double s1=0.0, s2=0.0;
for (int pair = 0; pair <4; pair++){
double s = scans_14[ns * NUM_ALL_SLICES + 4 + 3 * pair][nTile];
if (pair == 0){
s1 = s;
s2 = s;
} else {
s1= Math.min(s, s1);
s2= Math.max(s, s2);
}
}
comp_strength_rms[ns][nTile] = s2 - s1;
}
}
*/
/*
* None of comp_strength_rms methods works to detect potential outliers for horizontal/vertical features
*/
......@@ -1809,6 +1804,7 @@ public class AlignmentCorrection {
// create list for infinity data
ArrayList<Sample> inf_samples_list = selectInfinityTiles(
clt_parameters.fcorr_radius, // final double fcorr_radius,
clt_parameters.fcorr_inf_vert,// final boolean use_vertical,
0.0, // any > 0.0
max_diff, // max_diff, //clt_parameters.fcorr_inf_diff
......@@ -1836,7 +1832,7 @@ public class AlignmentCorrection {
total_weights[0] += s.weight;
}
for (int nTile = 0; nTile < num_tiles; nTile++) {
for (int nTile = 0; nTile < num_tiles; nTile++) if (center_mask[nTile]){
total_weights[1]+= inf_and_ly[1 * NUM_SLICES + 1][nTile];
}
......@@ -1855,7 +1851,7 @@ public class AlignmentCorrection {
}
// Supplement list with the lazy eye scans data - use all tiles
for (int nTile = 0; nTile < num_tiles; nTile++) {
for (int nTile = 0; nTile < num_tiles; nTile++) if (center_mask[nTile]) {
double w = inf_and_ly[1 * NUM_SLICES + 1][nTile];
if (w > 0.0) {
inf_samples_list.add(new Sample(1,nTile,w));
......@@ -2124,6 +2120,7 @@ public class AlignmentCorrection {
ArrayList<Sample> inf_samples_list = selectInfinityTiles(
clt_parameters.fcorr_radius, // final double fcorr_radius,
clt_parameters.fcorr_inf_vert,// final boolean use_vertical,
0.0, // any > 0.0
clt_parameters.fcorr_inf_diff, // max_diff, //clt_parameters.fcorr_inf_diff
......
......@@ -67,6 +67,19 @@ public class CLTPass3d{
{
this.tileProcessor = tileProcessor;
}
public CLTPass3d (TileProcessor tileProcessor, int mode)
{
this.tileProcessor = tileProcessor;
switch (mode){
case 0:
tile_op = new int [tileProcessor.getTilesY()][tileProcessor.getTilesX()];
disparity = new double [tileProcessor.getTilesY()][tileProcessor.getTilesX()];
break;
}
}
public TileProcessor getTileProcessor()
{
return this.tileProcessor;
......
......@@ -2007,6 +2007,7 @@ public class EyesisCorrectionParameters {
public double fine_corr_x_3 = 0.0; // additionally shift image in port 3 in x direction
public double fine_corr_y_3 = 0.0; // additionally shift image in port 3 in y direction
public double fcorr_radius = 0.75 ; // Do not try to correct outside this fraction of width/hight
public double fcorr_min_strength = 0.15 ; // 0.005 minimal correlation strength to apply fine correction
public double fcorr_disp_diff = 1.5; // consider only tiles with absolute residual disparity lower than
public boolean fcorr_quadratic = true; // Use quadratic polynomial for fine correction (false - only linear)
......@@ -2131,8 +2132,8 @@ public class EyesisCorrectionParameters {
public boolean correct_distortions = false; // Correct lens geometric distortions in a model (will need backdrop to be corrected too)
public boolean show_triangles = true; // Show generated triangles
public boolean avg_cluster_disp = false; // Weight-average disparity for the whole cluster
public double maxDispTriangle = 0.2; // Maximal disparity difference in a triangle face to show
public double maxDispTriangle = 0.2; // Maximal relative disparity difference in a triangle face
public double infinityDistance = 10000; // Distance to generate backdrop (0 - use regular backdrop)
public boolean shUseFlaps = true; // Split into shells with flaps
public boolean shAggrFade = true; // Aggressive fade alpha (whole boundary)
public int shMinArea = 1; // Minimal shell area (not counting flaps
......@@ -2245,19 +2246,23 @@ public class EyesisCorrectionParameters {
// Macro disparity scanning parameters
public double mc_disp8_step = 2.0; // Macro disparity scan step (actual disparity step is 8x)
public double mc_disp8_trust = 3.0; //Trust measured disparity within +/- this value
public double mc_strength = 0.2; // Minimal composite correlation to process
public double mc_unique_tol = 0.1; // Do not re-measure macro correlation if target disparity differs from some previous by this
public double mc_disp8_trust = 2.0; //Trust measured disparity within +/- this value
public double mc_strength = 0.2; // Minimal composite correlation to process (0.2..0.3)
public double mc_unique_tol = 0.05; // Do not re-measure macro correlation if target disparity differs from some previous by this
public double mc_trust_fin = 0.3; // When consolidating macro results, exclude high residual disparity
public double mc_trust_sigma = 0.2; // Gaussian sigma to reduce weight of large residual disparity
public double mc_ortho_weight = 0.5; // Weight from ortho neighbor supertiles
public double mc_diag_weight = 0.25; // Weight from diagonal neighbor supertiles
public double mc_gap = 0.4; // Do not remove measurements farther from the kept ones
// 0x1e, // 0x1f, // final int variants_mask,
public int gr_min_new = 20; // Discard variant if it requests too few tiles
public boolean gr_var_new_sngl = false;// Expand only unambiguous tiles over previously undefined
public boolean gr_var_new_fg = true; // Expand unambiguous and foreground tiles over previously undefined
public boolean gr_var_all_fg = true;
public boolean gr_var_new_bg = true;
public boolean gr_var_all_bg = true;
public boolean gr_var_next = true; // try next disparity range TODO: add related statements
public boolean gr_var_new_bg = false;
public boolean gr_var_all_bg = false;
public boolean gr_var_next = false; // try next disparity range TODO: add related statements
public int gr_num_steps = 8; // How far to extend over previously undefined disparity tiles
public int gr_steps_over = 4; // How far to extend over previously determined disparity tiles
public int gr_smpl_size = 5; // Extend sample square side
......@@ -2528,7 +2533,9 @@ public class EyesisCorrectionParameters {
public boolean show_histograms = false; // show supertile disparity histograms
public boolean show_init_refine = false; // show debug images during initial refinement
public boolean show_expand = false; // show debug images during disparity expansion
public boolean show_variant = false; // show prepareExpandVariant when elevating variant number
public boolean show_retry_far = false; // show debug images related to retrying far tiles near foreground
public boolean show_macro = false; // show debug images related to macro correlation
public boolean show_shells = false; // show 'shells'
public boolean show_neighbors = false; // show 'neighbors'
......@@ -2627,6 +2634,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"fine_corr_x_3", this.fine_corr_x_3 +"");
properties.setProperty(prefix+"fine_corr_y_3", this.fine_corr_y_3 +"");
properties.setProperty(prefix+"fcorr_radius", this.fcorr_radius +"");
properties.setProperty(prefix+"fcorr_min_strength",this.fcorr_min_strength +"");
properties.setProperty(prefix+"fcorr_disp_diff", this.fcorr_disp_diff +"");
properties.setProperty(prefix+"fcorr_quadratic", this.fcorr_quadratic+"");
......@@ -2739,6 +2747,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"show_triangles", this.show_triangles+"");
properties.setProperty(prefix+"avg_cluster_disp", this.avg_cluster_disp+"");
properties.setProperty(prefix+"maxDispTriangle", this.maxDispTriangle +"");
properties.setProperty(prefix+"infinityDistance", this.infinityDistance +"");
properties.setProperty(prefix+"shUseFlaps", this.shUseFlaps+"");
properties.setProperty(prefix+"shAggrFade", this.shAggrFade+"");
properties.setProperty(prefix+"shMinArea", this.shMinArea+"");
......@@ -2842,6 +2851,12 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"mc_strength", this.mc_strength +"");
properties.setProperty(prefix+"mc_unique_tol", this.mc_unique_tol +"");
properties.setProperty(prefix+"mc_trust_fin", this.mc_trust_fin +"");
properties.setProperty(prefix+"mc_trust_sigma", this.mc_trust_sigma +"");
properties.setProperty(prefix+"mc_ortho_weight", this.mc_ortho_weight +"");
properties.setProperty(prefix+"mc_diag_weight", this.mc_diag_weight +"");
properties.setProperty(prefix+"mc_gap", this.mc_gap +"");
properties.setProperty(prefix+"gr_min_new", this.gr_min_new+"");
properties.setProperty(prefix+"gr_var_new_sngl", this.gr_var_new_sngl+"");
properties.setProperty(prefix+"gr_var_new_fg", this.gr_var_new_fg+"");
......@@ -3092,7 +3107,9 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"show_histograms", this.show_histograms+"");
properties.setProperty(prefix+"show_init_refine", this.show_init_refine+"");
properties.setProperty(prefix+"show_expand", this.show_expand+"");
properties.setProperty(prefix+"show_variant", this.show_variant+"");
properties.setProperty(prefix+"show_retry_far", this.show_retry_far+"");
properties.setProperty(prefix+"show_macro", this.show_macro+"");
properties.setProperty(prefix+"show_shells", this.show_shells+"");
properties.setProperty(prefix+"show_neighbors", this.show_neighbors+"");
properties.setProperty(prefix+"show_flaps_dirs", this.show_flaps_dirs+"");
......@@ -3189,6 +3206,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"fine_corr_x_3")!=null) this.fine_corr_x_3=Double.parseDouble(properties.getProperty(prefix+"fine_corr_x_3"));
if (properties.getProperty(prefix+"fine_corr_y_3")!=null) this.fine_corr_y_3=Double.parseDouble(properties.getProperty(prefix+"fine_corr_y_3"));
if (properties.getProperty(prefix+"fcorr_radius")!=null) this.fcorr_radius=Double.parseDouble(properties.getProperty(prefix+"fcorr_radius"));
if (properties.getProperty(prefix+"fcorr_min_strength")!=null) this.fcorr_min_strength=Double.parseDouble(properties.getProperty(prefix+"fcorr_min_strength"));
if (properties.getProperty(prefix+"fcorr_disp_diff")!=null) this.fcorr_disp_diff=Double.parseDouble(properties.getProperty(prefix+"fcorr_disp_diff"));
if (properties.getProperty(prefix+"fcorr_quadratic")!=null) this.fcorr_quadratic=Boolean.parseBoolean(properties.getProperty(prefix+"fcorr_quadratic"));
......@@ -3302,6 +3320,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"show_triangles")!=null) this.show_triangles=Boolean.parseBoolean(properties.getProperty(prefix+"show_triangles"));
if (properties.getProperty(prefix+"avg_cluster_disp")!=null) this.avg_cluster_disp=Boolean.parseBoolean(properties.getProperty(prefix+"avg_cluster_disp"));
if (properties.getProperty(prefix+"maxDispTriangle")!=null) this.maxDispTriangle=Double.parseDouble(properties.getProperty(prefix+"maxDispTriangle"));
if (properties.getProperty(prefix+"infinityDistance")!=null) this.infinityDistance=Double.parseDouble(properties.getProperty(prefix+"infinityDistance"));
if (properties.getProperty(prefix+"shUseFlaps")!=null) this.shUseFlaps=Boolean.parseBoolean(properties.getProperty(prefix+"shUseFlaps"));
if (properties.getProperty(prefix+"shAggrFade")!=null) this.shAggrFade=Boolean.parseBoolean(properties.getProperty(prefix+"shAggrFade"));
if (properties.getProperty(prefix+"shMinArea")!=null) this.shMinArea=Integer.parseInt(properties.getProperty(prefix+"shMinArea"));
......@@ -3403,6 +3422,11 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"mc_disp8_trust")!=null) this.mc_disp8_trust=Double.parseDouble(properties.getProperty(prefix+"mc_disp8_trust"));
if (properties.getProperty(prefix+"mc_strength")!=null) this.mc_strength=Double.parseDouble(properties.getProperty(prefix+"mc_strength"));
if (properties.getProperty(prefix+"mc_unique_tol")!=null) this.mc_unique_tol=Double.parseDouble(properties.getProperty(prefix+"mc_unique_tol"));
if (properties.getProperty(prefix+"mc_trust_fin")!=null) this.mc_trust_fin=Double.parseDouble(properties.getProperty(prefix+"mc_trust_fin"));
if (properties.getProperty(prefix+"mc_trust_sigma")!=null) this.mc_trust_sigma=Double.parseDouble(properties.getProperty(prefix+"mc_trust_sigma"));
if (properties.getProperty(prefix+"mc_ortho_weight")!=null) this.mc_ortho_weight=Double.parseDouble(properties.getProperty(prefix+"mc_ortho_weight"));
if (properties.getProperty(prefix+"mc_diag_weight")!=null) this.mc_diag_weight=Double.parseDouble(properties.getProperty(prefix+"mc_diag_weight"));
if (properties.getProperty(prefix+"mc_gap")!=null) this.mc_gap=Double.parseDouble(properties.getProperty(prefix+"mc_gap"));
if (properties.getProperty(prefix+"gr_min_new")!=null) this.gr_min_new=Integer.parseInt(properties.getProperty(prefix+"gr_min_new"));
if (properties.getProperty(prefix+"gr_var_new_sngl")!=null) this.gr_var_new_sngl=Boolean.parseBoolean(properties.getProperty(prefix+"gr_var_new_sngl"));
......@@ -3657,7 +3681,9 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"show_histograms")!=null) this.show_histograms=Boolean.parseBoolean(properties.getProperty(prefix+"show_histograms"));
if (properties.getProperty(prefix+"show_init_refine")!=null) this.show_init_refine=Boolean.parseBoolean(properties.getProperty(prefix+"show_init_refine"));
if (properties.getProperty(prefix+"show_expand")!=null) this.show_expand=Boolean.parseBoolean(properties.getProperty(prefix+"show_expand"));
if (properties.getProperty(prefix+"show_variant")!=null) this.show_variant=Boolean.parseBoolean(properties.getProperty(prefix+"show_variant"));
if (properties.getProperty(prefix+"show_retry_far")!=null) this.show_retry_far=Boolean.parseBoolean(properties.getProperty(prefix+"show_retry_far"));
if (properties.getProperty(prefix+"show_macro")!=null) this.show_macro=Boolean.parseBoolean(properties.getProperty(prefix+"show_macro"));
if (properties.getProperty(prefix+"show_shells")!=null) this.show_shells=Boolean.parseBoolean(properties.getProperty(prefix+"show_shells"));
if (properties.getProperty(prefix+"show_neighbors")!=null) this.show_neighbors=Boolean.parseBoolean(properties.getProperty(prefix+"show_neighbors"));
if (properties.getProperty(prefix+"show_flaps_dirs")!=null) this.show_flaps_dirs=Boolean.parseBoolean(properties.getProperty(prefix+"show_flaps_dirs"));
......@@ -3769,7 +3795,8 @@ public class EyesisCorrectionParameters {
gd.addNumericField("X 3", this.fine_corr_x_3, 3);
gd.addNumericField("Y 4", this.fine_corr_y_3, 3);
gd.addNumericField("Minimal correlation strength to apply fine correction", this.fcorr_min_strength,3);
gd.addNumericField("Y 4", this.fcorr_radius, 3);
gd.addNumericField("Do not try to correct outside this fraction of width/hight", this.fcorr_min_strength,3);
gd.addNumericField("Consider only tiles with absolute residual disparity lower than", this.fcorr_disp_diff, 3);
gd.addCheckbox ("Use quadratic polynomial for fine correction (false - only linear)", this.fcorr_quadratic);
gd.addCheckbox ("Ignore current calculated fine correction (use manual only)", this.fcorr_ignore);
......@@ -3894,6 +3921,7 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Show generated triangles", this.show_triangles);
gd.addCheckbox ("Weight-average disparity for the whole cluster ", this.avg_cluster_disp);
gd.addNumericField("Maximal disparity difference in a triangle face to show", this.maxDispTriangle, 6);
gd.addNumericField("Distance to generate backdrop (0 - use regular backdrop)", this.infinityDistance, 8);
gd.addCheckbox ("Split into shells with flaps", this.shUseFlaps);
gd.addCheckbox ("Aggressive fade alpha (whole boundary)", this.shAggrFade);
......@@ -4008,6 +4036,11 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Minimal macro correlation strength to process", this.mc_strength, 6);
gd.addNumericField("Do not re-measure macro correlation if target disparity differs less", this.mc_unique_tol, 6);
gd.addNumericField("When consolidating macro results, exclude high residual disparity", this.mc_trust_fin, 6);
gd.addNumericField("Gaussian sigma to reduce weight of large residual disparity", this.mc_trust_sigma, 6);
gd.addNumericField("Weight from ortho neighbor supertiles", this.mc_ortho_weight, 6);
gd.addNumericField("Weight from diagonal neighbor supertiles", this.mc_diag_weight, 6);
gd.addNumericField("Do not remove measurements farther from the kept ones", this.mc_gap, 6);
gd.addMessage ("--- more growing parameters ---");
gd.addNumericField("Discard variant if it requests too few tiles", this.gr_min_new, 0);
......@@ -4273,7 +4306,9 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Show supertile disparity histograms ", this.show_histograms);
gd.addCheckbox ("Show debug images during initial refinement", this.show_init_refine);
gd.addCheckbox ("Show debug images during disparity expansion", this.show_expand);
gd.addCheckbox ("Show prepareExpandVariant when elevating variant", this.show_variant);
gd.addCheckbox ("Show debug images related to retrying far tiles near foreground", this.show_retry_far);
gd.addCheckbox ("Show debug images related to macro correlation", this.show_macro);
gd.addCheckbox ("Show 'shells'", this.show_shells);
gd.addCheckbox ("show 'neighbors'", this.show_neighbors);
gd.addCheckbox ("Show 'flaps-dirs'", this.show_flaps_dirs);
......@@ -4376,6 +4411,7 @@ public class EyesisCorrectionParameters {
this.fine_corr_x_3= gd.getNextNumber();
this.fine_corr_y_3= gd.getNextNumber();
this.fcorr_radius= gd.getNextNumber();
this.fcorr_min_strength= gd.getNextNumber();
this.fcorr_disp_diff= gd.getNextNumber();
this.fcorr_quadratic= gd.getNextBoolean();
......@@ -4490,6 +4526,7 @@ public class EyesisCorrectionParameters {
this.show_triangles= gd.getNextBoolean();
this.avg_cluster_disp= gd.getNextBoolean();
this.maxDispTriangle= gd.getNextNumber();
this.infinityDistance= gd.getNextNumber();
this.shUseFlaps= gd.getNextBoolean();
this.shAggrFade= gd.getNextBoolean();
this.shMinArea= (int) gd.getNextNumber();
......@@ -4592,6 +4629,12 @@ public class EyesisCorrectionParameters {
this.mc_strength= gd.getNextNumber();
this.mc_unique_tol= gd.getNextNumber();
this.mc_unique_tol= gd.getNextNumber();
this.mc_unique_tol= gd.getNextNumber();
this.mc_unique_tol= gd.getNextNumber();
this.mc_unique_tol= gd.getNextNumber();
this.mc_unique_tol= gd.getNextNumber();
this.gr_min_new= (int) gd.getNextNumber();
this.gr_var_new_sngl= gd.getNextBoolean();
this.gr_var_new_fg= gd.getNextBoolean();
......@@ -4846,7 +4889,9 @@ public class EyesisCorrectionParameters {
this.show_histograms= gd.getNextBoolean();
this.show_init_refine= gd.getNextBoolean();
this.show_expand= gd.getNextBoolean();
this.show_variant= gd.getNextBoolean();
this.show_retry_far= gd.getNextBoolean();
this.show_macro= gd.getNextBoolean();
this.show_shells= gd.getNextBoolean();
this.show_neighbors= gd.getNextBoolean();
this.show_flaps_dirs= gd.getNextBoolean();
......
......@@ -633,7 +633,8 @@ public class GeometryCorrection {
double rri = 1.0;
for (int j = 0; j < a.length; j++){
rri *= ri;
rD2rND += a[j]*(rri - a[j]); // BUG here !!!! - fix later, will need to re-adjust all fine corr
// rD2rND += a[j]*(rri - a[j]); // BUG here !!!! - fix later, will need to re-adjust all fine corr
rD2rND += a[j]*(rri - 1.0); // Fixed
}
double pXid = pXci * rD2rND;
double pYid = pYci * rD2rND;
......@@ -672,7 +673,7 @@ public class GeometryCorrection {
double rri = 1.0;
for (int j = 0; j < a.length; j++){
rri *= ri;
rD2rND += a[j]*(rri - a[j]);
rD2rND += a[j]*(rri - 1.0);
}
double pXid = pXci * rD2rND;
double pYid = pYci * rD2rND;
......
......@@ -3606,12 +3606,12 @@ public class ImageDtt {
} else { // copy by 1
for (int i = 0; i < transform_size2; i++){
int pi = ctile_top + i;
if (pi < 0) pi = 0;
else if (pi >= height) pi = height - 1;
if (pi < 0) pi &= 1;
else if (pi >= height) pi = height - 2 + (pi & 1);
for (int j = 0; j < transform_size2; j++){
int pj = ctile_left + j;
if (pj < 0) pj = 0;
else if (pj >= width) pj = width - 1;
if (pj < 0) pj &= 1;
else if (pj >= width) pj = width - 2 + (pj & 1);
tile_in[transform_size2 * i + j] = image_data[chn][pi * width + pj];
}
}
......
......@@ -23,6 +23,12 @@
**
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.concurrent.atomic.AtomicInteger;
public class MacroCorrelation {
TileProcessor tp; // pixel tile processor
TileProcessor mtp; // macro tile processor
......@@ -339,7 +345,7 @@ public class MacroCorrelation {
EyesisCorrectionParameters.CLTParameters clt_parameters,
GeometryCorrection geometryCorrection,
final double trustedCorrelation,
final double disp_far, // limit results to the disparity range
final double disp_far, // limit results to the disparity range, far - start with 1 step above 0 (was valid for all)
final double disp_near,
final double minStrength,
final double unique_tolerance,
......@@ -373,7 +379,217 @@ public class MacroCorrelation {
}
public ArrayList <CLTPass3d> prepareMeasurementsFromMacro(
final ArrayList <CLTPass3d> macro_passes, // macro correlation measurements
// in pixels
final double disp_far, // limit results to the disparity range
final double disp_near,
final double minStrength,
final double mc_trust_fin, // = 0.3; // When consolidating macro results, exclude high residual disparity
final double mc_trust_sigma, // = 0.2; // Gaussian sigma to reduce weight of large residual disparity
final double mc_ortho_weight, // = 0.5; // Weight from ortho neighbor supertiles
final double mc_diag_weight, // = 0.25; // Weight from diagonal neighbor supertiles
final double mc_gap, // = 0.4; // Do not remove measurements farther from the kept ones
final boolean usePoly, // use polynomial method to find max), valid if useCombo == false
final boolean sort_disparity, // sort results for increasing disparity (false - decreasing strength)
final int dbg_x,
final int dbg_y,
final int debugLevel)
{
class DispStrength{
double disparity;
double strength;
DispStrength (double disparity, double strength){
this.disparity = disparity;
this.strength = strength;
}
double [] toArray(){
double [] arr = {disparity, strength};
return arr;
}
public String toString(){
return String.format("disparity=%7.3f strength=%7.4f",disparity, strength);
}
}
final int mTilesX = mtp.getTilesX();
final int mTilesY = mtp.getTilesY();
final int mTiles = mTilesX * mTilesY;
final ArrayList <CLTPass3d> measurements = new ArrayList <CLTPass3d>();
final TileNeibs tnSurface = new TileNeibs(mtp.getTilesX(), mtp.getTilesY());
final Thread[] threads = ImageDtt.newThreadArray(tp.threadsMax);
final int [] max_meas = new int [threads.length]; // maximal numer of measurements per tile
final int [] num_meas = new int [threads.length]; // maximal numer of measurements per tile
final AtomicInteger ai_thread = new AtomicInteger(0);
final AtomicInteger ai = new AtomicInteger(0);
final int dbg_tile = dbg_x + dbg_y * mTilesX;
final double [][][] macro_ds = new double [mTiles][][];
final int firstPass = 0;
final int lastPassPlus1 = macro_passes.size();
final int disparity_index = usePoly ? ImageDtt.DISPARITY_INDEX_POLY : ImageDtt.DISPARITY_INDEX_CM;
final double disp_far8 = disp_far/tp.getTileSize(); // here tp, not mtp
final double disp_near8 = disp_near/tp.getTileSize(); // here tp, not mtp
final double corr_magic_scale = mtp.getMagicScale();
//mtp.clt_3d_passes
final double [] neib_weights = {
mc_ortho_weight,
mc_diag_weight,
mc_ortho_weight,
mc_diag_weight,
mc_ortho_weight,
mc_diag_weight,
mc_ortho_weight,
mc_diag_weight,
1.0};
final double kexp = (mc_trust_sigma == 0.0) ? 0.0: (0.5/mc_trust_sigma/mc_trust_sigma);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int this_thread = ai_thread.getAndIncrement();
for (int mTile0 = ai.getAndIncrement(); mTile0 < mTiles; mTile0 = ai.getAndIncrement()) {
int dl = (mTile0 == dbg_tile) ? debugLevel : -1;
if (dl > 0){
System.out.println("prepareMeasurementsFromMacro() mTile0="+mTile0);
}
ArrayList<DispStrength> ds_list = new ArrayList<DispStrength>();
for (int ipass = firstPass; ipass <lastPassPlus1; ipass++ ){
CLTPass3d pass = macro_passes.get(ipass);
if ( pass.isMeasured()) { // current tile has valid data
for (int dir = 0; dir < neib_weights.length; dir++){ // 8 - center
int mTile = tnSurface.getNeibIndex(mTile0, dir);
if ((mTile >= 0) && (neib_weights[dir] != 0.0)) {
int mty = mTile / mTilesX;
int mtx = mTile % mTilesX;
if (pass.tile_op[mty][mtx] != 0 ) { // current tile has valid data
double mdisp = pass.disparity_map[disparity_index][mTile];
double strength = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][mTile];
double adiff = Math.abs(mdisp);
if ((strength >= minStrength) && (adiff <= mc_trust_fin)){
double disp = mdisp/corr_magic_scale + pass.disparity[mty][mtx];
if ((disp >= disp_far8) && (disp <= disp_near8)) {
double weight = strength * neib_weights[dir];
if (mc_trust_sigma != 0.0){
weight *= Math.exp(-kexp*mdisp*mdisp);
}
ds_list.add(new DispStrength(disp, weight));
}
}
}
}
}
}
}
// sort by strength copy to new list then remove all that are closer than usePoly, repeat until not empty
Collections.sort(ds_list, new Comparator<DispStrength>() {
@Override
public int compare(DispStrength lhs, DispStrength rhs) {
// descending
return (lhs.strength > rhs.strength) ? -1 : (lhs.strength < rhs.strength) ? 1 : 0;
}
});
ArrayList<DispStrength> ds_list_keep = new ArrayList<DispStrength>();
while (!ds_list.isEmpty()){
DispStrength ds_kept = ds_list.remove(0);
ds_list_keep.add(ds_kept); // move strongest
for (int i = ds_list.size(); i > 0; i--){
DispStrength ds = ds_list.remove(0);
if (Math.abs(ds_kept.disparity-ds.disparity) >= mc_gap){
ds_list.add(ds);
}
}
}
if (!ds_list_keep.isEmpty()){
if (sort_disparity){
Collections.sort(ds_list_keep, new Comparator<DispStrength>() {
@Override
public int compare(DispStrength lhs, DispStrength rhs) {
// ascending
return (lhs.disparity < rhs.disparity) ? -1 : (lhs.disparity > rhs.disparity) ? 1 : 0;
}
});
}
macro_ds[mTile0] = new double[ds_list_keep.size()][];
int indx=0;
for (DispStrength ds:ds_list_keep){
macro_ds[mTile0][indx++] = ds.toArray();
}
if (max_meas[this_thread] < ds_list_keep.size()){
max_meas[this_thread] = ds_list_keep.size();
if (debugLevel > -1){ // (dl > 0){
System.out.println("prepareMeasurementsFromMacro() mTile0="+mTile0+" max_meas["+this_thread+"]="+max_meas[this_thread]);
}
}
num_meas[this_thread] += ds_list_keep.size();
}
}
}
};
}
ImageDtt.startAndJoin(threads);
int longest = 0;
int total_meas = 0;
for (int i = 0; i < max_meas.length; i++){
if (longest < max_meas[i]) {
longest = max_meas[i];
total_meas +=num_meas[i];
}
}
if (debugLevel > -1){
System.out.println("prepareMeasurementsFromMacro(): longest="+longest+" total_meas="+total_meas);
}
int op = ImageDtt.setImgMask(0, 0xf);
op = ImageDtt.setPairMask(op,0xf);
op = ImageDtt.setForcedDisparity(op,true);
final int fop = op;
ai.set(0);
ai_thread.set(0);
for (int i = 0; i < longest; i++){
measurements.add(new CLTPass3d(tp, 0 )); // mode 0 - initialize tile_op and disparity arrays
}
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
// int this_thread = ai_thread.getAndIncrement();
int tileSize = tp.getTileSize();
int tilesX = tp.getTilesX();
int tilesY = tp.getTilesY();
for (int mTile = ai.getAndIncrement(); mTile < mTiles; mTile = ai.getAndIncrement()) {
int dl = (mTile == dbg_tile) ? debugLevel : -1;
if (dl > 0){
System.out.println("prepareMeasurementsFromMacro().1 mTile0="+mTile);
}
if (macro_ds[mTile] != null){
int mty = mTile / mTilesX;
int mtx = mTile % mTilesX;
int ty0 = mty * tileSize;
int tx0 = mtx * tileSize;
int ty1 = ty0 + tileSize; if (ty1 > tilesY) ty1 = tilesY;
int tx1 = tx0 + tileSize; if (tx1 > tilesX) tx1 = tilesX;
for (int ipass = 0; ipass < macro_ds[mTile].length;ipass++){
CLTPass3d pass = measurements.get(ipass);
for (int ty = ty0; ty < ty1; ty++){
for (int tx = tx0; tx < tx1; tx++){
pass.tile_op[ty][tx] = fop;
pass.disparity[ty][tx] = macro_ds[mTile][ipass][0]*tileSize;
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return measurements;
}
}
......@@ -4671,6 +4671,7 @@ public class QuadCLT {
debugLevel); // int debugLevel)
double [][][] new_corr = ac.lazyEyeCorrection(
clt_parameters.fcorr_radius, // final double fcorr_radius,
clt_parameters.fcorr_inf_strength, // final double min_strenth,
clt_parameters.fcorr_inf_diff, // final double max_diff,
// 1.3, // final double comp_strength_var,
......@@ -4875,6 +4876,7 @@ public class QuadCLT {
double [][][] new_corr = ac.lazyEyeCorrection(
clt_parameters.fcorr_radius, // final double fcorr_radius,
clt_parameters.fcorr_inf_strength, // final double min_strenth,
clt_parameters.fcorr_inf_diff, // final double max_diff,
// 1.3, // final double comp_strength_var,
......@@ -5380,6 +5382,106 @@ public class QuadCLT {
tp.clt_3d_passes.get(0), // CLTPass3d scan,
"bgnd_data-"+tp.clt_3d_passes.size());
double [][] filtered_bgnd_disp_strength = tp.getFilteredDisparityStrength(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,// List, first, last - to search for the already tried disparity
tp.clt_3d_passes.size() - 1, // final int measured_scan_index, // will not look at higher scans
0, // final int start_scan_index,
null , // final boolean [] bg_tiles, // get from selected in clt_3d_passes.get(0);
0.0, // whatever as null above // clt_parameters.ex_min_over,// final double ex_min_over, // when expanding over previously detected (by error) background, disregard far tiles
disp_index, // final int disp_index,
str_index, // final int str_index,
null, // final double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
trustedCorrelation, // final double trustedCorrelation,
strength_floor, // final double strength_floor,
strength_pow, // final double strength_pow,
smplSide, // final int smplSide, // = 2; // Sample size (side of a square)
smplNum, // final int smplNum, // = 3; // Number after removing worst (should be >1)
smplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplRelRms, // final double smplRelRms, // = 0.005; // Maximal RMS/disparity in addition to smplRms
smplWnd, // final boolean smplWnd, //
max_abs_tilt, // final double max_abs_tilt, // = 2.0; // pix per tile
max_rel_tilt, // final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel); // final int debugLevel)
ImagePlus imp_bgnd = getBackgroundImage(
clt_parameters,
colorProcParameters,
rgbParameters,
name, // .getTitle(), //String name=(String) imp_src.getProperty("name");
ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4)
threadsMax, // maximal number of threads to launch
updateStatus,
1); // debugLevel);
// bgnd_data.texture = imp_bgnd.getTitle()+".png";
if (clt_parameters.show_expand ) { // getBackgroundImage() sets selected
String [] titles = {"disp","strength", "disp_combined","str_combined","max_tried","selected"};
String title = "FDS_"+(tp.clt_3d_passes.size() - 1);
double [][] dbg_img = new double [titles.length][];
dbg_img[0] = filtered_bgnd_disp_strength[0];
dbg_img[1] = filtered_bgnd_disp_strength[1];
dbg_img[2] = bgnd_data.getDisparity();
dbg_img[3] = bgnd_data.getStrength();
double [][] max_tried_disparity = bgnd_data.getMaxTriedDisparity();
if (max_tried_disparity != null){
dbg_img[4] = new double [tilesX * tilesY];
for (int ty = 0; ty < tilesY; ty++){
for (int tx = 0; tx < tilesX; tx++){
dbg_img[4][ty*tilesX + tx] = max_tried_disparity[ty][tx];
}
}
}
boolean [] s_selected = bgnd_data.selected;
if (s_selected != null) {
boolean [] s_border = (bgnd_data.border_tiles!= null) ? bgnd_data.border_tiles :(new boolean [s_selected.length]);
dbg_img[5] = new double [tilesX * tilesY];
for (int i = 0; i < dbg_img[5].length; i++){
dbg_img[5][i] = 1.0 * ((s_selected[i]?1:0) + (s_border[i]?2:0));
}
}
(new showDoubleFloatArrays()).showArrays(dbg_img, tilesX, tilesY, true, title,titles);
}
// if (debugLevel > -100) {
// return null;
// }
bgnd_data.texture = imp_bgnd.getTitle()+ (clt_parameters.black_back? ".jpeg" : ".png");
// create x3d file
X3dOutput x3dOutput = new X3dOutput(
clt_parameters,
correctionsParameters,
geometryCorrection,
tp.clt_3d_passes);
x3dOutput.generateBackground(clt_parameters.infinityDistance <= 0.0); // needs just first (background) scan
String x3d_path= correctionsParameters.selectX3dDirectory(
true, // smart,
true); //newAllowed, // save
// refine first measurement
int bg_pass = tp.clt_3d_passes.size() - 1; // 0
int refine_pass = tp.clt_3d_passes.size(); // 1
// final boolean show_init_refine = true;
// final boolean show_expand = true;
// if (show_init_refine)
tp.showScan(
tp.clt_3d_passes.get(bg_pass), // CLTPass3d scan,
"after_bg-"+tp.clt_3d_passes.size());
// Test macro correlation and exit.
MacroCorrelation mc = new MacroCorrelation(
......@@ -5418,9 +5520,11 @@ public class QuadCLT {
true, // final boolean copyDebug)
debugLevel);
mtp.clt_3d_passes.add(macro_combo);
if (clt_parameters.show_macro) {
mtp.showScan(
macro_combo, // CLTPass3d scan,
"macro_combo-"+mtp.clt_3d_passes.size());
}
for (int num_try = 0; num_try < 100; num_try++) {
CLTPass3d refined_macro = mc.refineMacro(
......@@ -5435,9 +5539,11 @@ public class QuadCLT {
1); // final int debugLevel)
if (refined_macro == null) break;
mtp.clt_3d_passes.add(refined_macro);
if (clt_parameters.show_macro) {
mtp.showScan(
refined_macro, // CLTPass3d scan,
"refined_macro-"+mtp.clt_3d_passes.size());
}
}
CLTPass3d macro_combo1 = mtp.compositeScan(
......@@ -5458,113 +5564,159 @@ public class QuadCLT {
true, // final boolean copyDebug)
debugLevel);
mtp.clt_3d_passes.add(macro_combo1);
if (clt_parameters.show_macro) {
mtp.showScan(
macro_combo1, // CLTPass3d scan,
"macro_combo-"+mtp.clt_3d_passes.size());
// Temporary exit here
if (debugLevel > -100){
return null;
}
ArrayList <CLTPass3d> new_meas = mc.prepareMeasurementsFromMacro(
mtp.clt_3d_passes, // final ArrayList <CLTPass3d> macro_passes, // macro correlation measurements
// in pixels
3.0, // final double disp_far, // limit results to the disparity range
clt_parameters.grow_disp_max, // final double disp_near,
clt_parameters.mc_strength, // final double minStrength,
clt_parameters.mc_strength, //final double mc_trust_fin, // = 0.3; // When consolidating macro results, exclude high residual disparity
clt_parameters.mc_strength, //final double mc_trust_sigma, // = 0.2; // Gaussian sigma to reduce weight of large residual disparity
clt_parameters.mc_strength, //final double mc_ortho_weight, // = 0.5; // Weight from ortho neighbor supertiles
clt_parameters.mc_strength, //final double mc_diag_weight, // = 0.25; // Weight from diagonal neighbor supertiles
clt_parameters.mc_strength, //final double mc_gap, // = 0.4; // Do not remove measurements farther from the kept ones
false, // final boolean usePoly, // use polynomial method to find max), valid if useCombo == false
true, // final boolean sort_disparity, // sort results for increasing disparity (false - decreasing strength)
clt_parameters.tileX, // final int dbg_x,
clt_parameters.tileY, // final int dbg_y,
debugLevel); // final int debugLevel);
System.out.println("new_meas.size()="+new_meas.size());
int indx = 0;
if (clt_parameters.show_macro) {
for (CLTPass3d pass: new_meas) {
tp.showScan(
pass, // CLTPass3d scan,
"meas-"+(indx++));
double [][] filtered_bgnd_disp_strength = tp.getFilteredDisparityStrength(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,// List, first, last - to search for the already tried disparity
tp.clt_3d_passes.size() - 1, // final int measured_scan_index, // will not look at higher scans
0, // final int start_scan_index,
null , // final boolean [] bg_tiles, // get from selected in clt_3d_passes.get(0);
0.0, // whatever as null above // clt_parameters.ex_min_over,// final double ex_min_over, // when expanding over previously detected (by error) background, disregard far tiles
disp_index, // final int disp_index,
str_index, // final int str_index,
null, // final double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
trustedCorrelation, // final double trustedCorrelation,
strength_floor, // final double strength_floor,
strength_pow, // final double strength_pow,
smplSide, // final int smplSide, // = 2; // Sample size (side of a square)
smplNum, // final int smplNum, // = 3; // Number after removing worst (should be >1)
smplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplRelRms, // final double smplRelRms, // = 0.005; // Maximal RMS/disparity in addition to smplRms
smplWnd, // final boolean smplWnd, //
max_abs_tilt, // final double max_abs_tilt, // = 2.0; // pix per tile
max_rel_tilt, // final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
dbg_x, // final int dbg_x,
dbg_y, // final int dbg_y,
debugLevel); // final int debugLevel)
if (clt_parameters.show_expand ) {
String [] titles = {"disp","strength", "disp_combined","str_combined","max_tried","selected"};
String title = "FDS_"+(tp.clt_3d_passes.size() - 1);
double [][] dbg_img = new double [titles.length][];
dbg_img[0] = filtered_bgnd_disp_strength[0];
dbg_img[1] = filtered_bgnd_disp_strength[1];
dbg_img[2] = bgnd_data.getDisparity();
dbg_img[3] = bgnd_data.getStrength();
double [][] max_tried_disparity = bgnd_data.getMaxTriedDisparity();
if (max_tried_disparity != null){
dbg_img[4] = new double [tilesX * tilesY];
for (int ty = 0; ty < tilesY; ty++){
for (int tx = 0; tx < tilesX; tx++){
dbg_img[4][ty*tilesX + tx] = max_tried_disparity[ty][tx];
}
}
}
boolean [] s_selected = bgnd_data.selected;
boolean [] s_border = bgnd_data.border_tiles;
if ((s_selected != null) && (s_border != null)){
dbg_img[5] = new double [tilesX * tilesY];
for (int i = 0; i < dbg_img[5].length; i++){
dbg_img[5][i] = 1.0 * ((s_selected[i]?1:0) + (s_border[i]?2:0));
}
}
(new showDoubleFloatArrays()).showArrays(dbg_img, tilesX, tilesY, true, title,titles);
}
int num_macro_refine = 3;
for (CLTPass3d from_macro_pass: new_meas) {
for (int nnn = 0; nnn < num_macro_refine; nnn ++){ //
refine_pass = tp.clt_3d_passes.size(); // 1
CLTPass3d refined = tp.refinePassSetup( // prepare tile tasks for the refine pass (re-measure disparities)
// final double [][][] image_data, // first index - number of image in a quad
clt_parameters,
clt_parameters.stUseRefine, // use supertiles
bg_pass,
// disparity range - differences from
clt_parameters.bgnd_range, // double disparity_far,
clt_parameters.grow_disp_max, // other_range, //double disparity_near, //
clt_parameters.ex_strength, // double this_sure, // minimal strength to be considered definitely good
clt_parameters.ex_nstrength, // double ex_nstrength, // minimal 4-corr strength divided by channel diff for new (border) tiles
clt_parameters.bgnd_maybe, // double this_maybe, // maximal strength to ignore as non-background
clt_parameters.sure_smth, // sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd
clt_parameters.pt_super_trust, // final double super_trust, // If strength exceeds ex_strength * super_trust, do not apply ex_nstrength and plate_ds
// using plates disparity/strength - averaged for small square sets of tiles. If null - just use raw tiles
null, // final double [][] plate_ds, // disparity/strength last time measured for the multi-tile squares. Strength =-1 - not measured. May be null
true, // final boolean keep_raw_fg, // do not replace raw tiles by the plates, if raw is closer (like poles)
0.0, // final double scale_filtered_strength_pre, // scale plate_ds[1] before comparing to raw strength
0.0, // final double scale_filtered_strength_post,// scale plate_ds[1] when replacing raw (generally plate_ds is more reliable if it exists)
ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4)
geometryCorrection,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel); //2);
tp.clt_3d_passes.add(refined);
/// if (debugLevel > 1)
if (debugLevel > 0)
tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"before_makeUnique-"+refine_pass);
int [] numLeftRemoved = tp.makeUnique(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
0, // final int firstPass,
refine_pass, // - 1, // final int lastPassPlus1,
tp.clt_3d_passes.get(refine_pass), // final CLTPass3d new_scan,
clt_parameters.grow_disp_max, // final double grow_disp_max,
clt_parameters.gr_unique_tol, // final double unique_tolerance,
clt_parameters.show_unique); // final boolean show_unique)
if (debugLevel > -1){
System.out.println("cycle makeUnique("+refine_pass+") -> left: "+numLeftRemoved[0]+", removed:" + numLeftRemoved[1]);
}
if (show_init_refine) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_refinePassSetup-"+tp.clt_3d_passes.size());
ImagePlus imp_bgnd = getBackgroundImage(
CLTMeasure( // perform single pass according to prepared tiles operations and disparity
image_data, // first index - number of image in a quad
clt_parameters,
colorProcParameters,
rgbParameters,
name, // .getTitle(), //String name=(String) imp_src.getProperty("name");
ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4)
refine_pass,
true, // final boolean save_textures,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
// bgnd_data.texture = imp_bgnd.getTitle()+".png";
bgnd_data.texture = imp_bgnd.getTitle()+ (clt_parameters.black_back? ".jpeg" : ".png");
// create x3d file
X3dOutput x3dOutput = new X3dOutput(
clt_parameters,
correctionsParameters,
geometryCorrection,
tp.clt_3d_passes);
if (debugLevel > -1){
System.out.println("CLTMeasure("+refine_pass+")");
}
if (show_init_refine) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_measure-"+tp.clt_3d_passes.size());
if (nnn < (num_macro_refine-1)) {
// if (clt_parameters.combine_refine){
CLTPass3d combo_pass = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
// tp.clt_3d_passes.get(bg_pass).getSelected(), // selected , // final boolean [] bg_tiles, // get from selected in clt_3d_passes.get(0);
// clt_parameters.ex_min_over,// final double ex_min_over, // when expanding over previously detected (by error) background, disregard far tiles
tp.getTrustedCorrelation(), // final double trustedCorrelation,
0.0, // clt_parameters.bgnd_range, // final double disp_far, // limit results to the disparity range
clt_parameters.grow_disp_max, // final double disp_near,
clt_parameters.combine_min_strength, // final double minStrength,
clt_parameters.combine_min_hor, // final double minStrengthHor,
clt_parameters.combine_min_vert, // final double minStrengthVert,
false, // final boolean no_weak,
false, // final boolean use_last, //
// TODO: when useCombo - pay attention to borders (disregard)
false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false
true, // final boolean copyDebug)
debugLevel);
x3dOutput.generateBackground();
String x3d_path= correctionsParameters.selectX3dDirectory(
true, // smart,
true); //newAllowed, // save
if (show_init_refine) tp.showScan(
combo_pass, // CLTPass3d scan,
"after_compositeScan-"+tp.clt_3d_passes.size());
// refine first measurement
int bg_pass = tp.clt_3d_passes.size() - 1; // 0
int refine_pass = tp.clt_3d_passes.size(); // 1
tp.clt_3d_passes.add(combo_pass);
// final boolean show_init_refine = true;
// final boolean show_expand = true;
}
}
// add new scan from macro
tp.clt_3d_passes.add(from_macro_pass);
CLTMeasure( // perform single pass according to prepared tiles operations and disparity
image_data, // first index - number of image in a quad
clt_parameters,
tp.clt_3d_passes.size() -1, // refine_pass,
true, // final boolean save_textures,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
if (debugLevel > -1){
System.out.println("CLTMeasure("+refine_pass+")");
}
if (show_init_refine) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_measure_macro-"+tp.clt_3d_passes.size());
// if (show_init_refine)
tp.showScan(
tp.clt_3d_passes.get(bg_pass), // CLTPass3d scan,
"after_bg-"+tp.clt_3d_passes.size());
}
for (int nnn = 0; nnn < 2; nnn ++){
/// Refining after all added
if (debugLevel > -1){
System.out.println("---- Refining after all added ----");
}
// first ("before_makeUnique-41-" was empty)
for (int nnn = 0; nnn < num_macro_refine; nnn ++){ //
refine_pass = tp.clt_3d_passes.size(); // 1
CLTPass3d refined = tp.refinePassSetup( // prepare tile tasks for the refine pass (re-measure disparities)
// final double [][][] image_data, // first index - number of image in a quad
......@@ -5592,8 +5744,8 @@ public class QuadCLT {
debugLevel); //2);
tp.clt_3d_passes.add(refined);
/// if (debugLevel > 1)
if (debugLevel > -1)
/// if (debugLevel > 1)
if (debugLevel > 0)
tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"before_makeUnique-"+refine_pass);
......@@ -5626,13 +5778,13 @@ public class QuadCLT {
if (show_init_refine) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_measure-"+tp.clt_3d_passes.size());
// if (nnn < (num_macro_refine-1)) {
// if (clt_parameters.combine_refine){
CLTPass3d combo_pass = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
// tp.clt_3d_passes.get(bg_pass).getSelected(), // selected , // final boolean [] bg_tiles, // get from selected in clt_3d_passes.get(0);
// tp.clt_3d_passes.get(bg_pass).getSelected(), // selected , // final boolean [] bg_tiles, // get from selected in clt_3d_passes.get(0);
// clt_parameters.ex_min_over,// final double ex_min_over, // when expanding over previously detected (by error) background, disregard far tiles
tp.getTrustedCorrelation(), // final double trustedCorrelation,
0.0, // clt_parameters.bgnd_range, // final double disp_far, // limit results to the disparity range
......@@ -5652,10 +5804,13 @@ public class QuadCLT {
"after_compositeScan-"+tp.clt_3d_passes.size());
tp.clt_3d_passes.add(combo_pass);
// refine_pass = tp.clt_3d_passes.size();
// }
}
///// Refining after all added - end
// TEMPORARY EXIT
// if (tp.clt_3d_passes.size() > 0) return null; // just to fool compiler
......@@ -5667,7 +5822,7 @@ public class QuadCLT {
// for (int num_expand = 0; (num_expand < 4) && (num_extended != 0); num_expand++) {
boolean over_infinity = false;
int dbg_start_pass = 4; // 10; // 20;
int dbg_end_pass = 20; // 12; // -29;
int dbg_end_pass = -20; // 12; // -29;
// final int dbg_x0 = 73; //
// final int dbg_y0 = 195; //
for (int num_expand = 0; num_expand < max_expand; num_expand++) {
......@@ -5969,7 +6124,8 @@ public class QuadCLT {
refine_pass = tp.clt_3d_passes.size(); // now points to the extended_pass !!
tp.clt_3d_passes.add(extended_pass);
if (clt_parameters.show_expand || (numLeftRemoved[1] > 1 )) tp.showScan(
if (clt_parameters.show_expand || (clt_parameters.show_variant && (numLeftRemoved[1] > 1 ))) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"prepareExpandVariant-"+numLeftRemoved[1]+"-"+refine_pass); //String title)
......@@ -6024,12 +6180,16 @@ public class QuadCLT {
// num_extended = numLeftRemoved[0];
//TODO: break if nothing wanted? - here yes, will make sense
} // end of old way
} // if (use_zMapExpansionStep) else
// } // if (use_zMapExpansionStep) else
//// num_extended = numLeftRemoved[0];
//// num_extended = numLeftRemoved[0];
// refine_pass = tp.clt_3d_passes.size(); //
//java.lang.IndexOutOfBoundsException: Index: 43, Size: 35
refine_pass = tp.clt_3d_passes.size() - 1; // was not here!
CLTMeasure( // perform single pass according to prepared tiles operations and disparity
image_data, // first index - number of image in a quad
clt_parameters,
......@@ -6077,19 +6237,20 @@ public class QuadCLT {
true, // final boolean copyDebug)
// (num_expand == 9)? 2: debugLevel);
debugLevel);
// tp.filterOverBackground(
// combo_pass, // final CLTPass3d pass,
// comboMinStrength, // final double minStrength,
// comboMinStrengthHor, // final double minStrengthHor,
// comboMinStrengthVert, //final double minStrengthVert,
// tp.clt_3d_passes.get(bg_pass).getSelected(), // selected , // final boolean [] bg_tiles, // get from selected in clt_3d_passes.get(0);
// clt_parameters.ex_min_over);// final double ex_min_over, // when expanding over previously detected (by error) background, disregard far tiles
// tp.filterOverBackground(
// combo_pass, // final CLTPass3d pass,
// comboMinStrength, // final double minStrength,
// comboMinStrengthHor, // final double minStrengthHor,
// comboMinStrengthVert, //final double minStrengthVert,
// tp.clt_3d_passes.get(bg_pass).getSelected(), // selected , // final boolean [] bg_tiles, // get from selected in clt_3d_passes.get(0);
// clt_parameters.ex_min_over);// final double ex_min_over, // when expanding over previously detected (by error) background, disregard far tiles
tp.clt_3d_passes.add(combo_pass);
// refine_pass = tp.clt_3d_passes.size();
// }
if (show_expand || (clt_parameters.show_expand && last_pass)) tp.showScan(
tp.clt_3d_passes.get(tp.clt_3d_passes.size() -1), // refine_pass), // CLTPass3d scan,
"after_combo_pass-"+(tp.clt_3d_passes.size() -1)); // (refine_pass)); //String title)
} // if (use_zMapExpansionStep) else
if (last_pass) {
......@@ -6144,9 +6305,8 @@ public class QuadCLT {
threadsMax, // maximal number of threads to launch
updateStatus,
0); // 2); // debugLevel);
// get images for predefined regions and disparities. First - with just fixed scans 1 .. list.size()
// TEMPORARY EXIT
// Save tp.clt_3d_passes.size() to roll back without restarting the program
tp.saveCLTPasses();
......@@ -6461,7 +6621,7 @@ public class QuadCLT {
dbg_y,
debugLevel);
num_extended = numLeftRemoved[0];
if (clt_parameters.show_expand || (numLeftRemoved[1] > 1 )) tp.showScan(
if (clt_parameters.show_expand || (clt_parameters.show_variant && (numLeftRemoved[1] > 1 ))) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"prepareExpandVariant-"+numLeftRemoved[1]+"-"+refine_pass); //String title)
}
......@@ -6631,9 +6791,12 @@ public class QuadCLT {
tp.clt_3d_passes.add(latest_scan); // put it back
}
int next_pass = tp.clt_3d_passes.size(); //
tp.showScan(
tp.clt_3d_passes.get(next_pass-1), // CLTPass3d scan,
"after_pass2-"+(next_pass-1)); //String title)
// tp.showScan(
// tp.clt_3d_passes.get(0), // CLTPass3d scan,
// "bg_scan"); //String title)
// tp.showScan(
// tp.clt_3d_passes.get(next_pass-1), // CLTPass3d scan,
// "after_pass2-"+(next_pass-1)); //String title)
// tp.thirdPassSetup( // prepare tile tasks for the second pass based on the previous one(s)
tp.thirdPassSetupSurf( // prepare tile tasks for the second pass based on the previous one(s) // needs last scan
......@@ -6654,12 +6817,94 @@ public class QuadCLT {
geometryCorrection,
tp.clt_3d_passes);
x3dOutput.generateBackground(); // needs just first (background) scan
x3dOutput.generateBackground(clt_parameters.infinityDistance <= 0.0); // needs just first (background) scan
String x3d_path= correctionsParameters.selectX3dDirectory(
true, // smart,
true); //newAllowed, // save
if (clt_parameters.infinityDistance > 0.0){ // generate background as a billboard
// tp.showScan(
// tp.clt_3d_passes.get(0), // CLTPass3d scan,
// "bg_scan_inf"); //String title)
double infinity_disparity = geometryCorrection.getDisparityFromZ(clt_parameters.infinityDistance);
int scanIndex = 0; // it already exists?
CLTPass3d scan = tp.clt_3d_passes.get(scanIndex);
// grow selection, then grow once more and create border_tiles
// create/rstore, probably not needed
boolean [] bg_sel_backup = scan.getSelected().clone();
boolean [] bg_border_backup = (scan.getBorderTiles() == null) ? null: scan.getBorderTiles().clone();
boolean [] bg_selected = scan.getSelected();
// tp.growTiles(
// 2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
// bg_selected,
// null); // prohibit
boolean [] border_tiles = bg_selected.clone();
tp.growTiles(
2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
bg_selected,
null); // prohibit
// for (int)
for (int i = 0; i < border_tiles.length; i++){
border_tiles[i] = !border_tiles[i] && bg_selected[i];
}
// update texture_tiles (remove what is known not to be background
for (int ty = 0; ty < tilesY; ty++){
for (int tx = 0; tx < tilesX; tx++){
if (!bg_selected[tx + tilesX*ty]){
scan.texture_tiles[ty][tx] = null;
}
}
}
scan.setBorderTiles(border_tiles);
// updates selection from non-null texture tiles
String texturePath = getPassImage( // get image from a single pass
clt_parameters,
colorProcParameters,
rgbParameters,
this.image_name+"-img_bgnd", // +scanIndex,
scanIndex,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
double [] scan_disparity = new double [tilesX * tilesY];
int indx = 0;
// boolean [] scan_selected = scan.getSelected();
for (int ty = 0; ty < tilesY; ty ++) for (int tx = 0; tx < tilesX; tx ++){
scan_disparity[indx++] = infinity_disparity;
}
// tp.showScan(
// scan, // CLTPass3d scan,
// "infinityDistance");
boolean showTri = false; // ((scanIndex < next_pass + 1) && clt_parameters.show_triangles) ||((scanIndex - next_pass) == 73);
generateClusterX3d(
x3dOutput,
texturePath,
"shape_id-bgnd", // (scanIndex - next_pass), // id
scan.getTextureBounds(),
scan.selected,
scan_disparity, // scan.disparity_map[ImageDtt.DISPARITY_INDEX_CM],
clt_parameters.transform_size,
clt_parameters.correct_distortions, // requires backdrop image to be corrected also
showTri, // (scanIndex < next_pass + 1) && clt_parameters.show_triangles,
infinity_disparity, // 0.3
clt_parameters.grow_disp_max, // other_range, // 2.0 'other_range - difference from the specified (*_CM)
clt_parameters.maxDispTriangle);
// maybe not needed
scan.setBorderTiles(bg_border_backup);
scan.setSelected(bg_sel_backup);
}
for (int scanIndex = next_pass; scanIndex < tp.clt_3d_passes.size(); scanIndex++){
......@@ -6779,7 +7024,7 @@ public class QuadCLT {
String id,
Rectangle bounds,
boolean [] selected,
double [] disparity,
double [] disparity, // if null, will use min_disparity
int tile_size,
boolean correctDistortions, // requires backdrop image to be corrected also
boolean show_triangles,
......@@ -6822,11 +7067,15 @@ public class QuadCLT {
if (show_triangles) {
double [] ddisp = (disparity == null)?(new double[1]):disparity;
if (disparity == null) {
ddisp[0] = min_disparity;
}
tp.testTriangles(
texturePath,
bounds,
selected,
disparity,
ddisp, // disparity, // if disparity.length == 1 - use for all
tile_size,
indices,
triangles);
......@@ -6862,6 +7111,7 @@ public class QuadCLT {
showDoubleFloatArrays sdfa_instance = null;
if (clt_parameters.debug_filters && (debugLevel > -1))
// if ((debugLevel > -1))
sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
CLTPass3d bgnd_data = tp.clt_3d_passes.get(0);
......@@ -6939,9 +7189,7 @@ public class QuadCLT {
for (int tileX = 0; tileX < tilesX; tileX++){
texture_tiles_bgnd[tileY][tileX]= null;
if ((texture_tiles[tileY][tileX] != null) &&
// bgnd_tiles[tileY * tilesX + tileX]) {
bgnd_tiles_grown2[tileY * tilesX + tileX]) {
// if (bgnd_tiles_grown[tileY * tilesX + tileX]) {
if (bgnd_tiles[tileY * tilesX + tileX]) {
texture_tiles_bgnd[tileY][tileX]= texture_tiles[tileY][tileX];
}else{
......@@ -6957,7 +7205,6 @@ public class QuadCLT {
texture_tiles_bgnd[tileY][tileX]= null;
if ((texture_tiles[tileY][tileX] != null) &&
bgnd_tiles[tileY * tilesX + tileX]) {
// if (bgnd_tiles_grown[tileY * tilesX + tileX]) {
if (bgnd_tiles_grown2[tileY * tilesX + tileX]) {
texture_tiles_bgnd[tileY][tileX]= texture_tiles[tileY][tileX];
}else{
......
......@@ -640,11 +640,9 @@ public class TileProcessor {
{
final int dbg_tile = (debugLevel > 0)? 839: -1; // x = 122, y= 108; -1; // 27669;
CLTPass3d combo_pass =new CLTPass3d(this);
final int tlen = tilesX * tilesY;
final int disparity_index = usePoly ? ImageDtt.DISPARITY_INDEX_POLY : ImageDtt.DISPARITY_INDEX_CM;
combo_pass.tile_op = new int [tilesY][tilesX];
combo_pass.disparity = new double [tilesY][tilesX];
// for (int i = 0; i< ImageDtt.QUAD; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i] = new double[tlen];
int op = ImageDtt.setImgMask(0, 0xf);
op = ImageDtt.setPairMask(op,0xf);
op = ImageDtt.setForcedDisparity(op,true);
......@@ -679,7 +677,7 @@ public class TileProcessor {
double disp_low = Math.min(disp, pass.disparity[ty][tx]);
double disp_high = Math.max(disp, pass.disparity[ty][tx]);
// if ((disp_high - disp_low) > 2 * unique_tolerance) { // suggested correction is not too small
if ((disp_high - disp_low) > unique_tolerance) { // suggested correction is not too small
if ((disp_high - disp_low) >= unique_tolerance) { // suggested correction is not too small
boolean duplicate = false;
for (int iother = firstPass; iother <lastPassPlus1; iother++ ) {
CLTPass3d other = passes.get(iother);
......@@ -714,8 +712,6 @@ public class TileProcessor {
/**
* Verify that selected points are not all on the same line
* @param sel 2-d sample selection in linescan order
......@@ -7357,7 +7353,8 @@ public class TileProcessor {
for (int x = 0; (x < width) && (indx <= maxIndex); x++){
if (indices[y][x] >=0){
// center coordinates for 8*8 tile is [3.5,3.5]
double disp = disparity[(bounds.y + y) * tilesX + (bounds.x + x)];
// double disp = disparity[(bounds.y + y) * tilesX + (bounds.x + x)];
double disp = (disparity == null)? min_disparity:( disparity[(bounds.y + y) * tilesX + (bounds.x + x)]);
if (disp < min_disparity) disp = min_disparity;
else if (disp > max_disparity) disp = max_disparity;
indexedDisparity[indx] =disp;
......@@ -7370,7 +7367,7 @@ public class TileProcessor {
public double [][] getCoords( // get world XYZ in meters for indices
double [] disparity,
double [] disparity, // null - use min_disparity
double min_disparity,
double max_disparity,
Rectangle bounds,
......@@ -7390,7 +7387,7 @@ public class TileProcessor {
// center coordinates for 8*8 tile is [3.5,3.5]
double px = (bounds.x + x + 0.5) * tile_size - 0.5;
double py = (bounds.y + y + 0.5) * tile_size - 0.5;
double disp = disparity[(bounds.y + y) * tilesX + (bounds.x + x)];
double disp = (disparity == null)? min_disparity:( disparity[(bounds.y + y) * tilesX + (bounds.x + x)]);
if (disp < min_disparity) disp = min_disparity;
else if (disp > max_disparity) disp = max_disparity;
coordinate[indx] = geometryCorrection.getWorldCoordinates(
......@@ -7528,7 +7525,7 @@ public class TileProcessor {
String [] titles = {"disparity","triangles"};
double [][] dbg_img = new double [titles.length][tilesX*tilesY*tile_size*tile_size];
for (int i = 0; i < selected.length; i++ ){
double d = selected[i]?disparity[i]:Double.NaN;
double d = selected[i]? ((disparity.length >1) ? disparity[i] : disparity[0]):Double.NaN;
int y = i / tilesX;
int x = i % tilesX;
for (int dy = 0; dy <tile_size; dy ++){
......
......@@ -64,7 +64,7 @@ public class X3dOutput {
this.clt_3d_passes = clt_3d_passes;
}
// init document, bounding box, backdrop
public void generateBackground()
public void generateBackground(boolean use_backdrop)
{
try {
......@@ -98,6 +98,7 @@ public class X3dOutput {
Element el_Bgnd = x3dDoc.createElement("Background");
el_Bgnd.setAttribute("class","Background");
el_Bgnd.setAttribute("id", "Background");
if (use_backdrop) {
el_Bgnd.setAttribute("frontUrl", bgnd_pass.texture);
// temporarily - add same picture to all other sides. Actually - any square will work, make some
// perspective grids/ colors to simplify orientation when looking wrong way
......@@ -106,6 +107,7 @@ public class X3dOutput {
el_Bgnd.setAttribute("rightUrl", bgnd_pass.texture);
el_Bgnd.setAttribute("topUrl", bgnd_pass.texture);
el_Bgnd.setAttribute("bottomUrl", bgnd_pass.texture);
}
el_Scene.appendChild(el_Bgnd);
}
......
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