Commit 9a499c0a authored by Andrey Filippov's avatar Andrey Filippov

working version

parent b3ad74ea
......@@ -1598,7 +1598,7 @@ public class ErsCorrection extends GeometryCorrection {
}
}
@Deprecated
public void compareDSItoWorldDerivatives(
QuadCLT scene_QuadClt,
double max_inf_disparity, // absolute value
......
......@@ -514,6 +514,7 @@ public class Interscene {
double min_ref_str = clt_parameters.imp.min_ref_str;
boolean ref_need_lma = clt_parameters.imp.ref_need_lma;
double min_ref_frac= clt_parameters.imp.min_ref_frac;
boolean ref_smooth = clt_parameters.imp.ref_smooth; //true; // use SfM filtering if available
boolean sfm_filter = clt_parameters.imp.sfm_filter; //true; // use SfM filtering if available
double sfm_minmax = clt_parameters.imp.sfm_minmax; //10.0; // minimal value of the SfM gain maximum to consider available
double sfm_fracmax = clt_parameters.imp.sfm_fracmax; // 0.75; // minimal fraction of the SfM maximal gain
......@@ -636,6 +637,7 @@ public class Interscene {
scene_index, // int nscene1, // compares to nscene0
null, // double [] ref_disparity, // null or alternative reference disparity
reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles
ref_smooth, // boolean smooth_disparity, // smooth disparity (according to clt_parameters)+update reliable_ref if true
scenes_xyzatr[ref_index], // double [][] scene0_xyzatr,,
initial_pose, // double [][] scene1_xyzatr,
Double.NaN, // double average_z,
......@@ -749,6 +751,7 @@ public class Interscene {
fpn_pairs[ipair][0], // int nscene1, // compares to nscene0
null, // double [] ref_disparity, // null or alternative reference disparity
reliable_ref, //boolean [] reliable_ref, // null or bitmask of reliable reference tiles
ref_smooth, // boolean smooth_disparity, // smooth disparity (according to clt_parameters)+update reliable_ref if true
scenes_xyzatr[fpn_pairs[ipair][1]], // double [][] scene0_xyzatr,,
scenes_xyzatr[fpn_pairs[ipair][0]], // initial_pose, // double [][] scene1_xyzatr,
Double.NaN, // double average_z,
......@@ -847,7 +850,13 @@ public class Interscene {
double sfm_minmax = clt_parameters.imp.sfm_minmax; //10.0; // minimal value of the SfM gain maximum to consider available
double sfm_fracmax = clt_parameters.imp.sfm_fracmax; // 0.75; // minimal fraction of the SfM maximal gain
double sfm_fracall = clt_parameters.imp.sfm_fracall; // 0.3; // minimal relative area of the SfM-e
int max_num_scenes = clt_parameters.imp.max_num_scenes; // cut longer series
boolean ref_smooth = clt_parameters.imp.ref_smooth; //true; // use SfM filtering if available
// double ref_sigma = clt_parameters.imp.ref_sigma; //10.0; // minimal value of the SfM gain maximum to consider available
// double ref_smooth_diff = clt_parameters.imp.ref_smooth_diff; // 0.75; // minimal fraction of the SfM maximal gain
int max_num_scenes = clt_parameters.imp.max_num_scenes; // cut longer series
boolean ims_use = clt_parameters.imp.ims_use;
boolean fmg_initial_en = clt_parameters.imp.fmg_initial_en; // enable IMS-based FPN mitigation for initial orientation
......@@ -906,7 +915,7 @@ public class Interscene {
ErsCorrection ers_reference = quadCLTs[ref_index].getErsCorrection();
int debug_scene = -15;
int debug_scene = 57; // -15; last before
boolean debug2 = !batch_mode; // false; // true;
boolean [] reliable_ref = null;
boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
......@@ -974,6 +983,26 @@ public class Interscene {
debugLevel); // final int debugLevel);
}
double [][][] ims_xyzatr;
// TODO: Remove when done!
// if ((nscene == 57) || (nscene == 58)) {
// }
/*
double [][][] ims_xyzatr_PIMU= QuadCLT.integratePIMU(
clt_parameters, // final CLTParameters clt_parameters,
quadCLTs, // final QuadCLT[] quadCLTs,
ref_index, // final int ref_index,
null, // double [][][] dxyzatr,
0, // final int early_index,
(quadCLTs.length -1) // int last_index,
);
double [][][] ims_xyzatr_INT=quadCLTs[ref_index].getXyzatrIms(
clt_parameters, // CLTParameters clt_parameters,
quadCLTs, // QuadCLT[] quadCLTs,
quat_corr, // double [] quat_corr, // only applies to rotations - verify!
debugLevel) ; // int debugLevel)
*/
if (inertial_only) {
ims_xyzatr = QuadCLT.integratePIMU(
clt_parameters, // final CLTParameters clt_parameters,
......@@ -991,7 +1020,29 @@ public class Interscene {
quat_corr, // double [] quat_corr, // only applies to rotations - verify!
debugLevel) ; // int debugLevel)
}
boolean man_corr = debugLevel<10;
int other_scene = -1; // 57
if (man_corr) {
other_scene = 57;
// double [][] xyz_atr_le = {{-0.5183922094898724, 9.154782438090823, 1.9419561092947408},{0,0,0}};
// double [][] xyz_atr_le = {{-0.8268073979557207, 12.435651264663617, 0.43389361433133333},{0,0,0}};
// double [][] xyz_atr_le = {
// {-1.5074533979557208, 5.289806264663618, 0.6908026143313334},
// {-0.015346300027727794,0.16450786973129805,-0.008030574830017914}};
double [][] xyz_atr_le = {
{-1.5074533979557208, 2.401806264663618, 0.6908026143313334},
{-0.015346300027727794,0.23050786973129805,-0.008030574830017914}};
// double [][] xyz_atr_le = {
// {0, 0, 0.6908026143313334},
// {0.018641752679327314, 0.2862869959075706, -0.008030574830017914}};
double [][] xyz_atr_gt = {{ 0, 0, 0}, {0,0,0}};
manualIMSCorrection (
ims_xyzatr, // double [][][] xyz_atr,
other_scene, // int corr_indx, // 57 correct scenes LE this
xyz_atr_le, // double [][] xyz_atr_le,
xyz_atr_gt);// double [][] xyz_atr_gt);
}
double [][][] scenes_xyzatr = new double [quadCLTs.length][][]; // previous scene relative to the next one
scenes_xyzatr[ref_index] = new double[2][3]; // all zeros
// boolean after_spiral = false;
......@@ -1019,6 +1070,9 @@ public class Interscene {
// min_max[1] = max_offset;
final double max_rms = clt_parameters.imp.eig_use? clt_parameters.imp.eig_max_rms: clt_parameters.imp.max_rms;
for (int scene_index = ref_index - 1; scene_index >= earliest_scene ; scene_index--) {
if (scene_index == other_scene) {
last_corr_xyzatr = new double [][] {ZERO3,ZERO3}; // start from scratch
}
if ((ref_index - scene_index) >= max_num_scenes){
earliest_scene = scene_index + 1;
if (debugLevel > -3) {
......@@ -1113,6 +1167,7 @@ public class Interscene {
scene_index, // int nscene1, // compares to nscene0
null, // double [] ref_disparity, // null or alternative reference disparity
reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles
ref_smooth, // boolean smooth_disparity, // smooth disparity (according to clt_parameters)+update reliable_ref if true
scenes_xyzatr[ref_index], // double [][] scene0_xyzatr,,
initial_pose, // double [][] scene1_xyzatr,
Double.NaN, // double average_z,
......@@ -1278,6 +1333,7 @@ public class Interscene {
fpn_pairs[ipair][0], // int nscene1, // compares to nscene0
null, // double [] ref_disparity, // null or alternative reference disparity
reliable_ref, //boolean [] reliable_ref, // null or bitmask of reliable reference tiles
ref_smooth, // boolean smooth_disparity, // smooth disparity (according to clt_parameters)+update reliable_ref if true
scenes_xyzatr[fpn_pairs[ipair][1]], // double [][] scene0_xyzatr,,
scenes_xyzatr[fpn_pairs[ipair][0]], // initial_pose, // double [][] scene1_xyzatr,
Double.NaN, // double average_z,
......@@ -1375,6 +1431,28 @@ public class Interscene {
return earliest_scene;
}
public static void manualIMSCorrection (
double [][][] xyz_atr,
int corr_indx, // 57 correct scenes LE this
double [][] xyz_atr_le,
double [][] xyz_atr_gt) {
for (int i = 0; i <= corr_indx; i++) {
for (int t = 0; t < xyz_atr_le.length; t++) {
for (int j = 0; j < xyz_atr_le[t].length; j++) {
xyz_atr[i][t][j] += xyz_atr_le[t][j];
}
}
}
for (int i = corr_indx+1; i < xyz_atr.length; i++) {
for (int t = 0; t < xyz_atr_le.length; t++) {
for (int j = 0; j < xyz_atr_le[t].length; j++) {
xyz_atr[i][t][j] += xyz_atr_gt[t][j];
}
}
}
}
public static void testPIMU(
final CLTParameters clt_parameters,
final QuadCLT[] quadCLTs,
......@@ -2167,7 +2245,7 @@ public class Interscene {
scenes_xyzatr[ref_index] = new double[2][3]; // all zeros
// should have at least next or previous non-null
int debug_scene = 69; // -68; // -8;
int debug_scene = 161; // 69; // -68; // -8;
RMSEStats rmse_stats = new RMSEStats();
RMSEStats rmse_stats_metric = clt_parameters.imp.eig_use ? (new RMSEStats()):null;
if (debug_ers) {
......@@ -2385,6 +2463,7 @@ public class Interscene {
test_pair[1], // 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
false, // boolean smooth_disparity, // smooth disparity (according to clt_parameters)+update reliable_ref if true
scenes_xyzatr[test_pair[0]],// double [][] scene0_xyzatr,
scenes_xyzatr[test_pair[1]], // double [][] scene1_xyzatr,
avg_z, // double average_z,
......@@ -2515,6 +2594,7 @@ public class Interscene {
nscene, // 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
false, // boolean smooth_disparity, // smooth disparity (according to clt_parameters)+update reliable_ref if true
scenes_xyzatr[ref_index],// double [][] scene0_xyzatr,
scenes_xyzatr[nscene], // double [][] scene1_xyzatr,
avg_z, // double average_z,
......@@ -2698,6 +2778,7 @@ public class Interscene {
fpn_pairs[ipair][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
false, // boolean smooth_disparity, // smooth disparity (according to clt_parameters)+update reliable_ref if true
scenes_xyzatr[fpn_pairs[ipair][1]],// double [][] scene0_xyzatr,
scenes_xyzatr[fpn_pairs[ipair][0]], // double [][] scene1_xyzatr,
avg_z, // double average_z,
......@@ -2774,6 +2855,7 @@ public class Interscene {
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
false, // boolean smooth_disparity, // smooth disparity (according to clt_parameters)+update reliable_ref if true
scenes_xyzatr[test_pair[1]],// double [][] scene0_xyzatr,
scenes_xyzatr[test_pair[0]], // double [][] scene1_xyzatr,
avg_z, // double average_z,
......@@ -2896,12 +2978,13 @@ public class Interscene {
int ref_index,
TpTask[][] tp_tasks_ref, // Should be TpTask[2][*]. If tp_tasks_ref[0] == null will calculate
// at set first scene to the GPU
double [][] pXpYD_ref, // should be se or at least double [num_tiles][] if tp_tasks_ref[0] == null
double [][] pXpYD_ref, // should be set 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
int nscene0, // may be == ref_index
int nscene1, // compares to nscene0
double [] ref_disparity, // null or alternative reference disparity
boolean [] reliable_ref, // null or bitmask of reliable reference tiles
boolean smooth_disparity, // smooth disparity (according to clt_parameters)+update reliable_ref if true
double [][] scene0_xyzatr,
double [][] scene1_xyzatr,
double average_z,
......@@ -2915,10 +2998,53 @@ public class Interscene {
double mb_max_gain, // 5.0; // motion blur maximal gain (if more - move second point more than a pixel
int debugLevel)
{
double ref_sigma = clt_parameters.imp.ref_sigma; //10.0; // minimal value of the SfM gain maximum to consider available
double ref_smooth_diff = clt_parameters.imp.ref_smooth_diff; // 0.75; // minimal fraction of the SfM maximal gain
boolean apply_nan = true;
// boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
if (ref_disparity == null) {
ref_disparity = quadCLTs[ref_index].getDLS()[use_lma_dsi?1:0];
}
if (smooth_disparity) {
double [] dbg_disparity = (debugLevel > 2) ? ref_disparity.clone() : null;
boolean [] dbg_reliable = ((dbg_disparity != null) && (reliable_ref != null)) ? reliable_ref.clone(): null;
ref_disparity = quadCLTs[ref_index].smoothDisparity(
ref_disparity, // double [] disparity_in, (will not modify)
reliable_ref, // boolean [] reliable_ref, // optional
ref_sigma, // double sigma,
ref_smooth_diff, // double max_diff,
apply_nan); // boolean apply_nan)
if (dbg_disparity != null) {
String [] dbg_titles = {"ref", "smooth", "reliable_in", "reliable_out"};
String dbg_title = quadCLTs[ref_index].getImageName()+"-smooth_ref";
double [][] dbg_img = new double [dbg_titles.length][ref_disparity.length];
for (int i = 0; i < dbg_img.length; i++) {
Arrays.fill(dbg_img[i], Double.NaN);
}
dbg_img[0] = dbg_disparity;
dbg_img[1] = ref_disparity;
for (int i = 0; i < ref_disparity.length; i++) {
if (dbg_reliable != null) {
dbg_img[2][i] = dbg_reliable[i] ? 10.0: Double.NaN;
}
if (reliable_ref != null) {
dbg_img[3][i] = reliable_ref[i] ? 10.0: Double.NaN;
}
}
int dbg_width = quadCLTs[ref_index].getTileProcessor().getTilesX();
int dbg_height = quadCLTs[ref_index].getTileProcessor().getTilesY();
ShowDoubleFloatArrays.showArrays(
dbg_img,
dbg_width,
dbg_height,
true,
dbg_title,
dbg_titles);
}
}
// TODO: set reference as new version of adjustPairsLMAInterscene() assumes it set
if ((tp_tasks_ref == null) || (tp_tasks_ref[0] == null)) { // calculate and setup reference (for comparison) scene to GPU
if (tp_tasks_ref == null) {
......@@ -3357,6 +3483,7 @@ public class Interscene {
// boolean dbg_images = false;
double [][] eigen_masked = clt_parameters.imp.eig_xy_lma? null : eigen;
String dbg_prefix = dbg_images? (first_QuadClt.getImageName()+"-"+scene_QuadClt.getImageName()+"-NLMA_"+nlma) : null;
final boolean same_weights = false;
intersceneLma.prepareLMA(
scene_xyzatr0, // final double [] scene_xyzatr0, // camera center in world coordinates (or null to use instance)
scene_xyzatr_pull, // final double [] scene_xyz_pull, // if both are not null, specify target values to pull to
......@@ -3371,6 +3498,7 @@ public class Interscene {
eigen_masked, // final double [][] eigen, // [tilesX*tilesY]{lamb0_x,lamb0_y, lamb0, lamb1} eigenvector0[x,y],lam0,lam1
coord_motion[1], // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate()
coord_motion[0], // final double [][] centers, // macrotile centers (in pixels and average disparities
same_weights, // final boolean same_weights,
(nlma == 0), // boolean first_run,
dbg_prefix, // String dbg_prefix, // null or image name prefix
clt_parameters.imp.debug_level); // final int debug_level)
......@@ -3838,7 +3966,8 @@ public class Interscene {
boolean mov_en = clt_parameters.imp.mov_en; // true; // enable detection/removal of the moving objects during pose matching
boolean mov_debug_images = clt_parameters.imp.showMovementDetection(imp_debug_level);
int mov_debug_level = clt_parameters.imp.movDebugLevel(imp_debug_level);
// if (dbg_prefix != null) {
// }
boolean fpn_remove = !fpn_disable && clt_parameters.imp.fpn_remove;
double fpn_max_offset = clt_parameters.imp.fpn_max_offset;
final double fpn_min_offset = clt_parameters.imp.fpn_min_offset;
......
......@@ -40,6 +40,7 @@ import javax.xml.bind.DatatypeConverter;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import Jama.Matrix;
import ij.ImagePlus;
public class IntersceneLma {
QuadCLT [] scenesCLT = null; // now will use just 2 - 0 -reference scene, 1 - scene.
......@@ -272,9 +273,10 @@ public class IntersceneLma {
final double eig_min_sqrt, // 1; // for sqrt(lambda) - consider infinity (infinite linear feature, a line)
//if (eigen != null) normalize by eigenvalues, recalc derivatives to eigenvectors directions
final double [][] eigen, // [tilesX*tilesY]{lamb0_x,lamb0_y, lamb0, lamb1} eigenvector0[x,y],lam0,lam1
// now includes optional Disparity as the last element (for num_components==3)
// 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
final boolean same_weights,
boolean first_run,
String dbg_prefix, // null or image name prefix
final int debug_level) {
......@@ -336,7 +338,9 @@ public class IntersceneLma {
}
if (vector_XYSDS != null) {// skip when used for the motion blur vectors, not LMA
setSamplesWeights(vector_XYSDS); // not regularized yet ! // 3d updated
setSamplesWeights(vector_XYSDS, // not regularized yet ! // 3d updated
same_weights); // final boolean same_weights) // same weight if > 0
} else {
weights = null; // new double[2 * centers.length];
}
......@@ -423,7 +427,7 @@ public class IntersceneLma {
// 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
final boolean same_weights,
boolean first_run,
final int debug_level)
{
......@@ -477,7 +481,8 @@ public class IntersceneLma {
}
if (vector_XYSDS != null) {// skip when used for the motion blur vectors, not LMA
setSamplesWeights(vector_XYSDS); // not regularized yet ! // 3d updated
setSamplesWeights(vector_XYSDS, // not regularized yet ! // 3d updated
same_weights); // final boolean same_weights) // same weight if > 0
} else {
weights = null; // new double[2 * centers.length];
}
......@@ -663,8 +668,35 @@ public class IntersceneLma {
last_rms); // final double [] rms_fp // null or [2]
this.initial_rms = this.last_rms.clone();
this.good_or_bad_rms = this.last_rms.clone();
if (debug_level > -1) { // temporary
if (dbg_prefix != null) { // -1) { // temporary
String dbg_title= scenesCLT[0].getImageName()+"-"+scenesCLT[1].getImageName()+"-FxDerivs";
int dbg_num_rows = 3;
boolean dbg_show_reg = true;
boolean dbg_show = true;
showFxDerivs(
fx, // double [] fX,
last_jt, // double [][] jt,
0, // int num_rows, // <=0 - stack 3?
dbg_show_reg, // boolean show_reg, // extra row for regularization parameters
dbg_show, // boolean show,
dbg_title); // String title);
showFxDerivs(
fx, // double [] fX,
last_jt, // double [][] jt,
dbg_num_rows, // int num_rows, // <=0 - stack 3?
dbg_show_reg, // boolean show_reg, // extra row for regularization parameters
dbg_show, // boolean show,
dbg_title); // String title);
double debug_delta = 1e-4;
boolean show_img = true;
/* debugDerivs(
parameters_vector, // double [] vector,
scenesCLT[1], // final QuadCLT scene_QuadClt,
scenesCLT[0], // final QuadCLT reference_QuadClt,
debug_delta, // final double delta,
show_img, // final boolean show_img,
debug_level); // final int debugLevel) */
/*
dbgYminusFxWeight(
this.last_ymfx,
......@@ -834,7 +866,8 @@ public class IntersceneLma {
}
private void setSamplesWeights(
final double [][] vector_XYSDS) // not regularized yet
final double [][] vector_XYSDS, // not regularized yet
final boolean same_weights) // same weight if > 0
{
//num_components 2 - old, 3 - with disparity
this.weights = new double [num_samples + parameters_vector.length];
......@@ -861,6 +894,9 @@ public class IntersceneLma {
continue;
}
if (w > 0) {
if (same_weights) {
w = 1.0;
}
anum_defined.getAndIncrement();
weights[num_components * iMTile] = w;
sw_arr[thread_num] += 2*w;
......@@ -975,7 +1011,357 @@ public class IntersceneLma {
}
// if eig_trans != null, transform derivatives, keep Fx
// if eig_trans != null, transform derivatives, keep Fx
public ImagePlus showFxDerivs(
double [] fX,
double [][] jt,
int num_rows, // <=0 - stack
boolean show_reg, // extra row for regularization parameters
boolean show,
String title) {
int gap = 1;
double [][][] scales = {
{{320,320}, {256,256} ,{0,1}}, //y *
{{320,320}, {256,256} ,{0,1}}, //fX *
{{ 0, 2.5}, { 0, 2.5} , {0,1}}, //y-fX *
{{0, 75}, { 0, 75}, {0,1}}, //hor *
{{0, 75}, { 0, 75}, {0,1}}, //vert *
{{ 0,100}, { 0,100}, {0,1}}, //"pX", // (pix) 0
{{ 0,100}, { 0,100}, {0,1}}, //"pY", // (pix) 1
{{0,100}, { 0,100}, {0,1}}, //"disp", // (pix) 2
{{0,100}, { 0,100}, {0,1}}, //"ers_vaz_ref", // (rad/sec) 3
{{0,100}, { 0,100}, {0,1}}, //"ers_vtl_ref", // (rad/sec) 4
{{0,100}, { 0,100}, {0,1}}, //"ers_vrl_ref", // (rad/sec) 5
{{0,100}, { 0,100}, {0,1}}, //"ers_dvx_ref", // (m/s) 6
{{0,100}, { 0,100}, {0,1}}, //"ers_dvy_ref", // (m/s) 7
{{0,100}, { 0,100}, {0,1}}, //"ers_dvz_ref", // (m/s) 8
{{-1120,20},{ 70,50}, {0,1}}, //"azimuth_ref", // (rad) 9 *
{{-70, 50},{-1120,20},{0,1}}, //"tilt_ref", // (rad) 10 *
{{0,500}, { 0,500}, {0,1}}, //"roll_ref", // (rad) 11 *
{{ 25,2.5}, {-1.5,0.5},{0,1}}, //"X_ref", // (m) 12 *
{{-1.5,0.5},{-25,2.5}, {0,1}}, //"Y_ref", // (m) 13 *
{{ 0, 7.5}, { 0, 7.5}, {0,1}}, //"Z_ref", // (m) 14 *
{{0,100}, { 0,100}, {0,1}}, //"ers_vaz_scene", // (rad/sec)15
{{0,100}, { 0,100}, {0,1}}, //"ers_vtl_scene", // (rad/sec)16
{{0,100}, { 0,100}, {0,1}}, //"ers_vrl_scene", // (rad/sec)17
{{0,100}, { 0,100}, {0,1}}, //"ers_dvx_scene", // (m/s) 18
{{0,100}, { 0,100}, {0,1}}, //"ers_dvy_scene", // (m/s) 19
{{0,100}, { 0,100}, {0,1}}, //"ers_dvz_scene", // (m/s) 20
{{1120,20}, { -70,50}, {0,1}}, //"azimuth_scene", // (rad) 21 *
{{70, 50}, {1120,20}, {0,1}}, //"tilt_scene", // (rad) 22 *
{{0,500}, { 0,500}, {0,1}}, //"Roll_scene", // (rad) 23 *
{{-25, 2.5},{ 1.5,0.5},{0,1}}, //"X_scene", // (m) 24 *
{{ 1.5,0.5},{25, 2.5}, {0,1}}, //"Y_scene", // (m) 25 *
{{ 0, 7.5}, { 0, 7.5}, {0,1}} //"Z_scene" // (m) 26 *
};
String [] titles_pre = {"y", "fx", "y-fx", "hor", "vert"};
int num_pre = titles_pre.length;
int length = num_samples/num_components;
int width = tilesX;
int height0 = length/width;
int height = height0 + (show_reg? 1 : 0);
int num_pars0 = jt.length;
int num_pars1 = jt.length+num_pre;
double [][] jt_ext = new double [num_pars1][];
jt_ext[0] = y_vector;
jt_ext[1] = fX;
jt_ext[2] = y_vector.clone();
for (int i = 0; i < jt_ext[2].length; i++) {
jt_ext[2][i] -= jt_ext[1][i];
}
double [][][] img_stack = new double [num_components][num_pars1][width*height];
String [] titles = new String [num_pars1];
for (int i = 0; i < num_pre; i++) {
titles[i] = titles_pre[i];
}
for (int i = 0; i < par_indices.length; i++) {
titles[i+num_pre] = ErsCorrection.DP_DERIV_NAMES[par_indices[i]];
jt_ext[i+num_pre] = jt[i];
}
// combine rotate and translate
// See if both azimuth_scene and X_scene are present
int [][] hor_vert_indices = {{-1,-1},{-1,-1}};
for (int i = 0; i < par_indices.length; i++) {
if (par_indices[i] ==ErsCorrection.DP_DSAZ) hor_vert_indices[0][0] = i;
if (par_indices[i] ==ErsCorrection.DP_DSX) hor_vert_indices[0][1] = i;
if (par_indices[i] ==ErsCorrection.DP_DSTL) hor_vert_indices[1][0] = i;
if (par_indices[i] ==ErsCorrection.DP_DSY) hor_vert_indices[1][1] = i;
}
for (int vnh = 0; vnh < hor_vert_indices.length; vnh++) if (( hor_vert_indices[vnh][0] >=0 ) && (hor_vert_indices[vnh][1] >= 0)){
double [] sw = new double[2],swd = new double[2];
for (int n = 0; n < hor_vert_indices[vnh].length; n++) {
for (int i = 0; i < length; i++) {
int indx = num_components * i + vnh;
double w = weights[indx];
double d = jt[hor_vert_indices[vnh][n]][indx];
sw [n]+=w;
swd[n]+=w*d;
}
swd[n] /= sw[n];
}
double mult_second = swd[0] / swd[1];
int jindex = 3 + vnh;
jt_ext[jindex] = new double [weights.length];
for (int i = 0; i < weights.length; i++) {
jt_ext[jindex][i] = jt[hor_vert_indices[vnh][0]][i] - mult_second * jt[hor_vert_indices[vnh][1]][i];
}
}
String [] titles_top = new String [num_components];
titles_top[0] = "pX";
titles_top[1] = "pY";
if (num_components > 2) {
titles_top[2] = "Disp";
}
for (int np = 0; np < num_pars1; np++){
for (int nc = 0; nc < num_components; nc++) {
Arrays.fill(img_stack[nc][np], Double.NaN);
if (jt_ext[np] != null) {
for (int npix = 0; npix < length; npix++) {
int sindx = nc+num_components*npix;
if (weights[sindx] > 0) {
if ((img_stack[nc]== null) || (img_stack[nc][np]== null) ||
(jt_ext[np]== null)) {
System.out.println("showFxDerivs(): Null pointer");
}
img_stack[nc][np][npix] = jt_ext[np][sindx]; // null pointer
}
}
if (show_reg) {
for (int i = 0; i < num_pars0; i++) {
img_stack[nc][np][length+i] = jt_ext[np][num_samples+i];
}
}
}
}
}
if (num_rows <= 0) {
ImagePlus imp_stack = ShowDoubleFloatArrays.showArraysHyperstack(
img_stack, // double[][][] pixels,
width, // int width,
title, // "terrain_vegetation_render.tiff", // String title, "time_derivs-rt"+diff_time_rt+"-rxy"+diff_time_rxy,
titles, // String [] titles, // all slices*frames titles or just slice titles or null
titles_top, // String [] frame_titles, // frame titles or null
show); // boolean show)
return imp_stack;
}
// TODO: add translate+rotate combo and scale factors to see all tiles simultaneously (as static members?)
int num_cols = (int) Math.ceil(1.0*num_pars1/num_rows);
int full_width = num_cols * (width + gap) - gap;
int full_height = num_rows * (height + gap) - gap;
double [][] tiled_stack = new double [num_components][full_width*full_height];
for (int nc = 0; nc < tiled_stack.length; nc++) {
Arrays.fill (tiled_stack[nc], Double.NaN);
}
for (int ntile = 0; ntile < num_pars1; ntile++) {
int tile_row = ntile / num_cols;
int tile_col = ntile % num_cols;
int tl_index = tile_row * (height + gap) * full_width + tile_col * (width + gap);
for (int nc = 0; nc < tiled_stack.length; nc++) {
int scale_index = (ntile<num_pre)? ntile: (par_indices[ntile-num_pre] + num_pre);
double offs = scales[scale_index][nc][0];
double div = scales[scale_index][nc][1];
for (int nrow = 0; nrow < height; nrow++) {
System.arraycopy(
img_stack[nc][ntile],
nrow * width,
tiled_stack[nc],
tl_index + nrow * full_width,
width);
if (nrow < height0) {
for (int i = 0; i < width; i++) {
int indx = tl_index + nrow * full_width + i;
tiled_stack[nc][indx]= (tiled_stack[nc][indx]- offs)/div;
}
}
}
}
}
ImagePlus imp_stack = ShowDoubleFloatArrays.makeArrays(
tiled_stack, // double[][] pixels,
full_width, //int width,
full_height, // int height,
title+"_tiled", // String title,
titles_top); // String [] titles)
imp_stack.getProcessor().resetMinAndMax();
if (show) {
imp_stack.show();
}
return imp_stack;
}
public double [][] getFxDerivsDelta(
double [] vector,
final double[] deltas, // same length as vector, or [1] - then use for all
final QuadCLT scene_QuadClt,
final QuadCLT reference_QuadClt,
final int debug_level) {
int dbg_n = -2256; // 1698; // -2486;
final boolean mb_mode = (weights == null); // mb_mode should have num_components==2 !
final int weights_length = mb_mode ? (2 * macrotile_centers.length) : weights.length; // OK to keep 2
double [][] jt = new double [vector.length][weights_length];
for (int nv = 0; nv < vector.length; nv++) {
double delta = (nv < deltas.length) ? deltas[nv] : deltas[deltas.length -1];
if (nv == dbg_n) {
System.out.println("getFxDerivsDelta(): nv="+nv);
}
double [] vpm = vector.clone();
vpm[nv]+= 0.5*delta;
double [] fx_p = getFxDerivs(
vpm,
null, // 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);
vpm[nv]-= delta;
double [] fx_m = getFxDerivs(
vpm,
null, // 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);
for (int i = 0; i <weights_length; i++) if ((weights==null) || (weights[i] > 0)) {
jt[nv][i] = (fx_p[i]-fx_m[i])/delta;
}
}
return jt;
}
public void debugDerivs(
double [] vector,
final QuadCLT scene_QuadClt,
final QuadCLT reference_QuadClt,
final double delta,
final boolean show_img,
final int debugLevel) {
double [] delta_scale ={
1.0, //"pX", // (pix) 0
1.0, //"pY", // (pix) 1
1.0, //"disp", // (pix) 2
1.0, //"ers_vaz_ref", // (rad/sec) 3
1.0, //"ers_vtl_ref", // (rad/sec) 4
1.0, //"ers_vrl_ref", // (rad/sec) 5
1.0, //"ers_dvx_ref", // (m/s) 6
1.0, //"ers_dvy_ref", // (m/s) 7
1.0, //"ers_dvz_ref", // (m/s) 8
1.0, //"azimuth_ref", // (rad) 9 *
1.0, //"tilt_ref", // (rad) 10 *
1.0, //"roll_ref", // (rad) 11 *
1.0, //"X_ref", // (m) 12 *
1.0, //"Y_ref", // (m) 13 *
1.0, //"Z_ref", // (m) 14 *
1.0, //"ers_vaz_scene", // (rad/sec)15
1.0, //"ers_vtl_scene", // (rad/sec)16
1.0, //"ers_vrl_scene", // (rad/sec)17
1.0, //"ers_dvx_scene", // (m/s) 18
1.0, //"ers_dvy_scene", // (m/s) 19
1.0, //"ers_dvz_scene", // (m/s) 20
1.0, //"azimuth_scene", // (rad) 21 *
1.0, //"tilt_scene", // (rad) 22 *
1.0, //"Roll_scene", // (rad) 23 *
1.0, //"X_scene", // (m) 24 *
1.0, //"Y_scene", // (m) 25 *
1.0 //"Z_scene" // (m) 26 *
};
// int length = num_samples/num_components;
// int width = tilesX;
// int height0 = length/width;
double [] deltas = new double [vector.length];
String [] par_names = new String[vector.length];
for (int i = 0; i < deltas.length; i++) {
deltas[i] = delta * delta_scale[par_indices[i]];
par_names[i] = ErsCorrection.DP_DERIV_NAMES[par_indices[i]];
}