Commit 88e3bc5d authored by Andrey Filippov's avatar Andrey Filippov

working on initial z-map generation

parent 8d62abba
......@@ -1219,6 +1219,7 @@ public class AlignmentCorrection {
}
return disp_strength;
}
public double[][] filterDisparityStrength (
final double[][] disp_strength_in,
final double strength_floor,
......@@ -1362,6 +1363,13 @@ public class AlignmentCorrection {
}
return disp_strength;
}
public void show_fine_corr(
double [][][] corr,
String prefix)
......
......@@ -74,7 +74,10 @@ public class CLTPass3d{
{
return texture_tiles;
}
public double [][] getMaxTriedDisparity()
{
return max_tried_disparity;
}
public double [][] getTileRBGA(
int num_layers)
{
......@@ -746,6 +749,9 @@ public class CLTPass3d{
public SuperTiles getSuperTiles()
{
return this.superTiles;
......@@ -764,6 +770,7 @@ public class CLTPass3d{
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, // use window functions for the samples
int measSel)
{
this.superTiles = new SuperTiles(
......@@ -780,6 +787,7 @@ public class CLTPass3d{
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
smplWnd, // final boolean smplWnd, // use window functions for the samples
measSel);
return this.superTiles;
}
......@@ -791,6 +799,7 @@ public class CLTPass3d{
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, // use window functions for the samples
int measSel)
{
if (this.superTiles == null){
......@@ -804,6 +813,7 @@ public class CLTPass3d{
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
smplWnd, // use window functions for the samples
measSel);
}
......
......@@ -529,7 +529,8 @@ public class ConnectionCosts {
conn_weight += 1.0;
}
}
double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight(),conn_weight};
// double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight(),conn_weight};
double [] value_weight = {merged_plane.getNormValue(),merged_plane.getWeight(),conn_weight};
if (starPwr != 0){
value_weight[0] /= (Math.pow((planes[nsTile][nl].getNumNeibBest() + 1.0), starPwr));
}
......@@ -638,7 +639,8 @@ public class ConnectionCosts {
conn_weight += entry.getValue();
}
double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight(),conn_weight};
// double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight(),conn_weight};
double [] value_weight = {merged_plane.getNormValue(),merged_plane.getWeight(),conn_weight};
if (starPwr != 0){
value_weight[0] /= (Math.pow(tile_weights.size() + 1.0, starPwr));
}
......
......@@ -2070,6 +2070,11 @@ public class EyesisCorrectionParameters {
public double ex_strength = 0.18; // minimal 4-corr strength to trust tile
public double ex_nstrength = 0.4; // minimal 4-corr strength divided by channel diff for new (border) tiles
public double pt_super_trust = 1.6; // If strength exceeds ex_strength * super_trust, do not apply ex_nstrength and plate_ds
public boolean pt_keep_raw_fg = true; // Do not replace raw tiles by the plates, if raw is closer (like poles)
public double pt_scale_pre = 1.5; // Scale plates strength before comparing to raw strength
public double pt_scale_post = 2.5; // Scale plates strength when replacing raw (plates d/s data is more reliable if it exists)
public double bgnd_sure = 0.18; // minimal strength to be considered definitely background
public double bgnd_maybe = 0.1; // maximal strength to ignore as non-background
// public double bgnd_2diff = 0.005; // maximal strength to ignore as non-background
......@@ -2116,6 +2121,9 @@ public class EyesisCorrectionParameters {
public boolean poles_force_disp = true; // Set disparity to that of the bottom of existing segment (false - use hor. disparity)
public int max_clusters = 300; // Maximal number of clusters to generate for one run
public boolean remove_scans = true; // Remove all unneeded scans when generating x3d output to save memory
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
......@@ -2179,6 +2187,7 @@ public class EyesisCorrectionParameters {
public int stSmplSide = 2; // Sample size (side of a square)
public int stSmplNum = 3; // Number after removing worst
public double stSmplRms = 0.1; // Maximal RMS of the remaining tiles in a sample
public boolean stSmplWnd = false; // Use window function for the samples (TODO: change default to true after testing)
public int stGrowSel = 2; // Grow initial selection before processing supertiles, odd - ortho. <0 - use all tiles
public int stMeasSel = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
......@@ -2461,6 +2470,7 @@ public class EyesisCorrectionParameters {
public boolean show_filter_scan = false; // show 'FilterScan'
public boolean show_combined = false; // show 'combo_scan' (combined multiple scans)
public boolean show_unique = false; // show 'unique_scan' (removed already measured tiles with the same disparity)
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_retry_far = false; // show debug images related to retrying far tiles near foreground
......@@ -2614,6 +2624,11 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"ex_strength", this.ex_strength +"");
properties.setProperty(prefix+"ex_nstrength", this.ex_nstrength +"");
properties.setProperty(prefix+"pt_super_trust", this.pt_super_trust +"");
properties.setProperty(prefix+"pt_keep_raw_fg", this.pt_keep_raw_fg+"");
properties.setProperty(prefix+"pt_scale_pre", this.pt_scale_pre +"");
properties.setProperty(prefix+"pt_scale_post", this.pt_scale_post +"");
properties.setProperty(prefix+"bgnd_sure", this.bgnd_sure +"");
properties.setProperty(prefix+"bgnd_maybe", this.bgnd_maybe +"");
properties.setProperty(prefix+"min_clstr_seed", this.min_clstr_seed+"");
......@@ -2660,6 +2675,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"max_clusters", this.max_clusters+"");
properties.setProperty(prefix+"remove_scans", this.remove_scans+"");
properties.setProperty(prefix+"correct_distortions",this.correct_distortions+"");
properties.setProperty(prefix+"show_triangles", this.show_triangles+"");
properties.setProperty(prefix+"avg_cluster_disp", this.avg_cluster_disp+"");
......@@ -2718,6 +2734,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"stSmplSide", this.stSmplSide+"");
properties.setProperty(prefix+"stSmplNum", this.stSmplNum+"");
properties.setProperty(prefix+"stSmplRms", this.stSmplRms +"");
properties.setProperty(prefix+"stSmplWnd", this.stSmplWnd+"");
properties.setProperty(prefix+"stGrowSel", this.stGrowSel+"");
properties.setProperty(prefix+"stMeasSel", this.stMeasSel+"");
......@@ -2969,6 +2986,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"show_filter_scan", this.show_filter_scan+"");
properties.setProperty(prefix+"show_combined", this.show_combined+"");
properties.setProperty(prefix+"show_unique", this.show_unique+"");
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_retry_far", this.show_retry_far+"");
......@@ -3123,6 +3141,11 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"ex_strength")!=null) this.ex_strength=Double.parseDouble(properties.getProperty(prefix+"ex_strength"));
if (properties.getProperty(prefix+"ex_nstrength")!=null) this.ex_nstrength=Double.parseDouble(properties.getProperty(prefix+"ex_nstrength"));
if (properties.getProperty(prefix+"pt_super_trust")!=null) this.pt_super_trust=Double.parseDouble(properties.getProperty(prefix+"pt_super_trust"));
if (properties.getProperty(prefix+"pt_keep_raw_fg")!=null) this.pt_keep_raw_fg=Boolean.parseBoolean(properties.getProperty(prefix+"pt_keep_raw_fg"));
if (properties.getProperty(prefix+"pt_scale_pre")!=null) this.pt_scale_pre=Double.parseDouble(properties.getProperty(prefix+"pt_scale_pre"));
if (properties.getProperty(prefix+"pt_scale_post")!=null) this.pt_scale_post=Double.parseDouble(properties.getProperty(prefix+"pt_scale_post"));
if (properties.getProperty(prefix+"bgnd_sure")!=null) this.bgnd_sure=Double.parseDouble(properties.getProperty(prefix+"bgnd_sure"));
if (properties.getProperty(prefix+"bgnd_maybe")!=null) this.bgnd_maybe=Double.parseDouble(properties.getProperty(prefix+"bgnd_maybe"));
if (properties.getProperty(prefix+"min_clstr_seed")!=null) this.min_clstr_seed=Integer.parseInt(properties.getProperty(prefix+"min_clstr_seed"));
......@@ -3167,6 +3190,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"poles_force_disp")!=null) this.poles_force_disp=Boolean.parseBoolean(properties.getProperty(prefix+"poles_force_disp"));
if (properties.getProperty(prefix+"max_clusters")!=null) this.max_clusters=Integer.parseInt(properties.getProperty(prefix+"max_clusters"));
if (properties.getProperty(prefix+"remove_scans")!=null) this.remove_scans=Boolean.parseBoolean(properties.getProperty(prefix+"remove_scans"));
if (properties.getProperty(prefix+"correct_distortions")!=null) this.correct_distortions=Boolean.parseBoolean(properties.getProperty(prefix+"correct_distortions"));
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"));
......@@ -3225,6 +3249,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"stSmplSide")!=null) this.stSmplSide=Integer.parseInt(properties.getProperty(prefix+"stSmplSide"));
if (properties.getProperty(prefix+"stSmplNum")!=null) this.stSmplNum=Integer.parseInt(properties.getProperty(prefix+"stSmplNum"));
if (properties.getProperty(prefix+"stSmplRms")!=null) this.stSmplRms=Double.parseDouble(properties.getProperty(prefix+"stSmplRms"));
if (properties.getProperty(prefix+"stSmplWnd")!=null) this.stSmplWnd=Boolean.parseBoolean(properties.getProperty(prefix+"stSmplWnd"));
if (properties.getProperty(prefix+"stGrowSel")!=null) this.stGrowSel=Integer.parseInt(properties.getProperty(prefix+"stGrowSel"));
if (properties.getProperty(prefix+"stMeasSel")!=null) this.stMeasSel=Integer.parseInt(properties.getProperty(prefix+"stMeasSel"));
......@@ -3478,6 +3503,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"show_filter_scan")!=null) this.show_filter_scan=Boolean.parseBoolean(properties.getProperty(prefix+"show_filter_scan"));
if (properties.getProperty(prefix+"show_combined")!=null) this.show_combined=Boolean.parseBoolean(properties.getProperty(prefix+"show_combined"));
if (properties.getProperty(prefix+"show_unique")!=null) this.show_unique=Boolean.parseBoolean(properties.getProperty(prefix+"show_unique"));
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_retry_far")!=null) this.show_retry_far=Boolean.parseBoolean(properties.getProperty(prefix+"show_retry_far"));
......@@ -3654,6 +3680,12 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Minimal 4-corr strength to trust tile", this.ex_strength, 3);
gd.addNumericField("Minimal 4-corr strength divided by channel diff for new (border) tiles", this.ex_nstrength, 3);
gd.addMessage ("********* Plates filetering when building initial z-map *********");
gd.addNumericField("If strength exceeds ex_strength * super_trust, do not apply ex_nstrength and plate_ds", this.pt_super_trust, 3);
gd.addCheckbox ("Do not replace raw tiles by the plates, if raw is closer (like poles)", this.pt_keep_raw_fg);
gd.addNumericField("Scale plates strength before comparing to raw strength", this.pt_scale_pre, 3);
gd.addNumericField("Scale plates strength when replacing raw (plates d/s data is more reliable if it exists)", this.pt_scale_post, 3);
gd.addNumericField("Minimal strength to be considered definitely background", this.bgnd_sure, 3);
gd.addNumericField("Maximal strength to ignore as non-background", this.bgnd_maybe, 3);
......@@ -3702,6 +3734,7 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Set disparity to that of the bottom of existing segment (false - use hor. disparity)",this.poles_force_disp);
gd.addNumericField("Maximal number of clusters to generate for one run", this.max_clusters, 0);
gd.addCheckbox ("Remove all unneeded scans when generating x3d output to save memory", this.remove_scans);
gd.addCheckbox ("Correct lens geometric distortions in a model (will need backdrop to be corrected too)", this.correct_distortions);
gd.addCheckbox ("Show generated triangles", this.show_triangles);
gd.addCheckbox ("Weight-average disparity for the whole cluster ", this.avg_cluster_disp);
......@@ -3763,6 +3796,7 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Sample size (side of a square)", this.stSmplSide, 0);
gd.addNumericField("Number after removing worst", this.stSmplNum, 0);
gd.addNumericField("Maximal RMS of the remaining tiles in a sample", this.stSmplRms, 6);
gd.addCheckbox ("Use window function for the samples", this.stSmplWnd);
gd.addNumericField("Grow initial selection before processing supertiles, odd - ortho. <0 - use all tiles",this.stGrowSel, 0);
gd.addNumericField("Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert",this.stMeasSel, 0);
......@@ -4026,6 +4060,7 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Show 'FilterScan'", this.show_filter_scan);
gd.addCheckbox ("Show 'combo_scan' (combined multiple scans)", this.show_combined);
gd.addCheckbox ("Show 'unique_scan' (removed already measured tiles with the same disparity)", this.show_unique);
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 debug images related to retrying far tiles near foreground", this.show_retry_far);
......@@ -4187,6 +4222,11 @@ public class EyesisCorrectionParameters {
this.ex_strength= gd.getNextNumber();
this.ex_nstrength= gd.getNextNumber();
this.pt_super_trust= gd.getNextNumber();
this.pt_keep_raw_fg= gd.getNextBoolean();
this.pt_scale_pre= gd.getNextNumber();
this.pt_scale_post= gd.getNextNumber();
this.bgnd_sure= gd.getNextNumber();
this.bgnd_maybe= gd.getNextNumber();
this.min_clstr_seed= (int) gd.getNextNumber();
......@@ -4231,6 +4271,7 @@ public class EyesisCorrectionParameters {
this.poles_force_disp= gd.getNextBoolean();
this.max_clusters= (int) gd.getNextNumber();
this.remove_scans= gd.getNextBoolean();
this.correct_distortions= gd.getNextBoolean();
this.show_triangles= gd.getNextBoolean();
this.avg_cluster_disp= gd.getNextBoolean();
......@@ -4289,6 +4330,7 @@ public class EyesisCorrectionParameters {
this.stSmplSide= (int) gd.getNextNumber();
this.stSmplNum= (int) gd.getNextNumber();
this.stSmplRms= gd.getNextNumber();
this.stSmplWnd= gd.getNextBoolean();
this.stGrowSel= (int) gd.getNextNumber();
this.stMeasSel= (int) gd.getNextNumber();
......@@ -4544,6 +4586,7 @@ public class EyesisCorrectionParameters {
this.show_filter_scan= gd.getNextBoolean(); // first on refine
this.show_combined= gd.getNextBoolean();
this.show_unique= gd.getNextBoolean();
this.show_histograms= gd.getNextBoolean();
this.show_init_refine= gd.getNextBoolean();
this.show_expand= gd.getNextBoolean();
this.show_retry_far= gd.getNextBoolean();
......
......@@ -317,14 +317,16 @@ public class LinkPlanes {
plDispNorm,
plane1);
if ((plMaxEigen != 0.0) &&
(plane1.getValue() > corr_max_eigen)){
if (debugLevel > 1) System.out.println(prefix+" plane1 is too thick ("+plane1.getValue()+" > corr_max_eigen="+corr_max_eigen+")");
// (plane1.getValue() > corr_max_eigen)){
(plane1.getNormValue() > corr_max_eigen)){
if (debugLevel > 1) System.out.println(prefix+" plane1 is too thick ("+plane1.getNormValue()+" > corr_max_eigen="+corr_max_eigen+")");
return false;
}
if ((plMaxEigen != 0.0) &&
(plane2.getValue() > corr_max_eigen)){
if (debugLevel > 1) System.out.println(prefix+" plane2 is too thick ("+plane2.getValue()+" > corr_max_eigen="+corr_max_eigen+")");
// (plane2.getValue() > corr_max_eigen)){
(plane2.getNormValue() > corr_max_eigen)){
if (debugLevel > 1) System.out.println(prefix+" plane2 is too thick ("+plane2.getNormValue()+" > corr_max_eigen="+corr_max_eigen+")");
return false;
}
......@@ -337,7 +339,8 @@ public class LinkPlanes {
true, // boolean sum_weights,
plPreferDisparity,
debugLevel - 2); // int debugLevel)
merged_ev = merged_pd.getValue();
// merged_ev = merged_pd.getValue();
merged_ev = merged_pd.getNormValue();
merged_wev = merged_pd.getWValue();
}
if (Double.isNaN(merged_ev_eq) || (!check_is_weak_only && Double.isNaN(merged_wev_eq))) {
......@@ -349,7 +352,8 @@ public class LinkPlanes {
true, // boolean sum_weights,
plPreferDisparity,
debugLevel - 2); // int debugLevel)
merged_ev_eq = merged_pd_eq.getValue();
// merged_ev_eq = merged_pd_eq.getValue();
merged_ev_eq = merged_pd_eq.getNormValue();
merged_wev_eq = merged_pd_eq.getWValue();
}
......@@ -357,8 +361,10 @@ public class LinkPlanes {
double w2 = plane2.getWeight();
double weakest = (w1 > w2) ? w2 : w1;
double this_rq_eq = mergeRQuality(
plane1.getValue(), // double L1,
plane2.getValue() , // double L2,
// plane1.getValue(), // double L1,
// plane2.getValue() , // double L2,
plane1.getNormValue(), // double L1,
plane2.getNormValue() , // double L2,
merged_ev_eq, // double L,
1.0, // double w1,
1.0, // double w2)
......@@ -382,8 +388,10 @@ public class LinkPlanes {
double this_rq = mergeRQuality(
plane1.getValue(), // double L1,
plane2.getValue() , // double L2,
// plane1.getValue(), // double L1,
// plane2.getValue() , // double L2,
plane1.getNormValue(), // double L1,
plane2.getNormValue() , // double L2,
merged_ev, // double L,
w1, // double w1,
w2, // double w2)
......@@ -423,7 +431,8 @@ public class LinkPlanes {
boolean OK_to_merge = false;
boolean notOK_to_merge = false;
// plSumThick should override weak_and_close
double sum_thick = Math.sqrt(plane1.getValue()) + Math.sqrt(plane2.getValue());
// double sum_thick = Math.sqrt(plane1.getValue()) + Math.sqrt(plane2.getValue());
double sum_thick = Math.sqrt(plane1.getNormValue()) + Math.sqrt(plane2.getNormValue());
double sum_wthick = Math.sqrt(plane1.getWValue()) + Math.sqrt(plane2.getWValue());
if (Math.sqrt(merged_ev) > plSumThick * sum_thick){
notOK_to_merge = true;
......@@ -511,7 +520,8 @@ public class LinkPlanes {
" this_wrq=" + (this_wrq) +
" this_wrq_eq=" + (this_wrq_eq) +
" w1="+w1+" w2="+w2+
" L1="+plane1.getValue()+" L2="+plane2.getValue()+
// " L1="+plane1.getValue()+" L2="+plane2.getValue()+
" L1="+plane1.getNormValue()+" L2="+plane2.getNormValue()+
" L="+merged_ev+" L_eq="+merged_ev_eq+
" L1W="+plane1.getWValue()+" L2W="+plane2.getWValue()+" LW="+merged_wev+
" L_eqW="+merged_wev_eq);
......@@ -538,7 +548,8 @@ public class LinkPlanes {
" this_wrq=" + (this_wrq) +
" this_wrq_eq=" + (this_wrq_eq) +
" w1="+w1+" w2="+w2+
" L1="+plane1.getValue()+" L2="+plane2.getValue()+
// " L1="+plane1.getValue()+" L2="+plane2.getValue()+
" L1="+plane1.getNormValue()+" L2="+plane2.getNormValue()+
" L="+merged_ev+" L_eq="+merged_ev_eq+
" L1W="+plane1.getWValue()+" L2W="+plane2.getWValue()+" LW="+merged_wev+
" L_eqW="+merged_wev_eq+
......@@ -562,7 +573,8 @@ public class LinkPlanes {
" this_wrq=" + (this_wrq) +
" this_wrq_eq=" + (this_wrq_eq) +
" w1="+w1+" w2="+w2+
" L1="+plane1.getValue()+" L2="+plane2.getValue()+
// " L1="+plane1.getValue()+" L2="+plane2.getValue()+
" L1="+plane1.getNormValue()+" L2="+plane2.getNormValue()+
" L="+merged_ev+" L_eq="+merged_ev_eq+
" L1W="+plane1.getWValue()+" L2W="+plane2.getWValue()+" LW="+merged_wev+
" L_eqW="+merged_wev_eq +
......@@ -643,7 +655,18 @@ public class LinkPlanes {
true, // boolean sum_weights,
plPreferDisparity,
debugLevel - 2); // int debugLevel)
merged_ev = merged_pd.getValue();
// merged_ev = merged_pd.getValue();
if ((merged_pd == null) || (merged_pd.getValues() == null) || (merged_pd.getWValues() == null)){
if (debugLevel > -1) {
if (merged_pd == null) {
System.out.println("getFitQualities(): merged_pd is null");
} else {
System.out.println("getFitQualities(): got null:\n"+merged_pd.toString());
}
}
return null;
}
merged_ev = merged_pd.getNormValue();
merged_wev = merged_pd.getWValue();
}
if (Double.isNaN(merged_ev_eq) || Double.isNaN(merged_wev_eq)) {
......@@ -655,30 +678,48 @@ public class LinkPlanes {
true, // boolean sum_weights,
plPreferDisparity,
debugLevel - 2); // int debugLevel)
merged_ev_eq = merged_pd_eq.getValue();
if ((merged_pd_eq == null) || (merged_pd_eq.getValues() == null) || (merged_pd_eq.getWValues() == null)){
if (debugLevel > -1) {
if (merged_pd_eq == null) {
System.out.println("getFitQualities(): merged_pd_eq is null");
} else {
System.out.println("getFitQualities(): got null:\n"+merged_pd_eq.toString());
}
}
return null;
}
// merged_ev_eq = merged_pd_eq.getValue();
merged_ev_eq = merged_pd_eq.getNormValue();
merged_wev_eq = merged_pd_eq.getWValue();
}
double w1 = plane1.getWeight();
double w2 = plane2.getWeight();
double this_rq = mergeRQuality(
plane1.getValue(), // double L1,
plane2.getValue(), // double L2,
// plane1.getValue(), // double L1,
// plane2.getValue(), // double L2,
plane1.getNormValue(), // double L1,
plane2.getNormValue(), // double L2,
merged_ev, // double L,
w1, // double w1,
w2, // double w2)
plEigenFloor);// double eigen_floor)
// if (this_rq == 0.01) System.out.println("getFitQualities(): this_rq was negative");
double this_rq_nofloor = mergeRQuality(
plane1.getValue(), // double L1,
plane2.getValue(), // double L2,
// plane1.getValue(), // double L1,
// plane2.getValue(), // double L2,
plane1.getNormValue(), // double L1,
plane2.getNormValue(), // double L2,
merged_ev, // double L,
w1, // double w1,
w2, // double w2)
0); // eigenFloor);// double eigen_floor)
// if (this_rq_nofloor == 0.01) System.out.println("getFitQualities(): this_rq_nofloor was negative");
double this_rq_eq = mergeRQuality(
plane1.getValue(), // double L1,
plane2.getValue(), // double L2,
// plane1.getValue(), // double L1,
// plane2.getValue(), // double L2,
plane1.getNormValue(), // double L1,
plane2.getNormValue(), // double L2,
merged_ev_eq, // double L,
1.0, // double w1,
1.0, // double w2)
......@@ -767,7 +808,8 @@ public class LinkPlanes {
// " this_wrq_eq_raw=" + (this_wrq_eq * (w1+w2)) +
// " this_rq_raw="+(this_rq * (w1+w2)) +
" w1="+w1+" w2="+w2+
" L1="+plane1.getValue()+" L2="+plane2.getValue()+" L="+merged_ev+
// " L1="+plane1.getValue()+" L2="+plane2.getValue()+" L="+merged_ev+
" L1="+plane1.getNormValue()+" L2="+plane2.getNormValue()+" L="+merged_ev+
" L_eq="+merged_ev_eq+
" L1W="+plane1.getWValue()+" L2W="+plane2.getWValue()+" LW="+merged_wev+
" L_eqW="+merged_wev_eq);
......@@ -862,7 +904,8 @@ public class LinkPlanes {
if (merged_pd !=null) { // now always, but may add later
/// merged_pd.scaleWeight(0.5);
this_plane.setNeibMatch (dir, np, merged_pd.getValue()); // smallest eigenValue
// this_plane.setNeibMatch (dir, np, merged_pd.getValue()); // smallest eigenValue
this_plane.setNeibMatch (dir, np, merged_pd.getNormValue()); // smallest eigenValue
this_plane.setNeibWMatch(dir, np, merged_pd.getWValue()); // smallest eigenValue
}
if (dl > 1){
......@@ -879,7 +922,8 @@ public class LinkPlanes {
if (merged_pd !=null) { // now always, but may add later
/// merged_pd.scaleWeight(0.5);
this_plane.setNeibMatchEq (dir, np, merged_pd.getValue()); // smallest eigenValue
// this_plane.setNeibMatchEq (dir, np, merged_pd.getValue()); // smallest eigenValue
this_plane.setNeibMatchEq (dir, np, merged_pd.getNormValue()); // smallest eigenValue
this_plane.setNeibWMatchEq(dir, np, merged_pd.getWValue()); // smallest eigenValue
}
if (dl > 1){
......@@ -1499,7 +1543,8 @@ public class LinkPlanes {
neibs_pd[dir], // neighbor, previous value
debugLevel - 2); // debugLevel);
// if (dl > 0) dbg_img[ 2 + dir] = other_plane.getSinglePlaneDisparity(false);
if ((other_plane != null) && ((other_plane.getValue() <= maxValue) || (maxValue == 0))) { // TODO:
// if ((other_plane != null) && ((other_plane.getValue() <= maxValue) || (maxValue == 0))) { // TODO:
if ((other_plane != null) && ((other_plane.getNormValue() <= maxValue) || (maxValue == 0))) { // TODO:
if (this_new_plane.getWeight() > 0.0){
this_new_plane = this_new_plane.mergePlaneToThis(
other_plane, // PlaneData otherPd,
......@@ -1542,7 +1587,8 @@ public class LinkPlanes {
if ( (center_weight > 0.0) &&
((center_pd.getValue() < maxValue) || (maxValue == 0) ||
// ((center_pd.getValue() < maxValue) || (maxValue == 0) ||
((center_pd.getNormValue() < maxValue) || (maxValue == 0) ||
(this_new_plane == null) || (this_new_plane.getWeight() == 0.0)) // keep measured if impossible to merge
){
......@@ -2308,12 +2354,14 @@ public class LinkPlanes {
plDispNorm,
merged_pd);
if ((plMaxEigen != 0.0) &&
(merged_pd.getValue() > corr_max_eigen)){
// (merged_pd.getValue() > corr_max_eigen)){
(merged_pd.getNormValue() > corr_max_eigen)){
valid_candidates[nsTile0][np1][np2] = false;
valid_candidates[nsTile0][np2][np1] = false;
if (debugLevel > 0){
System.out.println("keepSameTileConnections(): REMOVING pair nsTile0="+nsTile0+":"+np1+":"+np2+
" as the merge would have high eigenvalue = "+merged_pd.getValue()+" > " + corr_max_eigen);
// " as the merge would have high eigenvalue = "+merged_pd.getValue()+" > " + corr_max_eigen);
" as the merge would have high eigenvalue = "+merged_pd.getNormValue()+" > " + corr_max_eigen);
}
continue; // to the next pair
}
......@@ -3068,7 +3116,8 @@ public class LinkPlanes {
dl - 3); // int debugLevel)
if (merged_pd !=null) { // now always, but may add later
merged_ev[dir][np] = merged_pd.getValue(); // smallest eigenValue
// merged_ev[dir][np] = merged_pd.getValue(); // smallest eigenValue
merged_ev[dir][np] = merged_pd.getNormValue(); // smallest eigenValue
merged_wev[dir][np] = merged_pd.getWValue(); // smallest eigenValue
if (Double.isNaN(merged_ev[dir][np]) || Double.isNaN(merged_wev[dir][np]) ){
System.out.println("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" NaN");
......@@ -3085,7 +3134,8 @@ public class LinkPlanes {
dl - 3); // int debugLevel)
if (merged_pd !=null) { // now always, but may add later
merged_ev_eq[dir][np] = merged_pd.getValue(); // smallest eigenValue
// merged_ev_eq[dir][np] = merged_pd.getValue(); // smallest eigenValue
merged_ev_eq[dir][np] = merged_pd.getNormValue(); // smallest eigenValue
merged_wev_eq[dir][np] = merged_pd.getWValue(); // smallest eigenValue
if (Double.isNaN(merged_ev_eq[dir][np]) || Double.isNaN(merged_wev_eq[dir][np]) ){
System.out.println("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" NaN2");
......@@ -4082,7 +4132,8 @@ public class LinkPlanes {
mod_planes[nsTile][neibs[dir]], // neighbor, previous value
dl - 1); // debugLevel);
if (dl > 0) dbg_img[ 2 + dir] = other_plane.getSinglePlaneDisparity(false);
if ((other_plane != null) && ((other_plane.getValue() <= plMaxEigen) || (plMaxEigen == 0))) { // TODO:
// if ((other_plane != null) && ((other_plane.getValue() <= plMaxEigen) || (plMaxEigen == 0))) { // TODO:
if ((other_plane != null) && ((other_plane.getNormValue() <= plMaxEigen) || (plMaxEigen == 0))) { // TODO:
if (this_new_plane.getWeight() > 0.0){
this_new_plane = this_new_plane.mergePlaneToThis(
other_plane, // PlaneData otherPd,
......@@ -4132,7 +4183,8 @@ public class LinkPlanes {
(measured_planes[nsTile0] != null) &&
(measured_planes[nsTile0][np0] != null) &&
// ((measured_planes[nsTile0][np0].getValue() < plMaxEigen) || (plMaxEigen == 0))
((measured_planes[nsTile0][np0].getValue() < plMaxEigen) || (plMaxEigen == 0) ||
// ((measured_planes[nsTile0][np0].getValue() < plMaxEigen) || (plMaxEigen == 0) ||
((measured_planes[nsTile0][np0].getNormValue() < plMaxEigen) || (plMaxEigen == 0) ||
(this_new_plane == null) || (this_new_plane.getWeight() == 0.0)) // keep measured if impossible to merge
){ // merge with "measured"
......@@ -4163,7 +4215,8 @@ public class LinkPlanes {
this_new_plane.setNumPoints((int) (this_new_plane.getNumPoints()/true_num_merged));
}
// Revert if the result value is higher than imposed maximum
if ((this_new_plane.getValue() > plMaxEigen) && (plMaxEigen != 0)){ // TODO: Set more relaxed here?
// if ((this_new_plane.getValue() > plMaxEigen) && (plMaxEigen != 0)){ // TODO: Set more relaxed here?
if ((this_new_plane.getNormValue() > plMaxEigen) && (plMaxEigen != 0)){ // TODO: Set more relaxed here?
if (dl > 0){
System.out.println("planesSmoothStep nsTile0="+nsTile0+" smoothed plane is too thick, using previous one");
dbg_img = new double [titles.length][];
......@@ -4208,10 +4261,13 @@ public class LinkPlanes {
" num_merged="+num_merged + " rms = "+s+
" new_weight = "+new_planes[nsTile0][np0].getWeight()+
" old_weight = "+mod_planes[nsTile0][np0].getWeight()+
" new_value = "+new_planes[nsTile0][np0].getValue()+
" old_value = "+mod_planes[nsTile0][np0].getValue()+
" (new_value) = "+new_planes[nsTile0][np0].getValue()+
" (old_value) = "+mod_planes[nsTile0][np0].getValue()+
" new_norm_value = "+new_planes[nsTile0][np0].getNormValue()+
" old_norm_value = "+mod_planes[nsTile0][np0].getNormValue()+
" measured_weight = "+measured_planes[nsTile0][np0].getWeight()+
" measured_value = "+measured_planes[nsTile0][np0].getValue());
" (measured_value) = "+measured_planes[nsTile0][np0].getValue()+
" measured_norm_value = "+measured_planes[nsTile0][np0].getNormValue());
}
}
......
......@@ -331,6 +331,23 @@ public class MeasuredLayers {
return weights;
}
/**
* Get window function for tile samples (currently just 3x3) in a line-scan order
* @param smplSide square sample side
* @return [smplSide * smplSide]array of weights, 1.0 in the center
*/
public double [] getSampleWindow(int smplSide, boolean all1){
double [] weights = new double [smplSide * smplSide];
for (int sy = 0; sy < smplSide; sy++){
for (int sx = 0; sx < smplSide; sx++){
weights[sy * smplSide + sx] = all1? 1.0 : Math.sin(Math.PI*(sy+0.5)/smplSide) * Math.sin(Math.PI*(sx+0.5)/smplSide);
}
}
return weights;
}
/**
* Get selection for the specific measurement layer and supertile X,Y coordinates
......@@ -662,8 +679,211 @@ public class MeasuredLayers {
* @param smplNum number of averaged samples (should be <= smplSide * smplSide and > 1)
* @param smplRms maximal square root of variance (in disparity pixels) to accept the result
* @param null_if_none return null if there are no usable tiles in the result
* @param smplWnd multiply samples weights by a window function
* @param debugLevel debug level
* @return a pair of arrays (disparity and strengths) in line-scan order each
*/
public double[][] getDisparityStrength_old (
int num_layer,
int stX,
int stY,
boolean [] sel_in,
double strength_floor,
double strength_pow,
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst (should be >1)
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, //
boolean null_if_none,
int debugLevel)
{
if ((layers[num_layer] == null) && null_if_none){
return null;
}
int st2 = 2 * superTileSize;
int st_half = superTileSize/2;
double [][] ds = new double [2][st2*st2];
final int dbg_tile = ((stX == 22) && (stY == 19)) ? (5 + 7*16) : -1;// 50397;
int num_selected = 0;
int smpl_center = smplSide /2;
int st2e = st2 + smplSide;
int smplLen = smplSide*smplSide;
final double [] smpl_weights = getSampleWindow(smplSide, !smplWnd);
double [] disp = new double [st2e * st2e];
double [] weight = new double [st2e * st2e];
int st_halfe = st_half + smpl_center;
double smplVar = smplRms * smplRms; // maximal variance (weighted average of the squared difference from the mean)
if (layers[num_layer] != null) {
for (int dy = 0; dy < st2e; dy ++){
int y = superTileSize * stY -st_halfe + dy;
if ((y >= 0) && (y < tilesY)) {
for (int dx = 0; dx < st2e; dx ++){
int x = superTileSize * stX -st_halfe + dx;
if ((x >= 0) && (x < tilesX)) {
int indx = y * tilesX + x;
int indx_ste = dy * st2e + dx;
if (layers[num_layer][indx] != null){ // apply sel_in later
disp[indx_ste] = layers[num_layer][indx].getDisparity();
double w = layers[num_layer][indx].getStrength() - strength_floor;
if (w > 0) {
if (strength_pow != 1.0) w = Math.pow(w, strength_pow);
// w *= lapWeight[dy][dx];
disp[indx_ste] = layers[num_layer][indx].getDisparity();
weight[indx_ste] = w;
num_selected ++;
}
}
}
}
}
}
}
if (null_if_none && (num_selected == 0)) return null;
// now work with disp, strength [st2e*st2de] and filter results to ds[2][st2*st2], applying sel_in
num_selected = 0;
for (int dy = 0; dy < st2; dy ++){
for (int dx = 0; dx < st2; dx ++){
int indx = dy * st2 + dx;
if (indx == dbg_tile){
System.out.println("getDisparityStrength(): stX="+stX+" stY="+stY+" dx="+dx+" dy="+dy);
}
if (((sel_in == null) || sel_in[indx])){
int num_in_sample = 0;
double sum_wnd = 0.0;
boolean [] smpl_sel = new boolean [smplLen];
double [] smpl_d = new double [smplLen];
double [] smpl_w = new double [smplLen];
for (int sy = 0; sy < smplSide; sy++){
int y = dy + sy; // - smpl_center;
for (int sx = 0; sx < smplSide; sx++){
int x = dx + sx; // - smpl_center;
int indxe = y * st2e + x;
if (weight[indxe] > 0.0){
int indxs = sy * smplSide + sx;
smpl_sel[indxs] = true;
smpl_d[indxs] = disp[indxe];
smpl_w[indxs] = weight[indxe] * smpl_weights[indxs];
sum_wnd += smpl_weights[indxs];
num_in_sample ++;
}
}
}
if (num_in_sample >= smplNum){ // try, remove worst
// calculate
double sd=0.0, sd2 = 0.0, sw = 0.0;
for (int i = 0; i < smplLen; i++) if (smpl_sel[i]) {
double dw = smpl_d[i] * smpl_w[i];
sd += dw;
sd2 += dw * smpl_d[i];
sw += smpl_w[i];
}
// remove worst, update sd2, sd and sw
while ((num_in_sample > smplNum) && (sw > 0)){ // try, remove worst
double d_mean = sd/sw;
int iworst = -1;
double dworst2 = 0.0;
for (int i = 0; i < smplLen; i++) if (smpl_sel[i]) {
double d2 = (smpl_d[i] - d_mean);
d2 *=d2;
if (d2 > dworst2) {
iworst = i;
dworst2 = d2;
}
}
if (iworst < 0){
System.out.println("**** this is a BUG in getDisparityStrength() ****");
break;
}
// remove worst sample
smpl_sel[iworst] = false;
double dw = smpl_d[iworst] * smpl_w[iworst];
sd -= dw;
sd2 -= dw * smpl_d[iworst];
sw -= smpl_w[iworst];
sum_wnd -= smpl_weights[iworst];
num_in_sample --;
}
// calculate variance of the remaining set
if (sw > 0.0) {
sd /= sw;
sd2 /= sw;
double var = sd2 - sd * sd;
if (var < smplVar) { // good, save in the result array
ds[0][indx] = sd;
// ds[1][indx] = sw * lapWeight[dy][dx] /num_in_sample; // average weights, multiply by window //** TODO: change
ds[1][indx] = sw * lapWeight[dy][dx] /sum_wnd; // average weights, multiply by window //** TODO: change
}
} else {
num_in_sample = 0;
System.out.println("**** this is a BUG in getDisparityStrength(), shoud not happen ? ****");
}
}
}
}
}
return ds;
}
/**
* Verify that selected points are not all on the same line
* @param sel 2-d sample selection in linescan order
* @param side square samples side
* @return true if there are enough samples for plane extraction, false otherwise
*/
public boolean notColinear (
boolean [] sel,
int side)
{
int indx0, indx1;
for (indx0 = 0; indx0 < sel.length; indx0++){
if (sel[indx0]) break;
}
for (indx1 = indx0+1; indx1 < sel.length; indx1++){
if (sel[indx1]) break;
}
if (indx1 >= sel.length) return false; // too few points;
int sx0 = indx0 % side;
int sy0 = indx0 / side;
int sx1 = indx1 % side;
int sy1 = indx1 / side;
for (int indx = indx1 +1; indx < sel.length; indx++){
int sx = indx % side;
int sy = indx / side;
if ((sx - sx0) * (sy - sy1) != (sx - sx1) * (sy - sy0)){
return true;
}
}
return false;
}
/**
* Verify that selected points are not all on the same line, even if the specified one is removed
* @param indx index of the point to be removed
* @param sel 2-d sample selection in linescan order
* @param side square samples side
* @return true if there are enough samples for plane extraction, false otherwise
*/
public boolean notColinearWithout (
int indx,
boolean [] sel,
int side)
{
if (!sel[indx]){
throw new IllegalArgumentException ("notCoplanarWithout(): specified is the non existing index");
}
sel[indx] = false;
boolean rslt = notColinear ( sel, side);
sel[indx] = true;
return rslt;
}
// testing - redirecting all existing requests to this one with floating planes
public double[][] getDisparityStrength (
int num_layer,
int stX,
......@@ -674,22 +894,69 @@ public class MeasuredLayers {
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst (should be >1)
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean null_if_none)
boolean smplWnd, //
boolean null_if_none,
int debugLevel)
{
return getDisparityStrength (
num_layer, // int num_layer,
stX, // int stX,
stY, // int stY,
sel_in, // boolean [] sel_in,
null, // double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
strength_floor, // double strength_floor,
strength_pow, // double strength_pow,
smplSide, // int smplSide, // = 2; // Sample size (side of a square)
smplNum, // int smplNum, // = 3; // Number after removing worst (should be >1)
smplRms, // double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // boolean smplWnd, //
2.0, // double max_abs_tilt, // = 2.0; // pix per tile
0.2, // double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
null_if_none, // boolean null_if_none,
debugLevel); // int debugLevel)
}
public double[][] getDisparityStrength (
int num_layer,
int stX,
int stY,
boolean [] sel_in,
double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
double strength_floor,
double strength_pow,
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst (should be >1)
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, //
double max_abs_tilt, // = 2.0; // pix per tile
double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
boolean null_if_none,
int debugLevel)
{
if ((layers[num_layer] == null) && null_if_none){
return null;
}
int st2 = 2 * superTileSize;
int st_half = superTileSize/2;
double [][] ds = new double [2][st2*st2];
final int dbg_tile = ((stX == 22) && (stY == 19)) ? (5 + 7*16) : -1;// 50397;
int num_selected = 0;
int smpl_center = smplSide /2;
double smpl_dcenter = (smplSide -1.0) /2;
int st2e = st2 + smplSide;
int smplLen = smplSide*smplSide;
final double [] smpl_weights = getSampleWindow(smplSide, !smplWnd);
double [] disp = new double [st2e * st2e];
double [] weight = new double [st2e * st2e];
int st_halfe = st_half + smpl_center;
double smlVar = smplRms * smplRms; // maximal variance (weighted average of the squared difference from the mean)
double smplVar = smplRms * smplRms; // maximal variance (weighted average of the squared difference from the mean)
PolynomialApproximation pa = new PolynomialApproximation();
double thresholdLin = 1.0E-20; // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
double thresholdQuad = 1.0E-30; // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
if (layers[num_layer] != null) {
for (int dy = 0; dy < st2e; dy ++){
......@@ -700,6 +967,7 @@ public class MeasuredLayers {
if ((x >= 0) && (x < tilesX)) {
int indx = y * tilesX + x;
int indx_ste = dy * st2e + dx;
if (layers[num_layer][indx] != null){ // apply sel_in later
disp[indx_ste] = layers[num_layer][indx].getDisparity();
double w = layers[num_layer][indx].getStrength() - strength_floor;
......@@ -722,10 +990,15 @@ public class MeasuredLayers {
for (int dy = 0; dy < st2; dy ++){
for (int dx = 0; dx < st2; dx ++){
int indx = dy * st2 + dx;
if (indx == dbg_tile){
System.out.println("getDisparityStrength(): stX="+stX+" stY="+stY+" dx="+dx+" dy="+dy);
}
if (((sel_in == null) || sel_in[indx])){
int num_in_sample = 0;
double sum_wnd = 0.0;
boolean [] smpl_sel = new boolean [smplLen];
double [] smpl_d = new double [smplLen];
double [] smpl_p = new double [smplLen];
double [] smpl_w = new double [smplLen];
for (int sy = 0; sy < smplSide; sy++){
int y = dy + sy; // - smpl_center;
......@@ -736,12 +1009,167 @@ public class MeasuredLayers {
int indxs = sy * smplSide + sx;
smpl_sel[indxs] = true;
smpl_d[indxs] = disp[indxe];
smpl_w[indxs] = weight[indxe];
smpl_w[indxs] = weight[indxe] * smpl_weights[indxs];
sum_wnd += smpl_weights[indxs];
num_in_sample ++;
}
}
}
if (num_in_sample >= smplNum){ // try, remove worst
sample_loop:
{
boolean en_tilt = (tiltXY == null);
if (en_tilt) { // make sure there are enough samples and not all of them are on the same line
if (!notColinear(smpl_sel,smplSide)){
en_tilt = false;
}
}
if (en_tilt) { // enable floating tilt
double sd2 = 0.0, d_center = 0.0, sw = 0.0;
// TODO: making simple - recalculate after removing. Can be done more efficient.
while (num_in_sample >= smplNum) { // try, remove worst
sd2 = 0.0;
d_center = 0.0;
sw = 0.0;
double [][][] mdata = new double [num_in_sample][3][];
int mindx = 0;
for (int sy = 0; sy < smplSide; sy++){
for (int sx = 0; sx < smplSide; sx++){
int indxs = sy * smplSide + sx;
if (smpl_sel[indxs]) {
mdata[mindx][0] = new double [2];
mdata[mindx][0][0] = sx - smpl_dcenter;
mdata[mindx][0][1] = sy - smpl_dcenter;
mdata[mindx][1] = new double [1];
mdata[mindx][1][0] = smpl_d[indxs];
mdata[mindx][2] = new double [1];
mdata[mindx][2][0] = smpl_w[indxs];
mindx ++;
}
}
}
double[][] approx2d = pa.quadraticApproximation(
mdata,
true, // boolean forceLinear, // use linear approximation
thresholdLin, // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
thresholdQuad, // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
debugLevel);
if (approx2d == null){
if (debugLevel > -1){
System.out.println("getDisparityStrength(): can not find linear approximation");
}
break sample_loop;
}
// limit tilt to be within range
// double max_abs_tilt, // = 2.0; // pix per tile
// double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
double max_tilt = Math.min(max_abs_tilt, max_rel_tilt * approx2d[0][2]);
boolean overlimit = (Math.abs(approx2d[0][0]) > max_tilt) || (Math.abs(approx2d[0][1]) > max_tilt);
if (overlimit) {
approx2d[0][0] = Math.min(approx2d[0][0], max_tilt);
approx2d[0][1] = Math.min(approx2d[0][1], max_tilt);
approx2d[0][0] = Math.max(approx2d[0][0], -max_tilt);
approx2d[0][1] = Math.max(approx2d[0][1], -max_tilt);
}
// subtract tilt from disparity
for (int sy = 0; sy < smplSide; sy++){
for (int sx = 0; sx < smplSide; sx++){
int indxs = sy * smplSide + sx;
if (smpl_sel[indxs]) {
smpl_p[indxs] = approx2d[0][0] * (sx - smpl_dcenter) + approx2d[0][1] * (sy - smpl_dcenter) + approx2d[0][2];
}
}
}
if (overlimit){ // re-calculate disparity average (in the center)
double sd=0.0;
for (int indxs = 0; indxs < smplLen;indxs++) if (smpl_sel[indxs]) {
double d = smpl_d[indxs] - smpl_p[indxs];
double dw = d * smpl_w[indxs];
sd += dw;
sw += smpl_w[indxs];
}
sd /= sw;
for (int indxs = 0; indxs < smplLen;indxs++) if (smpl_sel[indxs]) {
smpl_p[indxs] += sd;
}
approx2d[0][2] += sd;
}
d_center = approx2d[0][2];
sw = 0.0;
for (int indxs = 0; indxs < smplLen;indxs++) if (smpl_sel[indxs]) {
double d = smpl_d[indxs] - smpl_p[indxs];
double dw = d * smpl_w[indxs];
// sd += dw;
sd2 += dw * smpl_d[indxs];
sw += smpl_w[indxs];
}
// remove worst - it should not make remaining set
if (num_in_sample > smplNum) { // remove worst if it is not the last run where only calculations are needed
// double d_mean = sd/sw;
int iworst = -1;
double dworst2 = 0.0;
for (int indxs = 0; indxs < smplLen; indxs++) if (smpl_sel[indxs]) {
// double d2 = (smpl_d[i] - d_mean);
double d2 = smpl_d[indxs] - smpl_p[indxs];
d2 *=d2;
if (d2 > dworst2) {
if (notColinearWithout (
indxs, // int indx,
smpl_sel, // boolean [] sel,
smplSide)) { // int side))
iworst = indxs;
dworst2 = d2;
}
}
}
if (iworst < 0){
System.out.println("**** this is a BUG in getDisparityStrength() can not find the worst sample ****");
break;
}
// remove worst sample
smpl_sel[iworst] = false;
// double dw = smpl_d[iworst] * smpl_w[iworst];
// sd -= dw;
// sd2 -= dw * smpl_d[iworst];
// sw -= smpl_w[iworst];
sum_wnd -= smpl_weights[iworst];
num_in_sample --;
} else {
break;
}
} // removing worst tiles, all done,
// calculate variance of the remaining set
if (sw > 0.0) {
// sd /= sw;
// sd2 /= sw;
double var = sd2/sw; // - sd * sd;
if (var < smplVar) { // good, save in the result array
ds[0][indx] = d_center;
// ds[1][indx] = sw * lapWeight[dy][dx] /num_in_sample; // average weights, multiply by window //** TODO: change
ds[1][indx] = sw * lapWeight[dy][dx] /sum_wnd; // average weights, multiply by window //** TODO: change
}
}
} else { // fixed tilt
// tilt around center
if ((tiltXY != null) && (tiltXY[0] != 0.0) && (tiltXY[1] != 0.0)){
for (int sy = 0; sy < smplSide; sy++){
for (int sx = 0; sx < smplSide; sx++){
int indxs = sy * smplSide + sx;
if (smpl_w[indxs] > 0.0) {
smpl_d[indxs] -= tiltXY[0]* (sx - smpl_dcenter) + tiltXY[1]* (sy - smpl_dcenter);
}
}
}
}
// calculate
double sd=0.0, sd2 = 0.0, sw = 0.0;
for (int i = 0; i < smplLen; i++) if (smpl_sel[i]) {
......@@ -773,6 +1201,7 @@ public class MeasuredLayers {
sd -= dw;
sd2 -= dw * smpl_d[iworst];
sw -= smpl_w[iworst];
sum_wnd -= smpl_weights[iworst];
num_in_sample --;
}
// calculate variance of the remaining set
......@@ -780,9 +1209,10 @@ public class MeasuredLayers {
sd /= sw;
sd2 /= sw;
double var = sd2 - sd * sd;
if (var < smlVar) { // good, save in the result array
if (var < smplVar) { // good, save in the result array
ds[0][indx] = sd;
ds[1][indx] = sw * lapWeight[dy][dx] /num_in_sample; // average weights, multiply by window
// ds[1][indx] = sw * lapWeight[dy][dx] /num_in_sample; // average weights, multiply by window //** TODO: change
ds[1][indx] = sw * lapWeight[dy][dx] /sum_wnd; // average weights, multiply by window //** TODO: change
}
} else {
num_in_sample = 0;
......@@ -791,11 +1221,20 @@ public class MeasuredLayers {
}
}
}
}
}
}
return ds;
}
public void growSelection(
int grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
boolean [] tiles,
......
......@@ -3864,310 +3864,6 @@ public class QuadCLT {
}
/*
public double [][][] fine_geometry_correction_old(
EyesisCorrectionParameters.CLTParameters clt_parameters,
double [][] disparity_map,
double [][] clt_mismatch,
int tilesX,
double magic_coeff, // still not understood coefficent that reduces reported disparity value. Seems to be around 8.5
int debugLevel)
{
// TODO: update the following indices when format of the arrays will change (removed unneeded data)
final int index_disparity = ImageDtt.DISPARITY_INDEX_CM; // 2; // "cm_disparity"
final int index_strength = ImageDtt.DISPARITY_STRENGTH_INDEX; //6; // "strength"
final int [] indices_mismatch = {1,4,6,9}; // "dy0", "dy1", "dx2", "dx3"
final int numTiles = disparity_map[0].length;
final int tilesY = numTiles/tilesX;
int numUsed = 0;
for (int i = 0; i < numTiles; i++) {
if ((disparity_map[index_strength][i] >= clt_parameters.fcorr_min_strength) &&
(Math.abs(disparity_map[index_disparity][i]) <= clt_parameters.fcorr_disp_diff)) numUsed ++;
}
double [][][] mdata = new double[numUsed][3][];
int indx = 0;
for (int i = 0; i < numTiles; i++) {
if ((disparity_map[index_strength][i] >= clt_parameters.fcorr_min_strength) &&
(Math.abs(disparity_map[index_disparity][i]) <= clt_parameters.fcorr_disp_diff)) {
int tileX = i % tilesX;
int tileY = i / tilesX;
mdata[indx][0] = new double [2];
mdata[indx][0][0] = (2.0 * tileX)/tilesX - 1.0; // -1.0 to +1.0;
mdata[indx][0][1] = (2.0 * tileY)/tilesY - 1.0; // -1.0 to +1.0
mdata[indx][1] = new double [indices_mismatch.length]; // 4
for (int ip = 0; ip < indices_mismatch.length; ip++) {
mdata[indx][1][ip] = clt_mismatch[indices_mismatch[ip]][i];
}
mdata[indx][2] = new double [1];
mdata[indx][2][0] = disparity_map[index_strength][i];
indx ++;
}
}
PolynomialApproximation pa = new PolynomialApproximation();
double thresholdLin = 1.0E-20; // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
double thresholdQuad = 1.0E-30; // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
/*
* returns array of vectors or null
* each vector (one per each z component) is either 6-element- (A,B,C,D,E,F) if quadratic is possible and enabled
* or 3-element - (D,E,F) if linear is possible and quadratic is not possible or disabled
* returns null if not enough data even for the linear approximation
*/
/*
double [][] coeffs = pa.quadraticApproximation(
mdata,
!clt_parameters.fcorr_quadratic, // boolean forceLinear, // use linear approximation
thresholdLin, // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
thresholdQuad, // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
debugLevel);
for (int i = 0; i < coeffs.length; i++){
if (coeffs[i] == null){
coeffs[i] = new double [6];
for (int j = 0; j < coeffs[i].length; i++) coeffs[i][j] = 0.0;
} else if (coeffs[i].length < 6){
double [] short_coeffs = coeffs[i];
coeffs[i] = new double [6];
for (int j = 0; j < coeffs[i].length; j++) {
if (j < (coeffs[i].length - short_coeffs.length)) coeffs[i][j] = 0.0;
else coeffs[i][j] = short_coeffs[j - (coeffs[i].length - short_coeffs.length)];
}
}
}
// convert to 8 sets of coefficient for px0, py0, px1, py1, ... py3.
double [][][] coeff_full = new double [4][2][6];
double scale = 0.5/magic_coeff;
for (int j = 0; j<6; j++){
coeff_full[0][0][j] = -coeffs[2][j] * scale;
coeff_full[0][1][j] = -coeffs[0][j] * scale;
coeff_full[1][0][j] = -coeffs[3][j] * scale;
coeff_full[1][1][j] = coeffs[0][j] * scale;
coeff_full[2][0][j] = coeffs[2][j] * scale;
coeff_full[2][1][j] = -coeffs[1][j] * scale;
coeff_full[3][0][j] = coeffs[3][j] * scale;
coeff_full[3][1][j] = coeffs[1][j] * scale;
}
if (debugLevel > -1){
int tilesX8 = (tilesX - 1) / 8 + 1;
int tilesY8 = (tilesY - 1) / 8 + 1;
int len8 = tilesX8*tilesY8;
double [][] mismatch_8 = new double[11][len8];
for (int i = 0; i < numTiles; i++) {
if ((disparity_map[index_strength][i] >= clt_parameters.fcorr_min_strength) &&
(Math.abs(disparity_map[index_disparity][i]) <= clt_parameters.fcorr_disp_diff)) {
int tileX = i % tilesX;
int tileY = i / tilesX;
int tX8 = tileX/8;
int tY8 = tileY/8;
int indx8 = tY8*tilesX8+tX8;
double tX = (2.0 * tileX)/tilesX - 1.0; // -1.0 to +1.0;
double tY = (2.0 * tileY)/tilesY - 1.0; // -1.0 to +1.0
double w = disparity_map[index_strength][i];
for (int ip = 0; ip < 4; ip++) {
mismatch_8[ip][indx8] += w * clt_mismatch[indices_mismatch[ip]][i];
}
mismatch_8[8][indx8] += w * tX;
mismatch_8[9][indx8] += w * tY;
mismatch_8[10][indx8] += w;
}
}
for (int i = 0; i < len8; i++) {
if (mismatch_8[10][i] > 0){
for (int n = 0; n<4; n++){
mismatch_8[n][i] /= mismatch_8[10][i];
}
mismatch_8[8][i] /= mismatch_8[10][i];
mismatch_8[9][i] /= mismatch_8[10][i];
} else {
for (int n = 0; n<4; n++){
mismatch_8[n][i] = Double.NaN;
}
mismatch_8[8][i] = Double.NaN;
mismatch_8[9][i] = Double.NaN;
}
for (int n = 0; n<4; n++){
double tX = mismatch_8[8][i];
double tY = mismatch_8[9][i];
//f(x,y)=A*x^2+B*y^2+C*x*y+D*x+E*y+F
mismatch_8[4+n][i] = (
coeffs[n][0]*tX*tX+
coeffs[n][1]*tY*tY+
coeffs[n][2]*tX*tY+
coeffs[n][3]*tX+
coeffs[n][4]*tY+
coeffs[n][5]);
}
}
String [] titles = {"dy0","dy1","dx2","dx3","cy0","cy1","cx2","cx3","tx","ty","w"};
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
sdfa_instance.showArrays(
mismatch_8,
tilesX8,
tilesY8,
true,
"mismatch_8",
titles);
}
return coeff_full;
}
// new one, pre-calculated from the disparity scan
public double [][][] fine_geometry_correction_old(
EyesisCorrectionParameters.CLTParameters clt_parameters,
double [][] clt_mismatch,
int tilesX,
double magic_coeff, // still not understood coefficent that reduces reported disparity value. Seems to be around 0.85
int debugLevel)
{
// TODO: update the following indices when format of the arrays will change (removed unneeded data)
final int [] indices_mismatch = {1,4,6,9}; // "dy0", "dy1", "dx2", "dx3"
final int numTiles = clt_mismatch[0].length;
final int tilesY = numTiles/tilesX;
int numUsed = 0;
double [] strength = new double [numTiles];
for (int i = 0; i < numTiles; i++) {
boolean all_pairs = true;
for (int nPair = 0; nPair < 4; nPair++){
double w = clt_mismatch[3 * nPair + 2][i];
if (w == 0.0) {
all_pairs = false;
strength[i] = 0.0;
break;
}
strength[i] += w;
}
if (all_pairs) numUsed ++;
}
double [][][] mdata = new double[numUsed][3][];
int indx = 0;
for (int i = 0; i < numTiles; i++) {
if (strength[i] > 0) {
int tileX = i % tilesX;
int tileY = i / tilesX;
mdata[indx][0] = new double [2];
mdata[indx][0][0] = (2.0 * tileX)/tilesX - 1.0; // -1.0 to +1.0;
mdata[indx][0][1] = (2.0 * tileY)/tilesY - 1.0; // -1.0 to +1.0
mdata[indx][1] = new double [indices_mismatch.length]; // 4
for (int ip = 0; ip < indices_mismatch.length; ip++) {
mdata[indx][1][ip] = clt_mismatch[indices_mismatch[ip]][i];
}
mdata[indx][2] = new double [1];
mdata[indx][2][0] = strength[i];
indx ++;
}
}
PolynomialApproximation pa = new PolynomialApproximation();
double thresholdLin = 1.0E-20; // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
double thresholdQuad = 1.0E-30; // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
*/
/*
* returns array of vectors or null
* each vector (one per each z component) is either 6-element- (A,B,C,D,E,F) if quadratic is possible and enabled
* or 3-element - (D,E,F) if linear is possible and quadratic is not possible or disabled
* returns null if not enough data even for the linear approximation
*/
/*
double [][] coeffs = pa.quadraticApproximation(
mdata,
!clt_parameters.fcorr_quadratic, // boolean forceLinear, // use linear approximation
thresholdLin, // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
thresholdQuad, // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
debugLevel);
for (int i = 0; i < coeffs.length; i++){
if (coeffs[i] == null){
coeffs[i] = new double [6];
for (int j = 0; j < coeffs[i].length; i++) coeffs[i][j] = 0.0;
} else if (coeffs[i].length < 6){
double [] short_coeffs = coeffs[i];
coeffs[i] = new double [6];
for (int j = 0; j < coeffs[i].length; j++) {
if (j < (coeffs[i].length - short_coeffs.length)) coeffs[i][j] = 0.0;
else coeffs[i][j] = short_coeffs[j - (coeffs[i].length - short_coeffs.length)];
}
}
}
// convert to 8 sets of coefficient for px0, py0, px1, py1, ... py3.
double [][][] coeff_full = new double [4][2][6];
double scale = 0.5/magic_coeff;
for (int j = 0; j<6; j++){
coeff_full[0][0][j] = -coeffs[2][j] * scale;
coeff_full[0][1][j] = -coeffs[0][j] * scale;
coeff_full[1][0][j] = -coeffs[3][j] * scale;
coeff_full[1][1][j] = coeffs[0][j] * scale;
coeff_full[2][0][j] = coeffs[2][j] * scale;
coeff_full[2][1][j] = -coeffs[1][j] * scale;
coeff_full[3][0][j] = coeffs[3][j] * scale;
coeff_full[3][1][j] = coeffs[1][j] * scale;
}
if (debugLevel > -1){
int tilesX8 = (tilesX - 1) / 8 + 1;
int tilesY8 = (tilesY - 1) / 8 + 1;
int len8 = tilesX8*tilesY8;
double [][] mismatch_8 = new double[11][len8];
for (int i = 0; i < numTiles; i++) {
if (strength[i] > 0) {
int tileX = i % tilesX;
int tileY = i / tilesX;
int tX8 = tileX/8;
int tY8 = tileY/8;
int indx8 = tY8*tilesX8+tX8;
double tX = (2.0 * tileX)/tilesX - 1.0; // -1.0 to +1.0;
double tY = (2.0 * tileY)/tilesY - 1.0; // -1.0 to +1.0
double w = strength[i];
for (int ip = 0; ip < 4; ip++) {
mismatch_8[ip][indx8] += w * clt_mismatch[indices_mismatch[ip]][i];
}
mismatch_8[8][indx8] += w * tX;
mismatch_8[9][indx8] += w * tY;
mismatch_8[10][indx8] += w;
}
}
for (int i = 0; i < len8; i++) {
if (mismatch_8[10][i] > 0){
for (int n = 0; n<4; n++){
mismatch_8[n][i] /= mismatch_8[10][i];
}
mismatch_8[8][i] /= mismatch_8[10][i];
mismatch_8[9][i] /= mismatch_8[10][i];
} else {
for (int n = 0; n<4; n++){
mismatch_8[n][i] = Double.NaN;
}
mismatch_8[8][i] = Double.NaN;
mismatch_8[9][i] = Double.NaN;
}
for (int n = 0; n<4; n++){
double tX = mismatch_8[8][i];
double tY = mismatch_8[9][i];
//f(x,y)=A*x^2+B*y^2+C*x*y+D*x+E*y+F
mismatch_8[4+n][i] = (
coeffs[n][0]*tX*tX+
coeffs[n][1]*tY*tY+
coeffs[n][2]*tX*tY+
coeffs[n][3]*tX+
coeffs[n][4]*tY+
coeffs[n][5]);
}
}
String [] titles = {"dy0","dy1","dx2","dx3","cy0","cy1","cx2","cx3","tx","ty","w"};
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
sdfa_instance.showArrays(
mismatch_8,
tilesX8,
tilesY8,
true,
"mismatch_8",
titles);
}
return coeff_full;
}
*/
/**
* Calculate quadratic polynomials for each subcamera X/Y correction to match disparity = 0 at infinity
* Next parameters are made separate to be able to modify them between different runs keeping clt_parameters
......@@ -4264,6 +3960,7 @@ public class QuadCLT {
mdata[indx][0][1] = (2.0 * tileY)/tilesY - 1.0; // -1.0 to +1.0
mdata[indx][1] = new double [1];
mdata[indx][1][0] = (disp_strength[2 * s.series + 0][s.tile]/magic_coeff - disp_surface[s.tile]); // disparity residual
mdata[indx][2] = new double [1];
mdata[indx][2][0] = s.weight; // disp_strength[2 * s.series + 1][s.tile]; // strength
// if (Math.abs( mdata[indx][1][0]) > max_diff) { // far tiles
// mdata[indx][2][0] *= far_pull;
......@@ -6006,6 +5703,21 @@ public class QuadCLT {
final int debugLevel)
{
final int max_expand = 100; // 30;
// Temporary assign here
final int disp_index = ImageDtt.DISPARITY_INDEX_CM;
final int str_index = ImageDtt.DISPARITY_STRENGTH_INDEX;
final double strength_floor = 0.8* clt_parameters.combine_min_strength;
final double strength_pow = 1.0;
final int smplSide = 5; // 3; // Sample size (side of a square)
final int smplNum = 13; // 5; // Number after removing worst (should be >1)
final double smplRms = 0.15; // 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd = true; //
final double max_abs_tilt = 2.0; // pix per tile
final double max_rel_tilt = 0.2; // (pix / disparity) per tile
final int dbg_x = 0;
final int dbg_y = 0;
// final double scale_filtered_strength = 2.5;
// final double reliable_raw_strength=0.25;
final boolean show_init_refine = clt_parameters.show_init_refine;
final boolean show_expand = clt_parameters.show_expand && (max_expand <= 10);
......@@ -6035,6 +5747,7 @@ public class QuadCLT {
tp.setTrustedCorrelation(clt_parameters.grow_disp_trust);
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
final double trustedCorrelation = tp.getTrustedCorrelation();
/// CLTPass3d bgnd_data = CLTBackgroundMeas( // measure background
......@@ -6045,6 +5758,63 @@ public class QuadCLT {
updateStatus,
debugLevel);
tp.clt_3d_passes.add(bgnd_data);
// if (show_init_refine)
tp.showScan(
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.size() - 1, // final int measured_scan_index, // will not look at higher scans
0, // final int start_scan_index,
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
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);
}
ImagePlus imp_bgnd = getBackgroundImage(
clt_parameters,
......@@ -6096,6 +5866,13 @@ public class QuadCLT {
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
......@@ -6170,8 +5947,33 @@ public class QuadCLT {
boolean last_pass = false;
// for (int num_expand = 0; (num_expand < 4) && (num_extended != 0); num_expand++) {
for (int num_expand = 0; num_expand < max_expand; num_expand++) {
// for (int num_expand = 0; (num_expand < 1) && (num_extended != 0); num_expand++) {
Runtime runtime = Runtime.getRuntime();
runtime.gc();
System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
// Temporarily mixing results of refinePassSetup() and tp.getFilteredDisparityStrength(). The Later needs measurement pass, not refined
double [][] filtered_disp_strength = tp.getFilteredDisparityStrength(
tp.clt_3d_passes.size() - 1, // final int measured_scan_index, // will not look at higher scans
0, // final int start_scan_index,
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
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)
refine_pass = tp.clt_3d_passes.size(); // 1
// refine pass uses hor/vert thresholds inside
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,
......@@ -6184,12 +5986,20 @@ public class QuadCLT {
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
filtered_disp_strength, // final double [][] plate_ds, // disparity/strength last time measured for the multi-tile squares. Strength =-1 - not measured. May be null
clt_parameters.pt_keep_raw_fg, // final boolean keep_raw_fg, // do not replace raw tiles by the plates, if raw is closer (like poles)
clt_parameters.pt_scale_pre, // final double scale_filtered_strength_pre, // scale plate_ds[1] before comparing to raw strength
clt_parameters.pt_scale_post, // 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);
if (show_expand || (clt_parameters.show_expand && last_pass)) {
tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
......@@ -6197,6 +6007,17 @@ public class QuadCLT {
}
// if (show_expand || (clt_parameters.show_expand && last_pass)) {
// tp.showScan(
// tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
// "after_refine-"+refine_pass);
// }
tp.calcMaxTried(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
......@@ -6222,6 +6043,38 @@ public class QuadCLT {
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_refine-combine-"+(tp.clt_3d_passes.size() - 1));
if (show_expand || (clt_parameters.show_expand && last_pass)) {
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_disp_strength[0];
dbg_img[1] = filtered_disp_strength[1];
dbg_img[2] = extended_pass.getDisparity();
dbg_img[3] = extended_pass.getStrength();
double [][] max_tried_disparity = extended_pass.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 = extended_pass.selected;
boolean [] s_border = extended_pass.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);
}
num_extended = tp.setupExtendDisparity(
extended_pass, // final CLTPass3d scan, // combined scan with max_tried_disparity, will be modified to re-scan
tp.clt_3d_passes.get(refine_pass), // final CLTPass3d last_scan, // last prepared tile - can use last_scan.disparity, .border_tiles and .selected
......@@ -6278,9 +6131,20 @@ public class QuadCLT {
updateStatus,
debugLevel);
if (show_expand || (clt_parameters.show_expand && last_pass)) tp.showScan(
// ********************************************** //
tp.removeNonMeasurement();
refine_pass = tp.clt_3d_passes.size() - 1;
// ********************************************** //
if (show_expand || (clt_parameters.show_expand && last_pass)) {
tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_measure-"+refine_pass); //String title)
// just testing:
}
if (debugLevel > -1){
......@@ -6308,8 +6172,8 @@ public class QuadCLT {
// refine_pass = tp.clt_3d_passes.size();
// }
if (show_expand || (clt_parameters.show_expand && last_pass)) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_combo_pass-"+(refine_pass)); //String title)
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 (last_pass) {
break;
} else if (numLeftRemoved[0] == 0){
......@@ -6341,6 +6205,8 @@ public class QuadCLT {
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, // super_trust, // If strength exceeds ex_strength * super_trust, do not apply ex_nstrength and plate_ds
ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4)
geometryCorrection,
threadsMax, // maximal number of threads to launch
......@@ -6352,7 +6218,9 @@ public class QuadCLT {
// Save tp.clt_3d_passes.size() to roll back without restarting the program
tp.saveCLTPasses();
Runtime runtime = Runtime.getRuntime();
runtime.gc();
System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
if (tp.clt_3d_passes.size() > 0) {
System.out.println("-------- temporary exit after secondPassSetup() ------- ");
......@@ -6488,14 +6356,21 @@ public class QuadCLT {
if (this.image_data == null){
return false;
}
tp.trimCLTPasses(); // make possible to run this method multiple time - remove extra passes added by it last time
int next_pass = tp.clt_3d_passes.size(); //
if (clt_parameters.remove_scans){
System.out.println("Removing all scans but the first(background) and the last to save memory");
System.out.println("Will need to re-start the program to be able to output differently");
CLTPass3d latest_scan = tp.clt_3d_passes.get(tp.clt_3d_passes.size() - 1);
tp.trimCLTPasses(1);
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.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)
tp.thirdPassSetupSurf( // prepare tile tasks for the second pass based on the previous one(s) // needs last scan
clt_parameters,
clt_parameters.bgnd_range, // double disparity_far,
clt_parameters.grow_disp_max, // other_range, //double disparity_near, //
......@@ -6513,7 +6388,7 @@ public class QuadCLT {
geometryCorrection,
tp.clt_3d_passes);
x3dOutput.generateBackground();
x3dOutput.generateBackground(); // needs just first (background) scan
String x3d_path= correctionsParameters.selectX3dDirectory(
true, // smart,
true); //newAllowed, // save
......@@ -6819,7 +6694,8 @@ 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_grown[tileY * tilesX + tileX]) {
if (bgnd_tiles_grown2[tileY * tilesX + tileX]) {
texture_tiles_bgnd[tileY][tileX]= texture_tiles[tileY][tileX];
}else{
texture_tiles_bgnd[tileY][tileX]= texture_tiles[tileY][tileX].clone();
......
......@@ -55,6 +55,7 @@ public class SuperTiles{
int smplSide = 2; // Sample size (side of a square)
int smplNum = 3; // Number after removing worst
double smplRms = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd = false; // final boolean smplWnd, // use window functions for the samples
......@@ -95,6 +96,7 @@ public class SuperTiles{
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, // use window functions for the samples
int measSel)
{
this.cltPass3d = cltPass3d;
......@@ -111,6 +113,7 @@ public class SuperTiles{
this.smplSide = smplSide; // Sample size (side of a square)
this.smplNum = smplNum; // Number after removing worst
this.smplRms = smplRms; // Maximal RMS of the remaining tiles in a sample
this.smplWnd = smplWnd; // Use window functions for the samples
this.measSel = measSel;
this.step_threshold_near = this.step_threshold_far * step_near / this.step_far ;
this.bin_far = this.step_threshold_far / this.step_far;
......@@ -160,6 +163,7 @@ public class SuperTiles{
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
smplWnd, // final boolean smplWnd, // use window functions for the samples
measSel); // calculate and blur supertiles (for all, not just selected?)
if (tileProcessor.globalDebugLevel > 0){
System.out.println("SuperTiles(): min_disparity = "+min_disparity+", max_disparity="+max_disparity);
......@@ -391,6 +395,7 @@ public class SuperTiles{
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst
final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd, //
final int measSel) //
{
if (disparity_strength != null) {
......@@ -448,7 +453,9 @@ public class SuperTiles{
smplSide, // int smplSide, // = 2; // Sample size (side of a square)
smplNum, //int smplNum, // = 3; // Number after removing worst (should be >1)
smplRms, //double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
true); // boolean null_if_none);
smplWnd,
true, // boolean null_if_none);
-1); // int debugLevel
} else {
disp_strength = measuredLayers.getDisparityStrength(
nl, // int num_layer,
......@@ -543,6 +550,7 @@ public class SuperTiles{
this.smplSide, // final int smplSide, // = 2; // Sample size (side of a square)
this.smplNum, // final int smplNum, // = 3; // Number after removing worst
this.smplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
this.smplWnd, // final boolean smplWnd, // use window functions for the samples
this.measSel);
final int globalDebugLevel = tileProcessor.globalDebugLevel;
maxMinMax = new double [disparityHistograms.length][][];
......@@ -680,6 +688,7 @@ public class SuperTiles{
this.smplSide, // final int smplSide, // = 2; // Sample size (side of a square)
this.smplNum, // final int smplNum, // = 3; // Number after removing worst
this.smplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
this.smplWnd, // final boolean smplWnd, //
this.measSel); // calculate and blur with the current settings, specified at instantiation
}
return showDisparityHistogram(disparityHistograms);
......@@ -694,6 +703,7 @@ public class SuperTiles{
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, //
int measSel) // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
{
getDisparityHistograms( // will recalculate if does not exist or some parameters changed
......@@ -704,6 +714,7 @@ public class SuperTiles{
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
smplWnd, // final boolean smplWnd, //
measSel); // calculate and blur with the current settings, specified at instantiation
return showDisparityHistogram(disparityHistograms);
}
......@@ -1404,7 +1415,7 @@ public class SuperTiles{
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst
final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd, //
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -1451,7 +1462,7 @@ public class SuperTiles{
plane_disp_strength[nsTile] = new double[measuredLayers.getNumLayers()][][];
for (int ml = 0; ml < plane_disp_strength[nsTile].length; ml++) if ((stMeasSel & ( 1 << ml)) != 0){
// TODO": apply tilt before/with getDisparityStrength()
if (smplMode) {
plane_disp_strength[nsTile][ml] = measuredLayers.getDisparityStrength(
ml, // int num_layer,
......@@ -1463,7 +1474,9 @@ public class SuperTiles{
smplSide, // int smplSide, // = 2; // Sample size (side of a square)
smplNum, //int smplNum, // = 3; // Number after removing worst (should be >1)
smplRms, //double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
true); // boolean null_if_none);
true, // boolean null_if_none);
smplWnd, // boolean smplWnd, //
dl);
} else {
plane_disp_strength[nsTile][ml] = measuredLayers.getDisparityStrength(
ml, // int num_layer,
......@@ -1859,7 +1872,7 @@ public class SuperTiles{
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst
final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd, // use window functions fro the samples
final double bin_blur_hor, // Blur disparity histograms for horizontal clusters by this sigma (in bins)
final double bin_blur_vert, // Blur disparity histograms for constant disparity clusters by this sigma (in bins)
// TODO: scale down max_diff_hor, max_diff_vert for large disparities?
......@@ -1871,6 +1884,7 @@ public class SuperTiles{
// TODO: scale down smallDiff for large disparities?
final double highMix, //stHighMix = 0.4; // Consider merging initial planes if jumps between ratio above
final double [] world_hor, // horizontal plane normal (default [0.0, 1.0, 0.0])
final boolean show_histograms,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -1908,7 +1922,7 @@ public class SuperTiles{
cltPass3d.getDisparity(), // double [] disparity,
cltPass3d.getStrength(), // double [] strength,
grown_selection); // null); // boolean [] selection) // may be null
if (debugLevel > 0) {
if (show_histograms && (debugLevel > 0)) {
String [] titles = {"d0","s0","d1","s1","d2","s2","d3","s3","s","d","selection"};
boolean [] dbg_sel= grown_selection; // cltPass3d.getSelected();
double [][] dbg_img = new double [titles.length][];
......@@ -1935,10 +1949,10 @@ public class SuperTiles{
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
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
smplWnd, // final boolean smplWnd, // use window functions fro the samples
debugLevel,
dbg_X,
dbg_Y);
......@@ -1950,9 +1964,10 @@ public class SuperTiles{
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
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
smplWnd, // final boolean smplWnd, // use window functions fro the samples
debugLevel,
dbg_X,
dbg_Y);
......@@ -1970,7 +1985,7 @@ public class SuperTiles{
final double [][][] mmm_hor = getMaxMinMax(
hor_disp_strength, // final double [][][][] disparity_strength, // pre-calculated disparity/strength [per super-tile][per-measurement layer][2][tiles] or null
null); // final boolean [][] tile_sel // null or per-measurement layer, per-tile selection. For each layer null - do not use, {} - use all
if (debugLevel > 0) {
if (show_histograms && (debugLevel > 0)) {
dbg_hist[1] = showDisparityHistogram();
dbg_hist[3] = showMaxMinMax();
}
......@@ -1980,11 +1995,11 @@ public class SuperTiles{
vert_disp_strength, // final double [][][][] disparity_strength, // pre-calculated disparity/strength [per super-tile][per-measurement layer][2][tiles] or null
null); // final boolean [][] tile_sel // null or per-measurement layer, per-tile selection. For each layer null - do not use, {} - use all
if (debugLevel > 0) {
if (show_histograms && (debugLevel > 0)) {
dbg_hist[0] = showDisparityHistogram();
dbg_hist[2] = showMaxMinMax();
}
if (debugLevel > 0) {
if (show_histograms && (debugLevel > 0)) {
int hist_width0 = showDisparityHistogramWidth();
int hist_height0 = dbg_hist[0].length/hist_width0;
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
......@@ -2155,6 +2170,7 @@ 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 smplWnd use window functions for the samples
* @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)
......@@ -2183,6 +2199,7 @@ public class SuperTiles{
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst
final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd, // use window functions for the samples
final double 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
......@@ -2257,7 +2274,7 @@ public class SuperTiles{
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
smplWnd, // final boolean smplWnd, // use window functions for the samples
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
......@@ -2363,7 +2380,7 @@ public class SuperTiles{
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst
final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd, // use window functions for the samples
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -2430,6 +2447,7 @@ public class SuperTiles{
smplSide, // int smplSide, // = 2; // Sample size (side of a square)
smplNum, // int smplNum, // = 3; // Number after removing worst
smplRms, // double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // final boolean smplWnd, // use window functions for the samples
dl); // int debugLevel);
if ((st_planes != null) && (!st_planes.isEmpty())){
......@@ -2472,6 +2490,7 @@ public class SuperTiles{
smplSide, // int smplSide, // = 2; // Sample size (side of a square)
smplNum, // int smplNum, // = 3; // Number after removing worst
smplRms, // double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // final boolean smplWnd, // use window functions for the samples
dl - 1); // int debugLevel);
}
......@@ -2551,7 +2570,7 @@ public class SuperTiles{
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst
final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd, // use window functions fro the samples
final double bin_blur_hor, // Blur disparity histograms for horizontal clusters by this sigma (in bins)
final double bin_blur_vert, // Blur disparity histograms for constant disparity clusters by this sigma (in bins)
final double max_diff_hor, // maximal disparity difference (to assign to a cluster (of Double.NaN) at first run for horizontal planes
......@@ -2565,6 +2584,7 @@ public class SuperTiles{
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])
final boolean show_histograms,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -2589,7 +2609,7 @@ public class SuperTiles{
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
smplWnd, // final boolean smplWnd, // use window functions fro the samples
bin_blur_hor, // final double bin_blur_hor, // Blur disparity histograms for horizontal clusters by this sigma (in bins)
bin_blur_vert, // final double bin_blur_vert, // Blur disparity histograms for constant disparity clusters by this sigma (in bins)
max_diff_hor, // final double max_diff_hor, // maximal disparity difference (to assign to a cluster (of Double.NaN) at first run for horizontal planes
......@@ -2598,7 +2618,8 @@ public class SuperTiles{
smallDiff, // final double smallDiff, // = 0.4; // Consider merging initial planes if disparity difference below
highMix, //final double highMix, // stHighMix = 0.4; // Consider merging initial planes if jumps between ratio above
world_hor, // final double [] world_hor, // horizontal plane normal (default [0.0, 1.0, 0.0])
debugLevel+1, // final int debugLevel,
show_histograms, // final boolean show_histograms,
debugLevel+0, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y)
......@@ -2616,7 +2637,7 @@ public class SuperTiles{
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
smplWnd, // final boolean smplWnd, // use window functions fro the samples
debugLevel, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y)
......@@ -2639,6 +2660,7 @@ public class SuperTiles{
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
smplWnd, // final boolean smplWnd, // use window functions for the samples
debugLevel + 2, // + 2, // 1, // final int debugLevel,
dbg_X, // final int dbg_X,
......@@ -2695,7 +2717,7 @@ public class SuperTiles{
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst
final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd, // use window functions for the samples
final double 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)
......@@ -2737,7 +2759,7 @@ public class SuperTiles{
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
smplWnd, // final boolean smplWnd, // use window functions for the samples
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)
......@@ -2775,7 +2797,7 @@ public class SuperTiles{
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
smplWnd, // final boolean smplWnd, // use window functions for the samples
debugLevel, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y)
......@@ -2798,7 +2820,7 @@ public class SuperTiles{
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
smplWnd, // final boolean smplWnd, // use window functions for the samples
debugLevel, // + 2, // 1, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y)
......@@ -5229,7 +5251,8 @@ public class SuperTiles{
preferDisparity,
debugLevel - 2); // int debugLevel)
}
ev_variants[variant][nt] = tri_plane.getValue();
// ev_variants[variant][nt] = tri_plane.getValue();
ev_variants[variant][nt] = tri_plane.getNormValue();
tri_merged[variant][nt] = tri_plane;
}
if ((best_pair < 0) || ((ev_variants[variant][0] + ev_variants[variant][1]) < best_value)){
......@@ -5299,7 +5322,8 @@ public class SuperTiles{
debugLevel - 1); // int debugLevel)
}
}
double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight()};
// double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight()};
double [] value_weight = {merged_plane.getNormValue(),merged_plane.getWeight()};
if (starPwr != 0){
value_weight[0] /= (Math.pow((planes[nsTile][nl].getNumNeibBest() + 1.0), starPwr));
}
......@@ -5496,7 +5520,8 @@ public class SuperTiles{
int num_sat = 0;
for (int j = 0; j < planes[i].length; j++) if (planes[i][j] != null){
// if (planes[i][j].getWeight() >= minWeight){ /// Later does not compare too minWeight
double eigVal = planes[i][j].getValue(); // ************** generated does not have value ????????????
// double eigVal = planes[i][j].getValue(); // ************** generated does not have value ????????????
double eigVal = planes[i][j].getNormValue(); // ************** generated does not have value ????????????
double disp = planes[i][j].getSinglePlaneDisparity(false)[centerIndex];
/*
if (disp > dispNorm) {
......@@ -5533,7 +5558,8 @@ public class SuperTiles{
if (planes[nsTile][np].getWeight() >= minWeight){
//&& (planes[nsTile][np].getValue() < maxEigen)){
double eigVal = planes[nsTile][np].getValue();
// double eigVal = planes[nsTile][np].getValue();
double eigVal = planes[nsTile][np].getNormValue();
double disp = planes[nsTile][np].getZxy()[0];
/*
if (disp > dispNorm) {
......@@ -6083,6 +6109,7 @@ public class SuperTiles{
smplSide,
smplNum,
smplRms,
smplWnd,
dl - 2); // int debugLevel)
if (disp_strength == null) {
System.out.println("=== BUG in applyMergePlanes(): failed to getPlaneFromMeas() for merged planes");
......@@ -6117,7 +6144,8 @@ public class SuperTiles{
targetEigen,
dispNorm,
planes[nsTile][np0]);
if (this_pd.getValue() > targetV) {
// if (this_pd.getValue() > targetV) {
if (this_pd.getNormValue() > targetV) {
boolean OK = this_pd.removeOutliers( // getPlaneFromMeas should already have run
disp_strength,
targetV, // double targetEigen, // target eigenvalue for primary axis (is disparity-dependent, so is non-constant)
......@@ -6238,7 +6266,7 @@ public class SuperTiles{
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst
final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd, // use window functions for the samples
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -6392,6 +6420,7 @@ public class SuperTiles{
smplSide,
smplNum,
smplRms,
smplWnd, // final boolean smplWnd, // use window functions for the samples
measSel, // int measSel, // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
allow_parallel, //boolean allow_parallel,
dl); // int debugLevel)
......@@ -6430,6 +6459,7 @@ public class SuperTiles{
smplSide,
smplNum,
smplRms,
smplWnd, // final boolean smplWnd, // use window functions for the samples
dl); // int debugLevel)
if (disp_strength == null) break;
// remove outliers //removeOutliers
......@@ -6440,7 +6470,8 @@ public class SuperTiles{
targetEigen,
dispNorm,
bpd[np][npip]);
if (bpd[np][npip].getValue() > targetV) {
// if (bpd[np][npip].getValue() > targetV) {
if (bpd[np][npip].getNormValue() > targetV) {
OK = bpd[np][npip].removeOutliers( // getPlaneFromMeas should already have run
disp_strength,
targetV, // double targetEigen, // target eigenvalue for primary axis (is disparity-dependent, so is non-constant)
......@@ -6667,7 +6698,8 @@ public class SuperTiles{
if ((plane_triads[nSplit][0] != null) && (plane_triads[nSplit][1] != null)){
double w1 = plane_triads[nSplit][0].getWeight();
double w2 = plane_triads[nSplit][1].getWeight();
split_quality[nSplit] = (w1 * plane_triads[nSplit][0].getValue() + w2 * plane_triads[nSplit][1].getValue())/
// split_quality[nSplit] = (w1 * plane_triads[nSplit][0].getValue() + w2 * plane_triads[nSplit][1].getValue())/
split_quality[nSplit] = (w1 * plane_triads[nSplit][0].getNormValue() + w2 * plane_triads[nSplit][1].getNormValue())/
(w1 + w2);
if (dl >0){
plane_triads[nSplit][2] = plane_triads[nSplit][0].clone().mergePlaneToThis(
......@@ -6707,7 +6739,8 @@ public class SuperTiles{
dl-1);
// check quality
if ((plane_triads[best_index][2] != null) &&
(plane_triads[best_index][2].getValue()/split_quality[best_index] > splitMinQuality)) {
// (plane_triads[best_index][2].getValue()/split_quality[best_index] > splitMinQuality)) {
(plane_triads[best_index][2].getNormValue()/split_quality[best_index] > splitMinQuality)) {
for (int nis = 0; nis < 2; nis++) {
plane_triads[best_index][nis].setNeibBest(neibs12[nis][best_index]);
}
......@@ -6785,9 +6818,12 @@ public class SuperTiles{
System.out.print((plane_triads[nSplit][2].getNeibBest(dir) >=0)?"+":"-");
}
System.out.println(" : "+split_quality[nSplit]+
" "+plane_triads[nSplit][0].getValue()+
" "+plane_triads[nSplit][1].getValue()+
" "+plane_triads[nSplit][2].getValue()+
// " "+plane_triads[nSplit][0].getValue()+
// " "+plane_triads[nSplit][1].getValue()+
// " "+plane_triads[nSplit][2].getValue()+
" "+plane_triads[nSplit][0].getNormValue()+
" "+plane_triads[nSplit][1].getNormValue()+
" "+plane_triads[nSplit][2].getNormValue()+
" w"+plane_triads[nSplit][0].getWeight()+
" w"+plane_triads[nSplit][1].getWeight()+
" w"+plane_triads[nSplit][2].getWeight()
......@@ -6852,7 +6888,8 @@ public class SuperTiles{
selection[nsTile][np] = true;
} else if (planes[nsTile][np].getWeight() >= minWeight) {
//&& (planes[nsTile][np].getValue() < maxEigen)){
double eigVal = planes[nsTile][np].getValue();
// double eigVal = planes[nsTile][np].getValue();
double eigVal = planes[nsTile][np].getNormValue();
double disp = planes[nsTile][np].getZxy()[0];
selection[nsTile][np] = (eigVal < corrMaxEigen(
maxEigen,
......
......@@ -94,6 +94,7 @@ public class TilePlanes {
int smplSide = 2; // Sample size (side of a square)
int smplNum = 3; // Number after removing worst
double smplRms = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd = false; // Use sample mode (false - regular tile mode)
double [] starValueWeight = null;
PlaneData starPlane = null;
......@@ -280,7 +281,7 @@ public class TilePlanes {
double [] px_py = getCenterPxPy();
if (zxy != null) s += String.format("\nzxy = [%8.3f, %8.3f, %8.3f] (pix)",zxy[0],zxy[1]+px_py[0],zxy[2]+px_py[1]);
else s += "\nzxy = null";
if (values != null) s += String.format(", values = [%8.5f, %8.4f, %8.3f] pix^2",values[0],values[1],values[2]);
if (values != null) s += String.format(", values = [%8.5f, %8.4f, %8.3f] (%8.3f) pix^2",values[0],values[1],values[2], getNormValue());
else s += " values = null";
if (vectors != null) s += String.format("\nvectors = [%8.5f, %8.5f, %8.5f], [%8.5f, %8.5f, %8.5f], [%8.5f, %8.5f, %8.5f]",
vectors[0][0],vectors[0][1],vectors[0][2], vectors[1][0],vectors[1][1],vectors[1][2], vectors[2][0],vectors[2][1],vectors[2][2]);
......@@ -747,6 +748,7 @@ public class TilePlanes {
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, // use window functions for the samples
int measSel, // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
boolean allow_parallel,
int debugLevel)
......@@ -788,7 +790,9 @@ public class TilePlanes {
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)
smplWnd, // use window functions for the samples
true, // boolean null_if_none)
debugLevel);
} else {
disp_strength[nl] = measuredLayers.getDisparityStrength(
nl, // int num_layer,
......@@ -912,7 +916,9 @@ public class TilePlanes {
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)
smplWnd, // use window functions for the samples
true, // boolean null_if_none)
debugLevel);
} else {
disp_strength[nl] = measuredLayers.getDisparityStrength(
nl, // int num_layer,
......@@ -1085,7 +1091,9 @@ public class TilePlanes {
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)
smplWnd, // use window functions for the samples
true, // boolean null_if_none)
debugLevel);
}
} else {
disp_str[nl] = measuredLayers.getDisparityStrength(
......@@ -1102,9 +1110,11 @@ public class TilePlanes {
}
int numRemoved = 0;
boolean no_bugs = true;
for (; (getValue() > targetEigen) && (numRemoved < maxRemoved); numRemoved++){
// for (; (getValue() > targetEigen) && (numRemoved < maxRemoved); numRemoved++){
for (; (getNormValue() > targetEigen) && (numRemoved < maxRemoved); numRemoved++){
if (debugLevel > 2){
System.out.println("removePlaneOutliers("+sTileXY[0]+":"+sTileXY[1]+"): numRemoved = "+numRemoved+" eigenValue = " + getValue()+" target = "+targetEigen);
System.out.println("removePlaneOutliers("+sTileXY[0]+":"+sTileXY[1]+"): numRemoved = "+numRemoved+
" eigenValue = " + getValue()+" norm eigenValue = " + getNormValue()+" target = "+targetEigen);
}
// make a plane and find the worst (largest disparity difference) tile
// z = -(x*Vx + y*Vy)/Vz
......@@ -1160,6 +1170,7 @@ public class TilePlanes {
smplSide,
smplNum,
smplRms,
smplWnd, // use window functions for the samples
debugLevel-1) != null);
if (!OK){ // restore last selection, re-run getPlaneFromMeas
......@@ -1178,6 +1189,7 @@ public class TilePlanes {
smplSide,
smplNum,
smplRms,
smplWnd, // use window functions for the samples
debugLevel-1) != null);
if (!OK) {
System.out.println("This is a BUG in removePlaneOutliers() - run with previous selection and failed");
......@@ -1210,6 +1222,7 @@ public class TilePlanes {
* @param smplSide size of the square sample side
* @param smplNum number of averaged samples (should be <= smplSide * smplSide and > 1)
* @param smplRms maximal square root of variance (in disparity pixels) to accept the result
* @param smplWnd use window functions for the samples
*
* @param debugLevel debug level
* @return per measurement layer : x,y,z, weight, or null if failed. This
......@@ -1225,11 +1238,11 @@ public class TilePlanes {
int min_tiles,
double strength_floor,
double strength_pow,
boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, // use window functions for the samples
int debugLevel)
{
double mindet = 1E-15;
......@@ -1247,6 +1260,7 @@ public class TilePlanes {
this.min_weight = min_weight;
this.min_tiles = min_tiles;
this.dispNorm = dispNorm;
this.smplWnd = smplWnd; // use window functions for the samples
this.smplMode = smplMode; // = true; // Use sample mode (false - regular tile mode)
this.smplSide = smplSide; // = 2; // Sample size (side of a square)
this.smplNum = smplNum; // = 3; // Number after removing worst
......@@ -1275,7 +1289,9 @@ public class TilePlanes {
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)
smplWnd, // final boolean smplWnd, // use window functions fro the samples
true, // boolean null_if_none)
debugLevel);
}
if (disp_str[nl] == null) continue;
if (Double.isNaN(disp_far) && Double.isNaN(disp_near)){
......@@ -1337,8 +1353,10 @@ public class TilePlanes {
dbg_img[0] = disp_str[nl][0];
dbg_img[1] = disp_str[nl][1];
dbg_img[2] = new double [stSize2*stSize2];
if (tile_sel[nl] != null) {
for (int i = 0; i < dbg_img[2].length; i++){
dbg_img[2][i] = tile_sel[nl][i]?1.0:0.0;
dbg_img[2][i] = tile_sel[nl][i]?1.0:0.0; // exception here?
}
}
sdfa_instance.showArrays(dbg_img, stSize2, stSize2, true, "disp_str_x"+sTileXY[0]+"_y"+sTileXY[1]+"_"+nl);
}
......@@ -1365,8 +1383,10 @@ public class TilePlanes {
if (w > 0.0){
double d = disp_str[nl][0][indx];
// referencing samples to centers of pixels
double x = ((indx % stSize2) - stSize + 0.5) * tileSize + 0.5; // in pixels, not in tiles
double y = ((indx / stSize2) - stSize + 0.5) * tileSize + 0.5;
// double x = ((indx % stSize2) - stSize + 0.5) * tileSize + 0.5; // in pixels, not in tiles
// double y = ((indx / stSize2) - stSize + 0.5) * tileSize + 0.5;
double x = ((indx % stSize2) - stSize + 0.5) * tileSize; // in pixels, not in tiles
double y = ((indx / stSize2) - stSize + 0.5) * tileSize;
sw += w;
swz += w * d;
swx += w * x;
......@@ -1400,8 +1420,10 @@ public class TilePlanes {
// double d = kz * (disp_str[nl][0][indx] - swz); // Not here!
double d = disp_str[nl][0][indx] - swz;
double wd = w*d;
double x = ((indx % stSize2) - stSize + 0.5) * tileSize + 0.5 - swx;
double y = ((indx / stSize2) - stSize + 0.5) * tileSize + 0.5 - swy;
// double x = ((indx % stSize2) - stSize + 0.5) * tileSize + 0.5 - swx;
// double y = ((indx / stSize2) - stSize + 0.5) * tileSize + 0.5 - swy;
double x = ((indx % stSize2) - stSize + 0.5) * tileSize - swx;
double y = ((indx / stSize2) - stSize + 0.5) * tileSize - swy;
acovar [0][0] += wd * d;
acovar [0][1] += wd * x;
acovar [0][2] += wd * y;
......@@ -1576,7 +1598,9 @@ public class TilePlanes {
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)
smplWnd, // use window functions for the samples
true, // boolean null_if_none)
debugLevel);
}
if (disp_str[nl] == null) continue;
if (Double.isNaN(disp_far) && Double.isNaN(disp_near)){
......@@ -1638,9 +1662,11 @@ public class TilePlanes {
dbg_img[0] = disp_str[nl][0];
dbg_img[1] = disp_str[nl][1];
dbg_img[2] = new double [stSize2*stSize2];
if (tile_sel[nl] != null) {
for (int i = 0; i < dbg_img[2].length; i++){
dbg_img[2][i] = tile_sel[nl][i]?1.0:0.0;
}
}
sdfa_instance.showArrays(dbg_img, stSize2, stSize2, true, "disp_str_x"+sTileXY[0]+"_y"+sTileXY[1]+"_"+nl);
}
}
......@@ -1673,8 +1699,10 @@ public class TilePlanes {
tiles_xyzw[nl][indx] = new double [4];
double d = disp_str[nl][0][indx];
// referencing samples to centers of pixels
double x = ((indx % stSize2) - stSize + 0.5) * tileSize + 0.5 + px_py[0]; // in pixels, not in tiles
double y = ((indx / stSize2) - stSize + 0.5) * tileSize + 0.5 + px_py[1];
// double x = ((indx % stSize2) - stSize + 0.5) * tileSize + 0.5 + px_py[0]; // in pixels, not in tiles
// double y = ((indx / stSize2) - stSize + 0.5) * tileSize + 0.5 + px_py[1];
double x = ((indx % stSize2) - stSize + 0.5) * tileSize + px_py[0]; // in pixels, not in tiles
double y = ((indx / stSize2) - stSize + 0.5) * tileSize + px_py[1];
// difference from getPlaneFromMeas
double [] wxyz = geometryCorrection.getWorldCoordinates(
x,
......@@ -1735,18 +1763,6 @@ public class TilePlanes {
if (tiles_xyzw[nl][indx] != null) {
double w = tiles_xyzw[nl][indx][3] / sw;
if (w > 0.0){
/*
double d = kz * (disp_str[nl][0][indx] - swz);
double wd = w*d;
double x = ((indx % stSize2) - stSize + 0.5) * tileSize + 0.5 - swx;
double y = ((indx / stSize2) - stSize + 0.5) * tileSize + 0.5 - swy;
acovar [0][0] += wd * d;
acovar [0][1] += wd * x;
acovar [0][2] += wd * y;
acovar [1][1] += w * x * x;
acovar [1][2] += w * x * y;
acovar [2][2] += w * y * y;
*/
double x = tiles_xyzw[nl][indx][0] - swx;
double y = tiles_xyzw[nl][indx][1] - swy;
double z = tiles_xyzw[nl][indx][2] - swz;
......@@ -1903,10 +1919,16 @@ public class TilePlanes {
}
public double [] getLinkCosts(int dir)
{
if ((link_costs==null) || (link_costs[dir] == null)){
return null;
}
return this.link_costs[dir];
}
public double getLinkCosts(int dir, int np)
{
if ((link_costs==null) || (link_costs[dir] == null)){
return Double.MAX_VALUE;
}
return this.link_costs[dir][np];
}
......@@ -2220,6 +2242,20 @@ public class TilePlanes {
public double getValue() {
return values[0];
}
/**
* Return "normalized" main eigenvalue - it is reduced for high disparities
* @return normalized main eigenvalue
*/
public double getNormValue(){
double val = values[0];
if ((dispNorm > 0.0) && (zxy[0] > dispNorm)){
double k = dispNorm / zxy[0];
val *= k*k;
}
return val;
}
public void setValues(double[] values) {
this.values = values;
}
......@@ -2330,9 +2366,11 @@ public class TilePlanes {
int indx_sel = (2*sy + superTileSize) * superTileSize + superTileSize/2;
// adding half-tile and half-pixel to match the center of the pixel. Supertile center is between
// pixel 31 and pixel 32 (counting from 0) in both directions
double y = tileSize * (sy + 0.5) + 0.5 - zxy[2];
// double y = tileSize * (sy + 0.5) + 0.5 - zxy[2];
double y = tileSize * (sy + 0.5) - zxy[2];
for (int sx = -superTileSize/2; sx < superTileSize/2; sx++){
double x = tileSize * (sx + 0.5) + 0.5 - zxy[1];
// double x = tileSize * (sx + 0.5) + 0.5 - zxy[1];
double x = tileSize * (sx + 0.5) - zxy[1];
if (plane_sel[indx_sel] || !useNaN || (plane_sel==null)){
disparities[indx] = zxy[0] - (normal[1] * x + normal[2] * y)/normal[0];
} else {
......@@ -2371,9 +2409,11 @@ public class TilePlanes {
for (int sy = -superTileSize; sy < superTileSize; sy++){
// adding half-tile and half-pixel to match the center of the pixel. Supertile center is between
// pixel 31 and pixel 32 (counting from 0) in both directions
double y = tileSize * (sy + 0.5) + 0.5 - zxy[2];
// double y = tileSize * (sy + 0.5) + 0.5 - zxy[2];
double y = tileSize * (sy + 0.5) - zxy[2];
for (int sx = -superTileSize; sx < superTileSize; sx++){
double x = tileSize * (sx + 0.5) + 0.5 - zxy[1];
// double x = tileSize * (sx + 0.5) + 0.5 - zxy[1];
double x = tileSize * (sx + 0.5) - zxy[1];
if (plane_sel[indx] || !useNaN || (plane_sel==null)){
if (useWorld) {
disparities[indx] = geometryCorrection.getPlaneDisparity( // disparity (at this center) for crossing other supertile plane
......@@ -2442,9 +2482,11 @@ public class TilePlanes {
for (int sy = -3 * superTileSize / 2; sy < 3* superTileSize / 2; sy++){
// adding half-tile and half-pixel to match the center of the pixel. Supertile center is between
// pixel 31 and pixel 32 (counting from 0) in both directions
double y = tileSize * (sy + 0.5) + 0.5 - zxy[2];
// double y = tileSize * (sy + 0.5) + 0.5 - zxy[2];
double y = tileSize * (sy + 0.5) - zxy[2];
for (int sx = -3 * superTileSize/2; sx < 3 * superTileSize / 2; sx++){
double x = tileSize * (sx + 0.5) + 0.5 - zxy[1];
// double x = tileSize * (sx + 0.5) + 0.5 - zxy[1];
double x = tileSize * (sx + 0.5) - zxy[1];
if (useWorld) {
disparities[indx] = geometryCorrection.getPlaneDisparity( // disparity (at this center) for crossing other supertile plane
getWorldXYZ(this.correctDistortions), // will calculate if not yet done so. Should it use otherPd, not pd? and then clone later?
......@@ -2575,9 +2617,11 @@ public class TilePlanes {
for (int sy = -superTileSize; sy < superTileSize; sy++){
// adding half-tile and half-pixel to match the center of the pixel. Supertile center is between
// pixel 31 and pixel 32 (counting from 0) in both directions
double y = tileSize * (sy + 0.5) + 0.5 - zxy[2];
// double y = tileSize * (sy + 0.5) + 0.5 - zxy[2];
double y = tileSize * (sy + 0.5) - zxy[2];
for (int sx = -superTileSize; sx < superTileSize; sx++){
double x = tileSize * (sx + 0.5) + 0.5 - zxy[1];
// double x = tileSize * (sx + 0.5) + 0.5 - zxy[1];
double x = tileSize * (sx + 0.5) - zxy[1];
if (useWorld) {
disp_strength[0][indx] = geometryCorrection.getPlaneDisparity( // disparity (at this center) for crossing other supertile plane
getWorldXYZ(this.correctDistortions), // will calculate if not yet done so. Should it use otherPd, not pd? and then clone later?
......@@ -2664,79 +2708,6 @@ public class TilePlanes {
scale_projection,
fraction_uni,
debugLevel);
/*
double [][] disp_strength = new double[2][4*superTileSize*superTileSize];
double [] normal = getVector();
double [] zxy = getZxy(); // {disparity, x center in pixels, y center in pixels (relative to a supertile center)
double weight = getWeight();
double k_gauss = 0;
Matrix val2d = null, vect2d = null;
if (scale_projection > 0.0){
EigenvalueDecomposition eig = get2dDecomposition();
val2d = eig.getD();
vect2d = eig.getV().transpose();
k_gauss = 0.5/(scale_projection*scale_projection);
if (divide_by_area) {
double area = Math.sqrt(val2d.get(0, 0)*val2d.get(1, 1));
if (area > 0){
weight /= area;
}
}
}
int ss2 = superTileSize;
int ss4 = 2 * superTileSize;
int [][] offsets = {
// ymin, ymax, xmin,xmax, offsy, offsx
{ 0, ss4, 0, ss4, 0, 0 }, // center
{ss2, ss4, 0, ss4, -ss2, 0 }, // N
{ss2, ss4, 0, ss2, -ss2, ss2 }, // NE
{ 0, ss4, 0, ss2, 0, ss2 }, // E
{ 0, ss2, 0, ss2, ss2, ss2 }, // SE
{ 0, ss2, 0, ss4, ss2, 0 }, // S
{ 0, ss2, ss2, ss4, ss2, -ss2 }, // SW
{ 0, ss4, ss2, ss4, 0, -ss2 }, // W
{ss2, ss4, ss2, ss4, -ss2, -ss2 }}; // NW
int dir1 = dir + 1;
double [] pxyc = getCenterPxPy(); // center of this supertile, not plane center
for (int iy = offsets[dir1][0]; iy < offsets[dir1][1]; iy++){
// adding half-tile and half-pixel to match the center of the pixel. Supertile center is between
// pixel 31 and pixel 32 (counting from 0) in both directions
double y = tileSize * (iy - ss2 + 0.5) + 0.5 - zxy[2];
int oy = iy + offsets[dir1][4]; //vert index in the result tile
for (int ix = offsets[dir1][2]; ix < offsets[dir1][3]; ix++){
double x = tileSize * (ix - ss2 + 0.5) + 0.5 - zxy[1];
int indx = ss4 * oy + ix + offsets[dir1][5];
int indx_i = iy * ss4 + ix; // input index
if (useWorld) {
disp_strength[0][indx] = geometryCorrection.getPlaneDisparity( // disparity (at this center) for crossing other supertile plane
getWorldXYZ(this.correctDistortions), // will calculate if not yet done so. Should it use otherPd, not pd? and then clone later?
x + pxyc[0] + zxy[1],
y + pxyc[1] + zxy[2],
this.correctDistortions);
} else {
disp_strength[0][indx] = zxy[0] - (normal[1] * x + normal[2] * y)/normal[0];
}
double w = weight;
if ((w > 0.0) && (scale_projection > 0.0)){
double [] xy = {x,y};
Matrix vxy = vect2d.times(new Matrix(xy,2)); // verify if it is correct
double r2 = 0;
for (int i = 0; i <2; i++){
double d = vxy.get(i,0);
r2 += d * d / val2d.get(i, i);
}
w *= ((1.0 - fraction_uni) * Math.exp(-k_gauss*r2) + fraction_uni);
if (window != null) w *= window[indx_i];
if (use_sel && (sel_mask != null) && !(sel_mask[indx_i])) w = 0.0;
}
disp_strength[1][indx] = w;
}
}
return disp_strength;
*/
}
public double [] getWorldXYZFromWorld()
......@@ -2844,10 +2815,12 @@ public class TilePlanes {
for (int iy = offsets[dir1][0]; iy < offsets[dir1][1]; iy++){
// adding half-tile and half-pixel to match the center of the pixel. Supertile center is between
// pixel 31 and pixel 32 (counting from 0) in both directions
double y = tileSize * (iy - ss2 + 0.5) + 0.5 - zxy[2];
// double y = tileSize * (iy - ss2 + 0.5) + 0.5 - zxy[2];
double y = tileSize * (iy - ss2 + 0.5) - zxy[2];
int oy = iy + offsets[dir1][4]; //vert index in the result tile
for (int ix = offsets[dir1][2]; ix < offsets[dir1][3]; ix++){
double x = tileSize * (ix - ss2 + 0.5) + 0.5 - zxy[1];
// double x = tileSize * (ix - ss2 + 0.5) + 0.5 - zxy[1];
double x = tileSize * (ix - ss2 + 0.5) - zxy[1];
int indx = ss4 * oy + ix + offsets[dir1][5];
int indx_i = iy * ss4 + ix; // input index
if (world_normal != null) {
......@@ -2963,10 +2936,12 @@ public class TilePlanes {
for (int iy = offsets[dir1][0]; iy < offsets[dir1][1]; iy++){
// adding half-tile and half-pixel to match the center of the pixel. Supertile center is between
// pixel 31 and pixel 32 (counting from 0) in both directions
double y = tileSize * (iy - ss2 + 0.5) + 0.5 - zxy[2];
// double y = tileSize * (iy - ss2 + 0.5) + 0.5 - zxy[2];
double y = tileSize * (iy - ss2 + 0.5) - zxy[2];
int oy = iy + offsets[dir1][4]; //vert index in the result tile
for (int ix = offsets[dir1][2]; ix < offsets[dir1][3]; ix++){
double x = tileSize * (ix - ss2 + 0.5) + 0.5 - zxy[1];
// double x = tileSize * (ix - ss2 + 0.5) + 0.5 - zxy[1];
double x = tileSize * (ix - ss2 + 0.5) - zxy[1];
int indx = ss2 * oy + ix + offsets[dir1][5];
int indx_i = iy * ss4 + ix; // ss2;
if (useWorld) {
......@@ -3102,6 +3077,16 @@ public class TilePlanes {
if (debugLevel > 0) {
System.out.println("mergePlaneToThis()");
}
if (values == null ) {
System.out.println("mergePlaneToThis(): values=null:\n"+toString());
return null;
}
if (otherPd.values == null ) {
System.out.println("mergePlaneToThis(): otherPd.values=null:\n"+otherPd.toString());
return null;
}
double [][] this_eig_avals = {
{values[0], 0.0, 0.0},
{0.0, values[1], 0.0},
......@@ -3268,7 +3253,7 @@ public class TilePlanes {
pd.setWeight(new_weight);
pd.setNumPoints(otherPd.getNumPoints()+this.getNumPoints());
// Repeat merging for world-based planes
mergePlaneToThisWorld(
return mergePlaneToThisWorld(
otherPd, // PlaneData otherPd,
pd, // PlaneData pd_partial, // disparity-based data is already merged
scale_other,
......@@ -3277,7 +3262,7 @@ public class TilePlanes {
sum_weights,
preferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
debugLevel);
return pd;
// return pd;
}
......@@ -3295,6 +3280,15 @@ public class TilePlanes {
if (debugLevel > 0) {
System.out.println("mergePlaneToThisWorld()");
}
if (wvalues == null ) {
System.out.println("mergePlaneToThisWorld(): wvalues=null:\n"+toString());
return null;
}
if (otherPd.wvalues == null ) {
System.out.println("mergePlaneToThisWorld(): otherPd.wvalues=null:\n"+otherPd.toString());
return null;
}
double [][] this_eig_avals = {
{wvalues[0], 0.0, 0.0},
{0.0, wvalues[1], 0.0},
......@@ -3794,9 +3788,12 @@ public class TilePlanes {
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, // use window functions for the samples
int debugLevel)
{
if (debugLevel > 2) debugLevel ++; // no show all eigen stuff (debugLevel > 3)
if (debugLevel > 2) {
debugLevel += 0; // +=1 // no show all eigen stuff (debugLevel > 3)
}
// first make a plane from all tiles
ArrayList<PlaneData> st_planes = new ArrayList<PlaneData>();
......@@ -3821,6 +3818,7 @@ public class TilePlanes {
smplSide,
smplNum,
smplRms,
smplWnd, // use window functions for the samples
debugLevel) != null); // int debugLevel)
if (OK) {
if (debugLevel > 0) {
......@@ -3837,12 +3835,16 @@ public class TilePlanes {
int max_outliers = (int) Math.round(pd.getNumPoints() * plFractOutliers);
if (max_outliers > plMaxOutliers) max_outliers = plMaxOutliers;
double targetV = plTargetEigen;
/* Does it needs to be twice?
double z0 = pd.getZxy()[0];
if ((dispNorm > 0.0) && (z0 > dispNorm)) {
if ((dispNorm > 0.0) && (z0 > dispNorm)) { // not needed ?
double dd = (dispNorm + z0)/ dispNorm; // > 1
targetV *= dd * dd; // > original
}
if (pd.getValues()[0] > targetV) {
*/
// if (pd.getValues()[0] > targetV) {
if (pd.getNormValue() > targetV) {
OK = pd.removeOutliers( // getPlaneFromMeas should already have run
disp_strength,
targetV, // double targetEigen, // target eigenvalue for primary axis (is disparity-dependent, so is non-constant)
......@@ -3913,6 +3915,7 @@ public class TilePlanes {
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst
final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd, // use window functions for the samples
final double max_disp_diff, // maximal disparity difference from the plane to consider tile
final double disp_range, // parallel move known planes around original know value for the best overall fit
......@@ -4029,7 +4032,9 @@ public class TilePlanes {
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)
smplWnd, // use window functions for the samples
true, // boolean null_if_none)
debugLevel);
} else {
disp_strength[ml] = measuredLayers.getDisparityStrength(
ml, // int num_layer,
......@@ -4323,7 +4328,7 @@ public class TilePlanes {
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst
final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd, // use window functions for the samples
final double 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
......@@ -4454,7 +4459,9 @@ public class TilePlanes {
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)
smplWnd, // use window functions for the samples
true, // boolean null_if_none)
debugLevel);
} else {
disp_strength[ml] = measuredLayers.getDisparityStrength(
ml, // int num_layer,
......@@ -5240,7 +5247,9 @@ public class TilePlanes {
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)
smplWnd, // use window functions for the samples
true, // boolean null_if_none)
debugLevel);
} else {
disp_strength[ml] = measuredLayers.getDisparityStrength(
ml, // int num_layer,
......
......@@ -26,6 +26,7 @@ import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Arrays;
//import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicInteger;
public class TileProcessor {
......@@ -85,18 +86,37 @@ public class TileProcessor {
public void resetCLTPasses(){
clt_3d_passes = new ArrayList<CLTPass3d>();
clt_3d_passes_size = 0;
Runtime runtime = Runtime.getRuntime();
runtime.gc();
System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
}
public void saveCLTPasses(){
clt_3d_passes_size = clt_3d_passes.size();
}
public void trimCLTPasses(int keep){
clt_3d_passes_size = keep;
trimCLTPasses();
}
public void trimCLTPasses(){
while (clt_3d_passes.size() > clt_3d_passes_size){
clt_3d_passes.remove(clt_3d_passes_size);
}
Runtime runtime = Runtime.getRuntime();
runtime.gc();
System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
}
public void removeNonMeasurement(){
for (int i = clt_3d_passes.size()-1; i > 0; i--) if (!clt_3d_passes.get(i).isMeasured()){
clt_3d_passes.remove(i);
}
}
......@@ -499,7 +519,470 @@ public class TileProcessor {
combo_pass.fixNaNDisparity(); // mostly for debug, measured disparity should be already fixed from NaN
return combo_pass;
}
//trustedCorrelation
/**
* Verify that selected points are not all on the same line
* @param sel 2-d sample selection in linescan order
* @param side square samples side
* @return true if there are enough samples for plane extraction, false otherwise
*/
public boolean notColinear (
boolean [] sel,
int side)
{
int indx0, indx1;
for (indx0 = 0; indx0 < sel.length; indx0++){
if (sel[indx0]) break;
}
for (indx1 = indx0+1; indx1 < sel.length; indx1++){
if (sel[indx1]) break;
}
if (indx1 >= sel.length) return false; // too few points;
int sx0 = indx0 % side;
int sy0 = indx0 / side;
int sx1 = indx1 % side;
int sy1 = indx1 / side;
for (int indx = indx1 +1; indx < sel.length; indx++){
int sx = indx % side;
int sy = indx / side;
if ((sx - sx0) * (sy - sy1) != (sx - sx1) * (sy - sy0)){
return true;
}
}
return false;
}
/**
* Verify that selected points are not all on the same line, even if the specified one is removed
* @param indx index of the point to be removed
* @param sel 2-d sample selection in linescan order
* @param side square samples side
* @return true if there are enough samples for plane extraction, false otherwise
*/
public boolean notColinearWithout (
int indx,
boolean [] sel,
int side)
{
if (!sel[indx]){
throw new IllegalArgumentException ("notCoplanarWithout(): specified is the non existing index");
}
sel[indx] = false;
boolean rslt = notColinear ( sel, side);
sel[indx] = true;
return rslt;
}
/**
* Get window function for tile samples (currently just 3x3) in a line-scan order
* @param smplSide square sample side
* @return [smplSide * smplSide]array of weights, 1.0 in the center
*/
public double [] getSampleWindow(int smplSide, boolean all1){
double [] weights = new double [smplSide * smplSide];
for (int sy = 0; sy < smplSide; sy++){
for (int sx = 0; sx < smplSide; sx++){
weights[sy * smplSide + sx] = all1? 1.0 : Math.sin(Math.PI*(sy+0.5)/smplSide) * Math.sin(Math.PI*(sx+0.5)/smplSide);
}
}
return weights;
}
/**
* Get disparity/strength for last measured tiles (measured_scan), using neighbors measured in the same or earlier
* scans, assuming the sample square can (almost) freely tilt for the best fit
* @param measured_scan_index index in the clt_3d_passes list of the latest measured scan
* @param start_scan_index lowest scan to use data from
* @param disp_index disparity index in disparity_map (normally ImageDtt.DISPARITY_INDEX_CM)
* @param str_index strength index in disparity_map (normally[ImageDtt.DISPARITY_STRENGTH_INDEX)
* @param tiltXY null (free floating) or fixed {tilt_x, tilt_y) of the sample
* @param trustedCorrelation maximal absolute value of measured correlation (no scaling) to trust (may use global trustedCorrelation)
* @param strength_floor subtract from the strength, discard negative
* @param strength_pow raise strength to this power
* @param smplSide side of tyhe sample square
* @param smplNum number of the best fit neighbors to keep
* @param smplRms maximal disparity RMS of the best remaining tiles to keep sample
* @param smplWnd use sample window function (false - all set to 1.0)
* @param max_abs_tilt maximal disparity tilt in disparity difference (pix) per tile;
* @param max_rel_tilt same as max_abs_tilt, but divided by disparity
* @param dbg_x debug tile X
* @param dbg_y debug tile Y
* @param debugLevel debug level
* @return {disparity,strength};
*/
// combo_pass.calc_disparity[nt] = pass.disparity_map[disparity_index][nt]/corr_magic_scale + pass.disparity[ty][tx];
public double [][] getFilteredDisparityStrength(
final int measured_scan_index, // will not look at higher scans (OK to be non-measured, last measured will be used then)
final int start_scan_index,
final int disp_index,
final int str_index,
final double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
final double trustedCorrelation,
final double strength_floor,
final double strength_pow,
final int smplSide, // = 2; // Sample size (side of a square)
final int smplNum, // = 3; // Number after removing worst (should be >1)
final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
final boolean smplWnd, //
final double max_abs_tilt, // = 2.0; // pix per tile
final double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
final int dbg_x,
final int dbg_y,
final int debugLevel)
{
final double [] smpl_weights = getSampleWindow(smplSide, !smplWnd);
final int smplLen = smplSide*smplSide;
final int smpl_center = smplSide / 2;
final int center_index = smpl_center * ( 1 + smplSide);
final double smpl_dcenter = (smplSide -1.0) /2;
// final TileNeibs tnSurface = new TileNeibs(tilesX, tilesY);
final int tiles = tilesX * tilesY;
final boolean [] measured = new boolean [tiles];
final double smplVar = smplRms * smplRms; // maximal variance (weighted average of the squared difference from the mean)
final double thresholdLin = 1.0E-20; // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
final double thresholdQuad = 1.0E-30; // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
final double [][] disp_strength = new double [2][tiles]; // strength < 0 - not measured!
final int dbg_tile = (debugLevel > 0) ?(dbg_x + dbg_y * tilesX) : -1;
// Create a list of only measurement scans
final ArrayList<CLTPass3d> measured_list = new ArrayList<CLTPass3d> ();
for (int ipass = start_scan_index; ipass <= measured_scan_index; ipass++){
CLTPass3d pass = clt_3d_passes.get(ipass);
if ((pass != null) && pass.isMeasured()){
measured_list.add(pass);
}
}
final CLTPass3d measured_scan =measured_list.get(measured_list.size() - 1);// use last measured scan
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) {
// int dl = (nTile == dbg_tile) ? debugLevel : -1;
int tileX = nTile % tilesX;
int tileY = nTile / tilesX;
measured[nTile] = measured_scan.tile_op[tileY][tileX] != 0;
if (!measured[nTile]) disp_strength[1][nTile] = -1.0;
}
}
};
}
ImageDtt.startAndJoin(threads);
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
PolynomialApproximation pa = new PolynomialApproximation();
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) if (measured[nTile]){
int dl = (nTile == dbg_tile) ? debugLevel : -1;
int tileX = nTile % tilesX;
int tileY = nTile / tilesX;
// check that the tile is strong enough and fractional disparity is in the trusted range
double w = measured_scan.disparity_map[str_index][nTile] - strength_floor;
if (w > 0) {
if (strength_pow != 1.0){
if (strength_pow == 0.0) {
w = 1.0;
} else {
w= Math.pow(w, strength_pow);
}
}
double disp = measured_scan.disparity_map[disp_index][nTile];
if (Math.abs(disp) <= trustedCorrelation){
disp = disp/corr_magic_scale + measured_scan.disparity[tileY][tileX];
// Center tile is valid, makes sense to investigate neighbors from this or earlier tiles
int num_in_sample = 1;
double sum_wnd = 1.0;
boolean [] smpl_sel = new boolean [smplLen];
double [] smpl_d = new double [smplLen];
double [] smpl_p = new double [smplLen];
double [] smpl_w = new double [smplLen];
// add center tile
smpl_sel[center_index] = true;
smpl_d[center_index] = disp;
smpl_w[center_index] = w;
// process tiles around, looking for the best fit among other tiles, skipping the center
for (int sy = 0; sy < smplSide; sy++){
int y = tileY + sy - smpl_center;
if ((y >= 0) && (y < tilesY)) {
for (int sx = 0; sx < smplSide; sx++){
int x = tileX + sx - smpl_center;
if ((x >= 0) && (x < tilesX)) {
int indxs = sy*smplSide + sx;
if (indxs != center_index) { // already assigned
int nTile1 = y * tilesX + x;
int best_pass_index = -1;
double best_adiff = Double.NaN;
for (int ipass = 0; ipass < measured_list.size(); ipass++){
CLTPass3d scan = measured_list.get(ipass);
double w1 = scan.disparity_map[str_index][nTile1] - strength_floor;
if (w1 > 0) {
if (strength_pow != 1.0){
if (strength_pow == 0.0) {
w1 = 1.0;
} else {
w1= Math.pow(w, strength_pow);
}
}
double disp1 = scan.disparity_map[disp_index][nTile1];
if (Math.abs(disp1) <= trustedCorrelation){
disp1 = disp1/corr_magic_scale + scan.disparity[y][x];
double adiff = Math.abs(disp1 - disp);
if ((best_pass_index < 0) || (adiff < best_adiff)){
best_pass_index = ipass;
best_adiff = adiff;
smpl_d[indxs] = disp1;
smpl_w[indxs] = w1;
// not summed yet!
}
}
}
}
if (best_pass_index >= 0){
smpl_w [indxs] *= smpl_weights[indxs];
smpl_sel[indxs] = true;
sum_wnd += smpl_weights[indxs];
num_in_sample ++;
}
}
}
}
}
}
// filled all neighbor tiles data. See if sufficient to proceed, then remove extra tiles
// and process the remaining ones
if (num_in_sample >= smplNum){ // try, remove worst
sample_loop:
{
boolean en_tilt = (tiltXY == null);
if (en_tilt) { // make sure there are enough samples and not all of them are on the same line
if (!notColinear(smpl_sel,smplSide)){
en_tilt = false;
}
}
if (en_tilt) { // enable floating tilt
double sd2 = 0.0, d_center = 0.0, sw = 0.0;
// TODO: making simple - recalculate after removing. Can be done more efficient.
while (num_in_sample >= smplNum) { // try, remove worst
sd2 = 0.0;
d_center = 0.0;
sw = 0.0;
double [][][] mdata = new double [num_in_sample][3][];
int mindx = 0;
for (int sy = 0; sy < smplSide; sy++){
for (int sx = 0; sx < smplSide; sx++){
int indxs = sy * smplSide + sx;
if (smpl_sel[indxs]) {
mdata[mindx][0] = new double [2];
mdata[mindx][0][0] = sx - smpl_dcenter;
mdata[mindx][0][1] = sy - smpl_dcenter;
mdata[mindx][1] = new double [1];
mdata[mindx][1][0] = smpl_d[indxs];
mdata[mindx][2] = new double [1];
mdata[mindx][2][0] = smpl_w[indxs];
mindx ++;
}
}
}
double[][] approx2d = pa.quadraticApproximation(
mdata,
true, // boolean forceLinear, // use linear approximation
thresholdLin, // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
thresholdQuad, // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
debugLevel);
if (approx2d == null){
if (debugLevel > -1){
System.out.println("getFilteredDisparityStrength(): can not find linear approximation");
}
break sample_loop;
}
// limit tilt to be within range
// double max_abs_tilt, // = 2.0; // pix per tile
// double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
double max_tilt = Math.min(max_abs_tilt, max_rel_tilt * approx2d[0][2]);
boolean overlimit = (Math.abs(approx2d[0][0]) > max_tilt) || (Math.abs(approx2d[0][1]) > max_tilt);
if (overlimit) {
approx2d[0][0] = Math.min(approx2d[0][0], max_tilt);
approx2d[0][1] = Math.min(approx2d[0][1], max_tilt);
approx2d[0][0] = Math.max(approx2d[0][0], -max_tilt);
approx2d[0][1] = Math.max(approx2d[0][1], -max_tilt);
}
// subtract tilt from disparity
for (int sy = 0; sy < smplSide; sy++){
for (int sx = 0; sx < smplSide; sx++){
int indxs = sy * smplSide + sx;
if (smpl_sel[indxs]) {
smpl_p[indxs] = approx2d[0][0] * (sx - smpl_dcenter) + approx2d[0][1] * (sy - smpl_dcenter) + approx2d[0][2];
}
}
}
if (overlimit){ // re-calculate disparity average (in the center)
double sd=0.0;
for (int indxs = 0; indxs < smplLen;indxs++) if (smpl_sel[indxs]) {
double d = smpl_d[indxs] - smpl_p[indxs];
double dw = d * smpl_w[indxs];
sd += dw;
sw += smpl_w[indxs];
}
sd /= sw;
for (int indxs = 0; indxs < smplLen;indxs++) if (smpl_sel[indxs]) {
smpl_p[indxs] += sd;
}
approx2d[0][2] += sd;
}
d_center = approx2d[0][2];
sw = 0.0;
for (int indxs = 0; indxs < smplLen;indxs++) if (smpl_sel[indxs]) {
double d = smpl_d[indxs] - smpl_p[indxs];
double dw = d * smpl_w[indxs];
// sd += dw;
sd2 += dw * smpl_d[indxs];
sw += smpl_w[indxs];
}
// remove worst - it should not make remaining set
if (num_in_sample > smplNum) { // remove worst if it is not the last run where only calculations are needed
// double d_mean = sd/sw;
int iworst = -1;
double dworst2 = 0.0;
for (int indxs = 0; indxs < smplLen; indxs++) if (smpl_sel[indxs]) {
// double d2 = (smpl_d[i] - d_mean);
double d2 = smpl_d[indxs] - smpl_p[indxs];
d2 *=d2;
if (d2 > dworst2) {
if (notColinearWithout (
indxs, // int indx,
smpl_sel, // boolean [] sel,
smplSide)) { // int side))
iworst = indxs;
dworst2 = d2;
}
}
}
if (iworst < 0){
System.out.println("**** this is a BUG in getFilteredDisparityStrength() can not find the worst sample ****");
break;
}
// remove worst sample
smpl_sel[iworst] = false;
// double dw = smpl_d[iworst] * smpl_w[iworst];
// sd -= dw;
// sd2 -= dw * smpl_d[iworst];
// sw -= smpl_w[iworst];
sum_wnd -= smpl_weights[iworst];
num_in_sample --;
} else {
break;
}
} // removing worst tiles, all done,
// calculate variance of the remaining set
if (sw > 0.0) {
// sd /= sw;
// sd2 /= sw;
double var = sd2/sw; // - sd * sd;
if (var < smplVar) { // good, save in the result array
disp_strength[0][nTile] = d_center;
// ds[1][indx] = sw * lapWeight[dy][dx] /num_in_sample; // average weights, multiply by window //** TODO: change
disp_strength[1][nTile] = sw /sum_wnd; // average weights, multiply by window //** TODO: change
}
}
} else { // fixed tilt
// tilt around center
if ((tiltXY != null) && (tiltXY[0] != 0.0) && (tiltXY[1] != 0.0)){
for (int sy = 0; sy < smplSide; sy++){
for (int sx = 0; sx < smplSide; sx++){
int indxs = sy * smplSide + sx;
if (smpl_w[indxs] > 0.0) {
smpl_d[indxs] -= tiltXY[0]* (sx - smpl_dcenter) + tiltXY[1]* (sy - smpl_dcenter);
}
}
}
}
// calculate
double sd=0.0, sd2 = 0.0, sw = 0.0;
for (int i = 0; i < smplLen; i++) if (smpl_sel[i]) {
double dw = smpl_d[i] * smpl_w[i];
sd += dw;
sd2 += dw * smpl_d[i];
sw += smpl_w[i];
}
// remove worst, update sd2, sd and sw
while ((num_in_sample > smplNum) && (sw > 0)){ // try, remove worst
double d_mean = sd/sw;
int iworst = -1;
double dworst2 = 0.0;
for (int i = 0; i < smplLen; i++) if (smpl_sel[i]) {
double d2 = (smpl_d[i] - d_mean);
d2 *=d2;
if (d2 > dworst2) {
iworst = i;
dworst2 = d2;
}
}
if (iworst < 0){
System.out.println("**** this is a BUG in getFilteredDisparityStrength() ****");
break;
}
// remove worst sample
smpl_sel[iworst] = false;
double dw = smpl_d[iworst] * smpl_w[iworst];
sd -= dw;
sd2 -= dw * smpl_d[iworst];
sw -= smpl_w[iworst];
sum_wnd -= smpl_weights[iworst];
num_in_sample --;
}
// calculate variance of the remaining set
if (sw > 0.0) {
sd /= sw;
sd2 /= sw;
double var = sd2 - sd * sd;
if (var < smplVar) { // good, save in the result array
disp_strength[0][nTile] = sd;
// ds[1][indx] = sw * lapWeight[dy][dx] /num_in_sample; // average weights, multiply by window //** TODO: change
disp_strength[1][nTile] = sw /sum_wnd; // average weights, multiply by window //** TODO: change
}
} else {
num_in_sample = 0;
System.out.println("**** this is a BUG in getFilteredDisparityStrength(), shoud not happen ? ****");
}
}
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return disp_strength;
}
/**
* Calculate max_tried_disparity from the provided scans (use only actually measured ones)
......@@ -606,7 +1089,7 @@ public class TileProcessor {
final boolean updateStatus,
final int debugLevel)
{
final int dbg_tile = 54627; // ty=159, tx = 249
final int dbg_tile = 39379; // 54627; // ty=159, tx = 249
final int tlen = tilesY * tilesX;
final boolean retryTwoSteps = true; // false; // true;
......@@ -690,17 +1173,7 @@ public class TileProcessor {
int [] neighbors = dp.getNeighbors( // creates neighbors mask from bitmask
grown, // these_tiles, // grown, // these_tiles, // boolean [] selected,
tilesX);
/*
if (clt_parameters.show_neighbors) {
double [] dbg_neib = dp.dbgShowNeighbors(
grown, // these_tiles, // grown, // these_tiles,
neighbors, // _orig, // int [] neighbors,
clt_parameters.transform_size, // int tile_size,
-1.0, // double bgnd,
1.0); // double fgnd)
sdfa_instance.showArrays(dbg_neib,tilesX*clt_parameters.transform_size, tilesY*clt_parameters.transform_size,"XXneighbors");
}
*/
double [] dbg_pre_disp = null;
if (show_debug) {
dbg_pre_disp = scan.getDisparity().clone();
......@@ -2302,6 +2775,13 @@ public class TileProcessor {
final double ex_nstrength, // minimal 4-corr strength divided by channel diff for new (border) tiles
final double this_maybe, // maximal strength to ignore as non-background
final double sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd
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
final double [][] plate_ds, // disparity/strength last time measured for the multi-tile squares. Strength =-1 - not measured. May be null
final boolean keep_raw_fg, // do not replace raw tiles by the plates, if raw is closer (like poles)
final double scale_filtered_strength_pre, // scale plate_ds[1] before comparing to raw strength
final double scale_filtered_strength_post,// scale plate_ds[1] when replacing raw (generally plate_ds is more reliable if it exists)
final boolean show_filter_scan,
final int min_clstr_seed, // clt_parameters.min_clstr_seed
final double min_clstr_weight, // double min_weight // minimal total weight of the cluster
......@@ -2313,7 +2793,7 @@ public class TileProcessor {
final int debugLevel
)
{
final double super_trust = 1.6; // If strength exceeds ex_strength * super_trust, do not apply ex_nstrength
// final double super_trust = 1.6; // If strength exceeds ex_strength * super_trust, do not apply ex_nstrength
final int dbg_tile = 49468; // x = 220, y = 152 (pavement line)
final boolean show_scan = show_filter_scan || (debugLevel > 1);
......@@ -2374,6 +2854,25 @@ public class TileProcessor {
// these_tiles[i] = true;
// }
}
// combine with plates if available
if ((plate_ds != null) && (plate_ds[1][i] >=0) && (this_strength[i] < ex_strength* super_trust)) { // plate_ds[1][i] == -1 - no data, was not measured
if (plate_ds[1][i] > 0){
if ( // !refined_selected[i] ||
!these_tiles[i] ||
(this_disparity[i] <= plate_ds[0][i]) || // keep old way detected (including poles) is closer, replace if raw is farther
(this_strength[i] < plate_ds[1][i] * scale_filtered_strength_pre) // keep old way detected (including poles) is closer, replace if raw is farther
) {
these_tiles[i] = true;
this_disparity[i] = plate_ds[0][i];
this_strength[i] = plate_ds[1][i];
}
} else if (these_tiles[i]){ // no plates and raw is not reliably
these_tiles[i] = false;
}
}
// see if the second worst variation exceeds sure_smth (like a window), really close object
int imax1 = 0;
for (int ip = 1; ip < these_diffs.length; ip++){
......@@ -2895,10 +3394,17 @@ public class TileProcessor {
int bg_scan_index,
double disparity_far, //
double disparity_near, //
double ex_strength, // minimal 4-corr strength to trust tile
double ex_strength, // minimal 4-corr strength to trust raw tile - above will prefer it to multi-tile plates
double ex_nstrength, // minimal 4-corr strength divided by channel diff for new (border) tiles
double this_maybe, // maximal strength to ignore as non-background
double sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd
double super_trust, // If strength exceeds ex_strength * super_trust, do not apply ex_nstrength and plate_ds
double [][] plate_ds, // disparity/strength last time measured for the multi-tile squares. Strength =-1 - not measured. May be null
boolean keep_raw_fg, // do not replace raw tiles by the plates, if raw is closer (like poles)
double scale_filtered_strength_pre, // scale plate_ds[1] before comparing to raw strength
double scale_filtered_strength_post,// scale plate_ds[1] when replacing raw (generally plate_ds is more reliable if it exists)
int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
GeometryCorrection geometryCorrection,
final int threadsMax, // maximal number of threads to launch
......@@ -3034,6 +3540,12 @@ public class TileProcessor {
ex_nstrength, // final double ex_nstrength, // minimal 4-corr strength divided by channel diff for new (border) tiles
this_maybe, // final double this_maybe, // maximal strength to ignore as non-background
sure_smth, // final double sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd
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
plate_ds, // final double [][] plate_ds, // disparity/strength last time measured for the multi-tile squares. Strength =-1 - not measured. May be null
keep_raw_fg, // final boolean keep_raw_fg, // do not replace raw tiles by the plates, if raw is closer (like poles)
scale_filtered_strength_pre, // final double scale_filtered_strength_pre, // scale plate_ds[1] before comparing to raw strength
scale_filtered_strength_post,// final double scale_filtered_strength_post,// scale plate_ds[1] when replacing raw (generally plate_ds is more reliable if it exists)
clt_parameters.show_filter_scan,
clt_parameters.min_clstr_seed, // clt_parameters.min_clstr_seed
clt_parameters.min_clstr_weight, // double min_weight // minimal total weight of the cluster
......@@ -3077,7 +3589,7 @@ public class TileProcessor {
double [] dbg_with_super_disp = null;
double [] dbg_outlayers = null;
if (use_supertiles) {
if (use_supertiles) { // *** currently is not used (obsolete ***
String [] dbg_st_titles = {"raw", "blurred"+clt_parameters.stSigma,"max-min-max"};
double [][] dbg_hist = new double[dbg_st_titles.length][];
......@@ -3094,6 +3606,7 @@ public class TileProcessor {
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[0] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -3110,6 +3623,7 @@ public class TileProcessor {
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[1] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -3137,6 +3651,9 @@ public class TileProcessor {
if (dbg_with_super_disp != null) dbg_with_super_disp = dbg_with_super_disp.clone(); // else no super disparity available
}
// replace weak outlaye tiles with weighted averages (modifies disparity)
boolean[] outlayers = scan_prev.replaceWeakOutlayers(
null, // final boolean [] selection,
......@@ -3884,6 +4401,7 @@ public class TileProcessor {
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[0] = scan_prev.getSuperTiles().showDisparityHistogram();
scan_prev.setSuperTiles(
......@@ -3899,6 +4417,7 @@ public class TileProcessor {
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[1] = scan_prev.getSuperTiles().showDisparityHistogram();
}
......@@ -3917,6 +4436,7 @@ public class TileProcessor {
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
if (show_st) { // otherwise only blured version is needed
dbg_hist[2] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -3945,6 +4465,7 @@ public class TileProcessor {
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
}
......@@ -3968,6 +4489,7 @@ public class TileProcessor {
clt_parameters.stSmplSide , // final int smplSide, // = 2; // Sample size (side of a square)
clt_parameters.stSmplNum , // final int smplNum, // = 3; // Number after removing worst
clt_parameters.stSmplRms , // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.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)
......@@ -3983,6 +4505,7 @@ public class TileProcessor {
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])
clt_parameters.show_histograms, // final boolean show_histograms,
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -4033,6 +4556,7 @@ public class TileProcessor {
clt_parameters.stSmplSide, // final int smplSide, // = 2; // Sample size (side of a square)
clt_parameters.stSmplNum, // final int smplNum, // = 3; // Number after removing worst
clt_parameters.stSmplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // final boolean smplWnd, // use window functions for the samples
clt_parameters.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
......@@ -4147,6 +4671,7 @@ public class TileProcessor {
clt_parameters.stSmplSide , // final int smplSide, // = 2; // Sample size (side of a square)
clt_parameters.stSmplNum , // final int smplNum, // = 3; // Number after removing worst
clt_parameters.stSmplRms , // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
debugLevel, // 1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -4686,6 +5211,8 @@ public class TileProcessor {
double ex_nstrength, // minimal 4-corr strength divided by channel diff for new (border) tiles
double this_maybe, // maximal strength to ignore as non-background
double sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd
double super_trust, // If strength exceeds ex_strength * super_trust, do not apply ex_nstrength and plate_ds
int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
GeometryCorrection geometryCorrection,
final int threadsMax, // maximal number of threads to launch
......@@ -4760,6 +5287,12 @@ public class TileProcessor {
this_maybe, // final double this_maybe, // maximal strength to ignore as non-background
sure_smth, // final double sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd
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)
true, // clt_parameters.show_filter_scan,
clt_parameters.min_clstr_seed, // clt_parameters.min_clstr_seed
clt_parameters.min_clstr_weight, // double min_weight // minimal total weight of the cluster
......@@ -4812,13 +5345,13 @@ public class TileProcessor {
// if (clt_parameters.stShow){
// try renovated supertiles. Do twice to show both original and blured histograms
// try renovated supertiles. Do twice to show both original and blurred histograms
double [] dbg_orig_disparity = null;
double [] dbg_with_super_disp = null;
double [] dbg_outlayers = null;
// boolean [] grown = these_tiles.clone();
if (use_supertiles || show_st) {
if (use_supertiles || show_st) {// currently not use (only to show)
String [] dbg_st_titles = {"raw", "blurred"+clt_parameters.stSigma,"max-min-max"};
double [][] dbg_hist = new double[dbg_st_titles.length][];
......@@ -4835,6 +5368,7 @@ public class TileProcessor {
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // Use window functions for the samples
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[0] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -4851,6 +5385,7 @@ public class TileProcessor {
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[1] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -6245,6 +6780,7 @@ public class TileProcessor {
}
int iSign (int a) {return (a > 0) ? 1 : ((a < 0)? -1 : 0);}
public void testTriangles(
String texturePath,
Rectangle bounds,
......@@ -6307,6 +6843,9 @@ public class TileProcessor {
"triangles-"+texturePath,
titles);
}
/* Create a Thread[] array as large as the number of processors available.
* From Stephan Preibisch's Multithreading.java class. See:
* http://repo.or.cz/w/trakem2.git?a=blob;f=mpi/fruitfly/general/MultiThreading.java;hb=HEAD
......
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