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

LY multi-scene

parent b23f9b92
......@@ -318,9 +318,24 @@ public class CLTParameters {
public int lyf_min_samples = 5; // Minimal number of tiles remaining in the sample
public boolean lyf_norm_center = true; // Replace samples with a single average with equal weight
public double ly_corr_scale = 1.0; // Scale calculated correction vector
public boolean lyr_filter_ds = false; // true;
public boolean lyr_filter_ds = false; // true;
public boolean lyr_filter_lyf = false; // ~clt_parameters.lyf_filter, but may be different, now off for a single cameras
// Multi-scene LY parameters
// Infinity detection
public double lyms_far_inf = -0.5; // Far limit when searching for infinity objects
public double lyms_near_inf = 0.5; // Near limit when searching for infinity objects
public double lyms_far_fract = 0.05; // Mode of disparity distribution within range
public double lyms_inf_range_offs = 0.05; // Add to the disparity distribution mode for infinity center
public double lyms_inf_range = 0.15; // Consider infinity tiles that are within +/- half of this range from infinity center
//non-infinity parameters
public double lyms_min_inf_str = 0.2; // Minimal strength of infinity tiles
public double lyms_min_fg_str = 0.4; // Minimal strength of non-infinity tiles
public int lyms_clust_size = 4; // cluster size (same in both directions) for measuring LY data
public double lyms_scene_range = 10.0; // disparity range for non-infinity in the same cluster
public int lyms_min_num_inf = 10; // Minimal number of tiles (in all scenes total) in an infinity cluster
// old fcorr parameters, reuse?
// public int fcorr_sample_size = 32; // Use square this size side to detect outliers
......@@ -1242,6 +1257,17 @@ public class CLTParameters {
properties.setProperty(prefix+"lyr_filter_ds", this.lyr_filter_ds +"");
properties.setProperty(prefix+"lyr_filter_lyf", this.lyr_filter_lyf +"");
properties.setProperty(prefix+"lyms_far_inf", this.lyms_far_inf +"");
properties.setProperty(prefix+"lyms_near_inf", this.lyms_near_inf +"");
properties.setProperty(prefix+"lyms_far_fract", this.lyms_far_fract +"");
properties.setProperty(prefix+"lyms_inf_range_offs", this.lyms_inf_range_offs +"");
properties.setProperty(prefix+"lyms_inf_range", this.lyms_inf_range +"");
properties.setProperty(prefix+"lyms_min_inf_str", this.lyms_min_inf_str +"");
properties.setProperty(prefix+"lyms_min_fg_str", this.lyms_min_fg_str +"");
properties.setProperty(prefix+"lyms_clust_size", this.lyms_clust_size +"");
properties.setProperty(prefix+"lyms_scene_range", this.lyms_scene_range +"");
properties.setProperty(prefix+"lyms_min_num_inf", this.lyms_min_num_inf +"");
properties.setProperty(prefix+"corr_magic_scale", this.corr_magic_scale +"");
properties.setProperty(prefix+"corr_select", this.corr_select +"");
......@@ -2073,6 +2099,17 @@ public class CLTParameters {
if (properties.getProperty(prefix+"lyr_filter_ds")!=null) this.lyr_filter_ds=Boolean.parseBoolean(properties.getProperty(prefix+"lyr_filter_ds"));
if (properties.getProperty(prefix+"lyr_filter_lyf")!=null) this.lyr_filter_lyf=Boolean.parseBoolean(properties.getProperty(prefix+"lyr_filter_lyf"));
if (properties.getProperty(prefix+"lyms_far_inf")!=null) this.lyms_far_inf=Double.parseDouble(properties.getProperty(prefix+"lyms_far_inf"));
if (properties.getProperty(prefix+"lyms_near_inf")!=null) this.lyms_near_inf=Double.parseDouble(properties.getProperty(prefix+"lyms_near_inf"));
if (properties.getProperty(prefix+"lyms_far_fract")!=null) this.lyms_far_fract=Double.parseDouble(properties.getProperty(prefix+"lyms_far_fract"));
if (properties.getProperty(prefix+"lyms_inf_range_offs")!=null) this.lyms_inf_range_offs=Double.parseDouble(properties.getProperty(prefix+"lyms_inf_range_offs"));
if (properties.getProperty(prefix+"lyms_inf_range")!=null) this.lyms_inf_range=Double.parseDouble(properties.getProperty(prefix+"lyms_inf_range"));
if (properties.getProperty(prefix+"lyms_min_inf_str")!=null) this.lyms_min_inf_str=Double.parseDouble(properties.getProperty(prefix+"lyms_min_inf_str"));
if (properties.getProperty(prefix+"lyms_min_fg_str")!=null) this.lyms_min_fg_str=Double.parseDouble(properties.getProperty(prefix+"lyms_min_fg_str"));
if (properties.getProperty(prefix+"lyms_clust_size")!=null) this.lyms_clust_size=Integer.parseInt(properties.getProperty(prefix+"lyms_clust_size"));
if (properties.getProperty(prefix+"lyms_scene_range")!=null) this.lyms_scene_range=Double.parseDouble(properties.getProperty(prefix+"lyms_scene_range"));
if (properties.getProperty(prefix+"lyms_min_num_inf")!=null) this.lyms_min_num_inf=Integer.parseInt(properties.getProperty(prefix+"lyms_min_num_inf"));
if (properties.getProperty(prefix+"corr_magic_scale")!=null) this.corr_magic_scale=Double.parseDouble(properties.getProperty(prefix+"corr_magic_scale"));
if (properties.getProperty(prefix+"corr_select")!=null) this.corr_select=Integer.parseInt(properties.getProperty(prefix+"corr_select"));
......@@ -3006,14 +3043,31 @@ public class CLTParameters {
gd.addCheckbox ("Filter lazy eye pairs by their values wen GT data is available", this.lyr_filter_lyf,
"Same as \"Filter lazy eye pairs by their values\" above, but for the rig-guided adjustments");
// gd.addNumericField("Use square this size side to detect outliers", this.fcorr_sample_size, 0);
// gd.addNumericField("Keep tiles only if there are more in each square", this.fcorr_mintiles, 0);
// gd.addNumericField("Remove this fraction of tiles from each sample", this.fcorr_reloutliers, 3);
// gd.addNumericField("Gaussian blur channel mismatch data", this.fcorr_sigma, 3);
/// gd.addNumericField("Calculated from correlation offset vs. actual one (not yet understood)", this.corr_magic_scale, 3);
gd.addTab ("LY multiscene", "Multiscene series Lazy Eye correction");
gd.addMessage ("--- Infinity detection ---");
gd.addNumericField("Infinity far", this.lyms_far_inf, 4,6,"pix",
"Far limit when searching for infinity objects");
gd.addNumericField("Infinity near", this.lyms_near_inf, 4,6,"pix",
"Near limit when searching for infinity objects");
gd.addNumericField("Infinity mode (0.0 - min, 1.0 - max", this.lyms_far_fract, 4,6,"",
"Mode of disparity distribution within range (0.0 - min, 1.0 - max)");
gd.addNumericField("Offset infinity center from mode", this.lyms_inf_range_offs, 4,6,"pix",
"Add to the disparity distribution mode for infinity center");
gd.addNumericField("Infinity full range", this.lyms_inf_range, 4,6,"pix",
"Consider infinity tiles that are within +/- half of this range from infinity center");
gd.addMessage ("--- LY data measurement ---");
gd.addNumericField("Minimal strength (infinity)", this.lyms_min_inf_str, 4,6,"",
"Minimal strength of infinity tiles");
gd.addNumericField("Minimal strength (non-infinity)", this.lyms_min_fg_str, 4,6,"",
"Minimal strength of non-infinity tiles");
gd.addNumericField("Cluster size", this.lyms_clust_size, 0,3,"pix",
"Cluster size (same in both directions) for measuring LY data");
gd.addNumericField("Per-scene disparity range", this.lyms_scene_range, 4,6,"pix",
"Disparity range for non-infinity in the same cluster");
gd.addNumericField("Minimal number of infinity tiles", this.lyms_min_num_inf, 0,3,"",
"Minimal number of tiles (in all scenes total) in an infinity cluster");
gd.addTab ("3D", "3D reconstruction");
gd.addMessage ("--- 3D reconstruction ---");
gd.addCheckbox ("Show generated textures", this.show_textures);
......@@ -3976,13 +4030,17 @@ public class CLTParameters {
this.lyr_filter_ds= gd.getNextBoolean();
this.lyr_filter_lyf= gd.getNextBoolean();
// this.fcorr_sample_size= (int)gd.getNextNumber();
// this.fcorr_mintiles= (int) gd.getNextNumber();
// this.fcorr_reloutliers= gd.getNextNumber();
// this.fcorr_sigma= gd.getNextNumber();
/// this.corr_magic_scale= gd.getNextNumber();
this.lyms_far_inf= gd.getNextNumber();
this.lyms_near_inf= gd.getNextNumber();
this.lyms_far_fract= gd.getNextNumber();
this.lyms_inf_range_offs= gd.getNextNumber();
this.lyms_inf_range= gd.getNextNumber();
this.lyms_min_inf_str= gd.getNextNumber();
this.lyms_min_fg_str= gd.getNextNumber();
this.lyms_clust_size= (int) gd.getNextNumber();
this.lyms_scene_range= gd.getNextNumber();
this.lyms_min_num_inf=(int) gd.getNextNumber();
this.show_textures= gd.getNextBoolean();
this.debug_filters= gd.getNextBoolean();
......
......@@ -8950,6 +8950,64 @@ public class ImageDttCPU {
return corr2d_decimated;
}
public static double [][] corr2d_decimate( // not used in lwir
final double [][] corr2d_img,
final int tilesX,
final int tilesY,
final int clust_size,
final int [] wh,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel) {
int len = 0;
final double [][] corr2d_decimated = new double [corr2d_img.length][];
for (int i = 0; i < corr2d_img.length; i++) {
if (corr2d_img[i] != null) {
len = corr2d_img[i].length;
break;
}
}
final int tile_size = (int) Math.round(Math.sqrt(len/(tilesX * tilesY)));
final int clustersX = (int) Math.ceil(1.0 * tilesX / clust_size);
final int clustersY = (int) Math.ceil(1.0 * tilesY / clust_size);
final int clusters = clustersX * clustersY;
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final int clust_lines = clust_size * tile_size;
final int in_line_len = clustersX * clust_size * tile_size;
final int out_line_len = clustersX * tile_size;
if (wh != null) {
wh[0] = clustersX * tile_size;
wh[1] = clustersY * tile_size;
}
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nLayer = ai.getAndIncrement(); nLayer < corr2d_img.length; nLayer = ai.getAndIncrement()) {
if (corr2d_img[nLayer] != null){
corr2d_decimated[nLayer] = new double [clusters * tile_size * tile_size];
for (int clustY = 0; clustY < clustersY; clustY++) {
for (int clustX = 0; clustX < clustersX; clustX++) {
int offs = clustY * clust_lines * in_line_len;
for (int line = 0; line < tile_size; line++) {
System.arraycopy(
corr2d_img[nLayer],
(clustY * clust_lines + line) * in_line_len + clustX * clust_lines,
corr2d_decimated[nLayer],
(clustY * tile_size + line) * out_line_len + clustX * tile_size,
tile_size);
}
}
}
}
}
}
};
}
startAndJoin(threads);
return corr2d_decimated;
}
......
......@@ -280,11 +280,13 @@ public class MultisceneLY {
public static double [][] useTilesLY(
final int clust_size,
final double inf_range, // full range centered at inf_disp_ref to be used as infinity
final double scene_range, // disparity range for non-infinity in the same cluster
final double scene_range, // disparity range for non-infinity in the same cluster
final int min_num_inf, // Minimal number of tiles (in all scenes total) in an infinity cluster
final QuadCLT [] scenes, // ordered by increasing timestamps
final boolean [][] valid_tile, // tile with lma and single correlation maximum
final double inf_disp_ref, // average disparity at infinity for ref scene
final boolean [][] is_infinity, // may be null, if not - may be infinity from the composite depth map
final boolean [][] is_infinity, // may be null (all non-infinity), if not - may be infinity from the composite depth map
final boolean only_infinity, // do not process non-infinity
int [] in_num_tiles, // null or array of number of clusters
boolean [] in_inf_cluster, // null or array of number of clusters, will return if cluster uses only infinite tiles
final int threadsMax,
......@@ -303,6 +305,10 @@ public class MultisceneLY {
final int [] num_tiles = (in_num_tiles != null)? in_num_tiles : (new int [clusters]);
final boolean [] inf_cluster = (in_inf_cluster != null)? in_inf_cluster : (new boolean [clusters]);
Arrays.fill(num_tiles, 0);
Arrays.fill(inf_cluster, false);
final int [] num_inf_cluster = new int[clusters];
for (int nscene = 0; nscene < num_scenes; nscene++) {
target_disparities[nscene] = scenes[nscene].getDSRBG()[0];
Arrays.fill(rslt_disparities[nscene], Double.NaN);
......@@ -314,7 +320,7 @@ public class MultisceneLY {
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
Cluster:
// Cluster:
for (int nClust = ai.getAndIncrement(); nClust < clusters; nClust = ai.getAndIncrement()) {
int clustX = nClust % clustersX;
int clustY = nClust / clustersX;
......@@ -329,8 +335,9 @@ public class MultisceneLY {
if (is_infinity[nscene][nTile] &&
valid_tile[nscene][nTile] && // next may be NaN
(Math.abs(target_disparities[nscene][nTile] - inf_disp_ref) <= inf_hrange)) {
inf_cluster[nClust] = true;
continue Cluster;
num_inf_cluster[nClust]++;
// inf_cluster[nClust] = true;
// continue Cluster;
}
}
}
......@@ -342,6 +349,21 @@ public class MultisceneLY {
};
}
ImageDtt.startAndJoin(threads);
ai.set(0);
// mark clusters as infinity if they have enough infinity tiles
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nClust = ai.getAndIncrement(); nClust < clusters; nClust = ai.getAndIncrement()) {
if (num_inf_cluster[nClust] >= min_num_inf) {
inf_cluster[nClust] = true;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
// Mark suitable infinity tiles (they are NaN now)
ai.set(0);
......@@ -378,91 +400,196 @@ public class MultisceneLY {
ImageDtt.startAndJoin(threads);
}
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
double [] clust_disp = new double[clusters];
// only use clusters that are not infinity
for (int nClust = ai.getAndIncrement(); nClust < clusters; nClust = ai.getAndIncrement()) if (!inf_cluster[nClust]){
int clustX = nClust % clustersX;
int clustY = nClust / clustersX;
// int num_tot = 0;
for (int nscene = 0; nscene < num_scenes; nscene++) {
Arrays.fill(clust_disp,Double.NaN);
double sum_disp = 0;
int num_disp = 0;
if (!only_infinity) {
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
double [] clust_disp = new double[clusters];
// only use clusters that are not infinity
for (int nClust = ai.getAndIncrement(); nClust < clusters; nClust = ai.getAndIncrement()) if (!inf_cluster[nClust]){
int clustX = nClust % clustersX;
int clustY = nClust / clustersX;
// int num_tot = 0;
for (int nscene = 0; nscene < num_scenes; nscene++) {
Arrays.fill(clust_disp,Double.NaN);
double sum_disp = 0;
int num_disp = 0;
for (int ctY = 0; ctY < clust_size; ctY++) {
int tileY = clustY * clust_size + ctY;
if (tileY < tilesY) {
for (int ctX = 0; ctX < clust_size; ctX++) {
int tileX = clustX * clust_size + ctX;
if (tileX < tilesX) {
int ct = ctY * clust_size + ctX;
int nTile = tileY*tilesX+tileX;
if (valid_tile[nscene][nTile]){
clust_disp[ct] = target_disparities[nscene][nTile];
sum_disp += clust_disp[ct];
num_disp ++;
for (int ctY = 0; ctY < clust_size; ctY++) {
int tileY = clustY * clust_size + ctY;
if (tileY < tilesY) {
for (int ctX = 0; ctX < clust_size; ctX++) {
int tileX = clustX * clust_size + ctX;
if (tileX < tilesX) {
int ct = ctY * clust_size + ctX;
int nTile = tileY*tilesX+tileX;
if (valid_tile[nscene][nTile]){
clust_disp[ct] = target_disparities[nscene][nTile];
sum_disp += clust_disp[ct];
num_disp ++;
}
}
}
}
}
}
while (num_disp > 0) {
int imin = 0;
int imax = 0;
for (int ct = 0; ct < clusters; ct++) if (!Double.isNaN(clust_disp[ct])){
if (!(clust_disp[ct] >= clust_disp[imin] )) imin = ct;
if (!(clust_disp[ct] <= clust_disp[imax] )) imax = ct;
}
if ((clust_disp[imax] - clust_disp[imin]) <= scene_range) {
break;
}
double disp_avg = sum_disp/num_disp;
if ((clust_disp[imax] - disp_avg) > (disp_avg - clust_disp[imin])){
sum_disp -= clust_disp[imax];
clust_disp[imax] = Double.NaN;
while (num_disp > 0) {
int imin = 0;
int imax = 0;
for (int ct = 0; ct < clusters; ct++) if (!Double.isNaN(clust_disp[ct])){
if (!(clust_disp[ct] >= clust_disp[imin] )) imin = ct;
if (!(clust_disp[ct] <= clust_disp[imax] )) imax = ct;
}
if ((clust_disp[imax] - clust_disp[imin]) <= scene_range) {
break;
}
double disp_avg = sum_disp/num_disp;
if ((clust_disp[imax] - disp_avg) > (disp_avg - clust_disp[imin])){
sum_disp -= clust_disp[imax];
clust_disp[imax] = Double.NaN;
} else {
sum_disp -= clust_disp[imin];
clust_disp[imin] = Double.NaN;
} else {
sum_disp -= clust_disp[imin];
clust_disp[imin] = Double.NaN;
}
num_disp --;
}
num_disp --;
}
for (int ctY = 0; ctY < clust_size; ctY++) {
int tileY = clustY * clust_size + ctY;
if (tileY < tilesY) {
for (int ctX = 0; ctX < clust_size; ctX++) {
int tileX = clustX * clust_size + ctX;
if (tileX < tilesX) {
int ct = ctY * clust_size + ctX;
int nTile = tileY*tilesX+tileX;
if (!Double.isNaN(clust_disp[ct])) {
rslt_disparities[nscene][nTile] = clust_disp[ct];
for (int ctY = 0; ctY < clust_size; ctY++) {
int tileY = clustY * clust_size + ctY;
if (tileY < tilesY) {
for (int ctX = 0; ctX < clust_size; ctX++) {
int tileX = clustX * clust_size + ctX;
if (tileX < tilesX) {
int ct = ctY * clust_size + ctX;
int nTile = tileY*tilesX+tileX;
if (!Double.isNaN(clust_disp[ct])) {
rslt_disparities[nscene][nTile] = clust_disp[ct];
}
}
}
}
}
num_tiles[nClust] += num_disp;
// num_tot += num_disp;
}
num_tiles[nClust] += num_disp;
// num_tot += num_disp;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
};
}
ImageDtt.startAndJoin(threads);
}
return rslt_disparities;
}
public static double [][][] getLYDataInfNoinf(
final CLTParameters clt_parameters,
final int clust_size,
final double inf_range, // full range centered at inf_disp_ref to be used as infinity
final double scene_range, // disparity range for non-infinity in the same cluster
final int min_num_inf, // Minimal number of tiles (in all scenes total) in an infinity cluster
final QuadCLT [] scenes, // ordered by increasing timestamps
final boolean [][] valid_tile, // tile with lma and single correlation maximum
final double inf_disp_ref, // average disparity at infinity for ref scene // is_scene_infinity
final boolean [][] is_scene_infinity, // may be null, if not - may be infinity from the composite depth map
final double [][][] target_disparities,
final double dbg_disparity_offset,
final int [][] in_num_tiles, // null or number of tiles per cluster to multiply strength
final int threadsMax,
final int debug_level){
final double [][][] inf_noinf_lazy_eye_data = new double [2][][];
int last_scene_index = scenes.length-1;
QuadCLT last_scene = scenes[last_scene_index];
int tilesX = last_scene.tp.getTilesX();
int tilesY = last_scene.tp.getTilesY();
int clustersX = (int) Math.ceil(1.0 * tilesX / clust_size);
int clustersY = (int) Math.ceil(1.0 * tilesY / clust_size);
int clusters = clustersX * clustersY;
final int [][] num_tiles = (in_num_tiles != null)? in_num_tiles : (new int [2][]);
for (int i = 0; i < num_tiles.length; i++) {
num_tiles[i] = new int [clusters];
}
// int [][] num_tiles = new int [2][clusters]; // may be null;; // null;
boolean [] inf_cluster = new boolean [clusters]; // null;
boolean debug = debug_level > -3;
// get for infinity only
double [][] target_disparities_inf = MultisceneLY.useTilesLY(
clust_size, // final int clust_size,
inf_range, // final double inf_range, // full range centered at inf_disp_ref to be used as infinity
scene_range, // final double scene_range, // disparity range for non-infinity in the same cluster
min_num_inf, // final int min_num_inf, // Minimal number of tiles (in all scenes total) in an infinity cluster
scenes, // final QuadCLT [] scenes, // ordered by increasing timestamps
valid_tile, // final boolean [][] valid_tile, // tile with lma and single correlation maximum
inf_disp_ref, // final double inf_disp_ref, // average disparity at infinity for ref scene // is_scene_infinity
is_scene_infinity, // final boolean [][] is_infinity, // may be null, if not - may be infinity from the composite depth map
true, // final boolean only_infinity, // do not process non-infinity
num_tiles[0], // int [] in_num_tiles, // null or array of number of clusters
inf_cluster, // boolean [] in_inf_cluster, // null or array of number of clusters, will return if cluster uses only infinite tiles
threadsMax, // final int threadsMax,
debug); // final boolean debug)
if (dbg_disparity_offset != 0.0) {
for (int nscene = 0; nscene < target_disparities_inf.length; nscene++) {
for (int i = 0; i < target_disparities_inf[nscene].length; i++) {
if (!Double.isNaN(target_disparities_inf[nscene][i])) {
target_disparities_inf[nscene][i] += dbg_disparity_offset;
}
}
}
}
inf_noinf_lazy_eye_data[0] = MultisceneLY.getLYData( // TODO: show lazy_eye_data[][]
clt_parameters, // final CLTParameters clt_parameters,
clust_size, // final int clust_size,
scenes, // final QuadCLT [] scenes, // ordered by increasing timestamps
target_disparities_inf, // final double[][] target_disparities,
num_tiles[0], // final int [] num_tiles,
threadsMax, // final int threadsMax,
debug_level); // final int debug_level);
// now for non-infinity:
double [][] target_disparities_noinf = MultisceneLY.useTilesLY(
clust_size, // final int clust_size,
inf_range, // final double inf_range, // full range centered at inf_disp_ref to be used as infinity
scene_range, // final double scene_range, // disparity range for non-infinity in the same cluster
min_num_inf, // final int min_num_inf, // Minimal number of tiles (in all scenes total) in an infinity cluster
scenes, // final QuadCLT [] scenes, // ordered by increasing timestamps
valid_tile, // final boolean [][] valid_tile, // tile with lma and single correlation maximum
inf_disp_ref, // final double inf_disp_ref, // average disparity at infinity for ref scene // is_scene_infinity
null, // final boolean [][] is_infinity, // may be null, if not - may be infinity from the composite depth map
false, // final boolean only_infinity, // do not process non-infinity
num_tiles[1], // int [] in_num_tiles, // null or array of number of clusters
inf_cluster, // boolean [] in_inf_cluster, // null or array of number of clusters, will return if cluster uses only infinite tiles
threadsMax, // final int threadsMax,
debug); // final boolean debug)
if (dbg_disparity_offset != 0.0) {
for (int nscene = 0; nscene < target_disparities_noinf.length; nscene++) {
for (int i = 0; i < target_disparities_noinf[nscene].length; i++) {
if (!Double.isNaN(target_disparities_noinf[nscene][i])) {
target_disparities_noinf[nscene][i] += dbg_disparity_offset;
}
}
}
}
inf_noinf_lazy_eye_data[1] = MultisceneLY.getLYData( // TODO: show lazy_eye_data[][]
clt_parameters, // final CLTParameters clt_parameters,
clust_size, // final int clust_size,
scenes, // final QuadCLT [] scenes, // ordered by increasing timestamps
target_disparities_noinf, // final double[][] target_disparities,
num_tiles[1], // final int [] num_tiles,
threadsMax, // final int threadsMax,
debug_level); // final int debug_level);
if (target_disparities != null) {
target_disparities[0] = target_disparities_inf;
target_disparities[1] = target_disparities_noinf;
}
return inf_noinf_lazy_eye_data;
}
public static double [][] getLYData(
final CLTParameters clt_parameters,
final int clust_size,
final QuadCLT [] scenes, // ordered by increasing timestamps
final double[][] target_disparities,
final int [] num_tiles,
final int [] num_tiles, // null or number of tiles per cluster to multiply strength
final int threadsMax,
final int debug_level){
int last_scene_index = scenes.length-1;
......@@ -700,6 +827,24 @@ public class MultisceneLY {
true,
last_scene.getImageName()+"-CORR-DECIMATED"+clust_size,
titles);
double [][] disparity_map_decimated = ImageDtt.corr2d_decimate( // not used in lwir
disparity_map, // final float [][] corr2d_img,
tilesX, // final int tilesX,
tilesY, // final int tilesY,
clust_size, // final int clust_size,
wh, // final int [] wh,
threadsMax, // final int threadsMax, // maximal number of threads to launch
debug_level); // final int globalDebugLevel)
(new ShowDoubleFloatArrays()).showArrays(
disparity_map_decimated,
wh[0],
wh[1],
true,
"disparity_map_decimated",
ImageDtt.getDisparityTitles(last_scene.getNumSensors(),last_scene.isMonochrome()) // ImageDtt.DISPARITY_TITLES
);
}
final double [][] rXY = last_scene.getErsCorrection().getRXY(false);
......@@ -719,7 +864,9 @@ public class MultisceneLY {
lazy_eye_data[nClust] = new double [ExtrinsicAdjustment.get_INDX_LENGTH(numSens)];
// Number of tiles, strength or a product
double strength = disparity_map[ImageDtt.DISPARITY_INDEX_POLY + 1][nTile0];
if (num_tiles != null) {
strength *= num_tiles[nClust];
}
lazy_eye_data[nClust][ExtrinsicAdjustment.INDX_STRENGTH] = strength;
lazy_eye_data[nClust][ExtrinsicAdjustment.INDX_TARGET] = combo_pXpYD[nTile0][2];
lazy_eye_data[nClust][ExtrinsicAdjustment.INDX_DIFF] = disparity_map[ImageDtt.DISPARITY_INDEX_POLY][nTile0];
......
......@@ -11147,11 +11147,24 @@ if (debugLevel > -100) return true; // temporarily !
threadsMax, // int threadsMax, // maximal number of threads to launch
updateStatus, // boolean updateStatus,
debugLevel); // int debugLevel)
/// quadCLTs[i].showDSIMain();
}
// int ref_index = quadCLTs.length-1; // last scene
boolean proc_infinity = true;
// QuadCLT ref_scene = quadCLTs[ref_index];
boolean lma_only = true; // use clt_parameters
double dbg_disparity_offset = 0.0; // 0.1
double inf_disp_ref = 0.0;
/*
double far_inf = -0.5; //
double near_inf = 0.5; //
double far_fract = 0.05; //
double inf_range_offs = 0.05; //
double inf_range = 0.15; //
double min_inf_str = 0.2; //
double min_fg_str = 0.4; //
// non-infinity parameters
int clust_size = 4;
double scene_range = 10.0; // disparity range for non-infinity in the same cluster
int min_num_inf = 10; // Minimal number of tiles (in all scenes total) in an infinity cluster
*/
int last_scene_index = quadCLTs.length-1;
QuadCLT last_scene = quadCLTs[last_scene_index];
String composite_suffix = "-INTER-INTRA-LMA";
......@@ -11162,36 +11175,23 @@ if (debugLevel > -100) return true; // temporarily !
0, // int num_slices, // (0 - all)
wh); // int [] wh)
// composite_ds == null if no file
boolean lma_only = true; // use clt_parameters
MultisceneLY multisceneLY = new MultisceneLY (
quadCLTs[0].getNumSensors(),
threadsMax, // int threadsMax, // maximal number of threads to launch
updateStatus); // boolean updateStatus);
/* String [] combo_dsn_titles_full = {"disp", "strength","disp_lma","num_valid","change",
"disp_bg", "strength_bg","disp_lma_bg","change_bg","disp_fg","disp_bg_all"}; */
// read interscene composite data
boolean [][] is_scene_infinity = null; // per scene, per tile - is infinity.
double far_inf = -0.5; //
double near_inf = 0.5; //
double far_fract = 0.05; //
double inf_range_offs = 0.05; //
double inf_range = 0.15; //
double min_inf_str = 0.2; //
double min_fg_str = 0.4; //
// non-infinity parameters
int clust_size = 4;
double inf_range2 = 0.5; // full range centered at inf_disp_ref to be used as infinity
double scene_range = 10.0; // disparity range for non-infinity in the same cluster
double inf_disp_ref = 0.0;
int tilesX = last_scene.tp.getTilesX();
int tilesY = last_scene.tp.getTilesY();
int clustersX = (int) Math.ceil(1.0 * tilesX / clust_size);
int clustersY = (int) Math.ceil(1.0 * tilesY / clust_size);
int clustersX = (int) Math.ceil(1.0 * tilesX / clt_parameters.lyms_clust_size);
int clustersY = (int) Math.ceil(1.0 * tilesY / clt_parameters.lyms_clust_size);
int clusters = clustersX * clustersY;
int [] num_tiles = null;
boolean [] inf_cluster = null;
// int [] num_tiles = new int [clusters]; // may be null;; // null;
// boolean [] inf_cluster = new boolean [clusters]; // null;
boolean debug = debugLevel > -3;
......@@ -11200,28 +11200,26 @@ if (debugLevel > -100) return true; // temporarily !
boolean [] ref_inf = MultisceneLY.getComboInfinity(
last_scene.tp, // TileProcessor tp,
composite_ds, // double [][] composite_ds,
far_inf, // double far_inf,
near_inf, // double near_inf,
far_fract, // double far_fract,
inf_range_offs, // double inf_range_offs,
inf_range, // double inf_range,
min_inf_str, // double min_inf_str,
min_fg_str, // double min_fg_str,
clt_parameters.lyms_far_inf, // double far_inf,
clt_parameters.lyms_near_inf, // double near_inf,
clt_parameters.lyms_far_fract, // double far_fract,
clt_parameters.lyms_inf_range_offs, // double inf_range_offs,
clt_parameters.lyms_inf_range, // double inf_range,
clt_parameters.lyms_min_inf_str, // double min_inf_str,
clt_parameters.lyms_min_fg_str, // double min_fg_str,
inf_avg, // double [] inf_avg,
debug); // boolean debug)
is_scene_infinity = MultisceneLY.infinityPerScene(
quadCLTs, // QuadCLT [] scenes,
// ref_index, // int indx_ref,
inf_avg[0], // double inf_disp_ref, // average disparity at infinity for ref scene
ref_inf, // boolean [] infinity_ref,
debug, // boolean debug,
threadsMax); // int threadsMax)
inf_disp_ref = inf_avg[0];
num_tiles = new int [clusters]; // may be null;
inf_cluster = new boolean [clusters]; // may be null;
}
// Read or generate+save number of correlation maximums per scene, per tile
// Will use only tiles with one and only one correlation maximum
int [][] numCorrMax = new int [quadCLTs.length][]; // ->
double [][] dNumCorrMax =last_scene.readDoubleArrayFromModelDirectory(
num_corr_max_suffix, // String suffix,
......@@ -11257,35 +11255,34 @@ if (debugLevel > -100) return true; // temporarily !
last_scene.tp.getTilesX(), // int width,
last_scene.tp.getTilesY()); // int height)
}
// valid tile - one and only one maximum
boolean [][] valid_tile = new boolean[numCorrMax.length][numCorrMax[0].length];
for (int nscene = 0; nscene < numCorrMax.length; nscene++) {
for (int nTile = 0; nTile < numCorrMax[nscene].length; nTile++) {
valid_tile[nscene][nTile] = numCorrMax[nscene][nTile] == 1; // only single-maximum
}
}
double [][] target_disparities = MultisceneLY.useTilesLY(
clust_size, // final int clust_size,
inf_range, // final double inf_range, // full range centered at inf_disp_ref to be used as infinity
scene_range, // final double scene_range, // disparity range for non-infinity in the same cluster
quadCLTs, // final QuadCLT [] scenes, // ordered by increasing timestamps
valid_tile, // final boolean [][] valid_tile, // tile with lma and single correlation maximum
inf_disp_ref, // final double inf_disp_ref, // average disparity at infinity for ref scene // is_scene_infinity
is_scene_infinity, // final boolean [][] is_infinity, // may be null, if not - may be infinity from the composite depth map
num_tiles, //int [] in_num_tiles, // null or array of number of clusters
inf_cluster, //boolean [] in_inf_cluster, // null or array of number of clusters, will return if cluster uses only infinite tiles
threadsMax, // final int threadsMax,
debug); // final boolean debug)
double [][] lazy_eye_data = MultisceneLY.getLYData( // TODO: show lazy_eye_data[][]
clt_parameters, // final CLTParameters clt_parameters,
clust_size, // final int clust_size,
quadCLTs, // final QuadCLT [] scenes, // ordered by increasing timestamps
target_disparities, // final double[][] target_disparities,
num_tiles, // final int [] num_tiles,
threadsMax, // final int threadsMax,
debugLevel); // final int debug_level);
int [][] num_tiles2 = new int[2][];
double [][][] target_disparities = new double [2][][];
double [][][] lazy_eye_data = MultisceneLY.getLYDataInfNoinf(
clt_parameters, // final CLTParameters clt_parameters,
clt_parameters.lyms_clust_size, // final int clust_size,
clt_parameters.lyms_inf_range, // final double inf_range, // full range centered at inf_disp_ref to be used as infinity
clt_parameters.lyms_scene_range, // final double scene_range, // disparity range for non-infinity in the same cluster
clt_parameters.lyms_min_num_inf, // final int min_num_inf, // Minimal number of tiles (in all scenes total) in an infinity cluster
quadCLTs, // final QuadCLT [] scenes, // ordered by increasing timestamps
valid_tile, // final boolean [][] valid_tile, // tile with lma and single correlation maximum
inf_disp_ref, // final double inf_disp_ref, // average disparity at infinity for ref scene // is_scene_infinity
is_scene_infinity, // final boolean [][] is_scene_infinity, // may be null, if not - may be infinity from the composite depth map
target_disparities, // final double[][] target_disparities,
dbg_disparity_offset, // final double dbg_disparity_offset,
num_tiles2, // final int [][] in_num_tiles, // null or number of tiles per cluster to multiply strength
threadsMax, // final int threadsMax,
debugLevel); // final int debug_level);
if (debugLevel > -4) {
// debug images
if (debugLevel > -3) {
double [][] dbg_numCorrMax = new double[numCorrMax.length][];
for (int i = 0; i < dbg_numCorrMax.length; i++) {
dbg_numCorrMax[i] = new double[numCorrMax[i].length];
......@@ -11299,103 +11296,55 @@ if (debugLevel > -100) return true; // temporarily !
tilesY,
true,
"numCorrMax");
double [][] dbg_num_tiles = new double[2][];
for (int i = 0; i < num_tiles2.length; i++ ) {
dbg_num_tiles[i] = new double [clusters];
for (int nClust = 0; nClust < clusters; nClust++) {
dbg_num_tiles[i][nClust] = num_tiles2[i][nClust];
}
}
(new ShowDoubleFloatArrays()).showArrays(
target_disparities,
tilesX,
tilesY,
dbg_num_tiles,
clustersX,
clustersY,
true,
"target_disparities");
if ((num_tiles != null) || (inf_cluster!= null)) {
double [][] dbg_num_tiles = new double[4][];
if (num_tiles != null) {
dbg_num_tiles[0] = new double [clusters];
for (int nClust = 0; nClust < clusters; nClust++) {
dbg_num_tiles[0][nClust] = num_tiles[nClust];
}
}
if (inf_cluster != null) {
dbg_num_tiles[1] = new double [clusters];
for (int nClust = 0; nClust < clusters; nClust++) {
dbg_num_tiles[1][nClust] = inf_cluster[nClust]?1.0:0.0;
}
}
if ((num_tiles != null) && (inf_cluster!= null)) {
dbg_num_tiles[2] = new double [clusters];
dbg_num_tiles[3] = new double [clusters];
Arrays.fill(dbg_num_tiles[2], Double.NaN);
Arrays.fill(dbg_num_tiles[3], Double.NaN);
for (int nClust = 0; nClust < clusters; nClust++) {
if (inf_cluster[nClust]){
dbg_num_tiles[2][nClust] = num_tiles[nClust];
} else {
dbg_num_tiles[3][nClust] = num_tiles[nClust];
}
}
}
"clusters_num_inf_boinf",
new String[] {"inf tiles", "noinf tiles"});
(new ShowDoubleFloatArrays()).showArrays(
dbg_num_tiles,
clustersX,
clustersY,
true,
"clusters_num_inf",
new String[] {"tiles","is_inf", "inf tiles", "fg tiles"});
if (lazy_eye_data != null) {
ExtrinsicAdjustment ea_dbg = new ExtrinsicAdjustment (
last_scene.getErsCorrection(), // GeometryCorrection gc,
clt_parameters.tileStep, // int clusterSize,
clustersX, // int clustersX,
clustersY); // int clustersY)
double [][] dbg_cluster = new double [ExtrinsicAdjustment.get_INDX_LENGTH(last_scene.getNumSensors())][clustersY * clustersX];
if (lazy_eye_data != null) {
ExtrinsicAdjustment ea_dbg = new ExtrinsicAdjustment (
last_scene.getErsCorrection(), // GeometryCorrection gc,
clt_parameters.tileStep, // int clusterSize,
clustersX, // int clustersX,
clustersY); // int clustersY)
double [][][] dbg_cluster = new double [lazy_eye_data.length][ExtrinsicAdjustment.get_INDX_LENGTH(last_scene.getNumSensors())][clustersY * clustersX];
for (int m = 0; m < lazy_eye_data.length; m++) {
for (int i = 0; i < dbg_cluster.length; i++) {
Arrays.fill(dbg_cluster[i], Double.NaN);
Arrays.fill(dbg_cluster[m][i], Double.NaN);
}
for (int n = 0; n < lazy_eye_data.length; n++) {
if (lazy_eye_data[n] != null) {
for (int n = 0; n < lazy_eye_data[m].length; n++) {
if (lazy_eye_data[m][n] != null) {
for (int i = 0; i < ExtrinsicAdjustment.get_INDX_LENGTH(last_scene.getNumSensors()); i++ ) {
dbg_cluster[i][n] = lazy_eye_data[n][i];
dbg_cluster[m][i][n] = lazy_eye_data[m][n][i];
}
}
}
}
for (int m = 0; m < lazy_eye_data.length; m++) {
(new ShowDoubleFloatArrays()).showArrays(
dbg_cluster,
clustersX,
clustersY,
true,
last_scene.getImageName()+"-lazy_eye_data",
ea_dbg.data_titles); // ExtrinsicAdjustment.DATA_TITLES);
dbg_cluster[m],
clustersX,
clustersY,
true,
last_scene.getImageName()+"-lazy_eye_data-"+m,
ea_dbg.data_titles); // ExtrinsicAdjustment.DATA_TITLES);
}
}
}
if (debugLevel > -100) {
return;
if (debugLevel > -3) {
System.out.println("adjustLYSeries() Done");
}
/*
String composite_suffix = "-INTER-INTRA-LMA";
int [] wh = new int[2];
double [][] composite_ds = ref_scene.readDoubleArrayFromModelDirectory(
composite_suffix, // String suffix,
0, // int num_slices, // (0 - all)
wh); // int [] wh)
* */
OpticalFlow opticalFlow = new OpticalFlow(
quadCLT_main.getNumSensors(),
clt_parameters.ofp.scale_no_lma_disparity, // double scale_no_lma_disparity,
threadsMax, // int threadsMax, // maximal number of threads to launch
updateStatus); // boolean updateStatus);
opticalFlow.adjustPairsDualPass(
clt_parameters, // CLTParameters clt_parameters,
clt_parameters.ofp.k_prev, // k_prev,
quadCLTs, // QuadCLT [] scenes, // ordered by increasing timestamps
clt_parameters.ofp.debug_level_optical); // 1); // -1); // int debug_level);
/* */
System.out.println("End of adjustLYSeries()");
}
......
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