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

working version

parent b3ad74ea
...@@ -1598,7 +1598,7 @@ public class ErsCorrection extends GeometryCorrection { ...@@ -1598,7 +1598,7 @@ public class ErsCorrection extends GeometryCorrection {
} }
} }
@Deprecated
public void compareDSItoWorldDerivatives( public void compareDSItoWorldDerivatives(
QuadCLT scene_QuadClt, QuadCLT scene_QuadClt,
double max_inf_disparity, // absolute value double max_inf_disparity, // absolute value
......
...@@ -514,6 +514,7 @@ public class Interscene { ...@@ -514,6 +514,7 @@ public class Interscene {
double min_ref_str = clt_parameters.imp.min_ref_str; double min_ref_str = clt_parameters.imp.min_ref_str;
boolean ref_need_lma = clt_parameters.imp.ref_need_lma; boolean ref_need_lma = clt_parameters.imp.ref_need_lma;
double min_ref_frac= clt_parameters.imp.min_ref_frac; 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 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_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_fracmax = clt_parameters.imp.sfm_fracmax; // 0.75; // minimal fraction of the SfM maximal gain
...@@ -636,6 +637,7 @@ public class Interscene { ...@@ -636,6 +637,7 @@ public class Interscene {
scene_index, // int nscene1, // compares to nscene0 scene_index, // int nscene1, // compares to nscene0
null, // double [] ref_disparity, // null or alternative reference disparity null, // double [] ref_disparity, // null or alternative reference disparity
reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles 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,, scenes_xyzatr[ref_index], // double [][] scene0_xyzatr,,
initial_pose, // double [][] scene1_xyzatr, initial_pose, // double [][] scene1_xyzatr,
Double.NaN, // double average_z, Double.NaN, // double average_z,
...@@ -749,6 +751,7 @@ public class Interscene { ...@@ -749,6 +751,7 @@ public class Interscene {
fpn_pairs[ipair][0], // int nscene1, // compares to nscene0 fpn_pairs[ipair][0], // int nscene1, // compares to nscene0
null, // double [] ref_disparity, // null or alternative reference disparity null, // double [] ref_disparity, // null or alternative reference disparity
reliable_ref, //boolean [] reliable_ref, // null or bitmask of reliable reference tiles 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][1]], // double [][] scene0_xyzatr,,
scenes_xyzatr[fpn_pairs[ipair][0]], // initial_pose, // double [][] scene1_xyzatr, scenes_xyzatr[fpn_pairs[ipair][0]], // initial_pose, // double [][] scene1_xyzatr,
Double.NaN, // double average_z, Double.NaN, // double average_z,
...@@ -847,6 +850,12 @@ public class Interscene { ...@@ -847,6 +850,12 @@ 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_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_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 double sfm_fracall = clt_parameters.imp.sfm_fracall; // 0.3; // minimal relative area of the SfM-e
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 int max_num_scenes = clt_parameters.imp.max_num_scenes; // cut longer series
boolean ims_use = clt_parameters.imp.ims_use; boolean ims_use = clt_parameters.imp.ims_use;
...@@ -906,7 +915,7 @@ public class Interscene { ...@@ -906,7 +915,7 @@ public class Interscene {
ErsCorrection ers_reference = quadCLTs[ref_index].getErsCorrection(); 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 debug2 = !batch_mode; // false; // true;
boolean [] reliable_ref = null; boolean [] reliable_ref = null;
boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi; boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
...@@ -974,6 +983,26 @@ public class Interscene { ...@@ -974,6 +983,26 @@ public class Interscene {
debugLevel); // final int debugLevel); debugLevel); // final int debugLevel);
} }
double [][][] ims_xyzatr; 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) { if (inertial_only) {
ims_xyzatr = QuadCLT.integratePIMU( ims_xyzatr = QuadCLT.integratePIMU(
clt_parameters, // final CLTParameters clt_parameters, clt_parameters, // final CLTParameters clt_parameters,
...@@ -991,7 +1020,29 @@ public class Interscene { ...@@ -991,7 +1020,29 @@ public class Interscene {
quat_corr, // double [] quat_corr, // only applies to rotations - verify! quat_corr, // double [] quat_corr, // only applies to rotations - verify!
debugLevel) ; // int debugLevel) 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 double [][][] scenes_xyzatr = new double [quadCLTs.length][][]; // previous scene relative to the next one
scenes_xyzatr[ref_index] = new double[2][3]; // all zeros scenes_xyzatr[ref_index] = new double[2][3]; // all zeros
// boolean after_spiral = false; // boolean after_spiral = false;
...@@ -1019,6 +1070,9 @@ public class Interscene { ...@@ -1019,6 +1070,9 @@ public class Interscene {
// min_max[1] = max_offset; // 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; 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--) { 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){ if ((ref_index - scene_index) >= max_num_scenes){
earliest_scene = scene_index + 1; earliest_scene = scene_index + 1;
if (debugLevel > -3) { if (debugLevel > -3) {
...@@ -1113,6 +1167,7 @@ public class Interscene { ...@@ -1113,6 +1167,7 @@ public class Interscene {
scene_index, // int nscene1, // compares to nscene0 scene_index, // int nscene1, // compares to nscene0
null, // double [] ref_disparity, // null or alternative reference disparity null, // double [] ref_disparity, // null or alternative reference disparity
reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles 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,, scenes_xyzatr[ref_index], // double [][] scene0_xyzatr,,
initial_pose, // double [][] scene1_xyzatr, initial_pose, // double [][] scene1_xyzatr,
Double.NaN, // double average_z, Double.NaN, // double average_z,
...@@ -1278,6 +1333,7 @@ public class Interscene { ...@@ -1278,6 +1333,7 @@ public class Interscene {
fpn_pairs[ipair][0], // int nscene1, // compares to nscene0 fpn_pairs[ipair][0], // int nscene1, // compares to nscene0
null, // double [] ref_disparity, // null or alternative reference disparity null, // double [] ref_disparity, // null or alternative reference disparity
reliable_ref, //boolean [] reliable_ref, // null or bitmask of reliable reference tiles 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][1]], // double [][] scene0_xyzatr,,
scenes_xyzatr[fpn_pairs[ipair][0]], // initial_pose, // double [][] scene1_xyzatr, scenes_xyzatr[fpn_pairs[ipair][0]], // initial_pose, // double [][] scene1_xyzatr,
Double.NaN, // double average_z, Double.NaN, // double average_z,
...@@ -1375,6 +1431,28 @@ public class Interscene { ...@@ -1375,6 +1431,28 @@ public class Interscene {
return earliest_scene; 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( public static void testPIMU(
final CLTParameters clt_parameters, final CLTParameters clt_parameters,
final QuadCLT[] quadCLTs, final QuadCLT[] quadCLTs,
...@@ -2167,7 +2245,7 @@ public class Interscene { ...@@ -2167,7 +2245,7 @@ public class Interscene {
scenes_xyzatr[ref_index] = new double[2][3]; // all zeros scenes_xyzatr[ref_index] = new double[2][3]; // all zeros
// should have at least next or previous non-null // 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 = new RMSEStats();
RMSEStats rmse_stats_metric = clt_parameters.imp.eig_use ? (new RMSEStats()):null; RMSEStats rmse_stats_metric = clt_parameters.imp.eig_use ? (new RMSEStats()):null;
if (debug_ers) { if (debug_ers) {
...@@ -2385,6 +2463,7 @@ public class Interscene { ...@@ -2385,6 +2463,7 @@ public class Interscene {
test_pair[1], // int nscene1, // compares to nscene0 test_pair[1], // int nscene1, // compares to nscene0
interscene_ref_disparity,// double [] ref_disparity, // null or alternative reference disparity interscene_ref_disparity,// double [] ref_disparity, // null or alternative reference disparity
reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles 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[0]],// double [][] scene0_xyzatr,
scenes_xyzatr[test_pair[1]], // double [][] scene1_xyzatr, scenes_xyzatr[test_pair[1]], // double [][] scene1_xyzatr,
avg_z, // double average_z, avg_z, // double average_z,
...@@ -2515,6 +2594,7 @@ public class Interscene { ...@@ -2515,6 +2594,7 @@ public class Interscene {
nscene, // int nscene1, // compares to nscene0 nscene, // int nscene1, // compares to nscene0
interscene_ref_disparity,// double [] ref_disparity, // null or alternative reference disparity interscene_ref_disparity,// double [] ref_disparity, // null or alternative reference disparity
reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles 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[ref_index],// double [][] scene0_xyzatr,
scenes_xyzatr[nscene], // double [][] scene1_xyzatr, scenes_xyzatr[nscene], // double [][] scene1_xyzatr,
avg_z, // double average_z, avg_z, // double average_z,
...@@ -2698,6 +2778,7 @@ public class Interscene { ...@@ -2698,6 +2778,7 @@ public class Interscene {
fpn_pairs[ipair][0], // int nscene1, // compares to nscene0 fpn_pairs[ipair][0], // int nscene1, // compares to nscene0
interscene_ref_disparity,// double [] ref_disparity, // null or alternative reference disparity interscene_ref_disparity,// double [] ref_disparity, // null or alternative reference disparity
reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles 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][1]],// double [][] scene0_xyzatr,
scenes_xyzatr[fpn_pairs[ipair][0]], // double [][] scene1_xyzatr, scenes_xyzatr[fpn_pairs[ipair][0]], // double [][] scene1_xyzatr,
avg_z, // double average_z, avg_z, // double average_z,
...@@ -2774,6 +2855,7 @@ public class Interscene { ...@@ -2774,6 +2855,7 @@ public class Interscene {
test_pair[0], // int nscene1, // compares to nscene0 test_pair[0], // int nscene1, // compares to nscene0
interscene_ref_disparity,// double [] ref_disparity, // null or alternative reference disparity interscene_ref_disparity,// double [] ref_disparity, // null or alternative reference disparity
reliable_ref, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles 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[1]],// double [][] scene0_xyzatr,
scenes_xyzatr[test_pair[0]], // double [][] scene1_xyzatr, scenes_xyzatr[test_pair[0]], // double [][] scene1_xyzatr,
avg_z, // double average_z, avg_z, // double average_z,
...@@ -2896,12 +2978,13 @@ public class Interscene { ...@@ -2896,12 +2978,13 @@ public class Interscene {
int ref_index, int ref_index,
TpTask[][] tp_tasks_ref, // Should be TpTask[2][*]. If tp_tasks_ref[0] == null will calculate TpTask[][] tp_tasks_ref, // Should be TpTask[2][*]. If tp_tasks_ref[0] == null will calculate
// at set first scene to the GPU // 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 // will be recalculated when tp_tasks_ref[0] == null, but for reference frame
int nscene0, // may be == ref_index int nscene0, // may be == ref_index
int nscene1, // compares to nscene0 int nscene1, // compares to nscene0
double [] ref_disparity, // null or alternative reference disparity double [] ref_disparity, // null or alternative reference disparity
boolean [] reliable_ref, // null or bitmask of reliable reference tiles 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 [][] scene0_xyzatr,
double [][] scene1_xyzatr, double [][] scene1_xyzatr,
double average_z, double average_z,
...@@ -2915,10 +2998,53 @@ public class Interscene { ...@@ -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 double mb_max_gain, // 5.0; // motion blur maximal gain (if more - move second point more than a pixel
int debugLevel) 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; // boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
if (ref_disparity == null) { if (ref_disparity == null) {
ref_disparity = quadCLTs[ref_index].getDLS()[use_lma_dsi?1:0]; 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 // 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) || (tp_tasks_ref[0] == null)) { // calculate and setup reference (for comparison) scene to GPU
if (tp_tasks_ref == null) { if (tp_tasks_ref == null) {
...@@ -3357,6 +3483,7 @@ public class Interscene { ...@@ -3357,6 +3483,7 @@ public class Interscene {
// boolean dbg_images = false; // boolean dbg_images = false;
double [][] eigen_masked = clt_parameters.imp.eig_xy_lma? null : eigen; 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; String dbg_prefix = dbg_images? (first_QuadClt.getImageName()+"-"+scene_QuadClt.getImageName()+"-NLMA_"+nlma) : null;
final boolean same_weights = false;
intersceneLma.prepareLMA( intersceneLma.prepareLMA(
scene_xyzatr0, // final double [] scene_xyzatr0, // 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)
scene_xyzatr_pull, // final double [] scene_xyz_pull, // if both are not null, specify target values to pull to 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 { ...@@ -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 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[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 coord_motion[0], // final double [][] centers, // macrotile centers (in pixels and average disparities
same_weights, // final boolean same_weights,
(nlma == 0), // boolean first_run, (nlma == 0), // boolean first_run,
dbg_prefix, // String dbg_prefix, // null or image name prefix dbg_prefix, // String dbg_prefix, // null or image name prefix
clt_parameters.imp.debug_level); // final int debug_level) clt_parameters.imp.debug_level); // final int debug_level)
...@@ -3838,7 +3966,8 @@ public class Interscene { ...@@ -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_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); boolean mov_debug_images = clt_parameters.imp.showMovementDetection(imp_debug_level);
int mov_debug_level = clt_parameters.imp.movDebugLevel(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; boolean fpn_remove = !fpn_disable && clt_parameters.imp.fpn_remove;
double fpn_max_offset = clt_parameters.imp.fpn_max_offset; double fpn_max_offset = clt_parameters.imp.fpn_max_offset;
final double fpn_min_offset = clt_parameters.imp.fpn_min_offset; final double fpn_min_offset = clt_parameters.imp.fpn_min_offset;
......
...@@ -40,6 +40,7 @@ import javax.xml.bind.DatatypeConverter; ...@@ -40,6 +40,7 @@ import javax.xml.bind.DatatypeConverter;
import com.elphel.imagej.common.ShowDoubleFloatArrays; import com.elphel.imagej.common.ShowDoubleFloatArrays;
import Jama.Matrix; import Jama.Matrix;
import ij.ImagePlus;
public class IntersceneLma { public class IntersceneLma {
QuadCLT [] scenesCLT = null; // now will use just 2 - 0 -reference scene, 1 - scene. QuadCLT [] scenesCLT = null; // now will use just 2 - 0 -reference scene, 1 - scene.
...@@ -275,6 +276,7 @@ public class IntersceneLma { ...@@ -275,6 +276,7 @@ public class IntersceneLma {
// 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 [][] vector_XYSDS,// optical flow X,Y, confidence obtained from the correlate2DIterate()
final double [][] centers, // macrotile centers (in pixels and average disparities final double [][] centers, // macrotile centers (in pixels and average disparities
final boolean same_weights,
boolean first_run, boolean first_run,
String dbg_prefix, // null or image name prefix String dbg_prefix, // null or image name prefix
final int debug_level) { final int debug_level) {
...@@ -336,7 +338,9 @@ public class IntersceneLma { ...@@ -336,7 +338,9 @@ public class IntersceneLma {
} }
if (vector_XYSDS != null) {// skip when used for the motion blur vectors, not LMA 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 { } else {
weights = null; // new double[2 * centers.length]; weights = null; // new double[2 * centers.length];
} }
...@@ -423,7 +427,7 @@ public class IntersceneLma { ...@@ -423,7 +427,7 @@ public class IntersceneLma {
// 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 [][] vector_XYSDS,// optical flow X,Y, confidence obtained from the correlate2DIterate()
final double [][] centers, // macrotile centers (in pixels and average disparities final double [][] centers, // macrotile centers (in pixels and average disparities
final boolean same_weights,
boolean first_run, boolean first_run,
final int debug_level) final int debug_level)
{ {
...@@ -477,7 +481,8 @@ public class IntersceneLma { ...@@ -477,7 +481,8 @@ public class IntersceneLma {
} }
if (vector_XYSDS != null) {// skip when used for the motion blur vectors, not LMA 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 { } else {
weights = null; // new double[2 * centers.length]; weights = null; // new double[2 * centers.length];
} }
...@@ -663,8 +668,35 @@ public class IntersceneLma { ...@@ -663,8 +668,35 @@ public class IntersceneLma {
last_rms); // final double [] rms_fp // null or [2] last_rms); // final double [] rms_fp // null or [2]
this.initial_rms = this.last_rms.clone(); this.initial_rms = this.last_rms.clone();
this.good_or_bad_rms = this.last_rms.clone(); this.good_or_bad_rms = this.last_rms.clone();
if (dbg_prefix != null) { // -1) { // temporary
if (debug_level > -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( dbgYminusFxWeight(
this.last_ymfx, this.last_ymfx,
...@@ -834,7 +866,8 @@ public class IntersceneLma { ...@@ -834,7 +866,8 @@ public class IntersceneLma {
} }
private void setSamplesWeights( 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 //num_components 2 - old, 3 - with disparity
this.weights = new double [num_samples + parameters_vector.length]; this.weights = new double [num_samples + parameters_vector.length];
...@@ -861,6 +894,9 @@ public class IntersceneLma { ...@@ -861,6 +894,9 @@ public class IntersceneLma {
continue; continue;
} }
if (w > 0) { if (w > 0) {
if (same_weights) {
w = 1.0;
}
anum_defined.getAndIncrement(); anum_defined.getAndIncrement();
weights[num_components * iMTile] = w; weights[num_components * iMTile] = w;
sw_arr[thread_num] += 2*w; sw_arr[thread_num] += 2*w;
...@@ -977,6 +1013,356 @@ public class IntersceneLma { ...@@ -977,6 +1013,356 @@ 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]];
}
String [] comp_names = {"dx", "dy","ddisp"};
double [][] jt = new double [vector.length][];
double [] fX = getFxDerivs(
vector, // final double [] vector,
jt, // final double [][] jt, // should be null or initialized with [vector.length][]
scene_QuadClt, // final QuadCLT scene_QuadClt,
reference_QuadClt, // final QuadCLT reference_QuadClt,
debugLevel); // final int debug_level)
double [][] jt_delta = getFxDerivsDelta (
vector, // final double [] vector,
deltas, // final double[] deltas, // same length as vector, or [1] - then use for all
scene_QuadClt, // final QuadCLT scene_QuadClt,
reference_QuadClt, // final QuadCLT reference_QuadClt,
debugLevel-10); // final int debug_level)
double [][] jt_diff = new double [jt_delta.length][jt_delta[0].length];
double max_err=0;
double min_bad = 0.01;
for (int n = 0; n < jt_diff.length; n++) {
for (int w = 0; w < jt_diff[0].length; w++) if (weights[w] > 0){ // skip zero weights
jt_diff[n][w] = jt[n][w] - jt_delta[n][w];
// int [] ti = par_rindex[n];
int ntile = w/num_components;
int ncomp = w % num_components;
if (Math.abs(jt_diff[n][w]) > max_err) {
System.out.println("debugDerivs(): n="+n+" ("+par_names[n]+"), ntile = "+ntile +", comp="+comp_names[ncomp] +", diff="+jt_diff[n][w]+" jt="+jt[n][w]+" jt_delta="+jt_delta[n][w]);
} else if (Math.abs(jt_diff[n][w]) > min_bad) {
System.out.println("debugDerivs(): n="+n+" ("+par_names[n]+"), ntile = "+ntile +", comp="+comp_names[ncomp] +", diff="+jt_diff[n][w]+" jt="+jt[n][w]+" jt_delta="+jt_delta[n][w]);
}
max_err = Math.max(max_err, Math.abs(jt_diff[n][w]));
}
}
System.out.println("delta = "+delta+", max_err = "+max_err);
if (show_img) {
String dbg_title= scenesCLT[0].getImageName()+"-"+scenesCLT[1].getImageName();
int dbg_num_rows = 3;
boolean dbg_show_reg = true;
boolean dbg_show = true;
showFxDerivs(
fX, // double [] fX,
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+"-jt"); // String title);
showFxDerivs(
fX, // double [] fX,
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+"-jt"); // String title);
showFxDerivs(
fX, // double [] fX,
jt_delta, // 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+"-jt_delta_"+delta); // String title);
showFxDerivs(
fX, // double [] fX,
jt_delta, // 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+"-jt_delta_"+delta); // String title);
showFxDerivs(
fX, // double [] fX,
jt_diff, // 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+"-jt_diff_"+delta); // String title);
showFxDerivs(
fX, // double [] fX,
jt_diff, // 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+"-jt_diff_"+delta); // String title);
}
return;
}
private double [] getFxDerivs( private double [] getFxDerivs(
double [] vector, double [] vector,
final double [][] jt, // should be null or initialized with [vector.length][] final double [][] jt, // should be null or initialized with [vector.length][]
......
...@@ -557,6 +557,11 @@ min_str_neib_fpn 0.35 ...@@ -557,6 +557,11 @@ min_str_neib_fpn 0.35
public boolean ref_need_lma_combo = true; // need LMA output for reliable tiles (when combo is available) public boolean ref_need_lma_combo = true; // need LMA output for reliable tiles (when combo is available)
public double min_ref_str = 0.33; // 0.22; // For orientations: use only tiles of the reference scene DSI_MAIN is stronger public double min_ref_str = 0.33; // 0.22; // For orientations: use only tiles of the reference scene DSI_MAIN is stronger
public double min_ref_frac = 0.2; // 0.22; if fraction number of reliable tiles is less than this, use best possible public double min_ref_frac = 0.2; // 0.22; if fraction number of reliable tiles is less than this, use best possible
public boolean ref_smooth = false; // smooth reference disparity for initial matching
public double ref_sigma = 2.0; // Gaussian sigma to smooth reference disparity for initial matching
public double ref_smooth_diff = 0.15; // discard smooth disparity if it differs by more from measured
// SfM-related filtering (remove tiles without SfM) // SfM-related filtering (remove tiles without SfM)
public boolean sfm_filter = true; // use SfM filtering if available public boolean sfm_filter = true; // use SfM filtering if available
public double sfm_minmax = 3.0; // 10.0 // minimal value of the SfM gain maximum to consider available public double sfm_minmax = 3.0; // 10.0 // minimal value of the SfM gain maximum to consider available
...@@ -736,6 +741,7 @@ min_str_neib_fpn 0.35 ...@@ -736,6 +741,7 @@ min_str_neib_fpn 0.35
public int terr_shrink_terrain= 20; // shrink accumulated terrain after cutting shrunk vegetation (added to terr_shrink_veget) public int terr_shrink_terrain= 20; // shrink accumulated terrain after cutting shrunk vegetation (added to terr_shrink_veget)
public double terr_vegetation_over = 35; // initial vegetation over (hotter) filled terrain public double terr_vegetation_over = 35; // initial vegetation over (hotter) filled terrain
public int terr_filter_veget = 10; // shrink+grow shrunk vegetation to remove small clusters public int terr_filter_veget = 10; // shrink+grow shrunk vegetation to remove small clusters
public int terr_veget_grow = 2; // grow (fill NaN holes) vegetation when extracting from multi-scene sequences
public boolean terr_tile_woi = true; // if false - use woi50; public boolean terr_tile_woi = true; // if false - use woi50;
public Rectangle terr_woi_enclos = new Rectangle(80, 210, 210, 230); // will be tiled, using width/height from woi_step; public Rectangle terr_woi_enclos = new Rectangle(80, 210, 210, 230); // will be tiled, using width/height from woi_step;
...@@ -1670,6 +1676,15 @@ min_str_neib_fpn 0.35 ...@@ -1670,6 +1676,15 @@ min_str_neib_fpn 0.35
gd.addNumericField("DSI_MAIN minimal fraction", this.min_ref_frac, 5,7,"", gd.addNumericField("DSI_MAIN minimal fraction", this.min_ref_frac, 5,7,"",
"If relative number of the reliable tiles is less than this - use this best fraction."); "If relative number of the reliable tiles is less than this - use this best fraction.");
gd.addMessage ("Smooth reference disparity for initial matching");
gd.addCheckbox ("Smooth reference disparity", this.ref_smooth,
"Smooth reference disparity for initial matching.");
gd.addNumericField("Reference disparity sigma", this.ref_sigma, 5,7,"pix",
"Gaussian sigma to smooth reference disparity for initial matching.");
gd.addNumericField("Max smooth offset", this.ref_smooth_diff, 5,7,"pix",
"Discard smooth disparity if it differs by more from measured.");
gd.addCheckbox ("Use SfM filtering if available", this.sfm_filter, gd.addCheckbox ("Use SfM filtering if available", this.sfm_filter,
"Mask out tiles without sufficient SfM gain (if SfM data is available)."); "Mask out tiles without sufficient SfM gain (if SfM data is available).");
gd.addNumericField("Min SfM gain maximum to consider", this.sfm_minmax, 5,7,"", gd.addNumericField("Min SfM gain maximum to consider", this.sfm_minmax, 5,7,"",
...@@ -2017,6 +2032,7 @@ min_str_neib_fpn 0.35 ...@@ -2017,6 +2032,7 @@ min_str_neib_fpn 0.35
gd.addNumericField("Vegetation hotter", terr_vegetation_over, 5,7,"", "Initially consider to be vegetation if it is this hotter than filled in terrain holes."); gd.addNumericField("Vegetation hotter", terr_vegetation_over, 5,7,"", "Initially consider to be vegetation if it is this hotter than filled in terrain holes.");
gd.addNumericField("Vegetation shrink+grow", terr_filter_veget, 0,3,"pix", "Shrink + grow hot enough vegetation to filter from small clusters - needed for initial alpha."); gd.addNumericField("Vegetation shrink+grow", terr_filter_veget, 0,3,"pix", "Shrink + grow hot enough vegetation to filter from small clusters - needed for initial alpha.");
gd.addNumericField("Grow vegetation extract", terr_veget_grow, 0,3,"pix", "Grow vegetation when extracting from the multi-scene sequences.");
gd.addMessage ("Scan WOI parameters"); gd.addMessage ("Scan WOI parameters");
gd.addCheckbox ("Tiled WOI", terr_tile_woi, "Process tiled WOI (False - a single one)."); gd.addCheckbox ("Tiled WOI", terr_tile_woi, "Process tiled WOI (False - a single one).");
...@@ -2532,6 +2548,9 @@ min_str_neib_fpn 0.35 ...@@ -2532,6 +2548,9 @@ min_str_neib_fpn 0.35
this.ref_need_lma_combo = gd.getNextBoolean(); this.ref_need_lma_combo = gd.getNextBoolean();
this.min_ref_str = gd.getNextNumber(); this.min_ref_str = gd.getNextNumber();
this.min_ref_frac = gd.getNextNumber(); this.min_ref_frac = gd.getNextNumber();
this.ref_smooth = gd.getNextBoolean();
this.ref_sigma = gd.getNextNumber();
this.ref_smooth_diff = gd.getNextNumber();
this.sfm_filter = gd.getNextBoolean(); this.sfm_filter = gd.getNextBoolean();
this.sfm_minmax = gd.getNextNumber(); this.sfm_minmax = gd.getNextNumber();
this.sfm_fracmax = gd.getNextNumber(); this.sfm_fracmax = gd.getNextNumber();
...@@ -2740,6 +2759,8 @@ min_str_neib_fpn 0.35 ...@@ -2740,6 +2759,8 @@ min_str_neib_fpn 0.35
terr_vegetation_over = gd.getNextNumber(); // double terr_vegetation_over = gd.getNextNumber(); // double
terr_filter_veget = (int) gd.getNextNumber(); // int terr_filter_veget = (int) gd.getNextNumber(); // int
terr_veget_grow = (int) gd.getNextNumber(); // int
terr_tile_woi = gd.getNextBoolean(); // boolean terr_tile_woi = gd.getNextBoolean(); // boolean
terr_continue = gd.getNextBoolean(); // boolean terr_continue = gd.getNextBoolean(); // boolean
terr_woi_enclos = stringToRectangle(gd.getNextString());// Rectangle terr_woi_enclos = stringToRectangle(gd.getNextString());// Rectangle
...@@ -3255,6 +3276,10 @@ min_str_neib_fpn 0.35 ...@@ -3255,6 +3276,10 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"min_ref_str", this.min_ref_str+""); // double properties.setProperty(prefix+"min_ref_str", this.min_ref_str+""); // double
properties.setProperty(prefix+"min_ref_frac", this.min_ref_frac+""); // double properties.setProperty(prefix+"min_ref_frac", this.min_ref_frac+""); // double
properties.setProperty(prefix+"ref_smooth", this.ref_smooth+""); // boolean
properties.setProperty(prefix+"ref_sigma", this.ref_sigma+""); // double
properties.setProperty(prefix+"ref_smooth_diff", this.ref_smooth_diff+""); // double
properties.setProperty(prefix+"sfm_filter", this.sfm_filter+""); // boolean properties.setProperty(prefix+"sfm_filter", this.sfm_filter+""); // boolean
properties.setProperty(prefix+"sfm_minmax", this.sfm_minmax+""); // double properties.setProperty(prefix+"sfm_minmax", this.sfm_minmax+""); // double
properties.setProperty(prefix+"sfm_fracmax", this.sfm_fracmax+""); // double properties.setProperty(prefix+"sfm_fracmax", this.sfm_fracmax+""); // double
...@@ -3417,8 +3442,12 @@ min_str_neib_fpn 0.35 ...@@ -3417,8 +3442,12 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"terr_nan_tolerance", terr_nan_tolerance+""); // double properties.setProperty(prefix+"terr_nan_tolerance", terr_nan_tolerance+""); // double
properties.setProperty(prefix+"terr_nan_grow", terr_nan_grow+""); // int properties.setProperty(prefix+"terr_nan_grow", terr_nan_grow+""); // int
properties.setProperty(prefix+"terr_nan_grow", terr_nan_grow+""); // int properties.setProperty(prefix+"terr_shrink_veget", terr_shrink_veget+""); // int
properties.setProperty(prefix+"terr_nan_grow", terr_nan_grow+""); // int properties.setProperty(prefix+"terr_shrink_terrain", terr_shrink_terrain+""); // int
properties.setProperty(prefix+"terr_vegetation_over", terr_vegetation_over+""); // double
properties.setProperty(prefix+"terr_filter_veget", terr_filter_veget+""); // int
properties.setProperty(prefix+"terr_veget_grow", terr_veget_grow+""); // int
properties.setProperty(prefix+"terr_nan_tolerance", terr_nan_tolerance+""); // double properties.setProperty(prefix+"terr_nan_tolerance", terr_nan_tolerance+""); // double
properties.setProperty(prefix+"terr_nan_grow", terr_nan_grow+""); // int properties.setProperty(prefix+"terr_nan_grow", terr_nan_grow+""); // int
...@@ -3940,6 +3969,10 @@ min_str_neib_fpn 0.35 ...@@ -3940,6 +3969,10 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"min_ref_str")!=null) this.min_ref_str=Double.parseDouble(properties.getProperty(prefix+"min_ref_str")); if (properties.getProperty(prefix+"min_ref_str")!=null) this.min_ref_str=Double.parseDouble(properties.getProperty(prefix+"min_ref_str"));
if (properties.getProperty(prefix+"min_ref_frac")!=null) this.min_ref_frac=Double.parseDouble(properties.getProperty(prefix+"min_ref_frac")); if (properties.getProperty(prefix+"min_ref_frac")!=null) this.min_ref_frac=Double.parseDouble(properties.getProperty(prefix+"min_ref_frac"));
if (properties.getProperty(prefix+"ref_smooth")!=null) this.ref_smooth=Boolean.parseBoolean(properties.getProperty(prefix+"ref_smooth"));
if (properties.getProperty(prefix+"ref_sigma")!=null) this.ref_sigma=Double.parseDouble(properties.getProperty(prefix+"ref_sigma"));
if (properties.getProperty(prefix+"ref_smooth_diff")!=null) this.ref_smooth_diff=Double.parseDouble(properties.getProperty(prefix+"ref_smooth_diff"));
if (properties.getProperty(prefix+"sfm_filter")!=null) this.sfm_filter=Boolean.parseBoolean(properties.getProperty(prefix+"sfm_filter")); if (properties.getProperty(prefix+"sfm_filter")!=null) this.sfm_filter=Boolean.parseBoolean(properties.getProperty(prefix+"sfm_filter"));
if (properties.getProperty(prefix+"sfm_minmax")!=null) this.sfm_minmax=Double.parseDouble(properties.getProperty(prefix+"sfm_minmax")); if (properties.getProperty(prefix+"sfm_minmax")!=null) this.sfm_minmax=Double.parseDouble(properties.getProperty(prefix+"sfm_minmax"));
if (properties.getProperty(prefix+"sfm_fracmax")!=null) this.sfm_fracmax=Double.parseDouble(properties.getProperty(prefix+"sfm_fracmax")); if (properties.getProperty(prefix+"sfm_fracmax")!=null) this.sfm_fracmax=Double.parseDouble(properties.getProperty(prefix+"sfm_fracmax"));
...@@ -4124,7 +4157,7 @@ min_str_neib_fpn 0.35 ...@@ -4124,7 +4157,7 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"terr_shrink_terrain")!= null) terr_shrink_terrain=Integer.parseInt(properties.getProperty(prefix+"terr_shrink_terrain")); if (properties.getProperty(prefix+"terr_shrink_terrain")!= null) terr_shrink_terrain=Integer.parseInt(properties.getProperty(prefix+"terr_shrink_terrain"));
if (properties.getProperty(prefix+"terr_vegetation_over")!= null) terr_vegetation_over=Double.parseDouble(properties.getProperty(prefix+"terr_vegetation_over")); if (properties.getProperty(prefix+"terr_vegetation_over")!= null) terr_vegetation_over=Double.parseDouble(properties.getProperty(prefix+"terr_vegetation_over"));
if (properties.getProperty(prefix+"terr_filter_veget")!= null) terr_filter_veget=Integer.parseInt(properties.getProperty(prefix+"terr_filter_veget")); if (properties.getProperty(prefix+"terr_filter_veget")!= null) terr_filter_veget=Integer.parseInt(properties.getProperty(prefix+"terr_filter_veget"));
if (properties.getProperty(prefix+"terr_veget_grow")!= null) terr_veget_grow=Integer.parseInt(properties.getProperty(prefix+"terr_veget_grow"));
if (properties.getProperty(prefix+"terr_tile_woi")!= null) terr_tile_woi=Boolean.parseBoolean(properties.getProperty(prefix+"terr_tile_woi")); if (properties.getProperty(prefix+"terr_tile_woi")!= null) terr_tile_woi=Boolean.parseBoolean(properties.getProperty(prefix+"terr_tile_woi"));
if (properties.getProperty(prefix+"terr_continue")!= null) terr_continue=Boolean.parseBoolean(properties.getProperty(prefix+"terr_continue")); if (properties.getProperty(prefix+"terr_continue")!= null) terr_continue=Boolean.parseBoolean(properties.getProperty(prefix+"terr_continue"));
if (properties.getProperty(prefix+"terr_woi_enclos")!= null) terr_woi_enclos=stringToRectangle((String) properties.getProperty(prefix+"terr_woi_enclos")); if (properties.getProperty(prefix+"terr_woi_enclos")!= null) terr_woi_enclos=stringToRectangle((String) properties.getProperty(prefix+"terr_woi_enclos"));
...@@ -4633,6 +4666,10 @@ min_str_neib_fpn 0.35 ...@@ -4633,6 +4666,10 @@ min_str_neib_fpn 0.35
imp.min_ref_str = this.min_ref_str; imp.min_ref_str = this.min_ref_str;
imp.min_ref_frac = this.min_ref_frac; imp.min_ref_frac = this.min_ref_frac;
imp.ref_smooth = this.ref_smooth;
imp.ref_sigma = this.ref_sigma;
imp.ref_smooth_diff = this.ref_smooth_diff;
imp.sfm_filter = this.sfm_filter; imp.sfm_filter = this.sfm_filter;
imp.sfm_minmax = this.sfm_minmax; imp.sfm_minmax = this.sfm_minmax;
imp.sfm_fracmax = this.sfm_fracmax; imp.sfm_fracmax = this.sfm_fracmax;
...@@ -4796,6 +4833,8 @@ min_str_neib_fpn 0.35 ...@@ -4796,6 +4833,8 @@ min_str_neib_fpn 0.35
imp.terr_vegetation_over = this.terr_vegetation_over; imp.terr_vegetation_over = this.terr_vegetation_over;
imp.terr_filter_veget = this.terr_filter_veget; imp.terr_filter_veget = this.terr_filter_veget;
imp.terr_veget_grow = this.terr_veget_grow;
imp.terr_tile_woi = this.terr_tile_woi; imp.terr_tile_woi = this.terr_tile_woi;
imp.terr_continue = this.terr_continue; imp.terr_continue = this.terr_continue;
imp.terr_woi_enclos = new Rectangle(this.terr_woi_enclos); imp.terr_woi_enclos = new Rectangle(this.terr_woi_enclos);
......
...@@ -13256,6 +13256,7 @@ public class OpticalFlow { ...@@ -13256,6 +13256,7 @@ public class OpticalFlow {
param_regweights, // final double [] param_regweights, param_regweights, // final double [] param_regweights,
vector_XYS, // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate() vector_XYS, // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate()
reference_tiles_macro, // final double [][] centers, // macrotile centers (in pixels and average disparities reference_tiles_macro, // final double [][] centers, // macrotile centers (in pixels and average disparities
false, // final boolean same_weights,
(nlma == 0), // boolean first_run, (nlma == 0), // boolean first_run,
clt_parameters.ilp.ilma_debug_level); // final int debug_level) clt_parameters.ilp.ilma_debug_level); // final int debug_level)
...@@ -13392,6 +13393,7 @@ public class OpticalFlow { ...@@ -13392,6 +13393,7 @@ public class OpticalFlow {
null, // final double [] param_regweights, null, // final double [] param_regweights,
null, // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate() null, // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate()
ref_pXpYD, // final double [][] centers, // macrotile centers (in pixels and average disparities ref_pXpYD, // final double [][] centers, // macrotile centers (in pixels and average disparities
false, // final boolean same_weights,
false, // boolean first_run, false, // boolean first_run,
debug_level); // final int debug_level) debug_level); // final int debug_level)
final double [][] last_jt = intersceneLma. getLastJT(); // alternating x,y for each selected parameters final double [][] last_jt = intersceneLma. getLastJT(); // alternating x,y for each selected parameters
...@@ -13716,6 +13718,7 @@ public class OpticalFlow { ...@@ -13716,6 +13718,7 @@ public class OpticalFlow {
clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights, clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights,
vector_XYS, // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate() vector_XYS, // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate()
reference_tiles_macro, // final double [][] centers, // macrotile centers (in pixels and average disparities reference_tiles_macro, // final double [][] centers, // macrotile centers (in pixels and average disparities
false, // final boolean same_weights,
(nlma == 0), // boolean first_run, (nlma == 0), // boolean first_run,
debug_level); // final int debug_level) debug_level); // final int debug_level)
int lmaResult = intersceneLma.runLma( int lmaResult = intersceneLma.runLma(
......
...@@ -2630,6 +2630,62 @@ public class QuadCLTCPU { ...@@ -2630,6 +2630,62 @@ public class QuadCLTCPU {
} }
public double [] smoothDisparity(
double [] disparity_in,
boolean [] reliable_ref, // optional
double sigma,
double max_diff,
boolean apply_nan) {
final int tilesX = tp.getTilesX();
double [] disparity = disparity_in.clone();
if (reliable_ref != null) {
for (int i = 0; i < reliable_ref.length; i++) {
if (!reliable_ref[i]) {
disparity[i] = Double.NaN;
}
}
}
boolean [] good_tiles = new boolean [disparity.length];
for (int i = 0; i < disparity.length; i++) {
good_tiles[i] = !Double.isNaN(disparity[i]);
}
double scale_sigma = 5.0; // non-NaN - 5 pixels from original NaN for each sigma
int grow = 2* Math.min((int) Math.ceil(sigma * scale_sigma), tilesX);
disparity = TileProcessor.fillNaNs(
disparity, // final double [] data,
null, // final boolean [] prohibit,
tilesX, // int width,
// CAREFUL ! Remaining NaN is grown by unsharp mask filter ************* !
grow, // 100, // 2*width, // 16, // final int grow,
0.7, // double diagonal_weight, // relative to ortho
100, // int num_passes,
0.03); // final double max_rchange, // = 0.01 - does not need to be accurate
(new DoubleGaussianBlur()).blurDouble(
disparity, //
tilesX,
disparity.length/tilesX,
sigma, // double sigmaX,
sigma, // double sigmaY,
0.01); // double accuracy)
if (max_diff > 0) {
for (int i = 0; i < disparity.length; i++) if (good_tiles[i]){
if (Math.abs(disparity[i] - disparity_in[i]) > max_diff) {
good_tiles[i] = false;
}
}
}
if (apply_nan) {
for (int i = 0; i < disparity.length; i++) if (!good_tiles[i]){
disparity[i] = Double.NaN;
}
}
if (reliable_ref != null) {
System.arraycopy(good_tiles, 0, reliable_ref, 0, disparity.length);
}
return disparity;
}
public double [][] getDLS(){ // get disparity, disparity_lma, strength, sfm_gain public double [][] getDLS(){ // get disparity, disparity_lma, strength, sfm_gain
......
...@@ -2278,6 +2278,7 @@ public class StructureFromMotion { ...@@ -2278,6 +2278,7 @@ public class StructureFromMotion {
null, // final double [] param_regweights, null, // final double [] param_regweights,
null, // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate() null, // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate()
ref_pXpYD, // final double [][] centers, // macrotile centers (in pixels and average disparities ref_pXpYD, // final double [][] centers, // macrotile centers (in pixels and average disparities
false, // final boolean same_weights,
false, // boolean first_run, false, // boolean first_run,
debug_level); // final int debug_level) debug_level); // final int debug_level)
last_jts[nscene] = intersceneLma. getLastJT(); // alternating x,y for each selected parameters last_jts[nscene] = intersceneLma. getLastJT(); // alternating x,y for each selected parameters
......
...@@ -487,6 +487,7 @@ public class VegetationLMA { ...@@ -487,6 +487,7 @@ public class VegetationLMA {
max_warp, // final double max_warp, max_warp, // final double max_warp,
valid_pixels_in, // final boolean [] valid_pixels_in, // should be initialized to woi, normally set to all true valid_pixels_in, // final boolean [] valid_pixels_in, // should be initialized to woi, normally set to all true
max_offset, // final int max_offset, max_offset, // final int max_offset,
elev_radius, // final double [] elev_radius, // this.elevation_radius
max_sacrifice, // final int max_sacrifice, max_sacrifice, // final int max_sacrifice,
valid_stats, // final int [] stats, valid_stats, // final int [] stats,
max_warp_scene_pix, // final int [] max_warp_scene_pix, max_warp_scene_pix, // final int [] max_warp_scene_pix,
...@@ -5200,12 +5201,14 @@ public class VegetationLMA { ...@@ -5200,12 +5201,14 @@ public class VegetationLMA {
final double max_warp, final double max_warp,
final boolean [] valid_pixels_in, // should be initialized to woi, normally set to all true final boolean [] valid_pixels_in, // should be initialized to woi, normally set to all true
final int max_offset, final int max_offset,
final double [] elev_radius, // this.elevation_radius
final int max_sacrifice, final int max_sacrifice,
final int [] stats, final int [] stats,
final int [] max_warp_scene_pix, final int [] max_warp_scene_pix,
final Rectangle woi, final Rectangle woi,
final Rectangle woi_veg // should be initialized, will be modified final Rectangle woi_veg // should be initialized, will be modified
) { ) {
final int dbg_pix = 801; // 918;
final int woi_length = woi.width*woi.height; final int woi_length = woi.width*woi.height;
final boolean [] valid_pixels = (valid_pixels_in != null) ? valid_pixels_in : (new boolean [woi_length]); final boolean [] valid_pixels = (valid_pixels_in != null) ? valid_pixels_in : (new boolean [woi_length]);
if (valid_pixels_in == null) { if (valid_pixels_in == null) {
...@@ -5255,6 +5258,9 @@ public class VegetationLMA { ...@@ -5255,6 +5258,9 @@ public class VegetationLMA {
int y = indx / woi_ext.width + woi_ext.y; int y = indx / woi_ext.width + woi_ext.y;
int x = indx % woi_ext.width + woi_ext.x; int x = indx % woi_ext.width + woi_ext.x;
int npix = x + y * full.width; int npix = x + y * full.width;
double radius = elev_radius[npix];
double radius2 = radius*radius;
int iradius = (int) Math.ceil (radius);
double elevation = tvao[TVAO_ELEVATION][npix]; double elevation = tvao[TVAO_ELEVATION][npix];
double vegetation = tvao[TVAO_VEGETATION][npix]; double vegetation = tvao[TVAO_VEGETATION][npix];
if (!Double.isNaN(elevation) && !Double.isNaN(vegetation)) { if (!Double.isNaN(elevation) && !Double.isNaN(vegetation)) {
...@@ -5267,6 +5273,37 @@ public class VegetationLMA { ...@@ -5267,6 +5273,37 @@ public class VegetationLMA {
if (scales != null) { if (scales != null) {
double dx = scales[0] * elevation; double dx = scales[0] * elevation;
double dy = scales[1] * elevation; double dy = scales[1] * elevation;
int ax0 = (int) Math.floor(x + dx - radius);
int ax1 = (int) Math.ceil (x + dx + radius);
int ay0 = (int) Math.floor(y + dy - radius);
int ay1 = (int) Math.ceil (y + dy + radius);
Rectangle ar = new Rectangle(ax0, ay0, ax1-ax0 +1, ay1-ay0 +1);
if (woi.intersects(ar)) {
boolean has_valid_dependent = false;
for (int ay = ay0; ay <= ay1; ay++) {
double ddy = ay - (y + dy);
double ddy2 = ddy*ddy;
for (int ax = ax0; ax <= ax1; ax++) {
if (woi.contains(ax,ay)) {
double ddx = ax - (x + dx);
double ddr2 = ddy2 + ddx*ddx;
if (ddr2 <= radius2) {
int wx = ax - woi.x;
int wy = ay - woi.y;
int wpix =wx + wy*woi.width;
if (valid_pixels[wpix]) {
has_veg_thread[nthread][nscene][wpix] = true;
has_valid_dependent = true;
}
}
}
}
}
if (has_valid_dependent) {
veg_scene_used_prefilter[indx] = true;
}
}
/*
int px05 = (int) Math.floor(x + dx); // TODO: check sign! // ELEV-SIGN int px05 = (int) Math.floor(x + dx); // TODO: check sign! // ELEV-SIGN
int py05 = (int) Math.floor(y + dy); // TODO: check sign! // ELEV-SIGN int py05 = (int) Math.floor(y + dy); // TODO: check sign! // ELEV-SIGN
if (woi_plus1.contains(px05,py05)) { // up to 1 pixel to the nearest if (woi_plus1.contains(px05,py05)) { // up to 1 pixel to the nearest
...@@ -5291,6 +5328,7 @@ public class VegetationLMA { ...@@ -5291,6 +5328,7 @@ public class VegetationLMA {
veg_scene_used_prefilter[indx] = true; veg_scene_used_prefilter[indx] = true;
} }
} }
*/
} }
} }
} }
...@@ -5338,6 +5376,9 @@ public class VegetationLMA { ...@@ -5338,6 +5376,9 @@ public class VegetationLMA {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
public void run() { public void run() {
for (int wPix = ai.getAndIncrement(); wPix < woi_length; wPix = ai.getAndIncrement()) { // if (valid_pixels[wPix]){ for (int wPix = ai.getAndIncrement(); wPix < woi_length; wPix = ai.getAndIncrement()) { // if (valid_pixels[wPix]){
if (wPix == dbg_pix) {
System.out.println ("getValidScenesPixels() 1 : wpix = "+wPix);
}
boolean has_offset_middle = true; boolean has_offset_middle = true;
for (int nscene = first_scene + max_sacrifice; nscene <= last_scene-max_sacrifice; nscene++) if (valid_scenes[nscene]){ for (int nscene = first_scene + max_sacrifice; nscene <= last_scene-max_sacrifice; nscene++) if (valid_scenes[nscene]){
if (!has_veg[nscene][wPix]) { if (!has_veg[nscene][wPix]) {
......
...@@ -401,14 +401,15 @@ public class VegetationModel { ...@@ -401,14 +401,15 @@ public class VegetationModel {
double min_above = 0.02; // 0.025; // .04; double min_above = 0.02; // 0.025; // .04;
int patch_neib = 4; // 5; int patch_neib = 4; // 5;
double neibs_pow = 0.5; double neibs_pow = 0.5;
final int grow_vegetation = clt_parameters.imp.terr_veget_grow;
double [][] combo_dsn =quadCLTs[ref_index].restoreComboDSI(true); double [][] combo_dsn =quadCLTs[ref_index].restoreComboDSI(true);
double [][] terr_veg = getTerrainVegetation( double [][] terr_veg = getTerrainVegetation(
combo_dsn, // double [][] combo_dsn); combo_dsn, // double [][] combo_dsn);
tilesX, // final int tilesX, tilesX, // final int tilesX,
min_above, // final double min_above, // absolute disparity difference min_above, // final double min_above, // absolute disparity difference
patch_neib, // final int patch_neib){ patch_neib, // final int patch_neib){
neibs_pow); // final double neibs_pow); neibs_pow, // final double neibs_pow);
grow_vegetation); // final int grow_vegetation);
if (show_debug) { if (show_debug) {
String [] titles_terr_veg = {"terrain","vegetation"}; String [] titles_terr_veg = {"terrain","vegetation"};
...@@ -725,7 +726,8 @@ public class VegetationModel { ...@@ -725,7 +726,8 @@ public class VegetationModel {
final int tilesX, final int tilesX,
final double min_above, // absolute disparity difference final double min_above, // absolute disparity difference
final int patch_neibs, final int patch_neibs,
final double neibs_pow){ // raise strength to this power when averaging neighbors final double neibs_pow, // raise strength to this power when averaging neighbors
final int grow_vegetation){
final double [] terrain = combo_dsn[OpticalFlow.COMBO_DSN_INDX_TERRAIN]; final double [] terrain = combo_dsn[OpticalFlow.COMBO_DSN_INDX_TERRAIN];
final double [] ground = combo_dsn[OpticalFlow.COMBO_DSN_INDX_GROUND]; final double [] ground = combo_dsn[OpticalFlow.COMBO_DSN_INDX_GROUND];
final double [] disparity = combo_dsn[OpticalFlow.COMBO_DSN_INDX_LMA]; final double [] disparity = combo_dsn[OpticalFlow.COMBO_DSN_INDX_LMA];
...@@ -733,7 +735,7 @@ public class VegetationModel { ...@@ -733,7 +735,7 @@ public class VegetationModel {
final int num_pixels = disparity.length; final int num_pixels = disparity.length;
final double [] vegetation = new double [num_pixels]; final double [] vegetation = new double [num_pixels];
Arrays.fill(vegetation, Double.NaN); Arrays.fill(vegetation, Double.NaN);
final int dbg_tile = -(22+17*80); final int dbg_tile = (25+20*80);
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX); final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
...@@ -771,7 +773,20 @@ public class VegetationModel { ...@@ -771,7 +773,20 @@ public class VegetationModel {
}; };
} }
ImageDtt.startAndJoin(threads); ImageDtt.startAndJoin(threads);
return new double [][] {terrain,vegetation}; double [] veget=vegetation;
if (grow_vegetation > 0) {
veget= TileProcessor.fillNaNs(
vegetation, // final double [] data,
null, // final boolean [] prohibit,
tilesX, // int width,
// CAREFUL ! Remaining NaN is grown by unsharp mask filter ************* !
grow_vegetation, // 100, // 2*width, // 16, // final int grow,
0.7, // double diagonal_weight, // relative to ortho
100, // int num_passes,
0.03); // final double max_rchange, // = 0.01 - does not need to be accurate
}
return new double [][] {terrain,veget}; // ation};
} }
...@@ -819,14 +834,15 @@ public class VegetationModel { ...@@ -819,14 +834,15 @@ public class VegetationModel {
double min_above = 0.02; // 0.025; // .04; double min_above = 0.02; // 0.025; // .04;
int patch_neib = 4; // 5; int patch_neib = 4; // 5;
double neibs_pow = 0.5; double neibs_pow = 0.5;
final int grow_vegetation = clt_parameters.imp.terr_veget_grow;
double [][] combo_dsn =quadCLTs[ref_index].restoreComboDSI(true); double [][] combo_dsn =quadCLTs[ref_index].restoreComboDSI(true);
double [][] terr_veg = getTerrainVegetation( double [][] terr_veg = getTerrainVegetation(
combo_dsn, // double [][] combo_dsn); combo_dsn, // double [][] combo_dsn);
tilesX, // final int tilesX, tilesX, // final int tilesX,
min_above, // final double min_above, // absolute disparity difference min_above, // final double min_above, // absolute disparity difference
patch_neib, // final int patch_neib){ patch_neib, // final int patch_neib){
neibs_pow); // final double neibs_pow); neibs_pow, // final double neibs_pow);
grow_vegetation); // final int grow_vegetation);
String [] titles_terr_veg = {"terrain","vegetation"}; String [] titles_terr_veg = {"terrain","vegetation"};
ShowDoubleFloatArrays.showArrays( ShowDoubleFloatArrays.showArrays(
...@@ -2089,7 +2105,7 @@ public class VegetationModel { ...@@ -2089,7 +2105,7 @@ public class VegetationModel {
lambda_scale_bad, // double lambda_scale_bad, // 8.0 lambda_scale_bad, // double lambda_scale_bad, // 8.0
lambda_max, // double lambda_max, // 100 lambda_max, // double lambda_max, // 100
rms_diff, // double rms_diff, // 0.001 rms_diff, // double rms_diff, // 0.001
15, // num_iter, //int num_iter, // 20 num_iter, // 15, // num_iter, //int num_iter, // 20
last_run, // boolean last_run, last_run, // boolean last_run,
null, // String dbg_prefix, null, // String dbg_prefix,
debugLevel); // int debug_level) debugLevel); // int debug_level)
......
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