Commit b5d06bab authored by Andrey Filippov's avatar Andrey Filippov

misalignment - converted to true rotations

parent 770a8d96
...@@ -612,11 +612,13 @@ public class AlignmentCorrection { ...@@ -612,11 +612,13 @@ public class AlignmentCorrection {
mdata = new double [8][samples_list.size()][3]; mdata = new double [8][samples_list.size()][3];
} }
int indx = 0; int indx = 0;
final Matrix [] corr_rots = qc.geometryCorrection.getCorrVector().getRotMatrices(); // get array of per-sensor rotation matrices
for (Sample s: samples_list){ for (Sample s: samples_list){
int tileX = s.tile % tilesX; int tileX = s.tile % tilesX;
int tileY = s.tile / tilesX; int tileY = s.tile / tilesX;
double centerX = tileX * qc.tp.getTileSize() + qc.tp.getTileSize()/2;// - shiftX; double centerX = tileX * qc.tp.getTileSize() + qc.tp.getTileSize()/2;// - shiftX;
double centerY = tileY * qc.tp.getTileSize() + qc.tp.getTileSize()/2;//- shiftY; double centerY = tileY * qc.tp.getTileSize() + qc.tp.getTileSize()/2;//- shiftY;
/*
double [][] centersXY_disp = qc.geometryCorrection.getPortsCoordinates( double [][] centersXY_disp = qc.geometryCorrection.getPortsCoordinates(
centerX, centerX,
centerY, centerY,
...@@ -625,6 +627,22 @@ public class AlignmentCorrection { ...@@ -625,6 +627,22 @@ public class AlignmentCorrection {
centerX, centerX,
centerY, centerY,
0.0); // disparity 0.0); // disparity
*/
double [][] centersXY_disp = qc.geometryCorrection.getPortsCoordinatesAndDerivatives(
corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
centerX,
centerY,
disp_strength[2 * s.series + 0][s.tile]/magic_coeff); // disparity
double [][] centersXY_inf = qc.geometryCorrection.getPortsCoordinatesAndDerivatives(
corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
centerX,
centerY,
0.0); // disparity
for (int i = 0; i < centersXY_disp.length;i++){ for (int i = 0; i < centersXY_disp.length;i++){
centersXY_disp[i][0] -= centersXY_inf[i][0]; centersXY_disp[i][0] -= centersXY_inf[i][0];
centersXY_disp[i][1] -= centersXY_inf[i][1]; centersXY_disp[i][1] -= centersXY_inf[i][1];
...@@ -2077,7 +2095,7 @@ B = |+dy0 -dy1 -2*dy3 | ...@@ -2077,7 +2095,7 @@ B = |+dy0 -dy1 -2*dy3 |
qc.geometryCorrection, // GeometryCorrection geometryCorrection, qc.geometryCorrection, // GeometryCorrection geometryCorrection,
qc.geometryCorrection.getCorrVector(), // GeometryCorrection.CorrVector corr_vector, qc.geometryCorrection.getCorrVector(), // GeometryCorrection.CorrVector corr_vector,
old_new_rms, // double [] old_new_rms, // should be double[2] old_new_rms, // double [] old_new_rms, // should be double[2]
debugLevel); // 2); // 1); // int debugLevel) 2); // debugLevel); // 2); // 1); // int debugLevel)
if (debugLevel > -1){ if (debugLevel > -1){
System.out.println("Old extrinsic corrections:"); System.out.println("Old extrinsic corrections:");
System.out.println(qc.geometryCorrection.getCorrVector().toString()); System.out.println(qc.geometryCorrection.getCorrVector().toString());
...@@ -2218,20 +2236,31 @@ B = |+dy0 -dy1 -2*dy3 | ...@@ -2218,20 +2236,31 @@ B = |+dy0 -dy1 -2*dy3 |
jt_dbg = new double [num_pars][2 * NUM_SENSORS * mismatch_list.size()]; jt_dbg = new double [num_pars][2 * NUM_SENSORS * mismatch_list.size()];
} }
Matrix [] corr_rots = corr_vector.getRotMatrices(); // get array of per-sensor rotation matrices
Matrix [][] deriv_rots = corr_vector.getRotDeriveMatrices();
for (int indx = 0; indx<mismatch_list.size(); indx++){ // need indx value for (int indx = 0; indx<mismatch_list.size(); indx++){ // need indx value
Mismatch mm = mismatch_list.get(indx); Mismatch mm = mismatch_list.get(indx);
double [] pXY = mm.getPXY(); double [] pXY = mm.getPXY();
double [][] deriv = new double [2 * NUM_SENSORS][]; double [][] deriv = new double [2 * NUM_SENSORS][];
int dbg_index =dbg_index (pXY, dbg_decimate); int dbg_index =dbg_index (pXY, dbg_decimate);
// double [][] f = // double [][] f =
geometryCorrection.getPortsCoordinatesAndDerivatives( /*
geometryCorrection.getPortsCoordinatesAndDerivatives_old(
corr_vector, // CorrVector corr_vector, corr_vector, // CorrVector corr_vector,
deriv, // boolean calc_deriv, deriv, // boolean calc_deriv,
pXY[0], // double px, pXY[0], // double px,
pXY[1], // double py, pXY[1], // double py,
mm.getDisparityMeas()); // getDisparityTask()); // double disparity) mm.getDisparityMeas()); // getDisparityTask()); // double disparity)
// convert to symmetrical coordianets */
geometryCorrection.getPortsCoordinatesAndDerivatives(
corr_rots, // Matrix [] rots,
deriv_rots, // Matrix [][] deriv_rots,
deriv, // boolean calc_deriv,
pXY[0], // double px,
pXY[1], // double py,
mm.getDisparityMeas()); // getDisparityTask()); // double disparity)
// convert to symmetrical coordinates
double [][] jt_partial = corr_vector.getJtPartial( double [][] jt_partial = corr_vector.getJtPartial(
deriv, // double [][] port_coord_deriv, deriv, // double [][] port_coord_deriv,
...@@ -2381,17 +2410,27 @@ B = |+dy0 -dy1 -2*dy3 | ...@@ -2381,17 +2410,27 @@ B = |+dy0 -dy1 -2*dy3 |
{ {
double [][] dMismatch_dXY = (new Mismatch()).get_dMismatch_dXY(); // just a static array double [][] dMismatch_dXY = (new Mismatch()).get_dMismatch_dXY(); // just a static array
double [] mv = new double [2 * NUM_SENSORS * mismatch_list.size()]; double [] mv = new double [2 * NUM_SENSORS * mismatch_list.size()];
Matrix [] corr_rots = corr_vector.getRotMatrices(); // get array of per-sensor rotation matrices
for (int indx = 0; indx<mismatch_list.size(); indx++){ // need indx value for (int indx = 0; indx<mismatch_list.size(); indx++){ // need indx value
Mismatch mm = mismatch_list.get(indx); Mismatch mm = mismatch_list.get(indx);
double [] pXY = mm.getPXY(); double [] pXY = mm.getPXY();
double [][] f = geometryCorrection.getPortsCoordinatesAndDerivatives( // 4x2 /*
double [][] f = geometryCorrection.getPortsCoordinatesAndDerivatives_old( // 4x2
corr_vector, // CorrVector corr_vector, corr_vector, // CorrVector corr_vector,
null, // boolean calc_deriv, null, // boolean calc_deriv,
pXY[0], // double px, pXY[0], // double px,
pXY[1], // double py, pXY[1], // double py,
mm.getDisparityMeas()); // getDisparityTask()); // double disparity) mm.getDisparityMeas()); // getDisparityTask()); // double disparity)
// convert to symmetrical coordianets */
double [][] f = geometryCorrection.getPortsCoordinatesAndDerivatives( // 4x2
corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // boolean calc_deriv,
pXY[0], // double px,
pXY[1], // double py,
mm.getDisparityMeas()); // getDisparityTask()); // double disparity)
// convert to symmetrical coordinates
// f is [4][2] array of port x,y coordinates - convert them to mv (linear array) // f is [4][2] array of port x,y coordinates - convert them to mv (linear array)
double [] mv_partial = new double [dMismatch_dXY.length]; double [] mv_partial = new double [dMismatch_dXY.length];
...@@ -2588,6 +2627,7 @@ B = |+dy0 -dy1 -2*dy3 | ...@@ -2588,6 +2627,7 @@ B = |+dy0 -dy1 -2*dy3 |
mismatch_list, // ArrayList<Mismatch> mismatch_list, mismatch_list, // ArrayList<Mismatch> mismatch_list,
geometryCorrection, // GeometryCorrection geometryCorrection, geometryCorrection, // GeometryCorrection geometryCorrection,
corr_vector, // GeometryCorrection.CorrVector corr_vector) corr_vector, // GeometryCorrection.CorrVector corr_vector)
// debugLevel); // int debugLevel)
debugLevel); // int debugLevel) debugLevel); // int debugLevel)
// convert Jacobian outputs to symmetrical measurement vectors (last one is non-zero only if disparity should be adjusted) // convert Jacobian outputs to symmetrical measurement vectors (last one is non-zero only if disparity should be adjusted)
...@@ -2684,9 +2724,9 @@ B = |+dy0 -dy1 -2*dy3 | ...@@ -2684,9 +2724,9 @@ B = |+dy0 -dy1 -2*dy3 |
} else if ((dbg_titles_mv.length * indx + i) >= jta_mv [oj].length){ } else if ((dbg_titles_mv.length * indx + i) >= jta_mv [oj].length){
System.out.println("solveCorr(): dbg_dmv_dsym.length="+dbg_dmv_dsym.length+ ", dbg_dmv_dsym[0].length="+dbg_dmv_dsym[0].length); System.out.println("solveCorr(): dbg_dmv_dsym.length="+dbg_dmv_dsym.length+ ", dbg_dmv_dsym[0].length="+dbg_dmv_dsym[0].length);
} }
dbg_dmv_dsym[i * dbg_titles_sym.length + j][dbg_index] = jta_mv [oj][dbg_titles_mv.length * indx + i]; //java.lang.ArrayIndexOutOfBoundsException: 3552 dbg_dmv_dsym[i * dbg_titles_sym.length + j][dbg_index] = jta_mv [oj][dbg_titles_mv.length * indx + i]; //java.lang.ArrayIndexOutOfBoundsException: 3552
dbg_dmv_dsym_delta[i * dbg_titles_sym.length + j][dbg_index] = jta_mv_delta [oj][dbg_titles_mv.length * indx + i]; dbg_dmv_dsym_delta[i * dbg_titles_sym.length + j][dbg_index] = jta_mv_delta [oj][dbg_titles_mv.length * indx + i];
dbg_dmv_dsym_diff[i * dbg_titles_sym.length + j][dbg_index] = jta_mv_delta [oj][dbg_titles_mv.length * indx + i] - jta_mv [oj][dbg_titles_mv.length * indx + i]; dbg_dmv_dsym_diff[i * dbg_titles_sym.length + j][dbg_index] = jta_mv_delta [oj][dbg_titles_mv.length * indx + i] - jta_mv [oj][dbg_titles_mv.length * indx + i];
oj++; oj++;
} }
} }
......
...@@ -114,13 +114,15 @@ public class EyesisCorrectionParameters { ...@@ -114,13 +114,15 @@ public class EyesisCorrectionParameters {
// CLT 3d batch parameters // CLT 3d batch parameters
public boolean clt_batch_4img = true; // Create a set of 4 images, usually for disparity = 0 public boolean clt_batch_apply_man = true; // Apply (and disable) manual pixel shift
public boolean clt_batch_extrinsic = false; // Calibrate extrinsic parameters for each set public boolean clt_batch_extrinsic = false; // Calibrate extrinsic parameters for each set
public boolean clt_batch_poly = false; // Calculate fine polynomial correction for each set public boolean clt_batch_poly = false; // Calculate fine polynomial correction for each set
public boolean clt_batch_4img = true; // Create a set of 4 images, usually for disparity = 0
public boolean clt_batch_explore = true; // 1-st step of 3d reconstruction - explore disparities for each tile public boolean clt_batch_explore = true; // 1-st step of 3d reconstruction - explore disparities for each tile
public boolean clt_batch_surf = true; // Create super-tile 2.5d surfaces public boolean clt_batch_surf = true; // Create super-tile 2.5d surfaces
public boolean clt_batch_assign = true; // Assign tiles to surfaces public boolean clt_batch_assign = true; // Assign tiles to surfaces
public boolean clt_batch_gen3d = true; // Generate 3d output: x3d and/or obj+mtl public boolean clt_batch_gen3d = true; // Generate 3d output: x3d and/or obj+mtl
public boolean clt_batch_dbg1 = true; // Generate debug images if a single set is selected
...@@ -215,13 +217,15 @@ public class EyesisCorrectionParameters { ...@@ -215,13 +217,15 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"x3dDirectory", this.x3dDirectory); properties.setProperty(prefix+"x3dDirectory", this.x3dDirectory);
properties.setProperty(prefix+"use_x3d_subdirs", this.use_x3d_subdirs+""); properties.setProperty(prefix+"use_x3d_subdirs", this.use_x3d_subdirs+"");
properties.setProperty(prefix+"clt_batch_4img", this.clt_batch_4img+""); properties.setProperty(prefix+"clt_batch_apply_man", this.clt_batch_apply_man+"");
properties.setProperty(prefix+"clt_batch_extrinsic", this.clt_batch_extrinsic+""); properties.setProperty(prefix+"clt_batch_extrinsic", this.clt_batch_extrinsic+"");
properties.setProperty(prefix+"clt_batch_poly", this.clt_batch_poly+""); properties.setProperty(prefix+"clt_batch_poly", this.clt_batch_poly+"");
properties.setProperty(prefix+"clt_batch_4img", this.clt_batch_4img+"");
properties.setProperty(prefix+"clt_batch_explore", this.clt_batch_explore+""); properties.setProperty(prefix+"clt_batch_explore", this.clt_batch_explore+"");
properties.setProperty(prefix+"clt_batch_surf", this.clt_batch_surf+""); properties.setProperty(prefix+"clt_batch_surf", this.clt_batch_surf+"");
properties.setProperty(prefix+"clt_batch_assign", this.clt_batch_assign+""); properties.setProperty(prefix+"clt_batch_assign", this.clt_batch_assign+"");
properties.setProperty(prefix+"clt_batch_gen3d", this.clt_batch_gen3d+""); properties.setProperty(prefix+"clt_batch_gen3d", this.clt_batch_gen3d+"");
properties.setProperty(prefix+"clt_batch_dbg1", this.clt_batch_dbg1+"");
} }
public void getProperties(String prefix,Properties properties){ public void getProperties(String prefix,Properties properties){
...@@ -317,13 +321,15 @@ public class EyesisCorrectionParameters { ...@@ -317,13 +321,15 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"use_x3d_subdirs")!= null) this.use_x3d_subdirs=Boolean.parseBoolean((String) properties.getProperty(prefix+"use_x3d_subdirs")); if (properties.getProperty(prefix+"use_x3d_subdirs")!= null) this.use_x3d_subdirs=Boolean.parseBoolean((String) properties.getProperty(prefix+"use_x3d_subdirs"));
if (properties.getProperty(prefix+"clt_batch_4img")!= null) this.clt_batch_4img=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_4img")); if (properties.getProperty(prefix+"clt_batch_apply_man")!= null) this.clt_batch_apply_man=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_apply_man"));
if (properties.getProperty(prefix+"clt_batch_extrinsic")!= null) this.clt_batch_extrinsic=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_extrinsic")); if (properties.getProperty(prefix+"clt_batch_extrinsic")!= null) this.clt_batch_extrinsic=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_extrinsic"));
if (properties.getProperty(prefix+"clt_batch_poly")!= null) this.clt_batch_poly=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_poly")); if (properties.getProperty(prefix+"clt_batch_poly")!= null) this.clt_batch_poly=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_poly"));
if (properties.getProperty(prefix+"clt_batch_4img")!= null) this.clt_batch_4img=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_4img"));
if (properties.getProperty(prefix+"clt_batch_explore")!= null) this.clt_batch_explore=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_explore")); if (properties.getProperty(prefix+"clt_batch_explore")!= null) this.clt_batch_explore=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_explore"));
if (properties.getProperty(prefix+"clt_batch_surf")!= null) this.clt_batch_surf=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_surf")); if (properties.getProperty(prefix+"clt_batch_surf")!= null) this.clt_batch_surf=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_surf"));
if (properties.getProperty(prefix+"clt_batch_assign")!= null) this.clt_batch_assign=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_assign")); if (properties.getProperty(prefix+"clt_batch_assign")!= null) this.clt_batch_assign=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_assign"));
if (properties.getProperty(prefix+"clt_batch_gen3d")!= null) this.clt_batch_gen3d=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_gen3d")); if (properties.getProperty(prefix+"clt_batch_gen3d")!= null) this.clt_batch_gen3d=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_gen3d"));
if (properties.getProperty(prefix+"clt_batch_dbg1")!= null) this.clt_batch_dbg1=Boolean.parseBoolean((String) properties.getProperty(prefix+"clt_batch_dbg1"));
} }
public boolean showDialog(String title) { public boolean showDialog(String title) {
...@@ -522,11 +528,11 @@ public class EyesisCorrectionParameters { ...@@ -522,11 +528,11 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Use individual subdirectory for each 3d model (timestamp as name)", this.use_x3d_subdirs); //10 gd.addCheckbox ("Use individual subdirectory for each 3d model (timestamp as name)", this.use_x3d_subdirs); //10
gd.addStringField("Results directory", this.resultsDirectory, 60); // 11 gd.addStringField ("Results directory", this.resultsDirectory, 60); // 11
gd.addCheckbox("Select results directory", false); // 12 gd.addCheckbox ("Select results directory", false); // 12
gd.addStringField("Source files prefix", this.sourcePrefix, 60); // 13 gd.addStringField ("Source files prefix", this.sourcePrefix, 60); // 13
gd.addStringField("Source files suffix", this.sourceSuffix, 60); // 14 gd.addStringField ("Source files suffix", this.sourceSuffix, 60); // 14
gd.addNumericField("First subcamera (in the source filename)", this.firstSubCamera, 0); // 15 gd.addNumericField("First subcamera (in the source filename)", this.firstSubCamera, 0); // 15
gd.addStringField("Sensor files prefix", this.sensorPrefix, 40); // 16 gd.addStringField("Sensor files prefix", this.sensorPrefix, 40); // 16
...@@ -535,15 +541,17 @@ public class EyesisCorrectionParameters { ...@@ -535,15 +541,17 @@ public class EyesisCorrectionParameters {
gd.addStringField("CLT kernel files prefix", this.cltKernelPrefix, 40); // 18 gd.addStringField("CLT kernel files prefix", this.cltKernelPrefix, 40); // 18
gd.addStringField("CLT symmetical kernel files", this.cltSuffix, 40); // 19 gd.addStringField("CLT symmetical kernel files", this.cltSuffix, 40); // 19
gd.addMessage("============ batch parameters ============"); gd.addMessage ("============ batch parameters ============");
gd.addCheckbox ("Create a set of 4 images, usually for disparity = 0", this.clt_batch_4img); // 20 gd.addCheckbox ("Apply (and disable) manual pixel shift", this.clt_batch_apply_man); // 20
gd.addCheckbox ("Calibrate extrinsic parameters for each set", this.clt_batch_extrinsic); // 21 gd.addCheckbox ("Calibrate extrinsic parameters for each set", this.clt_batch_extrinsic); // 21
gd.addCheckbox ("Calculate fine polynomial correction for each set", this.clt_batch_poly); // 22 gd.addCheckbox ("Calculate fine polynomial correction for each set", this.clt_batch_poly); // 22
gd.addCheckbox ("1-st step of 3d reconstruction - explore disparities for each tile", this.clt_batch_explore); // 23 gd.addCheckbox ("Create a set of 4 images, usually for disparity = 0", this.clt_batch_4img); // 23
gd.addCheckbox ("Create super-tile 2.5d surfaces", this.clt_batch_surf); // 24 gd.addCheckbox ("1-st step of 3d reconstruction - explore disparities for each tile", this.clt_batch_explore); // 24
gd.addCheckbox ("Assign tiles to surfaces", this.clt_batch_assign); // 25 gd.addCheckbox ("Create super-tile 2.5d surfaces", this.clt_batch_surf); // 25
gd.addCheckbox ("Generate 3d output: x3d and/or obj+mtl", this.clt_batch_gen3d); // 26 gd.addCheckbox ("Assign tiles to surfaces", this.clt_batch_assign); // 26
gd.addCheckbox ("Generate 3d output: x3d and/or obj+mtl", this.clt_batch_gen3d); // 27
gd.addCheckbox ("Generate debug images if a single set is selected", this.clt_batch_dbg1); // 28
WindowTools.addScrollBars(gd); WindowTools.addScrollBars(gd);
gd.showDialog(); gd.showDialog();
...@@ -567,13 +575,15 @@ public class EyesisCorrectionParameters { ...@@ -567,13 +575,15 @@ public class EyesisCorrectionParameters {
this.cltKernelPrefix= gd.getNextString(); // 18 this.cltKernelPrefix= gd.getNextString(); // 18
this.cltSuffix= gd.getNextString(); // 19 this.cltSuffix= gd.getNextString(); // 19
this.clt_batch_4img= gd.getNextBoolean(); // 20 this.clt_batch_apply_man= gd.getNextBoolean(); // 20
this.clt_batch_extrinsic= gd.getNextBoolean(); // 21 this.clt_batch_extrinsic= gd.getNextBoolean(); // 21
this.clt_batch_poly= gd.getNextBoolean(); // 22 this.clt_batch_poly= gd.getNextBoolean(); // 22
this.clt_batch_explore= gd.getNextBoolean(); // 23 this.clt_batch_4img= gd.getNextBoolean(); // 23
this.clt_batch_surf= gd.getNextBoolean(); // 24 this.clt_batch_explore= gd.getNextBoolean(); // 24
this.clt_batch_assign= gd.getNextBoolean(); // 25 this.clt_batch_surf= gd.getNextBoolean(); // 25
this.clt_batch_gen3d= gd.getNextBoolean(); // 26 this.clt_batch_assign= gd.getNextBoolean(); // 26
this.clt_batch_gen3d= gd.getNextBoolean(); // 27
this.clt_batch_dbg1= gd.getNextBoolean(); // 28
return true; return true;
} }
...@@ -2131,6 +2141,8 @@ public class EyesisCorrectionParameters { ...@@ -2131,6 +2141,8 @@ public class EyesisCorrectionParameters {
public double fine_corr_y_2 = 0.0; // additionally shift image in port 2 in y direction public double fine_corr_y_2 = 0.0; // additionally shift image in port 2 in y direction
public double fine_corr_x_3 = 0.0; // additionally shift image in port 3 in x direction public double fine_corr_x_3 = 0.0; // additionally shift image in port 3 in x direction
public double fine_corr_y_3 = 0.0; // additionally shift image in port 3 in y direction public double fine_corr_y_3 = 0.0; // additionally shift image in port 3 in y direction
public boolean fine_corr_ignore = false; // Ignore manual pixel correction
public boolean fine_corr_apply = true; // Apply and set to ignore manual pixel correction after extrinsics correction
public double fcorr_radius = 0.75 ; // Do not try to correct outside this fraction of width/hight public double fcorr_radius = 0.75 ; // Do not try to correct outside this fraction of width/hight
public double fcorr_min_strength = 0.15 ; // 0.005 minimal correlation strength to apply fine correction public double fcorr_min_strength = 0.15 ; // 0.005 minimal correlation strength to apply fine correction
...@@ -2786,6 +2798,8 @@ public class EyesisCorrectionParameters { ...@@ -2786,6 +2798,8 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"fine_corr_y_2", this.fine_corr_y_2 +""); properties.setProperty(prefix+"fine_corr_y_2", this.fine_corr_y_2 +"");
properties.setProperty(prefix+"fine_corr_x_3", this.fine_corr_x_3 +""); properties.setProperty(prefix+"fine_corr_x_3", this.fine_corr_x_3 +"");
properties.setProperty(prefix+"fine_corr_y_3", this.fine_corr_y_3 +""); properties.setProperty(prefix+"fine_corr_y_3", this.fine_corr_y_3 +"");
properties.setProperty(prefix+"fine_corr_ignore", this.fine_corr_ignore+"");
properties.setProperty(prefix+"fine_corr_apply", this.fine_corr_apply+"");
properties.setProperty(prefix+"fcorr_radius", this.fcorr_radius +""); properties.setProperty(prefix+"fcorr_radius", this.fcorr_radius +"");
properties.setProperty(prefix+"fcorr_min_strength",this.fcorr_min_strength +""); properties.setProperty(prefix+"fcorr_min_strength",this.fcorr_min_strength +"");
...@@ -3385,6 +3399,8 @@ public class EyesisCorrectionParameters { ...@@ -3385,6 +3399,8 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"fine_corr_y_2")!=null) this.fine_corr_y_2=Double.parseDouble(properties.getProperty(prefix+"fine_corr_y_2")); if (properties.getProperty(prefix+"fine_corr_y_2")!=null) this.fine_corr_y_2=Double.parseDouble(properties.getProperty(prefix+"fine_corr_y_2"));
if (properties.getProperty(prefix+"fine_corr_x_3")!=null) this.fine_corr_x_3=Double.parseDouble(properties.getProperty(prefix+"fine_corr_x_3")); if (properties.getProperty(prefix+"fine_corr_x_3")!=null) this.fine_corr_x_3=Double.parseDouble(properties.getProperty(prefix+"fine_corr_x_3"));
if (properties.getProperty(prefix+"fine_corr_y_3")!=null) this.fine_corr_y_3=Double.parseDouble(properties.getProperty(prefix+"fine_corr_y_3")); if (properties.getProperty(prefix+"fine_corr_y_3")!=null) this.fine_corr_y_3=Double.parseDouble(properties.getProperty(prefix+"fine_corr_y_3"));
if (properties.getProperty(prefix+"fine_corr_ignore")!=null) this.fine_corr_ignore=Boolean.parseBoolean(properties.getProperty(prefix+"fine_corr_ignore"));
if (properties.getProperty(prefix+"fine_corr_apply")!=null) this.fine_corr_apply=Boolean.parseBoolean(properties.getProperty(prefix+"fine_corr_apply"));
if (properties.getProperty(prefix+"fcorr_radius")!=null) this.fcorr_radius=Double.parseDouble(properties.getProperty(prefix+"fcorr_radius")); if (properties.getProperty(prefix+"fcorr_radius")!=null) this.fcorr_radius=Double.parseDouble(properties.getProperty(prefix+"fcorr_radius"));
if (properties.getProperty(prefix+"fcorr_min_strength")!=null) this.fcorr_min_strength=Double.parseDouble(properties.getProperty(prefix+"fcorr_min_strength")); if (properties.getProperty(prefix+"fcorr_min_strength")!=null) this.fcorr_min_strength=Double.parseDouble(properties.getProperty(prefix+"fcorr_min_strength"));
...@@ -4000,7 +4016,9 @@ public class EyesisCorrectionParameters { ...@@ -4000,7 +4016,9 @@ public class EyesisCorrectionParameters {
gd.addNumericField("X 2", this.fine_corr_x_2, 3); gd.addNumericField("X 2", this.fine_corr_x_2, 3);
gd.addNumericField("Y 2", this.fine_corr_y_2, 3); gd.addNumericField("Y 2", this.fine_corr_y_2, 3);
gd.addNumericField("X 3", this.fine_corr_x_3, 3); gd.addNumericField("X 3", this.fine_corr_x_3, 3);
gd.addNumericField("Y 4", this.fine_corr_y_3, 3); gd.addNumericField("Y 3", this.fine_corr_y_3, 3);
gd.addCheckbox ("Ignore manual pixel correction (set/reset automatically if enabled below)", this.fine_corr_ignore);
gd.addCheckbox ("Apply and set to ignore manual pixel correction after extrinsics correction", this.fine_corr_apply);
gd.addNumericField("fcorr_radius", this.fcorr_radius, 3); gd.addNumericField("fcorr_radius", this.fcorr_radius, 3);
gd.addNumericField("Do not try to correct outside this fraction of width/hight", this.fcorr_min_strength,3); gd.addNumericField("Do not try to correct outside this fraction of width/hight", this.fcorr_min_strength,3);
...@@ -4647,8 +4665,10 @@ public class EyesisCorrectionParameters { ...@@ -4647,8 +4665,10 @@ public class EyesisCorrectionParameters {
this.fine_corr_y_2= gd.getNextNumber(); this.fine_corr_y_2= gd.getNextNumber();
this.fine_corr_x_3= gd.getNextNumber(); this.fine_corr_x_3= gd.getNextNumber();
this.fine_corr_y_3= gd.getNextNumber(); this.fine_corr_y_3= gd.getNextNumber();
this.fine_corr_ignore= gd.getNextBoolean();
this.fine_corr_apply= gd.getNextBoolean();
this.fcorr_radius= gd.getNextNumber(); this.fcorr_radius= gd.getNextNumber();
this.fcorr_min_strength= gd.getNextNumber(); this.fcorr_min_strength= gd.getNextNumber();
this.fcorr_disp_diff= gd.getNextNumber(); this.fcorr_disp_diff= gd.getNextNumber();
this.fcorr_quadratic= gd.getNextBoolean(); this.fcorr_quadratic= gd.getNextBoolean();
......
...@@ -2327,7 +2327,7 @@ public class EyesisCorrections { ...@@ -2327,7 +2327,7 @@ public class EyesisCorrections {
saveAndShowEnable( imp, correctionsParameters , true, true); saveAndShowEnable( imp, correctionsParameters , true, true);
} }
private void saveAndShowEnable( public void saveAndShowEnable(
ImagePlus imp, ImagePlus imp,
EyesisCorrectionParameters.CorrectionParameters correctionsParameters, EyesisCorrectionParameters.CorrectionParameters correctionsParameters,
boolean enableSave, boolean enableSave,
......
...@@ -542,8 +542,8 @@ private Panel panel1, ...@@ -542,8 +542,8 @@ private Panel panel1,
if (DCT_MODE) { if (DCT_MODE) {
panelClt3 = new Panel(); panelClt3 = new Panel();
panelClt3.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap panelClt3.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap
addButton("Setup CLT Batch parameters", panelClt3, color_configure);
addButton("Setup CLT parameters", panelClt3, color_configure); addButton("Setup CLT parameters", panelClt3, color_configure);
addButton("Setup CLT Batch parameters", panelClt3, color_configure);
addButton("CLT batch process", panelClt3, color_process); addButton("CLT batch process", panelClt3, color_process);
add(panelClt3); add(panelClt3);
} }
...@@ -4604,7 +4604,7 @@ private Panel panel1, ...@@ -4604,7 +4604,7 @@ private Panel panel1,
System.out.println("Created new QuadCLT instance, will need to read CLT kernels"); System.out.println("Created new QuadCLT instance, will need to read CLT kernels");
} }
} }
QUAD_CLT.resetExtrinsicCorr(); QUAD_CLT.resetExtrinsicCorr(CLT_PARAMETERS);
return; return;
} else if (label.equals("CLT show fine corr")) { } else if (label.equals("CLT show fine corr")) {
if (QUAD_CLT == null){ if (QUAD_CLT == null){
......
...@@ -127,7 +127,137 @@ public class GeometryCorrection { ...@@ -127,7 +127,137 @@ public class GeometryCorrection {
static final int TILT_INDEX = 0; static final int TILT_INDEX = 0;
static final int AZIMUTH_INDEX = 3; static final int AZIMUTH_INDEX = 3;
static final int ROLL_INDEX = 6; static final int ROLL_INDEX = 6;
static final double ROT_AZ_SGN = -1.0; // sign of first sin for azimuth rotation
static final double ROT_TL_SGN = 1.0; // sign of first sin for tilt rotation
static final double ROT_RL_SGN = 1.0; // sign of first sin for roll rotation
double [] vector; double [] vector;
public Matrix [] getRotMatrices()
{
Matrix [] rots = new Matrix [4];
double [] azimuths = getAzimuths();
double [] tilts = getTilts();
double [] rolls = getFullRolls();
for (int chn = 0; chn < rots.length; chn++) {
double ca = Math.cos(azimuths[chn]);
double sa = Math.sin(azimuths[chn]);
double ct = Math.cos(tilts[chn]);
double st = Math.sin(tilts[chn]);
double cr = Math.cos(rolls[chn]);
double sr = Math.sin(rolls[chn]);
/*
double [][] a_az = { // inverted - OK
{ ca, 0.0, -sa},
{ 0.0, 1.0, 0.0},
{ sa, 0.0, ca}};
double [][] a_t = { // inverted - OK
{ 1.0, 0.0, 0.0},
{ 0.0, ct, st},
{ 0.0, -st, ct}};
double [][] a_r = { // inverted OK
{ cr, sr, 0.0},
{ -sr, cr, 0.0},
{ 0.0, 0.0, 1.0}};
*/
double [][] a_az = { // inverted - OK
{ ca, 0.0, sa * ROT_AZ_SGN },
{ 0.0, 1.0, 0.0},
{ -sa* ROT_AZ_SGN, 0.0, ca}};
double [][] a_t = { // inverted - OK
{ 1.0, 0.0, 0.0},
{ 0.0, ct, st * ROT_TL_SGN},
{ 0.0, -st * ROT_TL_SGN, ct}};
double [][] a_r = { // inverted OK
{ cr, sr * ROT_RL_SGN, 0.0},
{ -sr * ROT_RL_SGN, cr, 0.0},
{ 0.0, 0.0, 1.0}};
rots[chn] = (new Matrix(a_r).times(new Matrix(a_t).times(new Matrix(a_az))));
}
return rots;
}
/**
* Get derivatives of the rotation matrices, per sensor per axis (azimuth, tilt, roll)
* d/dx and d/dy should be normalized by z-component of the vector (not derivative)
* @return 2-d array array of derivatives matrices
*/
public Matrix [][] getRotDeriveMatrices()
{
Matrix [][] rot_derivs = new Matrix [4][3]; // channel, azimuth-tilt-roll
double [] azimuths = getAzimuths();
double [] tilts = getTilts();
double [] rolls = getFullRolls();
for (int chn = 0; chn < rot_derivs.length; chn++) {
double ca = Math.cos(azimuths[chn]);
double sa = Math.sin(azimuths[chn]);
double ct = Math.cos(tilts[chn]);
double st = Math.sin(tilts[chn]);
double cr = Math.cos(rolls[chn]);
double sr = Math.sin(rolls[chn]);
double [][] a_az = { // inverted - OK
{ ca, 0.0, sa * ROT_AZ_SGN },
{ 0.0, 1.0, 0.0},
{ -sa* ROT_AZ_SGN, 0.0, ca}};
double [][] a_t = { // inverted - OK
{ 1.0, 0.0, 0.0},
{ 0.0, ct, st * ROT_TL_SGN},
{ 0.0, -st * ROT_TL_SGN, ct}};
double [][] a_r = { // inverted OK
{ cr, sr * ROT_RL_SGN, 0.0},
{ -sr * ROT_RL_SGN, cr, 0.0},
{ 0.0, 0.0, 1.0}};
/*
double [][] a_daz = { // inverted - OK
{ -sa, 0.0, ca * ROT_AZ_SGN },
{ 0.0, 1.0, 0.0},
{ -ca* ROT_AZ_SGN, 0.0, -sa}};
double [][] a_dt = { // inverted - OK
{ 1.0, 0.0, 0.0},
{ 0.0, -st, ct * ROT_TL_SGN},
{ 0.0, -ct * ROT_TL_SGN, -st}};
double [][] a_dr = { // inverted OK
{ -sr, cr * ROT_RL_SGN, 0.0},
{ -cr * ROT_RL_SGN, -sr, 0.0},
{ 0.0, 0.0, 1.0}};
*/
double [][] a_daz = { // inverted - OK
{ -sa, 0.0, ca * ROT_AZ_SGN },
{ 0.0, 0.0, 0.0},
{ -ca* ROT_AZ_SGN, 0.0, -sa}};
double [][] a_dt = { // inverted - OK
{ 0.0, 0.0, 0.0},
{ 0.0, -st, ct * ROT_TL_SGN},
{ 0.0, -ct * ROT_TL_SGN, -st}};
double [][] a_dr = { // inverted OK
{ -sr, cr * ROT_RL_SGN, 0.0},
{ -cr * ROT_RL_SGN, -sr, 0.0},
{ 0.0, 0.0, 0.0}};
// d/d_az
rot_derivs[chn][0] = (new Matrix(a_r ).times(new Matrix(a_t ).times(new Matrix(a_daz))));
rot_derivs[chn][1] = (new Matrix(a_r ).times(new Matrix(a_dt).times(new Matrix(a_az ))));
rot_derivs[chn][2] = (new Matrix(a_dr).times(new Matrix(a_t ).times(new Matrix(a_az ))));
}
return rot_derivs;
}
public CorrVector () public CorrVector ()
{ {
this.vector = new double[10]; this.vector = new double[10];
...@@ -137,17 +267,28 @@ public class GeometryCorrection { ...@@ -137,17 +267,28 @@ public class GeometryCorrection {
double [] sym_vector, double [] sym_vector,
boolean [] par_mask) boolean [] par_mask)
{ {
this.vector = toTarArray(sym_vector, par_mask); this.vector = toTarArray(sym_vector, par_mask);
} }
public CorrVector ( public CorrVector (
double tilt0, double tilt1, double tilt2, double tilt0, double tilt1, double tilt2,
double azimuth0, double azimuth1, double azimuth2, double azimuth0, double azimuth1, double azimuth2,
double roll0, double roll1, double roll2, double roll3) double roll0, double roll1, double roll2, double roll3)
{} {
double [] v = {
tilt0, tilt1, tilt2,
azimuth0, azimuth1, azimuth2,
roll0, roll1, roll2, roll3};
this.vector = v;
}
public CorrVector (double [] vector) public CorrVector (double [] vector)
{ {
this.vector = vector; if (vector != null) {
this.vector = vector;
}
} }
/** /**
* Set subcamera corrections from a single array * Set subcamera corrections from a single array
...@@ -199,10 +340,28 @@ public class GeometryCorrection { ...@@ -199,10 +340,28 @@ public class GeometryCorrection {
double [] rolls = {vector[6],vector[7],vector[8], vector[9]}; double [] rolls = {vector[6],vector[7],vector[8], vector[9]};
return rolls; return rolls;
} }
public double getRoll(int indx) public double getRoll(int indx)
{ {
return vector[6 + indx]; return vector[6 + indx];
} }
// Include factory calibration rolls
public double [] getFullRolls()
{
double d2r= Math.PI/180.0;
double [] rolls = {
vector[6] + d2r * roll[0],
vector[7] + d2r * roll[1],
vector[8] + d2r * roll[2],
vector[9] + d2r * roll[3]};
return rolls;
}
public double getFullRoll(int indx)
{
return vector[6 + indx] + roll[indx] * Math.PI/180.0;
}
public String toString() public String toString()
{ {
String s; String s;
...@@ -242,10 +401,29 @@ public class GeometryCorrection { ...@@ -242,10 +401,29 @@ public class GeometryCorrection {
incrementVector(incr.toArray(), scale); incrementVector(incr.toArray(), scale);
} }
public CorrVector clone(){ public CorrVector clone(){
return new CorrVector(this.vector.clone()); return new CorrVector(this.vector.clone());
} }
/**
* Convert manual pixel shift between images to azimuth/tilt rotations (distortions ignored)
* and apply (add) them to the current vector (normally should be all 0.0)
* @param pXY_shift manula XY pixel corrections (shiftXY made of clt_parameters.fine_corr_[xy]_[0123])
*/
public void applyPixelShift(double [][] pXY_shift){
double [] pXY_avg = {0.0,0.0};
for (int i = 0; i < numSensors; i++){
for (int j = 0; j < 2; j++) {
pXY_avg[j] += pXY_shift[i][j]/numSensors;
}
}
double pix_to_rads = (0.001*pixelSize)/focalLength;
for (int i = 0; i < (numSensors -1); i++){
vector[TILT_INDEX + i] -= pix_to_rads * (pXY_shift[i][1] - pXY_avg[1]);
vector[AZIMUTH_INDEX + i] += pix_to_rads * (pXY_shift[i][0] - pXY_avg[0]);
}
}
/** /**
* Get conversion matrix from symmetrical coordinates * Get conversion matrix from symmetrical coordinates
* @return * @return
...@@ -983,25 +1161,25 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -983,25 +1161,25 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
* @return array of per port pairs of pixel shifts * @return array of per port pairs of pixel shifts
*/ */
public double [][] getPortsCoordinates( public double [][] getPortsCoordinates_old(
double px, double px,
double py, double py,
double disparity) double disparity)
{ {
// boolean new_ports = true; // false; double [][] port_coords = getPortsCoordinatesAndDerivatives_old(
// if (new_ports) {
return getPortsCoordinatesAndDerivatives(
getCorrVector(), // CorrVector corr_vector, getCorrVector(), // CorrVector corr_vector,
null, // boolean calc_deriv, null, // boolean calc_deriv,
px, // double px, px, // double px,
py, // double py, py, // double py,
disparity); // double disparity) disparity); // double disparity)
// } else { // double [][] port_coords_rot = getPortsCoordinatesAndDerivatives_rot(
// return getPortsCoordinates_nocorr( // old, tested // getCorrVector(), // CorrVector corr_vector,
// px, // null, // boolean calc_deriv,
// py, // px, // double px,
// disparity); // py, // double py,
// } // disparity); // double disparity)
return port_coords;
} }
/** /**
...@@ -1073,13 +1251,155 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -1073,13 +1251,155 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
*/ */
public double [][] getPortsCoordinatesAndDerivatives( public double [][] getPortsCoordinatesAndDerivatives(
Matrix [] rots,
Matrix [][] deriv_rots,
double [][] pXYderiv, // if not null, should be double[8][]
double px,
double py,
double disparity)
{
// String dbg_s = corr_vector.toString();
double [][] pXY = new double [numSensors][2];
double pXcd = px - 0.5 * this.pixelCorrectionWidth;
double pYcd = py - 0.5 * this.pixelCorrectionHeight;
double rD = Math.sqrt(pXcd*pXcd + pYcd*pYcd)*0.001*this.pixelSize; // distorted radius in a virtual center camera
double rND2R=getRByRDist(rD/this.distortionRadius, (debugLevel > -1));
double pXc = pXcd * rND2R; // non-distorted coordinates relative to the (0.5 * this.pixelCorrectionWidth, 0.5 * this.pixelCorrectionHeight)
double pYc = pYcd * rND2R; // in pixels
double [] a={this.distortionC,this.distortionB,this.distortionA,this.distortionA5,this.distortionA6,this.distortionA7,this.distortionA8};
// double corr_scale = focalLength/(0.001*pixelSize);
double fl_pix = focalLength/(0.001*pixelSize); // focal length in pixels
double ri_scale = 0.001 * this.pixelSize / this.distortionRadius;
// Matrix [] rots = corr_vector.getRotMatrices(); // get array of per-sensor rotation matrices
for (int i = 0; i < numSensors; i++){
// non-distorted XY of the shifted location of the individual sensor
double pXci0 = pXc - disparity * this.rXY[i][0]; // in pixels
double pYci0 = pYc - disparity * this.rXY[i][1];
// TODO: convert to true rotations
double [][] avi = {{pXci0}, {pYci0},{fl_pix}};
Matrix vi = new Matrix(avi); // non-distorted sensor channel view vector in pixels (z -along the common axis)
Matrix rvi = rots[i].times(vi);
double norm_z = fl_pix/rvi.get(2, 0);
double pXci = rvi.get(0, 0) * norm_z;
double pYci = rvi.get(1, 0) * norm_z;
// calculate back to distorted
double rNDi = Math.sqrt(pXci*pXci + pYci*pYci); // in pixels
// Rdist/R=A8*R^7+A7*R^6+A6*R^5+A5*R^4+A*R^3+B*R^2+C*R+(1-A6-A7-A6-A5-A-B-C)");
double ri = rNDi* ri_scale; // relative to distortion radius
// double rD2rND = (1.0 - distortionA8 - distortionA7 - distortionA6 - distortionA5 - distortionA - distortionB - distortionC);
double rD2rND = 1.0;
double rri = 1.0;
for (int j = 0; j < a.length; j++){
rri *= ri;
rD2rND += a[j]*(rri - 1.0); // Fixed
}
double pXid = pXci * rD2rND;
double pYid = pYci * rD2rND;
pXY[i][0] = pXid + this.pXY0[i][0];
pXY[i][1] = pYid + this.pXY0[i][1];
if (pXYderiv != null) {
pXYderiv[2 * i] = new double [CorrVector.LENGTH];
pXYderiv[2 * i+1] = new double [CorrVector.LENGTH];
Matrix drvi_daz = deriv_rots[i][0].times(vi);
Matrix drvi_dtl = deriv_rots[i][1].times(vi);
Matrix drvi_drl = deriv_rots[i][2].times(vi);
double dpXci_dazimuth = drvi_daz.get(0, 0) * norm_z - pXci * drvi_daz.get(2, 0) / rvi.get(2, 0);
double dpYci_dazimuth = drvi_daz.get(1, 0) * norm_z - pYci * drvi_daz.get(2, 0) / rvi.get(2, 0);
double dpXci_dtilt = drvi_dtl.get(0, 0) * norm_z - pXci * drvi_dtl.get(2, 0) / rvi.get(2, 0);
double dpYci_dtilt = drvi_dtl.get(1, 0) * norm_z - pYci * drvi_dtl.get(2, 0) / rvi.get(2, 0);
double dpXci_droll = drvi_drl.get(0, 0) * norm_z - pXci * drvi_drl.get(2, 0) / rvi.get(2, 0);
double dpYci_droll = drvi_drl.get(1, 0) * norm_z - pYci * drvi_drl.get(2, 0) / rvi.get(2, 0);
/// double dpXci_dazimuth = -corr_scale;
/// double dpYci_dtilt = corr_scale;
/// double dri_dazimuth = pXci/rNDi * dpXci_dazimuth * ri_scale;
/// double dri_dtilt = pYci/rNDi * dpYci_dtilt * ri_scale;
// double ri = ri_scale * Math.sqrt(pXci*pXci + pYci*pYci) ; // relative to distortion radius
double dri_dazimuth = ri_scale / rNDi* (pXci * dpXci_dazimuth + pYci * dpYci_dazimuth);
double dri_dtilt = ri_scale / rNDi* (pXci * dpXci_dtilt + pYci * dpYci_dtilt);
double dri_droll = ri_scale / rNDi* (pXci * dpXci_droll + pYci * dpYci_droll);
// TODO: verify dri_droll == 0 and remove
double drD2rND_dri = 0.0;
rri = 1.0;
for (int j = 0; j < a.length; j++){
drD2rND_dri += a[j] * (j+1) * rri;
rri *= ri;
}
// double pXid = pXci * rD2rND;
// double pYid = pYci * rD2rND;
double drD2rND_dazimuth = drD2rND_dri * dri_dazimuth;
double drD2rND_dtilt = drD2rND_dri * dri_dtilt;
// double drD2rND_droll = 0.0;
/// double dpXid_dazimuth = dpXci_dazimuth * rD2rND + pXid * drD2rND_dazimuth;
/// double dpYid_dazimuth = pYid * drD2rND_dazimuth;
/// double dpXid_dtilt = pXid * drD2rND_dtilt;
/// double dpYid_dtilt = dpYci_dtilt * rD2rND + pYid * drD2rND_dtilt;
//// double dpXid_dazimuth = dpXci_dazimuth * rD2rND + pXid * drD2rND_dazimuth;
//// double dpYid_dazimuth = dpYci_dazimuth * rD2rND + pYid * drD2rND_dazimuth;
//// double dpXid_dtilt = dpXci_dtilt * rD2rND + pXid * drD2rND_dtilt;
//// double dpYid_dtilt = dpYci_dtilt * rD2rND + pYid * drD2rND_dtilt;
double dpXid_dazimuth = dpXci_dazimuth * rD2rND + pXci * drD2rND_dazimuth;
double dpYid_dazimuth = dpYci_dazimuth * rD2rND + pYci * drD2rND_dazimuth;
double dpXid_dtilt = dpXci_dtilt * rD2rND + pXci * drD2rND_dtilt;
double dpYid_dtilt = dpYci_dtilt * rD2rND + pYci * drD2rND_dtilt;
double dpXid_droll = dpXci_droll * rD2rND;
double dpYid_droll = dpYci_droll * rD2rND;
/// double dxi_dazimuth = c_roll * dpXid_dazimuth + s_roll * dpYid_dazimuth;
/// double dyi_dazimuth = -s_roll * dpXid_dazimuth + c_roll * dpYid_dazimuth;
/// double dxi_dtilt = c_roll * dpXid_dtilt + s_roll * dpYid_dtilt;
/// double dyi_dtilt = -s_roll * dpXid_dtilt + c_roll * dpYid_dtilt;
// verify that d/dsym are well, symmetrical
if (i < (numSensors - 1)){
pXYderiv[2 * i + 0][CorrVector.TILT_INDEX+i] = dpXid_dtilt;
pXYderiv[2 * i + 1][CorrVector.TILT_INDEX+i] = dpYid_dtilt;
pXYderiv[2 * i + 0][CorrVector.AZIMUTH_INDEX+i] = dpXid_dazimuth;
pXYderiv[2 * i + 1][CorrVector.AZIMUTH_INDEX+i] = dpYid_dazimuth;
} else {
for (int j = 0; j < (numSensors - 1); j++){
pXYderiv[2 * i + 0][CorrVector.TILT_INDEX+j] = -dpXid_dtilt;
pXYderiv[2 * i + 1][CorrVector.TILT_INDEX+j] = -dpYid_dtilt;
pXYderiv[2 * i + 0][CorrVector.AZIMUTH_INDEX+j] = -dpXid_dazimuth;
pXYderiv[2 * i + 1][CorrVector.AZIMUTH_INDEX+j] = -dpYid_dazimuth;
}
}
// double dxi_droll = -s_roll * pXid + c_roll * pYid;
// double dyi_droll = -c_roll * pXid - s_roll * pYid;
pXYderiv[2 * i + 0][CorrVector.ROLL_INDEX+i] = dpXid_droll;
pXYderiv[2 * i + 1][CorrVector.ROLL_INDEX+i] = dpYid_droll;
}
}
return pXY;
}
public double [][] getPortsCoordinatesAndDerivatives_old(
CorrVector corr_vector, CorrVector corr_vector,
double [][] pXYderiv, // if not null, should be double[8][] double [][] pXYderiv, // if not null, should be double[8][]
double px, double px,
double py, double py,
double disparity) double disparity)
{ {
String dbg_s = corr_vector.toString(); // String dbg_s = corr_vector.toString();
double [][] pXY = new double [numSensors][2]; double [][] pXY = new double [numSensors][2];
...@@ -1096,6 +1416,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -1096,6 +1416,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
// non-distorted XY of the shifted location of the individual sensor // non-distorted XY of the shifted location of the individual sensor
double pXci = pXc - disparity * this.rXY[i][0]; // in pixels double pXci = pXc - disparity * this.rXY[i][0]; // in pixels
double pYci = pYc - disparity * this.rXY[i][1]; double pYci = pYc - disparity * this.rXY[i][1];
// TODO: convert to true rotations
// add misalignment, for small angles express in non-distorted pixels // add misalignment, for small angles express in non-distorted pixels
pXci += -corr_vector.getAzimuth(i) * corr_scale; pXci += -corr_vector.getAzimuth(i) * corr_scale;
pYci += corr_vector.getTilt(i) * corr_scale; pYci += corr_vector.getTilt(i) * corr_scale;
...@@ -1113,13 +1434,11 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -1113,13 +1434,11 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
double pXid = pXci * rD2rND; double pXid = pXci * rD2rND;
double pYid = pYci * rD2rND; double pYid = pYci * rD2rND;
// individual rotate (check sign) // individual rotate (check sign)
// double a_roll = (this.roll[i] - this.common_roll) * Math.PI/180.0 + corr_vector.getRoll(i) ;
double a_roll = (this.roll[i]) * Math.PI/180.0 + corr_vector.getRoll(i) ; double a_roll = (this.roll[i]) * Math.PI/180.0 + corr_vector.getRoll(i) ;
double c_roll = Math.cos(a_roll); double c_roll = Math.cos(a_roll);
double s_roll = Math.sin(a_roll); double s_roll = Math.sin(a_roll);
pXY[i][0] = c_roll * pXid + s_roll * pYid + this.pXY0[i][0]; pXY[i][0] = c_roll * pXid + s_roll * pYid + this.pXY0[i][0];
pXY[i][1] = -s_roll * pXid + c_roll * pYid + this.pXY0[i][1]; pXY[i][1] = -s_roll * pXid + c_roll * pYid + this.pXY0[i][1];
// double [][] pXYderiv = calc_deriv? new double [numSensors*2][CorrVector.LENGTH] : null;
if (pXYderiv != null) { if (pXYderiv != null) {
pXYderiv[2 * i] = new double [CorrVector.LENGTH]; pXYderiv[2 * i] = new double [CorrVector.LENGTH];
...@@ -1137,16 +1456,11 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -1137,16 +1456,11 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
double drD2rND_dazimuth = drD2rND_dri * dri_dazimuth; double drD2rND_dazimuth = drD2rND_dri * dri_dazimuth;
double drD2rND_dtilt = drD2rND_dri * dri_dtilt; double drD2rND_dtilt = drD2rND_dri * dri_dtilt;
// double pXid = pXci * rD2rND;
// double pYid = pYci * rD2rND;
double dpXid_dazimuth = dpXci_dazimuth * rD2rND + pXid * drD2rND_dazimuth; double dpXid_dazimuth = dpXci_dazimuth * rD2rND + pXid * drD2rND_dazimuth;
double dpYid_dazimuth = pYid * drD2rND_dazimuth; double dpYid_dazimuth = pYid * drD2rND_dazimuth;
double dpXid_dtilt = pXid * drD2rND_dtilt; double dpXid_dtilt = pXid * drD2rND_dtilt;
double dpYid_dtilt = dpYci_dtilt * rD2rND + pYid * drD2rND_dtilt; double dpYid_dtilt = dpYci_dtilt * rD2rND + pYid * drD2rND_dtilt;
// pXY[i][0] = c_roll * pXid + s_roll * pYid + this.pXY0[i][0];
// pXY[i][1] = -s_roll * pXid + c_roll * pYid + this.pXY0[i][1];
double dxi_dazimuth = c_roll * dpXid_dazimuth + s_roll * dpYid_dazimuth; double dxi_dazimuth = c_roll * dpXid_dazimuth + s_roll * dpYid_dazimuth;
double dyi_dazimuth = -s_roll * dpXid_dazimuth + c_roll * dpYid_dazimuth; double dyi_dazimuth = -s_roll * dpXid_dazimuth + c_roll * dpYid_dazimuth;
...@@ -1174,8 +1488,8 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -1174,8 +1488,8 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
} }
return pXY; return pXY;
} }
public double [][] getPortsCoordinatesAndDerivatives( public double [][] getPortsCoordinatesAndDerivatives_old(
double [] dbg_a_vector, // replace actual radial distortion coefficients double [] dbg_a_vector, // replace actual radial distortion coefficients
CorrVector corr_vector, CorrVector corr_vector,
double [][] pXYderiv, // if not null, should be double[8][] double [][] pXYderiv, // if not null, should be double[8][]
...@@ -1183,7 +1497,6 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -1183,7 +1497,6 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
double py, double py,
double disparity) double disparity)
{ {
// String dbg_s = corr_vector.toString();
double [][] pXY = new double [numSensors][2]; double [][] pXY = new double [numSensors][2];
...@@ -1292,7 +1605,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -1292,7 +1605,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
// debug version, calculates derivatives as differences // debug version, calculates derivatives as differences
public double [][] getPortsCoordinatesAndDerivatives( public double [][] getPortsCoordinatesAndDerivatives_old(
double [] dbg_a_vector, // replace actual radial distortion coefficients double [] dbg_a_vector, // replace actual radial distortion coefficients
double delta, // 1e-6 double delta, // 1e-6
CorrVector corr_vector, CorrVector corr_vector,
...@@ -1303,7 +1616,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -1303,7 +1616,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
{ {
double [][] pXYderiv0 = new double[8][]; double [][] pXYderiv0 = new double[8][];
double [][] rslt = getPortsCoordinatesAndDerivatives( double [][] rslt = getPortsCoordinatesAndDerivatives_old(
dbg_a_vector, // double [] dbg_a_vector, // replace actual radial distortion coefficients dbg_a_vector, // double [] dbg_a_vector, // replace actual radial distortion coefficients
corr_vector, // CorrVector corr_vector, corr_vector, // CorrVector corr_vector,
pXYderiv0, // null, // false, // boolean calc_deriv, pXYderiv0, // null, // false, // boolean calc_deriv,
...@@ -1319,7 +1632,8 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -1319,7 +1632,8 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
CorrVector cv_delta_m = corr_vector.clone(); CorrVector cv_delta_m = corr_vector.clone();
cv_delta_p.vector[nPar] += 0.5 *delta; cv_delta_p.vector[nPar] += 0.5 *delta;
cv_delta_m.vector[nPar] -= 0.5 *delta; cv_delta_m.vector[nPar] -= 0.5 *delta;
double [][] rslt_p = getPortsCoordinatesAndDerivatives(
double [][] rslt_p = getPortsCoordinatesAndDerivatives_old(
dbg_a_vector, // double [] dbg_a_vector, // replace actual radial distortion coefficients dbg_a_vector, // double [] dbg_a_vector, // replace actual radial distortion coefficients
cv_delta_p, // CorrVector corr_vector, cv_delta_p, // CorrVector corr_vector,
null, // boolean calc_deriv, null, // boolean calc_deriv,
...@@ -1327,7 +1641,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -1327,7 +1641,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
py, // double py, py, // double py,
disparity // double disparity disparity // double disparity
); );
double [][] rslt_m = getPortsCoordinatesAndDerivatives( double [][] rslt_m = getPortsCoordinatesAndDerivatives_old(
dbg_a_vector, // double [] dbg_a_vector, // replace actual radial distortion coefficients dbg_a_vector, // double [] dbg_a_vector, // replace actual radial distortion coefficients
cv_delta_m, // CorrVector corr_vector, cv_delta_m, // CorrVector corr_vector,
null, // boolean calc_deriv, null, // boolean calc_deriv,
...@@ -1344,10 +1658,70 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -1344,10 +1658,70 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
return rslt; return rslt;
} }
public double [][] getPortsCoordinatesAndDerivatives( // uses rotations
double [] dbg_a_vector, // replace actual radial distortion coefficients (not currently used)
double delta, // 1e-6
CorrVector corr_vector,
double [][] pXYderiv, // if not null, should be double[8][]
double px,
double py,
double disparity)
{
// slower, will re-calculate matrices for each tile, but for debug - that is OK
Matrix [] corr_rots = corr_vector.getRotMatrices(); // get array of per-sensor rotation matrices
/// Matrix [][] deriv_rots = corr_vector.getRotDeriveMatrices();
/// double [][] pXYderiv0 = new double[8][];
double [][] rslt = getPortsCoordinatesAndDerivatives(
// dbg_a_vector, // double [] dbg_a_vector, // replace actual radial distortion coefficients
corr_rots, // Matrix [] rots,
null, // deriv_rots, // Matrix [][] deriv_rots,
null, // pXYderiv0, // null, // false, // boolean calc_deriv,
px, // double px,
py, // double py,
disparity // double disparity
);
for (int i = 0; i < pXYderiv.length; i++){
pXYderiv[i] = new double [CorrVector.LENGTH];
}
for (int nPar = 0; nPar < CorrVector.LENGTH; nPar++){
CorrVector cv_delta_p = corr_vector.clone();
CorrVector cv_delta_m = corr_vector.clone();
cv_delta_p.vector[nPar] += 0.5 *delta;
cv_delta_m.vector[nPar] -= 0.5 *delta;
Matrix [] corr_rots_p = cv_delta_p.getRotMatrices(); // get array of per-sensor rotation matrices
Matrix [] corr_rots_m = cv_delta_m.getRotMatrices(); // get array of per-sensor rotation matrices
double [][] rslt_p = getPortsCoordinatesAndDerivatives(
// dbg_a_vector, // double [] dbg_a_vector, // replace actual radial distortion coefficients
corr_rots_p, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // boolean calc_deriv,
px, // double px,
py, // double py,
disparity // double disparity
);
double [][] rslt_m = getPortsCoordinatesAndDerivatives(
// dbg_a_vector, // double [] dbg_a_vector, // replace actual radial distortion coefficients
corr_rots_m, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // boolean calc_deriv,
px, // double px,
py, // double py,
disparity // double disparity
);
for (int sens = 0; sens < numSensors; sens++){
for (int dir = 0; dir < 2; dir++){
pXYderiv[2 * sens +dir][nPar] = (rslt_p[sens][dir] - rslt_m[sens][dir]) / delta;
}
}
}
return rslt;
}
// should return same as input if disparity==0 // should return same as input if disparity==0
public double [][] getPortsCoordinatesIdeal( public double [][] getPortsCoordinatesIdeal(
double px, double px,
...@@ -1399,12 +1773,12 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0. ...@@ -1399,12 +1773,12 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
double py, double py,
double disparity) double disparity)
{ {
if (macro_scale == 1){ // if (macro_scale == 1){
return getPortsCoordinates( // return getPortsCoordinates(
px * macro_scale, // px * macro_scale,
py * macro_scale, // py * macro_scale,
disparity); // disparity);
} // }
double [][] coords = getPortsCoordinatesIdeal( double [][] coords = getPortsCoordinatesIdeal(
px * macro_scale, px * macro_scale,
py * macro_scale, py * macro_scale,
......
import java.util.concurrent.atomic.AtomicInteger;
import ij.ImageStack;
/** /**
** **
** ImageDtt - Process images with DTT-based methods ** ImageDtt - Process images with DTT-based methods
...@@ -25,6 +21,9 @@ import ij.ImageStack; ...@@ -25,6 +21,9 @@ import ij.ImageStack;
** -----------------------------------------------------------------------------** ** -----------------------------------------------------------------------------**
** **
*/ */
import java.util.concurrent.atomic.AtomicInteger;
import Jama.Matrix;
import ij.ImageStack;
public class ImageDtt { public class ImageDtt {
...@@ -847,6 +846,7 @@ public class ImageDtt { ...@@ -847,6 +846,7 @@ public class ImageDtt {
final double [][][][][][] clt_data = new double[quad][nChn][tilesY][tilesX][4][]; final double [][][][][][] clt_data = new double[quad][nChn][tilesY][tilesX][4][];
final Thread[] threads = newThreadArray(threadsMax); final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0);
final Matrix [] corr_rots = geometryCorrection.getCorrVector().getRotMatrices(); // get array of per-sensor rotation matrices
if (globalDebugLevel > 0) { if (globalDebugLevel > 0) {
...@@ -872,23 +872,34 @@ public class ImageDtt { ...@@ -872,23 +872,34 @@ public class ImageDtt {
// tileX = nTile % tilesX; // tileX = nTile % tilesX;
tileY = nTile /tilesX; tileY = nTile /tilesX;
tileX = nTile % tilesX; tileX = nTile % tilesX;
for (int chn = 0; chn <numcol; chn++) {
centerX = tileX * transform_size + transform_size/2 - shiftX; centerX = tileX * transform_size + transform_size/2 - shiftX;
centerY = tileY * transform_size + transform_size/2 - shiftY; centerY = tileY * transform_size + transform_size/2 - shiftY;
double [][] centersXY = geometryCorrection.getPortsCoordinates( // double [][] centersXY = geometryCorrection.getPortsCoordinates(
centerX, // centerX,
centerY, // centerY,
disparity); // disparity);
if ((globalDebugLevel > 0) && (tileX >= debug_tileX - 2) && (tileX <= debug_tileX + 2) && double [][] centersXY = geometryCorrection.getPortsCoordinatesAndDerivatives(
(tileY >= debug_tileY - 2) && (tileY <= debug_tileY+2)) { corr_rots, // Matrix [] rots,
for (int i = 0; i < quad; i++) { null, // Matrix [][] deriv_rots,
System.out.println("clt_aberrations_quad(): color="+chn+", tileX="+tileX+", tileY="+tileY+ null, // double [][] pXYderiv, // if not null, should be double[8][]
" centerX="+centerX+" centerY="+centerY+" disparity="+disparity+ centerX,
" centersXY["+i+"][0]="+centersXY[i][0]+" centersXY["+i+"][1]="+centersXY[i][1]); centerY,
} disparity);
if ((globalDebugLevel > 0) && (tileX >= debug_tileX - 2) && (tileX <= debug_tileX + 2) &&
(tileY >= debug_tileY - 2) && (tileY <= debug_tileY+2)) {
for (int i = 0; i < quad; i++) {
System.out.println("clt_aberrations_quad(): tileX="+tileX+", tileY="+tileY+
" centerX="+centerX+" centerY="+centerY+" disparity="+disparity+
" centersXY["+i+"][0]="+centersXY[i][0]+" centersXY["+i+"][1]="+centersXY[i][1]);
} }
}
for (int chn = 0; chn <numcol; chn++) {
for (int i = 0; i < quad; i++) { for (int i = 0; i < quad; i++) {
fract_shiftsXY[i] = extract_correct_tile( // return a pair of resudual offsets fract_shiftsXY[i] = extract_correct_tile( // return a pair of resudual offsets
...@@ -1023,8 +1034,8 @@ public class ImageDtt { ...@@ -1023,8 +1034,8 @@ public class ImageDtt {
final int threadsMax, // maximal number of threads to launch final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel) final int globalDebugLevel)
{ {
final boolean debug_ports_coordinates = (debug_tileX == -1234);
final boolean macro_mode = macro_scale != 1; // correlate tile data instead of the pixel data final boolean macro_mode = macro_scale != 1; // correlate tile data instead of the pixel data
final int quad = 4; // number of subcameras final int quad = 4; // number of subcameras
final int numcol = 3; // number of colors final int numcol = 3; // number of colors
final int nChn = image_data[0].length; final int nChn = image_data[0].length;
...@@ -1163,9 +1174,19 @@ public class ImageDtt { ...@@ -1163,9 +1174,19 @@ public class ImageDtt {
sdfa_instance.showArrays(lt_window, 2*transform_size, 2*transform_size, "lt_window"); sdfa_instance.showArrays(lt_window, 2*transform_size, 2*transform_size, "lt_window");
} }
// final double [] overexposed = disparity_map[OVEREXPOSED]; /* final double [][] dbg_ports_coords = debug_ports_coordinates ? (new double[4*2*3][nTilesInChn]):null;
// final int [][] overexp_all = (saturation_imp != null) ? ( new int [tilesX*tilesY][2]): null; String [] dbg_titles = new String[4*2*3];
if (dbg_ports_coords != null) {
for (int dbg_p = 0; dbg_p < 4; dbg_p++){
for (int dbg_d = 0; dbg_d < 2; dbg_d++){
dbg_titles [6 * dbg_p + 3 * dbg_d + 0] = "port_"+dbg_p+((dbg_d > 0)?"y":"x")+"_diff";
dbg_titles [6 * dbg_p + 3 * dbg_d + 1] = "port_"+dbg_p+((dbg_d > 0)?"y":"x")+"_shft";
dbg_titles [6 * dbg_p + 3 * dbg_d + 2] = "port_"+dbg_p+((dbg_d > 0)?"y":"x")+"_rot";
}
}
}
*/
final Matrix [] corr_rots = geometryCorrection.getCorrVector().getRotMatrices(); // get array of per-sensor rotation matrices
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() {
...@@ -1182,6 +1203,7 @@ public class ImageDtt { ...@@ -1182,6 +1203,7 @@ public class ImageDtt {
PolynomialApproximation pa = null; PolynomialApproximation pa = null;
if (corr_max_weights_poly !=null) pa = new PolynomialApproximation(0); // debug level if (corr_max_weights_poly !=null) pa = new PolynomialApproximation(0); // debug level
for (int nTile = ai.getAndIncrement(); nTile < nTilesInChn; nTile = ai.getAndIncrement()) { for (int nTile = ai.getAndIncrement(); nTile < nTilesInChn; nTile = ai.getAndIncrement()) {
tileY = nTile /tilesX; tileY = nTile /tilesX;
tileX = nTile % tilesX; tileX = nTile % tilesX;
tIndex = tileY * tilesX + tileX; tIndex = tileY * tilesX + tileX;
...@@ -1197,10 +1219,105 @@ public class ImageDtt { ...@@ -1197,10 +1219,105 @@ public class ImageDtt {
boolean debugTile =(tileX == debug_tileX) && (tileY == debug_tileY); boolean debugTile =(tileX == debug_tileX) && (tileY == debug_tileY);
final int [] overexp_all = (saturation_imp != null) ? ( new int [2]): null; final int [] overexp_all = (saturation_imp != null) ? ( new int [2]): null;
// Moved from inside chn loop
centerX = tileX * transform_size + transform_size/2 - shiftX;
centerY = tileY * transform_size + transform_size/2 - shiftY;
// TODO: move port coordinates out of color channel loop
double [][] centersXY;
if (macro_mode){
if ((globalDebugLevel > -1) && (tileX == debug_tileX) && (tileY == debug_tileY)) { // before correction
System.out.println("\nUsing MACRO mode, centerX="+centerX+", centerY="+centerY);
}
centersXY = geometryCorrection.getPortsCoordinatesIdeal(
macro_scale,
centerX,
centerY,
macro_scale* disparity_array[tileY][tileX] + disparity_corr);
} else {
centersXY = geometryCorrection.getPortsCoordinatesAndDerivatives(
corr_rots, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
centerX,
centerY,
disparity_array[tileY][tileX] + disparity_corr);
/*
if (dbg_ports_coords != null) {
double [][] centersXY_shift = geometryCorrection.getPortsCoordinates_old(
centerX,
centerY,
disparity_array[tileY][tileX] + disparity_corr);
for (int dbg_p = 0; dbg_p < 4; dbg_p++){
for (int dbg_d = 0; dbg_d < 2; dbg_d++){
dbg_ports_coords[6 * dbg_p + 3 * dbg_d + 0][nTile] = centersXY[dbg_p][dbg_d] - centersXY_shift[dbg_p][dbg_d];
dbg_ports_coords[6 * dbg_p + 3 * dbg_d + 1][nTile] = centersXY_shift[dbg_p][dbg_d];
dbg_ports_coords[6 * dbg_p + 3 * dbg_d + 2][nTile] = centersXY[dbg_p][dbg_d];
}
}
// centersXY = centersXY_rot; // use these
}
*/
if ((globalDebugLevel > 0) && (tileX == debug_tileX) && (tileY == debug_tileY)) {
for (int i = 0; i < quad; i++) {
System.out.println("clt_aberrations_quad_corr(): tileX="+tileX+", tileY="+tileY+
" centerX="+centerX+" centerY="+centerY+" disparity="+disparity_array[tileY][tileX]+
" centersXY["+i+"][0]="+centersXY[i][0]+" centersXY["+i+"][1]="+centersXY[i][1]);
}
}
if ((globalDebugLevel > -1) && (tileX == debug_tileX) && (tileY == debug_tileY)) { // before correction
System.out.print(disparity_array[tileY][tileX]+"\t"+
centersXY[0][0]+"\t"+centersXY[0][1]+"\t"+
centersXY[1][0]+"\t"+centersXY[1][1]+"\t"+
centersXY[2][0]+"\t"+centersXY[2][1]+"\t"+
centersXY[3][0]+"\t"+centersXY[3][1]+"\t");
}
for (int ip = 0; ip < centersXY.length; ip++){
centersXY[ip][0] -= shiftXY[ip][0];
centersXY[ip][1] -= shiftXY[ip][1];
}
// TODO: use correction after disparity applied (to work for large disparity values)
if (fine_corr != null){
// old correction
//double tX = (2.0 * tileX)/tilesX - 1.0; // -1.0 to +1.0
//double tY = (2.0 * tileY)/tilesY - 1.0; // -1.0 to +1.0
//for (int ip = 0; ip < centersXY.length; ip++){
// //f(x,y)=A*x^2+B*y^2+C*x*y+D*x+E*y+F
// for (int d = 0; d <2; d++)
// centersXY[ip][d] -= (
// fine_corr[ip][d][0]*tX*tX+
// fine_corr[ip][d][1]*tY*tY+
// fine_corr[ip][d][2]*tX*tY+
// fine_corr[ip][d][3]*tX+
// fine_corr[ip][d][4]*tY+
// fine_corr[ip][d][5]);
//}
for (int ip = 0; ip < centersXY.length; ip++){
double [] tXY = geometryCorrection.getRelativeCoords(centersXY[ip]);
for (int d = 0; d <2; d++) {
centersXY[ip][d] -= (
fine_corr[ip][d][0]*tXY[0]*tXY[0]+
fine_corr[ip][d][1]*tXY[1]*tXY[1]+
fine_corr[ip][d][2]*tXY[0]*tXY[1]+
fine_corr[ip][d][3]*tXY[0]+
fine_corr[ip][d][4]*tXY[1]+
fine_corr[ip][d][5]);
}
}
}
} // if (macro_mode) ... else
for (int chn = 0; chn <numcol; chn++) { for (int chn = 0; chn <numcol; chn++) {
/*
centerX = tileX * transform_size + transform_size/2 - shiftX; centerX = tileX * transform_size + transform_size/2 - shiftX;
centerY = tileY * transform_size + transform_size/2 - shiftY; centerY = tileY * transform_size + transform_size/2 - shiftY;
// TODO: move port coordinates out of color channel loop
double [][] centersXY; double [][] centersXY;
if (macro_mode){ if (macro_mode){
if ((globalDebugLevel > -1) && (tileX == debug_tileX) && (tileY == debug_tileY) && (chn == 2)) { // before correction if ((globalDebugLevel > -1) && (tileX == debug_tileX) && (tileY == debug_tileY) && (chn == 2)) { // before correction
...@@ -1239,21 +1356,19 @@ public class ImageDtt { ...@@ -1239,21 +1356,19 @@ public class ImageDtt {
// TODO: use correction after disparity applied (to work for large disparity values) // TODO: use correction after disparity applied (to work for large disparity values)
if (fine_corr != null){ if (fine_corr != null){
// old correction // old correction
/* //double tX = (2.0 * tileX)/tilesX - 1.0; // -1.0 to +1.0
double tX = (2.0 * tileX)/tilesX - 1.0; // -1.0 to +1.0 //double tY = (2.0 * tileY)/tilesY - 1.0; // -1.0 to +1.0
double tY = (2.0 * tileY)/tilesY - 1.0; // -1.0 to +1.0 //for (int ip = 0; ip < centersXY.length; ip++){
for (int ip = 0; ip < centersXY.length; ip++){ // //f(x,y)=A*x^2+B*y^2+C*x*y+D*x+E*y+F
//f(x,y)=A*x^2+B*y^2+C*x*y+D*x+E*y+F // for (int d = 0; d <2; d++)
for (int d = 0; d <2; d++) // centersXY[ip][d] -= (
centersXY[ip][d] -= ( // fine_corr[ip][d][0]*tX*tX+
fine_corr[ip][d][0]*tX*tX+ // fine_corr[ip][d][1]*tY*tY+
fine_corr[ip][d][1]*tY*tY+ // fine_corr[ip][d][2]*tX*tY+
fine_corr[ip][d][2]*tX*tY+ // fine_corr[ip][d][3]*tX+
fine_corr[ip][d][3]*tX+ // fine_corr[ip][d][4]*tY+
fine_corr[ip][d][4]*tY+ // fine_corr[ip][d][5]);
fine_corr[ip][d][5]); //}
}
*/
for (int ip = 0; ip < centersXY.length; ip++){ for (int ip = 0; ip < centersXY.length; ip++){
double [] tXY = geometryCorrection.getRelativeCoords(centersXY[ip]); double [] tXY = geometryCorrection.getRelativeCoords(centersXY[ip]);
...@@ -1268,7 +1383,11 @@ public class ImageDtt { ...@@ -1268,7 +1383,11 @@ public class ImageDtt {
} }
} }
} }
} } // if (macro_mode) ... else
*/
if ((globalDebugLevel > -1) && (tileX == debug_tileX) && (tileY == debug_tileY) && (chn == 2)) { if ((globalDebugLevel > -1) && (tileX == debug_tileX) && (tileY == debug_tileY) && (chn == 2)) {
System.out.println("\nUsing "+(macro_mode?"MACRO":"PIXEL")+" mode, centerX="+centerX+", centerY="+centerY); System.out.println("\nUsing "+(macro_mode?"MACRO":"PIXEL")+" mode, centerX="+centerX+", centerY="+centerY);
System.out.println(disparity_array[tileY][tileX]+"\t"+ System.out.println(disparity_array[tileY][tileX]+"\t"+
...@@ -1821,6 +1940,11 @@ public class ImageDtt { ...@@ -1821,6 +1940,11 @@ public class ImageDtt {
}; };
} }
startAndJoin(threads); startAndJoin(threads);
/*
if (dbg_ports_coords != null) {
(new showDoubleFloatArrays()).showArrays(dbg_ports_coords, tilesX, tilesY, true, "ports_coordinates", dbg_titles);
}
*/
return clt_data; return clt_data;
} }
......
...@@ -106,12 +106,13 @@ public class QuadCLT { ...@@ -106,12 +106,13 @@ public class QuadCLT {
} }
} }
} }
GeometryCorrection gc = geometryCorrection;
if (geometryCorrection != null){ if (gc == null) { // if it was not yet created
for (int i = 0; i < GeometryCorrection.CORR_NAMES.length; i++){ gc = new GeometryCorrection(this.extrinsic_corr);
String name = prefix+"extrinsic_corr_"+GeometryCorrection.CORR_NAMES[i]; }
properties.setProperty(name, geometryCorrection.getCorrVector().toArray()[i]+""); for (int i = 0; i < GeometryCorrection.CORR_NAMES.length; i++){
} String name = prefix+"extrinsic_corr_"+GeometryCorrection.CORR_NAMES[i];
properties.setProperty(name, gc.getCorrVector().toArray()[i]+"");
} }
} }
...@@ -2607,7 +2608,7 @@ public class QuadCLT { ...@@ -2607,7 +2608,7 @@ public class QuadCLT {
updateStatus, updateStatus,
debugLevel); debugLevel);
Runtime.getRuntime().gc(); Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+fileIndices.length+") finished at "+ if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+setNames.size()+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")"); IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) { if (eyesisCorrections.stopRequested.get()>0) {
System.out.println("User requested stop"); System.out.println("User requested stop");
...@@ -3264,7 +3265,7 @@ public class QuadCLT { ...@@ -3264,7 +3265,7 @@ public class QuadCLT {
false, // batch_mode false, // batch_mode
debugLevel); debugLevel);
Runtime.getRuntime().gc(); Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+fileIndices.length+") finished at "+ if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+setNames.size()+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")"); IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) { if (eyesisCorrections.stopRequested.get()>0) {
System.out.println("User requested stop"); System.out.println("User requested stop");
...@@ -3596,11 +3597,15 @@ public class QuadCLT { ...@@ -3596,11 +3597,15 @@ public class QuadCLT {
// double min_corr_selected = clt_parameters.corr_normalize? clt_parameters.min_corr_normalized: clt_parameters.min_corr; // double min_corr_selected = clt_parameters.corr_normalize? clt_parameters.min_corr_normalized: clt_parameters.min_corr;
double min_corr_selected = clt_parameters.min_corr; double min_corr_selected = clt_parameters.min_corr;
double [][] shiftXY = { double [][] shiftXY = new double [4][2];
{clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0}, if (!clt_parameters.fine_corr_ignore) {
{clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1}, double [][] shiftXY0 = {
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2}, {clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}}; {clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1},
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}};
shiftXY = shiftXY0;
}
final double disparity_corr = (clt_parameters.z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/clt_parameters.z_correction); final double disparity_corr = (clt_parameters.z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/clt_parameters.z_correction);
double [][][][][][] clt_data = image_dtt.clt_aberrations_quad_corr( double [][][][][][] clt_data = image_dtt.clt_aberrations_quad_corr(
...@@ -3652,8 +3657,8 @@ public class QuadCLT { ...@@ -3652,8 +3657,8 @@ public class QuadCLT {
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing 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.shift_y, // final int shiftY, // shift image vertically (positive - down)
clt_parameters.tileX, // final int debug_tileX, -1234, // clt_parameters.tileX, // final int debug_tileX,
clt_parameters.tileY, // final int debug_tileY, clt_parameters.tileY, // final int debug_tileY, -1234 will cause port coordinates debug images
(clt_parameters.dbg_mode & 64) != 0, // no fract shift (clt_parameters.dbg_mode & 64) != 0, // no fract shift
(clt_parameters.dbg_mode & 128) != 0, // no convolve (clt_parameters.dbg_mode & 128) != 0, // no convolve
// (clt_parameters.dbg_mode & 256) != 0, // transpose convolve // (clt_parameters.dbg_mode & 256) != 0, // transpose convolve
...@@ -3719,7 +3724,7 @@ public class QuadCLT { ...@@ -3719,7 +3724,7 @@ public class QuadCLT {
(clt_parameters.keep_weights?rgba_weights_titles:rgba_titles)); (clt_parameters.keep_weights?rgba_weights_titles:rgba_titles));
} }
if (!batch_mode && clt_parameters.show_rgba_color) { if (!batch_mode && clt_parameters.show_rgba_color) {
// for now - use just RGB. Later add oprion for RGBA // for now - use just RGB. Later add option for RGBA
double [][] texture_rgb = {texture_overlap[0],texture_overlap[1],texture_overlap[2]}; double [][] texture_rgb = {texture_overlap[0],texture_overlap[1],texture_overlap[2]};
double [][] texture_rgba = {texture_overlap[0],texture_overlap[1],texture_overlap[2],texture_overlap[3]}; double [][] texture_rgba = {texture_overlap[0],texture_overlap[1],texture_overlap[2],texture_overlap[3]};
// ImagePlus img_texture = // ImagePlus img_texture =
...@@ -3976,7 +3981,7 @@ public class QuadCLT { ...@@ -3976,7 +3981,7 @@ public class QuadCLT {
debugLevel ); debugLevel );
} // end of generating shifted channel images } // end of generating shifted channel images
if (!batch_mode && clt_parameters.gen_chn_img) { if (clt_parameters.gen_chn_img) {
// combine to a sliced color image // combine to a sliced color image
int [] slice_seq = {0,1,3,2}; //clockwise int [] slice_seq = {0,1,3,2}; //clockwise
int width = imps_RGB[0].getWidth(); int width = imps_RGB[0].getWidth();
...@@ -3991,10 +3996,17 @@ public class QuadCLT { ...@@ -3991,10 +3996,17 @@ public class QuadCLT {
} }
ImagePlus imp_stack = new ImagePlus(name+"-SHIFTED-D"+clt_parameters.disparity, array_stack); ImagePlus imp_stack = new ImagePlus(name+"-SHIFTED-D"+clt_parameters.disparity, array_stack);
imp_stack.getProcessor().resetMinAndMax(); imp_stack.getProcessor().resetMinAndMax();
imp_stack.updateAndDraw(); if (!batch_mode) {
imp_stack.updateAndDraw();
}
//imp_stack.getProcessor().resetMinAndMax(); //imp_stack.getProcessor().resetMinAndMax();
//imp_stack.show(); //imp_stack.show();
eyesisCorrections.saveAndShow(imp_stack, this.correctionsParameters); // eyesisCorrections.saveAndShow(imp_stack, this.correctionsParameters);
eyesisCorrections.saveAndShowEnable(
imp_stack, // ImagePlus imp,
this.correctionsParameters, // EyesisCorrectionParameters.CorrectionParameters correctionsParameters,
true, // boolean enableSave,
!batch_mode) ;// boolean enableShow);
} }
if (clt_parameters.gen_4_img) { if (clt_parameters.gen_4_img) {
// Save as individual JPEG images in the model directory // Save as individual JPEG images in the model directory
...@@ -4301,12 +4313,16 @@ public class QuadCLT { ...@@ -4301,12 +4313,16 @@ public class QuadCLT {
System.out.println(geometryCorrection.getCorrVector().toString()); System.out.println(geometryCorrection.getCorrVector().toString());
} }
} }
public void resetExtrinsicCorr() public void resetExtrinsicCorr(
EyesisCorrectionParameters.CLTParameters clt_parameters)
{ {
this.extrinsic_corr = new double [GeometryCorrection.CORR_NAMES.length]; this.extrinsic_corr = new double [GeometryCorrection.CORR_NAMES.length];
if (geometryCorrection != null){ if (geometryCorrection != null){
geometryCorrection.setCorrVector(null); geometryCorrection.setCorrVector(null);
} }
if (clt_parameters.fine_corr_apply){
clt_parameters.fine_corr_ignore = false;
}
} }
public void cltDisparityScans( public void cltDisparityScans(
...@@ -4645,11 +4661,15 @@ public class QuadCLT { ...@@ -4645,11 +4661,15 @@ public class QuadCLT {
double disparity = clt_parameters.disp_scan_start + scan_step * clt_parameters.disp_scan_step; double disparity = clt_parameters.disp_scan_start + scan_step * clt_parameters.disp_scan_step;
double [][] disparity_array = tp.setSameDisparity(disparity); // [tp.tilesY][tp.tilesX] - individual per-tile expected disparity double [][] disparity_array = tp.setSameDisparity(disparity); // [tp.tilesY][tp.tilesX] - individual per-tile expected disparity
double [][] shiftXY = { double [][] shiftXY = new double [4][2];
{clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0}, if (!clt_parameters.fine_corr_ignore) {
{clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1}, double [][] shiftXY0 = {
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2}, {clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}}; {clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1},
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}};
shiftXY = shiftXY0;
}
final double disparity_corr = (clt_parameters.z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/clt_parameters.z_correction); final double disparity_corr = (clt_parameters.z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/clt_parameters.z_correction);
...@@ -5479,7 +5499,7 @@ public class QuadCLT { ...@@ -5479,7 +5499,7 @@ public class QuadCLT {
} }
Runtime.getRuntime().gc(); Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+fileIndices.length+") finished at "+ if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+setNames.size()+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")"); IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) { if (eyesisCorrections.stopRequested.get()>0) {
System.out.println("User requested stop"); System.out.println("User requested stop");
...@@ -7746,11 +7766,15 @@ public class QuadCLT { ...@@ -7746,11 +7766,15 @@ public class QuadCLT {
double [][] disparity_map = new double [ImageDtt.DISPARITY_TITLES.length][]; //[0] -residual disparity, [1] - orthogonal (just for debugging) double [][] disparity_map = new double [ImageDtt.DISPARITY_TITLES.length][]; //[0] -residual disparity, [1] - orthogonal (just for debugging)
double [][] shiftXY = { double [][] shiftXY = new double [4][2];
{clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0}, if (!clt_parameters.fine_corr_ignore) {
{clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1}, double [][] shiftXY0 = {
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2}, {clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}}; {clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1},
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}};
shiftXY = shiftXY0;
}
double [][][][] texture_tiles = new double [tilesY][tilesX][][]; // ["RGBA".length()][]; double [][][][] texture_tiles = new double [tilesY][tilesX][][]; // ["RGBA".length()][];
ImageDtt image_dtt = new ImageDtt(); ImageDtt image_dtt = new ImageDtt();
...@@ -7948,11 +7972,15 @@ public class QuadCLT { ...@@ -7948,11 +7972,15 @@ public class QuadCLT {
double [][] disparity_map = save_corr ? new double [ImageDtt.DISPARITY_TITLES.length][] : null; //[0] -residual disparity, [1] - orthogonal (just for debugging) double [][] disparity_map = save_corr ? new double [ImageDtt.DISPARITY_TITLES.length][] : null; //[0] -residual disparity, [1] - orthogonal (just for debugging)
double [][] shiftXY = { double [][] shiftXY = new double [4][2];
{clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0}, if (!clt_parameters.fine_corr_ignore) {
{clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1}, double [][] shiftXY0 = {
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2}, {clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}}; {clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1},
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}};
shiftXY = shiftXY0;
}
double [][][][] texture_tiles = save_textures ? new double [tilesY][tilesX][][] : null; // ["RGBA".length()][]; double [][][][] texture_tiles = save_textures ? new double [tilesY][tilesX][][] : null; // ["RGBA".length()][];
ImageDtt image_dtt = new ImageDtt(); ImageDtt image_dtt = new ImageDtt();
...@@ -8285,7 +8313,6 @@ public class QuadCLT { ...@@ -8285,7 +8313,6 @@ public class QuadCLT {
final boolean updateStatus, final boolean updateStatus,
final int debugLevel) final int debugLevel)
{ {
this.startTime=System.nanoTime(); this.startTime=System.nanoTime();
String [] sourceFiles=correctionsParameters.getSourcePaths(); String [] sourceFiles=correctionsParameters.getSourcePaths();
boolean [] enabledFiles=new boolean[sourceFiles.length]; boolean [] enabledFiles=new boolean[sourceFiles.length];
...@@ -8345,12 +8372,13 @@ public class QuadCLT { ...@@ -8345,12 +8372,13 @@ public class QuadCLT {
} }
setFiles.get(setNames.indexOf(setName)).add(new Integer(nFile)); setFiles.get(setNames.indexOf(setName)).add(new Integer(nFile));
} }
boolean batch_dbg = correctionsParameters.clt_batch_dbg1 && (setNames.size() < 2) ;
// Do per 4-image set processing // Do per 4-image set processing
int nSet = 0; int nSet = 0;
for (nSet = 0; nSet < setNames.size(); nSet++){ for (nSet = 0; nSet < setNames.size(); nSet++){
if ((nSet > 0) &&(debugLevel > -2)) { if ((nSet > 0) &&(debugLevel > -2)) {
System.out.println("Processing set "+(nSet+1)+" (of "+fileIndices.length+") finished at "+ System.out.println("Processing set "+(nSet+1)+" (of "+setNames.size()+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startSetTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")"); IJ.d2s(0.000000001*(System.nanoTime()-this.startSetTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
} }
this.startSetTime = System.nanoTime(); this.startSetTime = System.nanoTime();
...@@ -8365,29 +8393,67 @@ public class QuadCLT { ...@@ -8365,29 +8393,67 @@ public class QuadCLT {
referenceExposures, //final double [] referenceExposures, // =eyesisCorrections.calcReferenceExposures(debugLevel); // multiply each image by this and divide by individual (if not NaN) referenceExposures, //final double [] referenceExposures, // =eyesisCorrections.calcReferenceExposures(debugLevel); // multiply each image by this and divide by individual (if not NaN)
scaleExposures, // final double [] scaleExposures, // = new double[channelFiles.length]; // scaleExposures, // final double [] scaleExposures, // = new double[channelFiles.length]; //
saturation_imp, // final boolean [][] saturation_imp, // = (clt_parameters.sat_level > 0.0)? new boolean[channelFiles.length][] : null; saturation_imp, // final boolean [][] saturation_imp, // = (clt_parameters.sat_level > 0.0)? new boolean[channelFiles.length][] : null;
true, // final boolean batch_mode, // disable any debug images !batch_dbg, // final boolean batch_mode, // disable any debug images
debugLevel); // final int debugLevel) debugLevel); // final int debugLevel)
// once per quad here // once per quad here
if (imp_srcs == null) continue; if (imp_srcs == null) continue;
if (correctionsParameters.clt_batch_4img){ // creating GeometryCorrection instance for applyPixelShift()
processCLTQuadCorr( // returns ImagePlus, but it already should be saved/shown // setTiles (imp_srcs[0], // set global tp.tilesX, tp.tilesY
imp_srcs, // [srcChannel], // should have properties "name"(base for saving results), "channel","path" // clt_parameters,
saturation_imp, // boolean [][] saturation_imp, // (near) saturated pixels or null // threadsMax);
clt_parameters,
debayerParameters, if (correctionsParameters.clt_batch_apply_man) {
nonlinParameters, boolean fine_corr_set = !clt_parameters.fine_corr_ignore;
colorProcParameters, if (fine_corr_set) {
channelGainParameters, boolean nz = false;
rgbParameters, double [][] shiftXY = {
convolveFFTSize, // 128 - fft size, kernel size should be size/2 {clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0},
scaleExposures, {clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1},
false, // apply_corr, // calculate and apply additional fine geometry correction {clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2},
false, // infinity_corr, // calculate and apply geometry correction at infinity {clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}};
threadsMax, // maximal number of threads to launch
true, // batch_mode for (int i = 0; i < shiftXY.length; i++){
updateStatus, for (int j = 0; j < shiftXY[i].length; j++){
debugLevel); if (shiftXY[i][j] != 0.0) {
nz = true;
break;
}
}
}
if (nz) {
geometryCorrection.getCorrVector().applyPixelShift(
shiftXY); // double [][] pXY_shift)
clt_parameters.fine_corr_ignore = true;
System.out.println("Detected non-zero manual pixel correction, applying it to extrinsics (azimuth, tilt) and disabling");
}
}
} else if (!clt_parameters.fine_corr_ignore){ // temporary? Remove DC from the manual correction
double [][] shiftXY = {
{clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0},
{clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1},
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}};
double [] pXY_avg = {0.0,0.0};
for (int i = 0; i < shiftXY.length; i++){
for (int j = 0; j < 2; j++) {
pXY_avg[j] += shiftXY[i][j]/shiftXY.length;
}
}
for (int i = 0; i < shiftXY.length; i++){
for (int j = 0; j < 2; j++) {
shiftXY[i][j] -= pXY_avg[j];
}
}
clt_parameters.fine_corr_x_0 = shiftXY[0][0];
clt_parameters.fine_corr_y_0 = shiftXY[0][1];
clt_parameters.fine_corr_x_1 = shiftXY[1][0];
clt_parameters.fine_corr_y_1 = shiftXY[1][1];
clt_parameters.fine_corr_x_2 = shiftXY[2][0];
clt_parameters.fine_corr_y_2 = shiftXY[2][1];
clt_parameters.fine_corr_x_3 = shiftXY[3][0];
clt_parameters.fine_corr_y_3 = shiftXY[3][1];
} }
if (correctionsParameters.clt_batch_extrinsic) { if (correctionsParameters.clt_batch_extrinsic) {
if (tp != null) tp.resetCLTPasses(); if (tp != null) tp.resetCLTPasses();
...@@ -8410,7 +8476,7 @@ public class QuadCLT { ...@@ -8410,7 +8476,7 @@ public class QuadCLT {
false, // adjust_poly, false, // adjust_poly,
threadsMax, //final int threadsMax, // maximal number of threads to launch threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus, updateStatus, // final boolean updateStatus,
true, // final boolean batch_mode, !batch_dbg, // final boolean batch_mode,
debugLevel); // final int debugLevel) debugLevel); // final int debugLevel)
} }
} }
...@@ -8435,11 +8501,30 @@ public class QuadCLT { ...@@ -8435,11 +8501,30 @@ public class QuadCLT {
true, // adjust_poly, true, // adjust_poly,
threadsMax, //final int threadsMax, // maximal number of threads to launch threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus, updateStatus, // final boolean updateStatus,
true, // final boolean batch_mode, !batch_dbg, // final boolean batch_mode,
debugLevel); // final int debugLevel) debugLevel); // final int debugLevel)
} }
} }
if (correctionsParameters.clt_batch_4img){
processCLTQuadCorr( // returns ImagePlus, but it already should be saved/shown
imp_srcs, // [srcChannel], // should have properties "name"(base for saving results), "channel","path"
saturation_imp, // boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
debayerParameters,
nonlinParameters,
colorProcParameters,
channelGainParameters,
rgbParameters,
convolveFFTSize, // 128 - fft size, kernel size should be size/2
scaleExposures,
false, // apply_corr, // calculate and apply additional fine geometry correction
false, // infinity_corr, // calculate and apply geometry correction at infinity
threadsMax, // maximal number of threads to launch
!batch_dbg, // batch_mode
updateStatus,
debugLevel);
}
if (correctionsParameters.clt_batch_explore) { if (correctionsParameters.clt_batch_explore) {
if (tp != null) tp.resetCLTPasses(); if (tp != null) tp.resetCLTPasses();
boolean ok = preExpandCLTQuad3d( // returns ImagePlus, but it already should be saved/shown boolean ok = preExpandCLTQuad3d( // returns ImagePlus, but it already should be saved/shown
...@@ -8466,7 +8551,7 @@ public class QuadCLT { ...@@ -8466,7 +8551,7 @@ public class QuadCLT {
rgbParameters, rgbParameters,
threadsMax, // maximal number of threads to launch threadsMax, // maximal number of threads to launch
updateStatus, updateStatus,
true, // final boolean batch_mode, !batch_dbg, // final boolean batch_mode,
debugLevel); debugLevel);
} else continue; } else continue;
...@@ -8478,7 +8563,7 @@ public class QuadCLT { ...@@ -8478,7 +8563,7 @@ public class QuadCLT {
geometryCorrection, geometryCorrection,
threadsMax, threadsMax,
updateStatus, updateStatus,
true, // batch_mode !batch_dbg, // batch_mode
debugLevel); debugLevel);
} else continue; // if (correctionsParameters.clt_batch_surf) } else continue; // if (correctionsParameters.clt_batch_surf)
...@@ -8489,7 +8574,7 @@ public class QuadCLT { ...@@ -8489,7 +8574,7 @@ public class QuadCLT {
geometryCorrection, geometryCorrection,
threadsMax, threadsMax,
updateStatus, updateStatus,
true, // boolean batch_mode, !batch_dbg, // boolean batch_mode,
debugLevel); debugLevel);
if (!ok) continue; if (!ok) continue;
} else continue; // if (correctionsParameters.clt_batch_assign) } else continue; // if (correctionsParameters.clt_batch_assign)
...@@ -8501,7 +8586,7 @@ public class QuadCLT { ...@@ -8501,7 +8586,7 @@ public class QuadCLT {
rgbParameters, // EyesisCorrectionParameters.RGBParameters rgbParameters, rgbParameters, // EyesisCorrectionParameters.RGBParameters rgbParameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus, updateStatus, // final boolean updateStatus,
true, // final boolean batch_mode, !batch_dbg, // final boolean batch_mode,
debugLevel); // final int debugLevel) debugLevel); // final int debugLevel)
if (!ok) continue; if (!ok) continue;
} else continue; // if (correctionsParameters.clt_batch_gen3d) } else continue; // if (correctionsParameters.clt_batch_gen3d)
...@@ -8517,7 +8602,7 @@ public class QuadCLT { ...@@ -8517,7 +8602,7 @@ public class QuadCLT {
} }
} }
if (debugLevel > -2) { if (debugLevel > -2) {
System.out.println("Processing set "+(nSet+1)+" (of "+fileIndices.length+") finished at "+ System.out.println("Processing set "+nSet+" (of "+setNames.size()+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startSetTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")"); IJ.d2s(0.000000001*(System.nanoTime()-this.startSetTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
} }
......
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