Commit b469f1c2 authored by Andrey Filippov's avatar Andrey Filippov

Another snapshot

parent 30330dd5
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)
...@@ -232,4 +236,47 @@ public class TpTask { ...@@ -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
...@@ -1950,6 +1950,27 @@ public class Interscene { ...@@ -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]+
...@@ -2018,6 +2039,50 @@ public class Interscene { ...@@ -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];
...@@ -2208,10 +2273,9 @@ public class Interscene { ...@@ -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]
...@@ -2272,10 +2336,9 @@ public class Interscene { ...@@ -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]
...@@ -2341,6 +2404,9 @@ public class Interscene { ...@@ -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,
...@@ -2354,10 +2420,9 @@ public class Interscene { ...@@ -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]
...@@ -2382,10 +2447,9 @@ public class Interscene { ...@@ -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]
...@@ -2413,8 +2477,7 @@ public class Interscene { ...@@ -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;
...@@ -2437,8 +2500,8 @@ public class Interscene { ...@@ -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.
...@@ -2498,13 +2561,12 @@ public class Interscene { ...@@ -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,
...@@ -2538,8 +2600,7 @@ public class Interscene { ...@@ -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) &&
...@@ -2581,8 +2642,8 @@ public class Interscene { ...@@ -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.
...@@ -2632,8 +2693,8 @@ public class Interscene { ...@@ -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.
...@@ -2687,7 +2748,7 @@ public class Interscene { ...@@ -2687,7 +2748,7 @@ public class Interscene {
return null; return null;
} }
} }
return new double [][] {camera_xyz0, camera_atr0}; return scene_xyzatr0;
} }
...@@ -2954,7 +3015,8 @@ public class Interscene { ...@@ -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
...@@ -2988,6 +3050,17 @@ public class Interscene { ...@@ -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(), // ,
...@@ -3126,7 +3199,7 @@ public class Interscene { ...@@ -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?)
...@@ -3242,6 +3315,17 @@ public class Interscene { ...@@ -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,
......
...@@ -98,6 +98,13 @@ public class IntersceneLma { ...@@ -98,6 +98,13 @@ public class IntersceneLma {
return new double[] { return new double[] {
full_vector[ErsCorrection.DP_DSAZ],full_vector[ErsCorrection.DP_DSTL],full_vector[ErsCorrection.DP_DSRL]}; full_vector[ErsCorrection.DP_DSAZ],full_vector[ErsCorrection.DP_DSTL],full_vector[ErsCorrection.DP_DSRL]};
} }
public double [][] getSceneXYZATR(boolean initial) {
double [] full_vector = initial? backup_parameters_full: getFullVector(parameters_vector);
return new double[][] {
{full_vector[ErsCorrection.DP_DSX],full_vector[ErsCorrection.DP_DSY],full_vector[ErsCorrection.DP_DSZ]},
{full_vector[ErsCorrection.DP_DSAZ],full_vector[ErsCorrection.DP_DSTL],full_vector[ErsCorrection.DP_DSRL]}};
}
public double [] getReferenceXYZ(boolean initial) { public double [] getReferenceXYZ(boolean initial) {
double [] full_vector = initial? backup_parameters_full: getFullVector(parameters_vector); double [] full_vector = initial? backup_parameters_full: getFullVector(parameters_vector);
return new double[] { return new double[] {
...@@ -108,6 +115,12 @@ public class IntersceneLma { ...@@ -108,6 +115,12 @@ public class IntersceneLma {
return new double[] { return new double[] {
full_vector[ErsCorrection.DP_DAZ],full_vector[ErsCorrection.DP_DTL],full_vector[ErsCorrection.DP_DRL]}; full_vector[ErsCorrection.DP_DAZ],full_vector[ErsCorrection.DP_DTL],full_vector[ErsCorrection.DP_DRL]};
} }
public double [][] getReferenceXYZATR(boolean initial) {
double [] full_vector = initial? backup_parameters_full: getFullVector(parameters_vector);
return new double[][] {
{full_vector[ErsCorrection.DP_DX],full_vector[ErsCorrection.DP_DY],full_vector[ErsCorrection.DP_DZ]},
{full_vector[ErsCorrection.DP_DAZ],full_vector[ErsCorrection.DP_DTL],full_vector[ErsCorrection.DP_DRL]}};
}
public double [] getSceneERSXYZ(boolean initial) { // never used public double [] getSceneERSXYZ(boolean initial) { // never used
double [] full_vector = initial? backup_parameters_full: getFullVector(parameters_vector); double [] full_vector = initial? backup_parameters_full: getFullVector(parameters_vector);
...@@ -228,6 +241,144 @@ public class IntersceneLma { ...@@ -228,6 +241,144 @@ public class IntersceneLma {
return String.format(fmt, vector[0], vector[1], vector[2]); return String.format(fmt, vector[0], vector[1], vector[2]);
} }
public void prepareLMA(
final double [][] scene_xyzatr0, // camera center in world coordinates (or null to use instance)
final double [][] scene_xyzatr_pull, // if both are not null, specify target values to pull to
final double [][] ref_xyzatr, //
// reference atr, xyz are considered 0.0 - not anymore?
final QuadCLT scene_QuadClt,
final QuadCLT reference_QuadClt,
final boolean[] param_select,
final double [] param_regweights,
// now includes optional Disparity as the last element (for num_components==3)
final double [][] vector_XYSDS,// optical flow X,Y, confidence obtained from the correlate2DIterate()
final double [][] centers, // macrotile centers (in pixels and average disparities
boolean first_run,
final int debug_level) {
scenesCLT = new QuadCLT [] {reference_QuadClt, scene_QuadClt};
par_mask = param_select;
macrotile_centers = centers;
num_samples = num_components * centers.length;
ErsCorrection ers_ref = reference_QuadClt.getErsCorrection();
ErsCorrection ers_scene = scene_QuadClt.getErsCorrection();
final double [] scene_xyz = (scene_xyzatr0 != null) ? scene_xyzatr0[0] : ers_scene.camera_xyz;
final double [] scene_atr = (scene_xyzatr0 != null) ? scene_xyzatr0[1] : ers_scene.camera_atr;
final double [] reference_xyz = (ref_xyzatr != null)? ref_xyzatr[0]: ers_ref.camera_xyz; // new double[3];
final double [] reference_atr = (ref_xyzatr != null)? ref_xyzatr[1]: ers_ref.camera_xyz; // new double[3];
double [] full_parameters_vector = new double [] {
0.0, 0.0, 0.0,
ers_ref.ers_watr_center_dt[0], ers_ref.ers_watr_center_dt[1], ers_ref.ers_watr_center_dt[2],
ers_ref.ers_wxyz_center_dt[0], ers_ref.ers_wxyz_center_dt[1], ers_ref.ers_wxyz_center_dt[2],
reference_atr[0], reference_atr[1], reference_atr[2],
reference_xyz[0], reference_xyz[1], reference_xyz[2],
ers_scene.ers_watr_center_dt[0], ers_scene.ers_watr_center_dt[1], ers_scene.ers_watr_center_dt[2],
ers_scene.ers_wxyz_center_dt[0], ers_scene.ers_wxyz_center_dt[1], ers_scene.ers_wxyz_center_dt[2],
scene_atr[0], scene_atr[1], scene_atr[2],
scene_xyz[0], scene_xyz[1], scene_xyz[2]};
parameters_full = full_parameters_vector.clone();
if ((vector_XYSDS != null) && (first_run || (backup_parameters_full == null))) {
backup_parameters_full = full_parameters_vector.clone();
}
int num_pars = 0;
for (int i = 0; i < par_mask.length; i++) if (par_mask[i]) num_pars++;
par_indices = new int [num_pars];
num_pars = 0;
for (int i = 0; i < par_mask.length; i++) {
if (par_mask[i]) par_indices[num_pars++] = i;
}
parameters_vector = new double [par_indices.length];
for (int i = 0; i < par_indices.length; i++) {
parameters_vector[i] = full_parameters_vector[par_indices[i]];
}
if ((scene_xyzatr_pull != null) && (scene_xyzatr_pull[0] != null) && (scene_xyzatr_pull[1] != null)) {
double [] parameters_pull_full = parameters_full.clone();
for (int i = 0; i < 3; i++) {
parameters_pull_full[ErsCorrection.DP_DSX + i] = scene_xyzatr_pull[0][i];
parameters_pull_full[ErsCorrection.DP_DSAZ + i] = scene_xyzatr_pull[1][i];
// parameters_pull =
}
parameters_pull = new double [par_indices.length];
for (int i = 0; i < par_indices.length; i++) {
parameters_pull[i] = parameters_pull_full[par_indices[i]];
}
}
if (vector_XYSDS != null) {// skip when used for the motion blur vectors, not LMA
setSamplesWeights(vector_XYSDS); // not regularized yet ! // 3d updated
} else {
weights = null; // new double[2 * centers.length];
}
last_jt = new double [parameters_vector.length][];
if (debug_level > 1) {
System.out.println("prepareLMA() 1");
}
double [] fx = getFxDerivs(
parameters_vector, // double [] vector,
last_jt, // final double [][] jt, // should be null or initialized with [vector.length][]
scenesCLT[1], // final QuadCLT scene_QuadClt,
scenesCLT[0], // final QuadCLT reference_QuadClt,
debug_level); // final int debug_level)
if (vector_XYSDS == null) {
return; // for MB vectors (noLMA)
}
double [][] wjtj = getWJtJlambda( // USED in lwir all NAN
0.0, // final double lambda,
last_jt); // final double [][] jt) all 0???
for (int i = 0; i < parameters_vector.length; i++) {
int indx = num_samples + i;
if (wjtj[i][i] == 0) { // why is it zero (leading to NaN)
weights[indx] = 0;
} else {
weights[indx] = param_regweights[par_indices[i]]/Math.sqrt(wjtj[i][i]);
}
}
normalizeWeights(); // make full weight == 1.0; pure_weight <= 1.0;
// remeasure fx - now with regularization terms.
if (debug_level > 1) {
System.out.println("prepareLMA() 2");
}
fx = getFxDerivs(
parameters_vector, // double [] vector,
last_jt, // final double [][] jt, // should be null or initialized with [vector.length][]
scene_QuadClt, // final QuadCLT scene_QuadClt,
reference_QuadClt, // final QuadCLT reference_QuadClt,
debug_level); // final int debug_level)
// Why y_vector starts with initial value of fx???
y_vector = fx.clone();
for (int i = 0; i < vector_XYSDS.length; i++) {
if (vector_XYSDS[i] != null){
y_vector[num_components * i + 0] += vector_XYSDS[i][0];
y_vector[num_components * i + 1] += vector_XYSDS[i][1];
if (num_components > 2) {
y_vector[num_components * i + 2] += vector_XYSDS[i][2];
}
}
}
if (parameters_pull != null){
for (int i = 0; i < par_indices.length; i++) {
// y_vector [i + num_components * macrotile_centers.length] += parameters_pull[i]; // - parameters_initial[i]; // scale will be combined with weights
y_vector [i + num_components * macrotile_centers.length] = parameters_pull[i]; // - parameters_initial[i]; // scale will be combined with weights
}
}
last_rms = new double [2];
last_ymfx = getYminusFxWeighted(
fx, // final double [] fx,
last_rms); // final double [] rms_fp // null or [2]
initial_rms = last_rms.clone();
good_or_bad_rms = this.last_rms.clone();
}
public void prepareLMA( public void prepareLMA(
final double [] scene_xyz0, // camera center in world coordinates (or null to use instance) final double [] scene_xyz0, // camera center in world coordinates (or null to use instance)
final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance) final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance)
......
...@@ -2830,7 +2830,7 @@ public class OpticalFlow { ...@@ -2830,7 +2830,7 @@ public class OpticalFlow {
boolean debug_ers = false; // true; // false; // true; // true; //11.01.2022 boolean debug_ers = false; // true; // false; // true; // true; //11.01.2022
boolean ignore_ers = false; // false; boolean ignore_ers = false; // false;
TileProcessor tp = scene_QuadClt.getTileProcessor(); TileProcessor tp = scene_QuadClt.getTileProcessor();
final int tilesX = (full_woi_in==null) ? tp.getTilesX() : full_woi_in.width; // full width,includeing extra final int tilesX = (full_woi_in==null) ? tp.getTilesX() : full_woi_in.width; // full width,including extra
final int tilesY = (full_woi_in==null) ? tp.getTilesY() : full_woi_in.height; final int tilesY = (full_woi_in==null) ? tp.getTilesY() : full_woi_in.height;
final int offsetX_ref = (full_woi_in==null) ? 0 : full_woi_in.x; final int offsetX_ref = (full_woi_in==null) ? 0 : full_woi_in.x;
final int offsetY_ref = (full_woi_in==null) ? 0 : full_woi_in.y; final int offsetY_ref = (full_woi_in==null) ? 0 : full_woi_in.y;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment