Commit dd1befbb authored by Andrey Filippov's avatar Andrey Filippov

working on rig infinity calibration

parent c8fd13f4
import java.util.Properties;
/**
**
** BiQuadParameters - parameters defining Operation of a two quad camera rig
**
** Copyright (C) 2018 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
**
** BiQuadParameters.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
** -----------------------------------------------------------------------------**
**
*/
public class BiQuadParameters {
public boolean rig_mode_debug = true;
public boolean use_poly = true;
public boolean use_xy_poly = true;
public double min_poly_strength = 0.2;
public double min_xy_poly_strength = 1.0; // never
public double inf_min_strength_main = 0.12;
public double inf_min_strength_aux = 0.12;
public double inf_min_strength_rig = 0.25;
public double inf_max_disp_main = 0.15;
public double inf_max_disp_aux = 0.15;
public double inf_max_disp_rig = 0.5; // maybe even higher (2.0) to lock to initially high mismatch
public void dialogQuestions(GenericJTabbedDialog gd) {
gd.addCheckbox ("Debug rig/bi-camera functionality ", this.rig_mode_debug,"Enable debugging of the methods related to dual camera rig");
gd.addCheckbox ("Use poly for main/aux/rig correlations (false - CM)", this.use_poly,"Use LMA/polynomial if correlation is strong enough");
gd.addCheckbox ("Use poly for rig X/Y mismatch measurements", this.use_xy_poly,"Use polynomial forX/Y offset measurements if correlation is strong enough");
gd.addNumericField("Use poly mode for disparity if strength is greater than", this.min_poly_strength, 3,6,"",
"Minimal correlation strength to use poly mode (below use CM)");
gd.addNumericField("Use poly mode for X/Y rig correction if strength is greater than", this.min_xy_poly_strength, 3,6,"",
"Minimal correlation strength to use poly mode (below use CM) for measureking X/Y offset at infinity");
gd.addNumericField("Minimal strength for main camera correlation to use for infinity rig adjustment", this.inf_min_strength_main, 3,6,"",
"Do not use tile for infinity adjustment if main correlation strength is less than");
gd.addNumericField("Minimal strength for aux camera correlation to use for infinity rig adjustment", this.inf_min_strength_aux, 3,6,"",
"Do not use tile for infinity adjustment if aux correlation strength is less than");
gd.addNumericField("Minimal strength for inter-camera correlation to use for infinity rig adjustment", this.inf_min_strength_rig, 3,6,"",
"Do not use tile for infinity adjustment if inter-camera correlation strength is less than");
gd.addNumericField("Maximal absolute value of main camera disparity to use for infinity rig adjustment", this.inf_max_disp_main, 3,6,"pix",
"Do not use tile for infinity adjustment if absolute value of the main camera disparity is too high");
gd.addNumericField("Maximal absolute value of aux camera disparity to use for infinity rig adjustment", this.inf_max_disp_aux, 3,6,"pix",
"Do not use tile for infinity adjustment if absolute value of the main camera disparity is too high");
gd.addNumericField("Maximal absolute value of inter-camera disparity to use for infinity rig adjustment", this.inf_max_disp_rig, 3,6,"pix",
"Do not use tile for infinity adjustment if absolute value of the inter-camera disparity is too high");
}
public void dialogAnswers(GenericJTabbedDialog gd) {
this.rig_mode_debug= gd.getNextBoolean();
this.use_poly= gd.getNextBoolean();
this.use_xy_poly= gd.getNextBoolean();
this.min_poly_strength= gd.getNextNumber();
this.min_xy_poly_strength= gd.getNextNumber();
this.inf_min_strength_main= gd.getNextNumber();
this.inf_min_strength_aux= gd.getNextNumber();
this.inf_min_strength_rig= gd.getNextNumber();
this.inf_max_disp_main= gd.getNextNumber();
this.inf_max_disp_aux= gd.getNextNumber();
this.inf_max_disp_rig= gd.getNextNumber();
}
public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"rig_mode_debug", this.rig_mode_debug+"");
properties.setProperty(prefix+"use_poly", this.use_poly+"");
properties.setProperty(prefix+"use_xy_poly", this.use_xy_poly+"");
properties.setProperty(prefix+"min_poly_strength", this.min_poly_strength+"");
properties.setProperty(prefix+"min_xy_poly_strength", this.min_xy_poly_strength+"");
properties.setProperty(prefix+"inf_min_strength_main", this.inf_min_strength_main+"");
properties.setProperty(prefix+"inf_min_strength_aux", this.inf_min_strength_aux+"");
properties.setProperty(prefix+"inf_min_strength_rig", this.inf_min_strength_rig+"");
properties.setProperty(prefix+"inf_max_disp_main", this.inf_max_disp_main+"");
properties.setProperty(prefix+"inf_max_disp_aux", this.inf_max_disp_aux+"");
properties.setProperty(prefix+"inf_max_disp_rig", this.inf_max_disp_rig+"");
}
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"));
if (properties.getProperty(prefix+"use_poly")!=null) this.use_poly=Boolean.parseBoolean(properties.getProperty(prefix+"use_poly"));
if (properties.getProperty(prefix+"use_xy_poly")!=null) this.use_xy_poly=Boolean.parseBoolean(properties.getProperty(prefix+"use_xy_poly"));
if (properties.getProperty(prefix+"min_poly_strength")!=null) this.min_poly_strength=Double.parseDouble(properties.getProperty(prefix+"min_poly_strength"));
if (properties.getProperty(prefix+"min_xy_poly_strength")!=null) this.min_xy_poly_strength=Double.parseDouble(properties.getProperty(prefix+"min_xy_poly_strength"));
if (properties.getProperty(prefix+"inf_min_strength_main")!=null) this.inf_min_strength_main=Double.parseDouble(properties.getProperty(prefix+"inf_min_strength_main"));
if (properties.getProperty(prefix+"inf_min_strength_aux")!=null) this.inf_min_strength_aux=Double.parseDouble(properties.getProperty(prefix+"inf_min_strength_aux"));
if (properties.getProperty(prefix+"inf_min_strength_rig")!=null) this.inf_min_strength_rig=Double.parseDouble(properties.getProperty(prefix+"inf_min_strength_rig"));
if (properties.getProperty(prefix+"inf_max_disp_main")!=null) this.inf_max_disp_main=Double.parseDouble(properties.getProperty(prefix+"inf_max_disp_main"));
if (properties.getProperty(prefix+"inf_max_disp_aux")!=null) this.inf_max_disp_aux=Double.parseDouble(properties.getProperty(prefix+"inf_max_disp_aux"));
if (properties.getProperty(prefix+"inf_max_disp_rig")!=null) this.inf_max_disp_rig=Double.parseDouble(properties.getProperty(prefix+"inf_max_disp_rig"));
}
@Override
public BiQuadParameters clone() throws CloneNotSupportedException {
BiQuadParameters bqp = new BiQuadParameters();
bqp.rig_mode_debug= this.rig_mode_debug;
bqp.use_poly= this.use_poly;
bqp.use_xy_poly= this.use_xy_poly;
bqp.min_poly_strength = this.min_poly_strength;
bqp.min_xy_poly_strength = this.min_xy_poly_strength;
bqp.inf_min_strength_main = this.inf_min_strength_main;
bqp.inf_min_strength_aux = this.inf_min_strength_aux;
bqp.inf_min_strength_rig = this.inf_min_strength_rig;
bqp.inf_max_disp_main = this.inf_max_disp_main;
bqp.inf_max_disp_aux = this.inf_max_disp_aux;
bqp.inf_max_disp_rig = this.inf_max_disp_rig;
return bqp;
}
}
......@@ -307,7 +307,7 @@ public class Correlation2d {
/**
* Calculate all required image pairs phase correlation
* @param clt_data aberration-corrected FD CLT data [camera][color][quadrant][index]
* @param clt_data aberration-corrected FD CLT data for one tile [camera][color][quadrant][index]
* @param pairs_mask bimask of required pairs
* @param lpf optional low-pass filter
* @param col_weights RBG color weights
......@@ -337,6 +337,66 @@ public class Correlation2d {
return pairs_corr;
}
/**
* Calculate FD phase correlation between averaged FD data from two quad (or octal/mixed)
* cameras, each should be pre-shifted the same disparity
* @param clt_data_tile_main aberration-corrected FD CLT data for one tile of the main quad camera [sub-camera][color][quadrant][index]
* @param clt_data_tile_aux aberration-corrected FD CLT data for one tile of the auxiliary quad camera [sub-camera][color][quadrant][index]
* @param lpf optional low-pass filter
* @param col_weights RBG color weights
* @param fat_zero fat zero for phase correlations
* @return 2-d correlation array in line scan order
*/
public double [] correlateInterCamerasFD(
double [][][][] clt_data_tile_main,
double [][][][] clt_data_tile_aux,
double [] lpf,
double [] col_weights,
double fat_zero) {
if ((clt_data_tile_main == null) || (clt_data_tile_aux == null)) return null;
double [][][] clt_mix_main = cltMixCameras(clt_data_tile_main);
double [][][] clt_mix_aux = cltMixCameras(clt_data_tile_aux);
double [] inter_cam_corr = correlateCompositeFD(
clt_mix_main, // double [][][] clt_data1,
clt_mix_aux, // double [][][] clt_data2,
lpf, // double [] lpf,
col_weights, // double [] col_weights,
fat_zero); // double fat_zero)
return inter_cam_corr;
}
/**
* Average FD data from 4 sub-cameras (rendered for the same specific disparity/distance),
* each color component separately. Used to correlate a pair of quad-camera composite images
* @param clt_data_tile aberration-corrected FD CLT data for one tile [camera][color][quadrant][index]
* @return averaged for all cameras FD data [color][quadrant][index]
*/
public double [][][] cltMixCameras(
double [][][][] clt_data_tile){
int tlen = transform_size * transform_size;
double [][][] clt_mix = new double [clt_data_tile[0].length][4][tlen];
for (int color = 0; color < clt_mix.length; color++) {
for (int cltq = 0; cltq <4; cltq++) {
for (int i = 0; i < tlen; i++) {
for (int cam = 0; cam < clt_data_tile.length; cam++)
clt_mix[color][cltq][i] += clt_data_tile[cam][color][cltq][i];
}
}
}
double k = 1.0/clt_data_tile.length;
for (int color = 0; color < clt_mix.length; color++) {
for (int cltq = 0; cltq <4; cltq++) {
for (int i = 0; i < tlen; i++) {
clt_mix[color][cltq][i] *= k;
}
}
}
return clt_mix;
}
/**
* Combine (average) several specified correlation pairs that have the same grid (ortho/diagonal, different baselines)
* Ortho pairs will be transposed as needed to match horizontal pairs, diagonal ones - to match main diagonal (0->3)
......@@ -489,8 +549,22 @@ public class Correlation2d {
int hwidth,
boolean debug
) {
int dir = PAIRS[npair][2]; // 0 - hor, 1 - vert, 2 - parallel to row = col (main) diagonal (0->3), 3 -2->1
int ss = PAIRS[npair][3]/sub_sampling;
return scaleRotateInterpoateSingleCorrelation(
correlations[npair],
hwidth,
PAIRS[npair][2], // 0 - hor, 1 - vert, 2 - parallel to row = col (main) diagonal (0->3), 3 -2->1
PAIRS[npair][3]/sub_sampling,
debug);
}
public double [] scaleRotateInterpoateSingleCorrelation(
double [] corr,
int hwidth,
int dir, // 0 - hor, 1 - vert, 2 - parallel to row = col (main) diagonal (0->3), 3 -2->1
int ss,
boolean debug
) {
// int dir = PAIRS[npair][2]; // 0 - hor, 1 - vert, 2 - parallel to row = col (main) diagonal (0->3), 3 -2->1
// int ss = PAIRS[npair][3]/sub_sampling;
int center = transform_size - 1;
int width = 2 * center + 1;
double [] strip = new double [hwidth * width];
......@@ -498,9 +572,9 @@ public class Correlation2d {
int denom = ss * ((dir > 1)?1:2);
double rdenom = denom;
int ilimit = center * denom;
double [] corr = correlations[npair];
// double [] corr = correlations[npair];
if (debug) {
System.out.println("\n============== scaleRotateInterpoateSingleCorrelation(),npair ="+ npair+", sub_sampling="+sub_sampling+" ===============");
System.out.println("\n============== scaleRotateInterpoateSingleCorrelation() ===============");
}
for (int row = 0; row < hwidth; row++) {
......@@ -1135,6 +1209,88 @@ public class Correlation2d {
return rslt;
}
// run a single correlation poly
public double [] single2dPoly( // returns x-xcenter, y, strength (sign same as disparity)
ImageDttParameters imgdtt_params,
double [] corr,
double xcenter, // -disparity to compare. use 0?
double vasw_pwr, // value as weight to this power,
int debug_level,
int tileX, // just for debug output
int tileY
) {
double [] rslt = {Double.NaN,Double.NaN, 0.0};
Correlations2dLMA lma=corrLMA(
imgdtt_params, // ImageDttParameters imgdtt_params,
corr, // double [][] corrs,
true, // boolean run_poly_instead, // true - run LMA, false - run 2d polynomial approximation
xcenter, // double xcenter, // preliminary center x in pixels for largest baseline
vasw_pwr, // double vasw_pwr, // value as weight to this power,
debug_level, // -1, // int debug_level,
tileX, // int tileX, // just for debug output
tileY); //int tileY
if ((lma != null) && (lma.getPoly() != null)) {
double [] poly_xyvwh = lma.getPoly();
rslt[0] = xcenter - poly_xyvwh[0];
rslt[1] = -poly_xyvwh[1];
rslt[2] = Double.isNaN(poly_xyvwh[2])?0.0: poly_xyvwh[2];
}
return rslt;
}
public double [] single2dCM( // returns x-xcenter, y, strength (sign same as disparity)
ImageDttParameters imgdtt_params,
double [] corr,
double xcenter, // -disparity to compare. use 0?
double radius, // positive - within that distance, negative - within 2*(-radius)+1 square
int debug_level,
int tileX, // just for debug output
int tileY
) {
int width = 2 * transform_size - 1;
int center = transform_size - 1;
int center_index = (width + 1) * center; //
double [] rslt = {Double.NaN,Double.NaN, 0.0};
int ixcenter = (int) Math.round(xcenter);
int [] icenter = {ixcenter, 0};
//calculate as "center of mass"
int iradius = (int) Math.abs(radius);
int ir2 = (int) (radius*radius);
boolean square = radius <0;
double s0 = 0, sx=0, sy = 0;
for (int y = - iradius ; y <= iradius; y++){
int dataY = icenter[1] +y;
if ((dataY >= -center) && (dataY <= center)){
int y2 = y*y;
for (int x = - iradius ; x <= iradius; x++){
int dataX = icenter[0] +x;
double r2 = y2 + x * x;
if ((dataX >= -center) && (dataX <= center) && (square || (r2 <= ir2))){
double d = corr[dataY * width + dataX + center_index];
if (d > 0.0) {
s0 += d;
sx += d * dataX;
sy += d * dataY;
}
}
}
}
}
double xm = sx / s0;
double ym = sy / s0;
int ixm = (int) Math.round(xm);
int iym = (int) Math.round(ym);
double s = corr[iym * width + ixm + center_index];
rslt[0] = xcenter - xm;
rslt[1] = -ym;
rslt[2] = s;
return rslt;
}
public double [][] corr4dirsLMA(
ImageDttParameters imgdtt_params,
double [][] corrs,
......@@ -1446,6 +1602,121 @@ public class Correlation2d {
return lmaSuccess? lma: null;
}
// Run for a single horizontal 2d correlation array
public Correlations2dLMA corrLMA(
ImageDttParameters imgdtt_params,
double [] corr,
boolean run_poly_instead, // true - run LMA, false - run 2d polynomial approximation
double xcenter, // preliminary center x in pixels for largest baseline
double vasw_pwr, // value as weight to this power,
int debug_level,
int tileX, // just for debug output
int tileY)
{
double [][] groups_LMA = {corr}; // new double [ng][];
int [][] groups_pairs = {{1,0}}; // new int[ng][]; // number of combined pairs, index of base pair
int [] group_scale_ind = {0}; // new int [ng]; // number of combined pairs, index of base pair
double [] scales = {1.0};
Correlations2dLMA lma = new Correlations2dLMA(scales);
if (debug_level > 1) {
for (int i = 0; i < groups_pairs.length; i++) {
System.out.println("Group #"+i+" - "+groups_pairs[i][0]+", type:"+groups_pairs[i][1]);
}
}
addSamples(
xcenter, // double xcenter, // preliminary center x in pixels for largest baseline
imgdtt_params.cnvx_hwnd_size, // int hwindow_y, // = window_y.length; // should actually be the same?
imgdtt_params.cnvx_hwnd_size, //int hwindow_x, // = window_x.length;
vasw_pwr, // double vasw_pwr, // value as weight to this power,
groups_LMA, // double [][] groups_LMA,
groups_pairs, // int [][] groups_pairs,
scales, // double [] scales,
group_scale_ind, // int [] group_scale_ind,
lma, // Correlations2dLMA lma,
imgdtt_params.cnvx_add3x3, // boolean add3x3,
imgdtt_params.cnvx_weight, // double nc_cost,
debug_level); // int debug_level
boolean lmaSuccess;
if (run_poly_instead) {
lma.getMaxXYPoly( // get interpolated maximum coordinates using 2-nd degree polynomial
debug_level>3); // boolean debug
lmaSuccess = lma.getPolyFx() != null;
} else {
lma.initVector(
imgdtt_params.lma_adjust_wm, // boolean adjust_wm,
imgdtt_params.lma_adjust_wy, // boolean adjust_wy,
imgdtt_params.lma_adjust_wxy, // boolean adjust_wxy,
imgdtt_params.lma_adjust_ag, // boolean adjust_Ag,
xcenter, // double x0,
imgdtt_params.lma_half_width, // double half_width,
imgdtt_params.lma_cost_wy, // double cost_wy, // cost of non-zero this.all_pars[WYD_INDEX]
imgdtt_params.lma_cost_wxy //double cost_wxy // cost of non-zero this.all_pars[WXY_INDEX]
);
if (debug_level > 1) {
System.out.println("Input data:");
lma.printInputDataFx(false);
}
lmaSuccess = lma.runLma(
imgdtt_params.lma_lambda_initial, // double lambda, // 0.1
imgdtt_params.lma_lambda_scale_good, // double lambda_scale_good,// 0.5
imgdtt_params.lma_lambda_scale_bad, // double lambda_scale_bad, // 8.0
imgdtt_params.lma_lambda_max, // double lambda_max, // 100
imgdtt_params.lma_rms_diff, // double rms_diff, // 0.001
imgdtt_params.lma_num_iter, // int num_iter, // 20
debug_level); // int debug_level)
lma.updateFromVector();
double [] rms = lma.getRMS();
if (debug_level > 0) {
System.out.println("LMA ->"+lmaSuccess+" RMS="+rms[0]+", pure RMS="+rms[1]);
lma.printParams();
}
}
if ((debug_level > 1) && (groups_LMA !=null) && (groups_LMA.length > 0)) {
double [][] y_and_fx = new double [groups_LMA.length * 2][];
double [][] groups_fx = getFitSamples( // just for debug to compare LMA-fitted fx with original data
xcenter, // double xcenter, // preliminary center x in pixels for largest baseline
imgdtt_params.cnvx_hwnd_size, // int hwindow_y, // = window_y.length; // should actually be the same?
imgdtt_params.cnvx_hwnd_size, //int hwindow_x, // = window_x.length;
groups_pairs, // int [][] groups_pairs,
scales, // double [] scales,
group_scale_ind, // int [] group_scale_ind,
lma, // Correlations2dLMA lma,
groups_LMA, // double [][] groups_LMA,
imgdtt_params.cnvx_add3x3, // boolean add3x3,
imgdtt_params.cnvx_weight, // double nc_cost,
debug_level); // int debug_level
String [] titles = new String [groups_LMA.length * 2];
for (int i = 0; i < groups_LMA.length; i++) if (groups_pairs[i][0] > 0){
int base_pair = groups_pairs[i][1];
titles[2 * i] = (isDiagonalPair(base_pair)?"diag":"ortho")+getScaleOfPair(base_pair);
titles[2 * i + 1] = (isDiagonalPair(base_pair)?"diag":"ortho")+getScaleOfPair(base_pair)+"-fit";
y_and_fx[2 * i] = groups_LMA[i];
y_and_fx[2 * i + 1] = groups_fx[i];
}
// String [] titles = {"ortho","diagonal"};
(new showDoubleFloatArrays()).showArrays(
y_and_fx,
2 * transform_size-1,
2 * transform_size-1,
true, (run_poly_instead?"poly":"lma")+"_x"+tileX+"_y"+tileY, titles);
}
if (debug_level > 1) {
System.out.println("Input data and approximation:");
lma.printInputDataFx(true);
}
return lmaSuccess? lma: null;
}
/**
* Create mask of usable points, allowing only first non bi-convex away from the center
* @param corr_data correlation data, packed in linescan order
......
......@@ -3018,6 +3018,7 @@ public class EyesisCorrectionParameters {
public double [] vertical_xyz = {0.0,1.0,0.0}; // real world up unit vector in camera CS (x - right, y - up, z - to camera};
public ImageDttParameters img_dtt = new ImageDttParameters();
public BiQuadParameters rig = new BiQuadParameters();
public MeasuredLayersFilterParameters mlfp = new MeasuredLayersFilterParameters();
public HashMap<String,Double> z_corr_map = new HashMap<String,Double>();
......@@ -3661,6 +3662,7 @@ public class EyesisCorrectionParameters {
}
img_dtt.setProperties (prefix+"_img_dtt", properties);
mlfp.setProperties (prefix+"_mlfp", properties);
rig.setProperties (prefix+"_rig", properties);
}
public void getProperties(String prefix,Properties properties){
......@@ -4308,6 +4310,7 @@ public class EyesisCorrectionParameters {
}
img_dtt.getProperties (prefix+"_img_dtt", properties);
mlfp.getProperties (prefix+"_mlfp", properties);
rig.getProperties (prefix+"_rig", properties);
}
public boolean showJDialog() {
......@@ -4363,9 +4366,10 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Select all-pair correlation type to use 0 - CM, 1 - poly", this.corr_select, 0);
gd.addTab ("imageDtt", "Setup extra ImageDtt parameters - eventually all will be set that way");
// moved
this.img_dtt.dialogQuestions(gd);
gd.addTab ("Rig", "Parameters for the wide baseline rig with two quad cameras");
this.rig.dialogQuestions(gd);
gd.addTab ("vert/hor", "Enhance detection of horizontal/vertical features (when enh_ortho is enabled for tile");
gd.addMessage("--- Enhance detection of horizontal/vertical features (when enh_ortho is enabled for tile ---");
......@@ -5097,6 +5101,7 @@ public class EyesisCorrectionParameters {
this.img_dtt.dialogAnswers(gd);
this.rig.dialogAnswers(gd);
this.max_corr_double= gd.getNextBoolean();
this.corr_mode= (int) gd.getNextNumber();
......
......@@ -582,6 +582,7 @@ private Panel panel1,
addButton("CLT 2*4 images", panelClt4, color_conf_process);
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 show fine", panelClt4, color_configure);
add(panelClt4);
......@@ -4464,6 +4465,12 @@ private Panel panel1,
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
getPairImages2(true);
return;
/* ======================================================================== */
} else if (label.equals("Rig infinity calibration")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
infinityRig();
return;
/* ======================================================================== */
} else if (label.equals("AUX show fine")) {
if (QUAD_CLT == null){
......@@ -4744,9 +4751,7 @@ private Panel panel1,
return true;
}
public boolean getPairImages2( boolean new_mode) {
public boolean prepareRigImages() {
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
QuadCLT.PREFIX,
......@@ -4849,6 +4854,14 @@ private Panel panel1,
if (TWO_QUAD_CLT == null) {
TWO_QUAD_CLT = new TwoQuadCLT();
}
return true;
}
public boolean getPairImages2( boolean new_mode) {
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
if (new_mode) {
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Calculating combined correlations ++++++++++++++");
......@@ -4860,8 +4873,8 @@ private Panel panel1,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
CHANNEL_GAINS_PARAMETERS_AUX, //CorrectionColorProc.ColorGainsParameters channelGainParameters_aux,
// CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
// CHANNEL_GAINS_PARAMETERS_AUX, //CorrectionColorProc.ColorGainsParameters channelGainParameters_aux,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
......@@ -4901,11 +4914,40 @@ private Panel panel1,
true,
PROPERTIES);
}
return true;
}
public boolean infinityRig() {
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Processing Infinity rig calibration ++++++++++++++");
}
try {
TWO_QUAD_CLT.processInfinityRigs( // 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 ImagePlus selectCLTImage() {
if (!CLT_PARAMETERS.showJDialog()) return null;
......
......@@ -223,6 +223,70 @@ public class GeometryCorrection {
return rot;
}
/**
* Get derivatives of the auxiliary camera rotation matrix, per axis (azimuth, tilt, roll, zoom)
* d/dx and d/dy should be normalized by z-component of the vector (not derivative)
* @return 2-d array array of derivatives matrices
*/
//TODO: UPDATE to include scales
public Matrix [] getRotDeriveMatrices()
{
Matrix [] rot_derivs = new Matrix [4]; // channel, azimuth-tilt-roll-zoom
double ca = Math.cos(aux_azimuth);
double sa = Math.sin(aux_azimuth);
double ct = Math.cos(aux_tilt);
double st = Math.sin(aux_tilt);
double zoom = (1.0 + aux_zoom);
double cr = Math.cos(aux_roll);
double sr = Math.sin(aux_roll);
double [][] a_az = { // inverted - OK
{ ca, 0.0, sa * ROT_AZ_SGN },
{ 0.0, 1.0, 0.0},
{ -sa* ROT_AZ_SGN, 0.0, ca}};
double [][] a_t = { // inverted - OK
{ 1.0, 0.0, 0.0},
{ 0.0, ct, st * ROT_TL_SGN},
{ 0.0, -st * ROT_TL_SGN, ct}};
double [][] a_r = { // inverted OK
{ cr, sr * ROT_RL_SGN, 0.0},
{ -sr * ROT_RL_SGN, cr, 0.0},
{ 0.0, 0.0, 1.0}};
double [][] a_daz = { // inverted - OK
{ -sa, 0.0, ca * ROT_AZ_SGN },
{ 0.0, 0.0, 0.0},
{ -ca* ROT_AZ_SGN, 0.0, -sa}};
double [][] a_dt = { // inverted - OK
{ 0.0, 0.0, 0.0},
{ 0.0, -st, ct * ROT_TL_SGN},
{ 0.0, -ct * ROT_TL_SGN, -st}};
double [][] a_dr = { // inverted OK
{ -sr * zoom, cr * zoom * ROT_RL_SGN, 0.0},
{ -cr * zoom *ROT_RL_SGN, -sr * zoom, 0.0},
{ 0.0, 0.0, 0.0}};
double [][] a_dzoom = { // inverted OK
{ cr, sr * ROT_RL_SGN, 0.0},
{ -sr * ROT_RL_SGN, cr, 0.0},
{ 0.0, 0.0, 0.0}};
// d/d_az
rot_derivs[0] = (new Matrix(a_r ).times(new Matrix(a_t ).times(new Matrix(a_daz))));
rot_derivs[1] = (new Matrix(a_r ).times(new Matrix(a_dt).times(new Matrix(a_az ))));
rot_derivs[2] = (new Matrix(a_dr).times(new Matrix(a_t ).times(new Matrix(a_az ))));
rot_derivs[3] = (new Matrix(a_dzoom).times(new Matrix(a_t ).times(new Matrix(a_az ))));
return rot_derivs;
}
public void setProperties(String parent_prefix,Properties properties){
String prefix = parent_prefix + RIG_PREFIX;
......
......@@ -103,24 +103,25 @@ public class ImageDtt {
static int BI_ADISP_VERT_INDEX = 7; // 7 - disparity for 2 vertical pairs of the aux camera
static int BI_ADISP_DIAGM_INDEX = 8; // 8 - disparity for main diagonal pair of the aux camera
static int BI_ADISP_DIAGO_INDEX = 9; // 9 - disparity for main diagonal pair of the aux camera
static int BI_DISP_CROSSX_INDEX = 10; //10 - disparity between the main the aux camera (horizontal)
static int BI_DISP_CROSSY_INDEX = 11; //10 - disparity between the main the aux camera (vertical)
static int BI_STR_FULL_INDEX = 12; //11 - strength for all directions of the main camera
static int BI_STR_HOR_INDEX = 13; //12 - strength for 2 horizontal pairs of the main camera
static int BI_STR_VERT_INDEX = 14; //13 - strength for 2 vertical pairs of the main camera
static int BI_STR_DIAGM_INDEX = 15; //14 - strength for main diagonal pair of the main camera
static int BI_STR_DIAGO_INDEX = 16; //15 - strength for main diagonal pair of the main camera
static int BI_ASTR_FULL_INDEX = 17; //16 - strength for all directions of the aux camera
static int BI_ASTR_HOR_INDEX = 18; //17 - strength for 2 horizontal pairs of the aux camera
static int BI_ASTR_VERT_INDEX = 19; //18 - strength for 2 vertical pairs of the aux camera
static int BI_ASTR_DIAGM_INDEX = 20; //19 - strength for main diagonal pair of the aux camera
static int BI_ASTR_DIAGO_INDEX = 21; //20 - strength for main diagonal pair of the aux camera
static int BI_ASTR_CROSS_INDEX = 22; //21 - strength between the main the aux camera
static int BI_DISP_CROSS_INDEX = 10; //10 - disparity between the main the aux camera
static int BI_DISP_CROSS_DX_INDEX = 11; //11 - delta disparity between the main the aux camera (horizontal)
static int BI_DISP_CROSS_DY_INDEX = 12; //12 - delta disparity between the main the aux camera (vertical)
static int BI_STR_FULL_INDEX = 13; //13 - strength for all directions of the main camera
static int BI_STR_HOR_INDEX = 14; //14 - strength for 2 horizontal pairs of the main camera
static int BI_STR_VERT_INDEX = 15; //15 - strength for 2 vertical pairs of the main camera
static int BI_STR_DIAGM_INDEX = 16; //16 - strength for main diagonal pair of the main camera
static int BI_STR_DIAGO_INDEX = 17; //17 - strength for main diagonal pair of the main camera
static int BI_ASTR_FULL_INDEX = 18; //18 - strength for all directions of the aux camera
static int BI_ASTR_HOR_INDEX = 19; //19 - strength for 2 horizontal pairs of the aux camera
static int BI_ASTR_VERT_INDEX = 20; //20 - strength for 2 vertical pairs of the aux camera
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 String [] BIDISPARITY_TITLES = {
"disparity","disp_hor","disp_vert","disp_diagm","disp_diago",
"adisparity","adisp_hor","adisp_vert","adisp_diagm","adisp_diago",
"bi-disparity-x","bi-disparity-y",
"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"};
......@@ -136,6 +137,14 @@ 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
// indices in cross-camera correlation results
static int INDEX_DISP = 0;
static int INDEX_STRENGTH = 1;
static int INDEX_DX = 2;
static int INDEX_DY = 3;
static String [] SNGL_DISPARITY_TITLES = {
"disparity","disp_hor","disp_vert","disp_diagm","disp_diago",
"strength", "str_hor", "str_vert", "str_diagm", "str_diago"};
......@@ -1507,7 +1516,7 @@ public class ImageDtt {
final int globalDebugLevel)
{
// final boolean debug_ports_coordinates = (debug_tileX == -1234);
final double poly_corr = imgdtt_params.poly_corr_scale; // maybe add per-tile task bits to select none/near/far
// final double poly_corr = imgdtt_params.poly_corr_scale; // maybe add per-tile task bits to select none/near/far
final boolean macro_mode = macro_scale != 1; // correlate tile data instead of the pixel data
final int quad = 4; // number of subcameras
final int numcol = 3; // number of colors
......@@ -1658,8 +1667,8 @@ public class ImageDtt {
}
}
final double [] corr_max_weights_poly =(((max_corr_sigma > 0) && (disparity_map != null))?
setMaxXYWeights(max_corr_sigma,max_search_radius_poly): null); // here use square anyway
// final double [] corr_max_weights_poly =(((max_corr_sigma > 0) && (disparity_map != null))?
// setMaxXYWeights(max_corr_sigma,max_search_radius_poly): null); // here use square anyway
dtt.set_window(window_type);
final double [] lt_window = dtt.getWin2d(); // [256]
......@@ -7063,16 +7072,172 @@ public class ImageDtt {
return clt_data;
}
/**
* Calculate disparity and strength for a inter-camera phase correlation of a pair of quad-cameras
* @param clt_parameters various configuration parameters
* @param corr2d Instance of the 2d correlator class
* @param clt_data_tile_main aberration-corrected FD CLT data for one tile of the main quad camera [sub-camera][color][quadrant][index]
* @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 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
* @param debugLevel debug level
* @return
*/
public double [] tileInterCamCorrs(
final EyesisCorrectionParameters.CLTParameters clt_parameters,
final Correlation2d corr2d,
double [][][][] clt_data_tile_main,
double [][][][] clt_data_tile_aux,
final double [] filter,
final double [] col_weights,
double [][] tcorr_combo,
final int tileX, // only used in debug output
final int tileY,
final int debugLevel) {
double [] result = {Double.NaN, 0.0, Double.NaN, Double.NaN};
double [] inter_cam_corr = corr2d.correlateInterCamerasFD(
clt_data_tile_main, // double [][][][] clt_data_tile_main,
clt_data_tile_aux, // double [][][][] clt_data_tile_aux,
filter, // double [] lpf,
col_weights, // double [] col_weights,
clt_parameters.fat_zero); // double fat_zero)
double [] stripe_inter = corr2d. scaleRotateInterpoateSingleCorrelation(
inter_cam_corr, // double [] corr,
clt_parameters.img_dtt.corr_strip_hight, // int hwidth,
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 (tcorr_combo != null) {
tcorr_combo[0] = inter_cam_corr;
if (tcorr_combo.length > 1) {
tcorr_combo[1] = corr2d.debugStrip(stripe_inter);
}
if (tcorr_combo.length > 2) {
tcorr_combo[2] = corr2d.debugStrip2(stripe_inter);
}
}
// First get integer correlation center, relative to the center
int [] ixy = corr2d.getMaxXYInt( // find integer pair or null if below threshold
stripe_inter, // double [] data,
true, // boolean axis_only, for strip it is always true
clt_parameters.img_dtt.min_corr, // double minMax, // minimal value to consider (at integer location, not interpolated)
debugLevel > 0); // boolean debug);
double [] corr_stat = null;
// if integer argmax was strong enough, calculate CM argmax
// will not fill out DISPARITY_INDEX_INT+1, DISPARITY_INDEX_CM+1, DISPARITY_INDEX_POLY+1
// use clt_mismatch for that
double strength = 0.0;
double disparity = 0.0;
if (ixy != null) {
strength = stripe_inter[ixy[0]+clt_parameters.transform_size-1]; // strength at integer max on axis
disparity = -ixy[0];
result[INDEX_STRENGTH] = strength;
result[INDEX_DISP] = disparity;
if (Double.isNaN(strength)) {
System.out.println("BUG: 1. strength should not be NaN");
}
corr_stat = corr2d.getMaxXCm( // get fractional center as a "center of mass" inside circle/square from the integer max
stripe_inter, // double [] data, // [data_size * data_size]
ixy[0], // int ixcenter, // integer center x
// corr_wndy, // double [] window_y, // (half) window function in y-direction(perpendicular to disparity: for row0 ==1
// corr_wndx, // double [] window_x, // half of a window function in x (disparity) direction
(debugLevel > 0)); // boolean debug);
}
if (corr_stat != null) {
disparity = -corr_stat[0];
result[INDEX_DISP] = disparity;
// see if strength is enough to proceed with LMA/poly (otherwise keep disp/strength
if (strength > clt_parameters.img_dtt.min_poly_strength) {
// create LMA instance, calculate LMA composite argmax
// Create 2 groups: ortho & diag
Correlations2dLMA lma = corr2d.corrLMA(
clt_parameters.img_dtt, // ImageDttParameters clt_parameters.img_dtt,
inter_cam_corr, // double [] corr,
false, // boolean run_poly_instead, // true - run LMA, false - run 2d polynomial approximation
corr_stat[0], // double xcenter, // preliminary center x in pixels for largest baseline
clt_parameters.img_dtt.ortho_vasw_pwr, // double vasw_pwr, // value as weight to this power,
debugLevel, // int debug_level,
tileX, // int tileX, // just for debug output
tileY ); // int tileY
double [] lma_disparity_strength = null;
if (lma != null) {
lma_disparity_strength = lma.getDisparityStrength();
if (debugLevel > 0){
System.out.println(String.format("Tile X/Y = %d/%d LMA disparity = %7.4f, strength = %7.4f",
tileX, tileY,
lma_disparity_strength[0],lma_disparity_strength[1]));
}
// if enabled overwrite - replace DISPARITY_INDEX_CM and DISPARITY_STRENGTH_INDEX
if (clt_parameters.rig.use_poly) {
disparity = lma_disparity_strength[0];
strength = lma_disparity_strength[1];
result[INDEX_STRENGTH] = strength;
result[INDEX_DISP] = disparity;
if (Double.isNaN(strength)) {
System.out.println("BUG: 2. strength should not be NaN");
}
}
double [] corrXY = null;
if (clt_parameters.rig.use_xy_poly) {
corrXY= corr2d.single2dPoly( // returns x-xcenter, y, strength (sign same as disparity)
clt_parameters.img_dtt, // ImageDttParameters imgdtt_params,
inter_cam_corr, // double [] corr,
// See if -disparity should be here as in mismatch
0.0, // double xcenter, // -disparity to compare. use 0?
clt_parameters.img_dtt.ortho_vasw_pwr, // double vasw_pwr, // value as weight to this power,
debugLevel, // int debug_level,
tileX, // int tileX,
tileY); // int tileY
} else {
corrXY= corr2d.single2dCM( // returns x-xcenter, y, strength (sign same as disparity)
clt_parameters.img_dtt, // ImageDttParameters imgdtt_params,
inter_cam_corr, // double [] corr,
// See if -disparity should be here as in mismatch
0.0, // double xcenter, // -disparity to compare. use 0?
clt_parameters.max_corr_radius, // double vasw_pwr, // value as weight to this power,
debugLevel, // int debug_level,
tileX, // int tileX,
tileY); // int tileY
}
if (corrXY != null) {
result[INDEX_DX] = corrXY[0];
result[INDEX_DY] = corrXY[1];
}
}
}
} // end of if (corr_stat != null)
return result;
}
// processing two quad cameras
/**
* Calculate correlation/strength, start with center of mass (CM) for all available pairs, proceed with LMA
* if strength is sufficient. Calculate 4 directional correlation/strengths if requested and strong enough
* @param clt_parameters various configuration parameters
* @param get4dirs request 4 directional correlations (horizontal, vertical main diagonal, other diagonal)
* @param corr2d Instance of the 2d correlator class
* @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 tileX debug tile X
* @param tileY debug tile X
* @param debugLevel debug level
* @return {disparity, disp_hor, disp_vert, disp_diagm, disp_diago, strength, str_hor, str_vert, str_diagm, str_diago}
* indexed by DISP_*_INDEX and STR_*_INDEX constants
*/
public double [] tileCorrs(
final EyesisCorrectionParameters.CLTParameters clt_parameters,
final boolean get4dirs, // calcualte disparity/strength for each of teh 4 directions
final boolean get4dirs, // calculate disparity/strength for each of the 4 directions
final Correlation2d corr2d,
final double [][][][] clt_data,
final double [] filter,
......@@ -7090,9 +7255,7 @@ public class ImageDtt {
int all_pairs = clt_parameters.img_dtt.dbg_pair_mask; //TODO: use tile tasks
double [][] corrs = corr2d.correlateCompositeFD(
clt_data, // double [][][][][][] clt_data,
// tileX, // int tileX,
// tileY, // int tileY,
clt_data, // double [][][][] clt_data, // aberration-corrected FD CLT data for one tile [camera][color][quadrant][index]
all_pairs, // int pairs_mask,
filter, // double [] lpf,
col_weights, // double [] col_weights,
......@@ -7177,7 +7340,7 @@ public class ImageDtt {
lma_disparity_strength[0],lma_disparity_strength[1]));
}
// if enabled overwrite - replace DISPARITY_INDEX_CM and DISPARITY_STRENGTH_INDEX
if (clt_parameters.img_dtt.mix_corr_poly) {
if (clt_parameters.rig.use_poly) {
disparity = lma_disparity_strength[0];
strength = lma_disparity_strength[1];
result[STR_FULL_INDEX] = strength;
......@@ -7432,16 +7595,13 @@ public class ImageDtt {
final double [][][][][][] clt_kernels_main, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
final double [][][][][][] clt_kernels_aux, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
// final int debug_tileX,
// final int debug_tileY,
final boolean keep_clt_data,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
final int debugLevel)
{
final int globalDebugLevel = clt_parameters.rig.rig_mode_debug?debugLevel:-2;
final int debug_tileX = clt_parameters.tileX;
final int debug_tileY = clt_parameters.tileY;
// final boolean debug_ports_coordinates = (debug_tileX == -1234);
// final double poly_corr = clt_parameters.img_dtt.poly_corr_scale; // maybe add per-tile task bits to select none/near/far
final int quad_main = image_data_main.length; // number of subcameras
final int quad_aux = image_data_aux.length; // number of subcameras
final int numcol = 3; // number of colors
......@@ -7450,12 +7610,12 @@ public class ImageDtt {
final int tilesX=width/clt_parameters.transform_size;
final int tilesY=height/clt_parameters.transform_size;
final int nTilesInChn=tilesX*tilesY;
// clt_data does not need to be for the whole image
// final double [][][][][][] clt_data = new double[quad][nChn][tilesY][tilesX][][];
// final double [][][][][][][] clt_bidata = new double[2][quad][nChn][tilesY][tilesX][][]; // modify to have different number of sub-cameras in main/aux
final double [][][][][][][] clt_bidata = new double[2][][][][][][];
clt_bidata[0] = new double[quad_main][nChn][tilesY][tilesX][][];
clt_bidata[1] = new double[quad_aux][nChn][tilesY][tilesX][][];
// clt_data does not need to be for the whole image (no, it is used for textures)
final double [][][][][][][] clt_bidata = (keep_clt_data)? (new double[2][][][][][][]):null;
if (clt_bidata != null) {
clt_bidata[0] = new double[quad_main][nChn][tilesY][tilesX][][];
clt_bidata[1] = new double[quad_aux][nChn][tilesY][tilesX][][];
}
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
......@@ -7598,14 +7758,9 @@ public class ImageDtt {
double [][] fract_shiftsXY_main = new double[quad_main][];
double [][] fract_shiftsXY_aux = new double[quad_aux][];
double [][] tcorr_combo = null; // [15*15] pixel space
// double [][][] tcorr_partial = null; // [quad][numcol+1][15*15]
// double [][][][] tcorr_tpartial = null; // [quad][numcol+1][4][8*8]
double [][][][] clt_data_main = new double[quad_main][nChn][][];
double [][][][] clt_data_aux = new double[quad_aux][nChn][][];
// PolynomialApproximation pa = null;
// if (corr_max_weights_poly !=null) pa = new PolynomialApproximation(0); // debug level
Correlation2d corr2d = new Correlation2d(
clt_parameters.img_dtt, // ImageDttParameters imgdtt_params,
clt_parameters.transform_size, // int transform_size,
......@@ -7826,40 +7981,40 @@ public class ImageDtt {
// }
double [] tile_cors_main = tileCorrs(
double [] tile_corrs_main = tileCorrs(
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
true, // final boolean get4dirs, // calcualte disparity/strength for each of teh 4 directions
true, // final boolean get4dirs, // calculate disparity/strength for each of the 4 directions
corr2d, // final Correlation2d corr2d,
clt_data_main, // final double [][][][] clt_data,
clt_data_main, // final double [][][][] clt_data,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
double [] tile_cors_aux = tileCorrs(
double [] tile_corrs_aux = tileCorrs(
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
true, // final boolean get4dirs, // calcualte disparity/strength for each of teh 4 directions
true, // final boolean get4dirs, // calculate disparity/strength for each of the 4 directions
corr2d, // final Correlation2d corr2d,
clt_data_aux, // final double [][][][] clt_data,
clt_data_aux, // final double [][][][] clt_data,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
extra_disparity_main = tile_cors_main[DISP_FULL_INDEX];
extra_disparity_aux = tile_cors_aux[DISP_FULL_INDEX];
extra_disparity_main = tile_corrs_main[DISP_FULL_INDEX];
extra_disparity_aux = tile_corrs_aux[DISP_FULL_INDEX];
if (Double.isNaN(extra_disparity_main)) extra_disparity_main = 0;
if (Double.isNaN(extra_disparity_aux)) extra_disparity_aux = 0;
for (int i = 0; i < tile_cors_main.length; i++) {
for (int i = 0; i < tile_corrs_main.length; i++) {
int dest = SNGL_TO_BI[0][i];
if (disparity_bimap[dest] != null) disparity_bimap[dest][nTile] = tile_cors_main[i];
if (disparity_bimap[dest] != null) disparity_bimap[dest][nTile] = tile_corrs_main[i];
}
for (int i = 0; i < tile_cors_aux.length; i++) {
for (int i = 0; i < tile_corrs_aux.length; i++) {
int dest = SNGL_TO_BI[1][i];
if (disparity_bimap[dest] != null) disparity_bimap[dest][nTile] = tile_cors_aux[i];
if (disparity_bimap[dest] != null) disparity_bimap[dest][nTile] = tile_corrs_aux[i];
}
if (Double.isNaN(disparity_bimap[BI_STR_FULL_INDEX][tIndex])) {
System.out.println("BUG: 3. disparity_map[BI_STR_FULL_INDEX][tIndex] should not be NaN");
......@@ -7867,8 +8022,35 @@ public class ImageDtt {
if (Double.isNaN(disparity_bimap[BI_ASTR_FULL_INDEX][tIndex])) {
System.out.println("BUG: 3a. disparity_map[BI_ASTR_FULL_INDEX][tIndex] should not be NaN");
}
if (clt_corr_combo != null) { // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
tcorr_combo = new double [TCORR_TITLES.length][corr_size * corr_size];
}
double [] inter_corrs_dxy = tileInterCamCorrs(
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
corr2d, // final Correlation2d corr2d,
clt_data_main, // double [][][][] clt_data_tile_main,
clt_data_aux, // double [][][][] clt_data_tile_aux,
filter, // final double [] filter,
col_weights, // final double [] col_weights,
tcorr_combo, // double [][] tcorr_combo,
tileX, // final int tileX, // only used in debug output
tileY, // final int tileY,
tile_lma_debug_level); // final int debugLevel)
if (inter_corrs_dxy != null) {
disparity_bimap[BI_DISP_CROSS_INDEX][nTile] = inter_corrs_dxy[INDEX_DISP];
disparity_bimap[BI_STR_CROSS_INDEX][nTile] = inter_corrs_dxy[INDEX_STRENGTH];
disparity_bimap[BI_DISP_CROSS_DX_INDEX][nTile] = inter_corrs_dxy[INDEX_DX];
disparity_bimap[BI_DISP_CROSS_DY_INDEX][nTile] = inter_corrs_dxy[INDEX_DY];
}
} // 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
for (int i = 0; i < tcorr_combo.length; i++) {
clt_corr_combo[i][tileY][tileX] = tcorr_combo[i];
}
}
if (texture_tiles_main !=null) {
generateTextureTiles (
......@@ -7909,7 +8091,7 @@ public class ImageDtt {
tile_lma_debug_level); // final int debugLevel);
}
// Save channel tiles to result
if (keep_clt_data) {
if (clt_bidata != null) {
for (int i = 0; i < quad_main; i++) for (int j = 0; j < numcol; j++){
clt_bidata[0][i][j][tileY][tileX] = clt_data_main[i][j];
}
......
......@@ -6,7 +6,7 @@
**
** -----------------------------------------------------------------------------**
**
** ImageDtt.java is free software: you can redistribute it and/or modify
** ImageDttParameters.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
......@@ -103,7 +103,7 @@ public class ImageDttParameters {
public void dialogQuestions(GenericJTabbedDialog gd) {
gd.addCheckbox ("Enable ImageDtt correlation debug layers", this.corr_mode_debug,
"false - return (old) per-coor correlations, true - replace them with more pairs correlation (new)");
"false - return (old) per-coord correlations, true - replace them with more pairs correlation (new)");
gd.addCheckbox ("Replace CM layer with mixed/new poly one", this.mix_corr_poly);
gd.addNumericField("Use poly mode if strength is greater than", this.min_poly_strength, 3,6,"", "AND condition");
gd.addNumericField("Maximal polynomial approximation half-width", this.max_poly_hwidth, 3,6,"pix", "Maximal polynomial approximation half-width (in both directions), Most now are ~2.0");
......
......@@ -76,6 +76,11 @@ public class QuadCLT {
EyesisCorrectionParameters.CLTParameters clt_parameters,
int threadsMax
){
setTiles(clt_parameters,
imp.getWidth()/clt_parameters.transform_size,
imp.getHeight()/clt_parameters.transform_size,
threadsMax);
/*
if (tp == null){
tp = new TileProcessor(imp.getWidth()/clt_parameters.transform_size,
imp.getHeight()/clt_parameters.transform_size,
......@@ -86,8 +91,29 @@ public class QuadCLT {
clt_parameters.max_overexposure, // double maxOverexposure,
threadsMax);
}
*/
}
public void setTiles (
EyesisCorrectionParameters.CLTParameters clt_parameters,
int tilesX,
int tilesY,
int threadsMax
){
if (tp == null){
tp = new TileProcessor(
tilesX,
tilesY,
clt_parameters.transform_size,
clt_parameters.stSize,
clt_parameters.corr_magic_scale,
clt_parameters.grow_disp_trust,
clt_parameters.max_overexposure, // double maxOverexposure,
threadsMax);
}
}
public QuadCLT(
String prefix,
Properties properties,
......
import java.util.ArrayList;
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
......@@ -149,8 +151,8 @@ public class TwoQuadCLT {
EyesisCorrectionParameters.CLTParameters clt_parameters,
EyesisCorrectionParameters.DebayerParameters debayerParameters,
EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CorrectionColorProc.ColorGainsParameters channelGainParameters_main,
CorrectionColorProc.ColorGainsParameters channelGainParameters_aux,
// CorrectionColorProc.ColorGainsParameters channelGainParameters_main,
// CorrectionColorProc.ColorGainsParameters channelGainParameters_aux,
EyesisCorrectionParameters.RGBParameters rgbParameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
......@@ -214,8 +216,8 @@ public class TwoQuadCLT {
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
debayerParameters, // EyesisCorrectionParameters.DebayerParameters debayerParameters,
colorProcParameters, // EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
channelGainParameters_main, // CorrectionColorProc.ColorGainsParameters channelGainParameters_main,
channelGainParameters_aux, // CorrectionColorProc.ColorGainsParameters channelGainParameters_aux,
// channelGainParameters_main, // CorrectionColorProc.ColorGainsParameters channelGainParameters_main,
// channelGainParameters_aux, // CorrectionColorProc.ColorGainsParameters channelGainParameters_aux,
rgbParameters, // EyesisCorrectionParameters.RGBParameters rgbParameters,
scaleExposures_main, // double [] scaleExposures_main, // probably not needed here - restores brightness of the final image
scaleExposures_aux, // double [] scaleExposures_aux, // probably not needed here - restores brightness of the final image
......@@ -254,8 +256,6 @@ public class TwoQuadCLT {
EyesisCorrectionParameters.CLTParameters clt_parameters,
EyesisCorrectionParameters.DebayerParameters debayerParameters,
EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CorrectionColorProc.ColorGainsParameters channelGainParameters_main,
CorrectionColorProc.ColorGainsParameters channelGainParameters_aux,
EyesisCorrectionParameters.RGBParameters rgbParameters,
double [] scaleExposures_main, // probably not needed here - restores brightness of the final image
double [] scaleExposures_aux, // probably not needed here - restores brightness of the final image
......@@ -283,42 +283,15 @@ public class TwoQuadCLT {
results[i].setTitle(results[i].getTitle()+"RAW");
}
if (debugLevel>1) System.out.println("processing: "+path);
double [][][] double_stacks_main = new double [imp_quad_main.length][][];
for (int i = 0; i < double_stacks_main.length; i++){
double_stacks_main[i] = quadCLT_main.eyesisCorrections.bayerToDoubleStack(
imp_quad_main[i], // source Bayer image, linearized, 32-bit (float))
null); // no margins, no oversample
}
double [][][] double_stacks_aux = new double [imp_quad_main.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))
null); // no margins, no oversample
}
ImageDtt image_dtt = new ImageDtt();
for (int i = 0; i < double_stacks_main.length; i++){
for (int j =0 ; j < double_stacks_main[i][0].length; j++){
double_stacks_main[i][2][j]*=0.5; // Scale green 0.5 to compensate more pixels than R,B
}
}
for (int i = 0; i < double_stacks_aux.length; i++){
for (int j =0 ; j < double_stacks_aux[i][0].length; j++){
double_stacks_aux[i][2][j]*=0.5; // Scale green 0.5 to compensate more pixels than R,B
}
}
quadCLT_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);
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,
threadsMax, // maximal number of threads to launch
debugLevel); // final int debugLevel);
// temporary setting up tile task file (one integer per tile, bitmask
// for testing defined for a window, later the tiles to process will be calculated based on previous passes results
......@@ -358,14 +331,17 @@ public class TwoQuadCLT {
double [][] disparity_bimap = new double [ImageDtt.BIDISPARITY_TITLES.length][]; //[0] -residual disparity, [1] - orthogonal (just for debugging) last 4 - max pixel differences
double min_corr_selected = clt_parameters.min_corr;
ImageDtt image_dtt = new ImageDtt();
final double [][][][][][][] clt_bidata = // new double[2][quad][nChn][tilesY][tilesX][][]; // first index - main/aux
image_dtt.clt_bi_quad (
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
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_main, // final double [][][] image_data_main, // first index - number of image in a quad
double_stacks_aux, // final double [][][] image_data_aux, // first index - number of image in a quad
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
// correlation results - combo will be for the correation between two quad cameras
......@@ -537,7 +513,7 @@ public class TwoQuadCLT {
ImageDtt.BIDISPARITY_TITLES);
}
}
if (!batch_mode && !infinity_corr && clt_parameters.corr_show && (debugLevel > -1)){
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"};
for (int i = 0; i< titles.length; i++) titles[i] = ImageDtt.TCORR_TITLES[i];
......@@ -693,6 +669,336 @@ public class TwoQuadCLT {
}
}
}
return results;
}
public double [][][][] getRigImageStacks(
EyesisCorrectionParameters.CLTParameters clt_parameters,
QuadCLT quadCLT_main,
QuadCLT quadCLT_aux,
ImagePlus [] imp_quad_main,
ImagePlus [] imp_quad_aux,
int threadsMax, // maximal number of threads to launch
int debugLevel){
double [][][] double_stacks_main = new double [imp_quad_main.length][][];
for (int i = 0; i < double_stacks_main.length; i++){
double_stacks_main[i] = quadCLT_main.eyesisCorrections.bayerToDoubleStack(
imp_quad_main[i], // source Bayer image, linearized, 32-bit (float))
null); // no margins, no oversample
}
double [][][] double_stacks_aux = new double [imp_quad_main.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))
null); // no margins, no oversample
}
for (int i = 0; i < double_stacks_main.length; i++){
for (int j =0 ; j < double_stacks_main[i][0].length; j++){
double_stacks_main[i][2][j]*=0.5; // Scale green 0.5 to compensate more pixels than R,B
}
}
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
}
}
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;
}
public void processInfinityRigs( // actually there is no sense to process multiple image sets. Combine with other processing?
QuadCLT quadCLT_main,
QuadCLT quadCLT_aux,
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel) throws Exception
{
this.startTime=System.nanoTime();
String [] sourceFiles=quadCLT_main.correctionsParameters.getSourcePaths();
QuadCLT.SetChannels [] set_channels_main = quadCLT_main.setChannels(debugLevel);
QuadCLT.SetChannels [] set_channels_aux = quadCLT_aux.setChannels(debugLevel);
if ((set_channels_main == null) || (set_channels_main.length==0) || (set_channels_aux == null) || (set_channels_aux.length==0)) {
System.out.println("No files to process (of "+sourceFiles.length+")");
return;
}
double [] referenceExposures_main = quadCLT_main.eyesisCorrections.calcReferenceExposures(debugLevel); // multiply each image by this and divide by individual (if not NaN)
double [] referenceExposures_aux = quadCLT_aux.eyesisCorrections.calcReferenceExposures(debugLevel); // multiply each image by this and divide by individual (if not NaN)
for (int nSet = 0; nSet < set_channels_main.length; nSet++){
// check it is the same set for both cameras
if (set_channels_aux.length <= nSet ) {
throw new Exception ("Set naims 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()+"'");
}
int [] channelFiles_main = set_channels_main[nSet].fileNumber();
int [] channelFiles_aux = set_channels_aux[nSet].fileNumber();
boolean [][] saturation_imp_main = (clt_parameters.sat_level > 0.0)? new boolean[channelFiles_main.length][] : null;
boolean [][] saturation_imp_aux = (clt_parameters.sat_level > 0.0)? new boolean[channelFiles_main.length][] : null;
double [] scaleExposures_main = new double[channelFiles_main.length];
double [] scaleExposures_aux = new double[channelFiles_main.length];
ImagePlus [] imp_srcs_main = quadCLT_main.conditionImageSet(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
sourceFiles, // String [] sourceFiles,
set_channels_main[nSet].name(), // String set_name,
referenceExposures_main, // double [] referenceExposures,
channelFiles_main, // int [] channelFiles,
scaleExposures_main, //output // double [] scaleExposures
saturation_imp_main, //output // boolean [][] saturation_imp,
debugLevel); // int debugLevel);
ImagePlus [] imp_srcs_aux = quadCLT_aux.conditionImageSet(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
sourceFiles, // String [] sourceFiles,
set_channels_aux[nSet].name(), // String set_name,
referenceExposures_aux, // double [] referenceExposures,
channelFiles_aux, // int [] channelFiles,
scaleExposures_aux, //output // double [] scaleExposures
saturation_imp_aux, //output // boolean [][] saturation_imp,
debugLevel); // int debugLevel);
// Tempporarily processing individaully with the old code
processInfinityRig(
quadCLT_main, // QuadCLT quadCLT_main,
quadCLT_aux, // QuadCLT quadCLT_aux,
imp_srcs_main, // ImagePlus [] imp_quad_main,
imp_srcs_aux, // ImagePlus [] imp_quad_aux,
saturation_imp_main, // boolean [][] saturation_main, // (near) saturated pixels or null
saturation_imp_aux, // boolean [][] saturation_aux, // (near) saturated pixels or null
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+set_channels_aux.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (quadCLT_aux.eyesisCorrections.stopRequested.get()>0) {
System.out.println("User requested stop");
System.out.println("Processing "+(nSet + 1)+" file sets (of "+set_channels_main.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
return;
}
}
System.out.println("processCLTQuadCorrs(): processing "+(quadCLT_main.getTotalFiles(set_channels_main)+quadCLT_aux.getTotalFiles(set_channels_aux))+" files ("+set_channels_main.length+" file sets) finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
}
public boolean processInfinityRig(
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
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
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,
threadsMax, // maximal number of threads to launch
debugLevel); // final int debugLevel);
final int tilesX = quadCLT_main.tp.getTilesX();
double [][] disparity_bimap = measureInfinityRig(
quadCLT_main, //QuadCLT quadCLT_main, // tiles should be set
quadCLT_aux, //QuadCLT quadCLT_aux,
double_stacks, // double [][][][] double_stacks,
null, // ArrayList<Integer> tileList, // or null
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,
debugLevel); // final int debugLevel);
if (disparity_bimap != null) {
ArrayList<Integer> tileList = selectInfinityTiles(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
disparity_bimap, // double[][] disparity_bimap,
tilesX, // int tilesX,
clt_parameters.rig.rig_mode_debug); // boolean debug
System.out.println("Selected "+tileList.size()+" tiles for infinity correction");
}
// loop here with the same tileList
return true;
}
public double [][] measureInfinityRig(
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){
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;
}
}
// for infinity use disparity of all 0-s;
double [][] disparity_array = new double [quadCLT_main.tp.getTilesY()][quadCLT_main.tp.getTilesX()];
return 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
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
threadsMax, //final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel)
}
public 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
EyesisCorrectionParameters.CLTParameters clt_parameters,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel){
ImageDtt image_dtt = new ImageDtt();
double [][] disparity_bimap = new double [ImageDtt.BIDISPARITY_TITLES.length][]; //[0] -residual disparity, [1] - orthogonal (just for debugging) last 4 - max pixel differences
double min_corr_selected = clt_parameters.min_corr;
image_dtt.clt_bi_quad (
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
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
// 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]
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,
min_corr_selected, // final double min_corr, // 0.02; // minimal correlation value to consider valid
quadCLT_main.getGeometryCorrection(), // final GeometryCorrection geometryCorrection_main,
quadCLT_aux.getGeometryCorrection(), // final GeometryCorrection geometryCorrection_aux,
quadCLT_main.getCLTKernels(), // final double [][][][][][] clt_kernels_main, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
quadCLT_aux.getCLTKernels(), // final double [][][][][][] clt_kernels_aux, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
clt_parameters.corr_magic_scale, // final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
false, // true, // final boolean keep_clt_data,
threadsMax, // final int threadsMax, // maximal number of threads to launch
debugLevel); // final int globalDebugLevel);
return disparity_bimap;
}
ArrayList<Integer> selectInfinityTiles(
EyesisCorrectionParameters.CLTParameters clt_parameters,
double[][] disparity_bimap,
int tilesX,
boolean debug
){
ArrayList<Integer> tilesList = new ArrayList<Integer>();
int numTiles = disparity_bimap[ImageDtt.BI_STR_FULL_INDEX].length;
for (int nTile = 0; nTile < numTiles; nTile++) {
if ((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)&&
(Math.abs(disparity_bimap[ImageDtt.BI_DISP_FULL_INDEX][nTile]) <= clt_parameters.rig.inf_max_disp_main)&&
(Math.abs(disparity_bimap[ImageDtt.BI_ADISP_FULL_INDEX][nTile]) <= clt_parameters.rig.inf_max_disp_aux)&&
(Math.abs(disparity_bimap[ImageDtt.BI_DISP_CROSS_INDEX][nTile]) <= clt_parameters.rig.inf_max_disp_rig)) {
tilesList.add(nTile);
}
}
if (debug) {
String [] titles = {"disparity", "dx","dy","strength"};
double [][] dbg_inf = new double [4][numTiles];
for (int nTile = 0; nTile < numTiles; nTile++){
dbg_inf[0][nTile] = Double.NaN;
dbg_inf[1][nTile] = Double.NaN;
dbg_inf[2][nTile] = Double.NaN;
dbg_inf[3][nTile] = Double.NaN; // 0.0;
}
for (int nTile:tilesList) {
dbg_inf[0][nTile] = disparity_bimap[ImageDtt.BI_DISP_CROSS_INDEX][nTile];
dbg_inf[1][nTile] = disparity_bimap[ImageDtt.BI_DISP_CROSS_DX_INDEX][nTile];
dbg_inf[2][nTile] = disparity_bimap[ImageDtt.BI_DISP_CROSS_DY_INDEX][nTile];
dbg_inf[3][nTile] = disparity_bimap[ImageDtt.BI_STR_CROSS_INDEX][nTile];
}
(new showDoubleFloatArrays()).showArrays(
dbg_inf,
tilesX,
numTiles/tilesX,
true,
"Infinity_selected_data",
titles );
}
//new showDoubleFloatArrays()
return tilesList;
}
}
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