Loading src/main/java/AlignmentCorrection.java +7 −8 Original line number Original line Diff line number Diff line import java.util.ArrayList; import Jama.Matrix; import ij.IJ; import ij.ImagePlus; import ij.ImageStack; import ij.WindowManager; /** /** ** ** ** AlignmentCorrection - try to apply minor adjustments to the misaligned camera ** AlignmentCorrection - try to apply minor adjustments to the misaligned camera Loading @@ -29,6 +21,13 @@ import ij.WindowManager; ** -----------------------------------------------------------------------------** ** -----------------------------------------------------------------------------** ** ** */ */ import java.util.ArrayList; import Jama.Matrix; import ij.IJ; import ij.ImagePlus; import ij.ImageStack; import ij.WindowManager; public class AlignmentCorrection { public class AlignmentCorrection { static int NUM_SLICES = 10; // disp, strength, dx0, dy0, dx1, dy1, dx2, dy2, dx3, dy3) static int NUM_SLICES = 10; // disp, strength, dx0, dy0, dx1, dy1, dx2, dy2, dx3, dy3) Loading src/main/java/ExtendSurfaces.java 0 → 100644 +291 −0 Original line number Original line Diff line number Diff line import java.util.concurrent.atomic.AtomicInteger; /** ** ** ExtendSurfaces predict disparity in the unknown areas ** ** Copyright (C) 2017 Elphel, Inc. ** ** -----------------------------------------------------------------------------** ** ** ExtendSurfaces.java is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program. If not, see <http://www.gnu.org/licenses/>. ** -----------------------------------------------------------------------------** ** */ public class ExtendSurfaces { TileProcessor tp; public ExtendSurfaces(TileProcessor tp){ this.tp = tp; } public int smoothNew( // return maximal correction value // should first be initialized with all not known = Double.NaN final double [] values, // will be modified, Double.NaN is not yet assigned // final double [] strengths, // cell weights final boolean [] known, // cells with known values (will not be modified) final boolean [] new_cells, // cells that need to be calculated final int smpl_size, // == 5 final boolean use_wnd, // use window function fro the neighbors final double tilt_cost, final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg final double same_range, // modify final boolean en_normal, // expand sngle-range cells (that have all neighbors within split_threshold) final boolean en_far, // expand background - use neighbors cells within same_range from the lowest // en_near is only valid if !en_far final boolean en_near, // expand foreground - use neighbors cells within same_range from the highest final int max_tries, // maximal number of smoothing steps final double final_diff, // maximal change to finish iterations final int dbg_x, final int dbg_y, final int debugLevel) { for (int nTile = 0; nTile < values.length; nTile++){ if (!known[nTile]) values [nTile] = Double.NaN; } for (int num_try = 0; num_try < max_tries; num_try ++){ double max_diff = smoothNewStep( // return maximal correction value // should first be initialized with all not known = Double.NaN values, // final double [] values, // will be modified, Double.NaN is not yet assigned new_cells, // final boolean [] new_cells, // cells that need to be calculated smpl_size, // final int smpl_size, // == 5 use_wnd, // final boolean use_wnd, // use window function fro the neighbors tilt_cost, // final double tilt_cost, split_threshold, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg same_range, // final double same_range, // modify en_normal, // final boolean en_normal, // expand sngle-range cells (that have all neighbors within split_threshold) en_far, // final boolean en_far, // expand background - use neighbors cells within same_range from the lowest // en_near is only valid if !en_far en_near, // final boolean en_near, // expand foreground - use neighbors cells within same_range from the highest dbg_x, // final int dbg_x, dbg_y, // final int dbg_y, debugLevel); // final int debugLevel); if (max_diff <= final_diff) break; } int num_new = 0; for (int nTile = 0; nTile < values.length; nTile++){ if (new_cells[nTile] && !Double.isNaN(values[nTile])) num_new++; } return num_new; } public double smoothNewStep( // return maximal correction value // should first be initialized with all not known = Double.NaN final double [] values, // will be modified, Double.NaN is not yet assigned final boolean [] new_cells, // cells that need to be calculated final int smpl_size, // == 5 final boolean use_wnd, // use window function fro the neighbors final double tilt_cost, final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg final double same_range, // modify final boolean en_normal, // expand sngle-range cells (that have all neighbors within split_threshold) final boolean en_far, // expand background - use neighbors cells within same_range from the lowest // en_near is only valid if !en_far final boolean en_near, // expand foreground - use neighbors cells within same_range from the highest final int dbg_x, final int dbg_y, final int debugLevel) { final int tilesX = tp.getTilesX(); final int tilesY = tp.getTilesY(); final int smpl_half = smpl_size / 2; // 2 // probably should not be needed final double thresholdLin = 1.0E-20; // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail) final double [] damping = {tilt_cost,tilt_cost,0.0}; // 0.0 will be applied to average value, tilt_cost - to both tilts final int center_index = smpl_half * (smpl_size + 1); // final int smpl_high = smpl_size - smpl_low; // 3 final int smpl_len = smpl_size * smpl_size; final int dbg_tile = dbg_x + tilesX * dbg_y; final double [] smpl_weights = MeasuredLayers.getSampleWindow(smpl_size, !use_wnd); final Thread[] threads = ImageDtt.newThreadArray(tp.threadsMax); final double [] max_corrs = new double [threads.length]; final AtomicInteger ai_thread = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0); final double [] new_vals = values.clone(); final int [] neib_indices = new int [8]; // indices of the sample array immediately around the center; int ni = 0; for (int sy = -1; sy < 1; sy++) { for (int sx = -1; sx < 1; sx++) { if ((sy != 0) || (sx != 0)){ neib_indices[ni++] = (smpl_half + sx) + (smpl_half + sy) * smpl_size; } } } for (int ithread = 0; ithread < threads.length; ithread++) { threads[ithread] = new Thread() { public void run() { PolynomialApproximation pa = new PolynomialApproximation(); int this_thread = ai_thread.getAndIncrement(); for (int nTile = ai.getAndIncrement(); nTile < new_vals.length; nTile = ai.getAndIncrement()) { if (new_cells[nTile]) { int dl = (nTile == dbg_tile) ? debugLevel : -1; int tileX = nTile % tilesX; int tileY = nTile / tilesX; // boolean [] smpl_new = new boolean [smpl_len]; boolean [] smpl_sel = new boolean [smpl_len]; double [] smpl_d = new double [smpl_len]; // double [] smpl_p = new double [smpl_len]; double [] smpl_w = new double [smpl_len]; int num_in_sample = 0; for (int sy = 0; sy < smpl_size; sy++) { int y = tileY + sy - smpl_half; if ((y >= 0) && (y < tilesY)) { for (int sx = 0; sx < smpl_size; sx++) { int x = tileX + sx - smpl_half; if ((x >= 0) && (x < tilesX)) { int indx = x + y * tilesX; if (!Double.isNaN(values[indx]) && (indx != center_index)){ int indxs = sx + sy * smpl_size; // double w = smpl_weights[indxs]; smpl_sel[indxs] = true; smpl_d[indxs] = values[indx]; num_in_sample++; } } } } } if (num_in_sample > 0) { // add starting from the known cells. When using 5x5 samples, having immediate neighbor // to the center usually means that likely there is enough data to determine the tilt. boolean has_neib = false; for (int i = 0; i < neib_indices.length; i++) if (smpl_sel[neib_indices[i]]) { has_neib = true; break; } boolean process_sample = false; if (has_neib) { // all conditions met, find linear 2-d damped approximation for the center // if center was NaN - diff is the absolute value. int imin = -1, imax = -1; for (int indxs = 0; indxs < smpl_len; indxs ++ ) if (smpl_sel[indxs]){ if ((imin < 0) || (smpl_d[indxs] < smpl_d[imin])) imin = indxs ; if ((imax < 0) || (smpl_d[indxs] > smpl_d[imax])) imax = indxs ; } // does it all fit if ((smpl_d[imax] - smpl_d[imin]) <= split_threshold){ process_sample = en_normal; } else { if (en_far) { double threshold = smpl_d[imax] - smpl_d[imax]; for (int indxs = 0; indxs < smpl_len; indxs ++ ) if (smpl_sel[indxs]){ if (smpl_d[indxs] < threshold) { smpl_sel[indxs] = false; num_in_sample--; } } process_sample = true; } else if (en_near){ double threshold = smpl_d[imin] + smpl_d[imax]; for (int indxs = 0; indxs < smpl_len; indxs ++ ) if (smpl_sel[indxs]){ if (smpl_d[indxs] > threshold) { smpl_sel[indxs] = false; num_in_sample--; } } process_sample = true; } // removed some points - recheck neighbors if (process_sample){ has_neib = false; for (int i = 0; i < neib_indices.length; i++) if (smpl_sel[neib_indices[i]]) { has_neib = true; break; } if (!has_neib) process_sample = false; // neighbor was removed, will process // with other direction } } } if (process_sample) { // build linear 2d approximation, damped as there could be co-linear cells // or even a single cell double sw = 0.0; double [][][] mdata = new double [num_in_sample][3][]; int mindx = 0; for (int sy = 0; sy < smpl_size; sy++){ for (int sx = 0; sx < smpl_size; sx++){ int indxs = sy * smpl_size + sx; if (smpl_sel[indxs]) { mdata[mindx][0] = new double [2]; mdata[mindx][0][0] = sx - smpl_half; // should match integer center mdata[mindx][0][1] = sy - smpl_half; 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 damping, // double [] damping, thresholdLin, // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail) 0.0, // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail) dl); // int debugLevel; if (approx2d == null) { System.out.println("A BUG in smoothNewStep() - failed quadraticApproximation()"); continue; } double new_center_val = approx2d[0][0]; // Last coefficient, F (of 6) double this_corr; if (Double.isNaN(values[nTile])) this_corr = Math.abs(new_center_val); else this_corr = Math.abs(new_center_val - values[nTile]); new_vals[nTile] = new_center_val; max_corrs[this_thread] = Math.max(max_corrs[this_thread], this_corr); } } } } } }; } System.arraycopy(new_vals, 0, values, 0, new_vals.length); double max_corr = 0; for (int i = 0; i < max_corrs.length; i++) max_corr = Math.max(max_corr,max_corrs[i]); return max_corr; } } /* 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); */ No newline at end of file src/main/java/EyesisCorrectionParameters.java +20 −5 Original line number Original line Diff line number Diff line Loading @@ -2070,6 +2070,9 @@ public class EyesisCorrectionParameters { public double ex_strength = 0.18; // minimal 4-corr strength to trust tile 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 ex_nstrength = 0.4; // minimal 4-corr strength divided by channel diff for new (border) tiles public boolean ex_over_bgnd = false; // Allow expansion over previously identified background (infinity) public double ex_min_over = 1.0; // When expanding over background, disregard lower disparity public double pt_super_trust = 1.6; // If strength exceeds ex_strength * super_trust, do not apply ex_nstrength and plate_ds 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 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_pre = 1.5; // Scale plates strength before comparing to raw strength Loading Loading @@ -2417,7 +2420,7 @@ public class EyesisCorrectionParameters { public boolean tsLoopMulti = true; // Repeat multi-choice assignment while succeeding public boolean tsLoopMulti = true; // Repeat multi-choice assignment while succeeding public boolean tsReset = false; // Reset tiles to surfaces assignment public boolean tsReset = false; // Reset tiles to surfaces assignment public boolean tsShow = false; // Show results of tiles to surfaces assignment public boolean tsShow = false; // Show results of tiles to surfaces assignment public int tsNumClust = 50; // Number of clusters to keep public int tsNumClust = 500; // Number of clusters to keep public int tsConsensMode = 7; // Which assignments to match +1 - combo, +2 grown single, +4 plane seeds public int tsConsensMode = 7; // Which assignments to match +1 - combo, +2 grown single, +4 plane seeds public int tsConsensAgree = 1; // Minimal number of assignments to agree public int tsConsensAgree = 1; // Minimal number of assignments to agree Loading Loading @@ -2624,6 +2627,9 @@ public class EyesisCorrectionParameters { properties.setProperty(prefix+"ex_strength", this.ex_strength +""); properties.setProperty(prefix+"ex_strength", this.ex_strength +""); properties.setProperty(prefix+"ex_nstrength", this.ex_nstrength +""); properties.setProperty(prefix+"ex_nstrength", this.ex_nstrength +""); properties.setProperty(prefix+"ex_over_bgnd", this.ex_over_bgnd+""); properties.setProperty(prefix+"ex_min_over", this.ex_min_over +""); properties.setProperty(prefix+"pt_super_trust", this.pt_super_trust +""); 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_keep_raw_fg", this.pt_keep_raw_fg+""); properties.setProperty(prefix+"pt_scale_pre", this.pt_scale_pre +""); properties.setProperty(prefix+"pt_scale_pre", this.pt_scale_pre +""); Loading Loading @@ -3141,6 +3147,9 @@ 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_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+"ex_nstrength")!=null) this.ex_nstrength=Double.parseDouble(properties.getProperty(prefix+"ex_nstrength")); if (properties.getProperty(prefix+"ex_over_bgnd")!=null) this.ex_over_bgnd=Boolean.parseBoolean(properties.getProperty(prefix+"ex_over_bgnd")); if (properties.getProperty(prefix+"ex_min_over")!=null) this.ex_min_over=Double.parseDouble(properties.getProperty(prefix+"ex_min_over")); 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_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_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_pre")!=null) this.pt_scale_pre=Double.parseDouble(properties.getProperty(prefix+"pt_scale_pre")); Loading Loading @@ -3680,6 +3689,9 @@ public class EyesisCorrectionParameters { gd.addNumericField("Minimal 4-corr strength to trust tile", this.ex_strength, 3); 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.addNumericField("Minimal 4-corr strength divided by channel diff for new (border) tiles", this.ex_nstrength, 3); gd.addCheckbox ("Allow expansion over previously identified background (infinity)", this.ex_over_bgnd); gd.addNumericField("When expanding over background, disregard lower disparity ", this.ex_min_over, 3); gd.addMessage ("********* Plates filetering when building initial z-map *********"); 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.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.addCheckbox ("Do not replace raw tiles by the plates, if raw is closer (like poles)", this.pt_keep_raw_fg); Loading Loading @@ -3803,10 +3815,10 @@ public class EyesisCorrectionParameters { gd.addNumericField("Consider merging initial planes if disparity difference below", this.stSmallDiff, 6); gd.addNumericField("Consider merging initial planes if disparity difference below", this.stSmallDiff, 6); gd.addNumericField("Consider merging initial planes if jumps between ratio above", this.stHighMix, 6); gd.addNumericField("Consider merging initial planes if jumps between ratio above", this.stHighMix, 6); gd.addNumericField("Outlayer tiles weaker than this may be replaced from neighbors", this.outlayerStrength, 6); gd.addNumericField("Outlier tiles weaker than this may be replaced from neighbors", this.outlayerStrength, 6); gd.addNumericField("Replace weak outlayer tiles that do not have neighbors within this disparity difference", this.outlayerDiff, 6); gd.addNumericField("Replace weak outlier tiles that do not have neighbors within this disparity difference", this.outlayerDiff, 6); gd.addNumericField("Replace weak outlayer tiles that have higher disparity than weighted average", this.outlayerDiffPos, 6); gd.addNumericField("Replace weak outlier tiles that have higher disparity than weighted average", this.outlayerDiffPos, 6); gd.addNumericField("Replace weak outlayer tiles that have lower disparity than weighted average", this.outlayerDiffNeg, 6); gd.addNumericField("Replace weak outlier tiles that have lower disparity than weighted average", this.outlayerDiffNeg, 6); gd.addCheckbox ("Combine with all previous after refine pass", this.combine_refine); gd.addCheckbox ("Combine with all previous after refine pass", this.combine_refine); gd.addNumericField("Disregard weaker tiles when combining scans", this.combine_min_strength, 6); gd.addNumericField("Disregard weaker tiles when combining scans", this.combine_min_strength, 6); Loading Loading @@ -4222,6 +4234,9 @@ public class EyesisCorrectionParameters { this.ex_strength= gd.getNextNumber(); this.ex_strength= gd.getNextNumber(); this.ex_nstrength= gd.getNextNumber(); this.ex_nstrength= gd.getNextNumber(); this.ex_over_bgnd= gd.getNextBoolean(); this.ex_min_over= gd.getNextNumber(); this.pt_super_trust= gd.getNextNumber(); this.pt_super_trust= gd.getNextNumber(); this.pt_keep_raw_fg= gd.getNextBoolean(); this.pt_keep_raw_fg= gd.getNextBoolean(); this.pt_scale_pre= gd.getNextNumber(); this.pt_scale_pre= gd.getNextNumber(); Loading src/main/java/LinkPlanes.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -3879,7 +3879,7 @@ public class LinkPlanes { weak_pairs, // final boolean [][] weak_fg_pairs, weak_pairs, // final boolean [][] weak_fg_pairs, 1.0, // double relax, 1.0, // double relax, plWeakFgRelax, // final double relax_weak_fg, plWeakFgRelax, // final double relax_weak_fg, debugLevel, // final int debugLevel) 1+ debugLevel, // final int debugLevel) dbg_tileX, dbg_tileX, dbg_tileY); dbg_tileY); // Calculate costs of merging planes of the same supertile and remove those that are exceed threshold // Calculate costs of merging planes of the same supertile and remove those that are exceed threshold Loading src/main/java/MeasuredLayers.java +40 −4 Original line number Original line Diff line number Diff line Loading @@ -337,7 +337,7 @@ public class MeasuredLayers { * @return [smplSide * smplSide]array of weights, 1.0 in the center * @return [smplSide * smplSide]array of weights, 1.0 in the center */ */ public double [] getSampleWindow(int smplSide, boolean all1){ static double [] getSampleWindow(int smplSide, boolean all1){ double [] weights = new double [smplSide * smplSide]; double [] weights = new double [smplSide * smplSide]; for (int sy = 0; sy < smplSide; sy++){ for (int sy = 0; sy < smplSide; sy++){ for (int sx = 0; sx < smplSide; sx++){ for (int sx = 0; sx < smplSide; sx++){ Loading Loading @@ -898,6 +898,9 @@ public class MeasuredLayers { boolean null_if_none, boolean null_if_none, int debugLevel) int debugLevel) { { boolean use_new = true; // false; if (use_new) { return getDisparityStrength ( return getDisparityStrength ( num_layer, // int num_layer, num_layer, // int num_layer, stX, // int stX, stX, // int stX, Loading @@ -914,6 +917,25 @@ public class MeasuredLayers { 0.2, // double max_rel_tilt, // = 0.2; // (pix / disparity) per tile 0.2, // double max_rel_tilt, // = 0.2; // (pix / disparity) per tile null_if_none, // boolean null_if_none, null_if_none, // boolean null_if_none, debugLevel); // int debugLevel) debugLevel); // int debugLevel) } else { return getDisparityStrength_old ( 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 ( public double[][] getDisparityStrength ( Loading @@ -921,7 +943,9 @@ public class MeasuredLayers { int stX, int stX, int stY, int stY, boolean [] sel_in, boolean [] sel_in, double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values double [][] atiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values // if it has just one element - apply to all tiles, otherwise it is supposed // to be per-tile of a supertile array double strength_floor, double strength_floor, double strength_pow, double strength_pow, int smplSide, // = 2; // Sample size (side of a square) int smplSide, // = 2; // Sample size (side of a square) Loading Loading @@ -1018,7 +1042,7 @@ public class MeasuredLayers { if (num_in_sample >= smplNum){ // try, remove worst if (num_in_sample >= smplNum){ // try, remove worst sample_loop: sample_loop: { { boolean en_tilt = (tiltXY == null); boolean en_tilt = (atiltXY == null); if (en_tilt) { // make sure there are enough samples and not all of them are on the same line if (en_tilt) { // make sure there are enough samples and not all of them are on the same line if (!notColinear(smpl_sel,smplSide)){ if (!notColinear(smpl_sel,smplSide)){ en_tilt = false; en_tilt = false; Loading Loading @@ -1128,7 +1152,10 @@ public class MeasuredLayers { } } } } if (iworst < 0){ if (iworst < 0){ System.out.println("**** this is a BUG in getDisparityStrength() can not find the worst sample ****"); if (debugLevel > 0) { System.out.println("**** this may be BUG in getDisparityStrength() can not find the worst sample - all tiles fit perfectly ****"); } // this can happen if some samples are the same and all the pixels fit exactly - use all of them break; break; } } // remove worst sample // remove worst sample Loading Loading @@ -1158,6 +1185,15 @@ public class MeasuredLayers { } else { // fixed tilt } else { // fixed tilt // tilt around center // tilt around center double [] tiltXY= {0.0,0.0}; if (atiltXY != null){ // if null ( free but failed co-linear test - keep both tilts == 0.0 if (atiltXY.length == 1){ tiltXY = atiltXY[0]; // common for all tiles (such as constant disparity) } else if (atiltXY[indx] != null){ tiltXY = atiltXY[indx]; } } if ((tiltXY != null) && (tiltXY[0] != 0.0) && (tiltXY[1] != 0.0)){ if ((tiltXY != null) && (tiltXY[0] != 0.0) && (tiltXY[1] != 0.0)){ for (int sy = 0; sy < smplSide; sy++){ for (int sy = 0; sy < smplSide; sy++){ for (int sx = 0; sx < smplSide; sx++){ for (int sx = 0; sx < smplSide; sx++){ Loading Loading
src/main/java/AlignmentCorrection.java +7 −8 Original line number Original line Diff line number Diff line import java.util.ArrayList; import Jama.Matrix; import ij.IJ; import ij.ImagePlus; import ij.ImageStack; import ij.WindowManager; /** /** ** ** ** AlignmentCorrection - try to apply minor adjustments to the misaligned camera ** AlignmentCorrection - try to apply minor adjustments to the misaligned camera Loading @@ -29,6 +21,13 @@ import ij.WindowManager; ** -----------------------------------------------------------------------------** ** -----------------------------------------------------------------------------** ** ** */ */ import java.util.ArrayList; import Jama.Matrix; import ij.IJ; import ij.ImagePlus; import ij.ImageStack; import ij.WindowManager; public class AlignmentCorrection { public class AlignmentCorrection { static int NUM_SLICES = 10; // disp, strength, dx0, dy0, dx1, dy1, dx2, dy2, dx3, dy3) static int NUM_SLICES = 10; // disp, strength, dx0, dy0, dx1, dy1, dx2, dy2, dx3, dy3) Loading
src/main/java/ExtendSurfaces.java 0 → 100644 +291 −0 Original line number Original line Diff line number Diff line import java.util.concurrent.atomic.AtomicInteger; /** ** ** ExtendSurfaces predict disparity in the unknown areas ** ** Copyright (C) 2017 Elphel, Inc. ** ** -----------------------------------------------------------------------------** ** ** ExtendSurfaces.java is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program. If not, see <http://www.gnu.org/licenses/>. ** -----------------------------------------------------------------------------** ** */ public class ExtendSurfaces { TileProcessor tp; public ExtendSurfaces(TileProcessor tp){ this.tp = tp; } public int smoothNew( // return maximal correction value // should first be initialized with all not known = Double.NaN final double [] values, // will be modified, Double.NaN is not yet assigned // final double [] strengths, // cell weights final boolean [] known, // cells with known values (will not be modified) final boolean [] new_cells, // cells that need to be calculated final int smpl_size, // == 5 final boolean use_wnd, // use window function fro the neighbors final double tilt_cost, final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg final double same_range, // modify final boolean en_normal, // expand sngle-range cells (that have all neighbors within split_threshold) final boolean en_far, // expand background - use neighbors cells within same_range from the lowest // en_near is only valid if !en_far final boolean en_near, // expand foreground - use neighbors cells within same_range from the highest final int max_tries, // maximal number of smoothing steps final double final_diff, // maximal change to finish iterations final int dbg_x, final int dbg_y, final int debugLevel) { for (int nTile = 0; nTile < values.length; nTile++){ if (!known[nTile]) values [nTile] = Double.NaN; } for (int num_try = 0; num_try < max_tries; num_try ++){ double max_diff = smoothNewStep( // return maximal correction value // should first be initialized with all not known = Double.NaN values, // final double [] values, // will be modified, Double.NaN is not yet assigned new_cells, // final boolean [] new_cells, // cells that need to be calculated smpl_size, // final int smpl_size, // == 5 use_wnd, // final boolean use_wnd, // use window function fro the neighbors tilt_cost, // final double tilt_cost, split_threshold, // final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg same_range, // final double same_range, // modify en_normal, // final boolean en_normal, // expand sngle-range cells (that have all neighbors within split_threshold) en_far, // final boolean en_far, // expand background - use neighbors cells within same_range from the lowest // en_near is only valid if !en_far en_near, // final boolean en_near, // expand foreground - use neighbors cells within same_range from the highest dbg_x, // final int dbg_x, dbg_y, // final int dbg_y, debugLevel); // final int debugLevel); if (max_diff <= final_diff) break; } int num_new = 0; for (int nTile = 0; nTile < values.length; nTile++){ if (new_cells[nTile] && !Double.isNaN(values[nTile])) num_new++; } return num_new; } public double smoothNewStep( // return maximal correction value // should first be initialized with all not known = Double.NaN final double [] values, // will be modified, Double.NaN is not yet assigned final boolean [] new_cells, // cells that need to be calculated final int smpl_size, // == 5 final boolean use_wnd, // use window function fro the neighbors final double tilt_cost, final double split_threshold, // if full range of the values around the cell higher, need separate fg, bg final double same_range, // modify final boolean en_normal, // expand sngle-range cells (that have all neighbors within split_threshold) final boolean en_far, // expand background - use neighbors cells within same_range from the lowest // en_near is only valid if !en_far final boolean en_near, // expand foreground - use neighbors cells within same_range from the highest final int dbg_x, final int dbg_y, final int debugLevel) { final int tilesX = tp.getTilesX(); final int tilesY = tp.getTilesY(); final int smpl_half = smpl_size / 2; // 2 // probably should not be needed final double thresholdLin = 1.0E-20; // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail) final double [] damping = {tilt_cost,tilt_cost,0.0}; // 0.0 will be applied to average value, tilt_cost - to both tilts final int center_index = smpl_half * (smpl_size + 1); // final int smpl_high = smpl_size - smpl_low; // 3 final int smpl_len = smpl_size * smpl_size; final int dbg_tile = dbg_x + tilesX * dbg_y; final double [] smpl_weights = MeasuredLayers.getSampleWindow(smpl_size, !use_wnd); final Thread[] threads = ImageDtt.newThreadArray(tp.threadsMax); final double [] max_corrs = new double [threads.length]; final AtomicInteger ai_thread = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0); final double [] new_vals = values.clone(); final int [] neib_indices = new int [8]; // indices of the sample array immediately around the center; int ni = 0; for (int sy = -1; sy < 1; sy++) { for (int sx = -1; sx < 1; sx++) { if ((sy != 0) || (sx != 0)){ neib_indices[ni++] = (smpl_half + sx) + (smpl_half + sy) * smpl_size; } } } for (int ithread = 0; ithread < threads.length; ithread++) { threads[ithread] = new Thread() { public void run() { PolynomialApproximation pa = new PolynomialApproximation(); int this_thread = ai_thread.getAndIncrement(); for (int nTile = ai.getAndIncrement(); nTile < new_vals.length; nTile = ai.getAndIncrement()) { if (new_cells[nTile]) { int dl = (nTile == dbg_tile) ? debugLevel : -1; int tileX = nTile % tilesX; int tileY = nTile / tilesX; // boolean [] smpl_new = new boolean [smpl_len]; boolean [] smpl_sel = new boolean [smpl_len]; double [] smpl_d = new double [smpl_len]; // double [] smpl_p = new double [smpl_len]; double [] smpl_w = new double [smpl_len]; int num_in_sample = 0; for (int sy = 0; sy < smpl_size; sy++) { int y = tileY + sy - smpl_half; if ((y >= 0) && (y < tilesY)) { for (int sx = 0; sx < smpl_size; sx++) { int x = tileX + sx - smpl_half; if ((x >= 0) && (x < tilesX)) { int indx = x + y * tilesX; if (!Double.isNaN(values[indx]) && (indx != center_index)){ int indxs = sx + sy * smpl_size; // double w = smpl_weights[indxs]; smpl_sel[indxs] = true; smpl_d[indxs] = values[indx]; num_in_sample++; } } } } } if (num_in_sample > 0) { // add starting from the known cells. When using 5x5 samples, having immediate neighbor // to the center usually means that likely there is enough data to determine the tilt. boolean has_neib = false; for (int i = 0; i < neib_indices.length; i++) if (smpl_sel[neib_indices[i]]) { has_neib = true; break; } boolean process_sample = false; if (has_neib) { // all conditions met, find linear 2-d damped approximation for the center // if center was NaN - diff is the absolute value. int imin = -1, imax = -1; for (int indxs = 0; indxs < smpl_len; indxs ++ ) if (smpl_sel[indxs]){ if ((imin < 0) || (smpl_d[indxs] < smpl_d[imin])) imin = indxs ; if ((imax < 0) || (smpl_d[indxs] > smpl_d[imax])) imax = indxs ; } // does it all fit if ((smpl_d[imax] - smpl_d[imin]) <= split_threshold){ process_sample = en_normal; } else { if (en_far) { double threshold = smpl_d[imax] - smpl_d[imax]; for (int indxs = 0; indxs < smpl_len; indxs ++ ) if (smpl_sel[indxs]){ if (smpl_d[indxs] < threshold) { smpl_sel[indxs] = false; num_in_sample--; } } process_sample = true; } else if (en_near){ double threshold = smpl_d[imin] + smpl_d[imax]; for (int indxs = 0; indxs < smpl_len; indxs ++ ) if (smpl_sel[indxs]){ if (smpl_d[indxs] > threshold) { smpl_sel[indxs] = false; num_in_sample--; } } process_sample = true; } // removed some points - recheck neighbors if (process_sample){ has_neib = false; for (int i = 0; i < neib_indices.length; i++) if (smpl_sel[neib_indices[i]]) { has_neib = true; break; } if (!has_neib) process_sample = false; // neighbor was removed, will process // with other direction } } } if (process_sample) { // build linear 2d approximation, damped as there could be co-linear cells // or even a single cell double sw = 0.0; double [][][] mdata = new double [num_in_sample][3][]; int mindx = 0; for (int sy = 0; sy < smpl_size; sy++){ for (int sx = 0; sx < smpl_size; sx++){ int indxs = sy * smpl_size + sx; if (smpl_sel[indxs]) { mdata[mindx][0] = new double [2]; mdata[mindx][0][0] = sx - smpl_half; // should match integer center mdata[mindx][0][1] = sy - smpl_half; 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 damping, // double [] damping, thresholdLin, // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail) 0.0, // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail) dl); // int debugLevel; if (approx2d == null) { System.out.println("A BUG in smoothNewStep() - failed quadraticApproximation()"); continue; } double new_center_val = approx2d[0][0]; // Last coefficient, F (of 6) double this_corr; if (Double.isNaN(values[nTile])) this_corr = Math.abs(new_center_val); else this_corr = Math.abs(new_center_val - values[nTile]); new_vals[nTile] = new_center_val; max_corrs[this_thread] = Math.max(max_corrs[this_thread], this_corr); } } } } } }; } System.arraycopy(new_vals, 0, values, 0, new_vals.length); double max_corr = 0; for (int i = 0; i < max_corrs.length; i++) max_corr = Math.max(max_corr,max_corrs[i]); return max_corr; } } /* 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); */ No newline at end of file
src/main/java/EyesisCorrectionParameters.java +20 −5 Original line number Original line Diff line number Diff line Loading @@ -2070,6 +2070,9 @@ public class EyesisCorrectionParameters { public double ex_strength = 0.18; // minimal 4-corr strength to trust tile 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 ex_nstrength = 0.4; // minimal 4-corr strength divided by channel diff for new (border) tiles public boolean ex_over_bgnd = false; // Allow expansion over previously identified background (infinity) public double ex_min_over = 1.0; // When expanding over background, disregard lower disparity public double pt_super_trust = 1.6; // If strength exceeds ex_strength * super_trust, do not apply ex_nstrength and plate_ds 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 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_pre = 1.5; // Scale plates strength before comparing to raw strength Loading Loading @@ -2417,7 +2420,7 @@ public class EyesisCorrectionParameters { public boolean tsLoopMulti = true; // Repeat multi-choice assignment while succeeding public boolean tsLoopMulti = true; // Repeat multi-choice assignment while succeeding public boolean tsReset = false; // Reset tiles to surfaces assignment public boolean tsReset = false; // Reset tiles to surfaces assignment public boolean tsShow = false; // Show results of tiles to surfaces assignment public boolean tsShow = false; // Show results of tiles to surfaces assignment public int tsNumClust = 50; // Number of clusters to keep public int tsNumClust = 500; // Number of clusters to keep public int tsConsensMode = 7; // Which assignments to match +1 - combo, +2 grown single, +4 plane seeds public int tsConsensMode = 7; // Which assignments to match +1 - combo, +2 grown single, +4 plane seeds public int tsConsensAgree = 1; // Minimal number of assignments to agree public int tsConsensAgree = 1; // Minimal number of assignments to agree Loading Loading @@ -2624,6 +2627,9 @@ public class EyesisCorrectionParameters { properties.setProperty(prefix+"ex_strength", this.ex_strength +""); properties.setProperty(prefix+"ex_strength", this.ex_strength +""); properties.setProperty(prefix+"ex_nstrength", this.ex_nstrength +""); properties.setProperty(prefix+"ex_nstrength", this.ex_nstrength +""); properties.setProperty(prefix+"ex_over_bgnd", this.ex_over_bgnd+""); properties.setProperty(prefix+"ex_min_over", this.ex_min_over +""); properties.setProperty(prefix+"pt_super_trust", this.pt_super_trust +""); 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_keep_raw_fg", this.pt_keep_raw_fg+""); properties.setProperty(prefix+"pt_scale_pre", this.pt_scale_pre +""); properties.setProperty(prefix+"pt_scale_pre", this.pt_scale_pre +""); Loading Loading @@ -3141,6 +3147,9 @@ 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_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+"ex_nstrength")!=null) this.ex_nstrength=Double.parseDouble(properties.getProperty(prefix+"ex_nstrength")); if (properties.getProperty(prefix+"ex_over_bgnd")!=null) this.ex_over_bgnd=Boolean.parseBoolean(properties.getProperty(prefix+"ex_over_bgnd")); if (properties.getProperty(prefix+"ex_min_over")!=null) this.ex_min_over=Double.parseDouble(properties.getProperty(prefix+"ex_min_over")); 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_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_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_pre")!=null) this.pt_scale_pre=Double.parseDouble(properties.getProperty(prefix+"pt_scale_pre")); Loading Loading @@ -3680,6 +3689,9 @@ public class EyesisCorrectionParameters { gd.addNumericField("Minimal 4-corr strength to trust tile", this.ex_strength, 3); 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.addNumericField("Minimal 4-corr strength divided by channel diff for new (border) tiles", this.ex_nstrength, 3); gd.addCheckbox ("Allow expansion over previously identified background (infinity)", this.ex_over_bgnd); gd.addNumericField("When expanding over background, disregard lower disparity ", this.ex_min_over, 3); gd.addMessage ("********* Plates filetering when building initial z-map *********"); 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.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.addCheckbox ("Do not replace raw tiles by the plates, if raw is closer (like poles)", this.pt_keep_raw_fg); Loading Loading @@ -3803,10 +3815,10 @@ public class EyesisCorrectionParameters { gd.addNumericField("Consider merging initial planes if disparity difference below", this.stSmallDiff, 6); gd.addNumericField("Consider merging initial planes if disparity difference below", this.stSmallDiff, 6); gd.addNumericField("Consider merging initial planes if jumps between ratio above", this.stHighMix, 6); gd.addNumericField("Consider merging initial planes if jumps between ratio above", this.stHighMix, 6); gd.addNumericField("Outlayer tiles weaker than this may be replaced from neighbors", this.outlayerStrength, 6); gd.addNumericField("Outlier tiles weaker than this may be replaced from neighbors", this.outlayerStrength, 6); gd.addNumericField("Replace weak outlayer tiles that do not have neighbors within this disparity difference", this.outlayerDiff, 6); gd.addNumericField("Replace weak outlier tiles that do not have neighbors within this disparity difference", this.outlayerDiff, 6); gd.addNumericField("Replace weak outlayer tiles that have higher disparity than weighted average", this.outlayerDiffPos, 6); gd.addNumericField("Replace weak outlier tiles that have higher disparity than weighted average", this.outlayerDiffPos, 6); gd.addNumericField("Replace weak outlayer tiles that have lower disparity than weighted average", this.outlayerDiffNeg, 6); gd.addNumericField("Replace weak outlier tiles that have lower disparity than weighted average", this.outlayerDiffNeg, 6); gd.addCheckbox ("Combine with all previous after refine pass", this.combine_refine); gd.addCheckbox ("Combine with all previous after refine pass", this.combine_refine); gd.addNumericField("Disregard weaker tiles when combining scans", this.combine_min_strength, 6); gd.addNumericField("Disregard weaker tiles when combining scans", this.combine_min_strength, 6); Loading Loading @@ -4222,6 +4234,9 @@ public class EyesisCorrectionParameters { this.ex_strength= gd.getNextNumber(); this.ex_strength= gd.getNextNumber(); this.ex_nstrength= gd.getNextNumber(); this.ex_nstrength= gd.getNextNumber(); this.ex_over_bgnd= gd.getNextBoolean(); this.ex_min_over= gd.getNextNumber(); this.pt_super_trust= gd.getNextNumber(); this.pt_super_trust= gd.getNextNumber(); this.pt_keep_raw_fg= gd.getNextBoolean(); this.pt_keep_raw_fg= gd.getNextBoolean(); this.pt_scale_pre= gd.getNextNumber(); this.pt_scale_pre= gd.getNextNumber(); Loading
src/main/java/LinkPlanes.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -3879,7 +3879,7 @@ public class LinkPlanes { weak_pairs, // final boolean [][] weak_fg_pairs, weak_pairs, // final boolean [][] weak_fg_pairs, 1.0, // double relax, 1.0, // double relax, plWeakFgRelax, // final double relax_weak_fg, plWeakFgRelax, // final double relax_weak_fg, debugLevel, // final int debugLevel) 1+ debugLevel, // final int debugLevel) dbg_tileX, dbg_tileX, dbg_tileY); dbg_tileY); // Calculate costs of merging planes of the same supertile and remove those that are exceed threshold // Calculate costs of merging planes of the same supertile and remove those that are exceed threshold Loading
src/main/java/MeasuredLayers.java +40 −4 Original line number Original line Diff line number Diff line Loading @@ -337,7 +337,7 @@ public class MeasuredLayers { * @return [smplSide * smplSide]array of weights, 1.0 in the center * @return [smplSide * smplSide]array of weights, 1.0 in the center */ */ public double [] getSampleWindow(int smplSide, boolean all1){ static double [] getSampleWindow(int smplSide, boolean all1){ double [] weights = new double [smplSide * smplSide]; double [] weights = new double [smplSide * smplSide]; for (int sy = 0; sy < smplSide; sy++){ for (int sy = 0; sy < smplSide; sy++){ for (int sx = 0; sx < smplSide; sx++){ for (int sx = 0; sx < smplSide; sx++){ Loading Loading @@ -898,6 +898,9 @@ public class MeasuredLayers { boolean null_if_none, boolean null_if_none, int debugLevel) int debugLevel) { { boolean use_new = true; // false; if (use_new) { return getDisparityStrength ( return getDisparityStrength ( num_layer, // int num_layer, num_layer, // int num_layer, stX, // int stX, stX, // int stX, Loading @@ -914,6 +917,25 @@ public class MeasuredLayers { 0.2, // double max_rel_tilt, // = 0.2; // (pix / disparity) per tile 0.2, // double max_rel_tilt, // = 0.2; // (pix / disparity) per tile null_if_none, // boolean null_if_none, null_if_none, // boolean null_if_none, debugLevel); // int debugLevel) debugLevel); // int debugLevel) } else { return getDisparityStrength_old ( 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 ( public double[][] getDisparityStrength ( Loading @@ -921,7 +943,9 @@ public class MeasuredLayers { int stX, int stX, int stY, int stY, boolean [] sel_in, boolean [] sel_in, double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values double [][] atiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values // if it has just one element - apply to all tiles, otherwise it is supposed // to be per-tile of a supertile array double strength_floor, double strength_floor, double strength_pow, double strength_pow, int smplSide, // = 2; // Sample size (side of a square) int smplSide, // = 2; // Sample size (side of a square) Loading Loading @@ -1018,7 +1042,7 @@ public class MeasuredLayers { if (num_in_sample >= smplNum){ // try, remove worst if (num_in_sample >= smplNum){ // try, remove worst sample_loop: sample_loop: { { boolean en_tilt = (tiltXY == null); boolean en_tilt = (atiltXY == null); if (en_tilt) { // make sure there are enough samples and not all of them are on the same line if (en_tilt) { // make sure there are enough samples and not all of them are on the same line if (!notColinear(smpl_sel,smplSide)){ if (!notColinear(smpl_sel,smplSide)){ en_tilt = false; en_tilt = false; Loading Loading @@ -1128,7 +1152,10 @@ public class MeasuredLayers { } } } } if (iworst < 0){ if (iworst < 0){ System.out.println("**** this is a BUG in getDisparityStrength() can not find the worst sample ****"); if (debugLevel > 0) { System.out.println("**** this may be BUG in getDisparityStrength() can not find the worst sample - all tiles fit perfectly ****"); } // this can happen if some samples are the same and all the pixels fit exactly - use all of them break; break; } } // remove worst sample // remove worst sample Loading Loading @@ -1158,6 +1185,15 @@ public class MeasuredLayers { } else { // fixed tilt } else { // fixed tilt // tilt around center // tilt around center double [] tiltXY= {0.0,0.0}; if (atiltXY != null){ // if null ( free but failed co-linear test - keep both tilts == 0.0 if (atiltXY.length == 1){ tiltXY = atiltXY[0]; // common for all tiles (such as constant disparity) } else if (atiltXY[indx] != null){ tiltXY = atiltXY[indx]; } } if ((tiltXY != null) && (tiltXY[0] != 0.0) && (tiltXY[1] != 0.0)){ if ((tiltXY != null) && (tiltXY[0] != 0.0) && (tiltXY[1] != 0.0)){ for (int sy = 0; sy < smplSide; sy++){ for (int sy = 0; sy < smplSide; sy++){ for (int sx = 0; sx < smplSide; sx++){ for (int sx = 0; sx < smplSide; sx++){ Loading