Commit ba6fb0e3 authored by Andrey Filippov's avatar Andrey Filippov

working on large cluster in low-contarst (clouds in the sky)

parent 08bccd0d
......@@ -24,6 +24,7 @@ public class CLTParameters {
public double shift_x = 0.0;
public double shift_y = 0.0;
public int tileStep = 4; // process tileStep x tileStep cluster of tiles when adjusting lazy eye parameters
public int super_radius = 2; // Consolidate multiple clusterts for low-contrast infinity (clouds in the sky) 0 - none, 1 - 3x3, 2 - 5x5,
public int iclt_mask = 15; // which transforms to combine
public int tileX = -258; // number of kernel tile (0..163)
public int tileY = 133; // number of kernel tile (0..122)
......@@ -899,6 +900,7 @@ public class CLTParameters {
properties.setProperty(prefix+"shift_x", this.shift_x+"");
properties.setProperty(prefix+"shift_y", this.shift_y+"");
properties.setProperty(prefix+"tileStep", this.tileStep+"");
properties.setProperty(prefix+"tileSizeBg", this.super_radius+"");
properties.setProperty(prefix+"iclt_mask", this.iclt_mask+"");
properties.setProperty(prefix+"tileX", this.tileX+"");
properties.setProperty(prefix+"tileY", this.tileY+"");
......@@ -1668,6 +1670,7 @@ public class CLTParameters {
if (properties.getProperty(prefix+"shift_y")!=null) this.shift_y=Double.parseDouble(properties.getProperty(prefix+"shift_y"));
if (properties.getProperty(prefix+"tileStep")!=null) this.tileStep=Integer.parseInt(properties.getProperty(prefix+"tileStep"));
if (properties.getProperty(prefix+"tileSizeBg")!=null) this.super_radius=Integer.parseInt(properties.getProperty(prefix+"tileSizeBg"));
if (properties.getProperty(prefix+"iclt_mask")!=null) this.iclt_mask=Integer.parseInt(properties.getProperty(prefix+"iclt_mask"));
if (properties.getProperty(prefix+"tileX")!=null) this.tileX=Integer.parseInt(properties.getProperty(prefix+"tileX"));
if (properties.getProperty(prefix+"tileY")!=null) this.tileY=Integer.parseInt(properties.getProperty(prefix+"tileY"));
......@@ -2456,6 +2459,8 @@ public class CLTParameters {
gd.addNumericField("Lazy eye cluster size", this.tileStep, 0, 6, "tiles",
"Process tileStep x tileStep cluster of tiles when adjusting lazy eye parameters");
gd.addNumericField("Consolidate multiple clusterts around given for low-contrast infinity", this.super_radius, 0, 6, "clusters",
"e.g. for clouds in tghe sky 0 - none, 1 - 3x3, 2 - 5x5");
gd.addNumericField("Bit mask - which of 4 transforms to combine after iclt", this.iclt_mask, 0);
gd.addNumericField("Tile X to extract (0..163)", this.tileX, 0);
gd.addNumericField("Tile Y to extract (0..122)", this.tileY, 0);
......@@ -3392,6 +3397,7 @@ public class CLTParameters {
this.shift_y = gd.getNextNumber();
this.tileStep= (int) gd.getNextNumber();
this.super_radius= (int) gd.getNextNumber();
this.iclt_mask= (int) gd.getNextNumber();
this.tileX= (int) gd.getNextNumber();
this.tileY= (int) gd.getNextNumber();
......
......@@ -631,6 +631,7 @@ private Panel panel1,
addButton("CLT disparity scan", panelClt2, color_conf_process);
addButton("CLT reset fine corr", panelClt2, color_stop);
addButton("CLT reset extrinsic corr", panelClt2, color_stop);
addButton("ERS reset", panelClt2, color_stop);
addButton("CLT show geometry", panelClt2, color_configure);
addButton("CLT show fine corr", panelClt2, color_report);
addButton("CLT apply fine corr", panelClt2, color_process);
......@@ -711,6 +712,7 @@ private Panel panel1,
addButton("LWIR_TEST", panelClt_GPU, color_conf_process);
addButton("LWIR_ACQUIRE", panelClt_GPU, color_conf_process);
addButton("ERS reset", panelClt2, color_stop);
addButton("IMU main", panelClt_GPU, color_conf_process);
addButton("ERS main", panelClt_GPU, color_process);
addButton("IMU aux", panelClt_GPU, color_conf_process_aux);
......@@ -4559,6 +4561,21 @@ private Panel panel1,
}
QUAD_CLT.resetExtrinsicCorr(CLT_PARAMETERS);
return;
} else if (label.equals("ERS reset")) {
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
QuadCLT.PREFIX,
PROPERTIES,
EYESIS_CORRECTIONS,
CORRECTION_PARAMETERS);
if (DEBUG_LEVEL > 0){
System.out.println("Created new QuadCLT instance, will need to read CLT kernels");
}
}
QUAD_CLT.resetExtrinsicCorr(CLT_PARAMETERS);
return;
} else if (label.equals("CLT show geometry")) {
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
......
......@@ -1647,14 +1647,7 @@ public class GPUTileProcessor {
IJ.showMessage("Error", "No GPU kernel: GPU_CALCULATE_TILES_OFFSETS_kernel");
return;
}
if (gpu_debug_level > -1) {
System.out.println("num_task_tiles="+num_task_tiles);
}
// kernel parameters: pointer to pointers
// int [] GridFullWarps = {(num_task_tiles + 2 * TILES_PER_BLOCK_GEOM - 1)/TILES_PER_BLOCK_GEOM, 1, 1}; // round up
// int [] ThreadsFullWarps = {num_cams, TILES_PER_BLOCK_GEOM, 1}; // 4,8,1
int [] GridFullWarps = {1, 1, 1}; // round up
int [] GridFullWarps = {1, 1, 1};
int [] ThreadsFullWarps = {1, 1, 1}; // 4,8,1
Pointer kernelParameters = Pointer.to(
Pointer.to(gpu_tasks), // struct tp_task * gpu_tasks,
......@@ -1671,7 +1664,7 @@ public class GPUTileProcessor {
kernelParameters, null); // Kernel- and extra parameters
cuCtxSynchronize(); // remove later
if (gpu_debug_level > -1) {
System.out.println("======execSetTilesOffsets()");
System.out.println("======execSetTilesOffsets(), num_task_tiles="+num_task_tiles);
}
}
......
......@@ -1460,10 +1460,12 @@ public class Corr2dLMA {
return rslt;
}
public double [][] lmaDisparityStrength(
public double [][] lmaDisparityStrength( // restored from git
double lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
double lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
double lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
double lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
double lma_max_area, // maximal half-area (if > 0.0)
double lma_str_scale, // convert lma-generated strength to match previous ones - scale
double lma_str_offset // convert lma-generated strength to match previous ones - add to result
......@@ -1506,6 +1508,179 @@ public class Corr2dLMA {
return ds;
}
public double [][] lmaDisparityStrength0(
double lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
double lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
double lma_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
double lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
double lma_max_area, // maximal half-area (if > 0.0)
double lma_str_scale, // convert lma-generated strength to match previous ones - scale
double lma_str_offset // convert lma-generated strength to match previous ones - add to result
){
double [][] ds = new double[numTiles][2];
double [] rms = getRmsTile();
double [][] maxmin_amp = getMaxMinAmpTile();
double [][] abc = getABCTile();
for (int tile = 0; tile < numTiles; tile++) {
ds[tile][0] = Double.NaN;
if (Double.isNaN(maxmin_amp[tile][0])) {
continue;
}
double avg = 0.5*(maxmin_amp[tile][0]+maxmin_amp[tile][1]);
double rrms = rms[tile]/avg;
if (((lma_max_rel_rms > 0.0) && (rrms > lma_max_rel_rms)) ||
(Math.max(abc[tile][0], abc[tile][2]) < lma_min_max_ac)
// || (Math.min(abc[tile][0], abc[tile][2]) < lma_min_min_ac)
) {
continue;
}
if (lma_max_area > 0) {
if ((abc[tile][0] > 0.0) && (abc[tile][2] > 0.0)) {
// double area_old = 1.0/abc[tile][0] + 1.0/abc[tile][2]; // area of a maximum
double area = 1.0/Math.sqrt(abc[tile][0] * abc[tile][2]);
if (area > lma_max_area) {
continue; // too wide maximum
}
} else {
continue; // not a maximum
}
}
double strength = Math.sqrt(avg/rrms);
double disparity = -all_pars[DISP_INDEX + tile*TILE_PARAMS];
if ((strength < lma_min_strength) || Double.isNaN(disparity)) {
continue;
}
// strength = Math.sqrt(strength * Math.sqrt(abc[tile][0] * abc[tile][2])); // / area ); // new strength
ds[tile][0] = disparity;
ds[tile][1] = (strength * lma_str_scale) + lma_str_offset;
}
return ds;
}
public double [][] lmaDisparityStrengthLY(
double lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
double lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
double lma_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
double lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
double lma_max_area, // maximal half-area (if > 0.0)
double lma_str_scale, // convert lma-generated strength to match previous ones - scale
double lma_str_offset // convert lma-generated strength to match previous ones - add to result
){
double [][] ds = new double[numTiles][2];
double [] rms = getRmsTile();
double [][] maxmin_amp = getMaxMinAmpTile();
double [][] abc = getABCTile();
for (int tile = 0; tile < numTiles; tile++) {
ds[tile][0] = Double.NaN;
if (Double.isNaN(maxmin_amp[tile][0])) {
continue;
}
double avg = 0.5*(maxmin_amp[tile][0]+maxmin_amp[tile][1]);
double rrms = rms[tile]/avg;
if (((lma_max_rel_rms > 0.0) && (rrms > lma_max_rel_rms)) ||
(Math.max(abc[tile][0], abc[tile][2]) < lma_min_max_ac) ||
(Math.min(abc[tile][0], abc[tile][2]) < lma_min_min_ac)) {
continue;
}
if (lma_max_area > 0) {
if ((abc[tile][0] > 0.0) && (abc[tile][2] > 0.0)) {
// double area_old = 1.0/abc[tile][0] + 1.0/abc[tile][2]; // area of a maximum
double area = 1.0/Math.sqrt(abc[tile][0] * abc[tile][2]);
if (area > lma_max_area) {
continue; // too wide maximum
}
} else {
continue; // not a maximum
}
}
double strength = Math.sqrt(avg/rrms);
double disparity = -all_pars[DISP_INDEX + tile*TILE_PARAMS];
if ((strength < lma_min_strength) || Double.isNaN(disparity)) {
continue;
}
strength = Math.sqrt(strength * Math.sqrt(abc[tile][0] * abc[tile][2])); // / area ); // new strength
ds[tile][0] = disparity;
ds[tile][1] = (strength * lma_str_scale) + lma_str_offset;
}
return ds;
}
public double [][] lmaGetExtendedStats(
double lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
double lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
double lma_min_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
double lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
double lma_max_area, // maximal half-area (if > 0.0)
double lma_str_scale, // convert lma-generated strength to match previous ones - scale
double lma_str_offset // convert lma-generated strength to match previous ones - add to result
){
// double [][] ds = new double[numTiles][2];
double [][] ext_stats = new double[numTiles][11];
double [] rms = getRmsTile();
double [][] maxmin_amp = getMaxMinAmpTile();
double [][] abc = getABCTile();
for (int tile = 0; tile < numTiles; tile++) {
if (Double.isNaN(maxmin_amp[tile][0])) {
if (ext_stats[tile][10] == 0) ext_stats[tile][10] = 1;
}
ext_stats[tile][0] = maxmin_amp[tile][0];
double avg = 0.5*(maxmin_amp[tile][0]+maxmin_amp[tile][1]);
double rrms = rms[tile]/avg;
ext_stats[tile][1] = avg;
ext_stats[tile][2] = rrms; // -lma_max_rel_rms;
// ext_stats[tile][3] = Math.max(abc[tile][0], abc[tile][2])-lma_min_ac;
if (((lma_max_rel_rms > 0.0) && (rrms > lma_max_rel_rms)) ||
(Math.max(abc[tile][0], abc[tile][2]) < lma_min_max_ac) ||
(Math.min(abc[tile][0], abc[tile][2]) < lma_min_min_ac)) {
if (ext_stats[tile][10] == 0) ext_stats[tile][10] = 2;
// continue;
}
double area = Double.NaN;
double area_old = Double.NaN;
if (lma_max_area > 0) {
ext_stats[tile][5] = abc[tile][0];
ext_stats[tile][6] = abc[tile][2];
if ((abc[tile][0] > 0.0) && (abc[tile][2] > 0.0)) {
area_old = 1.0/abc[tile][0] + 1.0/abc[tile][2]; // area of a maximum
area = 1.0/Math.sqrt(abc[tile][0] * abc[tile][2]);
if (area > lma_max_area) {
if (ext_stats[tile][10] == 0) ext_stats[tile][10] = 3;
// continue; // too wide maximum
}
} else {
if (ext_stats[tile][10] == 0) ext_stats[tile][10] = 4;
// continue; // not a maximum
}
ext_stats[tile][7] = 1.0/area; // area-lma_max_area;
ext_stats[tile][4] = 1.0/area_old;
}
double strength = Math.sqrt(avg/rrms);
ext_stats[tile][9] = (strength * lma_str_scale) + lma_str_offset;
ext_stats[tile][3] = Math.sqrt(strength / area ); // new strength
double disparity = -all_pars[DISP_INDEX + tile*TILE_PARAMS];
if ((strength < lma_min_strength) || Double.isNaN(disparity)) {
if (ext_stats[tile][10] == 0) ext_stats[tile][10] = 5;
continue;
}
ext_stats[tile][8] = -all_pars[DISP_INDEX + tile*TILE_PARAMS];
if (ext_stats[tile][10] == 0) ext_stats[tile][10] = 6;
}
return ext_stats;
}
// ext_stats[tile][3] = Math.max(abc[tile][0], abc[tile][2])-lma_min_ac;
public double [][] getDdNd(){ // this.all_pars should be current
double [][] ddnd = new double [NUM_CAMS][2];
for (int nc = 0; nc < NUM_CAMS; nc++) {
......
......@@ -2449,6 +2449,7 @@ public class Correlation2d {
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
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
......@@ -2547,6 +2548,7 @@ public class Correlation2d {
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
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
......@@ -2842,6 +2844,7 @@ public class Correlation2d {
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_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
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
......
......@@ -151,6 +151,48 @@ public class ExtrinsicAdjustment {
titles); //ExtrinsicAdjustment.DATA_TITLES);
}
public static void showLYInput(
double[][] data,
String title,
int clustersX,
int clustersY) {
int clusters = clustersX * clustersY;
double [][] pixels = new double [ExtrinsicAdjustment.INDX_LENGTH+3][clusters];
String [] titles = new String[ExtrinsicAdjustment.INDX_LENGTH+3];
for (int i = 0; i < ExtrinsicAdjustment.INDX_LENGTH; i++) {
titles[i] = ExtrinsicAdjustment.DATA_TITLES[i];
}
titles[ExtrinsicAdjustment.INDX_LENGTH+0]="dx-sum";
titles[ExtrinsicAdjustment.INDX_LENGTH+1]="dy_sum";
titles[ExtrinsicAdjustment.INDX_LENGTH+2]="dd_sum";
for (int cluster = 0; cluster < clusters; cluster++) {
if (data[cluster] != null) {
for (int c = 0; c < data[cluster].length; c++) {
pixels[c][cluster] = data[cluster][c];
}
for (int i = 0;i <4; i++) {
pixels[ExtrinsicAdjustment.INDX_LENGTH+0][cluster] += 0.25 * data[cluster][ExtrinsicAdjustment.INDX_X0 + 2 * i];
pixels[ExtrinsicAdjustment.INDX_LENGTH+1][cluster] += 0.25 * data[cluster][ExtrinsicAdjustment.INDX_X0 + 2 * i + 1];
pixels[ExtrinsicAdjustment.INDX_LENGTH+2][cluster] += 0.25 * data[cluster][ExtrinsicAdjustment.INDX_DD0 + i];
}
} else {
for (int c = 0; c < pixels.length; c++) {
// pixels[c][cluster] = (c == ExtrinsicAdjustment.INDX_STRENGTH)? 0.0: Double.NaN;
pixels[c][cluster] = Double.NaN;
}
}
}
(new ShowDoubleFloatArrays()).showArrays(
pixels,
clustersX,
clustersY,
true,
title,
titles); //ExtrinsicAdjustment.DATA_TITLES);
}
private void showX0Y0(double [][] xy0, String title) {
String [] titles = {"xnd-0","ynd-0","xnd-1","ynd-1","xnd-2","ynd-2","xnd-3","ynd-3"};
int clusters = clustersX * clustersY;
......@@ -215,8 +257,10 @@ public class ExtrinsicAdjustment {
this.force_disparity = force_disparity_in;
boolean dbg_images = debugLevel > 0; // 2; // -3; // 2; // 1;
weight_window = getWeightWindow(marg_fract);
double rad_to_hdiag = 0.8;
weight_window = getWeightWindow(
marg_fract,
rad_to_hdiag); // limit corners
if (dbg_images) {
(new ShowDoubleFloatArrays()).showArrays(
......@@ -261,7 +305,7 @@ public class ExtrinsicAdjustment {
inf_min_disparity, // double min_infinity,
inf_max_disparity); // double max_infinity
}
/*
this.weights = getWeights(
measured_dsxy, // double [][] measured_dsxy,
(use_disparity? force_disparity: null), // boolean [] force_disparity, // same dimension as dsdn, true if disparity should be controlled
......@@ -269,12 +313,43 @@ public class ExtrinsicAdjustment {
min_num_forced, // int min_num_forced,
weight_disparity, // double weight_disparity,
weight_lazyeye); // double weight_lazyeye);
*/
double weight_infinity = 0.3; // // total weight of infinity tiles fraction (0.0 - 1.0)
weight_disparity = 0.0; // disparity weight relative to the sum of 8 lazy eye values of the same tile
double weight_disparity_inf = 0.5; // disparity weight relative to the sum of 8 lazy eye values of the same tile for infinity
double max_disparity_far = 5.0; // reduce weights of near tiles proportional to sqrt(max_disparity_far/disparity)
double max_disparity_use = 5.0 ; // temporarily to avoid ERS - disable near objects completely
double [][] clouds = detectClouds(
measured_dsxy,
force_disparity); // same dimension as dsdn, true if disparity should be controlled
String [] dbg_titles = {"clouds", "disparity","strength"};
(new ShowDoubleFloatArrays()).showArrays(
clouds,
clustersX,
clustersY,
true,
"clouds",
dbg_titles);
double min_fg_disp = 0.0; // 25.0; // minimal disparity to boost foreground objects
this.weights = getWeights( // will ignore window for infinity (already used for selection)
measured_dsxy, // double [][] measured_dsxy,
(use_disparity? force_disparity: null), // boolean [] force_disparity, // same dimension as dsdn, true if disparity should be controlled
filtered_infinity, // boolean [] filtered_infinity,
min_num_forced, // int min_num_forced,
weight_infinity, // double weight_infinity, // total weight of infinity tiles fraction (0.0 - 1.0)
weight_disparity, // double weight_disparity, // disparity weight relative to the sum of 8 lazy eye values of the same tile
weight_disparity_inf, // double weight_disparity_inf, // disparity weight relative to the sum of 8 lazy eye values of the same tile for infinity
max_disparity_far, // double max_disparity_far) // reduce weights of near tiles proportional to sqrt(max_disparity_far/disparity)
max_disparity_use);
double min_fg_disp = 0.00; // 25.0; // minimal disparity to boost foreground objects
double min_rel_over = 0.25; // minimal relative disparity over average for a row to boost foreground objects
int min_num_fg = min_num_forced;
double fg_boost_fraction = 0.5;
if (min_fg_disp > 0.0) {
if (min_fg_disp > 0.0) { // not needed
boolean [] select_ers = selectERS(
measured_dsxy, // double [][] measured_dsxy,
null, // boolean [] selection, // or null
......@@ -300,31 +375,46 @@ public class ExtrinsicAdjustment {
double [][] ers_tilt_az = getMovingObjects(
corr_vector, // GeometryCorrection.CorrVector corr_vector,
null ); // double [] fx
if (ers_tilt_az != null) {
showMovingObjects(
"Moving_objects", // String title,
ers_tilt_az);
double moving_sigma = 1.0;
double [] ers_blured = showMovingObjects(
double [] ers_blured = showMovingObjects( // uses weights for bluring
"Moving_objects_sigma"+moving_sigma, // String title,
ers_tilt_az,
moving_sigma, // double sigmaX,
0.01); // double accuracy
System.out.println("Moving objects");
double mov_avg = 0.0;
double [] cluster_weight = getClusterWeight();
double max_mov_disparity = 75.0;
double rad_to_hdiag_mov = 0.7 ; // 0.8
boolean [] moving_en= getMovingObjectsSel(
measured_dsxy, // to use target_disparity
cluster_weight,
max_mov_disparity, // disable higher disparity
rad_to_hdiag_mov); // 0.8 limit by radius too (1.0 - radius is half diagonal, same margins, use min)
int clusters = clustersX * clustersY;
double sw = 0.0;
double mov_avg = 0.0;
for (int cluster = 0; cluster < clusters; cluster++) {
if (!Double.isNaN(ers_blured[cluster])) mov_avg += ers_blured[cluster];
if (moving_en[cluster] && !Double.isNaN(ers_blured[cluster])) {
mov_avg += ers_blured[cluster] * cluster_weight[cluster];
sw += cluster_weight[cluster];
}
mov_avg /= clusters;
}
mov_avg /= sw; // clusters;
System.out.println("Average moving object detection value = "+mov_avg+
" (use to abandon detection if too high?");
// double min_l2 = 1.0 * mov_avg;
double min_l2 = 1.0 * mov_avg;
// double min_l2 = 1.0 * mov_avg;
double min_l2 = 2.50 * mov_avg; // 1.5 * mov_avg;
boolean [] moving_maybe = extractMovingObjects(
"Moving_objects_filtering", // String title,
ers_blured, //double [] ers_blured, // has NaNs
moving_en, // boolean [] moving_en
min_l2, // double min_l2); // minimal value (can use average or fraction of it?
4, // int shrink, // prevents growing outer border (==4)
2); // int grow) { // located moving areas
......@@ -340,6 +430,7 @@ public class ExtrinsicAdjustment {
this.weights, // double [] weights, // will be updated
moving_maybe); // boolean [] prohibit
}
}
double lambda = 0.1;
double lambda_scale_good = 0.5;
......@@ -516,7 +607,8 @@ public class ExtrinsicAdjustment {
return rslt;
}
private double [] getWeightWindow(double marg_fraction) { // 0.0 - no margins, 1.0 - pure cosine
@Deprecated
private double [] getWeightWindowOld(double marg_fraction) { // 0.0 - no margins, 1.0 - pure cosine
double mf_hor = marg_fraction;
double mf_vert = marg_fraction;
double [] wx = new double [clustersX];
......@@ -560,6 +652,74 @@ public class ExtrinsicAdjustment {
return w;
}
private double [] getWeightWindow(
double marg_fraction, // 0.0 - no margins, 1.0 - pure cosine
double rad_to_hdiag) // 0.8 limit by radius too (1.0 - radius is half diagonal, same margins, use min)
{
double mf_hor = marg_fraction;
double mf_vert = marg_fraction;
double [] wx = new double [clustersX];
double [] wy = new double [clustersY];
double [] w = new double [clustersX * clustersY];
// int [] boost_wnd = {33,15,40,35};
// double boost_scale = 1.0; // 100.0;
double centerX = 0.5 * (clustersX - 1);
double marg = centerX * mf_hor;
for (int x = 0; x <= clustersX / 2; x++) {
if (x < marg) {
wx[x] = Math.sin(Math.PI * x / 2.0 / marg);
wx[x] *= wx[x];
} else {
wx[x] = 1.0;
}
wx[clustersX - 1 -x ] = wx[x];
}
double centerY = 0.5 * (clustersY - 1);
marg = centerY * mf_vert;
for (int y = 0; y <= clustersY / 2; y++) {
if (y < marg) {
wy[y] = Math.sin(Math.PI * y / 2.0 / marg);
wy[y] *= wx[y];
} else {
wy[y] = 1.0;
}
wy[clustersY - 1 - y ] = wy[y];
}
for (int y = 0; y < clustersY; y++) {
for (int x = 0; x < clustersX; x++) {
w[y * clustersX + x] = wx[x]*wy[y];
/*
if (boost_scale > 1.0) {
if ((x >= boost_wnd[0]) && (x < boost_wnd[2]) && (y >= boost_wnd[1]) && (y < boost_wnd[3])) {
w[y * clustersX + x] *= boost_scale;
}
}
*/
}
}
double r_outer = Math.sqrt(centerX * centerX + centerY*centerY)* rad_to_hdiag; // relative to horizontal with
double r_marg = r_outer * marg_fraction;
for (int y = 0; y < clustersY; y++) {
for (int x = 0; x < clustersX; x++) {
double r = Math.sqrt((x - centerX)*(x - centerX) + (y - centerY)*(y - centerY));
double k = 1.0;
if (r > r_outer) {
k = 0.0;
} else if (r > (r_outer - r_marg)) {
k = Math.sin(Math.PI * (r_outer - r) / 2.0 / r_marg);
}
if (k < w[y * clustersX + x]) {
w[y * clustersX + x] = k;
}
}
}
return w;
}
// Make total weight of disparity (forced) samples - weight_disparity, weight of all others (8 per cluster) weight_lazyeye;
private boolean [] filterInfinity(
......@@ -668,7 +828,7 @@ public class ExtrinsicAdjustment {
double sw_near = 0.0;
int clusters = clustersX * clustersY;
for (int cluster = 0; cluster < clusters; cluster++) if (measured_dsxy[cluster] != null){
double disparity = measured_dsxy[cluster][ExtrinsicAdjustment.INDX_DISP];
double disparity = measured_dsxy[cluster][ExtrinsicAdjustment.INDX_TARGET]; // INDX_DISP];
if (disparity <= max_disparity) {
for (int i = 0; i < POINTS_SAMPLE; i++) {
sw_near += weights[cluster * POINTS_SAMPLE + i];
......@@ -682,7 +842,7 @@ public class ExtrinsicAdjustment {
if (sw_near > 0.0) {
double wboost = sw/sw_near;
for (int cluster = 0; cluster < clusters; cluster++) if (measured_dsxy[cluster] != null){
double disparity = measured_dsxy[cluster][ExtrinsicAdjustment.INDX_DISP];
double disparity = measured_dsxy[cluster][ExtrinsicAdjustment.INDX_TARGET]; // INDX_DISP];
if (disparity <= max_disparity) {
for (int i = 0; i < POINTS_SAMPLE; i++) {
weights[cluster * POINTS_SAMPLE + i] *= wboost;
......@@ -696,6 +856,49 @@ public class ExtrinsicAdjustment {
}
}
private boolean [] getMovingObjectsSel(
double [][] measured_dsxy, // to use target_disparity
double [] cluster_weights,
double max_disparity, // disable higher disparity
double rad_to_hdiag) // 0.8 limit by radius too (1.0 - radius is half diagonal, same margins, use min)
{
double centerX = 0.5 * (clustersX - 1);
double centerY = 0.5 * (clustersY - 1);
int clusters = clustersX * clustersY;
double [] weights = cluster_weights.clone();
double [] target_disparity = new double [clusters];
boolean [] selection = new boolean [clusters];
for (int cluster = 0; cluster < clusters; cluster++) {
if (measured_dsxy[cluster] != null){
target_disparity[cluster] = measured_dsxy[cluster][ExtrinsicAdjustment.INDX_TARGET];
} else {
weights[cluster] = 0.0;
}
}
target_disparity = (new DoubleGaussianBlur()).blurWithNaN(
target_disparity, // double[] pixels,
weights, // null, // double [] in_weight, // or null
clustersX,// int width,
clustersY,// int height,
0.5, // double sigmaX, slightly blur, mostly - just fill small gaps
0.5, // double sigmaY,
0.01); // double accuracy
double radius = Math.sqrt(centerX * centerX + centerY*centerY)* rad_to_hdiag; // relative to horizontal with
for (int y = 0; y < clustersY; y++) {
for (int x = 0; x < clustersX; x++) {
double r = Math.sqrt((x - centerX)*(x - centerX) + (y - centerY)*(y - centerY));
if (r < radius) {
int cluster = y * clustersX + x;
if (target_disparity[cluster] <= max_disparity) {
selection[cluster] = true;
}
}
}
}
return selection;
}
private void blockSelectedClusters(
double [][] measured_dsxy,
double [] weights,
......@@ -732,8 +935,8 @@ public class ExtrinsicAdjustment {
}
private double [] getWeights(
@Deprecated
private double [] getWeightsOld(
double [][] measured_dsxy,
boolean [] force_disparity, // same dimension as dsdn, true if disparity should be controlled
boolean [] filtered_infinity,
......@@ -800,6 +1003,152 @@ public class ExtrinsicAdjustment {
return weights;
}
private double [][] detectClouds(
double [][] measured_dsxy,
boolean [] force_disparity) // same dimension as dsdn, true if disparity should be controlled
{
int clusters = clustersX * clustersY;
if (force_disparity == null) {
force_disparity = new boolean[clusters];
for (int cluster = 0; cluster < clusters; cluster++) {
if ((measured_dsxy[cluster] != null) && (measured_dsxy[cluster][ExtrinsicAdjustment.INDX_TARGET] == 0.0)) {
force_disparity[cluster] = true;
}
}
}
double [][] clouds = new double [3][clusters];
for (int clusterX = 0; clusterX < clustersX; clusterX++) {
double sw = 0.0;
double sdw = 0.0;
for (int clusterY = 0; clusterY < clustersY; clusterY++) {
int cluster = clusterX + clustersX * clusterY;
if (force_disparity[cluster] && (measured_dsxy[cluster] != null)) {
double s = measured_dsxy[cluster][ExtrinsicAdjustment.INDX_STRENGTH];
double d = -measured_dsxy[cluster][ExtrinsicAdjustment.INDX_DIFF];
sw += s;
sdw += s * d;
}
if (sw >= 0) {
clouds[0][cluster] = sdw/sw;
} else {
clouds[0][cluster] = Double.NaN;
}
if (measured_dsxy[cluster] != null) {
clouds[1][cluster] = -measured_dsxy[cluster][ExtrinsicAdjustment.INDX_DIFF];
clouds[2][cluster] = measured_dsxy[cluster][ExtrinsicAdjustment.INDX_STRENGTH];
}
}
for (int cluster = 0; cluster < clusters; cluster++) {
if (!force_disparity[cluster]) {
clouds[0][cluster] = Double.NaN;
}
}
}
return clouds;
}
private double [] getWeights(
double [][] measured_dsxy,
boolean [] force_disparity, // same dimension as dsdn, true if disparity should be controlled
boolean [] filtered_infinity, // tiles known to be infinity
int min_num_forced, // if number of forced samples exceeds this, zero out weights of non-forced
double weight_infinity, // total weight of infinity tiles fraction (0.0 - 1.0)
double weight_disparity, // disparity weight relative to the sum of 8 lazy eye values of the same tile
double weight_disparity_inf, // disparity weight relative to the sum of 8 lazy eye values of the same tile for infinity
double max_disparity_far, // reduce weights of near tiles proportional to sqrt(max_disparity_far/disparity)
double max_disparity_use) // do not process near objects to avoid ERS
{
// weight_disparity =.5; // FIXME: Fix!
int clusters = clustersX * clustersY;
double [] weights = new double [clusters * POINTS_SAMPLE];
double [] strength = new double [clusters];
boolean [] disable = new boolean [clusters];
if (filtered_infinity != null) {
for (int cluster = 0; cluster < clusters; cluster++) {
disable[cluster] = force_disparity[cluster] && !filtered_infinity[cluster];
}
}
double sw = 0.0;
double swf = 0.0;
int num_forced = 0;
// if (force_disparity != null) for (int cluster = 0; cluster < clusters; cluster++) if (force_disparity[cluster])num_forced ++;
// boolean use_forced = num_forced >= min_num_forced;
for (int cluster = 0; cluster < clusters; cluster++) if ((measured_dsxy[cluster] != null) && !disable[cluster]){
double s =getClustWeight(
cluster,
measured_dsxy,
force_disparity, // same dimension as dsdn, true if disparity should be controlled
max_disparity_far, // reduce weights of near tiles proportional to sqrt(max_disparity_far/disparity)
max_disparity_use);
strength[cluster] = s;
if ((force_disparity != null) && (force_disparity[cluster])) {
swf += s;
num_forced++;
}
sw += s;
}
if (sw <= 0.0) {
return null;
}
boolean use_forced = num_forced >= min_num_forced;
double k_inf_disp, k_inf_ly, k_other_disp, k_other_ly;
if (sw <= swf) {
use_forced = false;
}
if (use_forced) {
// disparity weight non-zero only for infinity, non-disparity - equal scale for all
k_inf_disp = weight_disparity_inf * weight_infinity / swf;
k_inf_ly = (1.0 - weight_disparity_inf) * weight_infinity / swf / (POINTS_SAMPLE - 1);
k_other_disp = weight_disparity * (1.0 - weight_infinity) / (sw - swf);
k_other_ly = (1.0 - weight_disparity) * (1.0 - weight_infinity) / (sw - swf) / (POINTS_SAMPLE - 1);
} else {
k_other_disp = weight_disparity / sw;
k_other_ly = (1.0 - weight_disparity) / sw / (POINTS_SAMPLE - 1);
k_inf_disp = k_other_disp;
k_inf_ly = k_other_ly;
}
for (int cluster = 0; cluster < clusters; cluster++) if ((measured_dsxy[cluster] != null) && !disable[cluster]){
double s =strength[cluster];
if ((force_disparity != null) && force_disparity[cluster]) {
weights[cluster * POINTS_SAMPLE + 0] = s * k_inf_disp;
for (int i = 1; i < POINTS_SAMPLE; i++) {
weights[cluster * POINTS_SAMPLE + i] = s * k_inf_ly;
}
} else {
weights[cluster * POINTS_SAMPLE + 0] = s * k_other_disp;
for (int i = 1; i < POINTS_SAMPLE; i++) {
weights[cluster * POINTS_SAMPLE + i] = s * k_other_ly;
}
}
}
this.pure_weight = 1.0;
return weights;
}
private double getClustWeight(
int cluster,
double [][] measured_dsxy,
boolean [] force_disparity, // same dimension as dsdn, true if disparity should be controlled
double max_disparity_far, // reduce weights of near tiles proportional to sqrt(max_disparity_far/disparity)
double max_disparity_use) // do not process near objects to avoid ERS
{
double s = measured_dsxy[cluster][ExtrinsicAdjustment.INDX_STRENGTH];
if ((force_disparity == null) || (!force_disparity[cluster])) {
s *= weight_window[cluster];
}
double d = measured_dsxy[cluster][ExtrinsicAdjustment.INDX_TARGET];
if (d > max_disparity_far) {
s *= Math.sqrt(max_disparity_far/d);
}
if (d > max_disparity_use) {
s = 0.0;
}
return s;
}
private double [] getFx(
GeometryCorrection.CorrVector corr_vector)
{
......@@ -876,12 +1225,35 @@ public class ExtrinsicAdjustment {
return names;
}
// get full (s0..s18) index from jacobian parameter number
public int getFullParIndex(int indx) {
for (int i = 0; i < par_mask.length; i++) if (par_mask[i]){
if (indx == 0) {
return i;
}
indx --;
}
return -1;
}
public int getParIndex(int full_index) {
int indx = 0;
for (int i = 0; i < par_mask.length; i++) if (par_mask[i]){
if (i == full_index) {
return indx;
}
indx ++;
}
return -1;
}
private double dbgJacobians(
GeometryCorrection.CorrVector corr_vector,
double delta,
boolean graphic) {
// delta *= 0.1;
int gap = 10+0; //pix
int gap = 10; //pix
int clusters = clustersX * clustersY;
int num_pars = getNumPars();
String [] titles = getSymNames();
......@@ -1036,8 +1408,11 @@ public class ExtrinsicAdjustment {
GeometryCorrection.CorrVector corr_vector,
double [] fx // or null;
) {
int ers_tilt_index = GeometryCorrection.CorrVector.IMU_INDEX;
int ers_azimuth_index = GeometryCorrection.CorrVector.IMU_INDEX + 1;
int ers_tilt_index = getParIndex(GeometryCorrection.CorrVector.IMU_INDEX);
int ers_azimuth_index = getParIndex(GeometryCorrection.CorrVector.IMU_INDEX + 1);
if ((ers_tilt_index < 0) || (ers_azimuth_index < 0)) {
return null;
}
int clusters = clustersX * clustersY;
double [][] ers_tilt_az = new double [clusters][];
double [][] jt = getJacobianTransposed(corr_vector);
......@@ -1066,6 +1441,25 @@ public class ExtrinsicAdjustment {
0);
}
private double [] getClusterWeight() { // sum == 1.0;
int clusters = clustersX * clustersY;
double [] cluster_weights = new double [clusters];
double sw = 0.0;
for (int cluster = 0; cluster < clusters; cluster++) {
for (int i = 0; i < POINTS_SAMPLE; i++) {
cluster_weights[cluster] += this.weights[cluster * POINTS_SAMPLE + i];
sw += cluster_weights[cluster];
}
}
if (sw > 0.0){ // normally should be == 1.0
double k = 1.0/sw;
for (int cluster = 0; cluster < clusters; cluster++) {
cluster_weights[cluster] *= k;
}
}
return cluster_weights;
}
private double [] showMovingObjects(
String title,
double [][] ers_tilt_az,
......@@ -1096,12 +1490,7 @@ public class ExtrinsicAdjustment {
}
if (sigma > 0.0){
double [] cluster_weights = new double [clusters];
for (int cluster = 0; cluster < clusters; cluster++) {
for (int i = 0; i < POINTS_SAMPLE; i++) {
cluster_weights[cluster] += this.weights[cluster * POINTS_SAMPLE + i];
}
}
double [] cluster_weights = getClusterWeight();
for (int i = 0; i < dbg_img.length; i++) {
dbg_img[i] = (new DoubleGaussianBlur()).blurWithNaN(
dbg_img[i], // double[] pixels,
......@@ -1128,6 +1517,7 @@ public class ExtrinsicAdjustment {
public boolean [] extractMovingObjects(
String title,
double [] ers_blured, // has NaNs
boolean [] moving_en,
double min_l2, // minimal value (can use average or fraction of it?
int shrink, // prevents growing outer border (==4)
int grow) { // located moving areas
......@@ -1136,6 +1526,9 @@ public class ExtrinsicAdjustment {
boolean [] terrain = new boolean[clusters];
for (int i = 0; i < clusters; i++) {
terrain[i] = ers_blured[i] <= min_l2; // NaNs not included
// if (moving_en != null) {
// terrain[i] &= moving_en[i];
// }
}
// find largest terrain area
int [] iterrains = tn. enumerateClusters(
......@@ -1149,9 +1542,9 @@ public class ExtrinsicAdjustment {
boolean [] filled = tn.fillConcave(terrain_main);
tn.shrinkSelection(
shrink, // int shrink,
clustersX, // shrink, // int shrink, remove all open outside of moving_en
filled, // boolean [] tiles,
null); // boolean [] prohibit)
moving_en); // null); // boolean [] prohibit)
boolean [] moving = filled.clone();
for (int i = 0; i < clusters; i++) {
moving[i] &= !terrain_main[i];
......@@ -1527,7 +1920,7 @@ public class ExtrinsicAdjustment {
return null; // need to re-init/restart LMA
}
this.last_rms = getWYmFxRms(
this.last_ymfx); // modifies this.last_ymfx (weights and subtracts fx
this.last_ymfx); // modifies this.last_ymfx (weights and subtracts fx)
this.initial_rms = this.last_rms.clone();
this.good_or_bad_rms = this.last_rms.clone();
// TODO: Restore/implement
......
......@@ -552,6 +552,11 @@ public class GeometryCorrection {
extrinsic_corr = new CorrVector();
}
public void resetCorrVectorERS(){// not used in lwir
extrinsic_corr.setIMU(new double[6]);
}
public boolean [] getParMask( // for compatibility with old
// boolean disparity_only,
// boolean use_disparity,
......
......@@ -2274,6 +2274,7 @@ public class ImageDtt extends ImageDttCPU {
public double [][] cltMeasureLazyEyeGPU ( // returns d,s lazy eye parameters
final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
// if exactly zero - considered to be infinity capturing
final float [][][][] fcorr_td, // [tilesY][tilesX][pair][4*64] transform domain representation of 6 corr
final float [][][][] fdisp_dist, // [tilesY][tilesX][cams][4], // disparity derivatives vectors or null
final float [][][][] fpxpy, // [tilesY][tilesX][cams][2], tile {pX,pY}
......@@ -2285,6 +2286,7 @@ public class ImageDtt extends ImageDttCPU {
final GeometryCorrection geometryCorrection_main, // if not null correct this camera (aux) to the coordinates of the main
final double disparity_corr, // disparity at infinity
final int tileStep, // process tileStep x tileStep cluster of tiles when adjusting lazy eye parameters
final int super_radius, // 0 - none, 1 - 3x3, 2 - 5x5,
final int debug_tileX,
final int debug_tileY,
final int threadsMax, // maximal number of threads to launch
......@@ -2305,6 +2307,7 @@ public class ImageDtt extends ImageDttCPU {
final int debug_clustX = debug_tileX / tileStep;
final int debug_clustY = debug_tileY / tileStep;
/// final int bg_extra = (tileSizeBg - tileStep + 1) / 2; // add overlap around each bg cluster
// calculate which tiles to use for each cluster
// will generate sparse array for cluster central tiles to match CPU software
......@@ -2314,11 +2317,14 @@ public class ImageDtt extends ImageDttCPU {
final double [][][] clust_pY = new double [clustersY][clustersX][];
final double [][][] pxpy = new double [clustersY][clustersX][];
final double [][] disparity_array_center = new double [clustersY][clustersX];
final boolean [][] bg_cluster = new boolean [clustersY][clustersX];
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final double shiftX = 0.0;
final double shiftY = 0.0;
// final int super_radius = tileSizeBg; // rename? 0 - none, 1 - 3x3, 2 - 5x5, ...
// TODO: Maybe calculate full energy in each TD tile for normalization
// First pass merge correlation result for each cluster
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
......@@ -2326,23 +2332,34 @@ public class ImageDtt extends ImageDttCPU {
for (int nCluster = ai.getAndIncrement(); nCluster < nClustersInChn; nCluster = ai.getAndIncrement()) {
int clustY = nCluster / clustersX;
int clustX = nCluster % clustersX;
/// double [][][] centersXY = new double [clustSize][][];
/// double [][][] disp_dist = new double[clustSize][quad][]; // used to correct 3D correlations
/// double [][][] corrs = new double [clustSize][][];
/// double [][] corr_stat = new double [clustSize][];
/// double [] strength = new double [clustSize];
/// double [][] disp_str = new double [clustSize][];
/// double [][] pxpy = new double [clustSize][2];
boolean debugCluster = (clustX == debug_clustX) && (clustY == debug_clustY);
/// boolean debugCluster1 = (Math.abs(clustX - debug_clustX) < 10) && (Math.abs(clustY - debug_clustY) < 10);
if (debugCluster) {
System.out.println("debugCluster1");
}
/// int clust_lma_debug_level = debugCluster? imgdtt_params.lma_debug_level : -5;
// filter only tiles with similar disparity to enable lazy eye for the ERS.
int num_good_tiles = 0;
double avg= 0.0;
/// int corr_len = 0;
boolean has_bg = false;
for (int cTileY = 0; (cTileY < tileStep) && !has_bg; cTileY++) {
int tileY = clustY * tileStep + cTileY ;
if (tileY < tilesY) {
for (int cTileX = 0; (cTileX < tileStep) && !has_bg; cTileX++) {
int tileX = clustX * tileStep + cTileX ;
if ((tileX < tilesX) && (fcorr_td[tileY][tileX] != null)) {
double d = disparity_array [tileY][tileX];
if (d == 0) {
has_bg = true;
break;
}
}
}
}
}
bg_cluster[clustY][clustX] = has_bg;
float [][] ftd = new float [num_pairs][4* transform_size * transform_size];
// if (has_bg) {
while (true) {
int mnTx = -1, mnTy = -1, mxTx = -1, mxTy = -1;
double mn = Double.NaN;
......@@ -2354,9 +2371,11 @@ public class ImageDtt extends ImageDttCPU {
if (tileY < tilesY) {
for (int cTileX = 0; cTileX < tileStep; cTileX++) {
int tileX = clustX * tileStep + cTileX ;
//// if ((tileX < tilesX) && (tile_op[tileY][tileX] != 0)) {
if ((tileX < tilesX) && (fcorr_td[tileY][tileX] != null)) {
double d = disparity_array [tileY][tileX];
if (has_bg && (d != 0)) {
continue; // for bg tiles do not mix with non-bg
}
avg += d;
if (!(d <= mx)) {
mx = d;
......@@ -2390,7 +2409,6 @@ public class ImageDtt extends ImageDttCPU {
// for now - num_good_tiles - the only strength measure
// should it be calculated from the correlation normalization?
// will try to calculate through the sum of squared normalizations
float [][] ftd = new float [num_pairs][4* transform_size * transform_size];
if (num_good_tiles > 0) {
double dscale = 1.0/num_good_tiles;
......@@ -2398,7 +2416,7 @@ public class ImageDtt extends ImageDttCPU {
//fpxpy
double [] avg_py = new double [quad];
double [][] avg_disp_dist = new double [quad][4];
// double [][] avg_pxpy = new double [quad][2];
// double [][] avg_pxpy = new double [quad][2];
double [] avg_pxpy = new double [2];
for (int cTileY = 0; cTileY < tileStep; cTileY++) {
int tileY = clustY * tileStep + cTileY ;
......@@ -2421,15 +2439,7 @@ public class ImageDtt extends ImageDttCPU {
}
}
int centerY = clustY * tileStep + tileStep/2; // integer was 242!
int centerX = clustX * tileStep + tileStep/2; // integer
if (centerY >= tilesY) {
centerY = tilesY - 1;
}
if (centerX >= tilesX) {
centerX = tilesX - 1;
}
// tile_op[centerY][centerX] = task_val;
// tile_op[centerY][centerX] = task_val;
num_in_cluster [clustY][clustX] = num_good_tiles;
disparity_array_center[clustY][clustX] = avg;
......@@ -2463,6 +2473,16 @@ public class ImageDtt extends ImageDttCPU {
}
}
}
}
if (num_good_tiles > 0) {
int centerY = clustY * tileStep + tileStep/2; // integer was 242!
int centerX = clustX * tileStep + tileStep/2; // integer
if (centerY >= tilesY) {
centerY = tilesY - 1;
}
if (centerX >= tilesX) {
centerX = tilesX - 1;
}
float fscale = 1.0f/num_good_tiles;
for (int np = 0; np <num_pairs; np++) {
for (int i = 0; i < ftd[np].length; i++) {
......@@ -2476,6 +2496,7 @@ public class ImageDtt extends ImageDttCPU {
};
}
startAndJoin(threads);
int [][] pairs_map = {{0,0},{1,1},{2,2},{3,3},{4,4},{5,5}};
final int [] corr_indices = gpuQuad.setCorrTilesTd( // .length = 295866 should set num_corr_tiles!
fcorr_td_centers, // final float [][][][] corr_tiles, // [tileY][tileX][pair][4*64]
......@@ -2486,7 +2507,7 @@ public class ImageDtt extends ImageDttCPU {
gpu_corr_rad); // int corr_radius
final float [][] fcorr2D = gpuQuad.getCorr2D(gpu_corr_rad); // int corr_rad);
final int corr_length = fcorr2D[0].length;// all correlation tiles have the same size
final int corr_length = fcorr2D[0].length + 0;// all correlation tiles have the same size
final int num_tiles = corr_indices.length / num_pairs;
final double [][] corr_wnd = Corr2dLMA.getCorrWnd(
transform_size,
......@@ -2502,6 +2523,8 @@ public class ImageDtt extends ImageDttCPU {
}
}
}
final double [][] dbg_img = new double[19][clustersX*clustersY];
// Second pass - process normalized per-cluster correlations
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
......@@ -2525,13 +2548,14 @@ public class ImageDtt extends ImageDttCPU {
int tileY = nt / tilesX;
int clustX = tileX/tileStep;
int clustY = tileY/tileStep;
int nclust = clustX + clustY * clustersX;
dbg_img[0][nclust] = 1.0;
/// boolean debugCluster1 = (Math.abs(clustX - debug_clustX) < 10) && (Math.abs(clustY - debug_clustY) < 10);
double [] disp_str = null;
for (int indx_pair = 0; indx_pair < num_pairs; indx_pair++) {
int pair = corr_indices[indx_corr] & GPUTileProcessor.CORR_PAIRS_MASK; // ((1 << CORR_NTILE_SHIFT) - 1); // np should
assert pair < GPUTileProcessor.NUM_PAIRS : "invalid correllation pair";
/// pair_mask |= (1 << pair);
for (int i = 0; i < corr_length; i++) {
corrs[pair][i] = gpu_corr_scale * fcorr2D[indx_corr][i]; // from float to double
}
......@@ -2539,14 +2563,6 @@ public class ImageDtt extends ImageDttCPU {
}
// final float [][][][] fdisp_dist, // [tilesY][tilesX][cams][4], // disparity derivatives vectors or null
double [][] tile_disp_dist = disp_dist[clustY][clustX];
/*
double [][] disp_dist = new double [fdd.length][fdd[0].length];
for (int n = 0; n < fdd.length; n++) {
for (int i = 0; i < fdd[0].length; i++) {
disp_dist[n][i] = fdd[n][i]; // float to double
}
}
*/
// debug new LMA correlations
boolean debugCluster = (clustX == debug_clustX) && (clustY == debug_clustY);
......@@ -2598,11 +2614,13 @@ public class ImageDtt extends ImageDttCPU {
tileY); // int tileY
*/
if (lma2 != null) {
dbg_img[1][nclust] = 1.0;
// was for single tile
disp_str = lma2.lmaDisparityStrength(
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_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, // double lma_max_area, // maximal half-area (if > 0.0)
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
......@@ -2612,69 +2630,394 @@ public class ImageDtt extends ImageDttCPU {
lma2.printStats(ds_dbg,1);
}
//was for multi-tile
int nCluster = clustY * clustersX + clustX;
// int nCluster = clustY * clustersX + clustX;
double [][] ddnd = lma2.getDdNd();
double [] stats = lma2.getStats(num_in_cluster[clustY][clustX]);
double [][] lma_ds = lma2.lmaDisparityStrength( // [1][2]
// double [] stats = lma2.getStats (1); // num_in_cluster[clustY][clustX]);
double [] stats = lma2.getStats (num_in_cluster[clustY][clustX]);
dbg_img[2][nclust] = stats[0];
dbg_img[3][nclust] = stats[1];
dbg_img[4][nclust] = stats[2];
double [][] lma_ds = lma2.lmaDisparityStrengthLY( // [1][2]
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
1.0, // imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
0.0); // imgdtt_params.lma_str_offset); // convert lma-generated strength to match previous ones - add to result
double [][] dbg_ext_stat = lma2.lmaGetExtendedStats(
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
1.0, // imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
0.0); // imgdtt_params.lma_str_offset); // convert lma-generated strength to match previous ones - add to result
/// double [][] extra_stats = lma2.getTileStats();
// final double [][] lazy_eye_data = new double [clustersY*clustersX][];
// calculate average disparity per cluster using a sum of the disparity_array and the result of the LMA
lazy_eye_data[nCluster] = new double [ExtrinsicAdjustment.INDX_LENGTH];
double sum_w = 0;
// FIXME - single CTileX =0; cTileY = 0
/// int cTileY = 0;
/// int cTileX = 0;
/// int tIndex = tileY * tilesX + tileX;
for (int ii = 0; ii < dbg_ext_stat[0].length; ii++) {
dbg_img[5+ii][nclust] = dbg_ext_stat[0][ii];
}
dbg_img[16][nclust] = num_in_cluster[clustY][clustX];
double strengh_k = 1.0; // 0.2*Math.sqrt(num_in_cluster[clustY][clustX]); // approximately matching old/multitile
dbg_img[17][nclust] = strengh_k * lma_ds[0][1] * num_in_cluster[clustY][clustX];
dbg_img[18][nclust] = lma_ds[0][0] + disparity_array_center[clustY][clustX] + disparity_corr;
if ((lma_ds[0] != null) && (lma_ds[0][1]> 0.0)) {
double w = lma_ds[0][1];
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_DISP] += (lma_ds[0][0] + disparity_array_center[clustY][clustX] + disparity_corr) * w;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_TARGET] += (disparity_array_center[clustY][clustX] + disparity_corr) * w;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_DIFF] += lma_ds[0][0] * w;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_PX + 0] += pxpy[clustY][clustX][0] * w;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_PX + 1] += pxpy[clustY][clustX][1] * w;
lazy_eye_data[nclust] = new double [ExtrinsicAdjustment.INDX_LENGTH];
lazy_eye_data[nclust][ExtrinsicAdjustment.INDX_STRENGTH] = strengh_k * lma_ds[0][1] * num_in_cluster[clustY][clustX];
lazy_eye_data[nclust][ExtrinsicAdjustment.INDX_DISP] = lma_ds[0][0] + disparity_array_center[clustY][clustX] + disparity_corr;
lazy_eye_data[nclust][ExtrinsicAdjustment.INDX_TARGET] = (disparity_array_center[clustY][clustX] + disparity_corr);
lazy_eye_data[nclust][ExtrinsicAdjustment.INDX_DIFF] = lma_ds[0][0];
lazy_eye_data[nclust][ExtrinsicAdjustment.INDX_PX + 0] = pxpy[clustY][clustX][0];
lazy_eye_data[nclust][ExtrinsicAdjustment.INDX_PX + 1] = pxpy[clustY][clustX][1];
for (int cam = 0; cam < quad; cam++) {
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_DYDDISP0 + cam] += tile_disp_dist[cam][2] * w;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_PYDIST + cam] += clust_pY [clustY][clustX][cam] * w;
lazy_eye_data[nclust][ExtrinsicAdjustment.INDX_DYDDISP0 + cam] = tile_disp_dist[cam][2];
lazy_eye_data[nclust][ExtrinsicAdjustment.INDX_PYDIST + cam] = clust_pY [clustY][clustX][cam];
}
sum_w += w;
for (int cam = 0; cam < ddnd.length; cam++) {
if (ddnd[cam] != null) { //convert to x,y from dd/nd
lazy_eye_data[nclust][2 * cam + ExtrinsicAdjustment.INDX_X0 + 0] = ddnd[cam][0] * rXY[cam][0] - ddnd[cam][1] * rXY[cam][1];
lazy_eye_data[nclust][2 * cam + ExtrinsicAdjustment.INDX_X0 + 1] = ddnd[cam][0] * rXY[cam][1] + ddnd[cam][1] * rXY[cam][0];
lazy_eye_data[nclust][ExtrinsicAdjustment.INDX_DD0 + cam] = ddnd[cam][0];
lazy_eye_data[nclust][ExtrinsicAdjustment.INDX_ND0 + cam] = ddnd[cam][1];
} else {
lazy_eye_data[nclust][2 * cam + ExtrinsicAdjustment.INDX_X0 + 0] = Double.NaN;
lazy_eye_data[nclust][2 * cam + ExtrinsicAdjustment.INDX_X0 + 1] = Double.NaN;
lazy_eye_data[nclust][ExtrinsicAdjustment.INDX_DD0 + cam] = Double.NaN;
lazy_eye_data[nclust][ExtrinsicAdjustment.INDX_ND0 + cam] = Double.NaN;
}
}
if (sum_w > 0.0) { // may be simplified as there is only one tile now
double strengh_k = 0.2*Math.sqrt(num_in_cluster[clustY][clustX]); // approximately matching old/multitile
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_STRENGTH] =
stats[0] * num_in_cluster[clustY][clustX] * strengh_k;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_DISP] /= sum_w;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_TARGET] /= sum_w;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_DIFF] /= sum_w;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_PX + 0] /= sum_w;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_PX + 1] /= sum_w;
for (int cam = 0; cam < quad; cam++) {
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_DYDDISP0 + cam] /= sum_w;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_PYDIST + cam] /= sum_w;
}
}
} // end of tile
}
};
}
startAndJoin(threads);
(new ShowDoubleFloatArrays()).showArrays(
dbg_img,
clustersX,
clustersY,
true,
"ly_dbg"); // name+"-CORR2D-D"+clt_parameters.disparity,
if (super_radius == 0) {
return lazy_eye_data; // no processing of clouds in the sky
}
// save a copy of
final double [][] lazy_eye_data_final = new double [clustersY*clustersX][];
final int [][] num_in_cluster_final = new int [clustersY][clustersX]; // only in cluster centers
final float [][][][] fcorr_td_super = new float [tilesY][tilesX][][]; // sparse, only in cluster centers
// final float [][][][] fcorr_td_centers = new float [tilesY][tilesX][][]; // sparse, only in cluster centers
final double [][][][] disp_dist_super = new double [clustersY][clustersX][][];
final double [][][] clust_pY_super = new double [clustersY][clustersX][];
final double [][][] pxpy_super = new double [clustersY][clustersX][];
// pass 3 - prepare superclusters for weak infinity (clouds)
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nCluster = ai.getAndIncrement(); nCluster < nClustersInChn; nCluster = ai.getAndIncrement()) {
int clustY = nCluster / clustersX;
int clustX = nCluster % clustersX;
boolean debugCluster = (clustX == debug_clustX) && (clustY == debug_clustY);
/// boolean debugCluster1 = (Math.abs(clustX - debug_clustX) < 10) && (Math.abs(clustY - debug_clustY) < 10);
if (debugCluster) {
System.out.println("debugCluster3");
}
if (lazy_eye_data[nCluster] != null) {
lazy_eye_data_final[nCluster] = lazy_eye_data[nCluster];
num_in_cluster_final[clustY][clustX] = num_in_cluster[clustY][clustX];
} else if (bg_cluster[clustY][clustX]) { // only for empty (too weak) infinity
// only process empty infinity clusters
// filter only tiles with similar disparity to enable lazy eye for the ERS.
/// int num_good_super = 0; // number of clusters - remove?
int num_good_tiles = 0;
// boolean [][] usable_clust = new boolean [2 * super_radius + 1][2 * super_radius + 1];
// int [][] centersX = new int [2 * super_radius + 1][2 * super_radius + 1];
// int [][] centersY = new int [2 * super_radius + 1][2 * super_radius + 1];
// accumulate averages
float [][] ftd = new float [num_pairs][4* transform_size * transform_size];
double [] avg_py = new double [quad];
double [][] avg_disp_dist = new double [quad][4];
double [] avg_pxpy = new double [2];
for (int dClustY = -super_radius; dClustY <= super_radius; dClustY++) {
int iClustY = clustY + dClustY;
if ((iClustY >= 0) && (iClustY< clustersY)) {
for (int dClustX = -super_radius; dClustX <= super_radius; dClustX++) {
int iClustX = clustX + dClustX;
if ((iClustX >= 0) && (iClustX < clustersX)) {
int iCluster = iClustY * clustersX + iClustX;
int iCenterY = iClustY * tileStep + tileStep/2; // integer was 242!
int iCenterX = iClustX * tileStep + tileStep/2; // integer
if (iCenterY >= tilesY) {
iCenterY = tilesY - 1;
}
if (iCenterX >= tilesX) {
iCenterX = tilesX - 1;
}
if (bg_cluster[clustY][clustX] &&
(lazy_eye_data[iCluster] == null) &&
(fcorr_td_centers[iCenterY][iCenterX] != null)) {
// usable_clust[dClustY + super_radius][dClustX + super_radius] = true;
/// num_good_super++;
num_good_tiles += num_in_cluster[iClustY][iClustX];
double dscale = num_in_cluster[iClustY][iClustX];
float fscale = (float) dscale;
for (int np = 0; np <num_pairs; np++) {
for (int i = 0; i < ftd[np].length; i++) {
ftd[np][i]+= fscale * fcorr_td_centers[iCenterY][iCenterX][np][i];
}
}
for (int nc = 0; nc < quad; nc++) {
for (int i = 0; i < 4; i++) {
avg_disp_dist[nc][i] += dscale * disp_dist[iClustY][iClustX][nc][i];
}
avg_py[nc] += dscale * clust_pY[clustY][clustX][nc];
}
for (int i = 0; i < 2; i++) {
avg_pxpy[i] += dscale * pxpy [iClustY][iClustX][i] ;
}
}
}
}
}
}
num_in_cluster_final[clustY][clustX] = num_good_tiles;
double dscale = 1.0/num_good_tiles;
float fscale = (float) dscale;
for (int np = 0; np <num_pairs; np++) {
for (int i = 0; i < ftd[np].length; i++) {
ftd[np][i] *= fscale;
}
}
for (int nc = 0; nc < quad; nc++) {
for (int i = 0; i < 4; i++) {
avg_disp_dist[nc][i] *= dscale;
}
avg_py[nc] *= dscale;
}
for (int i = 0; i < 2; i++) {
avg_pxpy[i] *= dscale;
}
disp_dist_super[clustY][clustX] = avg_disp_dist;
pxpy_super [clustY][clustX] = avg_pxpy;
clust_pY_super [clustY][clustX] = avg_py; // to use for ERS
int centerY = clustY * tileStep + tileStep/2; // integer was 242!
int centerX = clustX * tileStep + tileStep/2; // integer
if (centerY >= tilesY) {
centerY = tilesY - 1;
}
if (centerX >= tilesX) {
centerX = tilesX - 1;
}
fcorr_td_super[centerY][centerX]= ftd;
} // else if (bg_cluster[clustY][clustX]) { // only for empty (too weak) infinity
} // end of cluster
}
};
}
startAndJoin(threads);
// 1) process fcorr_td_super with GPU
final int [] corr_indices_super = gpuQuad.setCorrTilesTd( // .length = 295866 should set num_corr_tiles!
fcorr_td_super, // final float [][][][] corr_tiles, // [tileY][tileX][pair][4*64]
pairs_map); // int [][] pairs) // typically {{0,0},{1,1},{2,2},{3,3},{4,4},{5,5} [0] - 3rd index in corr_tiles, [1] -
gpuQuad.execCorr2D_normalize(
false, // boolean combo, // normalize combo correlations (false - per-pair ones)
gpu_fat_zero, // double fat_zero);
gpu_corr_rad); // int corr_radius
final float [][] fcorr2D_super = gpuQuad.getCorr2D(gpu_corr_rad); // int corr_rad);
final int corr_length_super = fcorr2D_super[0].length + 0;// all correlation tiles have the same size
final int num_tiles_super = corr_indices_super.length / num_pairs;
/* Reuse same as already calculated
final double [][] corr_wnd = Corr2dLMA.getCorrWnd(
transform_size,
imgdtt_params.lma_wnd);
final double [] corr_wnd_inv_limited = (imgdtt_params.lma_min_wnd <= 1.0)? new double [corr_wnd.length * corr_wnd[0].length]: null;
if (corr_wnd_inv_limited != null) {
double inv_pwr = imgdtt_params.lma_wnd_pwr - (imgdtt_params.lma_wnd - 1.0); // compensate for lma_wnd
for (int i = imgdtt_params.lma_hard_marg; i < (corr_wnd.length - imgdtt_params.lma_hard_marg); i++) {
for (int j = imgdtt_params.lma_hard_marg; j < (corr_wnd.length - imgdtt_params.lma_hard_marg); j++) {
corr_wnd_inv_limited[i * (corr_wnd.length) + j] = 1.0/Math.max(Math.pow(corr_wnd[i][j],
inv_pwr),
imgdtt_params.lma_min_wnd);
}
}
}
*/
final double [][] dbg_img2 = new double[19][clustersX*clustersY];
// Fourth pass - process normalized per-cluster correlations for low-contrast infinity tiles (clouds in the sky)
ai.set(0);
// TODO: 2) calculate lazy_eye_data_final
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
Correlation2d corr2d = new Correlation2d(
imgdtt_params, // ImageDttParameters imgdtt_params,
transform_size, // int transform_size,
2.0, // double wndx_scale, // (wndy scale is always 1.0)
isMonochrome(), // boolean monochrome,
(globalDebugLevel > -1)); // boolean debug)
corr2d.createOrtoNotch(
imgdtt_params.getEnhOrthoWidth(isAux()), // double getEnhOrthoWidth(isAux()),
imgdtt_params.getEnhOrthoScale(isAux()), //double getEnhOrthoScale(isAux()),
(imgdtt_params.lma_debug_level > 1)); // boolean debug);
for (int indx_tile = ai.getAndIncrement(); indx_tile < num_tiles_super; indx_tile = ai.getAndIncrement()) {
double [][] corrs = new double [GPUTileProcessor.NUM_PAIRS][corr_length_super]; // 225-long (15x15)
int indx_corr = indx_tile * num_pairs;
int nt = (corr_indices_super[indx_corr] >> GPUTileProcessor.CORR_NTILE_SHIFT);
int tileX = nt % tilesX;
int tileY = nt / tilesX;
int clustX = tileX/tileStep;
int clustY = tileY/tileStep;
int nclust = clustX + clustY * clustersX;
dbg_img2[0][nclust] = 1.0;
double [] disp_str = null;
for (int indx_pair = 0; indx_pair < num_pairs; indx_pair++) {
int pair = corr_indices_super[indx_corr] & GPUTileProcessor.CORR_PAIRS_MASK; // ((1 << CORR_NTILE_SHIFT) - 1); // np should
assert pair < GPUTileProcessor.NUM_PAIRS : "invalid correllation pair";
for (int i = 0; i < corr_length_super; i++) {
corrs[pair][i] = gpu_corr_scale * fcorr2D_super[indx_corr][i]; // from float to double
}
indx_corr++;
}
// final float [][][][] fdisp_dist, // [tilesY][tilesX][cams][4], // disparity derivatives vectors or null
double [][] tile_disp_dist = disp_dist_super[clustY][clustX];
// debug new LMA correlations
boolean debugCluster = (clustX == debug_clustX) && (clustY == debug_clustY);
if (debugCluster) {
System.out.println("debugCluster2");
}
int tile_lma_debug_level = ((tileX == debug_tileX) && (tileY == debug_tileY))? imgdtt_params.lma_debug_level : -1;
int tdl = debugCluster ? tile_lma_debug_level : -3;
if (debugCluster && (globalDebugLevel > -1)) { // -2)) {
System.out.println("Will run new LMA for tileX="+tileX+", tileY="+tileY);
}
double [] poly_disp = {Double.NaN, 0.0};
Corr2dLMA lma2 = corr2d.corrLMA2Single( // multitile num_tiles_super == 1
imgdtt_params, // ImageDttParameters imgdtt_params,
true, // boolean adjust_ly, // adjust Lazy Eye
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)
corrs, // double [][] corrs,
tile_disp_dist,
rXY, // double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.dbg_pair_mask, // int pair_mask, // which pairs to process
null, // disp_str[cTile], //corr_stat[0], // double xcenter, // preliminary center x in pixels for largest baseline
poly_disp, // double[] poly_ds, // null or pair of disparity/strength
imgdtt_params.ortho_vasw_pwr, // double vasw_pwr, // value as weight to this power,
tdl, // tile_lma_debug_level, //+2, // int debug_level,
tileX, // int tileX, // just for debug output
tileY); // int tileY
/*
double [][] poly_disp2 = {{Double.NaN, 0.0}};
double [][][] corrs2 = {corrs};
double [][][] tile_disp_dist2 = {tile_disp_dist};
// TODO: maybe use corrLMA2Single again, but take care of initVector!
Corr2dLMA lma2 = corr2d.corrLMA2Multi( // multitile num_tiles_super == 1
imgdtt_params, // ImageDttParameters imgdtt_params,
1, // int clust_width,
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)
corrs2, // corrs, // double [][] corrs,
tile_disp_dist2,
rXY, // double [][] rXY, // non-distorted X,Y offset per nominal pixel of disparity
imgdtt_params.dbg_pair_mask, // int pair_mask, // which pairs to process
// null, // disp_str[cTile], //corr_stat[0], // double xcenter, // preliminary center x in pixels for largest baseline
poly_disp2, // double[] poly_ds, // null or pair of disparity/strength
imgdtt_params.ortho_vasw_pwr, // double vasw_pwr, // value as weight to this power,
tdl, // tile_lma_debug_level, //+2, // int debug_level,
tileX, // int tileX, // just for debug output
tileY); // int tileY
*/
if (lma2 != null) {
dbg_img2[1][nclust] = 1.0;
// was for single tile
disp_str = lma2.lmaDisparityStrength(
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_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, // double lma_max_area, // maximal half-area (if > 0.0)
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
)[0];
if (tile_lma_debug_level > 0) {
double [][] ds_dbg = {disp_str};
lma2.printStats(ds_dbg,1);
}
//was for multi-tile
// int nCluster = clustY * clustersX + clustX;
double [][] ddnd = lma2.getDdNd();
// double [] stats = lma2.getStats (1); // num_in_cluster_final[clustY][clustX]);
double [] stats = lma2.getStats (num_in_cluster_final[clustY][clustX]);
dbg_img2[2][nclust] = stats[0];
dbg_img2[3][nclust] = stats[1];
dbg_img2[4][nclust] = stats[2];
double k = 2.5;
double [][] lma_ds = lma2.lmaDisparityStrengthLY( // [1][2]
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
(1/k)*imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
(1/k)*imgdtt_params.lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
k* imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
1.0, // imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
0.0); // imgdtt_params.lma_str_offset); // convert lma-generated strength to match previous ones - add to result
double [][] dbg_ext_stat = lma2.lmaGetExtendedStats(
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
(1/k)*imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
(1/k)*imgdtt_params.lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
k* imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
1.0, // imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
0.0); // imgdtt_params.lma_str_offset); // convert lma-generated strength to match previous ones - add to result
for (int ii = 0; ii < dbg_ext_stat[0].length; ii++) {
dbg_img2[5+ii][nclust] = dbg_ext_stat[0][ii];
}
double strengh_k = 1.0; // 0.2*Math.sqrt(num_in_cluster[clustY][clustX]); // approximately matching old/multitile
strengh_k /= (2 * super_radius + 1)*(2 * super_radius + 1);
dbg_img2[16][nclust] = num_in_cluster_final[clustY][clustX];
dbg_img2[17][nclust] = strengh_k * lma_ds[0][1] * num_in_cluster_final[clustY][clustX];
dbg_img2[18][nclust] = lma_ds[0][0] + disparity_array_center[clustY][clustX] + disparity_corr;
if ((lma_ds[0] != null) && (lma_ds[0][1]> 0.0)) {
lazy_eye_data_final[nclust] = new double [ExtrinsicAdjustment.INDX_LENGTH];
lazy_eye_data_final[nclust][ExtrinsicAdjustment.INDX_STRENGTH] = strengh_k * lma_ds[0][1] * num_in_cluster_final[clustY][clustX];
lazy_eye_data_final[nclust][ExtrinsicAdjustment.INDX_DISP] = lma_ds[0][0] + disparity_array_center[clustY][clustX] + disparity_corr;
lazy_eye_data_final[nclust][ExtrinsicAdjustment.INDX_TARGET] = disparity_array_center[clustY][clustX] + disparity_corr;
lazy_eye_data_final[nclust][ExtrinsicAdjustment.INDX_DIFF] = lma_ds[0][0];
lazy_eye_data_final[nclust][ExtrinsicAdjustment.INDX_PX + 0] = pxpy_super[clustY][clustX][0];
lazy_eye_data_final[nclust][ExtrinsicAdjustment.INDX_PX + 1] = pxpy_super[clustY][clustX][1];
for (int cam = 0; cam < quad; cam++) {
lazy_eye_data_final[nclust][ExtrinsicAdjustment.INDX_DYDDISP0 + cam] = tile_disp_dist[cam][2];
lazy_eye_data_final[nclust][ExtrinsicAdjustment.INDX_PYDIST + cam] = clust_pY_super [clustY][clustX][cam];
}
for (int cam = 0; cam < ddnd.length; cam++) {
if (ddnd[cam] != null) { //convert to x,y from dd/nd
lazy_eye_data[nCluster][2 * cam + ExtrinsicAdjustment.INDX_X0 + 0] = ddnd[cam][0] * rXY[cam][0] - ddnd[cam][1] * rXY[cam][1];
lazy_eye_data[nCluster][2 * cam + ExtrinsicAdjustment.INDX_X0 + 1] = ddnd[cam][0] * rXY[cam][1] + ddnd[cam][1] * rXY[cam][0];
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_DD0 + cam] = ddnd[cam][0];
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_ND0 + cam] = ddnd[cam][1];
lazy_eye_data_final[nclust][2 * cam + ExtrinsicAdjustment.INDX_X0 + 0] = ddnd[cam][0] * rXY[cam][0] - ddnd[cam][1] * rXY[cam][1];
lazy_eye_data_final[nclust][2 * cam + ExtrinsicAdjustment.INDX_X0 + 1] = ddnd[cam][0] * rXY[cam][1] + ddnd[cam][1] * rXY[cam][0];
lazy_eye_data_final[nclust][ExtrinsicAdjustment.INDX_DD0 + cam] = ddnd[cam][0];
lazy_eye_data_final[nclust][ExtrinsicAdjustment.INDX_ND0 + cam] = ddnd[cam][1];
} else {
lazy_eye_data[nCluster][2 * cam + ExtrinsicAdjustment.INDX_X0 + 0] = Double.NaN;
lazy_eye_data[nCluster][2 * cam + ExtrinsicAdjustment.INDX_X0 + 1] = Double.NaN;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_DD0 + cam] = Double.NaN;
lazy_eye_data[nCluster][ExtrinsicAdjustment.INDX_ND0 + cam] = Double.NaN;
lazy_eye_data_final[nclust][2 * cam + ExtrinsicAdjustment.INDX_X0 + 0] = Double.NaN;
lazy_eye_data_final[nclust][2 * cam + ExtrinsicAdjustment.INDX_X0 + 1] = Double.NaN;
lazy_eye_data_final[nclust][ExtrinsicAdjustment.INDX_DD0 + cam] = Double.NaN;
lazy_eye_data_final[nclust][ExtrinsicAdjustment.INDX_ND0 + cam] = Double.NaN;
}
}
} else {
lazy_eye_data[nCluster] = null;
}
}
} // end of tile
......@@ -2682,8 +3025,32 @@ public class ImageDtt extends ImageDttCPU {
};
}
startAndJoin(threads);
(new ShowDoubleFloatArrays()).showArrays(
dbg_img2,
clustersX,
clustersY,
true,
"ly_dbg_clouds"); // name+"-CORR2D-D"+clt_parameters.disparity,
double[][] dbg_img_combo = new double [dbg_img.length][clustersX*clustersY];
int dbg_w_indx = 16;
for (int i = 0; i < dbg_img_combo.length; i++) {
dbg_img_combo[i] = dbg_img[i].clone();
for (int j = 0; j < dbg_img[i].length; j++) {
if (dbg_img2[dbg_w_indx][j] > 0.0) {
dbg_img_combo[i][j] = dbg_img2[i][j];
}
}
}
(new ShowDoubleFloatArrays()).showArrays(
dbg_img_combo,
clustersX,
clustersY,
true,
"ly_dbg_combo");
return lazy_eye_data;
return lazy_eye_data_final;
}
......
......@@ -2151,6 +2151,7 @@ public class ImageDttCPU {
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_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, // double lma_max_area, // maximal half-area (if > 0.0)
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
......@@ -2202,6 +2203,7 @@ public class ImageDttCPU {
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
1.0, // imgdtt_params.lma_str_scale, // convert lma-generated strength to match previous ones - scale
0.0); // imgdtt_params.lma_str_offset); // convert lma-generated strength to match previous ones - add to result
......@@ -2269,6 +2271,7 @@ public class ImageDttCPU {
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lma_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lma_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lma_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lma_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
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
......@@ -3343,6 +3346,7 @@ public class ImageDttCPU {
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_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
imgdtt_params.lmas_min_min_ac, // minimal of A and C coefficients minimum (measures sharpest point)
imgdtt_params.lmas_max_area, //double lma_max_area, // maximal half-area (if > 0.0)
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
......
......@@ -128,6 +128,7 @@ public class ImageDttParameters {
public double lmas_max_rel_rms = 0.3; // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
public double lmas_min_strength = 0.7; // minimal composite strength (sqrt(average amp squared over absolute RMS)
public double lmas_min_ac = 0.02; // minimal of a and C coefficients maximum (measures sharpest point/line)
public double lmas_min_min_ac = 0.007; // minimal of a and C coefficients minimum (measures sharpest point)
public double lmas_max_area = 0.0; // maximal half-area (if > 0.0)
public boolean lma_gaussian = false; // model correlation maximum as a Gaussian (false - as a parabola)
......@@ -163,10 +164,11 @@ public class ImageDttParameters {
public double lma_rms_diff = 0.003; //
public int lma_num_iter = 10; //
// Filtering and strength calculation
public double lma_max_rel_rms = 0.2; // 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_ac = 0.05; // minimal of a and C coefficients maximum (measures sharpest point/line)
public double lma_max_area = 45.0; // maximal half-area (if > 0.0)
public double lma_min_min_ac = 0.015; // minimal of a and C coefficients minimum (measures sharpest point)
public double lma_max_area = 30.0; //45.0; // maximal half-area (if > 0.0)
public double lma_str_scale = 0.2; // convert lma-generated strength to match previous ones - scale
public double lma_str_offset = 0.05; // convert lma-generated strength to match previous ones - add to result
......@@ -388,6 +390,8 @@ public class ImageDttParameters {
"Discard tile if composite strength (average amplitude over SQRT of RMS) is below");
gd.addNumericField("Minimal max (A,C)", this.lmas_min_ac, 6, 8, "",
"Minimal value of max (A,C) coefficients to keep the tile (measures sharpest point/line correlation maximum)");
gd.addNumericField("Minimal min (A,C)", this.lmas_min_min_ac, 6, 8, "",
"Minimal value of min (A,C) coefficients to keep the tile (measures sharpest point correlation maximum)");
gd.addNumericField("Maximal area", this.lmas_max_area, 6, 8, "sq.pix",
"Maximal product of maximum half-width by half-height, ignore check if <=0");
......@@ -453,6 +457,8 @@ public class ImageDttParameters {
"Discard tile if composite strength (average amplitude over SQRT of RMS) is below");
gd.addNumericField("Minimal max (A,C)", this.lma_min_ac, 6, 8, "",
"Minimal value of max (A,C) coefficients to keep the tile (measures sharpest point/line correlation maximum)");
gd.addNumericField("Minimal min (A,C)", this.lma_min_min_ac, 6, 8, "",
"Minimal value of min (A,C) coefficients to keep the tile (measures sharpest point correlation maximum)");
gd.addNumericField("Maximal area", this.lma_max_area, 6, 8, "sq.pix",
"Maximal product of maximum half-width by half-height, ignore check if <=0");
......@@ -605,6 +611,7 @@ public class ImageDttParameters {
this.lmas_max_rel_rms = gd.getNextNumber();
this.lmas_min_strength = gd.getNextNumber();
this.lmas_min_ac = gd.getNextNumber();
this.lmas_min_min_ac = gd.getNextNumber();
this.lmas_max_area = gd.getNextNumber();
this.lma_gaussian= gd.getNextBoolean();
......@@ -638,6 +645,7 @@ public class ImageDttParameters {
this.lma_max_rel_rms = gd.getNextNumber();
this.lma_min_strength = gd.getNextNumber();
this.lma_min_ac = gd.getNextNumber();
this.lma_min_min_ac = gd.getNextNumber();
this.lma_max_area = gd.getNextNumber();
this.lma_str_scale = gd.getNextNumber();
......@@ -754,6 +762,7 @@ public class ImageDttParameters {
properties.setProperty(prefix+"lmas_max_rel_rms", this.lmas_max_rel_rms +"");
properties.setProperty(prefix+"lmas_min_strength", this.lmas_min_strength +"");
properties.setProperty(prefix+"lmas_min_ac", this.lmas_min_ac +"");
properties.setProperty(prefix+"lmas_min_min_ac", this.lmas_min_min_ac +"");
properties.setProperty(prefix+"lmas_max_area", this.lmas_max_area +"");
properties.setProperty(prefix+"lma_gaussian", this.lma_gaussian +"");
......@@ -788,6 +797,7 @@ public class ImageDttParameters {
properties.setProperty(prefix+"lma_max_rel_rms", this.lma_max_rel_rms +"");
properties.setProperty(prefix+"lma_min_strength", this.lma_min_strength +"");
properties.setProperty(prefix+"lma_min_ac", this.lma_min_ac +"");
properties.setProperty(prefix+"lma_min_min_ac", this.lma_min_min_ac +"");
properties.setProperty(prefix+"lma_max_area", this.lma_max_area +"");
properties.setProperty(prefix+"lma_str_scale", this.lma_str_scale +"");
properties.setProperty(prefix+"lma_str_offset", this.lma_str_offset +"");
......@@ -909,6 +919,7 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"lmas_max_rel_rms")!=null) this.lmas_max_rel_rms=Double.parseDouble(properties.getProperty(prefix+"lmas_max_rel_rms"));
if (properties.getProperty(prefix+"lmas_min_strength")!=null) this.lmas_min_strength=Double.parseDouble(properties.getProperty(prefix+"lmas_min_strength"));
if (properties.getProperty(prefix+"lmas_min_ac")!=null) this.lmas_min_ac=Double.parseDouble(properties.getProperty(prefix+"lmas_min_ac"));
if (properties.getProperty(prefix+"lmas_min_min_ac")!=null) this.lmas_min_min_ac=Double.parseDouble(properties.getProperty(prefix+"lmas_min_min_ac"));
if (properties.getProperty(prefix+"lmas_max_area")!=null) this.lmas_max_area=Double.parseDouble(properties.getProperty(prefix+"lmas_max_area"));
if (properties.getProperty(prefix+"lma_gaussian")!=null) this.lma_gaussian=Boolean.parseBoolean(properties.getProperty(prefix+"lma_gaussian"));
......@@ -941,6 +952,7 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"lma_max_rel_rms")!=null) this.lma_max_rel_rms=Double.parseDouble(properties.getProperty(prefix+"lma_max_rel_rms"));
if (properties.getProperty(prefix+"lma_min_strength")!=null) this.lma_min_strength=Double.parseDouble(properties.getProperty(prefix+"lma_min_strength"));
if (properties.getProperty(prefix+"lma_min_ac")!=null) this.lma_min_ac=Double.parseDouble(properties.getProperty(prefix+"lma_min_ac"));
if (properties.getProperty(prefix+"lma_min_min_ac")!=null) this.lma_min_min_ac=Double.parseDouble(properties.getProperty(prefix+"lma_min_min_ac"));
if (properties.getProperty(prefix+"lma_max_area")!=null) this.lma_max_area=Double.parseDouble(properties.getProperty(prefix+"lma_max_area"));
if (properties.getProperty(prefix+"lma_str_scale")!=null) this.lma_str_scale=Double.parseDouble(properties.getProperty(prefix+"lma_str_scale"));
if (properties.getProperty(prefix+"lma_str_offset")!=null) this.lma_str_offset=Double.parseDouble(properties.getProperty(prefix+"lma_str_offset"));
......@@ -1059,6 +1071,7 @@ public class ImageDttParameters {
idp.lmas_max_rel_rms= this.lmas_max_rel_rms;
idp.lmas_min_strength= this.lmas_min_strength;
idp.lmas_min_ac= this.lmas_min_ac;
idp.lmas_min_min_ac= this.lmas_min_min_ac;
idp.lmas_max_area= this.lmas_max_area;
idp.lma_gaussian = this.lma_gaussian;
......@@ -1091,6 +1104,7 @@ public class ImageDttParameters {
idp.lma_max_rel_rms= this.lma_max_rel_rms;
idp.lma_min_strength= this.lma_min_strength;
idp.lma_min_ac= this.lma_min_ac;
idp.lma_min_min_ac= this.lma_min_min_ac;
idp.lma_max_area= this.lma_max_area;
idp.lma_str_scale= this.lma_str_scale;
idp.lma_str_offset= this.lma_str_offset;
......
......@@ -2319,71 +2319,9 @@ public class QuadCLT extends QuadCLTCPU {
float [][][][] fcorr_td = new float[tilesY][tilesX][][];
float [][][][] fdisp_dist = new float[tilesY][tilesX][][];
float [][][][] fpxpy = new float[tilesY][tilesX][][];
float [][][][] fpxpy_test = new float[tilesY][tilesX][][];
float [][][][] fpxpy_test1 = new float[tilesY][tilesX][][];
float [][][][] fpxpy_test2 = new float[tilesY][tilesX][][];
final double gpu_fat_zero = clt_parameters.getGpuFatZero(isMonochrome());
GPUTileProcessor.TpTask[][] test_tasks0 = image_dtt.clt_aberrations_quad_corr_GPU_test( // USED in LWIR
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
fcorr_td, // final float [][][][] corr_td, // [tilesY][tilesX][pair][4*64] transform domain representation of 6 corr pairs
null, // final float [][][][] corr_combo_td, // [4][tilesY][tilesX][pair][4*64] TD of combo corrs: qud, cross, hor,vert
// each of the top elements may be null to skip particular combo type
fdisp_dist, // final float [][][][] fdisp_dist, // [tilesY][tilesX][cams][4], // disparity derivatives vectors or null
fpxpy_test, // final float [][][][] fpxpy, // [tilesY][tilesX][cams][2], tile {pX,pY}
fpxpy_test1, // final float [][][][] fpxpy, // [tilesY][tilesX][cams][2], tile {pX,pY}
//// Uses quadCLT from gpuQuad
// correlation results - final and partial
null, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [type][tilesY][tilesX] should be set by caller
// types: 0 - selected correlation (product+offset), 1 - sum
null, // clt_corr_partial,// [tilesY][tilesX][quad]color][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [tilesY][tilesX] should be set by caller
// When clt_mismatch is non-zero, no far objects extraction will be attempted
null, // 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, // [8][tilesY][tilesX], only [6][] is needed on input or null - do not calculate
// last 2 - contrast, avg/ "geometric average)
0, // disparity_modes, // disparity_modes, // bit mask of disparity_map slices to calculate/return
null, // final double [][][][] texture_tiles, // compatible with the CPU ones
null, // texture_img, // texture_img, // null or [3][] (RGB) or [4][] RGBA
null, // texture_woi, // texture_woi, // null or generated texture location/size
null, // iclt_fimg, // will return quad images or null to skip, use quadCLT.linearStackToColor
clt_parameters.gpu_corr_scale, //.gpu_corr_scale, // gpu_corr_scale, // 0.75; // reduce GPU-generated correlation values
gpu_fat_zero, // final double gpu_fat_zero, // clt_parameters.getGpuFatZero(is_mono);absolute == 30.0\
clt_parameters.gpu_sigma_r, // 0.9, 1.1
clt_parameters.gpu_sigma_b, // 0.9, 1.1
clt_parameters.gpu_sigma_g, // 0.6, 0.7
clt_parameters.gpu_sigma_m, // = 0.4; // 0.7;
(isMonochrome()? 1.0 : clt_parameters.gpu_sigma_rb_corr), // final double gpu_sigma_rb_corr, // = 0.5; // apply LPF after accumulating R and B correlation before G, monochrome ? 1.0 : gpu_sigma_rb_corr;
clt_parameters.gpu_sigma_corr, // = 0.9;gpu_sigma_corr_m
image_dtt.transform_size - 1, // clt_parameters.gpu_corr_rad, // = transform_size - 1 ?
clt_parameters.corr_red, // +used
clt_parameters.corr_blue, // +used
clt_parameters.max_corr_radius,// 3.9;
clt_parameters.corr_mode, // Correlation mode: 0 - integer max, 1 - center of mass, 2 - polynomial
clt_parameters.min_shot, // 10.0; // Do not adjust for shot noise if lower than
clt_parameters.scale_shot, // 3.0; // scale when dividing by sqrt ( <0 - disable correction)
clt_parameters.diff_sigma, // 5.0;//RMS difference from average to reduce weights (~ 1.0 - 1/255 full scale image)
clt_parameters.diff_threshold, // 5.0; // RMS difference from average to discard channel (~ 1.0 - 1/255 full scale image)
clt_parameters.diff_gauss, // true; // when averaging images, use gaussian around average as weight (false - sharp all/nothing)
clt_parameters.min_agree, // 3.0; // minimal number of channels to agree on a point (real number to work with fuzzy averages)
clt_parameters.dust_remove, // Do not reduce average weight when only one image differes much from the average
geometryCorrection, // final GeometryCorrection geometryCorrection,
null, // final GeometryCorrection geometryCorrection_main, // if not null correct this camera (aux) to the coordinates of the main
clt_parameters.clt_window,
disparity_corr, // final double disparity_corr, // disparity at infinity
clt_parameters.tileX, // final int debug_tileX,
clt_parameters.tileY, // final int debug_tileY,
threadsMax,
debugLevel);
GPUTileProcessor.TpTask[][] test_tasks1 = image_dtt.clt_aberrations_quad_corr_GPU_test( // USED in LWIR
image_dtt.clt_aberrations_quad_corr_GPU( // USED in LWIR
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
......@@ -2393,7 +2331,6 @@ public class QuadCLT extends QuadCLTCPU {
// each of the top elements may be null to skip particular combo type
fdisp_dist, // final float [][][][] fdisp_dist, // [tilesY][tilesX][cams][4], // disparity derivatives vectors or null
fpxpy, // final float [][][][] fpxpy, // [tilesY][tilesX][cams][2], tile {pX,pY}
fpxpy_test2, // final float [][][][] fpxpy_test, // [tilesY][tilesX][cams][2], tile {pX,pY}
//// Uses quadCLT from gpuQuad
// correlation results - final and partial
null, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
......@@ -2439,153 +2376,6 @@ public class QuadCLT extends QuadCLTCPU {
clt_parameters.tileY, // final int debug_tileY,
threadsMax,
debugLevel);
if (dbg_lev > 0) {
double [][] dbg_disp = new double [16][tilesX*tilesY];
double [][] dbg_pxy = new double [8] [tilesX*tilesY];
double [][] dbg_pxy_test = new double [8] [tilesX*tilesY];
double [][] dbg_pxy_diff = new double [8] [tilesX*tilesY];
for (int tY = 0; tY<tilesY; tY++) {
for (int tX = 0; tX<tilesX; tX++) {
int indx = tY * tilesX + tX;
if (fdisp_dist[tY][tX] != null) {
for (int ncam = 0; ncam < 4; ncam++) {
for (int i = 0; i < 4; i++) {
dbg_disp[ncam * 4 + i][indx] = fdisp_dist[tY][tX][ncam][i];
}
for (int i = 0; i < 2; i++) {
dbg_pxy[ncam * 2 + i][indx] = fpxpy[tY][tX][ncam][i];
}
}
} else {
for (int ncam = 0; ncam < 4; ncam++) {
for (int i = 0; i < 4; i++) {
dbg_disp[ncam * 4 + i][indx] = Double.NaN;
}
for (int i = 0; i < 2; i++) {
dbg_pxy[ncam * 2 + i][indx] = Double.NaN;
}
}
}
if (fpxpy_test[tY][tX] != null) {
for (int ncam = 0; ncam < 4; ncam++) {
for (int i = 0; i < 2; i++) {
dbg_pxy_test[ncam * 2 + i][indx] = fpxpy_test[tY][tX][ncam][i];
}
}
} else {
for (int ncam = 0; ncam < 4; ncam++) {
for (int i = 0; i < 2; i++) {
dbg_pxy_test[ncam * 2 + i][indx] = Double.NaN;
}
}
}
}
}
double d2 = 0.0;
for (int n = 0; n < dbg_pxy_diff.length; n++) {
for (int i = 0; i < dbg_pxy_diff[n].length; i++) {
dbg_pxy_diff[n][i] = dbg_pxy[n][i] - dbg_pxy_test[n][i];
if (!Double.isNaN(dbg_pxy_diff[n][i])) {
d2+=dbg_pxy_diff[n][i]*dbg_pxy_diff[n][i];
if (dbg_pxy_diff[n][i] != 0.0) {
System.out.println("dbg_pxy - dbg_pxy_test mismatch @ n ="+n+" tile="+i);
// find tasks
int ty = i / tilesX;
int tx = i % tilesX;
System.out.println("tx= "+tx+", ty = "+ty);
// find index in test_tasks0[0]
int t0_indx = -1;
for (int ti = 0; ti < test_tasks0[0].length; ti++) {
GPUTileProcessor.TpTask t0 = test_tasks0[0][ti];
if ((t0.tx == tx) && (t0.ty == ty)) {
t0_indx = ti;
break;
}
}
int t1_indx = -1;
for (int ti = 0; ti < test_tasks1[0].length; ti++) {
GPUTileProcessor.TpTask t1 = test_tasks1[0][ti];
if ((t1.tx == tx) && (t1.ty == ty)) {
t1_indx = ti;
break;
}
}
System.out.println("tx= "+tx+", ty = "+ty+ " t0_indx="+t0_indx+ " t1_indx="+t1_indx);
System.out.print("");
}
}
}
}
System.out.println("(dbg_pxy - dbg_pxy_test) squared = "+d2);
d2 = 0.0;
for (int tY = 0; tY<tilesY; tY++) {
for (int tX = 0; tX<tilesX; tX++) {
int indx = tY * tilesX + tX;
if (fpxpy[tY][tX] != null) {
for (int ncam = 0; ncam < 4; ncam++) {
for (int i = 0; i < 2; i++) {
double diff = fpxpy[tY][tX][ncam][i] - fpxpy_test2[tY][tX][ncam][i];
if (diff != 0.0) {
System.out.println("fpxpy - fpxpy_test2 mismatch @ tile="+indx+" n ="+ncam+" i="+i);
System.out.print("");
}
d2 += diff*diff;
}
}
}
}
}
System.out.println("(fpxpy - fpxpy_test2) squared = "+d2);
d2 = 0.0;
for (int tY = 0; tY<tilesY; tY++) {
for (int tX = 0; tX<tilesX; tX++) {
int indx = tY * tilesX + tX;
if (fpxpy[tY][tX] != null) {
for (int ncam = 0; ncam < 4; ncam++) {
for (int i = 0; i < 2; i++) {
double diff = fpxpy_test[tY][tX][ncam][i] - fpxpy_test1[tY][tX][ncam][i];
if (diff != 0.0) {
System.out.println("fpxpy_test - fpxpy_test1 mismatch @ tile="+indx+" n ="+ncam+" i="+i);
System.out.print("");
}
d2 += diff*diff;
}
}
}
}
}
System.out.println("(fpxpy_test - fpxpy_test1) squared = "+d2);
(new ShowDoubleFloatArrays()).showArrays(
dbg_pxy,
tilesX,
tilesY,
true,
"fpxpy");
(new ShowDoubleFloatArrays()).showArrays(
dbg_pxy_test,
tilesX,
tilesY,
true,
"fpxpy_test");
(new ShowDoubleFloatArrays()).showArrays(
dbg_pxy_diff,
tilesX,
tilesY,
true,
"fpxpy_diff");
(new ShowDoubleFloatArrays()).showArrays(
dbg_disp,
tilesX,
tilesY,
true,
"fdisp_dist");
}
lazy_eye_data = image_dtt.cltMeasureLazyEyeGPU ( // returns d,s lazy eye parameters
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
......@@ -2599,55 +2389,12 @@ public class QuadCLT extends QuadCLTCPU {
null, // geometryCorrection_main, // final GeometryCorrection geometryCorrection_main, // if not null correct this camera (aux) to the coordinates of the main
disparity_corr, // final double disparity_corr, // disparity at infinity
clt_parameters.tileStep, // final int tileStep, // process tileStep x tileStep cluster of tiles when adjusting lazy eye parameters
clt_parameters.super_radius, // final int super_radius, // 0 - none, 1 - 3x3, 2 - 5x5,
clt_parameters.tileX, // final int debug_tileX,
clt_parameters.tileY, // final int debug_tileY,
threadsMax,
debugLevel);
if (dbg_lev > 0) {
double [][] dbg_disp = new double [16][tilesX*tilesY];
double [][] dbg_pxy = new double [8] [tilesX*tilesY];
for (int tY = 0; tY<tilesY; tY++) {
for (int tX = 0; tX<tilesX; tX++) {
int indx = tY * tilesX + tX;
if (fdisp_dist[tY][tX] != null) {
for (int ncam = 0; ncam < 4; ncam++) {
for (int i = 0; i < 4; i++) {
dbg_disp[ncam * 4 + i][indx] = fdisp_dist[tY][tX][ncam][i];
}
for (int i = 0; i < 2; i++) {
dbg_pxy[ncam * 2 + i][indx] = fpxpy[tY][tX][ncam][i];
}
}
} else {
for (int ncam = 0; ncam < 4; ncam++) {
for (int i = 0; i < 4; i++) {
dbg_disp[ncam * 4 + i][indx] = Double.NaN;
}
for (int i = 0; i < 2; i++) {
dbg_pxy[ncam * 2 + i][indx] = Double.NaN;
}
}
}
}
}
(new ShowDoubleFloatArrays()).showArrays(
dbg_disp,
tilesX,
tilesY,
true,
"fdisp_dist-after");
(new ShowDoubleFloatArrays()).showArrays(
dbg_pxy,
tilesX,
tilesY,
true,
"fpxpy-after");
}
}
scan.setLazyEyeData(lazy_eye_data);
......
......@@ -5894,14 +5894,21 @@ public class QuadCLTCPU {
public void resetExtrinsicCorr( // not used in lwir
CLTParameters clt_parameters)
{
// this.extrinsic_vect = new double [GeometryCorrection.CORR_NAMES.length];
this.extrinsic_vect = null;
if (extrinsic_vect != null) {
extrinsic_vect [GeometryCorrection.CorrVector.IMU_INDEX + 0] = 0.0;
extrinsic_vect [GeometryCorrection.CorrVector.IMU_INDEX + 1] = 0.0;
extrinsic_vect [GeometryCorrection.CorrVector.IMU_INDEX + 2] = 0.0;
extrinsic_vect [GeometryCorrection.CorrVector.IMU_INDEX + 3] = 0.0;
extrinsic_vect [GeometryCorrection.CorrVector.IMU_INDEX + 4] = 0.0;
extrinsic_vect [GeometryCorrection.CorrVector.IMU_INDEX + 5] = 0.0;
}
if (geometryCorrection != null){
geometryCorrection.resetCorrVector();
geometryCorrection.resetCorrVectorERS();
}
if (clt_parameters.fine_corr_apply){
clt_parameters.fine_corr_ignore = false;
}
gpuResetCorrVector();
}
public void cltDisparityScans( // not used in lwir
......@@ -7650,6 +7657,11 @@ public class QuadCLTCPU {
tp.clt_3d_passes.get(combo_scan), // CLTPass3d scan,
"combo_scan-"+combo_scan); //String title)
}
/* tp.showScan(
tp.clt_3d_passes.get(bg_scan), // CLTPass3d scan,
"bg_scan"); //String title)
*/
// combo_scan: normStrength - junk. Is it used?
boolean [] bg_sel = null;
boolean [] bg_use = null;
......@@ -7657,7 +7669,7 @@ public class QuadCLTCPU {
double [] combo_str = null;
boolean [] combo_use = null;
double [] combo_overexp = null;
int num_combo = 0;
int num_combo = 0+0 ;
double [][] filtered_bgnd_disp_strength = tp.getFilteredDisparityStrength(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,// List, first, last - to search for the already tried disparity
bg_scan, // final int measured_scan_index, // will not look at higher scans
......@@ -7669,7 +7681,7 @@ public class QuadCLTCPU {
ImageDtt.DISPARITY_STRENGTH_INDEX, // final int str_index,
null, // final double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
0.5, // clt_parameters.fcorr_inf_diff, // tp.getTrustedCorrelation(),// final double trustedCorrelation,
clt_parameters.fcorr_inf_strength, // final double strength_floor,
clt_parameters.fcorr_inf_strength, // final double strength_floor, 0.12
clt_parameters.inf_str_pow, // final double strength_pow,
clt_parameters.ly_smpl_side, // final int smplSide, // = 2; // Sample size (side of a square)
clt_parameters.ly_smpl_num, // final int smplNum, // = 3; // Number after removing worst (should be >1)
......@@ -7690,6 +7702,7 @@ public class QuadCLTCPU {
double [] bg_overexp = tp.clt_3d_passes.get(bg_scan).getOverexposedFraction();
for (int nTile = 0 ; nTile < bg_use.length; nTile++) {
if (bg_sel[nTile] &&
//// ((filtered_bgnd_disp_strength[1][nTile] > 0.0) || (bg_str[nTile] > 1.25 * clt_parameters.fcorr_inf_strength)) &&
(filtered_bgnd_disp_strength[1][nTile] > 0.0) &&
(bg_str[nTile] > clt_parameters.fcorr_inf_strength) && // 0.13
((bg_overexp == null) || (bg_overexp[nTile] < clt_parameters.lym_overexp)) //1e-4
......@@ -7697,6 +7710,17 @@ public class QuadCLTCPU {
bg_use[nTile] = true;
}
}
/*
// grow bg_use, but inside bg_sel;
int bg_grow = 9; //2*2;
tp.growTiles(
bg_grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
bg_use, // boolean [] tiles,
null); // boolean [] prohibit)
for (int nTile = 0 ; nTile < bg_use.length; nTile++) {
bg_use[nTile] &= bg_sel[nTile];
}
*/
if (true) { //!batch_mode && clt_parameters.show_extrinsic && (debugLevel >-1)) {
String [] dbg_titles = {"fdisp", "fstr", "disp", "str", "overexp","sel","use"};
double [][] ddd = {filtered_bgnd_disp_strength[0],filtered_bgnd_disp_strength[1],null,bg_str,bg_overexp, null, null};
......@@ -7714,7 +7738,7 @@ public class QuadCLTCPU {
"filtered_bgnd_disp_strength",dbg_titles);
}
int num_bg = tp.clt_3d_passes.get(bg_scan).setTileOpDisparity( // other minimal strength?
bg_use, // boolean [] selection,
bg_use, // bg_sel, // bg_use, // boolean [] selection, measure all that can be bg
null); // double [] disparity); // null for 0
// Prepare measurement of combo-scan - remove low strength and what was used for background
......@@ -7756,7 +7780,8 @@ public class QuadCLTCPU {
tp.threadsMax, // maximal number of threads to launch
false, // updateStatus,
debugLevelInner - 1);
if (!batch_mode && clt_parameters.show_extrinsic && (debugLevel >-3)) {
//// if (!batch_mode && clt_parameters.show_extrinsic && (debugLevel >-3))
{
tp.showScan(
tp.clt_3d_passes.get(bg_scan), // CLTPass3d scan, badly filtered?
"bg_scan_post"); //String title)
......@@ -7853,8 +7878,8 @@ public class QuadCLTCPU {
ac = new AlignmentCorrection(this);
}
// iteration steps
// if (!batch_mode && clt_parameters.show_extrinsic && (debugLevel >-1)) {
if (clt_parameters.show_extrinsic && (debugLevel > -1)) { // temporary
if (!batch_mode && clt_parameters.show_extrinsic && (debugLevel >-1)) {
//if (clt_parameters.show_extrinsic && (debugLevel > -1)) { // temporary
tp.showScan(
tp.clt_3d_passes.get(bg_scan), // CLTPass3d scan,
"bg_scan_post"); //String title)
......@@ -7862,6 +7887,9 @@ public class QuadCLTCPU {
tp.clt_3d_passes.get(combo_scan), // CLTPass3d scan,
"combo_scan-"+combo_scan+"_post"); //String title)
}
// tp.showScan(
// tp.clt_3d_passes.get(bg_scan), // CLTPass3d scan,
// "bg_scan_post"); //String title)
double comp_diff = min_sym_update + 1; // (> min_sym_update)
......@@ -7903,6 +7931,7 @@ public class QuadCLTCPU {
boolean apply_extrinsic = (clt_parameters.ly_corr_scale != 0.0);
CLTPass3d scan = tp.clt_3d_passes.get(combo_scan);
// for the second half of runs (always for single run) - limit infinity min/max
ea.showInput(scan.getLazyEyeData(),"first_data");
boolean debug_actual_LY_derivs = debugLevel > 9; // true
......@@ -7997,7 +8026,7 @@ public class QuadCLTCPU {
break;
}
if (update_disp_from_latest) { // true
/*
/**/
CLTMeasure( // perform single pass according to prepared tiles operations and disparity
clt_parameters,
combo_scan,
......@@ -8007,7 +8036,7 @@ public class QuadCLTCPU {
tp.threadsMax, // maximal number of threads to launch
false, // updateStatus,
debugLevelInner - 1);
*/
/**/
CLTMeasureCorr( // perform single pass according to prepared tiles operations and disparity
clt_parameters,
combo_scan,
......@@ -11448,26 +11477,27 @@ public class QuadCLTCPU {
final int debugLevel)
{
double [] parameter_scales = { // multiply delay for each parameter
0.014793657667505566, // 00 10
0.015484017460841183, // 01 10
0.02546712771769517, // 02 10
0.02071573747995167, // 03 10
0.026584237444512468, // 04 10
0.014168012698804967, // 05 10
1.8554483718240792E-4, // 06
2.3170738149889717E-4, // 07
3.713239026512266E-4, // 08
2.544834643007531E-4, // 09
2.5535557646736286E-4, // 10
1.98531249109261E-4, // 11
2.1802727086879284E-4, // 12
8.814346720176489E-1, // 5, // 13 10000x
7.071297501674136E-1, // 5, // 14 10000x
1.306306793587865E-0, // 4, // 15 10000x
2.8929916645453735E-0, // 4, // 16 10000x
2.943408022525927E-0, // 4, // 17 10000x
390.6185365641268}; //4}; // 18 100000x
// delta = 0.01;
0.3, // 0.014793657667505566, // 00 10
0.3, // 0.015484017460841183, // 01 10
0.3, // 0.02546712771769517, // 02 10
0.3, // 0.02071573747995167, // 03 10
0.3, // 0.026584237444512468, // 04 10
0.3, // 0.014168012698804967, // 05 10
2.0, // 1.8554483718240792E-4, // 06
0.3, //2.3170738149889717E-4, // 07
0.3, //3.713239026512266E-4, // 08
0.3, //2.544834643007531E-4, // 09
0.3, // 2.5535557646736286E-4, // 10
0.3, // 1.98531249109261E-4, // 11
0.3, // 2.1802727086879284E-4, // 12
150, // 8.814346720176489E-1, // 5, // 13 10000x
150, // 7.071297501674136E-1, // 5, // 14 10000x
150, // 1.306306793587865E-0, // 4, // 15 10000x
300, // 2.8929916645453735E-0, // 4, // 16 10000x
300, // 2.943408022525927E-0, // 4, // 17 10000x
500.0}; // 390.6185365641268}; //4}; // 18 100000x
// delta = 0.001; // should be 0.001
boolean debug_img = false;
int debugLevelInner = -5;
CLTPass3d scan = tp.clt_3d_passes.get(scanIndex);
GeometryCorrection.CorrVector corr_vector = geometryCorrection.getCorrVector().clone();
......@@ -11490,6 +11520,11 @@ public class QuadCLTCPU {
ly_initial[cluster] = ly[cluster].clone();
}
System.out.println(geometryCorrection.getCorrVector().toString());
if (debug_img) {
ea.showInput(
ly_initial, // double[][] data,
"drv_reference");// String title);
}
for (int npar = 0; npar < num_pars; npar++) {
// perform asymmetric delta
......@@ -11521,6 +11556,26 @@ public class QuadCLTCPU {
false, // updateStatus,
debugLevelInner -1); // - 1); // -5-1
ly = scan.getLazyEyeData();
if (debug_img) {
ea.showInput(
ly, // double[][] data,
"drv_par"+npar);// String title);
}
/* Tested - no difference
CLTMeasureLY( // perform single pass according to prepared tiles operations and disparity // USED in lwir
clt_parameters,
scanIndex, // final int scanIndex,
// only combine and calculate once, next passes keep
// remeasure each pass - target disparity is the same, but vector changes
0, // bg_scan, // (num_iter >0)? -1: bg_scan, // final int bgIndex, // combine, if >=0
tp.threadsMax, // maximal number of threads to launch
false, // updateStatus,
debugLevelInner -1); // - 1); // -5-1
ly = scan.getLazyEyeData();
ea.showInput(
ly, // double[][] data,
"drv_par"+npar+"-B");// String title);
*/
for (int cluster = 0; cluster < clusters; cluster++) if ((ly_initial[cluster] != null) && (ly[cluster]!=null)){
for (int nl = 0; nl < ly_initial[cluster].length; nl++) {
ly_diff[npar][nl][cluster] = rdelta * (ly[cluster][nl] - ly_initial[cluster][nl]);
......
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