Commit 37f405a5 authored by Andrey Filippov's avatar Andrey Filippov

Implemented MPO export for EO/LWIR dual-quad rig

parent 26cdc535
......@@ -149,6 +149,7 @@ public class EyesisCorrectionParameters {
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_4img = true; // Create a set of 4 images, usually for disparity = 0
public boolean clt_batch_4img_aux = true; // Create a set of 4 images, usually for disparity = 0 for AUX camera
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_assign = true; // Assign tiles to surfaces
......@@ -286,6 +287,7 @@ public class EyesisCorrectionParameters {
cp.clt_batch_extrinsic= this.clt_batch_extrinsic;
cp.clt_batch_poly= this.clt_batch_poly;
cp.clt_batch_4img= this.clt_batch_4img;
cp.clt_batch_4img_aux= this.clt_batch_4img_aux;
cp.clt_batch_explore= this.clt_batch_explore;
cp.clt_batch_surf= this.clt_batch_surf;
cp.clt_batch_assign= this.clt_batch_assign;
......@@ -461,6 +463,7 @@ public class EyesisCorrectionParameters {
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_4img", this.clt_batch_4img+"");
properties.setProperty(prefix+"clt_batch_4img_aux", this.clt_batch_4img_aux+"");
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_assign", this.clt_batch_assign+"");
......@@ -616,6 +619,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"clt_batch_extrinsic")!= null) this.clt_batch_extrinsic=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_extrinsic"));
if (properties.getProperty(prefix+"clt_batch_poly")!= null) this.clt_batch_poly=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_poly"));
if (properties.getProperty(prefix+"clt_batch_4img")!= null) this.clt_batch_4img=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_4img"));
if (properties.getProperty(prefix+"clt_batch_4img_aux")!= null) this.clt_batch_4img_aux=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_4img_aux"));
if (properties.getProperty(prefix+"clt_batch_explore")!= null) this.clt_batch_explore=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_explore"));
if (properties.getProperty(prefix+"clt_batch_surf")!= null) this.clt_batch_surf=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_surf"));
if (properties.getProperty(prefix+"clt_batch_assign")!= null) this.clt_batch_assign=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_assign"));
......@@ -983,6 +987,7 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Calibrate extrinsic parameters for each set", this.clt_batch_extrinsic); // 22
gd.addCheckbox ("Calculate fine polynomial correction for each set", this.clt_batch_poly); // 23
gd.addCheckbox ("Create a set of 4 images, usually for disparity = 0", this.clt_batch_4img); // 24
gd.addCheckbox ("Create a set of 4 images for AUX (LWIR) camera", this.clt_batch_4img_aux); // 24
gd.addCheckbox ("1-st step of 3d reconstruction - explore disparities for each tile", this.clt_batch_explore); // 25
gd.addCheckbox ("Create super-tile 2.5d surfaces", this.clt_batch_surf); // 26
gd.addCheckbox ("Assign tiles to surfaces", this.clt_batch_assign); // 27
......@@ -993,8 +998,9 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Create DSI combo image", this.clt_batch_dsi,
"Save main camera, dual-quad rig and optionally aux camera combo DSI image with the model");
gd.addCheckbox ("Include aux camera DSI data in the combo DSI", this.clt_batch_dsi_aux,
"Currently DSI for the AUX camera is offset (by the rig baseline) from the main and rig DSI. Aux DSI requires extra processing time");
gd.addCheckbox ("Include/genarate separate aux camera DSI data in the combo DSI", this.clt_batch_dsi_aux,
"8-rig: DSI for the AUX camera is offset (by the rig baseline) from the main and rig DSI. Aux DSI requires extra processing time."+
" EO+LWIR - generate a separate GT+AUX file");
gd.addCheckbox ("Save field adjustment data with the model", this.clt_batch_save_extrinsics,
"This data can be used to restore specific filed-adjusted cameras extrinsics used when the model was generated");
gd.addCheckbox ("Save all parameters with the model", this.clt_batch_save_all,
......@@ -1073,6 +1079,7 @@ public class EyesisCorrectionParameters {
this.clt_batch_extrinsic= gd.getNextBoolean(); // 22
this.clt_batch_poly= gd.getNextBoolean(); // 23
this.clt_batch_4img= gd.getNextBoolean(); // 24
this.clt_batch_4img_aux= gd.getNextBoolean(); // 24
this.clt_batch_explore= gd.getNextBoolean(); // 25
this.clt_batch_surf= gd.getNextBoolean(); // 26
this.clt_batch_assign= gd.getNextBoolean(); // 27
......
......@@ -5231,16 +5231,16 @@ private Panel panel1,
ds[l][i] = f_ds[l][i];
}
}
String [] titles = {"disparity","strength"};
(new ShowDoubleFloatArrays()) .showArrays(ds, width, height, true, title, titles);
String [] rslt_titles = split_fg_bg ? QuadCLT.FGBG_TITLES_AUX :QuadCLT.FGBG_TITLES_ADJ; // last 2 will be 0;
(new ShowDoubleFloatArrays()) .showArrays(ds, width, height, true, title, QuadCLT.FGBG_TITLES_ADJ);
int tile_size = CLT_PARAMETERS.transform_size;
int [] wh_aux = QUAD_CLT_AUX.getGeometryCorrection().getSensorWH();
int tilesX_aux = wh_aux[0] / tile_size;
int tilesY_aux = wh_aux[1] / tile_size;
// int num_slices = split_fg_bg? 7:2;
String [] fgbg_titles = {"disparity","strength", "rms","rms-split","fg-disp","fg-str","bg-disp","bg-str"};
String [] rslt_titles = split_fg_bg ? fgbg_titles :titles;
double [][] ds_aux = QUAD_CLT_AUX.depthMapMainToAux(
ds, // double [][] ds,
......
......@@ -2202,18 +2202,18 @@ B = |+dy0 -dy1 -2*dy3 |
int [] pq = per_quad.clone();
Arrays.sort(per_quad);
if (debugLevel > -20) {
System.out.print(String.format("Tiles per quadrants :[%d, %d, %d, %d], tiles at infinity %d", pq[0],pq[1],pq[2],pq[3],num_inf));
System.out.println(String.format("Tiles per quadrants :[%d, %d, %d, %d], tiles at infinity %d", pq[0],pq[1],pq[2],pq[3],num_inf));
}
if (per_quad[1] < min_per_quadrant) {
if (debugLevel > -20) {
System.out.print(String.format("Too few tiles in quadrants :[%d, %d, %d, %d], minimum for the second worst is %d", pq[0],pq[1],pq[2],pq[3],min_per_quadrant));
System.out.println(String.format("Too few tiles in quadrants :[%d, %d, %d, %d], minimum for the second worst is %d", pq[0],pq[1],pq[2],pq[3],min_per_quadrant));
}
return null;
}
if (num_inf < min_inf) {
if (debugLevel > -20) {
System.out.print(String.format("Too few tiles at infinity: %d minimum is %d", num_inf, min_inf));
System.out.println(String.format("Too few tiles at infinity: %d minimum is %d", num_inf, min_inf));
}
return null;
}
......@@ -2810,19 +2810,19 @@ B = |+dy0 -dy1 -2*dy3 |
Arrays.sort(per_quad);
if (per_quad[1] < min_per_quadrant) {
if (debugLevel > -20) {
System.out.print(String.format("Too few tiles in quadrants :[%d, %d, %d, %d], minimum for the second worst is %d", pq[0],pq[1],pq[2],pq[3],min_per_quadrant));
System.out.println(String.format("Too few tiles in quadrants :[%d, %d, %d, %d], minimum for the second worst is %d", pq[0],pq[1],pq[2],pq[3],min_per_quadrant));
}
return null;
}
if (num_inf < min_inf) {
if (debugLevel > -20) {
System.out.print(String.format("Too few tiles at infinity (<%4f): %d minimum is %d", inf_max_disparity, num_inf, min_inf));
System.out.println(String.format("Too few tiles at infinity (<%4f): %d minimum is %d", inf_max_disparity, num_inf, min_inf));
}
return null;
}
if (debugLevel > -20) {
System.out.print(String.format("Tiles per quadrants :[%d, %d, %d, %d], tiles at infinity %d", pq[0],pq[1],pq[2],pq[3],num_inf));
System.out.println(String.format("Tiles per quadrants :[%d, %d, %d, %d], tiles at infinity %d", pq[0],pq[1],pq[2],pq[3],num_inf));
}
double inf_fraction_limited = (inf_fraction >= 0.0) ?((inf_fraction > 1.0) ? 1.0 : inf_fraction):0.0;
......
......@@ -251,6 +251,8 @@ public class BiQuadParameters {
public boolean ml_copyJP4 = true; // Copy source jp4 files when running "Ground truth" command
public int ml_hwidth = 4; // Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)
// For dual-quad rig mode
public double ml_disparity_sweep = 2.0; // Disparity sweep around ground truth, each side
public int ml_sweep_steps = 1; // Number of disparity sweep steps
......@@ -268,6 +270,15 @@ public class BiQuadParameters {
public boolean ml_main_rnd = true; // generate ML from main camera DSI with random offset
public boolean ml_rig_rnd = true; // generate ML from rig DSI (GT) with random offset
// for EO+LWIR mode
public boolean ml_aux_ag = true; // aux (lwir) mode - generate 2dcorr for GT (average disparity)
public boolean ml_aux_fg = true; // aux (lwir) mode - generate 2dcorr for GT (foreground disparity)
public boolean ml_aux_bg = true; // aux (lwir) mode - generate 2dcorr for GT (background disparity)
public double ml_aux_low = 0.0; // aux (lwir) mode - disparity sweep low
public double ml_aux_high = 10.0; // aux (lwir) mode - disparity sweep high
public double ml_aux_step = 0.1; // aux (lwir) mode - disparity sweep step( >= 0 - no sweep)
// common
public boolean ml_keep_aux = false; // true; // include auxiliary camera data in the ML output
public boolean ml_keep_inter = false; // true; // include inter-camera correlation data in the ML output
public boolean ml_keep_hor_vert = true; // include combined horizontal and vertical pairs data in the ML output
......@@ -678,7 +689,7 @@ public class BiQuadParameters {
gd.addCheckbox ("Randomize offset", this.ml_randomize,
"Each tile will have individual offset, but it the range between the filename and next higher. Reduces sweep steps by 1");
gd.addMessage("Enhancing main camera dsi for generation of the ml files");
gd.addMessage("Enhancing main camera dsi for generation of the ml files (dual quad rig mode");
gd.addNumericField("Max disparity difference between rig and main camera", this.ml_rig_tolerance, 3,6,"",
"Replace main camera disparity if it differs from rig by more than this");
......@@ -693,6 +704,7 @@ public class BiQuadParameters {
gd.addNumericField("Extrapolated tile strength", this.ml_new_strength, 3,6,"",
"Assign this fraction of average neighbors strength strength to the tiles where strength is unknown (expanded tiles with extrapolated target)");
gd.addMessage("Dual-quad rig mode (8 identical cameras)");
gd.addCheckbox ("Generate ML 2d correlations from main camera DSI", this.ml_main,
"Target disparity/convergence extracted from the main camera DSI, filtered and expanded");
......@@ -701,6 +713,25 @@ public class BiQuadParameters {
gd.addCheckbox ("Generate ML from rig DSI (GT) with random offset", this.ml_rig_rnd,
"Main camera data is not used, offset is just random from the rig (ground truth)");
gd.addMessage("AUX mode (4×EO + 4×LWIR, different resolution)");
gd.addCheckbox ("Generate 2D correlation for GT (average disparity)", this.ml_aux_ag,
"Generate 2D correlation using tile weighted average disparity as target disparity");
gd.addCheckbox ("Generate 2D correlation for GT (foreground disparity)", this.ml_aux_fg,
"Generate 2D correlation using tile weighted foreground average disparity as target disparity");
gd.addCheckbox ("Generate 2D correlation for GT (background disparity)", this.ml_aux_bg,
"Generate 2D correlation using tile weighted background average disparity as target disparity");
gd.addNumericField("AUX (LWIR) camera disparity sweep low (start)", this.ml_aux_low, 3,6,"",
"Perform disparity sweep for AUX (LWIR) camera, starting with this disparity");
gd.addNumericField("AUX (LWIR) camera disparity sweep high (end)", this.ml_aux_high, 3,6,"",
"Perform disparity sweep for AUX (LWIR) camera, up to (inclusive) this disparity");
gd.addNumericField("AUX (LWIR) camera disparity sweep step (<=0 - no sweep generation)", this.ml_aux_step, 3,6,"",
"Perform disparity sweep for AUX (LWIR) camera with this disparity step. Values <=0.0 disable sweep.");
gd.addMessage("Common ML generation parameters");
gd.addCheckbox ("Include auxiliary camera data in the ML output", this.ml_keep_aux,
"ML output will have the second set of the layers for the auxiliary camera. Disparity values should be scaled for the camera baseline");
gd.addCheckbox ("Keep inter-camera correlation data", this.ml_keep_inter,
......@@ -932,6 +963,13 @@ public class BiQuadParameters {
this.ml_main_rnd= gd.getNextBoolean();
this.ml_rig_rnd= gd.getNextBoolean();
this.ml_aux_ag= gd.getNextBoolean();
this.ml_aux_fg= gd.getNextBoolean();
this.ml_aux_bg= gd.getNextBoolean();
this.ml_aux_low= gd.getNextNumber();
this.ml_aux_high= gd.getNextNumber();
this.ml_aux_step= gd.getNextNumber();
this.ml_keep_aux= gd.getNextBoolean();
this.ml_keep_inter= gd.getNextBoolean();
this.ml_keep_tbrl= gd.getNextBoolean();
......@@ -1155,6 +1193,13 @@ public class BiQuadParameters {
properties.setProperty(prefix+"ml_main_rnd", this.ml_main_rnd+"");
properties.setProperty(prefix+"ml_rig_rnd", this.ml_rig_rnd+"");
properties.setProperty(prefix+"ml_aux_ag", this.ml_aux_ag+"");
properties.setProperty(prefix+"ml_aux_fg", this.ml_aux_fg+"");
properties.setProperty(prefix+"ml_aux_bg", this.ml_aux_bg+"");
properties.setProperty(prefix+"ml_aux_low", this.ml_aux_low+"");
properties.setProperty(prefix+"ml_aux_high", this.ml_aux_high+"");
properties.setProperty(prefix+"ml_aux_step", this.ml_aux_step+"");
properties.setProperty(prefix+"ml_keep_aux", this.ml_keep_aux+"");
properties.setProperty(prefix+"ml_keep_inter", this.ml_keep_inter+"");
properties.setProperty(prefix+"ml_keep_tbrl", this.ml_keep_tbrl+"");
......@@ -1377,6 +1422,13 @@ public class BiQuadParameters {
if (properties.getProperty(prefix+"ml_main_rnd")!=null) this.ml_main_rnd=Boolean.parseBoolean(properties.getProperty(prefix+"ml_main_rnd"));
if (properties.getProperty(prefix+"ml_rig_rnd")!=null) this.ml_rig_rnd=Boolean.parseBoolean(properties.getProperty(prefix+"ml_rig_rnd"));
if (properties.getProperty(prefix+"ml_aux_ag")!=null) this.ml_aux_ag=Boolean.parseBoolean(properties.getProperty(prefix+"ml_aux_ag"));
if (properties.getProperty(prefix+"ml_aux_fg")!=null) this.ml_aux_fg=Boolean.parseBoolean(properties.getProperty(prefix+"ml_aux_fg"));
if (properties.getProperty(prefix+"ml_aux_bg")!=null) this.ml_aux_bg=Boolean.parseBoolean(properties.getProperty(prefix+"ml_aux_bg"));
if (properties.getProperty(prefix+"ml_aux_low")!=null) this.ml_aux_low=Double.parseDouble(properties.getProperty(prefix+"ml_aux_low"));
if (properties.getProperty(prefix+"ml_aux_high")!=null) this.ml_aux_high=Double.parseDouble(properties.getProperty(prefix+"ml_aux_high"));
if (properties.getProperty(prefix+"ml_aux_step")!=null) this.ml_aux_step=Double.parseDouble(properties.getProperty(prefix+"ml_aux_step"));
if (properties.getProperty(prefix+"ml_keep_aux")!=null) this.ml_keep_aux=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_aux"));
if (properties.getProperty(prefix+"ml_keep_inter")!=null) this.ml_keep_inter=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_inter"));
if (properties.getProperty(prefix+"ml_keep_tbrl")!=null) this.ml_keep_tbrl=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_tbrl"));
......@@ -1590,7 +1642,14 @@ public class BiQuadParameters {
bqp.ml_main_rnd = this.ml_main_rnd;
bqp.ml_rig_rnd = this.ml_rig_rnd;
bqp.ml_keep_aux= this.ml_keep_aux;
bqp.ml_aux_ag = this.ml_aux_ag;
bqp.ml_aux_fg = this.ml_aux_fg;
bqp.ml_aux_bg = this.ml_aux_bg;
bqp.ml_aux_low = this.ml_aux_low;
bqp.ml_aux_high = this.ml_aux_high;
bqp.ml_aux_step = this.ml_aux_step;
bqp.ml_keep_aux = this.ml_keep_aux;
bqp.ml_randomize = this.ml_randomize;
bqp.ml_rig_tolerance= this.ml_rig_tolerance;
......
......@@ -289,7 +289,7 @@ public class Correlation2d {
tcorr[col],
fat_zero/scale_value);
if (first_col < 0) {// accummulate all channels in frst non-null color ( 0 for color, 2 for mono?)
if (first_col < 0) {// accummulate all channels in first non-null color ( 0 for color, 2 for mono?)
first_col = col; // first non-empty color (2, green) or 0 for color images
for (int n = 0; n < 4; n++) {
for (int i = 0; i < transform_len; i++) {
......@@ -1150,8 +1150,8 @@ public class Correlation2d {
double fc1 = full_corr[2 * ndir + 1][findx++]; // 1 - bottom, 3 (right)
double cc = 0.0;
if (offset >= 0.0) {
if ((fc0 > 0.0) && (fc1 > 0.0)) {
cc = Math.sqrt((fc0+offset)*(fc1+offset)) - offset;
if ((fc0 > -offset) && (fc1 > -offset)) {
cc = Math.sqrt((fc0 + offset) * (fc1 + offset)) - offset;
}
} else {
cc = 0.5*(fc0+fc1);
......
......@@ -175,6 +175,14 @@ public class ImageDtt {
public static int ML_OTHER_TARGET = 0; // Offset to target disparity data in ML_OTHER_INDEX layer tile
public static int ML_OTHER_GTRUTH = 2; // Offset to ground truth disparity data in ML_OTHER_INDEX layer tile
public static int ML_OTHER_GTRUTH_STRENGTH = 4; // Offset to ground truth confidence data in ML_OTHER_INDEX layer tile
public static int ML_OTHER_GTRUTH_RMS = 6; // Offset to ground truth RMS in ML_OTHER_INDEX layer tile
public static int ML_OTHER_GTRUTH_RMS_SPLIT = 8; // Offset to ground truth combined FG/BG RMS in ML_OTHER_INDEX layer tile
public static int ML_OTHER_GTRUTH_FG_DISP = 10; // Offset to ground truth FG disparity in ML_OTHER_INDEX layer tile
public static int ML_OTHER_GTRUTH_FG_STR = 12; // Offset to ground truth FG strength in ML_OTHER_INDEX layer tile
public static int ML_OTHER_GTRUTH_BG_DISP = 14; // Offset to ground truth BG disparity in ML_OTHER_INDEX layer tile
public static int ML_OTHER_GTRUTH_BG_STR = 16; // Offset to ground truth BG strength in ML_OTHER_INDEX layer tile
public static int ML_OTHER_AUX_DISP = 18; // Offset to AUX heuristic disparity in ML_OTHER_INDEX layer tile
public static int ML_OTHER_AUX_STR = 20; // Offset to AUX heuristic strength in ML_OTHER_INDEX layer tile
// indices in cross-camera correlation results
......@@ -1815,6 +1823,10 @@ public class ImageDtt {
// TODO: move port coordinates out of color channel loop
double [][] centersXY;
if ((disparity_array == null) || (disparity_array[tileY] == null) || (Double.isNaN(disparity_array[tileY][tileX]))) {
System.out.println("Bug with disparity_array !!!");
continue; // nothing to do for this tile
}
if (macro_mode){
if ((globalDebugLevel > -1) && (tileX == debug_tileX) && (tileY == debug_tileY)) { // before correction
......@@ -7643,9 +7655,6 @@ public class ImageDtt {
col_weights, // double [] col_weights,
fatzero); // double fat_zero)
// calculate interpolated "strips" to match different scales and orientations (ortho/diagonal) on the
// fine (0.5 pix) grid. ortho for scale == 1 provide even/even samples (1/4 of all), diagonal ones -
// checkerboard pattern
if (ml_center_corr != null) {
corr2d.corrCenterValues(
ml_hwidth, // int hwidth,
......@@ -7654,6 +7663,9 @@ public class ImageDtt {
ml_center_corr); // double [][] center_corr)
}
// calculate interpolated "strips" to match different scales and orientations (ortho/diagonal) on the
// fine (0.5 pix) grid. ortho for scale == 1 provide even/even samples (1/4 of all), diagonal ones -
// checkerboard pattern
double [][] strips = corr2d.scaleRotateInterpoateCorrelations(
corrs, // double [][] correlations,
all_pairs, // int pairs_mask,
......@@ -8431,26 +8443,26 @@ public class ImageDtt {
corr2d, // final Correlation2d corr2d,
clt_data_main, // final double [][][][] clt_data,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
col_weights, // final double [] col_weights,
ml_hwidth, // final int ml_hwidth,
ml_data_main, // final double [][] ml_center_corr,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
double [] tile_corrs_aux = tileCorrs(
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
fatzero, // final double fatzero, // May use correlation fat zero from 2 different parameters - fat_zero and rig.ml_fatzero
true, // final boolean get4dirs, // calculate disparity/strength for each of the 4 directions
corr2d, // final Correlation2d corr2d,
corr2d, // final Correlation2d corr2d,
clt_data_aux, // final double [][][][] clt_data,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
col_weights, // final double [] col_weights,
ml_hwidth, // final int ml_hwidth,
ml_data_aux, // final double [][] ml_center_corr,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
ml_data_aux, // final double [][] ml_center_corr,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
extra_disparity_main = tile_corrs_main[DISP_FULL_INDEX];
extra_disparity_aux = tile_corrs_aux[DISP_FULL_INDEX];
......@@ -8771,10 +8783,11 @@ public class ImageDtt {
final CLTParameters clt_parameters,
final double fatzero, // May use correlation fat zero from 2 different parameters - fat_zero and rig.ml_fatzero
final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
// lt_rad = 0 for lwir
final int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
final boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity. If main camera is not calculated - use for AUX directly
final double [][][] image_data_main, // first index - number of image in a quad
final double [][][] image_data_aux, // first index - number of image in a quad
final boolean [][] saturation_main, // (near) saturated pixels or null
......@@ -8801,22 +8814,25 @@ public class ImageDtt {
final int threadsMax, // maximal number of threads to launch
final int debugLevel)
{
final boolean calc_main = (clt_kernels_main != null) && (image_data_main != null) && (geometryCorrection_main != null);
final boolean calc_aux = (clt_kernels_aux != null) && (image_data_aux != null) && (geometryCorrection_aux != null);
final boolean calc_both = calc_main && calc_aux;
final int globalDebugLevel = clt_parameters.rig.rig_mode_debug?debugLevel:-2;
final int debug_tileX = clt_parameters.tileX;
final int debug_tileY = clt_parameters.tileY;
final int quad_main = image_data_main.length; // number of subcameras
final int quad_aux = image_data_aux.length; // number of subcameras
final int quad_main = calc_main ? image_data_main.length: 0; // number of subcameras
final int quad_aux = calc_aux ? image_data_aux.length : 0; // number of subcameras
final int numcol = 3; // number of colors
final int nChn = image_data_main[0].length;
final int height=image_data_main[0][0].length/width;
// final int nColors = calc_main ? image_data_main[0].length : image_data_aux[0].length;
final int height = (calc_main ? image_data_main[0][0].length: image_data_aux[0][0].length)/width;
final int tilesX=width/clt_parameters.transform_size;
final int tilesY=height/clt_parameters.transform_size;
final int nTilesInChn=tilesX*tilesY;
// clt_data does not need to be for the whole image (no, it is used for textures)
final double [][][][][][][] clt_bidata = (keep_clt_data)? (new double[2][][][][][][]):null;
if (clt_bidata != null) {
clt_bidata[0] = new double[quad_main][nChn][tilesY][tilesX][][];
clt_bidata[1] = new double[quad_aux][nChn][tilesY][tilesX][][];
clt_bidata[0] = new double[quad_main][numcol][tilesY][tilesX][][];
clt_bidata[1] = new double[quad_aux][numcol][tilesY][tilesX][][];
}
final double [][] lt_corr = (lt_rad > 0)? (new double [nTilesInChn][]):null; // will keep inter-camera combo correlation, later combined in a separate multi-thread run
......@@ -8824,9 +8840,18 @@ public class ImageDtt {
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final double [] col_weights= new double [numcol]; // colors are RBG
col_weights[2] = 1.0/(1.0 + clt_parameters.corr_red + clt_parameters.corr_blue); // green color
col_weights[0] = clt_parameters.corr_red * col_weights[2];
col_weights[1] = clt_parameters.corr_blue * col_weights[2];
if (isMonochrome()) {
col_weights[2] = 1.0;// green color/mono
col_weights[0] = 0;
col_weights[1] = 0;
} else {
col_weights[2] = 1.0/(1.0 + clt_parameters.corr_red + clt_parameters.corr_blue); // green color
col_weights[0] = clt_parameters.corr_red * col_weights[2];
col_weights[1] = clt_parameters.corr_blue * col_weights[2];
}
final int corr_size = clt_parameters.transform_size * 2 -1;
final int [][] transpose_indices = new int [corr_size*(corr_size-1)/2][2];
int indx = 0;
......@@ -8862,11 +8887,6 @@ public class ImageDtt {
System.out.println("clt_aberrations_quad_corr(): width="+width+" height="+height+" transform_size="+clt_parameters.transform_size+
" debug_tileX="+debug_tileX+" debug_tileY="+debug_tileY+" globalDebugLevel="+globalDebugLevel);
}
/// final int [][] corr_pairs ={ // {first, second, rot} rot: 0 - as is, 1 - swap y,x
/// {0,1,0},
/// {2,3,0},
/// {0,2,1},
/// {1,3,1}};
final double[][] port_offsets = {
{-0.5, -0.5},
......@@ -8944,9 +8964,9 @@ public class ImageDtt {
sdfa_instance.showArrays(lt_window, 2*clt_parameters.transform_size, 2*clt_parameters.transform_size, "lt_window");
}
final Matrix [] corr_rots_main = geometryCorrection_main.getCorrVector().getRotMatrices(); // get array of per-sensor rotation matrices
final Matrix rigMatrix = geometryCorrection_aux.getRotMatrix(true);
final Matrix [] corr_rots_aux = geometryCorrection_aux.getCorrVector().getRotMatrices(rigMatrix); // get array of per-sensor rotation matrices
final Matrix [] corr_rots_main = calc_main?geometryCorrection_main.getCorrVector().getRotMatrices():null; // get array of per-sensor rotation matrices
final Matrix rigMatrix = calc_aux? geometryCorrection_aux.getRotMatrix(true):null;
final Matrix [] corr_rots_aux = calc_aux? geometryCorrection_aux.getCorrVector().getRotMatrices(rigMatrix):null; // get array of per-sensor rotation matrices (will be OK if (rigMatrix==null)
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
......@@ -8958,15 +8978,14 @@ public class ImageDtt {
// showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
double centerX; // center of aberration-corrected (common model) tile, X
double centerY; //
double [][] fract_shiftsXY_main = new double[quad_main][];
double [][] fract_shiftsXY_aux = new double[quad_aux][];
double [][] fract_shiftsXY_main = calc_main ? new double[quad_main][]:null;
double [][] fract_shiftsXY_aux = calc_aux ? new double[quad_aux][]:null;
double [][] tcorr_combo = null; // [15*15] pixel space
double [][][][] clt_data_main = new double[quad_main][nChn][][];
double [][][][] clt_data_aux = new double[quad_aux][nChn][][];
double [][] ml_data_main = (ml_data != null)? new double [ML_TOP_AUX_INDEX][(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
double [][] ml_data_aux = (ml_data != null)? new double [ML_TOP_AUX_INDEX][(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
double [] ml_data_inter = (ml_data != null)? new double [(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
// double [] ml_data_other = (ml_data != null)? new double [(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
double [][][][] clt_data_main = calc_main ? new double[quad_main][numcol][][] : null;
double [][][][] clt_data_aux = calc_aux? new double[quad_aux][numcol][][]:null;
double [][] ml_data_main = (calc_main && (ml_data != null)) ? new double [ML_VERT_INDEX+1][(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
double [][] ml_data_aux = (calc_aux && (ml_data != null)) ? new double [ML_VERT_INDEX+1][(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
double [] ml_data_inter = (calc_both && (ml_data != null)) ? new double [(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
double [] ml_data_dbg1 = (ml_data != null)? new double [(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
......@@ -8986,54 +9005,59 @@ public class ImageDtt {
if (disparity_bimap != null){
disparity_bimap[BI_TARGET_INDEX][tIndex] = Double.NaN;
}
continue; // nothing to do for this tile
continue; // nothing to do for this tile
}
int img_mask = getImgMask(tile_op[tileY][tileX]); // which images to use
/// int corr_mask = getPairMask(tile_op[tileY][tileX]); // which pairs to combine in the combo: 1 - top, 2 bottom, 4 - left, 8 - right
// mask out pairs that use missing channels
int img_mask = getImgMask(tile_op[tileY][tileX]); // which images to use
// Is it currently used with diagonals?
// TODO: use masks from tile task
/// for (int i = 0; i< corr_pairs.length; i++){
/// if ((((1 << corr_pairs[i][0]) & img_mask) == 0) || (((1 << corr_pairs[i][1]) & img_mask) == 0)) {
/// corr_mask &= ~ (1 << i);
/// }
/// }
// boolean debugTile =(tileX == debug_tileX) && (tileY == debug_tileY);
final int [] overexp_main = (saturation_main != null) ? ( new int [2]): null;
final int [] overexp_aux = (saturation_aux != null) ? ( new int [2]): null;
final int [] overexp_main = (calc_main && (saturation_main != null)) ? ( new int [2]): null;
final int [] overexp_aux = (calc_aux && (saturation_aux != null)) ? ( new int [2]): null;
// Moved from inside chn loop
centerX = tileX * clt_parameters.transform_size + clt_parameters.transform_size/2; // - shiftX;
centerY = tileY * clt_parameters.transform_size + clt_parameters.transform_size/2; // - shiftY;
// TODO: move port coordinates out of color channel loop
double [][] centersXY_main;
double [][] centersXY_aux;
double disparity_main = disparity_array[tileY][tileX];
double disparity_aux = disparity_main * geometryCorrection_aux.getDisparityRadius()/geometryCorrection_main.getDisparityRadius();
double [][] centersXY_main = null;
double [][] centersXY_aux = null;
double disparity_main = disparity_array[tileY][tileX]; // will be used for AUX directly if !calc_main
double disparity_aux = calc_both ? (disparity_main * geometryCorrection_aux.getDisparityRadius()/geometryCorrection_main.getDisparityRadius()) : 0.0;
if (disparity_bimap != null){
disparity_bimap[BI_TARGET_INDEX][tIndex] = disparity_main;
}
centersXY_main = geometryCorrection_main.getPortsCoordinatesAndDerivatives(
geometryCorrection_main, // GeometryCorrection gc_main,
false, // boolean use_rig_offsets,
corr_rots_main, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
centerX,
centerY,
disparity_main); // + disparity_corr);
if (calc_main) {
centersXY_main = geometryCorrection_main.getPortsCoordinatesAndDerivatives(
geometryCorrection_main, // GeometryCorrection gc_main,
false, // boolean use_rig_offsets,
corr_rots_main, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
centerX,
centerY,
disparity_main); // + disparity_corr);
}
if (calc_aux) {
if (calc_main) { // use rig and main coordinates
centersXY_aux = geometryCorrection_aux.getPortsCoordinatesAndDerivatives(
geometryCorrection_main, // GeometryCorrection gc_main,
true, // boolean use_rig_offsets,
corr_rots_aux, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
centerX,
centerY,
disparity_aux); // + disparity_corr);
} else {
centersXY_aux = geometryCorrection_aux.getPortsCoordinatesAndDerivatives(
geometryCorrection_aux, // GeometryCorrection gc_main,
false, // boolean use_rig_offsets,
corr_rots_aux, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
centerX,
centerY,
disparity_main); // + disparity_corr);
centersXY_aux = geometryCorrection_aux.getPortsCoordinatesAndDerivatives(
geometryCorrection_main, // GeometryCorrection gc_main,
true, // boolean use_rig_offsets,
corr_rots_aux, // Matrix [] rots,
null, // Matrix [][] deriv_rots,
null, // double [][] pXYderiv, // if not null, should be double[8][]
centerX,
centerY,
disparity_aux); // + disparity_corr);
}
}
// acquisition time of the tiles centers in scanline times
if (ers_delay != null) {
for (int i = 0; i < quad_main; i++) ers_delay[0][i][nTile] = centersXY_main[i][1]-geometryCorrection_main.woi_tops[i];
......@@ -9067,7 +9091,7 @@ public class ImageDtt {
}
for (int chn = 0; chn <numcol; chn++) {
if ((globalDebugLevel > -1) && (tileX == debug_tileX) && (tileY == debug_tileY) && (chn == 2)) {
if (calc_both && !isMonochrome() && (globalDebugLevel > -1) && (tileX == debug_tileX) && (tileY == debug_tileY) && (chn == 2)) {
System.out.println("\nMain camera, centerX="+centerX+", centerY="+centerY);
System.out.println(disparity_array[tileY][tileX]+"\t"+
centersXY_main[0][0]+"\t"+centersXY_main[0][1]+"\t"+
......@@ -9082,7 +9106,7 @@ public class ImageDtt {
centersXY_aux[3][0]+"\t"+centersXY_aux[3][1]+"\t");
}
for (int i = 0; i < quad_main; i++) {
for (int i = 0; i < quad_main; i++) { // quad_main == 0 if not calculated
clt_data_main[i][chn] = new double [4][];
fract_shiftsXY_main[i] = extract_correct_tile( // return a pair of residual offsets
image_data_main[i],
......@@ -9103,7 +9127,7 @@ public class ImageDtt {
}
for (int i = 0; i < quad_aux; i++) {
for (int i = 0; i < quad_aux; i++) { // quad_aux == 0 if not calculated
clt_data_aux[i][chn] = new double [4][];
fract_shiftsXY_aux[i] = extract_correct_tile( // return a pair of residual offsets
image_data_aux[i],
......@@ -9130,13 +9154,16 @@ public class ImageDtt {
if ((globalDebugLevel > 0) && (debug_tileX == tileX) && (debug_tileY == tileY) && (chn == 2)) {
ShowDoubleFloatArrays sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging?
String [] titles = {"CC0","SC0","CS0","SS0","CC1","SC1","CS1","SS1","CC2","SC2","CS2","SS2","CC3","SC3","CS3","SS3"};
double [][] dbg_tile = new double [16][];
for (int i = 0; i < 16; i++) dbg_tile[i]=clt_data_main[i>>2][chn][i & 3];
sdfa_instance.showArrays(dbg_tile, clt_parameters.transform_size, clt_parameters.transform_size, true, "MAIN_pre-shifted_x"+tileX+"_y"+tileY, titles);
double [][] dbg_tile_aux = new double [16][];
for (int i = 0; i < 16; i++) dbg_tile[i]=clt_data_aux[i>>2][chn][i & 3];
sdfa_instance.showArrays(dbg_tile_aux, clt_parameters.transform_size, clt_parameters.transform_size, true, "AUX_pre-shifted_x"+tileX+"_y"+tileY, titles);
if (calc_main) {
double [][] dbg_tile = new double [16][];
for (int i = 0; i < 16; i++) dbg_tile[i]=clt_data_main[i>>2][chn][i & 3];
sdfa_instance.showArrays(dbg_tile, clt_parameters.transform_size, clt_parameters.transform_size, true, "MAIN_pre-shifted_x"+tileX+"_y"+tileY, titles);
}
if (calc_aux) {
double [][] dbg_tile_aux = new double [16][];
for (int i = 0; i < 16; i++) dbg_tile_aux[i]=clt_data_aux[i>>2][chn][i & 3];
sdfa_instance.showArrays(dbg_tile_aux, clt_parameters.transform_size, clt_parameters.transform_size, true, "AUX_pre-shifted_x"+tileX+"_y"+tileY, titles);
}
}
if ((globalDebugLevel > 0) && (tileX >= debug_tileX - 2) && (tileX <= debug_tileX + 2) &&
......@@ -9171,19 +9198,20 @@ public class ImageDtt {
(tileY >= debug_tileY - 2) && (tileY <= debug_tileY+2)));
}
if ((globalDebugLevel > 0) && (debug_tileX == tileX) && (debug_tileY == tileY)) {
ShowDoubleFloatArrays sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging?
String [] titles = {"CC0","SC0","CS0","SS0","CC1","SC1","CS1","SS1","CC2","SC2","CS2","SS2","CC3","SC3","CS3","SS3"};
double [][] dbg_tile = new double [16][];
for (int i = 0; i < 16; i++) dbg_tile[i]=clt_data_main[i>>2][chn][i & 3];
sdfa_instance.showArrays(dbg_tile, clt_parameters.transform_size, clt_parameters.transform_size, true, "MAIN_shifted_x"+tileX+"_y"+tileY+"-z", titles);
double [][] dbg_tile_aux = new double [16][];
for (int i = 0; i < 16; i++) dbg_tile[i]=clt_data_aux[i>>2][chn][i & 3];
sdfa_instance.showArrays(dbg_tile_aux, clt_parameters.transform_size, clt_parameters.transform_size, true, "AUX_shifted_x"+tileX+"_y"+tileY+"-z", titles);
if (calc_main) {
double [][] dbg_tile = new double [16][];
for (int i = 0; i < 16; i++) dbg_tile[i]=clt_data_main[i>>2][chn][i & 3];
sdfa_instance.showArrays(dbg_tile, clt_parameters.transform_size, clt_parameters.transform_size, true, "MAIN_shifted_x"+tileX+"_y"+tileY+"-z", titles);
}
if (calc_aux) {
double [][] dbg_tile_aux = new double [16][];
for (int i = 0; i < 16; i++) dbg_tile_aux[i]=clt_data_aux[i>>2][chn][i & 3];
sdfa_instance.showArrays(dbg_tile_aux, clt_parameters.transform_size, clt_parameters.transform_size, true, "AUX_shifted_x"+tileX+"_y"+tileY+"-z", titles);
}
}
}
int tile_lma_debug_level = ((tileX == debug_tileX) && (tileY == debug_tileY))? clt_parameters.img_dtt.lma_debug_level : -1;
......@@ -9194,45 +9222,42 @@ public class ImageDtt {
// fill clt_corr_combo if it exists
if (disparity_bimap != null){ // not null - calculate correlations
// calculate overexposed fraction - remove ?
// if (saturation_imp != null){
// disparity_map[OVEREXPOSED][nTile] = (1.0 * overexp_all[0]) / overexp_all[1];
// }
double [] tile_corrs_main = tileCorrs(
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
fatzero, // final double fatzero, // May use correlation fat zero from 2 different parameters - fat_zero and rig.ml_fatzero
true, // final boolean get4dirs, // calculate disparity/strength for each of the 4 directions
corr2d, // final Correlation2d corr2d,
clt_data_main, // final double [][][][] clt_data,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
ml_hwidth, // final int ml_hwidth,
ml_data_main, // final double [][] ml_center_corr,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
double [] tile_corrs_aux = tileCorrs(
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
fatzero, // final double fatzero, // May use correlation fat zero from 2 different parameters - fat_zero and rig.ml_fatzero
true, // final boolean get4dirs, // calculate disparity/strength for each of the 4 directions
corr2d, // final Correlation2d corr2d,
clt_data_aux, // final double [][][][] clt_data,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
ml_hwidth, // final int ml_hwidth,
ml_data_aux, // final double [][] ml_center_corr,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
extra_disparity_main = tile_corrs_main[DISP_FULL_INDEX];
extra_disparity_aux = tile_corrs_aux[DISP_FULL_INDEX];
if (Double.isNaN(extra_disparity_main)) extra_disparity_main = 0;
if (Double.isNaN(extra_disparity_aux)) extra_disparity_aux = 0;
double [] tile_corrs_main = new double[0]; //null;
double [] tile_corrs_aux = new double[0]; //null;
if (calc_main) {
tile_corrs_main = tileCorrs(
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
fatzero, // final double fatzero, // May use correlation fat zero from 2 different parameters - fat_zero and rig.ml_fatzero
true, // final boolean get4dirs, // calculate disparity/strength for each of the 4 directions
corr2d, // final Correlation2d corr2d,
clt_data_main, // final double [][][][] clt_data,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
ml_hwidth, // final int ml_hwidth,
ml_data_main, // final double [][] ml_center_corr,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
extra_disparity_main = tile_corrs_main[DISP_FULL_INDEX];
if (Double.isNaN(extra_disparity_main)) extra_disparity_main = 0;
}
if (calc_aux) {
tile_corrs_aux = tileCorrs(
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
fatzero, // final double fatzero, // May use correlation fat zero from 2 different parameters - fat_zero and rig.ml_fatzero
true, // final boolean get4dirs, // calculate disparity/strength for each of the 4 directions
corr2d, // final Correlation2d corr2d,
clt_data_aux, // final double [][][][] clt_data,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
ml_hwidth, // final int ml_hwidth,
ml_data_aux, // final double [][] ml_center_corr,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
extra_disparity_aux = tile_corrs_aux[DISP_FULL_INDEX];
if (Double.isNaN(extra_disparity_aux)) extra_disparity_aux = 0;
}
for (int i = 0; i < tile_corrs_main.length; i++) {
int dest = SNGL_TO_BI[0][i];
......@@ -9242,96 +9267,97 @@ public class ImageDtt {
int dest = SNGL_TO_BI[1][i];
if (disparity_bimap[dest] != null) disparity_bimap[dest][nTile] = tile_corrs_aux[i];
}
if (Double.isNaN(disparity_bimap[BI_STR_FULL_INDEX][tIndex])) {
if (calc_main && Double.isNaN(disparity_bimap[BI_STR_FULL_INDEX][tIndex])) {
System.out.println("BUG: 3. disparity_map[BI_STR_FULL_INDEX][tIndex] should not be NaN");
}
if (Double.isNaN(disparity_bimap[BI_ASTR_FULL_INDEX][tIndex])) {
if (calc_aux && Double.isNaN(disparity_bimap[BI_ASTR_FULL_INDEX][tIndex])) {
System.out.println("BUG: 3a. disparity_map[BI_ASTR_FULL_INDEX][tIndex] should not be NaN");
}
if (clt_corr_combo != null) { // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
tcorr_combo = new double [TCORR_TITLES.length][corr_size * corr_size];
}
double [] inter_cam_corr = corr2d.correlateInterCamerasFD(
clt_data_main, // double [][][][] clt_data_tile_main,
clt_data_aux, // double [][][][] clt_data_tile_aux,
filter, // double [] lpf,
scale_strengths,
col_weights, // double [] col_weights,
fatzero); // double fat_zero)
double [] inter_corrs_dxy = tileInterCamCorrs(
no_int_x0, // final boolean no_int_x0, // do not offset window to integer - used when averaging low textures to avoid "jumps" for very wide
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
inter_cam_corr, // final double [] inter_cam_corr,
corr2d, // final Correlation2d corr2d,
ml_hwidth, // final int ml_hwidth,
ml_data_inter, // final double [] ml_center_corr,
tcorr_combo, // double [][] tcorr_combo,
notch_mode, // final boolean notch_mode,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
double [] inter_cam_corr = null;
double [] inter_corrs_dxy = null;
if (calc_both) {
inter_cam_corr = corr2d.correlateInterCamerasFD(
clt_data_main, // double [][][][] clt_data_tile_main,
clt_data_aux, // double [][][][] clt_data_tile_aux,
filter, // double [] lpf,
scale_strengths,
col_weights, // double [] col_weights,
fatzero); // double fat_zero)
inter_corrs_dxy = tileInterCamCorrs(
no_int_x0, // final boolean no_int_x0, // do not offset window to integer - used when averaging low textures to avoid "jumps" for very wide
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
inter_cam_corr, // final double [] inter_cam_corr,
corr2d, // final Correlation2d corr2d,
ml_hwidth, // final int ml_hwidth,
ml_data_inter, // final double [] ml_center_corr,
tcorr_combo, // double [][] tcorr_combo,
notch_mode, // final boolean notch_mode,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
if (lt_corr != null) {
lt_corr[tIndex] = inter_cam_corr;
}
if (lt_corr != null) {
lt_corr[tIndex] = inter_cam_corr;
}
if (inter_corrs_dxy != null) {
disparity_bimap[BI_DISP_CROSS_INDEX][nTile] = inter_corrs_dxy[INDEX_DISP];
disparity_bimap[BI_STR_CROSS_INDEX][nTile] = inter_corrs_dxy[INDEX_STRENGTH];
disparity_bimap[BI_DISP_CROSS_DX_INDEX][nTile] = inter_corrs_dxy[INDEX_DX];
disparity_bimap[BI_DISP_CROSS_DY_INDEX][nTile] = inter_corrs_dxy[INDEX_DY];
// TODO: Use strength for the same residual disparity
disparity_bimap[BI_STR_ALL_INDEX][nTile] =
Math.pow(inter_corrs_dxy[INDEX_STRENGTH]*
disparity_bimap[BI_STR_FULL_INDEX][nTile]*
disparity_bimap[BI_ASTR_FULL_INDEX][nTile], 1.0/3);
if (inter_corrs_dxy != null) {
disparity_bimap[BI_DISP_CROSS_INDEX][nTile] = inter_corrs_dxy[INDEX_DISP];
disparity_bimap[BI_STR_CROSS_INDEX][nTile] = inter_corrs_dxy[INDEX_STRENGTH];
disparity_bimap[BI_DISP_CROSS_DX_INDEX][nTile] = inter_corrs_dxy[INDEX_DX];
disparity_bimap[BI_DISP_CROSS_DY_INDEX][nTile] = inter_corrs_dxy[INDEX_DY];
// TODO: Use strength for the same residual disparity
disparity_bimap[BI_STR_ALL_INDEX][nTile] =
Math.pow(inter_corrs_dxy[INDEX_STRENGTH]*
disparity_bimap[BI_STR_FULL_INDEX][nTile]*
disparity_bimap[BI_ASTR_FULL_INDEX][nTile], 1.0/3);
}
}
// finalize ML stuff
if (ml_data != null) {
// save data for the main camera
for (int nlayer = 0; nlayer < ML_TOP_AUX_INDEX; nlayer++) {
// save main camera data
corr2d.saveMlTile(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
nlayer + 0, // int ml_layer,
ml_data_main[nlayer], // double [] ml_tile,
tilesX); // int tilesX);
if (calc_main) {
corr2d.saveMlTile(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
nlayer + 0, // int ml_layer,
ml_data_main[nlayer], // double [] ml_tile,
tilesX); // int tilesX);
}
// save aux_camera data
corr2d.saveMlTile(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
nlayer + ML_TOP_AUX_INDEX, // int ml_layer,
ml_data_aux[nlayer], // double [] ml_tile,
tilesX); // int tilesX);
if (calc_aux) {
corr2d.saveMlTile(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
nlayer + ML_TOP_AUX_INDEX, // int ml_layer,
ml_data_aux[nlayer], // double [] ml_tile,
tilesX); // int tilesX);
}
}
// save inter-camera correlation
corr2d.saveMlTile(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ML_INTER_INDEX, // int ml_layer,
ml_data_inter, // double [] ml_tile,
tilesX); // int tilesX);
if (calc_both ) {
corr2d.saveMlTile(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ML_INTER_INDEX, // int ml_layer,
ml_data_inter, // double [] ml_tile,
tilesX); // int tilesX);
}
// save other data (just 1 value)
/*
corr2d.saveMlTile(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ML_OTHER_INDEX, // int ml_layer,
ml_data_other, // double [] ml_tile,
tilesX); // int tilesX);
*/
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
......@@ -9342,7 +9368,7 @@ public class ImageDtt {
disparity_main, // target disparitydouble ml_value,
tilesX); // int tilesX);
if (ml_data_dbg1 != null) {
if (calc_both && (ml_data_dbg1 != null)) {
tileInterCamCorrs(
false, // final boolean no_int_x0, // do not offset window to integer - used when averaging low textures to avoid "jumps" for very wide
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
......@@ -9369,10 +9395,7 @@ public class ImageDtt {
ml_data_dbg1, // double [] ml_tile,
tilesX); // int tilesX);
}
}
} // if (disparity_map != null){ // not null - calculate correlations
if (tcorr_combo != null) { // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
......@@ -9381,7 +9404,7 @@ public class ImageDtt {
}
}
if (texture_tiles_main !=null) {
if (calc_main && (texture_tiles_main !=null)) {
generateTextureTiles (
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
extra_disparity_main, // final double extra_disparity,
......@@ -9400,7 +9423,7 @@ public class ImageDtt {
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel);
}
if (texture_tiles_aux !=null) {
if (calc_aux && (texture_tiles_aux !=null)) {
generateTextureTiles (
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
extra_disparity_aux, // final double extra_disparity,
......@@ -9435,7 +9458,7 @@ public class ImageDtt {
startAndJoin(threads);
// If it was low-texture mode, use lt_corr to average bi-quad inter-correlation between neighbor tiles and then calculate disparity/strength
if (lt_corr != null) {
if (calc_both && (lt_corr != null)) {
//notch_mode
// prepare weights for neighbors
final int lt_rad_x = notch_mode? 0: lt_rad;
......
......@@ -221,7 +221,7 @@ public class ImageDttParameters {
gd.addNumericField("0% to 100 % transition range for poles", this.corr_notch_blur, 3,6,"half-pix",
"Transition range, shifted sine is used");
gd.addMessage("Window for niormal correlations");
gd.addMessage("Window for normal correlations");
gd.addNumericField("Number of rows to calculate CM disparity", this.corr_wndy_size, 0, 3, "",
"Number of rows to calculate maximum. Normally should be equal to the previous parameter");
......
......@@ -68,6 +68,21 @@ import ij.process.ImageProcessor;
public class QuadCLT {
public static final String [] FGBG_TITLES_ADJ = {"disparity","strength"};
// public static final String [] FGBG_TITLES = {"disparity","strength", "rms","rms-split","fg-disp","fg-str","bg-disp","bg-str"};
public static final String [] FGBG_TITLES_AUX = {"disparity","strength", "rms","rms-split","fg-disp","fg-str","bg-disp","bg-str","aux-disp","aux-str"};
// public static final enum FGBG {DISPARITY, STRENGTH, RMS, RMS_SPLIT, FG_DISP, FG_STR, BG_DISP, BG_STR};
public static final int FGBG_DISPARITY = 0;
public static final int FGBG_STRENGTH = 1;
public static final int FGBG_RMS = 2;
public static final int FGBG_RMS_SPLIT = 3;
public static final int FGBG_FG_DISP = 4;
public static final int FGBG_FG_STR = 5;
public static final int FGBG_BG_DISP = 6;
public static final int FGBG_BG_STR = 7;
public static final int FGBG_AUX_DISP = 8; // AUX calculated disparity
public static final int FGBG_AUX_STR = 9; // AUX calculated strength
static String [] fine_corr_coeff_names = {"A","B","C","D","E","F"};
static String [] fine_corr_dir_names = {"X","Y"};
public static String PREFIX = "EYESIS_DCT."; // change later (first on save)
......@@ -6187,16 +6202,16 @@ public class QuadCLT {
}
// simple average (ignoring below minimal)
int num_slices = split_fg_bg? 8:2;
int num_slices = split_fg_bg? FGBG_TITLES_AUX.length:FGBG_TITLES_ADJ.length;
double [][] ds_aux_avg = new double [num_slices][tilesX_aux * tilesY_aux];
for (int ty = 0; ty < tilesY_aux; ty++) {
for (int tx = 0; tx < tilesX_aux; tx++) {
if ((ty == 3) && (tx == 12)) {
System.out.println("tx = "+tx+", ty = "+ty);
}
// if ((ty == 3) && (tx == 12)) {
// System.out.println("tx = "+tx+", ty = "+ty);
// }
int nt = ty * tilesX_aux + tx;
ds_aux_avg[0][nt] = Double.NaN;
ds_aux_avg[1][nt] = 0.0;
ds_aux_avg[FGBG_DISPARITY][nt] = Double.NaN;
ds_aux_avg[FGBG_STRENGTH][nt] = 0.0;
if(ds_list.get(nt).isEmpty()) continue;
Collections.sort(ds_list.get(nt), new Comparator<DS>() {
@Override
......@@ -6217,22 +6232,22 @@ public class QuadCLT {
swd2 += wd * dsi.disparity;
}
ds_aux_avg[0][nt] = swd/sw;
ds_aux_avg[1][nt] = sw/ds_list.get(nt).size();
ds_aux_avg[FGBG_DISPARITY][nt] = swd/sw;
ds_aux_avg[FGBG_STRENGTH][nt] = sw/ds_list.get(nt).size();
double rms = Math.sqrt( (swd2 * sw - swd * swd) / (sw * sw));
if (for_adjust && (rms >= clt_Parameters.ly_gt_rms)) { // remove ambiguous tiles
ds_aux_avg[0][nt] = Double.NaN;
ds_aux_avg[1][nt] = 0;
ds_aux_avg[FGBG_DISPARITY][nt] = Double.NaN;
ds_aux_avg[FGBG_STRENGTH][nt] = 0;
}
if (split_fg_bg) {
ds_aux_avg[2][nt] = rms;
ds_aux_avg[3][nt] = ds_aux_avg[2][nt]; // rms
ds_aux_avg[4][nt] = ds_aux_avg[0][nt]; // fg disp
ds_aux_avg[5][nt] = ds_aux_avg[1][nt]; // fg strength
ds_aux_avg[6][nt] = ds_aux_avg[0][nt]; // bg disp
ds_aux_avg[7][nt] = ds_aux_avg[1][nt]; // bg strength
ds_aux_avg[FGBG_RMS ][nt] = rms;
ds_aux_avg[FGBG_RMS_SPLIT][nt] = ds_aux_avg[2][nt]; // rms
ds_aux_avg[FGBG_FG_DISP][nt] = ds_aux_avg[0][nt]; // fg disp
ds_aux_avg[FGBG_FG_STR][nt] = ds_aux_avg[1][nt]; // fg strength
ds_aux_avg[FGBG_BG_DISP][nt] = ds_aux_avg[0][nt]; // bg disp
ds_aux_avg[FGBG_BG_STR][nt] = ds_aux_avg[1][nt]; // bg strength
if (rms >= clt_Parameters.ly_gt_rms) {
// splitting while minimizing sum of 2 squared errors
double [][] swfb = new double [2][ds_list.get(nt).size() -1];
......@@ -6261,12 +6276,12 @@ public class QuadCLT {
for (int i = 1; i < s2fb.length; i++) if (s2fb[i] < s2fb[nsplit]) {
nsplit = i;
}
ds_aux_avg[3][nt] = s2fb[nsplit]; // rms split
ds_aux_avg[4][nt] = swdfb[1][nsplit] / swfb[1][nsplit] ; // fg disp
ds_aux_avg[5][nt] = swfb[1][nsplit]/ (s2fb.length - nsplit) ; // fg strength
ds_aux_avg[FGBG_RMS_SPLIT][nt] = s2fb[nsplit]; // rms split
ds_aux_avg[FGBG_FG_DISP][nt] = swdfb[1][nsplit] / swfb[1][nsplit] ; // fg disp
ds_aux_avg[FGBG_FG_STR][nt] = swfb[1][nsplit]/ (s2fb.length - nsplit) ; // fg strength
ds_aux_avg[6][nt] = swdfb[0][nsplit] / swfb[0][nsplit] ; // bg disp
ds_aux_avg[7][nt] = swfb[0][nsplit]/ (nsplit + 1) ; // bg strength
ds_aux_avg[FGBG_BG_DISP][nt] = swdfb[0][nsplit] / swfb[0][nsplit] ; // bg disp
ds_aux_avg[FGBG_BG_STR][nt] = swfb[0][nsplit]/ (nsplit + 1) ; // bg strength
}
}
}
......@@ -7091,7 +7106,7 @@ public class QuadCLT {
System.out.println("#### extrinsicsCLT(): iteration step = "+(num_iter + 1) + " ( of "+max_tries+") change = "+
comp_diff + " ("+min_sym_update+"), previous RMS = " + new_corr[0][1][0]+ " (debugLevel = "+debugLevel+")");
}
if (debugLevel > -2) {
if (debugLevel > -10) {
if ((debugLevel > -1) || done) {
// System.out.println("#### extrinsicsCLT(): iteration step = "+(num_iter + 1) + " ( of "+max_tries+") change = "+
// comp_diff + " ("+min_sym_update+"), previous RMS = " + new_corr[0][1][0]);
......@@ -7712,7 +7727,7 @@ public class QuadCLT {
// Get filtered (by flexible "plates" that can tilt to accommodate tiles disparity/strength map, that uses data from all previous
// disparity "measurements". This data will be combined with individual tiles, quad, hor and vert correlation results
double [][] filtered_disp_strength = tp.getFilteredDisparityStrength(
double [][] filtered_disp_strength = tp.getFilteredDisparityStrength( // disp all 0?, str -1/0
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,// List, first, last - to search for the already tried disparity
lastPassPlus1 - 1, // final int measured_scan_index, // will not look at higher scans
0, // final int start_scan_index,
......@@ -7786,6 +7801,9 @@ public class QuadCLT {
refine_pass, // may add 1 to include current (for future?) // final int lastPassPlus1,
passes.get(refine_pass)); // final int lastPassPlus1,
// repeated composite scan may be replaced by just a clone
if (last_pass){
System.out.println("+++++++++++ Last pass - pre compositeScan() ++++++++++++");
}
CLTPass3d extended_pass = tp.compositeScan(
passes, // final ArrayList <CLTPass3d> passes,
......@@ -7904,7 +7922,7 @@ public class QuadCLT {
dbg_x,
dbg_y,
debugLevel);
num_extended = numLeftRemoved[0];
num_extended = numLeftRemoved[0]; //0,0
if (clt_parameters.show_expand || (clt_parameters.show_variant && (numLeftRemoved[1] > 1 ))) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"prepareExpandVariant-"+numLeftRemoved[1]+"-"+refine_pass); //String title)
......@@ -7971,7 +7989,7 @@ public class QuadCLT {
// num_extended = numLeftRemoved[0];
CLTMeasure( // perform single pass according to prepared tiles operations and disparity
CLTMeasure( // perform single pass according to prepared tiles operations and disparity BUG: gets with .disparity==null
image_data, // first index - number of image in a quad
saturation_imp, //final boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
......@@ -9055,9 +9073,30 @@ public class QuadCLT {
final int tilesY = tp.getTilesY();
CLTPass3d scan = tp.clt_3d_passes.get(scanIndex);
int [][] tile_op = scan.tile_op;
// Should not happen !
double [][] disparity_array = scan.disparity;
if (scan.disparity == null) {
System.out.println ("** BUG: should not happen - scan.disparity == null ! **");
System.out.println ("Trying to recover");
double [] backup_disparity = scan.getDisparity(0);
if (backup_disparity == null) {
System.out.println ("** BUG: no disparity at all !");
backup_disparity = new double[tilesX*tilesY];
}
scan.disparity = new double[tilesY][tilesX];
for (int ty = 0; ty < tilesY; ty++) {
for (int tx = 0; tx < tilesX; tx++) {
scan.disparity[ty][tx] = backup_disparity[ty*tilesX + tx];
if (Double.isNaN(scan.disparity[ty][tx])) {
scan.disparity[ty][tx] = 0;
tile_op[ty][tx] = 0;
}
}
}
disparity_array = scan.disparity;
}
double [][] disparity_array = scan.disparity;
// undecided, so 2 modes of combining alpha - same as rgb, or use center tile only
double [][][][] clt_corr_combo = new double [ImageDtt.TCORR_TITLES.length][tilesY][tilesX][]; // will only be used inside?
if (debugLevel > -1){
......
......@@ -84,6 +84,7 @@ public class TwoQuadCLT {
public QuadCLT quadCLT_main = null;
public QuadCLT quadCLT_aux = null;
public double [][] dsi = new double [DSI_SLICES.length][];
public double [][] dsi_aux_from_main; // Main camera DSI converted into the coordinates of the AUX one (see QuadCLT.FGBG_TITLES)-added two slises from aux ds
public TwoQuadCLT(
QuadCLT quadCLT_main,
......@@ -3525,6 +3526,179 @@ if (debugLevel > -100) return true; // temporarily !
}
}
public void outputMLDataLwir(
QuadCLT quadCLT_aux,
CLTParameters clt_parameters,
String ml_directory, // full path or null (will use config one)
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel) // throws Exception
{
if ((quadCLT_aux == null) || (quadCLT_aux.tp == null) || (this.dsi_aux_from_main == null)) {
String msg = "DSI data for AUX camera is not available. Please generateload it first";
IJ.showMessage("Error",msg);
System.out.println(msg);
return;
}
String img_name =quadCLT_main.image_name+"-ML_DATA-";
if (ml_directory == null) ml_directory= quadCLT_main.correctionsParameters.selectMlDirectory(
quadCLT_main.image_name,
true, // smart,
true); //newAllowed, // save
Correlation2d corr2d = new Correlation2d(
clt_parameters.img_dtt, // ImageDttParameters imgdtt_params,
clt_parameters.transform_size, // int transform_size,
2.0, // double wndx_scale, // (wndy scale is always 1.0)
quadCLT_aux.isMonochrome(), // boolean monochrome,
(debugLevel > -1)); // boolean debug)
if (clt_parameters.rig.ml_aux_ag) {
double [][] ml_data = remeasureAuxML(
quadCLT_aux, // QuadCLT quadCLT_aux,
this.dsi_aux_from_main[QuadCLT.FGBG_DISPARITY], // double [] disparity,
this.dsi_aux_from_main, // double [][] dsi_aux_from_main, // Main camera DSI converted into the coordinates of the AUX one (see QuadCLT.FGBG_TITLES)-
clt_parameters, // CLTParameters clt_parameters,
clt_parameters.rig.ml_hwidth, // int ml_hwidth,
clt_parameters.rig.ml_fatzero, // double fatzero,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
saveMlFile(
img_name, // String ml_title,
ml_directory, // String ml_directory,
Double.NaN, // double disp_offset_low,
0.0, // AG // double disp_offset_high,
null, // quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
corr2d, // Correlation2d corr2d, // to access "other" layer
clt_parameters.rig.ml_8bit, // boolean use8bpp, // true
clt_parameters.rig.ml_limit_extrim, // double limit_extrim, 1E-5
clt_parameters.rig.ml_keep_aux, // boolean keep_aux, false
clt_parameters.rig.ml_keep_inter, // boolean keep_inter, // false
clt_parameters.rig.ml_keep_hor_vert, // boolean keep_hor_vert, // true
clt_parameters.rig.ml_keep_tbrl, // boolean ml_keep_tbrl, // false
clt_parameters.rig.ml_keep_debug, // boolean keep_debug, // false
clt_parameters.rig.ml_fatzero, // double ml_fatzero, // 0.05
clt_parameters.rig.ml_hwidth, // int ml_hwidth, // 4
ml_data, // double [][] ml_data, //false
clt_parameters.rig.ml_show_ml, // boolean show,
debugLevel); // int debugLevel
}
if (clt_parameters.rig.ml_aux_fg) {
double [][] ml_data = remeasureAuxML(
quadCLT_aux, // QuadCLT quadCLT_aux,
this.dsi_aux_from_main[QuadCLT.FGBG_FG_DISP], // double [] disparity,
this.dsi_aux_from_main, // double [][] dsi_aux_from_main, // Main camera DSI converted into the coordinates of the AUX one (see QuadCLT.FGBG_TITLES)-
clt_parameters, // CLTParameters clt_parameters,
clt_parameters.rig.ml_hwidth, // int ml_hwidth,
clt_parameters.rig.ml_fatzero, // double fatzero,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
saveMlFile(
img_name, // String ml_title,
ml_directory, // String ml_directory,
Double.NaN, // double disp_offset_low,
1.0, // FG // double disp_offset_high,
null, // quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
corr2d, // Correlation2d corr2d, // to access "other" layer
clt_parameters.rig.ml_8bit, // boolean use8bpp, // true
clt_parameters.rig.ml_limit_extrim, // double limit_extrim, 1E-5
clt_parameters.rig.ml_keep_aux, // boolean keep_aux, false
clt_parameters.rig.ml_keep_inter, // boolean keep_inter, // false
clt_parameters.rig.ml_keep_hor_vert, // boolean keep_hor_vert, // true
clt_parameters.rig.ml_keep_tbrl, // boolean ml_keep_tbrl, // false
clt_parameters.rig.ml_keep_debug, // boolean keep_debug, // false
clt_parameters.rig.ml_fatzero, // double ml_fatzero, // 0.05
clt_parameters.rig.ml_hwidth, // int ml_hwidth, // 4
ml_data, // double [][] ml_data, //false
clt_parameters.rig.ml_show_ml, // boolean show,
debugLevel); // int debugLevel
}
if (clt_parameters.rig.ml_aux_bg) {
double [][] ml_data = remeasureAuxML(
quadCLT_aux, // QuadCLT quadCLT_aux,
this.dsi_aux_from_main[QuadCLT.FGBG_BG_DISP], // double [] disparity,
this.dsi_aux_from_main, // double [][] dsi_aux_from_main, // Main camera DSI converted into the coordinates of the AUX one (see QuadCLT.FGBG_TITLES)-
clt_parameters, // CLTParameters clt_parameters,
clt_parameters.rig.ml_hwidth, // int ml_hwidth,
clt_parameters.rig.ml_fatzero, // double fatzero,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
saveMlFile(
img_name, // String ml_title,
ml_directory, // String ml_directory,
Double.NaN, // double disp_offset_low,
-1.0, // BG // double disp_offset_high,
null, // quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
corr2d, // Correlation2d corr2d, // to access "other" layer
clt_parameters.rig.ml_8bit, // boolean use8bpp, // true
clt_parameters.rig.ml_limit_extrim, // double limit_extrim, 1E-5
clt_parameters.rig.ml_keep_aux, // boolean keep_aux, false
clt_parameters.rig.ml_keep_inter, // boolean keep_inter, // false
clt_parameters.rig.ml_keep_hor_vert, // boolean keep_hor_vert, // true
clt_parameters.rig.ml_keep_tbrl, // boolean ml_keep_tbrl, // false
clt_parameters.rig.ml_keep_debug, // boolean keep_debug, // false
clt_parameters.rig.ml_fatzero, // double ml_fatzero, // 0.05
clt_parameters.rig.ml_hwidth, // int ml_hwidth, // 4
ml_data, // double [][] ml_data, //false
clt_parameters.rig.ml_show_ml, // boolean show,
debugLevel); // int debugLevel
}
if (clt_parameters.rig.ml_aux_step > 0.0) {
double [] target_disparity = new double [this.dsi_aux_from_main[QuadCLT.FGBG_DISPARITY].length];
for (double disparity = clt_parameters.rig.ml_aux_low; disparity <= clt_parameters.rig.ml_aux_high; disparity += clt_parameters.rig.ml_aux_step) {
for (int nt = 0; nt < target_disparity.length; nt++) {
target_disparity[nt] = disparity;
}
double [][] ml_data = remeasureAuxML(
quadCLT_aux, // QuadCLT quadCLT_aux,
target_disparity, // double [] disparity,
this.dsi_aux_from_main, // double [][] dsi_aux_from_main, // Main camera DSI converted into the coordinates of the AUX one (see QuadCLT.FGBG_TITLES)-
clt_parameters, // CLTParameters clt_parameters,
clt_parameters.rig.ml_hwidth, // int ml_hwidth,
clt_parameters.rig.ml_fatzero, // double fatzero,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
saveMlFile(
img_name, // String ml_title,
ml_directory, // String ml_directory,
disparity, // absolute disparity // double disp_offset_low,
0.0, // not used // double disp_offset_high,
null, // -> aux_mode (LWIR), // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
corr2d, // Correlation2d corr2d, // to access "other" layer
clt_parameters.rig.ml_8bit, // boolean use8bpp, // true
clt_parameters.rig.ml_limit_extrim, // double limit_extrim, 1E-5
clt_parameters.rig.ml_keep_aux, // boolean keep_aux, false
clt_parameters.rig.ml_keep_inter, // boolean keep_inter, // false
clt_parameters.rig.ml_keep_hor_vert, // boolean keep_hor_vert, // true
clt_parameters.rig.ml_keep_tbrl, // boolean ml_keep_tbrl, // false
clt_parameters.rig.ml_keep_debug, // boolean keep_debug, // false
clt_parameters.rig.ml_fatzero, // double ml_fatzero, // 0.05
clt_parameters.rig.ml_hwidth, // int ml_hwidth, // 4
ml_data, // double [][] ml_data, //false
clt_parameters.rig.ml_show_ml, // boolean show,
debugLevel); // int debugLevel
}
}
Runtime.getRuntime().gc();
System.out.println("Generated ML data, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
}
public double [][] prepareRefineExistingDSI(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
......@@ -5870,9 +6044,16 @@ if (debugLevel > -100) return true; // temporarily !
public void saveMlFile(
String ml_title,
String ml_directory,
// new meanings in aux mode:
// disp_offset_low NaN:
// disp_offset_high = 0.0 use average GT disparity
// disp_offset_high > 0.0 use FG GT disparity
// disp_offset_high < 0.0 use BG GT disparity
// disp_offset_low != NaN: it is absolute disparity
double disp_offset_low, // NaN - Main camera is used
double disp_offset_high, // !NaN and isNaN(disp_offset_low) - random amplitude: positive - from main, negative - from rig
QuadCLT quadCLT_main,
QuadCLT quadCLT_main, // use null for aux mode
QuadCLT quadCLT_aux,
Correlation2d corr2d, // to access "other" layer
boolean use8bpp,
......@@ -5888,34 +6069,57 @@ if (debugLevel > -100) return true; // temporarily !
boolean show,
int debugLevel
) {
final int tilesX = quadCLT_main.tp.getTilesX();
final int tilesY = quadCLT_main.tp.getTilesY();
final boolean has_main = (quadCLT_main != null);
final boolean aux_mode = !has_main;
final int tilesX = (has_main) ? quadCLT_main.tp.getTilesX() : quadCLT_aux.tp.getTilesX();
final int tilesY = (has_main) ? quadCLT_main.tp.getTilesY() : quadCLT_aux.tp.getTilesY();
int ml_width = 2 * ml_hwidth + 1;
int width = tilesX * ml_width;
int height = tilesY * ml_width;
String title = ml_title+ (use8bpp?"08":"32")+"B-"+(keep_aux?"A":"")+(keep_inter?"I":"")+(keep_hor_vert?"O":"")+(ml_keep_tbrl?"T":"")+
(keep_debug?"D":"")+"-FZ"+ml_fatzero;
if (!Double.isNaN(disp_offset_low)) {
title += "-OFFS" + String.format("%8.5f",disp_offset_low).trim();
if (disp_offset_high > disp_offset_low) {
title+="_";
title+=String.format("%8.5f",disp_offset_high).trim();
if (aux_mode) {
if (!Double.isNaN(disp_offset_low)) {
title += "-D" + String.format("%08.5f",disp_offset_low).trim(); // absolute disparity
} else if (disp_offset_high > 0.0){ // foreground ground truth disparity
title += "-FG";
} else if (disp_offset_high < 0.0){ // background ground truth disparity
title += "-BG";
} else { // average ground truth disparity
title += "-AG";
}
} else {
// title += "-MAIN";
if (Double.isNaN(disp_offset_high)) {
title += "-MAIN";
if (!Double.isNaN(disp_offset_low)) {
title += "-OFFS" + String.format("%08.5f",disp_offset_low).trim();
if (disp_offset_high > disp_offset_low) {
title+="_";
title+=String.format("%08.5f",disp_offset_high).trim();
}
} else {
if (disp_offset_high > 0) {
title += "-MAIN_RND";
title+=String.format("%8.5f",disp_offset_high).trim();
if (Double.isNaN(disp_offset_high)) {
title += "-MAIN";
} else {
disp_offset_high = -disp_offset_high;
title+="-RIG_RND";
title+=String.format("%8.5f",disp_offset_high).trim();
if (disp_offset_high > 0) {
title += "-MAIN_RND";
title+=String.format("%08.5f",disp_offset_high).trim();
} else {
disp_offset_high = -disp_offset_high;
title+="-RIG_RND";
title+=String.format("%08.5f",disp_offset_high).trim();
}
}
}
}
int [] main_indices = {
ImageDtt.ML_TOP_INDEX, // 8 - top pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_BOTTOM_INDEX, // 9 - bottom pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_LEFT_INDEX, //10 - left pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_RIGHT_INDEX, //11 - right pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_DIAGM_INDEX, //12 - main diagonal (top-left to bottom-right) pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_DIAGO_INDEX, //13 - other diagonal (bottom-left to top-right) pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_HOR_INDEX, //14 - horizontal pairs combined 2d correlation center area (auxiliary camera)
ImageDtt.ML_VERT_INDEX //15 - vertical pairs combined 2d correlation center area (auxiliary camera)
};
int [] aux_indices = {
ImageDtt.ML_TOP_AUX_INDEX, // 8 - top pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_BOTTOM_AUX_INDEX, // 9 - bottom pair 2d correlation center area (auxiliary camera)
......@@ -5955,6 +6159,7 @@ if (debugLevel > -100) return true; // temporarily !
};
boolean [] skip_layers = new boolean [ImageDtt.ML_TITLES.length];
if (!has_main) for (int nl:main_indices) skip_layers[nl] = true;
if (!keep_aux) for (int nl:aux_indices) skip_layers[nl] = true;
if (!keep_inter) for (int nl:inter_indices) skip_layers[nl] = true;
if (!keep_hor_vert) for (int nl:hor_vert_indices) skip_layers[nl] = true;
......@@ -6018,6 +6223,19 @@ if (debugLevel > -100) return true; // temporarily !
}
}
// convert double data to byte, so v<=soft_mn -> 1; v>= soft_mx -> 255, NaN -> 0
int [] signed_data = {
ImageDtt.ML_OTHER_TARGET,
ImageDtt.ML_OTHER_GTRUTH,
ImageDtt.ML_OTHER_GTRUTH_FG_DISP,
ImageDtt.ML_OTHER_GTRUTH_BG_DISP,
ImageDtt.ML_OTHER_AUX_DISP};
int [] unsigned_data = {
ImageDtt.ML_OTHER_GTRUTH_STRENGTH,
ImageDtt.ML_OTHER_GTRUTH_RMS,
ImageDtt.ML_OTHER_GTRUTH_RMS_SPLIT,
ImageDtt.ML_OTHER_GTRUTH_FG_STR,
ImageDtt.ML_OTHER_GTRUTH_BG_STR,
ImageDtt.ML_OTHER_AUX_STR};
byte [][] iml_data = new byte [ml_data.length][];
for (int nl = 0; nl < ml_data.length; nl++) if (!skip_layers[nl]) {
iml_data[nl] = new byte [ml_data[nl].length];
......@@ -6025,7 +6243,7 @@ if (debugLevel > -100) return true; // temporarily !
// special treatment - make 2 bytes of one disparity value
for (int tileY = 0; tileY < tilesY; tileY++) {
for (int tileX = 0; tileX < tilesX; tileX++) {
// int nTile = tileY * tilesX + tileX;
/*
double target_disparity = corr2d.restoreMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
......@@ -6072,6 +6290,47 @@ if (debugLevel > -100) return true; // temporarily !
iml_data[nl][indx] = (byte) igtruth_strength[nb];
}
}
*/
for (int data:signed_data) if (aux_mode || (data <= ImageDtt.ML_OTHER_GTRUTH_STRENGTH)) {
double d = corr2d.restoreMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
data , // int ml_index,
tilesX); // int tilesX);
if (!Double.isNaN(d)) {
int id = (int) Math.round(128 * d) + 0x8000;
int [] ida = {id >> 8, id & 0xff};
for (int nb = 0; nb<2; nb++) {
int indx = corr2d.getMlTilePixelIndex(tileX,tileY, ml_hwidth, data + nb, tilesX);
iml_data[nl][indx] = (byte) ida[nb];
}
}
}
for (int data:unsigned_data) if (aux_mode || (data <= ImageDtt.ML_OTHER_GTRUTH_STRENGTH)) {
double d = corr2d.restoreMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
data , // int ml_index,
tilesX); // int tilesX);
if (!Double.isNaN(d) && (d > 0.0)) {
int iscale = 0x10000;
if ((data == ImageDtt.ML_OTHER_GTRUTH_RMS) || (data == ImageDtt.ML_OTHER_GTRUTH_RMS_SPLIT)) {
iscale = 0x1000;
}
int id = (int) Math.round(iscale * d);
int [] ida = {id >> 8, id & 0xff};
for (int nb = 0; nb<2; nb++) {
int indx = corr2d.getMlTilePixelIndex(tileX,tileY, ml_hwidth, data + nb, tilesX);
iml_data[nl][indx] = (byte) ida[nb];
}
}
}
}
}
} else {
......@@ -6100,26 +6359,40 @@ if (debugLevel > -100) return true; // temporarily !
}
}
double disparityRadiusMain = quadCLT_main.geometryCorrection.getDisparityRadius();
double disparityRadiusMain = has_main ? quadCLT_main.geometryCorrection.getDisparityRadius():Double.NaN;
double disparityRadiusAux = quadCLT_aux.geometryCorrection.getDisparityRadius();
double intercameraBaseline = quadCLT_aux.geometryCorrection.getBaseline();
double intercameraBaseline = has_main ? quadCLT_aux.geometryCorrection.getBaseline():Double.NaN;
ImagePlus imp_ml = new ImagePlus(title, array_stack);
imp_ml.setProperty("VERSION", "1.1");
imp_ml.setProperty("VERSION", "1.2");
imp_ml.setProperty("tileWidth", ""+ml_width);
imp_ml.setProperty("dispOffset", ""+disp_offset_low);
if (disp_offset_high>disp_offset_low) {
imp_ml.setProperty("dispOffsetLow", ""+disp_offset_low);
imp_ml.setProperty("dispOffsetHigh", ""+disp_offset_high);
}
imp_ml.setProperty("ML_OTHER_TARGET", ""+ImageDtt.ML_OTHER_TARGET);
imp_ml.setProperty("ML_OTHER_GTRUTH", ""+ImageDtt.ML_OTHER_GTRUTH);
imp_ml.setProperty("ML_OTHER_TARGET", ""+ImageDtt.ML_OTHER_TARGET);
imp_ml.setProperty("ML_OTHER_GTRUTH", ""+ImageDtt.ML_OTHER_GTRUTH);
imp_ml.setProperty("ML_OTHER_GTRUTH_STRENGTH", ""+ImageDtt.ML_OTHER_GTRUTH_STRENGTH);
imp_ml.setProperty("disparityRadiusMain", ""+disparityRadiusMain);
if (aux_mode) {
imp_ml.setProperty("ML_OTHER_GTRUTH_RMS", ImageDtt.ML_OTHER_GTRUTH_RMS);
imp_ml.setProperty("ML_OTHER_GTRUTH_RMS_SPLIT", ImageDtt.ML_OTHER_GTRUTH_RMS_SPLIT);
imp_ml.setProperty("ML_OTHER_GTRUTH_FG_DISP", ImageDtt.ML_OTHER_GTRUTH_FG_DISP);
imp_ml.setProperty("ML_OTHER_GTRUTH_FG_STR", ImageDtt.ML_OTHER_GTRUTH_FG_STR);
imp_ml.setProperty("ML_OTHER_GTRUTH_BG_DISP", ImageDtt.ML_OTHER_GTRUTH_BG_DISP);
imp_ml.setProperty("ML_OTHER_GTRUTH_BG_STR", ImageDtt.ML_OTHER_GTRUTH_BG_STR);
imp_ml.setProperty("ML_OTHER_AUX_DISP", ImageDtt.ML_OTHER_AUX_DISP);
imp_ml.setProperty("ML_OTHER_AUX_STR", ImageDtt.ML_OTHER_AUX_STR);
}
if (has_main) {
imp_ml.setProperty("disparityRadiusMain", ""+disparityRadiusMain);
imp_ml.setProperty("intercameraBaseline", ""+intercameraBaseline);
}
imp_ml.setProperty("disparityRadiusAux", ""+disparityRadiusAux);
imp_ml.setProperty("intercameraBaseline", ""+intercameraBaseline);
imp_ml.setProperty("data_min", ""+soft_mn);
imp_ml.setProperty("data_max", ""+soft_mx);
if (use8bpp) {
imp_ml.setProperty("data_min", ""+soft_mn);
imp_ml.setProperty("data_max", ""+soft_mx);
}
imp_ml.setProperty("comment_tileWidth", "Square tile size for each 2d correlation, always odd");
imp_ml.setProperty("comment_dispOffset", "Tile target disparity minus ground truth disparity");
......@@ -6130,12 +6403,24 @@ if (debugLevel > -100) return true; // temporarily !
imp_ml.setProperty("comment_ML_OTHER_TARGET", "Offset of the target disparity in the \"other\" layer tile");
imp_ml.setProperty("comment_ML_OTHER_GTRUTH", "Offset of the ground truth disparity in the \"other\" layer tile");
imp_ml.setProperty("comment_ML_OTHER_GTRUTH_STRENGTH", "Offset of the ground truth strength in the \"other\" layer tile");
imp_ml.setProperty("comment_data_min", "Defined only for 8bpp mode - value, corresponding to -127 (-128 is NaN)");
imp_ml.setProperty("comment_data_max", "Defined only for 8bpp mode - value, corresponding to +127 (-128 is NaN)");
imp_ml.setProperty("comment_disparityRadiusMain", "Side of the square where 4 main camera subcameras are located (mm)");
if (aux_mode) {
imp_ml.setProperty("comment_ML_OTHER_GTRUTH_RMS","Offset of the GT disparity RMS");
imp_ml.setProperty("comment_ML_OTHER_GTRUTH_RMS_SPLIT", "Offset of the GT disparity RMS combined from FG and BG");
imp_ml.setProperty("comment_ML_OTHER_GTRUTH_FG_DISP", "Offset of the GT FG disparity");
imp_ml.setProperty("comment_ML_OTHER_GTRUTH_FG_STR", "Offset of the GT FG strength");
imp_ml.setProperty("comment_ML_OTHER_GTRUTH_BG_DISP", "Offset of the GT BG disparity");
imp_ml.setProperty("comment_ML_OTHER_GTRUTH_BG_STR", "Offset of the GT BG strength");
}
if (use8bpp) {
imp_ml.setProperty("comment_data_min", "Defined only for 8bpp mode - value, corresponding to -127 (-128 is NaN)");
imp_ml.setProperty("comment_data_max", "Defined only for 8bpp mode - value, corresponding to +127 (-128 is NaN)");
}
if (has_main) {
imp_ml.setProperty("comment_disparityRadiusMain", "Side of the square where 4 main camera subcameras are located (mm)");
imp_ml.setProperty("comment_intercameraBaseline", "Horizontal distance between the main and the auxiliary camera centers (mm). Disparity is specified for the main camera");
}
imp_ml.setProperty("comment_disparityRadiusAux", "Side of the square where 4 main camera subcameras are located (mm). Disparity is specified for the main camera");
imp_ml.setProperty("comment_intercameraBaseline", "Horizontal distance between the main and the auxiliary camera centers (mm). Disparity is specified for the main camera");
(new JP46_Reader_camera(false)).encodeProperiesToInfo(imp_ml);
imp_ml.getProcessor().resetMinAndMax();
if (show ) {
......@@ -6981,6 +7266,8 @@ if (debugLevel > -100) return true; // temporarily !
return disparity_bimap;
}
public double [][] remeasureRigML(
double disparity_offset_low,
double disparity_offset_high,
......@@ -7011,9 +7298,6 @@ if (debugLevel > -100) return true; // temporarily !
int [][] tile_op = new int[tilesY][tilesX]; // common for both main and aux
double [][] disparity_array = new double[tilesY][tilesX];
// double [] disparity = src_bimap[ImageDtt.BI_TARGET_INDEX];
// double [] strength = src_bimap[ImageDtt.BI_STR_CROSS_INDEX];
boolean [] selection = new boolean [strength.length];
if (disparity_main != null) {
for (int nTile = 0; nTile < selection.length; nTile++) {
......@@ -7042,7 +7326,6 @@ if (debugLevel > -100) return true; // temporarily !
(debugLevel > -1)); // boolean debug)
for (int nTile = 0; nTile < disparity.length; nTile++) {
// if (((selection == null) || (selection[nTile]) && !Double.isNaN(disparity[nTile]))) {
if ((selection == null) || selection[nTile]) {
int tileY = nTile / tilesX;
int tileX = nTile % tilesX;
......@@ -7096,6 +7379,213 @@ if (debugLevel > -100) return true; // temporarily !
return ml_data;
}
double [][] measureAux(
// QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
int [][] tile_op, // common for both amin and aux
double [][] disparity_array,
double [][] ml_data, // data for ML - 10 layers - 4 center areas (3x3, 5x5,..) per camera-per direction, 1 - composite, and 1 with just 1 data (target disparity)
CLTParameters clt_parameters,
double fatzero,
boolean notch_mode, // use pole-detection mode for inter-camera correlation
int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using (2*notch_mode+1)^2 square
boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
ImageDtt image_dtt = new ImageDtt(quadCLT_aux.isMonochrome(),clt_parameters.getScaleStrength(true));
double [][] disparity_bimap = new double [ImageDtt.BIDISPARITY_TITLES.length][]; //[0] -residual disparity, [1] - orthogonal (just for debugging) last 4 - max pixel differences
image_dtt.clt_bi_quad (
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
fatzero, // final double fatzero, // May use correlation fat zero from 2 different parameters - fat_zero and rig.ml_fatzero
notch_mode, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
lt_rad, // final int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
no_int_x0, // final boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
tile_op, // final int [][] tile_op_main, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
disparity_array, // final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
null, // quadCLT_main.image_data, // final double [][][] image_data_main, // first index - number of image in a quad
quadCLT_aux.image_data, // final double [][][] image_data_aux, // first index - number of image in a quad
null, // quadCLT_main.saturation_imp, // final boolean [][] saturation_main, // (near) saturated pixels or null
quadCLT_aux.saturation_imp, // final boolean [][] saturation_aux, // (near) saturated pixels or null
// correlation results - combo will be for the correation between two quad cameras
null, // final double [][][][] clt_corr_combo, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
disparity_bimap, // final double [][] disparity_bimap, // [23][tilesY][tilesX]
ml_data, // final double [][] ml_data, // data for ML - 10 layers - 4 center areas (3x3, 5x5,..) per camera-per direction, 1 - composite, and 1 with just 1 data (target disparity)
null, // final double [][][][] texture_tiles_main, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
null, // final double [][][][] texture_tiles_aux, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
// quadCLT_main.tp.getTilesX()*clt_parameters.transform_size, // final int width,
quadCLT_aux.tp.getTilesX()*clt_parameters.transform_size, // final int width,
null, // quadCLT_main.getGeometryCorrection(), // final GeometryCorrection geometryCorrection_main,
quadCLT_aux.getGeometryCorrection(), // final GeometryCorrection geometryCorrection_aux,
null, // quadCLT_main.getCLTKernels(), // final double [][][][][][] clt_kernels_main, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
quadCLT_aux.getCLTKernels(), // final double [][][][][][] clt_kernels_aux, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
clt_parameters.corr_magic_scale, // final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
false, // true, // final boolean keep_clt_data,
null, // final double [][][] ers_delay, // if not null - fill with tile center acquisition delay
threadsMax, // final int threadsMax, // maximal number of threads to launch
debugLevel-2); // final int globalDebugLevel);
return disparity_bimap;
}
public double [][] remeasureAuxML(
QuadCLT quadCLT_aux,
double [] disparity, // Double.NaN - do not measure
double [][] dsi_aux_from_main, // Main camera DSI converted into the coordinates of the AUX one (see QuadCLT.FGBG_TITLES)-
CLTParameters clt_parameters,
int ml_hwidth,
double fatzero,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
int tile_op_all = clt_parameters.tile_task_op; //FIXME Use some constant?
final int tilesX = quadCLT_aux.tp.getTilesX();
final int tilesY = quadCLT_aux.tp.getTilesY();
// int ml_hwidth = 2;
int ml_width = 2 * ml_hwidth + 1;
double [][] ml_data = new double [ImageDtt.ML_TITLES.length][tilesX * tilesY * ml_width * ml_width];
for (int nLayer=0; nLayer < ml_data.length; nLayer++) {
for (int nTile=0; nTile < ml_data[nLayer].length; nTile++) {
ml_data[nLayer][nTile] = Double.NaN;
}
}
int [][] tile_op = new int[tilesY][tilesX]; // common for both main and aux
double [][] disparity_array = new double[tilesY][tilesX];
Correlation2d corr2d = new Correlation2d(
clt_parameters.img_dtt, // ImageDttParameters imgdtt_params,
clt_parameters.transform_size, // int transform_size,
2.0, // double wndx_scale, // (wndy scale is always 1.0)
quadCLT_aux.isMonochrome(),
(debugLevel > -1)); // boolean debug)
for (int nTile = 0; nTile < disparity.length; nTile++) if (!Double.isNaN(disparity[nTile])) {
int tileY = nTile / tilesX;
int tileX = nTile % tilesX;
tile_op[tileY][tileX] = tile_op_all;
disparity_array[tileY][tileX] = disparity[nTile];
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
ImageDtt.ML_OTHER_GTRUTH , // int ml_index,
dsi_aux_from_main[QuadCLT.FGBG_DISPARITY][nTile], // double ml_value,
tilesX); // int tilesX);
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
ImageDtt.ML_OTHER_GTRUTH_STRENGTH, // int ml_index,
dsi_aux_from_main[QuadCLT.FGBG_STRENGTH][nTile], // double ml_value,
tilesX); // int tilesX);
if (dsi_aux_from_main.length < (QuadCLT.FGBG_RMS -1)) continue;
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
ImageDtt.ML_OTHER_GTRUTH_RMS, // int ml_index,
dsi_aux_from_main[QuadCLT.FGBG_RMS][nTile], // double ml_value,
tilesX); // int tilesX);
if (dsi_aux_from_main.length < (QuadCLT.FGBG_RMS_SPLIT -1)) continue;
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
ImageDtt.ML_OTHER_GTRUTH_RMS_SPLIT, // int ml_index,
dsi_aux_from_main[QuadCLT.FGBG_RMS_SPLIT][nTile], // double ml_value,
tilesX); // int tilesX);
if (dsi_aux_from_main.length < (QuadCLT.FGBG_FG_DISP -1)) continue;
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
ImageDtt.ML_OTHER_GTRUTH_FG_DISP, // int ml_index,
dsi_aux_from_main[QuadCLT.FGBG_FG_DISP][nTile], // double ml_value,
tilesX); // int tilesX);
if (dsi_aux_from_main.length < (QuadCLT.FGBG_FG_STR -1)) continue;
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
ImageDtt.ML_OTHER_GTRUTH_FG_STR, // int ml_index,
dsi_aux_from_main[QuadCLT.FGBG_FG_STR][nTile], // double ml_value,
tilesX); // int tilesX);
if (dsi_aux_from_main.length < (QuadCLT.FGBG_BG_DISP -1)) continue;
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
ImageDtt.ML_OTHER_GTRUTH_BG_DISP, // int ml_index,
dsi_aux_from_main[QuadCLT.FGBG_BG_DISP][nTile], // double ml_value,
tilesX); // int tilesX);
if (dsi_aux_from_main.length < (QuadCLT.FGBG_BG_STR -1)) continue;
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
ImageDtt.ML_OTHER_GTRUTH_BG_STR, // int ml_index,
dsi_aux_from_main[QuadCLT.FGBG_BG_STR][nTile], // double ml_value,
tilesX); // int tilesX);
if (dsi_aux_from_main.length < (QuadCLT.FGBG_AUX_DISP -1)) continue;
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
ImageDtt.ML_OTHER_AUX_DISP, // int ml_index,
dsi_aux_from_main[QuadCLT.FGBG_AUX_DISP][nTile], // double ml_value,
tilesX); // int tilesX);
if (dsi_aux_from_main.length < (QuadCLT.FGBG_AUX_STR -1)) continue;
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
ImageDtt.ML_OTHER_AUX_STR, // int ml_index,
dsi_aux_from_main[QuadCLT.FGBG_AUX_STR][nTile], // double ml_value,
tilesX); // int tilesX);
}
measureAux(
quadCLT_aux, // QuadCLT quadCLT_aux,
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
ml_data, // double [][] ml_data, // data for ML - 10 layers - 4 center areas (3x3, 5x5,..) per camera-per direction, 1 - composite, and 1 with just 1 data (target disparity)
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
fatzero, // double fatzero,
false, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
0, // lt_rad, // final int // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
true, // whatever here. final boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very
threadsMax, // maximal number of threads to launch // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
return ml_data;
}
ArrayList<Integer> selectRigTiles(
CLTParameters clt_parameters,
boolean select_infinity,
......@@ -7768,7 +8258,8 @@ if (debugLevel > -100) return true; // temporarily !
// final boolean batch_mode = clt_parameters.batch_run;
// Reset dsi data (only 2 slices will be used)
this.dsi = new double [DSI_SLICES.length][];
quadCLT_aux.ds_from_main = null;
this.dsi_aux_from_main = null; // full data, including rms, fg and bg data
quadCLT_aux.ds_from_main = null; // this is for adjust6ment only (short)
final int debugLevelInner=clt_parameters.batch_run? -2: debugLevel;
this.startTime=System.nanoTime();
......@@ -7971,6 +8462,13 @@ if (debugLevel > -100) return true; // temporarily !
debugLevelInner); // final int debugLevel)
if (!ok) continue;
}
// save assigned disparity also? - with "-DSI_COMBO" suffix
if (quadCLT_main.correctionsParameters.clt_batch_dsi) {
saveDSI (
//clt_parameters
);
}
}
}
} else { // if (quadCLT_main.correctionsParameters.clt_batch_explore) {
......@@ -7986,7 +8484,7 @@ if (debugLevel > -100) return true; // temporarily !
// 2) Prepare full D/S and FG/BG data to be embedded within the ML files
double [][] main_ds = {dsi[DSI_DISPARITY_MAIN], dsi[DSI_STRENGTH_MAIN]};
quadCLT_aux.ds_from_main = quadCLT_aux.depthMapMainToAux(
quadCLT_aux.ds_from_main = quadCLT_aux.depthMapMainToAux( // only 2 layers for adjustments
main_ds, // double [][] ds,
quadCLT_main.getGeometryCorrection(), // GeometryCorrection geometryCorrection_main,
quadCLT_aux.getGeometryCorrection(), // GeometryCorrection geometryCorrection_aux,
......@@ -7995,7 +8493,7 @@ if (debugLevel > -100) return true; // temporarily !
true, // for_adjust,
debugLevel); // DEBUG_LEVEL); // int debug_level
double [][] ds_aux_ml = quadCLT_aux.depthMapMainToAux(
this.dsi_aux_from_main = quadCLT_aux.depthMapMainToAux( // 8 layers for ML generation/exporting + 2 zero layers
main_ds, // double [][] ds,
quadCLT_main.getGeometryCorrection(), // GeometryCorrection geometryCorrection_main,
quadCLT_aux.getGeometryCorrection(), // GeometryCorrection geometryCorrection_aux,
......@@ -8065,7 +8563,7 @@ if (debugLevel > -100) return true; // temporarily !
if (!ok) break;
}
// Generate 4 AUX camera images and thumbnail
if (quadCLT_main.correctionsParameters.clt_batch_4img){
if (quadCLT_main.correctionsParameters.clt_batch_4img_aux){
if (updateStatus) IJ.showStatus("Rendering 4 AUX image set (disparity = 0) for "+quadCLT_aux.image_name);
quadCLT_aux.processCLTQuadCorr( // returns ImagePlus, but it already should be saved/shown
......@@ -8085,10 +8583,52 @@ if (debugLevel > -100) return true; // temporarily !
quadCLT_aux.tp.resetCLTPasses();
}
// Currently - no LWIR 3D model generation, maybe it will be added later
// Generate AUX DS
if (quadCLT_main.correctionsParameters.clt_batch_dsi_aux) {
if (updateStatus) IJ.showStatus("Building basic DSI for the aux camera image set "+quadCLT_main.image_name+" (for DSI export)");
quadCLT_aux.preExpandCLTQuad3d( // returns ImagePlus, but it already should be saved/shown
imp_srcs_aux, // [srcChannel], // should have properties "name"(base for saving results), "channel","path"
saturation_imp_aux, // boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
debayerParameters,
colorProcParameters_aux,
rgbParameters,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevelInner);
if (updateStatus) IJ.showStatus("Expanding DSI for the aux camera image set "+quadCLT_main.image_name+" (for DSI export)");
quadCLT_aux.expandCLTQuad3d( // returns ImagePlus, but it already should be saved/shown
clt_parameters,
debayerParameters,
colorProcParameters_aux,
channelGainParameters,
rgbParameters,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
double [][] aux_last_scan = quadCLT_aux.tp.getShowDS(
quadCLT_aux.tp.clt_3d_passes.get( quadCLT_aux.tp.clt_3d_passes.size() -1),
false); // boolean force_final);
// TODO: Add new ML generation here
// dsi[DSI_DISPARITY_AUX] = aux_last_scan[0]; // incompatible dimensions
// dsi[DSI_STRENGTH_AUX] = aux_last_scan[1]; // incompatible dimensions
dsi_aux_from_main[QuadCLT.FGBG_AUX_DISP] = aux_last_scan[0];
dsi_aux_from_main[QuadCLT.FGBG_AUX_STR] = aux_last_scan[1];
saveDSIGTAux(); // GT from main and AUX DS
quadCLT_aux.tp.resetCLTPasses();
}
//
// TODO: Add new ML generation here
if (quadCLT_main.correctionsParameters.clt_batch_genMl) { // rig.ml_generate) { //clt_batch_genMl
outputMLDataLwir(
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
null, //String ml_directory, // full path or null (will use config one)
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
}
if (quadCLT_main.correctionsParameters.clt_batch_save_extrinsics) {
saveProperties(
......@@ -8102,6 +8642,7 @@ if (debugLevel > -100) return true; // temporarily !
properties, // Properties properties, // if null - will only save extrinsics)
debugLevel);
}
Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+set_channels_aux.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
......@@ -8143,7 +8684,6 @@ if (debugLevel > -100) return true; // temporarily !
}
public void saveDSIMain(
// CLTParameters clt_parameters
)
{
String x3d_path= quadCLT_main.correctionsParameters.selectX3dDirectory( // for x3d and obj
......@@ -8164,6 +8704,33 @@ if (debugLevel > -100) return true; // temporarily !
0); // int jpegQuality)
}
// Save GT from main and AUX calculated DS
public void saveDSIGTAux()
{
String x3d_path= quadCLT_main.correctionsParameters.selectX3dDirectory( // for x3d and obj
quadCLT_main.correctionsParameters.getModelName(quadCLT_main.image_name), // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
quadCLT_main.correctionsParameters.x3dModelVersion,
true, // smart,
true); //newAllowed, // save
String title = quadCLT_aux.image_name+"-DSI_GT-AUX";
// String [] titles = {DSI_SLICES[DSI_DISPARITY_MAIN], DSI_SLICES[DSI_STRENGTH_MAIN]};
// double [][] dsi_main = {dsi[DSI_DISPARITY_MAIN], dsi[DSI_STRENGTH_MAIN]};
ImagePlus imp = (new ShowDoubleFloatArrays()).makeArrays(
this.dsi_aux_from_main, // dsi_main,
quadCLT_aux.tp.getTilesX(),
quadCLT_aux.tp.getTilesY(),
title,
QuadCLT.FGBG_TITLES_AUX); // titles);
quadCLT_main.eyesisCorrections.saveAndShow(
imp, // ImagePlus imp,
x3d_path, // String path,
false, // boolean png,
false, // boolean show,
0); // int jpegQuality)
}
public int restoreDSI(String suffix){ // "-DSI_COMBO", "-DSI_MAIN" (DSI_COMBO_SUFFIX, DSI_MAIN_SUFFIX)
String x3d_path= quadCLT_main.correctionsParameters.selectX3dDirectory( // for x3d and obj
quadCLT_main.correctionsParameters.getModelName(quadCLT_main.image_name), // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
......
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