Commit 95647831 authored by Andrey Filippov's avatar Andrey Filippov

Attached ML generation and export of the DSI-aware warped images

parent 23452c5b
...@@ -1163,6 +1163,7 @@ public class ImageDtt extends ImageDttCPU { ...@@ -1163,6 +1163,7 @@ public class ImageDtt extends ImageDttCPU {
* Convert reference scene to FD and save result in extra GPU array for the future interscene correlation * Convert reference scene to FD and save result in extra GPU array for the future interscene correlation
* Geometry correction and images will come from gpuQuad instance - * Geometry correction and images will come from gpuQuad instance -
* @param imgdtt_params * @param imgdtt_params
* @param use_reference_buffer true - use extra GPU array, false - use main one
* @param tp_tasks * @param tp_tasks
* @param gpu_sigma_r * @param gpu_sigma_r
* @param gpu_sigma_b * @param gpu_sigma_b
...@@ -1173,6 +1174,7 @@ public class ImageDtt extends ImageDttCPU { ...@@ -1173,6 +1174,7 @@ public class ImageDtt extends ImageDttCPU {
*/ */
public void setReferenceTD( public void setReferenceTD(
final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
final boolean use_reference_buffer,
final TpTask[] tp_tasks, final TpTask[] tp_tasks,
final double gpu_sigma_r, // 0.9, 1.1 final double gpu_sigma_r, // 0.9, 1.1
final double gpu_sigma_b, // 0.9, 1.1 final double gpu_sigma_b, // 0.9, 1.1
...@@ -1201,7 +1203,7 @@ public class ImageDtt extends ImageDttCPU { ...@@ -1201,7 +1203,7 @@ public class ImageDtt extends ImageDttCPU {
tp_tasks, tp_tasks,
false); // boolean use_aux // while is it in class member? - just to be able to free false); // boolean use_aux // while is it in class member? - just to be able to free
// Skipping if ((fdisp_dist != null) || (fpxpy != null)) {... // Skipping if ((fdisp_dist != null) || (fpxpy != null)) {...
gpuQuad.execConvertDirect(true); // put results into a "reference" buffer gpuQuad.execConvertDirect(use_reference_buffer); // put results into a "reference" buffer
} }
......
...@@ -3803,7 +3803,9 @@ public class OpticalFlow { ...@@ -3803,7 +3803,9 @@ public class OpticalFlow {
{ {
boolean build_ref_dsi = false; // true; boolean build_ref_dsi = false; // true;
boolean build_orientations = false; boolean build_orientations = false;
boolean build_interscene = true; boolean build_interscene = false; // true;
boolean export_images = true; // 16-slice images (same disparity, COMBO_DSN_INDX_DISP_FG and COMBO_DSN_INDX_DISP_BG_ALL,
boolean show_images = true;
final int debugLevelInner=clt_parameters.batch_run? -2: debugLevel; // copied from TQ final int debugLevelInner=clt_parameters.batch_run? -2: debugLevel; // copied from TQ
if ((quadCLT_main != null) && (quadCLT_main.getGPU() != null)) { if ((quadCLT_main != null) && (quadCLT_main.getGPU() != null)) {
...@@ -3903,7 +3905,7 @@ public class OpticalFlow { ...@@ -3903,7 +3905,7 @@ public class OpticalFlow {
} // split cycles to remove output clutter } // split cycles to remove output clutter
} // if (build_ref_dsi) { } // if (build_ref_dsi) {
quadCLTs[ref_index] = (QuadCLT) quadCLT_main.spawnQuadCLT( 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,
colorProcParameters, // colorProcParameters, //
...@@ -3984,6 +3986,7 @@ public class OpticalFlow { ...@@ -3984,6 +3986,7 @@ public class OpticalFlow {
null, // String path, // full name with extension or w/o path to use x3d directory null, // String path, // full name with extension or w/o path to use x3d directory
debugLevel+1); debugLevel+1);
} // if (build_orientations) { } // if (build_orientations) {
double [][] combo_dsn_final = null;
if (build_interscene) { if (build_interscene) {
if (!build_orientations) { if (!build_orientations) {
for (int scene_index = ref_index - 1; scene_index >= 0 ; scene_index--) { for (int scene_index = ref_index - 1; scene_index >= 0 ; scene_index--) {
...@@ -3996,18 +3999,79 @@ public class OpticalFlow { ...@@ -3996,18 +3999,79 @@ public class OpticalFlow {
} }
} }
intersceneExport( combo_dsn_final = intersceneExport( // result indexed by COMBO_DSN_TITLES, COMBO_DSN_INDX_***
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
ers_reference, // ErsCorrection ers_reference, ers_reference, // ErsCorrection ers_reference,
quadCLTs, // QuadCLT [] scenes, quadCLTs, // QuadCLT [] scenes,
colorProcParameters, // ColorProcParameters colorProcParameters, colorProcParameters, // ColorProcParameters colorProcParameters,
debugLevel); // int debug_level debugLevel); // int debug_level
} }
if (export_images) {
if (combo_dsn_final == null) {
combo_dsn_final = quadCLTs[ref_index].readDoubleArrayFromModelDirectory(
"-INTER-INTRA-LMA", // String suffix,
0, // int num_slices, // (0 - all)
null); // int [] wh);
}
double [] fg_disparity = combo_dsn_final[COMBO_DSN_INDX_DISP_FG];
double [] bg_disparity = combo_dsn_final[COMBO_DSN_INDX_DISP_BG_ALL];
double [] constant_disparity = new double [fg_disparity.length];
Arrays.fill(constant_disparity,clt_parameters.disparity);
ImagePlus imp_constant = QuadCLT.renderGPUFromDSI(
clt_parameters, // CLTParameters clt_parameters,
constant_disparity, // double [] disparity_ref,
ZERO3, // final double [] scene_xyz, // camera center in world coordinates
ZERO3, // final double [] scene_atr, // camera orientation relative to world frame
quadCLTs[ref_index], // final QuadCLT scene,
"GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel)
quadCLTs[ref_index].saveImagePlusInModelDirectory(
"GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_constant); // ImagePlus imp)
if (show_images) {
imp_constant.show();
}
Arrays.fill(constant_disparity,clt_parameters.disparity);
ImagePlus imp_fg = QuadCLT.renderGPUFromDSI(
clt_parameters, // CLTParameters clt_parameters,
fg_disparity, // double [] disparity_ref,
ZERO3, // final double [] scene_xyz, // camera center in world coordinates
ZERO3, // final double [] scene_atr, // camera orientation relative to world frame
quadCLTs[ref_index], // final QuadCLT scene,
"GPU-SHIFTED-FOREGROUND", // String suffix,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel)
quadCLTs[ref_index].saveImagePlusInModelDirectory(
"GPU-SHIFTED-FOREGROUND", // String suffix,
imp_fg); // ImagePlus imp)
if (show_images) {
imp_fg.show();
}
ImagePlus imp_bg = QuadCLT.renderGPUFromDSI(
clt_parameters, // CLTParameters clt_parameters,
bg_disparity, // double [] disparity_ref,
ZERO3, // final double [] scene_xyz, // camera center in world coordinates
ZERO3, // final double [] scene_atr, // camera orientation relative to world frame
quadCLTs[ref_index], // final QuadCLT scene,
"GPU-SHIFTED-BACKGROUND", // String suffix,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel)
quadCLTs[ref_index].saveImagePlusInModelDirectory(
"GPU-SHIFTED-BACKGROUND", // String suffix,
imp_bg); // ImagePlus imp)
if (show_images) {
imp_bg.show();
}
}
// Add 16-images:
//disparity = 0, FG, BG
System.out.println("buildSeries(): DONE"); // System.out.println("buildSeries(): DONE"); //
return true; return true;
} }
public double [] spiralSearchATR( public double [] spiralSearchATR(
CLTParameters clt_parameters, CLTParameters clt_parameters,
QuadCLT reference_QuadClt, QuadCLT reference_QuadClt,
...@@ -5293,7 +5357,7 @@ public class OpticalFlow { ...@@ -5293,7 +5357,7 @@ public class OpticalFlow {
} }
public ImagePlus generateSceneOutlines( public static ImagePlus generateSceneOutlines(
QuadCLT ref_scene, // ordered by increasing timestamps QuadCLT ref_scene, // ordered by increasing timestamps
QuadCLT [] scenes, QuadCLT [] scenes,
int extra, // add around largest outline int extra, // add around largest outline
...@@ -5451,7 +5515,7 @@ public class OpticalFlow { ...@@ -5451,7 +5515,7 @@ public class OpticalFlow {
return imp_stack; return imp_stack;
} }
public void intersceneExport( public double [][] intersceneExport(
CLTParameters clt_parameters, CLTParameters clt_parameters,
ErsCorrection ers_reference, ErsCorrection ers_reference,
QuadCLT [] scenes, QuadCLT [] scenes,
...@@ -6033,7 +6097,7 @@ public class OpticalFlow { ...@@ -6033,7 +6097,7 @@ public class OpticalFlow {
System.out.println("intersceneExport(): saved "+file_path); System.out.println("intersceneExport(): saved "+file_path);
} }
if ( clt_parameters.ofp.pattern_mode) { if ( clt_parameters.ofp.pattern_mode) {
return; return combo_dsn_final;
} }
double [][] all_offsets = new double [disparity_steps][]; double [][] all_offsets = new double [disparity_steps][];
String [] soffset_centers = new String [disparity_steps]; String [] soffset_centers = new String [disparity_steps];
...@@ -6176,6 +6240,7 @@ public class OpticalFlow { ...@@ -6176,6 +6240,7 @@ public class OpticalFlow {
tilesX, // int width, tilesX, // int width,
tilesY); // int height) tilesY); // int height)
} }
return combo_dsn_final;
} }
/** /**
...@@ -9045,8 +9110,8 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -9045,8 +9110,8 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
final double min_strength_blur = 0.06; /// 0.2; final double min_strength_blur = 0.06; /// 0.2;
final double sigma = 2; /// 5; final double sigma = 2; /// 5;
final int num_blur = 1; // 3; final int num_blur = 1; // 3;
final double disparity_corr = 0.0; final double disparity_corr = 0.00;
final double outliers_max_strength = 0.1; /// 0.25;
final int outliers_nth_fromextrem = 1; // second from min/max - removes dual-tile max/mins final int outliers_nth_fromextrem = 1; // second from min/max - removes dual-tile max/mins
final double outliers_tolerance_absolute = .2; final double outliers_tolerance_absolute = .2;
final double outliers_tolerance_relative = .02; final double outliers_tolerance_relative = .02;
...@@ -9055,15 +9120,71 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -9055,15 +9120,71 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
final int outliers_nth_fromextrem2 = 0; // second from min/max - removes dual-tile max/mins final int outliers_nth_fromextrem2 = 0; // second from min/max - removes dual-tile max/mins
final double outliers_tolerance_absolute2 = .5; final double outliers_tolerance_absolute2 = .5;
final double outliers_tolerance_relative2 = .1; final double outliers_tolerance_relative2 = .1;
final double outliers_lma_max_strength = 0.5;
final double outliers_max_strength = 0.1; /// 0.25;
final double outliers_from_lma_max_strength = 0.5;
final double diff_from_lma_pos = 100.0;
final double diff_from_lma_neg = 2.0;
final int outliers_lma_nth_fromextrem = 1;
// final int margin = 4; /// was 8 for EO 8; // pixels // final int margin = 4; /// was 8 for EO 8; // pixels
final int margin = 8; // pixels final int margin = 8; // pixels
double [][] dsrbg = scene.getDSRBG(); // double [][] dsrbg = scene.getDSRBG();
if (dsrbg == null) { // if (dsrbg == null) {
// return null;
// }
double [][] dls = scene.getDLS();
if (dls == null) {
return null; return null;
} }
String [] dbg_titles = {"str", "lma", "disp","-lma","by-lma","-nonlma", "old-disp","old-sngl","weak","filled"};
double [][] dbg_img = new double [dbg_titles.length][];
//Remove crazy LMA high-disparity tiles
dbg_img[0] = dls[2].clone();
dbg_img[1] = dls[1].clone();
dbg_img[2] = dls[0].clone();
double [] disp_outliers = QuadCLT.removeDisparityLMAOutliers(
false, // final boolean non_ma,
dls, //final double [][] dls,
outliers_lma_max_strength, // final double max_strength, // do not touch stronger
outliers_lma_nth_fromextrem, // final int nth_fromextrem, // 0 - compare to max/min. 1 - second max/min, ...
outliers_tolerance_absolute, // final double tolerance_absolute,
outliers_tolerance_relative, // final double tolerance_relative,
tilesX, //final int width, //tilesX
outliers_max_iter, // final int max_iter,
threadsMax, // final int threadsMax,
debug_level); // final int debug_level)
dbg_img[3] = disp_outliers.clone();
disp_outliers = QuadCLT.removeDisparityOutliersByLMA(
new double[][] {disp_outliers, dls[1], dls[2]}, //final double [][] dls,
outliers_from_lma_max_strength, // final double max_strength, // do not touch stronger
diff_from_lma_pos, // final double diff_from_lma_pos, // Difference from farthest FG objects (OK to have large, e.g. 100)
diff_from_lma_neg, // final double diff_from_lma_neg, // Difference from nearest BG objects (small, as FG are usually more visible)
false, // final boolean remove_no_lma_neib, // remove without LMA neighbors
tilesX, //final int width, //tilesX
threadsMax, // final int threadsMax,
debug_level); // final int debug_level)
dbg_img[4] = disp_outliers.clone();
// mostly filter infinity, clouds, sky // mostly filter infinity, clouds, sky
double [] disp_outliers = QuadCLT.removeDisparityOutliers( disp_outliers = QuadCLT.removeDisparityLMAOutliers( // filter non-lma tiles
new double[][] {dsrbg[QuadCLT.DSRBG_DISPARITY], dsrbg[QuadCLT.DSRBG_STRENGTH]}, // double [][] ds0, true, // final boolean non_ma,
dls, //final double [][] dls,
outliers_lma_max_strength, // final double max_strength, // do not touch stronger
outliers_lma_nth_fromextrem, // final int nth_fromextrem, // 0 - compare to max/min. 1 - second max/min, ...
outliers_tolerance_absolute, // final double tolerance_absolute,
outliers_tolerance_relative, // final double tolerance_relative,
tilesX, //final int width, //tilesX
outliers_max_iter, // final int max_iter,
threadsMax, // final int threadsMax,
debug_level); // final int debug_level)
dbg_img[5] = disp_outliers.clone();
// Pre- 2022 filters, some may be obsolete
disp_outliers = QuadCLT.removeDisparityOutliers(
new double[][] {disp_outliers, dls[2]}, //final double [][] dls,
outliers_max_strength, // final double max_strength, // do not touch stronger outliers_max_strength, // final double max_strength, // do not touch stronger
outliers_nth_fromextrem, // final int nth_fromextrem, // 0 - compare to max/min. 1 - second max/min, ... outliers_nth_fromextrem, // final int nth_fromextrem, // 0 - compare to max/min. 1 - second max/min, ...
outliers_tolerance_absolute, // final double tolerance_absolute, outliers_tolerance_absolute, // final double tolerance_absolute,
...@@ -9073,9 +9194,10 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -9073,9 +9194,10 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
false, // final boolean fit_completely, // do not add tolerance when replacing false, // final boolean fit_completely, // do not add tolerance when replacing
threadsMax, // final int threadsMax, threadsMax, // final int threadsMax,
debug_level); // final int debug_level) debug_level); // final int debug_level)
dbg_img[6] = disp_outliers.clone();
// remove extreme single-tile outliers (some may be strong - 0.404) // remove extreme single-tile outliers (some may be strong - 0.404)
disp_outliers = QuadCLT.removeDisparityOutliers( disp_outliers = QuadCLT.removeDisparityOutliers(
new double[][] {disp_outliers, dsrbg[QuadCLT.DSRBG_STRENGTH]}, // double [][] ds0, new double[][] {disp_outliers, dls[2]}, //final double [][] dls,
outliers_max_strength2, // final double max_strength, // do not touch stronger outliers_max_strength2, // final double max_strength, // do not touch stronger
outliers_nth_fromextrem2, // final int nth_fromextrem, // 0 - compare to max/min. 1 - second max/min, ... outliers_nth_fromextrem2, // final int nth_fromextrem, // 0 - compare to max/min. 1 - second max/min, ...
outliers_tolerance_absolute2, // final double tolerance_absolute, outliers_tolerance_absolute2, // final double tolerance_absolute,
...@@ -9085,17 +9207,16 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -9085,17 +9207,16 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
false, // final boolean fit_completely, // do not add tolerance when replacing false, // final boolean fit_completely, // do not add tolerance when replacing
threadsMax, // final int threadsMax, threadsMax, // final int threadsMax,
debug_level); // final int debug_level) debug_level); // final int debug_level)
dbg_img[7] = disp_outliers.clone();
double [] disp = QuadCLT.blurWeak( double [] disp = QuadCLT.blurWeak(
new double[][] {disp_outliers, dsrbg[QuadCLT.DSRBG_STRENGTH]}, // double [][] ds, new double[][] {disp_outliers, dls[2]}, //final double [][] dls,
min_strength_blur, // double min_strength_blur, min_strength_blur, // double min_strength_blur,
min_strength_replace, // double min_strength_replace, min_strength_replace, // double min_strength_replace,
num_blur, // int n, num_blur, // int n,
tilesX, // int width, tilesX, // int width,
sigma); // double sigma); sigma); // double sigma);
dbg_img[8] = disp.clone();
double [][] ds = {disp, dsrbg[QuadCLT.DSRBG_STRENGTH]}; double [][] ds = {disp, dls[2]};
final double [][] ds_filled = QuadCLT.fillDisparityStrength( final double [][] ds_filled = QuadCLT.fillDisparityStrength(
ds, // final double [][] ds0, ds, // final double [][] ds0,
min_disparity, // final double min_disparity, min_disparity, // final double min_disparity,
...@@ -9106,8 +9227,20 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -9106,8 +9227,20 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
tilesX, // final int width, tilesX, // final int width,
threadsMax, // final int threadsMax, threadsMax, // final int threadsMax,
debug_level); // final int debug_level) debug_level); // final int debug_level)
dbg_img[9] = ds_filled[0].clone();
if ((debug_level > 0)) {// && (clt_parameters.ofp.enable_debug_images)) {
(new ShowDoubleFloatArrays()).showArrays(
dbg_img,
tilesX,
tilesY,
true,
"filtered-"+scene.getImageName(),
dbg_titles); // dsrbg_titles);
}
// Mask bad tiles // Mask bad tiles
final boolean [] valid_tiles = new boolean [tiles]; final boolean [] valid_tiles = new boolean [tiles]; // not used ?
final double [][] pXpYD = new double [tiles][3]; final double [][] pXpYD = new double [tiles][3];
final Thread[] threads = ImageDtt.newThreadArray(threadsMax); final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0);
...@@ -9165,8 +9298,8 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -9165,8 +9298,8 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
if ((debug_level > 0) && (clt_parameters.ofp.enable_debug_images)) { if ((debug_level > 0) && (clt_parameters.ofp.enable_debug_images)) {
String [] dbg_titles = {"disp", "disp_outliers", "disp_blur", "disp_filled", "str", "str_filled"}; dbg_titles = new String[]{"disp", "disp_outliers", "disp_blur", "disp_filled", "str", "str_filled"};
double [][] dbg_img = {dsrbg[QuadCLT.DSRBG_DISPARITY], disp_outliers, ds[0], ds_filled[0], ds[1], ds_filled[1]}; dbg_img = new double[][]{dls[0], disp_outliers, ds[0], ds_filled[0], ds[1], ds_filled[1]};
(new ShowDoubleFloatArrays()).showArrays( (new ShowDoubleFloatArrays()).showArrays(
dbg_img, dbg_img,
tilesX, tilesX,
...@@ -9285,7 +9418,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -9285,7 +9418,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
final double disparity_corr = 0.00; // (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction); final double disparity_corr = 0.00; // (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
double [][] dsrbg_ref= ref_scene.getDSRBG(); double [][] dsrbg_ref= ref_scene.getDSRBG();
double [][] ref_pXpYD = transformToScenePxPyD( // full size - [tilesX*tilesY], some nulls double [][] ref_pXpYD = transformToScenePxPyD( // full size - [tilesX*tilesY], some nulls
dsrbg_ref[00], // final double [] disparity_ref, // invalid tiles - NaN in disparity (maybe it should not be masked by margins?) dsrbg_ref[0], // final double [] disparity_ref, // invalid tiles - NaN in disparity (maybe it should not be masked by margins?)
ZERO3, // final double [] scene_xyz, // camera center in world coordinates ZERO3, // final double [] scene_xyz, // camera center in world coordinates
ZERO3, // final double [] scene_atr, // camera orientation relative to world frame ZERO3, // final double [] scene_atr, // camera orientation relative to world frame
ref_scene, // final QuadCLT scene_QuadClt, ref_scene, // final QuadCLT scene_QuadClt,
...@@ -9336,6 +9469,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -9336,6 +9469,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
ref_scene.saveQuadClt(); // to re-load new set of Bayer images to the GPU (do nothing for CPU) and Geometry ref_scene.saveQuadClt(); // to re-load new set of Bayer images to the GPU (do nothing for CPU) and Geometry
image_dtt.setReferenceTD( image_dtt.setReferenceTD(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
true, // final boolean use_reference_buffer,
tp_tasks_ref, // final TpTask[] tp_tasks, tp_tasks_ref, // final TpTask[] tp_tasks,
clt_parameters.gpu_sigma_r, // final double gpu_sigma_r, // 0.9, 1.1 clt_parameters.gpu_sigma_r, // final double gpu_sigma_r, // 0.9, 1.1
clt_parameters.gpu_sigma_b, // final double gpu_sigma_b, // 0.9, 1.1 clt_parameters.gpu_sigma_b, // final double gpu_sigma_b, // 0.9, 1.1
...@@ -9349,7 +9483,8 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -9349,7 +9483,8 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
clt_parameters.getColorProcParameters(ref_scene.isAux()), //ColorProcParameters colorProcParameters, clt_parameters.getColorProcParameters(ref_scene.isAux()), //ColorProcParameters colorProcParameters,
clt_parameters.getRGBParameters(), //EyesisCorrectionParameters.RGBParameters rgbParameters, clt_parameters.getRGBParameters(), //EyesisCorrectionParameters.RGBParameters rgbParameters,
toRGB, // boolean toRGB, toRGB, // boolean toRGB,
true); //boolean use_reference true, //boolean use_reference
"GPU-SHIFTED-REFERENCE"); // String suffix)
imp_render_ref.show(); imp_render_ref.show();
} }
...@@ -9376,7 +9511,9 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -9376,7 +9511,9 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
clt_parameters.getColorProcParameters(ref_scene.isAux()), //ColorProcParameters colorProcParameters, clt_parameters.getColorProcParameters(ref_scene.isAux()), //ColorProcParameters colorProcParameters,
clt_parameters.getRGBParameters(), //EyesisCorrectionParameters.RGBParameters rgbParameters, clt_parameters.getRGBParameters(), //EyesisCorrectionParameters.RGBParameters rgbParameters,
toRGB, // boolean toRGB, toRGB, // boolean toRGB,
false); //boolean use_reference false, //boolean use_reference
"GPU-SHIFTED-SCENE"); // String suffix)
imp_render_scene.show(); imp_render_scene.show();
} }
......
...@@ -122,6 +122,167 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -122,6 +122,167 @@ public class QuadCLT extends QuadCLTCPU {
} }
} }
public static double [] removeDisparityLMAOutliers( // just LMA FG
final boolean non_lma,
final double [][] dls,
final double max_strength, // do not touch stronger
final int nth_fromextrem, // 0 - compare to max/min. 1 - second max/min, ...
final double tolerance_absolute,
final double tolerance_relative,
final int width,
final int max_iter,
final int threadsMax,
final int debug_level)
{
final int tiles = dls[0].length;
final double [] disparity = dls[0].clone();
final double [] disparity_out = dls[0].clone();
final double [] disparity_lma = dls[1].clone();
final double [] strength = dls[2]; // will not be updated
final TileNeibs tn = new TileNeibs(width, tiles/width);
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger anum_updated = new AtomicInteger(0);
final int dbg_tile = 989;
for (int iter = 0; iter < max_iter; iter++) {
ai.set(0);
anum_updated.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
double [] neibs = new double[8];
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) {
if ((debug_level >0) && (nTile == dbg_tile)) {
System.out.println("removeDisparityOutliers() nTile="+nTile);
}
if ( !Double.isNaN(disparity[nTile]) &&
(!Double.isNaN(disparity_lma[nTile]) ^ non_lma) &&
(strength[nTile] < max_strength)) { // weak LMA
Arrays.fill(neibs, Double.NaN);
for (int dir = 0; dir < 8; dir++) {
int ineib = tn.getNeibIndex(nTile, dir);
if (ineib >= 0) {
neibs[dir] = non_lma ? disparity[ineib] : disparity_lma[ineib];
if (Double.isNaN(disparity[ineib])) {
neibs[dir] =Double.NaN;
}
}
}
Arrays.sort(neibs); // increasing, NaNs - in the end
int num_defined = neibs.length;
for (int i = 0; i < neibs.length; i++) {
if (Double.isNaN(neibs[i])) {
num_defined = i;
break;
}
}
if (num_defined > 0) {
int nth_min = nth_fromextrem;
if (nth_min >= num_defined) {
nth_min = num_defined - 1;
}
int nth_max = num_defined - 1 - nth_min;
double d_max = neibs[nth_max] + tolerance_absolute + neibs[nth_max]*tolerance_relative;
if ((non_lma ? disparity[nTile] : disparity_lma[nTile]) > d_max) {
disparity_out[nTile] = Double.NaN;
}
if (disparity_out[nTile] != disparity[nTile]) {
anum_updated.getAndIncrement();
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
if (anum_updated.get() ==0) {
break;
}
System.arraycopy(disparity_out,0,disparity,0,tiles);
}
return disparity_out;
}
/**
* Remove no-LMA tiles if they do not have a close neighbors that have LMA
* result. As an option - do not touch tiles that do not have LMA neighbors
* @param dls disparity, lma-disparity, strength (disparity and LMA disparity
* have the same values, just some of LMA have NaN.
* @param max_strength Do not touch tiles stronger than that
* @param diff_from_lma_pos Difference from farthest FG objects (OK to have large, e.g. 100)
* @param diff_from_lma_neg diff_from_lma_neg Difference from nearest BG objects (small, as FG are usually more visible)
* @param remove_no_lma_neib remove tiles that do not have LMA neighbors
* @param width DSI width
* @param threadsMax
* @param debug_level
* @return new disparity array, removed tiles are Double.NaN
*/
public static double [] removeDisparityOutliersByLMA(
final double [][] dls,
final double max_strength, // do not touch stronger
final double diff_from_lma_pos, // Difference from farthest FG objects (OK to have large, e.g. 100)
final double diff_from_lma_neg, // Difference from nearest BG objects (small, as FG are usually more visible)
final boolean remove_no_lma_neib, // remove without LMA neighbors
final int width, //tilesX
final int threadsMax,
final int debug_level)
{
final int tiles = dls[0].length;
final double [] disparity = dls[0].clone();
final double [] disparity_out = dls[0].clone();
final double [] disparity_lma = dls[1].clone();
final double [] strength = dls[2]; // will not be updated
final TileNeibs tn = new TileNeibs(width, tiles/width);
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger anum_updated = new AtomicInteger(0);
final int dbg_tile = 1066;
anum_updated.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) {
if ((debug_level >0) && (nTile == dbg_tile)) {
System.out.println("removeDisparityOutliers() nTile="+nTile);
}
if (Double.isNaN(disparity_lma[nTile]) && !Double.isNaN(disparity[nTile]) && (strength[nTile] < max_strength)) {
double best_fit_pos = Double.NaN; // Closest higher disparity than this
double best_fit_neg = Double.NaN; // Closest lower disparity than this
for (int dir = 0; dir < 8; dir++) {
int ineib = tn.getNeibIndex(nTile, dir);
if ( (ineib >= 0) &&
!Double.isNaN(disparity_lma[ineib]) &&
!Double.isNaN(disparity[ineib])) {
double d = disparity[nTile] - disparity_lma[ineib];
if (d > 0) {
if (!(d >= best_fit_neg)) {
best_fit_neg = d;
}
} else {
if (!(-d >= best_fit_pos)) {
best_fit_neg = -d;
}
}
}
}
if ( (best_fit_neg > diff_from_lma_neg) ||
(best_fit_pos > diff_from_lma_pos) ||
(Double.isNaN(best_fit_pos) && Double.isNaN(best_fit_neg) && remove_no_lma_neib)) {
disparity_out[nTile] = Double.NaN;
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return disparity_out;
}
public static double [] removeDisparityOutliers( public static double [] removeDisparityOutliers(
final double [][] ds0, final double [][] ds0,
final double max_strength, // do not touch stronger final double max_strength, // do not touch stronger
...@@ -199,8 +360,8 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -199,8 +360,8 @@ public class QuadCLT extends QuadCLTCPU {
System.arraycopy(disparity_out,0,disparity,0,tiles); System.arraycopy(disparity_out,0,disparity,0,tiles);
} }
return disparity_out; return disparity_out;
} }
public static double [][] fillDisparityStrength( public static double [][] fillDisparityStrength(
final double [][] ds0, final double [][] ds0,
final double min_disparity, final double min_disparity,
...@@ -1869,12 +2030,74 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -1869,12 +2030,74 @@ public class QuadCLT extends QuadCLTCPU {
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")"); IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
} }
public static ImagePlus renderGPUFromDSI(
CLTParameters clt_parameters,
double [] disparity_ref,
final double [] scene_xyz, // camera center in world coordinates
final double [] scene_atr, // camera orientation relative to world frame
final QuadCLT scene,
String suffix,
int threadsMax,
final int debugLevel){
double [][] pXpYD =OpticalFlow.transformToScenePxPyD(
disparity_ref, // final double [] disparity_ref, // invalid tiles - NaN in disparity
scene_xyz, // final double [] scene_xyz, // camera center in world coordinates
scene_atr, // final double [] scene_atr, // camera orientation relative to world frame
scene, // final QuadCLT scene_QuadClt,
scene, // final QuadCLT reference_QuadClt, // now - may be null - for testing if scene is rotated ref
threadsMax); // int threadsMax)
TpTask[] tp_tasks_ref = GpuQuad.setInterTasks(
scene.getNumSensors(),
scene.getErsCorrection().getSensorWH()[0],
!scene.hasGPU(), // final boolean calcPortsCoordinatesAndDerivatives, // GPU can calculate them centreXY
pXpYD, // final double [][] pXpYD, // per-tile array of pX,pY,disparity triplets (or nulls)
null, // final boolean [] selection, // may be null, if not null do not process unselected tiles
scene.getErsCorrection(), // final GeometryCorrection geometryCorrection,
0.0, // final double disparity_corr,
0, // margin, // final int margin, // do not use tiles if their centers are closer to the edges
null, // final boolean [] valid_tiles,
threadsMax); // final int threadsMax) // maximal number of threads to launch
scene.saveQuadClt(); // to re-load new set of Bayer images to the GPU (do nothing for CPU) and Geometry
ImageDtt image_dtt = new ImageDtt(
scene.getNumSensors(),
clt_parameters.transform_size,
clt_parameters.img_dtt,
scene.isAux(),
scene.isMonochrome(),
scene.isLwir(),
clt_parameters.getScaleStrength(scene.isAux()),
scene.getGPU());
boolean use_reference = false;
boolean toRGB = true; // does not work here, define in ColorProcParameters
image_dtt.setReferenceTD( // change to main?
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
use_reference, // true, // final boolean use_reference_buffer,
tp_tasks_ref, // final TpTask[] tp_tasks,
clt_parameters.gpu_sigma_r, // final double gpu_sigma_r, // 0.9, 1.1
clt_parameters.gpu_sigma_b, // final double gpu_sigma_b, // 0.9, 1.1
clt_parameters.gpu_sigma_g, // final double gpu_sigma_g, // 0.6, 0.7
clt_parameters.gpu_sigma_m, // final double gpu_sigma_m, // = 0.4; // 0.7;
threadsMax, // final int threadsMax, // maximal number of threads to launch
debugLevel); // final int globalDebugLevel);
ImagePlus imp_render = scene.renderFromTD (
clt_parameters, // CLTParameters clt_parameters,
clt_parameters.getColorProcParameters(scene.isAux()), //ColorProcParameters colorProcParameters,
clt_parameters.getRGBParameters(), //EyesisCorrectionParameters.RGBParameters rgbParameters,
toRGB, // boolean toRGB,
use_reference, //boolean use_reference
suffix); // String suffix)
return imp_render;
}
public ImagePlus renderFromTD ( public ImagePlus renderFromTD (
CLTParameters clt_parameters, CLTParameters clt_parameters,
ColorProcParameters colorProcParameters, ColorProcParameters colorProcParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters, EyesisCorrectionParameters.RGBParameters rgbParameters,
boolean toRGB, boolean toRGB,
boolean use_reference boolean use_reference,
String suffix
) { ) {
gpuQuad.execImcltRbgAll(isMonochrome(), use_reference); // add ref gpuQuad.execImcltRbgAll(isMonochrome(), use_reference); // add ref
// get data back from GPU // get data back from GPU
...@@ -1946,7 +2169,7 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -1946,7 +2169,7 @@ public class QuadCLT extends QuadCLTCPU {
/// array_stack.addSlice("port_"+slice_seq[i], results[slice_seq[i]].getProcessor().getPixels()); /// array_stack.addSlice("port_"+slice_seq[i], results[slice_seq[i]].getProcessor().getPixels());
/// } /// }
} }
ImagePlus imp_stack = new ImagePlus(image_name+sAux()+"GPU-SHIFTED-D"+clt_parameters.disparity, array_stack); ImagePlus imp_stack = new ImagePlus(image_name+sAux()+suffix, array_stack);
imp_stack.getProcessor().resetMinAndMax(); imp_stack.getProcessor().resetMinAndMax();
return imp_stack; return imp_stack;
} }
......
...@@ -158,6 +158,18 @@ public class QuadCLTCPU { ...@@ -158,6 +158,18 @@ public class QuadCLTCPU {
public double [][] ds_from_main = null; public double [][] ds_from_main = null;
public double [][] dsrbg = null; // D, S, R,B,G public double [][] dsrbg = null; // D, S, R,B,G
public double [][] getDLS(){ // get disparity, disparity_lma, strength
if (dsi == null) {
// System.out.println("dsi== null, use spawnQuadCLT(), restoreFromModel(), ... to set it");
return null;
}
double [][] dls = new double[3][];
dls[0] = dsi[isAux()? TwoQuadCLT.DSI_DISPARITY_AUX : TwoQuadCLT.DSI_DISPARITY_MAIN];
dls[1] = dsi[isAux()? TwoQuadCLT.DSI_DISPARITY_AUX_LMA : TwoQuadCLT.DSI_DISPARITY_MAIN_LMA];
dls[2] = dsi[isAux()? TwoQuadCLT.DSI_STRENGTH_AUX : TwoQuadCLT.DSI_STRENGTH_MAIN];
return dls;
}
public TileProcessor getTileProcessor() { public TileProcessor getTileProcessor() {
return tp; return tp;
} }
...@@ -502,8 +514,6 @@ public class QuadCLTCPU { ...@@ -502,8 +514,6 @@ public class QuadCLTCPU {
} }
public String [] getDSRGGTitles() { public String [] getDSRGGTitles() {
return isMonochrome()? return isMonochrome()?
// (new String[]{"disparity","strength", "disparity_lma","Y"}):
// (new String[]{"disparity","strength", "disparity_lma","R","B","G"});
(new String[]{"disparity","strength", "Y"}): (new String[]{"disparity","strength", "Y"}):
(new String[]{"disparity","strength", "R","B","G"}); (new String[]{"disparity","strength", "R","B","G"});
} }
...@@ -643,7 +653,7 @@ public class QuadCLTCPU { ...@@ -643,7 +653,7 @@ public class QuadCLTCPU {
return rgba; return rgba;
} }
public QuadCLTCPU restoreFromModel( public QuadCLTCPU restoreFromModel( // restores dsi
CLTParameters clt_parameters, CLTParameters clt_parameters,
ColorProcParameters colorProcParameters, ColorProcParameters colorProcParameters,
NoiseParameters noise_sigma_level, NoiseParameters noise_sigma_level,
......
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