Loading src/main/java/com/elphel/imagej/cameras/ThermalColor.java +2 −2 Original line number Diff line number Diff line Loading @@ -28,8 +28,8 @@ public class ThermalColor { double k = out_range/PALETTE_RANGE; double value = (v-min)/(max-min) * (this.palette.length - 1); int ivalue = (int) (value); if (ivalue < 0) return this.palette[0]; if (ivalue >= (this.palette.length -1)) return this.palette[this.palette.length -1]; if (value < 0) return this.palette[0]; if (value >= (this.palette.length -1)) return this.palette[this.palette.length -1]; double a = (value-ivalue); // 0..1 double [] rslt = { k*((1 - a) * this.palette[ivalue][0] + a * this.palette[ivalue+1][0]), Loading src/main/java/com/elphel/imagej/tileprocessor/IntersceneLmaParameters.java +1 −1 Original line number Diff line number Diff line Loading @@ -116,7 +116,7 @@ public class IntersceneLmaParameters { gd.addMessage("Interframe LMA parameters selection"); gd.addCheckbox ("3D mode (use disparity)", this.ilma_3d, "Use disparity for interscene matching (as for UAS imagery)" ); gd.addNumericField("Disp[arity weight", this.ilma_disparity_weight, 6,8,"", gd.addNumericField("Disparity weight", this.ilma_disparity_weight, 6,8,"", "Disparity component weight compared to dX and dY"); gd.addCheckbox ("LMA in 3D mode", this.ilma_3d_lma, "Use LMA disparity for interscene matching (as for UAS imagery)" ); Loading src/main/java/com/elphel/imagej/tileprocessor/OpticalFlow.java +94 −57 Original line number Diff line number Diff line Loading @@ -4538,6 +4538,10 @@ public class OpticalFlow { int min_num_scenes = clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it int max_num_scenes = clt_parameters.imp.max_num_scenes; // cut longer series double boost_max_short = 2.0; // double [] lma_rms = new double[2]; double [] use_atr = null; Loading Loading @@ -4689,6 +4693,26 @@ public class OpticalFlow { scenes_xyzatr[scene_index][1].clone()}; boolean rot_to_transl = after_spiral && clt_parameters.ilp.ilma_translation_priority; double [] reg_weights = rot_to_transl? clt_parameters.ilp.ilma_regularization_weights0 : clt_parameters.ilp.ilma_regularization_weights; min_max[1] = max_offset; if ((ref_index - scene_index) < min_num_scenes) { min_max[1] = boost_max_short * max_offset; if (debugLevel > -3) { System.out.println("As the current series ("+(ref_index - scene_index)+ " scenes) is shorter than minimal ("+min_num_scenes+"), the maximal shift is scaled by "+ boost_max_short + " to " + (boost_max_short * max_offset)+ " pixels"); } } if ((scene_index - earliest_scene) < min_num_scenes) { min_max[1] = boost_max_short * max_offset; if (debugLevel > -3) { System.out.println("As the remaining number of scenes to process ("+(scene_index - earliest_scene + 1)+ ") is less than minimal ("+min_num_scenes+"), the maximal shift is scaled by "+ boost_max_short + " to " + (boost_max_short * max_offset)+ " pixels"); } } scenes_xyzatr[scene_index] = adjustPairsLMAInterscene( clt_parameters, // CLTParameters clt_parameters, use_lma_dsi, // clt_parameters.imp.use_lma_dsi, Loading Loading @@ -5107,7 +5131,7 @@ public class OpticalFlow { if (!force_initial_orientations) { if ((quadCLTs[ref_index].getNumOrient() == 0) ||(!quadCLTs[ref_index].propertiesContainString (".scenes_"))) { if (debugLevel >-2) { if (debugLevel >-3) { System.out.println("Egomotion data for scene "+set_channels[ref_index].set_name+" does not exist, forcing its calculation."); } force_initial_orientations = true; Loading Loading @@ -5794,12 +5818,64 @@ public class OpticalFlow { } // for (int ibase = 0; ibase < baselines.length; ibase++) { }// for (int mode3d = 0; mode3d<generate_modes3d.length; mode3d++) if (generate_modes3d[mode3d]) { } // if (generate_mapped) { if (export_dsi_image || show_dsi_image) { if (combo_dsn_final == null) { /// combo_dsn_final =quadCLTs[ref_index].readDoubleArrayFromModelDirectory( /// "-INTER-INTRA-LMA", // String suffix, /// 0, // int num_slices, // (0 - all) /// null); // int [] wh); combo_dsn_final =quadCLTs[ref_index].restoreComboDSI(true); // also sets quadCLTs[ref_index].dsi and blue sky } // re-load , should create quadCLTs[ref_index].dsi double [][] dls = { combo_dsn_final[COMBO_DSN_INDX_DISP], combo_dsn_final[COMBO_DSN_INDX_LMA], combo_dsn_final[COMBO_DSN_INDX_STRENGTH] }; int dbg_condition = debug_ranges ? Math.max(1, debugLevel) : debugLevel; double [][] ds = conditionInitialDS( // Add debug szxy by providing debugLevel=1 true, // boolean use_conf, // use configuration parameters, false - use following clt_parameters, // CLTParameters clt_parameters, dls, // double [][] dls quadCLTs[ref_index], // QuadCLT scene, dbg_condition); // int debug_level) double [] disparity = ds[0]; double [] strength = ds[1]; double [][]szxy = getSceneSZXY( quadCLTs[ref_index], // QuadCLT scene, range_disparity_offset, // double disparity_offset, range_min_strength, // double min_strength, range_max, // double max_range, disparity, // double [] disparity, strength); // double [] strength) String [] szxy_titles = {"strength", "Z(m)", "X(m)", "Y(m)"}; TileProcessor tp = quadCLTs[ref_index].getTileProcessor(); int tilesX = tp.getTilesX(); int tilesY = tp.getTilesY(); ImagePlus impSZXY = ShowDoubleFloatArrays.makeArrays( szxy, tilesX, tilesY, quadCLTs[ref_index].getImageName()+"_SZXY", szxy_titles); if (export_dsi_image) { quadCLTs[ref_index].saveImagePlusInModelDirectory( null, // "GPU-SHIFTED-BACKGROUND", // String suffix, impSZXY); // ImagePlus imp) } if (show_dsi_image) { impSZXY.show(); } } // debugging 3D model int [] whs = new int[3]; double [] x0y0 = new double[2]; if (export3d) { //combo_dsn_final had strength 1.0e-4 where it should not? Reset it? /* */ /* boolean use_lma = true; // ; double discard_low = 0.01; // fraction of all pixels double discard_high = 0.5; // fraction of all pixels Loading @@ -5817,6 +5893,7 @@ public class OpticalFlow { double [] hdr_x0y0 = new double[2]; double [][] to_ground_xyxatr = quadCLTs[ref_index].getGround( use_lma, // boolean use_lma, clt_parameters.imp.range_disparity_offset,// double range_disparity_offset discard_low, // double discard_low, // fraction of all pixels discard_high, // double discard_high, // fraction of all pixels discard_adisp, // double discard_adisp, // discard above/below this fraction of average height Loading @@ -5827,7 +5904,7 @@ public class OpticalFlow { hdr_whs, // int [] whs, // initialize to int[3] to return {width, height, scale reduction} debugLevel); // int debug_level /**/ */ boolean ok_3d = TexturedModel.output3d( // quadCLTs have same image name, and everything else clt_parameters, // CLTParameters clt_parameters, Loading Loading @@ -6085,58 +6162,6 @@ public class OpticalFlow { } } if (export_dsi_image || show_dsi_image) { if (combo_dsn_final == null) { /// combo_dsn_final =quadCLTs[ref_index].readDoubleArrayFromModelDirectory( /// "-INTER-INTRA-LMA", // String suffix, /// 0, // int num_slices, // (0 - all) /// null); // int [] wh); combo_dsn_final =quadCLTs[ref_index].restoreComboDSI(true); // also sets quadCLTs[ref_index].dsi and blue sky } // re-load , should create quadCLTs[ref_index].dsi double [][] dls = { combo_dsn_final[COMBO_DSN_INDX_DISP], combo_dsn_final[COMBO_DSN_INDX_LMA], combo_dsn_final[COMBO_DSN_INDX_STRENGTH] }; int dbg_condition = debug_ranges ? Math.max(1, debugLevel) : debugLevel; double [][] ds = conditionInitialDS( // Add debug szxy by providing debugLevel=1 true, // boolean use_conf, // use configuration parameters, false - use following clt_parameters, // CLTParameters clt_parameters, dls, // double [][] dls quadCLTs[ref_index], // QuadCLT scene, dbg_condition); // int debug_level) double [] disparity = ds[0]; double [] strength = ds[1]; double [][]szxy = getSceneSZXY( quadCLTs[ref_index], // QuadCLT scene, range_disparity_offset, // double disparity_offset, range_min_strength, // double min_strength, range_max, // double max_range, disparity, // double [] disparity, strength); // double [] strength) String [] szxy_titles = {"strength", "Z(m)", "X(m)", "Y(m)"}; TileProcessor tp = quadCLTs[ref_index].getTileProcessor(); int tilesX = tp.getTilesX(); int tilesY = tp.getTilesY(); ImagePlus impSZXY = ShowDoubleFloatArrays.makeArrays( szxy, tilesX, tilesY, quadCLTs[ref_index].getImageName()+"_SZXY", szxy_titles); if (export_dsi_image) { quadCLTs[ref_index].saveImagePlusInModelDirectory( null, // "GPU-SHIFTED-BACKGROUND", // String suffix, impSZXY); // ImagePlus imp) } if (show_dsi_image) { impSZXY.show(); } } if (export_ml_files) { if (combo_dsn_final == null) { // always re-read? Loading Loading @@ -13112,11 +13137,22 @@ public class OpticalFlow { } return null; } if (avg_offs > min_max[1]) {// NaN - do not check; if (fail_reason != null) { fail_reason[0]=FAIL_REASON_MAX; } if (debug_level > -3){ System.out.println ("interCorrPair(): avg_offs = "+avg_offs+ " > "+min_max[1]+", sw = "+sw); } return null; } else { if (debug_level > -3){ System.out.println ("interCorrPair(): avg_offs = "+avg_offs+ " <= "+min_max[1]+", sw = "+sw); } } } double half_disparity = near_important ? 0.0 : clt_parameters.imp.half_disparity; Loading Loading @@ -14242,6 +14278,7 @@ public class OpticalFlow { // double mb_max_gain = clt_parameters.imp.mb_max_gain_inter; // 5.0; // motion blur maximal gain (if more - move second point more than a pixel int margin = clt_parameters.imp.margin; double second_margin = 1.1; // allow slightly larger offset for readjsutments (to be limited by the first pass) double boost_max_short = 5.0; // 2.0; // Some bug? int earliest_scene = 0; boolean use_combo_dsi = clt_parameters.imp.use_combo_dsi; boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi; Loading @@ -14250,14 +14287,14 @@ public class OpticalFlow { int tilesY = quadCLTs[ref_index].getTileProcessor().getTilesY(); int tile_size = quadCLTs[ref_index].getTileProcessor().getTileSize(); double min_offset = clt_parameters.imp.min_offset; double max_offset = second_margin*clt_parameters.imp.max_rel_offset * tilesX * tile_size; double max_offset = boost_max_short*second_margin*clt_parameters.imp.max_rel_offset * tilesX * tile_size; double max_roll = second_margin*clt_parameters.imp.max_roll_deg*Math.PI/180.0; double max_zoom_diff = second_margin*clt_parameters.imp.max_zoom_diff; boolean fpn_skip = clt_parameters.imp.fpn_skip; // if false - fail as before boolean fpn_rematch = clt_parameters.imp.fpn_rematch; // if false - keep previous double [] min_max = {min_offset, max_offset, 0.0} ; // {min, max, actual rms) int [] fail_reason = new int[1]; // null or int[1]: 0 - OK, 2 - LMA, 3 - min, 4 - max System.out.println("reAdjustPairsLMAInterscene(): min_offset="+min_max[0]+", max_offset="+min_max[1]); double [] disparity_raw = new double [tilesX * tilesY]; Arrays.fill(disparity_raw,clt_parameters.disparity); /// double [][] combo_dsn_final = quadCLTs[ref_index].readDoubleArrayFromModelDirectory( src/main/java/com/elphel/imagej/tileprocessor/QuadCLTCPU.java +44 −14 Original line number Diff line number Diff line Loading @@ -223,6 +223,7 @@ public class QuadCLTCPU { // cac public double [][] getGround( boolean use_lma, double disparity_offset, double discard_low, // fraction of all pixels double discard_high, // fraction of all pixels double discard_adisp, // discard above/below this fraction of average height Loading @@ -234,22 +235,24 @@ public class QuadCLTCPU { int debug_level ) { double [] z_tilts = null; final int tilesX=getTileProcessor().getTilesX(); final int tilesY=getTileProcessor().getTilesY(); double hist_rlow = 0.4; double normal_damping = 0.001; // pull to horizontal if not enough data // final int tilesX=getTileProcessor().getTilesX(); // final int tilesY=getTileProcessor().getTilesY(); double hist_rlow = 0.5; double hist_rhigh = 2.0; int min_good = 20; //number of good tiles int min_good_quad = 20; // number of good tiles per quadrantto calculate tilts int gap_frac2= 20; /// int min_good_quad = 20; // number of good tiles per quadrant to calculate tilts /// int gap_frac2= 20; double rel_hight = 0.2; // when calculating scale, ignore objects far from plane int num_bins = 1000; double [][] dls = getDLS(); if (dls==null) { return null; } double [][] ds = new double [][] {dls[use_lma?1:0], dls[2]}; double [][] ds = new double [][] {dls[use_lma?1:0].clone(), dls[2]}; double sw=0, swd=0; for (int i = 0; i < ds[0].length; i++) if (!Double.isNaN(ds[0][i])){ ds[0][i] -= disparity_offset; sw += ds[1][i]; swd += ds[0][i] * ds[1][i]; } Loading Loading @@ -318,7 +321,9 @@ public class QuadCLTCPU { } return null; // too few good } double z_avg= getGeometryCorrection().getZFromDisparity(swd/sw); // double z_avg= getGeometryCorrection().getZFromDisparity(swd/sw); /* int gap_x_0 = tilesX/2 - tilesX/gap_frac2; int gap_x_1 = tilesX/2 + tilesX/gap_frac2; int gap_y_0 = tilesY/2 - tilesY/gap_frac2; Loading Loading @@ -348,9 +353,11 @@ public class QuadCLTCPU { System.out.println("There are less than 3 quadrants ("+num_good_quads+") having more than "+min_good_quad+" tiles"); System.out.println("Using only level "+z_avg+", ignoring tilt."); } z_tilts = new double[] {z_avg, 0.0, 0.0}; // no tilts z_tilts = new double[] {-z_avg, 0.0, 0.0}; // no tilts // return new double[] {z_avg, 0.0, 0.0}; // no tilts } else { */ // fit plane double [] ref_disparity = ds[0].clone(); for (int i = 0; i < ref_disparity.length; i++) { Loading Loading @@ -381,17 +388,18 @@ public class QuadCLTCPU { mindx++; } PolynomialApproximation pa = new PolynomialApproximation(); double [] damping = new double [] {normal_damping, normal_damping}; double[][] approx2d = pa.quadraticApproximation( mdata, true, // boolean forceLinear, // use linear approximation null, // double [] damping, null OK damping, // double [] damping, null OK -1); // debug level z_tilts= new double [] { approx2d[0][2], approx2d[0][0], approx2d[0][1]}; if (debug_level > -3) { System.out.println("Found ground plane: level="+z_tilts[0]+", tiltX="+z_tilts[1]+", tiltY="+z_tilts[2]); } } /* } */ // ground - negative Z. picture right - positive X, picture up - positive Y // positive tiltX - to the right higher ground (lower altitude above it) or camera tilted left // positive tiltY - picture up - higher ground (or camera tilted back) Loading @@ -402,11 +410,16 @@ public class QuadCLTCPU { // It is approximate for small angles. OK for now double [][] to_ground_xyxatr = ErsCorrection.invertXYZATR(ground_xyxatr); // recalculate coordinates for all pixels including weak ones double [] ref_disparity = dls[0].clone(); // double [] ref_disparity = dls[0].clone(); for (int i = 0; i < ref_disparity.length; i++) { if (Double.isNaN(ref_disparity[i])) ref_disparity[i] = 0.0; else { ref_disparity[i] -= disparity_offset; } double [][] wxyz = OpticalFlow.transformToWorldXYZ( } // double [][] wxyz = OpticalFlow.transformToWorldXYZ( ref_disparity, // final double [] disparity_ref, // invalid tiles - NaN in disparity (QuadCLT) this, // final QuadCLT quadClt, // now - may be null - for testing if scene is rotated ref THREADS_MAX); // int threadsMax) Loading @@ -432,8 +445,11 @@ public class QuadCLTCPU { if (y < y_min_max[0]) y_min_max[0] = y; else if (y > y_min_max[1]) y_min_max[1] = y; } if ((x_min_max == null) || (y_min_max == null)) { return null; // no points at all? } if (x0y0!=null) { x0y0[0] = x_min_max[0]; x0y0[0] = x_min_max[0]; // null x0y0[1] = y_min_max[0]; } int scale = 0; Loading Loading @@ -8387,6 +8403,9 @@ public class QuadCLTCPU { double [][] rgba = new double [num_slices][]; for (int i = 0; i < 3; i++) rgba[i] = new double [texture_data[main_color_index].length]; for (int i = 0; i < rbg_in[main_color_index].length; i++) { if (i==160000) { System.out.println ("i="+i); } double [] rgb = tc.getRGB(texture_data[main_color_index][i]); rgba[0][i] = rgb[0]; // red rgba[1][i] = rgb[1]; // green Loading Loading @@ -15421,6 +15440,7 @@ public class QuadCLTCPU { public boolean writeLwirPreview( final CLTParameters clt_parameters, double [] data, double [] minmax, // null for auto QuadCLT scene, int tex_palette, String suffix, Loading @@ -15429,6 +15449,7 @@ public class QuadCLTCPU { clt_parameters, data, getTileProcessor().getTilesX() *getTileProcessor().getTileSize(), minmax, // double [] minmax, // null for auto scene, tex_palette, suffix, Loading @@ -15438,6 +15459,7 @@ public class QuadCLTCPU { final CLTParameters clt_parameters, double [] data, int width, double [] minmax, // null for auto QuadCLT scene, int tex_palette, String suffix, Loading @@ -15449,7 +15471,15 @@ public class QuadCLTCPU { for (int i = 0; i < rendered_texture[0].length; i++) { rendered_texture[1][i] = Double.isNaN(rendered_texture[0][i])? 0.0: 1.0; } double [] minmax = scene.getColdHot(); // used in linearStackToColor (from this current scene) // double [] minmax = scene.getColdHot(); // used in linearStackToColor (from this current scene) if (!suffix.equals("")) { if (minmax == null) { // to replace standard preview file name minmax = scene.getColdHot(); // used in linearStackToColor (from this current scene) suffix +="-AUTORANGE"; } else { suffix +="-RANGE"+(minmax[1]-minmax[0]); } } // int width = getTileProcessor().getTilesX() *getTileProcessor().getTileSize(); int height = data.length/width; String set_name = getImageName(); Loading
src/main/java/com/elphel/imagej/cameras/ThermalColor.java +2 −2 Original line number Diff line number Diff line Loading @@ -28,8 +28,8 @@ public class ThermalColor { double k = out_range/PALETTE_RANGE; double value = (v-min)/(max-min) * (this.palette.length - 1); int ivalue = (int) (value); if (ivalue < 0) return this.palette[0]; if (ivalue >= (this.palette.length -1)) return this.palette[this.palette.length -1]; if (value < 0) return this.palette[0]; if (value >= (this.palette.length -1)) return this.palette[this.palette.length -1]; double a = (value-ivalue); // 0..1 double [] rslt = { k*((1 - a) * this.palette[ivalue][0] + a * this.palette[ivalue+1][0]), Loading
src/main/java/com/elphel/imagej/tileprocessor/IntersceneLmaParameters.java +1 −1 Original line number Diff line number Diff line Loading @@ -116,7 +116,7 @@ public class IntersceneLmaParameters { gd.addMessage("Interframe LMA parameters selection"); gd.addCheckbox ("3D mode (use disparity)", this.ilma_3d, "Use disparity for interscene matching (as for UAS imagery)" ); gd.addNumericField("Disp[arity weight", this.ilma_disparity_weight, 6,8,"", gd.addNumericField("Disparity weight", this.ilma_disparity_weight, 6,8,"", "Disparity component weight compared to dX and dY"); gd.addCheckbox ("LMA in 3D mode", this.ilma_3d_lma, "Use LMA disparity for interscene matching (as for UAS imagery)" ); Loading
src/main/java/com/elphel/imagej/tileprocessor/OpticalFlow.java +94 −57 Original line number Diff line number Diff line Loading @@ -4538,6 +4538,10 @@ public class OpticalFlow { int min_num_scenes = clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it int max_num_scenes = clt_parameters.imp.max_num_scenes; // cut longer series double boost_max_short = 2.0; // double [] lma_rms = new double[2]; double [] use_atr = null; Loading Loading @@ -4689,6 +4693,26 @@ public class OpticalFlow { scenes_xyzatr[scene_index][1].clone()}; boolean rot_to_transl = after_spiral && clt_parameters.ilp.ilma_translation_priority; double [] reg_weights = rot_to_transl? clt_parameters.ilp.ilma_regularization_weights0 : clt_parameters.ilp.ilma_regularization_weights; min_max[1] = max_offset; if ((ref_index - scene_index) < min_num_scenes) { min_max[1] = boost_max_short * max_offset; if (debugLevel > -3) { System.out.println("As the current series ("+(ref_index - scene_index)+ " scenes) is shorter than minimal ("+min_num_scenes+"), the maximal shift is scaled by "+ boost_max_short + " to " + (boost_max_short * max_offset)+ " pixels"); } } if ((scene_index - earliest_scene) < min_num_scenes) { min_max[1] = boost_max_short * max_offset; if (debugLevel > -3) { System.out.println("As the remaining number of scenes to process ("+(scene_index - earliest_scene + 1)+ ") is less than minimal ("+min_num_scenes+"), the maximal shift is scaled by "+ boost_max_short + " to " + (boost_max_short * max_offset)+ " pixels"); } } scenes_xyzatr[scene_index] = adjustPairsLMAInterscene( clt_parameters, // CLTParameters clt_parameters, use_lma_dsi, // clt_parameters.imp.use_lma_dsi, Loading Loading @@ -5107,7 +5131,7 @@ public class OpticalFlow { if (!force_initial_orientations) { if ((quadCLTs[ref_index].getNumOrient() == 0) ||(!quadCLTs[ref_index].propertiesContainString (".scenes_"))) { if (debugLevel >-2) { if (debugLevel >-3) { System.out.println("Egomotion data for scene "+set_channels[ref_index].set_name+" does not exist, forcing its calculation."); } force_initial_orientations = true; Loading Loading @@ -5794,12 +5818,64 @@ public class OpticalFlow { } // for (int ibase = 0; ibase < baselines.length; ibase++) { }// for (int mode3d = 0; mode3d<generate_modes3d.length; mode3d++) if (generate_modes3d[mode3d]) { } // if (generate_mapped) { if (export_dsi_image || show_dsi_image) { if (combo_dsn_final == null) { /// combo_dsn_final =quadCLTs[ref_index].readDoubleArrayFromModelDirectory( /// "-INTER-INTRA-LMA", // String suffix, /// 0, // int num_slices, // (0 - all) /// null); // int [] wh); combo_dsn_final =quadCLTs[ref_index].restoreComboDSI(true); // also sets quadCLTs[ref_index].dsi and blue sky } // re-load , should create quadCLTs[ref_index].dsi double [][] dls = { combo_dsn_final[COMBO_DSN_INDX_DISP], combo_dsn_final[COMBO_DSN_INDX_LMA], combo_dsn_final[COMBO_DSN_INDX_STRENGTH] }; int dbg_condition = debug_ranges ? Math.max(1, debugLevel) : debugLevel; double [][] ds = conditionInitialDS( // Add debug szxy by providing debugLevel=1 true, // boolean use_conf, // use configuration parameters, false - use following clt_parameters, // CLTParameters clt_parameters, dls, // double [][] dls quadCLTs[ref_index], // QuadCLT scene, dbg_condition); // int debug_level) double [] disparity = ds[0]; double [] strength = ds[1]; double [][]szxy = getSceneSZXY( quadCLTs[ref_index], // QuadCLT scene, range_disparity_offset, // double disparity_offset, range_min_strength, // double min_strength, range_max, // double max_range, disparity, // double [] disparity, strength); // double [] strength) String [] szxy_titles = {"strength", "Z(m)", "X(m)", "Y(m)"}; TileProcessor tp = quadCLTs[ref_index].getTileProcessor(); int tilesX = tp.getTilesX(); int tilesY = tp.getTilesY(); ImagePlus impSZXY = ShowDoubleFloatArrays.makeArrays( szxy, tilesX, tilesY, quadCLTs[ref_index].getImageName()+"_SZXY", szxy_titles); if (export_dsi_image) { quadCLTs[ref_index].saveImagePlusInModelDirectory( null, // "GPU-SHIFTED-BACKGROUND", // String suffix, impSZXY); // ImagePlus imp) } if (show_dsi_image) { impSZXY.show(); } } // debugging 3D model int [] whs = new int[3]; double [] x0y0 = new double[2]; if (export3d) { //combo_dsn_final had strength 1.0e-4 where it should not? Reset it? /* */ /* boolean use_lma = true; // ; double discard_low = 0.01; // fraction of all pixels double discard_high = 0.5; // fraction of all pixels Loading @@ -5817,6 +5893,7 @@ public class OpticalFlow { double [] hdr_x0y0 = new double[2]; double [][] to_ground_xyxatr = quadCLTs[ref_index].getGround( use_lma, // boolean use_lma, clt_parameters.imp.range_disparity_offset,// double range_disparity_offset discard_low, // double discard_low, // fraction of all pixels discard_high, // double discard_high, // fraction of all pixels discard_adisp, // double discard_adisp, // discard above/below this fraction of average height Loading @@ -5827,7 +5904,7 @@ public class OpticalFlow { hdr_whs, // int [] whs, // initialize to int[3] to return {width, height, scale reduction} debugLevel); // int debug_level /**/ */ boolean ok_3d = TexturedModel.output3d( // quadCLTs have same image name, and everything else clt_parameters, // CLTParameters clt_parameters, Loading Loading @@ -6085,58 +6162,6 @@ public class OpticalFlow { } } if (export_dsi_image || show_dsi_image) { if (combo_dsn_final == null) { /// combo_dsn_final =quadCLTs[ref_index].readDoubleArrayFromModelDirectory( /// "-INTER-INTRA-LMA", // String suffix, /// 0, // int num_slices, // (0 - all) /// null); // int [] wh); combo_dsn_final =quadCLTs[ref_index].restoreComboDSI(true); // also sets quadCLTs[ref_index].dsi and blue sky } // re-load , should create quadCLTs[ref_index].dsi double [][] dls = { combo_dsn_final[COMBO_DSN_INDX_DISP], combo_dsn_final[COMBO_DSN_INDX_LMA], combo_dsn_final[COMBO_DSN_INDX_STRENGTH] }; int dbg_condition = debug_ranges ? Math.max(1, debugLevel) : debugLevel; double [][] ds = conditionInitialDS( // Add debug szxy by providing debugLevel=1 true, // boolean use_conf, // use configuration parameters, false - use following clt_parameters, // CLTParameters clt_parameters, dls, // double [][] dls quadCLTs[ref_index], // QuadCLT scene, dbg_condition); // int debug_level) double [] disparity = ds[0]; double [] strength = ds[1]; double [][]szxy = getSceneSZXY( quadCLTs[ref_index], // QuadCLT scene, range_disparity_offset, // double disparity_offset, range_min_strength, // double min_strength, range_max, // double max_range, disparity, // double [] disparity, strength); // double [] strength) String [] szxy_titles = {"strength", "Z(m)", "X(m)", "Y(m)"}; TileProcessor tp = quadCLTs[ref_index].getTileProcessor(); int tilesX = tp.getTilesX(); int tilesY = tp.getTilesY(); ImagePlus impSZXY = ShowDoubleFloatArrays.makeArrays( szxy, tilesX, tilesY, quadCLTs[ref_index].getImageName()+"_SZXY", szxy_titles); if (export_dsi_image) { quadCLTs[ref_index].saveImagePlusInModelDirectory( null, // "GPU-SHIFTED-BACKGROUND", // String suffix, impSZXY); // ImagePlus imp) } if (show_dsi_image) { impSZXY.show(); } } if (export_ml_files) { if (combo_dsn_final == null) { // always re-read? Loading Loading @@ -13112,11 +13137,22 @@ public class OpticalFlow { } return null; } if (avg_offs > min_max[1]) {// NaN - do not check; if (fail_reason != null) { fail_reason[0]=FAIL_REASON_MAX; } if (debug_level > -3){ System.out.println ("interCorrPair(): avg_offs = "+avg_offs+ " > "+min_max[1]+", sw = "+sw); } return null; } else { if (debug_level > -3){ System.out.println ("interCorrPair(): avg_offs = "+avg_offs+ " <= "+min_max[1]+", sw = "+sw); } } } double half_disparity = near_important ? 0.0 : clt_parameters.imp.half_disparity; Loading Loading @@ -14242,6 +14278,7 @@ public class OpticalFlow { // double mb_max_gain = clt_parameters.imp.mb_max_gain_inter; // 5.0; // motion blur maximal gain (if more - move second point more than a pixel int margin = clt_parameters.imp.margin; double second_margin = 1.1; // allow slightly larger offset for readjsutments (to be limited by the first pass) double boost_max_short = 5.0; // 2.0; // Some bug? int earliest_scene = 0; boolean use_combo_dsi = clt_parameters.imp.use_combo_dsi; boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi; Loading @@ -14250,14 +14287,14 @@ public class OpticalFlow { int tilesY = quadCLTs[ref_index].getTileProcessor().getTilesY(); int tile_size = quadCLTs[ref_index].getTileProcessor().getTileSize(); double min_offset = clt_parameters.imp.min_offset; double max_offset = second_margin*clt_parameters.imp.max_rel_offset * tilesX * tile_size; double max_offset = boost_max_short*second_margin*clt_parameters.imp.max_rel_offset * tilesX * tile_size; double max_roll = second_margin*clt_parameters.imp.max_roll_deg*Math.PI/180.0; double max_zoom_diff = second_margin*clt_parameters.imp.max_zoom_diff; boolean fpn_skip = clt_parameters.imp.fpn_skip; // if false - fail as before boolean fpn_rematch = clt_parameters.imp.fpn_rematch; // if false - keep previous double [] min_max = {min_offset, max_offset, 0.0} ; // {min, max, actual rms) int [] fail_reason = new int[1]; // null or int[1]: 0 - OK, 2 - LMA, 3 - min, 4 - max System.out.println("reAdjustPairsLMAInterscene(): min_offset="+min_max[0]+", max_offset="+min_max[1]); double [] disparity_raw = new double [tilesX * tilesY]; Arrays.fill(disparity_raw,clt_parameters.disparity); /// double [][] combo_dsn_final = quadCLTs[ref_index].readDoubleArrayFromModelDirectory(
src/main/java/com/elphel/imagej/tileprocessor/QuadCLTCPU.java +44 −14 Original line number Diff line number Diff line Loading @@ -223,6 +223,7 @@ public class QuadCLTCPU { // cac public double [][] getGround( boolean use_lma, double disparity_offset, double discard_low, // fraction of all pixels double discard_high, // fraction of all pixels double discard_adisp, // discard above/below this fraction of average height Loading @@ -234,22 +235,24 @@ public class QuadCLTCPU { int debug_level ) { double [] z_tilts = null; final int tilesX=getTileProcessor().getTilesX(); final int tilesY=getTileProcessor().getTilesY(); double hist_rlow = 0.4; double normal_damping = 0.001; // pull to horizontal if not enough data // final int tilesX=getTileProcessor().getTilesX(); // final int tilesY=getTileProcessor().getTilesY(); double hist_rlow = 0.5; double hist_rhigh = 2.0; int min_good = 20; //number of good tiles int min_good_quad = 20; // number of good tiles per quadrantto calculate tilts int gap_frac2= 20; /// int min_good_quad = 20; // number of good tiles per quadrant to calculate tilts /// int gap_frac2= 20; double rel_hight = 0.2; // when calculating scale, ignore objects far from plane int num_bins = 1000; double [][] dls = getDLS(); if (dls==null) { return null; } double [][] ds = new double [][] {dls[use_lma?1:0], dls[2]}; double [][] ds = new double [][] {dls[use_lma?1:0].clone(), dls[2]}; double sw=0, swd=0; for (int i = 0; i < ds[0].length; i++) if (!Double.isNaN(ds[0][i])){ ds[0][i] -= disparity_offset; sw += ds[1][i]; swd += ds[0][i] * ds[1][i]; } Loading Loading @@ -318,7 +321,9 @@ public class QuadCLTCPU { } return null; // too few good } double z_avg= getGeometryCorrection().getZFromDisparity(swd/sw); // double z_avg= getGeometryCorrection().getZFromDisparity(swd/sw); /* int gap_x_0 = tilesX/2 - tilesX/gap_frac2; int gap_x_1 = tilesX/2 + tilesX/gap_frac2; int gap_y_0 = tilesY/2 - tilesY/gap_frac2; Loading Loading @@ -348,9 +353,11 @@ public class QuadCLTCPU { System.out.println("There are less than 3 quadrants ("+num_good_quads+") having more than "+min_good_quad+" tiles"); System.out.println("Using only level "+z_avg+", ignoring tilt."); } z_tilts = new double[] {z_avg, 0.0, 0.0}; // no tilts z_tilts = new double[] {-z_avg, 0.0, 0.0}; // no tilts // return new double[] {z_avg, 0.0, 0.0}; // no tilts } else { */ // fit plane double [] ref_disparity = ds[0].clone(); for (int i = 0; i < ref_disparity.length; i++) { Loading Loading @@ -381,17 +388,18 @@ public class QuadCLTCPU { mindx++; } PolynomialApproximation pa = new PolynomialApproximation(); double [] damping = new double [] {normal_damping, normal_damping}; double[][] approx2d = pa.quadraticApproximation( mdata, true, // boolean forceLinear, // use linear approximation null, // double [] damping, null OK damping, // double [] damping, null OK -1); // debug level z_tilts= new double [] { approx2d[0][2], approx2d[0][0], approx2d[0][1]}; if (debug_level > -3) { System.out.println("Found ground plane: level="+z_tilts[0]+", tiltX="+z_tilts[1]+", tiltY="+z_tilts[2]); } } /* } */ // ground - negative Z. picture right - positive X, picture up - positive Y // positive tiltX - to the right higher ground (lower altitude above it) or camera tilted left // positive tiltY - picture up - higher ground (or camera tilted back) Loading @@ -402,11 +410,16 @@ public class QuadCLTCPU { // It is approximate for small angles. OK for now double [][] to_ground_xyxatr = ErsCorrection.invertXYZATR(ground_xyxatr); // recalculate coordinates for all pixels including weak ones double [] ref_disparity = dls[0].clone(); // double [] ref_disparity = dls[0].clone(); for (int i = 0; i < ref_disparity.length; i++) { if (Double.isNaN(ref_disparity[i])) ref_disparity[i] = 0.0; else { ref_disparity[i] -= disparity_offset; } double [][] wxyz = OpticalFlow.transformToWorldXYZ( } // double [][] wxyz = OpticalFlow.transformToWorldXYZ( ref_disparity, // final double [] disparity_ref, // invalid tiles - NaN in disparity (QuadCLT) this, // final QuadCLT quadClt, // now - may be null - for testing if scene is rotated ref THREADS_MAX); // int threadsMax) Loading @@ -432,8 +445,11 @@ public class QuadCLTCPU { if (y < y_min_max[0]) y_min_max[0] = y; else if (y > y_min_max[1]) y_min_max[1] = y; } if ((x_min_max == null) || (y_min_max == null)) { return null; // no points at all? } if (x0y0!=null) { x0y0[0] = x_min_max[0]; x0y0[0] = x_min_max[0]; // null x0y0[1] = y_min_max[0]; } int scale = 0; Loading Loading @@ -8387,6 +8403,9 @@ public class QuadCLTCPU { double [][] rgba = new double [num_slices][]; for (int i = 0; i < 3; i++) rgba[i] = new double [texture_data[main_color_index].length]; for (int i = 0; i < rbg_in[main_color_index].length; i++) { if (i==160000) { System.out.println ("i="+i); } double [] rgb = tc.getRGB(texture_data[main_color_index][i]); rgba[0][i] = rgb[0]; // red rgba[1][i] = rgb[1]; // green Loading Loading @@ -15421,6 +15440,7 @@ public class QuadCLTCPU { public boolean writeLwirPreview( final CLTParameters clt_parameters, double [] data, double [] minmax, // null for auto QuadCLT scene, int tex_palette, String suffix, Loading @@ -15429,6 +15449,7 @@ public class QuadCLTCPU { clt_parameters, data, getTileProcessor().getTilesX() *getTileProcessor().getTileSize(), minmax, // double [] minmax, // null for auto scene, tex_palette, suffix, Loading @@ -15438,6 +15459,7 @@ public class QuadCLTCPU { final CLTParameters clt_parameters, double [] data, int width, double [] minmax, // null for auto QuadCLT scene, int tex_palette, String suffix, Loading @@ -15449,7 +15471,15 @@ public class QuadCLTCPU { for (int i = 0; i < rendered_texture[0].length; i++) { rendered_texture[1][i] = Double.isNaN(rendered_texture[0][i])? 0.0: 1.0; } double [] minmax = scene.getColdHot(); // used in linearStackToColor (from this current scene) // double [] minmax = scene.getColdHot(); // used in linearStackToColor (from this current scene) if (!suffix.equals("")) { if (minmax == null) { // to replace standard preview file name minmax = scene.getColdHot(); // used in linearStackToColor (from this current scene) suffix +="-AUTORANGE"; } else { suffix +="-RANGE"+(minmax[1]-minmax[0]); } } // int width = getTileProcessor().getTilesX() *getTileProcessor().getTileSize(); int height = data.length/width; String set_name = getImageName();