Commit 2f7a08d9 authored by Andrey Filippov's avatar Andrey Filippov

intermediate, working, debugging interscene matching

parent ba860911
...@@ -2412,10 +2412,12 @@ public class Correlation2d { ...@@ -2412,10 +2412,12 @@ public class Correlation2d {
} }
public static double [] getMaxXYCm( public static double [] getMaxXYCm(
double [] data, double [] data, // will be modified if fpn_mask != null;
int data_width, // = 2 * transform_size - 1; int data_width, // = 2 * transform_size - 1;
double radius, // 0 - all same weight, > 0 cosine(PI/2*sqrt(dx^2+dy^2)/rad) double radius, // 0 - all same weight, > 0 cosine(PI/2*sqrt(dx^2+dy^2)/rad)
int refine, // re-center window around new maximum. 0 -no refines (single-pass) int refine, // re-center window around new maximum. 0 -no refines (single-pass)
boolean [] fpn_mask,
boolean ignore_border, // only if fpn_mask != null - ignore tile if maximum touches fpn_mask
boolean debug) boolean debug)
{ {
int data_height = data.length/data_width; int data_height = data.length/data_width;
...@@ -2428,8 +2430,29 @@ public class Correlation2d { ...@@ -2428,8 +2430,29 @@ public class Correlation2d {
} }
} }
double mx = data[imax]; double mx = data[imax];
x0 = imax % data_width; int ix0 = imax % data_width;
y0 = imax / data_width; int iy0 = imax / data_width;
x0 = ix0;
y0 = iy0;
// if (fpn_mask != null
if (fpn_mask != null) {
for (int i = 0; i < fpn_mask.length; i++) if (fpn_mask[i]) {
int iy = i / data_width;
int ix = i - iy * data_width;
if (ignore_border) {
if(((ix - ix0) <= 1) && ((ix - ix0) >= -1) && ((iy - iy0) <= 1) && ((iy - iy0) >= -1)) {
return null; // new double[3];
}
}
int ix1 = 2 * ix0 - ix;
if ((ix1 >= 0) && (ix1 < data_width)) {
int iy1 = 2 * iy0 - iy;
if ((iy1 >= 0) && (iy1 < data_height)) {
data[iy1 * data_width + ix1] = 0.0; // zero out symmetrical to fpn mask around integer maximum
}
}
}
}
//calculate as "center of mass" //calculate as "center of mass"
if (radius == 0) { if (radius == 0) {
double s0 = 0, sx=0,sy = 0; double s0 = 0, sx=0,sy = 0;
...@@ -2442,6 +2465,9 @@ public class Correlation2d { ...@@ -2442,6 +2465,9 @@ public class Correlation2d {
s0 += d; s0 += d;
sx += d * x; sx += d * x;
sy += d * y; sy += d * y;
} else if (Double.isNaN(d)) {
System.out.println("NaN in getMaxXYCm()");
return null;
} }
} }
} }
......
...@@ -2461,6 +2461,9 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2461,6 +2461,9 @@ public class ImageDtt extends ImageDttCPU {
// to be converted to float (may be null) // to be converted to float (may be null)
final double [][][] dcorr_tiles, // [tile][pair absolute, sparse][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate final double [][][] dcorr_tiles, // [tile][pair absolute, sparse][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
final double [][] pXpYD, // pXpYD for the reference scene final double [][] pXpYD, // pXpYD for the reference scene
final double [][] fpn_offsets, // null, or per-tile X,Y offset to be blanked
final double fpn_radius, // radius to be blanked around FPN offset center
final boolean fpn_ignore_border, // only if fpn_mask != null - ignore tile if maximum touches fpn_mask
final double[][][] motion_vectors, // [tilesY*tilesX][][] -> [][num_sel_sensors+1 or 2][3] final double[][][] motion_vectors, // [tilesY*tilesX][][] -> [][num_sel_sensors+1 or 2][3]
final boolean run_poly, // polynomial max, if false - centroid final boolean run_poly, // polynomial max, if false - centroid
final boolean use_partial, // find motion vectors for individual pairs, false - for sum only final boolean use_partial, // find motion vectors for individual pairs, false - for sum only
...@@ -2469,8 +2472,10 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2469,8 +2472,10 @@ public class ImageDtt extends ImageDttCPU {
final double td_weight, // mix correlations accumulated in TD with final double td_weight, // mix correlations accumulated in TD with
final double pd_weight, // correlations (post) accumulated in PD final double pd_weight, // correlations (post) accumulated in PD
final boolean td_nopd_only, // only use TD accumulated data if no safe PD is available for the tile. final boolean td_nopd_only, // only use TD accumulated data if no safe PD is available for the tile.
final double min_str, // = 0.25; final double min_str_nofpn, // = 0.25;
final double min_str_sum, // = 0.8; // 5; final double min_str_sum_nofpn,// = 0.8; // 5;
final double min_str_fpn, // = 0.25;
final double min_str_sum_fpn, // = 0.8; // 5;
final int min_neibs, // 2; // minimal number of strong neighbors (> min_str) final int min_neibs, // 2; // minimal number of strong neighbors (> min_str)
final double weight_zero_neibs,// 0.2; // Reduce weight for no-neib (1.0 for all 8) final double weight_zero_neibs,// 0.2; // Reduce weight for no-neib (1.0 for all 8)
final double half_disparity, // 5.0; // Reduce weight twice for this disparity final double half_disparity, // 5.0; // Reduce weight twice for this disparity
...@@ -2573,13 +2578,11 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2573,13 +2578,11 @@ public class ImageDtt extends ImageDttCPU {
final Thread[] threads = newThreadArray(threadsMax); final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
@Override @Override
public void run() { public void run() {
int tileY,tileX,nTile; // , chn; int tileY,tileX,nTile; // , chn;
// for (int iTile = ai.getAndIncrement(); iTile < tp_tasks.length; iTile = ai.getAndIncrement()) {
for (int iCorrTile = ai.getAndIncrement(); iCorrTile < num_tiles; iCorrTile = ai.getAndIncrement()) { for (int iCorrTile = ai.getAndIncrement(); iCorrTile < num_tiles; iCorrTile = ai.getAndIncrement()) {
nTile = (corr_indices[iCorrTile* used_sensors_list.length] >> GPUTileProcessor.CORR_NTILE_SHIFT); nTile = (corr_indices[iCorrTile* used_sensors_list.length] >> GPUTileProcessor.CORR_NTILE_SHIFT);
tileY = nTile / tilesX; tileY = nTile / tilesX;
...@@ -2588,6 +2591,29 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2588,6 +2591,29 @@ public class ImageDtt extends ImageDttCPU {
if (debugTile0) { if (debugTile0) {
System.out.println("clt_process_tl_correlations(): tileX="+tileX+", tileY="+tileY+", nTile="+nTile+", nTile="+nTile); System.out.println("clt_process_tl_correlations(): tileX="+tileX+", tileY="+tileY+", nTile="+nTile+", nTile="+nTile);
} }
// zero FPN right in the fcorr2D so it will go to both processing and display
boolean [] fpn_mask = null;
double min_str = min_str_nofpn; // higher threshold when FPN is possible
double min_str_sum = min_str_sum_nofpn; // higher threshold when FPN is possible
if ((fpn_offsets != null) && (fpn_offsets[nTile] != null)) {
double fpn_x = transform_size - 1 - fpn_offsets[nTile][0]; // 0 -> 7.0
double fpn_y = transform_size - 1 - fpn_offsets[nTile][1]; // 0 -> 7.0
int min_x = (int) Math.max(Math.round(fpn_x - fpn_radius),0);
int max_x = (int) Math.min(Math.round(fpn_x + fpn_radius), corr_size-1);
int min_y = (int) Math.max(Math.round(fpn_y - fpn_radius),0);
int max_y = (int) Math.min(Math.round(fpn_y + fpn_radius), corr_size-1);
int fcorr2D_indx = (iCorrTile + 1)* used_sensors_list.length -1; // last in each group - sum in TD
fpn_mask = new boolean[fcorr2D[fcorr2D_indx].length];
for (int iy = min_y; iy <= max_y; iy++) {
for (int ix = min_x; ix <= max_x; ix++) {
int indx = iy * corr_size + ix;
fcorr2D[fcorr2D_indx][indx] = 0;
fpn_mask[indx] = true;
}
}
min_str = min_str_fpn;
min_str_sum = min_str_sum_fpn;
}
double [][] corrs = new double [corrs_len + extra_len][]; double [][] corrs = new double [corrs_len + extra_len][];
// copy correlation tiles from the GPU's floating point arrays // copy correlation tiles from the GPU's floating point arrays
double scale = 1.0/getNumSensors(); double scale = 1.0/getNumSensors();
...@@ -2617,7 +2643,7 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2617,7 +2643,7 @@ public class ImageDtt extends ImageDttCPU {
} }
} }
if (dcorr_tiles != null) { if (dcorr_tiles != null) { // This will be visualized
int index_es = getNumSensors() + extra_len; int index_es = getNumSensors() + extra_len;
dcorr_tiles[iCorrTile] = new double[getNumSensors()+1 + extra_len][]; dcorr_tiles[iCorrTile] = new double[getNumSensors()+1 + extra_len][];
if (extra_sum) { if (extra_sum) {
...@@ -2651,6 +2677,8 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2651,6 +2677,8 @@ public class ImageDtt extends ImageDttCPU {
corr_size, // int data_width, // = 2 * transform_size - 1; corr_size, // int data_width, // = 2 * transform_size - 1;
centroid_radius, // double radius, // 0 - all same weight, > 0 cosine(PI/2*sqrt(dx^2+dy^2)/rad) centroid_radius, // double radius, // 0 - all same weight, > 0 cosine(PI/2*sqrt(dx^2+dy^2)/rad)
n_recenter, // int refine, // re-center window around new maximum. 0 -no refines (single-pass) n_recenter, // int refine, // re-center window around new maximum. 0 -no refines (single-pass)
null, // boolean [] fpn_mask,
false, // boolean ignore_border, // only if fpn_mask != null - ignore tile if maximum touches fpn_mask
false); // boolean debug) false); // boolean debug)
if (motion_vectors[nTile][nsens] != null) { if (motion_vectors[nTile][nsens] != null) {
if (motion_vectors[nTile][nsens][2] < min_vstr) { if (motion_vectors[nTile][nsens][2] < min_vstr) {
...@@ -2668,6 +2696,8 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2668,6 +2696,8 @@ public class ImageDtt extends ImageDttCPU {
corr_size, // int data_width, // = 2 * transform_size - 1; corr_size, // int data_width, // = 2 * transform_size - 1;
centroid_radius, // double radius, // 0 - all same weight, > 0 cosine(PI/2*sqrt(dx^2+dy^2)/rad) centroid_radius, // double radius, // 0 - all same weight, > 0 cosine(PI/2*sqrt(dx^2+dy^2)/rad)
n_recenter, // int refine, // re-center window around new maximum. 0 -no refines (single-pass) n_recenter, // int refine, // re-center window around new maximum. 0 -no refines (single-pass)
null, // boolean [] fpn_mask,
false, // boolean ignore_border, // only if fpn_mask != null - ignore tile if maximum touches fpn_mask
false); // boolean debug) false); // boolean debug)
if (mv_pd != null) { if (mv_pd != null) {
if (mv_pd[2] < min_str) { if (mv_pd[2] < min_str) {
...@@ -2683,6 +2713,8 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2683,6 +2713,8 @@ public class ImageDtt extends ImageDttCPU {
corr_size, // int data_width, // = 2 * transform_size - 1; corr_size, // int data_width, // = 2 * transform_size - 1;
centroid_radius, // double radius, // 0 - all same weight, > 0 cosine(PI/2*sqrt(dx^2+dy^2)/rad) centroid_radius, // double radius, // 0 - all same weight, > 0 cosine(PI/2*sqrt(dx^2+dy^2)/rad)
n_recenter, // int refine, // re-center window around new maximum. 0 -no refines (single-pass) n_recenter, // int refine, // re-center window around new maximum. 0 -no refines (single-pass)
fpn_mask, // boolean [] fpn_mask,
false, // boolean ignore_border, // only if fpn_mask != null - ignore tile if maximum touches fpn_mask
false); // boolean debug) false); // boolean debug)
if (mv_td != null) { if (mv_td != null) {
if (mv_td[2] < min_str_sum) { if (mv_td[2] < min_str_sum) {
...@@ -2735,6 +2767,9 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2735,6 +2767,9 @@ public class ImageDtt extends ImageDttCPU {
double l2; double l2;
TileNeibs tn = new TileNeibs(tilesX,tilesY); TileNeibs tn = new TileNeibs(tilesX,tilesY);
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) { for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) {
// if (nTile==162) {
// System.out.println("nTile="+nTile);
// }
if ((mv[nTile] != null) && (pXpYD[nTile] != null)) { if ((mv[nTile] != null) && (pXpYD[nTile] != null)) {
int num_neibs=0; int num_neibs=0;
double sx=0.0, sy=0.0; double sx=0.0, sy=0.0;
...@@ -2785,9 +2820,12 @@ public class ImageDtt extends ImageDttCPU { ...@@ -2785,9 +2820,12 @@ public class ImageDtt extends ImageDttCPU {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
@Override @Override
public void run() { public void run() {
double l2; // double l2;
TileNeibs tn = new TileNeibs(tilesX,tilesY); // TileNeibs tn = new TileNeibs(tilesX,tilesY);
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) { for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) {
// if (nTile==162) {
// System.out.println("nTile="+nTile);
// }
if ((mv[nTile] != null) && (pXpYD[nTile] != null)) { if ((mv[nTile] != null) && (pXpYD[nTile] != null)) {
if (mv[nTile][2] <= 0) { if (mv[nTile][2] <= 0) {
mv[nTile] = null; mv[nTile] = null;
......
...@@ -457,6 +457,36 @@ public class QuadCLTCPU { ...@@ -457,6 +457,36 @@ public class QuadCLTCPU {
silent); silent);
} }
public boolean [] getReliableTiles(
double min_strength,
boolean needs_lma) {
double [][] main_dsi = readDsiMain();
if (main_dsi == null) {
return null;
}
double [] disparity_lma = main_dsi[isAux()?TwoQuadCLT.DSI_DISPARITY_AUX_LMA:TwoQuadCLT.DSI_DISPARITY_MAIN_LMA];
double [] strength = main_dsi[isAux()?TwoQuadCLT.DSI_STRENGTH_AUX:TwoQuadCLT.DSI_STRENGTH_MAIN];
if ((strength == null) || (needs_lma && (disparity_lma == null) )) {
return null;
}
boolean [] reliable = new boolean [strength.length];
for (int i = 0; i < reliable.length; i++) {
reliable[i] = (strength[i] >= min_strength) && (!needs_lma || !Double.isNaN(disparity_lma[i]));
}
return reliable;
}
public double [][] readDsiMain(){
double [][] main_dsi = new double [TwoQuadCLT.DSI_SLICES.length][];
int slices = restoreDSI(
DSI_SUFFIXES[INDEX_DSI_MAIN], // String suffix, // "-DSI_COMBO", "-DSI_MAIN" (DSI_COMBO_SUFFIX, DSI_MAIN_SUFFIX)
main_dsi,
true); // boolean silent)
if (slices < 3) {
return null;
}
return main_dsi;
}
public int restoreDSI( public int restoreDSI(
String suffix, // "-DSI_COMBO", "-DSI_MAIN" (DSI_COMBO_SUFFIX, DSI_MAIN_SUFFIX) String suffix, // "-DSI_COMBO", "-DSI_MAIN" (DSI_COMBO_SUFFIX, DSI_MAIN_SUFFIX)
double [][] dsi, double [][] dsi,
......
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