Commit ff4593c5 authored by Andrey Filippov's avatar Andrey Filippov

Improving/Debugging initial DSI

parent e93c08dc
...@@ -35,6 +35,7 @@ public class CLTPass3d{ ...@@ -35,6 +35,7 @@ public class CLTPass3d{
private double [][] disparity_sav; // saved disparity private double [][] disparity_sav; // saved disparity
private int [][] tile_op_sav; // saved tile_op private int [][] tile_op_sav; // saved tile_op
public double [][] disparity_map = null; // add 4 layers - worst difference for the port 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 double [][] lazy_eye_data = null;
public int lma_cluster_size = -1; public int lma_cluster_size = -1;
public boolean [] lazy_eye_force_disparity = null; public boolean [] lazy_eye_force_disparity = null;
...@@ -315,7 +316,7 @@ public class CLTPass3d{ ...@@ -315,7 +316,7 @@ public class CLTPass3d{
} }
/** /**
* Get FPGA-calculated per-tile maximal differences between the particular image and the average one. * 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 (){ public double [][] getDiffs (){
...@@ -738,6 +739,45 @@ public class CLTPass3d{ ...@@ -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 public boolean [] hasLMADefined(){ // will try not to create this.has_lma
if (disparity_map == null) { if (disparity_map == null) {
if (has_lma==null) { if (has_lma==null) {
...@@ -1108,7 +1148,16 @@ public class CLTPass3d{ ...@@ -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 ( public double [] getSecondMaxDiff (
final boolean averaged) final boolean averaged)
{ {
...@@ -1170,8 +1219,58 @@ public class CLTPass3d{ ...@@ -1170,8 +1219,58 @@ public class CLTPass3d{
ImageDtt.startAndJoin(threads); ImageDtt.startAndJoin(threads);
return second_max_averaged; 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 // same, but 2 steps around
public boolean [] getUntestedBackgroundBorder2 ( public boolean [] getUntestedBackgroundBorder2 (
......
...@@ -52,7 +52,9 @@ public class MultisceneLY { ...@@ -52,7 +52,9 @@ public class MultisceneLY {
false, // final boolean need_diffs, // calculate diffs even if textures are not needed false, // final boolean need_diffs, // calculate diffs even if textures are not needed
0, // final int clust_radius, 0, // final int clust_radius,
true, // final boolean save_corr, 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 threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus, updateStatus, // final boolean updateStatus,
debug_level); // final int debugLevel); debug_level); // final int debugLevel);
......
...@@ -4244,6 +4244,8 @@ public class OpticalFlow { ...@@ -4244,6 +4244,8 @@ public class OpticalFlow {
0, // final int clust_radius, 0, // final int clust_radius,
true, // final boolean save_corr, true, // final boolean save_corr,
false, // final boolean run_lma, // = true; 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 threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus, updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel); debugLevel); // final int debugLevel);
...@@ -4544,7 +4546,8 @@ public class OpticalFlow { ...@@ -4544,7 +4546,8 @@ public class OpticalFlow {
debugLevel+1); debugLevel+1);
quadCLT_main.setLwirOffsets(quadCLTs[ref_index].getLwirOffsets()); quadCLT_main.setLwirOffsets(quadCLTs[ref_index].getLwirOffsets());
quadCLT_main.setLwirScales(quadCLTs[ref_index].getLwirScales()); 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" quadCLTs[ref_index] = (QuadCLT) quadCLT_main.spawnQuadCLT( // restores dsi from "DSI-MAIN"
set_channels[ref_index].set_name, set_channels[ref_index].set_name,
clt_parameters, clt_parameters,
......
...@@ -3847,6 +3847,9 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -3847,6 +3847,9 @@ public class QuadCLT extends QuadCLTCPU {
if ((gpuQuad == null) || !(isAux()?clt_parameters.gpu_use_aux : clt_parameters.gpu_use_main)) { if ((gpuQuad == null) || !(isAux()?clt_parameters.gpu_use_aux : clt_parameters.gpu_use_main)) {
return super.CLTBackgroundMeas( // measure background // USED in lwir return super.CLTBackgroundMeas( // measure background // USED in lwir
clt_parameters, 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 threadsMax, // maximal number of threads to launch
updateStatus, updateStatus,
debugLevel); debugLevel);
...@@ -3995,6 +3998,7 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -3995,6 +3998,7 @@ public class QuadCLT extends QuadCLTCPU {
public ImagePlus getBackgroundImage( public ImagePlus getBackgroundImage(
boolean [] bgnd_tiles, boolean [] bgnd_tiles,
CLTPass3d bgnd_data,
CLTParameters clt_parameters, CLTParameters clt_parameters,
ColorProcParameters colorProcParameters, ColorProcParameters colorProcParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters, EyesisCorrectionParameters.RGBParameters rgbParameters,
...@@ -4007,6 +4011,7 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -4007,6 +4011,7 @@ public class QuadCLT extends QuadCLTCPU {
if ((gpuQuad == null) || !(isAux()?clt_parameters.gpu_use_aux : clt_parameters.gpu_use_main)) { if ((gpuQuad == null) || !(isAux()?clt_parameters.gpu_use_aux : clt_parameters.gpu_use_main)) {
return super.getBackgroundImage( // measure background // USED in lwir return super.getBackgroundImage( // measure background // USED in lwir
bgnd_tiles, bgnd_tiles,
bgnd_data,
clt_parameters, clt_parameters,
colorProcParameters, colorProcParameters,
rgbParameters, rgbParameters,
...@@ -4019,7 +4024,7 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -4019,7 +4024,7 @@ public class QuadCLT extends QuadCLTCPU {
final int tilesX = tp.getTilesX(); final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY(); 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 boolean [] bgnd_tiles_grown2 = bgnd_data.getSelected().clone(); // only these have non 0 alpha
tp.growTiles( 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 2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
......
...@@ -12493,6 +12493,8 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -12493,6 +12493,8 @@ if (debugLevel > -100) return true; // temporarily !
0, // final int clust_radius, 0, // final int clust_radius,
true, // final boolean save_corr, true, // final boolean save_corr,
false, // final boolean run_lma, // = true; 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 threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus, updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel); 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