Commit 2790d745 authored by Andrey Filippov's avatar Andrey Filippov

Before fixing getIMU() and setIMU()

parent c1955bd8
......@@ -29,6 +29,7 @@ import java.util.Properties;
import com.elphel.imagej.common.GenericJTabbedDialog;
public class IntersceneMatchParameters {
public static String [] MODES3D = {"RAW", "INF", "FG", "BG"}; // RAW:-1
// Maybe add parameters to make sure there is enough data? Enough in each zone? Enough spread?
public boolean force_ref_dsi = false; // true;
public boolean force_orientations = false;
......@@ -44,6 +45,7 @@ public class IntersceneMatchParameters {
public boolean generate_mapped = true;
public int extra_hor_tile = 15;
public int extra_vert_tile = 10;
public boolean crop_3d = true; // do not show extra of FG/BG views (currently they only ref scene has disparity)
public int sensor_mask = 1; // -1 - all
public int mode3d = 1; // -1 - raw, 0 - infinity, 1 - FG, 2 - BG
public boolean show_mapped_color = true;
......@@ -53,6 +55,7 @@ public class IntersceneMatchParameters {
public double range_min_strength = 0.5;
public double range_max = 5000.0;
// Other parameters for filtering depth maps
public int num_bottom = 6; // average this number of lowest disparity neighbors (of 8)
public int num_passes = 100;
......@@ -132,6 +135,12 @@ public class IntersceneMatchParameters {
private boolean show_motion_vectors = true; // show calculated motion vectors
public int debug_level = -1; // all renders are disable for debug_level < 0, scene "renders" for for debug_level < 1
// Pairwise ERS testing
public boolean test_ers = false;
public int test_ers0 = -1; // try adjusting a pair of scenes with ERS. Reference scene index
public int test_ers1 = -1; // try adjusting a pair of scenes with ERS. Other scene index
public boolean renderRef() {return (debug_level>1) && render_ref;}
public boolean renderScene() {return (debug_level>1) && render_scene;}
public boolean show2dCorrelations() {return (debug_level>1) && show_2d_correlations;}
......@@ -175,6 +184,7 @@ public class IntersceneMatchParameters {
gd.addNumericField("Maximal displayed range", this.range_max, 5,7,"m",
"Do not display extremely far objects.");
gd.addMessage ("Depth map filtering parameters");
gd.addNumericField("Average lowest disparity neighbors", this.num_bottom, 0,3,"",
"Average this number of lowest disparity neighbors (of 8)");
......@@ -241,10 +251,17 @@ public class IntersceneMatchParameters {
"Enlarge reference scene window horizontally in each direction to accommodate other scenes in a sequence");
gd.addNumericField("Scene sequence vertical extra", this.extra_vert_tile, 0,3,"tiles",
"Enlarge reference scene window vertically in each direction to accommodate other scenes in a sequence");
gd.addCheckbox ("Crop 3D", this.crop_3d,
"Do not enlarge reference scene windows fro 3D views (FG, BG)");
gd.addNumericField("Sensor mask (bitmask, -1 - all sensors)",this.sensor_mask, 0,3,"",
"Select which sensors to be included in each scene of the sequence");
gd.addNumericField("3D mode (-1 - RAW, 0 - infinity, 1 - FG, 2 BG)", this.mode3d, 0, 3, "",
"3D mode for rendering scenes in a sequence: -1 - raw images, 0 - no 3D, use infinity; 1 - Foreground; 2 - Background");
gd. addChoice("3D mode ", MODES3D, MODES3D[this.mode3d + 1],
"3D mode for rendering scenes in a sequence: RAW - raw images, INF - no 3D, use infinity; FG - Foreground; BG - Background");
gd.addCheckbox ("Show scene sequences in (pseudo)colors", this.show_mapped_color,
"Show generated scene sequences in (pseudo)color mode");
gd.addCheckbox ("Show scene sequences in monochrome", this.show_mapped_mono,
......@@ -344,6 +361,15 @@ public class IntersceneMatchParameters {
gd.addNumericField("Debug Level for interscene match", this.debug_level, 0,3,"",
"Debug Level for the above parameters: renders and raw correlations need >1, motion vectors > 0");
gd.addMessage ("Pairwise ERS testing");
gd.addCheckbox ("Replace scene with reference scene", this.test_ers,
"Correlate reference scene with itself for testing (may want to manually change scene_atr and scene_xyz in debug mode)");
gd.addNumericField("Test scene reference index", this.test_ers0, 0,3,"",
"Reference scene index in a scene sequence");
gd.addNumericField("Test scene other scene index", this.test_ers1, 0,3,"",
"Other scene index in a scene sequence (should have a very different angular/linear velocity component)");
}
public void dialogAnswers(GenericJTabbedDialog gd) {
......@@ -392,8 +418,9 @@ public class IntersceneMatchParameters {
this.generate_mapped = gd.getNextBoolean();
this.extra_hor_tile = (int) gd.getNextNumber();
this.extra_vert_tile = (int) gd.getNextNumber();
this.crop_3d = gd.getNextBoolean();
this.sensor_mask = (int) gd.getNextNumber();
this.mode3d = (int) gd.getNextNumber();
this.mode3d = gd.getNextChoiceIndex() - 1;
this.show_mapped_color = gd.getNextBoolean();
this.show_mapped_mono = gd.getNextBoolean();
......@@ -439,6 +466,10 @@ public class IntersceneMatchParameters {
this.show_motion_vectors = gd.getNextBoolean();
this.debug_level = (int) gd.getNextNumber();
this.test_ers = gd.getNextBoolean();
this.test_ers0 = (int) gd.getNextNumber();
this.test_ers1 = (int) gd.getNextNumber();
if (this.weight_zero_neibs > 1.0) this.weight_zero_neibs = 1.0;
}
......@@ -488,6 +519,7 @@ public class IntersceneMatchParameters {
properties.setProperty(prefix+"generate_mapped", this.generate_mapped+""); // boolean
properties.setProperty(prefix+"extra_hor_tile", this.extra_hor_tile+""); // int
properties.setProperty(prefix+"extra_vert_tile", this.extra_vert_tile+""); // int
properties.setProperty(prefix+"crop_3d", this.crop_3d+""); // boolean
properties.setProperty(prefix+"sensor_mask", this.sensor_mask+""); // int
properties.setProperty(prefix+"mode3d", this.mode3d+""); // int
properties.setProperty(prefix+"show_mapped_color", this.show_mapped_color+""); // boolean
......@@ -534,6 +566,11 @@ public class IntersceneMatchParameters {
properties.setProperty(prefix+"show_2d_correlations", this.show_2d_correlations+"");// boolean
properties.setProperty(prefix+"show_motion_vectors", this.show_motion_vectors+""); // boolean
properties.setProperty(prefix+"debug_level", this.debug_level+""); // int
properties.setProperty(prefix+"test_ers", this.test_ers+""); // boolean
properties.setProperty(prefix+"test_ers0", this.test_ers0+""); // int
properties.setProperty(prefix+"test_ers1", this.test_ers1+""); // int
}
public void getProperties(String prefix,Properties properties){
......@@ -582,6 +619,7 @@ public class IntersceneMatchParameters {
if (properties.getProperty(prefix+"generate_mapped")!=null) this.generate_mapped=Boolean.parseBoolean(properties.getProperty(prefix+"generate_mapped"));
if (properties.getProperty(prefix+"extra_hor_tile")!=null) this.extra_hor_tile=Integer.parseInt(properties.getProperty(prefix+"extra_hor_tile"));
if (properties.getProperty(prefix+"extra_vert_tile")!=null) this.extra_vert_tile=Integer.parseInt(properties.getProperty(prefix+"extra_vert_tile"));
if (properties.getProperty(prefix+"crop_3d")!=null) this.crop_3d=Boolean.parseBoolean(properties.getProperty(prefix+"crop_3d"));
if (properties.getProperty(prefix+"sensor_mask")!=null) this.sensor_mask=Integer.parseInt(properties.getProperty(prefix+"sensor_mask"));
if (properties.getProperty(prefix+"mode3d")!=null) this.mode3d=Integer.parseInt(properties.getProperty(prefix+"mode3d"));
if (properties.getProperty(prefix+"show_mapped_color")!=null) this.show_mapped_color=Boolean.parseBoolean(properties.getProperty(prefix+"show_mapped_color"));
......@@ -627,6 +665,9 @@ public class IntersceneMatchParameters {
if (properties.getProperty(prefix+"show_2d_correlations")!=null) this.show_2d_correlations=Boolean.parseBoolean(properties.getProperty(prefix+"show_2d_correlations"));
if (properties.getProperty(prefix+"show_motion_vectors")!=null) this.show_motion_vectors=Boolean.parseBoolean(properties.getProperty(prefix+"show_motion_vectors"));
if (properties.getProperty(prefix+"debug_level")!=null) this.debug_level=Integer.parseInt(properties.getProperty(prefix+"debug_level"));
if (properties.getProperty(prefix+"test_ers")!=null) this.test_ers=Boolean.parseBoolean(properties.getProperty(prefix+"test_ers"));
if (properties.getProperty(prefix+"test_ers0")!=null) this.test_ers0=Integer.parseInt(properties.getProperty(prefix+"test_ers0"));
if (properties.getProperty(prefix+"test_ers1")!=null) this.test_ers1=Integer.parseInt(properties.getProperty(prefix+"test_ers1"));
}
@Override
......@@ -677,6 +718,7 @@ public class IntersceneMatchParameters {
imp.generate_mapped = this.generate_mapped;
imp.extra_hor_tile = this.extra_hor_tile;
imp.extra_vert_tile = this.extra_vert_tile;
imp.crop_3d = this.crop_3d;
imp.sensor_mask = this.sensor_mask;
imp.mode3d = this.mode3d;
imp.show_mapped_color = this.show_mapped_color;
......
......@@ -3976,12 +3976,16 @@ public class OpticalFlow {
boolean generate_mapped = clt_parameters.imp.generate_mapped;
int extra_hor_tile = clt_parameters.imp.extra_hor_tile;
int extra_vert_tile = clt_parameters.imp.extra_vert_tile;
boolean crop_3d = clt_parameters.imp.crop_3d;
int sensor_mask = clt_parameters.imp.sensor_mask; // -1 - all
int mode3d = clt_parameters.imp.mode3d; // 0 - infinity, 1 - FG, 2 - BG
boolean show_mapped_color = clt_parameters.imp.show_mapped_color;
boolean show_mapped_mono = clt_parameters.imp.show_mapped_mono;
boolean test_ers = clt_parameters.imp.test_ers;
int test_ers0 = clt_parameters.imp.test_ers0; // try adjusting a pair of scenes with ERS. Reference scene index
int test_ers1 = clt_parameters.imp.test_ers1; // try adjusting a pair of scenes with ERS. Other scene index
test_ers &= (test_ers0 >= 0) && (test_ers1 >= 0);
final int debugLevelInner=clt_parameters.batch_run? -2: debugLevel; // copied from TQ
......@@ -4230,6 +4234,32 @@ public class OpticalFlow {
debugLevel); // int debug_level
}
if (test_ers) {
test_ers0 = quadCLTs.length -1; // make it always == reference !
if (!build_orientations && !build_interscene) {
for (int nscene = 0; nscene < (quadCLTs.length -1); nscene++) {
if ((Math.abs(nscene - test_ers0) <= 1) || (Math.abs(nscene - test_ers1) <= 1)) {
quadCLTs[nscene] = (QuadCLT) quadCLT_main.spawnNoModelQuadCLT( // restores image data
set_channels[nscene].set_name,
clt_parameters,
colorProcParameters, //
threadsMax,
debugLevel-2);
}
}
}
testERS(
clt_parameters, // CLTParameters clt_parameters,
test_ers0, // int indx0, // reference scene in a pair
test_ers1, // int indx1, // other scene in a pair
// double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
debugLevel); // int debugLevel)
System.out.println("buildSeries(): ABORTED after test_ers"); //
return true;
}
if (generate_mapped) {
if (!build_orientations && !build_interscene) {
for (int scene_index = ref_index - 1; scene_index >= 0 ; scene_index--) {
......@@ -4241,13 +4271,10 @@ public class OpticalFlow {
debugLevel-2);
}
}
double [] selected_disparity = null;
int tilesX = quadCLTs[ref_index].getTileProcessor().getTilesX();
int tilesY = quadCLTs[ref_index].getTileProcessor().getTilesY();
if (mode3d == 0) {
selected_disparity = new double [tilesX * tilesY];
Arrays.fill(selected_disparity,clt_parameters.disparity);
} else {
double [] disparity_raw = new double [tilesX * tilesY];
Arrays.fill(disparity_raw,clt_parameters.disparity);
if (combo_dsn_final == null) {
combo_dsn_final = quadCLTs[ref_index].readDoubleArrayFromModelDirectory(
"-INTER-INTRA-LMA", // String suffix,
......@@ -4266,8 +4293,8 @@ public class OpticalFlow {
quadCLTs[ref_index], // QuadCLT scene,
debugLevel);
selected_disparity = ds[0]; // combo_dsn_final[COMBO_DSN_INDX_DISP_FG];
if (mode3d > 1) { // BG mode
double [] disparity_fg = ds[0]; // combo_dsn_final[COMBO_DSN_INDX_DISP_FG];
// BG mode
double [] bg_lma = combo_dsn_final[COMBO_DSN_INDX_DISP_BG_ALL].clone();
double [] bg_str = combo_dsn_final[COMBO_DSN_INDX_STRENGTH].clone();
......@@ -4293,9 +4320,7 @@ public class OpticalFlow {
dls_bg, // double [][] dls
quadCLTs[ref_index], // QuadCLT scene,
debugLevel);
selected_disparity = ds_bg[0]; // combo_dsn_final[COMBO_DSN_INDX_DISP_FG];
}
}
double [] disparity_bg = ds_bg[0]; // combo_dsn_final[COMBO_DSN_INDX_DISP_FG];
// for now using disparity for just standard size (90x64), later may use full size and at
// minimum fill peripheral areas with Laplassian?
Rectangle fov_tiles = new Rectangle(
......@@ -4303,14 +4328,57 @@ public class OpticalFlow {
extra_vert_tile,
tilesX + 2 * extra_hor_tile,
tilesY + 2 * extra_vert_tile);
boolean toRGB = !show_mapped_mono; // false; // true;// ** TEMPORARILY **
if ((mode3d < 0) || (crop_3d && (mode3d > 0))) {
fov_tiles = null; // use sensor dimensions
}
double [][] dxyzatr_dt = new double [quadCLTs.length][];
int [][] min_max_vel = getERSStats(
clt_parameters, // CLTParameters clt_parameters,
quadCLTs, // QuadCLT [] quadCLTs,
dxyzatr_dt); // double [][] dxyzatr_dt);
double [] vel_avg = new double [min_max_vel.length];
int navg = 0;
for (int n = 0; n < dxyzatr_dt.length; n++) if (dxyzatr_dt[n] != null){
for (int i = 0; i < vel_avg.length; i++) {
vel_avg[i] += dxyzatr_dt[n][i];
}
navg++;
}
for (int i = 0; i < vel_avg.length; i++) {
vel_avg[i] /= navg;
}
String [] vel_names = {"Vx","Vy","Vz","Vaz","Vtl","Vrl"};
String [] vel_units = {"m/s","m/s","m/s","mrad/s","mrad/s","mrad/s","mrad/s"};
System.out.println("Minimal/maximal/average linear and angular velocities of the scenes (ref. scene: "+
quadCLTs[quadCLTs.length - 1].getImageName()+")");
for (int i = 0; i < min_max_vel.length; i++) {
double v0 = dxyzatr_dt[min_max_vel[i][0]][i];
double v1 = dxyzatr_dt[min_max_vel[i][1]][i];
double va = vel_avg[i];
if (i == 2) { // forward movement
v0*=-1;
v1*=-1;
va*=-1;
}
if (i > 2) { // angular
v0*=1000;
v1*=1000;
va*=1000;
}
System.out.println(String.format(
"%3s: min: %3d (%8.3f%-6s), max: %3d (%8.3f%-6s), average: %8.3f%-6s",
vel_names[i], min_max_vel[i][0], v0, vel_units[i],
min_max_vel[i][1], v1, vel_units[i],
va, vel_units[i]));
}
for (int col_mode = 0; col_mode<2; col_mode++) {
// mode3d = col_mode/2 -1 ; // col_mode < 6
double[] selected_disparity = (mode3d > 1)?disparity_bg:((mode3d > 0)?disparity_fg: disparity_raw);
boolean toRGB = (col_mode & 1) == 0;
String scenes_suffix = quadCLTs[quadCLTs.length-1].getImageName()+
"-SEQ-"; // MOD3D"+mode3d + "-"+(toRGB?"COLOR":"MONO");
if (mode3d < 0) scenes_suffix+="RAW";
else if (mode3d == 0) scenes_suffix+="INF";
else if (mode3d == 1) scenes_suffix+="FG";
else if (mode3d == 2) scenes_suffix+="BG";
scenes_suffix += "-"+(toRGB?"COLOR":"MONO");
"-SEQ-" + IntersceneMatchParameters.MODES3D[mode3d+1] + "-"+(toRGB?"COLOR":"MONO");
ImagePlus imp_scenes = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
fov_tiles, // Rectangle fov_tiles,
......@@ -4321,17 +4389,12 @@ public class OpticalFlow {
selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
debugLevel); // int debugLevel);
quadCLTs[ref_index].saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_scenes); // ImagePlus imp)
if (show_mapped_color) {
imp_scenes.show();
/*
if (show_images_mono) {
if (toRGB ? show_mapped_color: show_mapped_mono) {
imp_scenes.show();
}
*/
}
}
if (export_images) {
......@@ -4543,6 +4606,224 @@ public class OpticalFlow {
return true;
}
public void testERS(
CLTParameters clt_parameters,
int indx0, // reference scene in a pair
int indx1, // other scene in a pair
// double [] ref_disparity,
QuadCLT [] quadCLTs,
int debugLevel) {
// First create a pair of images, similar to renderSceneSequence()
boolean toRGB = true;
int ref_index = quadCLTs.length-1;
indx0 = ref_index; // disregard initial setting, set to reference
int tilesX = quadCLTs[ref_index].getTileProcessor().getTilesX();
int tilesY = quadCLTs[ref_index].getTileProcessor().getTilesY();
double [] disparity_raw = new double [tilesX * tilesY];
Arrays.fill(disparity_raw,clt_parameters.disparity);
double [][] combo_dsn_final = quadCLTs[ref_index].readDoubleArrayFromModelDirectory(
"-INTER-INTRA-LMA", // String suffix,
0, // int num_slices, // (0 - all)
null); // int [] wh);
double [][] dls = {
combo_dsn_final[COMBO_DSN_INDX_DISP],
combo_dsn_final[COMBO_DSN_INDX_LMA],
combo_dsn_final[COMBO_DSN_INDX_STRENGTH]
};
double [][] ds = conditionInitialDS(
true, // boolean use_conf, // use configuration parameters, false - use following
clt_parameters, // CLTParameters clt_parameters,
dls, // double [][] dls
quadCLTs[ref_index], // QuadCLT scene,
debugLevel);
double [] disparity_fg = ds[0]; // combo_dsn_final[COMBO_DSN_INDX_DISP_FG];
// QuadCLT [] other_ref = {quadCLTs[indx1],quadCLTs[indx0]};
int [] other_ref = {indx1, indx0};
ErsCorrection ers_reference = quadCLTs[ref_index].getErsCorrection();
ImageStack stack_scenes = null;
int sensor_num = 0;
int sensor_mask = 1 << sensor_num;
String suffix = quadCLTs[indx0].getImageName()+"-"+quadCLTs[indx1].getImageName()+"-ERS_TEST";
double [][] dxyzatr_dt = new double[quadCLTs.length][];
for (int iscene = 0; iscene <2; iscene++) {
int nscene = other_ref[iscene];
String ts = quadCLTs[nscene].getImageName();
int nscene0 = nscene - ((nscene >0)? 1:0);
int nscene1 = nscene + ((nscene < ref_index)? 1:0);
double dt = quadCLTs[nscene1].getTimeStamp() - quadCLTs[nscene0].getTimeStamp();
String ts0 = quadCLTs[nscene0].getImageName();
String ts1 = quadCLTs[nscene1].getImageName();
double [] scene_xyz0 = ers_reference.getSceneXYZ(ts0);
double [] scene_atr0 = ers_reference.getSceneATR(ts0);
double [] scene_xyz1 = (nscene1== ref_index)? ZERO3:ers_reference.getSceneXYZ(ts1);
double [] scene_atr1 = (nscene1== ref_index)? ZERO3:ers_reference.getSceneATR(ts1);
dxyzatr_dt[nscene] = new double[6];
for (int i = 0; i < 3; i++) {
dxyzatr_dt[nscene][i] = (scene_xyz1[i]-scene_xyz0[i])/dt;
dxyzatr_dt[nscene][i + 3] = (scene_atr1[i]-scene_atr0[i])/dt;
}
double [] scene_xyz = ZERO3;
double [] scene_atr = ZERO3;
if (nscene != ref_index) {
scene_xyz = ers_reference.getSceneXYZ(ts);
scene_atr = ers_reference.getSceneATR(ts);
double [] scene_ers_xyz_dt = ers_reference.getSceneErsXYZ_dt(ts);
double [] scene_ers_atr_dt = ers_reference.getSceneErsATR_dt(ts);
quadCLTs[nscene].getErsCorrection().setErsDt(
scene_ers_xyz_dt, // double [] ers_xyz_dt,
scene_ers_atr_dt); // double [] ers_atr_dt)(ers_scene_original_xyz_dt);
}
ImagePlus imp_scene = QuadCLT.renderGPUFromDSI(
sensor_mask, // final int sensor_mask,
null, // final Rectangle full_woi_in, // show larger than sensor WOI (or null)
clt_parameters, // CLTParameters clt_parameters,
disparity_fg, // double [] disparity_ref,
scene_xyz, // final double [] scene_xyz, // camera center in world coordinates
scene_atr, // final double [] scene_atr, // camera orientation relative to world frame
quadCLTs[nscene], // final QuadCLT scene,
toRGB, // final boolean toRGB,
"", // String suffix, no suffix here
threadsMax, // int threadsMax,
debugLevel); // int debugLevel)
if (stack_scenes == null) {
stack_scenes = new ImageStack(imp_scene.getWidth(),imp_scene.getHeight());
}
stack_scenes.addSlice(
nscene+":"+ts,
imp_scene.getStack().getPixels(sensor_num+1));
}
ImagePlus imp_scenes = new ImagePlus(suffix, stack_scenes);
imp_scenes.getProcessor().resetMinAndMax();
imp_scenes.show();
String [] vel_names = {"Vx","Vy","Vz","Vaz","Vtl","Vrl"};
String [] vel_units = {"m/s","m/s","m/s","rad/s","rad/s","rad/s","rad/s"};
System.out.println("Pair: ref. scene "+indx0+": ("+quadCLTs[indx0].getImageName()+")"+
", other scene "+indx1+": ("+quadCLTs[indx1].getImageName()+")");
for (int i = 0; i < vel_names.length; i++) {
System.out.println(String.format(
"%3s: other: %3d (%8.3f%-6s), ref: %3d (%8.3f%-6s)",
vel_names[i], other_ref[0], dxyzatr_dt[other_ref[0]][i], vel_units[i],
other_ref[1], dxyzatr_dt[other_ref[1]][i], vel_units[i]));
}
double [] scene_xyz_pre = ZERO3;
double [] scene_atr_pre = ZERO3;
String ts_other = quadCLTs[other_ref[0]].getImageName(); // other scene
scene_xyz_pre = ers_reference.getSceneXYZ(ts_other);
scene_atr_pre = ers_reference.getSceneATR(ts_other);
double [] scene_ers_xyz_dt = ers_reference.getSceneErsXYZ_dt(ts_other);
double [] scene_ers_atr_dt = ers_reference.getSceneErsATR_dt(ts_other);
quadCLTs[other_ref[0]].getErsCorrection().setErsDt(
scene_ers_xyz_dt, // double [] ers_xyz_dt,
scene_ers_atr_dt); // double [] ers_atr_dt)(ers_scene_original_xyz_dt);
double [] lma_rms = new double[2];
double [][] adjusted_xyzatr = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters,
quadCLTs[other_ref[1]], // QuadCLT reference_QuadCLT,
quadCLTs[other_ref[0]], // QuadCLT scene_QuadCLT,
scene_xyz_pre, // xyz
scene_atr_pre, // atr
clt_parameters.ilp.ilma_lma_select, // final boolean[] param_select,
clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights,
lma_rms, // double [] rms, // null or double [2]
clt_parameters.imp.max_rms, // double max_rms,
clt_parameters.imp.debug_level); // 1); // -1); // int debug_level);
System.out.println("lma_rms={"+lma_rms[0]+","+lma_rms[1]+"}");
ImageStack stack_adjusted = null;
String suffix_adjusted = quadCLTs[indx0].getImageName()+"-"+quadCLTs[indx1].getImageName()+"-ERS_TEST_ADJUSTED";
for (int iscene = 0; iscene <2; iscene++) {
int nscene = other_ref[iscene];
String ts = quadCLTs[nscene].getImageName();
double [] scene_xyz = ZERO3;
double [] scene_atr = ZERO3;
if (nscene != ref_index) {
scene_xyz = ers_reference.getSceneXYZ(ts);
scene_atr = ers_reference.getSceneATR(ts);
double [] scene_ers_xyz_dt1 = ers_reference.getSceneErsXYZ_dt(ts);
double [] scene_ers_atr_dt1 = ers_reference.getSceneErsATR_dt(ts);
quadCLTs[nscene].getErsCorrection().setErsDt(
scene_ers_xyz_dt1, // double [] ers_xyz_dt,
scene_ers_atr_dt1); // double [] ers_atr_dt)(ers_scene_original_xyz_dt);
}
ImagePlus imp_scene = QuadCLT.renderGPUFromDSI(
sensor_mask, // final int sensor_mask,
null, // final Rectangle full_woi_in, // show larger than sensor WOI (or null)
clt_parameters, // CLTParameters clt_parameters,
disparity_fg, // double [] disparity_ref,
scene_xyz, // final double [] scene_xyz, // camera center in world coordinates
scene_atr, // final double [] scene_atr, // camera orientation relative to world frame
quadCLTs[nscene], // final QuadCLT scene,
toRGB, // final boolean toRGB,
"", // String suffix, no suffix here
threadsMax, // int threadsMax,
debugLevel); // int debugLevel)
if (stack_adjusted == null) {
stack_adjusted = new ImageStack(imp_scene.getWidth(),imp_scene.getHeight());
}
stack_adjusted.addSlice(
nscene+":"+ts,
imp_scene.getStack().getPixels(sensor_num+1));
}
ImagePlus imp_adjusted = new ImagePlus(suffix_adjusted, stack_adjusted);
imp_adjusted.getProcessor().resetMinAndMax();
imp_adjusted.show();
return;
}
public static int [][] getERSStats(
CLTParameters clt_parameters,
QuadCLT [] quadCLTs,
double [][] dxyzatr_dt) {
int ref_index = quadCLTs.length -1;
ErsCorrection ers_reference = quadCLTs[ref_index].getErsCorrection();
int dbg_scene = -95;
int [][] min_max_xyzatr = new int [6][2];
for (int i = 0; i < min_max_xyzatr.length; i++) {
Arrays.fill(min_max_xyzatr[i],-1);
}
if (dxyzatr_dt == null) {
dxyzatr_dt = new double[quadCLTs.length][];
} else {
Arrays.fill(dxyzatr_dt, null);
}
for (int nscene = 0; nscene < quadCLTs.length ; nscene++) if (quadCLTs[nscene] != null){
if (nscene== dbg_scene) {
System.out.println("renderSceneSequence(): nscene = "+nscene);
}
int nscene0 = nscene - ((nscene >0)? 1:0);
int nscene1 = nscene + ((nscene < ref_index)? 1:0);
double dt = quadCLTs[nscene1].getTimeStamp() - quadCLTs[nscene0].getTimeStamp();
String ts0 = quadCLTs[nscene0].getImageName();
String ts1 = quadCLTs[nscene1].getImageName();
double [] scene_xyz0 = ers_reference.getSceneXYZ(ts0);
double [] scene_atr0 = ers_reference.getSceneATR(ts0);
double [] scene_xyz1 = (nscene1== ref_index)? ZERO3:ers_reference.getSceneXYZ(ts1);
double [] scene_atr1 = (nscene1== ref_index)? ZERO3:ers_reference.getSceneATR(ts1);
dxyzatr_dt[nscene] = new double[6];
for (int i = 0; i < 3; i++) {
dxyzatr_dt[nscene][i] = (scene_xyz1[i]-scene_xyz0[i])/dt;
dxyzatr_dt[nscene][i + 3] = (scene_atr1[i]-scene_atr0[i])/dt;
}
for (int i = 0; i < dxyzatr_dt[nscene].length; i++) {
if ((min_max_xyzatr[i][0] < 0) || // update index of minimum
(dxyzatr_dt[nscene][i] < dxyzatr_dt[min_max_xyzatr[i][0]][i]) ) {
min_max_xyzatr[i][0] = nscene;
}
if ((min_max_xyzatr[i][1] < 0) || // update index of maximum
(dxyzatr_dt[nscene][i] > dxyzatr_dt[min_max_xyzatr[i][1]][i]) ) {
min_max_xyzatr[i][1] = nscene;
}
}
}
return min_max_xyzatr;
}
public ImagePlus renderSceneSequence(
CLTParameters clt_parameters,
Rectangle fov_tiles,
......@@ -4563,7 +4844,7 @@ public class OpticalFlow {
int nch = 0;
for (int i = 0; i < num_sens; i++) if (((sensor_mask >> i) & 1) != 0) channels[nch++] = i;
ImageStack stack_scenes = null;
int dbg_scene = 95;
int dbg_scene = -95;
for (int nscene = 0; nscene < quadCLTs.length ; nscene++) if (quadCLTs[nscene] != null){
if (nscene== dbg_scene) {
System.out.println("renderSceneSequence(): nscene = "+nscene);
......
......@@ -2684,7 +2684,7 @@ public class QuadCLTCPU {
}
}
}
public double []reformatKernel2( // averages by exactly 2 (decimate==2) // not used in lwir
public static double []reformatKernel2( // averages by exactly 2 (decimate==2) // not used in lwir
double [] src_kernel, //
int src_size,
int dst_size){
......@@ -2697,7 +2697,7 @@ public class QuadCLTCPU {
return dst_kernel;
}
private void reformatKernel2( // averages by exactly 2 (decimate==2) // not used in lwir
private static void reformatKernel2( // averages by exactly 2 (decimate==2) // not used in lwir
double [] src_kernel, //
double [] dst_kernel,
int src_size,
......@@ -2739,7 +2739,7 @@ public class QuadCLTCPU {
}
public ImageStack YPrPbToRGB(double [][] yPrPb, // USED in lwir
public static ImageStack YPrPbToRGB(double [][] yPrPb, // USED in lwir
double Kr, // 0.299;
double Kb, // 0.114;
int width
......@@ -2779,7 +2779,7 @@ public class QuadCLTCPU {
}
public double [][] YPrPbToRBG(double [][] yPrPb, // not used in lwir
public static double [][] YPrPbToRBG(double [][] yPrPb, // not used in lwir
double Kr, // 0.299;
double Kb, // 0.114;
int width
......@@ -2812,13 +2812,13 @@ public class QuadCLTCPU {
return rbg;
}
public void debayer_rbg( // not used in lwir
public static void debayer_rbg( // not used in lwir
ImageStack stack_rbg){
debayer_rbg(stack_rbg, 1.0);
}
// Simple in-place debayer by (bi) linear approximation, assumes [0R/00], [00/B0], [G0/0G] slices
public void debayer_rbg( // not used in lwir
public static void debayer_rbg( // not used in lwir
ImageStack stack_rbg,
double scale)
{
......@@ -5363,9 +5363,7 @@ public class QuadCLTCPU {
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
}
public void channelGainsEqualize( // USED in lwir
public static void channelGainsEqualize( // USED in lwir
boolean gain_equalize,
boolean colors_equalize,
boolean nosat_equalize,
......@@ -5397,7 +5395,7 @@ public class QuadCLTCPU {
debugLevel);
}
}
public void channelGainsEqualize_old( // not used in lwir
public static void channelGainsEqualize_old( // not used in lwir
boolean gain_equalize,
boolean colors_equalize,
boolean nosat_equalize,
......@@ -5471,7 +5469,7 @@ public class QuadCLTCPU {
}
}
public void channelGainsEqualize_new( // USED in lwir
public static void channelGainsEqualize_new( // USED in lwir
boolean gain_equalize,
boolean colors_equalize,
boolean nosat_equalize,
......@@ -5574,7 +5572,7 @@ public class QuadCLTCPU {
}
}
}
public double [] channelLwirEqualize( // USED in lwir
public static double [] channelLwirEqualize( // USED in lwir
int [] channelFiles,
ImagePlus [] imp_srcs,
boolean remove_dc,
......@@ -5583,9 +5581,6 @@ public class QuadCLTCPU {
int debugLevel){
double [] offsets = new double [channelFiles.length];
double [][] avr_pix = new double [channelFiles.length][2]; // val/weight
// double [] wnd_x = {};
// double [] wnd_y = {};
// double total_s = 0.0, total_w = 0.0;
DoubleAccumulator atotal_s = new DoubleAccumulator(Double::sum, 0L);
DoubleAccumulator atotal_w = new DoubleAccumulator(Double::sum, 0L);
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
......@@ -6667,43 +6662,12 @@ public class QuadCLTCPU {
z_correction +=clt_parameters.z_corr_map.get(name);// not used in lwir
}
final double disparity_corr = (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
/*
double [][] lazy_eye_data = image_dtt.cltMeasureLazyEye(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
tile_op, // per-tile operation bit codes
disparity_array, // final double disparity,
image_data, // double_stacks, // final double [][][] imade_data, // first index - number of image in a quad
saturation_imp, // boolean [][] saturation_imp, // (near) saturated pixels or null
clt_mismatch, // [12][tp.tilesY * tp.tilesX] // transpose unapplied. null - do not calculate
disparity_map, // [2][tp.tilesY * tp.tilesX]
imp_quad[0].getWidth(), // final int width,
clt_parameters.getFatZero(isMonochrome()), // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
clt_parameters.corr_red,
clt_parameters.corr_blue,
clt_parameters.getCorrSigma(image_dtt.isMonochrome()),
min_corr_selected, // 0.0001; // minimal correlation value to consider valid
geometryCorrection, // final GeometryCorrection geometryCorrection,
null, // final GeometryCorrection geometryCorrection_main, // if not null correct this camera (aux) to the coordinates of the main
clt_kernels, // final double [][][][][][] clt_kernels, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
clt_parameters.kernel_step,
clt_parameters.clt_window,
shiftXY, //
disparity_corr, // final double disparity_corr, // disparity at infinity
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing
clt_parameters.shift_y, // final int shiftY, // shift image vertically (positive - down)
clt_parameters.tileStep, // final int tileStep, // process tileStep x tileStep cluster of tiles when adjusting lazy eye parameters
clt_parameters.tileX, // -1234, // clt_parameters.tileX, // final int debug_tileX,
clt_parameters.tileY, // final int debug_tileY, -1234 will cause port coordinates debug images
threadsMax,
debugLevel);
*/
double [][] lazy_eye_data = image_dtt.cltMeasureLazyEye ( // returns d,s lazy eye parameters
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
tile_op, // final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
disparity_array, // final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
image_data, // final double [][][] imade_data, // first index - number of image in a quad
saturation_imp, // final boolean [][] saturation_imp, // (near) saturated pixels or null
// tilesX * image_dtt.transform_size, // final int width,
geometryCorrection.getSensorWH()[0], // final int width,
clt_parameters.getFatZero(isMonochrome()), // final double corr_fat_zero, // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
clt_parameters.corr_red, // final double corr_red,
......@@ -6713,7 +6677,6 @@ public class QuadCLTCPU {
geometryCorrection, // final GeometryCorrection geometryCorrection,
null, // final GeometryCorrection geometryCorrection_main, // if not null correct this camera (aux) to the coordinates of the main
clt_kernels, // final double [][][][][][] clt_kernels, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
// clt_parameters.kernel_step, // final int kernel_step,
clt_parameters.clt_window, // final int window_type,
shiftXY, // final double [][] shiftXY, // [port]{shiftX,shiftY}
disparity_corr, // final double disparity_corr, // disparity at infinity
......@@ -6732,8 +6695,6 @@ public class QuadCLTCPU {
threadsMax, // final int threadsMax, // maximal number of threads to launch
debugLevel - 2); // final int globalDebugLevel)
if (lazy_eye_data != null) {
int clustersX= (tilesX + clt_parameters.tileStep - 1) / clt_parameters.tileStep;
int clustersY= (tilesY + clt_parameters.tileStep - 1) / clt_parameters.tileStep;
......@@ -6903,7 +6864,7 @@ public class QuadCLTCPU {
return results;
}
double [][] resizeGridTexture( // USED in lwir
static double [][] resizeGridTexture( // USED in lwir
double [][] imgData,
int tileSize,
int tilesX,
......@@ -6928,7 +6889,7 @@ public class QuadCLTCPU {
}
return rslt;
}
public int [] getLwirHistogram( // USED in lwir
public static int [] getLwirHistogram( // USED in lwir
double [] data,
double hard_cold,
double hard_hot,
......@@ -6943,14 +6904,14 @@ public class QuadCLTCPU {
}
return hist;
}
public int [] getLwirHistogram( // USED in lwir
public static int [] getLwirHistogram( // USED in lwir
float [] data,
double hard_cold,
double hard_hot,
int num_bins) {
int [] hist = new int [num_bins];
double k = num_bins / (hard_hot - hard_cold);
for (double d:data) {
for (double d:data) if (!Double.isNaN(d)){
int bin = (int) ((d - hard_cold)*k);
if (bin < 0) bin = 0;
else if (bin >= num_bins) bin = (num_bins -1);
......@@ -6958,7 +6919,7 @@ public class QuadCLTCPU {
}
return hist;
}
public int [] addHist( // USED in lwir
public static int [] addHist( // USED in lwir
int [] this_hist,
int [] other_hist) {
for (int i = 0; i < this_hist.length; i++) {
......@@ -6968,7 +6929,7 @@ public class QuadCLTCPU {
}
// get low/high (soft min/max) from the histogram
// returns value between 0.0 (low histogram limit and 1.0 - high histgram limit
public double getMarginFromHist( // USED in lwir
public static double getMarginFromHist( // USED in lwir
int [] hist, // histogram
double cumul_val, // cummulative number of items to be ignored
boolean high_marg) { // false - find low margin(output ~0.0) , true - find high margin (output ~1.0)
......@@ -7004,19 +6965,25 @@ public class QuadCLTCPU {
return v;
}
public double [] autorange( // USED in lwir
public static double [] autorange( // USED in lwir
double [][][] iclt_data, // [iQuad][ncol][i] - normally only [][2][] is non-null
double hard_cold,// matches data, DC (this.lwir_offset) subtracted
double hard_hot, // matches data, DC (this.lwir_offset) subtracted
double too_cold, // pixels per image
double too_hot, // pixels per image
int num_bins) {
int ncol;
for (ncol = 0; ncol < iclt_data[0].length; ncol++) {
if (iclt_data[0][ncol] != null) break;
int num_chn = 0;
int ncol=0;
for (int nsens = 0; nsens < iclt_data.length; nsens++) if (iclt_data[nsens] != null) {
num_chn++;
if (ncol==0) {
for (ncol = 0; ncol < iclt_data[nsens].length; ncol++) {
if (iclt_data[nsens][ncol] != null) break;
}
too_cold *= iclt_data.length;
too_hot *= iclt_data.length;
}
}
too_cold *= num_chn; // iclt_data.length;
too_hot *= num_chn; // iclt_data.length;
int [] hist = null;
for (int iQuad = 0; iQuad < iclt_data.length; iQuad++) {
int [] this_hist = getLwirHistogram(
......@@ -7048,7 +7015,7 @@ public class QuadCLTCPU {
return abs_lim;
}
public double [] autorange( // USED in lwir
public static double [] autorange( // USED in lwir
float [][][] iclt_data, // [iQuad][ncol][i] - normally only [][2][] is non-null
double hard_cold,// matches data, DC (this.lwir_offset) subtracted
double hard_hot, // matches data, DC (this.lwir_offset) subtracted
......@@ -8043,88 +8010,6 @@ public class QuadCLTCPU {
}
}
public double [][] process_disparity_scan( // not used in lwir
double [][] disparities_maps,
double disp_step,
double disp_start,
double min_strength)
{
final int num_items = 5;
final int index_strength = 3;
final int index_cm = 1;
final int index_poly = 1;
final int ind_b_cm = 0;
final int ind_b_poly = 1;
final int ind_a_cm = 2;
final int ind_a_poly = 3;
final int ind_rms_cm = 4;
final int ind_rms_poly = 5;
final int ind_strength = 6;
final int ind_samples = 7;
final int num_steps = disparities_maps.length / num_items; // int, cm, poly, strength, variety
final int disp_len = disparities_maps[0].length;
double [][] rslt = new double [8][disp_len];
for (int i = 0; i < disp_len; i++){
double s0 = 0.0, sx = 0.0, sx2 = 0.0, sy_cm = 0.0, sxy_cm = 0.0, sy_poly = 0.0, sxy_poly = 0.0;
int samples = 0;
for (int step = 0; step < num_steps; step++ ){
double wi = disparities_maps[num_items*step + index_strength][i];
if (wi > min_strength) {
double xi = disp_start + step * disp_step;
double yi_cm = disparities_maps[num_items*step + index_cm][i];
double yi_poly = disparities_maps[num_items*step + index_poly][i];
if (Double.isNaN(yi_cm) || Double.isNaN(yi_poly)) continue;
s0 += wi;
sx += wi*xi;
sx2 += wi*xi*xi;
sy_cm += wi*yi_cm;
sxy_cm += wi*xi*yi_cm;
sy_poly += wi*yi_poly;
sxy_poly += wi*xi*yi_poly;
samples++;
}
}
double denom = (s0*sx2 - sx*sx);
rslt[ind_strength][i] = s0;
rslt[ind_samples][i] = samples;
if (denom != 0.0) {
rslt[ind_a_cm][i] = (s0*sxy_cm - sx*sy_cm) / denom;
rslt[ind_b_cm][i] = (sy_cm*sx2 - sx*sxy_cm) / denom;
rslt[ind_a_poly][i] = (s0*sxy_poly - sx*sy_poly) / denom;
rslt[ind_b_poly][i] = (sy_poly*sx2 - sx*sxy_poly) / denom;
rslt[ind_rms_cm][i] = 0.0;
rslt[ind_rms_poly][i] = 0.0;
for (int step = 0; step < num_steps; step++ ){
double wi = disparities_maps[num_items*step + index_strength][i];
if (wi > min_strength) {
double xi = disp_start + step * disp_step;
double yi_cm = disparities_maps[num_items*step + index_cm][i];
double yi_poly = disparities_maps[num_items*step + index_poly][i];
if (Double.isNaN(yi_cm) || Double.isNaN(yi_poly)) continue;
double d_cm = yi_cm - (rslt[ind_a_cm][i]*xi +rslt[ind_b_cm][i]);
double d_poly = yi_poly - (rslt[ind_a_poly][i]*xi +rslt[ind_b_poly][i]);
rslt[ind_rms_cm][i] += wi*d_cm*d_cm;
rslt[ind_rms_poly][i] += wi*d_poly*d_poly;
}
}
rslt[ind_rms_cm][i] = Math.sqrt(rslt[ind_rms_cm][i]/s0);
rslt[ind_rms_poly][i] = Math.sqrt(rslt[ind_rms_cm][i]/s0);
} else {
rslt[ind_a_cm][i] = Double.NaN;
rslt[ind_b_cm][i] = Double.NaN;
rslt[ind_a_poly][i] = Double.NaN;
rslt[ind_b_poly][i] = Double.NaN;
rslt[ind_rms_cm][i] = Double.NaN;
rslt[ind_rms_poly][i] = Double.NaN;
}
}
return rslt;
}
public void showCLTPlanes( // not used in lwir
CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
......
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