Commit a520cd7b authored by Andrey Filippov's avatar Andrey Filippov

Added 32-bit tiff output for ML data

parent 70ccd5f4
......@@ -65,6 +65,25 @@ public class BiQuadParameters {
public boolean rig_adjust_forward = false; // aux camera forward from the principal plane (not implemented)
public double rig_correction_scale= 1.0; // scale calculaated correction
public int min_new = 100; // Minimal number of he new tiles during rig refine
public int num_inf_refine = 20; // Number of infinity refine passes
public int num_near_refine = 20; // Number of non-infinity refine passes
public double min_trusted_strength = 0.1;//14// Minimal trusted combo strength;
public double trusted_tolerance = 1.0; // Trusted tolerance for small baseline camera(s)
public int ml_hwidth = 2; // Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)
public double ml_disparity_sweep = 2.0; // Disparity sweep around ground truth, each side
public int ml_sweep_steps = 5; // Number of disparity sweep steps
public boolean ml_keep_aux = true; // include auxiliary camera data in the ML output
public boolean ml_keep_inter = true; // include inter-camera correlation data in the ML output
public boolean ml_keep_hor_vert = true; // include combined horizontal and vertical pairs data in the ML output
public boolean ml_keep_debug= true; // include debug layer(s) data in the ML output
public boolean ml_8bit= true; // output in 8-bit format (default - 32-bit TIFF
public boolean ml_show_ml = true; // show each generated MLoutput file
public void dialogQuestions(GenericJTabbedDialog gd) {
......@@ -136,6 +155,39 @@ public class BiQuadParameters {
gd.addCheckbox ("Adjust aux camera distance from the main principal plane", this.rig_adjust_forward,"Not implemented, assumed zero");
gd.addNumericField("Scale calculated correction before applying", this.rig_correction_scale, 3,6,"",
"Debug feature");
gd.addNumericField("Minimal number of he new tiles during rig refine", this.min_new, 0,3,"",
"Exit from refine infinity cycle if number of new refine candidates is less than this number");
gd.addNumericField("Number of infinity refine passes", this.num_inf_refine, 0,3,"",
"Exit from refine non- infinity cycle if number of new refine candidates is less than this number");
gd.addNumericField("Number of non-infinity refine passes", this.num_near_refine, 0,3,"",
"Re-scan only previously selected tiles");
gd.addNumericField("Minimal trusted combo strength", this.min_trusted_strength, 3,6,"",
"Combo strength is cubic root of the product of main, aux and intyer correlation strengths");
gd.addNumericField("Trusted tolerance for small baseline camera(s)", this.trusted_tolerance, 3,6,"",
"When downscaling valid residual disparity from the most sensitive inter-camera, do not reduce it to be lower than this");
gd.addTab("ML","Parameters related to the ML files generation for the dual-quad camera rig");
gd.addNumericField("Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)", this.ml_hwidth, 0,3,"",
"Amount of data to export to the ML system");
gd.addNumericField("Disparity sweep around ground truth, each side", this.ml_disparity_sweep, 3,6,"",
"Sweep symmetrically target disparity around the ground truth disparity, each side");
gd.addNumericField("Number of target disparity sweep steps", this.ml_sweep_steps, 0,3,"",
"Generate this many files for each file set. Each tile results depend on the target disparity and this tile data, do not depend on other tiles target disparity");
gd.addCheckbox ("Include auxiliary camera data in the ML output", this.ml_keep_aux,
"ML output will have the second set of the layers for the auxiliary camera. Disparity values should be scaled for the camera baseline");
gd.addCheckbox ("Keep inter-camera correlation data", this.ml_keep_inter,
"Inter-camera correlation data has only one layer (and one correlation pair). It is used to generate ground truth data. Usable disparity range (measured in the main camera pixels) is ~1/5 of teh main camera");
gd.addCheckbox ("Keep combine horizonta/vertical pairs", this.ml_keep_hor_vert,
"Each of these two layers per camera are calculated from a pair of top/bottom and left/right pairs. Can possibly be used instead of originals to reduce amount of input data");
gd.addCheckbox ("Keep debug layer(s)", this.ml_keep_debug,
"Keep additional (debug) layers that may change for different file versions");
gd.addCheckbox ("Use 8 bpp TIFF (default - 32 bpp)", this.ml_8bit,
"Reduce file size by lowering bpp");
gd.addCheckbox ("Show each generated ML file", this.ml_show_ml,
"Use only for small number of generated files to reduce memory usage");
}
public void dialogAnswers(GenericJTabbedDialog gd) {
this.rig_mode_debug= gd.getNextBoolean();
......@@ -174,6 +226,22 @@ public class BiQuadParameters {
this.rig_adjust_distance= gd.getNextBoolean();
this.rig_adjust_forward= gd.getNextBoolean();
this.rig_correction_scale= gd.getNextNumber();
this.min_new= (int) gd.getNextNumber();
this.num_inf_refine= (int) gd.getNextNumber();
this.num_near_refine= (int) gd.getNextNumber();
this.min_trusted_strength= gd.getNextNumber();
this.trusted_tolerance= gd.getNextNumber();
this.ml_hwidth= (int) gd.getNextNumber();
this.ml_disparity_sweep= gd.getNextNumber();
this.ml_sweep_steps= (int) gd.getNextNumber();
this.ml_keep_aux= gd.getNextBoolean();
this.ml_keep_inter= gd.getNextBoolean();
this.ml_keep_hor_vert= gd.getNextBoolean();
this.ml_keep_debug= gd.getNextBoolean();
this.ml_8bit= gd.getNextBoolean();
this.ml_show_ml= gd.getNextBoolean();
}
public void setProperties(String prefix,Properties properties){
......@@ -216,6 +284,23 @@ public class BiQuadParameters {
properties.setProperty(prefix+"rig_adjust_forward", this.rig_adjust_forward+"");
properties.setProperty(prefix+"rig_correction_scale", this.rig_correction_scale+"");
properties.setProperty(prefix+"min_new", this.min_new+"");
properties.setProperty(prefix+"num_inf_refine", this.num_inf_refine+"");
properties.setProperty(prefix+"num_near_refine", this.num_near_refine+"");
properties.setProperty(prefix+"min_trusted_strength", this.min_trusted_strength+"");
properties.setProperty(prefix+"trusted_tolerance", this.trusted_tolerance+"");
properties.setProperty(prefix+"ml_hwidth", this.ml_hwidth+"");
properties.setProperty(prefix+"ml_disparity_sweep", this.ml_disparity_sweep+"");
properties.setProperty(prefix+"ml_sweep_steps", this.ml_sweep_steps+"");
properties.setProperty(prefix+"ml_keep_aux", this.ml_keep_aux+"");
properties.setProperty(prefix+"ml_keep_inter", this.ml_keep_inter+"");
properties.setProperty(prefix+"ml_keep_hor_vert", this.ml_keep_hor_vert+"");
properties.setProperty(prefix+"ml_keep_debug", this.ml_keep_debug+"");
properties.setProperty(prefix+"ml_8bit", this.ml_8bit+"");
properties.setProperty(prefix+"ml_show_ml", this.ml_show_ml+"");
}
public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"rig_mode_debug")!=null) this.rig_mode_debug=Boolean.parseBoolean(properties.getProperty(prefix+"rig_mode_debug"));
......@@ -254,6 +339,21 @@ public class BiQuadParameters {
if (properties.getProperty(prefix+"rig_adjust_forward")!=null) this.rig_adjust_forward=Boolean.parseBoolean(properties.getProperty(prefix+"rig_adjust_forward"));
if (properties.getProperty(prefix+"rig_correction_scale")!=null) this.rig_correction_scale=Double.parseDouble(properties.getProperty(prefix+"rig_correction_scale"));
if (properties.getProperty(prefix+"min_new")!=null) this.min_new=Integer.parseInt(properties.getProperty(prefix+"min_new"));
if (properties.getProperty(prefix+"num_inf_refine")!=null) this.num_inf_refine=Integer.parseInt(properties.getProperty(prefix+"num_inf_refine"));
if (properties.getProperty(prefix+"num_near_refine")!=null) this.num_near_refine=Integer.parseInt(properties.getProperty(prefix+"num_near_refine"));
if (properties.getProperty(prefix+"min_trusted_strength")!=null) this.min_trusted_strength=Double.parseDouble(properties.getProperty(prefix+"min_trusted_strength"));
if (properties.getProperty(prefix+"trusted_tolerance")!=null) this.trusted_tolerance=Double.parseDouble(properties.getProperty(prefix+"trusted_tolerance"));
if (properties.getProperty(prefix+"ml_hwidth")!=null) this.ml_hwidth=Integer.parseInt(properties.getProperty(prefix+"ml_hwidth"));
if (properties.getProperty(prefix+"ml_disparity_sweep")!=null) this.ml_disparity_sweep=Double.parseDouble(properties.getProperty(prefix+"ml_disparity_sweep"));
if (properties.getProperty(prefix+"ml_sweep_steps")!=null) this.ml_sweep_steps=Integer.parseInt(properties.getProperty(prefix+"ml_sweep_steps"));
if (properties.getProperty(prefix+"ml_keep_aux")!=null) this.ml_keep_aux=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_aux"));
if (properties.getProperty(prefix+"ml_keep_inter")!=null) this.ml_keep_inter=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_inter"));
if (properties.getProperty(prefix+"ml_keep_hor_vert")!=null) this.ml_keep_hor_vert=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_hor_vert"));
if (properties.getProperty(prefix+"ml_keep_debug")!=null) this.ml_keep_debug=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_debug"));
if (properties.getProperty(prefix+"ml_8bit")!=null) this.ml_8bit=Boolean.parseBoolean(properties.getProperty(prefix+"ml_8bit"));
if (properties.getProperty(prefix+"ml_show_ml")!=null) this.ml_show_ml=Boolean.parseBoolean(properties.getProperty(prefix+"ml_show_ml"));
}
@Override
public BiQuadParameters clone() throws CloneNotSupportedException {
......@@ -293,6 +393,22 @@ public class BiQuadParameters {
bqp.rig_adjust_distance= this.rig_adjust_distance;
bqp.rig_adjust_forward= this.rig_adjust_forward;
bqp.rig_correction_scale= this.rig_correction_scale;
bqp.min_new= this.min_new;
bqp.num_inf_refine= this.num_inf_refine;
bqp.num_near_refine= this.num_near_refine;
bqp.min_trusted_strength= this.min_trusted_strength;
bqp.trusted_tolerance= this.trusted_tolerance;
bqp.ml_hwidth= this.ml_hwidth;
bqp.ml_disparity_sweep= this.ml_disparity_sweep;
bqp.ml_sweep_steps= this.ml_sweep_steps;
bqp.ml_keep_aux= this.ml_keep_aux;
bqp.ml_keep_inter= this.ml_keep_inter;
bqp.ml_keep_hor_vert= this.ml_keep_hor_vert;
bqp.ml_keep_debug= this.ml_keep_debug;
bqp.ml_8bit= this.ml_8bit;
bqp.ml_show_ml= this.ml_show_ml;
return bqp;
......
......@@ -512,7 +512,7 @@ public class CLTPass3d{
*
* Replace weak by a weighted average of non-weak. If there are none - use weak ones, including this one too.
*/
public boolean[] replaceWeakOutlayers(
public boolean[] replaceWeakOutliers(
final boolean [] selection,
final double weakStrength, // strength to be considered weak, subject to this replacement
final double maxDiff,
......@@ -546,7 +546,7 @@ public class CLTPass3d{
(disparity[nTile] < absMinDisparity) ||
(disparity[nTile] > absMaxDisparity))&& ((selection == null) || selection[nTile])) {
if (nTile == dbg_nTile){
System.out.println("replaceWeakOutlayers():1 nTile="+nTile);
System.out.println("replaceWeakOutliers():1 nTile="+nTile);
}
double [] dbg_disparity = disparity;
double dbg_disparity_nTile = disparity[nTile];
......@@ -602,7 +602,7 @@ public class CLTPass3d{
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
if (nTile == dbg_nTile){
System.out.println("replaceWeakOutlayers():2 nTile="+nTile);
System.out.println("replaceWeakOutliers():2 nTile="+nTile);
}
if (weakOutlayers[nTile]) {
double sw = 0.0, sd = 0.0;
......
......@@ -185,6 +185,42 @@ public class Correlation2d {
double [][] clt_data2,
double [][] tcorr, // null or initialized to [4][transform_len]
double fat_zero) {
if (tcorr == null) tcorr = new double [4][transform_len];
double [] a2 = new double[transform_len];
double sa2 = 0.0;
for (int i = 0; i < transform_len; i++) {
double s1 = 0.0, s2=0.0;
for (int n = 0; n< 4; n++){
s1+=clt_data1[n][i] * clt_data1[n][i];
s2+=clt_data2[n][i] * clt_data2[n][i];
}
a2[i] = Math.sqrt(s1*s2);
sa2 += a2[i];
}
double fz2 = sa2/transform_len * fat_zero * fat_zero; // fat_zero squared to match units
for (int i = 0; i < transform_len; i++) {
double scale = 1.0 / (a2[i] + fz2);
for (int n = 0; n<4; n++){
tcorr[n][i] = 0;
for (int k=0; k<4; k++){
if (ZI[n][k] < 0)
tcorr[n][i] -=
clt_data1[-ZI[n][k]][i] * clt_data2[k][i];
else
tcorr[n][i] +=
clt_data1[ZI[n][k]][i] * clt_data2[k][i];
}
tcorr[n][i] *= scale;
}
}
return tcorr;
}
public double[][] correlateSingleColorFD_old(
double [][] clt_data1,
double [][] clt_data2,
double [][] tcorr, // null or initialized to [4][transform_len]
double fat_zero) {
if (tcorr == null) tcorr = new double [4][transform_len];
for (int i = 0; i < transform_len; i++) {
double s1 = 0.0, s2=0.0;
......@@ -210,6 +246,7 @@ public class Correlation2d {
}
/**
* Calculate color channels FD phase correlations, mix results with weights, apply optional low-pass filter
* and convert to the pixel domain as [(2*transform_size-1) * (2*transform_size-1)] tiles (15x15)
......@@ -845,6 +882,7 @@ public class Correlation2d {
}
/**
* Calculate 1-d maximum location, strength and half-width for the special strip (odd rows shifted by 0.5
* Negative values are ignored!
* Both x and y half-windows can be variable length (to reduce calculations with 0.0 elements), normalized
* so sums of zero element and twice all others are 1.0
* Window in Y direction corresponds to correlation stripe rows, corresponding to sqrt(2)/2 sensor pixels
......@@ -992,6 +1030,140 @@ public class Correlation2d {
}
/**
* Extract center 2-d correlation around zero from the full (now 15x15)
* @param hwidth half width of the output tile (0 -> 1x1, 1-> 3x3, 2->5x5)
* @param full_corr full pixel-domain correlation (now 15x15=225 long)
* @param center_corr - output array [(2*hwidth+1)*(2*hwidth+1)] or null
* @return center_corr - center part of the correlation in linescan order
*/
public double [] corrCenterValues(
int hwidth,
double [] full_corr,
double [] center_corr) {
if (full_corr == null) return null;
int center = transform_size - 1;
int width = 2 * center + 1;
int owidth = 2*hwidth+1;
if (center_corr == null) center_corr = new double [owidth*owidth];
int indx = 0;
int findx = (center - hwidth) * (width + 1); // top left corner
for (int row = 0; row < owidth; row++) {
for (int col = 0; col < owidth; col++) {
center_corr[indx++] = full_corr[findx++];
}
findx += width-owidth;
}
return center_corr;
}
/**
* Extract center 2-d correlations around zero from the full (now 15x15) correlations
* for each of the 6 pairs and 2 combined directions (horizontal, vertical)
* @param hwidth half width of the output tile (0 -> 1x1, 1-> 3x3, 2->5x5)
* @param offset add before multiplication, subtract in the end. If negative - use averaging
* instead of the shifted multiplication
* @param full_corr full pixel-domain correlation (now 15x15=225 long)for each of 6 pairs
* @param center_corr - output array [(2*hwidth+1)*(2*hwidth+1)]. should be [8][]
*/
public void corrCenterValues(
int hwidth,
double offset,
double [][] full_corr,
double [][] center_corr) {
// first 6 layers - directly correspond to pairs (top, bottom, left, right, diagonal main, diagonal other)
for (int i = 0; i < 6; i++) {
center_corr[i] = corrCenterValues(
hwidth,
full_corr[i],
center_corr[i]);
}
// combine vertical and horizontal pairs
int center = transform_size - 1;
int width = 2 * center + 1;
int owidth = 2 * hwidth + 1;
for (int ndir = 0; ndir < 2; ndir++) { // 0- hor, 1- vert
if (center_corr[ndir] == null) center_corr[ndir] = new double [owidth*owidth];
int indx = 0;
int findx = (center - hwidth) * (width + 1); // top left corner
for (int row = 0; row < owidth; row++) {
for (int col = 0; col < owidth; col++) {
double fc0 = full_corr[2 * ndir + 0][findx]; // 0 (top), 2 (left)
double fc1 = full_corr[2 * ndir + 1][findx++]; // 1 - bottom, 3 (right)
double cc = 0.0;
if (offset >= 0.0) {
if ((fc0 > 0.0) && (fc1 > 0.0)) {
cc = Math.sqrt((fc0+offset)*(fc1+offset)) - offset;
}
} else {
cc = 0.5*(fc0+fc1);
}
center_corr[ndir + 6][indx++] = cc; // save to 6-th and 7-th layer
}
findx += width-owidth;
}
}
}
/**
* Save 2d correlation data for one layer, one tile into the combined multi-layer ML array, viewable as an image
* @param tileX horizontal tile index
* @param tileY vertical tile index
* @param ml_hwidth half-width of the preserved 2d correlation (0 - single point, 1 -> 3x3, 2 -> 5x5, 7 - all data)
* @param ml_data multi-layer array, each layer matches an image of ((2 * ml_hwidth + 1) * tilesX) by ((2 * ml_hwidth + 1) * tilesY) in scanline order
* Each tile corresponds to (2 * ml_hwidth + 1) * (2 * ml_hwidth + 1) square in the image. Only selected tiles will be updated, so it is good to initialize array
* with all Double.NaN values
* @param ml_layer layer to save tile data
* @param ml_tile (2 * ml_hwidth + 1) * (2 * ml_hwidth + 1) tile data to be saved
* @param tilesX image width in tiles
*/
public void saveMlTile(
int tileX,
int tileY,
int ml_hwidth,
double [][] ml_data,
int ml_layer,
double [] ml_tile,
int tilesX) {
int tile_width = 2 * ml_hwidth + 1;
int full_width = tile_width * tilesX;
int oindex = tileY *tile_width * full_width + tileX * tile_width;
for (int row = 0; row < tile_width; row++) {
System.arraycopy(ml_tile, row * tile_width, ml_data[ml_layer], oindex, tile_width);
oindex += full_width;
}
}
/**
* Save a single value to the combined multi-layer ML array, viewable as an image
* @param tileX horizontal tile index
* @param tileY vertical tile index
* @param ml_hwidth half-width of the preserved 2d correlation (0 - single point, 1 -> 3x3, 2 -> 5x5, 7 - all data)
* @param ml_data multi-layer array, each layer matches an image of ((2 * ml_hwidth + 1) * tilesX) by ((2 * ml_hwidth + 1) * tilesY) in scanline order
* Each tile corresponds to (2 * ml_hwidth + 1) * (2 * ml_hwidth + 1) square in the image. Only selected tiles will be updated, so it is good to initialize array
* with all Double.NaN values
* @param ml_layer layer to save tile data
* @param ml_index data index within tile
* @param ml_value value to set
* @param tilesX image width in tiles
*/
public void saveMlTilePixel(
int tileX,
int tileY,
int ml_hwidth,
double [][] ml_data,
int ml_layer,
int ml_index,
double ml_value,
int tilesX) {
int tile_width = 2 * ml_hwidth + 1;
int full_width = tile_width * tilesX;
int oindex = tileY *tile_width * full_width + tileX * tile_width + (ml_index/tile_width)*full_width + (ml_index%tile_width) ;
ml_data[ml_layer][oindex] = ml_value;
}
public double [] debugStrip(
......@@ -1238,6 +1410,7 @@ public class Correlation2d {
return rslt;
}
// ignores negative values
public double [] single2dCM( // returns x-xcenter, y, strength (sign same as disparity)
ImageDttParameters imgdtt_params,
double [] corr,
......@@ -1408,7 +1581,7 @@ public class Correlation2d {
System.out.println(String.format("eff_strength = [%8.5f, %8.5f, %8.5f, %8.5f]", eff_strength[0], eff_strength[1], eff_strength[2], eff_strength[3]));
System.out.println(String.format("width_d = [%8.5f, %8.5f, %8.5f, %8.5f]", width_d[0], width_d[1], width_d[2], width_d[3]));
}
if (!strong[isel] || (isel <0)) {
if ((isel <0) || !strong[isel]) {
corr = Double.NaN;
if (debug) System.out.println("Direction with "+(bg?"min":"max")+" disparity is not strong enough -> no correction");
} else if (width_d[isel] > max_hwidth) {
......@@ -1446,7 +1619,7 @@ public class Correlation2d {
}
if (debug) System.out.println("lim = "+lim+", disp = "+disp);
}
double [] rslt = {disp, eff_strength[isel], mx - mn, are_ortho ?1.0 : 0.0};
double [] rslt = {disp, (isel >=0) ? eff_strength[isel]:0.0, mx - mn, are_ortho ?1.0 : 0.0};
if (debug) System.out.println(String.format("foregroundCorrect() -> [%8.5f, %8.5f, %8.5f, %3.1f]", rslt[0], rslt[1], rslt[2], rslt[3]));
return rslt;
......
......@@ -134,11 +134,12 @@ public class EyesisCorrectionParameters {
public String x3dModelVersion="v01";
public String x3dDirectory="";
public String mlDirectory="";
public CorrectionParameters getAux() {
return aux_camera;
}
public CorrectionParameters aux_camera = null; // auxiliarry camera parameters
public CorrectionParameters aux_camera = null; // auxiliary camera parameters
// public boolean use_aux = true; // Generate debug images if a single set is selected
public void updateAuxFromMain() { // from master to aux
if (aux_camera == null) {
......@@ -222,13 +223,10 @@ public class EyesisCorrectionParameters {
cp.referenceExposure= this.referenceExposure;
cp.relativeExposure= this.relativeExposure;
cp.swapSubchannels01= this.swapSubchannels01;
// cp.cltKernelDirectory= this.cltKernelDirectory;
// cp.cltKernelPrefix= this.cltKernelPrefix;
// cp.cltSuffix= this.cltSuffix;
cp.x3dDirectory= this.x3dDirectory;
cp.mlDirectory= this.mlDirectory;
cp.use_x3d_subdirs= this.use_x3d_subdirs;
cp.x3dSubdirPrefix= this.x3dSubdirPrefix;
// cp.x3dSubdirSuffix= this.x3dSubdirSuffix;
cp.x3dModelVersion= this.x3dModelVersion;
cp.clt_batch_apply_man= this.clt_batch_apply_man;
cp.clt_batch_extrinsic= this.clt_batch_extrinsic;
......@@ -365,10 +363,10 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"x3dSubdirPrefix", this.x3dSubdirPrefix+"");
properties.setProperty(prefix+"x3dSubdirSuffix", this.x3dSubdirSuffix+"");
properties.setProperty(prefix+"x3dModelVersion", this.x3dModelVersion);
properties.setProperty(prefix+"mlDirectory", this.mlDirectory);
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+"");
......@@ -494,6 +492,8 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"x3dModelVersion")!= null) this.x3dModelVersion=properties.getProperty(prefix+"x3dModelVersion");
if (properties.getProperty(prefix+"mlDirectory")!= null) this.mlDirectory=properties.getProperty(prefix+"mlDirectory");
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"));
......@@ -599,6 +599,8 @@ public class EyesisCorrectionParameters {
"When using timestamp as a subdirectory, add this prefix");
gd.addStringField ("x3d subdirectory suffix", this.x3dSubdirSuffix, 10,
"When using timestamp as a subdirectory, add this suffix");
gd.addStringField ("ML output directory", this.mlDirectory, 60);
gd.addCheckbox ("Select ML output directory", false);
gd.addStringField("Equirectangular maps directory (may be empty)", this.equirectangularDirectory, 60);
gd.addCheckbox("Select equirectangular maps directory", false);
......@@ -693,6 +695,8 @@ public class EyesisCorrectionParameters {
this.x3dSubdirPrefix= gd.getNextString();
this.x3dSubdirSuffix= gd.getNextString();
this.mlDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectMlDirectory(false, true);
this.equirectangularDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectEquirectangularDirectory(false, false);
this.resultsDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectResultsDirectory(false, true);
this.sourcePrefix= gd.getNextString();
......@@ -749,6 +753,8 @@ public class EyesisCorrectionParameters {
gd.addStringField ("x3d subdirectory prefix", this.x3dSubdirPrefix, 10, // 14a
"When using timestamp as a subdirectory, add this prefix");
gd.addStringField ("ML output directory", this.mlDirectory, 60); // 8d
gd.addCheckbox ("Select ML output directory", false); // 8e
gd.addMessage ("============ Main camera============");
......@@ -823,6 +829,7 @@ public class EyesisCorrectionParameters {
this.sourcePrefix= gd.getNextString(); // 13
this.sourceSuffix= gd.getNextString(); // 14
this.x3dSubdirPrefix= gd.getNextString(); // 14a
this.mlDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectMlDirectory(false, true); // 8d
// main camera
this.sensorDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectSensorDirectory(false, false); // 5
......@@ -1403,6 +1410,17 @@ public class EyesisCorrectionParameters {
return dir;
}
public String selectMlDirectory(boolean smart, boolean newAllowed) {
String dir= CalibrationFileManagement.selectDirectory(
smart,
newAllowed, // save
"ML output directory", // title
"Select ML output directory", // button
null, // filter
this.mlDirectory); //this.sourceDirectory);
if (dir!=null) this.mlDirectory=dir;
return dir;
}
// add prefix/suffix to the model name
public String getModelName(String name) {
return this.x3dSubdirPrefix + name + this.x3dSubdirSuffix;
......@@ -2988,7 +3006,7 @@ public class EyesisCorrectionParameters {
public boolean replaceWeakOutlayers = true; // false;
public boolean replaceWeakOutliers = true; // false;
public boolean dbg_migrate = true;
......
......@@ -583,7 +583,9 @@ private Panel panel1,
addButton("CLT 2*4 images - 2", panelClt4, color_conf_process);
addButton("CLT 2*4 images - 3", panelClt4, color_conf_process);
addButton("Rig infinity calibration", panelClt4, color_conf_process);
addButton("AUX Extrinsics", panelClt4, color_process);
addButton("AUX show fine", panelClt4, color_configure);
addButton("Rig enhance", panelClt4, color_conf_process);
add(panelClt4);
}
......@@ -4091,6 +4093,11 @@ private Panel panel1,
}
}
QUAD_CLT.listGeometryCorrection(true);
if (QUAD_CLT_AUX != null) { // Only show auxiliary camera geometry if it is initialized
System.out.println("\n === Auxiliary camera ===");
QUAD_CLT_AUX.listGeometryCorrection(true);
}
return;
} else if (label.equals("CLT show fine corr")) {
if (QUAD_CLT == null){
......@@ -4255,7 +4262,6 @@ private Panel panel1,
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL);
int numChannels=EYESIS_CORRECTIONS.getNumChannels();
// NONLIN_PARAMETERS.modifyNumChannels(numChannels);
CHANNEL_GAINS_PARAMETERS.modifyNumChannels(numChannels);
if (!QUAD_CLT.CLTKernelsAvailable()){
......@@ -4303,6 +4309,80 @@ private Panel panel1,
if (configPath!=null) {
saveTimestampedProperties( // save config again
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
}
return;
} else if (label.equals("AUX Extrinsics") || label.equals("AUX Poly corr")) {
boolean adjust_extrinsics = label.equals("AUX Extrinsics") || label.equals("AUX Poly corr");
boolean adjust_poly = label.equals("AUX Poly corr");
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
if (QUAD_CLT_AUX == null){
if (EYESIS_CORRECTIONS_AUX == null) {
EYESIS_CORRECTIONS_AUX = new EyesisCorrections(SYNC_COMMAND.stopRequested,CORRECTION_PARAMETERS.getAux());
}
QUAD_CLT_AUX = new QuadCLT (
QuadCLT.PREFIX_AUX,
PROPERTIES,
EYESIS_CORRECTIONS_AUX,
CORRECTION_PARAMETERS.getAux());
if (DEBUG_LEVEL > 0){
System.out.println("Created new QuadCLT instance for AUX camera, will need to read CLT kernels for aux camera");
}
}
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return;
EYESIS_CORRECTIONS_AUX.initSensorFiles(DEBUG_LEVEL);
int numChannelsAux=EYESIS_CORRECTIONS_AUX.getNumChannels();
CHANNEL_GAINS_PARAMETERS_AUX.modifyNumChannels(numChannelsAux);
if (!QUAD_CLT_AUX.CLTKernelsAvailable()){
if (DEBUG_LEVEL > 0){
System.out.println("Reading AUX CLT kernels");
}
QUAD_CLT_AUX.readCLTKernels(
CLT_PARAMETERS,
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
if (DEBUG_LEVEL > 1){
QUAD_CLT_AUX.showCLTKernels(
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
}
}
if (!QUAD_CLT_AUX.geometryCorrectionAvailable()){
if (DEBUG_LEVEL > 0){
System.out.println("Calculating geometryCorrection for AUX camera");
}
if (!QUAD_CLT_AUX.initGeometryCorrection(DEBUG_LEVEL+2)){
return;
}
}
QUAD_CLT_AUX.processCLTQuads3d(
adjust_extrinsics, // boolean adjust_extrinsics,
adjust_poly, // boolean adjust_poly,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CHANNEL_GAINS_PARAMETERS_AUX, //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); //final int debugLevel);
if (configPath!=null) {
saveTimestampedProperties( // save config again
configPath, // full path or null
......@@ -4502,7 +4582,15 @@ private Panel panel1,
QuadCLT dbg_QUAD_CLT_AUX = QUAD_CLT_AUX;
return;
/* ======================================================================== */
/* ======================================================================== */
} else if (label.equals("Rig enhance")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
enhanceByRig();
return;
/* ======================================================================== */
} else if (label.equals("CLT rig edit")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
if (QUAD_CLT_AUX == null){
......@@ -4918,6 +5006,38 @@ private Panel panel1,
}
public boolean enhanceByRig() {
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Enhancing single-camera DSI by the dual-camera rig++++++++++++++");
}
try {
TWO_QUAD_CLT.enhanceByRig( // 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,
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);
}
return true;
}
public boolean infinityRig() {
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
......
......@@ -117,7 +117,8 @@ public class ImageDtt {
static int BI_ASTR_DIAGM_INDEX = 21; //21 - strength for main diagonal pair of the aux camera
static int BI_ASTR_DIAGO_INDEX = 22; //22 - strength for main diagonal pair of the aux camera
static int BI_STR_CROSS_INDEX = 23; //23 - strength between the main the aux camera
static int BI_TARGET_INDEX = 24; //24 - target disparity
static int BI_STR_ALL_INDEX = 24; //23 - average strength (product of strengths to 1/3 power), TODO: strength at cross disparity
static int BI_TARGET_INDEX = 25; //24 - target disparity
static String [] BIDISPARITY_TITLES = {
"disparity","disp_hor","disp_vert","disp_diagm","disp_diago",
......@@ -125,7 +126,11 @@ public class ImageDtt {
"bi-disparity","bi-disparity-dx","bi-disparity-dy",
"strength", "str_hor", "str_vert", "str_diagm", "str_diago",
"astrength", "astr_hor", "astr_vert", "astr_diagm", "astr_diago",
"bi-strength", "target"};
"bi-strength", "all-strength", "target"};
static int [] BIDISPARITY_STRENGTHS= {
BI_STR_FULL_INDEX, BI_STR_VERT_INDEX, BI_STR_DIAGM_INDEX, BI_STR_DIAGO_INDEX,
BI_ASTR_FULL_INDEX, BI_ASTR_HOR_INDEX, BI_ASTR_VERT_INDEX, BI_ASTR_DIAGM_INDEX,
BI_ASTR_DIAGO_INDEX, BI_STR_CROSS_INDEX, BI_STR_ALL_INDEX};
static int DISP_FULL_INDEX = 0; // 0 - disparity for all directions of the main camera
static int DISP_HOR_INDEX = 1; // 1 - disparity for 2 horizontal pairs of the main camera
......@@ -138,6 +143,40 @@ public class ImageDtt {
static int STR_DIAGM_INDEX = 8; //14 - strength for main diagonal pair of the main camera
static int STR_DIAGO_INDEX = 9; //15 - strength for main diagonal pair of the main camera
// ML data
static int ML_TOP_INDEX = 0; // 0 - top pair 2d correlation center area
static int ML_BOTTOM_INDEX = 1; // 1 - bottom pair 2d correlation center area
static int ML_LEFT_INDEX = 2; // 2 - left pair 2d correlation center area
static int ML_RIGHT_INDEX = 3; // 3 - right pair 2d correlation center area
static int ML_DIAGM_INDEX = 4; // 4 - main diagonal (top-left to bottom-right) pair 2d correlation center area
static int ML_DIAGO_INDEX = 5; // 5 - other diagonal (bottom-left to top-right) pair 2d correlation center area
static int ML_HOR_INDEX = 6; // 6 - horizontal pairs combined 2d correlation center area
static int ML_VERT_INDEX = 7; // 7 - vertical pairs combined 2d correlation center area
static int ML_TOP_AUX_INDEX = 8; // 8 - top pair 2d correlation center area (auxiliary camera)
static int ML_BOTTOM_AUX_INDEX = 9; // 9 - bottom pair 2d correlation center area (auxiliary camera)
static int ML_LEFT_AUX_INDEX = 10; //10 - left pair 2d correlation center area (auxiliary camera)
static int ML_RIGHT_AUX_INDEX = 11; //11 - right pair 2d correlation center area (auxiliary camera)
static int ML_DIAGM_AUX_INDEX = 12; //12 - main diagonal (top-left to bottom-right) pair 2d correlation center area (auxiliary camera)
static int ML_DIAGO_AUX_INDEX = 13; //13 - other diagonal (bottom-left to top-right) pair 2d correlation center area (auxiliary camera)
static int ML_HOR_AUX_INDEX = 14; //14 - horizontal pairs combined 2d correlation center area (auxiliary camera)
static int ML_VERT_AUX_INDEX = 15; //15 - vertical pairs combined 2d correlation center area (auxiliary camera)
static int ML_INTER_INDEX = 16; //16 - inter-camera (between two quad ones) correlation center area
static int ML_OTHER_INDEX = 17; //17 - other data: 0 (top left tile corner) - preset disparity of the tile, 1: (next element) - ground trouth data, 2:
// ground truth confidence
static int ML_DBG1_INDEX = 18; //18 - just debug data (first - auto phase correlation)
static String [] ML_TITLES = {
"top-pair", "bottom-pair", "left_pair", "right-pair", "diagm-pair", "diago-pair","hor-pairs","vert-pairs",
"top-aux", "bottom-aux", "left_aux", "right-aux", "diagm-aux", "diago-aux", "hor-aux", "vert-aux",
"inter", "other", "dbg1"};
static int ML_OTHER_TARGET = 0; // Offset to target disparity data in ML_OTHER_INDEX layer tile
static int ML_OTHER_GTRUTH = 2; // Offset to ground truth disparity data in ML_OTHER_INDEX layer tile
static int ML_OTHER_GTRUTH_STRENGTH = 4; // Offset to ground truth confidence data in ML_OTHER_INDEX layer tile
// indices in cross-camera correlation results
static int INDEX_DISP = 0;
......@@ -2389,7 +2428,7 @@ public class ImageDtt {
for (int chn = 0; chn <numcol; chn++){
double [][] data1 = clt_data[corr_pairs[pair][0]][chn][tileY][tileX];
double [][] data2 = clt_data[corr_pairs[pair][1]][chn][tileY][tileX];
for (int i = 0; i < transform_len; i++) {
/* for (int i = 0; i < transform_len; i++) {
double s1 = 0.0, s2=0.0;
for (int n = 0; n< 4; n++){
s1+=data1[n][i] * data1[n][i];
......@@ -2408,7 +2447,37 @@ public class ImageDtt {
}
tcorr_tpartial[pair][chn][n][i] *= scale;
}
} */
double [] a2 = new double[transform_len];
double sa2 = 0.0;
for (int i = 0; i < transform_len; i++) {
double s1 = 0.0, s2=0.0;
for (int n = 0; n< 4; n++){
s1+=data1[n][i] * data1[n][i];
s2+=data2[n][i] * data2[n][i];
}
a2[i] = Math.sqrt(s1*s2);
sa2 += a2[i];
}
double fz2 = sa2/transform_len * corr_fat_zero * corr_fat_zero; // fat_zero squared to match units
for (int i = 0; i < transform_len; i++) {
double scale = 1.0 / (a2[i] + fz2);
for (int n = 0; n<4; n++){
tcorr_tpartial[pair][chn][n][i] = 0;
for (int k=0; k<4; k++){
if (zi[n][k] < 0)
tcorr_tpartial[pair][chn][n][i] -=
data1[-zi[n][k]][i] * data2[k][i];
else
tcorr_tpartial[pair][chn][n][i] +=
data1[zi[n][k]][i] * data2[k][i];
}
tcorr_tpartial[pair][chn][n][i] *= scale;
}
}
// got transform-domain correlation for the pair, 1 color
}
// calculate composite color
......@@ -6248,7 +6317,7 @@ public class ImageDtt {
for (int chn = 0; chn <numcol; chn++){
double [][] data1 = clt_data[corr_pairs[pair][0]][chn][tileY][tileX];
double [][] data2 = clt_data[corr_pairs[pair][1]][chn][tileY][tileX];
for (int i = 0; i < transform_len; i++) {
/* for (int i = 0; i < transform_len; i++) {
double s1 = 0.0, s2=0.0;
for (int n = 0; n< 4; n++){
s1+=data1[n][i] * data1[n][i];
......@@ -6267,6 +6336,35 @@ public class ImageDtt {
}
tcorr_tpartial[pair][chn][n][i] *= scale;
}
} */
double [] a2 = new double[transform_len];
double sa2 = 0.0;
for (int i = 0; i < transform_len; i++) {
double s1 = 0.0, s2=0.0;
for (int n = 0; n< 4; n++){
s1+=data1[n][i] * data1[n][i];
s2+=data2[n][i] * data2[n][i];
}
a2[i] = Math.sqrt(s1*s2);
sa2 += a2[i];
}
double fz2 = sa2/transform_len * corr_fat_zero * corr_fat_zero; // fat_zero squared to match units
for (int i = 0; i < transform_len; i++) {
double scale = 1.0 / (a2[i] + fz2);
for (int n = 0; n<4; n++){
tcorr_tpartial[pair][chn][n][i] = 0;
for (int k=0; k<4; k++){
if (zi[n][k] < 0)
tcorr_tpartial[pair][chn][n][i] -=
data1[-zi[n][k]][i] * data2[k][i];
else
tcorr_tpartial[pair][chn][n][i] +=
data1[zi[n][k]][i] * data2[k][i];
}
tcorr_tpartial[pair][chn][n][i] *= scale;
}
}
// got transform-domain correlation for the pair, 1 color
}
......@@ -7084,6 +7182,8 @@ public class ImageDtt {
* @param clt_data_tile_aux aberration-corrected FD CLT data for one tile of the auxiliary quad camera [sub-camera][color][quadrant][index]
* @param filter optional low-pass filter
* @param col_weights RBG color weights in combined phase correlation
* @param ml hwidth Optional to output data for ML: half width of the output tile (0 -> 1x1, 1-> 3x3, 2->5x5). Used only if center_corr != null
* @param ml_center_corr Optional to output data for ML: output array [(2*hwidth+1)*(2*hwidth+1)] or null
* @param tcorr_combo if not null then tcorr_combo will contain full 2d correlation for debugging (now 15x15 in line scan order)
* @param tileX debug tile X
* @param tileY debug tile X
......@@ -7093,11 +7193,13 @@ public class ImageDtt {
public double [] tileInterCamCorrs(
final EyesisCorrectionParameters.CLTParameters clt_parameters,
final Correlation2d corr2d,
double [][][][] clt_data_tile_main,
double [][][][] clt_data_tile_aux,
final double [][][][] clt_data_tile_main,
final double [][][][] clt_data_tile_aux,
final double [] filter,
final double [] col_weights,
double [][] tcorr_combo,
final int ml_hwidth,
final double [] ml_center_corr,
final double [][] tcorr_combo,
final int tileX, // only used in debug output
final int tileY,
final int debugLevel) {
......@@ -7115,6 +7217,12 @@ public class ImageDtt {
Correlation2d.PAIR_HORIZONTAL, // int dir, // 0 - hor, 1 - vert, 2 - parallel to row = col (main) diagonal (0->3), 3 -2->1
1, // int ss,
(debugLevel > 0)); // boolean debug
if (ml_center_corr != null) {
corr2d.corrCenterValues(
ml_hwidth,
inter_cam_corr,
ml_center_corr);
}
if (tcorr_combo != null) {
tcorr_combo[0] = inter_cam_corr;
......@@ -7233,6 +7341,8 @@ public class ImageDtt {
* @param clt_data aberration-corrected FD CLT data [camera][color][quadrant][index]
* @param filter optional low-pass filter
* @param col_weights RBG color weights in combined phase correlation
* @param ml hwidth Optional to output data for ML: half width of the output tile (0 -> 1x1, 1-> 3x3, 2->5x5). Used only if center_corr != null
* @param ml_center_corr Optional to output data for ML: output array [(2*hwidth+1)*(2*hwidth+1)] or null
* @param tileX debug tile X
* @param tileY debug tile X
* @param debugLevel debug level
......@@ -7246,6 +7356,8 @@ public class ImageDtt {
final double [][][][] clt_data,
final double [] filter,
final double [] col_weights,
final int ml_hwidth,
final double [][] ml_center_corr,
final int tileX, // only used in debug output
final int tileY,
final int debugLevel
......@@ -7268,6 +7380,13 @@ public class ImageDtt {
// calculate interpolated "strips" to match different scales and orientations (ortho/diagonal) on the
// fine (0.5 pix) grid. ortho for scale == 1 provide even/even samples (1/4 of all), diagonal ones -
// checkerboard pattern
if (ml_center_corr != null) {
corr2d.corrCenterValues(
ml_hwidth, // int hwidth,
clt_parameters.img_dtt.corr_offset, //double offset,
corrs, // double [][] full_corr,
ml_center_corr); // double [][] center_corr)
}
double [][] strips = corr2d.scaleRotateInterpoateCorrelations(
corrs, // double [][] correlations,
......@@ -7307,6 +7426,7 @@ public class ImageDtt {
if (Double.isNaN(strength)) {
System.out.println("BUG: 1. strength should not be NaN");
}
// Ignores negative values!
corr_stat = corr2d.getMaxXCm( // get fractional center as a "center of mass" inside circle/square from the integer max
strip_combo, // double [] data, // [data_size * data_size]
ixy[0], // int ixcenter, // integer center x
......@@ -7335,7 +7455,7 @@ public class ImageDtt {
tileY ); // int tileY
double [] lma_disparity_strength = null;
if (lma != null) {
double [] mod_disparity_diff = null;
// double [] mod_disparity_diff = null;
double [][] dir_corr_strength = null;
lma_disparity_strength = lma.getDisparityStrength();
if (debugLevel > 0){
......@@ -7355,7 +7475,9 @@ public class ImageDtt {
}
// Correction for far foreground objects
if ((clt_parameters.img_dtt.fo_correct && (strength > 0 * clt_parameters.img_dtt.fo_min_strength)) || get4dirs) {
// if ((clt_parameters.img_dtt.fo_correct && (strength > 0 * clt_parameters.img_dtt.fo_min_strength)) || get4dirs) {
// no fo_correct for the rig!
if (get4dirs) {
// try all dirs:
dir_corr_strength = corr2d.corr4dirsLMA(
clt_parameters.img_dtt, // ImageDttParameters clt_parameters.img_dtt,
......@@ -7404,7 +7526,7 @@ public class ImageDtt {
result[STR_DIAGO_INDEX] = 0.0;
}
/*
mod_disparity_diff = corr2d.foregroundCorrect(
clt_parameters.img_dtt.fo_far, // boolean bg,
clt_parameters.img_dtt.fo_ortho, // boolean ortho,
......@@ -7425,7 +7547,7 @@ public class ImageDtt {
result[DISP_FULL_INDEX] = disparity;
}
}
*/
}
}
}
......@@ -7577,19 +7699,18 @@ public class ImageDtt {
public double [][][][][][][] clt_bi_quad(
final EyesisCorrectionParameters.CLTParameters clt_parameters,
final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
// final int [][] tile_op_main, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
// final int [][] tile_op_aux, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
final double [][][] image_data_main, // first index - number of image in a quad
final double [][][] image_data_aux, // first index - number of image in a quad
final boolean [][] saturation_main, // (near) saturated pixels or null
final boolean [][] saturation_aux, // (near) saturated pixels or null
// correlation results - combo will be for the correation between two quad cameras
// correlation results - combo will be for the correlation between two quad cameras
final double [][][][] clt_corr_combo, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [type][tilesY][tilesX] should be set by caller
// types: 0 - selected correlation (product+offset), 1 - sum
final double [][] disparity_bimap, // [23][tilesY][tilesX], only [6][] is needed on input or null - do not calculate
// last 2 - contrast, avg/ "geometric average)
final double [][] ml_data, // data for ML - 18 layers - 4 center areas (3x3, 5x5,..) per camera-per direction, 1 - composite, and 1 with just 1 data (target disparity)
final double [][][][] texture_tiles_main, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
final double [][][][] texture_tiles_aux, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
final int width,
......@@ -7638,6 +7759,8 @@ public class ImageDtt {
}
}
// get ml_data half width
final int ml_hwidth = (ml_data != null)?(((int) Math.round(Math.sqrt(ml_data[0].length/nTilesInChn)) - 1) / 2):0;
// Create window to select center correlation strip using
// ortho_height - full width of non-zero elements
......@@ -7661,13 +7784,6 @@ public class ImageDtt {
System.out.println("clt_aberrations_quad_corr(): width="+width+" height="+height+" transform_size="+clt_parameters.transform_size+
" debug_tileX="+debug_tileX+" debug_tileY="+debug_tileY+" globalDebugLevel="+globalDebugLevel);
}
/*
final int [][] zi =
{{ 0, 1, 2, 3},
{-1, 0, -3, 2},
{-2, -3, 0, 1},
{ 3, -2, -1, 0}};
*/
final int [][] corr_pairs ={ // {first, second, rot} rot: 0 - as is, 1 - swap y,x
{0,1,0},
{2,3,0},
......@@ -7765,6 +7881,12 @@ public class ImageDtt {
double [][] tcorr_combo = null; // [15*15] pixel space
double [][][][] clt_data_main = new double[quad_main][nChn][][];
double [][][][] clt_data_aux = new double[quad_aux][nChn][][];
double [][] ml_data_main = (ml_data != null)? new double [ML_TOP_AUX_INDEX][(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
double [][] ml_data_aux = (ml_data != null)? new double [ML_TOP_AUX_INDEX][(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
double [] ml_data_inter = (ml_data != null)? new double [(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
// double [] ml_data_other = (ml_data != null)? new double [(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
double [] ml_data_dbg1 = (ml_data != null)? new double [(2*ml_hwidth +1)*(2*ml_hwidth +1)]:null;
Correlation2d corr2d = new Correlation2d(
clt_parameters.img_dtt, // ImageDttParameters imgdtt_params,
......@@ -7998,6 +8120,8 @@ public class ImageDtt {
clt_data_main, // final double [][][][] clt_data,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
ml_hwidth, // final int ml_hwidth,
ml_data_main, // final double [][] ml_center_corr,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
......@@ -8009,6 +8133,8 @@ public class ImageDtt {
clt_data_aux, // final double [][][][] clt_data,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
ml_hwidth, // final int ml_hwidth,
ml_data_aux, // final double [][] ml_center_corr,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
......@@ -8044,6 +8170,8 @@ public class ImageDtt {
clt_data_aux, // double [][][][] clt_data_tile_aux,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
ml_hwidth, // final int ml_hwidth,
ml_data_inter, // final double [] ml_center_corr,
tcorr_combo, // double [][] tcorr_combo,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
......@@ -8053,7 +8181,92 @@ public class ImageDtt {
disparity_bimap[BI_STR_CROSS_INDEX][nTile] = inter_corrs_dxy[INDEX_STRENGTH];
disparity_bimap[BI_DISP_CROSS_DX_INDEX][nTile] = inter_corrs_dxy[INDEX_DX];
disparity_bimap[BI_DISP_CROSS_DY_INDEX][nTile] = inter_corrs_dxy[INDEX_DY];
// TODO: Use strength for the same residual disparity
disparity_bimap[BI_STR_ALL_INDEX][nTile] =
Math.pow(inter_corrs_dxy[INDEX_STRENGTH]*
disparity_bimap[BI_STR_FULL_INDEX][nTile]*
disparity_bimap[BI_ASTR_FULL_INDEX][nTile], 1.0/3);
}
// finalize ML stuff
if (ml_data != null) {
// save data for the main camera
for (int nlayer = 0; nlayer < ML_TOP_AUX_INDEX; nlayer++) {
// save main camera data
corr2d.saveMlTile(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
nlayer + 0, // int ml_layer,
ml_data_main[nlayer], // double [] ml_tile,
tilesX); // int tilesX);
// save aux_camera data
corr2d.saveMlTile(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
nlayer + ML_TOP_AUX_INDEX, // int ml_layer,
ml_data_aux[nlayer], // double [] ml_tile,
tilesX); // int tilesX);
}
// save inter-camera correlation
corr2d.saveMlTile(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ML_INTER_INDEX, // int ml_layer,
ml_data_inter, // double [] ml_tile,
tilesX); // int tilesX);
// save oter data (just 1 value)
/*
corr2d.saveMlTile(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ML_OTHER_INDEX, // int ml_layer,
ml_data_other, // double [] ml_tile,
tilesX); // int tilesX);
*/
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ML_OTHER_INDEX, // int ml_layer,
ML_OTHER_TARGET , // int ml_index,
disparity_main, // target disparitydouble ml_value,
tilesX); // int tilesX);
if (ml_data_dbg1 != null) {
tileInterCamCorrs(
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
corr2d, // final Correlation2d corr2d,
clt_data_main, // double [][][][] clt_data_tile_main,
clt_data_main, // double [][][][] clt_data_tile_aux,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
ml_hwidth, // final int ml_hwidth,
ml_data_dbg1, // final double [] ml_center_corr,
null, // double [][] tcorr_combo,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
corr2d.saveMlTile(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ML_DBG1_INDEX, // int ml_layer,
ml_data_dbg1, // double [] ml_tile,
tilesX); // int tilesX);
}
}
} // if (disparity_map != null){ // not null - calculate correlations
if (tcorr_combo != null) { // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
......
......@@ -75,9 +75,9 @@ public class ImageDttParameters {
public boolean cnvx_add3x3 = true; // always select 3x3 cells around integer maximum
// Used for common interpolated stripes
public int corr_wndy_size = 9; // number of rows to calculate CM disparity
public double corr_wndy_hwidth = 6.0; // 50% window cutoff height
public double corr_wndy_blur = 5.0; // 100% to 0 % vertical transition range
public int corr_wndy_size = 2; // 9; // number of rows to calculate CM disparity
public double corr_wndy_hwidth = 1.0; // 6.0; // 50% window cutoff height
public double corr_wndy_blur = 1.0; // 5.0; // 100% to 0 % vertical transition range
public int corr_wndx_size = 9; // half number of columns to calculate CM disparity (each row has only odd/even columns, so disparity range is smaller
public double corr_wndx_hwidth = 6.0; // 50% window cutoff width
public double corr_wndx_blur = 5.0; // 100% to 0 % vertical transition range
......
......@@ -2584,6 +2584,8 @@ public class QuadCLT {
}
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++){
......@@ -3097,13 +3099,21 @@ public class QuadCLT {
SetChannels [] setChannels(
int debugLevel) {
return setChannels(null, debugLevel);
}
SetChannels [] setChannels(
String single_set_name, // process only files that contain specified series (timestamp) in the name
int debugLevel) {
String [] sourceFiles=correctionsParameters.getSourcePaths();
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)) {
if ((sourceFiles[nFile]!=null) && (sourceFiles[nFile].length()>1) && ((single_set_name == null) || (sourceFiles[nFile].contains(single_set_name)))) {
int [] channels={correctionsParameters.getChannelFromSourceTiff(sourceFiles[nFile])};
if (correctionsParameters.isJP4()){
int subCamera= channels[0]- correctionsParameters.firstSubCamera; // to match those in the sensor files
......@@ -3129,7 +3139,7 @@ public class QuadCLT {
int [][] fileIndices=new int [numImagesToProcess][2]; // file index, channel number
int index=0;
for (int nFile=0;nFile<enabledFiles.length;nFile++){ // enabledFiles not used anymore?
if ((sourceFiles[nFile]!=null) && (sourceFiles[nFile].length()>1)) {
if ((sourceFiles[nFile]!=null) && (sourceFiles[nFile].length()>1) && ((single_set_name == null) || (sourceFiles[nFile].contains(single_set_name)))) {
int [] channels={correctionsParameters.getChannelFromSourceTiff(sourceFiles[nFile])};
if (correctionsParameters.isJP4()){
int subCamera= channels[0]- correctionsParameters.firstSubCamera; // to match those in the sensor files
......@@ -3171,6 +3181,8 @@ public class QuadCLT {
}
return sc;
}
int getTotalFiles(SetChannels [] sc) {
int nf = 0;
for (int i = 0; i < sc.length; i++) nf+=sc[i].fileNumber().length;
......@@ -5500,7 +5512,6 @@ public class QuadCLT {
boolean adjust_poly,
EyesisCorrectionParameters.CLTParameters clt_parameters,
EyesisCorrectionParameters.DebayerParameters debayerParameters,
// EyesisCorrectionParameters.NonlinParameters nonlinParameters,
EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CorrectionColorProc.ColorGainsParameters channelGainParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
......@@ -5511,6 +5522,13 @@ public class QuadCLT {
{
this.startTime=System.nanoTime();
String [] sourceFiles=correctionsParameters.getSourcePaths();
SetChannels [] set_channels=setChannels(debugLevel);
if ((set_channels == null) || (set_channels.length==0)) {
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;
......@@ -5568,6 +5586,10 @@ public class QuadCLT {
}
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++){
......@@ -5751,15 +5773,37 @@ public class QuadCLT {
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();
boolean [][] saturation_imp = (clt_parameters.sat_level > 0.0)? new boolean[channelFiles.length][] : null;
double [] scaleExposures = new double[channelFiles.length];
ImagePlus [] imp_srcs = conditionImageSet(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
sourceFiles, // String [] sourceFiles,
set_channels[nSet].name(), // String set_name,
referenceExposures, // double [] referenceExposures,
channelFiles, // int [] channelFiles,
scaleExposures, //output // double [] scaleExposures
saturation_imp, //output // boolean [][] saturation_imp,
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"
saturation_imp, // boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
debayerParameters,
// nonlinParameters,
colorProcParameters,
// channelGainParameters,
rgbParameters,
threadsMax, // maximal number of threads to launch
updateStatus,
......@@ -5774,16 +5818,13 @@ public class QuadCLT {
adjust_poly,
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus,// final boolean updateStatus,
// false, // final boolean batch_mode,
debugLevel); // final int debugLevel)
} else {
expandCLTQuad3d( // returns ImagePlus, but it already should be saved/shown
imp_srcs, // [srcChannel], // should have properties "name"(base for saving results), "channel","path"
clt_parameters,
debayerParameters,
// nonlinParameters,
colorProcParameters,
channelGainParameters,
rgbParameters,
......@@ -5793,26 +5834,28 @@ public class QuadCLT {
}
Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+setNames.size()+") finished at "+
// if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+setNames.size()+") finished at "+
// IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
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) {
System.out.println("User requested stop");
return;
}
}
System.out.println("Processing "+fileIndices.length+" files finished at "+
// System.out.println("Processing "+fileIndices.length+" files finished at "+
// IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
System.out.println("Processing "+getTotalFiles(set_channels)+" files finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
}
// public ImagePlus preExpandCLTQuad3d(
public boolean preExpandCLTQuad3d(
ImagePlus [] imp_quad, // should have properties "name"(base for saving results), "channel","path"
boolean [][] saturation_imp, // (near) saturated pixels or null
EyesisCorrectionParameters.CLTParameters clt_parameters,
EyesisCorrectionParameters.DebayerParameters debayerParameters,
// EyesisCorrectionParameters.NonlinParameters nonlinParameters,
EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
// CorrectionColorProc.ColorGainsParameters channelGainParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
......@@ -5845,12 +5888,7 @@ public class QuadCLT {
tp.resetCLTPasses();
tp.setTrustedCorrelation(clt_parameters.grow_disp_trust);
// final int tilesX = tp.getTilesX();
// final int tilesY = tp.getTilesY();
// final double trustedCorrelation = tp.getTrustedCorrelation();
/// CLTPass3d bgnd_data = CLTBackgroundMeas( // measure background
CLTPass3d bgnd_data = CLTBackgroundMeas( // measure background
image_data, //
saturation_imp, // boolean [][] saturation_imp, // (near) saturated pixels or null
......@@ -6559,7 +6597,7 @@ public class QuadCLT {
public boolean expandCLTQuad3d(
ImagePlus [] imp_quad, // should have properties "name"(base for saving results), "channel","path"
// ImagePlus [] imp_quad, // should have properties "name"(base for saving results), "channel","path"
EyesisCorrectionParameters.CLTParameters clt_parameters,
EyesisCorrectionParameters.DebayerParameters debayerParameters,
// EyesisCorrectionParameters.NonlinParameters nonlinParameters,
......@@ -6973,7 +7011,7 @@ public class QuadCLT {
tp.threadsMax, // maximal number of threads to launch
false, // updateStatus,
debugLevel);
passes.add(refined);
passes.add(refined); // adding new scan, not yet measured
refine_pass ++; // tp.refinePassSetup adds to the list
if (show_expand || (clt_parameters.show_expand && dbg_pass)) {
tp.showScan(
......@@ -8825,7 +8863,7 @@ public class QuadCLT {
if (ok) {
System.out.println("Explore 3d space");
expandCLTQuad3d( // returns ImagePlus, but it already should be saved/shown
imp_srcs, // [srcChannel], // should have properties "name"(base for saving results), "channel","path"
// imp_srcs, // [srcChannel], // should have properties "name"(base for saving results), "channel","path"
clt_parameters,
debayerParameters,
// nonlinParameters,
......
......@@ -2075,7 +2075,7 @@ public class TileProcessor {
public void showScan(
CLTPass3d scan,
String title)
String in_title)
{
showDoubleFloatArrays sdfa_instance = null;
sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
......@@ -2101,10 +2101,14 @@ public class TileProcessor {
"diff2maxAvg", // 18
"normStrength", // 19
"overexp"}; // 20
String title=in_title;
if (scan.isMeasured()) title+="+M"; else title+="-M";
if (scan.isProcessed()) title+="+P"; else title+="-P";
if (scan.isCombo()) title+="+C"; else title+="-C";
if (scan.getTextureTiles()!=null) title+="+T"; else title+="-T";
int tlen = tilesX*tilesY;
// double [][] dbg_img = new double[titles.length][tlen];
double [][] dbg_img = new double[titles.length][];
if (scan.tile_op != null) dbg_img[ 0] = new double[tlen];
if (scan.disparity != null) dbg_img[ 2] = new double[tlen];
......@@ -2153,10 +2157,10 @@ public class TileProcessor {
}
}
title += "-";
if (scan.isMeasured()) title += "M";
if (scan.isProcessed()) title += "P";
if (scan.isCombo()) title += "C";
// title += "-";
// if (scan.isMeasured()) title += "M";
// if (scan.isProcessed()) title += "P";
// if (scan.isCombo()) title += "C";
sdfa_instance.showArrays(dbg_img, tilesX, tilesY, true, title,titles);
System.out.println("showScan("+title+"): isMeasured()="+scan.isMeasured()+", isProcessed()="+scan.isProcessed()+", isCombo()="+scan.isCombo());
......@@ -4165,7 +4169,7 @@ public class TileProcessor {
// final double [][][] image_data, // first index - number of image in a quad
EyesisCorrectionParameters.CLTParameters clt_parameters,
// disparity range - differences from
boolean use_supertiles, // false
boolean use_supertiles, // false (2018)
int bg_scan_index, // 0
double disparity_far, // 0.3
double disparity_near, // 150
......@@ -4343,9 +4347,9 @@ public class TileProcessor {
// try renovated supertiles. Do twice to show both original and blured histograms
double [] dbg_orig_disparity = null;
double [] dbg_with_super_disp = null;
double [] dbg_outlayers = null;
double [] dbg_outliers = null;
if (use_supertiles) { // *** currently is not used (obsolete ***
if (use_supertiles) { // *** currently is not used (2018 obsolete ***)
String [] dbg_st_titles = {"raw", "blurred"+clt_parameters.stSigma,"max-min-max"};
double [][] dbg_hist = new double[dbg_st_titles.length][];
......@@ -4355,22 +4359,9 @@ public class TileProcessor {
clt_parameters.stStepThreshold, // double step_threshold,
clt_parameters.stMinDisparity, // double min_disparity,
clt_parameters.grow_disp_max, // double max_disparity,
// clt_parameters.stFloor, // double strength_floor,
// clt_parameters.stPow, // double strength_pow,
0.0,// NO BLUR double stBlurSigma)
false, //clt_parameters.stSmplMode, // Use sample mode (false - regular tile mode)
clt_parameters.mlfp, // filter parameters
// clt_parameters.stSmplSide, // Sample size (side of a square)
// clt_parameters.stSmplNum, // Number after removing worst
// clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
// clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
// clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[0] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -4380,22 +4371,9 @@ public class TileProcessor {
clt_parameters.stStepThreshold, // double step_threshold,
clt_parameters.stMinDisparity, // double min_disparity,
clt_parameters.grow_disp_max, // double max_disparity,
// clt_parameters.stFloor, // double strength_floor,
// clt_parameters.stPow, // double strength_pow,
clt_parameters.stSigma, // with blur double stBlurSigma)
false, //clt_parameters.stSmplMode, // Use sample mode (false - regular tile mode)
clt_parameters.mlfp, // filter parameters
// clt_parameters.stSmplSide, // Sample size (side of a square)
// clt_parameters.stSmplNum, // Number after removing worst
// clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
// clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
// clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[1] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -4422,12 +4400,12 @@ public class TileProcessor {
if (dbg_with_super_disp != null) dbg_with_super_disp = dbg_with_super_disp.clone(); // else no super disparity available
}
} // end of if (use_supertiles) { // *** currently is not used (2018 obsolete ***)
// replace weak outlaye tiles with weighted averages (modifies disparity)
boolean[] outlayers = scan_prev.replaceWeakOutlayers(
// replace weak outliers tiles with weighted averages (modifies disparity)
boolean[] outliers = scan_prev.replaceWeakOutliers(
null, // final boolean [] selection,
clt_parameters.outlayerStrength , //final double weakStrength, // strength to be considered weak, subject to this replacement
clt_parameters.outlayerDiff, // final double maxDiff)
......@@ -4436,10 +4414,10 @@ public class TileProcessor {
0.5 * disparity_far,
2.0 * disparity_near,
debugLevel);
dbg_outlayers = new double[outlayers.length];
dbg_outliers = new double[outliers.length];
for (int i = 0; i < outlayers.length; i++){
dbg_outlayers[i] = outlayers[i]? 1.0:0.0;
for (int i = 0; i < outliers.length; i++){
dbg_outliers[i] = outliers[i]? 1.0:0.0;
}
// set disparity for border pixels (may be overkill)
......@@ -4482,7 +4460,7 @@ public class TileProcessor {
clt_parameters.tiIterations, // final int num_passes,
Math.pow(10.0, -clt_parameters.tiPrecision), // final double maxDiff, // maximal change in any of the disparity values
neighbors, // final int [] neighbors, // +1 - up (N), +2 - up-right - NE, ... +0x80 - NW
scan_prev.getDisparity(), // final double [] disparity, // current disparity value
scan_prev.getDisparity(), // final double [] disparity, // current disparity value - will be modified
scan_prev.getDisparity().clone(), // final double [] measured_disparity, // measured disparity
scan_prev.getStrength(), // final double [] strength,
null, // this_hor_disparity, // final double hor_disparity, // not yet used
......@@ -4492,13 +4470,7 @@ public class TileProcessor {
clt_parameters,
threadsMax, // maximal number of threads to launch
debugLevel); // (clt_3d_passes.size() == 3)? 2: 0); // debugLevel);
// double [] dbg_after3 = scan_prev.getDisparity().clone();
/*
double [] measured_disparity = dp.dbgRescaleToPixels(
this_disparity,
clt_parameters.transform_size); // int tile_size)
*/
// prepare new task and run
double [][] disparityTask = new double [tilesY][tilesX];
int [][] tile_op = new int [tilesY][tilesX];
......@@ -4525,7 +4497,7 @@ public class TileProcessor {
for (int i = 0; i < masked_filtered.length; i++){
if (!grown[i]) masked_filtered[i] = Double.NaN;
}
if (show_super && false){ // something is broken, java.lang.NullPointerException at TileProcessor.refinePassSetup(TileProcessor.java:4488)
if (show_super && (debugLevel > 100)){ // something is broken, java.lang.NullPointerException at TileProcessor.refinePassSetup(TileProcessor.java:4488)
String [] dbg_disp_tiltes={"masked", "filtered", "disp_combo", "disparity","st_disparity", "strength",
"st_strength","outlayers","these","border","border_tiles"}; // ,"before","after","after1","after2","after3","neib"};
double [][] dbg_disp = new double [dbg_disp_tiltes.length][];
......@@ -4536,22 +4508,15 @@ public class TileProcessor {
dbg_disp[4] = scan_prev.getBgDisparity(); // -
dbg_disp[5] = scan_prev.getStrength(); // +
dbg_disp[6] = scan_prev.getBgStrength(); // -
dbg_disp[7] = dbg_outlayers; // +
dbg_disp[7] = dbg_outliers; // +
dbg_disp[8] = new double [masked_filtered.length];
dbg_disp[9] = new double [masked_filtered.length];
dbg_disp[10] = new double [masked_filtered.length];
// dbg_disp[16] = new double [masked_filtered.length];
for (int i = 0; i < dbg_disp[8].length; i++){
dbg_disp[8][i] = these_tiles[i]? 1.0: 0.0;
dbg_disp[9][i] = border[i]? 1.0: 0.0;
dbg_disp[10][i] = borderTiles[i]? 1.0: 0.0;
// dbg_disp[16][i] = neighbors[i];
}
// dbg_disp[11] = dbg_before;
// dbg_disp[12] = dbg_after;
// dbg_disp[13] = dbg_after1;
// dbg_disp[14] = dbg_after2;
// dbg_disp[15] = dbg_after3;
sdfa_instance.showArrays(dbg_disp, tilesX, tilesY, true, "refine_disparity_supertiles-"+clt_3d_passes.size(),dbg_disp_tiltes);
}
......@@ -4561,8 +4526,6 @@ public class TileProcessor {
scan_next.tile_op = tile_op;
scan_next.border_tiles = borderTiles;
scan_next.selected = grown; // includes border_tiles
// clt_3d_passes.add(scan_next); // was here
// }
return scan_next;
}
......@@ -5646,36 +5609,6 @@ public class TileProcessor {
total += num_added;
System.out.println("Total: added "+total+ " links between supertiles");
}
/*
while (true) {
int num_added = 0;
if (clt_parameters.plFillSquares){
num_added += lp.fillSquares(
st.planes_mod,
lp.getRelaxComplete() * lp.getExNeibCost(),
2, // debugLevel, // 0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
}
if (debugLevel > -1) {
System.out.println("after fillSquares() added "+num_added);
}
if (clt_parameters.plCutCorners){
num_added += lp.cutCorners(
st.planes_mod,
lp.getRelaxComplete() * lp.getExNeibCost(),
2, // debugLevel, // 0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
}
if (debugLevel > -1) {
System.out.println("after cutCorners() added (cumulative) "+num_added);
}
if (num_added == 0) break;
}
*/
}
......@@ -5725,6 +5658,10 @@ public class TileProcessor {
}
public void showPlaneData(
String suffix,
EyesisCorrectionParameters.CLTParameters clt_parameters,
......@@ -6047,14 +5984,12 @@ public class TileProcessor {
public void secondPassSetup( // prepare tile tasks for the second pass based on the previous one(s)
// final double [][][] image_data, // first index - number of image in a quad
EyesisCorrectionParameters.CLTParameters clt_parameters,
boolean use_supertiles,
int bg_scan_index,
// disparity range - differences from
double disparity_far, //
double disparity_near, //
// double this_sure, // minimal strength to be considered definitely background
double ex_strength, // minimal 4-corr strength to trust tile
double ex_nstrength, // minimal 4-corr strength divided by channel diff for new (border) tiles
double this_maybe, // maximal strength to ignore as non-background
......@@ -6072,7 +6007,6 @@ public class TileProcessor {
CLTPass3d scan_bg = clt_3d_passes.get(bg_scan_index); //
CLTPass3d scan_prev = clt_3d_passes.get(clt_3d_passes.size() -1); // get last one
CLTPass3d scan_lm = getLastMeasured(-1);
// boolean [] border_tiles = (scan_lm != null) ? scan_lm.getBorderTiles() : null;
showDoubleFloatArrays sdfa_instance = null;
if (!batch_mode && (debugLevel > -1)) sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
......@@ -6081,7 +6015,6 @@ public class TileProcessor {
boolean [] these_tiles;
int [] replaced = null; // +1 - hor, +2 - vert
// int [] replaced0 = null; // +1 - hor, +2 - vert
if (!clt_parameters.ortho_old) {
replaced = combineOrthoDisparity(
......@@ -6098,7 +6031,6 @@ public class TileProcessor {
clt_parameters.or_absVert, // 0.19; // Minimal vertical absolute scaled offset ortho strength needed for replacement
clt_parameters.or_maxDisp, // 5.0; // Maximal disparity to apply ortho correction
clt_parameters.show_ortho_combine, // show replacement of disparity/strength by those of hor/vert
debugLevelInner);
if (clt_parameters.poles_fix) {
......@@ -6121,7 +6053,6 @@ public class TileProcessor {
if (debugLevel > 0){
System.out.println("fixVerticalPoles() replaced "+ numFixed+ " tiles.");
}
// replaced0 = replaced.clone();
for (int i = 0; i < replaced.length; i++){
if (tilesHor[i]) replaced[i] |= 1;
}
......@@ -6130,12 +6061,10 @@ public class TileProcessor {
scan_prev, // final CLTPass3d scan,
scan_bg.selected, // get from selected in clt_3d_passes.get(0);
clt_parameters.ex_min_over,// when expanding over previously detected (by error) background, disregard far tiles
// border_tiles, // final boolean [] border_tiles, // last measured boirder tiles
scan_lm, // final CLTPass3d last_meas, // last measured scan (with border_tiles and getSecondMaxDiff
replaced, // final int [] horVertMod, // +1 - modified by hor correlation, +2 - modified by vert correlation (or null)
disparity_far, // final double disparity_far, //
disparity_near, // final double disparity_near, //
// this_sure, // final double this_sure, // minimal strength to be considered definitely background
ex_strength, // final double ex_strength, // minimal 4-corr strength to trust tile
ex_nstrength, // final double ex_nstrength, // minimal 4-corr strength divided by channel diff for new (border) tiles
......@@ -6155,8 +6084,6 @@ public class TileProcessor {
clt_parameters.fill_gaps, // fill_gaps, // int depth, // same as grow - odd - 4 directions, even - 8
clt_parameters.fill_final, // final boolean poison_gaps, // Do not fill gaps that have even single "poisoned" tile
true, // final boolean zero_gap_strength, // set strength to zero when covering gaps
// final int threadsMax, // maximal number of threads to launch
// final boolean updateStatus,
batch_mode ? -5: 2); //debugLevel);
} else { //!ortho_old
these_tiles= combineHorVertDisparity_old(
......@@ -6173,8 +6100,6 @@ public class TileProcessor {
scan_prev.combineHorVertStrength(true, false); // strength now max of original and horizontal. Use scale instead of boolean?
}
double [] this_disparity = scan_prev.getDisparity(); // returns a copy of the FPGA-generated disparity combined with the target one
double [] this_strength = scan_prev.getStrength(); // cloned, can be modified/ read back
......@@ -6193,16 +6118,16 @@ public class TileProcessor {
scan_prev.setSelected(these_tiles); // New
if (!batch_mode) {
showScan( scan_prev, "LastFilteredScan");
}
//************************************************
// Show supertiles histograms
// if (clt_parameters.stShow){
// try renovated supertiles. Do twice to show both original and blurred histograms
double [] dbg_orig_disparity = null;
double [] dbg_with_super_disp = null;
double [] dbg_outlayers = null;
double [] dbg_outliers = null;
// boolean [] grown = these_tiles.clone();
if (use_supertiles || show_st) {// currently not use (only to show)
......@@ -6215,25 +6140,10 @@ public class TileProcessor {
clt_parameters.stStepThreshold, // double step_threshold,
clt_parameters.stMinDisparity, // double min_disparity,
clt_parameters.grow_disp_max, // double max_disparity,
// clt_parameters.stFloor, // double strength_floor,
// clt_parameters.stPow, // double strength_pow,
0.0, // NO BLUR double stBlurSigma)
false, //clt_parameters.stSmplMode, // Use sample mode (false - regular tile mode)
clt_parameters.mlfp, // Filter parameters
// clt_parameters.stSmplSide, // Sample size (side of a square)
// clt_parameters.stSmplNum, // Number after removing worst
// clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
// clt_parameters.stSmplWnd, // Use window functions for the samples
// clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[0] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -6243,23 +6153,9 @@ public class TileProcessor {
clt_parameters.stStepThreshold, // double step_threshold,
clt_parameters.stMinDisparity, // double min_disparity,
clt_parameters.grow_disp_max, // double max_disparity,
// clt_parameters.stFloor, // double strength_floor,
// clt_parameters.stPow, // double strength_pow,
clt_parameters.stSigma, // with blur double stBlurSigma)
false, //clt_parameters.stSmplMode, // Use sample mode (false - regular tile mode)
clt_parameters.mlfp, // Filter parameters
// clt_parameters.stSmplSide, // Sample size (side of a square)
// clt_parameters.stSmplNum, // Number after removing worst
// clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
// clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
// clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[1] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -6272,44 +6168,7 @@ public class TileProcessor {
if (show_st){
sdfa_instance.showArrays(dbg_hist, hist_width0, hist_height0, true, "disparity_supertiles_histograms",dbg_st_titles);
}
/**
st.processPlanes2(
null, // final boolean [] selected, // or null
0.3, // final double min_disp,
false, // final boolean invert_disp, // use 1/disparity
clt_parameters.plDispNorm, // = 2.0; // Normalize disparities to the average if above
clt_parameters.plMinPoints, // = 5; // Minimal number of points for plane detection
clt_parameters.plTargetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
clt_parameters.plFractOutliers, // = 0.3; // Maximal fraction of outliers to remove
clt_parameters.plMaxOutliers, // = 20; // Maximal number of outliers to remove
geometryCorrection,
clt_parameters.correct_distortions,
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
if (use_supertiles) {
scan_prev.getBgDispStrength( // calculate (check non-null)?
clt_parameters.stMinBgDisparity, // final double minBgDisparity,
clt_parameters.stMinBgFract); // final double minBgFract);
dbg_orig_disparity = scan_prev.getDisparity().clone();
// combine weak with supertiles
dbg_with_super_disp = scan_prev.combineSuper(
true, //boolean updateStrength, // use ST strength if true, keep original (update disparity only) if false
clt_parameters.stStrengthScale, // Multiply st strength if used instead of regular strength (only if updateStrength)
clt_parameters.stUseDisp); //.15; // Use background disparity from supertiles if tile strength is less
if (dbg_with_super_disp != null) dbg_with_super_disp = dbg_with_super_disp.clone(); // else no super disparity available
}
*/
}
// return scan_next;
}
//==================
......@@ -6505,525 +6364,6 @@ public class TileProcessor {
public void thirdPassSetupOld( // prepare tile tasks for the second pass based on the previous one(s)
EyesisCorrectionParameters.CLTParameters clt_parameters,
double disparity_far, //
double disparity_near, //
GeometryCorrection geometryCorrection,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
CLTPass3d scan_prev = clt_3d_passes.get(clt_3d_passes.size() -1); // get last one
double [] dbg_orig_disparity = null;
double [] dbg_with_super_disp = null;
double [] dbg_outlayers = null;
showDoubleFloatArrays sdfa_instance = null;
if (debugLevel > -1) sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
boolean [] these_tiles = scan_prev.getSelected();
double [] this_disparity = scan_prev.getDisparity(); // returns a copy of the FPGA-generated disparity combined with the target one
double [] this_strength = scan_prev.getStrength(); // cloned, can be modified/ read back
dbg_orig_disparity = this_disparity.clone();
SuperTiles st = scan_prev.getSuperTiles();
if (clt_parameters.plSnapDispAny >= 0.0) {
double [] snap_disparity = st.snapDisparity(
this_disparity, // final double [] disparity,
this_strength, // final double [] strength,
null, // this_selection, // final boolean [] selection, // can be null
clt_parameters.plDispNorm, // final double dispNorm, // plDispNorm
clt_parameters.plSnapDispAny, //final double snapDispAny, // = .2, // Maximal (scaled by plDispNorm) disparity difference to snap to plane at any strength
clt_parameters.plSnapStrengthAny,//final double snapStrengthAny, // = .2, // Maximal strength to fit any distance (if does not fit otherwise - treat as zero strength
clt_parameters.plSnapNegAny, //final double snapNegAny, // = .2, // Maximal negative disparity difference from the best match
clt_parameters.plSnapDispMax, // final double snapDispMax, // = .5, // Maximal (scaled by plDispNorm) disparity difference to snap to plane at low strength
clt_parameters.plSnapDispWeight, // final double snapDispWeight, // = .5, // Maximal disparity diff. by weight product to snap to plane
clt_parameters.plSnapZeroMode, // final int snapZeroMode, // Zero strength snap mode: 0: no special treatment, 1 - strongest, 2 - farthest
1); // final int debugLevel)
System.arraycopy(snap_disparity, 0, this_disparity, 0, snap_disparity.length);
}
if (clt_parameters.replaceWeakOutlayers) {
boolean[] outlayers = scan_prev.replaceWeakOutlayers(
null, // final boolean [] selection,
clt_parameters.outlayerStrength , //final double weakStrength, // strength to be considered weak, subject to this replacement
clt_parameters.outlayerDiff, // final double maxDiff)
clt_parameters.outlayerDiffPos, // final double maxDiff)
clt_parameters.outlayerDiffNeg, // final double maxDiff)
0.5 * disparity_far,
2.0 * disparity_near,
debugLevel);
dbg_outlayers = new double[outlayers.length];
for (int i = 0; i < outlayers.length; i++){
dbg_outlayers[i] = outlayers[i]? 1.0:0.0;
}
double [] masked_filtered = scan_prev.getDisparity().clone();
if (clt_parameters.stShow){
String [] dbg_disp_tiltes={"masked", "filtered", "disp_combo", "disparity","st_disparity", "strength", "st_strength","outlayers"};
double [][] dbg_disp = new double [dbg_disp_tiltes.length][];
dbg_disp[0] = masked_filtered; //+
dbg_disp[1] = scan_prev.getDisparity(); //+
dbg_disp[2] = dbg_with_super_disp; // -
dbg_disp[3] = dbg_orig_disparity; //+
dbg_disp[4] = scan_prev.getBgDisparity();
dbg_disp[5] = scan_prev.getStrength(); //+
dbg_disp[6] = scan_prev.getBgStrength();
dbg_disp[7] = dbg_outlayers; // + (all 0)
sdfa_instance.showArrays(dbg_disp, tilesX, tilesY, true, "disparity_supertiles",dbg_disp_tiltes);
}
}
//clt_parameters.transform_size;
DisparityProcessor dp = new DisparityProcessor(this, clt_parameters.transform_size * geometryCorrection.getScaleDzDx());
boolean [] grown = these_tiles.clone();
growTiles(
2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
grown, // boolean [] tiles,
null); // boolean [] prohibit)
boolean [] border = grown.clone();
for (int i = 0; i < border.length; i++) border[i] &= !these_tiles[i];
// double [] dbg_before = scan_prev.getDisparity().clone();
scan_prev.fixNaNDisparity(
grown, // border, // boolean [] select, // which tiles to correct (null - all)
scan_prev.getDisparity(), // double [] disparity,
scan_prev.getStrength()); // double [] strength)
// double [] dbg_after = scan_prev.getDisparity().clone();
/// for (int i = 0; i < masked_filtered.length; i++){
/// if (!grown[i]) masked_filtered[i] = Double.NaN;
/// }
int [] neighbors = dp.getNeighbors( // creates neighbors mask from bitmask
grown, // these_tiles, // grown, // these_tiles, // boolean [] selected,
tilesX);
// int [] neighbors_orig = neighbors.clone();
double [] dbg_neib = dp.dbgShowNeighbors(
grown, // these_tiles, // grown, // these_tiles,
neighbors, // _orig, // int [] neighbors,
clt_parameters.transform_size, // int tile_size,
-1.0, // double bgnd,
1.0); // double fgnd)
double [] new_disparity = this_disparity.clone();
double [][]dbgDeriv = new double [2][]; // [these_tiles.length];
// sdfa_instance.showArrays(dbg_neib,tilesX*clt_parameters.transform_size, tilesY*clt_parameters.transform_size,"neighbors");
dp.smoothDisparity(
clt_parameters.tiDispPull, // final double dispPull, // clt_parameters.tiDispPull or 0.0
3, // final int mask, // 1 - work on internal elements, 2 - on border elements, 3 - both (internal first);
clt_parameters.tiIterations, // final int num_passes,
Math.pow(10.0, -clt_parameters.tiPrecision), // final double maxDiff, // maximal change in any of the disparity values
neighbors, // final int [] neighbors, // +1 - up (N), +2 - up-right - NE, ... +0x80 - NW
new_disparity, // final double [] disparity, // current disparity value
this_disparity, // final double [] measured_disparity, // measured disparity
this_strength, // final double [] strength,
null, // this_hor_disparity, // final double hor_disparity, // not yet used
null, // hor_strength_conv, // final double hor_strength, // not yet used
these_tiles, // grown, // these_tiles, // final boolean [] selected,
border, // final boolean [] border,
clt_parameters,
// dbgDeriv, // final double [][] dbgDeriv, //double [2][len] or null;
threadsMax, // maximal number of threads to launch
debugLevel);
double [] measured_disparity = dp.dbgRescaleToPixels(
this_disparity,
clt_parameters.transform_size); // int tile_size)
//break once
double [][] stresses = new double [clt_parameters.tiNumCycles + 1][];
double [][] neibs_broken = new double [clt_parameters.tiNumCycles][];
double [][] smooth_disparities = new double [clt_parameters.tiNumCycles + 1][];
smooth_disparities[0] = dp.dbgRescaleToPixels(
new_disparity,
clt_parameters.transform_size);
boolean [] too_far = new boolean [this_strength.length];
boolean [] too_near = new boolean [this_strength.length];
double [] true_strength = this_strength.clone(); // this strength will be modified to remove too near tiles (too far - TBD)
/** */
// for (int numCycle = 0; numCycle < clt_parameters.tiNumCycles; numCycle++) { // = 5; // Number of cycles break-smooth (after the first smooth)
for (int numCycle = 0; numCycle < 1; numCycle++) { // = 5; // Number of cycles break-smooth (after the first smooth)
// more smoothing
double disp_pull = clt_parameters.tiDispPull;
if (numCycle >= (clt_parameters.tiNumCycles -2)) {
disp_pull = clt_parameters.tiDispPullPreFinal; // 0.1 * clt_parameters.tiDispPull;
if (numCycle >= (clt_parameters.tiNumCycles -1)) {
disp_pull = clt_parameters.tiDispPullPreFinal; // 0.01 * clt_parameters.tiDispPull;
}
}
double breakScale = disp_pull / clt_parameters.tiDispPull; // 1.0;
/** */
if ((clt_parameters.tiBreakMode & 1) != 0) {
dp.breakDisparity( // break using derivatives
clt_parameters.tiBreak3 * breakScale, // clt_parameters.tiBreak, // final double break4, // clt_parameters.tiBreak/0 allow disconnecting from neighbors (fg/bg)
0, // mode, // 0: 3-rd derivative, 1: - third * first (compare positive threshold only), 2: second by abs(first) (compare positive threshold only)
neighbors, // final int [] neighbors, // UPDATED +1 - up (N), +2 - up-right - NE, ... +0x80 - NW
new_disparity, // final double [] disparity, // current disparity value
grown, // these_tiles, // final boolean [] selected,
true, // final boolean extend_flat, // if the tile is on the hor/vert edge, assume same disparity on the other side
clt_parameters.tiBreakSame, // final double k_same,
clt_parameters.tiBreakTurn, // final double k_turn,
clt_parameters,
dbgDeriv, // final double [][] dbgDeriv, //double [2][len] or null;
threadsMax, // maximal number of threads to launch
debugLevel);
}
if ((clt_parameters.tiBreakMode & 2) != 0) {
dp.breakDisparity( // break using derivatives
clt_parameters.tiBreak31 * breakScale, // clt_parameters.tiBreak, // final double break4, // clt_parameters.tiBreak/0 allow disconnecting from neighbors (fg/bg)
1, // mode, // 0: 3-rd derivative, 1: - third * first (compare positive threshold only), 2: second by abs(first) (compare positive threshold only)
neighbors, // final int [] neighbors, // UPDATED +1 - up (N), +2 - up-right - NE, ... +0x80 - NW
new_disparity, // final double [] disparity, // current disparity value
grown, // these_tiles, // final boolean [] selected,
true, // final boolean extend_flat, // if the tile is on the hor/vert edge, assume same disparity on the other side
clt_parameters.tiBreakSame, // final double k_same,
clt_parameters.tiBreakTurn, // final double k_turn,
clt_parameters,
dbgDeriv, // final double [][] dbgDeriv, //double [2][len] or null;
threadsMax, // maximal number of threads to launch
debugLevel);
}
if ((clt_parameters.tiBreakMode & 4) != 0) {
dp.breakDisparity( // break using derivatives
clt_parameters.tiBreak21 * breakScale, // clt_parameters.tiBreak, // final double break4, // clt_parameters.tiBreak/0 allow disconnecting from neighbors (fg/bg)
2, // mode, // 0: 3-rd derivative, 1: - third * first (compare positive threshold only), 2: second by abs(first) (compare positive threshold only)
neighbors, // final int [] neighbors, // UPDATED +1 - up (N), +2 - up-right - NE, ... +0x80 - NW
new_disparity, // final double [] disparity, // current disparity value
grown, // these_tiles, // final boolean [] selected,
true, // final boolean extend_flat, // if the tile is on the hor/vert edge, assume same disparity on the other side
clt_parameters.tiBreakSame, // final double k_same,
clt_parameters.tiBreakTurn, // final double k_turn,
clt_parameters,
dbgDeriv, // final double [][] dbgDeriv, //double [2][len] or null;
threadsMax, // maximal number of threads to launch
debugLevel);
}
if ((clt_parameters.tiBreakMode & 8) != 0) { // remove too far
boolean [] found = dp.findNearFar(
true, // boolean findFar,
clt_parameters.tiBreakFar, // double threshold, // select tiles with non-zero strength that are far/near
new_disparity, // current (approximated) disparity value
this_disparity, // measured disparity
this_strength, // final double [] strength, // masked by previously removed tiles as far/near
grown);//these_tiles); // final boolean [] selected);
if (found != null){
for (int i=0;i < too_far.length; i++){
too_far[i] |=found[i];
if (too_far[i]) this_strength[i] =0.0;
}
}
}
if ((clt_parameters.tiBreakMode & 16) != 0) { // remove too near
boolean [] found = dp.findNearFar(
false, // boolean findFar,
clt_parameters.tiBreakNear, // double threshold, // select tiles with non-zero strength that are far/near
new_disparity, // current (approximated) disparity value
this_disparity, // measured disparity
this_strength, // final double [] strength, // masked by previously removed tiles as far/near
grown);// these_tiles); // final boolean [] selected);
if (found != null){
for (int i=0;i < too_near.length; i++){
too_near[i] |=found[i];
if (too_near[i]) this_strength[i] =0.0;
}
}
}
/* */
if ((dbgDeriv != null) && (dbgDeriv[0] != null)) {
stresses[numCycle] = dp.dbgShowStress(
dbgDeriv, // double [][] stress,
clt_parameters.transform_size); // int tile_size)
} else {
stresses[numCycle] = null;
}
// Now heal some broken gaps back
double healOrtho = 0.0;
if (numCycle >= (clt_parameters.tiNumCycles -2)) {
healOrtho = clt_parameters.tiHealPreLast;
if (numCycle >= (clt_parameters.tiNumCycles -1)) {
healOrtho =clt_parameters.tiHealLast;
}
}
if (healOrtho > 0.0){
dp.reconnectDisparity( // connect disconnected tiles if they have close approximated disparity
healOrtho, // final double maxDiffOrto,
0, // healOrtho*1.5, // final double maxDiffDiagonal,
neighbors, // final int [] neighbors, // +1 - up (N), +2 - up-right - NE, ... +0x80 - NW
new_disparity, // final double [] disparity, // current disparity value
grown, // these_tiles, // final boolean [] selected,
threadsMax, // maximal number of threads to launch
debugLevel);
}
if (numCycle >= (clt_parameters.tiNumCycles -2)) { // only heal during last 2 passes?
if (clt_parameters.tiHealSame > 0){
int numHealed = dp.healSame( // returns number of new ortho connections // ty = 325
neighbors,
clt_parameters.tiHealSame , // int maxlen,
// just to fill in diagonals
grown, // these_tiles, // final boolean [] selected,
threadsMax,
debugLevel);
if (debugLevel > -1){
System.out.println("Healed "+numHealed+" connections");
}
}
}
neibs_broken[numCycle] = dp.dbgShowNeighbors(
grown, // these_tiles, // grown, // these_tiles,
neighbors, // _orig, // int [] neighbors,
clt_parameters.transform_size, // int tile_size,
-1.0, // double bgnd,
1.0); // double fgnd)
dp.smoothDisparity(
disp_pull, // clt_parameters.tiDispPull, // final double dispPull, // clt_parameters.tiDispPull or 0.0
3, // final int mask, // 1 - work on internal elements, 2 - on border elements, 3 - both (internal first);
clt_parameters.tiIterations, // final int num_passes,
Math.pow(10.0, -clt_parameters.tiPrecision), // final double maxDiff, // maximal change in any of the disparity values
neighbors, // final int [] neighbors, // +1 - up (N), +2 - up-right - NE, ... +0x80 - NW
new_disparity, // final double [] disparity, // current disparity value
this_disparity, // final double [] measured_disparity, // measured disparity
this_strength, // final double [] strength,
null, // this_hor_disparity, // final double hor_disparity, // not yet used
null, // hor_strength_conv, // final double hor_strength, // not yet used
grown, // these_tiles, //???? // grown, // these_tiles, // final boolean [] selected,
border, // final boolean [] border,
clt_parameters,
threadsMax, // maximal number of threads to launch
debugLevel);
smooth_disparities[numCycle+1] = dp.dbgRescaleToPixels(
new_disparity,
clt_parameters.transform_size);
}
/** */
// Just calculate stress, do not actually break (after last smoothing)
dp.breakDisparity(
0.0, // final double break4, // clt_parameters.tiBreak/0 allow disconnecting from neighbors (fg/bg)
0, // clt_parameters.tiBreakMode, // mode, // 0: 3-rd derivative, 1: - third * first (compare positive threshold only), 2: second by abs(first) (compare positive threshold only)
neighbors, // final int [] neighbors, // UPDATED +1 - up (N), +2 - up-right - NE, ... +0x80 - NW
new_disparity, // final double [] disparity, // current disparity value
grown, // these_tiles, // final boolean [] selected,
true, // final boolean extend_flat, // if the tile is on the hor/vert edge, assume same disparity on the other side
clt_parameters.tiBreakSame, // final double k_same,
clt_parameters.tiBreakTurn, // final double k_turn,
clt_parameters,
dbgDeriv, // final double [][] dbgDeriv, //double [2][len] or null;
threadsMax, // maximal number of threads to launch
debugLevel);
stresses[clt_parameters.tiNumCycles] = dp.dbgShowStress(
dbgDeriv, // double [][] stress,
clt_parameters.transform_size); // int tile_size)
// String [] titles0 = {"neib", "neib_broken", "stress", "stress1", "disp-measured", "disp-result","disp-result1"};
double [] dbg_far_near=new double[too_far.length];
for (int i = 0; i < dbg_far_near.length; i++){
if (!these_tiles[i]) dbg_far_near[i]= Double.NaN;
else if (too_far[i]) dbg_far_near[i]= -1.0;
else if (too_near[i]) dbg_far_near[i]= 1.0;
else dbg_far_near[i]= 0.0;
}
double [][] disp_diff = new double [3][this_disparity.length];
for (int i = 0; i< this_disparity.length; i++) {
if (this_strength[i] > 0.0) disp_diff[0][i] = this_disparity[i]-new_disparity[i];
else disp_diff[0][i] = Double.NaN;
if (too_far[i]) disp_diff[1][i] = this_disparity[i]-new_disparity[i];
else disp_diff[1][i] = Double.NaN;
if (too_near[i]) disp_diff[2][i] = this_disparity[i]-new_disparity[i];
else disp_diff[2][i] = Double.NaN;
}
if (clt_parameters.show_neighbors) {
int numImages = 2 + 3*clt_parameters.tiNumCycles+2+3 + 3;
String [] titles_all = new String[numImages];
double [][] dbg_img = new double[numImages][];
int indx = 0;
titles_all[indx] = "neib";
dbg_img[indx++]= dbg_neib;
for (int i = 0; i < neibs_broken.length; i++){
titles_all[indx] = "neib_"+i;
dbg_img[indx++]= neibs_broken[i];
}
for (int i = 0; i < stresses.length; i++){
titles_all[indx] = "stress_"+i;
dbg_img[indx++]= stresses[i];
}
titles_all[indx] = "disp_meas";
dbg_img[indx++]= measured_disparity;
for (int i = 0; i < smooth_disparities.length; i++){
titles_all[indx] = "disp_"+i;
dbg_img[indx++]= smooth_disparities[i];
}
titles_all[indx] = "far-/near+";
dbg_img[indx++] = dp.dbgRescaleToPixels(
dbg_far_near,
clt_parameters.transform_size);
// double [][] dbg_img = {dbg_neib, dbg_neib_broken, stress, stress1, measured_disparity, smooth_disparity,smooth_disparity1};
// sdfa_instance.showArrays(dbg_neib,tilesX*clt_parameters.transform_size, tilesY*clt_parameters.transform_size,"neighbors");
titles_all[indx] = "strength_orig";
dbg_img[indx++] = dp.dbgRescaleToPixels(
true_strength,
clt_parameters.transform_size);
titles_all[indx] = "strength_mod";
dbg_img[indx++] = dp.dbgRescaleToPixels(
this_strength,
clt_parameters.transform_size);
titles_all[indx] = "diff_this";
dbg_img[indx++] = dp.dbgRescaleToPixels(
disp_diff[0],
clt_parameters.transform_size);
titles_all[indx] = "diff_far";
dbg_img[indx++] = dp.dbgRescaleToPixels(
disp_diff[1],
clt_parameters.transform_size);
titles_all[indx] = "diff_near";
dbg_img[indx++] = dp.dbgRescaleToPixels(
disp_diff[2],
clt_parameters.transform_size);
sdfa_instance.showArrays(dbg_img, tilesX*clt_parameters.transform_size, tilesY*clt_parameters.transform_size,
true, "neighbors", titles_all);
}
//disp_diff
//************************************************
int [][] flaps = dp.createOverlapGeometry(
neighbors, // +1 - up (N), +2 - up-right - NE, ... +0x80 - NW
grown, // these_tiles, // final boolean [] selected, // only inner?
border, // final boolean [] border,
threadsMax, // maximal number of threads to launch
debugLevel);
String [] titleFlaps = {"neib","N","NE","E","SE","S","SW","W","NW"};
if (clt_parameters.show_flaps_dirs){
double [][] dbg_flaps = dp.dbgShowOverlaps(
// boolean [] selected,
flaps, // int [][] flaps,
clt_parameters.transform_size, // int tile_size,
-1.0, // double bgnd,
1.0); // double fgnd)
double [] dbg_neibs = dp.dbgShowNeighbors(
grown, // these_tiles, // grown, // these_tiles,
neighbors, // _orig, // int [] neighbors,
clt_parameters.transform_size, // int tile_size,
-1.0, // double bgnd,
1.0); // double fgnd)
double [][] dbg_flaps_all = {dbg_neibs,dbg_flaps[0],dbg_flaps[1],dbg_flaps[2],dbg_flaps[3],dbg_flaps[4],dbg_flaps[5],dbg_flaps[6],dbg_flaps[7]};
sdfa_instance.showArrays(dbg_flaps_all, tilesX*clt_parameters.transform_size, tilesY*clt_parameters.transform_size,
true, "flaps-dirs", titleFlaps);
}
int [][][] clustersNO= dp.extractNonOlerlap(
true, // diag_en,
neighbors, // +1 - up (N), +2 - up-right - NE, ... +0x80 - NW
grown, // these_tiles, // final boolean [] selected, // only inner?
border, // border should be diagonal!
threadsMax, // maximal number of threads to launch
debugLevel);
if (clt_parameters.show_first_clusters){
int dbg_max_cluster_show = 50;
if (dbg_max_cluster_show > clustersNO.length) dbg_max_cluster_show = clustersNO.length;
double [][] dbg_clusters_show = new double [titleFlaps.length+dbg_max_cluster_show][neighbors.length];
for (int i = 0; i < neighbors.length; i++){
dbg_clusters_show[0][i] = neighbors[i];
for (int j = 0; j < 8; j++){
if (flaps[i] != null) dbg_clusters_show[1+j][i] = flaps[i][j];
}
}
// String [] titleFlaps = {"neib","N","NE","E","SE","S","SW","W","NW"};
String [] titleClusters = new String [titleFlaps.length+dbg_max_cluster_show];
// int indxClust = 0;
for (int i = 0; i < titleFlaps.length; i++){
titleClusters[i] = titleFlaps[i];
}
for (int i = 0; i < dbg_max_cluster_show; i++){
titleClusters[titleFlaps.length+i] = "C"+i;
}
for (int nClust = 0; nClust <dbg_max_cluster_show; nClust++){
for (int i = 0; i < clustersNO[nClust][0].length; i++){
dbg_clusters_show[nClust + 9][clustersNO[nClust][0][i]] += 32.0; // 1.0;
}
for (int i = 0; i < clustersNO[nClust][1].length; i++){
dbg_clusters_show[nClust + 9][clustersNO[nClust][1][i]] += 64.0; // 2.0;
}
for (int i = 0; i < clustersNO[nClust][2].length; i++){
dbg_clusters_show[nClust + 9][clustersNO[nClust][2][i]] += 128.0;// 4.0;
}
}
sdfa_instance.showArrays(dbg_clusters_show, tilesX, tilesY, true, "first "+dbg_max_cluster_show+" clusters",titleClusters);
}
int numScans= 0;
if (clt_parameters.shUseFlaps) {
numScans = createTileOverlapTasks(
clt_parameters.max_clusters, // 50, // int maxClusters,
clt_parameters.shMinArea, // int minClusterArea,
new_disparity, // [] disparity_in, masked ok too
this_strength, // double [] strength_in,
Math.pow(10.0, -clt_parameters.tiPrecision), // double maxChange, // adjust border disparity until change is below this.
clt_parameters.shMinStrength, // double minStrength,
clustersNO, // int [] clusters_in,
disparity_far,
disparity_near,
clt_parameters.show_shells,
debugLevel);
} else {
int [] enum_clusters = enumerateClusters(
true, // boolean diag_en,
grown); // these_tiles); // boolean [] tiles_src)
numScans = createTileTasks(
50, // int maxClusters,
0, // int minClusterArea,
new_disparity, // this_disparity, // [] disparity_in, masked ok too
this_strength, // double [] strength_in,
0.0, // double minStrength,
enum_clusters, // int [] clusters_in,
disparity_far,
disparity_near,
debugLevel);
}
if (debugLevel > -1){
System.out.println("secondPassSetup(): created "+ numScans+ " FPGA passes.");
}
if (debugLevel > 10){ // null pointer
String [] titles = new String [clt_3d_passes.size()];
double [][] disparities = new double [titles.length][tilesX*tilesY];
for (int i = 0; i < titles.length; i++) {
titles[i] = i+"_scan";
double [][] disparityTiles = clt_3d_passes.get(i).disparity;
for (int ty = 0; ty < tilesY; ty++) for (int tx = 0; tx < tilesX; tx++){
disparities[i][ty*tilesX+tx] = disparityTiles[ty][tx]; // null pointer
}
}
sdfa_instance.showArrays(disparities, tilesX, tilesY, true, "disparities_scans",titles);
}
// return scan_next;
}
public int fixVerticalPoles( // return number of replaced cells
CLTPass3d scan, // scan data to use
boolean [] selection, // start with only from selections (if not null, continue regardless)
......
......@@ -3,6 +3,8 @@ import java.util.ArrayList;
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.Prefs;
import ij.io.FileSaver;
/**
** TwoQuadCLT - Process images from a pair of Quad/Octal cameras
......@@ -60,10 +62,10 @@ public class TwoQuadCLT {
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 naims for cameras do not match: main camera: '"+set_channels_main[nSet].name()+"', aux. camera: nothing");
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 naims for cameras do not match: main camera: '"+set_channels_main[nSet].name()+"', aux. camera: '"+set_channels_main[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();
......@@ -172,10 +174,10 @@ public class TwoQuadCLT {
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 naims for cameras do not match: main camera: '"+set_channels_main[nSet].name()+"', aux. camera: nothing");
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 naims for cameras do not match: main camera: '"+set_channels_main[nSet].name()+"', aux. camera: '"+set_channels_main[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();
......@@ -283,13 +285,14 @@ public class TwoQuadCLT {
results[i].setTitle(results[i].getTitle()+"RAW");
}
if (debugLevel>1) System.out.println("processing: "+path);
double [][][][] double_stacks = getRigImageStacks(
getRigImageStacks(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
imp_quad_main, // ImagePlus [] imp_quad_main,
imp_quad_aux, // ImagePlus [] imp_quad_aux,
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
threadsMax, // maximal number of threads to launch
debugLevel); // final int debugLevel);
......@@ -333,6 +336,7 @@ public class TwoQuadCLT {
double min_corr_selected = clt_parameters.min_corr;
ImageDtt image_dtt = new ImageDtt();
double [][] ml_data = null;
final double [][][][][][][] clt_bidata = // new double[2][quad][nChn][tilesY][tilesX][][]; // first index - main/aux
image_dtt.clt_bi_quad (
......@@ -340,15 +344,16 @@ public class TwoQuadCLT {
tile_op_main, // final int [][] tile_op_main, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
// tile_op_aux, // final int [][] tile_op_aux, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
disparity_array_main, // final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
double_stacks[0], // final double [][][] image_data_main, // first index - number of image in a quad
double_stacks[1], // final double [][][] image_data_aux, // first index - number of image in a quad
saturation_main, // final boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // final boolean [][] saturation_aux, // (near) saturated pixels or null
quadCLT_main.image_data, // final double [][][] image_data_main, // first index - number of image in a quad
quadCLT_aux.image_data, // final double [][][] image_data_aux, // first index - number of image in a quad
quadCLT_main.saturation_imp, // final boolean [][] saturation_main, // (near) saturated pixels or null
quadCLT_aux.saturation_imp, // final boolean [][] saturation_aux, // (near) saturated pixels or null
// correlation results - combo will be for the correation between two quad cameras
clt_corr_combo, // final double [][][][] clt_corr_combo, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [type][tilesY][tilesX] should be set by caller
// types: 0 - selected correlation (product+offset), 1 - sum
disparity_bimap, // final double [][] disparity_bimap, // [23][tilesY][tilesX]
ml_data, // final double [][] ml_data, // data for ML - 10 layers - 4 center areas (3x3, 5x5,..) per camera-per direction, 1 - composite, and 1 with just 1 data (target disparity)
texture_tiles_main, // final double [][][][] texture_tiles_main, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
texture_tiles_aux, // final double [][][][] texture_tiles_aux, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
imp_quad_main[0].getWidth(), // final int width,
......@@ -467,7 +472,7 @@ public class TwoQuadCLT {
double [][] texture_rgba_main = {texture_overlap_main[0],texture_overlap_main[1],texture_overlap_main[2],texture_overlap_main[3]};
double [][] texture_rgb_aux = {texture_overlap_aux[0],texture_overlap_aux[1],texture_overlap_aux[2]};
double [][] texture_rgba_aux = {texture_overlap_aux[0],texture_overlap_aux[1],texture_overlap_aux[2],texture_overlap_aux[3]};
quadCLT_main.linearStackToColor(
ImagePlus imp_texture_main = quadCLT_main.linearStackToColor(
clt_parameters,
colorProcParameters,
rgbParameters,
......@@ -475,14 +480,14 @@ public class TwoQuadCLT {
"-D"+clt_parameters.disparity+"-MAIN", //String suffix, // such as disparity=...
toRGB,
!quadCLT_main.correctionsParameters.jpeg, // boolean bpp16, // 16-bit per channel color mode for result
true, // boolean saveShowIntermediate, // save/show if set globally
true, // boolean saveShowFinal, // save/show result (color image?)
false, // true, // boolean saveShowIntermediate, // save/show if set globally
false, // true, // boolean saveShowFinal, // save/show result (color image?)
((clt_parameters.alpha1 > 0)? texture_rgba_main: texture_rgb_main),
tilesX * clt_parameters.transform_size,
tilesY * clt_parameters.transform_size,
1.0, // double scaleExposure, // is it needed?
debugLevel );
quadCLT_aux.linearStackToColor(
ImagePlus imp_texture_aux = quadCLT_aux.linearStackToColor(
clt_parameters,
colorProcParameters,
rgbParameters,
......@@ -490,13 +495,22 @@ public class TwoQuadCLT {
"-D"+clt_parameters.disparity+"-AUX", //String suffix, // such as disparity=...
toRGB,
!quadCLT_aux.correctionsParameters.jpeg, // boolean bpp16, // 16-bit per channel color mode for result
true, // boolean saveShowIntermediate, // save/show if set globally
true, // boolean saveShowFinal, // save/show result (color image?)
false, // true, // boolean saveShowIntermediate, // save/show if set globally
false, // true, // boolean saveShowFinal, // save/show result (color image?)
((clt_parameters.alpha1 > 0)? texture_rgba_aux: texture_rgb_aux),
tilesX * clt_parameters.transform_size,
tilesY * clt_parameters.transform_size,
1.0, // double scaleExposure, // is it needed?
debugLevel );
int width = imp_texture_main.getWidth();
int height =imp_texture_main.getHeight();
ImageStack texture_stack=new ImageStack(width,height);
texture_stack.addSlice("main", imp_texture_main.getProcessor().getPixels());
texture_stack.addSlice("auxiliary", imp_texture_aux. getProcessor().getPixels());
ImagePlus imp_texture_stack = new ImagePlus(name+"-TEXTURES-D"+clt_parameters.disparity, texture_stack);
imp_texture_stack.getProcessor().resetMinAndMax();
// imp_texture_stack.updateAndDraw();
imp_texture_stack.show();
}
}
}
......@@ -511,8 +525,29 @@ public class TwoQuadCLT {
true,
name+"-DISP_MAP-D"+clt_parameters.disparity,
ImageDtt.BIDISPARITY_TITLES);
boolean [] trusted = getTrustedDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, //QuadCLT quadCLT_aux,
0.14, // 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
1.0, // double trusted_tolerance,
null, // boolean [] was_trusted,
disparity_bimap ); // double [][] bimap // current state of measurements
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[nTile]) disparity_bimap[layer][nTile] = Double.NaN;
}
}
sdfa_instance.showArrays(
disparity_bimap,
tilesX,
tilesY,
true,
name+"-DISP_MAP_TRUSTED-D"+clt_parameters.disparity,
ImageDtt.BIDISPARITY_TITLES);
}
}
if (!batch_mode && !infinity_corr && clt_parameters.corr_show && (debugLevel > -2)){
double [][] corr_rslt = new double [clt_corr_combo.length][];
String [] titles = new String[clt_corr_combo.length]; // {"combo","sum"};
......@@ -676,13 +711,15 @@ public class TwoQuadCLT {
public double [][][][] getRigImageStacks(
// public double [][][][] getRigImageStacks(
public void getRigImageStacks(
EyesisCorrectionParameters.CLTParameters clt_parameters,
QuadCLT quadCLT_main,
QuadCLT quadCLT_aux,
ImagePlus [] imp_quad_main,
ImagePlus [] imp_quad_aux,
boolean [][] saturation_main, // (near) saturated pixels or null
boolean [][] saturation_aux, // (near) saturated pixels or null
int threadsMax, // maximal number of threads to launch
int debugLevel){
double [][][] double_stacks_main = new double [imp_quad_main.length][][];
......@@ -692,7 +729,7 @@ public class TwoQuadCLT {
null); // no margins, no oversample
}
double [][][] double_stacks_aux = new double [imp_quad_main.length][][];
double [][][] double_stacks_aux = new double [imp_quad_aux.length][][];
for (int i = 0; i < double_stacks_aux.length; i++){
double_stacks_aux[i] = quadCLT_aux.eyesisCorrections.bayerToDoubleStack(
imp_quad_aux[i], // source Bayer image, linearized, 32-bit (float))
......@@ -709,15 +746,23 @@ public class TwoQuadCLT {
double_stacks_aux[i][2][j]*=0.5; // Scale green 0.5 to compensate more pixels than R,B
}
}
double [][][][] rigStacks = {double_stacks_main,double_stacks_aux};
quadCLT_main.setTiles (imp_quad_main[0], // set global tp.tilesX, tp.tilesY
clt_parameters,
threadsMax);
quadCLT_aux.setTiles (imp_quad_aux[0], // set global tp.tilesX, tp.tilesY
clt_parameters,
threadsMax);
return rigStacks;
String name_main = (String) imp_quad_main[0].getProperty("name");
String name_aux = (String) imp_quad_main[0].getProperty("name");
quadCLT_main.image_name = name_main;
quadCLT_aux.image_name = name_aux;
quadCLT_main.image_data = double_stacks_main;
quadCLT_aux.image_data = double_stacks_aux;
quadCLT_main.saturation_imp = saturation_main;
quadCLT_aux.saturation_imp = saturation_aux;
// quadCLT_main.tp.resetCLTPasses();
quadCLT_main.tp.setTrustedCorrelation(clt_parameters.grow_disp_trust);
quadCLT_aux.tp.setTrustedCorrelation(clt_parameters.grow_disp_trust);
}
......@@ -743,10 +788,10 @@ public class TwoQuadCLT {
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 naims for cameras do not match: main camera: '"+set_channels_main[nSet].name()+"', aux. camera: nothing");
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 naims for cameras do not match: main camera: '"+set_channels_main[nSet].name()+"', aux. camera: '"+set_channels_main[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();
......@@ -822,19 +867,28 @@ public class TwoQuadCLT {
final boolean updateStatus,
final int debugLevel0){
final int debugLevel = debugLevel0 + (clt_parameters.rig.rig_mode_debug?2:0);
double [][][][] double_stacks = getRigImageStacks(
// double [][][][] double_stacks =
getRigImageStacks(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
imp_quad_main, // ImagePlus [] imp_quad_main,
imp_quad_aux, // ImagePlus [] imp_quad_aux,
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
threadsMax, // maximal number of threads to launch
debugLevel); // final int debugLevel);
quadCLT_main.tp.resetCLTPasses();
quadCLT_aux.tp.resetCLTPasses();
final int tilesX = quadCLT_main.tp.getTilesX();
// perform full re-measure cycles
double [][] disparity_bimap = null;
int [] num_new = new int[1];
for (int num_full_cycle = 0; num_full_cycle < clt_parameters.rig.rig_adjust_full_cycles;num_full_cycle++) {
disparity_bimap = null;
ArrayList<Integer> tile_list = new ArrayList<Integer>();
......@@ -847,12 +901,9 @@ public class TwoQuadCLT {
disparity_bimap = measureNewRigDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
disparity_bimap, // double [][] src_bimap, // current state of measurements (or null for new measurement)
disparity, // double disparity,
tile_list, // ArrayList<Integer> tile_list, // or null. If non-null - do not remeasure members of teh list
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_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,
......@@ -869,24 +920,23 @@ public class TwoQuadCLT {
ImageDtt.BIDISPARITY_TITLES);
}
}
if (disparity > 0.0) { // refine non-infinity passes
// first - refine once for the main camera
double [][] prev_bimap = null;
double [] scale_bad = null;
for (int nrefine = 0; nrefine < clt_parameters.rig.num_refine_master; nrefine++) {
double [][] disparity_bimap_new = refineRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
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
0, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
null, // scale_bad, // double [] scale_bad,
2, //0, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
true, // boolean keep_inf, // keep expected disparity 0.0 if it was so
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
null, // tile_list, // ArrayList<Integer> tile_list, // or null
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
num_new, // int [] num_new,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
......@@ -912,16 +962,15 @@ public class TwoQuadCLT {
double [][] disparity_bimap_new = refineRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
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,
2, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
true, // boolean keep_inf, // keep expected disparity 0.0 if it was so
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
null, // tile_list, // ArrayList<Integer> tile_list, // or null
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
num_new, // int [] num_new,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
......@@ -963,23 +1012,22 @@ public class TwoQuadCLT {
disparity_bimap = refineRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
disparity_bimap, // double [][] src_bimap, // current state of measurements (or null for new measurement)
null, // double [][] prev_bimap, // previous state of measurements or null
null, // double [] scale_bad,
2, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
// will still re-measure infinity if refine_min_strength == 0.0
true, // boolean keep_inf, // keep expected disparity 0.0 if it was so
0.0, // double refine_min_strength, // do not refine weaker tiles
0.0, // double refine_tolerance, // do not refine if absolute disparity below
tile_list, // ArrayList<Integer> tile_list, // or null
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
num_new, // int [] num_new,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
// show updated results for the list
if (debugLevel > -1) showListedRigTiles(
if (debugLevel > -2) showListedRigTiles(
"selected_rig_tiles", // title
tile_list, //ArrayList<Integer> tile_list,
disparity_bimap, // double[][] disparity_bimap,
......@@ -1024,47 +1072,549 @@ public class TwoQuadCLT {
}
/*
public double [][] measureInfinityRig(
// improve DSI acquired for a single camera by use of a pair
// Run this after "CLT 3D"
public double [][] enhanceByRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][][][] double_stacks,
ArrayList<Integer> tileList, // or null
boolean [][] saturation_main, // (near) saturated pixels or null
boolean [][] saturation_aux, // (near) saturated pixels or null
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
final int debugLevel) throws Exception
{
// int min_new = 100; // make a parameter
// int num_inf_refine = 20;
// int num_near_refine = 20;
// double min_trusted_strength = 0.1; // 14;
// double trusted_tolerance = 1.0;
System.out.println("enhanceByRig()");
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);
int tilesX = quadCLT_main.tp.getTilesX();
int tilesY = quadCLT_main.tp.getTilesX();
int [][] tile_op;
if (tileList == null ) {
tile_op = quadCLT_main.tp.setSameTileOp(clt_parameters, clt_parameters.tile_task_op, debugLevel);
} else {
tile_op = new int [tilesY][tilesX];
for (int nTile:tileList) {
tile_op[nTile/tilesX][nTile%tilesX] = clt_parameters.tile_task_op;
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
}
}
// for infinity use disparity of all 0-s;
double [][] disparity_array = new double [quadCLT_main.tp.getTilesY()][quadCLT_main.tp.getTilesX()];
return measureRig(
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();
double [][] disparity_bimap_infinity = measureNewRigDisparity(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
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 teh list
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_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 > -2) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap_infinity,
tilesX,
disparity_bimap_infinity[0].length/tilesX,
true,
quadCLT_main.image_name+"DISP_MAP-INFINITY",
ImageDtt.BIDISPARITY_TITLES);
}
double [][] prev_bimap = null;
double [] scale_bad = new double [trusted_infinity.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++) {
// 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)
prev_bimap, // double [][] prev_bimap, // previous state of measurements or null
scale_bad, // double [] scale_bad,
2, // 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
num_new, // int [] num_new,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
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
if (debugLevel > -2) {
System.out.println("enhanceByRig(): refined (infinity) "+num_new[0]+" tiles");
}
if (num_new[0] < clt_parameters.rig.min_new) break;
}
if (clt_parameters.show_map && (debugLevel > -2) && 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 ++;
}
}
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);
}
(new showDoubleFloatArrays()).showArrays(
disparity_bimap_infinity,
tilesX,
disparity_bimap_infinity[0].length/tilesX,
true,
quadCLT_main.image_name+"-INFINITY-REFINED-TRUSTED"+clt_parameters.disparity,
ImageDtt.BIDISPARITY_TITLES);
}
// Get DSI from the main camera
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 > -2) && clt_parameters.rig.rig_mode_debug){
(new showDoubleFloatArrays()).showArrays(
disparity_bimap,
tilesX,
disparity_bimap[0].length/tilesX,
true,
quadCLT_main.image_name+"DISP_MAP-NONINFINITY",
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,
2, // 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,
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 > -2) && 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 > -2) && 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);
}
// grow around using all camera and inter-camera correlations (try to get low-textured,like our street)
// re-measure with ML data output
// int ml_hwidth = 2; // move to clt_parameters
// int ml_width = 2 * clt_parameters.rig.ml_hwidth + 1;
String ml_directory= quadCLT_main.correctionsParameters.selectMlDirectory(
true, // smart,
true); //newAllowed, // save
for (int sweep_step = 0; sweep_step < clt_parameters.rig.ml_sweep_steps; sweep_step++){
double disparity_offset = 0; // clt_parameters.rig.ml_disparity_sweep * (2.0 * sweep_step/(clt_parameters.rig.ml_sweep_steps - 1.0) -1.0);
if (clt_parameters.rig.ml_sweep_steps > 1) {
disparity_offset = clt_parameters.rig.ml_disparity_sweep * (2.0 * sweep_step/(clt_parameters.rig.ml_sweep_steps - 1.0) -1.0);
}
double [][] ml_data = remeasureRigML(
disparity_offset, // double disparity_offset,
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
disparity_bimap, // double [][] src_bimap,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_parameters.rig.ml_hwidth, // int ml_hwidth
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
saveMlFile(
quadCLT_main.image_name+"-ML_DATA-OFFS_", // String ml_title,
ml_directory, // String ml_directory,
disparity_offset, // double disp_offset,
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
clt_parameters.rig.ml_keep_aux, // boolean keep_aux,
clt_parameters.rig.ml_keep_inter, // boolean keep_inter,
clt_parameters.rig.ml_keep_hor_vert, // boolean keep_hor_vert,
clt_parameters.rig.ml_keep_debug, // boolean keep_debug,
clt_parameters.rig.ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
clt_parameters.rig.ml_show_ml, // boolean show,
debugLevel); // int debugLevel
}
return null;
//clt_3d_passes
}
public void saveMlFile(
String ml_title,
String ml_directory,
double disp_offset,
QuadCLT quadCLT_main,
QuadCLT quadCLT_aux,
boolean keep_aux,
boolean keep_inter,
boolean keep_hor_vert,
boolean keep_debug,
int ml_hwidth,
double [][] ml_data,
boolean show,
int debugLevel
) {
final int tilesX = quadCLT_main.tp.getTilesX();
final int tilesY = quadCLT_main.tp.getTilesY();
int ml_width = 2 * ml_hwidth + 1;
int width = tilesX * ml_width;
int height = tilesY * ml_width;
String title = ml_title+(keep_aux?"A":"")+(keep_inter?"I":"")+(keep_hor_vert?"O":"")+(keep_debug?"D":"")+disp_offset;
int [] aux_indices = {
ImageDtt.ML_TOP_AUX_INDEX, // 8 - top pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_BOTTOM_AUX_INDEX, // 9 - bottom pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_LEFT_AUX_INDEX, //10 - left pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_RIGHT_AUX_INDEX, //11 - right pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_DIAGM_AUX_INDEX, //12 - main diagonal (top-left to bottom-right) pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_DIAGO_AUX_INDEX, //13 - other diagonal (bottom-left to top-right) pair 2d correlation center area (auxiliary camera)
ImageDtt.ML_HOR_AUX_INDEX, //14 - horizontal pairs combined 2d correlation center area (auxiliary camera)
ImageDtt.ML_VERT_AUX_INDEX //15 - vertical pairs combined 2d correlation center area (auxiliary camera)
};
int [] inter_indices = {
ImageDtt.ML_INTER_INDEX //16 - inter-camera (between two quad ones) correlation center area
};
int [] hor_vert_indices = {
ImageDtt.ML_HOR_INDEX, // 6 - horizontal pairs combined 2d correlation center area
ImageDtt.ML_VERT_INDEX, // 7 - vertical pairs combined 2d correlation center area
ImageDtt.ML_HOR_AUX_INDEX, //14 - horizontal pairs combined 2d correlation center area (auxiliary camera)
ImageDtt.ML_VERT_AUX_INDEX //15 - vertical pairs combined 2d correlation center area (auxiliary camera)
};
int [] dbg_indices = {
ImageDtt.ML_DBG1_INDEX //18 - just debug data (first - auto phase correlation)
};
boolean [] skip_layers = new boolean [ImageDtt.ML_TITLES.length];
if (!keep_aux) for (int nl:aux_indices) skip_layers[nl] = true;
if (!keep_inter) for (int nl:inter_indices) skip_layers[nl] = true;
if (!keep_hor_vert) for (int nl:hor_vert_indices) skip_layers[nl] = true;
if (!keep_debug) for (int nl:dbg_indices) skip_layers[nl] = true;
float [] fpixels;
ImageStack array_stack=new ImageStack(width,height);
for (int nl = 0; nl< ml_data.length; nl++) if (!skip_layers[nl]) {
fpixels=new float[ml_data[nl].length];
for (int j=0;j<fpixels.length;j++) fpixels[j]=(float) ml_data[nl][j];
array_stack.addSlice(ImageDtt.ML_TITLES[nl], fpixels);
}
double disparityRadiusMain = quadCLT_main.geometryCorrection.getDisparityRadius();
double disparityRadiusAux = quadCLT_aux.geometryCorrection.getDisparityRadius();
double intercameraBaseline = quadCLT_aux.geometryCorrection.getBaseline();
ImagePlus imp_ml = new ImagePlus(title, array_stack);
imp_ml.setProperty("VERSION", "1.0");
imp_ml.setProperty("tileWidth", ""+ml_width);
imp_ml.setProperty("dispOffset", ""+disp_offset);
imp_ml.setProperty("ML_OTHER_TARGET", ""+ImageDtt.ML_OTHER_TARGET);
imp_ml.setProperty("ML_OTHER_GTRUTH", ""+ImageDtt.ML_OTHER_GTRUTH);
imp_ml.setProperty("ML_OTHER_GTRUTH_STRENGTH", ""+ImageDtt.ML_OTHER_GTRUTH_STRENGTH);
imp_ml.setProperty("disparityRadiusMain", ""+disparityRadiusMain);
imp_ml.setProperty("disparityRadiusAux", ""+disparityRadiusAux);
imp_ml.setProperty("intercameraBaseline", ""+intercameraBaseline);
imp_ml.setProperty("comment_tileWidth", "Square tile size for each 2d correlation, always odd");
imp_ml.setProperty("comment_dispOffset", "Tile target disparity minum ground truth disparity");
imp_ml.setProperty("comment_ML_OTHER_TARGET", "Offset of the target disparity in the \"other\" layer tile");
imp_ml.setProperty("comment_ML_OTHER_GTRUTH", "Offset of the ground truth disparity in the \"other\" layer tile");
imp_ml.setProperty("comment_ML_OTHER_GTRUTH_STRENGTH", "Offset of the ground truth strength in the \"other\" layer tile");
imp_ml.setProperty("comment_disparityRadiusMain", "Side of the square where 4 main camera subcameras are located (mm)");
imp_ml.setProperty("comment_disparityRadiusAux", "Side of the square where 4 main camera subcameras are located (mm). Disparity is specified for the main camera");
imp_ml.setProperty("comment_intercameraBaseline", "Horizontal distance between the main and the auxiliary camera centers (mm). Disparity is specified for the main camera");
(new JP46_Reader_camera(false)).encodeProperiesToInfo(imp_ml);
imp_ml.getProcessor().resetMinAndMax();
if (show ) {
imp_ml.show();
}
String path = ml_directory+=Prefs.getFileSeparator()+imp_ml.getTitle();
FileSaver fs=new FileSaver(imp_ml);
fs.saveAsTiff(path+".tiff");
}
/**
* Get disparity from the DSI data of the main camera and re-measure with the rig
* @param scan - main camera DSI scan to get initial disparity and selection from
* @param quadCLT_main main camera QuadCLT instance (should have tp initialized)
* @param quadCLT_aux auxiliary camera QuadCLT instance (should have tp initialized)
* @param clt_parameters various configuration parameters
* @param threadsMax maximal number of threads to use
* @param updateStatus update IJ status bar
* @param debugLevel debug level
* @return rig measurement results
*/
public double [][] setBimapFromCLTPass3d(
CLTPass3d scan,
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
int tile_op_all = clt_parameters.tile_task_op; //FIXME Use some constant?
final int tilesX = quadCLT_main.tp.getTilesX();
final int tilesY = quadCLT_main.tp.getTilesY();
int [][] tile_op = new int[tilesY][tilesX]; // common for both amin and aux
double [][] disparity_array = new double[tilesY][tilesX];
double [] disparity = scan.getDisparity();
double [] strength = scan.getOriginalStrength();
// boolean [] selection = scan.getSelected();
boolean [] selection = new boolean [strength.length];
for (int nTile = 0; nTile < selection.length; nTile++) {
selection[nTile] = strength[nTile] > 0.0;
}
for (int nTile = 0; nTile < disparity.length; nTile++) {
if (((selection == null) || (selection[nTile]) && !Double.isNaN(disparity[nTile]))) {
int tileY = nTile / tilesX;
int tileX = nTile % tilesX;
tile_op[tileY][tileX] = tile_op_all;
disparity_array[tileY][tileX] = disparity[nTile];
}
}
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,
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
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,
threadsMax, //final int threadsMax, // maximal number of threads to launch
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
debugLevel); // final int debugLevel);
return disparity_bimap;
}
/**
* Select tiles that have small enough residual disparity to trust on each of the two cameras and the whole rig.
* @param quadCLT_main main camera QuadCLT instance (should have tp initialized)
* @param quadCLT_aux auxiliary camera QuadCLT instance (should have tp initialized)
* @param max_trusted_disparity maximal disparity on a rig to trust (currently 4.0 pixels from zero each way)
* @param trusted_tolerance allow other cameras with scaled disparity if their disparity is under this value (for small baselines)
* @param bimap measured data
* @return per-tile array of trusted tiles
*/
boolean [] getTrustedDisparity(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double min_combo_strength, // check correlation strength combined for all 3 correlations
double max_trusted_disparity,
double trusted_tolerance,
boolean [] was_trusted,
double [][] bimap // current state of measurements
) {
double trusted_inter = max_trusted_disparity;
double trusted_main = trusted_inter * quadCLT_main.geometryCorrection.getDisparityRadius()/quadCLT_aux.geometryCorrection.getBaseline();
double trusted_aux = trusted_inter * quadCLT_aux.geometryCorrection.getDisparityRadius()/quadCLT_aux.geometryCorrection.getBaseline();
if (trusted_main < trusted_tolerance) trusted_main = trusted_tolerance;
if (trusted_aux < trusted_tolerance) trusted_aux = trusted_tolerance;
boolean [] trusted = new boolean [bimap[ImageDtt.BI_DISP_CROSS_INDEX].length];
for (int i = 0; i < trusted.length; i++) {
trusted[i] = (Math.abs(bimap[ImageDtt.BI_DISP_CROSS_INDEX][i]) <= trusted_inter) &&
(Math.abs(bimap[ImageDtt.BI_DISP_FULL_INDEX][i]) <= trusted_main) &&
(Math.abs(bimap[ImageDtt.BI_ADISP_FULL_INDEX][i]) <= trusted_aux) &&
(bimap[ImageDtt.BI_STR_ALL_INDEX][i] >= min_combo_strength) &&
((was_trusted == null) || was_trusted[i]);
}
return trusted;
}
*/
/**
* Refine (re-measure with updated expected disparity) tiles. If refine_min_strength and refine_tolerance are both
......@@ -1072,7 +1622,6 @@ public class TwoQuadCLT {
* With refine_min_strength == 0, will re-measure infinity (have keep_inf == true)
* @param quadCLT_main main camera QuadCLT instance (should have tp initialized)
* @param quadCLT_aux auxiliary camera QuadCLT instance (should have tp initialized)
* @param double_stacks image data from both cameras converted to double and conditioned
* @param src_bimap results of the older measurements (now includes expected disparity)
* @param prev_bimap results of the even older measurements to interpolate if there was an overshoot
* @param refine_mode reference camera data: 0 - main camera, 1 - aux camera, 2 - cross-camera
......@@ -1080,8 +1629,7 @@ public class TwoQuadCLT {
* @param refine_min_strength do not refine weaker tiles
* @param refine_tolerance do not refine if residual disparity (after FD pre-shift by expected disparity) less than this
* @param tile_list list of selected tiles or null. If null - try to refine all tiles, otherwise - only listed tiles
* @param saturation_main saturated pixels bitmaps for the main camera
* @param saturation_aux saturated pixels bitmaps for the auxiliary camera
* @param num_new - otional int [1] to return number of new tiles
* @param clt_parameters various configuration parameters
* @param threadsMax maximal number of threads to use
* @param updateStatus update IJ status bar
......@@ -1091,17 +1639,54 @@ public class TwoQuadCLT {
public double [][] refineRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][][][] double_stacks,
double [][] src_bimap, // current state of measurements
double [][] prev_bimap, // previous state of measurements or null
double [] scale_bad,
int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
boolean keep_inf, // keep expected disparity 0.0 if it was so
double refine_min_strength, // do not refine weaker tiles
double refine_tolerance, // do not refine if absolute disparity below
ArrayList<Integer> tile_list, // or null
// boolean [] unstable,
boolean [][] saturation_main, // (near) saturated pixels or null
boolean [][] saturation_aux, // (near) saturated pixels or null
int [] num_new,
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
boolean [] selection = null;
if (tile_list != null) {
selection = new boolean [quadCLT_main.tp.getTilesX() * quadCLT_main.tp.getTilesY()];
for (int nTile:tile_list) selection[nTile] = true;
}
return refineRigSel(
quadCLT_main, // tiles should be set
quadCLT_aux,
src_bimap, // current state of measurements
prev_bimap, // previous state of measurements or null
scale_bad, //
refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
keep_inf, // keep expected disparity 0.0 if it was so
refine_min_strength, // do not refine weaker tiles
refine_tolerance, // do not refine if absolute disparity below
selection,
num_new,
clt_parameters,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
}
public double [][] refineRigSel(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][] src_bimap, // current state of measurements
double [][] prev_bimap, // previous state of measurements or null
double [] scale_bad,
int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
boolean keep_inf, // keep expected disparity 0.0 if it was so
double refine_min_strength, // do not refine weaker tiles
double refine_tolerance, // do not refine if absolute disparity below
boolean [] selection,
int [] num_new,
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
......@@ -1115,42 +1700,16 @@ public class TwoQuadCLT {
double disp_scale_inter = disp_scale_main * quadCLT_main.geometryCorrection.getDisparityRadius()/quadCLT_aux.geometryCorrection.getBaseline();
int tile_op_all = clt_parameters.tile_task_op; //FIXME Use some constant?
int numMeas = 0;
if (tile_list == null) { // refine all
for (int tileY = 0; tileY<tilesY;tileY++) {
for (int tileX = 0; tileX<tilesX;tileX++) {
int nTile = tileY * tilesX + tileX;
if (!Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
if (prepRefineTile(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
tile_op_all, // int tile_op_all,
src_bimap, // double [][] src_bimap, // current state of measurements
prev_bimap, // double [][] prev_bimap, // previous state of measurements or null
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
refine_mode, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
keep_inf, // boolean keep_inf, // keep expected disparity 0.0 if it was so
refine_min_strength, // double refine_min_strength, // do not refine weaker tiles
refine_tolerance, // double refine_tolerance, // do not refine if absolute disparity below
disp_scale_main, // double disp_scale_main, // 1.0
disp_scale_aux, //double disp_scale_aux, // ~0.58
disp_scale_inter, //double disp_scale_inter, // ~4.86
// scale_step, // double scale_step, // scale for "unstable tiles"
tileX, // int tileX,
tileY, // int tileY,
nTile )) numMeas++; //int nTile
}
}
}
} else {
for (int nTile: tile_list) {
int tileY = nTile / tilesX;
int tileX = nTile % tilesX;
if (!(Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]))) {
if (((selection == null) || selection[nTile]) && !Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
if (prepRefineTile(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
tile_op_all, // int tile_op_all,
src_bimap, // double [][] src_bimap, // current state of measurements
prev_bimap, // double [][] prev_bimap, // previous state of measurements or null
scale_bad, // double [] scale_bad,
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
refine_mode, // int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
......@@ -1160,6 +1719,7 @@ public class TwoQuadCLT {
disp_scale_main, // double disp_scale_main, // 1.0
disp_scale_aux, //double disp_scale_aux, // ~0.58
disp_scale_inter, //double disp_scale_inter, // ~4.86
// scale_step, // double scale_step, // scale for "unstable tiles"
tileX, // int tileX,
tileY, // int tileY,
nTile )) numMeas++; //int nTile
......@@ -1172,21 +1732,19 @@ public class TwoQuadCLT {
double [][] disparity_bimap = measureRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
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,
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
// combine with old results for tiles that were not re-measured
if (tile_list == null) { // refine all
for (int tileY = 0; tileY<tilesY;tileY++) {
for (int tileX = 0; tileX<tilesX;tileX++) {
int nTile = tileY * tilesX + tileX;
if ((selection == null) || selection[nTile]) {
if (Double.isNaN(disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile]) && !Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
for (int i = 0; i < disparity_bimap.length; i++) {
disparity_bimap[i][nTile] = src_bimap[i][nTile];
......@@ -1194,22 +1752,17 @@ public class TwoQuadCLT {
}
}
}
} else {
for (int nTile: tile_list) {
if (Double.isNaN(disparity_bimap[ImageDtt.BI_TARGET_INDEX][nTile]) && !Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) {
for (int i = 0; i < disparity_bimap.length; i++) {
disparity_bimap[i][nTile] = src_bimap[i][nTile];
}
}
}
if (num_new != null) {
num_new[0] = numMeas;
}
return disparity_bimap;
}
/**
* Add measurements with new specified disparity of the main camera
* @param quadCLT_main main camera QuadCLT instance (should have tp initialized)
* @param quadCLT_aux auxiliary camera QuadCLT instance (should have tp initialized)
* @param double_stacks image data from both cameras converted to double and conditioned
* @param src_bimap results of the older measurements (now includes expected disparity) or null (no old results available)
* @param disparity new expected disparity value to try
* @param tile_list list of selected tiles or null. If not null, will not re-measure listed tiles
......@@ -1225,12 +1778,9 @@ public class TwoQuadCLT {
public double [][] measureNewRigDisparity(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][][][] double_stacks,
double [][] src_bimap, // current state of measurements (or null for new measurement)
double disparity,
ArrayList<Integer> tile_list, // or null. If non-null - do not remeasure members of teh list
boolean [][] saturation_main, // (near) saturated pixels or null
boolean [][] saturation_aux, // (near) saturated pixels or null
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
......@@ -1262,11 +1812,9 @@ public class TwoQuadCLT {
double [][] disparity_bimap = measureRig(
quadCLT_main, // QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, // QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
tile_op, // int [][] tile_op, // common for both amin and aux
disparity_array, // double [][] disparity_array,
saturation_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
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,
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
......@@ -1309,6 +1857,7 @@ public class TwoQuadCLT {
int tile_op_all,
double [][] src_bimap, // current state of measurements
double [][] prev_bimap, // previous state of measurements or null
double [] scale_bad,
int [][] tile_op, // common for both amin and aux
double [][] disparity_array,
int refine_mode, // 0 - by main, 1 - by aux, 2 - by inter
......@@ -1323,7 +1872,7 @@ public class TwoQuadCLT {
int tileY,
int nTile) {
boolean debug_this = nTile==61924;
boolean debug_this = nTile==40661; // 61924;
// check if it was measured (skip NAN)
if (Double.isNaN(src_bimap[ImageDtt.BI_TARGET_INDEX][nTile])) return false;
// check if it is infinity and change is prohibited
......@@ -1359,24 +1908,45 @@ public class TwoQuadCLT {
if (strength < refine_min_strength) return false;
// residual disparity large enough to bother
if (Math.abs(diff_disp) < refine_tolerance) return false;
tile_op[tileY][tileX] = tile_op_all;
// or use extrapolate too?
if (debug_this) {
System.out.println("disp_scale="+disp_scale);
// System.out.println("disp_scale="+disp_scale);
if (prev_bimap != null) {
System.out.print("prepRefineTile(): prev_bimap[ImageDtt.BI_TARGET_INDEX][nTile] = "+prev_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+
", src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]="+src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+", diff_prev="+diff_prev+", diff_disp="+diff_disp);
// System.out.println(
/// "prepRefineTile(): prev_bimap[ImageDtt.BI_TARGET_INDEX][nTile] = "+prev_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+
// ", src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]="+src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+", diff_prev="+diff_prev+", diff_disp="+diff_disp);
} else {
System.out.print("prepRefineTile(): src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]="+src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+", diff_prev="+diff_prev+", diff_disp="+diff_disp);
// System.out.println("prepRefineTile(): src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]="+src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+", diff_prev="+diff_prev+", diff_disp="+diff_disp);
}
}
boolean from_prev = false;
if ((scale_bad != null) && (Math.abs(diff_disp) > Math.abs(diff_prev))){
scale_bad[nTile] *= 0.9; // reduce step
from_prev = true;
}
double new_disp;
if (Double.isNaN(diff_prev) || (diff_prev * diff_disp > 0)) {
disparity_array[tileY][tileX] = src_bimap[ImageDtt.BI_TARGET_INDEX][nTile] + diff_disp*disp_scale;
if (debug_this) System.out.println(" >> 1 => disparity_array["+tileY+"]["+tileX+"]="+disparity_array[tileY][tileX]);
new_disp = src_bimap[ImageDtt.BI_TARGET_INDEX][nTile] + diff_disp*disp_scale;
// if (debug_this) System.out.println(" >> 1 => disparity_array["+tileY+"]["+tileX+"]="+new_disp);
} else { // interpolate
disparity_array[tileY][tileX] = (src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]*diff_prev - prev_bimap[ImageDtt.BI_TARGET_INDEX][nTile]*diff_disp)/(diff_prev-diff_disp);
if (debug_this) System.out.println(" >> 2 => disparity_array["+tileY+"]["+tileX+"]="+disparity_array[tileY][tileX]);
new_disp = (src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]*diff_prev - prev_bimap[ImageDtt.BI_TARGET_INDEX][nTile]*diff_disp)/(diff_prev-diff_disp);
// if (debug_this) System.out.println(" >> 2 => disparity_array["+tileY+"]["+tileX+"]="+new_disp);
}
double ref_target = from_prev ? prev_bimap[ImageDtt.BI_TARGET_INDEX][nTile] : src_bimap[ImageDtt.BI_TARGET_INDEX][nTile];
if ((scale_bad != null) && (scale_bad[nTile] < 1.0)) {
new_disp = ref_target * (1.0 - scale_bad[nTile]) + new_disp * scale_bad[nTile];
// if (debug_this) System.out.println(" scale_bad["+nTile+"]= "+scale_bad[nTile]+" , corrected new_disp="+new_disp+" (was "+ src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+
// ", prev "+prev_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+")");
} else if (prev_bimap!=null){
// if (debug_this) System.out.println("new_disp="+new_disp+" (was "+ src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+
// ", prev "+prev_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+")");
}
if (debug_this) System.out.println("prepRefineTile():target_diff "+ src_bimap[ImageDtt.BI_TARGET_INDEX][nTile]+","+diff_disp+","+scale_bad[nTile]);
if (Math.abs((new_disp - ref_target)/new_disp) < refine_tolerance) return false;
disparity_array[tileY][tileX] = new_disp;
tile_op[tileY][tileX] = tile_op_all;
return true;
}
......@@ -1384,11 +1954,9 @@ public class TwoQuadCLT {
private double [][] measureRig(
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][][][] double_stacks,
int [][] tile_op, // common for both amin and aux
double [][] disparity_array,
boolean [][] saturation_main, // (near) saturated pixels or null
boolean [][] saturation_aux, // (near) saturated pixels or 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)
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
......@@ -1403,13 +1971,14 @@ public class TwoQuadCLT {
tile_op, // final int [][] tile_op_main, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
// tile_op, // final int [][] tile_op_aux, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
disparity_array, // final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
double_stacks[0], // final double [][][] image_data_main, // first index - number of image in a quad
double_stacks[1], // final double [][][] image_data_aux, // first index - number of image in a quad
saturation_main, // final boolean [][] saturation_main, // (near) saturated pixels or null
saturation_aux, // final boolean [][] saturation_aux, // (near) saturated pixels or null
quadCLT_main.image_data, // final double [][][] image_data_main, // first index - number of image in a quad
quadCLT_aux.image_data, // final double [][][] image_data_aux, // first index - number of image in a quad
quadCLT_main.saturation_imp, // final boolean [][] saturation_main, // (near) saturated pixels or null
quadCLT_aux.saturation_imp, // final boolean [][] saturation_aux, // (near) saturated pixels or null
// correlation results - combo will be for the correation between two quad cameras
null, // final double [][][][] clt_corr_combo, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
disparity_bimap, // final double [][] disparity_bimap, // [23][tilesY][tilesX]
ml_data, // final double [][] ml_data, // data for ML - 10 layers - 4 center areas (3x3, 5x5,..) per camera-per direction, 1 - composite, and 1 with just 1 data (target disparity)
null, // final double [][][][] texture_tiles_main, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
null, // final double [][][][] texture_tiles_aux, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
quadCLT_main.tp.getTilesX()*clt_parameters.transform_size, // final int width,
......@@ -1426,6 +1995,87 @@ public class TwoQuadCLT {
return disparity_bimap;
}
public double [][] remeasureRigML(
double disparity_offset,
QuadCLT quadCLT_main, // tiles should be set
QuadCLT quadCLT_aux,
double [][] src_bimap,
EyesisCorrectionParameters.CLTParameters clt_parameters,
int ml_hwidth,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
int tile_op_all = clt_parameters.tile_task_op; //FIXME Use some constant?
final int tilesX = quadCLT_main.tp.getTilesX();
final int tilesY = quadCLT_main.tp.getTilesY();
// int ml_hwidth = 2;
int ml_width = 2 * ml_hwidth + 1;
double [][] ml_data = new double [ImageDtt.ML_TITLES.length][tilesX * tilesY * ml_width * ml_width];
for (int nLayer=0; nLayer < ml_data.length; nLayer++) {
for (int nTile=0; nTile < ml_data[nLayer].length; nTile++) {
ml_data[nLayer][nTile] = Double.NaN;
}
}
int [][] tile_op = new int[tilesY][tilesX]; // common for both main and aux
double [][] disparity_array = new double[tilesY][tilesX];
double [] disparity = src_bimap[ImageDtt.BI_TARGET_INDEX];
double [] strength = src_bimap[ImageDtt.BI_STR_ALL_INDEX];
boolean [] selection = new boolean [strength.length];
for (int nTile = 0; nTile < selection.length; nTile++) {
selection[nTile] = strength[nTile] > 0.0;
}
Correlation2d corr2d = new Correlation2d(
clt_parameters.img_dtt, // ImageDttParameters imgdtt_params,
clt_parameters.transform_size, // int transform_size,
2.0, // double wndx_scale, // (wndy scale is always 1.0)
(debugLevel > -1)); // boolean debug)
for (int nTile = 0; nTile < disparity.length; nTile++) {
if (((selection == null) || (selection[nTile]) && !Double.isNaN(disparity[nTile]))) {
int tileY = nTile / tilesX;
int tileX = nTile % tilesX;
tile_op[tileY][tileX] = tile_op_all;
disparity_array[tileY][tileX] = disparity[nTile]+disparity_offset;
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
ImageDtt.ML_OTHER_GTRUTH , // int ml_index,
disparity[nTile], // target disparitydouble ml_value,
tilesX); // int tilesX);
corr2d.saveMlTilePixel(
tileX, // int tileX,
tileY, // int tileY,
ml_hwidth, // int ml_hwidth,
ml_data, // double [][] ml_data,
ImageDtt.ML_OTHER_INDEX, // int ml_layer,
ImageDtt.ML_OTHER_GTRUTH_STRENGTH, // int ml_index,
strength[nTile], // target disparitydouble ml_value,
tilesX); // int tilesX);
}
}
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,
ml_data, // double [][] ml_data, // data for ML - 10 layers - 4 center areas (3x3, 5x5,..) per camera-per direction, 1 - composite, and 1 with just 1 data (target disparity)
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // maximal number of threads to launch // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
return ml_data;
}
ArrayList<Integer> selectRigTiles(
EyesisCorrectionParameters.CLTParameters clt_parameters,
......@@ -1460,14 +2110,9 @@ public class TwoQuadCLT {
(disparity_bimap[ImageDtt.BI_STR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_main)&&
(disparity_bimap[ImageDtt.BI_ASTR_FULL_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_aux)&&
(disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX][nTile] >= clt_parameters.rig.inf_min_strength_rig)&&
(disparity_bimap[ImageDtt.BI_DISP_FULL_INDEX][nTile] <= clt_parameters.rig.inf_max_disp_main) &&
(disparity_bimap[ImageDtt.BI_ADISP_FULL_INDEX][nTile] <= clt_parameters.rig.inf_max_disp_aux) &&
(disparity_bimap[ImageDtt.BI_DISP_CROSS_INDEX][nTile] <= clt_parameters.rig.inf_max_disp_rig) &&
(disparity_bimap[ImageDtt.BI_DISP_FULL_INDEX][nTile] >= -clt_parameters.rig.inf_max_disp_main) &&
(disparity_bimap[ImageDtt.BI_ADISP_FULL_INDEX][nTile] >= -clt_parameters.rig.inf_max_disp_aux) &&
(disparity_bimap[ImageDtt.BI_DISP_CROSS_INDEX][nTile] >= -clt_parameters.rig.inf_max_disp_rig * clt_parameters.rig.inf_neg_tolerance)) {
(Math.abs(disparity_bimap[ImageDtt.BI_DISP_FULL_INDEX][nTile]) <= clt_parameters.rig.near_max_disp_main)&&
(Math.abs(disparity_bimap[ImageDtt.BI_ADISP_FULL_INDEX][nTile]) <= clt_parameters.rig.near_max_disp_aux)&&
(Math.abs(disparity_bimap[ImageDtt.BI_DISP_CROSS_INDEX][nTile]) <= clt_parameters.rig.near_max_disp_rig)) {
tilesList.add(nTile);
}
}
......
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