Commit b23f9b92 authored by Andrey Filippov's avatar Andrey Filippov

Implementing LY from scene series

parent 89fbf5c2
...@@ -718,23 +718,16 @@ public class Eyesis_Correction implements PlugIn, ActionListener { ...@@ -718,23 +718,16 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
addButton("DSI histogram", panelClt5, color_report); addButton("DSI histogram", panelClt5, color_report);
addButton("ML recalc", panelClt5, color_process); addButton("ML recalc", panelClt5, color_process);
addButton("Inter Test", panelClt5, color_stop); addButton("Inter Test", panelClt5, color_stop);
// addButton("Aux Inter Test", panelClt5, color_stop);
addButton("Inter Pairs", panelClt5, color_process); addButton("Inter Pairs", panelClt5, color_process);
// addButton("Aux Inter Pairs", panelClt5, color_process);
addButton("Inter LMA", panelClt5, color_stop); addButton("Inter LMA", panelClt5, color_stop);
// addButton("Aux Inter LMA", panelClt5, color_stop);
addButton("Inter Series", panelClt5, color_process); addButton("Inter Series", panelClt5, color_process);
// addButton("Aux Inter Series", panelClt5, color_process);
addButton("Inter Accumulate", panelClt5, color_process); addButton("Inter Accumulate", panelClt5, color_process);
// addButton("Aux Inter Accumulate", panelClt5, color_process);
addButton("Inter Noise", panelClt5, color_process); addButton("Inter Noise", panelClt5, color_process);
// addButton("Inter Noise Aux", panelClt5, color_process);
addButton("Inter Debug Noise", panelClt5, color_report); addButton("Inter Debug Noise", panelClt5, color_report);
// addButton("Batch Noise Aux", panelClt5, color_report);
addButton("Noise Stats", panelClt5, color_process); addButton("Noise Stats", panelClt5, color_process);
// addButton("Noise Stats Aux", panelClt5, color_process);
addButton("Test 1D", panelClt5, color_process); addButton("Test 1D", panelClt5, color_process);
addButton("Colorize Depth", panelClt5, color_process); addButton("Colorize Depth", panelClt5, color_process);
addButton("Main LY series", panelClt5, color_process);
plugInFrame.add(panelClt5); plugInFrame.add(panelClt5);
} }
...@@ -752,6 +745,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener { ...@@ -752,6 +745,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
addButton("Noise Stats Aux", panelClt5aux, color_process); addButton("Noise Stats Aux", panelClt5aux, color_process);
addButton("Colorize Depth", panelClt5aux, color_process); addButton("Colorize Depth", panelClt5aux, color_process);
addButton("Inter Intra ML", panelClt5aux, color_report); addButton("Inter Intra ML", panelClt5aux, color_report);
addButton("Aux LY series", panelClt5aux, color_process);
plugInFrame.add(panelClt5aux); plugInFrame.add(panelClt5aux);
} }
...@@ -5267,6 +5261,21 @@ public class Eyesis_Correction implements PlugIn, ActionListener { ...@@ -5267,6 +5261,21 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
CLT_PARAMETERS.batch_run = true; CLT_PARAMETERS.batch_run = true;
testInterLMA(true); testInterLMA(true);
return; return;
/* ======================================================================== */
} else if (label.equals("Main LY series")) {
DEBUG_LEVEL = MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
CLT_PARAMETERS.batch_run = true;
adjustLYSeries(false);
return;
/* ======================================================================== */
} else if (label.equals("Aux LY series")) {
DEBUG_LEVEL = MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
CLT_PARAMETERS.batch_run = true;
adjustLYSeries(true);
return;
/* ======================================================================== */ /* ======================================================================== */
} else if (label.equals("CLT rig edit")) { } else if (label.equals("CLT rig edit")) {
DEBUG_LEVEL = MASTER_DEBUG_LEVEL; DEBUG_LEVEL = MASTER_DEBUG_LEVEL;
...@@ -7364,6 +7373,101 @@ public class Eyesis_Correction implements PlugIn, ActionListener { ...@@ -7364,6 +7373,101 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
return true; return true;
} }
/**
* Adjust LY using consecutive series of scenes
* @param use_aux
* @return
*/
public boolean adjustLYSeries(boolean use_aux) {
long startTime = System.nanoTime();
// load needed sensor and kernels files
if (!prepareRigImages())
return false;
String configPath = getSaveCongigPath();
if (configPath.equals("ABORT"))
return false;
setAllProperties(PROPERTIES); // batchRig may save properties with the model. Extrinsics will be updated,
// others should be set here
if (DEBUG_LEVEL > -2) {
System.out.println("++++++++++++++ adjustLYSeries ++++++++++++++");
}
if (CLT_PARAMETERS.useGPU()) { // only init GPU instances if it is used
if (GPU_TILE_PROCESSOR == null) {
try {
GPU_TILE_PROCESSOR = new GPUTileProcessor(CORRECTION_PARAMETERS.tile_processor_gpu);
} catch (Exception e) {
System.out.println("Failed to initialize GPU class");
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} // final int debugLevel);
}
if (use_aux) {
if (CLT_PARAMETERS.useGPU(true) && (QUAD_CLT_AUX != null) && (GPU_QUAD_AUX == null)) { // if GPU AUX is
// needed
try {
GPU_QUAD_AUX = new GpuQuad(//
GPU_TILE_PROCESSOR, QUAD_CLT_AUX, CLT_PARAMETERS.gpu_debug_level);
} catch (Exception e) {
System.out.println("Failed to initialize GpuQuad class");
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} // final int debugLevel);
QUAD_CLT_AUX.setGPU(GPU_QUAD_AUX);
}
} else {
if (CLT_PARAMETERS.useGPU(false) && (QUAD_CLT != null) && (GPU_QUAD == null)) { // if GPU main is needed
try {
GPU_QUAD = new GpuQuad(GPU_TILE_PROCESSOR, QUAD_CLT, CLT_PARAMETERS.gpu_debug_level);
} catch (Exception e) {
System.out.println("Failed to initialize GpuQuad class");
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} // final int debugLevel);
QUAD_CLT.setGPU(GPU_QUAD);
}
}
}
QuadCLT quadCLT = use_aux ? QUAD_CLT_AUX : QUAD_CLT;
ColorProcParameters colorProcParameters = use_aux ? COLOR_PROC_PARAMETERS_AUX : COLOR_PROC_PARAMETERS;
try {
TWO_QUAD_CLT.adjustLYSeries(
quadCLT, // QUAD_CLT, // QuadCLT quadCLT_main,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, // EyesisCorrectionParameters.DebayerParameters debayerParameters,
colorProcParameters, // COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters
// colorProcParameters,
CHANNEL_GAINS_PARAMETERS, // CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, // EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters
// equirectangularParameters,
PROPERTIES, // Properties properties,
true, // false, // boolean reset_from_extrinsics,
THREADS_MAX, // final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, // final boolean updateStatus,
DEBUG_LEVEL);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // final int debugLevel);
if (configPath != null) {
saveTimestampedProperties( // save config again
configPath, // full path or null
null, // use as default directory if path==null
true, PROPERTIES);
}
System.out.println("adjustLYSeries(): Processing finished at "
+ IJ.d2s(0.000000001 * (System.nanoTime() - startTime), 3) + " sec, --- Free memory="
+ Runtime.getRuntime().freeMemory() + " (of " + Runtime.getRuntime().totalMemory() + ")");
return true;
}
public boolean test1d() { public boolean test1d() {
Clt1d clt1d = new Clt1d(CLT_PARAMETERS.transform_size); // CLT_PARAMETERS Clt1d clt1d = new Clt1d(CLT_PARAMETERS.transform_size); // CLT_PARAMETERS
clt1d.test1d(CLT_PARAMETERS); clt1d.test1d(CLT_PARAMETERS);
......
...@@ -34,10 +34,11 @@ public class CLTPass3d{ ...@@ -34,10 +34,11 @@ public class CLTPass3d{
public int [][] tile_op; // what was done in the current pass public int [][] tile_op; // what was done in the current pass
private double [][] disparity_sav; // saved disparity private double [][] disparity_sav; // saved disparity
private int [][] tile_op_sav; // saved tile_op private int [][] tile_op_sav; // saved tile_op
public double [][] disparity_map = null; // add 4 layers - worst difference for the port public double [][] disparity_map = null; // add 4 layers - worst difference for the port
public double [][] lazy_eye_data = null; public double [][] lazy_eye_data = null;
public int lma_cluster_size = -1; public int lma_cluster_size = -1;
public boolean [] lazy_eye_force_disparity = null; public boolean [] lazy_eye_force_disparity = null;
public int [] num_tile_max = null; // number of maximums in a tile
double [] calc_disparity = null; // composite disparity, calculated from "disparity", and "disparity_map" fields double [] calc_disparity = null; // composite disparity, calculated from "disparity", and "disparity_map" fields
...@@ -361,6 +362,20 @@ public class CLTPass3d{ ...@@ -361,6 +362,20 @@ public class CLTPass3d{
public boolean [] getSelected(){ public boolean [] getSelected(){
return selected; return selected;
} }
public boolean [] getSelectedOrTileOp(){ // to use instead of getSelected if it is null
if (selected != null) return selected;
if (tile_op== null) return null;
boolean [] to_selected = new boolean [tile_op.length * tile_op[0].length];
int indx = 0;
for (int ty = 0; ty < tile_op.length; ty++) {
for (int tx = 0; tx < tile_op[ty].length; tx++) {
to_selected[indx++] = tile_op[ty][tx] != 0;
}
}
return to_selected;
}
public boolean [] getBorderTiles(){ public boolean [] getBorderTiles(){
return this.border_tiles; return this.border_tiles;
...@@ -646,6 +661,19 @@ public class CLTPass3d{ ...@@ -646,6 +661,19 @@ public class CLTPass3d{
} }
return disparityLMA; return disparityLMA;
} }
public int [] getNumTileMax() {
if (num_tile_max == null) {
if (disparity_map[ImageDtt.DISPARITY_VARIATIONS_INDEX] == null) {
return null;
}
num_tile_max = new int [disparity_map[ImageDtt.DISPARITY_VARIATIONS_INDEX].length];
for (int i = 0; i < num_tile_max.length; i++) {
///https://stackoverflow.com/questions/6341896/cast-int-to-double-then-back-to-int-in-java
num_tile_max[i] = (int) disparity_map[ImageDtt.DISPARITY_VARIATIONS_INDEX][i];
}
}
return num_tile_max;
}
public double getDisprityHor(int nt) { public double getDisprityHor(int nt) {
return (disparity_map[ImageDtt.DISPARITY_INDEX_HOR] == null) ? Double.NaN : disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt]; return (disparity_map[ImageDtt.DISPARITY_INDEX_HOR] == null) ? Double.NaN : disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt];
......
...@@ -3989,6 +3989,24 @@ public class Correlation2d { ...@@ -3989,6 +3989,24 @@ public class Correlation2d {
double [][] pair_offsets = null; double [][] pair_offsets = null;
/// if (imgdtt_params.lmamask_en && (disp_str != null)) { /// if (imgdtt_params.lmamask_en && (disp_str != null)) {
if (disp_str != null) { if (disp_str != null) {
// 04/22/2022 - trying to get m_disp - it was null
lma.initVector(
null, // boolean [] adjust_disparities, // null - adjust all, otherwise - per maximum
imgdtt_params.lmas_adjust_wm, // boolean adjust_width, // adjust width of the maximum - lma_adjust_wm
imgdtt_params.lmas_adjust_ag, // boolean adjust_scales, // adjust 2D correlation scales - lma_adjust_ag
imgdtt_params.lmas_adjust_wy, // boolean adjust_ellipse, // allow non-circular correlation maximums lma_adjust_wy
(adjust_ly ? imgdtt_params.lma_adjust_wxy : false), //imgdtt_params.lma_adjust_wxy, // boolean adjust_lazyeye_par, // adjust disparity corrections parallel to disparities lma_adjust_wxy
(adjust_ly ? imgdtt_params.lma_adjust_ly1: false), // imgdtt_params.lma_adjust_ly1, // boolean adjust_lazyeye_ortho, // adjust disparity corrections orthogonal to disparities lma_adjust_ly1
new double[][][] {{disp_str}}, // disp_str2_scaled}, // xcenter,
imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width
(adjust_ly ? imgdtt_params.lma_cost_wy : 0.0), // imgdtt_params.lma_cost_wy, // double cost_lazyeye_par, // cost for each of the non-zero disparity corrections lma_cost_wy
(adjust_ly ? imgdtt_params.lma_cost_wxy : 0.0) //imgdtt_params.lma_cost_wxy // double cost_lazyeye_odtho // cost for each of the non-zero ortho disparity corrections lma_cost_wxy
);
lma.setMatrices(disp_dist);
lma.initMatrices(); // should be called after initVector and after setMatrices
// End of 04/22/2022 - trying to get m_disp - it was null
pair_offsets = lma.getPairsOffsets( pair_offsets = lma.getPairsOffsets(
corrs, // double [][] corrs, corrs, // double [][] corrs,
pair_mask, // boolean [] pair_mask, pair_mask, // boolean [] pair_mask,
...@@ -4599,7 +4617,7 @@ public class Correlation2d { ...@@ -4599,7 +4617,7 @@ public class Correlation2d {
lma_corr_weights = lma_corr_weights0; lma_corr_weights = lma_corr_weights0;
disp_str_all = disp_str_dual; disp_str_all = disp_str_dual;
own_masks = own_masks0; own_masks = own_masks0;
common_scale = new boolean[] {imgdtt_params.bimax_common_fg}; common_scale = new boolean[] {imgdtt_params.bimax_common_fg};
} else { // only 2 max are supported } else { // only 2 max are supported
if (lma_corr_weights0.length > 2) { if (lma_corr_weights0.length > 2) {
System.out.println("corrLMA2DualMax(): Only 2 correlation maximums are currently supported, all but 2 strongest are discarded"); System.out.println("corrLMA2DualMax(): Only 2 correlation maximums are currently supported, all but 2 strongest are discarded");
...@@ -5390,7 +5408,7 @@ public class Correlation2d { ...@@ -5390,7 +5408,7 @@ public class Correlation2d {
double [][] corrs, double [][] corrs,
double [][] weights){ double [][] weights){
double [][] xy_offsets_pairs = new double[corrs.length][]; // double [][] xy_offsets_pairs = new double[corrs.length][]; //
for (int np = 0; np < corrs.length; np++) if (corrs[np]!= null) { for (int np = 0; np < corrs.length; np++) if ((corrs[np]!= null) && (weights[np]!= null)) {
double [] wcorr = new double [corrs[np].length]; double [] wcorr = new double [corrs[np].length];
double pair_weights = 0.0; double pair_weights = 0.0;
for (int i = 0; i < wcorr.length; i++) if (weights[np][i] > 0.0){ for (int i = 0; i < wcorr.length; i++) if (weights[np][i] > 0.0){
......
...@@ -258,7 +258,7 @@ public class ImageDttParameters { ...@@ -258,7 +258,7 @@ public class ImageDttParameters {
public int lma_num_iter = 10; // public int lma_num_iter = 10; //
// Filtering and strength calculation // Filtering and strength calculation
public boolean lma_multi_cons = true; // false - run multi-tile LMA on all tiles, true - average each pare over all tiles public boolean lma_multi_cons = true; // false - run multi-tile LMA on all tiles, true - average each pair over all tiles
public double lma_max_rel_rms = 0.25; // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) public double lma_max_rel_rms = 0.25; // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
public double lma_min_strength = 1.0; // minimal composite strength (sqrt(average amp squared over absolute RMS) public double lma_min_strength = 1.0; // minimal composite strength (sqrt(average amp squared over absolute RMS)
......
...@@ -5323,38 +5323,6 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -5323,38 +5323,6 @@ public class QuadCLT extends QuadCLTCPU {
// use new, LMA-based mismatch calculation // use new, LMA-based mismatch calculation
double [][] lazy_eye_data = null; double [][] lazy_eye_data = null;
if ((gpuQuad == null) || !(isAux()?clt_parameters.gpu_use_aux_adjust : clt_parameters.gpu_use_main_adjust)) { // CPU if ((gpuQuad == null) || !(isAux()?clt_parameters.gpu_use_aux_adjust : clt_parameters.gpu_use_main_adjust)) { // CPU
/*
lazy_eye_data = image_dtt.cltMeasureLazyEye ( // returns d,s lazy eye parameters
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
image_data, // final double [][][] imade_data, // first index - number of image in a quad
saturation_imp, // boolean [][] saturation_imp, // (near) saturated pixels or null
null, // final double [][] clt_mismatch, // [12][tilesY * tilesX] // ***** transpose unapplied ***** ?. null - do not calculate
// values in the "main" directions have disparity (*_CM) subtracted, in the perpendicular - as is
null, // disparity_map, // [12][tp.tilesY * tp.tilesX]
tilesX * image_dtt.transform_size, // imp_quad[0].getWidth(), // final int width,
clt_parameters.getFatZero(isMonochrome()), // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
clt_parameters.corr_red,
clt_parameters.corr_blue,
clt_parameters.getCorrSigma(image_dtt.isMonochrome()),
min_corr_selected, // 0.0001; // minimal correlation value to consider valid
geometryCorrection, // final GeometryCorrection geometryCorrection,
null, // final GeometryCorrection geometryCorrection_main, // if not null correct this camera (aux) to the coordinates of the main
clt_kernels, // final double [][][][][][] clt_kernels, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
clt_parameters.kernel_step,
// image_dtt.transform_size,
clt_parameters.clt_window,
shiftXY, //
disparity_corr, // final double disparity_corr, // disparity at infinity
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing
clt_parameters.shift_y, // final int shiftY, // shift image vertically (positive - down)
clt_parameters.tileStep, // final int tileStep, // process tileStep x tileStep cluster of tiles when adjusting lazy eye parameters
clt_parameters.tileX, // final int debug_tileX,
clt_parameters.tileY, // final int debug_tileY,
threadsMax,
debugLevel - 2);
*/
lazy_eye_data = image_dtt.cltMeasureLazyEye ( // returns d,s lazy eye parameters lazy_eye_data = image_dtt.cltMeasureLazyEye ( // returns d,s lazy eye parameters
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
tile_op, // final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile tile_op, // final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
......
...@@ -101,8 +101,8 @@ public class TileNeibs{ ...@@ -101,8 +101,8 @@ public class TileNeibs{
/** /**
* Get 2d element index after step N, NE, ... NW. Returns -1 if leaving array * Get 2d element index after step N, NE, ... NW. Returns -1 if leaving array
* @param indx start index * @param indx start index
* @param dx offsett in x direction * @param dx offset in x direction
* @param dy offsett in y direction * @param dy offset in y direction
* @return new index or -1 if leaving * @return new index or -1 if leaving
*/ */
int getNeibIndex(int indx, int dx, int dy) { int getNeibIndex(int indx, int dx, int dy) {
......
...@@ -4892,7 +4892,7 @@ ImageDtt.startAndJoin(threads); ...@@ -4892,7 +4892,7 @@ ImageDtt.startAndJoin(threads);
} }
public void growTiles( public static void growTiles(
int grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more int grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
boolean [] tiles, boolean [] tiles,
boolean [] prohibit, boolean [] prohibit,
......
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