Commit 9a970304 authored by Andrey Filippov's avatar Andrey Filippov

Improving basic depth map generation

parent f801b9b5
...@@ -59,6 +59,7 @@ public class CLTPass3d{ ...@@ -59,6 +59,7 @@ public class CLTPass3d{
private double [] bgTileStrength = null; private double [] bgTileStrength = null;
private boolean [] border_tiles = null; // these are border tiles, zero out alpha private boolean [] border_tiles = null; // these are border tiles, zero out alpha
private boolean [] selected = null; // which tiles are selected for this layer private boolean [] selected = null; // which tiles are selected for this layer
boolean [] has_lma = null; // which tiles are measured with LMA (reliable strength)
public double [][][][] texture_tiles; public double [][][][] texture_tiles;
// texture_selection is only used for the GPU and if not null means it is for the GPU // texture_selection is only used for the GPU and if not null means it is for the GPU
public boolean [] texture_selection = null; // use by the GPU to set texture to generate public boolean [] texture_selection = null; // use by the GPU to set texture to generate
...@@ -70,6 +71,7 @@ public class CLTPass3d{ ...@@ -70,6 +71,7 @@ public class CLTPass3d{
public Rectangle texture_bounds; // in tiles, not pixels ! public Rectangle texture_bounds; // in tiles, not pixels !
public int dbg_index; public int dbg_index;
public int disparity_index = ImageDtt.DISPARITY_INDEX_CM; // may also be ImageDtt.DISPARITY_INDEX_POLY public int disparity_index = ImageDtt.DISPARITY_INDEX_CM; // may also be ImageDtt.DISPARITY_INDEX_POLY
public int lma_disparity_index = ImageDtt.DISPARITY_INDEX_POLY; // set to -1 to ignore and always use just CM (also applies to lma_strength - next)
public double [][] tiles_RBGA = null; public double [][] tiles_RBGA = null;
SuperTiles superTiles = null; SuperTiles superTiles = null;
...@@ -362,6 +364,15 @@ public class CLTPass3d{ ...@@ -362,6 +364,15 @@ public class CLTPass3d{
this.border_tiles = border_tiles; this.border_tiles = border_tiles;
} }
public boolean [] getLMA() {
if (has_lma == null) {
has_lma = hasLMADefined();
}
return has_lma;
}
public void setLMA(boolean [] has_lma) {// use for combo tiles
this.has_lma = has_lma;
}
public void fixNaNDisparity() public void fixNaNDisparity()
{ {
...@@ -599,24 +610,31 @@ public class CLTPass3d{ ...@@ -599,24 +610,31 @@ public class CLTPass3d{
// methods to "condition" measured disparity values // methods to "condition" measured disparity values
public void conditionDisparity() public void conditionDisparity()
{ {
/*
conditionDisparity(disparity_index); conditionDisparity(disparity_index);
} }
public void conditionDisparity(int disparity_index) public void conditionDisparity(int disparity_index) // only called from above
{ {
*/
int tilesX = tileProcessor.getTilesX(); int tilesX = tileProcessor.getTilesX();
int tilesY = tileProcessor.getTilesY(); int tilesY = tileProcessor.getTilesY();
double corr_magic_scale = tileProcessor.getMagicScale(); double corr_magic_scale = tileProcessor.getMagicScale();
double corr_magic_scale_LMA = 1.0;
// int lma_disparity_index = ImageDtt.DISPARITY_INDEX_POLY;
this.disparity_index = disparity_index; // this.disparity_index = disparity_index;
calc_disparity = new double[tilesY*tilesX]; calc_disparity = new double[tilesY*tilesX];
calc_disparity_hor = new double[tilesY*tilesX]; calc_disparity_hor = new double[tilesY*tilesX];
calc_disparity_vert = new double[tilesY*tilesX]; calc_disparity_vert = new double[tilesY*tilesX];
double [] lma_disparity = (lma_disparity_index >= 0) ? disparity_map[lma_disparity_index] : null;
for (int i = 0; i < tilesY; i++){ for (int i = 0; i < tilesY; i++){
for (int j = 0; j < tilesX; j++){ for (int j = 0; j < tilesX; j++){
int indx = i * tilesX + j; int indx = i * tilesX + j;
if ((lma_disparity != null) && !Double.isNaN(lma_disparity[indx])) {
calc_disparity[indx] = lma_disparity[indx]/corr_magic_scale_LMA + this.disparity[i][j];
} else {
calc_disparity[indx] = disparity_map[disparity_index][indx]/corr_magic_scale + this.disparity[i][j]; calc_disparity[indx] = disparity_map[disparity_index][indx]/corr_magic_scale + this.disparity[i][j];
}
calc_disparity_hor[indx] = disparity_map[ImageDtt.DISPARITY_INDEX_HOR][indx]/corr_magic_scale + this.disparity[i][j]; calc_disparity_hor[indx] = disparity_map[ImageDtt.DISPARITY_INDEX_HOR][indx]/corr_magic_scale + this.disparity[i][j];
calc_disparity_vert[indx] = disparity_map[ImageDtt.DISPARITY_INDEX_VERT][indx]/corr_magic_scale + this.disparity[i][j]; calc_disparity_vert[indx] = disparity_map[ImageDtt.DISPARITY_INDEX_VERT][indx]/corr_magic_scale + this.disparity[i][j];
} }
...@@ -624,6 +642,28 @@ public class CLTPass3d{ ...@@ -624,6 +642,28 @@ public class CLTPass3d{
calc_disparity_combo = calc_disparity.clone(); // for now - just clone, can be modified separately and combined with hor/vert calc_disparity_combo = calc_disparity.clone(); // for now - just clone, can be modified separately and combined with hor/vert
} }
public boolean [] hasLMADefined(){ // will try not to create this.has_lma
if (disparity_map == null) {
if (has_lma==null) {
return null;
} else {
return has_lma;
}
}
int tilesX = tileProcessor.getTilesX();
int tilesY = tileProcessor.getTilesY();
double [] lma_disparity = (lma_disparity_index >= 0) ? disparity_map[lma_disparity_index] : null;
boolean [] lma_defined = new boolean[tilesX * tilesY];
if (lma_disparity != null) {
for (int i = 0; i < lma_disparity.length; i++) {
lma_defined[i] = !Double.isNaN(lma_disparity[i]);
}
}
return lma_defined;
}
// bypassing calculations // bypassing calculations
public void setCalcDisparityStrength( public void setCalcDisparityStrength(
double [] disparity, double [] disparity,
...@@ -644,7 +684,7 @@ public class CLTPass3d{ ...@@ -644,7 +684,7 @@ public class CLTPass3d{
* *
* Replace weak by a weighted average of non-weak. If there are none - use weak ones, including this one too. * Replace weak by a weighted average of non-weak. If there are none - use weak ones, including this one too.
*/ */
public boolean[] replaceWeakOutliers( public boolean[] replaceWeakOutliers( // does not replace tiles with LMA available, busts LMA-defined strengths when averaging
final boolean [] selection, final boolean [] selection,
final double weakStrength, // strength to be considered weak, subject to this replacement final double weakStrength, // strength to be considered weak, subject to this replacement
final double maxDiff, final double maxDiff,
...@@ -654,6 +694,7 @@ public class CLTPass3d{ ...@@ -654,6 +694,7 @@ public class CLTPass3d{
final double disparityNear, final double disparityNear,
final int debugLevel) final int debugLevel)
{ {
final double scale_strength_lma = 5.0; // increase LMA-defined strength during averaging
final int tilesX = tileProcessor.getTilesX(); final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY(); final int tilesY = tileProcessor.getTilesY();
...@@ -663,6 +704,8 @@ public class CLTPass3d{ ...@@ -663,6 +704,8 @@ public class CLTPass3d{
final int [] dirs = dirs8; final int [] dirs = dirs8;
final double [] disparity = getDisparity(0); final double [] disparity = getDisparity(0);
final double [] strength = getStrength(); final double [] strength = getStrength();
final boolean [] has_lma = getLMA();
final double absMinDisparity = 0.5 * disparityFar; // adjust? below this is definitely wrong (weak) final double absMinDisparity = 0.5 * disparityFar; // adjust? below this is definitely wrong (weak)
final double absMaxDisparity = 1.5 * disparityNear; // change? final double absMaxDisparity = 1.5 * disparityNear; // change?
final int dbg_nTile = (debugLevel > 0) ? 43493: -1; // x=77,y=134; // 42228; // x = 108, y = 130 46462; // 41545; final int dbg_nTile = (debugLevel > 0) ? 43493: -1; // x=77,y=134; // 42228; // x = 108, y = 130 46462; // 41545;
...@@ -674,7 +717,7 @@ public class CLTPass3d{ ...@@ -674,7 +717,7 @@ public class CLTPass3d{
@Override @Override
public void run() { public void run() {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) { for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
if (((strength[nTile] < weakStrength) || if (((!has_lma[nTile] && (strength[nTile] < weakStrength)) ||
(disparity[nTile] < absMinDisparity) || (disparity[nTile] < absMinDisparity) ||
(disparity[nTile] > absMaxDisparity))&& ((selection == null) || selection[nTile])) { (disparity[nTile] > absMaxDisparity))&& ((selection == null) || selection[nTile])) {
if (nTile == dbg_nTile){ if (nTile == dbg_nTile){
...@@ -698,6 +741,9 @@ public class CLTPass3d{ ...@@ -698,6 +741,9 @@ public class CLTPass3d{
(disparity[nTile1] >= disparityFar) && // don't count on too near/too far for averaging (disparity[nTile1] >= disparityFar) && // don't count on too near/too far for averaging
(disparity[nTile1] <= disparityNear)){ (disparity[nTile1] <= disparityNear)){
double w = strength[nTile1]; double w = strength[nTile1];
if (has_lma[nTile1]) {
w *= scale_strength_lma;
}
sw += w; sw += w;
sd += w * disparity[nTile1]; sd += w * disparity[nTile1];
hasNeighbors = true; hasNeighbors = true;
...@@ -742,12 +788,18 @@ public class CLTPass3d{ ...@@ -742,12 +788,18 @@ public class CLTPass3d{
int nTile1 = nTile + dirs[dir]; int nTile1 = nTile + dirs[dir];
if (!weakOutliers[nTile1] && ((selection == null) || selection[nTile1 ]) ) { if (!weakOutliers[nTile1] && ((selection == null) || selection[nTile1 ]) ) {
double w = strength[nTile1]; double w = strength[nTile1];
if (has_lma[nTile1]) {
w *= scale_strength_lma;
}
sw += w; sw += w;
sd += w * src_disparity[nTile1]; sd += w * src_disparity[nTile1];
} }
} }
if (sw == 0) { // Nothing strong around - repeat with weak and this one too. if (sw == 0) { // Nothing strong around - repeat with weak and this one too.
double w = strength[nTile]; double w = strength[nTile];
if (has_lma[nTile]) {
w *= scale_strength_lma;
}
if (!Double.isNaN( src_disparity[nTile])) { if (!Double.isNaN( src_disparity[nTile])) {
sw += w; sw += w;
sd += w * src_disparity[nTile]; sd += w * src_disparity[nTile];
...@@ -756,6 +808,9 @@ public class CLTPass3d{ ...@@ -756,6 +808,9 @@ public class CLTPass3d{
int nTile1 = nTile + dirs[dir]; int nTile1 = nTile + dirs[dir];
if ((selection == null) || selection[nTile1 ]) { if ((selection == null) || selection[nTile1 ]) {
w = strength[nTile1]; w = strength[nTile1];
if (has_lma[nTile1]) {
w *= scale_strength_lma;
}
if (!Double.isNaN( src_disparity[nTile1])) { if (!Double.isNaN( src_disparity[nTile1])) {
sw += w; sw += w;
sd += w * src_disparity[nTile1]; sd += w * src_disparity[nTile1];
......
...@@ -79,7 +79,7 @@ public class Corr2dLMA { ...@@ -79,7 +79,7 @@ public class Corr2dLMA {
/// final static int NUM_CAMS = 4; // not all have to be used, so it is maximal number of cameras /// final static int NUM_CAMS = 4; // not all have to be used, so it is maximal number of cameras
/// final static int NUM_PAIRS = NUM_CAMS* (NUM_CAMS -1)/2; // number of possible pairs /// final static int NUM_PAIRS = NUM_CAMS* (NUM_CAMS -1)/2; // number of possible pairs
final static int NTILE0 = 0; final static int NTILE0 = 0;
final static int DISP_INDEX = 0; // common/average disparity final static int DISP_INDEX = 0; // common/average disparity (negative!)
final static int A_INDEX = 1; // A*(x-x0)^2 final static int A_INDEX = 1; // A*(x-x0)^2
final static int B_INDEX = 2; // 2*B*(x-x0)*(y-y0) final static int B_INDEX = 2; // 2*B*(x-x0)*(y-y0)
final static int CMA_INDEX = 3; // C*(y-y0)^2, encode C-A final static int CMA_INDEX = 3; // C*(y-y0)^2, encode C-A
...@@ -2116,6 +2116,7 @@ public class Corr2dLMA { ...@@ -2116,6 +2116,7 @@ public class Corr2dLMA {
public double [][] lmaDisparityStrength( public double [][] lmaDisparityStrength(
double lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
double lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) 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_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_max_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
...@@ -2136,6 +2137,9 @@ public class Corr2dLMA { ...@@ -2136,6 +2137,9 @@ public class Corr2dLMA {
if (maxmin_amp[tile][1] < 0.0) { if (maxmin_amp[tile][1] < 0.0) {
continue; // inverse maximum - discard tile continue; // inverse maximum - discard tile
} }
if ((maxmin_amp[tile][1]/maxmin_amp[tile][0]) < lmas_min_amp) {
continue; // inverse maximum - discard tile
}
double avg = 0.50*(maxmin_amp[tile][0]+maxmin_amp[tile][1]); // max_min[1] can be negative - filter it out? double avg = 0.50*(maxmin_amp[tile][0]+maxmin_amp[tile][1]); // max_min[1] can be negative - filter it out?
double rrms = rms[tile]/avg; double rrms = rms[tile]/avg;
if (((lma_max_rel_rms > 0.0) && (rrms > lma_max_rel_rms)) || if (((lma_max_rel_rms > 0.0) && (rrms > lma_max_rel_rms)) ||
......
...@@ -3422,6 +3422,7 @@ public class Correlation2d { ...@@ -3422,6 +3422,7 @@ public class Correlation2d {
// double [][] ds = lma.getDisparityStrength(); // double [][] ds = lma.getDisparityStrength();
ds = lma.lmaDisparityStrength( ds = lma.lmaDisparityStrength(
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) 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_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_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
...@@ -3521,6 +3522,7 @@ public class Correlation2d { ...@@ -3521,6 +3522,7 @@ public class Correlation2d {
} }
// double [][] ds = lma.getDisparityStrength(); // double [][] ds = lma.getDisparityStrength();
ds = lma.lmaDisparityStrength( ds = lma.lmaDisparityStrength(
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) 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_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_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
...@@ -3858,6 +3860,7 @@ public class Correlation2d { ...@@ -3858,6 +3860,7 @@ public class Correlation2d {
double [][] dispStr = lma.lmaDisparityStrength( //TODO: add parameter to filter out negative minimums ? double [][] dispStr = lma.lmaDisparityStrength( //TODO: add parameter to filter out negative minimums ?
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
......
...@@ -268,6 +268,7 @@ public class DisparityProcessor { ...@@ -268,6 +268,7 @@ public class DisparityProcessor {
final double [] disparity, // current disparity value final double [] disparity, // current disparity value
final double [] measured_disparity, // measured disparity final double [] measured_disparity, // measured disparity
final double [] strength, final double [] strength,
final boolean [] has_lma,
final double [] hor_disparity, // not yet used final double [] hor_disparity, // not yet used
final double [] hor_strength, // not yet used final double [] hor_strength, // not yet used
final boolean [] selected, final boolean [] selected,
...@@ -276,6 +277,7 @@ public class DisparityProcessor { ...@@ -276,6 +277,7 @@ public class DisparityProcessor {
final int threadsMax, // maximal number of threads to launch final int threadsMax, // maximal number of threads to launch
final int debugLevel) final int debugLevel)
{ {
final double scale_strength_lma = 5.0; // increase LMA-defined strength during averaging
final int dbg_tile = -1; // 28643; // x=131, y=88 final int dbg_tile = -1; // 28643; // x=131, y=88
ShowDoubleFloatArrays sdfa_instance = null; ShowDoubleFloatArrays sdfa_instance = null;
if (debugLevel > 0) sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging? if (debugLevel > 0) sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging?
...@@ -382,7 +384,12 @@ public class DisparityProcessor { ...@@ -382,7 +384,12 @@ public class DisparityProcessor {
// } // }
// calculate pull by the measured disparity // calculate pull by the measured disparity
double disparity_diff = (measured_disparity[nTile] - disp_data[0][nTile]); double disparity_diff = (measured_disparity[nTile] - disp_data[0][nTile]);
double eff_strength = ((border != null) && border[nTile])? 0.0: (strength[nTile] - clt_parameters.tiStrengthOffset); double str = strength[nTile];
if (has_lma[nTile]) {
str *= scale_strength_lma;
}
// double eff_strength = ((border != null) && border[nTile])? 0.0: (strength[nTile] - clt_parameters.tiStrengthOffset);
double eff_strength = ((border != null) && border[nTile])? 0.0: (str - clt_parameters.tiStrengthOffset);
if (eff_strength < 0) eff_strength = 0; if (eff_strength < 0) eff_strength = 0;
double disparity_pull = eff_strength; double disparity_pull = eff_strength;
// if (tileY == 89){ // if (tileY == 89){
......
...@@ -3291,6 +3291,7 @@ public class ImageDtt extends ImageDttCPU { ...@@ -3291,6 +3291,7 @@ public class ImageDtt extends ImageDttCPU {
if (dbg_img != null) dbg_img[1][nclust] = 1.0; if (dbg_img != null) dbg_img[1][nclust] = 1.0;
// was for single tile // was for single tile
disp_str = lma2.lmaDisparityStrength( disp_str = lma2.lmaDisparityStrength(
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
...@@ -3583,31 +3584,10 @@ public class ImageDtt extends ImageDttCPU { ...@@ -3583,31 +3584,10 @@ public class ImageDtt extends ImageDttCPU {
tileX, // int tileX, // just for debug output tileX, // int tileX, // just for debug output
tileY); // int tileY 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) { if (lma2 != null) {
// was for single tile // was for single tile
disp_str = lma2.lmaDisparityStrength( disp_str = lma2.lmaDisparityStrength(
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
......
...@@ -2305,6 +2305,7 @@ public class ImageDttCPU { ...@@ -2305,6 +2305,7 @@ public class ImageDttCPU {
} }
if (lma2 != null) { if (lma2 != null) {
disp_str[cTile] = lma2.lmaDisparityStrength( disp_str[cTile] = lma2.lmaDisparityStrength(
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
...@@ -2357,6 +2358,7 @@ public class ImageDttCPU { ...@@ -2357,6 +2358,7 @@ public class ImageDttCPU {
double [][] ddnd = lma2.getDdNd(); double [][] ddnd = lma2.getDdNd();
double [] stats = lma2.getStats(num_good_tiles); double [] stats = lma2.getStats(num_good_tiles);
double [][] lma_ds = lma2.lmaDisparityStrength( double [][] lma_ds = lma2.lmaDisparityStrength(
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) 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_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_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
...@@ -2425,6 +2427,7 @@ public class ImageDttCPU { ...@@ -2425,6 +2427,7 @@ public class ImageDttCPU {
// just for debugging, can be removed // just for debugging, can be removed
if (disparity_map != null){ if (disparity_map != null){
double [][] lma2_ds = lma2.lmaDisparityStrength( double [][] lma2_ds = lma2.lmaDisparityStrength(
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) 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_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_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
...@@ -3107,6 +3110,7 @@ public class ImageDttCPU { ...@@ -3107,6 +3110,7 @@ public class ImageDttCPU {
if (lma2 != null) { if (lma2 != null) {
dbg_num_good_lma ++; dbg_num_good_lma ++;
disp_str[cTile] = lma2.lmaDisparityStrength( disp_str[cTile] = lma2.lmaDisparityStrength(
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
...@@ -3289,6 +3293,7 @@ public class ImageDttCPU { ...@@ -3289,6 +3293,7 @@ public class ImageDttCPU {
double [][] ddnd = lma2.getDdNd(); double [][] ddnd = lma2.getDdNd();
double [] stats = lma2.getStats(num_good_tiles); double [] stats = lma2.getStats(num_good_tiles);
double [][] lma_ds = lma2.lmaDisparityStrength( double [][] lma_ds = lma2.lmaDisparityStrength(
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lma_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) 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_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_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
...@@ -4141,17 +4146,9 @@ public class ImageDttCPU { ...@@ -4141,17 +4146,9 @@ public class ImageDttCPU {
} }
} }
// calculate CM maximums for all mixed channels // calculate CM maximums for all mixed channels
// First get integer correlation center, relative to the center // First get integer correlation center, relative to the center
double [] corr_combo_max = corr_combo[Correlation2d.MCORR_COMB.ALL.ordinal()]; double [] corr_combo_max = corr_combo[Correlation2d.MCORR_COMB.ALL.ordinal()];
/*
int [] ixy = corr2d.getMaxXYInt( // find integer pair or null if below threshold
strip_combo, // double [] data,
true, // boolean axis_only,
imgdtt_params.min_corr, // double minMax, // minimal value to consider (at integer location, not interpolated)
tile_lma_debug_level > 0); // boolean debug);
*/
if (debugTile0) { if (debugTile0) {
System.out.println("tileX = "+tileX+", tileY = "+tileY); System.out.println("tileX = "+tileX+", tileY = "+tileY);
} }
...@@ -4175,6 +4172,7 @@ public class ImageDttCPU { ...@@ -4175,6 +4172,7 @@ public class ImageDttCPU {
// disp_str[1] = strip_combo[ixy[0]+transform_size-1]; // strength at integer max on axis // disp_str[1] = strip_combo[ixy[0]+transform_size-1]; // strength at integer max on axis
disp_str = disp_str_int; disp_str = disp_str_int;
disparity_map[DISPARITY_INDEX_INT][tIndex] = disp_str[0]; // -ixy[0]; disparity_map[DISPARITY_INDEX_INT][tIndex] = disp_str[0]; // -ixy[0];
disparity_map[DISPARITY_INDEX_CM+1][tIndex] = disp_str[1]; // reusing old fine-corr
disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] = disp_str[1]; disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] = disp_str[1];
if (Double.isNaN(disparity_map[DISPARITY_STRENGTH_INDEX][tIndex])) { if (Double.isNaN(disparity_map[DISPARITY_STRENGTH_INDEX][tIndex])) {
...@@ -4190,6 +4188,7 @@ public class ImageDttCPU { ...@@ -4190,6 +4188,7 @@ public class ImageDttCPU {
(tile_lma_debug_level > 0)); // boolean debug); (tile_lma_debug_level > 0)); // boolean debug);
if (corr_stat != null) { if (corr_stat != null) {
disparity_map[DISPARITY_INDEX_CM][tIndex] = -corr_stat[0]; // -ixy[0]; disparity_map[DISPARITY_INDEX_CM][tIndex] = -corr_stat[0]; // -ixy[0];
disparity_map[DISPARITY_INDEX_CM+1][tIndex] = corr_stat[1]; // reusing old fine-corr
disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] = corr_stat[1]; disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] = corr_stat[1];
} }
} }
...@@ -4228,7 +4227,8 @@ public class ImageDttCPU { ...@@ -4228,7 +4227,8 @@ public class ImageDttCPU {
if (corr_stat != null) { if (corr_stat != null) {
// skipping DISPARITY_VARIATIONS_INDEX - it was not used // skipping DISPARITY_VARIATIONS_INDEX - it was not used
disp_str[0] = -corr_stat[0]; disp_str[0] = -corr_stat[0];
disparity_map[DISPARITY_INDEX_CM][tIndex] = disp_str[0]; // disparity is negative X disp_str[1] = corr_stat[1];
// disparity_map[DISPARITY_INDEX_CM][tIndex] = disp_str[0]; // disparity is negative X. Already done above
if (tile_lma_debug_level > 0) { if (tile_lma_debug_level > 0) {
System.out.println("Will run getMaxXSOrtho( ) for tileX="+tileX+", tileY="+tileY); System.out.println("Will run getMaxXSOrtho( ) for tileX="+tileX+", tileY="+tileY);
} }
...@@ -4260,6 +4260,7 @@ public class ImageDttCPU { ...@@ -4260,6 +4260,7 @@ public class ImageDttCPU {
double [][] ds = null; double [][] ds = null;
if (lma2 != null) { if (lma2 != null) {
ds = lma2.lmaDisparityStrength( ds = lma2.lmaDisparityStrength(
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
...@@ -4271,8 +4272,11 @@ public class ImageDttCPU { ...@@ -4271,8 +4272,11 @@ public class ImageDttCPU {
if (ds != null) { // always true if (ds != null) { // always true
disparity_map[DISPARITY_INDEX_POLY][tIndex] = ds[0][0]; disparity_map[DISPARITY_INDEX_POLY][tIndex] = ds[0][0];
disparity_map[DISPARITY_INDEX_POLY+1][tIndex] = ds[0][1]; disparity_map[DISPARITY_INDEX_POLY+1][tIndex] = ds[0][1];
disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] = ds[0][1]; // overwrite with LMA strength
if (debugTile0) { if (debugTile0) {
lma2.printStats(ds,1); lma2.printStats(ds,1);
if (imgdtt_params.lmas_LY_single) {
double [][] ddnd = lma2.getDdNd(); double [][] ddnd = lma2.getDdNd();
if (ddnd != null) { if (ddnd != null) {
double [][] dxy= new double [ddnd.length][2]; double [][] dxy= new double [ddnd.length][2];
...@@ -4291,10 +4295,12 @@ public class ImageDttCPU { ...@@ -4291,10 +4295,12 @@ public class ImageDttCPU {
System.out.print("Y = ["); System.out.print("Y = [");
for (int i = 0; i < dxy.length; i++) System.out.print(String.format(" %6.3f,", dxy[i][1])); System.out.println("]"); for (int i = 0; i < dxy.length; i++) System.out.print(String.format(" %6.3f,", dxy[i][1])); System.out.println("]");
System.out.println(); System.out.println();
} else {
System.out.println("No dd/nd and x/y offsets data is available ");
}
} else {
System.out.println("LY offsets are not measured");
} }
} }
} }
} }
...@@ -13876,6 +13882,7 @@ public class ImageDttCPU { ...@@ -13876,6 +13882,7 @@ public class ImageDttCPU {
double [][] ds = null; double [][] ds = null;
if (lma2 != null) { if (lma2 != null) {
ds = lma2.lmaDisparityStrength( ds = lma2.lmaDisparityStrength(
imgdtt_params.lmas_min_amp, // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) imgdtt_params.lmas_max_rel_rms, // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS) imgdtt_params.lmas_min_strength, // minimal composite strength (sqrt(average amp squared over absolute RMS)
imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line) imgdtt_params.lmas_min_ac, // minimal of A and C coefficients maximum (measures sharpest point/line)
......
...@@ -164,11 +164,14 @@ public class ImageDttParameters { ...@@ -164,11 +164,14 @@ public class ImageDttParameters {
public double lmas_rms_diff = 0.0003; // public double lmas_rms_diff = 0.0003; //
public int lmas_num_iter = 20; ///10 public int lmas_num_iter = 20; ///10
// Filtering and strength calculation // Filtering and strength calculation
public double lmas_max_rel_rms = 0.3; // maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3) // High ratio of amplitudes may be caused by "neighbors" correlations when the same object disappears from the tile
public double lmas_min_strength = 0.7; // minimal composite strength (sqrt(average amp squared over absolute RMS) // for small disparities 0.5...0.7 is OK, for larger, and small objects on uniform background, may need 0.2
public double lmas_min_ac = 0.02; // minimal of a and C coefficients maximum (measures sharpest point/line) public double lmas_min_amp = 0.25; // minimal ratio of minimal pair correlation amplitude to maximal pair correlation amplitude
public double lmas_min_min_ac = 0.007; // minimal of a and C coefficients minimum (measures sharpest point) public double lmas_max_rel_rms = 0.3; // LWIR16: 0.5 maximal relative (to average max/min amplitude LMA RMS) // May be up to 0.3)
public double lmas_max_area = 0.0; // maximal half-area (if > 0.0) public double lmas_min_strength = 0.7; // LWIR16: 0.4 minimal composite strength (sqrt(average amp squared over absolute RMS)
public double lmas_min_ac = 0.02; // LWIR16: 0.01 minimal of a and C coefficients maximum (measures sharpest point/line)
public double lmas_min_min_ac = 0.007; // LWIR16: 0.007 minimal of a and C coefficients minimum (measures sharpest point)
public double lmas_max_area = 0.0; // LWIR16: 0.0 maximal half-area (if > 0.0)
// public boolean lma_gaussian = false; // model correlation maximum as a Gaussian (false - as a parabola) // public boolean lma_gaussian = false; // model correlation maximum as a Gaussian (false - as a parabola)
public int lma_gaussian = 0; // 0 - parabola, 1 - Gaussian, 2 - limited parabola, 3 - limited squared parabola public int lma_gaussian = 0; // 0 - parabola, 1 - Gaussian, 2 - limited parabola, 3 - limited squared parabola
...@@ -214,8 +217,8 @@ public class ImageDttParameters { ...@@ -214,8 +217,8 @@ public class ImageDttParameters {
public double lma_min_min_ac = 0.015; // minimal of a and C coefficients minimum (measures sharpest point) 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_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_scale = 0.2; // LWIR16: 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 public double lma_str_offset = 0.05; // LWIR16: 0.05 convert lma-generated strength to match previous ones - add to result
// Lazy eye results interpretation // Lazy eye results interpretation
...@@ -546,6 +549,8 @@ public class ImageDttParameters { ...@@ -546,6 +549,8 @@ public class ImageDttParameters {
gd.addNumericField("LMA maximal iterations", this.lmas_num_iter, 0, 3, "", gd.addNumericField("LMA maximal iterations", this.lmas_num_iter, 0, 3, "",
"Limit LMA cycles, so it will exit after certain number of small improvements"); "Limit LMA cycles, so it will exit after certain number of small improvements");
gd.addMessage("LMA (single) results filtering"); gd.addMessage("LMA (single) results filtering");
gd.addNumericField("Minimal weakest pair to strongest pair correlation amplitude ratio",this.lmas_min_amp, 6, 8, "",
"Discard tile if ratio of the weakest correlation pair amplitude to that of the strongest one is lower than this");
gd.addNumericField("Maximal relative RMS ", this.lmas_max_rel_rms, 6, 8, "", gd.addNumericField("Maximal relative RMS ", this.lmas_max_rel_rms, 6, 8, "",
"Discard tile if ratio of RMS to average of min and max amplitude exceeds this value"); "Discard tile if ratio of RMS to average of min and max amplitude exceeds this value");
gd.addNumericField("Minimal composite strength", this.lmas_min_strength, 6, 8, "", gd.addNumericField("Minimal composite strength", this.lmas_min_strength, 6, 8, "",
...@@ -816,6 +821,7 @@ public class ImageDttParameters { ...@@ -816,6 +821,7 @@ public class ImageDttParameters {
this.lmas_lambda_initial = gd.getNextNumber(); this.lmas_lambda_initial = gd.getNextNumber();
this.lmas_rms_diff = gd.getNextNumber(); this.lmas_rms_diff = gd.getNextNumber();
this.lmas_num_iter= (int) gd.getNextNumber(); this.lmas_num_iter= (int) gd.getNextNumber();
this.lmas_min_amp = gd.getNextNumber();
this.lmas_max_rel_rms = gd.getNextNumber(); this.lmas_max_rel_rms = gd.getNextNumber();
this.lmas_min_strength = gd.getNextNumber(); this.lmas_min_strength = gd.getNextNumber();
this.lmas_min_ac = gd.getNextNumber(); this.lmas_min_ac = gd.getNextNumber();
...@@ -1007,6 +1013,7 @@ public class ImageDttParameters { ...@@ -1007,6 +1013,7 @@ public class ImageDttParameters {
properties.setProperty(prefix+"lmas_lambda_initial", this.lmas_lambda_initial +""); properties.setProperty(prefix+"lmas_lambda_initial", this.lmas_lambda_initial +"");
properties.setProperty(prefix+"lmas_rms_diff", this.lmas_rms_diff +""); properties.setProperty(prefix+"lmas_rms_diff", this.lmas_rms_diff +"");
properties.setProperty(prefix+"lmas_num_iter", this.lmas_num_iter +""); properties.setProperty(prefix+"lmas_num_iter", this.lmas_num_iter +"");
properties.setProperty(prefix+"lmas_min_amp", this.lmas_min_amp +"");
properties.setProperty(prefix+"lmas_max_rel_rms", this.lmas_max_rel_rms +""); 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_strength", this.lmas_min_strength +"");
properties.setProperty(prefix+"lmas_min_ac", this.lmas_min_ac +""); properties.setProperty(prefix+"lmas_min_ac", this.lmas_min_ac +"");
...@@ -1209,6 +1216,7 @@ public class ImageDttParameters { ...@@ -1209,6 +1216,7 @@ public class ImageDttParameters {
if (properties.getProperty(prefix+"lmas_lambda_initial")!=null) this.lmas_lambda_initial=Double.parseDouble(properties.getProperty(prefix+"lmas_lambda_initial")); if (properties.getProperty(prefix+"lmas_lambda_initial")!=null) this.lmas_lambda_initial=Double.parseDouble(properties.getProperty(prefix+"lmas_lambda_initial"));
if (properties.getProperty(prefix+"lmas_rms_diff")!=null) this.lmas_rms_diff=Double.parseDouble(properties.getProperty(prefix+"lmas_rms_diff")); if (properties.getProperty(prefix+"lmas_rms_diff")!=null) this.lmas_rms_diff=Double.parseDouble(properties.getProperty(prefix+"lmas_rms_diff"));
if (properties.getProperty(prefix+"lmas_num_iter")!=null) this.lmas_num_iter=Integer.parseInt(properties.getProperty(prefix+"lmas_num_iter")); if (properties.getProperty(prefix+"lmas_num_iter")!=null) this.lmas_num_iter=Integer.parseInt(properties.getProperty(prefix+"lmas_num_iter"));
if (properties.getProperty(prefix+"lmas_min_amp")!=null) this.lmas_min_amp=Double.parseDouble(properties.getProperty(prefix+"lmas_min_amp"));
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_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_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_ac")!=null) this.lmas_min_ac=Double.parseDouble(properties.getProperty(prefix+"lmas_min_ac"));
...@@ -1416,6 +1424,7 @@ public class ImageDttParameters { ...@@ -1416,6 +1424,7 @@ public class ImageDttParameters {
idp.lmas_lambda_initial = this.lmas_lambda_initial; idp.lmas_lambda_initial = this.lmas_lambda_initial;
idp.lmas_rms_diff = this.lmas_rms_diff; idp.lmas_rms_diff = this.lmas_rms_diff;
idp.lmas_num_iter = this.lmas_num_iter; idp.lmas_num_iter = this.lmas_num_iter;
idp.lmas_min_amp= this.lmas_min_amp;
idp.lmas_max_rel_rms= this.lmas_max_rel_rms; idp.lmas_max_rel_rms= this.lmas_max_rel_rms;
idp.lmas_min_strength= this.lmas_min_strength; idp.lmas_min_strength= this.lmas_min_strength;
idp.lmas_min_ac= this.lmas_min_ac; idp.lmas_min_ac= this.lmas_min_ac;
......
...@@ -3158,7 +3158,7 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -3158,7 +3158,7 @@ public class QuadCLT extends QuadCLTCPU {
ColorProcParameters colorProcParameters, ColorProcParameters colorProcParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters, EyesisCorrectionParameters.RGBParameters rgbParameters,
String name, String name,
int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4) // int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
int threadsMax, // maximal number of threads to launch int threadsMax, // maximal number of threads to launch
boolean updateStatus, boolean updateStatus,
int debugLevel int debugLevel
...@@ -3170,7 +3170,7 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -3170,7 +3170,7 @@ public class QuadCLT extends QuadCLTCPU {
colorProcParameters, colorProcParameters,
rgbParameters, rgbParameters,
name, name,
disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4) // disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
threadsMax, // maximal number of threads to launch threadsMax, // maximal number of threads to launch
updateStatus, updateStatus,
debugLevel); debugLevel);
......
...@@ -7160,7 +7160,7 @@ public class QuadCLTCPU { ...@@ -7160,7 +7160,7 @@ public class QuadCLTCPU {
false, // final boolean no_weak, false, // final boolean no_weak,
false, // final boolean use_last, // false, // final boolean use_last, //
// TODO: when useCombo - pay attention to borders (disregard) // TODO: when useCombo - pay attention to borders (disregard)
false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false // false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false
true, // final boolean copyDebug) true, // final boolean copyDebug)
debugLevel); debugLevel);
...@@ -7243,7 +7243,7 @@ public class QuadCLTCPU { ...@@ -7243,7 +7243,7 @@ public class QuadCLTCPU {
false, // final boolean no_weak, false, // final boolean no_weak,
false, // final boolean use_last, // false, // final boolean use_last, //
// TODO: when useCombo - pay attention to borders (disregard) // TODO: when useCombo - pay attention to borders (disregard)
false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false // false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false
true, // final boolean copyDebug) true, // final boolean copyDebug)
debugLevel); debugLevel);
...@@ -7469,7 +7469,7 @@ public class QuadCLTCPU { ...@@ -7469,7 +7469,7 @@ public class QuadCLTCPU {
boolean [] bgmask = getBackgroundImageMasks( boolean [] bgmask = getBackgroundImageMasks(
clt_parameters, clt_parameters,
name, // .getTitle(), //String name=(String) imp_src.getProperty("name"); name, // .getTitle(), //String name=(String) imp_src.getProperty("name");
ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4) // ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4)
threadsMax, // maximal number of threads to launch threadsMax, // maximal number of threads to launch
updateStatus, updateStatus,
debugLevel); debugLevel);
...@@ -7480,7 +7480,7 @@ public class QuadCLTCPU { ...@@ -7480,7 +7480,7 @@ public class QuadCLTCPU {
colorProcParameters, colorProcParameters,
rgbParameters, rgbParameters,
name, // .getTitle(), //String name=(String) imp_src.getProperty("name"); name, // .getTitle(), //String name=(String) imp_src.getProperty("name");
ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4) // ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4)
threadsMax, // maximal number of threads to launch threadsMax, // maximal number of threads to launch
updateStatus, updateStatus,
debugLevel); debugLevel);
...@@ -7690,8 +7690,7 @@ public class QuadCLTCPU { ...@@ -7690,8 +7690,7 @@ public class QuadCLTCPU {
true, // final boolean keep_raw_fg, // do not replace raw tiles by the plates, if raw is closer (like poles) true, // final boolean keep_raw_fg, // do not replace raw tiles by the plates, if raw is closer (like poles)
0.0, // final double scale_filtered_strength_pre, // scale plate_ds[1] before comparing to raw strength 0.0, // final double scale_filtered_strength_pre, // scale plate_ds[1] before comparing to raw strength
0.0, // final double scale_filtered_strength_post,// scale plate_ds[1] when replacing raw (generally plate_ds is more reliable if it exists) 0.0, // final double scale_filtered_strength_post,// scale plate_ds[1] when replacing raw (generally plate_ds is more reliable if it exists)
// ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4)
ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4)
geometryCorrection, geometryCorrection,
threadsMax, // maximal number of threads to launch threadsMax, // maximal number of threads to launch
updateStatus, updateStatus,
...@@ -7830,8 +7829,7 @@ public class QuadCLTCPU { ...@@ -7830,8 +7829,7 @@ public class QuadCLTCPU {
true, // final boolean keep_raw_fg, // do not replace raw tiles by the plates, if raw is closer (like poles) true, // final boolean keep_raw_fg, // do not replace raw tiles by the plates, if raw is closer (like poles)
0.0, // final double scale_filtered_strength_pre, // scale plate_ds[1] before comparing to raw strength 0.0, // final double scale_filtered_strength_pre, // scale plate_ds[1] before comparing to raw strength
0.0, // final double scale_filtered_strength_post,// scale plate_ds[1] when replacing raw (generally plate_ds is more reliable if it exists) 0.0, // final double scale_filtered_strength_post,// scale plate_ds[1] when replacing raw (generally plate_ds is more reliable if it exists)
// ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4)
ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4)
geometryCorrection, geometryCorrection,
threadsMax, // maximal number of threads to launch threadsMax, // maximal number of threads to launch
updateStatus, updateStatus,
...@@ -7892,6 +7890,28 @@ public class QuadCLTCPU { ...@@ -7892,6 +7890,28 @@ public class QuadCLTCPU {
false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false
true, // final boolean copyDebug) true, // final boolean copyDebug)
debugLevel); debugLevel);
for (int nexpand = 0; nexpand < 20; nexpand++) {
int num_added = tp.expandCertain (
combo_pass, // final CLTPass3d combo_pass, // modify
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
0.5, // final int disp_avg_arange, // average neighbors with disparity not more than that from the lowest
0.1, // final int disp_avg_rrange, // same, relative to disparity
1.0, // final int disp_arange, // look for a fit within range from the neighbor
0.1, // final int disp_rrange, // same, relative to disparity
2, // final int min_defined, // minimal number of defined neighbors that fit into the range
tp.getTrustedCorrelation(), // final double trustedCorrelation,
tp.getMaxOverexposure(), // final double max_overexposure,
debugLevel); // final int debugLevel)
if (num_added==0) {
break;
}
if (show_init_refine) tp.showScan(
combo_pass, // CLTPass3d scan,
"expamded-"+nexpand+"-added-"+num_added);
}
if (show_init_refine) tp.showScan( if (show_init_refine) tp.showScan(
combo_pass, // CLTPass3d scan, combo_pass, // CLTPass3d scan,
...@@ -9770,7 +9790,7 @@ public class QuadCLTCPU { ...@@ -9770,7 +9790,7 @@ public class QuadCLTCPU {
pt_keep_raw_fg, // final boolean keep_raw_fg, // do not replace raw tiles by the plates, if raw is closer (like poles) pt_keep_raw_fg, // final boolean keep_raw_fg, // do not replace raw tiles by the plates, if raw is closer (like poles)
pt_scale_pre, // final double scale_filtered_strength_pre, // scale plate_ds[1] before comparing to raw strength pt_scale_pre, // final double scale_filtered_strength_pre, // scale plate_ds[1] before comparing to raw strength
pt_scale_post, // final double scale_filtered_strength_post,// scale plate_ds[1] when replacing raw (generally plate_ds is more reliable if it exists) pt_scale_post, // final double scale_filtered_strength_post,// scale plate_ds[1] when replacing raw (generally plate_ds is more reliable if it exists)
ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4) // ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4)
geometryCorrection, geometryCorrection,
tp.threadsMax, // maximal number of threads to launch tp.threadsMax, // maximal number of threads to launch
false, // updateStatus, false, // updateStatus,
...@@ -10472,7 +10492,7 @@ public class QuadCLTCPU { ...@@ -10472,7 +10492,7 @@ public class QuadCLTCPU {
// ColorProcParameters colorProcParameters, // ColorProcParameters colorProcParameters,
// EyesisCorrectionParameters.RGBParameters rgbParameters, // EyesisCorrectionParameters.RGBParameters rgbParameters,
String name, String name,
int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4) // int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
int threadsMax, // maximal number of threads to launch int threadsMax, // maximal number of threads to launch
boolean updateStatus, boolean updateStatus,
int debugLevel int debugLevel
...@@ -10500,7 +10520,7 @@ public class QuadCLTCPU { ...@@ -10500,7 +10520,7 @@ public class QuadCLTCPU {
clt_parameters.sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd clt_parameters.sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd
clt_parameters.min_clstr_seed, // number of tiles in a cluster to seed (just background?) clt_parameters.min_clstr_seed, // number of tiles in a cluster to seed (just background?)
clt_parameters.min_clstr_block,// number of tiles in a cluster to block (just non-background?) clt_parameters.min_clstr_block,// number of tiles in a cluster to block (just non-background?)
disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4) // disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
clt_parameters.show_bgnd_nonbgnd, clt_parameters.show_bgnd_nonbgnd,
(clt_parameters.debug_filters ? (debugLevel) : -1)); (clt_parameters.debug_filters ? (debugLevel) : -1));
boolean [] bgnd_tiles_new = tp.getBackgroundMask_new( // which tiles do belong to the background boolean [] bgnd_tiles_new = tp.getBackgroundMask_new( // which tiles do belong to the background
...@@ -10510,7 +10530,7 @@ public class QuadCLTCPU { ...@@ -10510,7 +10530,7 @@ public class QuadCLTCPU {
clt_parameters.sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd clt_parameters.sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd
clt_parameters.min_clstr_seed, // number of tiles in a cluster to seed (just background?) clt_parameters.min_clstr_seed, // number of tiles in a cluster to seed (just background?)
clt_parameters.min_clstr_block,// number of tiles in a cluster to block (just non-background?) clt_parameters.min_clstr_block,// number of tiles in a cluster to block (just non-background?)
disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4) // disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
clt_parameters.show_bgnd_nonbgnd, clt_parameters.show_bgnd_nonbgnd,
(clt_parameters.debug_filters ? (debugLevel) : -1)); (clt_parameters.debug_filters ? (debugLevel) : -1));
boolean [] bgnd_dbg = bgnd_tiles.clone(); // only these have non 0 alpha boolean [] bgnd_dbg = bgnd_tiles.clone(); // only these have non 0 alpha
...@@ -10567,7 +10587,7 @@ public class QuadCLTCPU { ...@@ -10567,7 +10587,7 @@ public class QuadCLTCPU {
ColorProcParameters colorProcParameters, ColorProcParameters colorProcParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters, EyesisCorrectionParameters.RGBParameters rgbParameters,
String name, String name,
int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4) // int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
int threadsMax, // maximal number of threads to launch int threadsMax, // maximal number of threads to launch
boolean updateStatus, boolean updateStatus,
int debugLevel int debugLevel
......
...@@ -41,25 +41,28 @@ public class TileProcessor { ...@@ -41,25 +41,28 @@ public class TileProcessor {
public static String [] SCAN_TITLES4 = { public static String [] SCAN_TITLES4 = {
"tile_op", // 0 "tile_op", // 0
"final", // 1 - calculated, filtered, combined disparity "final", // 1 - calculated, filtered, combined disparity
"disparity", // 2 "calc", // 2 - calc_disparity
"disp_cm", // 3 "calc_lma", // 3 - calc_disparity, lma-only
"disp_hor", // 4 "disparity", // 4
"disp_vert", // 5 "disp_cm", // 5
"final_strength",// 6 "disp_hor", // 6
"strength", // 7 "disp_vert", // 7
"strength_hor", // 8 "final_strength",// 8
"strength_vert", // 9 "strength", // 9
"selection", // 10 "strength_hor", // 10
"border_tiles", // 11 "strength_vert", // 11
"max_tried", // 12 "selection", // 12
"diff0", // 13 "has_lma", // 13
"diff1", // 14 "border_tiles", // 14 11
"diff2", // 15 "max_tried", // 15 12
"diff3", // 16 "diff0", // 16 13
"diff2max", // 17 "diff1", // 17 14
"diff2maxAvg", // 18 "diff2", // 18 15
"normStrength", // 19 "diff3", // 19 16
"overexp", // 20 "diff2max", // 20 17
"diff2maxAvg", // 21 18
"normStrength", // 22 19
"overexp", // 23 20
"r0","r1","r2","r3", "r0","r1","r2","r3",
"b0","b1","b2","b3", "b0","b1","b2","b3",
"g0","g1","g2","g3", "g0","g1","g2","g3",
...@@ -1049,7 +1052,7 @@ public class TileProcessor { ...@@ -1049,7 +1052,7 @@ public class TileProcessor {
no_weak, no_weak,
use_last, // use_last, //
// TODO: when useCombo - pay attention to borders (disregard) // TODO: when useCombo - pay attention to borders (disregard)
usePoly, // use polynomial method to find max), valid if useCombo == false // usePoly, // use polynomial method to find max), valid if useCombo == false
copyDebug, copyDebug,
debugLevel).get(0); debugLevel).get(0);
} }
...@@ -1058,19 +1061,21 @@ public class TileProcessor { ...@@ -1058,19 +1061,21 @@ public class TileProcessor {
double disparity; double disparity;
double strength; double strength;
double adiff; double adiff;
boolean has_lma;
DSD (int indx){ // only index DSD (int indx){ // only index
this.indx = indx; this.indx = indx;
} }
DSD (int indx, double disparity, double strength, double adiff){ DSD (int indx, double disparity, double strength, double adiff, boolean has_lma){
this.indx = indx; this.indx = indx;
this.disparity = disparity; this.disparity = disparity;
this.strength = strength; this.strength = strength;
this.adiff = adiff; this.adiff = adiff;
this.has_lma = has_lma;
} }
} }
private ArrayList<DSD> filterDsdList( private ArrayList<DSD> filterDsdList( // TODO: Finish adding has_lma !!!!!!!!!!!!!!!!!
ArrayList<DSD> src_list, ArrayList<DSD> src_list,
double disp_tolerance, double disp_tolerance,
int max_len, int max_len,
...@@ -1080,21 +1085,37 @@ public class TileProcessor { ...@@ -1080,21 +1085,37 @@ public class TileProcessor {
} }
ArrayList<DSD> filtered_list = new ArrayList<DSD>(); ArrayList<DSD> filtered_list = new ArrayList<DSD>();
ArrayList<DSD> list_in = src_list; ArrayList<DSD> list_in = src_list;
// if there is at least one with lma - remove all without lma measurements
boolean some_lma = false;
for (DSD dsd : src_list) {
some_lma |= dsd.has_lma;
if (some_lma) {
break;
}
}
while (!list_in.isEmpty()) { while (!list_in.isEmpty()) {
int best_indx = 0; int best_indx = 0;
for (int i = 1; i < list_in.size(); i++) { for (int i = 1; i < list_in.size(); i++) {
if (list_in.get(i).adiff < list_in.get(best_indx).adiff) { DSD dsd = list_in.get(i);
if (dsd.has_lma | !some_lma) {
if (dsd.adiff < list_in.get(best_indx).adiff) {
best_indx = i; best_indx = i;
} }
} }
}
DSD best_dsd = list_in.get(best_indx); DSD best_dsd = list_in.get(best_indx);
filtered_list.add(best_dsd); filtered_list.add(best_dsd);
ArrayList<DSD> list_remain = new ArrayList<DSD>(); ArrayList<DSD> list_remain = new ArrayList<DSD>();
for (DSD dsd: list_in) { for (DSD dsd: list_in) {
if (dsd.has_lma | !some_lma) {
if (Math.abs(best_dsd.disparity - dsd.disparity) > disp_tolerance) { if (Math.abs(best_dsd.disparity - dsd.disparity) > disp_tolerance) {
list_remain.add(dsd); list_remain.add(dsd);
} }
} }
}
list_in = list_remain; list_in = list_remain;
} }
// Trim if too long // Trim if too long
...@@ -1103,6 +1124,9 @@ public class TileProcessor { ...@@ -1103,6 +1124,9 @@ public class TileProcessor {
Collections.sort(filtered_list, new Comparator<DSD>() { // descending (switched rhs, lhs) Collections.sort(filtered_list, new Comparator<DSD>() { // descending (switched rhs, lhs)
@Override @Override
public int compare(DSD rhs, DSD lhs) { public int compare(DSD rhs, DSD lhs) {
// if (rhs.has_lma !=lhs.has_lma) {
// return rhs.has_lma ? -1 : 1;
// }
return rhs.strength > lhs.strength ? -1 : (rhs.strength < lhs.strength ) ? 1 : 0; return rhs.strength > lhs.strength ? -1 : (rhs.strength < lhs.strength ) ? 1 : 0;
} }
}); });
...@@ -1171,16 +1195,19 @@ public class TileProcessor { ...@@ -1171,16 +1195,19 @@ public class TileProcessor {
final boolean no_weak, final boolean no_weak,
final boolean use_last, // final boolean use_last, //
// TODO: when useCombo - pay attention to borders (disregard) // TODO: when useCombo - pay attention to borders (disregard)
final boolean usePoly, // use polynomial method to find max), valid if useCombo == false // final boolean usePoly, // use polynomial method to find max), valid if useCombo == false
final boolean copyDebug, final boolean copyDebug,
final int debugLevel) final int debugLevel)
{ {
// CLTPass3d combo_pass =new CLTPass3d(this); // CLTPass3d combo_pass =new CLTPass3d(this);
final boolean descending = false; // disparity order in the result list final boolean descending = false; // disparity order in the result list
final double disparity_tolerance = 0.5; // minimal disparity to separate FG/BG final double disparity_tolerance = 0.5; // minimal disparity to separate FG/BG
final double corr_magic_scale_lma = 1.0;
final int tlen = tilesX * tilesY; final int tlen = tilesX * tilesY;
final int disparity_index = usePoly ? ImageDtt.DISPARITY_INDEX_POLY : ImageDtt.DISPARITY_INDEX_CM; // will use (09/2021) both ImageDtt.DISPARITY_INDEX_CM and ImageDtt.DISPARITY_INDEX_POLY (now LMA)
// final int disparity_index = usePoly ? ImageDtt.DISPARITY_INDEX_POLY : ImageDtt.DISPARITY_INDEX_CM;
final ArrayList<CLTPass3d> combo_pass_list = new ArrayList<CLTPass3d>(); final ArrayList<CLTPass3d> combo_pass_list = new ArrayList<CLTPass3d>();
final int dbg_tile = (debugLevel > 0)? 35114: -1; // x = 122, y= 108; -1; // 27669; final int dbg_tile = (debugLevel > 0)? 35114: -1; // x = 122, y= 108; -1; // 27669;
for (int np = 0; np < num_planes; np++) { for (int np = 0; np < num_planes; np++) {
...@@ -1188,7 +1215,6 @@ public class TileProcessor { ...@@ -1188,7 +1215,6 @@ public class TileProcessor {
} }
for (CLTPass3d combo_pass : combo_pass_list) { for (CLTPass3d combo_pass : combo_pass_list) {
combo_pass.tile_op = new int [tilesY][tilesX]; // for just non-zero combo_pass.tile_op = new int [tilesY][tilesX]; // for just non-zero
// combo_pass.disparity_map = new double [ImageDtt.DISPARITY_TITLES.length][];
combo_pass.disparity_map = new double [ImageDtt.getDisparityTitles(getNumSensors()).length][]; combo_pass.disparity_map = new double [ImageDtt.getDisparityTitles(getNumSensors()).length][];
for (int i = 0; i< numSensors; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i] = new double[tlen]; for (int i = 0; i< numSensors; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i] = new double[tlen];
...@@ -1199,6 +1225,8 @@ public class TileProcessor { ...@@ -1199,6 +1225,8 @@ public class TileProcessor {
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH] = new double[tlen]; combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH] = new double[tlen];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT] = new double[tlen]; combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT] = new double[tlen];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH] = new double[tlen]; combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH] = new double[tlen];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY] = new double[tlen]; // LMA disparity
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY+1] = new double[tlen]; // LMA strength
} }
// for now - will copy from the best full correlation measurement // for now - will copy from the best full correlation measurement
combo_pass.texture_tiles = new double [tilesY][tilesX][][]; combo_pass.texture_tiles = new double [tilesY][tilesX][][];
...@@ -1210,350 +1238,22 @@ public class TileProcessor { ...@@ -1210,350 +1238,22 @@ public class TileProcessor {
combo_pass.strength = new double [tlen]; combo_pass.strength = new double [tlen];
combo_pass.strength_hor = new double [tlen]; combo_pass.strength_hor = new double [tlen];
combo_pass.strength_vert = new double [tlen]; combo_pass.strength_vert = new double [tlen];
combo_pass.has_lma = new boolean [tlen];
for (int ty = 0; ty < tilesY; ty ++) for (int tx = 0; tx < tilesX; tx ++) combo_pass.texture_tiles[ty][tx] = null; for (int ty = 0; ty < tilesY; ty ++) for (int tx = 0; tx < tilesX; tx ++) combo_pass.texture_tiles[ty][tx] = null;
} }
// * Calculates calc_disparity, calc_disparity_hor, calc_disparity_vert, strength, strength_hor, strength_vert, // * Calculates calc_disparity, calc_disparity_hor, calc_disparity_vert, strength, strength_hor, strength_vert,
// temporary: // temporary:
final CLTPass3d combo_pass0 = combo_pass_list.get(0); final CLTPass3d combo_pass0 = combo_pass_list.get(0);
//convert to multithreacded
final Thread[] threads = ImageDtt.newThreadArray(threadsMax); final Thread[] threads = ImageDtt.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() {
for (int nTile = ai.getAndIncrement(); nTile < tlen; nTile = ai.getAndIncrement()) { for (int nTile = ai.getAndIncrement(); nTile < tlen; nTile = ai.getAndIncrement()) {
int tx = nTile % tilesX; int tx = nTile % tilesX;
int ty = nTile / tilesX; int ty = nTile / tilesX;
int nt = ty * tilesX + tx;
int best_index = -1;
int best_index_hor = -1;
int best_index_vert = -1;
int best_weak_index = -1;
int best_weak_index_hor = -1;
int best_weak_index_vert = -1;
// for "strong" result (above minStrength) the best fit is with smallest residual disparity
// for weak ones - the strongest.
// TODO: handle ortho (if requested so)
// after refine - use last, after extend - use strongest of all
double adiff_best = Double.NaN;
double adiff_best_hor = Double.NaN;
double adiff_best_vert = Double.NaN;
double strongest_weak = 0.0;
double strongest_weak_hor = 0.0;
double strongest_weak_vert = 0.0;
combo_pass0.max_tried_disparity[ty][tx] = Double.NaN;
if (nt == dbg_tile) {
System.out.println("compositeScan(): nt = "+nt);
}
ArrayList<DSD> quad_list = new ArrayList<DSD>();
ArrayList<DSD> hor_list = new ArrayList<DSD>();
ArrayList<DSD> vert_list = new ArrayList<DSD>();
for (int ipass = firstPass; ipass <lastPassPlus1; ipass++ ){
CLTPass3d pass = passes.get(ipass);
if (nt == dbg_tile) {
System.out.println("compositeScan(): ipass = "+ipass+" nt = "+nt+" pass.tile_op["+ty+"]["+tx+"]="+pass.tile_op[ty][tx]+
" pass.isCombo()="+(pass.isCombo())+" pass.isProcessed()="+(pass.isProcessed()));
}
if ( pass.isMeasured() && (pass.tile_op[ty][tx] != 0 )) { // current tile has valid data
if ( (Double.isNaN(combo_pass0.max_tried_disparity[ty][tx]) ||
(pass.disparity[ty][tx] > combo_pass0.max_tried_disparity[ty][tx]))){
combo_pass0.max_tried_disparity[ty][tx] = pass.disparity[ty][tx];
}
boolean last = (ipass == (lastPassPlus1-1)) && use_last;
double mdisp = pass.disparity_map[disparity_index][nt];
double mdisp_hor = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt];
double mdisp_vert = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT][nt];
double strength = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt];
double strength_hor = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH][nt];
double strength_vert = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH][nt];
boolean overexposed = (max_overexposure > 0.0) &&
(pass.disparity_map[ImageDtt.OVEREXPOSED] != null) &&
(pass.disparity_map[ImageDtt.OVEREXPOSED][nt] > max_overexposure);
if (!overexposed) {
double adiff = Math.abs(mdisp);
double adiff_hor = Math.abs(mdisp_hor);
double adiff_vert = Math.abs(mdisp_vert);
if (adiff <= trustedCorrelation){
double disp = mdisp/corr_magic_scale + pass.disparity[ty][tx];
// do not consider tiles over background if they are far and initially identified as background
// if ((bg_tiles == null) || !bg_tiles[nt] || (disp >= ex_min_over)) {
if ((disp >= disp_far) && (disp <= disp_near) && !Double.isNaN(adiff)){
if (strength >= minStrength) {
if (!(adiff >= adiff_best)){ // adiff_best == Double.NaN works too
adiff_best = adiff;
best_index = ipass;
}
quad_list.add(new DSD(ipass, disp, strength, adiff));
} else {
if ((last && (strength > 0.0)) || (!no_weak && (strength > strongest_weak))){
strongest_weak = strength;
best_weak_index = ipass;
}
}
}
// }
}
if (!Double.isNaN(minStrengthHor) && (adiff_hor <= trustedCorrelation)){
double disp_hor = mdisp_hor/corr_magic_scale + pass.disparity[ty][tx];
if ((disp_hor >= disp_far) && (disp_hor <= disp_near) && !Double.isNaN(adiff_hor)){
if (strength_hor >= minStrengthHor) {
if (!(adiff_hor >= adiff_best_hor)){ // adiff_best == Double.NaN works too
adiff_best_hor = adiff_hor;
best_index_hor = ipass;
}
hor_list.add(new DSD(ipass, disp_hor, strength_hor, adiff_hor));
} else {
if ((last && (strength_hor > 0.0)) || (!no_weak && (strength_hor > strongest_weak_hor))){
strongest_weak_hor = strength_hor;
best_weak_index_hor = ipass;
}
}
}
}
if (!Double.isNaN(minStrengthVert) && (adiff_vert <= trustedCorrelation)){
double disp_vert = mdisp_vert/corr_magic_scale + pass.disparity[ty][tx];
if ((disp_vert >= disp_far) && (disp_vert <= disp_near) && !Double.isNaN(adiff_vert)){
if (strength_vert >= minStrengthVert) {
if (!(adiff_vert >= adiff_best_vert)){ // adiff_best == Double.NaN works too
adiff_best_vert = adiff_vert;
best_index_vert = ipass;
}
vert_list.add(new DSD(ipass, disp_vert, strength_vert, adiff_vert));
} else {
if ((last && (strength_vert > 0.0)) || (!no_weak && (strength_vert > strongest_weak_vert))){
strongest_weak_vert = strength_vert;
best_weak_index_vert = ipass;
}
}
}
}
}
}
}
if (best_index < 0) best_index = best_weak_index;
if (best_index_hor < 0) best_index_hor = best_weak_index_hor;
if (best_index_vert < 0) best_index_vert = best_weak_index_vert;
//clt_parameters.gr_unique_tol
/*
private ArrayList<DSD> filterDsdList(
ArrayList<DSD> src_list,
double disp_tolerance,
int max_len,
boolean descending){ // false: disparity from far to near, true - near to far
final boolean descending = false; // disparity order in the result list
final double disparity_tolerance = 0.5; // minimal disparity to separate FG/BG
*/
if (quad_list.isEmpty()) {
if (best_index >= 0) {
quad_list.add(new DSD(best_index)); // only index, disparity and strength
}
}
// now quad_list contains 0, 1 for weak, 1.. num_planes for enough strong ones
quad_list = filterDsdList(
quad_list, // ArrayList<DSD> src_list,
disparity_tolerance, // double disp_tolerance,
num_planes, // int max_len,
descending); // boolean descending)
for (int np = 0; np< quad_list.size(); np++) {
CLTPass3d pass = passes.get(quad_list.get(np).indx);
CLTPass3d combo_pass = combo_pass_list.get(np);
combo_pass.tile_op[ty][tx] = pass.tile_op[ty][tx];
if (pass.texture_tiles != null) {
combo_pass.texture_tiles[ty][tx] = pass.texture_tiles[ty][tx];
}
combo_pass.calc_disparity[nt] = pass.disparity_map[disparity_index][nt]/corr_magic_scale + pass.disparity[ty][tx];
combo_pass.strength[nt] = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt];
// Only copy for full disparity
for (int i = 0; i< numSensors; i++) {
if (pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i]!= null) {// do not copy empty
combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt] = pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt];
}
}
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt];
combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt] = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt];
}
}
// fill empty planes (if any). May be all if there were no even weak tiles (old best_index<0)
for (int np = quad_list.size(); np < num_planes; np++) {
CLTPass3d combo_pass = combo_pass_list.get(np);
combo_pass.tile_op[ty][tx] = 0;
combo_pass.texture_tiles[ty][tx] = null;
combo_pass.calc_disparity[nt] = Double.NaN;
combo_pass.strength[nt] = 0.0;
// Only copy for full disparity
for (int i = 0; i< numSensors; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt] = Double.NaN;
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt] = Double.NaN;
combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt] = Double.NaN;
}
}
// TODO: For now hor/vert are added independently and are not synchronized to full-quad correlations
if (hor_list.isEmpty()) {
if (best_index_hor >= 0) {
hor_list.add(new DSD(best_index_hor)); // only index, disparity and strength
}
}
// now quad_list contains 0, 1 for weak, 1.. num_planes for enough strong ones
hor_list = filterDsdList(
hor_list, // ArrayList<DSD> src_list,
disparity_tolerance, // double disp_tolerance,
num_planes, // int max_len,
descending); // boolean descending)
for (int np = 0; np< hor_list.size(); np++) {
CLTPass3d pass = passes.get(hor_list.get(np).indx);
CLTPass3d combo_pass = combo_pass_list.get(np);
combo_pass.tile_op[ty][tx] = pass.tile_op[ty][tx]; // just non-zero
combo_pass.calc_disparity_hor[nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt]/corr_magic_scale + pass.disparity[ty][tx];
combo_pass.strength_hor[nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH][nt];
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH][nt];
}
}
// fill empty planes (if any). May be all if there were no even weak tiles (old best_index<0)
for (int np = hor_list.size(); np < num_planes; np++) {
CLTPass3d combo_pass = combo_pass_list.get(np);
combo_pass.calc_disparity_hor[nt] = Double.NaN;
combo_pass.strength_hor[nt] = 0.0;
// Only copy for full disparity
for (int i = 0; i< numSensors; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt] = Double.NaN;
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt] = Double.NaN;
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH][nt] = 0.0;
}
}
if (vert_list.isEmpty()) {
if (best_index_vert >= 0) {
hor_list.add(new DSD(best_index_vert)); // only index, disparity and strength
}
}
vert_list = filterDsdList(
vert_list, // ArrayList<DSD> src_list,
disparity_tolerance, // double disp_tolerance,
num_planes, // int max_len,
descending); // boolean descending)
for (int np = 0; np< vert_list.size(); np++) {
CLTPass3d pass = passes.get(vert_list.get(np).indx);
CLTPass3d combo_pass = combo_pass_list.get(np);
combo_pass.tile_op[ty][tx] = pass.tile_op[ty][tx]; // just non-zero
combo_pass.calc_disparity_vert[nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT][nt]/corr_magic_scale + pass.disparity[ty][tx];
combo_pass.strength_vert[nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH][nt];
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT][nt];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH][nt];
}
}
// fill empty planes (if any). May be all if there were no even weak tiles (old best_index<0)
for (int np = vert_list.size(); np < num_planes; np++) {
CLTPass3d combo_pass = combo_pass_list.get(np);
combo_pass.calc_disparity_vert[nt] = Double.NaN;
combo_pass.strength_vert[nt] = 0.0;
// Only copy for full disparity
for (int i = 0; i< numSensors; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt] = Double.NaN;
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT][nt] = Double.NaN;
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH][nt] = 0.0;
}
}
// Duplicate some values from the combo_pass0 to all other passes (if any)
for (int np = 1; np < combo_pass_list.size(); np++) {
CLTPass3d combo_pass = combo_pass_list.get(np);
combo_pass.max_tried_disparity[ty][tx] = combo_pass0.max_tried_disparity[ty][tx];
}
}
}
};
}
ImageDtt.startAndJoin(threads);
for (CLTPass3d combo_pass : combo_pass_list) {
// getDisparity(): calc_disparity_combo = calc_disparity.clone();
combo_pass.getDisparity(); // See if it does not break anything - triggers calculation if not done yet
combo_pass.fixNaNDisparity(); // mostly for debug, measured disparity should be already fixed from NaN
}
return combo_pass_list;
}
public ArrayList<CLTPass3d> compositeScanSingleThread(
final int num_planes,
final ArrayList <CLTPass3d> passes,
final int firstPass,
final int lastPassPlus1,
final double trustedCorrelation,
final double max_overexposure,
final double disp_far, // limit results to the disparity range
final double disp_near,
final double minStrength,
final double minStrengthHor,
final double minStrengthVert,
final boolean no_weak,
final boolean use_last, //
// TODO: when useCombo - pay attention to borders (disregard)
final boolean usePoly, // use polynomial method to find max), valid if useCombo == false
final boolean copyDebug,
final int debugLevel)
{
// CLTPass3d combo_pass =new CLTPass3d(this);
final boolean descending = false; // disparity order in the result list
final double disparity_tolerance = 0.5; // minimal disparity to separate FG/BG
final int tlen = tilesX * tilesY;
final int disparity_index = usePoly ? ImageDtt.DISPARITY_INDEX_POLY : ImageDtt.DISPARITY_INDEX_CM;
final ArrayList<CLTPass3d> combo_pass_list = new ArrayList<CLTPass3d>();
final int dbg_tile = (debugLevel > 0)? 35114: -1; // x = 122, y= 108; -1; // 27669;
for (int np = 0; np < num_planes; np++) {
combo_pass_list.add(new CLTPass3d(this));
}
for (CLTPass3d combo_pass : combo_pass_list) {
combo_pass.tile_op = new int [tilesY][tilesX]; // for just non-zero
// combo_pass.disparity_map = new double [ImageDtt.DISPARITY_TITLES.length][];
combo_pass.disparity_map = new double [ImageDtt.getDisparityTitles(getNumSensors()).length][];
for (int i = 0; i< numSensors; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i] = new double[tlen];
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM] = new double[tlen];
combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX] = new double[tlen];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR] = new double[tlen];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH] = new double[tlen];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT] = new double[tlen];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH] = new double[tlen];
}
// for now - will copy from the best full correlation measurement
combo_pass.texture_tiles = new double [tilesY][tilesX][][];
combo_pass.max_tried_disparity = new double [tilesY][tilesX];
combo_pass.is_combo = true;
combo_pass.calc_disparity = new double [tlen];
combo_pass.calc_disparity_hor = new double [tlen];
combo_pass.calc_disparity_vert = new double [tlen];
combo_pass.strength = new double [tlen];
combo_pass.strength_hor = new double [tlen];
combo_pass.strength_vert = new double [tlen];
for (int ty = 0; ty < tilesY; ty ++) for (int tx = 0; tx < tilesX; tx ++) combo_pass.texture_tiles[ty][tx] = null;
}
// * Calculates calc_disparity, calc_disparity_hor, calc_disparity_vert, strength, strength_hor, strength_vert,
// temporary:
CLTPass3d combo_pass0 = combo_pass_list.get(0);
for (int ty = 0; ty < tilesY; ty ++) {
for (int tx = 0; tx < tilesX; tx ++){
int nt = ty * tilesX + tx; int nt = ty * tilesX + tx;
int best_index = -1; int best_index = -1;
int best_index_hor = -1; int best_index_hor = -1;
...@@ -1572,13 +1272,13 @@ ImageDtt.startAndJoin(threads); ...@@ -1572,13 +1272,13 @@ ImageDtt.startAndJoin(threads);
double strongest_weak = 0.0; double strongest_weak = 0.0;
double strongest_weak_hor = 0.0; double strongest_weak_hor = 0.0;
double strongest_weak_vert = 0.0; double strongest_weak_vert = 0.0;
boolean use_lma = false; // tile has at least one LMA-measured scan
combo_pass0.max_tried_disparity[ty][tx] = Double.NaN; combo_pass0.max_tried_disparity[ty][tx] = Double.NaN;
if (nt == dbg_tile) { if (nt == dbg_tile) {
System.out.println("compositeScan(): nt = "+nt); System.out.println("compositeScan(): nt = "+nt);
} }
ArrayList<DSD> quad_list = new ArrayList<DSD>(); ArrayList<DSD> full_list = new ArrayList<DSD>();
ArrayList<DSD> hor_list = new ArrayList<DSD>(); ArrayList<DSD> hor_list = new ArrayList<DSD>();
ArrayList<DSD> vert_list = new ArrayList<DSD>(); ArrayList<DSD> vert_list = new ArrayList<DSD>();
for (int ipass = firstPass; ipass <lastPassPlus1; ipass++ ){ for (int ipass = firstPass; ipass <lastPassPlus1; ipass++ ){
...@@ -1593,7 +1293,17 @@ ImageDtt.startAndJoin(threads); ...@@ -1593,7 +1293,17 @@ ImageDtt.startAndJoin(threads);
combo_pass0.max_tried_disparity[ty][tx] = pass.disparity[ty][tx]; combo_pass0.max_tried_disparity[ty][tx] = pass.disparity[ty][tx];
} }
boolean last = (ipass == (lastPassPlus1-1)) && use_last; boolean last = (ipass == (lastPassPlus1-1)) && use_last;
double mdisp = pass.disparity_map[disparity_index][nt]; double [] mdisp_lma_arr = pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY];
boolean m_lma = (mdisp_lma_arr != null) && !Double.isNaN(mdisp_lma_arr[nt]);
if (use_lma && !m_lma) { // already has lma -measured, but the current is not
// should not, but may happen that closer measurement will not result in LMA while some other (stray?) did
continue;
}
boolean first_lma = !use_lma && m_lma;
use_lma = m_lma;
double mdisp = m_lma?
mdisp_lma_arr[nt] : pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt];
double corr_magic = m_lma ? corr_magic_scale_lma : corr_magic_scale;
double mdisp_hor = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt]; double mdisp_hor = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt];
double mdisp_vert = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT][nt]; double mdisp_vert = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT][nt];
...@@ -1610,19 +1320,19 @@ ImageDtt.startAndJoin(threads); ...@@ -1610,19 +1320,19 @@ ImageDtt.startAndJoin(threads);
double adiff_vert = Math.abs(mdisp_vert); double adiff_vert = Math.abs(mdisp_vert);
if (adiff <= trustedCorrelation){ if (adiff <= trustedCorrelation){
double disp = mdisp/corr_magic_scale + pass.disparity[ty][tx]; double disp = mdisp/corr_magic + pass.disparity[ty][tx];
// do not consider tiles over background if they are far and initially identified as background // do not consider tiles over background if they are far and initially identified as background
// if ((bg_tiles == null) || !bg_tiles[nt] || (disp >= ex_min_over)) { // if ((bg_tiles == null) || !bg_tiles[nt] || (disp >= ex_min_over)) {
if ((disp >= disp_far) && (disp <= disp_near) && !Double.isNaN(adiff)){ if ((disp >= disp_far) && (disp <= disp_near) && !Double.isNaN(adiff)){
if (strength >= minStrength) { if (m_lma || (strength >= minStrength)) {
if (!(adiff >= adiff_best)){ // adiff_best == Double.NaN works too if (first_lma || !(adiff >= adiff_best)){ // adiff_best == Double.NaN works too
adiff_best = adiff; adiff_best = adiff;
best_index = ipass; best_index = ipass;
} }
quad_list.add(new DSD(ipass, disp, strength, adiff)); full_list.add(new DSD(ipass, disp, strength, adiff, m_lma));
} else { } else {
if ((last && (strength > 0.0)) || (!no_weak && (strength > strongest_weak))){ if ((last && (strength > 0.0)) || (!no_weak && (strength > strongest_weak))){
strongest_weak = strength; strongest_weak = strength; // definitely not LMA
best_weak_index = ipass; best_weak_index = ipass;
} }
} }
...@@ -1638,7 +1348,7 @@ ImageDtt.startAndJoin(threads); ...@@ -1638,7 +1348,7 @@ ImageDtt.startAndJoin(threads);
adiff_best_hor = adiff_hor; adiff_best_hor = adiff_hor;
best_index_hor = ipass; best_index_hor = ipass;
} }
hor_list.add(new DSD(ipass, disp_hor, strength_hor, adiff_hor)); hor_list.add(new DSD(ipass, disp_hor, strength_hor, adiff_hor, false)); // hor_lma not yet defined
} else { } else {
if ((last && (strength_hor > 0.0)) || (!no_weak && (strength_hor > strongest_weak_hor))){ if ((last && (strength_hor > 0.0)) || (!no_weak && (strength_hor > strongest_weak_hor))){
strongest_weak_hor = strength_hor; strongest_weak_hor = strength_hor;
...@@ -1656,7 +1366,7 @@ ImageDtt.startAndJoin(threads); ...@@ -1656,7 +1366,7 @@ ImageDtt.startAndJoin(threads);
adiff_best_vert = adiff_vert; adiff_best_vert = adiff_vert;
best_index_vert = ipass; best_index_vert = ipass;
} }
vert_list.add(new DSD(ipass, disp_vert, strength_vert, adiff_vert)); vert_list.add(new DSD(ipass, disp_vert, strength_vert, adiff_vert, false)); // vert_lma not yet defined
} else { } else {
if ((last && (strength_vert > 0.0)) || (!no_weak && (strength_vert > strongest_weak_vert))){ if ((last && (strength_vert > 0.0)) || (!no_weak && (strength_vert > strongest_weak_vert))){
strongest_weak_vert = strength_vert; strongest_weak_vert = strength_vert;
...@@ -1671,37 +1381,35 @@ ImageDtt.startAndJoin(threads); ...@@ -1671,37 +1381,35 @@ ImageDtt.startAndJoin(threads);
if (best_index < 0) best_index = best_weak_index; if (best_index < 0) best_index = best_weak_index;
if (best_index_hor < 0) best_index_hor = best_weak_index_hor; if (best_index_hor < 0) best_index_hor = best_weak_index_hor;
if (best_index_vert < 0) best_index_vert = best_weak_index_vert; if (best_index_vert < 0) best_index_vert = best_weak_index_vert;
//clt_parameters.gr_unique_tol //clt_parameters.gr_unique_tol
/* if (full_list.isEmpty()) {
private ArrayList<DSD> filterDsdList(
ArrayList<DSD> src_list,
double disp_tolerance,
int max_len,
boolean descending){ // false: disparity from far to near, true - near to far
final boolean descending = false; // disparity order in the result list
final double disparity_tolerance = 0.5; // minimal disparity to separate FG/BG
*/
if (quad_list.isEmpty()) {
if (best_index >= 0) { if (best_index >= 0) {
quad_list.add(new DSD(best_index)); // only index, disparity and strength full_list.add(new DSD(best_index)); // only index, disparity and strength
} }
} }
// now quad_list contains 0, 1 for weak, 1.. num_planes for enough strong ones // now full_list contains 0, 1 for weak, 1.. num_planes for enough strong ones
quad_list = filterDsdList( full_list = filterDsdList(
quad_list, // ArrayList<DSD> src_list, full_list, // ArrayList<DSD> src_list,
disparity_tolerance, // double disp_tolerance, disparity_tolerance, // double disp_tolerance,
num_planes, // int max_len, num_planes, // int max_len,
descending); // boolean descending) descending); // boolean descending)
for (int np = 0; np< quad_list.size(); np++) { for (int np = 0; np< full_list.size(); np++) {
CLTPass3d pass = passes.get(quad_list.get(np).indx); CLTPass3d pass = passes.get(full_list.get(np).indx);
CLTPass3d combo_pass = combo_pass_list.get(np); CLTPass3d combo_pass = combo_pass_list.get(np);
combo_pass.tile_op[ty][tx] = pass.tile_op[ty][tx]; combo_pass.tile_op[ty][tx] = pass.tile_op[ty][tx];
if (pass.texture_tiles != null) { if (pass.texture_tiles != null) {
combo_pass.texture_tiles[ty][tx] = pass.texture_tiles[ty][tx]; combo_pass.texture_tiles[ty][tx] = pass.texture_tiles[ty][tx];
} }
combo_pass.calc_disparity[nt] = pass.disparity_map[disparity_index][nt]/corr_magic_scale + pass.disparity[ty][tx]; double [] mdisp_lma_arr = pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY];
boolean m_lma = (mdisp_lma_arr != null) && !Double.isNaN(mdisp_lma_arr[nt]);
double mdisp = m_lma?
mdisp_lma_arr[nt] : pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt];
double corr_magic = m_lma ? corr_magic_scale_lma : corr_magic_scale;
// combo_pass.calc_disparity[nt] = pass.disparity_map[disparity_index][nt]/corr_magic_scale + pass.disparity[ty][tx];
combo_pass.calc_disparity[nt] = mdisp/corr_magic + pass.disparity[ty][tx];
combo_pass.strength[nt] = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt]; combo_pass.strength[nt] = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt];
combo_pass.has_lma[nt] = m_lma;
// Only copy for full disparity // Only copy for full disparity
for (int i = 0; i< numSensors; i++) { for (int i = 0; i< numSensors; i++) {
if (pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i]!= null) {// do not copy empty if (pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i]!= null) {// do not copy empty
...@@ -1712,20 +1420,25 @@ ImageDtt.startAndJoin(threads); ...@@ -1712,20 +1420,25 @@ ImageDtt.startAndJoin(threads);
if (copyDebug){ if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt]; combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt];
combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt] = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt]; combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt] = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY][nt];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY+1][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY+1][nt];
} }
} }
// fill empty planes (if any). May be all if there were no even weak tiles (old best_index<0) // fill empty planes (if any). May be all if there were no even weak tiles (old best_index<0)
for (int np = quad_list.size(); np < num_planes; np++) { for (int np = full_list.size(); np < num_planes; np++) {
CLTPass3d combo_pass = combo_pass_list.get(np); CLTPass3d combo_pass = combo_pass_list.get(np);
combo_pass.tile_op[ty][tx] = 0; combo_pass.tile_op[ty][tx] = 0;
combo_pass.texture_tiles[ty][tx] = null; combo_pass.texture_tiles[ty][tx] = null;
combo_pass.calc_disparity[nt] = Double.NaN; combo_pass.calc_disparity[nt] = Double.NaN;
combo_pass.strength[nt] = 0.0; combo_pass.strength[nt] = 0.0;
// combo_pass.has_lma[nt] = false;
// Only copy for full disparity // Only copy for full disparity
for (int i = 0; i< numSensors; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt] = Double.NaN; for (int i = 0; i< numSensors; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt] = Double.NaN;
if (copyDebug){ if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt] = Double.NaN; combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt] = Double.NaN;
combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt] = Double.NaN; combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt] = Double.NaN;
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY][nt] = Double.NaN;
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY+1][nt] = Double.NaN;
} }
} }
// TODO: For now hor/vert are added independently and are not synchronized to full-quad correlations // TODO: For now hor/vert are added independently and are not synchronized to full-quad correlations
...@@ -1808,6 +1521,9 @@ ImageDtt.startAndJoin(threads); ...@@ -1808,6 +1521,9 @@ ImageDtt.startAndJoin(threads);
} }
} }
} }
};
}
ImageDtt.startAndJoin(threads);
for (CLTPass3d combo_pass : combo_pass_list) { for (CLTPass3d combo_pass : combo_pass_list) {
// getDisparity(): calc_disparity_combo = calc_disparity.clone(); // getDisparity(): calc_disparity_combo = calc_disparity.clone();
combo_pass.getDisparity(); // See if it does not break anything - triggers calculation if not done yet combo_pass.getDisparity(); // See if it does not break anything - triggers calculation if not done yet
...@@ -1818,83 +1534,79 @@ ImageDtt.startAndJoin(threads); ...@@ -1818,83 +1534,79 @@ ImageDtt.startAndJoin(threads);
@Deprecated public int expandCertain (
public CLTPass3d compositeScanOld( final CLTPass3d combo_pass, // modify
final ArrayList <CLTPass3d> passes, final ArrayList <CLTPass3d> passes,
final int firstPass, final int firstPass,
final int lastPassPlus1, final int lastPassPlus1,
final double disp_avg_arange, // average neighbors with disparity not more than that from the lowest
final double disp_avg_rrange, // same, relative to disparity
final double disp_arange, // look for a fit within range from the neighbor
final double disp_rrange, // same, relative to disparity
final int min_defined, // minimal number of defined neighbors that fit into the range
final double trustedCorrelation, final double trustedCorrelation,
final double max_overexposure, final double max_overexposure,
final double disp_far, // limit results to the disparity range
final double disp_near,
final double minStrength,
final double minStrengthHor,
final double minStrengthVert,
final boolean no_weak,
final boolean use_last, //
// TODO: when useCombo - pay attention to borders (disregard)
final boolean usePoly, // use polynomial method to find max), valid if useCombo == false
final boolean copyDebug,
final int debugLevel) final int debugLevel)
{ {
final int dbg_tile = (debugLevel > 0)? 35114: -1; // x = 122, y= 108; -1; // 27669;
CLTPass3d combo_pass =new CLTPass3d(this);
final int tlen = tilesX * tilesY; final int tlen = tilesX * tilesY;
final int disparity_index = usePoly ? ImageDtt.DISPARITY_INDEX_POLY : ImageDtt.DISPARITY_INDEX_CM; final int dbg_tile = -1; // (debugLevel > 0)? 35114: -1; // x = 122, y= 108; -1; // 27669;
combo_pass.tile_op = new int [tilesY][tilesX]; // for just non-zero final boolean [] has_lma = combo_pass.getLMA();
// combo_pass.disparity_map = new double [ImageDtt.DISPARITY_TITLES.length][]; final boolean [] new_defined = has_lma.clone();
combo_pass.disparity_map = new double [ImageDtt.getDisparityTitles(getNumSensors()).length][]; final boolean [] added_defined =new boolean [new_defined.length];
for (int i = 0; i< numSensors; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i] = new double[tlen]; growTiles(
if (copyDebug){ 2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM] = new double[tlen]; new_defined, // boolean [] tiles,
combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX] = new double[tlen]; null); // boolean [] prohibit)
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR] = new double[tlen]; for (int i = 0; i < new_defined.length; i++) {
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH] = new double[tlen]; new_defined[i] &= !has_lma[i];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT] = new double[tlen];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH] = new double[tlen];
} }
// temporary:
// final CLTPass3d combo_pass0 = combo_pass_list.get(0);
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
final TileNeibs tn = new TileNeibs(tilesX, tilesY);
// for now - will copy from the best full correlation measurement for (int nTile = ai.getAndIncrement(); nTile < tlen; nTile = ai.getAndIncrement()) {
combo_pass.texture_tiles = new double [tilesY][tilesX][][]; int tx = nTile % tilesX;
combo_pass.max_tried_disparity = new double [tilesY][tilesX]; int ty = nTile / tilesX;
combo_pass.is_combo = true;
combo_pass.calc_disparity = new double [tlen];
combo_pass.calc_disparity_hor = new double [tlen];
combo_pass.calc_disparity_vert = new double [tlen];
combo_pass.strength = new double [tlen];
combo_pass.strength_hor = new double [tlen];
combo_pass.strength_vert = new double [tlen];
// * Calculates calc_disparity, calc_disparity_hor, calc_disparity_vert, strength, strength_hor, strength_vert,
for (int ty = 0; ty < tilesY; ty ++) for (int tx = 0; tx < tilesX; tx ++) combo_pass.texture_tiles[ty][tx] = null;
for (int ty = 0; ty < tilesY; ty ++) {
for (int tx = 0; tx < tilesX; tx ++){
int nt = ty * tilesX + tx; int nt = ty * tilesX + tx;
int best_index = -1; if (new_defined[nt]) {
int best_index_hor = -1; double [] neib_lma = new double[8];
int best_index_vert = -1; double min_disp = Double.NaN;
int best_weak_index = -1; for (int dir = 0; dir < neib_lma.length; dir++) {
int best_weak_index_hor = -1; int nt1 = tn.getNeibIndex(nt, dir);
int best_weak_index_vert = -1; if ((nt1 >= 0) && has_lma[nt1]) {
// for "strong" result (above minStrength) the best fit is with smallest residual disparity neib_lma[dir] = combo_pass.calc_disparity[nt1];
// for weak ones - the strongest. if (!(neib_lma[dir] >= min_disp)) { // for NaN
// TODO: handle ortho (if requested so) min_disp = neib_lma[dir];
// after refine - use last, after extend - use strongest of all }
} else {
double adiff_best = Double.NaN; neib_lma[dir] = Double.NaN;
double adiff_best_hor = Double.NaN; }
double adiff_best_vert = Double.NaN; }
double strongest_weak = 0.0; double max_disp = min_disp * (1.0 + disp_avg_rrange) + disp_avg_arange;
double strongest_weak_hor = 0.0; double sw=0.0, swd = 0.0;
double strongest_weak_vert = 0.0; int num_neibs = 0;
for (int dir = 0; dir < neib_lma.length; dir++) {
combo_pass.max_tried_disparity[ty][tx] = Double.NaN; if (neib_lma[dir] <= max_disp) {
if (nt == dbg_tile) { double w = 1.0; // use any weights here?
System.out.println("compositeScan(): nt = "+nt); sw += w;
swd += w * neib_lma[dir];
num_neibs++;
} }
}
if (num_neibs >= min_defined) {
//min_defined
double avg_lma = swd/sw;
// Now find "best fit": smallest residual within range
double drange = Math.max(disp_arange, disp_rrange * avg_lma);
int best_index = -1;
double best_adiff = Double.NaN;
for (int ipass = firstPass; ipass <lastPassPlus1; ipass++ ){ for (int ipass = firstPass; ipass <lastPassPlus1; ipass++ ){
CLTPass3d pass = passes.get(ipass); CLTPass3d pass = passes.get(ipass);
if (nt == dbg_tile) { if (nt == dbg_tile) {
...@@ -1902,154 +1614,56 @@ ImageDtt.startAndJoin(threads); ...@@ -1902,154 +1614,56 @@ ImageDtt.startAndJoin(threads);
" pass.isCombo()="+(pass.isCombo())+" pass.isProcessed()="+(pass.isProcessed())); " pass.isCombo()="+(pass.isCombo())+" pass.isProcessed()="+(pass.isProcessed()));
} }
if ( pass.isMeasured() && (pass.tile_op[ty][tx] != 0 )) { // current tile has valid data if ( pass.isMeasured() && (pass.tile_op[ty][tx] != 0 )) { // current tile has valid data
if ( (Double.isNaN(combo_pass.max_tried_disparity[ty][tx]) || double mdisp = pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt];
(pass.disparity[ty][tx] > combo_pass.max_tried_disparity[ty][tx]))){
combo_pass.max_tried_disparity[ty][tx] = pass.disparity[ty][tx];
}
boolean last = (ipass == (lastPassPlus1-1)) && use_last;
double mdisp = pass.disparity_map[disparity_index][nt];
double mdisp_hor = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt];
double mdisp_vert = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT][nt];
double strength = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt];
double strength_hor = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH][nt];
double strength_vert = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH][nt];
boolean overexposed = (max_overexposure > 0.0) && boolean overexposed = (max_overexposure > 0.0) &&
(pass.disparity_map[ImageDtt.OVEREXPOSED] != null) && (pass.disparity_map[ImageDtt.OVEREXPOSED] != null) &&
(pass.disparity_map[ImageDtt.OVEREXPOSED][nt] > max_overexposure); (pass.disparity_map[ImageDtt.OVEREXPOSED][nt] > max_overexposure);
if (!overexposed) { if (!overexposed) {
double adiff = Math.abs(mdisp); double adiff = Math.abs(mdisp);
double adiff_hor = Math.abs(mdisp_hor);
double adiff_vert = Math.abs(mdisp_vert);
if (adiff <= trustedCorrelation){ if (adiff <= trustedCorrelation){
double disp = mdisp/corr_magic_scale + pass.disparity[ty][tx]; double disp = mdisp/corr_magic_scale + pass.disparity[ty][tx];
// do not consider tiles over background if they are far and initially identified as background double disp_adiff = Math.abs(disp - avg_lma);
// if ((bg_tiles == null) || !bg_tiles[nt] || (disp >= ex_min_over)) { if (disp_adiff <= drange) {
if ((disp >= disp_far) && (disp <= disp_near) && !Double.isNaN(adiff)){ if (!(best_adiff <= adiff)) {
if (strength >= minStrength) { best_adiff = adiff;
if (!(adiff >= adiff_best)){ // adiff_best == Double.NaN works too
adiff_best = adiff;
best_index = ipass; best_index = ipass;
} }
} else {
if ((last && (strength > 0.0)) || (!no_weak && (strength > strongest_weak))){
strongest_weak = strength;
best_weak_index = ipass;
}
}
}
// }
} }
if (!Double.isNaN(minStrengthHor) && (adiff_hor <= trustedCorrelation)){
double disp_hor = mdisp_hor/corr_magic_scale + pass.disparity[ty][tx];
if ((disp_hor >= disp_far) && (disp_hor <= disp_near) && !Double.isNaN(adiff_hor)){
if (strength_hor >= minStrengthHor) {
if (!(adiff_hor >= adiff_best_hor)){ // adiff_best == Double.NaN works too
adiff_best_hor = adiff_hor;
best_index_hor = ipass;
} }
} else {
if ((last && (strength_hor > 0.0)) || (!no_weak && (strength_hor > strongest_weak_hor))){
strongest_weak_hor = strength_hor;
best_weak_index_hor = ipass;
} }
} }
} }
if (best_index >= 0) {
CLTPass3d pass = passes.get(best_index);
added_defined[nt] = true;
if (pass.texture_tiles != null) {
combo_pass.texture_tiles[ty][tx] = pass.texture_tiles[ty][tx];
} }
combo_pass.calc_disparity[nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt]/corr_magic_scale + pass.disparity[ty][tx];
if (!Double.isNaN(minStrengthVert) && (adiff_vert <= trustedCorrelation)){ combo_pass.strength[nt] = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt];
double disp_vert = mdisp_vert/corr_magic_scale + pass.disparity[ty][tx];
if ((disp_vert >= disp_far) && (disp_vert <= disp_near) && !Double.isNaN(adiff_vert)){
if (strength_vert >= minStrengthVert) {
if (!(adiff_vert >= adiff_best_vert)){ // adiff_best == Double.NaN works too
adiff_best_vert = adiff_vert;
best_index_vert = ipass;
} }
} else {
if ((last && (strength_vert > 0.0)) || (!no_weak && (strength_vert > strongest_weak_vert))){
strongest_weak_vert = strength_vert;
best_weak_index_vert = ipass;
} }
} }
} }
} }
};
} }
ImageDtt.startAndJoin(threads);
int num_new = 0;
for (int i = 0; i < added_defined.length; i++) if (added_defined[i]){
has_lma[i] = true;
num_new++;
} }
combo_pass.setLMA(has_lma);
// combo_pass.calc_disparity_combo = combo_pass.calc_disparity.clone();
return num_new; // combo_pass_list;
} }
if (best_index < 0) best_index = best_weak_index;
if (best_index_hor < 0) best_index_hor = best_weak_index_hor;
if (best_index_vert < 0) best_index_vert = best_weak_index_vert;
if (best_index >= 0){
CLTPass3d pass = passes.get(best_index);
combo_pass.tile_op[ty][tx] = pass.tile_op[ty][tx];
if (pass.texture_tiles != null) {
combo_pass.texture_tiles[ty][tx] = pass.texture_tiles[ty][tx];
}
combo_pass.calc_disparity[nt] = pass.disparity_map[disparity_index][nt]/corr_magic_scale + pass.disparity[ty][tx];
combo_pass.strength[nt] = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt];
// Only copy for full disparity
for (int i = 0; i< numSensors; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt] = pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt];
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt];
combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt] = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt];
}
} else {
combo_pass.calc_disparity[nt] = Double.NaN;
combo_pass.strength[nt] = 0.0;
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt] = Double.NaN;
combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt] = 0.0;
}
}
if (best_index_hor >= 0){
CLTPass3d pass = passes.get(best_index_hor);
combo_pass.tile_op[ty][tx] = pass.tile_op[ty][tx]; // just non-zero
combo_pass.calc_disparity_hor[nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt]/corr_magic_scale + pass.disparity[ty][tx];
combo_pass.strength_hor[nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH][nt];
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH][nt];
}
} else {
combo_pass.calc_disparity_hor[nt] = Double.NaN;
combo_pass.strength_hor[nt] = 0.0;
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR][nt] = Double.NaN;
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH][nt] = 0.0;
}
}
if (best_index_vert >= 0){
CLTPass3d pass = passes.get(best_index_vert);
combo_pass.tile_op[ty][tx] = pass.tile_op[ty][tx]; // just non-zero
combo_pass.calc_disparity_vert[nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT][nt]/corr_magic_scale + pass.disparity[ty][tx];
combo_pass.strength_vert[nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH][nt];
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT][nt];
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH][nt];
}
} else {
combo_pass.calc_disparity_vert[nt] = Double.NaN;
combo_pass.strength_vert[nt] = 0.0;
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT][nt] = Double.NaN;
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH][nt] = 0.0;
}
}
}
}
combo_pass.getDisparity(); // See if it does not break anything - triggers calculation if not done yet
combo_pass.fixNaNDisparity(); // mostly for debug, measured disparity should be already fixed from NaN
return combo_pass;
}
/** /**
...@@ -3369,6 +2983,7 @@ ImageDtt.startAndJoin(threads); ...@@ -3369,6 +2983,7 @@ ImageDtt.startAndJoin(threads);
scan.getDisparity(), // final double [] disparity, // current disparity value scan.getDisparity(), // final double [] disparity, // current disparity value
scan.getDisparity().clone(), // final double [] measured_disparity, // measured disparity scan.getDisparity().clone(), // final double [] measured_disparity, // measured disparity
scan.getStrength(), // final double [] strength, scan.getStrength(), // final double [] strength,
scan.hasLMADefined(),
null, // this_hor_disparity, // final double hor_disparity, // not yet used null, // this_hor_disparity, // final double hor_disparity, // not yet used
null, // hor_strength_conv, // final double hor_strength, // not yet used null, // hor_strength_conv, // final double hor_strength, // not yet used
known_tiles, // these_tiles, // grown, // these_tiles, // final boolean [] selected, known_tiles, // these_tiles, // grown, // these_tiles, // final boolean [] selected,
...@@ -3778,26 +3393,29 @@ ImageDtt.startAndJoin(threads); ...@@ -3778,26 +3393,29 @@ ImageDtt.startAndJoin(threads);
// boolean [] ly_force = scan.getLazyEyeForceDisparity(); // boolean [] ly_force = scan.getLazyEyeForceDisparity();
int i_tile_op = getScanTitleIndex("tile_op"); // 0 int i_tile_op = getScanTitleIndex("tile_op"); // 0
int i_final = getScanTitleIndex("final"); // 1 int i_final = getScanTitleIndex("final"); // 1
int i_disparity = getScanTitleIndex("disparity"); // 2 int i_calc = getScanTitleIndex("calc"); // 2
int i_disp_cm = getScanTitleIndex("disp_cm"); // 3 int i_calc_lma = getScanTitleIndex("calc_lma"); // 3
int i_disp_hor = getScanTitleIndex("disp_hor"); // 4 int i_disparity = getScanTitleIndex("disparity"); // 4
int i_disp_vert = getScanTitleIndex("disp_vert"); // 5 int i_disp_cm = getScanTitleIndex("disp_cm"); // 5
int i_final_strength = getScanTitleIndex("final_strength"); // 6 int i_disp_hor = getScanTitleIndex("disp_hor"); // 6
int i_strength = getScanTitleIndex("strength"); // 7 int i_disp_vert = getScanTitleIndex("disp_vert"); // 7
int i_strength_hor = getScanTitleIndex("strength_hor"); // 8 int i_final_strength = getScanTitleIndex("final_strength"); // 8
int i_strength_vert = getScanTitleIndex("strength_vert"); // 9 int i_strength = getScanTitleIndex("strength"); // 9
int i_selection = getScanTitleIndex("selection"); // 10 int i_strength_hor = getScanTitleIndex("strength_hor"); // 10
int i_border_tiles = getScanTitleIndex("border_tiles"); // 11 int i_strength_vert = getScanTitleIndex("strength_vert"); // 11
int i_max_tried = getScanTitleIndex("max_tried"); // 12 int i_selection = getScanTitleIndex("selection"); // 12
int i_diff0 = getScanTitleIndex("diff0"); // 13* int i_border_tiles = getScanTitleIndex("border_tiles"); // 13
int i_diff2max = getScanTitleIndex("diff2max"); // 17* int i_has_lma = getScanTitleIndex("has_lma"); // 14
int i_diff2maxAvg = getScanTitleIndex("diff2maxAvg"); // 18* int i_max_tried = getScanTitleIndex("max_tried"); // 15 12
int i_normStrength = getScanTitleIndex("normStrength"); // 19* int i_diff0 = getScanTitleIndex("diff0"); // 16 13*
int i_overexp = getScanTitleIndex("overexp"); // 20* int i_diff2max = getScanTitleIndex("diff2max"); // 20 17*
int i_diff2maxAvg = getScanTitleIndex("diff2maxAvg"); // 21 18*
int i_normStrength = getScanTitleIndex("normStrength"); // 22 19*
int i_overexp = getScanTitleIndex("overexp"); // 23 20*
int i_getImgToneRGB = ImageDtt.getImgToneRGB(numSensors); int i_getImgToneRGB = ImageDtt.getImgToneRGB(numSensors);
boolean [] has_lma = scan.getLMA(); // .hasLMADefined();
int tlen = tilesX*tilesY; int tlen = tilesX*tilesY;
if (scan.tile_op == null) measured_only = false; if (scan.tile_op == null) measured_only = false;
boolean [] measured = new boolean [tlen]; boolean [] measured = new boolean [tlen];
...@@ -3806,12 +3424,18 @@ ImageDtt.startAndJoin(threads); ...@@ -3806,12 +3424,18 @@ ImageDtt.startAndJoin(threads);
if (scan.disparity != null) dbg_img[i_disparity] = new double[tlen]; if (scan.disparity != null) dbg_img[i_disparity] = new double[tlen];
if (scan.getSelected() != null) dbg_img[i_selection] = new double[tlen]; if (scan.getSelected() != null) dbg_img[i_selection] = new double[tlen];
if (scan.getBorderTiles() != null) dbg_img[i_border_tiles] = new double[tlen]; if (scan.getBorderTiles() != null) dbg_img[i_border_tiles] = new double[tlen];
if (has_lma != null) dbg_img[i_has_lma] = new double[tlen];
if (scan.max_tried_disparity != null) dbg_img[i_max_tried] = new double[tlen]; if (scan.max_tried_disparity != null) dbg_img[i_max_tried] = new double[tlen];
// if (ly_force != null) dbg_img[ly_force_indx] = new double[tlen]; // if (ly_force != null) dbg_img[ly_force_indx] = new double[tlen];
boolean [] gotSelected = scan.getSelected(); boolean [] gotSelected = scan.getSelected();
boolean [] gotBorderTiles = scan.getBorderTiles(); boolean [] gotBorderTiles = scan.getBorderTiles();
dbg_img[i_final] = scan.calc_disparity_combo;
dbg_img[i_calc] = scan.calc_disparity;
if ((has_lma != null) &&(dbg_img[i_calc] !=null)) {
dbg_img[i_calc_lma] = dbg_img[i_calc].clone();
}
for (int ty = 0; ty < tilesY; ty++) for (int tx = 0; tx < tilesX; tx++){ for (int ty = 0; ty < tilesY; ty++) for (int tx = 0; tx < tilesX; tx++){
int nt = ty*tilesX + tx; int nt = ty*tilesX + tx;
if (scan.tile_op != null) { if (scan.tile_op != null) {
...@@ -3821,13 +3445,14 @@ ImageDtt.startAndJoin(threads); ...@@ -3821,13 +3445,14 @@ ImageDtt.startAndJoin(threads);
if (scan.disparity != null) dbg_img[i_disparity] [nt] = scan.disparity[ty][tx]; if (scan.disparity != null) dbg_img[i_disparity] [nt] = scan.disparity[ty][tx];
// if (scan.selected != null) dbg_img[i_selection] [nt] = scan.selected[nt]? 1.0:0.0; // if (scan.selected != null) dbg_img[i_selection] [nt] = scan.selected[nt]? 1.0:0.0;
if (gotSelected != null) dbg_img[i_selection] [nt] = gotSelected[nt]? 1.0:0.0; if (gotSelected != null) dbg_img[i_selection] [nt] = gotSelected[nt]? 1.0:0.0;
if (has_lma != null) dbg_img[i_has_lma] [nt] = has_lma[nt]? 1.0:0.0;
if ((dbg_img[i_calc_lma] != null) && !has_lma[nt]) dbg_img[i_calc_lma] [nt] = Double.NaN;
if (gotBorderTiles != null) dbg_img[i_border_tiles][nt] = gotBorderTiles[nt]? 1.0:0.0; if (gotBorderTiles != null) dbg_img[i_border_tiles][nt] = gotBorderTiles[nt]? 1.0:0.0;
if (scan.max_tried_disparity != null) dbg_img[i_max_tried] [nt] = scan.max_tried_disparity[ty][tx]; if (scan.max_tried_disparity != null) dbg_img[i_max_tried] [nt] = scan.max_tried_disparity[ty][tx];
// if (ly_force != null) dbg_img[ly_force_indx][nt] = ly_force[nt]? 1.0:0.0; // if (ly_force != null) dbg_img[ly_force_indx][nt] = ly_force[nt]? 1.0:0.0;
} }
double [] strength4 = null; double [] strength4 = null;
if (scan.disparity_map != null){ if (scan.disparity_map != null){
strength4 = scan.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX]; strength4 = scan.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX];
dbg_img[i_disp_cm] = scan.disparity_map[ImageDtt.DISPARITY_INDEX_CM]; dbg_img[i_disp_cm] = scan.disparity_map[ImageDtt.DISPARITY_INDEX_CM];
dbg_img[i_disp_hor] = scan.disparity_map[ImageDtt.DISPARITY_INDEX_HOR]; dbg_img[i_disp_hor] = scan.disparity_map[ImageDtt.DISPARITY_INDEX_HOR];
...@@ -3843,7 +3468,7 @@ ImageDtt.startAndJoin(threads); ...@@ -3843,7 +3468,7 @@ ImageDtt.startAndJoin(threads);
dbg_img[this_IMG_TONE_RGB+i] = scan.disparity_map[i_getImgToneRGB + i]; dbg_img[this_IMG_TONE_RGB+i] = scan.disparity_map[i_getImgToneRGB + i];
} }
} }
dbg_img[i_final] = scan.calc_disparity_combo;
dbg_img[i_final_strength] = scan.strength; dbg_img[i_final_strength] = scan.strength;
double [][] these_diffs = scan.getDiffs(); double [][] these_diffs = scan.getDiffs();
double [] diff2max = scan.getSecondMaxDiff(false); double [] diff2max = scan.getSecondMaxDiff(false);
...@@ -3897,33 +3522,35 @@ ImageDtt.startAndJoin(threads); ...@@ -3897,33 +3522,35 @@ ImageDtt.startAndJoin(threads);
double sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd double sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd
int min_clstr_seed, // number of tiles in a cluster to seed (just background?) int min_clstr_seed, // number of tiles in a cluster to seed (just background?)
int min_clstr_block, // number of tiles in a cluster to block (just non-background?) int min_clstr_block, // number of tiles in a cluster to block (just non-background?)
int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4) // int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
boolean show_bgnd_nonbgnd, boolean show_bgnd_nonbgnd,
int debugLevel int debugLevel
){ ){
boolean [] bgnd_tiles = new boolean [tilesY * tilesX]; boolean [] bgnd_tiles = new boolean [tilesY * tilesX];
boolean [] nonbgnd_tiles = new boolean [tilesY * tilesX]; boolean [] nonbgnd_tiles = new boolean [tilesY * tilesX];
boolean [] block_propagate = new boolean [tilesY * tilesX]; boolean [] block_propagate = new boolean [tilesY * tilesX];
// int quad = 4;
ShowDoubleFloatArrays sdfa_instance = null; ShowDoubleFloatArrays sdfa_instance = null;
if (debugLevel > -1) if (debugLevel > -1)
sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging? sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging?
CLTPass3d bgnd_data = clt_3d_passes.get(0); CLTPass3d bgnd_data = clt_3d_passes.get(0);
double [][] disparity_map= bgnd_data.disparity_map; double [][] disparity_map= bgnd_data.disparity_map;
double [] disparity = bgnd_data.getDisparity();
double [] strength = bgnd_data.getStrength();
boolean [] has_lma = bgnd_data.hasLMADefined(); // trust LMA regardless of strength
int [] dbg_numtile = new int [2]; int [] dbg_numtile = new int [2];
for (int tileY = 0; tileY < tilesY; tileY++){ for (int tindx = 0; tindx < disparity.length; tindx++) {
for (int tileX = 0; tileX < tilesX; tileX++){ // if (Math.abs(disparity_map[disparity_index][tindx]) < bgnd_range){
int tindx = tileY * tilesX + tileX; if (Math.abs(disparity[tindx]) < bgnd_range){
// if (disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][tindx] >= bgnd_sure){
if (Math.abs(disparity_map[disparity_index][tindx]) < bgnd_range){ if (has_lma [tindx] || (strength[tindx] >= bgnd_sure)){
if (disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][tindx] >= bgnd_sure){
bgnd_tiles[tindx] = true; bgnd_tiles[tindx] = true;
dbg_numtile[0]++; dbg_numtile[0]++;
} }
} else { } else {
if (disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][tindx] > bgnd_maybe){ // maybe non-bkgnd // if (disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][tindx] > bgnd_maybe){ // maybe non-bkgnd
if (disparity_map[disparity_index][tindx] > 0.0) { // disregard negative disparity points if (has_lma [tindx] || (strength[tindx] >= bgnd_maybe)){ // maybe non-bkgnd
// if (disparity_map[disparity_index][tindx] > 0.0) { // disregard negative disparity points
if (disparity[tindx] > 0.0) { // disregard negative disparity points
nonbgnd_tiles[tindx] = true; nonbgnd_tiles[tindx] = true;
dbg_numtile[1]++; dbg_numtile[1]++;
} }
...@@ -3940,7 +3567,6 @@ ImageDtt.startAndJoin(threads); ...@@ -3940,7 +3567,6 @@ ImageDtt.startAndJoin(threads);
} }
block_propagate[tindx] = (disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax2][tindx] > sure_smth); block_propagate[tindx] = (disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax2][tindx] > sure_smth);
} }
}
if (debugLevel > -1) { if (debugLevel > -1) {
System.out.println("Before removing small clusters: number of background tiles = "+dbg_numtile[0]+", non-bgnd tiles = "+dbg_numtile[1]); System.out.println("Before removing small clusters: number of background tiles = "+dbg_numtile[0]+", non-bgnd tiles = "+dbg_numtile[1]);
} }
...@@ -3975,14 +3601,15 @@ ImageDtt.startAndJoin(threads); ...@@ -3975,14 +3601,15 @@ ImageDtt.startAndJoin(threads);
} }
if ((sdfa_instance != null) && show_bgnd_nonbgnd) { if ((sdfa_instance != null) && show_bgnd_nonbgnd) {
String [] titles = {"bgnd","nonbgnd","block","strength","disparity"}; String [] titles = {"bgnd","nonbgnd","block","strength","disparity","LMA"};
double [][] dbg_img = new double[titles.length][tilesY * tilesX]; double [][] dbg_img = new double[titles.length][tilesY * tilesX];
for (int i = 0; i<dbg_img[0].length;i++){ for (int i = 0; i<dbg_img[0].length;i++){
dbg_img[0][i] = bgnd_tiles [i] ? 1 : 0; dbg_img[0][i] = bgnd_tiles [i] ? 1 : 0;
dbg_img[1][i] = nonbgnd_tiles [i] ? 1 : 0; dbg_img[1][i] = nonbgnd_tiles [i] ? 1 : 0;
dbg_img[2][i] = block_propagate[i] ? 1 : 0; dbg_img[2][i] = block_propagate[i] ? 1 : 0;
dbg_img[3][i] = disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][i]; dbg_img[3][i] = strength[i]; // disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][i];
dbg_img[4][i] = disparity_map[disparity_index][i]; dbg_img[4][i] = disparity[i]; //disparity_map[disparity_index][i];
dbg_img[5][i] = has_lma[i] ? 1 : 0;
} }
sdfa_instance.showArrays(dbg_img, tilesX, tilesY, true, "bgnd_nonbgnd",titles); sdfa_instance.showArrays(dbg_img, tilesX, tilesY, true, "bgnd_nonbgnd",titles);
} }
...@@ -4053,7 +3680,7 @@ ImageDtt.startAndJoin(threads); ...@@ -4053,7 +3680,7 @@ ImageDtt.startAndJoin(threads);
double sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd double sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd
int min_clstr_seed, // number of tiles in a cluster to seed (just background?) int min_clstr_seed, // number of tiles in a cluster to seed (just background?)
int min_clstr_block, // number of tiles in a cluster to block (just non-background?) int min_clstr_block, // number of tiles in a cluster to block (just non-background?)
int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4) // int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
boolean show_bgnd_nonbgnd, boolean show_bgnd_nonbgnd,
int debugLevel int debugLevel
){ ){
...@@ -4064,25 +3691,29 @@ ImageDtt.startAndJoin(threads); ...@@ -4064,25 +3691,29 @@ ImageDtt.startAndJoin(threads);
ShowDoubleFloatArrays sdfa_instance = null; ShowDoubleFloatArrays sdfa_instance = null;
if (debugLevel > -1) if (debugLevel > -1)
sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging? sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging?
// boolean [] new_tiles = new boolean [tilesY * tilesX]; // grow selection by 1 tile over non-background?
CLTPass3d bgnd_data = clt_3d_passes.get(0); CLTPass3d bgnd_data = clt_3d_passes.get(0);
// double [][][][] texture_tiles = bgnd_data.texture_tiles; double [] disparity = bgnd_data.getDisparity();
double [] strength = bgnd_data.getStrength();
boolean [] has_lma = bgnd_data.hasLMADefined(); // trust LMA regardless of strength
double [][] disparity_map= bgnd_data.disparity_map; double [][] disparity_map= bgnd_data.disparity_map;
double [] dbg_worst2 = new double [disparity_map[ImageDtt.IMG_DIFF0_INDEX].length]; double [] dbg_worst2 = new double [disparity_map[ImageDtt.IMG_DIFF0_INDEX].length];
final TileNeibs tnSurface = new TileNeibs(tilesX, tilesY); final TileNeibs tnSurface = new TileNeibs(tilesX, tilesY);
for (int tileY = 0; tileY < tilesY; tileY++){ // for (int tileY = 0; tileY < tilesY; tileY++){
for (int tileX = 0; tileX < tilesX; tileX++){ // for (int tileX = 0; tileX < tilesX; tileX++){
int tindx = tileY * tilesX + tileX; for (int tindx = 0; tindx < disparity.length; tindx++) {
// int tindx = tileY * tilesX + tileX;
if (Math.abs(disparity_map[disparity_index][tindx]) < bgnd_range){ // if (Math.abs(disparity_map[disparity_index][tindx]) < bgnd_range){
if (disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][tindx] >= bgnd_sure){ if (Math.abs(disparity[tindx]) < bgnd_range){
// if (disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][tindx] >= bgnd_sure){
if (has_lma [tindx] || (strength[tindx] >= bgnd_sure)){
bgnd_tiles[tindx] = true; bgnd_tiles[tindx] = true;
} }
} else { } else {
if (disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][tindx] > bgnd_maybe){ // maybe non-bkgnd // if (disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][tindx] > bgnd_maybe){ // maybe non-bkgnd
if (disparity_map[disparity_index][tindx] > 0.0) { // disregard negative disparity points if (has_lma [tindx] || (strength[tindx] >= bgnd_maybe)){ // maybe non-bkgnd
// if (disparity_map[disparity_index][tindx] > 0.0) { // disregard negative disparity points
if (disparity[tindx] > 0.0) { // disregard negative disparity points
nonbgnd_tiles[tindx] = true; nonbgnd_tiles[tindx] = true;
} }
} }
...@@ -4092,7 +3723,7 @@ ImageDtt.startAndJoin(threads); ...@@ -4092,7 +3723,7 @@ ImageDtt.startAndJoin(threads);
double worst1 = 0.0; double worst1 = 0.0;
// modified to look around for the 1-st maximum // modified to look around for the 1-st maximum
for (int i = 1; i< getNumSensors(); i++){ for (int i = 1; i< getNumSensors(); i++){
// if (disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx] > disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax1][tindx]){ // if (disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx] > disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax1][tindx]){
if (disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx] > worst1){ if (disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx] > worst1){
imax1 = i; imax1 = i;
worst1 = disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx]; worst1 = disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx];
...@@ -4115,7 +3746,7 @@ ImageDtt.startAndJoin(threads); ...@@ -4115,7 +3746,7 @@ ImageDtt.startAndJoin(threads);
block_propagate[tindx] = (disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax2][tindx] > sure_smth); block_propagate[tindx] = (disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax2][tindx] > sure_smth);
} }
} // }
// grow block by 1 ? // grow block by 1 ?
tnSurface.growSelection( tnSurface.growSelection(
2, // grow, 2, // grow,
...@@ -4148,14 +3779,15 @@ ImageDtt.startAndJoin(threads); ...@@ -4148,14 +3779,15 @@ ImageDtt.startAndJoin(threads);
} }
if ((sdfa_instance != null) && show_bgnd_nonbgnd) { if ((sdfa_instance != null) && show_bgnd_nonbgnd) {
String [] titles = {"bgnd","nonbgnd","block","strength","disparity"}; String [] titles = {"bgnd","nonbgnd","block","strength","disparity","LMA"};
double [][] dbg_img = new double[titles.length][tilesY * tilesX]; double [][] dbg_img = new double[titles.length][tilesY * tilesX];
for (int i = 0; i<dbg_img[0].length;i++){ for (int i = 0; i<dbg_img[0].length;i++){
dbg_img[0][i] = bgnd_tiles [i] ? 1 : 0; dbg_img[0][i] = bgnd_tiles [i] ? 1 : 0;
dbg_img[1][i] = nonbgnd_tiles [i] ? 1 : 0; dbg_img[1][i] = nonbgnd_tiles [i] ? 1 : 0;
dbg_img[2][i] = block_propagate[i] ? 1 : 0; dbg_img[2][i] = block_propagate[i] ? 1 : 0;
dbg_img[3][i] = disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][i]; dbg_img[3][i] = strength[i];
dbg_img[4][i] = disparity_map[disparity_index][i]; dbg_img[4][i] = disparity[i];
dbg_img[5][i] = has_lma[i] ? 1 : 0;
} }
sdfa_instance.showArrays(dbg_img, tilesX, tilesY, true, "bgnd_nonbgnd_new",titles); sdfa_instance.showArrays(dbg_img, tilesX, tilesY, true, "bgnd_nonbgnd_new",titles);
} }
...@@ -5284,7 +4916,7 @@ ImageDtt.startAndJoin(threads); ...@@ -5284,7 +4916,7 @@ ImageDtt.startAndJoin(threads);
{ {
// final double super_trust = 1.6; // If strength exceeds ex_strength * super_trust, do not apply ex_nstrength // final double super_trust = 1.6; // If strength exceeds ex_strength * super_trust, do not apply ex_nstrength
final int dbg_tile = -41030; // x = 206, y = 126 (324*126+206) final int dbg_tile = -410300; // x = 206, y = 126 (324*126+206)
final boolean show_scan = show_filter_scan || (debugLevel > 1); final boolean show_scan = show_filter_scan || (debugLevel > 1);
ShowDoubleFloatArrays sdfa_instance = null; ShowDoubleFloatArrays sdfa_instance = null;
if ((debugLevel > -2) && ((debugLevel > -1) || show_scan)) sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging? if ((debugLevel > -2) && ((debugLevel > -1) || show_scan)) sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging?
...@@ -5297,6 +4929,7 @@ ImageDtt.startAndJoin(threads); ...@@ -5297,6 +4929,7 @@ ImageDtt.startAndJoin(threads);
final int tlen = tilesY * tilesX; final int tlen = tilesY * tilesX;
double [] this_disparity = scan.getDisparity(); // currently calculated, including ortho double [] this_disparity = scan.getDisparity(); // currently calculated, including ortho
double [] this_strength = scan.getStrength(); // cloned, can be modified/ read back double [] this_strength = scan.getStrength(); // cloned, can be modified/ read back
boolean [] has_lma = scan.hasLMADefined(); // true - any strength
double [][] these_diffs = scan.getDiffs(); double [][] these_diffs = scan.getDiffs();
// double [] orig_strength = scan.getOriginalStrength(); // to compare clusters // double [] orig_strength = scan.getOriginalStrength(); // to compare clusters
...@@ -5318,7 +4951,7 @@ ImageDtt.startAndJoin(threads); ...@@ -5318,7 +4951,7 @@ ImageDtt.startAndJoin(threads);
} }
if (this_disparity[i] < disparity_far) { if (this_disparity[i] < disparity_far) {
if (this_strength[i] > this_maybe){ if (has_lma[i] || (this_strength[i] > this_maybe)){
if (bg_tiles[i]) { // far can only be among previously selected for bgnd? bg_tiles = null ? if (bg_tiles[i]) { // far can only be among previously selected for bgnd? bg_tiles = null ?
far_tiles[i] = true; far_tiles[i] = true;
} }
...@@ -5326,16 +4959,16 @@ ImageDtt.startAndJoin(threads); ...@@ -5326,16 +4959,16 @@ ImageDtt.startAndJoin(threads);
} else if (this_disparity[i] > disparity_near){ } else if (this_disparity[i] > disparity_near){
// if ((this_strength[i] > this_maybe) && ! bg_tiles[i]){ // can not be farther if selected for near? // if ((this_strength[i] > this_maybe) && ! bg_tiles[i]){ // can not be farther if selected for near?
// if ((this_strength[i] > this_maybe) || used_hor[i] || used_vert[i] ){ // can not be farther if selected for near? // if ((this_strength[i] > this_maybe) || used_hor[i] || used_vert[i] ){ // can not be farther if selected for near?
if ((this_strength[i] > this_maybe)){ // can not be farther if selected for near? if (has_lma[i] || (this_strength[i] > this_maybe)){ // can not be farther if selected for near?
near_tiles[i] = true; near_tiles[i] = true;
} }
} else { // in range } else { // in range
// Higher difference, higher the correlation strength is needed // Higher difference, higher the correlation strength is needed
// assuming this_strength is combine of the strength4 and hor/vert, apply to any // assuming this_strength is combine of the strength4 and hor/vert, apply to any
// if (!bg_tiles[i] || (this_disparity[i] >= ex_min_over)) { // if (!bg_tiles[i] || (this_disparity[i] >= ex_min_over)) {
if ((this_strength[i] > ex_strength) || (horVertMod != null) && (horVertMod[i] != 0)){ if (has_lma[i] || (this_strength[i] > ex_strength) || (horVertMod != null) && (horVertMod[i] != 0)){
these_tiles[i] = true; these_tiles[i] = true;
if (this_strength[i] < ex_strength* super_trust) { if (!has_lma[i] && (this_strength[i] < ex_strength* super_trust)) {
if (second_max_diff != null) { // only apply to the border tiles, so by next pass they () weak can be used? if (second_max_diff != null) { // only apply to the border tiles, so by next pass they () weak can be used?
if (border_tiles[i] && (this_strength[i] < second_max_diff[i] * ex_nstrength)) { if (border_tiles[i] && (this_strength[i] < second_max_diff[i] * ex_nstrength)) {
these_tiles[i] = false; these_tiles[i] = false;
...@@ -5350,7 +4983,7 @@ ImageDtt.startAndJoin(threads); ...@@ -5350,7 +4983,7 @@ ImageDtt.startAndJoin(threads);
// } // }
} }
// combine with plates if available // combine with plates if available
if ((plate_ds != null) && (plate_ds[1][i] >=0) && (this_strength[i] < ex_strength* super_trust)) { // plate_ds[1][i] == -1 - no data, was not measured if ((plate_ds != null) && (plate_ds[1][i] >=0) && !has_lma[i] && (this_strength[i] < ex_strength* super_trust)) { // plate_ds[1][i] == -1 - no data, was not measured
// if (!bg_tiles[i] || (plate_ds[0][i] >= ex_min_over)) { // prevent expanding over correct background far tiles // if (!bg_tiles[i] || (plate_ds[0][i] >= ex_min_over)) { // prevent expanding over correct background far tiles
// expanding over (wrong) background is only OK for near tiles // expanding over (wrong) background is only OK for near tiles
if (plate_ds[1][i] > 0){ if (plate_ds[1][i] > 0){
...@@ -5399,9 +5032,7 @@ ImageDtt.startAndJoin(threads); ...@@ -5399,9 +5032,7 @@ ImageDtt.startAndJoin(threads);
boolean[] dbg_before_lone = null; boolean[] dbg_before_lone = null;
boolean[] dbg_before_gaps = null; boolean[] dbg_before_gaps = null;
if (min_clstr_seed > 1){ if (min_clstr_seed > 1){
// TODO: check - now no limit on the strength of the offending selections, only on these onses // TODO: check - now no limit on the strength of the offending selections, only on these onses
removeSmallClusters( removeSmallClusters(
false, //true, // boolean diag_en, // enable diagonal directions, false only up, dowm, right,left false, //true, // boolean diag_en, // enable diagonal directions, false only up, dowm, right,left
far_tiles, // boolean [] tiles_src, // selected tiles, will modified far_tiles, // boolean [] tiles_src, // selected tiles, will modified
...@@ -5956,7 +5587,7 @@ ImageDtt.startAndJoin(threads); ...@@ -5956,7 +5587,7 @@ ImageDtt.startAndJoin(threads);
double scale_filtered_strength_pre, // 1.5 scale plate_ds[1] before comparing to raw strength double scale_filtered_strength_pre, // 1.5 scale plate_ds[1] before comparing to raw strength
double scale_filtered_strength_post,// 2.5 scale plate_ds[1] when replacing raw (generally plate_ds is more reliable if it exists) double scale_filtered_strength_post,// 2.5 scale plate_ds[1] when replacing raw (generally plate_ds is more reliable if it exists)
int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4) // int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
GeometryCorrection geometryCorrection, GeometryCorrection geometryCorrection,
final int threadsMax, // maximal number of threads to launch final int threadsMax, // maximal number of threads to launch
final boolean updateStatus, final boolean updateStatus,
...@@ -6075,14 +5706,14 @@ ImageDtt.startAndJoin(threads); ...@@ -6075,14 +5706,14 @@ ImageDtt.startAndJoin(threads);
(new ShowDoubleFloatArrays()).showArrays(dbg_img, tilesX, tilesY, true, "ortho_combine",dbg_titles); (new ShowDoubleFloatArrays()).showArrays(dbg_img, tilesX, tilesY, true, "ortho_combine",dbg_titles);
} }
if (debugLevel > 10){ if (debugLevel > -1){
showScan( scan_prev, "preFilter_last"); showScan( scan_prev, "preFilter_last");
showScan( scan_lm, "preFilter_meas"); showScan( scan_lm, "preFilter_meas");
} }
boolean [] these_tiles = FilterScan( boolean [] these_tiles = FilterScan( // added has_LMA
scan_prev, // final CLTPass3d scan, scan_prev, // final CLTPass3d scan,
scan_bg.getSelected(), // selected, // get from selected in clt_3d_passes.get(0); // null? scan_bg.getSelected(), // selected, // get from selected in clt_3d_passes.get(0); // null?
clt_parameters.ex_min_over,// when expanding over previously detected (by error) background, disregard far tiles clt_parameters.ex_min_over,// when expanding over previously detected (by error) background, disregard far tiles
...@@ -6178,7 +5809,7 @@ ImageDtt.startAndJoin(threads); ...@@ -6178,7 +5809,7 @@ ImageDtt.startAndJoin(threads);
// replace weak outliers tiles with weighted averages (modifies disparity) // replace weak outliers tiles with weighted averages (modifies disparity)
boolean[] outliers = scan_prev.replaceWeakOutliers( boolean[] outliers = scan_prev.replaceWeakOutliers( // used has_LMA
null, // final boolean [] selection, null, // final boolean [] selection,
clt_parameters.outlierStrength , //final double weakStrength, // strength to be considered weak, subject to this replacement clt_parameters.outlierStrength , //final double weakStrength, // strength to be considered weak, subject to this replacement
clt_parameters.outlierDiff, // final double maxDiff) clt_parameters.outlierDiff, // final double maxDiff)
...@@ -6236,6 +5867,7 @@ ImageDtt.startAndJoin(threads); ...@@ -6236,6 +5867,7 @@ ImageDtt.startAndJoin(threads);
scan_prev.getDisparity(), // final double [] disparity, // current disparity value - will be modified scan_prev.getDisparity(), // final double [] disparity, // current disparity value - will be modified
scan_prev.getDisparity().clone(), // final double [] measured_disparity, // measured disparity scan_prev.getDisparity().clone(), // final double [] measured_disparity, // measured disparity
scan_prev.getStrength(), // final double [] strength, scan_prev.getStrength(), // final double [] strength,
scan_prev.hasLMADefined(), // final boolean [] has_lma,
null, // this_hor_disparity, // final double hor_disparity, // not yet used null, // this_hor_disparity, // final double hor_disparity, // not yet used
null, // hor_strength_conv, // final double hor_strength, // not yet used null, // hor_strength_conv, // final double hor_strength, // not yet used
these_tiles, // grown, // these_tiles, // final boolean [] selected, these_tiles, // grown, // these_tiles, // final boolean [] selected,
...@@ -6271,24 +5903,27 @@ ImageDtt.startAndJoin(threads); ...@@ -6271,24 +5903,27 @@ ImageDtt.startAndJoin(threads);
if (!grown[i]) masked_filtered[i] = Double.NaN; if (!grown[i]) masked_filtered[i] = Double.NaN;
} }
if (show_super && (debugLevel > 100)){ // something is broken, java.lang.NullPointerException at TileProcessor.refinePassSetup(TileProcessor.java:4488) if (show_super && (debugLevel > 100)){ // something is broken, java.lang.NullPointerException at TileProcessor.refinePassSetup(TileProcessor.java:4488)
String [] dbg_disp_tiltes={"masked", "filtered", "disp_combo", "disparity","st_disparity", "strength", String [] dbg_disp_tiltes={"masked", "filtered", "disp_combo", "disparity","st_disparity", "has_lma", "strength",
"st_strength","outliers","these","border","border_tiles"}; // ,"before","after","after1","after2","after3","neib"}; "st_strength","outliers","these","border","border_tiles"}; // ,"before","after","after1","after2","after3","neib"};
double [][] dbg_disp = new double [dbg_disp_tiltes.length][]; double [][] dbg_disp = new double [dbg_disp_tiltes.length][];
boolean [] has_lma = scan_prev.hasLMADefined();
dbg_disp[0] = masked_filtered; // + dbg_disp[0] = masked_filtered; // +
dbg_disp[1] = scan_prev.getDisparity(); // + dbg_disp[1] = scan_prev.getDisparity(); // +
dbg_disp[2] = dbg_with_super_disp; // - dbg_disp[2] = dbg_with_super_disp; // -
dbg_disp[3] = dbg_orig_disparity; // - dbg_disp[3] = dbg_orig_disparity; // -
dbg_disp[4] = scan_prev.getBgDisparity(); // - dbg_disp[4] = scan_prev.getBgDisparity(); // -
dbg_disp[5] = scan_prev.getStrength(); // + dbg_disp[5] = new double [masked_filtered.length];
dbg_disp[6] = scan_prev.getBgStrength(); // - dbg_disp[6] = scan_prev.getStrength(); // +
dbg_disp[7] = dbg_outliers; // + dbg_disp[7] = scan_prev.getBgStrength(); // -
dbg_disp[8] = new double [masked_filtered.length]; dbg_disp[8] = dbg_outliers; // +
dbg_disp[9] = new double [masked_filtered.length]; dbg_disp[9] = new double [masked_filtered.length];
dbg_disp[10] = new double [masked_filtered.length]; dbg_disp[10] = new double [masked_filtered.length];
dbg_disp[11] = new double [masked_filtered.length];
for (int i = 0; i < dbg_disp[8].length; i++){ for (int i = 0; i < dbg_disp[8].length; i++){
dbg_disp[8][i] = these_tiles[i]? 1.0: 0.0; dbg_disp[5][i] = has_lma[i]? 1.0: 0.0;
dbg_disp[9][i] = border[i]? 1.0: 0.0; dbg_disp[9][i] = these_tiles[i]? 1.0: 0.0;
dbg_disp[10][i] = borderTiles[i]? 1.0: 0.0; dbg_disp[10][i] = border[i]? 1.0: 0.0;
dbg_disp[11][i] = borderTiles[i]? 1.0: 0.0;
} }
(new ShowDoubleFloatArrays()).showArrays(dbg_disp, tilesX, tilesY, true, "refine_disparity_supertiles-"+clt_3d_passes.size(),dbg_disp_tiltes); (new ShowDoubleFloatArrays()).showArrays(dbg_disp, tilesX, tilesY, true, "refine_disparity_supertiles-"+clt_3d_passes.size(),dbg_disp_tiltes);
...@@ -6298,7 +5933,6 @@ ImageDtt.startAndJoin(threads); ...@@ -6298,7 +5933,6 @@ ImageDtt.startAndJoin(threads);
scan_next.disparity = disparityTask; scan_next.disparity = disparityTask;
scan_next.tile_op = tile_op; scan_next.tile_op = tile_op;
scan_next.setBorderTiles (borderTiles); scan_next.setBorderTiles (borderTiles);
// scan_next.selected = grown; // includes border_tiles
scan_next.setSelected(grown); // includes border_tiles scan_next.setSelected(grown); // includes border_tiles
return scan_next; return scan_next;
} }
......
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