Commit ff4593c5 authored by Andrey Filippov's avatar Andrey Filippov

Improving/Debugging initial DSI

parent e93c08dc
......@@ -351,6 +351,23 @@ public class CLTParameters {
public int corr_select = 0; // Select correlation type for all-pair supertiles and assignments (0 - CM, 1 - polynomial)
// 3d reconstruction
// maximal difference between sensors for the same tile when approximately (within correlation range) converged
// Maybe add later minimal strength that overrides this limitation (for gradients)
public double mismatch_rgb = 10.0;
public double mismatch_lwir = 300.0;
public double mismatch_override = 0.6; // correlation strength to override large mismatch
public double fom_min_strength = 0.12;// discard all weaker
public double fom_adisp_rgb = 0.5;
public double fom_cdiff_rgb = 0.1;
public double fom_adisp_lwir = 0.5;
public double fom_cdiff_lwir = 0.03; // 0.02;
public double fom_inf_bonus = 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
public double fom_inf_range = 0.8; // 0.5
public boolean show_textures = true; // show generated textures
public boolean debug_filters = false;// show intermediate results of filtering
// not used anywhere so far
......@@ -412,7 +429,7 @@ public class CLTParameters {
public double or_absVert = 0.19; // Minimal vertical absolute scaled offset ortho strength needed for replacement
public double or_maxDisp = 5.0; // Maximal disparity to apply ortho correction
public boolean poles_fix = true; // Continue vertical structures to the ground
public boolean poles_fix = false; // true; // Continue vertical structures to the ground
public int poles_len = 25; // Number of tiles to extend over the poles bottoms
public double poles_ratio = 1.0; // Maximal ratio of invisible to visible pole length
public double poles_min_strength = 0.1; // Set new pole segment strength to max of horizontal correlation and this value
......@@ -515,6 +532,9 @@ public class CLTParameters {
public double outlierDiffPos = 1.0; // Replace weak outlier tiles that have higher disparity than weighted average
public double outlierDiffNeg = 0.4; // Replace weak outlier tiles that have lower disparity than weighted average
// TODO: Make refine skip if already good?
public boolean combine_refine = true; // combine with all previous after refine pass
public double combine_min_strength = 0.12; // Disregard weaker tiles when combining scans
......@@ -1040,6 +1060,16 @@ public class CLTParameters {
public int getLyInfScale (int num_tiles) {
return (int) Math.max(ly_inf_scale_r * num_tiles , ly_inf_scale );
}
public double getMaxChannelMismatch(boolean lwir){
return lwir? mismatch_lwir : mismatch_rgb;
}
public double getFomWAdisp(boolean lwir){
return lwir? fom_adisp_lwir : fom_adisp_rgb;
}
public double getFomCDiff(boolean lwir){
return lwir? fom_cdiff_lwir : fom_cdiff_rgb;
}
public CLTParameters(){}
public void setProperties(String prefix,Properties properties){
......@@ -1305,6 +1335,18 @@ public class CLTParameters {
properties.setProperty(prefix+"corr_magic_scale", this.corr_magic_scale +"");
properties.setProperty(prefix+"corr_select", this.corr_select +"");
properties.setProperty(prefix+"mismatch_rgb", this.mismatch_rgb+"");
properties.setProperty(prefix+"mismatch_lwir", this.mismatch_lwir+"");
properties.setProperty(prefix+"mismatch_override", this.mismatch_override+"");
properties.setProperty(prefix+"fom_min_strength", this.fom_min_strength+"");
properties.setProperty(prefix+"fom_adisp_rgb", this.fom_adisp_rgb+"");
properties.setProperty(prefix+"fom_cdiff_rgb", this.fom_cdiff_rgb+"");
properties.setProperty(prefix+"fom_adisp_lwir", this.fom_adisp_lwir+"");
properties.setProperty(prefix+"fom_cdiff_lwir", this.fom_cdiff_lwir+"");
properties.setProperty(prefix+"fom_inf_bonus", this.fom_inf_bonus+"");
properties.setProperty(prefix+"fom_inf_range", this.fom_inf_range+"");
properties.setProperty(prefix+"show_textures", this.show_textures+"");
properties.setProperty(prefix+"debug_filters", this.debug_filters+"");
......@@ -2150,6 +2192,18 @@ public class CLTParameters {
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"));
if (properties.getProperty(prefix+"mismatch_rgb")!=null) this.mismatch_rgb=Double.parseDouble(properties.getProperty(prefix+"mismatch_rgb"));
if (properties.getProperty(prefix+"mismatch_lwir")!=null) this.mismatch_lwir=Double.parseDouble(properties.getProperty(prefix+"mismatch_lwir"));
if (properties.getProperty(prefix+"mismatch_override")!=null) this.mismatch_override=Double.parseDouble(properties.getProperty(prefix+"mismatch_override"));
if (properties.getProperty(prefix+"fom_min_strength")!=null) this.fom_min_strength=Double.parseDouble(properties.getProperty(prefix+"fom_min_strength"));
if (properties.getProperty(prefix+"fom_adisp_rgb")!=null) this.fom_adisp_rgb=Double.parseDouble(properties.getProperty(prefix+"fom_adisp_rgb"));
if (properties.getProperty(prefix+"fom_cdiff_rgb")!=null) this.fom_cdiff_rgb=Double.parseDouble(properties.getProperty(prefix+"fom_cdiff_rgb"));
if (properties.getProperty(prefix+"fom_adisp_lwir")!=null) this.fom_adisp_lwir=Double.parseDouble(properties.getProperty(prefix+"fom_adisp_lwir"));
if (properties.getProperty(prefix+"fom_cdiff_lwir")!=null) this.fom_cdiff_lwir=Double.parseDouble(properties.getProperty(prefix+"fom_cdiff_lwir"));
if (properties.getProperty(prefix+"fom_inf_bonus")!=null) this.fom_inf_bonus=Double.parseDouble(properties.getProperty(prefix+"fom_inf_bonus"));
if (properties.getProperty(prefix+"fom_inf_range")!=null) this.fom_inf_range=Double.parseDouble(properties.getProperty(prefix+"fom_inf_range"));
if (properties.getProperty(prefix+"show_textures")!=null) this.show_textures=Boolean.parseBoolean(properties.getProperty(prefix+"show_textures"));
if (properties.getProperty(prefix+"debug_filters")!=null) this.debug_filters=Boolean.parseBoolean(properties.getProperty(prefix+"debug_filters"));
......@@ -3111,6 +3165,30 @@ public class CLTParameters {
"Minimal number of tiles (in all scenes total) in an infinity cluster");
gd.addTab ("3D", "3D reconstruction");
gd.addNumericField("Maximal channel mismatchatch for RGB cameras", this.mismatch_rgb, 4,6,"counts",
"Discard correlation results during disparity sweep if channels differ more (RGB)");
gd.addNumericField("Maximal channel mismatchatch for LWIR cameras", this.mismatch_lwir, 4,6,"counts",
"Discard correlation results during disparity sweep if channels differ more (LWIR)");
gd.addNumericField("Minimal correlation strength to override mismatch filter", this.mismatch_override, 4,6,"",
"Allow tiles with the really strong correlation to have large mismatch.");
gd.addMessage ("--- FOM for initial DSI ---");
gd.addNumericField("Minimal strength", this.fom_min_strength, 4,6,"",
"Discard all weaker tiles (FOM=NEGATIVE_INFINITY).");
gd.addNumericField("Weight of residual disparity, RGB", this.fom_adisp_rgb, 4,6,"",
"Subtract absolute value of the residual disparity from the tile correlation strength for RGB sensors.");
gd.addNumericField("Weight of residual disparity, LWIR", this.fom_adisp_lwir, 4,6,"",
"Subtract absolute value of the residual disparity from the tile correlation strength for LWIR sensors.");
gd.addNumericField("Weight of interchannel mismatch, RGB", this.fom_cdiff_rgb, 4,6,"",
"Allows to discard gross mismatch. Requires photometric equalization that in turn requires DSI, so reduce if calibration is not available");
gd.addNumericField("Weight of interchannel mismatch, LWIR", this.fom_cdiff_lwir, 4,6,"",
"Allows to discard gross mismatch. Requires photometric equalization that in turn requires DSI, so reduce if calibration is not available");
gd.addNumericField("Infinity tiles FOM bonus", this.fom_inf_bonus, 4,6,"",
"Prevent stray FG over sky - add to FOM.");
gd.addNumericField("Infinity bonus disparity range", this.fom_inf_range, 4,6,"pix",
"Infinity range to receive FOM bonus.");
gd.addMessage ("--- 3D reconstruction ---");
gd.addCheckbox ("Show generated textures", this.show_textures);
gd.addCheckbox ("show intermediate results of filtering", this.debug_filters);
......@@ -3410,7 +3488,7 @@ public class CLTParameters {
gd.addNumericField("Do not re-measure correlation if target disparity differs from some previous less", this.gr_unique_tol, 6);
gd.addNumericField("Larger tolerance for expanding (not refining)", this.gr_unique_pretol, 6);
gd.addMessage ("--- Mukti-tile DSI expansion ---");
gd.addMessage ("--- Multi-tile DSI expansion ---");
gd.addNumericField("Maximal cluster radius", this.gr_max_clust_radius, 0,6,"",
"2 - 3x3, 3 - 5x5, 4 - 7x7 tiles");
gd.addNumericField("Number of refines for each cluster radius", this.gr_num_refines, 0,6,"",
......@@ -4092,6 +4170,18 @@ public class CLTParameters {
this.lyms_scene_range= gd.getNextNumber();
this.lyms_min_num_inf=(int) gd.getNextNumber();
this.mismatch_rgb= gd.getNextNumber();
this.mismatch_lwir= gd.getNextNumber();
this.mismatch_override= gd.getNextNumber();
this.fom_min_strength= gd.getNextNumber();
this.fom_adisp_rgb= gd.getNextNumber();
this.fom_adisp_lwir= gd.getNextNumber();
this.fom_cdiff_rgb= gd.getNextNumber();
this.fom_cdiff_lwir= gd.getNextNumber();
this.fom_inf_bonus= gd.getNextNumber();
this.fom_inf_range= gd.getNextNumber();
this.show_textures= gd.getNextBoolean();
this.debug_filters= gd.getNextBoolean();
this.min_smth= gd.getNextNumber();
......
......@@ -35,6 +35,7 @@ public class CLTPass3d{
private double [][] disparity_sav; // saved disparity
private int [][] tile_op_sav; // saved tile_op
public double [][] disparity_map = null; // add 4 layers - worst difference for the port
public double [] second_max = null;
public double [][] lazy_eye_data = null;
public int lma_cluster_size = -1;
public boolean [] lazy_eye_force_disparity = null;
......@@ -315,7 +316,7 @@ public class CLTPass3d{
}
/**
* Get FPGA-calculated per-tile maximal differences between the particular image and the average one.
* @return per-camera sesnor array of line-scan differences
* @return per-camera sensor array of line-scan differences
*/
public double [][] getDiffs (){
......@@ -738,6 +739,45 @@ public class CLTPass3d{
}
}
/**
* Remove correlation results for tiles that have large variations - this normally leads to fake high-disparity
* values in the sky (at a distance of disparity from the high-contrast skyline). This method should only be used
* during initial disparity scan as FG/BG overlap also causes mismatch.
* This method calculates ands sets this.
* Images have to be equalized.second_max
* @param max_diff maximal difference for the sane correlation results (50-100 for LWIR?)
* @param mismatch_override keep tile with large mismatch if there is LMA with really strong correlation
*/
public void resetByDiff(
double max_diff,
double mismatch_override) {
setSecondMax();
if ((disparity_map == null) ||(disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX] == null)) {
System.out.println("resetByDiff(): strength is null! (no tiles left)");
return;
}
int len = disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX].length; // null
if ((lma_disparity_index >= 0) && (disparity_map[lma_disparity_index] != null) && (disparity_map[lma_disparity_index+1] != null)){
for (int i = 0; i < len; i++ ) {
if (second_max[i] > max_diff) {
if ((mismatch_override <= 0) || !(disparity_map[lma_disparity_index +1][i] >= mismatch_override)) {
disparity_map[lma_disparity_index][i] = Double.NaN;
disparity_map[lma_disparity_index +1][i] = 0.0;
disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][i] = 0.0; // disparity_cm will stay
}
}
}
} else { // Seems first are all non-LMA
for (int i = 0; i < len; i++ ) {
if ((second_max[i] > max_diff) &&
((mismatch_override <= 0) || !(disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][i] >= mismatch_override))) {
disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][i] = 0.0;
}
}
}
}
public boolean [] hasLMADefined(){ // will try not to create this.has_lma
if (disparity_map == null) {
if (has_lma==null) {
......@@ -1108,7 +1148,16 @@ public class CLTPass3d{
}
}
public void setSecondMax() {
this.second_max = getSecondMaxDiff(false);
}
public double [] getSecondMax() {
if (this.second_max == null) {
setSecondMax();
}
return this.second_max;
}
public double [] getSecondMaxDiff (
final boolean averaged)
{
......@@ -1170,8 +1219,58 @@ public class CLTPass3d{
ImageDtt.startAndJoin(threads);
return second_max_averaged;
}
@Deprecated
public double [] getFOM(
double w_adisp,
double w_cdiff
) {
// should it use getDisparity(), getStrength()?
final double [] strength = disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX];
final double [] disparity = disparity_map[ImageDtt.DISPARITY_INDEX_CM]; // is it combined with LMA?
// final double [] second_max_diff = getSecondMaxDiff(false);
final double [] fom = new double [strength.length];
final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < fom.length; nTile = ai.getAndIncrement()) {
double tfom = strength[nTile] - w_adisp * Math.abs(disparity[nTile]) - w_cdiff * second_max[nTile];
if ((strength[nTile] <= 0) || Double.isNaN(tfom)) {
fom[nTile] = Double.NEGATIVE_INFINITY;
} else {
fom[nTile] = tfom;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return fom;
}
public double getFOM(
int nTile,
double min_strength,
double w_adisp,
double w_cdiff
){
final double strength = disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nTile];
final double disparity = disparity_map[ImageDtt.DISPARITY_INDEX_CM][nTile]; // is it combined with LMA?
// double fom = strength - w_adisp * Math.abs(disparity) - w_cdiff * second_max;
double fom = strength
- w_adisp * Math.abs(disparity)
- w_cdiff * second_max[nTile] *(min_strength/strength);
if ((strength <= 0) || (strength <= min_strength) || Double.isNaN(fom)) {
return Double.NEGATIVE_INFINITY;
} else {
return fom;
}
}
// same, but 2 steps around
public boolean [] getUntestedBackgroundBorder2 (
......
......@@ -52,7 +52,9 @@ public class MultisceneLY {
false, // final boolean need_diffs, // calculate diffs even if textures are not needed
0, // final int clust_radius,
true, // final boolean save_corr,
run_lma, // final boolean run_lma, // = true;
run_lma, // final boolean run_lma, // = true;
0.0, // final double max_chn_diff, // filter correlation results by maximum difference between channels
-1.0, // final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debug_level); // final int debugLevel);
......
......@@ -4244,6 +4244,8 @@ public class OpticalFlow {
0, // final int clust_radius,
true, // final boolean save_corr,
false, // final boolean run_lma, // = true;
0.0, // final double max_chn_diff, // filter correlation results by maximum difference between channels
-1.0, // final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
......@@ -4544,7 +4546,8 @@ public class OpticalFlow {
debugLevel+1);
quadCLT_main.setLwirOffsets(quadCLTs[ref_index].getLwirOffsets());
quadCLT_main.setLwirScales(quadCLTs[ref_index].getLwirScales());
// Re-read reference and other scenes using new offsets
// Re-read reference and other scenes using new offsets
quadCLTs[ref_index].saveQuadClt(); // to re-load new set of Bayer images to the GPU (do nothing for CPU) and Geometry
quadCLTs[ref_index] = (QuadCLT) quadCLT_main.spawnQuadCLT( // restores dsi from "DSI-MAIN"
set_channels[ref_index].set_name,
clt_parameters,
......
......@@ -3847,6 +3847,9 @@ public class QuadCLT extends QuadCLTCPU {
if ((gpuQuad == null) || !(isAux()?clt_parameters.gpu_use_aux : clt_parameters.gpu_use_main)) {
return super.CLTBackgroundMeas( // measure background // USED in lwir
clt_parameters,
true, // final boolean run_lma, //
clt_parameters.getMaxChannelMismatch(isLwir()), // max_chn_diff, //final double max_chn_diff, // filter correlation results by maximum difference between channels
clt_parameters.mismatch_override, // final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
......@@ -3995,6 +3998,7 @@ public class QuadCLT extends QuadCLTCPU {
public ImagePlus getBackgroundImage(
boolean [] bgnd_tiles,
CLTPass3d bgnd_data,
CLTParameters clt_parameters,
ColorProcParameters colorProcParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
......@@ -4007,6 +4011,7 @@ public class QuadCLT extends QuadCLTCPU {
if ((gpuQuad == null) || !(isAux()?clt_parameters.gpu_use_aux : clt_parameters.gpu_use_main)) {
return super.getBackgroundImage( // measure background // USED in lwir
bgnd_tiles,
bgnd_data,
clt_parameters,
colorProcParameters,
rgbParameters,
......@@ -4019,7 +4024,7 @@ public class QuadCLT extends QuadCLTCPU {
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
CLTPass3d bgnd_data = tp.clt_3d_passes.get(0);
// CLTPass3d bgnd_data = tp.clt_3d_passes.get(0);
boolean [] bgnd_tiles_grown2 = bgnd_data.getSelected().clone(); // only these have non 0 alpha
tp.growTiles(
2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
......
......@@ -8389,7 +8389,7 @@ public class QuadCLTCPU {
// Add here composite scans and show FG and BG images
// adjust extrinsics here
// Only here it uses 2 planes
ArrayList<CLTPass3d> combo_pass_list = tp.compositeScan(
2, // just FG and BG
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
......@@ -8686,33 +8686,57 @@ public class QuadCLTCPU {
final boolean updateStatus,
final int debugLevel)
{
final boolean show_init_refine = clt_parameters.show_init_refine; // change to true?
boolean lwir2022 = true;
boolean debug2 = true;
boolean no_macro = isLwir(); // make it a separate configurable parameter?
// change debugLevel to 0
this.startStepTime=System.nanoTime()+0;
final boolean show_init_refine = clt_parameters.show_init_refine; // change to true?
final double max_mismatch = clt_parameters.getMaxChannelMismatch(isLwir());
final double mismatch_override = clt_parameters.mismatch_override;
final double fom_min_strength = clt_parameters.fom_min_strength;
final double fom_adisp = clt_parameters.getFomWAdisp(isLwir()); // 0.5;
final double fom_cdiff = clt_parameters.getFomCDiff(isLwir()); // 0.02;
final double fom_inf_bonus = clt_parameters.fom_inf_bonus; // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
final double fom_inf_range = clt_parameters.fom_inf_range; // 0.5;
//max_expand
// String name = (String) imp_quad[0].getProperty("name");
String name = getImageName();
// should create data for the macro! (diff, rgb) make sure .texture_tiles is measured correctly
CLTPass3d bgnd_data = CLTBackgroundMeas( // measure background - both CPU and GPU (remove textures from GPU)
CLTPass3d bgnd_data_lma = CLTBackgroundMeas( // measure background - both CPU and GPU (remove textures from GPU)
clt_parameters,
threadsMax, // maximal number of threads to launch
true, // final boolean run_lma, //
max_mismatch, // max_chn_diff, //final double max_chn_diff, // filter correlation results by maximum difference between channels
mismatch_override, // final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
if (clt_parameters.img_dtt.lmamask_dbg) {
System.out.println("Remove me - QCC8257");
return false;
}
tp.clt_3d_passes.add(bgnd_data_lma);
CLTPass3d bgnd_data_nolma = CLTBackgroundMeas( // measure background - both CPU and GPU (remove textures from GPU)
clt_parameters,
false, // final boolean run_lma, //
max_mismatch, // max_chn_diff, //final double max_chn_diff, // filter correlation results by maximum difference between channels
mismatch_override, // final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
tp.clt_3d_passes.add(bgnd_data_nolma);
tp.clt_3d_passes.add(bgnd_data);
// if (show_init_refine)
// if ((debugLevel > -2) && clt_parameters.show_first_bg) {
if ((debugLevel > -2) && clt_parameters.show_first_bg) {
if ((debugLevel > -3) && clt_parameters.show_first_bg) {
tp.showScan(
tp.clt_3d_passes.get(0), // CLTPass3d scan,
"bgnd_data-"+tp.clt_3d_passes.size());
"bgnd_data_lma-"+tp.clt_3d_passes.size());
tp.showScan(
tp.clt_3d_passes.get(1), // CLTPass3d scan,
"bgnd_data_nolma-"+tp.clt_3d_passes.size());
}
//TODO: Move away from here?
......@@ -8720,11 +8744,14 @@ public class QuadCLTCPU {
boolean [] bgmask = getBackgroundImageMasks(
clt_parameters,
name, // .getTitle(), //String name=(String) imp_src.getProperty("name");
bgnd_data_lma, // CLTPass3d bgnd_data,
name, // .getTitle(), //String name=(String) imp_src.getProperty("name");
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
bgnd_data_nolma.setSelected(bgnd_data_lma.getSelected());
if ((debugLevel > -2) && (bgmask != null)) {
double [][] dbg_img = new double[1][tp.getTilesY() * tp.getTilesX()];
for (int i = 0; i<dbg_img[0].length;i++){
......@@ -8739,6 +8766,7 @@ public class QuadCLTCPU {
ImagePlus imp_bgnd_int = getBackgroundImage( // null pointer
bgmask, // boolean [] bgnd_tiles,
bgnd_data_lma, // CLTPass3d bgnd_data,
clt_parameters,
colorProcParameters,
rgbParameters,
......@@ -8765,7 +8793,7 @@ public class QuadCLTCPU {
//// imp_bgnd.show(); /// all black -> change clt_parameters.alpha0, clt_parameters.alpha1
bgnd_data.texture = (imp_bgnd == null)? null: ( imp_bgnd.getTitle()+ (clt_parameters.black_back? ".jpeg" : ".png"));
bgnd_data_lma.texture = (imp_bgnd == null)? null: ( imp_bgnd.getTitle()+ (clt_parameters.black_back? ".jpeg" : ".png"));
// create x3d file
X3dOutput x3dOutput = new X3dOutput(
......@@ -8816,10 +8844,10 @@ public class QuadCLTCPU {
double [][][] input_data = mc.CLTMacroSetData( // perform single pass according to prepared tiles operations and disparity
bgnd_data); // final CLTPass3d src_scan, // results of the normal correlations (now expecting infinity)
bgnd_data_nolma); // final CLTPass3d src_scan, // results of the normal correlations (now expecting infinity)
TileProcessor mtp = mc.CLTMacroScan( // perform single pass according to prepared tiles operations and disparity
bgnd_data, // final CLTPass3d src_scan, // results of the normal correlations (now expecting infinity)
bgnd_data_nolma, // final CLTPass3d src_scan, // results of the normal correlations (now expecting infinity)
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
geometryCorrection, // GeometryCorrection geometryCorrection,
0.0, // final double macro_disparity_low,
......@@ -8934,10 +8962,13 @@ public class QuadCLTCPU {
clt_parameters.img_dtt.setMcorrNeib(getNumSensors(),true);
clt_parameters.img_dtt.setMcorrSq (getNumSensors(),true); // remove even more?
clt_parameters.img_dtt.setMcorrDia (getNumSensors(),true); // remove even more?
boolean save_run_lma = clt_parameters.correlate_lma;
clt_parameters.correlate_lma = false;
// boolean save_run_lma = clt_parameters.correlate_lma;
// clt_parameters.correlate_lma = false;
int dbg_num_new = 0; // only BG in the list
if (show_init_refine) tp.showScan(
tp.clt_3d_passes.get(tp.clt_3d_passes.size()-1), // CLTPass3d scan,
"before adding-"+tp.clt_3d_passes.size());
for (CLTPass3d from_macro_pass: new_meas) {
if (debugLevel > -3) {
System.out.println("Next from new_meas: "+dbg_num_new);
......@@ -8987,22 +9018,27 @@ public class QuadCLTCPU {
if (debugLevel > -3){ // -1
System.out.println("cycle makeUnique("+refine_pass+") -> left: "+numLeftRemoved[0]+", removed:" + numLeftRemoved[1]);
}
if (show_init_refine) tp.showScan(
if (show_init_refine && (debugLevel>0)) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_refinePassSetup-"+tp.clt_3d_passes.size());
// Adding filtering for large difference only here (high-disparity ghosts in the sky)
// In other places may harm FG/BG borders
CLTMeasCorr( // perform single pass according to prepared tiles operations and disparity // CUDA_ERROR_INVALID_VALUE on lowres
clt_parameters,
refine_pass,
false, // true, // final boolean save_textures,
false, // true, // final boolean save_textures,
0, // final int clust_radius,
threadsMax, // maximal number of threads to launch
false, // clt_parameters.correlate_lma, // final boolean run_lma, //
max_mismatch, // final double max_chn_diff, // filter correlation results by maximum difference between channels
mismatch_override, //final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
if (debugLevel > -3){
System.out.println("CLTMeasCorr("+refine_pass+")-*");
}
if (show_init_refine) tp.showScan(
if ((debugLevel > 0) && show_init_refine) tp.showScan( // remove by debug
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_measure-"+tp.clt_3d_passes.size());
if (nnn < (clt_parameters.gr_num_refines-1)) { // all but last, because after last the next fresh one will be used
......@@ -9026,7 +9062,7 @@ public class QuadCLTCPU {
true, // final boolean copyDebug)
debugLevel);
if (show_init_refine) tp.showScan(
if (show_init_refine && (debugLevel>0)) tp.showScan(
combo_pass, // CLTPass3d scan,
"after_compositeScan-"+tp.clt_3d_passes.size());
......@@ -9041,47 +9077,103 @@ public class QuadCLTCPU {
tp.clt_3d_passes.size() -1, // new, refine_pass+1, - just added from macro - VERIFY
true, // final boolean save_textures,
0, // final int clust_radius,
threadsMax, // maximal number of threads to launch
false, // clt_parameters.correlate_lma, // final boolean run_lma, //
max_mismatch, // final double max_chn_diff, // filter correlation results by maximum difference between channels
mismatch_override, //final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
if (debugLevel > -1){
System.out.println("CLTMeasure("+(tp.clt_3d_passes.size() -1)+")");
}
if (show_init_refine) tp.showScan(
tp.clt_3d_passes.get(tp.clt_3d_passes.size() -1), // CLTPass3d scan,
"after_measure_macro-"+tp.clt_3d_passes.size());
if (debugLevel > -1){
System.out.println("CLTMeasure("+(tp.clt_3d_passes.size() -1)+")");
}
}
// Restore pair selection and minimize them for scanning, then restore;
if (!clt_parameters.gr_reduce_sngl) {
clt_parameters.img_dtt.setMcorr(getNumSensors(), save_pairs_selection); // restore
}
clt_parameters.correlate_lma = save_run_lma; // restore
// clt_parameters.correlate_lma = save_run_lma; // restore *********
// Manually debug here for various tiles
int dbg_tileX = 58; // 42;
int dbg_tileY = 48; // 28;
boolean break_now = true;
while (!break_now && debug2) {
tp.printScans(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
0, // bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
false, // final boolean use_lma,
fom_min_strength, // final double min_strength,
fom_adisp, // final double fom_adisp, // 0.5
fom_cdiff, // final double fom_cdiff, // 0.02
fom_inf_bonus, // final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
fom_inf_range, // final double fom_inf_range, // 0.5;
dbg_tileX, // final int tileX,
dbg_tileY); // final int tileY
CLTPass3d combo_pass = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
// tp.getTrustedCorrelation(), // final double trustedCorrelation,
fom_min_strength, // final double fom_min_strength,
false, // final boolean fom_use_lma,
fom_adisp, // final double fom_adisp, // 0.5
fom_cdiff, // final double fom_cdiff, // 0.02
fom_inf_bonus, // final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
fom_inf_range, // final double fom_inf_range, // 0.5;
true, // final boolean copyDebug)
debugLevel);
tp.showScan( combo_pass, "combo_after_all_measured-"+tp.clt_3d_passes.size());
if (break_now) {
break;
}
}
/// Refining after all added
if (debugLevel > -3){
System.out.println("---- Refining after all added , combining all previous mesurements ----");
System.out.println("---- Refining after all added , combining all previous measurements ----");
}
// first - combine all measured before (that was missing)
CLTPass3d combo_pass = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
tp.getTrustedCorrelation(), // final double trustedCorrelation,
tp.getMaxOverexposure(), // final double max_overexposure,
0.0, // clt_parameters.bgnd_range, // final double disp_far, // limit results to the disparity range
clt_parameters.grow_disp_max, // final double disp_near,
clt_parameters.combine_min_strength, // final double minStrength,
clt_parameters.combine_min_hor, // final double minStrengthHor,
clt_parameters.combine_min_vert, // final double minStrengthVert,
false, // final boolean no_weak,
false, // final boolean use_last, //
// TODO: when useCombo - pay attention to borders (disregard)
false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false
true, // final boolean copyDebug)
debugLevel);
CLTPass3d combo_pass = null;
if (lwir2022) {
combo_pass = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
fom_min_strength, // final double fom_min_strength,
false, // final boolean fom_use_lma,
fom_adisp, // final double fom_adisp, // 0.5
fom_cdiff, // final double fom_cdiff, // 0.02
fom_inf_bonus, // final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
fom_inf_range, // final double fom_inf_range, // 0.5;
true, // final boolean copyDebug)
debugLevel);
} else {
combo_pass = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
tp.getTrustedCorrelation(), // final double trustedCorrelation,
tp.getMaxOverexposure(), // final double max_overexposure,
0.0, // clt_parameters.bgnd_range, // final double disp_far, // limit results to the disparity range
clt_parameters.grow_disp_max, // final double disp_near,
clt_parameters.combine_min_strength, // final double minStrength,
clt_parameters.combine_min_hor, // final double minStrengthHor,
clt_parameters.combine_min_vert, // final double minStrengthVert,
false, // final boolean no_weak,
false, // final boolean use_last, //
// TODO: when useCombo - pay attention to borders (disregard)
false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false
true, // final boolean copyDebug)
debugLevel);
}
tp.clt_3d_passes.add(combo_pass);
if (debugLevel > -3){
System.out.println("---- Refining after all added , combined all previous mesurements ----");
......@@ -9089,6 +9181,57 @@ public class QuadCLTCPU {
if (show_init_refine) tp.showScan(
tp.clt_3d_passes.get(tp.clt_3d_passes.size() -1), // last scan (combo)
"combo_after_all_measured-"+tp.clt_3d_passes.size());
// now measure with LMA everything w/o filtering
// next adds to the list !
refine_pass = tp.clt_3d_passes.size(); // 1
CLTPass3d refined0 = tp.refinePassSetup( // prepare tile tasks for the refine pass (re-measure disparities)
combo_pass, // CLTPass3d combo_pass,
debugLevel); // final int debugLevel);
tp.clt_3d_passes.add(refined0);
if (show_init_refine) tp.showScan(
tp.clt_3d_passes.get(tp.clt_3d_passes.size() -1), // last scan (combo)
"first_refined-"+tp.clt_3d_passes.size());
CLTMeasCorr( // perform single pass according to prepared tiles operations and disparity
clt_parameters,
tp.clt_3d_passes.size() - 1,// last one, combo
true, // final boolean save_textures,
0, // final int clust_radius,
clt_parameters.correlate_lma, // final boolean run_lma, //
max_mismatch, // final double max_chn_diff, // filter correlation results by maximum difference between channels
mismatch_override, //final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
// if (debugLevel > -1){
if (debugLevel > -3){
System.out.println("After first LMA measure ("+(tp.clt_3d_passes.size() - 1)+")");
}
if (show_init_refine) {
tp.showScan(
tp.clt_3d_passes.get(tp.clt_3d_passes.size() - 1), // CLTPass3d scan,
"after_first_lma_measure-"+tp.clt_3d_passes.size());
}
combo_pass = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
fom_min_strength, // final double fom_min_strength,
true, // final boolean fom_use_lma,
fom_adisp, // final double fom_adisp, // 0.5
fom_cdiff, // final double fom_cdiff, // 0.02
fom_inf_bonus, // final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
fom_inf_range, // final double fom_inf_range, // 0.5;
true, // final boolean copyDebug)
debugLevel);
tp.clt_3d_passes.add(combo_pass);
if (show_init_refine) {
tp.showScan(
tp.clt_3d_passes.get(tp.clt_3d_passes.size() - 1), // CLTPass3d scan,
"combo_after_first_lma-"+tp.clt_3d_passes.size());
}
// find out - why first pass corresponds to last scan step?
// first ("before_makeUnique-41-" was empty)
......@@ -9097,6 +9240,7 @@ public class QuadCLTCPU {
clt_parameters.img_dtt.setMcorr(getNumSensors(), save_pairs_selection); // restore
}
refine_pass = tp.clt_3d_passes.size(); // 1
// refinePassSetup() - old one - try to update
CLTPass3d refined = tp.refinePassSetup( // prepare tile tasks for the refine pass (re-measure disparities)
// final double [][][] image_data, // first index - number of image in a quad
clt_parameters,
......@@ -9122,12 +9266,14 @@ public class QuadCLTCPU {
updateStatus,
debugLevel); //2);
tp.clt_3d_passes.add(refined);
/// if (debugLevel > 1)
if (debugLevel > 0)
if (debug2 && (debugLevel > -3)) { // && (debugLevel > 0)
tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"before_makeUnique-"+refine_pass);
}
int [] numLeftRemoved = tp.makeUnique(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
0, // final int firstPass,
......@@ -9143,23 +9289,38 @@ public class QuadCLTCPU {
if (debugLevel > -1){
System.out.println("cycle makeUnique("+refine_pass+") -> left: "+numLeftRemoved[0]+", removed:" + numLeftRemoved[1]);
}
if (show_init_refine) tp.showScan(
if (debug2 && (debugLevel > -3)) { // (show_init_refine && (debugLevel >0)) {
tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_refinePassSetup-"+tp.clt_3d_passes.size());
}
// first time - last scan step????
// CLTMeasureCorr( // perform single pass according to prepared tiles operations and disparity
CLTMeasCorr( // perform single pass according to prepared tiles operations and disparity
// image_data, // first index - number of image in a quad
// saturation_imp, //final boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
refine_pass,
true, // final boolean save_textures,
0, // final int clust_radius,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
if (lwir2022) {
CLTMeasCorr( // perform single pass according to prepared tiles operations and disparity
clt_parameters,
refine_pass,
true, // final boolean save_textures,
0, // final int clust_radius,
clt_parameters.correlate_lma, // final boolean run_lma, //
max_mismatch, // final double max_chn_diff, // filter correlation results by maximum difference between channels
mismatch_override, //final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
} else {
CLTMeasCorr( // perform single pass according to prepared tiles operations and disparity
clt_parameters,
refine_pass,
true, // final boolean save_textures,
0, // final int clust_radius,
clt_parameters.correlate_lma, // final boolean run_lma, //
0, // final double max_chn_diff, // filter correlation results by maximum difference between channels
-1, //final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
}
// if (debugLevel > -1){
if (debugLevel > -2){
System.out.println("?.CLTMeasure("+refine_pass+")");
......@@ -9167,37 +9328,73 @@ public class QuadCLTCPU {
if (show_init_refine) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_measure-"+tp.clt_3d_passes.size());
// CLTPass3d
combo_pass = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
tp.getTrustedCorrelation(), // final double trustedCorrelation,
tp.getMaxOverexposure(), // final double max_overexposure,
0.0, // clt_parameters.bgnd_range, // final double disp_far, // limit results to the disparity range
clt_parameters.grow_disp_max, // final double disp_near,
clt_parameters.combine_min_strength, // final double minStrength,
clt_parameters.combine_min_hor, // final double minStrengthHor,
clt_parameters.combine_min_vert, // final double minStrengthVert,
false, // final boolean no_weak,
false, // final boolean use_last, //
// TODO: when useCombo - pay attention to borders (disregard)
false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false
true, // final boolean copyDebug)
debugLevel);
//
if (lwir2022) {
combo_pass = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
fom_min_strength, // final double fom_min_strength,
true, // final boolean fom_use_lma,
fom_adisp, // final double fom_adisp, // 0.5
fom_cdiff, // final double fom_cdiff, // 0.02
fom_inf_bonus, // final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
fom_inf_range, // final double fom_inf_range, // 0.5;
true, // final boolean copyDebug)
debugLevel);
} else {
combo_pass = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
tp.getTrustedCorrelation(), // final double trustedCorrelation,
tp.getMaxOverexposure(), // final double max_overexposure,
0.0, // clt_parameters.bgnd_range, // final double disp_far, // limit results to the disparity range
clt_parameters.grow_disp_max, // final double disp_near,
clt_parameters.combine_min_strength, // final double minStrength,
clt_parameters.combine_min_hor, // final double minStrengthHor,
clt_parameters.combine_min_vert, // final double minStrengthVert,
false, // final boolean no_weak,
false, // final boolean use_last, //
// TODO: when useCombo - pay attention to borders (disregard)
false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false
true, // final boolean copyDebug)
debugLevel);
}
tp.clt_3d_passes.add(combo_pass);
}
if (show_init_refine) {
tp.showScan(
tp.clt_3d_passes.get(tp.clt_3d_passes.size() - 1), // CLTPass3d scan,
"before multi-tile-"+tp.clt_3d_passes.size());
}
// create and measure several variable-cluster scans from the same single-tile combo_pass
// CLTPass3d
combo_pass = tp.clt_3d_passes.get(tp.clt_3d_passes.size() - 1); // last pass created by tp.compositeScan
break_now = true;
while (!break_now && debug2) {
tp.printScans(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
0, // bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
true, // final boolean use_lma,
fom_min_strength, // final double min_strength,
fom_adisp, // final double fom_adisp, // 0.5
fom_cdiff, // final double fom_cdiff, // 0.02
fom_inf_bonus, // final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
fom_inf_range, // final double fom_inf_range, // 0.5;
dbg_tileX, // final int tileX,
dbg_tileY); // final int tileY
}
// int max_clust_radius = 4; // 7x7
CLTPass3d [] combo_multi = new CLTPass3d[clt_parameters.gr_max_clust_radius+1];
combo_multi[0] = combo_pass;
int max_expand_radius = 0; // max_clust_radius;
for (int clust_radius = 2; clust_radius <= clt_parameters.gr_max_clust_radius; clust_radius++) {
// for (int clust_radius = 4; clust_radius <= max_clust_radius; clust_radius++) { // just for faster testing
if (clt_parameters.gr_reduce_multi) {
clt_parameters.img_dtt.setMcorr(getNumSensors(), 0 ); // remove all
......@@ -9209,7 +9406,7 @@ public class QuadCLTCPU {
// using combo_pass (latest)
int num_added = 0;
if (clust_radius < max_expand_radius) {
if (clust_radius < max_expand_radius) { // disabled currently by int max_expand_radius = 0;
num_added = tp.expandCertainMulti (
combo_pass, // CLTPass3d combo_pass, // modify
tp.clt_3d_passes, //ArrayList <CLTPass3d> passes,
......@@ -9267,6 +9464,9 @@ public class QuadCLTCPU {
refine_pass,
false, // true, // final boolean save_textures,
clust_radius, // final int clust_radius,
clt_parameters.correlate_lma, // final boolean run_lma, //
0, // final double max_chn_diff, // filter correlation results by maximum difference between channels
-1, //final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax,
updateStatus,
debugLevel);
......@@ -9274,24 +9474,38 @@ public class QuadCLTCPU {
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_measure-"+tp.clt_3d_passes.size());
combo_multi[clust_radius-1] = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
tp.getTrustedCorrelation(), // final double trustedCorrelation,
tp.getMaxOverexposure(), // final double max_overexposure,
-0.5, // 0.0, // clt_parameters.bgnd_range, // final double disp_far, // limit results to the disparity range
clt_parameters.grow_disp_max, // final double disp_near,
clt_parameters.combine_min_strength, // final double minStrength,
clt_parameters.combine_min_hor, // final double minStrengthHor,
clt_parameters.combine_min_vert, // final double minStrengthVert,
false, // final boolean no_weak,
false, // final boolean use_last, //
// TODO: when useCombo - pay attention to borders (disregard)
false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false
true, // final boolean copyDebug)
debugLevel);
if (lwir2022) {
combo_multi[clust_radius-1] = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
fom_min_strength, // final double fom_min_strength,
true, // final boolean fom_use_lma,
fom_adisp, // final double fom_adisp, // 0.5
fom_cdiff, // final double fom_cdiff, // 0.02
fom_inf_bonus, // final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
fom_inf_range, // final double fom_inf_range, // 0.5;
true, // final boolean copyDebug)
debugLevel);
} else {
combo_multi[clust_radius-1] = tp.compositeScan(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
tp.getTrustedCorrelation(), // final double trustedCorrelation,
tp.getMaxOverexposure(), // final double max_overexposure,
-0.5, // 0.0, // clt_parameters.bgnd_range, // final double disp_far, // limit results to the disparity range
clt_parameters.grow_disp_max, // final double disp_near,
clt_parameters.combine_min_strength, // final double minStrength,
clt_parameters.combine_min_hor, // final double minStrengthHor,
clt_parameters.combine_min_vert, // final double minStrengthVert,
false, // final boolean no_weak,
false, // final boolean use_last, //
// TODO: when useCombo - pay attention to borders (disregard)
false, // final boolean usePoly) // use polynomial method to find max), valid if useCombo == false
true, // final boolean copyDebug)
debugLevel);
}
double [] disparity_LMA = combo_multi[clust_radius-1].getDisparityLMA();
for (int i = 0; i< disparity.length; i++) {
if (!Double.isNaN(disparity_LMA[i])) {
......@@ -9304,12 +9518,30 @@ public class QuadCLTCPU {
tp.clt_3d_passes.add(combo_multi[clust_radius-1] );
combo_pass = combo_multi[clust_radius-1];
// combine tasks from (original) combo_pass and combo_pass_multi (use its combo_disparity, but saved getLMA from original combo_pass ?
// when done, grow to fill gaps from 3x3 first (by 1 step) and from 5x5 - second?(by 2 steps), ...
}
}
break_now = true;
while (!break_now && debug2) {
tp.printScans(
tp.clt_3d_passes, // final ArrayList <CLTPass3d> passes,
0, // bg_pass, // final int firstPass,
tp.clt_3d_passes.size(), // final int lastPassPlus1,
true, // final boolean use_lma,
fom_min_strength, // final double min_strength,
fom_adisp, // final double fom_adisp, // 0.5
fom_cdiff, // final double fom_cdiff, // 0.02
fom_inf_bonus, // final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
fom_inf_range, // final double fom_inf_range, // 0.5;
dbg_tileX, // final int tileX,
dbg_tileY); // final int tileY
}
// Restore pairs selection
clt_parameters.img_dtt.setMcorr(getNumSensors(), save_pairs_selection); // restore
if (clt_parameters.gr_nan_bg) {
......@@ -11930,18 +12162,14 @@ public class QuadCLTCPU {
// public ImagePlus getBackgroundImage( // USED in lwir
public boolean[] getBackgroundImageMasks( // USED in lwir
// boolean no_image_save,
CLTParameters clt_parameters,
// ColorProcParameters colorProcParameters,
// EyesisCorrectionParameters.RGBParameters rgbParameters,
CLTPass3d bgnd_data,
String name,
// int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
int threadsMax, // maximal number of threads to launch
boolean updateStatus,
int debugLevel
)
{
// final boolean new_mode = false;
boolean dbg_gpu_transition = true;
......@@ -11953,8 +12181,7 @@ public class QuadCLTCPU {
if ((debugLevel > -1))
sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging?
CLTPass3d bgnd_data = tp.clt_3d_passes.get(0);
// double [][][][] texture_tiles = bgnd_data.texture_tiles;
// CLTPass3d bgnd_data = tp.clt_3d_passes.get(0);
boolean [] bgnd_tiles = tp.getBackgroundMask( // which tiles do belong to the background
clt_parameters.bgnd_range, // disparity range to be considered background
......@@ -12031,6 +12258,7 @@ public class QuadCLTCPU {
// Get BG image from already available non-overlapped texture_tiles in bg_scan
public ImagePlus getBackgroundImage( // USED in lwir
boolean [] bgnd_tiles,
CLTPass3d bgnd_data,
CLTParameters clt_parameters,
ColorProcParameters colorProcParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
......@@ -12045,7 +12273,7 @@ public class QuadCLTCPU {
final boolean new_mode = false;
int num_bgnd = 0;
CLTPass3d bgnd_data = tp.clt_3d_passes.get(0);
// CLTPass3d bgnd_data = tp.clt_3d_passes.get(0);
double [][][][] texture_tiles = bgnd_data.texture_tiles;
double [][][][] texture_tiles_bgnd = new double[tilesY][tilesX][][];
double [] alpha_zero = new double [4*clt_parameters.transform_size*clt_parameters.transform_size];
......@@ -12467,7 +12695,10 @@ public class QuadCLTCPU {
public CLTPass3d CLTBackgroundMeas( // measure background // USED in lwir
CLTParameters clt_parameters,
CLTParameters clt_parameters,
final boolean run_lma, //
final double max_chn_diff, // filter correlation results by maximum difference between channels
final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
......@@ -12488,7 +12719,9 @@ public class QuadCLTCPU {
true, // final boolean need_diffs, // calculate diffs even if textures are not needed. Also calculates low-res
0, // final int clust_radius,
true, // final boolean save_corr,
true, // final boolean run_lma, // = true;
run_lma, // true, // final boolean run_lma, // = true;
max_chn_diff, // 0.0, // final double max_chn_diff, // filter correlation results by maximum difference between channels
mismatch_override,// -1.0, // final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
......@@ -12694,6 +12927,8 @@ public class QuadCLTCPU {
clust_radius, // final int clust_radius,
true, // final boolean save_corr,
run_lma, // final boolean run_lma, // = true;
0.0, // final double max_chn_diff, // filter correlation results by maximum difference between channels
-1.0, // final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
......@@ -13205,13 +13440,17 @@ public class QuadCLTCPU {
final int scanIndex,
final boolean save_textures,
final int clust_radius,
final boolean run_lma, //
final double max_chn_diff, // filter correlation results by maximum difference between channels
final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
CLTPass3d scan = tp.clt_3d_passes.get(scanIndex);
boolean run_lma = clt_parameters.correlate_lma;
boolean need_diffs = true; //???
// boolean run_lma = clt_parameters.correlate_lma;
boolean need_diffs = true;
// double mismatch_override =
CLTMeas( // perform single pass according to prepared tiles operations and disparity
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
scan, // final CLTPass3d scan,
......@@ -13220,6 +13459,8 @@ public class QuadCLTCPU {
clust_radius, // final int clust_radius,
true, // final boolean save_corr,
run_lma, // final boolean run_lma, // = true;
max_chn_diff, // final double max_chn_diff, // filter correlation results by maximum difference between channels
mismatch_override, // final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
......@@ -13230,7 +13471,7 @@ public class QuadCLTCPU {
double [] disparity) { // all that are not null
return null;
}
// Trying 10/2021 ImageDttCPU methods
// Trying 10/2021 ImageDttCPU methods. 7/18/22 - added max_chn_diff to get rid of ghosts in the sky
public CLTPass3d CLTMeas( // perform single pass according to prepared tiles operations and disparity // USED in lwir
final CLTParameters clt_parameters,
final CLTPass3d scan,
......@@ -13239,6 +13480,8 @@ public class QuadCLTCPU {
final int clust_radius,
final boolean save_corr,
final boolean run_lma, // = true;
final double max_chn_diff, // filter correlation results by maximum difference between channels
final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
......@@ -13579,6 +13822,12 @@ public class QuadCLTCPU {
scan.is_measured = true; // but no disparity map/textures
scan.is_combo = false;
scan.has_lma = null;
if (max_chn_diff > 0 ) {
scan.resetByDiff(
max_chn_diff,
mismatch_override);
}
scan.getLMA(); // recalculate
scan.getNumTileMax(); // calculate
scan.resetProcessed();
......@@ -14973,6 +15222,8 @@ public class QuadCLTCPU {
clust_radius, // final int clust_radius,
true, // final boolean save_corr,
true, // final boolean run_lma, // = true;
0.0, // final double max_chn_diff, // filter correlation results by maximum difference between channels
-1.0, // final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
100, // final int threadsMax, // maximal number of threads to launch
true, // final boolean updateStatus,
0); // final int debugLevel)
......
......@@ -1058,28 +1058,70 @@ public class TileProcessor {
copyDebug,
debugLevel).get(0);
}
class DSD{
int indx;
double disparity;
double strength;
double adiff;
public class DSD implements Comparable<DSD>{
int indx;
double disparity;
double strength;
double adiff;
boolean has_lma;
int clust_radius;
double fom = Double.NEGATIVE_INFINITY;
DSD (int indx){ // only index
this.indx = indx;
}
DSD ( int indx,
double disparity,
double strength,
double adiff,
boolean has_lma,
int clust_radius
){
this.indx = indx;
this.disparity = disparity;
this.strength = strength;
this.adiff = adiff;
this.has_lma = has_lma;
this.clust_radius = clust_radius;
}
DSD (int indx, double disparity, double strength, double adiff, boolean has_lma, int clust_radius){
DSD ( int indx,
double disparity,
double strength,
double adiff,
boolean has_lma,
int clust_radius,
double fom
){
this.indx = indx;
this.disparity = disparity;
this.strength = strength;
this.adiff = adiff;
this.has_lma = has_lma;
this.clust_radius = clust_radius;
this.fom = fom;
}
@Override
public int compareTo(DSD other) {
return (Double.valueOf(this.disparity)).compareTo(other.disparity);
}
}
private ArrayList<DSD> filterDsdList( // TODO: Finish adding has_lma !!!!!!!!!!!!!!!!!
Comparator<DSD> dsdByFom = new Comparator<DSD>() {
public int compare(DSD lhs, DSD rhs) {
return (lhs.fom > rhs.fom) ? 1 : ((lhs.fom < rhs.fom)? -1: 0);
}
};
Comparator<DSD> dsdByLmaRadFom = new Comparator<DSD>() {
public int compare(DSD lhs, DSD rhs) {
if ( lhs.has_lma && !rhs.has_lma) return 1;
if (!lhs.has_lma && rhs.has_lma) return -1;
if ( lhs.clust_radius < rhs.clust_radius) return 1;
if ( lhs.clust_radius > rhs.clust_radius) return -1;
return (lhs.fom > rhs.fom) ? 1 : ((lhs.fom < rhs.fom)? -1: 0);
}
};
private static ArrayList<DSD> filterDsdList( // TODO: Finish adding has_lma !!!!!!!!!!!!!!!!!
ArrayList<DSD> src_list,
double disp_tolerance,
int max_len,
......@@ -1405,6 +1447,7 @@ public class TileProcessor {
disparity_tolerance, // double disp_tolerance,
num_planes, // int max_len,
descending); // boolean descending)
// here got 1 entry for each plane (currently - just one plane
for (int np = 0; np< full_list.size(); np++) {
CLTPass3d pass = passes.get(full_list.get(np).indx);
CLTPass3d combo_pass = combo_pass_list.get(np);
......@@ -1418,7 +1461,6 @@ public class TileProcessor {
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.has_lma[nt] = m_lma;
......@@ -1441,6 +1483,7 @@ public class TileProcessor {
}
}
// fill empty planes (if any). May be all if there were no even weak tiles (old best_index<0)
// ???
for (int np = full_list.size(); np < num_planes; np++) {
CLTPass3d combo_pass = combo_pass_list.get(np);
combo_pass.tile_op[ty][tx] = 0;
......@@ -1449,7 +1492,9 @@ public class TileProcessor {
combo_pass.strength[nt] = 0.0;
// combo_pass.has_lma[nt] = false;
// 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){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt] = Double.NaN;
combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt] = Double.NaN;
......@@ -1552,7 +1597,292 @@ ImageDtt.startAndJoin(threads);
return combo_pass_list;
}
/**
* Prepare combined map from multiple passes. Single-plane, no vertical/horizontal processing
* Designed to prevent false near objects over empty sky. Should be used after correlation data
* is filtered by pixel values differences between channels (that requires good equqlization)
* When selecting between multiple measured "scans" (for each tile) only measured ones are
* processed - others are ignored.
* For now - single plane only!
* First all non-lma data is removed if lma exists
* Second only the smallest radius data is kept
* Third: maximal strength scan is found, and tiles stronger that this value decreased by str_tolerance
* are kept.
* Among them the lowest disparity one is found. Tiles from this disparity to this disparity plus
* disp_range are considered, among them the smallest adisp (absolute value of the residual disparity)
* is selected)
* @param passes input data as an ArrayList <CLTPass3d>
* @param firstPass index of the first pass to use
* @param lastPassPlus1 index plus 1 of the last pass to use
* @param disp_far lowest disparity value to consider (does not apply to max_tried_disparity)
* @param disp_near highest disparity value to consider (does not apply to max_tried_disparity)
* @param fom_min_strength ignore weaker tiles
* @param fom_use_lma obey LMA/noLMA and clust_radius
* @param fom_adisp weight of the absolute value of the residual disparity
* @param fom_cdiff weight of the inter-channel pixel mismatch (needs photometric equalization)
* @param fom_inf_bonus select among this weaker than the highest FOM
* @param fom_inf_range select among tiles with this larger disparity than zero (infinity)
* @param copyDebug copy data that is only needed for debug purposes
* @param debugLevel debug level
* @return composite scan (not added to the list)
*/
public CLTPass3d compositeScan(
final ArrayList <CLTPass3d> passes,
final int firstPass,
final int lastPassPlus1,
// final double trustedCorrelation,
final double fom_min_strength,
final boolean fom_use_lma,
final double fom_adisp, // 0.5
final double fom_cdiff, // 0.02
final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
final double fom_inf_range, // 0.5;
final boolean copyDebug,
final int debugLevel)
{
final double corr_magic_scale_lma = 1.0;
final int dbg_tile = -1;
final int tlen = tilesX * tilesY;
// 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;
CLTPass3d combo_pass = new CLTPass3d(this);
combo_pass.tile_op = new int [tilesY][tilesX]; // for just non-zero
combo_pass.disparity_map = new double [ImageDtt.getDisparityTitles(getNumSensors(), isMonochrome()).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];
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
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];
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;
// final CLTPass3d combo_pass0 = combo_pass; // will replace!
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() {
for (int nTile = ai.getAndIncrement(); nTile < tlen; nTile = ai.getAndIncrement()) {
int tx = nTile % tilesX;
int ty = nTile / tilesX;
ArrayList<DSD> dsd_list = new ArrayList<DSD>();
for (int ipass = firstPass; ipass <lastPassPlus1; ipass++ ){
CLTPass3d pass = passes.get(ipass);
if (nTile == dbg_tile) {
System.out.println("compositeScan(): ipass = "+ipass+" nTile = "+nTile+" 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_pass.max_tried_disparity[ty][tx]) ||
(pass.disparity[ty][tx] > combo_pass.max_tried_disparity[ty][tx]))){
combo_pass.max_tried_disparity[ty][tx] = pass.disparity[ty][tx];
}
int clust_radius = pass.getClustRadius();
double [] mdisp_lma_arr = pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY];
boolean m_lma = (mdisp_lma_arr != null) && !Double.isNaN(mdisp_lma_arr[nTile]);
double mdisp = m_lma?
mdisp_lma_arr[nTile] : pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nTile];
double corr_magic = m_lma ? corr_magic_scale_lma : corr_magic_scale;
double strength = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nTile];
double adiff = Math.abs(mdisp);
double disp = mdisp/corr_magic + pass.disparity[ty][tx];
if (strength >= fom_min_strength) {
double fom = pass.getFOM(
nTile,
fom_min_strength,
fom_adisp,
fom_cdiff);
dsd_list.add(new DSD(ipass, disp, strength, adiff, m_lma, clust_radius,fom)); //second_max_diff[nt]));
}
}
}
if (!dsd_list.isEmpty()) {
// DSD dsd_max_fom = fom_use_lma ? Collections.max(dsd_list, dsdByLmaRadFom):Collections.max(dsd_list, dsdByFom);
DSD fom_best = getSkyFom(
dsd_list, // final ArrayList<DSD> dsd_list,
fom_use_lma, // boolean use_lma, // and radius
fom_inf_bonus, // final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
fom_inf_range); // final double fom_inf_range) // 0.5;
Collections.sort(dsd_list);
CLTPass3d pass = passes.get(fom_best.indx);
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];
}
double [] mdisp_lma_arr = pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY];
boolean m_lma = (mdisp_lma_arr != null) && !Double.isNaN(mdisp_lma_arr[nTile]);
double mdisp = m_lma?
mdisp_lma_arr[nTile] : pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nTile];
double corr_magic = m_lma ? corr_magic_scale_lma : corr_magic_scale;
combo_pass.calc_disparity[nTile] = mdisp/corr_magic + pass.disparity[ty][tx];
combo_pass.strength[nTile] = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nTile];
combo_pass.has_lma[nTile] = m_lma;
// 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][nTile] = pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nTile];
}
}
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nTile] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nTile];
combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nTile] = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nTile];
if (pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY] != null) {
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY][nTile] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY][nTile];
}
if (pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY + 1] != null) {
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY+1][nTile] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY+1][nTile];
}
}
} else { // Fill in data for empty tile
combo_pass.tile_op[ty][tx] = 0;
combo_pass.texture_tiles[ty][tx] = null;
combo_pass.calc_disparity[nTile] = Double.NaN;
combo_pass.strength[nTile] = 0.0;
// Only copy for full disparity
for (int i = 0; i< numSensors; i++) {
combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nTile] = Double.NaN;
}
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nTile] = Double.NaN;
combo_pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nTile] = Double.NaN;
if (combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY] != null) {
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY][nTile] = Double.NaN;
}
if (combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY+1] != null) {
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_POLY+1][nTile] = Double.NaN;
}
}
}// if (!dsd_list.isEmpty()) else {
// fill empty planes (if any). May be all if there were no even weak tiles (old best_index<0)
}
}
};
}
ImageDtt.startAndJoin(threads);
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;
}
public DSD getSkyFom(
final ArrayList<DSD> dsd_list,
boolean use_lma, // and radius
final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
final double fom_inf_range) // 0.5;
{
if (dsd_list.isEmpty()) {
return null;
}
DSD dsd_max_fom = use_lma ? Collections.max(dsd_list, dsdByLmaRadFom):Collections.max(dsd_list, dsdByFom);
double min_fom = dsd_max_fom.fom - fom_inf_bonus;
boolean need_lma = use_lma ? dsd_max_fom.has_lma : false;
int max_radius = use_lma ? dsd_max_fom.clust_radius:-1;
double best_fom = Double.NaN;
DSD dsd_best = dsd_max_fom;
for (int i = 0; i < dsd_list.size(); i++) {
DSD dsd = dsd_list.get(i);
if ( (dsd.fom >= min_fom) &&
(!need_lma || dsd.has_lma) &&
((max_radius < 0) || (dsd.clust_radius <= max_radius)) &&
(dsd.disparity <= fom_inf_range) &&
!(dsd.fom <= best_fom)) {
best_fom = dsd.fom;
dsd_best = dsd;
}
}
return dsd_best; // dsd_best will not be modified from dsd_max_fom.indx if no infinity result is good enough
}
public void printScans(
final ArrayList <CLTPass3d> passes,
final int firstPass,
final int lastPassPlus1,
final boolean use_lma,
final double fom_min_strength,
final double fom_adisp, // 0.5
final double fom_cdiff, // 0.02
final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
final double fom_inf_range, // 0.5;
final int tileX,
final int tileY
) {
ArrayList<DSD> dsd_list = new ArrayList<DSD>();
int nt = getTilesX()*tileY + tileX;
final double corr_magic_scale_lma = 1.0;
for (int ipass = firstPass; ipass <lastPassPlus1; ipass++ ){
CLTPass3d pass = passes.get(ipass);
if ( pass.isMeasured() && (pass.tile_op[tileY][tileX] != 0 )) {
int clust_radius = pass.getClustRadius();
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;
double strength = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt];
double adiff = Math.abs(mdisp);
double disp = mdisp/corr_magic + pass.disparity[tileY][tileX];
double fom = pass.getFOM(
nt,
fom_min_strength,
fom_adisp,
fom_cdiff);
dsd_list.add(new DSD(ipass, disp, strength, adiff, m_lma, clust_radius,fom)); //second_max_diff[nt]));
}
}
if (dsd_list.isEmpty()) {
System.out.println("Scans for tileX="+tileX+" tileY="+tileY+ " ntile="+nt+" list IS EMPTY");
return;
}
DSD dsd_max_fom = use_lma ? Collections.max(dsd_list, dsdByLmaRadFom):Collections.max(dsd_list, dsdByFom);
DSD sky_best = getSkyFom(
dsd_list, // final ArrayList<DSD> dsd_list,
use_lma, // boolean use_lma, // and radius
fom_inf_bonus, // final double fom_inf_bonus, // 0.2; // add this to infinity FOM (if it is closer than fom_inf_range)
fom_inf_range); // final double fom_inf_range) // 0.5;
Collections.sort(dsd_list);
System.out.println ("Scans for tileX="+tileX+" tileY="+tileY+ " ntile="+nt+
" (fom_adisp="+fom_adisp+", fom_cdiff="+fom_cdiff+
", fom_inf_bonus="+fom_inf_bonus+", fom_inf_range="+fom_inf_range+"):");
// System.out.println (" 0: 1.907 0.1389 1.6207 false 0 165.572 chn_dif");
System.out.println (" pass disp stren adisp lma R chn_dif FOM");
for (DSD dsd:dsd_list) {
CLTPass3d pass = passes.get(dsd.indx);
double [] diffs = pass.getSecondMaxDiff(false);
String prefix = " ";
if (dsd.indx == dsd_max_fom.indx) {
prefix = "+";
if (dsd.indx == sky_best.indx) {
prefix = "*";
}
} else if (dsd.indx == sky_best.indx) {
prefix = "S";
}
System.out.println (String.format("%1s%4d: %8.3f %6.4f %6.4f %5b %1d %8.3f %8.3f",
prefix, //
dsd.indx, dsd.disparity, dsd.strength, dsd.adiff, dsd.has_lma, dsd.clust_radius, diffs[nt], dsd.fom));
}
System.out.println();
return;
}
public int expandCertain (
final CLTPass3d combo_pass, // modify
......@@ -5277,9 +5607,9 @@ ImageDtt.startAndJoin(threads);
System.out.println("FilterScan(): this_disparity["+i+"] = "+this_disparity[i]+"this_strength["+i+"] = "+this_strength[i]);
}
if (this_disparity[i] < disparity_far) {
if (this_disparity[i] < disparity_far) {
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 ? // null here
far_tiles[i] = true;
}
}
......@@ -5898,6 +6228,38 @@ ImageDtt.startAndJoin(threads);
return null;
}
public CLTPass3d refinePassSetup( // prepare tile tasks for the second pass based on the previous one(s)
CLTPass3d combo_pass,
final int debugLevel) {
CLTPass3d scan_next =new CLTPass3d(this);
double [] prev_disparity = combo_pass.getDisparity(1); // (0) - calc_disparity_combo - wrong
double [][] disparityTask = new double [tilesY][tilesX];
int [][] tile_op = new int [tilesY][tilesX];
boolean [] borderTiles = new boolean[tilesY*tilesX]; // to zero alpha in the images
boolean [] need_meas = new boolean [prev_disparity.length];
for (int i = 0; i < need_meas.length; i++) {
need_meas[i] = !Double.isNaN(prev_disparity[i]);
}
int op = ImageDtt.setImgMask(0, 0xf);
op = ImageDtt.setPairMask(op,0xf);
op = ImageDtt.setForcedDisparity(op,true);
for (int ty = 0; ty < tilesY; ty++) for (int tx = 0; tx <tilesX; tx++){
int indx = tilesX * ty + tx;
disparityTask[ty][tx] = prev_disparity[indx];
tile_op[ty][tx] = op;
}
scan_next.setClustRadius(0);
scan_next.disparity = disparityTask; // will have NaN-s
scan_next.tile_op = tile_op;
scan_next.setBorderTiles (borderTiles);
scan_next.setSelected(need_meas); // includes border_tiles
return scan_next;
}
public CLTPass3d refinePassSetupMulti( // prepare tile tasks for the second pass based on the previous one(s)
CLTPass3d combo_pass,
int clust_radius, // 0 - initial single-tile, 1 - 1x1 (same), 2 - 3x3, 3 5x5
......
......@@ -12493,6 +12493,8 @@ if (debugLevel > -100) return true; // temporarily !
0, // final int clust_radius,
true, // final boolean save_corr,
false, // final boolean run_lma, // = true;
0.0, // final double max_chn_diff, // filter correlation results by maximum difference between channels
-1.0, // final double mismatch_override, // keep tile with large mismatch if there is LMA with really strong correlation
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
......
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