Commit 26cdc535 authored by Andrey Filippov's avatar Andrey Filippov

Implementing batch mode for EO/LWIR images

parent be9da419
......@@ -181,7 +181,15 @@ public class CLTParameters {
public int ly_par_sel = 0; // Manually select the parameter mask bit 0 - sym0, bit1 - sym1, ... (0 - use checkbox selections above)
public boolean ly_right_left= false; // equalize weights of right/left FoV (use with horizon in both halves and gross infinity correction)
public double ly_inf_frac = 0.5; // Relative weight of infinity calibration data
public int ly_per_quad = 10; // minimal tiles per quadrant (not counting the worst) tp proceed
public double ly_per_quad_r = 0.01; // minimal relative tiles per quadrant (not counting the worst) tp proceed
public int ly_inf = 10; // minimal number of tiles at infinity to proceed
public double ly_inf_r = 0.01; // minimal relative number of tiles at infinity to proceed
public int ly_inf_scale = 20; // minimal number of tiles at infinity to apply weight scaling
public double ly_inf_scale_r = 0.02; // minimal relative number of tiles at infinity to apply weight scaling
public double ly_inf_frac = 0.7; // Relative weight of infinity calibration data
public double ly_inf_max_disparity = 0.2; // Maximal disparity to be treated as infinity when adjusting with rig data
public boolean ly_inf_disp= false; // Correct disparity for infinity tiles
public boolean ly_inf_force= false; // Force convergence correction during extrinsic, even with no infinity data
......@@ -191,8 +199,14 @@ public class CLTParameters {
public int ly_smpl_num = 5; // Number after removing worst (should be >1)
// public double ly_meas_disp = 1.5; // Maximal measured relative disparity - using (0.8*disp_scan_step)
public double ly_smpl_rms = 0.2; // 1; // Maximal RMS of the remaining tiles in a sample
public double ly_disp_var = 0.5; // 2; // Maximal full disparity difference to 8 neighbors
public double ly_disp_rvar = 0.02; // Maximal relative full disparity difference to 8 neighbors
public double ly_disp_var = 0.1; // Maximal full disparity difference to 8 neighbors
public double ly_disp_rvar = 0.01; // Maximal relative full disparity difference to 8 neighbors
public double ly_disp_var_gt = 0.5; // Maximal full disparity difference to 8 neighbors when GT is available
public double ly_disp_rvar_gt = 0.05; // Maximal relative full disparity difference to 8 neighbors when GT is available
public double ly_norm_disp = 5.0; // Reduce weight of higher disparity tiles
// Lazy eye multi-step fitting
......@@ -796,6 +810,15 @@ public class CLTParameters {
return aux ? lym_change_aux : lym_change;
}
public int getLyPerQuad (int num_tiles) {
return (int) Math.max(ly_per_quad_r * num_tiles , ly_per_quad );
}
public int getLyInf (int num_tiles) {
return (int) Math.max(ly_inf_r * num_tiles , ly_inf );
}
public int getLyInfScale (int num_tiles) {
return (int) Math.max(ly_inf_scale_r * num_tiles , ly_inf_scale );
}
public CLTParameters(){}
public void setProperties(String prefix,Properties properties){
......@@ -945,6 +968,13 @@ public class CLTParameters {
properties.setProperty(prefix+"ly_par_sel", this.ly_par_sel+"");
properties.setProperty(prefix+"ly_right_left", this.ly_right_left+"");
properties.setProperty(prefix+"ly_per_quad", this.ly_per_quad +"");
properties.setProperty(prefix+"ly_per_quad_r", this.ly_per_quad_r +"");
properties.setProperty(prefix+"ly_inf", this.ly_inf +"");
properties.setProperty(prefix+"ly_inf_r", this.ly_inf_r +"");
properties.setProperty(prefix+"ly_inf_scale", this.ly_inf_scale +"");
properties.setProperty(prefix+"ly_inf_scale_r", this.ly_inf_scale_r +"");
properties.setProperty(prefix+"ly_inf_frac", this.ly_inf_frac +"");
properties.setProperty(prefix+"ly_inf_max_disparity", this.ly_inf_max_disparity +"");
......@@ -957,6 +987,8 @@ public class CLTParameters {
properties.setProperty(prefix+"ly_smpl_rms", this.ly_smpl_rms +"");
properties.setProperty(prefix+"ly_disp_var", this.ly_disp_var +"");
properties.setProperty(prefix+"ly_disp_rvar", this.ly_disp_rvar +"");
properties.setProperty(prefix+"ly_disp_var_gt", this.ly_disp_var_gt +"");
properties.setProperty(prefix+"ly_disp_rvar_gt", this.ly_disp_rvar_gt +"");
properties.setProperty(prefix+"ly_norm_disp", this.ly_norm_disp +"");
properties.setProperty(prefix+"lym_overexp", this.lym_overexp +"");
properties.setProperty(prefix+"lym_update_disp", this.lym_update_disp+"");
......@@ -1653,6 +1685,13 @@ public class CLTParameters {
if (properties.getProperty(prefix+"ly_par_sel")!=null) this.ly_par_sel=Integer.parseInt(properties.getProperty(prefix+"ly_par_sel"));
if (properties.getProperty(prefix+"ly_right_left")!=null) this.ly_right_left=Boolean.parseBoolean(properties.getProperty(prefix+"ly_right_left"));
if (properties.getProperty(prefix+"ly_per_quad")!=null) this.ly_per_quad=Integer.parseInt(properties.getProperty(prefix+"ly_per_quad"));
if (properties.getProperty(prefix+"ly_per_quad_r")!=null) this.ly_per_quad_r=Double.parseDouble(properties.getProperty(prefix+"ly_per_quad_r"));
if (properties.getProperty(prefix+"ly_inf")!=null) this.ly_inf=Integer.parseInt(properties.getProperty(prefix+"ly_inf"));
if (properties.getProperty(prefix+"ly_inf_r")!=null) this.ly_inf_r=Double.parseDouble(properties.getProperty(prefix+"ly_inf_r"));
if (properties.getProperty(prefix+"ly_inf_scale")!=null) this.ly_inf_scale=Integer.parseInt(properties.getProperty(prefix+"ly_inf_scale"));
if (properties.getProperty(prefix+"ly_inf_scale_r")!=null) this.ly_inf_scale_r=Double.parseDouble(properties.getProperty(prefix+"ly_inf_scale_r"));
if (properties.getProperty(prefix+"ly_inf_frac")!=null) this.ly_inf_frac=Double.parseDouble(properties.getProperty(prefix+"ly_inf_frac"));
if (properties.getProperty(prefix+"ly_inf_max_disparity")!=null) this.ly_inf_max_disparity=Double.parseDouble(properties.getProperty(prefix+"ly_inf_max_disparity"));
......@@ -1668,6 +1707,8 @@ public class CLTParameters {
if (properties.getProperty(prefix+"ly_smpl_rms")!=null) this.ly_smpl_rms=Double.parseDouble(properties.getProperty(prefix+"ly_smpl_rms"));
if (properties.getProperty(prefix+"ly_disp_var")!=null) this.ly_disp_var=Double.parseDouble(properties.getProperty(prefix+"ly_disp_var"));
if (properties.getProperty(prefix+"ly_disp_rvar")!=null) this.ly_disp_rvar=Double.parseDouble(properties.getProperty(prefix+"ly_disp_rvar"));
if (properties.getProperty(prefix+"ly_disp_var_gt")!=null) this.ly_disp_var_gt=Double.parseDouble(properties.getProperty(prefix+"ly_disp_var_gt"));
if (properties.getProperty(prefix+"ly_disp_rvar_gt")!=null) this.ly_disp_rvar_gt=Double.parseDouble(properties.getProperty(prefix+"ly_disp_rvar_gt"));
if (properties.getProperty(prefix+"ly_norm_disp")!=null) this.ly_norm_disp=Double.parseDouble(properties.getProperty(prefix+"ly_norm_disp"));
if (properties.getProperty(prefix+"lym_overexp")!=null) this.lym_overexp=Double.parseDouble(properties.getProperty(prefix+"lym_overexp"));
if (properties.getProperty(prefix+"lym_update_disp")!=null) this.lym_update_disp=Boolean.parseBoolean(properties.getProperty(prefix+"lym_update_disp"));
......@@ -2227,6 +2268,8 @@ public class CLTParameters {
// GenericDialog gd = new GenericDialog("Set CLT parameters");
GenericJTabbedDialog gd = new GenericJTabbedDialog("Set CLT parameters",800,900);
gd.addTab ("General", "General parameters");
gd.addNumericField("Nominal (rectilinear) disparity between side of square cameras (pix)", this.disparity, 3,7,"pix",
"Used when rendering 4 images");
gd.addNumericField("Transform size (default 8)", this.transform_size, 0, 6, "pixels","Should always be 8");
gd.addNumericField("Lapped transform window type (0- rectangular, 1 - sinus)", this.clt_window, 0);
gd.addNumericField("shift_x", this.shift_x, 4);
......@@ -2261,8 +2304,6 @@ public class CLTParameters {
gd.addNumericField("Value (max) in vignetting data to correspond to 1x in the kernel", this.vignetting_max, 3);
gd.addNumericField("Do not try to correct vignetting smaller than this fraction of max", this.vignetting_range, 3);
gd.addNumericField("Kernel step in pixels (has 1 kernel margin on each side)", this.kernel_step, 0);
gd.addNumericField("Nominal (rectilinear) disparity between side of square cameras (pix)", this.disparity, 3,7,"pix",
"Used when rendering 4 images");
gd.addNumericField("Inverse distance to infinity (misalignment correction)", this.z_correction, 6);
gd.addCheckbox ("Perform correlation", this.correlate);
gd.addNumericField("Bitmask of pairs to combine in the composite (top, bottom, left,righth)", this.corr_mask, 0);
......@@ -2406,6 +2447,14 @@ public class CLTParameters {
gd.addCheckbox ("Equalize weights of right/left FoV", this.ly_right_left,
"Use this mode use with horizon visible in both FoV halves when gross infinity correction is needed");
gd.addNumericField("Minimal tiles per quadrant (not counting the worst) tp proceed", this.ly_per_quad, 0);
gd.addNumericField("Minimal tiles per quadrant (not counting the worst) tp proceed - fraction of all tiles", this.ly_per_quad_r, 3);
gd.addNumericField("Minimal number of tiles at infinity to proceed", this.ly_inf, 0);
gd.addNumericField("Minimal number of tiles at infinity to proceed - fraction of all tiles", this.ly_inf_r, 3);
gd.addNumericField("Minimal number of tiles at infinity to apply weight scaling", this.ly_inf_scale, 0);
gd.addNumericField("Minimal number of tiles at infinity to apply weight scaling - fraction of all tiles", this.ly_inf_scale_r, 3);
gd.addNumericField("Relative weight of infinity calibration data", this.ly_inf_frac, 3);
gd.addNumericField("Maximal disparity to be treated as infinity when adjusting with the rig data", this.ly_inf_max_disparity, 8,3,"pix",
......@@ -2425,6 +2474,10 @@ public class CLTParameters {
"Full allowed mismatch is a sum of absolute and disparity times relative");
gd.addNumericField("Maximal relative full disparity difference to 8 neighbors", this.ly_disp_rvar, 8,5,"",
"Full allowed mismatch is a sum of absolute and disparity times relative");
gd.addNumericField("Maximal full disparity difference to 8 neighbors with GT", this.ly_disp_var_gt, 8,5,"pix",
"Full allowed mismatch is a sum of absolute and disparity times relative (relaxed when ground truth is available)");
gd.addNumericField("Maximal relative full disparity difference to 8 neighbors with GT", this.ly_disp_rvar_gt, 8,5,"",
"Full allowed mismatch is a sum of absolute and disparity times relative (relaxed when ground truth is available)");
gd.addNumericField("Reduce weight of higher disparity tiles", this.ly_norm_disp, 5);
gd.addMessage ("--- Lazy eye multi-step fitting ---");
gd.addNumericField("Any (near) saturated pixels - discard tile (see sat_level also)", this.lym_overexp, 10);
......@@ -3067,6 +3120,7 @@ public class CLTParameters {
gd.showDialog();
*/
if (gd.wasCanceled()) return false;
this.disparity= gd.getNextNumber();
this.transform_size= (int) gd.getNextNumber();
this.clt_window= (int) gd.getNextNumber();
this.shift_x = gd.getNextNumber();
......@@ -3099,7 +3153,6 @@ public class CLTParameters {
this.vignetting_max= gd.getNextNumber();
this.vignetting_range= gd.getNextNumber();
this.kernel_step= (int) gd.getNextNumber();
this.disparity= gd.getNextNumber();
this.z_correction= gd.getNextNumber();
this.correlate= gd.getNextBoolean();
this.corr_mask= (int) gd.getNextNumber();
......@@ -3216,6 +3269,14 @@ public class CLTParameters {
this.ly_par_sel= (int) gd.getNextNumber();
this.ly_right_left= gd.getNextBoolean();
this.ly_per_quad= (int) gd.getNextNumber();
this.ly_per_quad_r= gd.getNextNumber();
this.ly_inf= (int) gd.getNextNumber();
this.ly_inf_r= gd.getNextNumber();
this.ly_inf_scale= (int) gd.getNextNumber();
this.ly_inf_scale_r= gd.getNextNumber();
this.ly_inf_frac= gd.getNextNumber();
this.ly_inf_max_disparity= gd.getNextNumber();
......@@ -3228,6 +3289,8 @@ public class CLTParameters {
this.ly_smpl_rms= gd.getNextNumber();
this.ly_disp_var= gd.getNextNumber();
this.ly_disp_rvar= gd.getNextNumber();
this.ly_disp_var_gt= gd.getNextNumber();
this.ly_disp_rvar_gt= gd.getNextNumber();
this.ly_norm_disp= gd.getNextNumber();
this.lym_overexp= gd.getNextNumber();
this.lym_update_disp= gd.getNextBoolean();
......
......@@ -169,6 +169,7 @@ public class EyesisCorrectionParameters {
public String mlDirectory="ml";
public boolean thumb_overwrite = true;
public int thumb_width = 200;
public int thumb_height = 100;
public double thumb_h_center = 0.5;
......@@ -296,6 +297,17 @@ public class EyesisCorrectionParameters {
cp.clt_batch_dsi_aux= this.clt_batch_dsi_aux;
cp.clt_batch_save_extrinsics= this.clt_batch_save_extrinsics;
cp.clt_batch_save_all= this.clt_batch_save_all;
cp.thumb_overwrite = this.thumb_overwrite;
cp.thumb_width = this.thumb_width;
cp.thumb_height = this.thumb_height;
cp.thumb_h_center = this.thumb_h_center;
cp.thumb_v_center = this.thumb_v_center;
cp.thumb_size = this.thumb_size;
cp.default_rating = this.default_rating;
}
......@@ -462,6 +474,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"clt_batch_save_extrinsics", this.clt_batch_save_extrinsics+"");
properties.setProperty(prefix+"clt_batch_save_all", this.clt_batch_save_all+"");
properties.setProperty(prefix+"thumb_overwrite", this.thumb_overwrite+"");
properties.setProperty(prefix+"thumb_width", this.thumb_width+"");
properties.setProperty(prefix+"thumb_height", this.thumb_height+"");
properties.setProperty(prefix+"thumb_h_center", this.thumb_h_center+"");
......@@ -616,6 +629,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"clt_batch_save_extrinsics")!= null) this.clt_batch_save_extrinsics=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_save_extrinsics"));
if (properties.getProperty(prefix+"clt_batch_save_all")!= null) this.clt_batch_save_all=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_save_all"));
if (properties.getProperty(prefix+"thumb_overwrite")!= null) this.thumb_overwrite=Boolean.parseBoolean(properties.getProperty(prefix+"thumb_overwrite"));
if (properties.getProperty(prefix+"thumb_width")!=null) this.thumb_width=Integer.parseInt(properties.getProperty(prefix+"thumb_width"));
if (properties.getProperty(prefix+"thumb_height")!=null) this.thumb_height=Integer.parseInt(properties.getProperty(prefix+"thumb_height"));
if (properties.getProperty(prefix+"thumb_h_center")!=null) this.thumb_h_center= Double.parseDouble(properties.getProperty(prefix+"thumb_h_center"));
......@@ -769,6 +783,7 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Swap top and equator images", this.swapSubchannels01);
gd.addTab("Thumbnails","Thumbnail image generation");
gd.addCheckbox("Overwrite existing thumbnail images",this.thumb_overwrite);
gd.addNumericField("Thumbnail image width", this.thumb_width, 0,4,"pix",
"");
gd.addNumericField("Thumbnail image height", this.thumb_height, 0,4,"pix",
......@@ -871,6 +886,7 @@ public class EyesisCorrectionParameters {
this.removeUnusedSensorData= gd.getNextBoolean();
this.swapSubchannels01= gd.getNextBoolean();
this.thumb_overwrite = gd.getNextBoolean();
this.thumb_width= (int) gd.getNextNumber();
this.thumb_height= (int) gd.getNextNumber();
this.thumb_h_center= gd.getNextNumber();
......
......@@ -705,6 +705,10 @@ private Panel panel1,
addButton("GPU files", panelClt_GPU, color_conf_process);
addButton("Rig8 gpu", panelClt_GPU, color_conf_process);
addButton("ShowGPU", panelClt_GPU, color_conf_process);
addButton("LWIR_TEST", panelClt_GPU, color_conf_process);
addButton("LWIR_ACQUIRE", panelClt_GPU, color_conf_process);
plugInFrame.add(panelClt_GPU);
}
if (LWIR_MODE) {
......@@ -730,13 +734,13 @@ private Panel panel1,
addButton("AUX OUT 3D", panelLWIR, color_process_aux);
addButton("Main img AUX", panelLWIR, color_process_aux);
addButton("Main to AUX", panelLWIR, color_process_aux);
addButton("LWIR_TEST", panelLWIR, color_conf_process);
addButton("LWIR_ACQUIRE", panelLWIR, color_conf_process);
addButton("LWIR batch", panelClt4, color_process);
// addButton("LWIR_TEST", panelLWIR, color_conf_process);
// addButton("LWIR_ACQUIRE", panelLWIR, color_conf_process);
plugInFrame.add(panelLWIR);
}
plugInFrame.pack();
//"LWIR batch"
GUI.center(plugInFrame);
plugInFrame.setVisible(true);
FHT_INSTANCE= new DoubleFHT();
......@@ -3960,12 +3964,6 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
/*
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL,
true, // true - ignore missing files
true, // boolean all_sensors,
COLOR_PROC_PARAMETERS.correct_vignetting); //boolean correct_vignetting
*/
QUAD_CLT.resetGeometryCorrection();
QUAD_CLT.initGeometryCorrection(DEBUG_LEVEL+2);
......@@ -5016,6 +5014,14 @@ private Panel panel1,
batchRig();
return;
/* ======================================================================== */
} else if (label.equals("LWIR batch")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
CLT_PARAMETERS.batch_run = true;
batchLwir();
return;
/* ======================================================================== */
} else if (label.equals("CLT rig edit")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
......@@ -5464,7 +5470,7 @@ private Panel panel1,
return true;
}
// inverted false/true in initSensorFiles(), should work with LWIR also
public boolean prepareRigImages() {
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
......@@ -5489,8 +5495,6 @@ private Panel panel1,
System.out.println("Created new QuadCLT instance, will need to read CLT kernels");
}
}
// QuadCLT dbg_QUAD_CLT = QUAD_CLT;
// QuadCLT dbg_QUAD_CLT_AUX = QUAD_CLT_AUX;
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
if (DEBUG_LEVEL > -2){
......@@ -5498,15 +5502,15 @@ private Panel panel1,
}
EYESIS_CORRECTIONS.initSensorFiles(
DEBUG_LEVEL+2,
true,
false,
false, // true,
true, // false,
COLOR_PROC_PARAMETERS.correct_vignetting); //boolean correct_vignetting
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Running initSensorFiles for the auxiliary camera ++++++++++++++");
}
EYESIS_CORRECTIONS_AUX.initSensorFiles(DEBUG_LEVEL+2,
true,
false,
false, // true,
true, // false,
COLOR_PROC_PARAMETERS_AUX.correct_vignetting); //boolean correct_vignetting
......@@ -6149,6 +6153,52 @@ private Panel panel1,
return true;
}
public boolean batchLwir() {
long startTime=System.nanoTime();
// load needed sensor and kernels files
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
setAllProperties(PROPERTIES); // batchRig may save properties with the model. Extrinsics will be updated, others should be set here
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Running batch processing of dual-quad EO/LWIR camera rig ++++++++++++++");
}
// parameters are different
/// if (COLOR_PROC_PARAMETERS_AUX == null) {
/// COLOR_PROC_PARAMETERS_AUX = COLOR_PROC_PARAMETERS.clone();
/// }
try {
TWO_QUAD_CLT.batchLwirRig(
QUAD_CLT, // QuadCLT quadCLT_main,
QUAD_CLT_AUX, // QuadCLT quadCLT_aux,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
COLOR_PROC_PARAMETERS_AUX, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters_aux,
CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
PROPERTIES, // Properties properties,
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
DEBUG_LEVEL);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //final int debugLevel);
if (configPath!=null) {
saveTimestampedProperties( // save config again
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
}
System.out.println("batchRig(): Processing finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+" sec, --- Free memory="+
Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
return true;
}
......@@ -6337,7 +6387,9 @@ private Panel panel1,
String mask = ".*EXTRINSICS\\.corr-xml";
String full_conf_suffix = ".corr-xml";
String dsi_suffix = "-DSI_COMBO.tiff";
// String dsi_suffix = "-DSI_COMBO.tiff";
String dsi_suffix = TwoQuadCLT.DSI_COMBO_SUFFIX+".tiff";
String correction_parameters_prefix = "CORRECTION_PARAMETERS.";
System.out.println("File mask = "+mask);
......
......@@ -23,6 +23,7 @@ package com.elphel.imagej.tileprocessor;
**
*/
import java.util.ArrayList;
import java.util.Arrays;
import com.elphel.imagej.cameras.CLTParameters;
import com.elphel.imagej.common.DoubleGaussianBlur;
......@@ -1775,6 +1776,11 @@ B = |+dy0 -dy1 -2*dy3 |
final int hist_min_samples,
final boolean hist_norm_center, // if there are more tiles that fit than min_samples, replace with
final double inf_fraction, // fraction of the weight for the infinity tiles
final int min_per_quadrant, // minimal tiles per quadrant (not counting the worst) tp proceed
final int min_inf, // minimal number of tiles at infinity to proceed
final int min_inf_to_scale, // minimal number of tiles at infinity to apply weight scaling
final boolean right_left, // equalize weights of right/left FoV (use with horizon in both halves and gross infinity correction)
CLTParameters clt_parameters,
double [][] scans_14,
......@@ -2172,12 +2178,44 @@ B = |+dy0 -dy1 -2*dy3 |
// adjust weight to balance infinity data and lazy eye one. As some tiles were discarded by selectInfinityTiles() list and not the original
// array has to be used to find the total weight of the infinity tile. Other ones will be used with no extra filtering
double [] total_weights = new double[2];
int num_inf = 0;
int [] per_quad = new int[4];
for (Sample s: inf_samples_list) {
total_weights[0] += s.weight;
if (s.weight > 0.0) {
num_inf ++;
int hx = (s.tile % tilesX) / (tilesX/2);
int hy = (s.tile / tilesX) / (tilesY/2);
per_quad[hx + 2*hy]++;
}
}
for (int nTile = 0; nTile < num_tiles; nTile++) if (center_mask[nTile]){ // calculate total weight of non-infinity
total_weights[1]+= inf_and_ly[1 * NUM_SLICES + 1][nTile];
if (inf_and_ly[1 * NUM_SLICES + 1][nTile] > 0.0) {
int hx = (nTile % tilesX) / (tilesX/2);
int hy = (nTile / tilesX) / (tilesY/2);
per_quad[hx + 2*hy]++;
}
}
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));
}
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));
}
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));
}
return null;
}
double inf_fraction_limited = (inf_fraction >= 0.0) ?((inf_fraction > 1.0) ? 1.0 : inf_fraction):0.0;
......@@ -2187,6 +2225,15 @@ B = |+dy0 -dy1 -2*dy3 |
(1.0 - inf_fraction_limited) * (total_weights[0] + total_weights[1]) / total_weights[1],
};
if (num_inf < min_inf_to_scale) {
if (debugLevel>-1) {
System.out.println("Too few infinity tiles to boost ("+num_inf+" < "+min_inf_to_scale+", keeping original weights");
}
} else if (weights[0] > weights[1]) {
if (debugLevel>-1) {
System.out.println("Boosting weights of far tiles (weights[0]="+weights[0]+", weights[1]="+weights[1]);
}
for (int ns = 0; ns <2; ns++) {
for (int nTile = 0; nTile < num_tiles; nTile++) {
inf_and_ly[ns * NUM_SLICES + 1][nTile] *= weights[ns];
......@@ -2195,8 +2242,12 @@ B = |+dy0 -dy1 -2*dy3 |
for (Sample s: inf_samples_list) {
s.weight *= weights[0];
}
// } else {
// inf_samples_list = new ArrayList<Sample>(); // do not use infinity at all
} else {
if (debugLevel>-1) {
System.out.println("There are already more far tiles than requested (weights[0]="+weights[0]+", weights[1]="+weights[1]+", so keeping original weights");
}
}
}
///-----
......@@ -2325,7 +2376,11 @@ B = |+dy0 -dy1 -2*dy3 |
System.out.println(corr_vector.toString());
}
if (apply_extrinsic){
qc.geometryCorrection.getCorrVector().incrementVector(corr_vector, clt_parameters.ly_corr_scale);
boolean ok = qc.geometryCorrection.getCorrVector().incrementVector(corr_vector, clt_parameters.ly_corr_scale);
if (!ok) {
System.out.println("Failed to solve correction, corr_vector:"+corr_vector.toString());
return null;
}
if (debugLevel > -1){
System.out.println("New extrinsic corrections:");
System.out.println(qc.geometryCorrection.getCorrVector().toString());
......@@ -2351,7 +2406,46 @@ B = |+dy0 -dy1 -2*dy3 |
/**
*
* @param use_poly
* @param restore_disp_inf
* @param fcorr_radius
* @param min_strength_in
* @param strength_pow
* @param lazyEyeCompDiff
* @param lazyEyeSmplSide
* @param lazyEyeSmplNum
* @param lazyEyeSmplRms
* @param lazyEyeDispVariation
* @param lazyEyeDispRelVariation
* @param ly_norm_disp
* @param smplSide
* @param smplNum
* @param smplRms
* @param hist_smpl_side
* @param hist_disp_min
* @param hist_disp_step
* @param hist_num_bins
* @param hist_sigma
* @param hist_max_diff
* @param hist_min_samples
* @param hist_norm_center
* @param inf_fraction
* @param min_per_quadrant
* @param min_inf
* @param min_inf_to_scale
* @param inf_max_disparity
* @param clt_parameters
* @param scans_14
* @param gt_disparity_strength
* @param filter_ds
* @param filter_lyf
* @param tilesX
* @param magic_coeff
* @param debugLevel
* @return will return null if can not adjust
*/
......@@ -2387,6 +2481,9 @@ B = |+dy0 -dy1 -2*dy3 |
final int hist_min_samples,
final boolean hist_norm_center, // if there are more tiles that fit than min_samples, replace with
final double inf_fraction, // fraction of the weight for the infinity tiles
final int min_per_quadrant, // minimal tiles per quadrant (not counting the worst) tp proceed
final int min_inf, // minimal number of tiles at infinity to proceed
final int min_inf_to_scale, // minimal number of tiles at infinity to apply weight scaling
final double inf_max_disparity, // use all smaller disparities as inf_fraction
CLTParameters clt_parameters,
double [][] scans_14, // here - always 14 - infinity and non-infinity
......@@ -2542,6 +2639,13 @@ B = |+dy0 -dy1 -2*dy3 |
}
}
}
if (debugLevel > 0) { // 0) {
String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"};
(new ShowDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "removed_residual"+lazyEyeCompDiff, prefixes);
}
for (int nTile = 0; nTile < num_tiles; nTile++) {
if (nTile == dbg_nTile){
System.out.println("lazyEyeCorrectionFromGT().2: nTile="+nTile);
......@@ -2559,6 +2663,10 @@ B = |+dy0 -dy1 -2*dy3 |
}
}
if (debugLevel > 0) { // 0) {
String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"};
(new ShowDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "removed_residual-1"+lazyEyeCompDiff, prefixes);
}
// reduce influence of high disparity, using combined disparity
// double norm_ly_disparity = 100.0; // disabling
......@@ -2567,6 +2675,10 @@ B = |+dy0 -dy1 -2*dy3 |
combo_mismatch[1][nTile] *= ly_norm_disp/combo_mismatch[0][nTile];
}
}
if (debugLevel > 0) { // 0) {
String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"};
(new ShowDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "removed_residual-2"+lazyEyeCompDiff, prefixes);
}
// instance of class to operate navigation over tiles
......@@ -2681,13 +2793,36 @@ B = |+dy0 -dy1 -2*dy3 |
// final double inf_fraction, // fraction of the weight for the infinity tiles
// final double inf_max_disparity, // use all smaller disparities as inf_fraction
double [] total_weights = new double[2];
for (int nTile = 0; nTile < combo_mismatch[INDEX_10_WEIGHT].length; nTile++ ) if (center_mask[nTile]){
int num_inf = 0;
int [] per_quad = new int[4];
for (int nTile = 0; nTile < combo_mismatch[INDEX_10_WEIGHT].length; nTile++ ) if (center_mask[nTile] && (combo_mismatch[INDEX_10_WEIGHT][nTile] > 0.0)){
if (combo_mismatch[INDEX_10_DISPARITY][nTile] <= inf_max_disparity) {
total_weights[0] += combo_mismatch[INDEX_10_WEIGHT][nTile];
num_inf ++;
} else {
total_weights[1] += combo_mismatch[INDEX_10_WEIGHT][nTile];
}
int hx = (nTile % tilesX) / (tilesX/2);
int hy = (nTile / tilesX) / (tilesY/2);
per_quad[hx + 2*hy]++;
}
int [] pq = per_quad.clone();
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));
}
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));
}
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));
}
double inf_fraction_limited = (inf_fraction >= 0.0) ?((inf_fraction > 1.0) ? 1.0 : inf_fraction):0.0;
......@@ -2696,10 +2831,13 @@ B = |+dy0 -dy1 -2*dy3 |
inf_fraction_limited * (total_weights[0] + total_weights[1]) / total_weights[0],
(1.0 - inf_fraction_limited) * (total_weights[0] + total_weights[1]) / total_weights[1],
};
if (weights[0]> weights[1]) {
if (num_inf < min_inf_to_scale) {
if (debugLevel>-1) {
System.out.println("Too few infinity tiles to boost ("+num_inf+" < "+min_inf_to_scale+", keeping original weights");
}
} else if (weights[0] > weights[1]) {
if (debugLevel>-1) {
System.out.println("Boosting weights of far tiles (weights[0]="+weights[0]+", weights[1]="+weights[1]+", so keeping original weights");
System.out.println("Boosting weights of far tiles (weights[0]="+weights[0]+", weights[1]="+weights[1]);
}
for (int nTile = 0; nTile < num_tiles; nTile++) {
if (combo_mismatch[INDEX_10_DISPARITY][nTile] <= inf_max_disparity) {
......@@ -2714,8 +2852,6 @@ B = |+dy0 -dy1 -2*dy3 |
}
}
ArrayList<Sample> samples_list = new ArrayList<Sample>();
for (int nTile = 0; nTile < num_tiles; nTile++) if (combo_mismatch[INDEX_10_WEIGHT][nTile] > 0.0) {
......@@ -2742,7 +2878,7 @@ B = |+dy0 -dy1 -2*dy3 |
if (debugLevel > 1) {
String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"};
(new ShowDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "combo_mismatch" , prefixes);
(new ShowDoubleFloatArrays()).showArrays(combo_mismatch, tilesX, combo_mismatch[0].length/tilesX, true, "combo_mismatch4" , prefixes);
}
......
......@@ -998,6 +998,9 @@ public class GeometryCorrection {
}
public void showRig() {
if (this.rigOffset == null) {
this.rigOffset = new RigOffset();
}
this.rigOffset.showRigOffsets();
}
......@@ -1401,18 +1404,22 @@ public class GeometryCorrection {
public void incrementVector(double [] incr,
// returns false if any component is NaN, in that case do not increment
public boolean incrementVector(double [] incr,
double scale)
{
for (int i = 0; i < incr.length; i++){
if (Double.isNaN(vector[i])) return false;
}
for (int i = 0; i < incr.length; i++){
vector[i]+= incr[i] * scale;
}
return true;
}
public void incrementVector(CorrVector incr, double scale)
public boolean incrementVector(CorrVector incr, double scale)
{
incrementVector(incr.toArray(), scale);
return incrementVector(incr.toArray(), scale);
}
@Override
......
......@@ -83,7 +83,8 @@ public class MLStats {
int result_disparity_step = 10; // bins
String mask = ".*-DSI_COMBO\\.tiff";
// String mask = ".*-DSI_COMBO\\.tiff";
String mask = ".*"+TwoQuadCLT.DSI_COMBO_SUFFIX+"\\.tiff";
GenericDialog gd = new GenericDialog("Select file mask and histogram parameters");
gd.addStringField ("Combined DSI file mask: ", mask, 40);
......@@ -443,7 +444,8 @@ public class MLStats {
{
String mask = ".*EXTRINSICS\\.corr-xml";
String full_conf_suffix = ".corr-xml";
String dsi_suffix = "-DSI_COMBO.tiff";
// String dsi_suffix = "-DSI_COMBO.tiff";
String dsi_suffix = TwoQuadCLT.DSI_COMBO_SUFFIX+".tiff";
String correction_parameters_prefix = "CORRECTION_PARAMETERS.";
System.out.println("File mask = "+mask);
......
......@@ -109,6 +109,7 @@ public class QuadCLT {
// magic scale should be set before using TileProcessor (calculated disparities depend on it)
public boolean isMonochrome() {return is_mono;}
public boolean isAux() {return is_aux;}
public String sAux() {return isAux()?"-AUX":"";}
public boolean isLwir() {return !Double.isNaN(lwir_offset);} // clt_kernels
public double getLwirOffset() {return lwir_offset;}
......@@ -1532,7 +1533,7 @@ public class QuadCLT {
if (equirectangularParameters.clearAllMaps) eyesisCorrections.pixelMapping.deleteEquirectangularMapAll(srcChannel); // save memory? //removeUnusedSensorData - no, use equirectangular specific settings
}
//pixelMapping
Runtime.getRuntime().gc();
// Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing image "+(iImage+1)+" (of "+fileIndices.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
......@@ -1641,7 +1642,8 @@ public class QuadCLT {
}
String title=name+"-"+String.format("%02d", channel);
// String title=name+"-"+String.format("%02d", channel);
String title=String.format("%s%s-%02d",name, sAux(), channel);
ImagePlus result=imp_src;
if (debugLevel>1) System.out.println("processing: "+path);
result.setTitle(title+"RAW");
......@@ -2214,7 +2216,7 @@ public class QuadCLT {
if (equirectangularParameters.clearAllMaps) eyesisCorrections.pixelMapping.deleteEquirectangularMapAll(srcChannel); // save memory? //removeUnusedSensorData - no, use equirectangular specific settings
}
//pixelMapping
Runtime.getRuntime().gc();
// Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing image "+(iImage+1)+" (of "+fileIndices.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
......@@ -2255,7 +2257,8 @@ public class QuadCLT {
int channel= (Integer) imp_src.getProperty("channel");
String path= (String) imp_src.getProperty("path");
String title=name+"-"+String.format("%02d", channel);
// String title=name+"-"+String.format("%02d", channel);
String title=String.format("%s%s-%02d",name, sAux(), channel);
ImagePlus result=imp_src;
if (debugLevel>1) System.out.println("processing: "+path);
result.setTitle(title+"RAW");
......@@ -2810,7 +2813,7 @@ public class QuadCLT {
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
Runtime.getRuntime().gc();
// Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+setNames.size()+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
......@@ -2897,7 +2900,8 @@ public class QuadCLT {
for (int iQuad = 0; iQuad <clt_data.length; iQuad++){
String title=name+"-"+String.format("%02d", iQuad);
// String title=name+"-"+String.format("%02d", iQuad);
String title=String.format("%s%s-%02d",name, sAux(), iQuad);
String titleFull=title+"-SPLIT";
if (clt_parameters.getCorrSigma(image_dtt.isMonochrome()) > 0){ // no filter at all
......@@ -3560,14 +3564,13 @@ public class QuadCLT {
colorProcParameters,
channelGainParameters,
rgbParameters,
// convolveFFTSize, // 128 - fft size, kernel size should be size/2
scaleExposures,
apply_corr, // calculate and apply additional fine geometry correction
infinity_corr, // calculate and apply geometry correction at infinity
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
Runtime.getRuntime().gc();
//Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+set_channels.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
......@@ -3880,6 +3883,7 @@ public class QuadCLT {
ShowDoubleFloatArrays sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging?
// may use this.StartTime to report intermediate steps execution times
// String aux = isAux()?"-AUX":"";
String name=this.correctionsParameters.getModelName((String) imp_quad[0].getProperty("name"));
// int channel= Integer.parseInt((String) imp_src.getProperty("channel"));
String path= (String) imp_quad[0].getProperty("path");
......@@ -4058,7 +4062,7 @@ public class QuadCLT {
tilesX * (2 * clt_parameters.transform_size),
tilesY * (2 * clt_parameters.transform_size),
true,
name + "-TXTNOL-D"+clt_parameters.disparity,
name+sAux() + "-TXTNOL-D"+clt_parameters.disparity,
(clt_parameters.keep_weights?rbga_weights_titles:rbga_titles));
}
......@@ -4088,7 +4092,7 @@ public class QuadCLT {
tilesX * clt_parameters.transform_size,
tilesY * clt_parameters.transform_size,
true,
name + "-TXTOL-D"+clt_parameters.disparity,
name+sAux() + "-TXTOL-D"+clt_parameters.disparity,
(clt_parameters.keep_weights?rbga_weights_titles:rbga_titles));
}
if (!batch_mode && clt_parameters.show_rgba_color) {
......@@ -4100,7 +4104,7 @@ public class QuadCLT {
clt_parameters,
colorProcParameters,
rgbParameters,
name+"-texture", // String name,
name+sAux()+"-texture", // String name,
"-D"+clt_parameters.disparity, //String suffix, // such as disparity=...
toRGB,
!this.correctionsParameters.jpeg, // boolean bpp16, // 16-bit per channel color mode for result
......@@ -4124,7 +4128,7 @@ public class QuadCLT {
tilesX,
tilesY,
true,
name+"-DISP_MAP-D"+clt_parameters.disparity,
name+sAux()+"-DISP_MAP-D"+clt_parameters.disparity,
ImageDtt.DISPARITY_TITLES);
}
}
......@@ -4196,7 +4200,7 @@ public class QuadCLT {
tilesX,
tilesY,
true,
name + "-inf_corr",
name+sAux() + "-inf_corr",
titles );
}
} else { // calculate/apply coefficients
......@@ -4208,7 +4212,7 @@ public class QuadCLT {
tilesX,
tilesY,
true,
name + "-inf_corr",
name+sAux() + "-inf_corr",
titles );
}
}
......@@ -4276,7 +4280,7 @@ public class QuadCLT {
tilesX*(2*clt_parameters.transform_size),
tilesY*(2*clt_parameters.transform_size),
true,
name + "-CORR-D"+clt_parameters.disparity,
name+sAux()+"-CORR-D"+clt_parameters.disparity,
titles );
}
......@@ -4302,7 +4306,7 @@ public class QuadCLT {
tilesX*(2*clt_parameters.transform_size),
tilesY*(2*clt_parameters.transform_size),
true,
name+"-PART_CORR-D"+clt_parameters.disparity);
name+sAux()+"-PART_CORR-D"+clt_parameters.disparity);
// titles);
}
}
......@@ -4397,7 +4401,7 @@ public class QuadCLT {
ImagePlus [] imps_RGB = new ImagePlus[clt_data.length];
for (int iQuad = 0; iQuad < clt_data.length; iQuad++){
if (!clt_parameters.gen_chn_img) continue;
String title=name+"-"+String.format("%02d", iQuad);
String title=String.format("%s%s-%02d",name, sAux(), iQuad);
imps_RGB[iQuad] = linearStackToColor(
clt_parameters,
colorProcParameters,
......@@ -4429,7 +4433,7 @@ public class QuadCLT {
array_stack.addSlice("port_"+slice_seq[i], results[slice_seq[i]].getProcessor().getPixels());
}
}
ImagePlus imp_stack = new ImagePlus(name+"-SHIFTED-D"+clt_parameters.disparity, array_stack);
ImagePlus imp_stack = new ImagePlus(name+sAux()+"-SHIFTED-D"+clt_parameters.disparity, array_stack);
imp_stack.getProcessor().resetMinAndMax();
if (!batch_mode) {
imp_stack.updateAndDraw();
......@@ -4469,7 +4473,7 @@ public class QuadCLT {
createThumbNailImage(
imps_RGB[0],
model_path,
"thumb",
"thumb"+sAux(),
debugLevel);
......@@ -4741,7 +4745,8 @@ public class QuadCLT {
true); // replace NaN with 0.0
ImagePlus imp_rgba = EyesisCorrections.convertRGBAFloatToRGBA32(
stack, // ImageStack stackFloat, //r,g,b,a
name+"ARGB"+suffix, // String title,
// name+"ARGB"+suffix, // String title,
name+suffix, // String title,
0.0, // double r_min,
255.0, // double r_max,
0.0, // double g_min,
......@@ -4829,7 +4834,7 @@ public class QuadCLT {
// if (debugLevel > -1) System.out.println("before colors.2");
if (saveShowIntermediate && (debugLevel > 1)){
// if (saveShowIntermediate && (debugLevel > -1)){
ImagePlus imp_dbg=new ImagePlus(name+"-preColors",stack);
ImagePlus imp_dbg=new ImagePlus(name+sAux()+"-preColors",stack);
eyesisCorrections.saveAndShow(
imp_dbg,
this.correctionsParameters);
......@@ -4876,7 +4881,7 @@ public class QuadCLT {
colorProcParameters.kr, // 0.299;
colorProcParameters.kb, // 0.114;
stack.getWidth());
titleFull=name+"-RGB-float"+suffix;
titleFull=name+sAux()+"-RGB-float"+suffix;
//Trim stack to just first 3 slices
if (saveShowIntermediate && (debugLevel > 1)){ // 2){
ImagePlus imp_dbg=new ImagePlus("YPrPbToRGB",stack);
......@@ -4887,7 +4892,7 @@ public class QuadCLT {
while (stack.getSize() > 3) stack.deleteLastSlice();
if (debugLevel > 1) System.out.println("Trimming color stack");
} else {
titleFull=name+"-YPrPb"+suffix;
titleFull=name+sAux()+"-YPrPb"+suffix;
if (debugLevel > 1) System.out.println("Using full stack, including YPbPr");
}
......@@ -4918,7 +4923,7 @@ public class QuadCLT {
stack,
rgbParameters);
titleFull=name+"-RGB48"+suffix;
titleFull=name+sAux()+"-RGB48"+suffix;
result= new ImagePlus(titleFull, stack);
result.updateAndDraw();
if (debugLevel > 1) {
......@@ -5290,7 +5295,7 @@ public class QuadCLT {
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
Runtime.getRuntime().gc();
//Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+fileIndices.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
......@@ -5497,7 +5502,7 @@ public class QuadCLT {
scans, // double [][] data,
tilesX, // int tilesX,
debugLevel); // int debugLevel)
int num_tiles = disp_strength[0].length;
double [][][] new_corr = ac.lazyEyeCorrection(
clt_parameters.ly_poly, // final boolean use_poly,
true, // final boolean restore_disp_inf, // Restore subtracted disparity for scan #0 (infinity)
......@@ -5529,6 +5534,9 @@ public class QuadCLT {
clt_parameters.ih_min_samples, // 10, // final int hist_min_samples,
clt_parameters.ih_norm_center, // true, // final boolean hist_norm_center, // if there are more tiles that fit than min_samples, replace with
clt_parameters.ly_inf_frac, // 0.5, // final double inf_fraction, // fraction of the weight for the infinity tiles
clt_parameters.getLyPerQuad(num_tiles), // final int min_per_quadrant, // minimal tiles per quadrant (not counting the worst) tp proceed
clt_parameters.getLyInf(num_tiles), // final int min_inf, // minimal number of tiles at infinity to proceed
clt_parameters.getLyInfScale(num_tiles),// final int min_inf_to_scale, // minimal number of tiles at infinity to apply weight scaling
clt_parameters.ly_right_left, // false // equalize weights of right/left FoV (use with horizon in both halves and gross infinity correction)
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
disp_strength, // scans, // double [][] disp_strength,
......@@ -5580,7 +5588,7 @@ public class QuadCLT {
tilesY,
disparities_titles);
ImagePlus imp_stack = new ImagePlus( name+"-DISP_MAPS", array_stack);
ImagePlus imp_stack = new ImagePlus( name+sAux()+"-DISP_MAPS", array_stack);
imp_stack.getProcessor().resetMinAndMax();
imp_stack.updateAndDraw();
//imp_stack.getProcessor().resetMinAndMax();
......@@ -5599,7 +5607,7 @@ public class QuadCLT {
tilesX,
tilesY,
trend_titles);
ImagePlus imp_stack_trends = new ImagePlus( name+"-DISP_TRENDS", trends_stack);
ImagePlus imp_stack_trends = new ImagePlus( name+sAux()+"-DISP_TRENDS", trends_stack);
imp_stack_trends.getProcessor().resetMinAndMax();
imp_stack_trends.updateAndDraw();
eyesisCorrections.saveAndShow(imp_stack_trends, this.correctionsParameters);
......@@ -5707,6 +5715,7 @@ public class QuadCLT {
tilesX, // int tilesX,
debugLevel); // int debugLevel)
int num_tiles = disp_strength[0].length;
double [][][] new_corr = ac.lazyEyeCorrection(
clt_parameters.ly_poly, // final boolean use_poly,
......@@ -5738,6 +5747,9 @@ public class QuadCLT {
clt_parameters.ih_min_samples, // 10, // final int hist_min_samples,
clt_parameters.ih_norm_center, // true, // final boolean hist_norm_center, // if there are more tiles that fit than min_samples, replace with
clt_parameters.ly_inf_frac, // 0.5, // final double inf_fraction, // fraction of the weight for the infinity tiles
clt_parameters.getLyPerQuad(num_tiles), // final int min_per_quadrant, // minimal tiles per quadrant (not counting the worst) tp proceed
clt_parameters.getLyInf(num_tiles), // final int min_inf, // minimal number of tiles at infinity to proceed
clt_parameters.getLyInfScale(num_tiles),// final int min_inf_to_scale, // minimal number of tiles at infinity to apply weight scaling
clt_parameters.ly_right_left, // false // equalize weights of right/left FoV (use with horizon in both halves and gross infinity correction)
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
disp_strength, // scans, // double [][] disp_strength,
......@@ -6001,7 +6013,7 @@ public class QuadCLT {
tp.ShowScansSFB(
combo_pass_list, // ArrayList<CLTPass3d> scans, // list of composite scans
this.image_name+"-SFB"); // String title);
this.image_name+sAux()+"-SFB0"); // String title);
}
if (adjust_extrinsics) {
......@@ -6082,7 +6094,7 @@ public class QuadCLT {
tp.ShowScansSFB(
combo_pass_list, // ArrayList<CLTPass3d> scans, // list of composite scans
this.image_name+"-SFB"); // String title);
this.image_name+sAux()+"-SFB1"); // String title);
Runtime.getRuntime().gc();
......@@ -6743,7 +6755,15 @@ public class QuadCLT {
}
return measurements;
}
/**
*
* @param clt_parameters
* @param adjust_poly
* @param threadsMax
* @param updateStatus
* @param debugLevel
* @return true on success, false - on failure
*/
public boolean extrinsicsCLT(
CLTParameters clt_parameters,
boolean adjust_poly,
......@@ -6984,8 +7004,7 @@ public class QuadCLT {
double [][] target_disparity = {tp.clt_3d_passes.get(bg_scan).getDisparity(0), tp.clt_3d_passes.get(combo_scan).getDisparity(0)};
int num_tiles = tp.clt_3d_passes.get(combo_scan).getStrength().length;
// TODO: fix above for using GT
......@@ -7021,6 +7040,11 @@ public class QuadCLT {
clt_parameters.ih_min_samples, // 10, // final int hist_min_samples,
clt_parameters.ih_norm_center, // true, // final boolean hist_norm_center, // if there are more tiles that fit than min_samples, replace with
clt_parameters.ly_inf_frac, // 0.5, // final double inf_fraction, // fraction of the weight for the infinity tiles
clt_parameters.getLyPerQuad(num_tiles), // final int min_per_quadrant, // minimal tiles per quadrant (not counting the worst) tp proceed
clt_parameters.getLyInf(num_tiles), // final int min_inf, // minimal number of tiles at infinity to proceed
clt_parameters.getLyInfScale(num_tiles),// final int min_inf_to_scale, // minimal number of tiles at infinity to apply weight scaling
clt_parameters.ly_right_left, // false // equalize weights of right/left FoV (use with horizon in both halves and gross infinity correction)
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
scans14, // disp_strength, // scans, // double [][] disp_strength,
......@@ -7028,6 +7052,9 @@ public class QuadCLT {
tp.getTilesX(), // int tilesX,
clt_parameters.corr_magic_scale, // double magic_coeff, // still not understood coefficent that reduces reported disparity value. Seems to be around 8.5
debugLevelInner - 1); // + (clt_parameters.fine_dbg ? 1:0)); // int debugLevel)
if (new_corr == null) {
return false;
}
comp_diff = 0.0;
int num_pars = 0;
if (adjust_poly) {
......@@ -7078,7 +7105,7 @@ public class QuadCLT {
}
}
}
return (comp_diff < (adjust_poly ? min_poly_update : min_sym_update));
return true; // (comp_diff < (adjust_poly ? min_poly_update : min_sym_update));
}
......@@ -7112,7 +7139,17 @@ public class QuadCLT {
}
/**
*
* @param geometryCorrection_main
* @param rig_disp_strength
* @param clt_parameters
* @param adjust_poly
* @param threadsMax
* @param updateStatus
* @param debugLevel
* @return true on success, false on failure
*/
public boolean extrinsicsCLTfromGT(
// TwoQuadCLT twoQuadCLT, //maybe null in no-rig mode, otherwise may contain rig measurements to be used as infinity ground truth
GeometryCorrection geometryCorrection_main, // only used for aux camera if coordinates are for main (null for LWIR)
......@@ -7220,6 +7257,8 @@ public class QuadCLT {
double [][][] new_corr;
double [][][] gt_disparity_strength = {rig_disp_strength};
int num_tiles = comboScan.getStrength().length;
new_corr = ac.lazyEyeCorrectionFromGT(
/// geometryCorrection_main, //final GeometryCorrection geometryCorrection_main, // if not null - this is an AUX camera of a rig
adjust_poly, // final boolean use_poly,
......@@ -7232,8 +7271,8 @@ public class QuadCLT {
clt_parameters.ly_smpl_side, // 3, // final int lazyEyeSmplSide, // = 2; // Sample size (side of a square)
clt_parameters.ly_smpl_num, // 5, // final int lazyEyeSmplNum, // = 3; // Number after removing worst (should be >1)
clt_parameters.ly_smpl_rms, // 0.1, // final double lazyEyeSmplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
clt_parameters.ly_disp_var, // 0.2, // final double lazyEyeDispVariation, // 0.2, maximal full disparity difference between tgh tile and 8 neighborxs
clt_parameters.ly_disp_rvar, // 0.2, // final double lazyEyeDispRelVariation, // 0.02 Maximal relative full disparity difference to 8 neighbors
clt_parameters.ly_disp_var_gt, // 0.2, // final double lazyEyeDispVariation, // 0.2, maximal full disparity difference between tgh tile and 8 neighborxs
clt_parameters.ly_disp_rvar_gt, // 0.2, // final double lazyEyeDispRelVariation, // 0.02 Maximal relative full disparity difference to 8 neighbors
clt_parameters.ly_norm_disp, // final double ly_norm_disp, // = 5.0; // Reduce weight of higher disparity tiles
clt_parameters.inf_smpl_side, // 3, // final int smplSide, // = 2; // Sample size (side of a square)
clt_parameters.inf_smpl_num, // 5, // final int smplNum, // = 3; // Number after removing worst (should be >1)
......@@ -7248,6 +7287,10 @@ public class QuadCLT {
clt_parameters.ih_min_samples, // 10, // final int hist_min_samples,
clt_parameters.ih_norm_center, // true, // final boolean hist_norm_center, // if there are more tiles that fit than min_samples, replace with
clt_parameters.ly_inf_frac, // 0.5, // final double inf_fraction, // fraction of the weight for the infinity tiles
clt_parameters.getLyPerQuad(num_tiles), // final int min_per_quadrant, // minimal tiles per quadrant (not counting the worst) tp proceed
0, // clt_parameters.getLyInf(num_tiles), // final int min_inf, // minimal number of tiles at infinity to proceed
clt_parameters.getLyInfScale(num_tiles),// final int min_inf_to_scale, // minimal number of tiles at infinity to apply weight scaling
clt_parameters.ly_inf_max_disparity, // inf_max_disparity, // final double inf_max_disparity, // use all smaller disparities as inf_fraction
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
scans14, // disp_strength, // scans, // double [][] disp_strength,
......@@ -7257,6 +7300,9 @@ public class QuadCLT {
tp.getTilesX(), // int tilesX,
clt_parameters.corr_magic_scale, // double magic_coeff, // still not understood coefficent that reduces reported disparity value. Seems to be around 8.5
debugLevelInner - 1); // + (clt_parameters.fine_dbg ? 1:0)); // int debugLevel)
if (new_corr == null) {
return false;
}
comp_diff = 0.0;
int num_pars = 0;
if (adjust_poly) {
......@@ -7305,7 +7351,7 @@ public class QuadCLT {
}
}
}
return (comp_diff < (adjust_poly ? min_poly_update : min_sym_update));
return true; // (comp_diff < (adjust_poly ? min_poly_update : min_sym_update));
}
......@@ -7547,9 +7593,9 @@ public class QuadCLT {
// Save tp.clt_3d_passes.size() to roll back without restarting the program
tp.saveCLTPasses(false); // not rig, and reset rig data
Runtime runtime = Runtime.getRuntime();
runtime.gc();
System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
/// Runtime runtime = Runtime.getRuntime();
/// runtime.gc();
/// System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
return true; // null;
}
......@@ -8027,7 +8073,7 @@ public class QuadCLT {
tp.getTilesX(),
tp.getTilesY(),
true,
image_name+"-PERIODIC",
image_name+sAux()+"-PERIODIC",
dbg_titles);
return true;
}
......@@ -9823,28 +9869,35 @@ public class QuadCLT {
int debugLevel)
{
String thumb_path = dir + Prefs.getFileSeparator() + name+".jpeg";
if (new File(thumb_path).exists()) {
if (new File(thumb_path).exists() && !correctionsParameters.thumb_overwrite) {
System.out.println("file "+thumb_path+" exists, skipping thumbnail generation");
return false;
}
int image_width = imp.getWidth();
int image_height = imp.getHeight();
ImageProcessor ip = imp.getProcessor().duplicate();
if ((image_width >= correctionsParameters.thumb_width) &&
(image_height >= correctionsParameters.thumb_height)) {
double scale_h = 1.0 * (correctionsParameters.thumb_width + 1)/image_width;
double scale_v = 1.0 * (correctionsParameters.thumb_height + 1)/image_height;
double scale = ((scale_h > scale_v) ? scale_h : scale_v) / correctionsParameters.thumb_size;
ImageProcessor ip = imp.getProcessor().duplicate();
ip.setInterpolationMethod(ImageProcessor.BICUBIC);
if (!isMonochrome()) {
ip.blurGaussian(2.0);
}
ip.scale(scale, scale);
int lm = (int) Math.round (((image_width*scale)-correctionsParameters.thumb_width)* correctionsParameters.thumb_h_center + (0.5*image_width*(1.0-scale)));
int tm = (int) Math.round (((image_height*scale)-correctionsParameters.thumb_height)* correctionsParameters.thumb_v_center + (0.5*image_height*(1.0-scale)));
Rectangle r = new Rectangle(lm,tm,correctionsParameters.thumb_width,correctionsParameters.thumb_height);
ip.setRoi(r);
ImageProcessor ip2 = ip.crop();
ImagePlus ip_thumb = new ImagePlus(name,ip2);
ip = ip.crop();
} else {
}
ImagePlus ip_thumb = new ImagePlus(name,ip);
eyesisCorrections.saveAndShow(
ip_thumb,
dir,
......@@ -9852,6 +9905,7 @@ public class QuadCLT {
false,
correctionsParameters.JPEG_quality, // jpegQuality); // jpegQuality){// <0 - keep current, 0 - force Tiff, >0 use for JPEG
(debugLevel > -2) ? debugLevel : 1); // int debugLevel (print what it saves)
return true;
}
......
......@@ -23,7 +23,6 @@ package com.elphel.imagej.tileprocessor;
**
*/
import java.awt.Point;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
......@@ -4216,7 +4215,9 @@ public class TilePlanes {
if (world_xyz != null) {
double l2 = world_xyz[0]*world_xyz[0] + world_xyz[1]*world_xyz[1]+world_xyz[2]*world_xyz[2];
if (l2 < 0.5) {
if (debugLevel > -1) {
System.out.println("getWorldXYZ(): l2="+l2); // +" this=\n"+this.toString());
}
world_xyz = null;
}
}
......@@ -4316,8 +4317,10 @@ public class TilePlanes {
world_xyz = norm_xyz.times((xyz.transpose().times(norm_xyz).get(0,0))).getColumnPackedCopy();
double l2 = world_xyz[0]*world_xyz[0] + world_xyz[1]*world_xyz[1]+world_xyz[2]*world_xyz[2];
if (l2 < 0.5) {
if (debugLevel > -1) {
System.out.println("getWorldXYZ(): l2="+l2); // +" this=\n"+this.toString());
}
}
return world_xyz;
}
......
......@@ -63,6 +63,10 @@ public class TwoQuadCLT {
public static int DSI_STRENGTH_MAIN = 4;
public static int DSI_STRENGTH_AUX = 5;
public static int DSI_STRENGTH_RIG = 6;
public static String DSI_COMBO_SUFFIX = "-DSI_COMBO";
public static String DSI_MAIN_SUFFIX = "-DSI_MAIN";
public static String [] DSI_SLICES =
{ "disparity_main",
"disparity_aux",
......@@ -3249,7 +3253,7 @@ if (debugLevel > -100) return true; // temporarily !
}
}
}
// System.out.println("jp4_copy_path = "+jp4_copy_path);
System.out.println("jp4_copy_path = "+jp4_copy_path);
// System.out.println("Do something useful here");
}
......@@ -7313,7 +7317,7 @@ if (debugLevel > -100) return true; // temporarily !
System.out.println("Adjusting main camera image set for "+quadCLT_main.image_name+
" (w/o rig), pass "+(num_adjust_main+1)+" of "+quadCLT_main.correctionsParameters.rig_batch_adjust_main);
}
quadCLT_main.extrinsicsCLT(
boolean ok = quadCLT_main.extrinsicsCLT(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
false, // adjust_poly,
threadsMax, //final int threadsMax, // maximal number of threads to launch
......@@ -7321,6 +7325,7 @@ if (debugLevel > -100) return true; // temporarily !
debugLevelInner); // final int debugLevel)
// clear memory for main
quadCLT_main.tp.resetCLTPasses();
if (!ok) break;
}
// Early aux camera adjustment, rig data is not available
......@@ -7348,7 +7353,7 @@ if (debugLevel > -100) return true; // temporarily !
System.out.println("Adjusting aux camera image set for "+quadCLT_main.image_name+
" (w/o rig), pass "+(num_adjust_aux+1)+" of "+quadCLT_main.correctionsParameters.rig_batch_adjust_aux);
}
quadCLT_aux.extrinsicsCLT(
boolean ok = quadCLT_aux.extrinsicsCLT(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
false, // adjust_poly,
threadsMax, //final int threadsMax, // maximal number of threads to launch
......@@ -7356,6 +7361,7 @@ if (debugLevel > -100) return true; // temporarily !
debugLevelInner); // final int debugLevel)
// clear memory for aux
quadCLT_aux.tp.resetCLTPasses();
if (!ok) break;
}
// Early rig adjustment, main/aux are not adjusted with rig data
for (int num_adjust_rig = 0; num_adjust_rig < quadCLT_main.correctionsParameters.rig_batch_adjust_rig; num_adjust_rig++) {
......@@ -7455,7 +7461,7 @@ if (debugLevel > -100) return true; // temporarily !
// geometryCorrection_main = twoQuadCLT.quadCLT_main.getGeometryCorrection();
// }
quadCLT_main.extrinsicsCLTfromGT(
boolean ok = quadCLT_main.extrinsicsCLTfromGT(
// this, // TwoQuadCLT twoQuadCLT, //maybe null in no-rig mode, otherwise may contain rig measurements to be used as infinity ground truth
null,
gt_disp_strength,
......@@ -7464,6 +7470,7 @@ if (debugLevel > -100) return true; // temporarily !
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus,// final boolean updateStatus,
debugLevelInner); // final int debugLevel)
if (!ok) break;
}
for (int num_adjust_aux = 0; num_adjust_aux < quadCLT_main.correctionsParameters.rig_batch_adjust_aux_gt; num_adjust_aux++) {
......@@ -7478,7 +7485,7 @@ if (debugLevel > -100) return true; // temporarily !
clt_parameters,
debugLevelInner); // final int debugLevel)
quadCLT_aux.extrinsicsCLTfromGT(
boolean ok = quadCLT_aux.extrinsicsCLTfromGT(
// this, // TwoQuadCLT twoQuadCLT, //maybe null in no-rig mode, otherwise may contain rig measurements to be used as infinity ground truth
quadCLT_main.getGeometryCorrection(),
gt_disp_strength,
......@@ -7487,6 +7494,7 @@ if (debugLevel > -100) return true; // temporarily !
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus,// final boolean updateStatus,
debugLevelInner); // final int debugLevel)
if (!ok) break;
}
// Late rig adjustment, after main/aux are adjusted with rig data as ground truth
// keeping the same DSI, required measurements will be performed anyway
......@@ -7709,7 +7717,9 @@ if (debugLevel > -100) return true; // temporarily !
if (quadCLT_main.correctionsParameters.clt_batch_dsi) {
saveDSI (clt_parameters);
saveDSI (
//clt_parameters
);
}
if (quadCLT_main.correctionsParameters.clt_batch_save_extrinsics) {
......@@ -7740,15 +7750,384 @@ if (debugLevel > -100) return true; // temporarily !
}
public void batchLwirRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
CLTParameters clt_parameters,
EyesisCorrectionParameters.DebayerParameters debayerParameters,
ColorProcParameters colorProcParameters,
ColorProcParameters colorProcParameters_aux,
CorrectionColorProc.ColorGainsParameters channelGainParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
Properties properties,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel) throws Exception
{
// 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;
final int debugLevelInner=clt_parameters.batch_run? -2: debugLevel;
this.startTime=System.nanoTime();
String [] sourceFiles=quadCLT_main.correctionsParameters.getSourcePaths();
QuadCLT.SetChannels [] set_channels_main = quadCLT_main.setChannels(debugLevel);
QuadCLT.SetChannels [] set_channels_aux = quadCLT_aux.setChannels(debugLevel);
if ((set_channels_main == null) || (set_channels_main.length==0) || (set_channels_aux == null) || (set_channels_aux.length==0)) {
System.out.println("No files to process (of "+sourceFiles.length+")");
return;
}
double [] referenceExposures_main = null;
double [] referenceExposures_aux = null;
if (!colorProcParameters.lwir_islwir) referenceExposures_main = quadCLT_main.eyesisCorrections.calcReferenceExposures(debugLevel);
if (!colorProcParameters_aux.lwir_islwir) referenceExposures_aux = quadCLT_aux.eyesisCorrections.calcReferenceExposures(debugLevel);
for (int nSet = 0; nSet < set_channels_main.length; nSet++){
// check it is the same set for both cameras
if (set_channels_aux.length <= nSet ) {
throw new Exception ("Set names for cameras do not match: main camera: '"+set_channels_main[nSet].name()+"', aux. camera: nothing");
}
if (!set_channels_main[nSet].name().equals(set_channels_aux[nSet].name())) {
throw new Exception ("Set names for cameras do not match: main camera: '"+set_channels_main[nSet].name()+"', aux. camera: '"+set_channels_main[nSet].name()+"'");
}
int [] channelFiles_main = set_channels_main[nSet].fileNumber();
int [] channelFiles_aux = set_channels_aux[nSet].fileNumber();
boolean [][] saturation_imp_main = (clt_parameters.sat_level > 0.0)? new boolean[channelFiles_main.length][] : null;
boolean [][] saturation_imp_aux = (clt_parameters.sat_level > 0.0)? new boolean[channelFiles_main.length][] : null;
double [] scaleExposures_main = new double[channelFiles_main.length];
double [] scaleExposures_aux = new double[channelFiles_main.length];
if (updateStatus) IJ.showStatus("Conditioning main camera image set for "+quadCLT_main.image_name);
ImagePlus [] imp_srcs_main = quadCLT_main.conditionImageSet(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
colorProcParameters, // ColorProcParameters colorProcParameters, //
sourceFiles, // String [] sourceFiles,
set_channels_main[nSet].name(), // String set_name,
referenceExposures_main, // double [] referenceExposures,
channelFiles_main, // int [] channelFiles,
scaleExposures_main, //output // double [] scaleExposures
saturation_imp_main, //output // boolean [][] saturation_imp,
debugLevelInner); // int debugLevel);
if (updateStatus) IJ.showStatus("Conditioning aux camera image set for "+quadCLT_main.image_name);
// optionally adjust main, aux (aux always will use main - calculate if needed
// Early main camera adjustment, rig data is not available
// with LWIR only 1 type of adjustments is possibkle - pre for main, post for aux. Combine configuration fields made for the 8-rig
int adjust_main = (quadCLT_main.correctionsParameters.rig_batch_adjust_main > quadCLT_main.correctionsParameters.rig_batch_adjust_main_gt)?
quadCLT_main.correctionsParameters.rig_batch_adjust_main : quadCLT_main.correctionsParameters.rig_batch_adjust_main_gt;
int adjust_aux = (quadCLT_main.correctionsParameters.rig_batch_adjust_aux > quadCLT_main.correctionsParameters.rig_batch_adjust_aux_gt)?
quadCLT_main.correctionsParameters.rig_batch_adjust_aux : quadCLT_main.correctionsParameters.rig_batch_adjust_aux_gt;
for (int num_adjust_main = 0; num_adjust_main < adjust_main; num_adjust_main++) {
if (updateStatus) IJ.showStatus("Building basic DSI for the main camera image set "+quadCLT_main.image_name+
", pass "+(num_adjust_main+1)+" of "+adjust_main);
if (debugLevel > -5) {
System.out.println("Building basic DSI for the main camera image set "+quadCLT_main.image_name+
", pass "+(num_adjust_main+1)+" of "+adjust_main);
}
quadCLT_main.preExpandCLTQuad3d( // returns ImagePlus, but it already should be saved/shown
imp_srcs_main, // [srcChannel], // should have properties "name"(base for saving results), "channel","path"
saturation_imp_main, // boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
debayerParameters,
colorProcParameters,
rgbParameters,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevelInner);
// adjust extrinsics here
System.out.println("Adjust main extrinsics here");
if (updateStatus) IJ.showStatus("Adjusting main camera image set for "+quadCLT_main.image_name+
", pass "+(num_adjust_main+1)+" of "+adjust_main);
if (debugLevel > -5) {
System.out.println("Adjusting main camera image set for "+quadCLT_main.image_name+
", pass "+(num_adjust_main+1)+" of "+adjust_main);
}
boolean ok = quadCLT_main.extrinsicsCLT(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
false, // adjust_poly,
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus,// final boolean updateStatus,
debugLevelInner); // final int debugLevel)
// clear memory for main
quadCLT_main.tp.resetCLTPasses();
if (!ok) break;
}
// Generate 4 main camera images and thumbnail
if (quadCLT_main.correctionsParameters.clt_batch_4img){
if (updateStatus) IJ.showStatus("Rendering 4 image set (disparity = 0) for "+quadCLT_main.image_name);
quadCLT_main.processCLTQuadCorr( // returns ImagePlus, but it already should be saved/shown
imp_srcs_main, // [srcChannel], // should have properties "name"(base for saving results), "channel","path"
saturation_imp_main, // boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
debayerParameters,
colorProcParameters,
channelGainParameters,
rgbParameters,
scaleExposures_main,
false, // calculate and apply additional fine geometry correction
false, // calculate and apply geometry correction at infinity
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
quadCLT_main.tp.resetCLTPasses();
}
if (quadCLT_main.correctionsParameters.clt_batch_explore) {
if (updateStatus) IJ.showStatus("Building basic DSI for the main camera image set "+quadCLT_main.image_name+" (after all adjustments)");
quadCLT_main.preExpandCLTQuad3d( // returns ImagePlus, but it already should be saved/shown
imp_srcs_main, // [srcChannel], // should have properties "name"(base for saving results), "channel","path"
saturation_imp_main, // boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
debayerParameters,
colorProcParameters,
rgbParameters,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevelInner);
if (updateStatus) IJ.showStatus("Expanding DSI for the main camera image set "+quadCLT_main.image_name+" (after all adjustments)");
quadCLT_main.expandCLTQuad3d( // returns ImagePlus, but it already should be saved/shown
clt_parameters,
debayerParameters,
colorProcParameters,
channelGainParameters,
rgbParameters,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
double [][] main_last_scan = quadCLT_main.tp.getShowDS(
quadCLT_main.tp.clt_3d_passes.get( quadCLT_main.tp.clt_3d_passes.size() -1),
false); // boolean force_final);
dsi[DSI_DISPARITY_MAIN] = main_last_scan[0];
dsi[DSI_STRENGTH_MAIN] = main_last_scan[1];
if (quadCLT_main.correctionsParameters.clt_batch_dsi) { // Should be always enabled ?
saveDSIMain ();
}
Runtime.getRuntime().gc();
System.out.println("--- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (quadCLT_main.correctionsParameters.clt_batch_surf) {
if (updateStatus) IJ.showStatus("Creating and filtering supertile plane surfaces from the DSI "+quadCLT_main.image_name);
quadCLT_main.tp.showPlanes(
clt_parameters,
quadCLT_main.geometryCorrection,
threadsMax,
updateStatus,
debugLevelInner);
if (quadCLT_main.correctionsParameters.clt_batch_assign) {
if (updateStatus) IJ.showStatus("Assigning tiles to candidate surfaces "+quadCLT_main.image_name);
double [][] assignments_dbg = quadCLT_main.tp.assignTilesToSurfaces(
clt_parameters,
quadCLT_main.geometryCorrection,
threadsMax,
updateStatus,
debugLevelInner);
if (assignments_dbg == null) continue;
dsi[DSI_DISPARITY_X3D] = assignments_dbg[TileSurface.ASGN_A_DISP];
// TODO use assignments_dbg
// generate ML data if enabled
/*
if (quadCLT_main.correctionsParameters.clt_batch_genMl) { // rig.ml_generate) { //clt_batch_genMl
outputMLData(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
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)
}
*/
// copy regardless of ML generation
// See if it will copy all files, not just the main camera ones
if (clt_parameters.rig.ml_copyJP4) {
copyJP4src(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
debugLevel); // final int debugLevel)
}
if (quadCLT_main.correctionsParameters.clt_batch_gen3d) {
if (updateStatus) IJ.showStatus("Generating and exporting 3D scene model "+quadCLT_main.image_name);
boolean ok = quadCLT_main.output3d(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
colorProcParameters, // EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
rgbParameters, // EyesisCorrectionParameters.RGBParameters rgbParameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevelInner); // final int debugLevel)
if (!ok) continue;
}
}
}
} else { // if (quadCLT_main.correctionsParameters.clt_batch_explore) {
int num_restored = restoreDSI(DSI_MAIN_SUFFIX); // "-DSI_COMBO", "-DSI_MAIN"
if (num_restored < 2) {
System.out.println("No DSI form the main camera is available. Please re-run with 'clt_batch_explore' enabled to generate it");
return;
}
}
// Process AUX (LWIR) camera data
// 1) Prepare DS for adjustments (just d/s, with ambiguous disparity tiles removed)
// 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(
main_ds, // double [][] ds,
quadCLT_main.getGeometryCorrection(), // GeometryCorrection geometryCorrection_main,
quadCLT_aux.getGeometryCorrection(), // GeometryCorrection geometryCorrection_aux,
clt_parameters,
false, // split_fg_bg,
true, // for_adjust,
debugLevel); // DEBUG_LEVEL); // int debug_level
double [][] ds_aux_ml = quadCLT_aux.depthMapMainToAux(
main_ds, // double [][] ds,
quadCLT_main.getGeometryCorrection(), // GeometryCorrection geometryCorrection_main,
quadCLT_aux.getGeometryCorrection(), // GeometryCorrection geometryCorrection_aux,
clt_parameters,
true, // split_fg_bg,
false, // for_adjust,
debugLevel); // int debug_level
ImagePlus [] imp_srcs_aux = quadCLT_aux.conditionImageSet(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
colorProcParameters_aux, // ColorProcParameters colorProcParameters, //
sourceFiles, // String [] sourceFiles,
set_channels_aux[nSet].name(), // String set_name,
referenceExposures_aux, // double [] referenceExposures,
channelFiles_aux, // int [] channelFiles,
scaleExposures_aux, //output // double [] scaleExposures
saturation_imp_aux, //output // boolean [][] saturation_imp,
debugLevelInner); // int debugLevel);
// optionally adjust AUX extrinsics (using quadCLT_aux.ds_from_main )
for (int num_adjust_aux = 0; num_adjust_aux < adjust_aux; num_adjust_aux++) {
if (updateStatus) IJ.showStatus("Building basic DSI for the AUX camera image set "+quadCLT_main.image_name+
" using main camera DSI, pass "+(num_adjust_aux+1)+" of "+num_adjust_aux);
if (debugLevel > -5) {
System.out.println("Building basic DSI for the AUX camera image set "+quadCLT_main.image_name+
" using main camera DSI, pass "+(num_adjust_aux+1)+" of "+num_adjust_aux);
}
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);
// adjust extrinsics here
System.out.println("Adjust AUX extrinsics here");
if (updateStatus) IJ.showStatus("Adjusting AUX camera image set for "+quadCLT_aux.image_name+
", pass "+(num_adjust_aux+1)+" of "+adjust_aux);
if (debugLevel > -5) {
System.out.println("Adjusting AUX camera image set for "+quadCLT_aux.image_name+
", pass "+(num_adjust_aux+1)+" of "+adjust_aux);
}
if (quadCLT_aux.ds_from_main == null) {
System.out.println("BUG: quadCLT_aux.ds_from_main should be not null here!");
// adjust w/o main camera - maybe will be used in the future
boolean ok = quadCLT_aux.extrinsicsCLT(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
false, // adjust_poly,
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus,// final boolean updateStatus,
debugLevelInner); // final int debugLevel)
if (!ok) break;
}
boolean ok = quadCLT_aux.extrinsicsCLTfromGT(
null,
quadCLT_aux.ds_from_main, // gt_disp_strength,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
false, // adjust_poly,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel + 2); // final int debugLevel)
// clear memory for AUX
quadCLT_aux.tp.resetCLTPasses();
if (!ok) break;
}
// Generate 4 AUX camera images and thumbnail
if (quadCLT_main.correctionsParameters.clt_batch_4img){
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
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,
channelGainParameters,
rgbParameters,
scaleExposures_aux,
false, // calculate and apply additional fine geometry correction
false, // calculate and apply geometry correction at infinity
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
quadCLT_aux.tp.resetCLTPasses();
}
// Currently - no LWIR 3D model generation, maybe it will be added later
// TODO: Add new ML generation here
if (quadCLT_main.correctionsParameters.clt_batch_save_extrinsics) {
saveProperties(
null, // String path, // full name with extension or w/o path to use x3d directory
null, // Properties properties, // if null - will only save extrinsics)
debugLevel);
}
if (quadCLT_main.correctionsParameters.clt_batch_save_all) {
saveProperties(
null, // String path, // full name with extension or w/o path to use x3d directory
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()+")");
if (quadCLT_aux.eyesisCorrections.stopRequested.get()>0) {
System.out.println("User requested stop");
System.out.println("Processing "+(nSet + 1)+" file sets (of "+set_channels_main.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
return;
}
}
System.out.println("processCLTQuadCorrs(): processing "+(quadCLT_main.getTotalFiles(set_channels_main)+quadCLT_aux.getTotalFiles(set_channels_aux))+" files ("+set_channels_main.length+" file sets) finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
}
public void saveDSI(
CLTParameters clt_parameters)
// CLTParameters clt_parameters
)
{
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_main.image_name+"-DSI_COMBO";
String title = quadCLT_main.image_name+DSI_COMBO_SUFFIX;
ImagePlus imp = (new ShowDoubleFloatArrays()).makeArrays(dsi,quadCLT_main.tp.getTilesX(), quadCLT_main.tp.getTilesY(), title, DSI_SLICES);
quadCLT_main.eyesisCorrections.saveAndShow(
imp, // ImagePlus imp,
......@@ -7757,13 +8136,80 @@ if (debugLevel > -100) return true; // temporarily !
false, // boolean show,
0); // int jpegQuality)
}
public void showDSI()
{
String title = quadCLT_main.image_name+"-DSI_COMBO";
String title = quadCLT_main.image_name+DSI_COMBO_SUFFIX;
(new ShowDoubleFloatArrays()).showArrays(dsi,quadCLT_main.tp.getTilesX(), quadCLT_main.tp.getTilesY(), true, title, DSI_SLICES);
}
public void saveDSIMain(
// CLTParameters clt_parameters
)
{
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_main.image_name+"-DSI_MAIN";
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(dsi_main,quadCLT_main.tp.getTilesX(), quadCLT_main.tp.getTilesY(), title, 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
quadCLT_main.correctionsParameters.x3dModelVersion,
true, // smart,
true); //newAllowed, // save
String file_path = x3d_path + Prefs.getFileSeparator() + quadCLT_main.image_name + suffix + ".tiff";
ImagePlus imp = null;
try {
imp = new ImagePlus(file_path);
} catch (Exception e) {
System.out.println ("Failed to open "+file_path);
return -1;
}
System.out.println("restoreDSI(): got "+imp.getStackSize()+" slices");
if (imp.getStackSize() < 2) {
System.out.println ("Failed to read "+file_path);
return -1;
}
int num_slices_read = 0;
ImageStack dsi_stack = imp.getStack();
for (int nl = 0; nl < imp.getStackSize(); nl++) {
for (int n = 0; n < DSI_SLICES.length; n++)
if (TwoQuadCLT.DSI_SLICES[n].equals(dsi_stack.getSliceLabel(nl + 1))) {
float [] fpixels = (float[]) dsi_stack.getPixels(nl + 1);
dsi[n] = new double [fpixels.length];
for (int i = 0; i < fpixels.length; i++) {
dsi[n][i] = fpixels[i];
}
num_slices_read ++;
break;
}
}
return num_slices_read;
}
public void showDSIMain()
{
String title = quadCLT_main.image_name+"-DSI_MAIN";
String [] titles = {DSI_SLICES[DSI_DISPARITY_MAIN], DSI_SLICES[DSI_STRENGTH_MAIN]};
double [][] dsi_main = {dsi[DSI_DISPARITY_MAIN], dsi[DSI_STRENGTH_MAIN]};
(new ShowDoubleFloatArrays()).showArrays(dsi_main,quadCLT_main.tp.getTilesX(), quadCLT_main.tp.getTilesY(), true, title, titles);
}
public double [][] getRigDSI(
String path_DSI, // Combo DSI path
boolean main) // false - rig
......
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