Commit c3ee5b3f authored by Andrey Filippov's avatar Andrey Filippov

Dual max LMA

parent db3deeef
...@@ -74,6 +74,10 @@ import jcuda.nvrtc.nvrtcProgram; ...@@ -74,6 +74,10 @@ import jcuda.nvrtc.nvrtcProgram;
public class GPUTileProcessor { public class GPUTileProcessor {
public static boolean USE_DS_DP = false; // Use Dynamic Shared memory with Dynamic Parallelism (not implemented) public static boolean USE_DS_DP = false; // Use Dynamic Shared memory with Dynamic Parallelism (not implemented)
String LIBRARY_PATH = "/usr/local/cuda/targets/x86_64-linux/lib/libcudadevrt.a"; // linux String LIBRARY_PATH = "/usr/local/cuda/targets/x86_64-linux/lib/libcudadevrt.a"; // linux
// Can be downloaded and twice extracted from
// https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-cudart-dev-11-2_11.2.152-1_amd64.deb
// First deb itself, then data.tar.xz, and it will have usr/local/cuda/targets/x86_64-linux/lib/libcudadevrt.a inside
// Found "cuda-cudart-dev" on https://ubuntu.pkgs.org/
static String GPU_RESOURCE_DIR = "kernels"; static String GPU_RESOURCE_DIR = "kernels";
static String [] GPU_KERNEL_FILES = {"dtt8x8.cuh","TileProcessor.cuh"}; static String [] GPU_KERNEL_FILES = {"dtt8x8.cuh","TileProcessor.cuh"};
// "*" - generated defines, first index - separately compiled unit // "*" - generated defines, first index - separately compiled unit
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3518,6 +3518,7 @@ public class Correlation2d { ...@@ -3518,6 +3518,7 @@ public class Correlation2d {
} }
Corr2dLMA lma = new Corr2dLMA( Corr2dLMA lma = new Corr2dLMA(
corrs.length, corrs.length,
1, // int numMax,
this, // Correlation2d correlation2d, this, // Correlation2d correlation2d,
transform_size, transform_size,
corr_wnd, corr_wnd,
...@@ -3620,6 +3621,7 @@ public class Correlation2d { ...@@ -3620,6 +3621,7 @@ public class Correlation2d {
lma.addSample( // x = 0, y=0 - center lma.addSample( // x = 0, y=0 - center
ntile, // tile ntile, // tile
npair, npair,
0, // int imax, // number of maximum (just a hint)
// fcam, // int fcam, // first camera index // fcam, // int fcam, // first camera index
// scam, // int scam, // second camera index // scam, // int scam, // second camera index
ix, // int x, // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis ix, // int x, // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis
...@@ -3660,12 +3662,13 @@ public class Correlation2d { ...@@ -3660,12 +3662,13 @@ public class Correlation2d {
boolean lmaSuccess = false; boolean lmaSuccess = false;
while (!lmaSuccess) { while (!lmaSuccess) {
boolean OK = lma.initVector( // USED in lwir boolean OK = lma.initVector( // USED in lwir
null, // boolean [] adjust_disparities, // null - adjust all, otherwise - per maximum
imgdtt_params.lma_adjust_wm, // boolean adjust_width, // adjust width of the maximum - lma_adjust_wm imgdtt_params.lma_adjust_wm, // boolean adjust_width, // adjust width of the maximum - lma_adjust_wm
imgdtt_params.lma_adjust_ag, // boolean adjust_scales, // adjust 2D correlation scales - lma_adjust_ag imgdtt_params.lma_adjust_ag, // boolean adjust_scales, // adjust 2D correlation scales - lma_adjust_ag
imgdtt_params.lma_adjust_wy, // boolean adjust_ellipse, // allow non-circular correlation maximums lma_adjust_wy imgdtt_params.lma_adjust_wy, // boolean adjust_ellipse, // allow non-circular correlation maximums lma_adjust_wy
imgdtt_params.lma_adjust_wxy, // boolean adjust_lazyeye_par, // adjust disparity corrections parallel to disparities lma_adjust_wxy imgdtt_params.lma_adjust_wxy, // boolean adjust_lazyeye_par, // adjust disparity corrections parallel to disparities lma_adjust_wxy
imgdtt_params.lma_adjust_ly1, // boolean adjust_lazyeye_ortho, // adjust disparity corrections orthogonal to disparities lma_adjust_ly1 imgdtt_params.lma_adjust_ly1, // boolean adjust_lazyeye_ortho, // adjust disparity corrections orthogonal to disparities lma_adjust_ly1
disp_str, // xcenter_str, // double [][] disp_str, // initial value of disparity/strength/? new double[][][] {disp_str}, // xcenter,
imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width
imgdtt_params.lma_cost_wy, // double cost_lazyeye_par, // cost for each of the non-zero disparity corrections lma_cost_wy imgdtt_params.lma_cost_wy, // double cost_lazyeye_par, // cost for each of the non-zero disparity corrections lma_cost_wy
imgdtt_params.lma_cost_wxy // double cost_lazyeye_odtho // cost for each of the non-zero ortho disparity corrections lma_cost_wxy imgdtt_params.lma_cost_wxy // double cost_lazyeye_odtho // cost for each of the non-zero ortho disparity corrections lma_cost_wxy
...@@ -3746,6 +3749,7 @@ public class Correlation2d { ...@@ -3746,6 +3749,7 @@ public class Correlation2d {
} else { // have to restart LMA initialization } else { // have to restart LMA initialization
lma = new Corr2dLMA( lma = new Corr2dLMA(
corrs.length, corrs.length,
1, // int numMax,
this, // Correlation2d correlation2d, this, // Correlation2d correlation2d,
transform_size, transform_size,
corr_wnd, corr_wnd,
...@@ -3755,12 +3759,14 @@ public class Correlation2d { ...@@ -3755,12 +3759,14 @@ public class Correlation2d {
lma.setSamples(samples); // restore samples lma.setSamples(samples); // restore samples
} }
lma.initVector( // USED in lwir lma.initVector( // USED in lwir
null, // boolean [] adjust_disparities, // null - adjust all, otherwise - per maximum
imgdtt_params.lma_adjust_wm, // boolean adjust_width, // adjust width of the maximum - lma_adjust_wm imgdtt_params.lma_adjust_wm, // boolean adjust_width, // adjust width of the maximum - lma_adjust_wm
imgdtt_params.lma_adjust_ag, // boolean adjust_scales, // adjust 2D correlation scales - lma_adjust_ag imgdtt_params.lma_adjust_ag, // boolean adjust_scales, // adjust 2D correlation scales - lma_adjust_ag
imgdtt_params.lma_adjust_wy, // boolean adjust_ellipse, // allow non-circular correlation maximums lma_adjust_wy imgdtt_params.lma_adjust_wy, // boolean adjust_ellipse, // allow non-circular correlation maximums lma_adjust_wy
true, // imgdtt_params.lma_adjust_wxy, // boolean adjust_lazyeye_par, // adjust disparity corrections parallel to disparities lma_adjust_wxy true, // imgdtt_params.lma_adjust_wxy, // boolean adjust_lazyeye_par, // adjust disparity corrections parallel to disparities lma_adjust_wxy
true, // imgdtt_params.lma_adjust_ly1, // boolean adjust_lazyeye_ortho, // adjust disparity corrections orthogonal to disparities lma_adjust_ly1 true, // imgdtt_params.lma_adjust_ly1, // boolean adjust_lazyeye_ortho, // adjust disparity corrections orthogonal to disparities lma_adjust_ly1
ds, // disp_str, // xcenter_str, // double [][] disp_str, // initial value of disparity/strength/? // ds, // disp_str, // xcenter_str, // double [][] disp_str, // initial value of disparity/strength/?
new double[][][] {ds}, // xcenter,
imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width
imgdtt_params.lma_cost_wy, // double cost_lazyeye_par, // cost for each of the non-zero disparity corrections lma_cost_wy imgdtt_params.lma_cost_wy, // double cost_lazyeye_par, // cost for each of the non-zero disparity corrections lma_cost_wy
imgdtt_params.lma_cost_wxy // double cost_lazyeye_odtho // cost for each of the non-zero ortho disparity corrections lma_cost_wxy imgdtt_params.lma_cost_wxy // double cost_lazyeye_odtho // cost for each of the non-zero ortho disparity corrections lma_cost_wxy
...@@ -3959,6 +3965,7 @@ public class Correlation2d { ...@@ -3959,6 +3965,7 @@ public class Correlation2d {
int corr_size = 2 * transform_size - 1; int corr_size = 2 * transform_size - 1;
Corr2dLMA lma = new Corr2dLMA( Corr2dLMA lma = new Corr2dLMA(
1, 1,
1, // int numMax,
this, // Correlation2d correlation2d, this, // Correlation2d correlation2d,
transform_size, transform_size,
corr_wnd, corr_wnd,
...@@ -4118,6 +4125,7 @@ public class Correlation2d { ...@@ -4118,6 +4125,7 @@ public class Correlation2d {
lma.addSample( // x = 0, y=0 - center lma.addSample( // x = 0, y=0 - center
0, // tile 0, // tile
npair, npair,
0, // int imax, // number of maximum (just a hint)
ix, // int x, // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis ix, // int x, // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis
iy, // int y, // y coordinate (0 - disparity axis) iy, // int y, // y coordinate (0 - disparity axis)
v, // double v, // correlation value at that point v, // double v, // correlation value at that point
...@@ -4193,12 +4201,13 @@ public class Correlation2d { ...@@ -4193,12 +4201,13 @@ public class Correlation2d {
} }
lma.initVector( 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_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_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 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_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 (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
disp_str2_scaled, // xcenter, new double[][][] {disp_str2_scaled}, // xcenter,
imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width 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_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 (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
...@@ -4262,7 +4271,8 @@ public class Correlation2d { ...@@ -4262,7 +4271,8 @@ public class Correlation2d {
if (disp != null) { if (disp != null) {
disp_str2[0] = disp; disp_str2[0] = disp;
lma.initDisparity( // USED in lwir null pointer lma.initDisparity( // USED in lwir null pointer
disp_str2); // double [][] disp_str // initial value of disparity disp_str2, // double [][] disp_str // initial value of disparity
0); // int nmax); //
if (debug_level > 1) { if (debug_level > 1) {
System.out.println("Input data:"); System.out.println("Input data:");
...@@ -4413,15 +4423,7 @@ public class Correlation2d { ...@@ -4413,15 +4423,7 @@ public class Correlation2d {
if (imgdtt_params.lma_sigma > 0) gb = new DoubleGaussianBlur(); if (imgdtt_params.lma_sigma > 0) gb = new DoubleGaussianBlur();
int center = transform_size - 1; int center = transform_size - 1;
int corr_size = 2 * transform_size - 1; int corr_size = 2 * transform_size - 1;
Corr2dLMA lma = new Corr2dLMA( double [][][] pair_offsets0 = getPairsOffsets(
1,
this, // Correlation2d correlation2d,
transform_size,
corr_wnd,
rXY, //double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.lmas_gaussian //boolean gaussian_mode
);
double [][][] pair_offsets0 = lma.getPairsOffsets(
corrs, // double [][] corrs, corrs, // double [][] corrs,
pair_mask, // boolean [] pair_mask, pair_mask, // boolean [] pair_mask,
disp_str_dual, // double [][] disparity_strengths, disp_str_dual, // double [][] disparity_strengths,
...@@ -4429,7 +4431,7 @@ public class Correlation2d { ...@@ -4429,7 +4431,7 @@ public class Correlation2d {
double [][][] own_masks0 = new double [pair_offsets0.length][][]; double [][][] own_masks0 = new double [pair_offsets0.length][][];
double [][][] lma_corr_weights0 = getLmaWeights( double [][][] lma_corr_weights0 = getLmaWeights(
imgdtt_params, // ImageDttParameters imgdtt_params, imgdtt_params, // ImageDttParameters imgdtt_params,
lma, // Corr2dLMA lma, // lma, // Corr2dLMA lma,
imgdtt_params.bimax_lpf_neib, // double lpf_neib, // if >0, add ortho neibs (corners - squared) imgdtt_params.bimax_lpf_neib, // double lpf_neib, // if >0, add ortho neibs (corners - squared)
imgdtt_params.bimax_notch_pwr, // double notch_pwr, // = 4.00; imgdtt_params.bimax_notch_pwr, // double notch_pwr, // = 4.00;
imgdtt_params.bimax_adv_power, // double adv_power, // reduce weight from overlap with adversarial maximum imgdtt_params.bimax_adv_power, // double adv_power, // reduce weight from overlap with adversarial maximum
...@@ -4572,6 +4574,16 @@ public class Correlation2d { ...@@ -4572,6 +4574,16 @@ public class Correlation2d {
if (num_used_pairs < imgdtt_params.bimax_min_num_pairs) { if (num_used_pairs < imgdtt_params.bimax_min_num_pairs) {
return null; return null;
} }
Corr2dLMA lma = new Corr2dLMA(
1,
lma_corr_weights.length, // int numMax,
this, // Correlation2d correlation2d,
transform_size,
corr_wnd,
rXY, //double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.lmas_gaussian //boolean gaussian_mode
);
for (int npair = 0; npair < pair_mask.length; npair++) if ((corrs[npair] != null) && (used_pairs[npair])){ for (int npair = 0; npair < pair_mask.length; npair++) if ((corrs[npair] != null) && (used_pairs[npair])){
for (int nmax = 0; nmax < lma_corr_weights.length; nmax++) { // use same blurred version for all max-es for (int nmax = 0; nmax < lma_corr_weights.length; nmax++) { // use same blurred version for all max-es
for (int i = 1; i < lma_corr_weights[nmax][npair].length; i++) if (lma_corr_weights[nmax][npair][i] > 0.0) { for (int i = 1; i < lma_corr_weights[nmax][npair].length; i++) if (lma_corr_weights[nmax][npair][i] > 0.0) {
...@@ -4582,13 +4594,14 @@ public class Correlation2d { ...@@ -4582,13 +4594,14 @@ public class Correlation2d {
if (vasw_pwr != 0) { if (vasw_pwr != 0) {
w *= Math.pow(Math.abs(v), vasw_pwr); w *= Math.pow(Math.abs(v), vasw_pwr);
} }
lma.addSample( // x = 0, y=0 - center lma.addSample( // x = 0, y=0 - center
0, // tile 0, // tile
npair, npair,
ix, // int x, // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis nmax, // int imax, // number of maximum (just a hint)
iy, // int y, // y coordinate (0 - disparity axis) ix, // int x, // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis
v, // double v, // correlation value at that point iy, // int y, // y coordinate (0 - disparity axis)
w); //double w) // sample weight v, // double v, // correlation value at that point
w); //double w) // sample weight
} }
} }
...@@ -4631,43 +4644,57 @@ public class Correlation2d { ...@@ -4631,43 +4644,57 @@ public class Correlation2d {
corr_size, corr_size,
corr_size, corr_size,
true, true,
"samples_weights"+"_x"+tileX+"_y"+tileY, "samples_weights"+"_x"+tileX+"_y"+tileY+"_nmx"+nmax,
getCorrTitles()); getCorrTitles());
} }
} }
} }
// initially will use just first (selected) maximum, both - whenLMA will be modified to support 3 maximums. // initially will use just first (selected) maximum, both - whenLMA will be modified to support 3 maximums.
double [][] disp_str2 = {disp_str_all[0]}; // temporary // will be calculated/set later double [][][] disp_str2 = new double[disp_str_all.length][1][];// = {disp_str_all[0]}; // temporary // will be calculated/set later
for (int i = 0; i <disp_str_all.length; i++) if (disp_str_all[i] != null){
disp_str2[i][0] = disp_str_all[i];
}
// double [][] disp_str2 = {disp_str_all[0]}; // temporary // will be calculated/set later
boolean lmaSuccess = false; boolean lmaSuccess = false;
int num_lma_retries = 0; // int num_lma_retries = 0;
while (!lmaSuccess) { // When running LMA - first do not touch disparity?
num_lma_retries ++; // debug // int lma_pass = imgdtt_params.bimax_dual_pass? 0 : 1; // pass0 - w/o disparity, pass 1 - with
lma.initVector( boolean [] adjust_disparities = new boolean [disp_str_all.length]; // all false;
boolean needprep = true; //t npass = 0;
for (int npass = (imgdtt_params.bimax_dual_pass? 00 : 1); npass < 2; npass++) { // may break while (!lmaSuccess) {
// num_lma_retries ++; // debug
if (needprep) {
lma.preparePars(
disp_str2, // double [][][] disp_str_all, initial value of disparity [max][tile]{disp, strength}
imgdtt_params.lma_half_width); // double half_width, // A=1/(half_widh)^2 lma_half_width
needprep = false;
lma.setMatrices (disp_dist);
lma.initMatrices (); // should be called after initVector and after setMatrices
lma.initDisparity(disp_str2); // initial value of disparity [max][tile]{disp, strength}
} else {
lma.updateFromVector();
}
if (npass > 0) {
adjust_disparities = null;
}
lma.setParMask( // USED in lwir
adjust_disparities, // 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_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_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 imgdtt_params.lmas_adjust_wy, // boolean adjust_ellipse, // allow non-circular correlation maximums lma_adjust_wy
false, // (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 false, // (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
false, // (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 false, // (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
disp_str2, // xcenter,
imgdtt_params.lma_half_width, // double half_width, // A=1/(half_widh)^2 lma_half_width
0.0, // (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 0.0, // (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
0.0 // (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 0.0); // (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
lma.initDisparity( // USED in lwir null pointer if (debug_level > 0) { // 1) {
disp_str2); // double [][] disp_str // initial value of disparity
if (debug_level > 1) {
System.out.println("Input data:"); System.out.println("Input data:");
lma.printInputDataFx(false); lma.printInputDataFx(false);
lma.printParams(); lma.printParams();
} }
lmaSuccess = lma.runLma( lmaSuccess = lma.runLma(
imgdtt_params.lmas_lambda_initial, // double lambda, // 0.1 imgdtt_params.lmas_lambda_initial, // double lambda, // 0.1
imgdtt_params.lma_lambda_scale_good, // double lambda_scale_good,// 0.5 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_scale_bad, // double lambda_scale_bad, // 8.0
...@@ -4679,14 +4706,12 @@ public class Correlation2d { ...@@ -4679,14 +4706,12 @@ public class Correlation2d {
if (debug_level > -2) { if (debug_level > -2) {
System.out.println("Found bad tile/pair during single (probably wrong initial maximum - try around preliminary? "+lma.getBadTile()); System.out.println("Found bad tile/pair during single (probably wrong initial maximum - try around preliminary? "+lma.getBadTile());
} }
} else {
break;
} }
} }
if (lmaSuccess) { if (lmaSuccess) {
lma.updateFromVector(); lma.updateFromVector();
double [][] dispStr = lma.lmaDisparityStrength( //TODO: add parameter to filter out negative minimums ? double [][][] dispStrs = lma.lmaDisparityStrengths( //TODO: add parameter to filter out negative minimums ?
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
...@@ -4696,20 +4721,25 @@ public class Correlation2d { ...@@ -4696,20 +4721,25 @@ public class Correlation2d {
imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
imgdtt_params.lma_str_offset // convert lma-generated strength to match previous ones - add to result imgdtt_params.lma_str_offset // convert lma-generated strength to match previous ones - add to result
); );
if (dispStr[0][1] <= 0) { for (int nmax = 0; nmax < dispStrs.length; nmax++) if (dispStrs[nmax][0][1] <= 0) {
lmaSuccess = false; lmaSuccess = false;
break;
}
if (!lmaSuccess) {
if (debug_lma_tile != null) { if (debug_lma_tile != null) {
debug_lma_tile[3] = num_lma_retries; // number of wasted attempts // debug_lma_tile[3] = num_lma_retries; // number of wasted attempts
debug_lma_tile[4] = lma.getNumIter(); debug_lma_tile[4] = lma.getNumIter();
} }
} else { } else {
if (debug_level > -2) { if (debug_level > -2) {
System.out.println(String.format("LMA disparity=%8.5f, str=%8.5f", for (int nmax = 0; nmax < dispStrs.length; nmax++) {
dispStr[0][0],dispStr[0][1])); System.out.println(String.format("LMA max-%d: disparity=%8.5f, str=%8.5f",
nmax,dispStrs[nmax][0][0],dispStrs[nmax][0][1]));
}
} }
double [] rms = lma.getRMS(); double [] rms = lma.getRMS();
if (debug_lma_tile != null) { if (debug_lma_tile != null) {
debug_lma_tile[3] = num_lma_retries; // number of wasted attempts // debug_lma_tile[3] = num_lma_retries; // number of wasted attempts
debug_lma_tile[4] = lma.getNumIter(); debug_lma_tile[4] = lma.getNumIter();
debug_lma_tile[5] = rms[1]; // pure rms debug_lma_tile[5] = rms[1]; // pure rms
} }
...@@ -4747,7 +4777,7 @@ public class Correlation2d { ...@@ -4747,7 +4777,7 @@ public class Correlation2d {
} }
} else if (debug_lma_tile != null) { } else if (debug_lma_tile != null) {
debug_lma_tile[3] = num_lma_retries; // number of wasted attempts // debug_lma_tile[3] = num_lma_retries; // number of wasted attempts
} }
return lmaSuccess? lma: null; return lmaSuccess? lma: null;
} }
...@@ -4777,10 +4807,61 @@ public class Correlation2d { ...@@ -4777,10 +4807,61 @@ public class Correlation2d {
} }
} }
/**
* Calculate offsets for multiple disparities, for each defined pair x,y expected offset, assuming only disparity, not lazy eye
* @param corrs - pairs 2D correlations (each in scanline order) - just to determine null/non-null
* @param disparity_strengths - expected {disparity, strength} pairs (e.g. from CM)
* @param disp_dist - per camera disparity matrix as a 1d (linescan order))
* @return array of per-disparity, per pair x,y expected center offset in 2D correlations or nulls for undefined pairs (or null if already set)
*/
public double [][][] getPairsOffsets(
double [][] corrs,
boolean [] pair_mask,
double [][] disparity_strengths,
double [][] disp_dist){ //
double [][][] pairs_offsets = new double [disparity_strengths.length][][];
for (int i = 0; i < pairs_offsets.length; i++) {
pairs_offsets[i] = getPairsOffsets(
corrs, // double [][] corrs,
pair_mask, // boolean [] pair_mask,
disparity_strengths[i][0], // double disparity,
disp_dist); // double [][] disp_dist)
}
return pairs_offsets;
}
/**
* Calculate each defined pair x,y expected offset, assuming only disparity, not lazy eye
* @param corrs - pairs 2D correlations (each in scanline order) - just to determine null/non-null
* @param disparity - expected disparity (e.g. from CM)
* @param disp_dist - per camera disparity matrix as a 1d (linescan order))
* @return per pair x,y expected center offset in 2D correlations or nulls for undefined pairs (or null if already set)
*/
public double [][] getPairsOffsets(
double [][] corrs,
boolean [] pair_mask,
double disparity,
double [][] disp_dist){ //
double [][] xy_offsets = new double [corrs.length][];
Matrix [] m_disp = Corr2dLMA.getMatrices(
disp_dist, // double [][] am_disp,
getNumSensors()); // int num_cams)
for (int pair = 0; pair < xy_offsets.length; pair++) if ((pair < getNumPairs()) && (corrs[pair] != null) && ((pair_mask == null) || pair_mask[pair])){ // OK to calculate for each
int [] fscam = getPair(pair); // returns [first_cam, second_cam]
Matrix mdd_dnd = new Matrix(new double[] {-disparity, 0.0},2);
Matrix xcam_ycam_f = m_disp[fscam[0]].times(mdd_dnd);
Matrix xcam_ycam_s = m_disp[fscam[1]].times(mdd_dnd);
xy_offsets[pair] = xcam_ycam_f.minus(xcam_ycam_s).getColumnPackedCopy();
}
return xy_offsets;
}
public double[][][] getLmaWeights( public double[][][] getLmaWeights(
ImageDttParameters imgdtt_params, ImageDttParameters imgdtt_params,
Corr2dLMA lma, // Corr2dLMA lma,
double lpf_neib, // if >0, add ortho neibs (corners - squared) double lpf_neib, // if >0, add ortho neibs (corners - squared)
double notch_pwr, // = 4.00; double notch_pwr, // = 4.00;
double adv_power, // reduce weight from overlap with adversarial maximum double adv_power, // reduce weight from overlap with adversarial maximum
......
...@@ -2629,9 +2629,9 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2629,9 +2629,9 @@ public class ImageDtt extends ImageDttCPU {
} }
} }
if (debugTile1) { if (debugTile1) {
correlation2d.corrLMA2DualMax( // null pointer Corr2dLMA lma_dual = correlation2d.corrLMA2DualMax( // null pointer
imgdtt_params, // ImageDttParameters imgdtt_params, imgdtt_params, // ImageDttParameters imgdtt_params,
1, // int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG 0, // 3, // 0, // 1, // int combine_mode, // 0 - both, 1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
// imgdtt_params.lmas_LY_single, // false, // boolean adjust_ly, // adjust Lazy Eye // imgdtt_params.lmas_LY_single, // false, // boolean adjust_ly, // adjust Lazy Eye
corr_wnd, // double [][] corr_wnd, // correlation window to save on re-calculation of the window corr_wnd, // double [][] corr_wnd, // correlation window to save on re-calculation of the window
corr_wnd_inv_limited, // corr_wnd_limited, // correlation window, limited not to be smaller than threshold - used for finding max/convex areas (or null) corr_wnd_inv_limited, // corr_wnd_limited, // correlation window, limited not to be smaller than threshold - used for finding max/convex areas (or null)
...@@ -2647,6 +2647,8 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2647,6 +2647,8 @@ public class ImageDtt extends ImageDttCPU {
(debugTile0 ? 1: -2), // int debug_level, (debugTile0 ? 1: -2), // int debug_level,
tileX, // int tileX, // just for debug output tileX, // int tileX, // just for debug output
tileY ); tileY );
System.out.println("clt_process_tl_correlations() corrLMA2DualMax() done, lma_dual="+
((lma_dual== null)? "null": " not null"));
} }
......
...@@ -84,6 +84,7 @@ public class ImageDttParameters { ...@@ -84,6 +84,7 @@ public class ImageDttParameters {
public int bimax_rad_convex_search = 2; // how far from predicted to search for maximums public int bimax_rad_convex_search = 2; // how far from predicted to search for maximums
public int bimax_min_num_samples = 4; // minimal number of samples per pair per maximum public int bimax_min_num_samples = 4; // minimal number of samples per pair per maximum
public int bimax_min_num_pairs = 8; // minimal number of used pairs public int bimax_min_num_pairs = 8; // minimal number of used pairs
public boolean bimax_dual_pass = true; // First pass - do not adjust disparity
//lmamask_ //lmamask_
public boolean lmamask_dbg = false; // show LMA images, exit after single BG public boolean lmamask_dbg = false; // show LMA images, exit after single BG
...@@ -183,7 +184,7 @@ public class ImageDttParameters { ...@@ -183,7 +184,7 @@ public class ImageDttParameters {
public double lma_disp_range = 5.0; // disparity range to combine in one cluster (to mitigate ERS public double lma_disp_range = 5.0; // disparity range to combine in one cluster (to mitigate ERS
// LMA single parameters // LMA single parameters
// public boolean lmas_gaussian = false; // model correlation maximum as a Gaussian (false - as a parabola) // public boolean lmas_gaussian = false; // model correlation maximum as a Gaussian (false - as a parabola)
public int lmas_gaussian = 0; // 0 - parabola, 1 - Gaussian, 2 - limited parabola, 3 - limited squared parabola public int lmas_gaussian = 3; // 0 - parabola, 1 - Gaussian, 2 - limited parabola, 3 - limited squared parabola
public boolean lmas_adjust_wm = true; // used in new for width public boolean lmas_adjust_wm = true; // used in new for width
public boolean lmas_adjust_wy = true; // adjust non-circular public boolean lmas_adjust_wy = true; // adjust non-circular
public boolean lmas_adjust_ag = true; // adjust gains gains public boolean lmas_adjust_ag = true; // adjust gains gains
...@@ -212,7 +213,7 @@ public class ImageDttParameters { ...@@ -212,7 +213,7 @@ public class ImageDttParameters {
public int lma_gaussian = 0; // 0 - parabola, 1 - Gaussian, 2 - limited parabola, 3 - limited squared parabola public int lma_gaussian = 0; // 0 - parabola, 1 - Gaussian, 2 - limited parabola, 3 - limited squared parabola
public boolean lma_second = true; // re-run LMA after removing weak/failed tiles public boolean lma_second = true; // re-run LMA after removing weak/failed tiles
// public boolean lma_second_gaussian = false; // re-run after removing weal/failed in Gaussian mode // public boolean lma_second_gaussian = false; // re-run after removing weal/failed in Gaussian mode
public int lma_second_gaussian = 0; // false; // re-run after removing weal/failed in Gaussian mode public int lma_second_gaussian = 0; // false; // re-run after removing weak/failed in Gaussian mode
public boolean lma_adjust_wm = true; // used in new for width public boolean lma_adjust_wm = true; // used in new for width
public boolean lma_adjust_wy = true; // false; // used in new for ellipse public boolean lma_adjust_wy = true; // false; // used in new for ellipse
public boolean lma_adjust_wxy = true; // used in new for lazy eye adjust parallel-to-disparity correction public boolean lma_adjust_wxy = true; // used in new for lazy eye adjust parallel-to-disparity correction
...@@ -472,6 +473,8 @@ public class ImageDttParameters { ...@@ -472,6 +473,8 @@ public class ImageDttParameters {
"Minimal number of samples per pair per maximum to use this pair by LMA (each of the maximums used)"); "Minimal number of samples per pair per maximum to use this pair by LMA (each of the maximums used)");
gd.addNumericField("Minimal number of used pairs", this.bimax_min_num_pairs, 0, 3, "", gd.addNumericField("Minimal number of used pairs", this.bimax_min_num_pairs, 0, 3, "",
"Do not use LMA if total number of used pairs is lower"); "Do not use LMA if total number of used pairs is lower");
gd.addCheckbox ("Dual-pass LMA", this.bimax_dual_pass,
"First adjust other parameters (keeping disparities), then add disparities");
gd.addMessage("LMA samples filter based on estimated disparity"); gd.addMessage("LMA samples filter based on estimated disparity");
gd.addCheckbox ("Debug LMA", this.lmamask_dbg, gd.addCheckbox ("Debug LMA", this.lmamask_dbg,
...@@ -888,6 +891,7 @@ public class ImageDttParameters { ...@@ -888,6 +891,7 @@ public class ImageDttParameters {
this.bimax_rad_convex_search= (int) gd.getNextNumber(); this.bimax_rad_convex_search= (int) gd.getNextNumber();
this.bimax_min_num_samples= (int) gd.getNextNumber(); this.bimax_min_num_samples= (int) gd.getNextNumber();
this.bimax_min_num_pairs= (int) gd.getNextNumber(); this.bimax_min_num_pairs= (int) gd.getNextNumber();
this.bimax_dual_pass = gd.getNextBoolean();
this.lmamask_dbg = gd.getNextBoolean(); this.lmamask_dbg = gd.getNextBoolean();
this.lmamask_en = gd.getNextBoolean(); this.lmamask_en = gd.getNextBoolean();
...@@ -1114,6 +1118,7 @@ public class ImageDttParameters { ...@@ -1114,6 +1118,7 @@ public class ImageDttParameters {
properties.setProperty(prefix+"bimax_rad_convex_search", this.bimax_rad_convex_search +""); properties.setProperty(prefix+"bimax_rad_convex_search", this.bimax_rad_convex_search +"");
properties.setProperty(prefix+"bimax_min_num_samples", this.bimax_min_num_samples +""); properties.setProperty(prefix+"bimax_min_num_samples", this.bimax_min_num_samples +"");
properties.setProperty(prefix+"bimax_min_num_pairs", this.bimax_min_num_pairs +""); properties.setProperty(prefix+"bimax_min_num_pairs", this.bimax_min_num_pairs +"");
properties.setProperty(prefix+"bimax_dual_pass", this.bimax_dual_pass +"");
properties.setProperty(prefix+"lmamask_dbg", this.lmamask_dbg +""); properties.setProperty(prefix+"lmamask_dbg", this.lmamask_dbg +"");
properties.setProperty(prefix+"lmamask_en", this.lmamask_en +""); properties.setProperty(prefix+"lmamask_en", this.lmamask_en +"");
...@@ -1344,6 +1349,7 @@ public class ImageDttParameters { ...@@ -1344,6 +1349,7 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"bimax_rad_convex_search")!=null) this.bimax_rad_convex_search=Integer.parseInt(properties.getProperty(prefix+"bimax_rad_convex_search")); if (properties.getProperty(prefix+"bimax_rad_convex_search")!=null) this.bimax_rad_convex_search=Integer.parseInt(properties.getProperty(prefix+"bimax_rad_convex_search"));
if (properties.getProperty(prefix+"bimax_min_num_samples")!=null) this.bimax_min_num_samples=Integer.parseInt(properties.getProperty(prefix+"bimax_min_num_samples")); if (properties.getProperty(prefix+"bimax_min_num_samples")!=null) this.bimax_min_num_samples=Integer.parseInt(properties.getProperty(prefix+"bimax_min_num_samples"));
if (properties.getProperty(prefix+"bimax_min_num_pairs")!=null) this.bimax_min_num_pairs=Integer.parseInt(properties.getProperty(prefix+"bimax_min_num_pairs")); if (properties.getProperty(prefix+"bimax_min_num_pairs")!=null) this.bimax_min_num_pairs=Integer.parseInt(properties.getProperty(prefix+"bimax_min_num_pairs"));
if (properties.getProperty(prefix+"bimax_dual_pass")!=null) this.bimax_dual_pass=Boolean.parseBoolean(properties.getProperty(prefix+"bimax_dual_pass"));
if (properties.getProperty(prefix+"lmamask_dbg")!=null) this.lmamask_dbg=Boolean.parseBoolean(properties.getProperty(prefix+"lmamask_dbg")); if (properties.getProperty(prefix+"lmamask_dbg")!=null) this.lmamask_dbg=Boolean.parseBoolean(properties.getProperty(prefix+"lmamask_dbg"));
if (properties.getProperty(prefix+"lmamask_en")!=null) this.lmamask_en=Boolean.parseBoolean(properties.getProperty(prefix+"lmamask_en")); if (properties.getProperty(prefix+"lmamask_en")!=null) this.lmamask_en=Boolean.parseBoolean(properties.getProperty(prefix+"lmamask_en"));
...@@ -1591,6 +1597,7 @@ public class ImageDttParameters { ...@@ -1591,6 +1597,7 @@ public class ImageDttParameters {
idp.bimax_rad_convex_search= this.bimax_rad_convex_search; idp.bimax_rad_convex_search= this.bimax_rad_convex_search;
idp.bimax_min_num_samples= this.bimax_min_num_samples; idp.bimax_min_num_samples= this.bimax_min_num_samples;
idp.bimax_min_num_pairs= this.bimax_min_num_pairs; idp.bimax_min_num_pairs= this.bimax_min_num_pairs;
idp.bimax_dual_pass= this.bimax_dual_pass;
idp.lmamask_dbg= this.lmamask_dbg; idp.lmamask_dbg= this.lmamask_dbg;
idp.lmamask_en= this.lmamask_en; idp.lmamask_en= this.lmamask_en;
......
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