Loading src/main/java/com/elphel/imagej/gpu/TpTask.java +47 −0 Original line number Original line Diff line number Diff line package com.elphel.imagej.gpu; package com.elphel.imagej.gpu; import java.util.Arrays; import com.elphel.imagej.common.ShowDoubleFloatArrays; public class TpTask { public class TpTask { public int task; public int task; // task bits 0..7 - texture neighbors (0 - N, 1 - NE, ..., 7 - NW) // task bits 0..7 - texture neighbors (0 - N, 1 - NE, ..., 7 - NW) Loading Loading @@ -232,4 +236,47 @@ public class TpTask { } } return flt; return flt; } } public static void showTpTask( TpTask[] tp_tasks, int tilesX, int tilesY, String title) { int numSensors = tp_tasks[0].num_sensors; String [] titles0 = {"X-cent", "Y-cent", "Disp","Scale"}; String [] titles = new String[titles0.length+2*numSensors]; for (int i = 0; i < titles0.length; i++) { titles[i] = titles0[i]; } for (int i = 0; i < numSensors; i++) { titles[titles0.length + 2*i + 0] = "X-"+i; titles[titles0.length + 2*i + 1] = "Y-"+i; } double [][] data = new double [titles.length][tilesX*tilesY]; for (int i = 0; i < data.length; i++) { Arrays.fill(data[i], Double.NaN); } for (int nTask = 0; nTask < tp_tasks.length; nTask++) { TpTask task = tp_tasks[nTask]; int nTile = task.ty*tilesX+task.tx; data [0][nTile] = task.centerXY[0]; data [1][nTile] = task.centerXY[1]; data [2][nTile] = task.target_disparity; data [3][nTile] = task.scale; for (int i = 0; i < numSensors; i++) { data [titles0.length + 2*i + 0][nTile] = task.xy[i][0]; data [titles0.length + 2*i + 1][nTile] = task.xy[i][1]; } } ShowDoubleFloatArrays.showArrays( data, tilesX, tilesY, true, title, titles); } } } No newline at end of file src/main/java/com/elphel/imagej/tileprocessor/Interscene.java +121 −37 Original line number Original line Diff line number Diff line Loading @@ -1950,6 +1950,27 @@ public class Interscene { avg_z, // double avg_z, avg_z, // double avg_z, last_scene, // latest_scene, // int ref_index, // >= earliest_scene last_scene, // latest_scene, // int ref_index, // >= earliest_scene earliest_scene); // int earliest_scene) earliest_scene); // int earliest_scene) boolean test_adjust1 = debugLevel > 1000; if (test_adjust1) { int [][] fpn_pairs_dbg = new int [fpn_pairs.length+3][2]; int ipair = 0; for (; ipair < fpn_pairs.length; ipair++) { fpn_pairs_dbg[ipair] = fpn_pairs[ipair].clone(); } fpn_pairs_dbg[ipair++] = new int[] {41,30}; fpn_pairs_dbg[ipair++] = new int[] {30,45}; fpn_pairs_dbg[ipair++] = new int[] {41,45}; for (int i = fpn_pairs.length; i < fpn_pairs_dbg.length; i++) { int nscene = fpn_pairs_dbg[i][0]; quadCLTs[nscene].getErsCorrection().setErsDt( // set for ref also (should be set before non-ref!) QuadCLTCPU.scaleDtToErs( clt_parameters, dxyzatr_dt[nscene])); } fpn_pairs = fpn_pairs_dbg; } for (int ipair = 0; ipair < fpn_pairs.length; ipair++) if (fpn_pairs[ipair][1] >= 0) { for (int ipair = 0; ipair < fpn_pairs.length; ipair++) if (fpn_pairs[ipair][1] >= 0) { if (debugLevel > -4) { if (debugLevel > -4) { System.out.println("Mitigating FPN for scene "+fpn_pairs[ipair][0]+ System.out.println("Mitigating FPN for scene "+fpn_pairs[ipair][0]+ Loading Loading @@ -2018,6 +2039,50 @@ public class Interscene { } } } } boolean test_adjust1 = debugLevel > 1000; if (test_adjust1) { int [] test_pair = {0, ref_index}; while (test_adjust1) { double [] test_lma_rms = new double[2]; TpTask[][] tp_tasks_test_rel_ref = new TpTask[2][]; System.out.println("test_adjust scene = "+test_pair[0]+", reference="+test_pair[1]); double [][] test_xyzatr = adjustDiffPairsLMAInterscene( // compare two scenes, first may be reference, use motion blur clt_parameters, //CLTParameters clt_parameters, use_lma_dsi, //,boolean use_lma_dsi, fpn_disable, // boolean fpn_disable, // disable fpn filter if images are known to be too close disable_ers, // boolean disable_ers, min_max, // double [] min_max, // null or pair of minimal and maximal offsets fail_reason, // int [] fail_reason, // null or int[1]: 0 - OK, 1 - LMA, 2 - min, 3 - max quadCLTs, // QuadCLT [] quadCLTs, ref_index, // int ref_index, tp_tasks_test_rel_ref, // TpTask[][] tp_tasks_ref, // Should be TpTask[2][*]. If tp_tasks_ref[0] == null will calculate // at set first scene to the GPU pXpYD_ref, // double [][] pXpYD_ref, // should be se or at least double [num_tiles][] if tp_tasks_ref[0] == null // will be recalculated when tp_tasks_ref[0] == null, but for reference frame test_pair[1], // int nscene0, // may be == ref_index test_pair[0], // int nscene1, // compares to nscene0 interscene_ref_disparity,// double [] ref_disparity, // null or alternative reference disparity reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles scenes_xyzatr[test_pair[1]],// double [][] scene0_xyzatr, scenes_xyzatr[test_pair[0]], // double [][] scene1_xyzatr, avg_z, // double average_z, scenes_xyzatr_pull [test_pair[0]], // double [][] scene1_xyzatr_pull, param_select, // boolean[] param_select, param_regweights, // double [] param_regweights, test_lma_rms, // double [] rms_out, // null or double [2] max_rms, // double max_rms, mb_en, // boolean mb_en, mb_tau, // double mb_tau, // 0.008; // time constant, sec mb_max_gain, // double mb_max_gain, // 5.0; // motion blur maximal gain (if more - move second point more than a pixel clt_parameters.imp.debug_level); // int debugLevel) boolean adjust_OK_test = test_xyzatr != null; System.out.println("adjust_OK_test = "+adjust_OK_test); System.out.println("reAdjustPairsLMAInterscene "+test_pair[0]+ quadCLTs[test_pair[1]].getImageName() + "/" + quadCLTs[test_pair[0]].getImageName()+ " Done. RMS="+test_lma_rms[0]); System.out.println("test_adjust = "+test_adjust1); } } // TODO: after all scenes done, see if any of scenes_xyzatr[] is null, and if fpn_rematch - rematch // TODO: after all scenes done, see if any of scenes_xyzatr[] is null, and if fpn_rematch - rematch if (dbg_mb_img != null) { if (dbg_mb_img != null) { String [] dbg_mb_titles = new String[quadCLTs.length]; String [] dbg_mb_titles = new String[quadCLTs.length]; Loading Loading @@ -2208,10 +2273,9 @@ public class Interscene { reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles tp_tasks_ref[0], // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction tp_tasks_ref[0], // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction quadCLTs[nscene1], // QuadCLT scene_QuadClt, quadCLTs[nscene1], // QuadCLT scene_QuadClt, scene1_xyzatr[0], // double [] camera_xyz, scene1_xyzatr, // double [][] camera_xyzatr, scene1_xyzatr[1], // double [] camera_atr, scene1_xyzatr_pull,// double [][] scene_xyzatr_pull, // if both are not null, specify target values to pull to scene1_xyzatr_pull[0], // double [] scene_xyz_pull, // if both are not null, specify target values to pull to scene0_xyzatr, // double [][] ref_xyzatr, scene1_xyzatr_pull[1], // double [] scene_atr_pull, param_select, // boolean[] param_select, param_select, // boolean[] param_select, param_regweights, // double [] param_regweights, param_regweights, // double [] param_regweights, rms_out, // double [] rms_out, // null or double [2] rms_out, // double [] rms_out, // null or double [2] Loading Loading @@ -2272,10 +2336,9 @@ public class Interscene { reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles tp_tasks_ref[0], // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction tp_tasks_ref[0], // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction quadCLTs[nscene1], // QuadCLT scene_QuadClt, quadCLTs[nscene1], // QuadCLT scene_QuadClt, scene1_xyzatr[0], // double [] camera_xyz, scene1_xyzatr, // double [][] camera_xyzatr, scene1_xyzatr[1], // double [] camera_atr, scene1_xyzatr_pull,// double [][] scene_xyzatr_pull, // if both are not null, specify target values to pull to scene1_xyzatr_pull[0], // double [] scene_xyz_pull, // if both are not null, specify target values to pull to scene0_xyzatr, // double [][] ref_xyzatr, scene1_xyzatr_pull[1], // double [] scene_atr_pull, param_select, // boolean[] param_select, param_select, // boolean[] param_select, param_regweights, // double [] param_regweights, param_regweights, // double [] param_regweights, rms_out, // double [] rms_out, // null or double [2] rms_out, // double [] rms_out, // null or double [2] Loading Loading @@ -2341,6 +2404,9 @@ public class Interscene { 0.0, // double mb_max_gain, // 5.0; // motion blur maximal gain (if more - move second point more than a pixel 0.0, // double mb_max_gain, // 5.0; // motion blur maximal gain (if more - move second point more than a pixel null, // double [][] mb_vectors, // now [2][ntiles]; null, // double [][] mb_vectors, // now [2][ntiles]; debug_level); // int debug_level) debug_level); // int debug_level) double [][] scene_xyzatr = new double[][] {camera_xyz, camera_atr}; // double [][] scene_xyzatr_pull = new double[][] {scene_xyz_pull, scene_atr_pull}; // double [][] ref_xyzatr = new double[2][3]; return adjustPairsLMAInterscene( // assumes reference GPU data is already set - once for multiple scenes return adjustPairsLMAInterscene( // assumes reference GPU data is already set - once for multiple scenes clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters, true, // boolean initial_adjust, true, // boolean initial_adjust, Loading @@ -2354,10 +2420,9 @@ public class Interscene { reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles tp_tasks_ref2[0], // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction tp_tasks_ref2[0], // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction scene_QuadClt, // QuadCLT scene_QuadClt, scene_QuadClt, // QuadCLT scene_QuadClt, camera_xyz, // double [] camera_xyz, scene_xyzatr, // double [][] scene_xyzatr, camera_atr, // double [] camera_atr, scene_xyzatr_pull, // double [][] scene_xyzatr_pull, // if both are not null, specify target values to pull to scene_xyz_pull, // double [] scene_xyz_pull, // if both are not null, specify target values to pull to ref_xyzatr, // double [][] ref_xyzatr scene_atr_pull, // double [] scene_atr_pull, param_select, // boolean[] param_select, param_select, // boolean[] param_select, param_regweights, // double [] param_regweights, param_regweights, // double [] param_regweights, rms_out, // double [] rms_out, // null or double [2] rms_out, // double [] rms_out, // null or double [2] Loading @@ -2382,10 +2447,9 @@ public class Interscene { boolean [] reliable_ref, // null or bitmask of reliable reference tiles boolean [] reliable_ref, // null or bitmask of reliable reference tiles TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction QuadCLT scene_QuadClt, QuadCLT scene_QuadClt, double [] camera_xyz, double [][] scene_xyzatr, double [] camera_atr, double [][] scene_xyzatr_pull, // if both are not null, specify target values to pull to double [] scene_xyz_pull, // if both are not null, specify target values to pull to double [][] ref_xyzatr, // double [] scene_atr_pull, // boolean[] param_select, boolean[] param_select, double [] param_regweights, double [] param_regweights, double [] rms_out, // null or double [2] double [] rms_out, // null or double [2] Loading Loading @@ -2413,8 +2477,7 @@ public class Interscene { disparity_weight); disparity_weight); int lmaResult = -1; int lmaResult = -1; boolean last_run = false; boolean last_run = false; double[] camera_xyz0 = camera_xyz.clone(); double[][] scene_xyzatr0 = new double [][] {scene_xyzatr[0].clone(),scene_xyzatr[1].clone()}; double[] camera_atr0 = camera_atr.clone(); double [][][] coord_motion = null; double [][][] coord_motion = null; boolean show_corr_fpn = (!clt_parameters.multiseq_run) && (debug_level > -1); // -3; *********** Change to debug FPN correleation *** boolean show_corr_fpn = (!clt_parameters.multiseq_run) && (debug_level > -1); // -3; *********** Change to debug FPN correleation *** // float [][] dbg_corr_fpn = debug_corr_fpn ? (new float [34][]) : null; // float [][] dbg_corr_fpn = debug_corr_fpn ? (new float [34][]) : null; Loading @@ -2437,8 +2500,8 @@ public class Interscene { pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene tp_tasks_ref, // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction tp_tasks_ref, // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction scene_QuadClt, // QuadCLT scene_QuadCLT, scene_QuadClt, // QuadCLT scene_QuadCLT, camera_xyz0, // xyz scene_xyzatr0[0], // xyz camera_atr0, // pose[1], // atr scene_xyzatr0[1], // pose[1], // atr reliable_ref, // ****null, // final boolean [] selection, // may be null, if not null do not process unselected tiles reliable_ref, // ****null, // final boolean [] selection, // may be null, if not null do not process unselected tiles margin, // final int margin, margin, // final int margin, sensor_mask_inter, // final int sensor_mask_inter, // The bitmask - which sensors to correlate, -1 - all. sensor_mask_inter, // final int sensor_mask_inter, // The bitmask - which sensors to correlate, -1 - all. Loading Loading @@ -2498,13 +2561,12 @@ public class Interscene { ers_scene.ers_wxyz_center_dt = ers_ref.ers_wxyz_center_dt.clone(); ers_scene.ers_wxyz_center_dt = ers_ref.ers_wxyz_center_dt.clone(); */ */ } } // double [][] ref_xyzatr_inv = ErsCorrection.invertXYZATR(ref_xyzatr); // TODO: save ers_scene.ers_watr_center_dt and ers_scene.ers_wxyz_center_dt // TODO: save ers_scene.ers_watr_center_dt and ers_scene.ers_wxyz_center_dt intersceneLma.prepareLMA( intersceneLma.prepareLMA( camera_xyz0, // final double [] scene_xyz0, // camera center in world coordinates (or null to use instance) scene_xyzatr0, // final double [] scene_xyzatr0, // camera center in world coordinates (or null to use instance) camera_atr0, // final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance) scene_xyzatr_pull, // final double [] scene_xyz_pull, // if both are not null, specify target values to pull to scene_xyz_pull, // final double [] scene_xyz_pull, // if both are not null, specify target values to pull to ref_xyzatr, // _inv, // ref_xyzatr, scene_atr_pull, // final double [] scene_atr_pull, // // reference atr, xyz are considered 0.0 not anymore? // reference atr, xyz are considered 0.0 not anymore? scene_QuadClt, // final QuadCLT scene_QuadClt, scene_QuadClt, // final QuadCLT scene_QuadClt, reference_QuadClt, // final QuadCLT reference_QuadClt, reference_QuadClt, // final QuadCLT reference_QuadClt, Loading Loading @@ -2538,8 +2600,7 @@ public class Interscene { System.out.println ("iter="+lmaResult+", RMS="+intersceneLma.getLastRms()[0]+ System.out.println ("iter="+lmaResult+", RMS="+intersceneLma.getLastRms()[0]+ " (Pure RMS="+intersceneLma.getLastRms()[1]+")"); " (Pure RMS="+intersceneLma.getLastRms()[1]+")"); } } camera_xyz0 = intersceneLma.getSceneXYZ(false); // true for initial values scene_xyzatr0 = intersceneLma.getSceneXYZATR(false); // true for initial values camera_atr0 = intersceneLma.getSceneATR(false); // true for initial values double [] diffs_atr = intersceneLma.getV3Diff(ErsCorrection.DP_DSAZ); double [] diffs_atr = intersceneLma.getV3Diff(ErsCorrection.DP_DSAZ); double [] diffs_xyz = intersceneLma.getV3Diff(ErsCorrection.DP_DSX); double [] diffs_xyz = intersceneLma.getV3Diff(ErsCorrection.DP_DSX); if ((diffs_atr[0] < clt_parameters.imp.exit_change_atr) && if ((diffs_atr[0] < clt_parameters.imp.exit_change_atr) && Loading Loading @@ -2581,8 +2642,8 @@ public class Interscene { pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene tp_tasks_ref, // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction tp_tasks_ref, // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction scene_QuadClt, // QuadCLT scene_QuadCLT, scene_QuadClt, // QuadCLT scene_QuadCLT, camera_xyz0, // xyz scene_xyzatr0[0], // xyz camera_atr0, // pose[1], // atr scene_xyzatr0[1], // pose[1], // atr reliable_ref, // ****null, // final boolean [] selection, // may be null, if not null do not process unselected tiles reliable_ref, // ****null, // final boolean [] selection, // may be null, if not null do not process unselected tiles margin, // final int margin, margin, // final int margin, sensor_mask_inter, // final int sensor_mask_inter, // The bitmask - which sensors to correlate, -1 - all. sensor_mask_inter, // final int sensor_mask_inter, // The bitmask - which sensors to correlate, -1 - all. Loading Loading @@ -2632,8 +2693,8 @@ public class Interscene { pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene tp_tasks_ref, // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction tp_tasks_ref, // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction scene_QuadClt, // QuadCLT scene_QuadCLT, scene_QuadClt, // QuadCLT scene_QuadCLT, camera_xyz0, // xyz scene_xyzatr0[0], // xyz camera_atr0, // pose[1], // atr scene_xyzatr0[1], // pose[1], // atr reliable_ref, // ****null, // final boolean [] selection, // may be null, if not null do not process unselected tiles reliable_ref, // ****null, // final boolean [] selection, // may be null, if not null do not process unselected tiles margin, // final int margin, margin, // final int margin, sensor_mask_inter, // final int sensor_mask_inter, // The bitmask - which sensors to correlate, -1 - all. sensor_mask_inter, // final int sensor_mask_inter, // The bitmask - which sensors to correlate, -1 - all. Loading Loading @@ -2687,7 +2748,7 @@ public class Interscene { return null; return null; } } } } return new double [][] {camera_xyz0, camera_atr0}; return scene_xyzatr0; } } Loading Loading @@ -2954,7 +3015,8 @@ public class Interscene { double fpn_max_offset = clt_parameters.imp.fpn_max_offset; double fpn_max_offset = clt_parameters.imp.fpn_max_offset; double fpn_radius = clt_parameters.imp.fpn_radius; double fpn_radius = clt_parameters.imp.fpn_radius; boolean fpn_ignore_border = clt_parameters.imp.fpn_ignore_border; // only if fpn_mask != null - ignore tile if maximum touches fpn_mask boolean fpn_ignore_border = clt_parameters.imp.fpn_ignore_border; // only if fpn_mask != null - ignore tile if maximum touches fpn_mask boolean show_tptask_ref = false; boolean show_tptask_scene = false; boolean eq_debug = false; boolean eq_debug = false; boolean transform_debug = false; boolean transform_debug = false; boolean eq_en = near_important && clt_parameters.imp.eq_en; // true;// equalize "important" FG tiles for better camera XYZ fitting boolean eq_en = near_important && clt_parameters.imp.eq_en; // true;// equalize "important" FG tiles for better camera XYZ fitting Loading Loading @@ -2988,6 +3050,17 @@ public class Interscene { System.out.println("interCorrPair(): "+IntersceneLma.printNameV3("ATR",scene_atr)+ System.out.println("interCorrPair(): "+IntersceneLma.printNameV3("ATR",scene_atr)+ " "+IntersceneLma.printNameV3("XYZ",scene_xyz)); " "+IntersceneLma.printNameV3("XYZ",scene_xyz)); } } if (show_tptask_ref) { if (tp_tasks_ref != null){ String dbg_title = ref_scene.getImageName()+"-ref"; TpTask.showTpTask( tp_tasks_ref, // TpTask[] tp_tasks, tilesX, // int tilesX, tilesY, // int tilesY, dbg_title); // String title) } } ImageDtt image_dtt; ImageDtt image_dtt; image_dtt = new ImageDtt( image_dtt = new ImageDtt( ref_scene.getNumSensors(), // , ref_scene.getNumSensors(), // , Loading Loading @@ -3126,7 +3199,7 @@ public class Interscene { } } } } if (transform_debug) { if (transform_debug) { // calculate with no transform // calculate wi/media/elphel/SSD3-4GB/lwir16-proc/berdich3/sel-mod1/1697879036_777649/debug/v15_12A/th no transform double [][] dbg_ref_pXpYD = OpticalFlow.transformToScenePxPyD( // will be null for disparity == NaN, total size - tilesX*tilesY double [][] dbg_ref_pXpYD = OpticalFlow.transformToScenePxPyD( // will be null for disparity == NaN, total size - tilesX*tilesY null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null) null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null) ref_disparity, // dls[0], // final double [] disparity_ref, // invalid tiles - NaN in disparity (maybe it should not be masked by margins?) ref_disparity, // dls[0], // final double [] disparity_ref, // invalid tiles - NaN in disparity (maybe it should not be masked by margins?) Loading Loading @@ -3242,6 +3315,17 @@ public class Interscene { THREADS_MAX, // final int threadsMax, // maximal number of threads to launch THREADS_MAX, // final int threadsMax, // maximal number of threads to launch debug_level); // final int globalDebugLevel); debug_level); // final int globalDebugLevel); } } if (show_tptask_scene) { for (int i = 0; i < tp_tasks.length; i++) if (tp_tasks_ref[i] != null){ String dbg_title = scene.getImageName()+"-scn-"+i; TpTask.showTpTask( tp_tasks[i], // TpTask[] tp_tasks, tilesX, // int tilesX, tilesY, // int tilesY, dbg_title); // String title) } } if (show_render_ref) { if (show_render_ref) { ImagePlus imp_render_ref = ref_scene.renderFromTD ( ImagePlus imp_render_ref = ref_scene.renderFromTD ( -1, // final int sensor_mask, -1, // final int sensor_mask, Loading Loading
src/main/java/com/elphel/imagej/gpu/TpTask.java +47 −0 Original line number Original line Diff line number Diff line package com.elphel.imagej.gpu; package com.elphel.imagej.gpu; import java.util.Arrays; import com.elphel.imagej.common.ShowDoubleFloatArrays; public class TpTask { public class TpTask { public int task; public int task; // task bits 0..7 - texture neighbors (0 - N, 1 - NE, ..., 7 - NW) // task bits 0..7 - texture neighbors (0 - N, 1 - NE, ..., 7 - NW) Loading Loading @@ -232,4 +236,47 @@ public class TpTask { } } return flt; return flt; } } public static void showTpTask( TpTask[] tp_tasks, int tilesX, int tilesY, String title) { int numSensors = tp_tasks[0].num_sensors; String [] titles0 = {"X-cent", "Y-cent", "Disp","Scale"}; String [] titles = new String[titles0.length+2*numSensors]; for (int i = 0; i < titles0.length; i++) { titles[i] = titles0[i]; } for (int i = 0; i < numSensors; i++) { titles[titles0.length + 2*i + 0] = "X-"+i; titles[titles0.length + 2*i + 1] = "Y-"+i; } double [][] data = new double [titles.length][tilesX*tilesY]; for (int i = 0; i < data.length; i++) { Arrays.fill(data[i], Double.NaN); } for (int nTask = 0; nTask < tp_tasks.length; nTask++) { TpTask task = tp_tasks[nTask]; int nTile = task.ty*tilesX+task.tx; data [0][nTile] = task.centerXY[0]; data [1][nTile] = task.centerXY[1]; data [2][nTile] = task.target_disparity; data [3][nTile] = task.scale; for (int i = 0; i < numSensors; i++) { data [titles0.length + 2*i + 0][nTile] = task.xy[i][0]; data [titles0.length + 2*i + 1][nTile] = task.xy[i][1]; } } ShowDoubleFloatArrays.showArrays( data, tilesX, tilesY, true, title, titles); } } } No newline at end of file
src/main/java/com/elphel/imagej/tileprocessor/Interscene.java +121 −37 Original line number Original line Diff line number Diff line Loading @@ -1950,6 +1950,27 @@ public class Interscene { avg_z, // double avg_z, avg_z, // double avg_z, last_scene, // latest_scene, // int ref_index, // >= earliest_scene last_scene, // latest_scene, // int ref_index, // >= earliest_scene earliest_scene); // int earliest_scene) earliest_scene); // int earliest_scene) boolean test_adjust1 = debugLevel > 1000; if (test_adjust1) { int [][] fpn_pairs_dbg = new int [fpn_pairs.length+3][2]; int ipair = 0; for (; ipair < fpn_pairs.length; ipair++) { fpn_pairs_dbg[ipair] = fpn_pairs[ipair].clone(); } fpn_pairs_dbg[ipair++] = new int[] {41,30}; fpn_pairs_dbg[ipair++] = new int[] {30,45}; fpn_pairs_dbg[ipair++] = new int[] {41,45}; for (int i = fpn_pairs.length; i < fpn_pairs_dbg.length; i++) { int nscene = fpn_pairs_dbg[i][0]; quadCLTs[nscene].getErsCorrection().setErsDt( // set for ref also (should be set before non-ref!) QuadCLTCPU.scaleDtToErs( clt_parameters, dxyzatr_dt[nscene])); } fpn_pairs = fpn_pairs_dbg; } for (int ipair = 0; ipair < fpn_pairs.length; ipair++) if (fpn_pairs[ipair][1] >= 0) { for (int ipair = 0; ipair < fpn_pairs.length; ipair++) if (fpn_pairs[ipair][1] >= 0) { if (debugLevel > -4) { if (debugLevel > -4) { System.out.println("Mitigating FPN for scene "+fpn_pairs[ipair][0]+ System.out.println("Mitigating FPN for scene "+fpn_pairs[ipair][0]+ Loading Loading @@ -2018,6 +2039,50 @@ public class Interscene { } } } } boolean test_adjust1 = debugLevel > 1000; if (test_adjust1) { int [] test_pair = {0, ref_index}; while (test_adjust1) { double [] test_lma_rms = new double[2]; TpTask[][] tp_tasks_test_rel_ref = new TpTask[2][]; System.out.println("test_adjust scene = "+test_pair[0]+", reference="+test_pair[1]); double [][] test_xyzatr = adjustDiffPairsLMAInterscene( // compare two scenes, first may be reference, use motion blur clt_parameters, //CLTParameters clt_parameters, use_lma_dsi, //,boolean use_lma_dsi, fpn_disable, // boolean fpn_disable, // disable fpn filter if images are known to be too close disable_ers, // boolean disable_ers, min_max, // double [] min_max, // null or pair of minimal and maximal offsets fail_reason, // int [] fail_reason, // null or int[1]: 0 - OK, 1 - LMA, 2 - min, 3 - max quadCLTs, // QuadCLT [] quadCLTs, ref_index, // int ref_index, tp_tasks_test_rel_ref, // TpTask[][] tp_tasks_ref, // Should be TpTask[2][*]. If tp_tasks_ref[0] == null will calculate // at set first scene to the GPU pXpYD_ref, // double [][] pXpYD_ref, // should be se or at least double [num_tiles][] if tp_tasks_ref[0] == null // will be recalculated when tp_tasks_ref[0] == null, but for reference frame test_pair[1], // int nscene0, // may be == ref_index test_pair[0], // int nscene1, // compares to nscene0 interscene_ref_disparity,// double [] ref_disparity, // null or alternative reference disparity reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles scenes_xyzatr[test_pair[1]],// double [][] scene0_xyzatr, scenes_xyzatr[test_pair[0]], // double [][] scene1_xyzatr, avg_z, // double average_z, scenes_xyzatr_pull [test_pair[0]], // double [][] scene1_xyzatr_pull, param_select, // boolean[] param_select, param_regweights, // double [] param_regweights, test_lma_rms, // double [] rms_out, // null or double [2] max_rms, // double max_rms, mb_en, // boolean mb_en, mb_tau, // double mb_tau, // 0.008; // time constant, sec mb_max_gain, // double mb_max_gain, // 5.0; // motion blur maximal gain (if more - move second point more than a pixel clt_parameters.imp.debug_level); // int debugLevel) boolean adjust_OK_test = test_xyzatr != null; System.out.println("adjust_OK_test = "+adjust_OK_test); System.out.println("reAdjustPairsLMAInterscene "+test_pair[0]+ quadCLTs[test_pair[1]].getImageName() + "/" + quadCLTs[test_pair[0]].getImageName()+ " Done. RMS="+test_lma_rms[0]); System.out.println("test_adjust = "+test_adjust1); } } // TODO: after all scenes done, see if any of scenes_xyzatr[] is null, and if fpn_rematch - rematch // TODO: after all scenes done, see if any of scenes_xyzatr[] is null, and if fpn_rematch - rematch if (dbg_mb_img != null) { if (dbg_mb_img != null) { String [] dbg_mb_titles = new String[quadCLTs.length]; String [] dbg_mb_titles = new String[quadCLTs.length]; Loading Loading @@ -2208,10 +2273,9 @@ public class Interscene { reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles tp_tasks_ref[0], // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction tp_tasks_ref[0], // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction quadCLTs[nscene1], // QuadCLT scene_QuadClt, quadCLTs[nscene1], // QuadCLT scene_QuadClt, scene1_xyzatr[0], // double [] camera_xyz, scene1_xyzatr, // double [][] camera_xyzatr, scene1_xyzatr[1], // double [] camera_atr, scene1_xyzatr_pull,// double [][] scene_xyzatr_pull, // if both are not null, specify target values to pull to scene1_xyzatr_pull[0], // double [] scene_xyz_pull, // if both are not null, specify target values to pull to scene0_xyzatr, // double [][] ref_xyzatr, scene1_xyzatr_pull[1], // double [] scene_atr_pull, param_select, // boolean[] param_select, param_select, // boolean[] param_select, param_regweights, // double [] param_regweights, param_regweights, // double [] param_regweights, rms_out, // double [] rms_out, // null or double [2] rms_out, // double [] rms_out, // null or double [2] Loading Loading @@ -2272,10 +2336,9 @@ public class Interscene { reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles tp_tasks_ref[0], // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction tp_tasks_ref[0], // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction quadCLTs[nscene1], // QuadCLT scene_QuadClt, quadCLTs[nscene1], // QuadCLT scene_QuadClt, scene1_xyzatr[0], // double [] camera_xyz, scene1_xyzatr, // double [][] camera_xyzatr, scene1_xyzatr[1], // double [] camera_atr, scene1_xyzatr_pull,// double [][] scene_xyzatr_pull, // if both are not null, specify target values to pull to scene1_xyzatr_pull[0], // double [] scene_xyz_pull, // if both are not null, specify target values to pull to scene0_xyzatr, // double [][] ref_xyzatr, scene1_xyzatr_pull[1], // double [] scene_atr_pull, param_select, // boolean[] param_select, param_select, // boolean[] param_select, param_regweights, // double [] param_regweights, param_regweights, // double [] param_regweights, rms_out, // double [] rms_out, // null or double [2] rms_out, // double [] rms_out, // null or double [2] Loading Loading @@ -2341,6 +2404,9 @@ public class Interscene { 0.0, // double mb_max_gain, // 5.0; // motion blur maximal gain (if more - move second point more than a pixel 0.0, // double mb_max_gain, // 5.0; // motion blur maximal gain (if more - move second point more than a pixel null, // double [][] mb_vectors, // now [2][ntiles]; null, // double [][] mb_vectors, // now [2][ntiles]; debug_level); // int debug_level) debug_level); // int debug_level) double [][] scene_xyzatr = new double[][] {camera_xyz, camera_atr}; // double [][] scene_xyzatr_pull = new double[][] {scene_xyz_pull, scene_atr_pull}; // double [][] ref_xyzatr = new double[2][3]; return adjustPairsLMAInterscene( // assumes reference GPU data is already set - once for multiple scenes return adjustPairsLMAInterscene( // assumes reference GPU data is already set - once for multiple scenes clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters, true, // boolean initial_adjust, true, // boolean initial_adjust, Loading @@ -2354,10 +2420,9 @@ public class Interscene { reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles tp_tasks_ref2[0], // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction tp_tasks_ref2[0], // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction scene_QuadClt, // QuadCLT scene_QuadClt, scene_QuadClt, // QuadCLT scene_QuadClt, camera_xyz, // double [] camera_xyz, scene_xyzatr, // double [][] scene_xyzatr, camera_atr, // double [] camera_atr, scene_xyzatr_pull, // double [][] scene_xyzatr_pull, // if both are not null, specify target values to pull to scene_xyz_pull, // double [] scene_xyz_pull, // if both are not null, specify target values to pull to ref_xyzatr, // double [][] ref_xyzatr scene_atr_pull, // double [] scene_atr_pull, param_select, // boolean[] param_select, param_select, // boolean[] param_select, param_regweights, // double [] param_regweights, param_regweights, // double [] param_regweights, rms_out, // double [] rms_out, // null or double [2] rms_out, // double [] rms_out, // null or double [2] Loading @@ -2382,10 +2447,9 @@ public class Interscene { boolean [] reliable_ref, // null or bitmask of reliable reference tiles boolean [] reliable_ref, // null or bitmask of reliable reference tiles TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction QuadCLT scene_QuadClt, QuadCLT scene_QuadClt, double [] camera_xyz, double [][] scene_xyzatr, double [] camera_atr, double [][] scene_xyzatr_pull, // if both are not null, specify target values to pull to double [] scene_xyz_pull, // if both are not null, specify target values to pull to double [][] ref_xyzatr, // double [] scene_atr_pull, // boolean[] param_select, boolean[] param_select, double [] param_regweights, double [] param_regweights, double [] rms_out, // null or double [2] double [] rms_out, // null or double [2] Loading Loading @@ -2413,8 +2477,7 @@ public class Interscene { disparity_weight); disparity_weight); int lmaResult = -1; int lmaResult = -1; boolean last_run = false; boolean last_run = false; double[] camera_xyz0 = camera_xyz.clone(); double[][] scene_xyzatr0 = new double [][] {scene_xyzatr[0].clone(),scene_xyzatr[1].clone()}; double[] camera_atr0 = camera_atr.clone(); double [][][] coord_motion = null; double [][][] coord_motion = null; boolean show_corr_fpn = (!clt_parameters.multiseq_run) && (debug_level > -1); // -3; *********** Change to debug FPN correleation *** boolean show_corr_fpn = (!clt_parameters.multiseq_run) && (debug_level > -1); // -3; *********** Change to debug FPN correleation *** // float [][] dbg_corr_fpn = debug_corr_fpn ? (new float [34][]) : null; // float [][] dbg_corr_fpn = debug_corr_fpn ? (new float [34][]) : null; Loading @@ -2437,8 +2500,8 @@ public class Interscene { pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene tp_tasks_ref, // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction tp_tasks_ref, // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction scene_QuadClt, // QuadCLT scene_QuadCLT, scene_QuadClt, // QuadCLT scene_QuadCLT, camera_xyz0, // xyz scene_xyzatr0[0], // xyz camera_atr0, // pose[1], // atr scene_xyzatr0[1], // pose[1], // atr reliable_ref, // ****null, // final boolean [] selection, // may be null, if not null do not process unselected tiles reliable_ref, // ****null, // final boolean [] selection, // may be null, if not null do not process unselected tiles margin, // final int margin, margin, // final int margin, sensor_mask_inter, // final int sensor_mask_inter, // The bitmask - which sensors to correlate, -1 - all. sensor_mask_inter, // final int sensor_mask_inter, // The bitmask - which sensors to correlate, -1 - all. Loading Loading @@ -2498,13 +2561,12 @@ public class Interscene { ers_scene.ers_wxyz_center_dt = ers_ref.ers_wxyz_center_dt.clone(); ers_scene.ers_wxyz_center_dt = ers_ref.ers_wxyz_center_dt.clone(); */ */ } } // double [][] ref_xyzatr_inv = ErsCorrection.invertXYZATR(ref_xyzatr); // TODO: save ers_scene.ers_watr_center_dt and ers_scene.ers_wxyz_center_dt // TODO: save ers_scene.ers_watr_center_dt and ers_scene.ers_wxyz_center_dt intersceneLma.prepareLMA( intersceneLma.prepareLMA( camera_xyz0, // final double [] scene_xyz0, // camera center in world coordinates (or null to use instance) scene_xyzatr0, // final double [] scene_xyzatr0, // camera center in world coordinates (or null to use instance) camera_atr0, // final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance) scene_xyzatr_pull, // final double [] scene_xyz_pull, // if both are not null, specify target values to pull to scene_xyz_pull, // final double [] scene_xyz_pull, // if both are not null, specify target values to pull to ref_xyzatr, // _inv, // ref_xyzatr, scene_atr_pull, // final double [] scene_atr_pull, // // reference atr, xyz are considered 0.0 not anymore? // reference atr, xyz are considered 0.0 not anymore? scene_QuadClt, // final QuadCLT scene_QuadClt, scene_QuadClt, // final QuadCLT scene_QuadClt, reference_QuadClt, // final QuadCLT reference_QuadClt, reference_QuadClt, // final QuadCLT reference_QuadClt, Loading Loading @@ -2538,8 +2600,7 @@ public class Interscene { System.out.println ("iter="+lmaResult+", RMS="+intersceneLma.getLastRms()[0]+ System.out.println ("iter="+lmaResult+", RMS="+intersceneLma.getLastRms()[0]+ " (Pure RMS="+intersceneLma.getLastRms()[1]+")"); " (Pure RMS="+intersceneLma.getLastRms()[1]+")"); } } camera_xyz0 = intersceneLma.getSceneXYZ(false); // true for initial values scene_xyzatr0 = intersceneLma.getSceneXYZATR(false); // true for initial values camera_atr0 = intersceneLma.getSceneATR(false); // true for initial values double [] diffs_atr = intersceneLma.getV3Diff(ErsCorrection.DP_DSAZ); double [] diffs_atr = intersceneLma.getV3Diff(ErsCorrection.DP_DSAZ); double [] diffs_xyz = intersceneLma.getV3Diff(ErsCorrection.DP_DSX); double [] diffs_xyz = intersceneLma.getV3Diff(ErsCorrection.DP_DSX); if ((diffs_atr[0] < clt_parameters.imp.exit_change_atr) && if ((diffs_atr[0] < clt_parameters.imp.exit_change_atr) && Loading Loading @@ -2581,8 +2642,8 @@ public class Interscene { pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene tp_tasks_ref, // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction tp_tasks_ref, // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction scene_QuadClt, // QuadCLT scene_QuadCLT, scene_QuadClt, // QuadCLT scene_QuadCLT, camera_xyz0, // xyz scene_xyzatr0[0], // xyz camera_atr0, // pose[1], // atr scene_xyzatr0[1], // pose[1], // atr reliable_ref, // ****null, // final boolean [] selection, // may be null, if not null do not process unselected tiles reliable_ref, // ****null, // final boolean [] selection, // may be null, if not null do not process unselected tiles margin, // final int margin, margin, // final int margin, sensor_mask_inter, // final int sensor_mask_inter, // The bitmask - which sensors to correlate, -1 - all. sensor_mask_inter, // final int sensor_mask_inter, // The bitmask - which sensors to correlate, -1 - all. Loading Loading @@ -2632,8 +2693,8 @@ public class Interscene { pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene tp_tasks_ref, // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction tp_tasks_ref, // TpTask[] tp_tasks_ref, // only (main if MB correction) tasks for FPN correction scene_QuadClt, // QuadCLT scene_QuadCLT, scene_QuadClt, // QuadCLT scene_QuadCLT, camera_xyz0, // xyz scene_xyzatr0[0], // xyz camera_atr0, // pose[1], // atr scene_xyzatr0[1], // pose[1], // atr reliable_ref, // ****null, // final boolean [] selection, // may be null, if not null do not process unselected tiles reliable_ref, // ****null, // final boolean [] selection, // may be null, if not null do not process unselected tiles margin, // final int margin, margin, // final int margin, sensor_mask_inter, // final int sensor_mask_inter, // The bitmask - which sensors to correlate, -1 - all. sensor_mask_inter, // final int sensor_mask_inter, // The bitmask - which sensors to correlate, -1 - all. Loading Loading @@ -2687,7 +2748,7 @@ public class Interscene { return null; return null; } } } } return new double [][] {camera_xyz0, camera_atr0}; return scene_xyzatr0; } } Loading Loading @@ -2954,7 +3015,8 @@ public class Interscene { double fpn_max_offset = clt_parameters.imp.fpn_max_offset; double fpn_max_offset = clt_parameters.imp.fpn_max_offset; double fpn_radius = clt_parameters.imp.fpn_radius; double fpn_radius = clt_parameters.imp.fpn_radius; boolean fpn_ignore_border = clt_parameters.imp.fpn_ignore_border; // only if fpn_mask != null - ignore tile if maximum touches fpn_mask boolean fpn_ignore_border = clt_parameters.imp.fpn_ignore_border; // only if fpn_mask != null - ignore tile if maximum touches fpn_mask boolean show_tptask_ref = false; boolean show_tptask_scene = false; boolean eq_debug = false; boolean eq_debug = false; boolean transform_debug = false; boolean transform_debug = false; boolean eq_en = near_important && clt_parameters.imp.eq_en; // true;// equalize "important" FG tiles for better camera XYZ fitting boolean eq_en = near_important && clt_parameters.imp.eq_en; // true;// equalize "important" FG tiles for better camera XYZ fitting Loading Loading @@ -2988,6 +3050,17 @@ public class Interscene { System.out.println("interCorrPair(): "+IntersceneLma.printNameV3("ATR",scene_atr)+ System.out.println("interCorrPair(): "+IntersceneLma.printNameV3("ATR",scene_atr)+ " "+IntersceneLma.printNameV3("XYZ",scene_xyz)); " "+IntersceneLma.printNameV3("XYZ",scene_xyz)); } } if (show_tptask_ref) { if (tp_tasks_ref != null){ String dbg_title = ref_scene.getImageName()+"-ref"; TpTask.showTpTask( tp_tasks_ref, // TpTask[] tp_tasks, tilesX, // int tilesX, tilesY, // int tilesY, dbg_title); // String title) } } ImageDtt image_dtt; ImageDtt image_dtt; image_dtt = new ImageDtt( image_dtt = new ImageDtt( ref_scene.getNumSensors(), // , ref_scene.getNumSensors(), // , Loading Loading @@ -3126,7 +3199,7 @@ public class Interscene { } } } } if (transform_debug) { if (transform_debug) { // calculate with no transform // calculate wi/media/elphel/SSD3-4GB/lwir16-proc/berdich3/sel-mod1/1697879036_777649/debug/v15_12A/th no transform double [][] dbg_ref_pXpYD = OpticalFlow.transformToScenePxPyD( // will be null for disparity == NaN, total size - tilesX*tilesY double [][] dbg_ref_pXpYD = OpticalFlow.transformToScenePxPyD( // will be null for disparity == NaN, total size - tilesX*tilesY null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null) null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null) ref_disparity, // dls[0], // final double [] disparity_ref, // invalid tiles - NaN in disparity (maybe it should not be masked by margins?) ref_disparity, // dls[0], // final double [] disparity_ref, // invalid tiles - NaN in disparity (maybe it should not be masked by margins?) Loading Loading @@ -3242,6 +3315,17 @@ public class Interscene { THREADS_MAX, // final int threadsMax, // maximal number of threads to launch THREADS_MAX, // final int threadsMax, // maximal number of threads to launch debug_level); // final int globalDebugLevel); debug_level); // final int globalDebugLevel); } } if (show_tptask_scene) { for (int i = 0; i < tp_tasks.length; i++) if (tp_tasks_ref[i] != null){ String dbg_title = scene.getImageName()+"-scn-"+i; TpTask.showTpTask( tp_tasks[i], // TpTask[] tp_tasks, tilesX, // int tilesX, tilesY, // int tilesY, dbg_title); // String title) } } if (show_render_ref) { if (show_render_ref) { ImagePlus imp_render_ref = ref_scene.renderFromTD ( ImagePlus imp_render_ref = ref_scene.renderFromTD ( -1, // final int sensor_mask, -1, // final int sensor_mask, Loading