Commit a7a1e850 authored by Andrey Filippov's avatar Andrey Filippov

Debugging batch processing

parent cb61d659
......@@ -118,8 +118,11 @@ public class EyesisCorrectionParameters {
public String x3dSubdirSuffix= "";
// CLT 3d batch parameters
public int rig_batch_adjust_main = 0;
public int rig_batch_adjust_aux = 0;
public int rig_batch_adjust_rig = 0;
public boolean clt_batch_apply_man = true; // Apply (and disable) manual pixel shift
public boolean clt_batch_apply_man = false; // Apply (and disable) manual pixel shift
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
......@@ -240,6 +243,12 @@ public class EyesisCorrectionParameters {
cp.x3dSubdirPrefix= this.x3dSubdirPrefix;
cp.x3dModelVersion= this.x3dModelVersion;
cp.jp4SubDir= this.jp4SubDir;
cp.rig_batch_adjust_main= this.rig_batch_adjust_main;
cp.rig_batch_adjust_aux= this.rig_batch_adjust_aux;
cp.rig_batch_adjust_rig= this.rig_batch_adjust_rig;
cp.clt_batch_apply_man= this.clt_batch_apply_man;
cp.clt_batch_extrinsic= this.clt_batch_extrinsic;
cp.clt_batch_poly= this.clt_batch_poly;
......@@ -380,6 +389,10 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"mlDirectory", this.mlDirectory);
properties.setProperty(prefix+"rig_batch_adjust_main", this.rig_batch_adjust_main+"");
properties.setProperty(prefix+"rig_batch_adjust_aux", this.rig_batch_adjust_aux+"");
properties.setProperty(prefix+"rig_batch_adjust_rig", this.rig_batch_adjust_rig+"");
properties.setProperty(prefix+"clt_batch_apply_man", this.clt_batch_apply_man+"");
properties.setProperty(prefix+"clt_batch_extrinsic", this.clt_batch_extrinsic+"");
properties.setProperty(prefix+"clt_batch_poly", this.clt_batch_poly+"");
......@@ -517,6 +530,10 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"mlDirectory")!= null) this.mlDirectory=properties.getProperty(prefix+"mlDirectory");
if (properties.getProperty(prefix+"rig_batch_adjust_main")!=null) this.rig_batch_adjust_main=Integer.parseInt(properties.getProperty(prefix+"rig_batch_adjust_main"));
if (properties.getProperty(prefix+"rig_batch_adjust_aux")!=null) this.rig_batch_adjust_aux=Integer.parseInt(properties.getProperty(prefix+"rig_batch_adjust_aux"));
if (properties.getProperty(prefix+"rig_batch_adjust_rig")!=null) this.rig_batch_adjust_rig=Integer.parseInt(properties.getProperty(prefix+"rig_batch_adjust_rig"));
if (properties.getProperty(prefix+"clt_batch_apply_man")!= null) this.clt_batch_apply_man=Boolean.parseBoolean(properties.getProperty(prefix+"clt_batch_apply_man"));
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"));
......@@ -534,7 +551,6 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"thumb_size") !=null) this.thumb_size= Double.parseDouble(properties.getProperty(prefix+"thumb_size"));
if (properties.getProperty(prefix+"default_rating") !=null) this.default_rating= Integer.parseInt(properties.getProperty(prefix+"default_rating"));
// copy common parameters to the auxiliary camera ones
updateAuxFromMain();
String aux_prefix = prefix + AUX_PREFIX;
......@@ -853,6 +869,10 @@ public class EyesisCorrectionParameters {
gd.addTab ("Batch", "Select Batch parameters");
gd.addNumericField("Repeat main camera field adjustment", this.rig_batch_adjust_main, 0);
gd.addNumericField("Repeat aux camera field adjustment", this.rig_batch_adjust_aux, 0);
gd.addNumericField("Repeat 2-quad camera rig field adjustment", this.rig_batch_adjust_rig, 0);
gd.addCheckbox ("Apply (and disable) manual pixel shift", this.clt_batch_apply_man); // 21
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
......@@ -914,6 +934,10 @@ public class EyesisCorrectionParameters {
this.aux_camera.cltSuffix= gd.getNextString(); // 20b
this.aux_camera.x3dSubdirSuffix= gd.getNextString(); // 20ba
this.rig_batch_adjust_main = (int) gd.getNextNumber();
this.rig_batch_adjust_aux = (int) gd.getNextNumber();
this.rig_batch_adjust_rig = (int) gd.getNextNumber();
this.clt_batch_apply_man= gd.getNextBoolean(); // 21
this.clt_batch_extrinsic= gd.getNextBoolean(); // 22
this.clt_batch_poly= gd.getNextBoolean(); // 23
......
......@@ -585,19 +585,19 @@ private Panel panel1,
// addButton("CLT 2*4 images - 3", panelClt4, color_conf_process);
addButton("SHOW extrinsics", panelClt4, color_configure);
addButton("MAIN extrinsics", panelClt4, color_process);
addButton("RIG extrinsics", panelClt4, color_conf_process);
addButton("AUX extrinsics", panelClt4, color_process);
addButton("RIG extrinsics", panelClt4, color_conf_process);
addButton("Rig8 images", panelClt4, color_conf_process);
// addButton("Rig enhance", panelClt4, color_conf_process);
// /"Reset GT"
addButton("Reset GT", panelClt4, color_stop);
// addButton("Ground truth 0", panelClt4, color_configure);
addButton("Ground truth", panelClt4, color_conf_process);
addButton("Show biscan", panelClt4, color_configure);
addButton("Poles GT", panelClt4, color_process);
addButton("ML export", panelClt4, color_conf_process);
addButton("JP4 copy", panelClt4, color_conf_process);
addButton("Rig batch", panelClt4, color_process);
add(panelClt4);
......@@ -4556,17 +4556,11 @@ private Panel panel1,
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
getPairImages();
return;
/* ======================================================================== */
} else if (label.equals("CLT 2*4 images - 2")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
getPairImages2(false);
return;
/* ======================================================================== */
} else if (label.equals("Rig8 images")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
getPairImages2(true);
getPairImages2();
return;
/* ======================================================================== */
} else if (label.equals("RIG extrinsics")) {
......@@ -4615,17 +4609,10 @@ private Panel panel1,
return;
/* ======================================================================== */
} else if (label.equals("Ground truth 0")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
enhanceByRig(false);
return;
/* ======================================================================== */
} else if (label.equals("Ground truth")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
enhanceByRig(true);
groundTruth();
return;
/* ======================================================================== */
} else if (label.equals("Show biscan")) {
......@@ -4659,6 +4646,13 @@ private Panel panel1,
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
copyJP4src();
return;
/* ======================================================================== */
} else if (label.equals("Rig batch")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
CLT_PARAMETERS.batch_run = true;
batchRig();
return;
/* ======================================================================== */
} else if (label.equals("CLT rig edit")) {
......@@ -5015,12 +5009,11 @@ private Panel panel1,
return true;
}
public boolean getPairImages2( boolean new_mode) {
public boolean getPairImages2() {
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
if (new_mode) {
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Calculating combined correlations ++++++++++++++");
}
......@@ -5041,29 +5034,6 @@ private Panel panel1,
// TODO Auto-generated catch block
e.printStackTrace();
} //final int debugLevel);
} else {
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Calculating per quad camera correlations ++++++++++++++");
}
try {
TWO_QUAD_CLT.processCLTQuadCorrs(
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,
CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
CHANNEL_GAINS_PARAMETERS_AUX, //CorrectionColorProc.ColorGainsParameters channelGainParameters_aux,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
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
......@@ -5157,7 +5127,7 @@ private Panel panel1,
true,
PROPERTIES);
}
System.out.println("enhanceByRig(): Processing finished at "+
System.out.println("processPoles(): Processing finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+" sec, --- Free memory="+
Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
......@@ -5251,7 +5221,7 @@ private Panel panel1,
return true;
}
public boolean enhanceByRig( boolean use_planes) {
public boolean groundTruth() {
long startTime=System.nanoTime();
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
boolean OK = clt3d(
......@@ -5271,11 +5241,10 @@ private Panel panel1,
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Enhancing single-camera DSI by the dual-camera rig using planes ++++++++++++++");
}
TWO_QUAD_CLT.enhanceByRig( // actually there is no sense to process multiple image sets. Combine with other processing?
TWO_QUAD_CLT.groundTruth( // actually there is no sense to process multiple image sets. Combine with other processing?
QUAD_CLT, // QuadCLT quadCLT_main,
QUAD_CLT_AUX, // QuadCLT quadCLT_aux,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
use_planes, // final boolean use_planes,
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
DEBUG_LEVEL -2);
......@@ -5286,13 +5255,68 @@ private Panel panel1,
true,
PROPERTIES);
}
System.out.println("enhanceByRig(): Processing finished at "+
System.out.println("groundTruth(): Processing finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+" sec, --- Free memory="+
Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
return true;
}
public boolean batchRig() {
long startTime=System.nanoTime();
/* if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
boolean OK = clt3d(
false, // boolean adjust_extrinsics,
false); // boolean adjust_poly);
if (! OK) {
String msg = "DSI data is not available and \"CLT 3D\" failed";
IJ.showMessage("Error",msg);
System.out.println(msg);
return false;
}
}
*/
// load needed sensor and kernels files
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Running batch processing of dual-quad camera rig ++++++++++++++");
}
try {
TWO_QUAD_CLT.batchRig(
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,
CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
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;
}
public boolean exportMLData() {
long startTime=System.nanoTime();
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.rig_pre_poles_ds == null)) {
......
......@@ -5685,254 +5685,6 @@ public class QuadCLT {
System.out.println("No files to process (of "+sourceFiles.length+")");
return;
}
/*
boolean [] enabledFiles=new boolean[sourceFiles.length];
for (int i=0;i<enabledFiles.length;i++) enabledFiles[i]=false;
int numFilesToProcess=0;
int numImagesToProcess=0;
for (int nFile=0;nFile<enabledFiles.length;nFile++){
if ((sourceFiles[nFile]!=null) && (sourceFiles[nFile].length()>1)) {
int [] channels={correctionsParameters.getChannelFromSourceTiff(sourceFiles[nFile])};
if (correctionsParameters.isJP4()){
int subCamera= channels[0]- correctionsParameters.firstSubCamera; // to match those in the sensor files
// removeUnusedSensorData should be off!?
channels=this.eyesisCorrections.pixelMapping.channelsForSubCamera(subCamera);
}
if (channels!=null){
for (int i=0;i<channels.length;i++) if (eyesisCorrections.isChannelEnabled(channels[i])){
if (!enabledFiles[nFile]) numFilesToProcess++;
enabledFiles[nFile]=true;
numImagesToProcess++;
}
}
}
}
if (numFilesToProcess==0){
System.out.println("No files to process (of "+sourceFiles.length+")");
return;
} else {
if (debugLevel>0) System.out.println(numFilesToProcess+ " files to process (of "+sourceFiles.length+"), "+numImagesToProcess+" images to process");
}
double [] referenceExposures=eyesisCorrections.calcReferenceExposures(debugLevel); // multiply each image by this and divide by individual (if not NaN)
int [][] fileIndices=new int [numImagesToProcess][2]; // file index, channel number
int index=0;
for (int nFile=0;nFile<enabledFiles.length;nFile++){
if ((sourceFiles[nFile]!=null) && (sourceFiles[nFile].length()>1)) {
int [] channels={correctionsParameters.getChannelFromSourceTiff(sourceFiles[nFile])};
if (correctionsParameters.isJP4()){
int subCamera= channels[0]- correctionsParameters.firstSubCamera; // to match those in the sensor files
channels=eyesisCorrections.pixelMapping.channelsForSubCamera(subCamera);
}
if (channels!=null){
for (int i=0;i<channels.length;i++) if (eyesisCorrections.isChannelEnabled(channels[i])){
fileIndices[index ][0]=nFile;
fileIndices[index++][1]=channels[i];
}
}
}
}
ArrayList<String> setNames = new ArrayList<String>();
ArrayList<ArrayList<Integer>> setFiles = new ArrayList<ArrayList<Integer>>();
for (int iImage=0;iImage<fileIndices.length;iImage++){
int nFile=fileIndices[iImage][0];
String setName = correctionsParameters.getNameFromSourceTiff(sourceFiles[nFile]);
if (!setNames.contains(setName)) {
setNames.add(setName);
setFiles.add(new ArrayList<Integer>());
}
setFiles.get(setNames.indexOf(setName)).add(new Integer(nFile));
}
for (int nSet = 0; nSet < setNames.size(); nSet++){
int maxChn = 0;
for (int i = 0; i < setFiles.get(nSet).size(); i++){
int chn = fileIndices[setFiles.get(nSet).get(i)][1];
if (chn > maxChn) maxChn = chn;
}
int [] channelFiles = new int[maxChn+1];
for (int i =0; i < channelFiles.length; i++) channelFiles[i] = -1;
for (int i = 0; i < setFiles.get(nSet).size(); i++){
channelFiles[fileIndices[setFiles.get(nSet).get(i)][1]] = setFiles.get(nSet).get(i);
}
ImagePlus [] imp_srcs = new ImagePlus[channelFiles.length];
boolean [][] saturation_imp = (clt_parameters.sat_level > 0.0)? new boolean[channelFiles.length][] : null;
double [] scaleExposures = new double[channelFiles.length];
for (int srcChannel=0; srcChannel<channelFiles.length; srcChannel++){
int nFile=channelFiles[srcChannel];
imp_srcs[srcChannel]=null;
if (nFile >=0){
if (correctionsParameters.isJP4()){
int subchannel=eyesisCorrections.pixelMapping.getSubChannel(srcChannel);
if (this.correctionsParameters.swapSubchannels01) {
switch (subchannel){
case 0: subchannel=1; break;
case 1: subchannel=0; break;
}
}
if (debugLevel>0) System.out.println("Processing set " + setNames.get(nSet)+" channel "+srcChannel+" - subchannel "+subchannel+" of "+sourceFiles[nFile]);
ImagePlus imp_composite=eyesisCorrections.JP4_INSTANCE.open(
"", // path,
sourceFiles[nFile],
"", //arg - not used in JP46 reader
true, // un-apply camera color gains
null, // new window
false); // do not show
imp_srcs[srcChannel]=eyesisCorrections.JP4_INSTANCE.demuxImage(imp_composite, subchannel);
if (imp_srcs[srcChannel] == null) imp_srcs[srcChannel] = imp_composite; // not a composite image
// do we need to add any properties?
} else {
imp_srcs[srcChannel]=new ImagePlus(sourceFiles[nFile]);
// (new JP46_Reader_camera(false)).decodeProperiesFromInfo(imp_src); // decode existent properties from info
eyesisCorrections.JP4_INSTANCE.decodeProperiesFromInfo(imp_srcs[srcChannel]); // decode existent properties from info
if (debugLevel>0) System.out.println("Processing "+sourceFiles[nFile]);
}
scaleExposures[srcChannel] = 1.0;
if (!Double.isNaN(referenceExposures[nFile]) && (imp_srcs[srcChannel].getProperty("EXPOSURE")!=null)){
scaleExposures[srcChannel] = referenceExposures[nFile]/Double.parseDouble((String) imp_srcs[srcChannel].getProperty("EXPOSURE"));
if (debugLevel>0) System.out.println("Will scale intensity (to compensate for exposure) by "+scaleExposures[srcChannel]);
}
imp_srcs[srcChannel].setProperty("name", correctionsParameters.getNameFromSourceTiff(sourceFiles[nFile]));
imp_srcs[srcChannel].setProperty("channel", srcChannel); // it may already have channel
imp_srcs[srcChannel].setProperty("path", sourceFiles[nFile]); // it may already have channel
if (this.correctionsParameters.pixelDefects && (eyesisCorrections.defectsXY!=null)&& (eyesisCorrections.defectsXY[srcChannel]!=null)){
// apply pixel correction
int numApplied= eyesisCorrections.correctDefects(
imp_srcs[srcChannel],
srcChannel,
debugLevel);
if ((debugLevel>0) && (numApplied>0)) { // reduce verbosity after verified defect correction works
System.out.println("Corrected "+numApplied+" pixels in "+sourceFiles[nFile]);
}
}
float [] pixels=(float []) imp_srcs[srcChannel].getProcessor().getPixels();
int width = imp_srcs[srcChannel].getWidth();
int height = imp_srcs[srcChannel].getHeight();
if (clt_parameters.sat_level > 0.0){
double [] saturations = {
Double.parseDouble((String) imp_srcs[srcChannel].getProperty("saturation_1")),
Double.parseDouble((String) imp_srcs[srcChannel].getProperty("saturation_0")),
Double.parseDouble((String) imp_srcs[srcChannel].getProperty("saturation_3")),
Double.parseDouble((String) imp_srcs[srcChannel].getProperty("saturation_2"))};
saturation_imp[srcChannel] = new boolean[width*height];
System.out.println(String.format("channel %d saturations = %6.2f %6.2f %6.2f %6.2f", srcChannel,
saturations[0],saturations[1],saturations[2],saturations[3]));
double [] scaled_saturations = new double [saturations.length];
for (int i = 0; i < scaled_saturations.length; i++){
scaled_saturations[i] = saturations[i] * clt_parameters.sat_level;
}
for (int y = 0; y < height-1; y+=2){
for (int x = 0; x < width-1; x+=2){
if (pixels[y*width+x ] > scaled_saturations[0]) saturation_imp[srcChannel][y*width+x ] = true;
if (pixels[y*width+x+ 1] > scaled_saturations[1]) saturation_imp[srcChannel][y*width+x +1] = true;
if (pixels[y*width+x+width ] > scaled_saturations[2]) saturation_imp[srcChannel][y*width+x+width ] = true;
if (pixels[y*width+x+width+1] > scaled_saturations[3]) saturation_imp[srcChannel][y*width+x+width+1] = true;
}
}
if (debugLevel>0) {
double [] max_pix= {0.0, 0.0, 0.0, 0.0};
for (int y = 0; y < height-1; y+=2){
for (int x = 0; x < width-1; x+=2){
if (pixels[y*width+x ] > max_pix[0]) max_pix[0] = pixels[y*width+x ];
if (pixels[y*width+x+ 1] > max_pix[1]) max_pix[1] = pixels[y*width+x+ 1];
if (pixels[y*width+x+width ] > max_pix[2]) max_pix[2] = pixels[y*width+x+width ];
if (pixels[y*width+x+width+1] > max_pix[3]) max_pix[3] = pixels[y*width+x+width+1];
}
}
System.out.println(String.format("channel %d max_pix[] = %6.2f %6.2f %6.2f %6.2f", srcChannel, max_pix[0], max_pix[1], max_pix[2], max_pix[3]));
}
}
if (this.correctionsParameters.vignetting){
if ((eyesisCorrections.channelVignettingCorrection==null) || (srcChannel<0) || (srcChannel>=eyesisCorrections.channelVignettingCorrection.length) || (eyesisCorrections.channelVignettingCorrection[srcChannel]==null)){
System.out.println("No vignetting data for channel "+srcChannel);
return;
}
/// float [] pixels=(float []) imp_srcs[srcChannel].getProcessor().getPixels();
if (pixels.length!=eyesisCorrections.channelVignettingCorrection[srcChannel].length){
System.out.println("Vignetting data for channel "+srcChannel+" has "+eyesisCorrections.channelVignettingCorrection[srcChannel].length+" pixels, image "+sourceFiles[nFile]+" has "+pixels.length);
return;
}
// TODO: Move to do it once:
double min_non_zero = 0.0;
for (int i=0;i<pixels.length;i++){
double d = eyesisCorrections.channelVignettingCorrection[srcChannel][i];
if ((d > 0.0) && ((min_non_zero == 0) || (min_non_zero > d))){
min_non_zero = d;
}
}
double max_vign_corr = clt_parameters.vignetting_range*min_non_zero;
System.out.println("Vignetting data: channel="+srcChannel+", min = "+min_non_zero);
for (int i=0;i<pixels.length;i++){
double d = eyesisCorrections.channelVignettingCorrection[srcChannel][i];
if (d > max_vign_corr) d = max_vign_corr;
pixels[i]*=d;
}
// Scale here, combine with vignetting later?
/// int width = imp_srcs[srcChannel].getWidth();
/// int height = imp_srcs[srcChannel].getHeight();
for (int y = 0; y < height-1; y+=2){
for (int x = 0; x < width-1; x+=2){
pixels[y*width+x ] *= clt_parameters.scale_g;
pixels[y*width+x+width+1] *= clt_parameters.scale_g;
pixels[y*width+x +1] *= clt_parameters.scale_r;
pixels[y*width+x+width ] *= clt_parameters.scale_b;
}
}
} else { // assuming GR/BG pattern
System.out.println("Applying fixed color gain correction parameters: Gr="+
clt_parameters.novignetting_r+", Gg="+clt_parameters.novignetting_g+", Gb="+clt_parameters.novignetting_b);
/// float [] pixels=(float []) imp_srcs[srcChannel].getProcessor().getPixels();
/// int width = imp_srcs[srcChannel].getWidth();
/// int height = imp_srcs[srcChannel].getHeight();
double kr = clt_parameters.scale_r/clt_parameters.novignetting_r;
double kg = clt_parameters.scale_g/clt_parameters.novignetting_g;
double kb = clt_parameters.scale_b/clt_parameters.novignetting_b;
for (int y = 0; y < height-1; y+=2){
for (int x = 0; x < width-1; x+=2){
pixels[y*width+x ] *= kg;
pixels[y*width+x+width+1] *= kg;
pixels[y*width+x +1] *= kr;
pixels[y*width+x+width ] *= kb;
}
}
}
}
}
System.out.println("Temporarily applying scaleExposures[] here" );
for (int srcChannel=0; srcChannel<channelFiles.length; srcChannel++){
float [] pixels=(float []) imp_srcs[srcChannel].getProcessor().getPixels();
for (int i = 0; i < pixels.length; i++){
pixels[i] *= scaleExposures[srcChannel];
}
scaleExposures[srcChannel] = 1.0;
}
// once per quad here
// may need to equalize gains between channels
if (clt_parameters.gain_equalize || clt_parameters.colors_equalize){
channelGainsEqualize(
clt_parameters.gain_equalize,
clt_parameters.colors_equalize,
clt_parameters.nosat_equalize, // boolean nosat_equalize,
channelFiles,
imp_srcs,
saturation_imp, // boolean[][] saturated,
setNames.get(nSet), // just for debug messages == setNames.get(nSet)
debugLevel);
}
*/
double [] referenceExposures=eyesisCorrections.calcReferenceExposures(debugLevel); // multiply each image by this and divide by individual (if not NaN)
for (int nSet = 0; nSet < set_channels.length; nSet++){
int [] channelFiles = set_channels[nSet].fileNumber();
......@@ -5950,11 +5702,6 @@ public class QuadCLT {
debugLevel); // int debugLevel);
// once per quad here
preExpandCLTQuad3d( // returns ImagePlus, but it already should be saved/shown
imp_srcs, // [srcChannel], // should have properties "name"(base for saving results), "channel","path"
......
......@@ -110,6 +110,13 @@ public class TileProcessor {
clt_3d_passes = new ArrayList<CLTPass3d>();
clt_3d_passes_size = 0;
clt_3d_passes_rig_size = 0;
rig_disparity_strength = null; // invalidate
rig_pre_poles_ds = null;
rig_post_poles_ds = null;
rig_pre_poles_sel = null;
rig_post_poles_sel = null;
clt_3d_passes_rig_size = 0;
Runtime runtime = Runtime.getRuntime();
runtime.gc();
System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
......
......@@ -274,8 +274,8 @@ public class TwoQuadCLT {
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
// final boolean batch_mode = clt_parameters.batch_run; //disable any debug images
boolean batch_mode = false;
final boolean batch_mode = clt_parameters.batch_run; //disable any debug images
// boolean batch_mode = false;
boolean infinity_corr = false;
double [][] scaleExposures= {scaleExposures_main, scaleExposures_aux};
boolean toRGB= quadCLT_main.correctionsParameters.toRGB;
......@@ -1311,11 +1311,10 @@ if (debugLevel > -100) return true; // temporarily !
// improve DSI acquired for a single camera by use of a pair
// Run this after "CLT 3D"
public void enhanceByRig(
public void groundTruth(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
EyesisCorrectionParameters.CLTParameters clt_parameters,
final boolean use_planes,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)// throws Exception
......@@ -1332,7 +1331,6 @@ if (debugLevel > -100) return true; // temporarily !
double [][] rig_disparity_strength = quadCLT_main.getGroundTruthByRig(); // saved pair
if (rig_disparity_strength == null) {
if (use_planes) {
rig_disparity_strength = groundTruthByRigPlanes(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
......@@ -1340,15 +1338,6 @@ if (debugLevel > -100) return true; // temporarily !
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
} else {
rig_disparity_strength = groundTruthByRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
}
if (rig_disparity_strength != null) {
quadCLT_main.tp.rig_disparity_strength = rig_disparity_strength;
}
......@@ -1706,12 +1695,33 @@ if (debugLevel > -100) return true; // temporarily !
String [] sourceFiles_main=quadCLT_main.correctionsParameters.getSourcePaths();
//
// String [] sourceFiles_aux=quadCLT_main.correctionsParameters.getSourcePaths();
String set_name = quadCLT_main.image_name;
if (set_name == null ) {
QuadCLT.SetChannels [] set_channels=quadCLT_main.setChannels(debugLevel);
set_name = set_channels[0].set_name;
}
QuadCLT.SetChannels [] set_channels_main = quadCLT_main.setChannels(set_name,debugLevel); // only for specified image timestamp
QuadCLT.SetChannels [] set_channels_aux = quadCLT_aux.setChannels(set_name,debugLevel);
ArrayList<String> path_list = new ArrayList<String>();
for (int i = 0; i < set_channels_main.length; i++) {
for (int fn:set_channels_main[i].file_number) {
path_list.add(sourceFiles_main[fn]);
}
}
for (int i = 0; i < set_channels_aux.length; i++) {
for (int fn:set_channels_aux[i].file_number) {
path_list.add(sourceFiles_main[fn]);
}
}
if (quadCLT_main.gps_lla != null) {
String kml_copy_dir= quadCLT_main.correctionsParameters.selectX3dDirectory(
set_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
......@@ -1738,7 +1748,8 @@ if (debugLevel > -100) return true; // temporarily !
dir.mkdirs();
System.out.println("Created "+dir);
}
for (String fname:sourceFiles_main) {
for (String fname:path_list) {
if (fname.contains(quadCLT_main.image_name)) { // only files containing set name // TODO:improve
File file = new File(fname);
try {
Files.copy(
......@@ -1751,7 +1762,8 @@ if (debugLevel > -100) return true; // temporarily !
System.out.println("Failed to copy "+fname+" -> "+dir);
}
}
// 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");
}
......@@ -3842,615 +3854,141 @@ if (debugLevel > -100) return true; // temporarily !
public double [][] groundTruthByRig(
public double [][] fillPoorTextureByInter(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
EyesisCorrectionParameters.CLTParameters clt_parameters,
double [][] disparity_bimap,
BiCamDSI biCamDSI,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel) // throws Exception
final int debugLevel)// throws Exception
{
int refine_inter = 2; // 3; // 3 - dx, 2 - disparity
System.out.println("enhanceByRig()");
if ((quadCLT_main == null) || (quadCLT_aux == null)) {
System.out.println("QuadCLT instances are not initilaized");
return null;
}
// verify main camera has measured data
// Measure with target disparity == 0
if ((quadCLT_main.tp == null) || (quadCLT_main.tp.clt_3d_passes == null) || (quadCLT_main.tp.clt_3d_passes.size() ==0)){
System.out.println("No DSI data for the main camera is available. Please run \"CLT 3D\" command");
return null;
}
// See if auxiliary camera has images configured, if not - do it now. First need to get image name
if (quadCLT_aux.image_name ==null) {
// String image_name = quadCLT_main.image_name;
String [] sourceFiles=quadCLT_main.correctionsParameters.getSourcePaths();
QuadCLT.SetChannels [] set_channels_aux = quadCLT_aux.setChannels(quadCLT_main.image_name, debugLevel);
if ((set_channels_aux == null) || (set_channels_aux.length==0)) {
System.out.println("No files for the auxiliary camera match series "+quadCLT_main.image_name);
return null;
}
double [] referenceExposures_aux = quadCLT_aux.eyesisCorrections.calcReferenceExposures(debugLevel); // multiply each image by this and divide by individual (if not NaN)
int [] channelFiles_aux = set_channels_aux[0].fileNumber();
// make single
boolean [][] saturation_aux = (clt_parameters.sat_level > 0.0)? new boolean[channelFiles_aux.length][] : null;
double [] scaleExposures_aux = new double[channelFiles_aux.length];
ImagePlus [] imp_srcs_aux = quadCLT_aux.conditionImageSet(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
sourceFiles, // String [] sourceFiles,
quadCLT_main.image_name, // set_channels_aux[0].name(), // String set_name,
referenceExposures_aux, // double [] referenceExposures,
channelFiles_aux, // int [] channelFiles,
scaleExposures_aux, //output // double [] scaleExposures
saturation_aux, //output // boolean [][] saturation_imp,
debugLevel); // int debugLevel);
final int refine_inter = 2; // use inter-cam disparity for refinement
final int tilesX = quadCLT_main.tp.getTilesX();
// final int tilesY = quadCLT_main.tp.getTilesY();
double [] suggestedLTMeasurements = biCamDSI.suggestLTTiles(
disparity_bimap, // double [][] disparity_bimap,
null, // boolean [] trusted, // may be null if disparity is alreasdy NaN-ed
clt_parameters.rig.lt_min_disparity, // double min_disparity, // = 0.0; // apply low texture to near objects
clt_parameters.rig.lt_trusted_strength, // double trusted_strength, // = 0.2; // strength sufficient without neighbors
clt_parameters.rig.lt_strength_rfloor, // double strength_rfloor, // = 0.28; // strength floor relative to trusted_strength
clt_parameters.rig.lt_need_friends, // double need_friends, // = 0.4; // strength sufficient with neighbors support, fraction of lt_trusted_strength
clt_parameters.rig.lt_extend_dist, // int extend_dist, // = 3; // how far to extend around known tiles (probably should increase this value up to?
// dealing with neighbors variance
clt_parameters.rig.lt_wsigma, // double wsigma, // = 1.0; // influence of far neighbors diminish as a Gaussian with this sigma
clt_parameters.rig.lt_max_asigma, // double max_asigma, // = .15; // Maximal acceptable standard deviation of the neighbors (remove, then add)
clt_parameters.rig.lt_max_rsigma, // double max_rsigma, // = .05; // Maximal acceptable standard deviation of the neighbors (remove, then add)
debugLevel); // int debugLevel
double [][][] double_stacks_aux = new double [imp_srcs_aux.length][][];
for (int i = 0; i < double_stacks_aux.length; i++){
double_stacks_aux[i] = quadCLT_aux.eyesisCorrections.bayerToDoubleStack(
imp_srcs_aux[i], // source Bayer image, linearized, 32-bit (float))
null); // no margins, no oversample
}
for (int i = 0; i < double_stacks_aux.length; i++){
for (int j =0 ; j < double_stacks_aux[i][0].length; j++){
double_stacks_aux[i][2][j]*=0.5; // Scale green 0.5 to compensate more pixels than R,B
}
}
quadCLT_aux.setTiles (imp_srcs_aux[0], // set global tp.tilesX, tp.tilesY
clt_parameters,
threadsMax);
quadCLT_aux.image_name = quadCLT_main.image_name;
quadCLT_aux.image_data = double_stacks_aux;
quadCLT_aux.saturation_imp = saturation_aux;
quadCLT_aux.tp.setTrustedCorrelation(clt_parameters.grow_disp_trust);
quadCLT_aux.tp.resetCLTPasses();
}
//Re-measure background
final int tilesX = quadCLT_main.tp.getTilesX();
final int tilesY = quadCLT_main.tp.getTilesY();
double [][] disparity_bimap_infinity = measureNewRigDisparity(
double [][] disparity_bimap_lt = setBimapFromDisparityNaN(
suggestedLTMeasurements, // double [] disparity,
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
null, // double [][] src_bimap, // current state of measurements (or null for new measurement)
0, // double disparity,
null, // ArrayList<Integer> tile_list, // or null. If non-null - do not remeasure members of the list
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
false, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
0, // final int // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
// use default mode:
// first measurement - use default value:
clt_parameters.rig.no_int_x0, // boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
int [] num_new = new int[1];
boolean [] trusted_infinity = getTrustedDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters.rig.min_trusted_strength, // double min_combo_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity, // 4.0 -> change to rig_trust
clt_parameters.rig.trusted_tolerance, // double trusted_tolerance,
null, // boolean [] was_trusted,
disparity_bimap_infinity ); // double [][] bimap // current state of measurements
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){
if (clt_parameters.show_map && (debugLevel > -2) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap_infinity,
disparity_bimap_lt,
tilesX,
disparity_bimap_infinity[0].length/tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"DISP_MAP-INFINITY",
quadCLT_main.image_name+"NEW_LT_MEASURED",
ImageDtt.BIDISPARITY_TITLES);
}
// refine just the new suggested measurements
double [][] prev_bimap = null;
double [] scale_bad = new double [trusted_infinity.length];
int [] num_new = new int[1];
double [] scale_bad = new double [suggestedLTMeasurements.length];
for (int i = 0; i < scale_bad.length; i++) scale_bad[i] = 1.0;
for (int nref = 0; nref < clt_parameters.rig.num_inf_refine; nref++) {
prev_bimap = null;
boolean [] trusted_lt = null;
for (int nref = 0; nref < clt_parameters.rig.num_near_refine; nref++) {
// refine infinity using inter correlation
double [][] disparity_bimap_new = refineRigSel(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
disparity_bimap_infinity, // double [][] src_bimap, // current state of measurements (or null for new measurement)
disparity_bimap_lt, // double [][] src_bimap, // current state of measurements (or null for new measurement)
prev_bimap, // double [][] prev_bimap, // previous state of measurements or null
scale_bad, // double [] scale_bad,
refine_inter, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
false, // boolean keep_inf, // keep expected disparity 0.0 if it was so
0.0, // clt_parameters.rig.refine_min_strength , // double refine_min_strength, // do not refine weaker tiles
clt_parameters.rig.refine_tolerance , // double refine_tolerance, // do not refine if absolute disparity below
trusted_infinity, // tile_list, // ArrayList<Integer> tile_list, // or null
trusted_lt, // null, // trusted_lt, // tile_list, // ArrayList<Integer> tile_list, // or null
num_new, // int [] num_new,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
false, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
0, // final int // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
// refine mode - disable window preset:
// in refine mode disable int preset of the window
true, // boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
prev_bimap = disparity_bimap_infinity;
disparity_bimap_infinity = disparity_bimap_new;
trusted_infinity = getTrustedDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters.rig.min_trusted_strength, // double min_combo_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity, // 4.0 -> change to rig_trust
clt_parameters.rig.trusted_tolerance, // double trusted_tolerance,
trusted_infinity, // null, // boolean [] was_trusted,
disparity_bimap_infinity ); // double [][] bimap // current state of measurements
prev_bimap = disparity_bimap_lt;
disparity_bimap_lt = disparity_bimap_new;
//low texture may have very poor individual correlations, do not check them at all
trusted_lt = getTrustedDisparityInter(
0.0, // clt_parameters.rig.lt_trusted_strength*clt_parameters.rig.lt_need_friends, // double min_inter_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity,
trusted_lt, // boolean [] was_trusted,
disparity_bimap_lt ); // double [][] bimap // current state of measurements
if (debugLevel > -2) {
System.out.println("enhanceByRig(): refined (infinity) "+num_new[0]+" tiles");
System.out.println("enhanceByRig(): refined (lt) "+num_new[0]+" tiles");
}
if (num_new[0] < clt_parameters.rig.min_new) break;
}
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){
for (int layer = 0; layer < disparity_bimap_infinity.length; layer ++) if (disparity_bimap_infinity[layer] != null){
for (int nTile = 0; nTile < disparity_bimap_infinity[layer].length; nTile++) {
if (!trusted_infinity[nTile]) disparity_bimap_infinity[layer][nTile] = Double.NaN;
}
}
if (scale_bad!= null) {
int num_bad = 0, num_trusted = 0;
for (int nTile = 0; nTile < scale_bad.length; nTile++) {
if (!trusted_infinity[nTile]) scale_bad[nTile] = Double.NaN;
else {
if (scale_bad[nTile] < 1.0) num_bad++;
scale_bad[nTile] = -scale_bad[nTile];
num_trusted ++;
trusted_lt = getTrustedDisparityInter(
clt_parameters.rig.lt_trusted_strength*clt_parameters.rig.lt_need_friends, // double min_inter_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity,
trusted_lt, // boolean [] was_trusted,
disparity_bimap_lt ); // double [][] bimap // current state of measurements
}
}
System.out.println("num_trusted = "+num_trusted+", num_bad = "+num_bad);
(new showDoubleFloatArrays()).showArrays(
scale_bad,
tilesX,
disparity_bimap_infinity[0].length/tilesX,
quadCLT_main.image_name+"-INFINITY-SCALE_BAD"+clt_parameters.disparity);
}
if (clt_parameters.show_map && (debugLevel > -2) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap_infinity,
disparity_bimap_lt,
tilesX,
disparity_bimap_infinity[0].length/tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"-INFINITY-REFINED-TRUSTED"+clt_parameters.disparity,
quadCLT_main.image_name+"NEW_LT_REFINED",
ImageDtt.BIDISPARITY_TITLES);
}
// Get DSI from the main camera
quadCLT_main.tp.trimCLTPasses(false); // remove rig composite scan if any
// last but not including any rid data
CLTPass3d scan_last = quadCLT_main.tp.clt_3d_passes.get( quadCLT_main.tp.clt_3d_passes_size -1); // get last one
double [][] disparity_bimap = setBimapFromCLTPass3d(
scan_last, // CLTPass3d scan,
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
// int [] num_new = new int[1];
boolean [] trusted_near = getTrustedDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
0.5*clt_parameters.rig.min_trusted_strength, // double min_combo_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity, // 4.0 -> change to rig_trust
clt_parameters.rig.trusted_tolerance, // double trusted_tolerance,
null, // boolean [] was_trusted,
disparity_bimap); // double [][] bimap // current state of measurements
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){
// combine new measured results with the previously known (new overwrites old
for (int nTile = 0; nTile < disparity_bimap_lt[0].length; nTile++) {
// if (trusted_lt[nTile] &&
// (!trusted_near[nTile] ||
// (disparity_bimap_infinity[ImageDtt.BI_STR_ALL_INDEX][nTile] > disparity_bimap[ImageDtt.BI_STR_ALL_INDEX][nTile]))) {
// start with unconditional use of new
if (trusted_lt[nTile]) {
for (int i = 0; i < disparity_bimap.length; i++) if (disparity_bimap!=null) {
disparity_bimap[i][nTile] = disparity_bimap_lt[i][nTile];
}
// trusted_near[nTile] = true;
}
}
if (clt_parameters.show_map && (debugLevel > -2) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
disparity_bimap_lt,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"DISP_MAP-NONINFINITY",
quadCLT_main.image_name+"DSI_ADDED",
ImageDtt.BIDISPARITY_TITLES);
}
for (int i = 0; i < scale_bad.length; i++) scale_bad[i] = 1.0;
prev_bimap = null;
for (int nref = 0; nref < clt_parameters.rig.num_near_refine; nref++) {
// refine infinity using inter correlation
double [][] disparity_bimap_new = refineRigSel(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
disparity_bimap, // double [][] src_bimap, // current state of measurements (or null for new measurement)
prev_bimap, // double [][] prev_bimap, // previous state of measurements or null
scale_bad, // double [] scale_bad,
refine_inter, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
false, // boolean keep_inf, // keep expected disparity 0.0 if it was so
0.0, // clt_parameters.rig.refine_min_strength , // double refine_min_strength, // do not refine weaker tiles
clt_parameters.rig.refine_tolerance , // double refine_tolerance, // do not refine if absolute disparity below
trusted_near, // tile_list, // ArrayList<Integer> tile_list, // or null
num_new, // int [] num_new,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
false, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
0, // final int // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
// disable window preset in refine mode
true, // boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
prev_bimap = disparity_bimap;
disparity_bimap = disparity_bimap_new;
trusted_near = getTrustedDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters.rig.min_trusted_strength, // double min_combo_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity, // 4.0 -> change to rig_trust
clt_parameters.rig.trusted_tolerance, // double trusted_tolerance,
trusted_near, // null, // boolean [] was_trusted,
disparity_bimap ); // double [][] bimap // current state of measurements
if (debugLevel > -2) {
System.out.println("enhanceByRig(): refined (near) "+num_new[0]+" tiles");
}
if (num_new[0] < clt_parameters.rig.min_new) break;
}
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){
for (int layer = 0; layer < disparity_bimap.length; layer ++) if (disparity_bimap[layer] != null){
for (int nTile = 0; nTile < disparity_bimap[layer].length; nTile++) {
if (!trusted_near[nTile]) disparity_bimap[layer][nTile] = Double.NaN;
}
}
if (scale_bad!= null) {
int num_bad = 0, num_trusted = 0;
for (int nTile = 0; nTile < scale_bad.length; nTile++) {
if (!trusted_near[nTile]) scale_bad[nTile] = Double.NaN;
else {
if (scale_bad[nTile] < 1.0) num_bad++;
scale_bad[nTile] = -scale_bad[nTile];
num_trusted ++;
}
}
System.out.println("num_trusted = "+num_trusted+", num_bad = "+num_bad);
(new showDoubleFloatArrays()).showArrays(
scale_bad,
tilesX,
disparity_bimap[0].length/tilesX,
quadCLT_main.image_name+"-NEAR-SCALE_BAD"+clt_parameters.disparity);
}
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"-NEAR-REFINED-TRUSTED"+clt_parameters.disparity,
ImageDtt.BIDISPARITY_TITLES);
}
// Combine infinity and non-infinity
for (int nTile = 0; nTile < disparity_bimap[0].length; nTile++) {
if (trusted_infinity[nTile] &&
(!trusted_near[nTile] ||
(disparity_bimap_infinity[ImageDtt.BI_STR_ALL_INDEX][nTile] > disparity_bimap[ImageDtt.BI_STR_ALL_INDEX][nTile]))) {
for (int i = 0; i < disparity_bimap.length; i++) if (disparity_bimap_infinity[i]!=null) {
disparity_bimap[i][nTile] = disparity_bimap_infinity[i][nTile];
}
trusted_near[nTile] = true;
}
}
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"DSI_ALL",
ImageDtt.BIDISPARITY_TITLES);
for (int layer = 0; layer < disparity_bimap.length; layer ++) if (disparity_bimap[layer] != null){
for (int nTile = 0; nTile < disparity_bimap[layer].length; nTile++) {
if (!trusted_near[nTile]) disparity_bimap[layer][nTile] = Double.NaN;
}
}
for (int layer:ImageDtt.BIDISPARITY_STRENGTHS) if (disparity_bimap[layer] != null){
for (int nTile = 0; nTile < disparity_bimap[layer].length; nTile++) {
if (!trusted_near[nTile]) disparity_bimap[layer][nTile] = 0.0;
}
}
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"-DSI-ALL-TRUSTED"+clt_parameters.disparity,
ImageDtt.BIDISPARITY_TITLES);
}
// repeat multiple times (need to compare added tiles (after cleanup? - return number of tiles after cleanu-up and compare improvements)
int num_trusted = 0;
// final int tilesX = quadCLT_main.tp.getTilesX();
// final int tilesY = quadCLT_main.tp.getTilesY();
// grow around using all camera and inter-camera correlations (try to get low-textured,like our street pavement)
BiCamDSI biCamDSI = new BiCamDSI( tilesX, tilesY,threadsMax);
int min_added_tiles = clt_parameters.rig.lt_min_new;
for (int num_fill = 0; num_fill < clt_parameters.rig.lt_repeat; num_fill++) {
int num_new_trusted = biCamDSI.removeLTUntrusted(
disparity_bimap, // double [][] disparity_bimap,
clt_parameters.rig.lt_min_disparity, // double min_disparity, // = 0.0; // apply low texture to near objects
clt_parameters.rig.lt_trusted_strength, // double trusted_strength, // = 0.2; // strength sufficient without neighbors
clt_parameters.rig.lt_need_friends, // double need_friends, // = 0.4; // strength sufficient with neighbors support, fraction of lt_trusted_strength
clt_parameters.rig.lt_friends_diff, // double friends_diff, // = 0.2; // pix difference to neighbors to be considered a match (TODO: use tilted)
clt_parameters.rig.lt_friends_rdiff, // double friends_rdiff, // = 0.04; // additional relative pix per pixel of disparity
clt_parameters.rig.lt_min_friends_any, // int min_friends_any, // = 2; // minimal number of even weak friends
clt_parameters.rig.lt_min_friends_trusted, // int min_friends_trusted, // = 2; // minimal number of trusted (strong or already confirmed)
clt_parameters.rig.lt_friends_dist, // int friends_dist, // = 3; // how far to look for friends
debugLevel); // int debugLevel
if ((num_new_trusted - num_trusted) < min_added_tiles) {
if (debugLevel > -2) {
System.out.println("enhanceByRig(): pass="+num_fill+", number of added tiles = "+(num_new_trusted - num_trusted)+" < " +min_added_tiles+", done adding");
break;
}
} else {
if (debugLevel > -2) {
System.out.println("enhanceByRig(): pass="+num_fill+", number of added tiles = "+(num_new_trusted - num_trusted));
}
}
num_trusted = num_new_trusted;
disparity_bimap = fillPoorTextureByInter(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
disparity_bimap, //double [][] disparity_bimap,
biCamDSI, // BiCamDSI biCamDSI,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel-2); // final int debugLevel)// throws Exception
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){ //OK
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"DSI_LT-N"+num_fill,
ImageDtt.BIDISPARITY_TITLES);
}
}
int num_new_trusted = biCamDSI.removeLTUntrusted(
disparity_bimap, // double [][] disparity_bimap,
clt_parameters.rig.lt_min_disparity, // double min_disparity, // = 0.0; // apply low texture to near objects
clt_parameters.rig.lt_trusted_strength, // double trusted_strength, // = 0.2; // strength sufficient without neighbors
clt_parameters.rig.lt_need_friends, // double need_friends, // = 0.4; // strength sufficient with neighbors support, fraction of lt_trusted_strength
clt_parameters.rig.lt_friends_diff, // double friends_diff, // = 0.2; // pix difference to neighbors to be considered a match (TODO: use tilted)
clt_parameters.rig.lt_friends_rdiff, // double friends_rdiff, // = 0.04; // additional relative pix per pixel of disparity
clt_parameters.rig.lt_min_friends_any, // int min_friends_any, // = 2; // minimal number of even weak friends
clt_parameters.rig.lt_min_friends_trusted, // int min_friends_trusted, // = 2; // minimal number of trusted (strong or already confirmed)
clt_parameters.rig.lt_friends_dist, // int friends_dist, // = 3; // how far to look for friends
debugLevel); // int debugLevel
if (clt_parameters.show_map && (debugLevel > -2) && clt_parameters.rig.rig_mode_debug){ //OK
System.out.println("There are total "+num_new_trusted+" trusted tiles in ground truth data");
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"DSI_LT-FINAL",
ImageDtt.BIDISPARITY_TITLES);
}
if (clt_parameters.rig.lt_remove_stray) {
int num_stray_removed = biCamDSI.removeFalseMatches(
disparity_bimap, // double [][] disparity_bimap,
clt_parameters.rig.lt_trusted_strength, //double trusted_strength, // = 0.2; // strength sufficient without neighbors
clt_parameters.rig.lt_stray_rstrength, // double stray_rstrength, // = 2.0; // Relative to trusted strength - trust above that
clt_parameters.rig.lt_strength_rfloor, // double strength_rfloor, // = 0.28; // Relative to trusted strength
clt_parameters.rig.lt_stray_dist , // int stray_dist, // = 2; // How far to look (and erase) around a potentially falsely matched tile
clt_parameters.rig.lt_stray_over , // double stray_over, // = 2.0; // Stray tile should be this stronger than the strongest neighbor to be recognized
debugLevel); // int debugLevel
if (debugLevel > -2) {
System.out.println("removeFalseMatches() found ="+num_stray_removed+" false matches and erased those tiles and tiles around");
}
if (num_stray_removed > 0) {
// refine again:
num_trusted = 0;
for (int num_fill = 0; num_fill < clt_parameters.rig.lt_repeat; num_fill++) {
num_new_trusted = biCamDSI.removeLTUntrusted(
disparity_bimap, // double [][] disparity_bimap,
clt_parameters.rig.lt_min_disparity, // double min_disparity, // = 0.0; // apply low texture to near objects
clt_parameters.rig.lt_trusted_strength, // double trusted_strength, // = 0.2; // strength sufficient without neighbors
clt_parameters.rig.lt_need_friends, // double need_friends, // = 0.4; // strength sufficient with neighbors support, fraction of lt_trusted_strength
clt_parameters.rig.lt_friends_diff, // double friends_diff, // = 0.2; // pix difference to neighbors to be considered a match (TODO: use tilted)
clt_parameters.rig.lt_friends_rdiff, // double friends_rdiff, // = 0.04; // additional relative pix per pixel of disparity
clt_parameters.rig.lt_min_friends_any, // int min_friends_any, // = 2; // minimal number of even weak friends
clt_parameters.rig.lt_min_friends_trusted, // int min_friends_trusted, // = 2; // minimal number of trusted (strong or already confirmed)
clt_parameters.rig.lt_friends_dist, // int friends_dist, // = 3; // how far to look for friends
debugLevel); // int debugLevel
if ((num_new_trusted - num_trusted) < min_added_tiles) {
if (debugLevel > -2) {
System.out.println("enhanceByRig(): pass="+num_fill+", number of added tiles = "+(num_new_trusted - num_trusted)+" < " +min_added_tiles+", done adding");
break;
}
} else {
if (debugLevel > -2) {
System.out.println("enhanceByRig(): pass="+num_fill+", number of added tiles = "+(num_new_trusted - num_trusted));
}
}
num_trusted = num_new_trusted;
disparity_bimap = fillPoorTextureByInter(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
disparity_bimap, //double [][] disparity_bimap,
biCamDSI, // BiCamDSI biCamDSI,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel-2); // final int debugLevel)// throws Exception
if (clt_parameters.show_map && (debugLevel > 0) && clt_parameters.rig.rig_mode_debug){ //OK
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"DSI_LT-N"+num_fill,
ImageDtt.BIDISPARITY_TITLES);
}
}
}
}
double [][] rig_disparity_strength = {disparity_bimap[ImageDtt.BI_TARGET_INDEX],disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX]};
return rig_disparity_strength;
}
public double [][] fillPoorTextureByInter(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
EyesisCorrectionParameters.CLTParameters clt_parameters,
double [][] disparity_bimap,
BiCamDSI biCamDSI,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)// throws Exception
{
final int refine_inter = 2; // use inter-cam disparity for refinement
final int tilesX = quadCLT_main.tp.getTilesX();
// final int tilesY = quadCLT_main.tp.getTilesY();
double [] suggestedLTMeasurements = biCamDSI.suggestLTTiles(
disparity_bimap, // double [][] disparity_bimap,
null, // boolean [] trusted, // may be null if disparity is alreasdy NaN-ed
clt_parameters.rig.lt_min_disparity, // double min_disparity, // = 0.0; // apply low texture to near objects
clt_parameters.rig.lt_trusted_strength, // double trusted_strength, // = 0.2; // strength sufficient without neighbors
clt_parameters.rig.lt_strength_rfloor, // double strength_rfloor, // = 0.28; // strength floor relative to trusted_strength
clt_parameters.rig.lt_need_friends, // double need_friends, // = 0.4; // strength sufficient with neighbors support, fraction of lt_trusted_strength
clt_parameters.rig.lt_extend_dist, // int extend_dist, // = 3; // how far to extend around known tiles (probably should increase this value up to?
// dealing with neighbors variance
clt_parameters.rig.lt_wsigma, // double wsigma, // = 1.0; // influence of far neighbors diminish as a Gaussian with this sigma
clt_parameters.rig.lt_max_asigma, // double max_asigma, // = .15; // Maximal acceptable standard deviation of the neighbors (remove, then add)
clt_parameters.rig.lt_max_rsigma, // double max_rsigma, // = .05; // Maximal acceptable standard deviation of the neighbors (remove, then add)
debugLevel); // int debugLevel
double [][] disparity_bimap_lt = setBimapFromDisparityNaN(
suggestedLTMeasurements, // double [] disparity,
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
false, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
0, // final int // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
// first measurement - use default value:
clt_parameters.rig.no_int_x0, // boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
if (clt_parameters.show_map && (debugLevel > -2) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap_lt,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"NEW_LT_MEASURED",
ImageDtt.BIDISPARITY_TITLES);
}
// refine just the new suggested measurements
double [][] prev_bimap = null;
int [] num_new = new int[1];
double [] scale_bad = new double [suggestedLTMeasurements.length];
for (int i = 0; i < scale_bad.length; i++) scale_bad[i] = 1.0;
prev_bimap = null;
boolean [] trusted_lt = null;
for (int nref = 0; nref < clt_parameters.rig.num_near_refine; nref++) {
// refine infinity using inter correlation
double [][] disparity_bimap_new = refineRigSel(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
disparity_bimap_lt, // double [][] src_bimap, // current state of measurements (or null for new measurement)
prev_bimap, // double [][] prev_bimap, // previous state of measurements or null
scale_bad, // double [] scale_bad,
refine_inter, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
false, // boolean keep_inf, // keep expected disparity 0.0 if it was so
0.0, // clt_parameters.rig.refine_min_strength , // double refine_min_strength, // do not refine weaker tiles
clt_parameters.rig.refine_tolerance , // double refine_tolerance, // do not refine if absolute disparity below
trusted_lt, // null, // trusted_lt, // tile_list, // ArrayList<Integer> tile_list, // or null
num_new, // int [] num_new,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
false, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
0, // final int // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
// in refine mode disable int preset of the window
true, // boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
prev_bimap = disparity_bimap_lt;
disparity_bimap_lt = disparity_bimap_new;
//low texture may have very poor individual correlations, do not check them at all
trusted_lt = getTrustedDisparityInter(
0.0, // clt_parameters.rig.lt_trusted_strength*clt_parameters.rig.lt_need_friends, // double min_inter_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity,
trusted_lt, // boolean [] was_trusted,
disparity_bimap_lt ); // double [][] bimap // current state of measurements
if (debugLevel > -2) {
System.out.println("enhanceByRig(): refined (lt) "+num_new[0]+" tiles");
}
if (num_new[0] < clt_parameters.rig.min_new) break;
}
trusted_lt = getTrustedDisparityInter(
clt_parameters.rig.lt_trusted_strength*clt_parameters.rig.lt_need_friends, // double min_inter_strength, // check correlation strength combined for all 3 correlations
clt_parameters.grow_disp_trust, // double max_trusted_disparity,
trusted_lt, // boolean [] was_trusted,
disparity_bimap_lt ); // double [][] bimap // current state of measurements
if (clt_parameters.show_map && (debugLevel > -2) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap_lt,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"NEW_LT_REFINED",
ImageDtt.BIDISPARITY_TITLES);
}
// combine new measured results with the previously known (new overwrites old
for (int nTile = 0; nTile < disparity_bimap_lt[0].length; nTile++) {
// if (trusted_lt[nTile] &&
// (!trusted_near[nTile] ||
// (disparity_bimap_infinity[ImageDtt.BI_STR_ALL_INDEX][nTile] > disparity_bimap[ImageDtt.BI_STR_ALL_INDEX][nTile]))) {
// start with unconditional use of new
if (trusted_lt[nTile]) {
for (int i = 0; i < disparity_bimap.length; i++) if (disparity_bimap!=null) {
disparity_bimap[i][nTile] = disparity_bimap_lt[i][nTile];
}
// trusted_near[nTile] = true;
}
}
if (clt_parameters.show_map && (debugLevel > -2) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap_lt,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"DSI_ADDED",
ImageDtt.BIDISPARITY_TITLES);
}
return disparity_bimap;
}
return disparity_bimap;
}
......@@ -5320,79 +4858,6 @@ if (debugLevel > -100) return true; // temporarily !
}
private void showMeasuredPoles(
String title,
int tilesX,
double [][][] measured_poles) {
int num_layers = measured_poles.length;
String [] titles = new String[2 * num_layers];
double [][] dbg_img = new double[2 * num_layers][];
for (int i = 0; i < num_layers; i++) {
titles[i] = "disparity_"+i;
titles[i+num_layers] = "strength_"+i;
dbg_img[i] = measured_poles[i][0];
dbg_img[i+num_layers] = measured_poles[i][1];
}
(new showDoubleFloatArrays()).showArrays(
dbg_img,
tilesX,
dbg_img[0].length/tilesX,
true,
title,
titles);
}
private double [][][] measurePoles(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][] poles_ds,
EyesisCorrectionParameters.CLTParameters clt_parameters,
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
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
int num_layers = poles_ds.length;
int tile_op_all = clt_parameters.tile_task_op; //FIXME Use some constant?
int tilesX =quadCLT_main.tp.getTilesX();
int tilesY =quadCLT_main.tp.getTilesY();
double [][][] measuredDisparityStrength = new double [num_layers][2][]; // num_tiles];
for (int layer = 0; layer < num_layers; layer++) {
int [][] tile_op = new int [tilesY][tilesX];
double [][] disparity_array = new double [tilesY][tilesX];
for (int tileY = 0; tileY<tilesY;tileY++) {
for (int tileX = 0; tileX<tilesX;tileX++) {
int nTile = tileY * tilesX + tileX;
disparity_array[tileY][tileX] = poles_ds[layer][nTile];
if (!Double.isNaN(poles_ds[layer][nTile])) {
tile_op[tileY][tileX] = tile_op_all;
}
}
}
double [][] disparity_bimap = measureRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
null, // 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,
clt_parameters.fat_zero, // double fatzero,
notch_mode, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
lt_rad, // final int // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
true, // boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
measuredDisparityStrength[layer][0] = disparity_bimap[ImageDtt.BI_DISP_CROSS_INDEX];
measuredDisparityStrength[layer][1] = disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX];
}
return measuredDisparityStrength;
}
double [][] measureRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
......@@ -5608,6 +5073,246 @@ if (debugLevel > -100) return true; // temporarily !
titles );
}
public void batchRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
EyesisCorrectionParameters.CLTParameters clt_parameters,
EyesisCorrectionParameters.DebayerParameters debayerParameters,
EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CorrectionColorProc.ColorGainsParameters channelGainParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
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;
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 = quadCLT_main.eyesisCorrections.calcReferenceExposures(debugLevel); // multiply each image by this and divide by individual (if not NaN)
double [] referenceExposures_aux = quadCLT_aux.eyesisCorrections.calcReferenceExposures(debugLevel); // multiply each image by this and divide by individual (if not NaN)
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];
ImagePlus [] imp_srcs_main = quadCLT_main.conditionImageSet(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
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);
ImagePlus [] imp_srcs_aux = quadCLT_aux.conditionImageSet(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
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 main, aux, rig here
for (int num_adjust_main = 0; num_adjust_main < quadCLT_main.correctionsParameters.rig_batch_adjust_main; num_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");
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)
}
for (int num_adjust_aux = 0; num_adjust_aux < quadCLT_main.correctionsParameters.rig_batch_adjust_aux; 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,
rgbParameters,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevelInner);
// adjust extrinsics here
System.out.println("Adjust aux extrinsics here");
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)
}
for (int num_adjust_rig = 0; num_adjust_rig < quadCLT_main.correctionsParameters.rig_batch_adjust_rig; num_adjust_rig++) {
processInfinityRig(
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
imp_srcs_main, // ImagePlus [] imp_quad_main,
imp_srcs_aux, // ImagePlus [] imp_quad_aux,
saturation_imp_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_imp_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevelInner-2); // final int debugLevel);
}
if ( (quadCLT_main.correctionsParameters.rig_batch_adjust_main > 0) ||
(quadCLT_main.correctionsParameters.rig_batch_adjust_aux > 0) ||
(quadCLT_main.correctionsParameters.rig_batch_adjust_rig > 0)) {
quadCLT_main.showExtrinsicCorr("main"); // show_fine_corr("main");
quadCLT_aux.showExtrinsicCorr("aux"); // show_fine_corr("aux");
quadCLT_aux.geometryCorrection.showRig();// show_fine_corr("aux");
quadCLT_main.tp.resetCLTPasses();
quadCLT_aux.tp.resetCLTPasses();
}
// Generate 8 images and thumbnails
if (quadCLT_main.correctionsParameters.clt_batch_4img){
processCLTQuadCorrPair(
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
imp_srcs_main, // ImagePlus [] imp_quad_main,
imp_srcs_aux, // ImagePlus [] imp_quad_aux,
saturation_imp_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_imp_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
debayerParameters, // EyesisCorrectionParameters.DebayerParameters debayerParameters,
colorProcParameters, // EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
rgbParameters, // EyesisCorrectionParameters.RGBParameters rgbParameters,
scaleExposures_main, // double [] scaleExposures_main, // probably not needed here - restores brightness of the final image
scaleExposures_aux, // double [] scaleExposures_aux, // probably not needed here - restores brightness of the final image
false, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
// averages measurements
clt_parameters.rig.lt_avg_radius,// final int lt_rad, // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevelInner); // final int debugLevel);
}
// ground truth and then all the rest
quadCLT_main.tp.resetCLTPasses();
quadCLT_aux.tp.resetCLTPasses();
if (quadCLT_main.correctionsParameters.clt_batch_explore) {
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);
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);
groundTruth( // actually there is no sense to process multiple image sets. Combine with other processing?
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevelInner-2); // final int debugLevel);
} else {
continue;
}
biCamDSI_persistent = null; // to save memory
Runtime.getRuntime().gc();
System.out.println("--- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (quadCLT_main.correctionsParameters.clt_batch_surf) {
quadCLT_main.tp.showPlanes(
clt_parameters,
quadCLT_main.geometryCorrection,
threadsMax,
updateStatus,
debugLevelInner);
} else continue; // if (correctionsParameters.clt_batch_surf)
if (quadCLT_main.correctionsParameters.clt_batch_assign) {
boolean ok = quadCLT_main.tp.assignTilesToSurfaces(
clt_parameters,
quadCLT_main.geometryCorrection,
threadsMax,
updateStatus,
debugLevelInner);
if (!ok) continue;
} else continue; // if (correctionsParameters.clt_batch_assign)
if (quadCLT_main.correctionsParameters.clt_batch_gen3d) {
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 continue; // if (correctionsParameters.clt_batch_gen3d)
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()+")");
}
}
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