Loading src/main/java/AlignmentCorrection.java +197 −62 Original line number Original line Diff line number Diff line Loading @@ -153,6 +153,7 @@ public class AlignmentCorrection { tilesX, tilesX, magic_coeff, // still not understood coefficient that reduces reported disparity value. Seems to be around 8.5 magic_coeff, // still not understood coefficient that reduces reported disparity value. Seems to be around 8.5 debugLevel); debugLevel); /* double [][][] disparity_corr_coefficiants = null; double [][][] disparity_corr_coefficiants = null; if (clt_parameters.inf_disp_apply) { if (clt_parameters.inf_disp_apply) { disparity_corr_coefficiants = infinityCorrection( disparity_corr_coefficiants = infinityCorrection( Loading @@ -176,11 +177,13 @@ public class AlignmentCorrection { "");// String prefix) "");// String prefix) } } } } if (clt_parameters.inf_mism_apply) { */ double [][][] mismatch_corr_coefficiants = infinityMismatchCorrection( double [][][] mismatch_corr_coefficiants = null; clt_parameters.fcorr_quadratic,// final boolean use_quadratic, // if (clt_parameters.inf_disp_apply) { mismatch_corr_coefficiants = infinityMismatchCorrection( clt_parameters.fcorr_inf_quad, // final boolean use_quadratic, clt_parameters.fcorr_inf_vert, // final boolean use_vertical, clt_parameters.fcorr_inf_vert, // final boolean use_vertical, !clt_parameters.inf_disp_apply, // final boolean use_disparity, // for infinity clt_parameters.ly_inf_en, // final boolean use_disparity, // for infinity clt_parameters, clt_parameters, disp_strength, disp_strength, samples_list, samples_list, Loading @@ -193,6 +196,7 @@ public class AlignmentCorrection { mismatch_corr_coefficiants, // double [][][] corr, mismatch_corr_coefficiants, // double [][][] corr, "");// String prefix) "");// String prefix) } } /* if (disparity_corr_coefficiants == null) { if (disparity_corr_coefficiants == null) { disparity_corr_coefficiants = mismatch_corr_coefficiants; disparity_corr_coefficiants = mismatch_corr_coefficiants; if (debugLevel > -1){ if (debugLevel > -1){ Loading @@ -211,8 +215,9 @@ public class AlignmentCorrection { System.out.println("infinityCorrection(): combining coefficient increments from infinityCorrection and infinityMismatchCorrection"); System.out.println("infinityCorrection(): combining coefficient increments from infinityCorrection and infinityMismatchCorrection"); } } } } } */ return disparity_corr_coefficiants; // } return mismatch_corr_coefficiants; } } /** /** Loading Loading @@ -622,7 +627,7 @@ public class AlignmentCorrection { Matrix AINV = A.inverse(); Matrix AINV = A.inverse(); double scale = 0.5/magic_coeff; double scale = 0.5/magic_coeff; double [][] dbg_xy = null; double [][] dbg_xy = null; if (debugLevel > -1) { if (debugLevel > 0) { dbg_xy = new double [9][num_tiles]; dbg_xy = new double [9][num_tiles]; } } for (Sample s: samples_list){ for (Sample s: samples_list){ Loading Loading @@ -1167,10 +1172,12 @@ public class AlignmentCorrection { double sdw = 0.0, sw = 0.0; double sdw = 0.0, sw = 0.0; double [] sm = new double [NUM_SLICES - 2]; double [] sm = new double [NUM_SLICES - 2]; for (int sY = 0; sY < smpl_side; sY++){ for (int sY = -smpl_side/2; sY < smpl_side/2; sY++){ int y = tY + sY; int y = tY + sY; for (int sX = 0; sX < smpl_side; sX++){ if ((y >= 0) && (y <tilesY)) { for (int sX = -smpl_side/2; sX < smpl_side/2; sX++){ int x = tX + sX; int x = tX + sX; if ((x >= 0) && (x <tilesX)) { int nTile = y * tilesX + x; int nTile = y * tilesX + x; double w = disp_strength_in[1][nTile]; double w = disp_strength_in[1][nTile]; if (w > 0.0){ if (w > 0.0){ Loading @@ -1185,6 +1192,8 @@ public class AlignmentCorrection { } } } } } } } } if ((num_samples > min_samples) && (sw > 0.0)){ if ((num_samples > min_samples) && (sw > 0.0)){ int nTile = tY * tilesX + tX; int nTile = tY * tilesX + tX; disp_strength[0][nTile] = sdw/sw; // weighted average disparity disp_strength[0][nTile] = sdw/sw; // weighted average disparity Loading Loading @@ -1370,7 +1379,77 @@ public class AlignmentCorrection { } } } } public double [][] getFineCorrFromImage( public double [][] getDoubleFromImage( ImagePlus imp_src, int debugLevel) { // double min_max_ratio = 1.3; ImageStack clt_mismatches_stack= imp_src.getStack(); final int tilesX = clt_mismatches_stack.getWidth(); // tp.getTilesX(); final int tilesY = clt_mismatches_stack.getHeight(); // tp.getTilesY(); final int nTiles =tilesX * tilesY; final double [][] data = new double [clt_mismatches_stack.getSize()][nTiles]; for (int n = 0; n < data.length; n++) { float [] fpixels = (float[]) clt_mismatches_stack.getPixels(n +1); for (int i = 0; i < nTiles; i++){ data[n][i] = fpixels[i]; } } return data; } public double [][] getFineCorrFromDoubleArray( double [][] data, int tilesX, int debugLevel) { // double min_max_ratio = 1.3; final int tilesY = data[0].length/tilesX; // tp.getTilesY(); final int nTiles =tilesX * tilesY; final int num_scans = data.length/NUM_ALL_SLICES; final double [][] scans = new double [num_scans * NUM_ALL_SLICES][nTiles]; for (int ns = 0; ns < num_scans; ns++){ // double [][]min_max_strength = new double[2][nTiles]; for (int pair = 0; pair < 4; pair++){ float [][] fset = new float [3][]; // fset[0] = (float[]) clt_mismatches_stack.getPixels(12 * num_scans + ns +1); // fset[1] = (float[]) clt_mismatches_stack.getPixels(13 * num_scans + ns +1); // scans[ns * NUM_ALL_SLICES + 0] = data[12 * num_scans + ns]; scans[ns * NUM_ALL_SLICES + 1] = data[13 * num_scans + ns]; // for (int i = 0; i < nTiles; i++){ // scans[ns * NUM_ALL_SLICES + 0][i] = fset[0][i]; // disparity // scans[ns * NUM_ALL_SLICES + 1][i] = fset[1][i]; // strength // } // fset[0] = (float[]) clt_mismatches_stack.getPixels((2 * pair + 0) * num_scans + ns +1); // fset[1] = (float[]) clt_mismatches_stack.getPixels((2 * pair + 1) * num_scans + ns +1); // // fset[2] = (float[]) clt_mismatches_stack.getPixels((8 + pair ) * num_scans + ns +1); scans[ns * NUM_ALL_SLICES + pair * 3 + 2] = data[(2 * pair + 0) * num_scans + ns]; scans[ns * NUM_ALL_SLICES + pair * 3 + 3] = data[(2 * pair + 1) * num_scans + ns]; scans[ns * NUM_ALL_SLICES + pair * 3 + 4] = data[(8 + pair ) * num_scans + ns]; // for (int i = 0; i < nTiles; i++){ // scans[ns * NUM_ALL_SLICES + pair * 3 + 2][i] = fset[0][i]; // dx_i // scans[ns * NUM_ALL_SLICES + pair * 3 + 3][i] = fset[1][i]; // dy_i // scans[ns * NUM_ALL_SLICES + pair * 3 + 4][i] = fset[2][i]; // str_i // } } } if (debugLevel > 0) { String [] prefixes = {"disparity", "strength", "dx0", "dy0", "str0", "dx1", "dy1", "str1", "dx2", "dy2", "str2", "dx3", "dy3", "str3"}; String [] titles = new String [num_scans * NUM_ALL_SLICES]; for (int ns = 0; ns < num_scans; ns++){ for (int i = 0; i < NUM_ALL_SLICES; i++){ titles[ns * NUM_ALL_SLICES + i] = prefixes[i]+"_"+ns; } } (new showDoubleFloatArrays()).showArrays(scans, tilesX, tilesY, true, "scans" , titles); } return scans; } public double [][] getFineCorrFromImage_old( ImagePlus imp_src, ImagePlus imp_src, int debugLevel) int debugLevel) { { Loading @@ -1397,28 +1476,13 @@ public class AlignmentCorrection { fset[1] = (float[]) clt_mismatches_stack.getPixels((2 * pair + 1) * num_scans + ns +1); // fset[1] = (float[]) clt_mismatches_stack.getPixels((2 * pair + 1) * num_scans + ns +1); // fset[2] = (float[]) clt_mismatches_stack.getPixels((8 + pair ) * num_scans + ns +1); fset[2] = (float[]) clt_mismatches_stack.getPixels((8 + pair ) * num_scans + ns +1); for (int i = 0; i < nTiles; i++){ for (int i = 0; i < nTiles; i++){ // if (i == 55156) { // 52564){ // System.out.println("tile="+i+" scan="+ns+" pair = "+pair+ "fset[2]["+i+"]="+fset[2][i]); // } scans[ns * NUM_ALL_SLICES + pair * 3 + 2][i] = fset[0][i]; // dx_i scans[ns * NUM_ALL_SLICES + pair * 3 + 2][i] = fset[0][i]; // dx_i scans[ns * NUM_ALL_SLICES + pair * 3 + 3][i] = fset[1][i]; // dy_i scans[ns * NUM_ALL_SLICES + pair * 3 + 3][i] = fset[1][i]; // dy_i scans[ns * NUM_ALL_SLICES + pair * 3 + 4][i] = fset[2][i]; // str_i scans[ns * NUM_ALL_SLICES + pair * 3 + 4][i] = fset[2][i]; // str_i // if ((pair == 0) || (fset[2][i] < min_max_strength[0][i])) min_max_strength[0][i] = fset[2][i]; // if ((pair == 0) || (fset[2][i] > min_max_strength[1][i])) min_max_strength[1][i] = fset[2][i]; // if (fset[2][i] < min_comp_strength) { // scans[ns * NUM_SLICES + 1][i] = -1.0; // -1.0 - temporary to indicate // }; } } } } // for (int i = 0; i < nTiles; i++){ // if (min_max_strength[1][i] > (min_max_ratio * min_max_strength[0][i]) ){ // scans[ns * NUM_SLICES + 1][i] = -1.0; // -1.0 - temporary to indicate // } // } } } if (debugLevel > -1) { if (debugLevel > -1) { // String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "str0", "dx1", "dy1", "str1", "dx2", "dy2", "str2", "dx3", "dy3", "str3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "str0", "dx1", "dy1", "str1", "dx2", "dy2", "str2", "dx3", "dy3", "str3"}; String [] titles = new String [num_scans * NUM_ALL_SLICES]; String [] titles = new String [num_scans * NUM_ALL_SLICES]; for (int ns = 0; ns < num_scans; ns++){ for (int ns = 0; ns < num_scans; ns++){ Loading @@ -1436,7 +1500,7 @@ public class AlignmentCorrection { public double [][][] lazyEyeCorrection( public double [][][] lazyEyeCorrection( final double min_strength_in, final double min_strength_in, final double max_diff, final double max_diff, final double comp_strength_var, // final double comp_strength_var, final int max_iterations, final int max_iterations, final double max_coeff_diff, final double max_coeff_diff, final double far_pull, // = 0.2; // 1; // 0.5; final double far_pull, // = 0.2; // 1; // 0.5; Loading Loading @@ -1475,6 +1539,10 @@ public class AlignmentCorrection { scans[ns * NUM_SLICES + i] = scans_14[ns * NUM_ALL_SLICES + indices_14_10[i]]; scans[ns * NUM_SLICES + i] = scans_14[ns * NUM_ALL_SLICES + indices_14_10[i]]; } } } } // (new showDoubleFloatArrays()).showArrays(scans_14, tilesX, tilesY, true, "scans14"); // (new showDoubleFloatArrays()).showArrays(scans, tilesX, tilesY, true, "scans10"); for (int ns = 0; ns < num_scans; ns++){ for (int ns = 0; ns < num_scans; ns++){ for (int nTile = 0; nTile < num_tiles; nTile++){ for (int nTile = 0; nTile < num_tiles; nTile++){ double s1=0.0, s2=0.0; double s1=0.0, s2=0.0; Loading Loading @@ -1510,7 +1578,7 @@ public class AlignmentCorrection { * None of comp_strength_rms methods works to detect potential outliers for horizontal/vertical features * None of comp_strength_rms methods works to detect potential outliers for horizontal/vertical features */ */ if (debugLevel > -1) { if (debugLevel > 0) { String [] titles = new String [num_scans]; String [] titles = new String [num_scans]; for (int ns = 0; ns < num_scans; ns++){ for (int ns = 0; ns < num_scans; ns++){ titles[ns] = "scan_" + ns; titles[ns] = "scan_" + ns; Loading @@ -1529,18 +1597,9 @@ public class AlignmentCorrection { tilesX);// final int tilesX); tilesX);// final int tilesX); if (debugLevel > -1) { if (debugLevel > -1) { System.out.println("lazyEyeCorrection() 1: removing tile with residual disparity absoulte value > "+lazyEyeCompDiff); System.out.println("lazyEyeCorrection() 1: removing tiles with residual disparity absoulte value > "+lazyEyeCompDiff); } } /* for (int ns = 0; ns < num_scans; ns++){ for (int i = 0; i < num_tiles; i++){ double disp = filtered_scans[ns * NUM_SLICES + 0][i]; if (Math.abs(disp) > lazyEyeCompDiff) { filtered_scans[ns * NUM_SLICES + 1][i] = 0.0; } } } */ double [][] combo_mismatch = new double [NUM_SLICES][num_tiles]; double [][] combo_mismatch = new double [NUM_SLICES][num_tiles]; double [] combo_comp_rms = new double [num_tiles]; double [] combo_comp_rms = new double [num_tiles]; for (int ns = 0; ns < num_scans; ns++){ for (int ns = 0; ns < num_scans; ns++){ Loading Loading @@ -1598,7 +1657,7 @@ public class AlignmentCorrection { } } } } if (debugLevel > -1) { if (debugLevel > 0) { String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; (new showDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "combo_mismatch" , prefixes); (new showDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "combo_mismatch" , prefixes); } } Loading @@ -1612,7 +1671,7 @@ public class AlignmentCorrection { true, // final boolean norm_center, // if there are more tiles that fit than minsamples, replace with a single equal weight true, // final boolean norm_center, // if there are more tiles that fit than minsamples, replace with a single equal weight tilesX); // final int tilesX); tilesX); // final int tilesX); if (debugLevel > -1) { if (debugLevel > 0) { String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; (new showDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "filtered_mismatch" , prefixes); (new showDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "filtered_mismatch" , prefixes); } } Loading Loading @@ -1666,7 +1725,7 @@ public class AlignmentCorrection { hist_min_samples, // final int min_samples, hist_min_samples, // final int min_samples, hist_norm_center, // final boolean norm_center, // if there are more tiles that fit than minsamples, replace with hist_norm_center, // final boolean norm_center, // if there are more tiles that fit than minsamples, replace with tilesX); // final int tilesX) tilesX); // final int tilesX) if (debugLevel > 0){ if (debugLevel > 1){ double [][] dbg_img = inf_scan.clone(); double [][] dbg_img = inf_scan.clone(); for (int n = 0; n < inf_scan.length; n++){ for (int n = 0; n < inf_scan.length; n++){ dbg_img[n] = inf_scan[n].clone(); dbg_img[n] = inf_scan[n].clone(); Loading @@ -1689,7 +1748,7 @@ public class AlignmentCorrection { } } if (debugLevel > -1) { if (debugLevel > 0) { String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] titles = new String [2 * NUM_SLICES]; String [] titles = new String [2 * NUM_SLICES]; for (int i = 0; i < NUM_SLICES; i++){ for (int i = 0; i < NUM_SLICES; i++){ Loading Loading @@ -1805,7 +1864,7 @@ public class AlignmentCorrection { } } if (debugLevel > -1) { if (debugLevel > 0) { String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] titles = new String [num_scans * NUM_SLICES]; String [] titles = new String [num_scans * NUM_SLICES]; for (int ns = 0; ns < num_scans; ns++){ for (int ns = 0; ns < num_scans; ns++){ Loading @@ -1817,7 +1876,7 @@ public class AlignmentCorrection { } } if (debugLevel > -1) { if (debugLevel > 0) { String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; (new showDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "combo_mismatch" , prefixes); (new showDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "combo_mismatch" , prefixes); } } Loading @@ -1842,7 +1901,83 @@ public class AlignmentCorrection { return mismatch_corr_coefficiants; return mismatch_corr_coefficiants; } } public double [][] combineCltMismatches( EyesisCorrectionParameters.CLTParameters clt_parameters, double [][][] clt_mismatches, double [][][] disparity_maps, int disparity_index, int strength_index) { int n = clt_mismatches.length; double [][] combo = new double [clt_parameters.disp_scan_count * AlignmentCorrection.NUM_ALL_SLICES][]; for (int pair = 0; pair < 4; pair++){ for (int i = 0; i < n; i++){ combo[(2 * pair + 0) * n + i] = clt_mismatches[i][3 * pair + 0]; combo[(2 * pair + 1) * n + i] = clt_mismatches[i][3 * pair + 1]; combo[(2 * 4 + pair) * n + i] = clt_mismatches[i][3 * pair + 2]; } } for (int i = 0; i < n; i++){ combo[12 * n + i] = disparity_maps[i][disparity_index]; combo[13 * n + i] = disparity_maps[i][strength_index]; } return combo; } public void showCltMismatches( String title, EyesisCorrectionParameters.CLTParameters clt_parameters, double [][] combo_data, int tilesX, int tilesY) { showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); String [] titles = new String [combo_data.length]; int num_scans = combo_data.length / AlignmentCorrection.NUM_ALL_SLICES; for (int pair = 0; pair < 4; pair++){ for (int i = 0; i < num_scans; i++){ double disparity = clt_parameters.disp_scan_start + i * clt_parameters.disp_scan_step; titles[(2 * pair + 0) * num_scans + i] = "dx_"+pair+"_"+disparity; titles[(2 * pair + 1) * num_scans + i] = "dy_"+pair+"_"+disparity; titles[(2 * 4 + pair) * num_scans + i] = "strength_"+pair+"_"+disparity; } } for (int i = 0; i < num_scans; i++){ double disparity = clt_parameters.disp_scan_start + i * clt_parameters.disp_scan_step; titles[ 12 * num_scans + i] = "disp_"+disparity; titles[ 13 * num_scans + i] = "strength_"+disparity; } sdfa_instance.showArrays(combo_data, tilesX,tilesY, true, title, titles); } public void showCltMismatch( String title, EyesisCorrectionParameters.CLTParameters clt_parameters, double [][] clt_mismatch, int tilesX, int tilesY) { showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); String [] titles = new String [12]; double [][] dbg_clt_mismatch= new double [12][]; for (int pair = 0; pair < 4; pair++){ titles[2 * pair + 0] = "dx_"+pair; titles[2 * pair + 1] = "dy_"+pair; titles[2 * 4 + pair] = "strength_"+pair; dbg_clt_mismatch[(2 * pair + 0)] = clt_mismatch[3 * pair + 0].clone(); dbg_clt_mismatch[(2 * pair + 1)] = clt_mismatch[3 * pair + 1].clone(); dbg_clt_mismatch[(2 * 4 + pair)] = clt_mismatch[3 * pair + 2]; for (int i = 0; i < dbg_clt_mismatch[(2 * 4 + pair)].length; i++ ){ if (dbg_clt_mismatch[(2 * 4 + pair)][i] == 0.0){ dbg_clt_mismatch[(2 * pair + 0)][i] = Double.NaN; dbg_clt_mismatch[(2 * pair + 1)][i] = Double.NaN; } } } sdfa_instance.showArrays(dbg_clt_mismatch, tilesX, tilesY, true, title, titles); } public void process_fine_corr( public void process_fine_corr( Loading src/main/java/CLTPass3d.java +173 −7 Original line number Original line Diff line number Diff line Loading @@ -51,7 +51,7 @@ public class CLTPass3d{ public boolean [] border_tiles = null; // these are border tiles, zero out alpha public boolean [] border_tiles = null; // these are border tiles, zero out alpha public boolean [] selected = null; // which tiles are selected for this layer public boolean [] selected = null; // which tiles are selected for this layer public double [][][][] texture_tiles; public double [][][][] texture_tiles; public double [][] max_tried_disparity = null; //[ty][tx] used for combined passes, shows maximal disparity wor this tile, regardless of results public double [][] max_tried_disparity = null; //[ty][tx] used for combined passes, shows maximal disparity for this tile, regardless of results public boolean is_combo = false; public boolean is_combo = false; public boolean is_measured = false; public boolean is_measured = false; public String texture = null; // relative (to x3d) path public String texture = null; // relative (to x3d) path Loading Loading @@ -190,6 +190,7 @@ public class CLTPass3d{ */ */ public double [][] getDiffs (){ public double [][] getDiffs (){ if (disparity_map == null) return null; double [][] these_diffs = new double[ImageDtt.QUAD][]; double [][] these_diffs = new double[ImageDtt.QUAD][]; for (int i = 0; i< ImageDtt.QUAD; i++) these_diffs[i] = disparity_map[ImageDtt.IMG_DIFF0_INDEX + i]; for (int i = 0; i< ImageDtt.QUAD; i++) these_diffs[i] = disparity_map[ImageDtt.IMG_DIFF0_INDEX + i]; return these_diffs; return these_diffs; Loading @@ -208,6 +209,10 @@ public class CLTPass3d{ return selected; return selected; } } public boolean [] getBorderTiles(){ return this.border_tiles; } public void setSelected (boolean [] selected) { public void setSelected (boolean [] selected) { this.selected = selected; this.selected = selected; } } Loading Loading @@ -444,7 +449,7 @@ public class CLTPass3d{ * Replaces current combo disparity for tiles that are weak and do not have any neighbor within disparity range from this one * Replaces current combo disparity for tiles that are weak and do not have any neighbor within disparity range from this one * @param selection optional boolean mask of tiles to use/update * @param selection optional boolean mask of tiles to use/update * @param weakStrength maximal strength of the tile to be considered weak one * @param weakStrength maximal strength of the tile to be considered weak one * @param maxDiff maximal difference from the most similar neighbor to be considered an outlayer * @param maxDiff maximal difference from the most similar neighbor to be considered an outlier * @param disparityFar minimal acceptable disparity for weak tiles * @param disparityFar minimal acceptable disparity for weak tiles * @param disparityNear maximal acceptable disparity for weak tiles * @param disparityNear maximal acceptable disparity for weak tiles * @return mask of weak (replaced) tiles * @return mask of weak (replaced) tiles Loading @@ -455,8 +460,8 @@ public class CLTPass3d{ final boolean [] selection, final boolean [] selection, final double weakStrength, // strength to be considered weak, subject to this replacement final double weakStrength, // strength to be considered weak, subject to this replacement final double maxDiff, final double maxDiff, final double maxDiffPos, // Replace weak outlayer tiles that have higher disparity than weighted average final double maxDiffPos, // Replace weak outlier tiles that have higher disparity than weighted average final double maxDiffNeg, // Replace weak outlayer tiles that have lower disparity than weighted average final double maxDiffNeg, // Replace weak outlier tiles that have lower disparity than weighted average final double disparityFar, final double disparityFar, final double disparityNear, final double disparityNear, final int debugLevel) final int debugLevel) Loading @@ -474,7 +479,7 @@ public class CLTPass3d{ final double absMaxDisparity = 1.5 * disparityNear; // change? final double absMaxDisparity = 1.5 * disparityNear; // change? final int dbg_nTile = (debugLevel > 0) ? 43493: -1; // x=77,y=134; // 42228; // x = 108, y = 130 46462; // 41545; final int dbg_nTile = (debugLevel > 0) ? 43493: -1; // x=77,y=134; // 42228; // x = 108, y = 130 46462; // 41545; final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.threadsMax); final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.threadsMax); // first pass = find outlayers // first pass = find outliers final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0); for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) { threads[ithread] = new Thread() { threads[ithread] = new Thread() { Loading Loading @@ -507,7 +512,7 @@ public class CLTPass3d{ sw += w; sw += w; sd += w * disparity[nTile1]; sd += w * disparity[nTile1]; hasNeighbors = true; hasNeighbors = true; if (Math.abs(disparity[nTile]-disparity[nTile1]) <= maxDiff){ // any outlayer - will be false if (Math.abs(disparity[nTile]-disparity[nTile1]) <= maxDiff){ // any outlier - will be false weakOutlayers[nTile] = false; weakOutlayers[nTile] = false; // break; // break; } } Loading @@ -531,7 +536,7 @@ public class CLTPass3d{ } } ImageDtt.startAndJoin(threads); ImageDtt.startAndJoin(threads); // second pass - replace outlayers // second pass - replace outliers final double [] src_disparity = disparity.clone(); final double [] src_disparity = disparity.clone(); ai.set(0); ai.set(0); for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) { Loading Loading @@ -580,6 +585,167 @@ public class CLTPass3d{ return weakOutlayers; return weakOutlayers; } } public boolean [] getUntestedBackgroundBorder ( final boolean [] known, final double [] disparity, final double grow_disp_step, final int debugLevel) { final int tilesX = tileProcessor.getTilesX(); final int tilesY = tileProcessor.getTilesY(); final int num_tiles = tilesX * tilesY; final TileNeibs tnImage = new TileNeibs(tilesX, tilesY); // num_tiles/tilesX); final boolean [] untested_bgnd = new boolean [num_tiles]; final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.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 < num_tiles; nTile = ai.getAndIncrement()) { if (known[nTile]){ int tX = nTile % tilesX; int tY = nTile / tilesX; double max_disp = max_tried_disparity[tY][tX] + grow_disp_step; for (int dir = 0; dir < 8; dir++){ int nTile1 = tnImage.getNeibIndex(nTile, dir); if ((nTile1 >=0) && known[nTile1] && (disparity[nTile1] > max_disp)) { untested_bgnd[nTile] = true; break; } } } } } }; } ImageDtt.startAndJoin(threads); return untested_bgnd; } public boolean [] measuredTiles () { final int tilesX = tileProcessor.getTilesX(); final int tilesY = tileProcessor.getTilesY(); final int num_tiles = tilesX * tilesY; final boolean [] measured = new boolean [num_tiles]; final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.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 < num_tiles; nTile = ai.getAndIncrement()) { int tX = nTile % tilesX; int tY = nTile / tilesX; measured[nTile] = tile_op[tY][tX] != 0; } } }; } ImageDtt.startAndJoin(threads); return measured; } public double [] getSecondMaxDiff ( final boolean averaged) { final double [][] diffs = getDiffs(); if (diffs == null) return null; final int tilesX = tileProcessor.getTilesX(); final int tilesY = tileProcessor.getTilesY(); final int num_tiles = tilesX * tilesY; final double [] second_max = new double [num_tiles]; final boolean [] measured = measuredTiles (); final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.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 < num_tiles; nTile = ai.getAndIncrement()) { int imax1 = 0; for (int ip = 1; ip < diffs.length; ip++){ if (diffs[ip][nTile] > diffs[imax1][nTile]) imax1 = ip; } int imax2 = (imax1 == 0)? 1 : 0; for (int ip = 0; ip < diffs.length; ip++) if (ip != imax1) { if (diffs[ip][nTile] > diffs[imax2][nTile]) imax2 = ip; } second_max[nTile] = diffs[imax2][nTile]; } } }; } ImageDtt.startAndJoin(threads); if (!averaged) return second_max; final TileNeibs tnImage = new TileNeibs(tilesX, tilesY); // num_tiles/tilesX); final double [] second_max_averaged = new double [num_tiles]; final double [] dir_weights = {1.0/16, 1.0/8, 1.0/16, 1.0/8, 1.0/16, 1.0/8, 1.0/16, 1.0/8, 1.0/4}; ai.set(0); for (int ithread = 0; ithread < threads.length; ithread++) { threads[ithread] = new Thread() { public void run() { for (int nTile = ai.getAndIncrement(); nTile < num_tiles; nTile = ai.getAndIncrement()) if (measured[nTile]) { double sw = 0.0; double swd = 0.0; for (int dir = 0; dir < 9; dir++){ // including 8 - center int nTile1 = tnImage.getNeibIndex(nTile, dir); if ((nTile1 >=0) && measured[nTile1]) { sw += dir_weights[dir]; swd += dir_weights[dir] * second_max[nTile1] ; } } second_max_averaged[nTile] = swd/sw; } } }; } ImageDtt.startAndJoin(threads); return second_max_averaged; } // same, but 2 steps around public boolean [] getUntestedBackgroundBorder2 ( final boolean [] known, final double [] disparity, final double grow_disp_step, final int debugLevel) { final int tilesX = tileProcessor.getTilesX(); final int tilesY = tileProcessor.getTilesY(); final int num_tiles = tilesX * tilesY; final TileNeibs tnImage = new TileNeibs(tilesX, tilesY); // num_tiles/tilesX); final boolean [] untested_bgnd = new boolean [num_tiles]; final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.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 < num_tiles; nTile = ai.getAndIncrement()) { if (known[nTile]){ int tX = nTile % tilesX; int tY = nTile / tilesX; double max_disp = max_tried_disparity[tY][tX] + grow_disp_step; for (int dir = 0; dir < 24; dir++){ int nTile1 = tnImage.getNeibIndex2(nTile, dir); if ((nTile1 >=0) && known[nTile1] && (disparity[nTile1] > max_disp)) { untested_bgnd[nTile] = true; break; } } } } } }; } ImageDtt.startAndJoin(threads); return untested_bgnd; } public SuperTiles getSuperTiles() public SuperTiles getSuperTiles() { { return this.superTiles; return this.superTiles; Loading Loading
src/main/java/AlignmentCorrection.java +197 −62 Original line number Original line Diff line number Diff line Loading @@ -153,6 +153,7 @@ public class AlignmentCorrection { tilesX, tilesX, magic_coeff, // still not understood coefficient that reduces reported disparity value. Seems to be around 8.5 magic_coeff, // still not understood coefficient that reduces reported disparity value. Seems to be around 8.5 debugLevel); debugLevel); /* double [][][] disparity_corr_coefficiants = null; double [][][] disparity_corr_coefficiants = null; if (clt_parameters.inf_disp_apply) { if (clt_parameters.inf_disp_apply) { disparity_corr_coefficiants = infinityCorrection( disparity_corr_coefficiants = infinityCorrection( Loading @@ -176,11 +177,13 @@ public class AlignmentCorrection { "");// String prefix) "");// String prefix) } } } } if (clt_parameters.inf_mism_apply) { */ double [][][] mismatch_corr_coefficiants = infinityMismatchCorrection( double [][][] mismatch_corr_coefficiants = null; clt_parameters.fcorr_quadratic,// final boolean use_quadratic, // if (clt_parameters.inf_disp_apply) { mismatch_corr_coefficiants = infinityMismatchCorrection( clt_parameters.fcorr_inf_quad, // final boolean use_quadratic, clt_parameters.fcorr_inf_vert, // final boolean use_vertical, clt_parameters.fcorr_inf_vert, // final boolean use_vertical, !clt_parameters.inf_disp_apply, // final boolean use_disparity, // for infinity clt_parameters.ly_inf_en, // final boolean use_disparity, // for infinity clt_parameters, clt_parameters, disp_strength, disp_strength, samples_list, samples_list, Loading @@ -193,6 +196,7 @@ public class AlignmentCorrection { mismatch_corr_coefficiants, // double [][][] corr, mismatch_corr_coefficiants, // double [][][] corr, "");// String prefix) "");// String prefix) } } /* if (disparity_corr_coefficiants == null) { if (disparity_corr_coefficiants == null) { disparity_corr_coefficiants = mismatch_corr_coefficiants; disparity_corr_coefficiants = mismatch_corr_coefficiants; if (debugLevel > -1){ if (debugLevel > -1){ Loading @@ -211,8 +215,9 @@ public class AlignmentCorrection { System.out.println("infinityCorrection(): combining coefficient increments from infinityCorrection and infinityMismatchCorrection"); System.out.println("infinityCorrection(): combining coefficient increments from infinityCorrection and infinityMismatchCorrection"); } } } } } */ return disparity_corr_coefficiants; // } return mismatch_corr_coefficiants; } } /** /** Loading Loading @@ -622,7 +627,7 @@ public class AlignmentCorrection { Matrix AINV = A.inverse(); Matrix AINV = A.inverse(); double scale = 0.5/magic_coeff; double scale = 0.5/magic_coeff; double [][] dbg_xy = null; double [][] dbg_xy = null; if (debugLevel > -1) { if (debugLevel > 0) { dbg_xy = new double [9][num_tiles]; dbg_xy = new double [9][num_tiles]; } } for (Sample s: samples_list){ for (Sample s: samples_list){ Loading Loading @@ -1167,10 +1172,12 @@ public class AlignmentCorrection { double sdw = 0.0, sw = 0.0; double sdw = 0.0, sw = 0.0; double [] sm = new double [NUM_SLICES - 2]; double [] sm = new double [NUM_SLICES - 2]; for (int sY = 0; sY < smpl_side; sY++){ for (int sY = -smpl_side/2; sY < smpl_side/2; sY++){ int y = tY + sY; int y = tY + sY; for (int sX = 0; sX < smpl_side; sX++){ if ((y >= 0) && (y <tilesY)) { for (int sX = -smpl_side/2; sX < smpl_side/2; sX++){ int x = tX + sX; int x = tX + sX; if ((x >= 0) && (x <tilesX)) { int nTile = y * tilesX + x; int nTile = y * tilesX + x; double w = disp_strength_in[1][nTile]; double w = disp_strength_in[1][nTile]; if (w > 0.0){ if (w > 0.0){ Loading @@ -1185,6 +1192,8 @@ public class AlignmentCorrection { } } } } } } } } if ((num_samples > min_samples) && (sw > 0.0)){ if ((num_samples > min_samples) && (sw > 0.0)){ int nTile = tY * tilesX + tX; int nTile = tY * tilesX + tX; disp_strength[0][nTile] = sdw/sw; // weighted average disparity disp_strength[0][nTile] = sdw/sw; // weighted average disparity Loading Loading @@ -1370,7 +1379,77 @@ public class AlignmentCorrection { } } } } public double [][] getFineCorrFromImage( public double [][] getDoubleFromImage( ImagePlus imp_src, int debugLevel) { // double min_max_ratio = 1.3; ImageStack clt_mismatches_stack= imp_src.getStack(); final int tilesX = clt_mismatches_stack.getWidth(); // tp.getTilesX(); final int tilesY = clt_mismatches_stack.getHeight(); // tp.getTilesY(); final int nTiles =tilesX * tilesY; final double [][] data = new double [clt_mismatches_stack.getSize()][nTiles]; for (int n = 0; n < data.length; n++) { float [] fpixels = (float[]) clt_mismatches_stack.getPixels(n +1); for (int i = 0; i < nTiles; i++){ data[n][i] = fpixels[i]; } } return data; } public double [][] getFineCorrFromDoubleArray( double [][] data, int tilesX, int debugLevel) { // double min_max_ratio = 1.3; final int tilesY = data[0].length/tilesX; // tp.getTilesY(); final int nTiles =tilesX * tilesY; final int num_scans = data.length/NUM_ALL_SLICES; final double [][] scans = new double [num_scans * NUM_ALL_SLICES][nTiles]; for (int ns = 0; ns < num_scans; ns++){ // double [][]min_max_strength = new double[2][nTiles]; for (int pair = 0; pair < 4; pair++){ float [][] fset = new float [3][]; // fset[0] = (float[]) clt_mismatches_stack.getPixels(12 * num_scans + ns +1); // fset[1] = (float[]) clt_mismatches_stack.getPixels(13 * num_scans + ns +1); // scans[ns * NUM_ALL_SLICES + 0] = data[12 * num_scans + ns]; scans[ns * NUM_ALL_SLICES + 1] = data[13 * num_scans + ns]; // for (int i = 0; i < nTiles; i++){ // scans[ns * NUM_ALL_SLICES + 0][i] = fset[0][i]; // disparity // scans[ns * NUM_ALL_SLICES + 1][i] = fset[1][i]; // strength // } // fset[0] = (float[]) clt_mismatches_stack.getPixels((2 * pair + 0) * num_scans + ns +1); // fset[1] = (float[]) clt_mismatches_stack.getPixels((2 * pair + 1) * num_scans + ns +1); // // fset[2] = (float[]) clt_mismatches_stack.getPixels((8 + pair ) * num_scans + ns +1); scans[ns * NUM_ALL_SLICES + pair * 3 + 2] = data[(2 * pair + 0) * num_scans + ns]; scans[ns * NUM_ALL_SLICES + pair * 3 + 3] = data[(2 * pair + 1) * num_scans + ns]; scans[ns * NUM_ALL_SLICES + pair * 3 + 4] = data[(8 + pair ) * num_scans + ns]; // for (int i = 0; i < nTiles; i++){ // scans[ns * NUM_ALL_SLICES + pair * 3 + 2][i] = fset[0][i]; // dx_i // scans[ns * NUM_ALL_SLICES + pair * 3 + 3][i] = fset[1][i]; // dy_i // scans[ns * NUM_ALL_SLICES + pair * 3 + 4][i] = fset[2][i]; // str_i // } } } if (debugLevel > 0) { String [] prefixes = {"disparity", "strength", "dx0", "dy0", "str0", "dx1", "dy1", "str1", "dx2", "dy2", "str2", "dx3", "dy3", "str3"}; String [] titles = new String [num_scans * NUM_ALL_SLICES]; for (int ns = 0; ns < num_scans; ns++){ for (int i = 0; i < NUM_ALL_SLICES; i++){ titles[ns * NUM_ALL_SLICES + i] = prefixes[i]+"_"+ns; } } (new showDoubleFloatArrays()).showArrays(scans, tilesX, tilesY, true, "scans" , titles); } return scans; } public double [][] getFineCorrFromImage_old( ImagePlus imp_src, ImagePlus imp_src, int debugLevel) int debugLevel) { { Loading @@ -1397,28 +1476,13 @@ public class AlignmentCorrection { fset[1] = (float[]) clt_mismatches_stack.getPixels((2 * pair + 1) * num_scans + ns +1); // fset[1] = (float[]) clt_mismatches_stack.getPixels((2 * pair + 1) * num_scans + ns +1); // fset[2] = (float[]) clt_mismatches_stack.getPixels((8 + pair ) * num_scans + ns +1); fset[2] = (float[]) clt_mismatches_stack.getPixels((8 + pair ) * num_scans + ns +1); for (int i = 0; i < nTiles; i++){ for (int i = 0; i < nTiles; i++){ // if (i == 55156) { // 52564){ // System.out.println("tile="+i+" scan="+ns+" pair = "+pair+ "fset[2]["+i+"]="+fset[2][i]); // } scans[ns * NUM_ALL_SLICES + pair * 3 + 2][i] = fset[0][i]; // dx_i scans[ns * NUM_ALL_SLICES + pair * 3 + 2][i] = fset[0][i]; // dx_i scans[ns * NUM_ALL_SLICES + pair * 3 + 3][i] = fset[1][i]; // dy_i scans[ns * NUM_ALL_SLICES + pair * 3 + 3][i] = fset[1][i]; // dy_i scans[ns * NUM_ALL_SLICES + pair * 3 + 4][i] = fset[2][i]; // str_i scans[ns * NUM_ALL_SLICES + pair * 3 + 4][i] = fset[2][i]; // str_i // if ((pair == 0) || (fset[2][i] < min_max_strength[0][i])) min_max_strength[0][i] = fset[2][i]; // if ((pair == 0) || (fset[2][i] > min_max_strength[1][i])) min_max_strength[1][i] = fset[2][i]; // if (fset[2][i] < min_comp_strength) { // scans[ns * NUM_SLICES + 1][i] = -1.0; // -1.0 - temporary to indicate // }; } } } } // for (int i = 0; i < nTiles; i++){ // if (min_max_strength[1][i] > (min_max_ratio * min_max_strength[0][i]) ){ // scans[ns * NUM_SLICES + 1][i] = -1.0; // -1.0 - temporary to indicate // } // } } } if (debugLevel > -1) { if (debugLevel > -1) { // String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "str0", "dx1", "dy1", "str1", "dx2", "dy2", "str2", "dx3", "dy3", "str3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "str0", "dx1", "dy1", "str1", "dx2", "dy2", "str2", "dx3", "dy3", "str3"}; String [] titles = new String [num_scans * NUM_ALL_SLICES]; String [] titles = new String [num_scans * NUM_ALL_SLICES]; for (int ns = 0; ns < num_scans; ns++){ for (int ns = 0; ns < num_scans; ns++){ Loading @@ -1436,7 +1500,7 @@ public class AlignmentCorrection { public double [][][] lazyEyeCorrection( public double [][][] lazyEyeCorrection( final double min_strength_in, final double min_strength_in, final double max_diff, final double max_diff, final double comp_strength_var, // final double comp_strength_var, final int max_iterations, final int max_iterations, final double max_coeff_diff, final double max_coeff_diff, final double far_pull, // = 0.2; // 1; // 0.5; final double far_pull, // = 0.2; // 1; // 0.5; Loading Loading @@ -1475,6 +1539,10 @@ public class AlignmentCorrection { scans[ns * NUM_SLICES + i] = scans_14[ns * NUM_ALL_SLICES + indices_14_10[i]]; scans[ns * NUM_SLICES + i] = scans_14[ns * NUM_ALL_SLICES + indices_14_10[i]]; } } } } // (new showDoubleFloatArrays()).showArrays(scans_14, tilesX, tilesY, true, "scans14"); // (new showDoubleFloatArrays()).showArrays(scans, tilesX, tilesY, true, "scans10"); for (int ns = 0; ns < num_scans; ns++){ for (int ns = 0; ns < num_scans; ns++){ for (int nTile = 0; nTile < num_tiles; nTile++){ for (int nTile = 0; nTile < num_tiles; nTile++){ double s1=0.0, s2=0.0; double s1=0.0, s2=0.0; Loading Loading @@ -1510,7 +1578,7 @@ public class AlignmentCorrection { * None of comp_strength_rms methods works to detect potential outliers for horizontal/vertical features * None of comp_strength_rms methods works to detect potential outliers for horizontal/vertical features */ */ if (debugLevel > -1) { if (debugLevel > 0) { String [] titles = new String [num_scans]; String [] titles = new String [num_scans]; for (int ns = 0; ns < num_scans; ns++){ for (int ns = 0; ns < num_scans; ns++){ titles[ns] = "scan_" + ns; titles[ns] = "scan_" + ns; Loading @@ -1529,18 +1597,9 @@ public class AlignmentCorrection { tilesX);// final int tilesX); tilesX);// final int tilesX); if (debugLevel > -1) { if (debugLevel > -1) { System.out.println("lazyEyeCorrection() 1: removing tile with residual disparity absoulte value > "+lazyEyeCompDiff); System.out.println("lazyEyeCorrection() 1: removing tiles with residual disparity absoulte value > "+lazyEyeCompDiff); } } /* for (int ns = 0; ns < num_scans; ns++){ for (int i = 0; i < num_tiles; i++){ double disp = filtered_scans[ns * NUM_SLICES + 0][i]; if (Math.abs(disp) > lazyEyeCompDiff) { filtered_scans[ns * NUM_SLICES + 1][i] = 0.0; } } } */ double [][] combo_mismatch = new double [NUM_SLICES][num_tiles]; double [][] combo_mismatch = new double [NUM_SLICES][num_tiles]; double [] combo_comp_rms = new double [num_tiles]; double [] combo_comp_rms = new double [num_tiles]; for (int ns = 0; ns < num_scans; ns++){ for (int ns = 0; ns < num_scans; ns++){ Loading Loading @@ -1598,7 +1657,7 @@ public class AlignmentCorrection { } } } } if (debugLevel > -1) { if (debugLevel > 0) { String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; (new showDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "combo_mismatch" , prefixes); (new showDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "combo_mismatch" , prefixes); } } Loading @@ -1612,7 +1671,7 @@ public class AlignmentCorrection { true, // final boolean norm_center, // if there are more tiles that fit than minsamples, replace with a single equal weight true, // final boolean norm_center, // if there are more tiles that fit than minsamples, replace with a single equal weight tilesX); // final int tilesX); tilesX); // final int tilesX); if (debugLevel > -1) { if (debugLevel > 0) { String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; (new showDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "filtered_mismatch" , prefixes); (new showDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "filtered_mismatch" , prefixes); } } Loading Loading @@ -1666,7 +1725,7 @@ public class AlignmentCorrection { hist_min_samples, // final int min_samples, hist_min_samples, // final int min_samples, hist_norm_center, // final boolean norm_center, // if there are more tiles that fit than minsamples, replace with hist_norm_center, // final boolean norm_center, // if there are more tiles that fit than minsamples, replace with tilesX); // final int tilesX) tilesX); // final int tilesX) if (debugLevel > 0){ if (debugLevel > 1){ double [][] dbg_img = inf_scan.clone(); double [][] dbg_img = inf_scan.clone(); for (int n = 0; n < inf_scan.length; n++){ for (int n = 0; n < inf_scan.length; n++){ dbg_img[n] = inf_scan[n].clone(); dbg_img[n] = inf_scan[n].clone(); Loading @@ -1689,7 +1748,7 @@ public class AlignmentCorrection { } } if (debugLevel > -1) { if (debugLevel > 0) { String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] titles = new String [2 * NUM_SLICES]; String [] titles = new String [2 * NUM_SLICES]; for (int i = 0; i < NUM_SLICES; i++){ for (int i = 0; i < NUM_SLICES; i++){ Loading Loading @@ -1805,7 +1864,7 @@ public class AlignmentCorrection { } } if (debugLevel > -1) { if (debugLevel > 0) { String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] titles = new String [num_scans * NUM_SLICES]; String [] titles = new String [num_scans * NUM_SLICES]; for (int ns = 0; ns < num_scans; ns++){ for (int ns = 0; ns < num_scans; ns++){ Loading @@ -1817,7 +1876,7 @@ public class AlignmentCorrection { } } if (debugLevel > -1) { if (debugLevel > 0) { String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"}; (new showDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "combo_mismatch" , prefixes); (new showDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "combo_mismatch" , prefixes); } } Loading @@ -1842,7 +1901,83 @@ public class AlignmentCorrection { return mismatch_corr_coefficiants; return mismatch_corr_coefficiants; } } public double [][] combineCltMismatches( EyesisCorrectionParameters.CLTParameters clt_parameters, double [][][] clt_mismatches, double [][][] disparity_maps, int disparity_index, int strength_index) { int n = clt_mismatches.length; double [][] combo = new double [clt_parameters.disp_scan_count * AlignmentCorrection.NUM_ALL_SLICES][]; for (int pair = 0; pair < 4; pair++){ for (int i = 0; i < n; i++){ combo[(2 * pair + 0) * n + i] = clt_mismatches[i][3 * pair + 0]; combo[(2 * pair + 1) * n + i] = clt_mismatches[i][3 * pair + 1]; combo[(2 * 4 + pair) * n + i] = clt_mismatches[i][3 * pair + 2]; } } for (int i = 0; i < n; i++){ combo[12 * n + i] = disparity_maps[i][disparity_index]; combo[13 * n + i] = disparity_maps[i][strength_index]; } return combo; } public void showCltMismatches( String title, EyesisCorrectionParameters.CLTParameters clt_parameters, double [][] combo_data, int tilesX, int tilesY) { showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); String [] titles = new String [combo_data.length]; int num_scans = combo_data.length / AlignmentCorrection.NUM_ALL_SLICES; for (int pair = 0; pair < 4; pair++){ for (int i = 0; i < num_scans; i++){ double disparity = clt_parameters.disp_scan_start + i * clt_parameters.disp_scan_step; titles[(2 * pair + 0) * num_scans + i] = "dx_"+pair+"_"+disparity; titles[(2 * pair + 1) * num_scans + i] = "dy_"+pair+"_"+disparity; titles[(2 * 4 + pair) * num_scans + i] = "strength_"+pair+"_"+disparity; } } for (int i = 0; i < num_scans; i++){ double disparity = clt_parameters.disp_scan_start + i * clt_parameters.disp_scan_step; titles[ 12 * num_scans + i] = "disp_"+disparity; titles[ 13 * num_scans + i] = "strength_"+disparity; } sdfa_instance.showArrays(combo_data, tilesX,tilesY, true, title, titles); } public void showCltMismatch( String title, EyesisCorrectionParameters.CLTParameters clt_parameters, double [][] clt_mismatch, int tilesX, int tilesY) { showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); String [] titles = new String [12]; double [][] dbg_clt_mismatch= new double [12][]; for (int pair = 0; pair < 4; pair++){ titles[2 * pair + 0] = "dx_"+pair; titles[2 * pair + 1] = "dy_"+pair; titles[2 * 4 + pair] = "strength_"+pair; dbg_clt_mismatch[(2 * pair + 0)] = clt_mismatch[3 * pair + 0].clone(); dbg_clt_mismatch[(2 * pair + 1)] = clt_mismatch[3 * pair + 1].clone(); dbg_clt_mismatch[(2 * 4 + pair)] = clt_mismatch[3 * pair + 2]; for (int i = 0; i < dbg_clt_mismatch[(2 * 4 + pair)].length; i++ ){ if (dbg_clt_mismatch[(2 * 4 + pair)][i] == 0.0){ dbg_clt_mismatch[(2 * pair + 0)][i] = Double.NaN; dbg_clt_mismatch[(2 * pair + 1)][i] = Double.NaN; } } } sdfa_instance.showArrays(dbg_clt_mismatch, tilesX, tilesY, true, title, titles); } public void process_fine_corr( public void process_fine_corr( Loading
src/main/java/CLTPass3d.java +173 −7 Original line number Original line Diff line number Diff line Loading @@ -51,7 +51,7 @@ public class CLTPass3d{ public boolean [] border_tiles = null; // these are border tiles, zero out alpha public boolean [] border_tiles = null; // these are border tiles, zero out alpha public boolean [] selected = null; // which tiles are selected for this layer public boolean [] selected = null; // which tiles are selected for this layer public double [][][][] texture_tiles; public double [][][][] texture_tiles; public double [][] max_tried_disparity = null; //[ty][tx] used for combined passes, shows maximal disparity wor this tile, regardless of results public double [][] max_tried_disparity = null; //[ty][tx] used for combined passes, shows maximal disparity for this tile, regardless of results public boolean is_combo = false; public boolean is_combo = false; public boolean is_measured = false; public boolean is_measured = false; public String texture = null; // relative (to x3d) path public String texture = null; // relative (to x3d) path Loading Loading @@ -190,6 +190,7 @@ public class CLTPass3d{ */ */ public double [][] getDiffs (){ public double [][] getDiffs (){ if (disparity_map == null) return null; double [][] these_diffs = new double[ImageDtt.QUAD][]; double [][] these_diffs = new double[ImageDtt.QUAD][]; for (int i = 0; i< ImageDtt.QUAD; i++) these_diffs[i] = disparity_map[ImageDtt.IMG_DIFF0_INDEX + i]; for (int i = 0; i< ImageDtt.QUAD; i++) these_diffs[i] = disparity_map[ImageDtt.IMG_DIFF0_INDEX + i]; return these_diffs; return these_diffs; Loading @@ -208,6 +209,10 @@ public class CLTPass3d{ return selected; return selected; } } public boolean [] getBorderTiles(){ return this.border_tiles; } public void setSelected (boolean [] selected) { public void setSelected (boolean [] selected) { this.selected = selected; this.selected = selected; } } Loading Loading @@ -444,7 +449,7 @@ public class CLTPass3d{ * Replaces current combo disparity for tiles that are weak and do not have any neighbor within disparity range from this one * Replaces current combo disparity for tiles that are weak and do not have any neighbor within disparity range from this one * @param selection optional boolean mask of tiles to use/update * @param selection optional boolean mask of tiles to use/update * @param weakStrength maximal strength of the tile to be considered weak one * @param weakStrength maximal strength of the tile to be considered weak one * @param maxDiff maximal difference from the most similar neighbor to be considered an outlayer * @param maxDiff maximal difference from the most similar neighbor to be considered an outlier * @param disparityFar minimal acceptable disparity for weak tiles * @param disparityFar minimal acceptable disparity for weak tiles * @param disparityNear maximal acceptable disparity for weak tiles * @param disparityNear maximal acceptable disparity for weak tiles * @return mask of weak (replaced) tiles * @return mask of weak (replaced) tiles Loading @@ -455,8 +460,8 @@ public class CLTPass3d{ final boolean [] selection, final boolean [] selection, final double weakStrength, // strength to be considered weak, subject to this replacement final double weakStrength, // strength to be considered weak, subject to this replacement final double maxDiff, final double maxDiff, final double maxDiffPos, // Replace weak outlayer tiles that have higher disparity than weighted average final double maxDiffPos, // Replace weak outlier tiles that have higher disparity than weighted average final double maxDiffNeg, // Replace weak outlayer tiles that have lower disparity than weighted average final double maxDiffNeg, // Replace weak outlier tiles that have lower disparity than weighted average final double disparityFar, final double disparityFar, final double disparityNear, final double disparityNear, final int debugLevel) final int debugLevel) Loading @@ -474,7 +479,7 @@ public class CLTPass3d{ final double absMaxDisparity = 1.5 * disparityNear; // change? final double absMaxDisparity = 1.5 * disparityNear; // change? final int dbg_nTile = (debugLevel > 0) ? 43493: -1; // x=77,y=134; // 42228; // x = 108, y = 130 46462; // 41545; final int dbg_nTile = (debugLevel > 0) ? 43493: -1; // x=77,y=134; // 42228; // x = 108, y = 130 46462; // 41545; final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.threadsMax); final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.threadsMax); // first pass = find outlayers // first pass = find outliers final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0); for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) { threads[ithread] = new Thread() { threads[ithread] = new Thread() { Loading Loading @@ -507,7 +512,7 @@ public class CLTPass3d{ sw += w; sw += w; sd += w * disparity[nTile1]; sd += w * disparity[nTile1]; hasNeighbors = true; hasNeighbors = true; if (Math.abs(disparity[nTile]-disparity[nTile1]) <= maxDiff){ // any outlayer - will be false if (Math.abs(disparity[nTile]-disparity[nTile1]) <= maxDiff){ // any outlier - will be false weakOutlayers[nTile] = false; weakOutlayers[nTile] = false; // break; // break; } } Loading @@ -531,7 +536,7 @@ public class CLTPass3d{ } } ImageDtt.startAndJoin(threads); ImageDtt.startAndJoin(threads); // second pass - replace outlayers // second pass - replace outliers final double [] src_disparity = disparity.clone(); final double [] src_disparity = disparity.clone(); ai.set(0); ai.set(0); for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) { Loading Loading @@ -580,6 +585,167 @@ public class CLTPass3d{ return weakOutlayers; return weakOutlayers; } } public boolean [] getUntestedBackgroundBorder ( final boolean [] known, final double [] disparity, final double grow_disp_step, final int debugLevel) { final int tilesX = tileProcessor.getTilesX(); final int tilesY = tileProcessor.getTilesY(); final int num_tiles = tilesX * tilesY; final TileNeibs tnImage = new TileNeibs(tilesX, tilesY); // num_tiles/tilesX); final boolean [] untested_bgnd = new boolean [num_tiles]; final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.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 < num_tiles; nTile = ai.getAndIncrement()) { if (known[nTile]){ int tX = nTile % tilesX; int tY = nTile / tilesX; double max_disp = max_tried_disparity[tY][tX] + grow_disp_step; for (int dir = 0; dir < 8; dir++){ int nTile1 = tnImage.getNeibIndex(nTile, dir); if ((nTile1 >=0) && known[nTile1] && (disparity[nTile1] > max_disp)) { untested_bgnd[nTile] = true; break; } } } } } }; } ImageDtt.startAndJoin(threads); return untested_bgnd; } public boolean [] measuredTiles () { final int tilesX = tileProcessor.getTilesX(); final int tilesY = tileProcessor.getTilesY(); final int num_tiles = tilesX * tilesY; final boolean [] measured = new boolean [num_tiles]; final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.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 < num_tiles; nTile = ai.getAndIncrement()) { int tX = nTile % tilesX; int tY = nTile / tilesX; measured[nTile] = tile_op[tY][tX] != 0; } } }; } ImageDtt.startAndJoin(threads); return measured; } public double [] getSecondMaxDiff ( final boolean averaged) { final double [][] diffs = getDiffs(); if (diffs == null) return null; final int tilesX = tileProcessor.getTilesX(); final int tilesY = tileProcessor.getTilesY(); final int num_tiles = tilesX * tilesY; final double [] second_max = new double [num_tiles]; final boolean [] measured = measuredTiles (); final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.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 < num_tiles; nTile = ai.getAndIncrement()) { int imax1 = 0; for (int ip = 1; ip < diffs.length; ip++){ if (diffs[ip][nTile] > diffs[imax1][nTile]) imax1 = ip; } int imax2 = (imax1 == 0)? 1 : 0; for (int ip = 0; ip < diffs.length; ip++) if (ip != imax1) { if (diffs[ip][nTile] > diffs[imax2][nTile]) imax2 = ip; } second_max[nTile] = diffs[imax2][nTile]; } } }; } ImageDtt.startAndJoin(threads); if (!averaged) return second_max; final TileNeibs tnImage = new TileNeibs(tilesX, tilesY); // num_tiles/tilesX); final double [] second_max_averaged = new double [num_tiles]; final double [] dir_weights = {1.0/16, 1.0/8, 1.0/16, 1.0/8, 1.0/16, 1.0/8, 1.0/16, 1.0/8, 1.0/4}; ai.set(0); for (int ithread = 0; ithread < threads.length; ithread++) { threads[ithread] = new Thread() { public void run() { for (int nTile = ai.getAndIncrement(); nTile < num_tiles; nTile = ai.getAndIncrement()) if (measured[nTile]) { double sw = 0.0; double swd = 0.0; for (int dir = 0; dir < 9; dir++){ // including 8 - center int nTile1 = tnImage.getNeibIndex(nTile, dir); if ((nTile1 >=0) && measured[nTile1]) { sw += dir_weights[dir]; swd += dir_weights[dir] * second_max[nTile1] ; } } second_max_averaged[nTile] = swd/sw; } } }; } ImageDtt.startAndJoin(threads); return second_max_averaged; } // same, but 2 steps around public boolean [] getUntestedBackgroundBorder2 ( final boolean [] known, final double [] disparity, final double grow_disp_step, final int debugLevel) { final int tilesX = tileProcessor.getTilesX(); final int tilesY = tileProcessor.getTilesY(); final int num_tiles = tilesX * tilesY; final TileNeibs tnImage = new TileNeibs(tilesX, tilesY); // num_tiles/tilesX); final boolean [] untested_bgnd = new boolean [num_tiles]; final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.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 < num_tiles; nTile = ai.getAndIncrement()) { if (known[nTile]){ int tX = nTile % tilesX; int tY = nTile / tilesX; double max_disp = max_tried_disparity[tY][tX] + grow_disp_step; for (int dir = 0; dir < 24; dir++){ int nTile1 = tnImage.getNeibIndex2(nTile, dir); if ((nTile1 >=0) && known[nTile1] && (disparity[nTile1] > max_disp)) { untested_bgnd[nTile] = true; break; } } } } } }; } ImageDtt.startAndJoin(threads); return untested_bgnd; } public SuperTiles getSuperTiles() public SuperTiles getSuperTiles() { { return this.superTiles; return this.superTiles; Loading