Commit f7907c7d authored by Andrey Filippov's avatar Andrey Filippov

Working on the image sequences captured from the UAS

parent 23dab5f8
...@@ -3573,7 +3573,7 @@ public class GpuQuad{ // quad camera description ...@@ -3573,7 +3573,7 @@ public class GpuQuad{ // quad camera description
* @param threadsMax Maximal number of threads to run concurrently. * @param threadsMax Maximal number of threads to run concurrently.
* @return Array of TpTask instances (fully prepared) to be fed to the GPU * @return Array of TpTask instances (fully prepared) to be fed to the GPU
*/ */
public TpTask[] setInterTasks( public TpTask[] setInterTasks( // not used 2023.08.04
final boolean calcPortsCoordinatesAndDerivatives, // GPU can calculate them centreXY final boolean calcPortsCoordinatesAndDerivatives, // GPU can calculate them centreXY
final double [][] pXpYD, // per-tile array of pX,pY,disparity triplets (or nulls) final double [][] pXpYD, // per-tile array of pX,pY,disparity triplets (or nulls)
final boolean [] selection, // may be null, if not null do not process unselected tiles final boolean [] selection, // may be null, if not null do not process unselected tiles
......
...@@ -33,7 +33,8 @@ public class EventLogger { ...@@ -33,7 +33,8 @@ public class EventLogger {
} }
Arrays.sort(logger_files); // increasing start time stamps Arrays.sort(logger_files); // increasing start time stamps
String out_did_gps_path = "/home/elphel/lwir16-proc/office_04/did_gps"; // String out_did_gps_path = "/home/elphel/lwir16-proc/office_04/did_gps";
String out_did_gps_path = dir+"../did_gps";
int gps_mask = 7; // +1 - DID_GPS1_POS, +2 - DID_GPS2_POS, +4 - DID_GPS1_UBX_POS int gps_mask = 7; // +1 - DID_GPS1_POS, +2 - DID_GPS2_POS, +4 - DID_GPS1_UBX_POS
for (int nf = 0; nf < logger_files.length; nf++) { for (int nf = 0; nf < logger_files.length; nf++) {
System.out.println("Printing all DID_INS_1 data in "+logger_files[nf].abs_path); System.out.println("Printing all DID_INS_1 data in "+logger_files[nf].abs_path);
......
...@@ -325,6 +325,10 @@ public class ErsCorrection extends GeometryCorrection { ...@@ -325,6 +325,10 @@ public class ErsCorrection extends GeometryCorrection {
properties.setProperty(prefix+SCENES_PREFIX+"_"+k+"_dt", s_scenes[1]); properties.setProperty(prefix+SCENES_PREFIX+"_"+k+"_dt", s_scenes[1]);
properties.setProperty(prefix+SCENES_PREFIX+"_"+k+"_d2t", s_scenes[2]); properties.setProperty(prefix+SCENES_PREFIX+"_"+k+"_d2t", s_scenes[2]);
// properties.setProperty(prefix+SCENES_PREFIX+"_"+k, getScene(k).toString()); // properties.setProperty(prefix+SCENES_PREFIX+"_"+k, getScene(k).toString());
} else { // so it is important to scenes_poses.put(timestamp, null), not scenes_poses.remove(ts)
properties.remove(prefix+SCENES_PREFIX+"_"+k);
properties.remove(prefix+SCENES_PREFIX+"_"+k+"_dt");
properties.remove(prefix+SCENES_PREFIX+"_"+k+"_d2t");
} }
} }
} }
...@@ -408,6 +412,12 @@ public class ErsCorrection extends GeometryCorrection { ...@@ -408,6 +412,12 @@ public class ErsCorrection extends GeometryCorrection {
return scenes_poses.get(timestamp); return scenes_poses.get(timestamp);
} }
public double[][] getSceneXYZATR(String timestamp) {
XyzAtr scene = scenes_poses.get(timestamp);
if (scene == null) return null;
return scene.getXYZATR();
}
public double[] getSceneXYZ(String timestamp) { public double[] getSceneXYZ(String timestamp) {
XyzAtr scene = scenes_poses.get(timestamp); XyzAtr scene = scenes_poses.get(timestamp);
if (scene == null) return null; if (scene == null) return null;
...@@ -2103,6 +2113,17 @@ public class ErsCorrection extends GeometryCorrection { ...@@ -2103,6 +2113,17 @@ public class ErsCorrection extends GeometryCorrection {
scene_xyz, // double [] camera_xyz, // camera center in world coordinates scene_xyz, // double [] camera_xyz, // camera center in world coordinates
scene_rot_matrix, // Matrix rot_matrix, // 1-st of 4 matricesArray of 4 matrices - scene_rot_matrix, // Matrix rot_matrix, // 1-st of 4 matricesArray of 4 matrices -
LINE_ERR); // double line_err) // threshold error in scan lines (1.0) LINE_ERR); // double line_err) // threshold error in scan lines (1.0)
if (pXpYD_scene == null) {
System.out.println("getDPxSceneDParameters(): pXpYD_scene==null. Object too close to the lens?"); // not here
return null;
}
if (Double.isNaN(pXpYD_scene[2])) {
System.out.println("getDPxSceneDParameters(): pXpYD_scene[2]==NaN.");
System.out.println("xyz4=["+xyz4[0]+","+xyz4[1]+","+xyz4[2]+","+xyz4[3]+"]");
System.out.println("scene_xyz=["+scene_xyz[0]+","+scene_xyz[1]+","+scene_xyz[2]+"]");
System.out.println("pXpYD_reference=["+pXpYD_reference[0]+","+pXpYD_reference[1]+","+pXpYD_reference[2]+"]");
return null;
}
Vector3D[] scene_vectors = ers_scene.getDWorldDPixels( // [0] X,Y,Z, other ones [DW_D* + 1] Vector3D[] scene_vectors = ers_scene.getDWorldDPixels( // [0] X,Y,Z, other ones [DW_D* + 1]
correctDistortions, correctDistortions,
...@@ -2111,8 +2132,12 @@ public class ErsCorrection extends GeometryCorrection { ...@@ -2111,8 +2132,12 @@ public class ErsCorrection extends GeometryCorrection {
scene_xyz, scene_xyz,
scene_matrices_inverse, scene_matrices_inverse,
debug_level); debug_level);
if (scene_vectors == null) {
System.out.println("getDPxSceneDParameters(): scene_vectors==null. Why?");
return null;
}
Matrix dx_dpscene = new Matrix(new double[][] { Matrix dx_dpscene = new Matrix(new double[][] {
scene_vectors[DW_DPX + 1].toArray(), scene_vectors[DW_DPX + 1].toArray(), // null pointer?
scene_vectors[DW_DPY + 1].toArray(), scene_vectors[DW_DPY + 1].toArray(),
scene_vectors[DW_DD + 1].toArray()}).transpose(); scene_vectors[DW_DD + 1].toArray()}).transpose();
// next variables are {x,y,z} * disparity // next variables are {x,y,z} * disparity
...@@ -2153,8 +2178,10 @@ public class ErsCorrection extends GeometryCorrection { ...@@ -2153,8 +2178,10 @@ public class ErsCorrection extends GeometryCorrection {
dpscene_dxyz = dx_dpscene.inverse(); dpscene_dxyz = dx_dpscene.inverse();
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
System.out.println("dx_dpscene is singular"); if (debug_level > -1) {
System.out.println("dx_dpscene is singular, debug_level="+debug_level+"> -1");
e.printStackTrace(); e.printStackTrace();
}
return null; return null;
} }
Matrix dpscene_dxyz_minus = dpscene_dxyz.times(-1.0); // negated to calculate /d{pX,pY,D) for the scene parameters Matrix dpscene_dxyz_minus = dpscene_dxyz.times(-1.0); // negated to calculate /d{pX,pY,D) for the scene parameters
......
...@@ -1326,6 +1326,8 @@ public class ImageDtt extends ImageDttCPU { ...@@ -1326,6 +1326,8 @@ public class ImageDtt extends ImageDttCPU {
public double [][][] clt_process_tl_interscene( // convert to pixel domain and process correlations already prepared in fcorr_td and/or fcorr_combo_td public double [][][] clt_process_tl_interscene( // convert to pixel domain and process correlations already prepared in fcorr_td and/or fcorr_combo_td
final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
// only used here to keep extra array element for disparity difference
boolean use3D, // generate disparity difference
final float [][][][] fcorr_td, // [tilesY][tilesX][pair][4*64] transform domain representation of all selected corr pairs final float [][][][] fcorr_td, // [tilesY][tilesX][pair][4*64] transform domain representation of all selected corr pairs
float [][][] num_acc, // number of accumulated tiles [tilesY][tilesX][pair] (or null). Can be inner null if not used in tp_tasks float [][][] num_acc, // number of accumulated tiles [tilesY][tilesX][pair] (or null). Can be inner null if not used in tp_tasks
double [] dcorr_weight, // alternative to num_acc, compatible with CPU processing (only one non-zero enough) double [] dcorr_weight, // alternative to num_acc, compatible with CPU processing (only one non-zero enough)
...@@ -1601,9 +1603,10 @@ public class ImageDtt extends ImageDttCPU { ...@@ -1601,9 +1603,10 @@ public class ImageDtt extends ImageDttCPU {
} }
} }
if ((mv_td != null) || (mv_pd != null)) { if ((mv_td != null) || (mv_pd != null)) {
double [] mv = new double[3]; double [] mv = new double[3 + (use3D? 2 :0)]; // keep for disparity/strength
if (mv_pd != null) { if (mv_pd != null) {
mv = mv_pd; /// mv = mv_pd;
System.arraycopy(mv_pd, 0, mv, 0, 3); // keep [3] for optional disparities
// mv[2] *= pd_weight; // mv[2] *= pd_weight;
if ((mv_td != null) && !td_nopd_only) { // mix if ((mv_td != null) && !td_nopd_only) { // mix
mv[0] = (mv[0] * pd_weight + mv_td[0] * td_weight)/ (pd_weight + td_weight); mv[0] = (mv[0] * pd_weight + mv_td[0] * td_weight)/ (pd_weight + td_weight);
...@@ -1612,7 +1615,8 @@ public class ImageDtt extends ImageDttCPU { ...@@ -1612,7 +1615,8 @@ public class ImageDtt extends ImageDttCPU {
mv[2] = (mv[2] * pd_weight + mv_td[2] * td_weight)/ (pd_weight + td_weight); mv[2] = (mv[2] * pd_weight + mv_td[2] * td_weight)/ (pd_weight + td_weight);
} // mix } // mix
} else { // (mv_pd == null) && (mv_td != null) below } else { // (mv_pd == null) && (mv_td != null) below
mv = mv_td; /// mv = mv_td;
System.arraycopy(mv_td, 0, mv, 0, 3); // keep [3] for optional disparities
//mv[2] *= td_weight; //mv[2] *= td_weight;
} }
if (mv != null) { if (mv != null) {
......
...@@ -15,13 +15,11 @@ import javax.xml.bind.DatatypeConverter; ...@@ -15,13 +15,11 @@ import javax.xml.bind.DatatypeConverter;
import Jama.Matrix; import Jama.Matrix;
public class IntersceneLma { public class IntersceneLma {
// OpticalFlow opticalFlow = null;
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.
private double [] last_rms = null; // {rms, rms_pure}, matching this.vector private double [] last_rms = null; // {rms, rms_pure}, matching this.vector
private double [] good_or_bad_rms = null; // just for diagnostics, to read last (failed) rms private double [] good_or_bad_rms = null; // just for diagnostics, to read last (failed) rms
private double [] initial_rms = null; // {rms, rms_pure}, first-calcualted rms private double [] initial_rms = null; // {rms, rms_pure}, first-calcualted rms
private double [] y_vector = null; // sum of fx(initial parameters) and correlation offsets private double [] y_vector = null; // sum of fx(initial parameters) and correlation offsets
// private double [][] vector_XYS = null; // optical flow X,Y, confidence obtained from the correlate2DIterate()
private double [] last_ymfx = null; private double [] last_ymfx = null;
private double [][] last_jt = null; private double [][] last_jt = null;
private double [] weights; // normalized so sum is 1.0 for all - samples and extra regularization private double [] weights; // normalized so sum is 1.0 for all - samples and extra regularization
...@@ -31,19 +29,25 @@ public class IntersceneLma { ...@@ -31,19 +29,25 @@ public class IntersceneLma {
private double [] parameters_full = null; // full parameters vector for the currenl LMA run private double [] parameters_full = null; // full parameters vector for the currenl LMA run
private double [] backup_parameters_full = null; // full parameters vector before first LMA run private double [] backup_parameters_full = null; // full parameters vector before first LMA run
private double [] parameters_vector = null; private double [] parameters_vector = null;
// private double [] parameters_initial = null; // (will be used to pull for regularization) private double [] parameters_pull = null; // for regularization - error is proportional to difference between
// current vector and parameters_pull
private double [][] macrotile_centers = null; // (will be used to pull for regularization) private double [][] macrotile_centers = null; // (will be used to pull for regularization)
private double infinity_disparity = 0.1; // treat lower as infinity private double infinity_disparity = 0.1; // treat lower as infinity
private int num_samples = 0; private int num_samples = 0;
private boolean thread_invariant = true; // Do not use DoubleAdder, provide results not dependent on threads private boolean thread_invariant = true; // Do not use DoubleAdder, provide results not dependent on threads
private int num_components = 2; // 2 for 2D matching only,3 - include disparity
private double disparity_weight = 1.0; // relative weight of disparity errors
public IntersceneLma( public IntersceneLma(
// OpticalFlow opticalFlow, boolean thread_invariant,
boolean thread_invariant double disparity_weight
) { ) {
this.thread_invariant = thread_invariant; this.thread_invariant = thread_invariant;
// this.opticalFlow = opticalFlow; this.num_components = (disparity_weight > 0) ? 3 : 2;
} }
public int getNumComponents() {
return num_components;
}
public double [][] getLastJT(){ public double [][] getLastJT(){
return last_jt; return last_jt;
} }
...@@ -105,7 +109,8 @@ public class IntersceneLma { ...@@ -105,7 +109,8 @@ public class IntersceneLma {
boolean adj = false; boolean adj = false;
for (int i = 0; i <3; i++) adj |= par_mask[n+i]; for (int i = 0; i <3; i++) adj |= par_mask[n+i];
if (allvectors || adj) { if (allvectors || adj) {
String line = printNameV3(n, false, w,d)+" (was "+printNameV3(n, true, w,d)+")"; String line = printNameV3(n, false, w,d)+" (" + getCompareType()+
" "+printNameV3(n, true, w,d)+")";
line += ", diff_last="+String.format(fmt1, getV3Diff(n)[0]); line += ", diff_last="+String.format(fmt1, getV3Diff(n)[0]);
line += ", diff_first="+String.format(fmt1, getV3Diff(n)[1]); line += ", diff_first="+String.format(fmt1, getV3Diff(n)[1]);
lines.add(line); lines.add(line);
...@@ -135,8 +140,15 @@ public class IntersceneLma { ...@@ -135,8 +140,15 @@ public class IntersceneLma {
return new double [] {Math.sqrt(l2_start), Math.sqrt(l2_backup)}; return new double [] {Math.sqrt(l2_start), Math.sqrt(l2_backup)};
} }
public String getCompareType() {
return (parameters_pull != null)? "pull": "was";
}
public String printNameV3(int indx, boolean initial, int w, int d) { public String printNameV3(int indx, boolean initial, int w, int d) {
double [] full_vector = initial? backup_parameters_full: getFullVector(parameters_vector); boolean use_pull = parameters_pull != null;
double [] full_vector = initial?
(use_pull? getFullVector(parameters_pull) : backup_parameters_full):
getFullVector(parameters_vector);
double [] vector = new double[3]; double [] vector = new double[3];
for (int i = 0; i <3; i++) { for (int i = 0; i <3; i++) {
vector[i] = full_vector[indx + i]; vector[i] = full_vector[indx + i];
...@@ -166,20 +178,25 @@ public class IntersceneLma { ...@@ -166,20 +178,25 @@ public class IntersceneLma {
public void prepareLMA( public void prepareLMA(
final double [] scene_xyz0, // camera center in world coordinates (or null to use instance) final double [] scene_xyz0, // camera center in world coordinates (or null to use instance)
final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance) final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance)
final double [] scene_xyz_pull, // if both are not null, specify target values to pull to
final double [] scene_atr_pull, //
// reference atr, xyz are considered 0.0 // reference atr, xyz are considered 0.0
final QuadCLT scene_QuadClt, final QuadCLT scene_QuadClt,
final QuadCLT reference_QuadClt, final QuadCLT reference_QuadClt,
final boolean[] param_select, final boolean[] param_select,
final double [] param_regweights, final double [] param_regweights,
final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate() // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate()
// 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 double [][] centers, // macrotile centers (in pixels and average disparities
boolean first_run, boolean first_run,
final int debug_level) final int debug_level)
{ {
scenesCLT = new QuadCLT [] {reference_QuadClt, scene_QuadClt}; scenesCLT = new QuadCLT [] {reference_QuadClt, scene_QuadClt};
par_mask = param_select; par_mask = param_select;
macrotile_centers = centers; macrotile_centers = centers;
num_samples = 2 * centers.length; num_samples = num_components * centers.length;
ErsCorrection ers_ref = reference_QuadClt.getErsCorrection(); ErsCorrection ers_ref = reference_QuadClt.getErsCorrection();
ErsCorrection ers_scene = scene_QuadClt.getErsCorrection(); ErsCorrection ers_scene = scene_QuadClt.getErsCorrection();
final double [] scene_xyz = (scene_xyz0 != null) ? scene_xyz0 : ers_scene.camera_xyz; final double [] scene_xyz = (scene_xyz0 != null) ? scene_xyz0 : ers_scene.camera_xyz;
...@@ -197,19 +214,36 @@ public class IntersceneLma { ...@@ -197,19 +214,36 @@ public class IntersceneLma {
scene_atr[0], scene_atr[1], scene_atr[2], scene_atr[0], scene_atr[1], scene_atr[2],
scene_xyz[0], scene_xyz[1], scene_xyz[2]}; scene_xyz[0], scene_xyz[1], scene_xyz[2]};
parameters_full = full_parameters_vector.clone(); parameters_full = full_parameters_vector.clone();
if ((vector_XYS != null) && (first_run || (backup_parameters_full == null))) { if ((vector_XYSDS != null) && (first_run || (backup_parameters_full == null))) {
backup_parameters_full = full_parameters_vector.clone(); backup_parameters_full = full_parameters_vector.clone();
} }
int num_pars = 0; int num_pars = 0;
for (int i = 0; i < par_mask.length; i++) if (par_mask[i]) num_pars++; for (int i = 0; i < par_mask.length; i++) if (par_mask[i]) num_pars++;
par_indices = new int [num_pars]; par_indices = new int [num_pars];
num_pars = 0; num_pars = 0;
for (int i = 0; i < par_mask.length; i++) if (par_mask[i]) par_indices[num_pars++] = i; for (int i = 0; i < par_mask.length; i++) {
if (par_mask[i]) par_indices[num_pars++] = i;
}
parameters_vector = new double [par_indices.length]; parameters_vector = new double [par_indices.length];
for (int i = 0; i < par_indices.length; i++) parameters_vector[i] = full_parameters_vector[par_indices[i]]; for (int i = 0; i < par_indices.length; i++) {
parameters_vector[i] = full_parameters_vector[par_indices[i]];
}
if (vector_XYS != null) {// skip when used for the motion blur vectors, not LMA if ((scene_xyz_pull != null) && (scene_atr_pull != null)) {
setSamplesWeights(vector_XYS); // not regularized yet ! double [] parameters_pull_full = parameters_full.clone();
for (int i = 0; i < 3; i++) {
parameters_pull_full[ErsCorrection.DP_DSX + i] = scene_xyz_pull[i];
parameters_pull_full[ErsCorrection.DP_DSAZ + i] = scene_atr_pull[i];
// parameters_pull =
}
parameters_pull = new double [par_indices.length];
for (int i = 0; i < par_indices.length; i++) {
parameters_pull[i] = parameters_pull_full[par_indices[i]];
}
}
if (vector_XYSDS != null) {// skip when used for the motion blur vectors, not LMA
setSamplesWeights(vector_XYSDS); // not regularized yet ! // 3d updated
} else { } else {
weights = null; // new double[2 * centers.length]; weights = null; // new double[2 * centers.length];
} }
...@@ -224,7 +258,7 @@ public class IntersceneLma { ...@@ -224,7 +258,7 @@ public class IntersceneLma {
scenesCLT[1], // final QuadCLT scene_QuadClt, scenesCLT[1], // final QuadCLT scene_QuadClt,
scenesCLT[0], // final QuadCLT reference_QuadClt, scenesCLT[0], // final QuadCLT reference_QuadClt,
debug_level); // final int debug_level) debug_level); // final int debug_level)
if (vector_XYS == null) { if (vector_XYSDS == null) {
return; // for MB vectors (noLMA) return; // for MB vectors (noLMA)
} }
...@@ -233,8 +267,12 @@ public class IntersceneLma { ...@@ -233,8 +267,12 @@ public class IntersceneLma {
last_jt); // final double [][] jt) all 0??? last_jt); // final double [][] jt) all 0???
for (int i = 0; i < parameters_vector.length; i++) { for (int i = 0; i < parameters_vector.length; i++) {
int indx = num_samples + i; int indx = num_samples + i;
if (wjtj[i][i] == 0) { // why is it zero (leading to NaN)
weights[indx] = 0;
} else {
weights[indx] = param_regweights[par_indices[i]]/Math.sqrt(wjtj[i][i]); weights[indx] = param_regweights[par_indices[i]]/Math.sqrt(wjtj[i][i]);
} }
}
normalizeWeights(); // make full weight == 1.0; pure_weight <= 1.0; normalizeWeights(); // make full weight == 1.0; pure_weight <= 1.0;
// remeasure fx - now with regularization terms. // remeasure fx - now with regularization terms.
...@@ -248,15 +286,18 @@ public class IntersceneLma { ...@@ -248,15 +286,18 @@ public class IntersceneLma {
reference_QuadClt, // final QuadCLT reference_QuadClt, reference_QuadClt, // final QuadCLT reference_QuadClt,
debug_level); // final int debug_level) debug_level); // final int debug_level)
y_vector = fx.clone(); y_vector = fx.clone();
for (int i = 0; i < vector_XYS.length; i++) { for (int i = 0; i < vector_XYSDS.length; i++) {
if (vector_XYS[i] != null){ if (vector_XYSDS[i] != null){
y_vector[2 * i + 0] += vector_XYS[i][0]; y_vector[num_components * i + 0] += vector_XYSDS[i][0];
y_vector[2 * i + 1] += vector_XYS[i][1]; y_vector[num_components * i + 1] += vector_XYSDS[i][1];
if (num_components > 2) {
y_vector[num_components * i + 2] += vector_XYSDS[i][2];
}
} }
} }
last_rms = new double [2]; last_rms = new double [2];
last_ymfx = getYminusFxWeighted( last_ymfx = getYminusFxWeighted(
// vector_XYS, // final double [][] vector_XYS,
fx, // final double [] fx, fx, // final double [] fx,
last_rms); // final double [] rms_fp // null or [2] last_rms); // final double [] rms_fp // null or [2]
initial_rms = last_rms.clone(); initial_rms = last_rms.clone();
...@@ -369,7 +410,6 @@ public class IntersceneLma { ...@@ -369,7 +410,6 @@ public class IntersceneLma {
scenesCLT[0], // final QuadCLT reference_QuadClt, scenesCLT[0], // final QuadCLT reference_QuadClt,
debug_level); // final int debug_level) debug_level); // final int debug_level)
last_ymfx = getYminusFxWeighted( last_ymfx = getYminusFxWeighted(
// vector_XYS, // final double [][] vector_XYS,
fx, // final double [] fx, fx, // final double [] fx,
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();
...@@ -524,7 +564,6 @@ public class IntersceneLma { ...@@ -524,7 +564,6 @@ public class IntersceneLma {
scenesCLT[0], // final QuadCLT reference_QuadClt, scenesCLT[0], // final QuadCLT reference_QuadClt,
debug_level); // final int debug_level) debug_level); // final int debug_level)
last_ymfx = getYminusFxWeighted( last_ymfx = getYminusFxWeighted(
// vector_XYS, // final double [][] vector_XYS,
fx, // final double [] fx, fx, // final double [] fx,
this.last_rms); // final double [] rms_fp // null or [2] this.last_rms); // final double [] rms_fp // null or [2]
if (last_ymfx == null) { if (last_ymfx == null) {
...@@ -545,23 +584,37 @@ public class IntersceneLma { ...@@ -545,23 +584,37 @@ public class IntersceneLma {
private void setSamplesWeights( private void setSamplesWeights(
final double [][] vector_XYS) // not regularizedn yet final double [][] vector_XYSDS) // not regularized yet
{ {
//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];
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);
double sum_weights; double sum_weights;
if (thread_invariant) { if (thread_invariant) {
final double [] sw_arr = new double [vector_XYS.length]; final int num_types = (num_components > 2) ? 2 : 1;
final double [] sw_arr = new double [num_types * vector_XYSDS.length];
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
public void run() { public void run() {
for (int iMTile = ai.getAndIncrement(); iMTile < vector_XYS.length; iMTile = ai.getAndIncrement()) if (vector_XYS[iMTile] != null){ for (int iMTile = ai.getAndIncrement(); iMTile < vector_XYSDS.length; iMTile = ai.getAndIncrement()) if (vector_XYSDS[iMTile] != null){
double w = vector_XYS[iMTile][2]; double w = vector_XYSDS[iMTile][2];
weights[2 * iMTile] = w; if (Double.isNaN(w)) {
// asum_weight.add(w); w = 0;
sw_arr[iMTile] = w; }
weights[num_components * iMTile] = w;
sw_arr[num_types * iMTile] = 2*w;
//disparity_weight
if (num_types > 1) {
w = vector_XYSDS[iMTile][4] * disparity_weight;
if (Double.isNaN(w) || Double.isNaN(vector_XYSDS[iMTile][3])) {
w = 0;
vector_XYSDS[iMTile][3] = 0.0;
}
weights[num_components * iMTile + 2] = w;
sw_arr[num_types * iMTile + 1] = w;
}
} }
} }
}; };
...@@ -576,10 +629,20 @@ public class IntersceneLma { ...@@ -576,10 +629,20 @@ public class IntersceneLma {
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
public void run() { public void run() {
for (int iMTile = ai.getAndIncrement(); iMTile < vector_XYS.length; iMTile = ai.getAndIncrement()) if (vector_XYS[iMTile] != null){ for (int iMTile = ai.getAndIncrement(); iMTile < vector_XYSDS.length; iMTile = ai.getAndIncrement()) if (vector_XYSDS[iMTile] != null){
double w = vector_XYS[iMTile][2]; double w = vector_XYSDS[iMTile][2];
weights[2 * iMTile] = w; if (Double.isNaN(w)) {
w = 0;
}
weights[num_components * iMTile] = w;
asum_weight.add(w); asum_weight.add(w);
w = vector_XYSDS[iMTile][4] * disparity_weight;
if (Double.isNaN(w) || Double.isNaN(vector_XYSDS[iMTile][3])) {
w = 0;
vector_XYSDS[iMTile][3] = 0.0;
}
weights[num_components * iMTile + 2] = w;
asum_weight.add(2*w);
} }
} }
}; };
...@@ -591,14 +654,15 @@ public class IntersceneLma { ...@@ -591,14 +654,15 @@ public class IntersceneLma {
System.out.println("!!!!!! setSamplesWeights(): sum_weights=="+sum_weights+" <= 1E-8"); System.out.println("!!!!!! setSamplesWeights(): sum_weights=="+sum_weights+" <= 1E-8");
} }
ai.set(0); ai.set(0);
// final double s = 0.5/asum_weight.sum(); // final double s = 0.5/sum_weights;
final double s = 0.5/sum_weights; final double s = 1.0/sum_weights; // already taken care of
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
public void run() { public void run() {
for (int iMTile = ai.getAndIncrement(); iMTile < vector_XYS.length; iMTile = ai.getAndIncrement()) if (vector_XYS[iMTile] != null){ for (int iMTile = ai.getAndIncrement(); iMTile < vector_XYSDS.length; iMTile = ai.getAndIncrement()) if (vector_XYSDS[iMTile] != null){
weights[2 * iMTile] *= s; weights[num_components * iMTile] *= s;
weights[2 * iMTile + 1] = weights[2 * iMTile]; weights[num_components * iMTile + 1] = weights[num_components * iMTile];
weights[num_components * iMTile + 2] *=s;
} }
} }
}; };
...@@ -607,49 +671,6 @@ public class IntersceneLma { ...@@ -607,49 +671,6 @@ public class IntersceneLma {
pure_weight = 1.0; pure_weight = 1.0;
} }
/*
@Deprecated
private void normalizeWeights_old()
{
//num_samples
final Thread[] threads = ImageDtt.newThreadArray(opticalFlow.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final DoubleAdder asum_weight = new DoubleAdder();
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int i = ai.getAndIncrement(); i < num_samples; i = ai.getAndIncrement()){
asum_weight.add(weights[i]);
}
}
};
}
ImageDtt.startAndJoin(threads);
final double s_pure = asum_weight.sum();
for (int i = 0; i < par_indices.length; i++) {
int indx = num_samples + i;
asum_weight.add(weights[indx]);
}
double full_weight = asum_weight.sum();
pure_weight = s_pure/full_weight;
final double s = 1.0/asum_weight.sum();
if (Double.isNaN(s)) {
System.out.println("normalizeWeights(): s == NaN : 1");
}
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int i = ai.getAndIncrement(); i < weights.length; i = ai.getAndIncrement()){
weights[i] *= s;
}
}
};
}
ImageDtt.startAndJoin(threads);
}
*/
private void normalizeWeights() private void normalizeWeights()
{ {
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX); final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
...@@ -658,11 +679,19 @@ public class IntersceneLma { ...@@ -658,11 +679,19 @@ public class IntersceneLma {
if (thread_invariant) { if (thread_invariant) {
sum_weight_pure = 00; sum_weight_pure = 00;
for (int i = 0; i < num_samples; i++) { for (int i = 0; i < num_samples; i++) {
if (Double.isNaN(weights[i])) {
System.out.println("normalizeWeights(): weights["+i+"] == NaN: 1");
weights[i] = 0;
}
sum_weight_pure += weights[i]; sum_weight_pure += weights[i];
} }
full_weight = sum_weight_pure; full_weight = sum_weight_pure;
for (int i = 0; i < par_indices.length; i++) { for (int i = 0; i < par_indices.length; i++) {
int indx = num_samples + i; int indx = num_samples + i;
if (Double.isNaN(weights[indx])) {
System.out.println("normalizeWeights(): weights["+indx+"] == NaN: 1.5, i="+i);
weights[indx] = 0;
}
full_weight += weights[indx]; full_weight += weights[indx];
} }
} else { } else {
...@@ -671,6 +700,10 @@ public class IntersceneLma { ...@@ -671,6 +700,10 @@ public class IntersceneLma {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
public void run() { public void run() {
for (int i = ai.getAndIncrement(); i < num_samples; i = ai.getAndIncrement()){ for (int i = ai.getAndIncrement(); i < num_samples; i = ai.getAndIncrement()){
if (Double.isNaN(weights[i])) {
System.out.println("normalizeWeights(): weights["+i+"== NaN: 2");
weights[i] = 0;
}
asum_weight.add(weights[i]); asum_weight.add(weights[i]);
} }
} }
...@@ -680,6 +713,10 @@ public class IntersceneLma { ...@@ -680,6 +713,10 @@ public class IntersceneLma {
sum_weight_pure = asum_weight.sum(); sum_weight_pure = asum_weight.sum();
for (int i = 0; i < par_indices.length; i++) { for (int i = 0; i < par_indices.length; i++) {
int indx = num_samples + i; int indx = num_samples + i;
if (Double.isNaN(weights[indx])) {
System.out.println("normalizeWeights(): weights["+indx+"] == NaN: 1.5, i="+i);
weights[indx] = 0;
}
asum_weight.add(weights[indx]); asum_weight.add(weights[indx]);
} }
full_weight = asum_weight.sum(); full_weight = asum_weight.sum();
...@@ -730,8 +767,8 @@ public class IntersceneLma { ...@@ -730,8 +767,8 @@ public class IntersceneLma {
final double [] scene_atr = new double[3]; final double [] scene_atr = new double[3];
final double [] reference_xyz = new double[3]; // will stay 0 final double [] reference_xyz = new double[3]; // will stay 0
final double [] reference_atr = new double[3]; // will stay 0 final double [] reference_atr = new double[3]; // will stay 0
final boolean mb_mode = (weights == null); 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; final int weights_length = mb_mode ? (2 * macrotile_centers.length) : weights.length; // OK to keep 2
final double [] fx = mb_mode ? null : (new double [weights_length]); // weights.length]; : weights.length : final double [] fx = mb_mode ? null : (new double [weights_length]); // weights.length]; : weights.length :
if (jt != null) { if (jt != null) {
for (int i = 0; i < jt.length; i++) { for (int i = 0; i < jt.length; i++) {
...@@ -787,14 +824,20 @@ public class IntersceneLma { ...@@ -787,14 +824,20 @@ public class IntersceneLma {
boolean bad_tile = false; boolean bad_tile = false;
if (!bad_tile) { if (!bad_tile) {
if (!mb_mode) { if (!mb_mode) {
fx[2 * iMTile + 0] = deriv_params[0][0]; // pX fx[num_components * iMTile + 0] = deriv_params[0][0]; // pX
fx[2 * iMTile + 1] = deriv_params[0][1]; // pY fx[num_components * iMTile + 1] = deriv_params[0][1]; // pY
if (num_components > 2) {
fx[num_components * iMTile + 2] = deriv_params[0][2]; // D
}
} }
if (jt != null) { if (jt != null) {
for (int i = 0; i < par_indices.length; i++) { for (int i = 0; i < par_indices.length; i++) {
int indx = par_indices[i] + 1; int indx = par_indices[i] + 1;
jt[i][2 * iMTile + 0] = deriv_params[indx][0]; // pX jt[i][num_components * iMTile + 0] = deriv_params[indx][0]; // pX
jt[i][2 * iMTile + 1] = deriv_params[indx][1]; // pY (disparity is not used) jt[i][num_components * iMTile + 1] = deriv_params[indx][1]; // pY (disparity is not used)
if (num_components > 2) {
jt[i][num_components * iMTile + 2] = deriv_params[indx][2]; // pY (disparity is used)
}
} }
} }
} }
...@@ -815,8 +858,13 @@ public class IntersceneLma { ...@@ -815,8 +858,13 @@ public class IntersceneLma {
} }
// pull to the initial parameter values // pull to the initial parameter values
for (int i = 0; i < par_indices.length; i++) { for (int i = 0; i < par_indices.length; i++) {
fx [i + 2 * macrotile_centers.length] = vector[i]; // - parameters_initial[i]; // scale will be combined with weights fx [i + num_components * macrotile_centers.length] = vector[i]; // - parameters_initial[i]; // scale will be combined with weights
jt[i][i + 2 * macrotile_centers.length] = 1.0; // scale will be combined with weights jt[i][i + num_components * macrotile_centers.length] = 1.0; // scale will be combined with weights
}
if (parameters_pull != null){
for (int i = 0; i < par_indices.length; i++) {
fx [i + num_components * macrotile_centers.length] -= parameters_pull[i]; // - parameters_initial[i]; // scale will be combined with weights
}
} }
if (debug_level > 3) { if (debug_level > 3) {
try { try {
...@@ -872,7 +920,6 @@ public class IntersceneLma { ...@@ -872,7 +920,6 @@ public class IntersceneLma {
} }
private double [] getYminusFxWeighted( private double [] getYminusFxWeighted(
// final double [][] vector_XYS,
final double [] fx, final double [] fx,
final double [] rms_fp // null or [2] final double [] rms_fp // null or [2]
) { ) {
...@@ -885,9 +932,13 @@ public class IntersceneLma { ...@@ -885,9 +932,13 @@ public class IntersceneLma {
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
public void run() { public void run() {
for (int i = ai.getAndIncrement(); i < num_samples; i = ai.getAndIncrement()) { for (int i = ai.getAndIncrement(); i < num_samples; i = ai.getAndIncrement()) if (weights[i] > 0) {
double d = y_vector[i] - fx[i]; double d = y_vector[i] - fx[i];
double wd = d * weights[i]; double wd = d * weights[i];
if (Double.isNaN(wd)) {
System.out.println("getYminusFxWeighted(): weights["+i+"]="+weights[i]+", wd="+wd+
", y_vector[i]="+y_vector[i]+", fx[i]="+fx[i]);
}
//double l2 = d * wd; //double l2 = d * wd;
l2_arr[i] = d * wd; l2_arr[i] = d * wd;
wymfw[i] = wd; wymfw[i] = wd;
...@@ -949,88 +1000,4 @@ public class IntersceneLma { ...@@ -949,88 +1000,4 @@ public class IntersceneLma {
baos.close(); baos.close();
} }
} }
/*
* par_indices
double [] rslt = {rms, rms_pure};
*
vector_XYS *
private double [] getFx(
GeometryCorrection.CorrVector corr_vector)
{
int clusters = clustersX * clustersY;
Matrix [] corr_rots = corr_vector.getRotMatrices(); // get array of per-sensor rotation matrices
Matrix [][] deriv_rots = corr_vector.getRotDeriveMatrices();
double [] imu = corr_vector.getIMU(); // i)
double [] y_minus_fx = new double [clusters * POINTS_SAMPLE];
for (int cluster = 0; cluster < clusters; cluster++) {
if (measured_dsxy[cluster] != null){
double [] ddnd = geometryCorrection.getPortsDDNDAndDerivativesNew( // USED in lwir
geometryCorrection, // GeometryCorrection gc_main,
use_rig_offsets, // boolean use_rig_offsets,
corr_rots, // Matrix [] rots,
deriv_rots, // Matrix [][] deriv_rots,
null, // double [][] DDNDderiv, // if not null, should be double[8][]
pY_offset[cluster], // double [] py_offset, // array of per-port average pY offset from the center (to correct ERS) or null (for no ERS)
imu, // double [] imu,
x0y0[cluster], // double [] pXYND0, // per-port non-distorted coordinates corresponding to the correlation measurements
world_xyz[cluster], // double [] xyz, // world XYZ for ERS correction
measured_dsxy[cluster][ExtrinsicAdjustment.INDX_PX + 0], // double px,
measured_dsxy[cluster][ExtrinsicAdjustment.INDX_PX + 1], // double py,
measured_dsxy[cluster][ExtrinsicAdjustment.INDX_TARGET]); // double disparity);
//arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
// System.arraycopy(src_pixels, 0, dst_pixels, 0, src_pixels.length); for the borders closer to 1/2 kernel size
ddnd[0] = ddnd[0]; // ?
for (int i = 0; i < NUM_SENSORS; i++) {
ddnd[i + 1] = ddnd[i + 1];
ddnd[i + 5] = ddnd[i + 5];
}
System.arraycopy(ddnd, 0, y_minus_fx, cluster*POINTS_SAMPLE, POINTS_SAMPLE);
}
}
return y_minus_fx;
}
private double [][] getJacobianTransposed(
GeometryCorrection.CorrVector corr_vector,
double delta){
int clusters = clustersX * clustersY;
int num_pars = getNumPars();
double [][] jt = new double [num_pars][clusters * POINTS_SAMPLE ];
double rdelta = 1.0/delta;
for (int par = 0; par < num_pars; par++) {
double [] pars = new double[num_pars];
pars[par] = delta;
GeometryCorrection.CorrVector corr_delta = geometryCorrection.getCorrVector(pars, par_mask);
GeometryCorrection.CorrVector corr_vectorp = corr_vector.clone();
GeometryCorrection.CorrVector corr_vectorm = corr_vector.clone();
corr_vectorp.incrementVector(corr_delta, 0.5);
corr_vectorm.incrementVector(corr_delta, -0.5);
double [] fx_p = getFx(corr_vectorp);
double [] fx_m = getFx(corr_vectorm);
for (int i = 0; i < fx_p.length; i++) {
jt[par][i] = (fx_p[i] - fx_m[i])*rdelta;
}
}
return jt;
}
private int [] setWeights( // number right, number left
double [][] measured_dsxy,
boolean [] force_disparity, // same dimension as dsdn, true if disparity should be controlled
boolean [] filtered_infinity, // tiles known to be infinity
double [] distance_from_edge,// to reduce weight of the mountain ridge, increase clouds (or null)
int min_num_forced, // if number of forced samples exceeds this, zero out weights of non-forced
boolean infinity_right_left, // each halve should have > min_num_forced, will calculate separate average
double weight_infinity, // total weight of infinity tiles fraction (0.0 - 1.0)
double weight_disparity, // disparity weight relative to the sum of 8 lazy eye values of the same tile
double weight_disparity_inf, // disparity weight relative to the sum of 8 lazy eye values of the same tile for infinity
double max_disparity_far, // reduce weights of near tiles proportional to sqrt(max_disparity_far/disparity)
double max_disparity_use) // do not process near objects to avoid ERS
{}
*/
} }
...@@ -29,6 +29,10 @@ import java.util.Properties; ...@@ -29,6 +29,10 @@ import java.util.Properties;
import com.elphel.imagej.common.GenericJTabbedDialog; import com.elphel.imagej.common.GenericJTabbedDialog;
public class IntersceneLmaParameters { public class IntersceneLmaParameters {
public boolean ilma_3d = false; // use disparity for interscene matching (as for UAS imagery)
public double ilma_disparity_weight = 2.0; // disparity component weight compared to dX and dY
public boolean ilma_3d_lma = false; // Use LMA for disparity in 3D pose matching mode
public boolean ilma_3d_tilt_only = true; // remove disparity average, use tilts only
public boolean ilma_thread_invariant = true; // Do not use DoubleAdder, provide results not dependent on threads public boolean ilma_thread_invariant = true; // Do not use DoubleAdder, provide results not dependent on threads
public boolean [] ilma_lma_select = new boolean [ErsCorrection.DP_NUM_PARS]; // first three will not be used public boolean [] ilma_lma_select = new boolean [ErsCorrection.DP_NUM_PARS]; // first three will not be used
public double [] ilma_regularization_weights = new double [ErsCorrection.DP_NUM_PARS]; // first three will not be used public double [] ilma_regularization_weights = new double [ErsCorrection.DP_NUM_PARS]; // first three will not be used
...@@ -107,6 +111,15 @@ public class IntersceneLmaParameters { ...@@ -107,6 +111,15 @@ public class IntersceneLmaParameters {
public void dialogQuestions(GenericJTabbedDialog gd) { public void dialogQuestions(GenericJTabbedDialog gd) {
gd.addMessage("Interframe LMA parameters selection"); gd.addMessage("Interframe LMA parameters selection");
gd.addCheckbox ("3D mode (use disparity)", this.ilma_3d,
"Use disparity for interscene matching (as for UAS imagery)" );
gd.addNumericField("Disp[arity weight", this.ilma_disparity_weight, 6,8,"",
"Disparity component weight compared to dX and dY");
gd.addCheckbox ("LMA in 3D mode", this.ilma_3d_lma,
"Use LMA disparity for interscene matching (as for UAS imagery)" );
gd.addCheckbox ("Remove average disparity, use tilts only", this.ilma_3d_tilt_only,
"Calculate disparity for tilts only." );
gd.addCheckbox ("Thread-invariant execution", this.ilma_thread_invariant, gd.addCheckbox ("Thread-invariant execution", this.ilma_thread_invariant,
"Do not use DoubleAdder and provide results not dependent on threads" ); "Do not use DoubleAdder and provide results not dependent on threads" );
for (int i = ErsCorrection.DP_DVAZ; i < ErsCorrection.DP_NUM_PARS; i++) { for (int i = ErsCorrection.DP_DVAZ; i < ErsCorrection.DP_NUM_PARS; i++) {
...@@ -163,6 +176,10 @@ public class IntersceneLmaParameters { ...@@ -163,6 +176,10 @@ public class IntersceneLmaParameters {
} }
public void dialogAnswers(GenericJTabbedDialog gd) { public void dialogAnswers(GenericJTabbedDialog gd) {
this.ilma_3d = gd.getNextBoolean();
this.ilma_disparity_weight = gd.getNextNumber();
this.ilma_3d_lma = gd.getNextBoolean();
this.ilma_3d_tilt_only = gd.getNextBoolean();
this.ilma_thread_invariant = gd.getNextBoolean(); this.ilma_thread_invariant = gd.getNextBoolean();
for (int i = ErsCorrection.DP_DVAZ; i < ErsCorrection.DP_NUM_PARS; i++) { for (int i = ErsCorrection.DP_DVAZ; i < ErsCorrection.DP_NUM_PARS; i++) {
this.ilma_lma_select[i] = gd.getNextBoolean(); this.ilma_lma_select[i] = gd.getNextBoolean();
...@@ -191,6 +208,10 @@ public class IntersceneLmaParameters { ...@@ -191,6 +208,10 @@ public class IntersceneLmaParameters {
} }
public void setProperties(String prefix,Properties properties){ public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"ilma_3d", this.ilma_3d+"");
properties.setProperty(prefix+"ilma_disparity_weight", this.ilma_disparity_weight+"");
properties.setProperty(prefix+"ilma_3d_lma", this.ilma_3d_lma+"");
properties.setProperty(prefix+"ilma_3d_tilt_only", this.ilma_3d_tilt_only+"");
properties.setProperty(prefix+"ilma_thread_invariant", this.ilma_thread_invariant+""); properties.setProperty(prefix+"ilma_thread_invariant", this.ilma_thread_invariant+"");
for (int i = ErsCorrection.DP_DVAZ; i < ErsCorrection.DP_NUM_PARS; i++) { for (int i = ErsCorrection.DP_DVAZ; i < ErsCorrection.DP_NUM_PARS; i++) {
properties.setProperty(prefix+ErsCorrection.DP_DERIV_NAMES[i]+"_sel", this.ilma_lma_select[i]+""); properties.setProperty(prefix+ErsCorrection.DP_DERIV_NAMES[i]+"_sel", this.ilma_lma_select[i]+"");
...@@ -216,6 +237,10 @@ public class IntersceneLmaParameters { ...@@ -216,6 +237,10 @@ public class IntersceneLmaParameters {
properties.setProperty(prefix+"ilma_debug_ers", this.ilma_debug_ers+""); properties.setProperty(prefix+"ilma_debug_ers", this.ilma_debug_ers+"");
} }
public void getProperties(String prefix,Properties properties){ public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"ilma_3d")!=null) this.ilma_3d=Boolean.parseBoolean(properties.getProperty(prefix+"ilma_3d"));
if (properties.getProperty(prefix+"ilma_disparity_weight")!=null) this.ilma_disparity_weight=Double.parseDouble(properties.getProperty(prefix+"ilma_disparity_weight"));
if (properties.getProperty(prefix+"ilma_3d_lma")!=null) this.ilma_3d_lma=Boolean.parseBoolean(properties.getProperty(prefix+"ilma_3d_lma"));
if (properties.getProperty(prefix+"ilma_3d_tilt_only")!=null) this.ilma_3d_tilt_only=Boolean.parseBoolean(properties.getProperty(prefix+"ilma_3d_tilt_only"));
if (properties.getProperty(prefix+"ilma_thread_invariant")!=null) this.ilma_thread_invariant=Boolean.parseBoolean(properties.getProperty(prefix+"ilma_thread_invariant")); if (properties.getProperty(prefix+"ilma_thread_invariant")!=null) this.ilma_thread_invariant=Boolean.parseBoolean(properties.getProperty(prefix+"ilma_thread_invariant"));
for (int i = ErsCorrection.DP_DVAZ; i < ErsCorrection.DP_NUM_PARS; i++) { for (int i = ErsCorrection.DP_DVAZ; i < ErsCorrection.DP_NUM_PARS; i++) {
String pn_sel = prefix+ErsCorrection.DP_DERIV_NAMES[i]+"_sel"; String pn_sel = prefix+ErsCorrection.DP_DERIV_NAMES[i]+"_sel";
...@@ -255,6 +280,10 @@ public class IntersceneLmaParameters { ...@@ -255,6 +280,10 @@ public class IntersceneLmaParameters {
@Override @Override
public IntersceneLmaParameters clone() throws CloneNotSupportedException { public IntersceneLmaParameters clone() throws CloneNotSupportedException {
IntersceneLmaParameters ilp = new IntersceneLmaParameters(); IntersceneLmaParameters ilp = new IntersceneLmaParameters();
ilp.ilma_3d = this.ilma_3d;
ilp.ilma_disparity_weight = this.ilma_disparity_weight;
ilp.ilma_3d_lma = this.ilma_3d_lma;
ilp.ilma_3d_tilt_only = this.ilma_3d_tilt_only;
ilp.ilma_thread_invariant = this.ilma_thread_invariant; ilp.ilma_thread_invariant = this.ilma_thread_invariant;
System.arraycopy(this.ilma_lma_select, 0, ilp.ilma_lma_select, 0, ilma_lma_select.length); System.arraycopy(this.ilma_lma_select, 0, ilp.ilma_lma_select, 0, ilma_lma_select.length);
System.arraycopy(this.ilma_regularization_weights, 0, ilp.ilma_regularization_weights, 0, ilma_regularization_weights.length); System.arraycopy(this.ilma_regularization_weights, 0, ilp.ilma_regularization_weights, 0, ilma_regularization_weights.length);
......
...@@ -67,7 +67,11 @@ public class IntersceneMatchParameters { ...@@ -67,7 +67,11 @@ public class IntersceneMatchParameters {
public boolean [] generate_stereo_var = new boolean[stereo_views.length]; public boolean [] generate_stereo_var = new boolean[stereo_views.length];
// Other parameters // Other parameters
public double scale_extrap_atr = 1.0; // scale angular extrapolation
public double scale_extrap_xyz = 0.0; // scale linear extrapolation (1.0 for drones)
public int avg_len = 1; // average pose over number of previous scenes
public int min_num_scenes = 10; // abandon series if there are less than this number of scenes in it public int min_num_scenes = 10; // abandon series if there are less than this number of scenes in it
public int max_num_scenes = 100; // abandon series if longer than
public double blur_egomotion = 2.0; public double blur_egomotion = 2.0;
...@@ -449,13 +453,23 @@ public class IntersceneMatchParameters { ...@@ -449,13 +453,23 @@ public class IntersceneMatchParameters {
"Display calculated depth map in meters"); "Display calculated depth map in meters");
gd.addMessage ("Additional parameters"); gd.addMessage ("Additional parameters");
gd.addCheckbox ("Color NaN background", this.show_color_nan, gd.addCheckbox ("Color NaN background", this.show_color_nan,
"Use NaN for undefined tiles (false - 0.0f). NaN produces sharp distinct result, 0.0f - blended"); "Use NaN for undefined tiles (false - 0.0f). NaN produces sharp distinct result, 0.0f - blended");
gd.addCheckbox ("Mono NaN background", this.show_mono_nan, gd.addCheckbox ("Mono NaN background", this.show_mono_nan,
"Use NaN for undefined tiles (false - 0.0f). NaN produces sharp distinct result, 0.0f - blended"); "Use NaN for undefined tiles (false - 0.0f). NaN produces sharp distinct result, 0.0f - blended");
gd.addNumericField("Scale angular pose extrapolation", this.scale_extrap_atr, 3,5,"",
"Scale angular extrapolation relative to the previous pair");
gd.addNumericField("Scale linear pose extrapolation", this.scale_extrap_xyz, 3,5,"",
"Scale linear extrapolation relative to the previous pair (use 1.0 for a drone)");
gd.addNumericField("Number of previous scenes to extrapolate",this.avg_len, 0,3,"",
"Average this number of previous scenes movement for next scene prediction");
gd.addNumericField("Minimal number of scenes to keep series",this.min_num_scenes, 0,3,"", gd.addNumericField("Minimal number of scenes to keep series",this.min_num_scenes, 0,3,"",
"Scrap all seriest if less numer of scenes can be matched to the reference scene (including reference itself)"); "Scrap all seriest if less numer of scenes can be matched to the reference scene (including reference itself)");
gd.addNumericField("Cut longer series", this.max_num_scenes, 0,3,"",
"Cut longer series");
gd.addNumericField("LPF egomotion sigma", this.blur_egomotion, 3,5,"scenes", gd.addNumericField("LPF egomotion sigma", this.blur_egomotion, 3,5,"scenes",
"LPF egomotion components with this sigma before using as ERS (not implemented)."); "LPF egomotion components with this sigma before using as ERS (not implemented).");
...@@ -999,8 +1013,11 @@ public class IntersceneMatchParameters { ...@@ -999,8 +1013,11 @@ public class IntersceneMatchParameters {
this.show_color_nan = gd.getNextBoolean(); this.show_color_nan = gd.getNextBoolean();
this.show_mono_nan = gd.getNextBoolean(); this.show_mono_nan = gd.getNextBoolean();
this.scale_extrap_atr = gd.getNextNumber();
this.scale_extrap_xyz = gd.getNextNumber();
this.avg_len = (int) gd.getNextNumber();
this.min_num_scenes = (int) gd.getNextNumber(); this.min_num_scenes = (int) gd.getNextNumber();
this.max_num_scenes = (int) gd.getNextNumber();
this.blur_egomotion = gd.getNextNumber(); this.blur_egomotion = gd.getNextNumber();
this.range_disparity_offset = gd.getNextNumber(); this.range_disparity_offset = gd.getNextNumber();
this.range_min_strength = gd.getNextNumber(); this.range_min_strength = gd.getNextNumber();
...@@ -1008,9 +1025,6 @@ public class IntersceneMatchParameters { ...@@ -1008,9 +1025,6 @@ public class IntersceneMatchParameters {
this.export3d = gd.getNextBoolean(); this.export3d = gd.getNextBoolean();
this.scene_is_ref_test = gd.getNextBoolean(); this.scene_is_ref_test = gd.getNextBoolean();
this.render_ref = gd.getNextBoolean(); this.render_ref = gd.getNextBoolean();
this.render_scene = gd.getNextBoolean(); this.render_scene = gd.getNextBoolean();
...@@ -1329,12 +1343,15 @@ public class IntersceneMatchParameters { ...@@ -1329,12 +1343,15 @@ public class IntersceneMatchParameters {
properties.setProperty(prefix+"show_color_nan", this.show_color_nan + ""); // boolean properties.setProperty(prefix+"show_color_nan", this.show_color_nan + ""); // boolean
properties.setProperty(prefix+"show_mono_nan", this.show_mono_nan + ""); // boolean properties.setProperty(prefix+"show_mono_nan", this.show_mono_nan + ""); // boolean
properties.setProperty(prefix+"scale_extrap_atr", this.scale_extrap_atr+""); // double
properties.setProperty(prefix+"scale_extrap_xyz", this.scale_extrap_xyz+""); // double
properties.setProperty(prefix+"avg_len", this.avg_len+""); // int
properties.setProperty(prefix+"min_num_scenes", this.min_num_scenes+""); // int properties.setProperty(prefix+"min_num_scenes", this.min_num_scenes+""); // int
properties.setProperty(prefix+"max_num_scenes", this.max_num_scenes+""); // int
properties.setProperty(prefix+"blur_egomotion", this.blur_egomotion+""); // double properties.setProperty(prefix+"blur_egomotion", this.blur_egomotion+""); // double
properties.setProperty(prefix+"range_disparity_offset", this.range_disparity_offset+""); // double properties.setProperty(prefix+"range_disparity_offset", this.range_disparity_offset+""); // double
properties.setProperty(prefix+"range_min_strength", this.range_min_strength+""); // double properties.setProperty(prefix+"range_min_strength", this.range_min_strength+""); // double
properties.setProperty(prefix+"range_max", this.range_max+""); // double properties.setProperty(prefix+"range_max", this.range_max+""); // double
properties.setProperty(prefix+"export3d", this.export3d+""); // boolean properties.setProperty(prefix+"export3d", this.export3d+""); // boolean
properties.setProperty(prefix+"scene_is_ref_test", this.scene_is_ref_test+""); // boolean properties.setProperty(prefix+"scene_is_ref_test", this.scene_is_ref_test+""); // boolean
...@@ -1606,7 +1623,13 @@ public class IntersceneMatchParameters { ...@@ -1606,7 +1623,13 @@ public class IntersceneMatchParameters {
if (properties.getProperty(prefix+"show_color_nan")!=null) this.show_color_nan=Boolean.parseBoolean(properties.getProperty(prefix+"show_color_nan")); if (properties.getProperty(prefix+"show_color_nan")!=null) this.show_color_nan=Boolean.parseBoolean(properties.getProperty(prefix+"show_color_nan"));
if (properties.getProperty(prefix+"show_mono_nan")!=null) this.show_mono_nan=Boolean.parseBoolean(properties.getProperty(prefix+"show_mono_nan")); if (properties.getProperty(prefix+"show_mono_nan")!=null) this.show_mono_nan=Boolean.parseBoolean(properties.getProperty(prefix+"show_mono_nan"));
if (properties.getProperty(prefix+"scale_extrap_atr")!=null) this.scale_extrap_atr=Double.parseDouble(properties.getProperty(prefix+"scale_extrap_atr"));
if (properties.getProperty(prefix+"scale_extrap_xyz")!=null) this.scale_extrap_xyz=Double.parseDouble(properties.getProperty(prefix+"scale_extrap_xyz"));
if (properties.getProperty(prefix+"avg_len")!=null) this.avg_len=Integer.parseInt(properties.getProperty(prefix+"avg_len"));
if (properties.getProperty(prefix+"min_num_scenes")!=null) this.min_num_scenes=Integer.parseInt(properties.getProperty(prefix+"min_num_scenes")); if (properties.getProperty(prefix+"min_num_scenes")!=null) this.min_num_scenes=Integer.parseInt(properties.getProperty(prefix+"min_num_scenes"));
if (properties.getProperty(prefix+"max_num_scenes")!=null) this.max_num_scenes=Integer.parseInt(properties.getProperty(prefix+"max_num_scenes"));
if (properties.getProperty(prefix+"blur_egomotion")!=null) this.blur_egomotion=Double.parseDouble(properties.getProperty(prefix+"blur_egomotion")); if (properties.getProperty(prefix+"blur_egomotion")!=null) this.blur_egomotion=Double.parseDouble(properties.getProperty(prefix+"blur_egomotion"));
if (properties.getProperty(prefix+"range_disparity_offset")!=null)this.range_disparity_offset=Double.parseDouble(properties.getProperty(prefix+"range_disparity_offset")); if (properties.getProperty(prefix+"range_disparity_offset")!=null)this.range_disparity_offset=Double.parseDouble(properties.getProperty(prefix+"range_disparity_offset"));
if (properties.getProperty(prefix+"range_min_strength")!=null) this.range_min_strength=Double.parseDouble(properties.getProperty(prefix+"range_min_strength")); if (properties.getProperty(prefix+"range_min_strength")!=null) this.range_min_strength=Double.parseDouble(properties.getProperty(prefix+"range_min_strength"));
...@@ -1895,15 +1918,17 @@ public class IntersceneMatchParameters { ...@@ -1895,15 +1918,17 @@ public class IntersceneMatchParameters {
imp.debug_ranges = this.debug_ranges; imp.debug_ranges = this.debug_ranges;
imp.show_ranges = this.show_ranges; imp.show_ranges = this.show_ranges;
imp.export_ml_files = this.export_ml_files; imp.export_ml_files = this.export_ml_files;
imp.show_color_nan = this.show_color_nan; imp.show_color_nan = this.show_color_nan;
imp.show_mono_nan = this.show_mono_nan; imp.show_mono_nan = this.show_mono_nan;
imp.scale_extrap_atr = this.scale_extrap_atr;
imp.scale_extrap_xyz = this.scale_extrap_xyz;
imp.avg_len = this.avg_len;
imp.min_num_scenes = this.min_num_scenes; imp.min_num_scenes = this.min_num_scenes;
imp.max_num_scenes = this.max_num_scenes;
imp.blur_egomotion = this.blur_egomotion; imp.blur_egomotion = this.blur_egomotion;
imp.range_disparity_offset = this.range_disparity_offset; imp.range_disparity_offset = this.range_disparity_offset;
imp.range_min_strength = this.range_min_strength; imp.range_min_strength = this.range_min_strength;
imp.range_max = this.range_max; imp.range_max = this.range_max;
imp.export3d = this.export3d; imp.export3d = this.export3d;
......
...@@ -3530,12 +3530,15 @@ public class OpticalFlow { ...@@ -3530,12 +3530,15 @@ public class OpticalFlow {
scenes_xyzatr[i] = adjustPairsLMAInterscene( scenes_xyzatr[i] = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
reference_QuadClt, // QuadCLT reference_QuadCLT, reference_QuadClt, // QuadCLT reference_QuadCLT,
null, // double [] ref_disparity, // null or alternative reference disparity null, // double [] ref_disparity, // null or alternative reference disparity
null, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles null, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles
scene_QuadClt, // QuadCLT scene_QuadCLT, scene_QuadClt, // QuadCLT scene_QuadCLT,
scenes_xyzatr[i][0], // xyz scenes_xyzatr[i][0], // xyz
scenes_xyzatr[i][1], // atr scenes_xyzatr[i][1], // atr
null, // double [] scene_xyz_pull, // if both are not null, specify target values to pull to
null, // double [] scene_atr_pull, //
clt_parameters.ilp.ilma_lma_select, // final boolean[] param_select, clt_parameters.ilp.ilma_lma_select, // final boolean[] param_select,
clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights, clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights,
rms2, // double [] rms, // null or double [2] rms2, // double [] rms, // null or double [2]
...@@ -4498,9 +4501,14 @@ public class OpticalFlow { ...@@ -4498,9 +4501,14 @@ public class OpticalFlow {
final boolean updateStatus, final boolean updateStatus,
final int debugLevel) { final int debugLevel) {
double scale_extrap_atr = clt_parameters.imp.scale_extrap_atr;
double scale_extrap_xyz = clt_parameters.imp.scale_extrap_xyz;
int avg_len = clt_parameters.imp.avg_len;
double maximal_series_rms = 0.0; double maximal_series_rms = 0.0;
double min_ref_str = clt_parameters.imp.min_ref_str; double min_ref_str = clt_parameters.imp.min_ref_str;
int min_num_scenes = clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it int min_num_scenes = clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it
int max_num_scenes = clt_parameters.imp.max_num_scenes; // cut longer series
double [] lma_rms = new double[2]; double [] lma_rms = new double[2];
double [] use_atr = null; double [] use_atr = null;
for (int scene_index = ref_index - 1; scene_index >= 0 ; scene_index--) { for (int scene_index = ref_index - 1; scene_index >= 0 ; scene_index--) {
...@@ -4531,12 +4539,22 @@ public class OpticalFlow { ...@@ -4531,12 +4539,22 @@ public class OpticalFlow {
quadCLTs[ref_index].getTileProcessor().getTilesY(), quadCLTs[ref_index].getTileProcessor().getTilesY(),
"reliable_ref"); "reliable_ref");
} }
} }
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
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 ((ref_index - scene_index) >= max_num_scenes){
earliest_scene = scene_index + 1;
if (debugLevel > -3) {
System.out.println("Cutting too long series at scene "+scene_index+" (of "+ quadCLTs.length+". excluding) ");
}
// set this and all previous to null
for (; scene_index >= 0 ; scene_index--) {
ers_reference.addScene(quadCLTs[scene_index].getImageName(), null);
}
break;
}
if (scene_index == debug_scene) { if (scene_index == debug_scene) {
System.out.println("scene_index = "+scene_index); System.out.println("scene_index = "+scene_index);
System.out.println("scene_index = "+scene_index); System.out.println("scene_index = "+scene_index);
...@@ -4569,9 +4587,9 @@ public class OpticalFlow { ...@@ -4569,9 +4587,9 @@ public class OpticalFlow {
System.out.println("adjusting orientation, scene_index="+scene_index); System.out.println("adjusting orientation, scene_index="+scene_index);
System.out.println("adjusting orientation, scene_index="+scene_index); System.out.println("adjusting orientation, scene_index="+scene_index);
} }
int num_avg = 1; // 3; // int avg_len = 1; // 3;
double scale_xyz = 0.0; // 0.5; // double scale_xyz = 0.0; // 0.5;
int na = num_avg; int na = avg_len;
if ((scene_index + 1 + na) > ref_index) { if ((scene_index + 1 + na) > ref_index) {
na = ref_index - (scene_index + 1); na = ref_index - (scene_index + 1);
} }
...@@ -4584,7 +4602,8 @@ public class OpticalFlow { ...@@ -4584,7 +4602,8 @@ public class OpticalFlow {
last_diff[1][i] /= na; last_diff[1][i] /= na;
} }
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
last_diff[0][i] *= scale_xyz; last_diff[0][i] *= scale_extrap_xyz;
last_diff[1][i] *= scale_extrap_atr;
} }
scenes_xyzatr[scene_index] = ErsCorrection.combineXYZATR( scenes_xyzatr[scene_index] = ErsCorrection.combineXYZATR(
scenes_xyzatr[scene_index+1], scenes_xyzatr[scene_index+1],
...@@ -4593,12 +4612,15 @@ public class OpticalFlow { ...@@ -4593,12 +4612,15 @@ public class OpticalFlow {
// Refine with LMA // Refine with LMA
scenes_xyzatr[scene_index] = adjustPairsLMAInterscene( scenes_xyzatr[scene_index] = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
quadCLTs[ref_index], // QuadCLT reference_QuadCLT, quadCLTs[ref_index], // QuadCLT reference_QuadCLT,
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
scene_QuadClt, // QuadCLT scene_QuadCLT, scene_QuadClt, // QuadCLT scene_QuadCLT,
scenes_xyzatr[scene_index][0], // xyz scenes_xyzatr[scene_index][0], // xyz
scenes_xyzatr[scene_index][1], // atr scenes_xyzatr[scene_index][1], // atr
scenes_xyzatr[scene_index][0], // double [] scene_xyz_pull, // if both are not null, specify target values to pull to
scenes_xyzatr[scene_index][1], // double [] scene_atr_pull, //
clt_parameters.ilp.ilma_lma_select, // final boolean[] param_select, clt_parameters.ilp.ilma_lma_select, // final boolean[] param_select,
clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights, clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights,
lma_rms, // double [] rms, // null or double [2] lma_rms, // double [] rms, // null or double [2]
...@@ -4717,6 +4739,7 @@ public class OpticalFlow { ...@@ -4717,6 +4739,7 @@ public class OpticalFlow {
boolean show_dsi_image = clt_parameters.imp.show_ranges && !batch_mode; boolean show_dsi_image = clt_parameters.imp.show_ranges && !batch_mode;
boolean show_images = clt_parameters.imp.show_images && !batch_mode; boolean show_images = clt_parameters.imp.show_images && !batch_mode;
int min_num_scenes = clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it int min_num_scenes = clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it
int max_num_scenes = clt_parameters.imp.max_num_scenes; // cut longer series
boolean show_images_bgfg = clt_parameters.imp.show_images_bgfg && !batch_mode; boolean show_images_bgfg = clt_parameters.imp.show_images_bgfg && !batch_mode;
boolean show_images_mono = clt_parameters.imp.show_images_mono && !batch_mode; boolean show_images_mono = clt_parameters.imp.show_images_mono && !batch_mode;
...@@ -4971,7 +4994,8 @@ public class OpticalFlow { ...@@ -4971,7 +4994,8 @@ public class OpticalFlow {
} }
} }
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 (!quadCLTs[ref_index].tsExists(set_channels[scene_index].set_name)) { if ((!quadCLTs[ref_index].tsExists(set_channels[scene_index].set_name)) ||
((ref_index - scene_index) >= max_num_scenes)) {
earliest_scene = scene_index + 1; earliest_scene = scene_index + 1;
} }
} }
...@@ -6538,12 +6562,15 @@ public class OpticalFlow { ...@@ -6538,12 +6562,15 @@ public class OpticalFlow {
double [][] adjusted_xyzatr = adjustPairsLMAInterscene( double [][] adjusted_xyzatr = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
quadCLTs[other_ref[1]], // QuadCLT reference_QuadCLT, quadCLTs[other_ref[1]], // QuadCLT reference_QuadCLT,
null, // double [] ref_disparity, // null or alternative reference disparity null, // double [] ref_disparity, // null or alternative reference disparity
null, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles null, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles
quadCLTs[other_ref[0]], // QuadCLT scene_QuadCLT, quadCLTs[other_ref[0]], // QuadCLT scene_QuadCLT,
scene_xyz_pre, // xyz scene_xyz_pre, // xyz
scene_atr_pre, // atr scene_atr_pre, // atr
null, // double [] scene_xyz_pull, // if both are not null, specify target values to pull to
null, // double [] scene_atr_pull, //
clt_parameters.ilp.ilma_lma_select, // final boolean[] param_select, clt_parameters.ilp.ilma_lma_select, // final boolean[] param_select,
clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights, clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights,
lma_rms, // double [] rms, // null or double [2] lma_rms, // double [] rms, // null or double [2]
...@@ -6638,6 +6665,7 @@ public class OpticalFlow { ...@@ -6638,6 +6665,7 @@ public class OpticalFlow {
QuadCLT [] quadCLTs, QuadCLT [] quadCLTs,
double [][] dxyzatr_dt) { double [][] dxyzatr_dt) {
int ref_index = quadCLTs.length -1; int ref_index = quadCLTs.length -1;
int earlies_scene = quadCLTs[ref_index].getEarliestScene(quadCLTs);
ErsCorrection ers_reference = quadCLTs[ref_index].getErsCorrection(); ErsCorrection ers_reference = quadCLTs[ref_index].getErsCorrection();
int dbg_scene = -95; int dbg_scene = -95;
int [][] min_max_xyzatr = new int [6][2]; int [][] min_max_xyzatr = new int [6][2];
...@@ -6649,13 +6677,13 @@ public class OpticalFlow { ...@@ -6649,13 +6677,13 @@ public class OpticalFlow {
} else { } else {
Arrays.fill(dxyzatr_dt, null); Arrays.fill(dxyzatr_dt, null);
} }
for (int nscene = 0; nscene < quadCLTs.length ; nscene++) if (quadCLTs[nscene] != null){ for (int nscene = earlies_scene; nscene < quadCLTs.length ; nscene++) if (quadCLTs[nscene] != null){
if (nscene== dbg_scene) { if (nscene== dbg_scene) {
System.out.println("renderSceneSequence(): nscene = "+nscene); System.out.println("renderSceneSequence(): nscene = "+nscene);
} }
String ts = quadCLTs[nscene].getImageName(); String ts = quadCLTs[nscene].getImageName();
if ((ers_reference.getSceneXYZ(ts) != null) && (ers_reference.getSceneATR(ts) != null)) { if ((ers_reference.getSceneXYZ(ts) != null) && (ers_reference.getSceneATR(ts) != null)) {
int nscene0 = nscene - ((nscene >0)? 1:0); int nscene0 = nscene - ((nscene > earlies_scene)? 1:0);
int nscene1 = nscene + ((nscene < ref_index)? 1:0); int nscene1 = nscene + ((nscene < ref_index)? 1:0);
String ts0 = quadCLTs[nscene0].getImageName(); String ts0 = quadCLTs[nscene0].getImageName();
if ((ers_reference.getSceneXYZ(ts0) == null) || (ers_reference.getSceneATR(ts0) == null)) { if ((ers_reference.getSceneXYZ(ts0) == null) || (ers_reference.getSceneATR(ts0) == null)) {
...@@ -6927,6 +6955,8 @@ public class OpticalFlow { ...@@ -6927,6 +6955,8 @@ public class OpticalFlow {
boolean [] reliable_ref, boolean [] reliable_ref,
int debugLevel int debugLevel
) { ) {
// boolean use3D = clt_parameters.ilp.ilma_3d && (clt_parameters.ilp.ilma_disparity_weight > 0);
// double disparity_weight = use3D? clt_parameters.ilp.ilma_disparity_weight : 0.0;
int [][] offset_start_corner = {{-1,-1},{1,-1},{1,1},{-1,1}}; //{x,y} int [][] offset_start_corner = {{-1,-1},{1,-1},{1,1},{-1,1}}; //{x,y}
int [][] offset_move = {{1,0},{0,1},{-1,0},{0,-1}}; int [][] offset_move = {{1,0},{0,1},{-1,0},{0,-1}};
int margin = clt_parameters.imp.margin; int margin = clt_parameters.imp.margin;
...@@ -7001,6 +7031,8 @@ public class OpticalFlow { ...@@ -7001,6 +7031,8 @@ public class OpticalFlow {
} }
double [][][] coord_motion = interCorrPair( // new double [tilesY][tilesX][][]; double [][][] coord_motion = interCorrPair( // new double [tilesY][tilesX][][];
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
false, // use3D, // boolean use3D, // generate disparity difference
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
0, // mb_max_gain, // double mb_max_gain, 0, // mb_max_gain, // double mb_max_gain,
reference_QuadClt, // QuadCLT reference_QuadCLT, reference_QuadClt, // QuadCLT reference_QuadCLT,
ref_disparity, // null, // double [] ref_disparity, // null or alternative reference disparity ref_disparity, // null, // double [] ref_disparity, // null or alternative reference disparity
...@@ -7276,12 +7308,15 @@ public class OpticalFlow { ...@@ -7276,12 +7308,15 @@ public class OpticalFlow {
if (high_res_motion_vectors) { if (high_res_motion_vectors) {
scenes_xyzatr[i] = adjustPairsLMAInterscene( scenes_xyzatr[i] = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
reference_QuadClt, // QuadCLT reference_QuadCLT, reference_QuadClt, // QuadCLT reference_QuadCLT,
null, // double [] ref_disparity, // null or alternative reference disparity null, // double [] ref_disparity, // null or alternative reference disparity
null, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles null, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles
scene_QuadClt, // QuadCLT scene_QuadCLT, scene_QuadClt, // QuadCLT scene_QuadCLT,
combo_XYZATR[0], // xyz combo_XYZATR[0], // xyz
combo_XYZATR[1], // atr combo_XYZATR[1], // atr
null, // double [] scene_xyz_pull, // if both are not null, specify target values to pull to
null, // double [] scene_atr_pull, //
param_select2, // final boolean[] param_select, param_select2, // final boolean[] param_select,
param_regweights2, // final double [] param_regweights, param_regweights2, // final double [] param_regweights,
lma_rms, // double [] rms, // null or double [2] lma_rms, // double [] rms, // null or double [2]
...@@ -7384,12 +7419,15 @@ public class OpticalFlow { ...@@ -7384,12 +7419,15 @@ public class OpticalFlow {
if (high_res_motion_vectors) { if (high_res_motion_vectors) {
scenes_xyzatr[i] = adjustPairsLMAInterscene( scenes_xyzatr[i] = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
reference_QuadClt, // QuadCLT reference_QuadCLT, reference_QuadClt, // QuadCLT reference_QuadCLT,
null, // double [] ref_disparity, // null or alternative reference disparity null, // double [] ref_disparity, // null or alternative reference disparity
null, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles null, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles
scene_QuadClt, // QuadCLT scene_QuadCLT, scene_QuadClt, // QuadCLT scene_QuadCLT,
combo_XYZATR[0], // xyz combo_XYZATR[0], // xyz
combo_XYZATR[1], // atr combo_XYZATR[1], // atr
null, // double [] scene_xyz_pull, // if both are not null, specify target values to pull to
null, // double [] scene_atr_pull, //
param_select2, // final boolean[] param_select, param_select2, // final boolean[] param_select,
param_regweights2, // final double [] param_regweights, param_regweights2, // final double [] param_regweights,
lma_rms, // double [] rms, // null or double [2] lma_rms, // double [] rms, // null or double [2]
...@@ -7524,12 +7562,15 @@ public class OpticalFlow { ...@@ -7524,12 +7562,15 @@ public class OpticalFlow {
if (high_res_motion_vectors) { if (high_res_motion_vectors) {
scenes_xyzatr[i] = adjustPairsLMAInterscene( scenes_xyzatr[i] = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
reference_QuadClt, // QuadCLT reference_QuadCLT, reference_QuadClt, // QuadCLT reference_QuadCLT,
null, // double [] ref_disparity, // null or alternative reference disparity null, // double [] ref_disparity, // null or alternative reference disparity
null, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles null, // boolean [] reliable_ref, // null or bitmask of reliable reference tiles
scenes[i], // QuadCLT scene_QuadCLT, scenes[i], // QuadCLT scene_QuadCLT,
scene_xyz, // combo_XYZATR[0], // xyz scene_xyz, // combo_XYZATR[0], // xyz
scene_atr, // combo_XYZATR[1], // atr scene_atr, // combo_XYZATR[1], // atr
null, // double [] scene_xyz_pull, // if both are not null, specify target values to pull to
null, // double [] scene_atr_pull, //
param_select3, // 3, // 2, // final boolean[] param_select, param_select3, // 3, // 2, // final boolean[] param_select,
param_regweights2, // final double [] param_regweights, param_regweights2, // final double [] param_regweights,
lma_rms, // double [] rms, // null or double [2] lma_rms, // double [] rms, // null or double [2]
...@@ -8393,7 +8434,7 @@ public class OpticalFlow { ...@@ -8393,7 +8434,7 @@ public class OpticalFlow {
QuadCLT ref_scene = scenes[indx_ref]; // ordered by increasing timestamps QuadCLT ref_scene = scenes[indx_ref]; // ordered by increasing timestamps
boolean generate_outlines = false; // true; // TODO: move to configs boolean generate_outlines = false; // true; // TODO: move to configs
System.out.println("intersceneExport(), scene timestamp="+ref_scene.getImageName()); System.out.println("intersceneExport(), scene timestamp="+ref_scene.getImageName());
int num_scenes = scenes.length; // int num_scenes = scenes.length;
String [] combo_dsn_titles_full = COMBO_DSN_TITLES.clone(); String [] combo_dsn_titles_full = COMBO_DSN_TITLES.clone();
String [] combo_dsn_titles = new String [COMBO_DSN_INDX_DISP_BG]; String [] combo_dsn_titles = new String [COMBO_DSN_INDX_DISP_BG];
for (int i = 0; i < combo_dsn_titles.length; i++) { for (int i = 0; i < combo_dsn_titles.length; i++) {
...@@ -8627,6 +8668,7 @@ public class OpticalFlow { ...@@ -8627,6 +8668,7 @@ public class OpticalFlow {
combo_dsn_final[COMBO_DSN_INDX_STRENGTH]}; combo_dsn_final[COMBO_DSN_INDX_STRENGTH]};
int split_src = -1; int split_src = -1;
if (split_pass >= 0) { if (split_pass >= 0) {
if (split_pass == 0) { if (split_pass == 0) {
split_src= 0 ; // AVG split_src= 0 ; // AVG
target_disparity=avg_ds[0]; target_disparity=avg_ds[0];
...@@ -8993,7 +9035,7 @@ public class OpticalFlow { ...@@ -8993,7 +9035,7 @@ public class OpticalFlow {
// add far split if available // add far split if available
boolean mod_cumul_disp = true; boolean mod_cumul_disp = true;
boolean mod_cumul_bg_disp = true; boolean mod_cumul_bg_disp = true;
if (far_fg_ds[0] != null) { if ((far_fg_ds != null) && (far_fg_ds[0] != null)) {
for (int nTile =0; nTile < combo_dsn_change[0].length; nTile++) { for (int nTile =0; nTile < combo_dsn_change[0].length; nTile++) {
if (!Double.isNaN(far_fg_ds[0][nTile]) && !Double.isNaN(far_bg_ds[0][nTile])) { if (!Double.isNaN(far_fg_ds[0][nTile]) && !Double.isNaN(far_bg_ds[0][nTile])) {
// filtering // filtering
...@@ -10264,7 +10306,7 @@ public class OpticalFlow { ...@@ -10264,7 +10306,7 @@ public class OpticalFlow {
final int num_scenes = scenes.length+0; final int num_scenes = scenes.length+0;
final double [][][] initial_ds = new double[num_scenes][][]; final double [][][] initial_ds = new double[num_scenes][][];
final ErsCorrection ers_reference = ref_scene.getErsCorrection(); final ErsCorrection ers_reference = ref_scene.getErsCorrection();
for (int i = 0; i < num_scenes; i++) { for (int i = 0; i < num_scenes; i++) if (scenes[i] != null) {
initial_ds[i] = conditionInitialDS( initial_ds[i] = conditionInitialDS(
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
scenes[i], // QuadCLT scene, scenes[i], // QuadCLT scene,
...@@ -10273,7 +10315,7 @@ public class OpticalFlow { ...@@ -10273,7 +10315,7 @@ public class OpticalFlow {
if (debug_level > -1) { if (debug_level > -1) {
String [] dbg_titles = new String [2*num_scenes]; String [] dbg_titles = new String [2*num_scenes];
double [][] dbg_img = new double [2*num_scenes][]; double [][] dbg_img = new double [2*num_scenes][];
for (int i = 0; i < num_scenes; i++) { for (int i = 0; i < num_scenes; i++) if (scenes[i] != null) {
dbg_titles[i + 0] = "d-"+scenes[i].getImageName(); dbg_titles[i + 0] = "d-"+scenes[i].getImageName();
dbg_titles[i + num_scenes] = "s-"+scenes[i].getImageName(); dbg_titles[i + num_scenes] = "s-"+scenes[i].getImageName();
if (initial_ds[i] != null) { if (initial_ds[i] != null) {
...@@ -10298,7 +10340,7 @@ public class OpticalFlow { ...@@ -10298,7 +10340,7 @@ public class OpticalFlow {
double [][][] initial_toref_ds = new double[num_scenes][][]; double [][][] initial_toref_ds = new double[num_scenes][][];
initial_toref_ds[indx_ref] = initial_ds[indx_ref]; initial_toref_ds[indx_ref] = initial_ds[indx_ref];
// reference camera ERS should be already set // reference camera ERS should be already set
for (int i = 0; i < num_scenes; i++) if ((i != indx_ref) && (initial_ds[i] != null)) { for (int i = 0; i < num_scenes; i++) if ((i != indx_ref) && (initial_ds[i] != null) && (scenes[i] != null)) {
String ts = scenes[i].getImageName(); String ts = scenes[i].getImageName();
double [] scene_xyz = ers_reference.getSceneXYZ(ts); double [] scene_xyz = ers_reference.getSceneXYZ(ts);
double [] scene_atr = ers_reference.getSceneATR(ts); double [] scene_atr = ers_reference.getSceneATR(ts);
...@@ -10327,7 +10369,7 @@ public class OpticalFlow { ...@@ -10327,7 +10369,7 @@ public class OpticalFlow {
if (debug_level > -1) { // **** Used to create images for report ! if (debug_level > -1) { // **** Used to create images for report !
String [] dbg_titles = new String [2*num_scenes]; String [] dbg_titles = new String [2*num_scenes];
double [][] dbg_img = new double [2*num_scenes][]; double [][] dbg_img = new double [2*num_scenes][];
for (int i = 0; i < num_scenes; i++) { for (int i = 0; i < num_scenes; i++) if (scenes[i] != null) {
dbg_titles[i + 0] = "d-"+scenes[i].getImageName(); dbg_titles[i + 0] = "d-"+scenes[i].getImageName();
dbg_titles[i + num_scenes] = "s-"+scenes[i].getImageName(); dbg_titles[i + num_scenes] = "s-"+scenes[i].getImageName();
if (initial_toref_ds[i] != null) { if (initial_toref_ds[i] != null) {
...@@ -10623,7 +10665,7 @@ public class OpticalFlow { ...@@ -10623,7 +10665,7 @@ public class OpticalFlow {
//TODO: Need to set scenes[indx_ref].getErsCorrection().setErsDt() before processing scenes ? //TODO: Need to set scenes[indx_ref].getErsCorrection().setErsDt() before processing scenes ?
for (int nscene = 0; nscene < scenes.length; nscene++) { for (int nscene = 0; nscene < scenes.length; nscene++) if (scenes[nscene] != null){
String ts = scenes[nscene].getImageName(); String ts = scenes[nscene].getImageName();
double [][] scene_pXpYD; double [][] scene_pXpYD;
if (nscene == indx_ref) { if (nscene == indx_ref) {
...@@ -12420,9 +12462,35 @@ public class OpticalFlow { ...@@ -12420,9 +12462,35 @@ public class OpticalFlow {
ref_scene.saveQuadClt(); // to re-load new set of Bayer images to the GPU (do nothing for CPU) and Geometry ref_scene.saveQuadClt(); // to re-load new set of Bayer images to the GPU (do nothing for CPU) and Geometry
return tp_tasks_ref; return tp_tasks_ref;
} }
/**
*
* @param clt_parameters
* @param use3D when true, generate disparity difference in addition to average {pX,pY}
* @param mb_max_gain
* @param ref_scene
* @param ref_disparity
* @param pXpYD_ref
* @param tp_tasks_ref
* @param scene
* @param scene_xyz
* @param scene_atr
* @param selection
* @param margin
* @param sensor_mask_inter
* @param accum_2d_corr
* @param dbg_corr_fpn
* @param near_important
* @param all_fpn
* @param mb_vectors
* @param imp_debug_level
* @param debug_level
* @return
*/
public static double [][][] interCorrPair( // return [tilesX*telesY]{ref_pXpYD, dXdYS} public static double [][][] interCorrPair( // return [tilesX*telesY]{ref_pXpYD, dXdYS}
CLTParameters clt_parameters, CLTParameters clt_parameters,
boolean use3D, // generate disparity difference
boolean fpn_disable, // disable fpn filter if images are known to be too close
double mb_max_gain, double mb_max_gain,
QuadCLT ref_scene, QuadCLT ref_scene,
double [] ref_disparity, // null or alternative reference disparity double [] ref_disparity, // null or alternative reference disparity
...@@ -12443,6 +12511,8 @@ public class OpticalFlow { ...@@ -12443,6 +12511,8 @@ public class OpticalFlow {
int imp_debug_level, // MANUALLY change to 2 for debug! int imp_debug_level, // MANUALLY change to 2 for debug!
int debug_level) int debug_level)
{ {
boolean use3D_lma = clt_parameters.ilp.ilma_3d_lma;
boolean use3D_lma_tilt_only = clt_parameters.ilp.ilma_3d_tilt_only;
if (!ref_scene.hasGPU()) { if (!ref_scene.hasGPU()) {
throw new IllegalArgumentException ("interCorrPair(): CPU mode not supported"); throw new IllegalArgumentException ("interCorrPair(): CPU mode not supported");
} }
...@@ -12461,7 +12531,7 @@ public class OpticalFlow { ...@@ -12461,7 +12531,7 @@ public class OpticalFlow {
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);
boolean fpn_remove = 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;
double fpn_radius = clt_parameters.imp.fpn_radius; double fpn_radius = clt_parameters.imp.fpn_radius;
boolean fpn_ignore_border = clt_parameters.imp.fpn_ignore_border; // only if fpn_mask != null - ignore tile if maximum touches fpn_mask boolean fpn_ignore_border = clt_parameters.imp.fpn_ignore_border; // only if fpn_mask != null - ignore tile if maximum touches fpn_mask
...@@ -12480,6 +12550,7 @@ public class OpticalFlow { ...@@ -12480,6 +12550,7 @@ public class OpticalFlow {
double eq_weight_scale = clt_parameters.imp.eq_weight_scale; // 10; double eq_weight_scale = clt_parameters.imp.eq_weight_scale; // 10;
double eq_level = clt_parameters.imp.eq_level; // 0.8; // equalize to (log) fraction of average/this strength double eq_level = clt_parameters.imp.eq_level; // 0.8; // equalize to (log) fraction of average/this strength
final double scene_disparity_cor = clt_parameters.imp.disparity_corr; // 04/07/2023 // 0.0;
final double gpu_sigma_corr = clt_parameters.getGpuCorrSigma(ref_scene.isMonochrome()); final double gpu_sigma_corr = clt_parameters.getGpuCorrSigma(ref_scene.isMonochrome());
final double gpu_sigma_rb_corr = ref_scene.isMonochrome()? 1.0 : clt_parameters.gpu_sigma_rb_corr; final double gpu_sigma_rb_corr = ref_scene.isMonochrome()? 1.0 : clt_parameters.gpu_sigma_rb_corr;
final double gpu_sigma_log_corr = clt_parameters.getGpuCorrLoGSigma(ref_scene.isMonochrome()); final double gpu_sigma_log_corr = clt_parameters.getGpuCorrLoGSigma(ref_scene.isMonochrome());
...@@ -12508,6 +12579,7 @@ public class OpticalFlow { ...@@ -12508,6 +12579,7 @@ public class OpticalFlow {
ref_scene.isLwir(), ref_scene.isLwir(),
clt_parameters.getScaleStrength(ref_scene.isAux()), clt_parameters.getScaleStrength(ref_scene.isAux()),
ref_scene.getGPU()); ref_scene.getGPU());
image_dtt.getCorrelation2d(); // initiate image_dtt.correlation2d, needed if disparity_map != null
if (ref_scene.getGPU() != null) { if (ref_scene.getGPU() != null) {
ref_scene.getGPU().setGpu_debug_level(debug_level - 4); // monitor GPU ops >=-1 ref_scene.getGPU().setGpu_debug_level(debug_level - 4); // monitor GPU ops >=-1
} }
...@@ -12524,6 +12596,101 @@ public class OpticalFlow { ...@@ -12524,6 +12596,101 @@ public class OpticalFlow {
scene_atr, // final double [] scene_atr, // camera orientation relative to world frame scene_atr, // final double [] scene_atr, // camera orientation relative to world frame
scene, // final QuadCLT scene_QuadClt, scene, // final QuadCLT scene_QuadClt,
scene_is_ref_test ? null: ref_scene); // final QuadCLT reference_QuadClt) scene_is_ref_test ? null: ref_scene); // final QuadCLT reference_QuadClt)
double [][] scene_disparity_strength = null; // calculate if needed
if (use3D) { //(scene_disparity_strength != null)
final boolean [] valid_tiles = new boolean[tilesX * tilesY]; // or use null?
float [][][][] fcorr_td = new float[tilesY][tilesX][][];
int mcorr_sel = Correlation2d.corrSelEncode(clt_parameters.img_dtt, scene.getNumSensors());
double [][] disparity_map = new double [ImageDtt.getDisparityTitles(scene.getNumSensors(), scene.isMonochrome()).length][];
TpTask[] tp_tasks_disp = GpuQuad.setInterTasks( // just to calculate valid_tiles
scene.getNumSensors(),
scene.getGeometryCorrection().getSensorWH()[0],
!scene.hasGPU(), // final boolean calcPortsCoordinatesAndDerivatives, // GPU can calculate them centreXY
scene_pXpYD, // final double [][] pXpYD, // per-tile array of pX,pY,disparity triplets (or nulls)
null, // final boolean [] selection, // may be null, if not null do not process unselected tiles
scene.getGeometryCorrection(), // final GeometryCorrection geometryCorrection,
scene_disparity_cor, // final double disparity_corr,
margin, // final int margin, // do not use tiles if their centers are closer to the edges
valid_tiles, // final boolean [] valid_tiles,
THREADS_MAX); // final int threadsMax) // maximal number of threads to launch
image_dtt.quadCorrTD( // maybe remove "imageDtt."
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
tp_tasks_disp, // *** will be updated inside from GPU-calculated geometry
fcorr_td, // fcorrs_td[nscene], // [tilesY][tilesX][pair][4*64] transform domain representation of 6 corr pairs
clt_parameters.gpu_sigma_r, // 0.9, 1.1
clt_parameters.gpu_sigma_b, // 0.9, 1.1
clt_parameters.gpu_sigma_g, // 0.6, 0.7
clt_parameters.gpu_sigma_m, // = 0.4; // 0.7;
gpu_sigma_rb_corr, // final double gpu_sigma_rb_corr, // = 0.5; // apply LPF after accumulating R and B correlation before G, monochrome ? 1.0 : gpu_sigma_rb_corr;
gpu_sigma_corr, // = 0.9;gpu_sigma_corr_m
gpu_sigma_log_corr, // final double gpu_sigma_log_corr, // hpf to reduce dynamic range for correlations
clt_parameters.corr_red, // +used
clt_parameters.corr_blue, // +used
mcorr_sel, // final int mcorr_sel, // Which pairs to correlate // +1 - all, +2 - dia, +4 - sq, +8 - neibs, +16 - hor + 32 - vert
THREADS_MAX, // maximal number of threads to launch
debug_level);
image_dtt.clt_process_tl_correlations( // convert to pixel domain and process correlations already prepared in fcorr_td and/or fcorr_combo_td
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
fcorr_td, // final float [][][][] fcorr_td, // [tilesY][tilesX][pair][4*64] transform domain representation of all selected corr pairs
null, // num_acc, // float [][][] num_acc, // number of accumulated tiles [tilesY][tilesX][pair] (or null)
null, // tile_corr_weights, // dcorr_weight, // double [] dcorr_weight, // alternative to num_acc, compatible with CPU processing (only one non-zero enough)
clt_parameters.gpu_corr_scale, // final double gpu_corr_scale, // 0.75; // reduce GPU-generated correlation values
clt_parameters.getGpuFatZero(scene.isMonochrome()), // final double gpu_fat_zero, // clt_parameters.getGpuFatZero(is_mono);absolute == 30.0
image_dtt.transform_size - 1, // final int gpu_corr_rad, // = transform_size - 1 ?
// The tp_tasks data should be decoded from GPU to get coordinates
tp_tasks_disp, // final TpTask [] tp_tasks, // data from the reference frame - will be applied to LMW for the integrated correlations
null, // final double [][][] far_fgbg, // null, or [tilesY][tilesX]{disp(fg)-disp(bg), str(fg)-str(bg)} hints for LMA FG/BG split
scene.getGeometryCorrection().getRXY(false), // final double [][] rXY, // from geometryCorrection
// next both can be nulls
null, // final double [][][][] clt_corr_out, // sparse (by the first index) [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] or null
// combo will be added as extra pair if mcorr_comb_width > 0 and clt_corr_out has a slot for it
// to be converted to float
null, // dcorr_tiles, // final double [][][] dcorr_tiles, // [tile][pair][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// When clt_mismatch is non-zero, no far objects extraction will be attempted
false, // final boolean use_rms, // DISPARITY_STRENGTH_INDEX means LMA RMS (18/04/2023)
//optional, may be null
disparity_map, // final double [][] disparity_map, // [8][tilesY][tilesX], only [6][] is needed on input or null - do not calculate
null, // final double [][] ddnd, // data for LY. SHould be either null or [num_sensors][]
use3D_lma, // run_lma, // clt_parameters.correlate_lma, // final boolean run_lma, // calculate LMA, false - CM only
// define combining of all 2D correlation pairs for CM (LMA does not use them)
clt_parameters.img_dtt.mcorr_comb_width, //final int mcorr_comb_width, // combined correlation tile width (set <=0 to skip combined correlations)
clt_parameters.img_dtt.mcorr_comb_height,//final int mcorr_comb_height, // combined correlation tile full height
clt_parameters.img_dtt.mcorr_comb_offset,//final int mcorr_comb_offset, // combined correlation tile height offset: 0 - centered (-height/2 to height/2), height/2 - only positive (0 to height)
clt_parameters.img_dtt.mcorr_comb_disp, //final double mcorr_comb_disp, // Combined tile per-pixel disparity for baseline == side of a square
clt_parameters.clt_window, // final int window_type, // GPU: will not be used
clt_parameters.tileX, // final int debug_tileX,
clt_parameters.tileY, // final int debug_tileY,
THREADS_MAX, // final int threadsMax, // maximal number of threads to launch
null, // final String debug_suffix,
debug_level); // + 2+1); // -1 ); // final int globalDebugLevel)\
if (use3D_lma) {
scene_disparity_strength=new double[][]{
disparity_map[ImageDtt.DISPARITY_INDEX_POLY],
disparity_map[ImageDtt.DISPARITY_INDEX_POLY+1]};
} else {
scene_disparity_strength=new double[][]{
disparity_map[ImageDtt.DISPARITY_INDEX_CM],
disparity_map[ImageDtt.DISPARITY_INDEX_CM+1]};
}
// remove disparity average, only detect tilts
if (use3D_lma_tilt_only) {
double sw = 0, swd = 0;
for (int i = 0; i < scene_disparity_strength[0].length; i++) {
if (Double.isNaN(scene_disparity_strength[0][i]) || Double.isNaN(scene_disparity_strength[1][i])) {
scene_disparity_strength[0][i]=0;
scene_disparity_strength[1][i]=0;
}
sw += scene_disparity_strength[1][i];
swd += scene_disparity_strength[0][i] * scene_disparity_strength[1][i];
}
double avg = swd/sw;
for (int i = 0; i < scene_disparity_strength[0].length; i++) {
scene_disparity_strength[0][i] -= avg;
}
}
}
if (transform_debug) { if (transform_debug) {
// calculate with no transform // calculate with no transform
double [][] dbg_ref_pXpYD = transformToScenePxPyD( // will be null for disparity == NaN, total size - tilesX*tilesY double [][] dbg_ref_pXpYD = transformToScenePxPyD( // will be null for disparity == NaN, total size - tilesX*tilesY
...@@ -12700,6 +12867,8 @@ public class OpticalFlow { ...@@ -12700,6 +12867,8 @@ public class OpticalFlow {
} }
coord_motion = image_dtt.clt_process_tl_interscene( // convert to pixel domain and process correlations already prepared in fcorr_td and/or fcorr_combo_td coord_motion = image_dtt.clt_process_tl_interscene( // convert to pixel domain and process correlations already prepared in fcorr_td and/or fcorr_combo_td
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
// only used here to keep extra array element for disparity difference
use3D, // boolean use3D, // generate disparity difference
fcorr_td, // final float [][][][] fcorr_td, // [tilesY][tilesX][pair][4*64] transform domain representation of all selected corr pairs fcorr_td, // final float [][][][] fcorr_td, // [tilesY][tilesX][pair][4*64] transform domain representation of all selected corr pairs
null, // float [][][] num_acc, // number of accumulated tiles [tilesY][tilesX][pair] (or null). Can be inner null if not used in tp_tasks null, // float [][][] num_acc, // number of accumulated tiles [tilesY][tilesX][pair] (or null). Can be inner null if not used in tp_tasks
null, // double [] dcorr_weight, // alternative to num_acc, compatible with CPU processing (only one non-zero enough) null, // double [] dcorr_weight, // alternative to num_acc, compatible with CPU processing (only one non-zero enough)
...@@ -12735,12 +12904,22 @@ public class OpticalFlow { ...@@ -12735,12 +12904,22 @@ public class OpticalFlow {
clt_parameters.tileY, // final int debug_tileY, clt_parameters.tileY, // final int debug_tileY,
THREADS_MAX, // final int threadsMax, // maximal number of threads to launch THREADS_MAX, // final int threadsMax, // maximal number of threads to launch
debug_level); debug_level);
// optional coord_motion[1][3..4] is reserved for disparity difference and strength
// final int globalDebugLevel); // final int globalDebugLevel);
if (coord_motion == null) { if (coord_motion == null) {
System.out.println("clt_process_tl_interscene() returned null"); System.out.println("clt_process_tl_interscene() returned null");
return null; return null;
} }
if (use3D) {//(scene_disparity_strength != null)
// combine motion vector with disparity_diff/strength
int num_slices = scene_disparity_strength.length;
int coord_motion_slice = coord_motion.length - 1; // used for motionvector - last index
for (int tile = 0; tile < coord_motion[coord_motion_slice].length; tile++ ) if ( coord_motion[coord_motion_slice][tile] != null){
for (int i = 0; i < num_slices; i++) {
coord_motion[coord_motion_slice][tile][i+3] = scene_disparity_strength[i][tile];
}
}
}
if (eq_en) { if (eq_en) {
// double eq_weight_add = (min_str * clt_parameters.imp.pd_weight + min_str_sum * clt_parameters.imp.td_weight) / // double eq_weight_add = (min_str * clt_parameters.imp.pd_weight + min_str_sum * clt_parameters.imp.td_weight) /
// (clt_parameters.imp.pd_weight + clt_parameters.imp.td_weight); // (clt_parameters.imp.pd_weight + clt_parameters.imp.td_weight);
...@@ -12901,27 +13080,29 @@ public class OpticalFlow { ...@@ -12901,27 +13080,29 @@ public class OpticalFlow {
true, true,
scene.getImageName()+"-"+ref_scene.getImageName()+"-motion_vectors", scene.getImageName()+"-"+ref_scene.getImageName()+"-motion_vectors",
titles); titles);
} }
if (show_coord_motion) { if (show_coord_motion) {
//coord_motion //coord_motion
String [] mvTitles = {"dx", "dy", "conf", "pX", "pY","Disp","defined"}; // ,"blurX","blurY", "blur"}; String [] mvTitles = {"dx", "dy", "conf","disp_diff", "disp_str", "pX", "pY","Disp","defined"}; // ,"blurX","blurY", "blur"};
double [][] dbg_img = new double [mvTitles.length][tilesX*tilesY]; double [][] dbg_img = new double [mvTitles.length][];
for (int l = 0; l < dbg_img.length; l++) { for (int l = 0; l < dbg_img.length; l++) {
if (use3D || (l < 3) || (l > 4) ) {
dbg_img[l] = new double [tilesX*tilesY]; // keep unused null
Arrays.fill(dbg_img[l], Double.NaN); Arrays.fill(dbg_img[l], Double.NaN);
} }
}
for (int nTile = 0; nTile < coord_motion[0].length; nTile++) { for (int nTile = 0; nTile < coord_motion[0].length; nTile++) {
if (coord_motion[0][nTile] != null) { if (coord_motion[0][nTile] != null) {
for (int i = 0; i <3; i++) { for (int i = 0; i < 3; i++) {
dbg_img[3+i][nTile] = coord_motion[0][nTile][i]; dbg_img[5+i][nTile] = coord_motion[0][nTile][i];
} }
} }
if (coord_motion[1][nTile] != null) { if (coord_motion[1][nTile] != null) {
for (int i = 0; i <3; i++) { for (int i = 0; i < (use3D? 5 : 3); i++) {
dbg_img[0+i][nTile] = coord_motion[1][nTile][i]; dbg_img[0+i][nTile] = coord_motion[1][nTile][i];
} }
} }
dbg_img[6][nTile] = ((coord_motion[0][nTile] != null)?1:0)+((coord_motion[0][nTile] != null)?2:0); dbg_img[8][nTile] = ((coord_motion[0][nTile] != null)?1:0)+((coord_motion[0][nTile] != null)?2:0);
} }
ShowDoubleFloatArrays.showArrays( // out of boundary 15 ShowDoubleFloatArrays.showArrays( // out of boundary 15
dbg_img, dbg_img,
...@@ -13497,6 +13678,8 @@ public class OpticalFlow { ...@@ -13497,6 +13678,8 @@ public class OpticalFlow {
double max_rms, double max_rms,
int debug_level) int debug_level)
{ {
boolean use3D = clt_parameters.ilp.ilma_3d;
double disparity_weight = use3D? clt_parameters.ilp.ilma_disparity_weight : 0.0;
TileProcessor tp = reference_QuadCLT.getTileProcessor(); TileProcessor tp = reference_QuadCLT.getTileProcessor();
final int iscale = 8; final int iscale = 8;
boolean blur_reference = false; boolean blur_reference = false;
...@@ -13528,7 +13711,8 @@ public class OpticalFlow { ...@@ -13528,7 +13711,8 @@ public class OpticalFlow {
iscale); // int iscale) // 8 iscale); // int iscale) // 8
} }
IntersceneLma intersceneLma = new IntersceneLma( IntersceneLma intersceneLma = new IntersceneLma(
clt_parameters.ilp.ilma_thread_invariant); clt_parameters.ilp.ilma_thread_invariant,
disparity_weight);
int nlma = 0; int nlma = 0;
int lmaResult = -1; int lmaResult = -1;
// debug: had to clt_parameters.ofp.debug_level_iterate=-10 to stop images // debug: had to clt_parameters.ofp.debug_level_iterate=-10 to stop images
...@@ -13664,6 +13848,8 @@ public class OpticalFlow { ...@@ -13664,6 +13848,8 @@ public class OpticalFlow {
intersceneLma.prepareLMA( intersceneLma.prepareLMA(
camera_xyz0, // final double [] scene_xyz0, // camera center in world coordinates (or null to use instance) camera_xyz0, // final double [] scene_xyz0, // camera center in world coordinates (or null to use instance)
camera_atr0, // final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance) camera_atr0, // final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance)
null, // final double [] scene_xyz_pull, // if both are not null, specify target values to pull to
null, // final double [] scene_atr_pull, //
// reference atr, xyz are considered 0.0 // reference atr, xyz are considered 0.0
scene_QuadCLT, // final QuadCLT scene_QuadClt, scene_QuadCLT, // final QuadCLT scene_QuadClt,
reference_QuadCLT, // final QuadCLT reference_QuadClt, reference_QuadCLT, // final QuadCLT reference_QuadClt,
...@@ -13756,6 +13942,7 @@ public class OpticalFlow { ...@@ -13756,6 +13942,7 @@ public class OpticalFlow {
int debugLevel) int debugLevel)
{ {
System.out.println("reAdjustPairsLMAInterscene(): using mb_max_gain="+mb_max_gain); System.out.println("reAdjustPairsLMAInterscene(): using mb_max_gain="+mb_max_gain);
int avg_len = clt_parameters.imp.avg_len;
// boolean test_motion_blur = true;//false // boolean test_motion_blur = true;//false
// Set up velocities from known coordinates, use averaging // Set up velocities from known coordinates, use averaging
double half_run_range = clt_parameters.ilp.ilma_motion_filter; // 3.50; // make a parameter double half_run_range = clt_parameters.ilp.ilma_motion_filter; // 3.50; // make a parameter
...@@ -14034,6 +14221,48 @@ public class OpticalFlow { ...@@ -14034,6 +14221,48 @@ public class OpticalFlow {
double [][] mb_vectors = null; double [][] mb_vectors = null;
scene_xyz_pre = ers_reference.getSceneXYZ(ts); scene_xyz_pre = ers_reference.getSceneXYZ(ts);
scene_atr_pre = ers_reference.getSceneATR(ts); scene_atr_pre = ers_reference.getSceneATR(ts);
double [][] scene_xyzatr = new double[][] {scene_xyz_pre, scene_atr_pre};
double [][] inv_scene = ErsCorrection.invertXYZATR(scene_xyzatr);
double [] avg_weights = new double [2*avg_len+1];
int n_pre = nscene + avg_len;
int n_post = nscene - avg_len;
if (n_post < earliest_scene) n_post = earliest_scene;
if (n_pre > ref_index) n_pre = ref_index;
double s0=0, sx=0, sx2=0;
double [][] sy = new double[2][3], sxy = new double [2][3];
for (int n_other = n_post; n_other <= n_pre; n_other++) {
int ix = n_other - nscene; //+/-i
int i = ix + avg_len; // >=0
avg_weights[i] = Math.cos(Math.PI * (i - avg_len) / (2 * avg_len + 1));
double [][] other_xyzatr = ers_reference.getSceneXYZATR(quadCLTs[n_other].getImageName());
double [][] other_rel = (n_other != ref_index)?ErsCorrection.combineXYZATR(other_xyzatr,inv_scene):
(new double[2][3]);
double w = avg_weights[i];
s0 += w;
sx += w * ix;
sx2 += w * ix * ix;
for (int j = 0; j < other_rel.length; j++) {
for (int k = 0; k < other_rel[j].length; k++) {
sy [j][k] += w * other_rel[j][k];
sxy[j][k] += w * other_rel[j][k] * ix;
}
}
}
boolean fpn_disable = false; // estimate they are too close
// double angle_per_pixel = reference_QuadClt.getGeometryCorrection().getCorrVector().getTiltAzPerPixel() * pix_step;
double angle_per_pixel = ers_reference.getCorrVector().getTiltAzPerPixel();
//ers_reference
// double [][] scene_xyzatr_pull = new double [][] {scene_xyz_pre.clone(),scene_atr_pre.clone()};
double [][] diff_pull = new double [2][3];
for (int j = 0; j < diff_pull.length; j++) {
for (int k = 0; k < diff_pull[j].length; k++) {
diff_pull[j][k]=(sy[j][k]*sx2 - sxy[j][k]*sx) / (s0*sx2 - sx*sx);
}
}
double [][] scene_pull = ErsCorrection.combineXYZATR(scene_xyzatr,diff_pull);
// temporary! TODO: replace with smooth version
// double [] scene_xyz_pull = scene_xyz_pre.clone();
// double [] scene_atr_pull = scene_atr_pre.clone();
if (mb_en) { if (mb_en) {
// double [][] dxyzatr_dt_scene = getVelocities( // double [][] dxyzatr_dt_scene = getVelocities(
// quadCLTs, // QuadCLT [] quadCLTs, // quadCLTs, // QuadCLT [] quadCLTs,
...@@ -14053,6 +14282,7 @@ public class OpticalFlow { ...@@ -14053,6 +14282,7 @@ public class OpticalFlow {
double [] lma_rms = new double[2]; double [] lma_rms = new double[2];
scenes_xyzatr[nscene] = adjustPairsLMAInterscene( scenes_xyzatr[nscene] = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
fpn_disable, // boolean fpn_disable, // disable fpn filter if images are known to be too close
quadCLTs[ref_index], // QuadCLT reference_QuadCLT, quadCLTs[ref_index], // QuadCLT reference_QuadCLT,
interscene_ref_disparity, // double [] ref_disparity, // null or alternative reference disparity interscene_ref_disparity, // double [] ref_disparity, // null or alternative reference disparity
ref_pXpYD, // double [][] pXpYD_ref, // pXpYD for the reference scene ref_pXpYD, // double [][] pXpYD_ref, // pXpYD for the reference scene
...@@ -14061,6 +14291,8 @@ public class OpticalFlow { ...@@ -14061,6 +14291,8 @@ public class OpticalFlow {
quadCLTs[nscene], // QuadCLT scene_QuadCLT, quadCLTs[nscene], // QuadCLT scene_QuadCLT,
scene_xyz_pre, // xyz scene_xyz_pre, // xyz
scene_atr_pre, // atr scene_atr_pre, // atr
scene_pull[0], // double [] scene_xyz_pull, // if both are not null, specify target values to pull to
scene_pull[1], // double [] scene_atr_pull,
clt_parameters.ilp.ilma_lma_select, // final boolean[] param_select, clt_parameters.ilp.ilma_lma_select, // final boolean[] param_select,
clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights, clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights,
lma_rms, // double [] rms, // null or double [2] lma_rms, // double [] rms, // null or double [2]
...@@ -14081,6 +14313,7 @@ public class OpticalFlow { ...@@ -14081,6 +14313,7 @@ public class OpticalFlow {
// set this and all previous to null // set this and all previous to null
for (; nscene >= 0 ; nscene--) { for (; nscene >= 0 ; nscene--) {
ers_reference.addScene(quadCLTs[nscene].getImageName(), null); ers_reference.addScene(quadCLTs[nscene].getImageName(), null);
quadCLTs[nscene] = null; // completely remove early scenes?
} }
break; break;
} }
...@@ -14174,10 +14407,13 @@ public class OpticalFlow { ...@@ -14174,10 +14407,13 @@ public class OpticalFlow {
final int tilesX = ref_scene.tp.getTilesX(); final int tilesX = ref_scene.tp.getTilesX();
// final int tilesY = ref_scene.tp.getTilesY(); // final int tilesY = ref_scene.tp.getTilesY();
IntersceneLma intersceneLma = new IntersceneLma( IntersceneLma intersceneLma = new IntersceneLma(
false); // clt_parameters.ilp.ilma_thread_invariant); false, // clt_parameters.ilp.ilma_thread_invariant);
0.0); // always no disparity
intersceneLma.prepareLMA( intersceneLma.prepareLMA(
camera_xyz, // final double [] scene_xyz0, // camera center in world coordinates (or null to use instance) camera_xyz, // final double [] scene_xyz0, // camera center in world coordinates (or null to use instance)
camera_atr, // final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance) camera_atr, // final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance)
null, // final double [] scene_xyz_pull, // if both are not null, specify target values to pull to
null, // final double [] scene_atr_pull, //
scene, // final QuadCLT scene_QuadClt, scene, // final QuadCLT scene_QuadClt,
ref_scene, // final QuadCLT reference_QuadClt, ref_scene, // final QuadCLT reference_QuadClt,
param_select, // final boolean[] param_select, param_select, // final boolean[] param_select,
...@@ -14352,12 +14588,15 @@ public class OpticalFlow { ...@@ -14352,12 +14588,15 @@ public class OpticalFlow {
public static double[][] adjustPairsLMAInterscene( public static double[][] adjustPairsLMAInterscene(
CLTParameters clt_parameters, CLTParameters clt_parameters,
boolean fpn_disable, // disable fpn filter if images are known to be too close
QuadCLT reference_QuadClt, QuadCLT reference_QuadClt,
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
QuadCLT scene_QuadClt, QuadCLT scene_QuadClt,
double [] camera_xyz, double [] camera_xyz,
double [] camera_atr, double [] camera_atr,
double [] scene_xyz_pull, // if both are not null, specify target values to pull to
double [] scene_atr_pull, //
boolean[] param_select, boolean[] param_select,
double [] param_regweights, double [] param_regweights,
double [] rms_out, // null or double [2] double [] rms_out, // null or double [2]
...@@ -14392,6 +14631,7 @@ public class OpticalFlow { ...@@ -14392,6 +14631,7 @@ public class OpticalFlow {
debug_level); // int debug_level) debug_level); // int debug_level)
return adjustPairsLMAInterscene( // assumes reference GPU data is already set - once for multiple scenes return adjustPairsLMAInterscene( // assumes reference GPU data is already set - once for multiple scenes
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
reference_QuadClt, // QuadCLT reference_QuadClt, reference_QuadClt, // QuadCLT reference_QuadClt,
ref_disparity, // double [] ref_disparity, // null or alternative reference disparity ref_disparity, // double [] ref_disparity, // null or alternative reference disparity
pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene pXpYD_ref, // double [][] pXpYD_ref, // pXpYD for the reference scene
...@@ -14401,6 +14641,8 @@ public class OpticalFlow { ...@@ -14401,6 +14641,8 @@ public class OpticalFlow {
scene_QuadClt, // QuadCLT scene_QuadClt, scene_QuadClt, // QuadCLT scene_QuadClt,
camera_xyz, // double [] camera_xyz, camera_xyz, // double [] camera_xyz,
camera_atr, // double [] camera_atr, camera_atr, // double [] camera_atr,
scene_xyz_pull, // double [] scene_xyz_pull, // if both are not null, specify target values to pull to
scene_atr_pull, // double [] scene_atr_pull,
param_select, // boolean[] param_select, param_select, // boolean[] param_select,
param_regweights, // double [] param_regweights, param_regweights, // double [] param_regweights,
rms_out, // double [] rms_out, // null or double [2] rms_out, // double [] rms_out, // null or double [2]
...@@ -14414,6 +14656,7 @@ public class OpticalFlow { ...@@ -14414,6 +14656,7 @@ public class OpticalFlow {
public static double[][] adjustPairsLMAInterscene( // assumes reference scene already set in GPU. public static double[][] adjustPairsLMAInterscene( // assumes reference scene already set in GPU.
CLTParameters clt_parameters, CLTParameters clt_parameters,
boolean fpn_disable, // disable fpn filter if images are known to be too close
QuadCLT reference_QuadClt, QuadCLT reference_QuadClt,
double [] ref_disparity, // null or alternative reference disparity double [] ref_disparity, // null or alternative reference disparity
double [][] pXpYD_ref, // pXpYD for the reference scene double [][] pXpYD_ref, // pXpYD for the reference scene
...@@ -14422,6 +14665,8 @@ public class OpticalFlow { ...@@ -14422,6 +14665,8 @@ public class OpticalFlow {
QuadCLT scene_QuadClt, QuadCLT scene_QuadClt,
double [] camera_xyz, double [] camera_xyz,
double [] camera_atr, double [] camera_atr,
double [] scene_xyz_pull, // if both are not null, specify target values to pull to
double [] scene_atr_pull, //
boolean[] param_select, boolean[] param_select,
double [] param_regweights, double [] param_regweights,
double [] rms_out, // null or double [2] double [] rms_out, // null or double [2]
...@@ -14432,11 +14677,15 @@ public class OpticalFlow { ...@@ -14432,11 +14677,15 @@ public class OpticalFlow {
double [][] mb_vectors, // now [2][ntiles]; double [][] mb_vectors, // now [2][ntiles];
int debug_level) int debug_level)
{ {
boolean use3D = clt_parameters.ilp.ilma_3d;
// boolean use3D_lma = clt_parameters.ilp.ilma_3d_lma;
double disparity_weight = use3D? clt_parameters.ilp.ilma_disparity_weight : 0.0;
int margin = clt_parameters.imp.margin; int margin = clt_parameters.imp.margin;
int sensor_mask_inter = clt_parameters.imp.sensor_mask_inter ; //-1; int sensor_mask_inter = clt_parameters.imp.sensor_mask_inter ; //-1;
float [][][] facc_2d_img = new float [1][][]; float [][][] facc_2d_img = new float [1][][];
IntersceneLma intersceneLma = new IntersceneLma( IntersceneLma intersceneLma = new IntersceneLma(
clt_parameters.ilp.ilma_thread_invariant); clt_parameters.ilp.ilma_thread_invariant,
disparity_weight);
int lmaResult = -1; int lmaResult = -1;
boolean last_run = false; boolean last_run = false;
double[] camera_xyz0 = camera_xyz.clone(); double[] camera_xyz0 = camera_xyz.clone();
...@@ -14451,6 +14700,8 @@ public class OpticalFlow { ...@@ -14451,6 +14700,8 @@ public class OpticalFlow {
// pass dxyzatr_dt, not mb_vectors? Or update velocities too? // pass dxyzatr_dt, not mb_vectors? Or update velocities too?
coord_motion = interCorrPair( // new double [tilesY][tilesX][][]; coord_motion = interCorrPair( // new double [tilesY][tilesX][][];
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
use3D, // boolean use3D, // generate disparity difference
fpn_disable, // boolean fpn_disable, // disable fpn filter if images are known to be too close
mb_max_gain, // double mb_max_gain, mb_max_gain, // double mb_max_gain,
reference_QuadClt, // QuadCLT reference_QuadCLT, reference_QuadClt, // QuadCLT reference_QuadCLT,
ref_disparity, // double [] ref_disparity, // null or alternative reference disparity ref_disparity, // double [] ref_disparity, // null or alternative reference disparity
...@@ -14476,6 +14727,8 @@ public class OpticalFlow { ...@@ -14476,6 +14727,8 @@ public class OpticalFlow {
intersceneLma.prepareLMA( intersceneLma.prepareLMA(
camera_xyz0, // final double [] scene_xyz0, // camera center in world coordinates (or null to use instance) camera_xyz0, // final double [] scene_xyz0, // camera center in world coordinates (or null to use instance)
camera_atr0, // final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance) camera_atr0, // final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance)
scene_xyz_pull, // final double [] scene_xyz_pull, // if both are not null, specify target values to pull to
scene_atr_pull, // final double [] scene_atr_pull, //
// reference atr, xyz are considered 0.0 // reference atr, xyz are considered 0.0
scene_QuadClt, // final QuadCLT scene_QuadClt, scene_QuadClt, // final QuadCLT scene_QuadClt,
reference_QuadClt, // final QuadCLT reference_QuadClt, reference_QuadClt, // final QuadCLT reference_QuadClt,
...@@ -14508,16 +14761,22 @@ public class OpticalFlow { ...@@ -14508,16 +14761,22 @@ public class OpticalFlow {
} }
} }
if (show_corr_fpn && (debug_level > -1)) { // now not needed, restore if needed if (show_corr_fpn && (debug_level > -1)) { // now not needed, restore if needed
String [] fpn_dbg_titles = new String[2 + scene_QuadClt.getNumSensors() * 2]; int num_components = intersceneLma.getNumComponents();
fpn_dbg_titles[00] = "X_avg"; String [] fpn_dbg_titles = new String[num_components + scene_QuadClt.getNumSensors() * 2];
fpn_dbg_titles[0] = "X_avg";
fpn_dbg_titles[1] = "X_avg"; fpn_dbg_titles[1] = "X_avg";
if (num_components > 2) {
fpn_dbg_titles[2] = "Disp";
}
for (int i = 0; i < scene_QuadClt.getNumSensors(); i++) { for (int i = 0; i < scene_QuadClt.getNumSensors(); i++) {
fpn_dbg_titles[2 + 2*i] = "X-"+i; fpn_dbg_titles[num_components + 0 + 2*i] = "X-"+i;
fpn_dbg_titles[3 + 2*i] = "Y-"+i; fpn_dbg_titles[num_components + 1 + 2*i] = "Y-"+i;
} }
float [][] dbg_corr_fpn = new float [fpn_dbg_titles.length][]; float [][] dbg_corr_fpn = new float [fpn_dbg_titles.length][];
coord_motion = interCorrPair( // new double [tilesY][tilesX][][]; coord_motion = interCorrPair( // new double [tilesY][tilesX][][];
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
false, // boolean use3D, // generate disparity difference
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
mb_max_gain, // double mb_max_gain, mb_max_gain, // double mb_max_gain,
reference_QuadClt, // QuadCLT reference_QuadCLT, reference_QuadClt, // QuadCLT reference_QuadCLT,
ref_disparity, // double [] ref_disparity, // null or alternative reference disparity ref_disparity, // double [] ref_disparity, // null or alternative reference disparity
...@@ -14559,6 +14818,8 @@ public class OpticalFlow { ...@@ -14559,6 +14818,8 @@ public class OpticalFlow {
float [][] dbg_corr_fpn = new float [fpn_dbg_titles.length][]; float [][] dbg_corr_fpn = new float [fpn_dbg_titles.length][];
coord_motion = interCorrPair( // new double [tilesY][tilesX][][]; coord_motion = interCorrPair( // new double [tilesY][tilesX][][];
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
false, // boolean use3D, // generate disparity difference
false, // boolean fpn_disable, // disable fpn filter if images are known to be too close
mb_max_gain, // double mb_max_gain, mb_max_gain, // double mb_max_gain,
reference_QuadClt, // QuadCLT reference_QuadCLT, reference_QuadClt, // QuadCLT reference_QuadCLT,
ref_disparity, // double [] ref_disparity, // null or alternative reference disparity ref_disparity, // double [] ref_disparity, // null or alternative reference disparity
...@@ -14651,6 +14912,8 @@ public class OpticalFlow { ...@@ -14651,6 +14912,8 @@ public class OpticalFlow {
double corr_scale, // = 0.75 double corr_scale, // = 0.75
int debug_level) int debug_level)
{ {
boolean use3D = clt_parameters.ilp.ilma_3d;
double disparity_weight = use3D? clt_parameters.ilp.ilma_disparity_weight : 0.0;
TileProcessor tp = reference_QuadCLT.getTileProcessor(); TileProcessor tp = reference_QuadCLT.getTileProcessor();
final int iscale = 8; final int iscale = 8;
boolean blur_reference = false; boolean blur_reference = false;
...@@ -14714,7 +14977,8 @@ public class OpticalFlow { ...@@ -14714,7 +14977,8 @@ public class OpticalFlow {
iscale); // int iscale) // 8 iscale); // int iscale) // 8
} }
IntersceneLma intersceneLma = new IntersceneLma( IntersceneLma intersceneLma = new IntersceneLma(
clt_parameters.ilp.ilma_thread_invariant); clt_parameters.ilp.ilma_thread_invariant,
disparity_weight);
for (int nlma = 0; nlma < clt_parameters.ilp.ilma_num_corr; nlma++) { for (int nlma = 0; nlma < clt_parameters.ilp.ilma_num_corr; nlma++) {
boolean last_run = nlma == ( clt_parameters.ilp.ilma_num_corr - 1); boolean last_run = nlma == ( clt_parameters.ilp.ilma_num_corr - 1);
int transform_size = tp.getTileSize(); int transform_size = tp.getTileSize();
...@@ -14789,6 +15053,8 @@ public class OpticalFlow { ...@@ -14789,6 +15053,8 @@ public class OpticalFlow {
intersceneLma.prepareLMA( intersceneLma.prepareLMA(
camera_xyz0, // final double [] scene_xyz0, // camera center in world coordinates (or null to use instance) camera_xyz0, // final double [] scene_xyz0, // camera center in world coordinates (or null to use instance)
camera_atr0, // final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance) camera_atr0, // final double [] scene_atr0, // camera orientation relative to world frame (or null to use instance)
null, // final double [] scene_xyz_pull, // if both are not null, specify target values to pull to
null, // final double [] scene_atr_pull, //
// reference atr, xyz are considered 0.0 // reference atr, xyz are considered 0.0
scene_QuadCLT, // final QuadCLT scene_QuadClt, scene_QuadCLT, // final QuadCLT scene_QuadClt,
reference_QuadCLT, //final QuadCLT reference_QuadClt, reference_QuadCLT, //final QuadCLT reference_QuadClt,
......
...@@ -807,7 +807,7 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -807,7 +807,7 @@ public class QuadCLT extends QuadCLTCPU {
debugLevel); // int debugLevel); debugLevel); // int debugLevel);
// once per quad here // once per quad here. "GPU not initialized, using CPU mode"
processCLTQuadCorrGPU( // returns ImagePlus, but it already should be saved/shown processCLTQuadCorrGPU( // returns ImagePlus, but it already should be saved/shown
null, // imp_srcs, // [srcChannel], // should have properties "name"(base for saving results), "channel","path" null, // imp_srcs, // [srcChannel], // should have properties "name"(base for saving results), "channel","path"
saturation_imp, // boolean [][] saturation_imp, // (near) saturated pixels or null saturation_imp, // boolean [][] saturation_imp, // (near) saturated pixels or null
......
...@@ -189,6 +189,9 @@ public class QuadCLTCPU { ...@@ -189,6 +189,9 @@ public class QuadCLTCPU {
} }
String ts = scenes[nscene].getImageName(); String ts = scenes[nscene].getImageName();
if (!ts.equals(ts_ref)) { if (!ts.equals(ts_ref)) {
if (ers_reference.getScene(ts) == null) {
return nscene + 1;
}
double [] scene_xyz = ers_reference.getSceneXYZ(ts); double [] scene_xyz = ers_reference.getSceneXYZ(ts);
double [] scene_atr = ers_reference.getSceneATR(ts); double [] scene_atr = ers_reference.getSceneATR(ts);
if ((scene_xyz == null) || (scene_atr == null)){ if ((scene_xyz == null) || (scene_atr == null)){
...@@ -15028,7 +15031,43 @@ public class QuadCLTCPU { ...@@ -15028,7 +15031,43 @@ public class QuadCLTCPU {
return true; return true;
} }
public boolean writePreview(
double [] data,
// boolean overwrite, // correctionsParameters.thumb_overwrite
int debugLevel
)
{
int width = getTileProcessor().getTilesX() *getTileProcessor().getTileSize();
int height = data.length/width;
String set_name = getImageName();
if (set_name == null ) {
QuadCLTCPU.SetChannels [] set_channels = setChannels(debugLevel);
set_name = set_channels[0].set_name;
}
String model_dir= correctionsParameters.selectX3dDirectory(
set_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
null,
true, // smart,
true); //newAllowed, // save\
String title = getImageName()+"-preview";
ImagePlus imp= ShowDoubleFloatArrays.makeArrays(data, width, height, title);
String preview_path = model_dir + Prefs.getFileSeparator() + title+".jpeg";
if (new File(preview_path).exists() && !correctionsParameters.thumb_overwrite) {
System.out.println("file "+preview_path+" exists, skipping preview generation");
return false;
}
if (debugLevel > -2) {
System.out.println("Saving preview image to "+preview_path);
}
EyesisCorrections.saveAndShow(
imp,
model_dir,
false,
false,
correctionsParameters.JPEG_quality, // jpegQuality); // jpegQuality){// <0 - keep current, 0 - force Tiff, >0 use for JPEG
(debugLevel > -2) ? debugLevel : 1); // int debugLevel (print what it saves)
return true;
}
public boolean writeRatingFile( // USED in lwir public boolean writeRatingFile( // USED in lwir
int debugLevel int debugLevel
......
...@@ -2691,7 +2691,7 @@ public class TexturedModel { ...@@ -2691,7 +2691,7 @@ public class TexturedModel {
boolean [] scenes_sel = new boolean[scenes.length]; boolean [] scenes_sel = new boolean[scenes.length];
// for (int i = scenes.length - 10; i < scenes.length; i++) { // start with just one (reference) scene // for (int i = scenes.length - 10; i < scenes.length; i++) { // start with just one (reference) scene
for (int i = 0; i < scenes.length; i++) { // start with just one (reference) scene for (int i = 0; i < scenes.length; i++) if (scenes[i] != null){ // start with just one (reference) scene
scenes_sel[i] = true; scenes_sel[i] = true;
} }
...@@ -7297,7 +7297,7 @@ public class TexturedModel { ...@@ -7297,7 +7297,7 @@ public class TexturedModel {
min_trim_disparity, // final double min_trim_disparity, // do not try to trim texture outlines with lower disparities min_trim_disparity, // final double min_trim_disparity, // do not try to trim texture outlines with lower disparities
tp_tasks_ref, // final TpTask[][][] tp_tasks_ref, // reference tasks for each slice to get offsets tp_tasks_ref, // final TpTask[][][] tp_tasks_ref, // reference tasks for each slice to get offsets
ref_scene.getImageName()); // null); // ref_scene.getImageName()); // final String dbg_prefix); ref_scene.getImageName()); // null); // ref_scene.getImageName()); // final String dbg_prefix);
if (debugLevel > -1) { if (debugLevel > -20) {
double [][] dbg_textures = new double [faded_textures.length * faded_textures[0].length][faded_textures[0][0].length]; double [][] dbg_textures = new double [faded_textures.length * faded_textures[0].length][faded_textures[0][0].length];
String [] dbg_titles = new String[dbg_textures.length]; String [] dbg_titles = new String[dbg_textures.length];
String [] dbg_subtitles = new String [faded_textures[0].length]; String [] dbg_subtitles = new String [faded_textures[0].length];
...@@ -7309,14 +7309,22 @@ public class TexturedModel { ...@@ -7309,14 +7309,22 @@ public class TexturedModel {
dbg_titles[i] = dbg_subtitles[i % dbg_subtitles.length] + "-" + (i / dbg_subtitles.length); dbg_titles[i] = dbg_subtitles[i % dbg_subtitles.length] + "-" + (i / dbg_subtitles.length);
} }
String suffix = "-combined_textures-prenorm-pre_UM";
if (!batch_run && (debugLevel > -1)) {
ShowDoubleFloatArrays.showArrays( ShowDoubleFloatArrays.showArrays(
dbg_textures, dbg_textures,
tilesX * transform_size, tilesX * transform_size,
tilesY * transform_size, tilesY * transform_size,
true, true,
ref_scene.getImageName()+"-combined_textures-prenorm-pre_UM", ref_scene.getImageName()+suffix,
dbg_titles); dbg_titles);
}
ref_scene.saveDoubleArrayInModelDirectory(
suffix, // String suffix,
null, // String [] labels, // or null
dbg_textures, // double [][] data,
tilesX * transform_size, // int width, // int tilesX,
tilesY * transform_size); // int height, // int tilesY,
} }
// fix alpha // fix alpha
if (alphaOverlapFix) { if (alphaOverlapFix) {
...@@ -7342,7 +7350,7 @@ public class TexturedModel { ...@@ -7342,7 +7350,7 @@ public class TexturedModel {
THREADS_MAX); // final int threadsMax) // maximal number of threads to launch THREADS_MAX); // final int threadsMax) // maximal number of threads to launch
} }
if (debugLevel > -1) { if (debugLevel > -20) {
double [][] dbg_textures = new double [faded_textures.length * faded_textures[0].length][faded_textures[0][0].length]; double [][] dbg_textures = new double [faded_textures.length * faded_textures[0].length][faded_textures[0][0].length];
String [] dbg_titles = new String[dbg_textures.length]; String [] dbg_titles = new String[dbg_textures.length];
String [] dbg_subtitles = new String [faded_textures[0].length]; String [] dbg_subtitles = new String [faded_textures[0].length];
...@@ -7355,14 +7363,23 @@ public class TexturedModel { ...@@ -7355,14 +7363,23 @@ public class TexturedModel {
dbg_titles[i] = dbg_subtitles[i % dbg_subtitles.length] + "-" + (i / dbg_subtitles.length); dbg_titles[i] = dbg_subtitles[i % dbg_subtitles.length] + "-" + (i / dbg_subtitles.length);
} }
String suffix = "-combined_textures-filled-NaNs";
if (!batch_run && (debugLevel > -1)) {
ShowDoubleFloatArrays.showArrays( ShowDoubleFloatArrays.showArrays(
dbg_textures, dbg_textures,
tilesX * transform_size, tilesX * transform_size,
tilesY * transform_size, tilesY * transform_size,
true, true,
ref_scene.getImageName()+"-combined_textures-filled-NaNs", ref_scene.getImageName()+suffix,
dbg_titles); dbg_titles);
} }
ref_scene.saveDoubleArrayInModelDirectory(
suffix, // String suffix,
null, // String [] labels, // or null
dbg_textures, // double [][] data,
tilesX * transform_size, // int width, // int tilesX,
tilesY * transform_size); // int height, // int tilesY,
}
// Optionally apply UM (before auto/manual range) // Optionally apply UM (before auto/manual range)
final boolean um_ignore_alpha = true; final boolean um_ignore_alpha = true;
...@@ -7376,7 +7393,7 @@ public class TexturedModel { ...@@ -7376,7 +7393,7 @@ public class TexturedModel {
tex_um_weight); // final double um_weight) tex_um_weight); // final double um_weight)
} }
if (debugLevel > -1) { if (debugLevel > -20) {
double [][] dbg_textures = new double [faded_textures.length * faded_textures[0].length][faded_textures[0][0].length]; double [][] dbg_textures = new double [faded_textures.length * faded_textures[0].length][faded_textures[0][0].length];
String [] dbg_titles = new String[dbg_textures.length]; String [] dbg_titles = new String[dbg_textures.length];
String [] dbg_subtitles = new String [faded_textures[0].length]; String [] dbg_subtitles = new String [faded_textures[0].length];
...@@ -7389,20 +7406,39 @@ public class TexturedModel { ...@@ -7389,20 +7406,39 @@ public class TexturedModel {
dbg_titles[i] = dbg_subtitles[i % dbg_subtitles.length] + "-" + (i / dbg_subtitles.length); dbg_titles[i] = dbg_subtitles[i % dbg_subtitles.length] + "-" + (i / dbg_subtitles.length);
} }
String suffix = "-combined_textures-prenorm";
if (!batch_run && (debugLevel > -1)) {
ShowDoubleFloatArrays.showArrays( ShowDoubleFloatArrays.showArrays(
dbg_textures, dbg_textures,
tilesX * transform_size, tilesX * transform_size,
tilesY * transform_size, tilesY * transform_size,
true, true,
ref_scene.getImageName()+"-combined_textures-prenorm", ref_scene.getImageName()+suffix,
dbg_titles); dbg_titles);
}
ref_scene.saveDoubleArrayInModelDirectory(
suffix, // String suffix,
null, // String [] labels, // or null
dbg_textures, // double [][] data,
tilesX * transform_size, // int width, // int tilesX,
tilesY * transform_size); // int height, // int tilesY,
if (dbg_weights != null) { if (dbg_weights != null) {
suffix = "-texture_weights-prenorm";
if (!batch_run && (debugLevel > -1)) {
ShowDoubleFloatArrays.showArrays( ShowDoubleFloatArrays.showArrays(
dbg_weights, dbg_weights,
tilesX, tilesX * transform_size,
tilesY, tilesY * transform_size,
true, true,
ref_scene.getImageName()+"-texture_weights-prenorm"); ref_scene.getImageName()+suffix,
dbg_titles);
}
ref_scene.saveDoubleArrayInModelDirectory(
suffix, // String suffix,
null, // String [] labels, // or null
dbg_weights, // double [][] data,
tilesX * transform_size, // int width, // int tilesX,
tilesY * transform_size); // int height, // int tilesY,
} }
} }
...@@ -7471,7 +7507,7 @@ public class TexturedModel { ...@@ -7471,7 +7507,7 @@ public class TexturedModel {
} }
if (!batch_run && (debugLevel > -2)) { if (debugLevel > -20) { // always
double [][] dbg_textures = new double [faded_textures.length * faded_textures[0].length][faded_textures[0][0].length]; double [][] dbg_textures = new double [faded_textures.length * faded_textures[0].length][faded_textures[0][0].length];
String [] dbg_titles = new String[dbg_textures.length]; String [] dbg_titles = new String[dbg_textures.length];
String [] dbg_subtitles = new String [faded_textures[0].length]; String [] dbg_subtitles = new String [faded_textures[0].length];
...@@ -7484,21 +7520,47 @@ public class TexturedModel { ...@@ -7484,21 +7520,47 @@ public class TexturedModel {
dbg_titles[i] = dbg_subtitles[i % dbg_subtitles.length] + "-" + (i / dbg_subtitles.length); dbg_titles[i] = dbg_subtitles[i % dbg_subtitles.length] + "-" + (i / dbg_subtitles.length);
} }
ref_scene.writePreview( // may movbe to different (earlier) stage of processing, (search for "-combined_textures")
dbg_textures[0], // double [] data,
debugLevel); // int debugLevel
String suffix = "-combined_textures";
if (!batch_run && (debugLevel > -1)) {
ShowDoubleFloatArrays.showArrays( ShowDoubleFloatArrays.showArrays(
dbg_textures, dbg_textures,
tilesX * transform_size, tilesX * transform_size,
tilesY * transform_size, tilesY * transform_size,
true, true,
ref_scene.getImageName()+"-combined_textures", ref_scene.getImageName()+suffix,
dbg_titles); dbg_titles);
}
ref_scene.saveDoubleArrayInModelDirectory(
suffix, // String suffix,
null, // String [] labels, // or null
dbg_textures, // double [][] data,
tilesX * transform_size, // int width, // int tilesX,
tilesY * transform_size); // int height, // int tilesY,
if (dbg_weights != null) { if (dbg_weights != null) {
suffix = "-texture_weights";
if (!batch_run && (debugLevel > -1)) {
ShowDoubleFloatArrays.showArrays( ShowDoubleFloatArrays.showArrays(
dbg_weights, dbg_weights,
tilesX, tilesX * transform_size,
tilesY, tilesY * transform_size,
true, true,
ref_scene.getImageName()+"-texture_weights"); ref_scene.getImageName()+suffix,
dbg_titles);
} }
ref_scene.saveDoubleArrayInModelDirectory(
suffix, // String suffix,
null, // String [] labels, // or null
dbg_weights, // double [][] data,
tilesX * transform_size, // int width, // int tilesX,
tilesY * transform_size); // int height, // int tilesY,
}
} }
return faded_textures; return faded_textures;
} }
...@@ -7528,6 +7590,7 @@ public class TexturedModel { ...@@ -7528,6 +7590,7 @@ public class TexturedModel {
int transform_size, int transform_size,
int debugLevel) int debugLevel)
{ {
boolean save_tiff_texture = true;
if (debugLevel > -2) { if (debugLevel > -2) {
System.out.println("getInterCombinedTextures(): no_alpha=" + no_alpha); // true System.out.println("getInterCombinedTextures(): no_alpha=" + no_alpha); // true
} }
...@@ -7540,8 +7603,18 @@ public class TexturedModel { ...@@ -7540,8 +7603,18 @@ public class TexturedModel {
double [] minmax = parameter_scene.getColdHot(); // used in linearStackToColor double [] minmax = parameter_scene.getColdHot(); // used in linearStackToColor
ImagePlus [] imp_tex = new ImagePlus[num_slices]; ImagePlus [] imp_tex = new ImagePlus[num_slices];
for (int nslice = 0; nslice < num_slices; nslice++) { for (int nslice = 0; nslice < num_slices; nslice++) {
String suffix=String.format("-combo%03d-texture",nslice);
String title=String.format("%s-combo%03d-texture",ref_scene.getImageName(), nslice); String title=String.format("%s-combo%03d-texture",ref_scene.getImageName(), nslice);
double [][] rendered_texture = faded_textures[nslice].clone(); // shallow ! double [][] rendered_texture = faded_textures[nslice].clone(); // shallow !
if (save_tiff_texture) {
ref_scene.saveDoubleArrayInModelDirectory(
suffix, // String suffix,
null, // String [] labels, // or null
rendered_texture, // double [][] data,
tilesX * transform_size, // int width, // int tilesX,
tilesY * transform_size); // int height, // int tilesY,
}
if (no_alpha) { if (no_alpha) {
rendered_texture[1] = new double [rendered_texture[0].length]; rendered_texture[1] = new double [rendered_texture[0].length];
for (int i = 0; i < rendered_texture[0].length; i++) { for (int i = 0; i < rendered_texture[0].length; i++) {
......
...@@ -124,7 +124,9 @@ public class XyzAtr { ...@@ -124,7 +124,9 @@ public class XyzAtr {
String.format("%f, %f, %f, %f, %f, %f",ers_xyz_d2t[0], ers_xyz_d2t[1], ers_xyz_d2t[2], ers_atr_d2t[0], ers_atr_d2t[1], ers_atr_d2t[2])}; String.format("%f, %f, %f, %f, %f, %f",ers_xyz_d2t[0], ers_xyz_d2t[1], ers_xyz_d2t[2], ers_atr_d2t[0], ers_atr_d2t[1], ers_atr_d2t[2])};
} }
public double [][] getXYZATR() {
return new double[][] {xyz,atr};
}
public double [] getXYZ() { public double [] getXYZ() {
return xyz; return xyz;
} }
......
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