Commit b6994b6e authored by Andrey Filippov's avatar Andrey Filippov

Fixing field correction

parent 3868b0a7
This diff is collapsed.
......@@ -704,7 +704,7 @@ public class Correlation2d {
if (Double.isNaN(data[imx]) || (data[i] > data[imx])) imx = i;
}
}
if (data[imx] < minMax) {
if (!(data[imx] >= minMax)) {
if (debug){
System.out.println("getMaxXYInt() -> null (data["+imx+"] = "+data[imx]+" < "+minMax);
}
......@@ -963,6 +963,101 @@ public class Correlation2d {
return padded_strip;
}
public double [] mismatchPairsCM( // returns x-xcenter, y, strength (sign same as disparity)
ImageDttParameters imgdtt_params,
double [][] corrs,
int pair_mask, // which pairs to process
double xcenter, // -disparity to compare
double radius, // positive - within that distance, negative - within 2*(-radius)+1 square
int debug_level,
int tileX, // just for debug output
int tileY)
{
boolean debug = debug_level > 0;
int width = 2 * transform_size - 1;
int center = transform_size - 1;
int center_index = (width + 1) * center; //
int num_pairs = 0;
for (int i = 0; i < corrs.length; i++) if ((corrs[i] != null) && (((1 << i) & pair_mask) != 0)) {
num_pairs++;
}
double [] rslt = new double[3 * num_pairs];
int np= 0;
int [] icenter = new int[2];
int ixcenter = (int) Math.round(xcenter);
for (int pair = 0; pair < corrs.length; pair++) if ((corrs[pair] != null) && (((1 << pair) & pair_mask) != 0)) {
// int this_mask = 1 << pair;
if ( isHorizontalPair(pair)) {
icenter[0] = ixcenter;
icenter[1] = 0;
} else if (isVerticalPair(pair)) {
icenter[0] = 0;
icenter[1] = ixcenter;
} else if (isDiagonalMainPair(pair)) {
icenter[0] = ixcenter;
icenter[1] = ixcenter;
} else if (isDiagonalOtherPair(pair)) {
icenter[0] = ixcenter;
icenter[1] = -ixcenter;
} else {
System.out.println("************ BUG: illegal pair type for pair1"+pair);
return null;
}
//calculate as "center of mass"
int iradius = (int) Math.abs(radius);
int ir2 = (int) (radius*radius);
boolean square = radius <0;
double s0 = 0, sx=0, sy = 0;
for (int y = - iradius ; y <= iradius; y++){
int dataY = icenter[1] +y;
if ((dataY >= -center) && (dataY <= center)){
int y2 = y*y;
for (int x = - iradius ; x <= iradius; x++){
int dataX = icenter[0] +x;
double r2 = y2 + x * x;
if ((dataX >= -center) && (dataX <= center) && (square || (r2 <= ir2))){
double d = corrs[pair][dataY * width + dataX + center_index];
if (d > 0.0) {
s0 += d;
sx += d * dataX;
sy += d * dataY;
}
}
}
}
}
double xm = sx / s0;
double ym = sy / s0;
int ixm = (int) Math.round(xm);
int iym = (int) Math.round(ym);
double s = corrs[pair][iym * width + ixm + center_index];
if ( isHorizontalPair(pair)) {
rslt[3 * np + 0] = xcenter - xm;
rslt[3 * np + 1] = -ym;
} else if (isVerticalPair(pair)) {
rslt[3 * np + 0] = -xm;
rslt[3 * np + 1] = xcenter - ym;
} else if (isDiagonalMainPair(pair)) {
rslt[3 * np + 0] = xcenter - xm;
rslt[3 * np + 1] = xcenter - ym;
} else if (isDiagonalOtherPair(pair)) {
rslt[3 * np + 0] = xcenter - xm;
rslt[3 * np + 1] = -xcenter - ym;
} else {
System.out.println("************ BUG: illegal pair type for pair "+pair);
return null;
}
rslt[3 * np + 2] = s;
if (debug){
System.out.println("getMaxXYInt() -> "+rslt[0]+"/"+rslt[1]);
}
np++;
}
return rslt;
}
// returns array 3*num_pairs long
// TODO: now works for small offsets. Maybe add re-calculate int argmax for each pair? xcenter is still needed to subtract Add switch? (small/large correction)
......@@ -983,9 +1078,9 @@ public class Correlation2d {
double [] rslt = new double[3 * num_pairs];
int np= 0;
for (int i = 0; i < corrs.length; i++) if ((corrs[i] != null) && (((1 << i) & pair_mask) != 0)) {
for (int pair = 0; pair < corrs.length; pair++) if ((corrs[pair] != null) && (((1 << pair) & pair_mask) != 0)) {
// for (int np = 0; np < num_pairs; np++) {
int this_mask = 1 << i;
int this_mask = 1 << pair;
Correlations2dLMA lma=corrLMA(
imgdtt_params, // ImageDttParameters imgdtt_params,
corrs, // double [][] corrs,
......@@ -1000,23 +1095,43 @@ public class Correlation2d {
if ((lma == null) || (lma.getPoly() == null)) {
rslt[3 * np + 0] = Double.NaN;
rslt[3 * np + 1] = Double.NaN;
rslt[3 * np + 2] = Double.NaN;
rslt[3 * np + 2] = 0.0;
} else {
double [] poly_xyvwh = lma.getPoly();
rslt[3 * np + 0] = xcenter - poly_xyvwh[0];
rslt[3 * np + 1] = -poly_xyvwh[1];
rslt[3 * np + 2] = poly_xyvwh[2];
if ( isHorizontalPair(pair)) {
rslt[3 * np + 0] = xcenter - poly_xyvwh[0];
rslt[3 * np + 1] = -poly_xyvwh[1];
} else if (isVerticalPair(pair)) {
rslt[3 * np + 0] = -poly_xyvwh[1];
rslt[3 * np + 1] = xcenter - poly_xyvwh[0];
} else if (isDiagonalMainPair(pair)) {
// rslt[3 * np + 0] = xcenter - poly_xyvwh[0];
// rslt[3 * np + 1] = -poly_xyvwh[1];
rslt[3 * np + 0] = xcenter - poly_xyvwh[0] + poly_xyvwh[1]; // x - y
rslt[3 * np + 1] = xcenter - poly_xyvwh[0] - poly_xyvwh[1]; // x + y
} else if (isDiagonalOtherPair(pair)) {
// rslt[3 * np + 0] = xcenter - poly_xyvwh[0];
// rslt[3 * np + 1] = poly_xyvwh[1];
rslt[3 * np + 0] = xcenter - poly_xyvwh[0] + poly_xyvwh[1]; // x - y
rslt[3 * np + 1] = -xcenter + poly_xyvwh[0] + poly_xyvwh[1]; // x + y
} else {
System.out.println("************ BUG: illegal pair type for pair "+pair);
return null;
}
rslt[3 * np + 2] = Double.isNaN(poly_xyvwh[2])?0.0: poly_xyvwh[2];
}
if (debug_level > 0) {
System.out.println(String.format("mismatchPairs(), np = %d pairs mask = 0x%x, dx=%f, dy=%f, strength=%f", np, this_mask, rslt[3 * np + 0], rslt[3 * np + 1], rslt[3 * np + 2]));
if ((Double.isNaN(rslt[3 * np + 0]) || Double.isNaN(rslt[3 * np + 1])) && (rslt[3 * np + 2] > 0.0)) {
System.out.println("************ mismatchPairs() Fix NaN!!!!! **************");
System.out.println(String.format("(), np = %d pairs mask = 0x%x, dx=%f, dy=%f, strength=%f", np, this_mask, rslt[3 * np + 0], rslt[3 * np + 1], rslt[3 * np + 2]));
}
if (debug_level > -1) {
System.out.println(String.format("(), np = %d pairs mask = 0x%x, dx=%f, dy=%f, strength=%f", np, this_mask, rslt[3 * np + 0], rslt[3 * np + 1], rslt[3 * np + 2]));
}
np++;
}
return rslt;
}
public double [][] corr4dirsLMA(
ImageDttParameters imgdtt_params,
double [][] corrs,
......
......@@ -2459,6 +2459,7 @@ public class EyesisCorrectionParameters {
public double ly_inf_frac = 0.5; // Relative weight of infinity calibration data
public boolean ly_on_scan = true; // Calculate and apply lazy eye correction after disparity scan (poly or extrinsic)
public boolean ly_inf_en = false; // true; // Simultaneously correct disparity at infinity (both poly and extrinsic)
public boolean ly_inf_disp= false; // Correct disparity for infinity tiles
public boolean ly_inf_force= false; // Force convergence correction during extrinsic, even with no infinity data
public boolean ly_com_roll= false; // Enable common roll (valid for high disparity range only)
......@@ -3140,6 +3141,8 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"ly_inf_frac", this.ly_inf_frac +"");
properties.setProperty(prefix+"ly_on_scan", this.ly_on_scan+"");
properties.setProperty(prefix+"ly_inf_en", this.ly_inf_en+"");
properties.setProperty(prefix+"ly_inf_disp", this.ly_inf_disp+"");
properties.setProperty(prefix+"ly_inf_force", this.ly_inf_force+"");
properties.setProperty(prefix+"ly_com_roll", this.ly_com_roll+"");
properties.setProperty(prefix+"ly_focalLength", this.ly_focalLength+"");
......@@ -3770,6 +3773,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"ly_inf_frac")!=null) this.ly_inf_frac=Double.parseDouble(properties.getProperty(prefix+"ly_inf_frac"));
if (properties.getProperty(prefix+"ly_on_scan")!=null) this.ly_on_scan=Boolean.parseBoolean(properties.getProperty(prefix+"ly_on_scan"));
if (properties.getProperty(prefix+"ly_inf_en")!=null) this.ly_inf_en=Boolean.parseBoolean(properties.getProperty(prefix+"ly_inf_en"));
if (properties.getProperty(prefix+"ly_inf_disp")!=null) this.ly_inf_disp=Boolean.parseBoolean(properties.getProperty(prefix+"ly_inf_disp"));
if (properties.getProperty(prefix+"ly_inf_force")!=null) this.ly_inf_force=Boolean.parseBoolean(properties.getProperty(prefix+"ly_inf_force"));
if (properties.getProperty(prefix+"ly_com_roll")!=null) this.ly_com_roll=Boolean.parseBoolean(properties.getProperty(prefix+"ly_com_roll"));
if (properties.getProperty(prefix+"ly_focalLength")!=null) this.ly_focalLength=Boolean.parseBoolean(properties.getProperty(prefix+"ly_focalLength"));
......@@ -4431,12 +4435,15 @@ public class EyesisCorrectionParameters {
gd.addMessage ("Maximal measured relative disparity = "+ (0.8*disp_scan_step)+" (0.8 * disp_scan_step)");
// gd.addNumericField("Maximal measured relative disparity", this.ly_meas_disp, 3);
gd.addNumericField("Maximal RMS of the remaining tiles in a sample", this.ly_smpl_rms, 5);
gd.addNumericField("Maximal full disparity difference to 8 neighbors", this.ly_disp_var, 5);
gd.addNumericField("Maximal relative full disparity difference to 8 neighbors", this.ly_disp_rvar, 5);
gd.addNumericField("Maximal full disparity difference to 8 neighbors", this.ly_disp_var, 8,5,"pix",
"Full allowed mismatch is a sum of absolute and disparity times relative");
gd.addNumericField("Maximal relative full disparity difference to 8 neighbors", this.ly_disp_rvar, 8,5,"",
"Full allowed mismatch is a sum of absolute and disparity times relative");
gd.addNumericField("Reduce weight of higher disparity tiles", this.ly_norm_disp, 5);
gd.addNumericField("Relative weight of infinity calibration data", this.ly_inf_frac, 3);
gd.addCheckbox ("Calculate and apply lazy eye correction after disparity scan (poly or extrinsic), may repeat",this.ly_on_scan);
gd.addCheckbox ("Use infinity disparity (disable if there is not enough of infinity data), both poly and extrinsic", this.ly_inf_en);
gd.addCheckbox ("Correct disparity for infinity tiles )has to disable until code fixed)", this.ly_inf_disp);
gd.addCheckbox ("Force convergence correction during extrinsic, even with no infinity data", this.ly_inf_force);
gd.addCheckbox ("Enable common roll adjustment (valid for high disparity range scans only)", this.ly_com_roll);
gd.addCheckbox ("Correct scales (focal length temperature? variations)", this.ly_focalLength);
......@@ -5139,6 +5146,7 @@ public class EyesisCorrectionParameters {
this.ly_inf_frac= gd.getNextNumber();
this.ly_on_scan= gd.getNextBoolean();
this.ly_inf_en= gd.getNextBoolean();
this.ly_inf_disp= gd.getNextBoolean();
this.ly_inf_force= gd.getNextBoolean();
this.ly_com_roll= gd.getNextBoolean();
this.ly_focalLength= gd.getNextBoolean();
......@@ -5790,12 +5798,12 @@ public class EyesisCorrectionParameters {
if (z_corr_map.size() > 0) {
gd.addMessage("Edit infinity disparity correction (in 1/m), set >= 1.0 to remove for the following");
for (HashMap.Entry<String,Double> entry : z_corr_map.entrySet()){
gd.addNumericField(entry.getKey(), entry.getValue(), 8);
gd.addNumericField(entry.getKey(), entry.getValue(), 9,12, "m-1");
}
}
gd.addMessage("Add new infinity correction");
gd.addStringField ("Timestamp string (seconds_microseconds):", "", 40);
gd.addNumericField("Infinity correction (in 1/m)", 0, 8);
gd.addNumericField("Infinity correction (in 1/m)", 0, 9,12,"m-1");
gd.addCheckbox ("Clear list", false);
WindowTools.addScrollBars(gd);
gd.showDialog();
......
......@@ -101,11 +101,13 @@ public class GeometryCorrection {
}
public boolean [] getParMask(
boolean disparity_only,
boolean use_disparity,
boolean common_roll,
boolean corr_focalLength)
{
return (new CorrVector()).getParMask(
disparity_only,
use_disparity,
common_roll,
corr_focalLength);
......@@ -378,7 +380,7 @@ public class GeometryCorrection {
s += " |↘ ↙| |↘ ↗| |↗ ↘| |↙ ↘| |↙ ↗| |↖ ↘| 6: common roll 7:(r0-r3)/2, |- +| |- -| |- +|\n";
s += " 0: |↗ ↖| 1: |↙ ↖| 2: |↖ ↙| 3: |↖ ↗| 4: |↗ ↙| 5: |↘ ↖| 8:(r1-r2)/2 9:(r0+r3-r1-r2)/4 10: |- +| 11: |+ +| 12: |+ -|\n";
s += String.format(" 0: %8.5f° 1:%8.5f° 2:%8.5f° 3:%8.5f° 4:%8.5f° 5:%8.5f° 6:%8.5f° 7:%8.5f° 8:%8.5f° 9:%8.5f° 10: %8.5f‰ 11:%8.5f‰ 12:%8.5f‰\n" ,
s += String.format(" 0:%9.6f° 1:%8.5f° 2:%8.5f° 3:%8.5f° 4:%8.5f° 5:%8.5f° 6:%8.5f° 7:%8.5f° 8:%8.5f° 9:%8.5f° 10: %8.5f‰ 11:%8.5f‰ 12:%8.5f‰\n" ,
sv[0], sv[1], sv[2], sv[3], sv[4], sv[5], sv[6], sv[7], sv[8], sv[9], 1000*sv[10], 1000*sv[11], 1000*sv[12] );
return s;
......@@ -506,21 +508,25 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
}
public boolean [] getParMask(
boolean disparity_only,
boolean use_disparity,
boolean common_roll,
boolean corr_focalLength)
{
common_roll &= !disparity_only;
corr_focalLength &= !disparity_only;
use_disparity |= disparity_only;
boolean [] par_mask = {
use_disparity, //sym0
true, //sym1
true, //sym2
true, //sym3
true, //sym4
true, //sym5
!disparity_only, //sym1
!disparity_only, //sym2
!disparity_only, //sym3
!disparity_only, //sym4
!disparity_only, //sym5
common_roll, //sym6 // common roll
true, //sym7
true, //sym8
true, //sym9
!disparity_only, //sym7
!disparity_only, //sym8
!disparity_only, //sym9
corr_focalLength, //sym10
corr_focalLength, //sym11
corr_focalLength //sym12
......@@ -533,7 +539,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
* Get partial transposed Jacobian as 2d array (for one measurement set) from partial Jacobian for each sample
* with derivatives of port coordinates (all 4) by 3 tilts (ports 0..2), 3 azimuths (ports 0..2) and all 4 rolls
* Tilt and azimuth for port 3 is calculated so center would not move. Tilt is positive up, azimuth - right and
* roll - clockwise
* roll - clockwise. Added zooms (difference from 1.0) for sensors 0..2
*
* Result is transposed Jacobian (rows (9 , 10,12 or 13) - parameters, columns - port coordinate components (8). Parameters
* here are symmetrical, 0 is disparity-related (all to the center), remaining 9 preserve disparity and
......@@ -1225,7 +1231,7 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
double dpYci_droll = drvi_drl.get(1, 0) * norm_z - pYci * drvi_drl.get(2, 0) / rvi.get(2, 0);
double dpXci_dzoom = drvi_dzm.get(0, 0) * norm_z - pXci * drvi_dzm.get(2, 0) / rvi.get(2, 0);
double dpYci_dzoom = drvi_drl.get(1, 0) * norm_z - pYci * drvi_dzm.get(2, 0) / rvi.get(2, 0);
double dpYci_dzoom = drvi_dzm.get(1, 0) * norm_z - pYci * drvi_dzm.get(2, 0) / rvi.get(2, 0);
double dri_dazimuth = ri_scale / rNDi* (pXci * dpXci_dazimuth + pYci * dpYci_dazimuth);
double dri_dtilt = ri_scale / rNDi* (pXci * dpXci_dtilt + pYci * dpYci_dtilt);
......@@ -1258,22 +1264,22 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
// 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;
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;
pXYderiv[2 * i + 0][CorrVector.ZOOM_INDEX+i] = dpXid_dzoom;
pXYderiv[2 * i + 1][CorrVector.ZOOM_INDEX+i] = dpYid_dzoom;
pXYderiv[2 * i + 0][CorrVector.ZOOM_INDEX+i] = dpXid_dzoom;
pXYderiv[2 * i + 1][CorrVector.ZOOM_INDEX+i] = dpYid_dzoom;
} 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.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;
pXYderiv[2 * i + 0][CorrVector.ZOOM_INDEX+j] = -dpXid_dzoom;
pXYderiv[2 * i + 1][CorrVector.ZOOM_INDEX+j] = -dpYid_dzoom;
pXYderiv[2 * i + 0][CorrVector.ZOOM_INDEX+j] = -dpXid_dzoom;
pXYderiv[2 * i + 1][CorrVector.ZOOM_INDEX+j] = -dpYid_dzoom;
}
}
pXYderiv[2 * i + 0][CorrVector.ROLL_INDEX+i] = dpXid_droll;
......
......@@ -1493,7 +1493,7 @@ public class ImageDtt {
if (i == (transform_size-1)) enh_ortho_scale[i] = 0.0 ; // hardwired 0 in the center
enh_ortho_scale[i] *= Math.sin(Math.PI*(i+1.0)/(2*transform_size));
}
if (globalDebugLevel > 0){
if (globalDebugLevel > 1){
System.out.println("enhortho_width="+ imgdtt_params.enhortho_width+" enhortho_scale="+ imgdtt_params.enhortho_scale);
for (int i = 0; i < corr_size; i++){
System.out.println(" enh_ortho_scale["+i+"]="+ enh_ortho_scale[i]);
......@@ -1927,7 +1927,7 @@ public class ImageDtt {
}
}
int tile_lma_debug_level = ((tileX == debug_tileX) && (tileY == debug_tileY))?imgdtt_params.lma_debug_level : -1;
int tile_lma_debug_level = ((tileX == debug_tileX) && (tileY == debug_tileY))? imgdtt_params.lma_debug_level : -1;
// all color channels are done here
double extra_disparity = 0.0; // used for textures: if allowed, shift images extra before trying to combine
......@@ -1935,7 +1935,10 @@ public class ImageDtt {
// fill clt_corr_combo if it exists
if (disparity_map != null){ // not null - calculate correlations
for (int i = 0; i < disparity_map.length; i++) {
if (disparity_map[i] != null) disparity_map[i][nTile] = Double.NaN; // once and for all
if (disparity_map[i] != null) disparity_map[i][nTile] = (
(i == DISPARITY_STRENGTH_INDEX) ||
(i == DISPARITY_INDEX_HOR_STRENGTH) ||
(i == DISPARITY_INDEX_VERT_STRENGTH)) ? 0.0 : Double.NaN; // once and for all
}
//clt_mismatch should only be used with disparity_map != null;
if (clt_mismatch != null) {
......@@ -2056,6 +2059,9 @@ public class ImageDtt {
disparity_map[DISPARITY_INDEX_INT][tIndex] = -ixy[0];
// disparity_map[DISPARITY_INDEX_INT + 1][tIndex] =
disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] = strength;
if (Double.isNaN(disparity_map[DISPARITY_STRENGTH_INDEX][tIndex])) {
System.out.println("BUG: 1. disparity_map[DISPARITY_STRENGTH_INDEX]["+tIndex+"] should not be NaN");
}
corr_stat = corr2d.getMaxXCm( // get fractional center as a "center of mass" inside circle/square from the integer max
strip_combo, // double [] data, // [data_size * data_size]
ixy[0], // int ixcenter, // integer center x
......@@ -2140,6 +2146,9 @@ public class ImageDtt {
strength = lma_disparity_strength[1];
disparity_map[DISPARITY_INDEX_CM] [tIndex] = disparity;
disparity_map[DISPARITY_STRENGTH_INDEX] [tIndex] = strength;
if (Double.isNaN(disparity_map[DISPARITY_STRENGTH_INDEX][tIndex])) {
System.out.println("BUG: 2. disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] should not be NaN");
}
}
// store debug data
// if strong enough and enabled - try to improve far objects
......@@ -2203,20 +2212,38 @@ public class ImageDtt {
}
if (tile_lma_debug_level > -1) {
System.out.println("debug12348973591");
}
if (clt_mismatch != null) { // mod_disparity_diff should be calculated
// bypass difference or zero strength if disparity difference is too high (will influence mismatch correction)
// but setting it too low will make it impossible to correct larger mismatches. Maybe multi-pass?
if (mod_disparity_diff[2] <= imgdtt_params.mismatch_max_diff) { // may be NaN, will fail test as intended
double [] mismatch_result = corr2d.mismatchPairs( // returns x-xcenter, y, strength (sign same as disparity)
if (tile_lma_debug_level > -1) {
System.out.println("debug12348973590");
}
double [] mismatch_result;
if (imgdtt_params.ly_poly) {
mismatch_result = corr2d.mismatchPairs( // returns x-xcenter, y, strength (sign same as disparity)
imgdtt_params, // ImageDttParameters imgdtt_params,
corrs, // double [][] corrs,
all_pairs, // int pair_mask, // which pairs to process
-disparity, // double xcenter, // preliminary center x in pixels for largest baseline
imgdtt_params.ortho_vasw_pwr, // double vasw_pwr, // value as weight to this power,
max_corr_radius, // double vasw_pwr, // value as weight to this power,
tile_lma_debug_level,// int debug_level,
tileX, // int tileX, // just for debug output
tileY ); // int tileY
} else {
mismatch_result = corr2d.mismatchPairsCM( // returns x-xcenter, y, strength (sign same as disparity)
imgdtt_params, // ImageDttParameters imgdtt_params,
corrs, // double [][] corrs,
all_pairs, // int pair_mask, // which pairs to process
-disparity, // double xcenter, // preliminary center x in pixels for largest baseline
imgdtt_params.ortho_vasw_pwr, // radius, // positive - within that distance, negative - within 2*(-radius)+1 square
tile_lma_debug_level,// int debug_level,
tileX, // int tileX, // just for debug output
tileY ); // int tileY
}
if (tile_lma_debug_level > 0) {
System.out.println("Lazy eye mismatch:");
for (int np = 0; np < mismatch_result.length/3; np++) {
......@@ -2241,8 +2268,11 @@ public class ImageDtt {
else if (corr_mode == 3) extra_disparity = disparity_map[DISPARITY_INDEX_HOR][tIndex];
else if (corr_mode == 4) extra_disparity = disparity_map[DISPARITY_INDEX_VERT][tIndex];
if (Double.isNaN(extra_disparity)) extra_disparity = 0;
} // if (disparity_map != null){ // not null - calculate correlations
if (Double.isNaN(disparity_map[DISPARITY_STRENGTH_INDEX][tIndex])) {
System.out.println("BUG: 3. disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] should not be NaN");
}
} // if (disparity_map != null){ // not null - calculate correlations
// only debug is left
......@@ -5617,7 +5647,7 @@ public class ImageDtt {
if (i == (transform_size-1)) enh_ortho_scale[i] = 0.0 ; // hardwired 0 in the center
enh_ortho_scale[i] *= Math.sin(Math.PI*(i+1.0)/(2*transform_size));
}
if (globalDebugLevel > 0){
if (globalDebugLevel > 1){
System.out.println("enhortho_width="+ imgdtt_params.enhortho_width+" enhortho_scale="+ imgdtt_params.enhortho_scale);
for (int i = 0; i < corr_size; i++){
System.out.println(" enh_ortho_scale["+i+"]="+ enh_ortho_scale[i]);
......@@ -5797,7 +5827,7 @@ public class ImageDtt {
corr2d.createOrtoNotch(
imgdtt_params.enhortho_width, // double enhortho_width,
imgdtt_params.enhortho_scale, //double enhortho_scale,
true); // boolean debug);
false); // true); // boolean debug);
// public int enhortho_width = 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
// public double enhortho_scale = 0.0; // 0.2; // multiply center correlation pixels (inside enhortho_width)
......
......@@ -44,6 +44,7 @@ public class ImageDttParameters {
public int enhortho_width = 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
public double enhortho_scale = 0.0; // 0.2; // multiply center correlation pixels (inside enhortho_width)
public boolean ly_poly = false; // Use polynomial when measuring mismatch (false - use center of mass)
public boolean fo_correct = true; // correct far objects by comparing orthogonal correlations
public boolean fo_far = false;// Use smallest disparity (false - largest)
......@@ -122,7 +123,9 @@ public class ImageDttParameters {
"Raise value to this power and apply as weight. Reduce width to 3 samples if false, 5 OK when true");
gd.addNumericField("Reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)", this.enhortho_width, 0);
gd.addNumericField("Multiply center correlation pixels (inside enhortho_width) (1.0 - disables enh_orttho)", this.enhortho_scale, 3);
gd.addNumericField("Multiply center correlation pixels (inside enhortho_width) (1.0 - disables enh_ortho)", this.enhortho_scale, 3);
gd.addCheckbox ("Use polynomial when measuring mismatch (false - use center of mass)", this.ly_poly);
gd.addMessage("Far objects correction");
gd.addCheckbox ("Try to correct far objects (make them closer) by hor/vert comparison", this.fo_correct);
......@@ -247,6 +250,8 @@ public class ImageDttParameters {
this.enhortho_width= (int) gd.getNextNumber();
this.enhortho_scale= gd.getNextNumber();
this.ly_poly = gd.getNextBoolean();
this.fo_correct = gd.getNextBoolean();
this.fo_far = gd.getNextBoolean();
this.fo_min_strength = gd.getNextNumber();
......@@ -330,6 +335,8 @@ public class ImageDttParameters {
properties.setProperty(prefix+"twice_diagonal", this.twice_diagonal +"");
properties.setProperty(prefix+"min_corr", this.min_corr +"");
properties.setProperty(prefix+"ly_poly", this.ly_poly +"");
properties.setProperty(prefix+"fo_correct", this.fo_correct +"");
properties.setProperty(prefix+"fo_far", this.fo_far +"");
properties.setProperty(prefix+"fo_min_strength", this.fo_min_strength +"");
......@@ -402,6 +409,8 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"enhortho_scale")!=null) this.enhortho_scale=Double.parseDouble(properties.getProperty(prefix+"enhortho_scale"));
if (properties.getProperty(prefix+"fo_correct")!=null) this.fo_correct=Boolean.parseBoolean(properties.getProperty(prefix+"fo_correct"));
if (properties.getProperty(prefix+"ly_poly")!=null) this.ly_poly=Boolean.parseBoolean(properties.getProperty(prefix+"ly_poly"));
if (properties.getProperty(prefix+"fo_far")!=null) this.fo_far=Boolean.parseBoolean(properties.getProperty(prefix+"fo_far"));
if (properties.getProperty(prefix+"fo_min_strength")!=null) this.fo_min_strength=Double.parseDouble(properties.getProperty(prefix+"fo_min_strength"));
if (properties.getProperty(prefix+"fo_min_eff")!=null) this.fo_min_eff=Double.parseDouble(properties.getProperty(prefix+"fo_min_eff"));
......@@ -481,6 +490,8 @@ public class ImageDttParameters {
idp.enhortho_width = this.enhortho_width;
idp.enhortho_scale = this.enhortho_scale;
idp.ly_poly = this.ly_poly;
idp.fo_correct = this.fo_correct;
idp.fo_far = this.fo_far;
idp.fo_min_strength = this.fo_min_strength;
......
......@@ -3807,7 +3807,8 @@ public class QuadCLT {
// visualize correlation results
if (clt_corr_combo!=null){
if (disparity_map != null){
if (!batch_mode && !infinity_corr && clt_parameters.show_map && (debugLevel > -1)){
// if (!batch_mode && !infinity_corr && clt_parameters.show_map && (debugLevel > -1)){
if (!batch_mode && clt_parameters.show_map && (debugLevel > -1)){
sdfa_instance.showArrays(
disparity_map,
tilesX,
......@@ -3821,14 +3822,32 @@ public class QuadCLT {
if (infinity_corr && (disparity_map != null)){
System.out.println("=== applying geometry correction coefficients to correct disparity at infinity ===");
System.out.println("=== Set inf_repeat =0 to disable automatic correction and just generate a data image to correct in offline mode ===");
double [][] inf_ds = {
double [] mismatch_strength = disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX].clone();
int [] strength_indices = {2,5,8,11};
for (int nt = 0; nt < mismatch_strength.length; nt++) {
if (Double.isNaN(mismatch_strength[nt])) {
mismatch_strength[nt] = 0.0;
} else {
if (mismatch_strength[nt] > 0) {
for (int i = 0; i < strength_indices.length; i++) {
if (!(mismatch_strength[nt] < clt_mismatch[strength_indices[i]][nt])) {
mismatch_strength[nt] = clt_mismatch[strength_indices[i]][nt];
}
// if (nt == 37005) {
// System.out.println("breakpoint in processCLTQuadCorr()");
// }
}
}
}
}
double [][] inf_ds = { // when using with disparity, programmed disparity should be 0
disparity_map[ImageDtt.DISPARITY_INDEX_CM],
disparity_map[ ImageDtt.DISPARITY_STRENGTH_INDEX]};
mismatch_strength}; // disparity_map[ ImageDtt.DISPARITY_STRENGTH_INDEX]};
String [] titles = {"disp_cm", "strength"};
if (!batch_mode && (clt_mismatch != null)){
double [][] inf_ds1 = {
disparity_map[ImageDtt.DISPARITY_INDEX_CM],
disparity_map[ ImageDtt.DISPARITY_STRENGTH_INDEX],
mismatch_strength, //disparity_map[ ImageDtt.DISPARITY_STRENGTH_INDEX],
clt_mismatch[0], // dx0
clt_mismatch[1], // dy0 +
clt_mismatch[3], // dx1
......@@ -3895,7 +3914,7 @@ public class QuadCLT {
clt_parameters.corr_magic_scale, // double magic_coeff, // still not understood coefficent that reduces reported disparity value. Seems to be around 8.5
debugLevel + (clt_parameters.fine_dbg ? 1:0)); // int debugLevel)
if (debugLevel > -1){
if ((new_corr != null) && (debugLevel > -1)){
System.out.println("process_infinity_corr(): ready to apply infinity correction");
show_fine_corr(
new_corr, // double [][][] corr,
......@@ -3965,7 +3984,7 @@ public class QuadCLT {
for (int iQuad = 0; iQuad < clt_data.length; iQuad++){
String title=name+"-"+String.format("%02d", iQuad);
// String titleFull=title+"-SPLIT-D"+clt_parameters.disparity;
// String titleFull=title+"-SPLIT-D"+clt_parameters.disparity;
if (clt_parameters.corr_sigma > 0){ // no filter at all
for (int chn = 0; chn < clt_data[iQuad].length; chn++) {
......@@ -3978,8 +3997,6 @@ public class QuadCLT {
}
}
// int tp.tilesY = imp_quad[iQuad].getHeight()/clt_parameters.transform_size;
// int tp.tilesX = imp_quad[iQuad].getWidth()/clt_parameters.transform_size;
if (debugLevel > 0){
System.out.println("--tilesX="+tilesX);
System.out.println("--tilesY="+tilesY);
......@@ -4059,7 +4076,7 @@ public class QuadCLT {
}
//imp_stack.getProcessor().resetMinAndMax();
//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,
......@@ -4068,9 +4085,9 @@ public class QuadCLT {
}
if (clt_parameters.gen_4_img) {
// Save as individual JPEG images in the model directory
String x3d_path= correctionsParameters.selectX3dDirectory(
name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.x3dModelVersion,
String x3d_path= correctionsParameters.selectX3dDirectory(
name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.x3dModelVersion,
true, // smart,
true); //newAllowed, // save
for (int sub_img = 0; sub_img < 4; sub_img++){
......@@ -4855,6 +4872,7 @@ public class QuadCLT {
double [][][] new_corr = ac.lazyEyeCorrection(
clt_parameters.ly_poly, // final boolean use_poly,
true, // final boolean restore_disp_inf, // Restore subtracted disparity for scan #0 (infinity)
clt_parameters.fcorr_radius, // final double fcorr_radius,
clt_parameters.fcorr_inf_strength, // final double min_strenth,
clt_parameters.fcorr_inf_diff, // final double max_diff,
......@@ -4960,7 +4978,7 @@ public class QuadCLT {
return results;
}
public void process_infinity_corr(
public void process_infinity_corr( //from existing image
EyesisCorrectionParameters.CLTParameters clt_parameters,
int debugLevel
) {
......@@ -5059,6 +5077,7 @@ public class QuadCLT {
double [][][] new_corr = ac.lazyEyeCorrection(
clt_parameters.ly_poly, // final boolean use_poly,
true, // final boolean restore_disp_inf, // Restore subtracted disparity for scan #0 (infinity)
clt_parameters.fcorr_radius, // final double fcorr_radius,
clt_parameters.fcorr_inf_strength, // final double min_strenth,
clt_parameters.fcorr_inf_diff, // final double max_diff,
......@@ -6037,6 +6056,7 @@ public class QuadCLT {
int bg_scan = 0;
int combo_scan= tp.clt_3d_passes.size()-1;
if (!batch_mode && clt_parameters.show_extrinsic && (debugLevel >-1)) {
// if (!batch_mode && (debugLevel >-1)) {
tp.showScan(
tp.clt_3d_passes.get(bg_scan), // CLTPass3d scan,
"bg_scan"); //String title)
......@@ -6179,7 +6199,7 @@ public class QuadCLT {
double [] dbg_bg_use = new double [bg_sel.length];
double [] dbg_combo_use = new double [bg_sel.length];
for (int i= 0; i < bg_sel.length; i++) {
dbg_bg_sel[i] = bg_sel[i]? 1.0:0.0;
dbg_bg_sel[i] = bg_sel[i]? 1.0:0.0; //only sky, no far mountains (too high disparity!)
dbg_bg_use[i] = bg_use[i]? 1.0:0.0;
dbg_combo_use[i] = combo_use[i]? 1.0:0.0;
}
......@@ -6189,7 +6209,7 @@ public class QuadCLT {
filtered_combo_scand_isp_strength[0],
filtered_combo_scand_isp_strength[1],
dbg_bg_sel,
dbg_bg_use,
dbg_bg_use, // too few
dbg_combo_use};
(new showDoubleFloatArrays()).showArrays(dbg_img, tp.getTilesX(), tp.getTilesY(), true, "extrinsics_bgnd_combo",titles);
}
......@@ -6233,7 +6253,9 @@ public class QuadCLT {
scans14[14 * 0 + 2 + i] = bg_mismatch[i];
scans14[14 * 1 + 2 + i] = combo_mismatch[i];
}
// (new showDoubleFloatArrays()).showArrays(scans14, tp.getTilesX(), tp.getTilesY(), true, "scans_14"); // , titles);
if (debugLevelInner > 0) {
(new showDoubleFloatArrays()).showArrays(scans14, tp.getTilesX(), tp.getTilesY(), true, "scans_14"); // , titles);
}
if (!batch_mode && clt_parameters.show_extrinsic && (debugLevel > 1)) {
tp.showScan(
......@@ -6247,6 +6269,7 @@ public class QuadCLT {
double [][] target_disparity = {tp.clt_3d_passes.get(bg_scan).getDisparity(0), tp.clt_3d_passes.get(combo_scan).getDisparity(0)};
double [][][] new_corr = ac.lazyEyeCorrection(
adjust_poly, // final boolean use_poly,
true, // final boolean restore_disp_inf, // Restore subtracted disparity for scan #0 (infinity)
clt_parameters.fcorr_radius, // final double fcorr_radius,
clt_parameters.fcorr_inf_strength, // final double min_strenth,
clt_parameters.fcorr_inf_diff, // final double max_diff,
......
......@@ -656,7 +656,7 @@ public class TileProcessor {
final boolean usePoly, // use polynomial method to find max), valid if useCombo == false
final int debugLevel)
{
final int dbg_tile = (debugLevel > 0)? 839: -1; // x = 122, y= 108; -1; // 27669;
final int dbg_tile = (debugLevel > 0)? -839: -1; // x = 122, y= 108; -1; // 27669;
CLTPass3d combo_pass =new CLTPass3d(this);
final int disparity_index = usePoly ? ImageDtt.DISPARITY_INDEX_POLY : ImageDtt.DISPARITY_INDEX_CM;
combo_pass.tile_op = new int [tilesY][tilesX];
......@@ -3514,12 +3514,15 @@ public class TileProcessor {
{
// final double super_trust = 1.6; // If strength exceeds ex_strength * super_trust, do not apply ex_nstrength
final int dbg_tile = 41030; // x = 206, y = 126 (324*126+206)
final int dbg_tile = -41030; // x = 206, y = 126 (324*126+206)
final boolean show_scan = show_filter_scan || (debugLevel > 1);
showDoubleFloatArrays sdfa_instance = null;
if ((debugLevel > -2) && ((debugLevel > -1) || show_scan)) sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
if (debugLevel > -2){
System.out.println("FilterScan(,,"+disparity_far+", " +disparity_near+", "+ sure_smth);
if (debugLevel > -2){ //-2
if (debugLevel > -1){ //-2
System.out.print("FilterScan(,,"+disparity_far+", " +disparity_near+", "+ sure_smth+"... ");
}
System.out.print(".");
}
final int tlen = tilesY * tilesX;
double [] this_disparity = scan.getDisparity(); // currently calculated, including ortho
......
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