Commit c1955bd8 authored by Andrey Filippov's avatar Andrey Filippov

More debugging

parent 7d01b009
......@@ -65,8 +65,11 @@ public class GpuQuad{ // quad camera description
private CUdeviceptr gpu_kernels;
private CUdeviceptr gpu_kernel_offsets;
private CUdeviceptr gpu_bayer;
// private CUdeviceptr gpu_tasks;
private CUdeviceptr gpu_ftasks;
private CUdeviceptr gpu_ftasks=null;
private int gpu_ftasks_len = 0;
private CUdeviceptr gpu_active_tiles=null; // will be re-allocated with gpu_ftasks
private CUdeviceptr gpu_corrs;
private CUdeviceptr gpu_corr_weights;
private CUdeviceptr gpu_corrs_td;
......@@ -98,7 +101,7 @@ public class GpuQuad{ // quad camera description
private CUdeviceptr gpu_rot_deriv;
private CUdeviceptr gpu_geometry_correction;
private CUdeviceptr gpu_rByRDist;
private CUdeviceptr gpu_active_tiles;
// private CUdeviceptr gpu_active_tiles;
private CUdeviceptr gpu_num_active_tiles;
private int mclt_stride;
private int corr_stride;
......@@ -274,8 +277,7 @@ public class GpuQuad{ // quad camera description
gpu_kernels = new CUdeviceptr();
gpu_kernel_offsets = new CUdeviceptr();
gpu_bayer = new CUdeviceptr();
// gpu_tasks = new CUdeviceptr(); // allocate tilesX * tilesY * TPTASK_SIZE * Sizeof.FLOAT
gpu_ftasks = new CUdeviceptr(); // allocate tilesX * tilesY * getTaskSize() * Sizeof.FLOAT
/// gpu_ftasks = new CUdeviceptr(); // allocate tilesX * tilesY * getTaskSize() * Sizeof.FLOAT
gpu_corrs = new CUdeviceptr(); // allocate tilesX * tilesY * NUM_PAIRS * CORR_SIZE * Sizeof.FLOAT
gpu_corr_weights = new CUdeviceptr(); // allocate tilesX * tilesY * NUM_PAIRS * Sizeof.FLOAT
......@@ -284,8 +286,6 @@ public class GpuQuad{ // quad camera description
gpu_corrs_combo_td = new CUdeviceptr(); // allocate tilesX * tilesY * 4 * DTT_SIZE * DTT_SIZE * Sizeof.FLOAT
gpu_textures = new CUdeviceptr(); // allocate tilesX * tilesY * ? * 256 * Sizeof.FLOAT
/// gpu_clt = new CUdeviceptr();
/// gpu_4_images = new CUdeviceptr();
gpu_corr_indices = new CUdeviceptr(); // allocate tilesX * tilesY * 6 * Sizeof.FLOAT
// May add separate gpu_corr_indices_td here
gpu_corr_combo_indices = new CUdeviceptr(); // allocate tilesX * tilesY * 1 * Sizeof.FLOAT
......@@ -309,7 +309,7 @@ public class GpuQuad{ // quad camera description
gpu_geometry_correction= new CUdeviceptr();
gpu_rByRDist= new CUdeviceptr(); // calculated once for the camera distortion model in CPU (move to GPU?)
gpu_active_tiles = new CUdeviceptr(); // TILESX*TILESY*sizeof(int)
/// gpu_active_tiles = new CUdeviceptr(); // TILESX*TILESY*sizeof(int)
gpu_num_active_tiles = new CUdeviceptr(); // 1 int
// Init data arrays for all kernels
......@@ -330,19 +330,6 @@ public class GpuQuad{ // quad camera description
Sizeof.FLOAT); // int ElementSizeBytes)
mclt_stride = (int)(device_stride[0] / Sizeof.FLOAT);
// Maybe move _bayer to use variable width/height as gpu_clt, gpu_corr_images_h
/*
gpu_corr_images_h[ncam] = new CUdeviceptr();
cuMemAllocPitch (
gpu_corr_images_h[ncam], // CUdeviceptr dptr,
device_stride, // long[] pPitch,
(img_width + GPUTileProcessor.DTT_SIZE) * Sizeof.FLOAT, // long WidthInBytes,
3*(img_height + GPUTileProcessor.DTT_SIZE),// long Height,
Sizeof.FLOAT); // int ElementSizeBytes)
imclt_stride = (int)(device_stride[0] / Sizeof.FLOAT);
*/
/// gpu_clt_h[ncam] = new CUdeviceptr();
/// cuMemAlloc(gpu_clt_h[ncam],tilesY * tilesX * num_colors * 4 * GPUTileProcessor.DTT_SIZE * GPUTileProcessor.DTT_SIZE * Sizeof.FLOAT ); // public static int cuMemAlloc(CUdeviceptr dptr, long bytesize)
}
// now create device arrays pointers
if (Sizeof.POINTER != Sizeof.LONG) {
......@@ -353,14 +340,10 @@ public class GpuQuad{ // quad camera description
cuMemAlloc(gpu_kernels, num_cams * Sizeof.POINTER);
cuMemAlloc(gpu_kernel_offsets, num_cams * Sizeof.POINTER);
cuMemAlloc(gpu_bayer, num_cams * Sizeof.POINTER);
/// cuMemAlloc(gpu_clt, num_cams * Sizeof.POINTER);
/// cuMemAlloc(gpu_4_images, num_cams * Sizeof.POINTER);
long [] gpu_kernels_l = new long [num_cams];
long [] gpu_kernel_offsets_l = new long [num_cams];
long [] gpu_bayer_l = new long [num_cams];
/// long [] gpu_clt_l = new long [num_cams];
/// long [] gpu_4_images_l = new long [num_cams];
for (int ncam = 0; ncam < num_cams; ncam++) gpu_kernels_l[ncam] = GPUTileProcessor.getPointerAddress(gpu_kernels_h[ncam]);
cuMemcpyHtoD(gpu_kernels, Pointer.to(gpu_kernels_l), num_cams * Sizeof.POINTER);
......@@ -371,23 +354,16 @@ public class GpuQuad{ // quad camera description
for (int ncam = 0; ncam < num_cams; ncam++) gpu_bayer_l[ncam] = GPUTileProcessor.getPointerAddress(gpu_bayer_h[ncam]);
cuMemcpyHtoD(gpu_bayer, Pointer.to(gpu_bayer_l), num_cams * Sizeof.POINTER);
/// for (int ncam = 0; ncam < num_cams; ncam++) gpu_clt_l[ncam] = GPUTileProcessor.getPointerAddress(gpu_clt_h[ncam]);
/// cuMemcpyHtoD(gpu_clt, Pointer.to(gpu_clt_l), num_cams * Sizeof.POINTER);
/// for (int ncam = 0; ncam < num_cams; ncam++) gpu_4_images_l[ncam] = GPUTileProcessor.getPointerAddress(gpu_corr_images_h[ncam]);
/// cuMemcpyHtoD(gpu_4_images, Pointer.to(gpu_4_images_l), num_cams * Sizeof.POINTER);
// Set GeometryCorrection data
cuMemAlloc(gpu_geometry_correction, GeometryCorrection.arrayLength(GPUTileProcessor.MAX_NUM_CAMS) * Sizeof.FLOAT); // always maximal number of cameras (sparse)
cuMemAlloc(gpu_rByRDist, GPUTileProcessor.RBYRDIST_LEN * Sizeof.FLOAT);
cuMemAlloc(gpu_rot_deriv, 5*GPUTileProcessor.MAX_NUM_CAMS*3*3 * Sizeof.FLOAT); // always maximal number of cameras (sparse)
// cuMemAlloc(gpu_correction_vector, CorrVector.LENGTH * Sizeof.FLOAT);
cuMemAlloc(gpu_correction_vector, GPUTileProcessor.CORR_VECTOR_MAX_LENGTH * Sizeof.FLOAT); // update CORR_VECTOR_LENGTH to fit
// Set task array
// cuMemAlloc(gpu_tasks, tilesX * tilesY * GPUTileProcessor.TPTASK_SIZE * Sizeof.FLOAT);
cuMemAlloc(gpu_ftasks, tilesX * tilesY * getTaskSize() * Sizeof.FLOAT);
// cuMemAlloc(gpu_ftasks, tilesX * tilesY * getTaskSize() * Sizeof.FLOAT);
// checkAllocateGpuFtasks((tilesX+4) * (tilesY+4)); // +4 - "a little more" (will reallocate if needed)
checkAllocateGpuFtasks(tilesX * tilesY); // +4 - "a little more" (will reallocate if needed)
//=========== Seems that in many places Sizeof.POINTER (==8) is used instead of Sizeof.FLOAT !!! ============
// Set corrs array
int num_pairs = Correlation2d.getNumPairs(quadCLT.getNumSensors());
......@@ -412,8 +388,8 @@ public class GpuQuad{ // quad camera description
cuMemAlloc(gpu_num_texture_ovlp, 8 * Sizeof.FLOAT);
cuMemAlloc(gpu_texture_indices_len, 1 * Sizeof.FLOAT);
cuMemAlloc(gpu_active_tiles, tilesX * tilesY * Sizeof.FLOAT);
// will be dynamically allocated with gpu_ftasks
// cuMemAlloc(gpu_active_tiles, tilesX * tilesY * Sizeof.FLOAT);
cuMemAlloc(gpu_num_active_tiles, 1 * Sizeof.FLOAT);
cuMemAlloc(gpu_corr_weights, num_pairs* tilesX * tilesY * Sizeof.FLOAT);
......@@ -473,6 +449,33 @@ public class GpuQuad{ // quad camera description
Sizeof.FLOAT); // int ElementSizeBytes)
texture_stride_rgba = (int)(device_stride[0] / Sizeof.FLOAT);
}
private void checkAllocateGpuFtasks(int max_tasks) {
/*
* Got jcuda.CudaException: CUDA_ERROR_MISALIGNED_ADDRESS
at jcuda.driver.JCudaDriver.checkResult(JCudaDriver.java:396)
at jcuda.driver.JCudaDriver.cuCtxSynchronize(JCudaDriver.java:2426)
at com.elphel.imagej.gpu.GpuQuad.execConvertDirect(GpuQuad.java:1596)
Will try rounding to multiple of smth (was 0x80)
*/
max_tasks = (max_tasks + 0x7f) & ~0x7f;
if (max_tasks > gpu_ftasks_len) {
if (gpu_ftasks != null) {
cuMemFree (gpu_ftasks);
}
if (gpu_active_tiles != null) {
cuMemFree (gpu_active_tiles);
}
gpu_ftasks = new CUdeviceptr();
cuMemAlloc(gpu_ftasks, max_tasks * getTaskSize() * Sizeof.FLOAT);
gpu_active_tiles = new CUdeviceptr();
cuMemAlloc(gpu_active_tiles, max_tasks * Sizeof.FLOAT);
gpu_ftasks_len = max_tasks;
}
}
public int getTilesX() {
return getImageWidth() / GPUTileProcessor.DTT_SIZE;
}
......@@ -619,7 +622,8 @@ public class GpuQuad{ // quad camera description
)
{
if (verify) checkTasks(tile_tasks);
num_task_tiles = tile_tasks.length;
num_task_tiles = tile_tasks.length; // only place that modifies num_task_tiles and may require allocation
checkAllocateGpuFtasks(num_task_tiles);
int task_size = getTaskSize();
float [] ftasks = new float [task_size * num_task_tiles];
for (int i = 0; i < num_task_tiles; i++) {
......@@ -645,7 +649,7 @@ public class GpuQuad{ // quad camera description
boolean use_aux // while is it in class member? - just to be able to free
)
{
num_task_tiles = tile_tasks.length;
num_task_tiles = tile_tasks.length; // does not require re-allocation, as tile_tasks should be already set to GPU
int task_size = getTaskSize();
float [] ftasks = new float [task_size * num_task_tiles];
cuMemcpyDtoH(Pointer.to(ftasks), gpu_ftasks, task_size * num_task_tiles * Sizeof.FLOAT);
......
......@@ -41,10 +41,48 @@ public class IntersceneMatchParameters {
public boolean show_mono_nan = false; // use NAN background for monochrome images (sharp, but distinct black)
public boolean show_ranges = true;
public boolean generate_mapped = true;
public int extra_hor_tile = 15;
public int extra_vert_tile = 10;
public int sensor_mask = 1; // -1 - all
public int mode3d = 1; // -1 - raw, 0 - infinity, 1 - FG, 2 - BG
public boolean show_mapped_color = true;
public boolean show_mapped_mono = false;
public double range_disparity_offset = -0.08;
public double range_min_strength = 0.5;
public double range_max = 5000.0;
// Other parameters for filtering depth maps
public int num_bottom = 6; // average this number of lowest disparity neighbors (of 8)
public int num_passes = 100;
public double max_change = 1.0e-3;
public double min_disparity = -0.2;
public double max_sym_disparity = 0.2;
public double min_strength_replace = 0.05; /// 0.14; /// Before /// - LWIR, after - RGB
public double min_strength_blur = 0.06; /// 0.2;
public double sigma = 2; /// 5;
public int num_blur = 1; // 3;
public double disparity_corr = 0.0;
public int outliers_nth_fromextrem = 1; // second from min/max - removes dual-tile max/mins
public double outliers_tolerance_absolute = 0.2;
public double outliers_tolerance_relative = 0.02;
public int outliers_max_iter = 100;
public double outliers_max_strength2 = 1.0; // 0.5; any
public int outliers_nth_fromextrem2 = 0; // second from min/max - removes dual-tile max/mins
public double outliers_tolerance_absolute2 = 0.5;
public double outliers_tolerance_relative2 = 0.1;
public double outliers_lma_max_strength = 0.5;
public double outliers_max_strength = 0.1; /// 0.25;
public double outliers_from_lma_max_strength = 0.8;
public int search_radius = 3; // Search farther if no LMA neighbor is found closer. Original value - 1 (8 neighbors)
public boolean remove_no_lma_neib = true;
public double diff_from_lma_pos = 100.0;
public double diff_from_lma_neg = 2.0;
public int outliers_lma_nth_fromextrem = 1;
public int filter_margin = -8; // 8; // pixels
// Some "AGC" to adjust how much to discard
public int margin = 1; // do not use tiles if their centers are closer to the image edge
......@@ -126,7 +164,8 @@ public class IntersceneMatchParameters {
"Use NaN for undefined tiles (false - 0.0f). NaN produces sharp distinct result, 0.0f - blended");
gd.addCheckbox ("Mono NaN background", this.show_mono_nan,
"Use NaN for undefined tiles (false - 0.0f). NaN produces sharp distinct result, 0.0f - blended");
gd.addMessage ("Metric distance map generation");
gd.addCheckbox ("Show distances in meters", this.show_ranges,
"Calculate strength, distance, X, and Y in meters");
gd.addNumericField("Disparity at infinity", this.range_disparity_offset, 5,7,"pix",
......@@ -135,6 +174,81 @@ public class IntersceneMatchParameters {
"Disregard weaker results when measuring range.");
gd.addNumericField("Maximal displayed range", this.range_max, 5,7,"m",
"Do not display extremely far objects.");
gd.addMessage ("Depth map filtering parameters");
gd.addNumericField("Average lowest disparity neighbors", this.num_bottom, 0,3,"",
"Average this number of lowest disparity neighbors (of 8)");
gd.addNumericField("Number of filter iterations", this.num_passes, 0,3,"",
"Number of filter iterations");
gd.addNumericField("Maximal change to exit", this.max_change, 5,7,"pix",
"Maximal change to exit iterations");
gd.addNumericField("Minimal disparity", this.min_disparity, 5,7,"pix",
"Minimal acceptable disparity");
gd.addNumericField("Max neib. disparity difference", this.max_sym_disparity, 5,7,"pix",
"Difference from the nearest of neighbors should not exceed this");
gd.addNumericField("Minimal strength to replace", this.min_strength_replace, 5,7,"",
"Minimal strength to replace");
gd.addNumericField("Minimal strength to blur", this.min_strength_blur, 5,7,"",
"Minimal strength to blur");
gd.addNumericField("Blur weak sigma", this.sigma, 5,7,"",
"Blur weak sigma");
gd.addNumericField("Number of blur passes", this.num_blur, 0,3,"",
"Number of blur passes");
gd.addNumericField("Disparity offset (not used)", this.disparity_corr, 5,7,"",
"for setInterTasks() - currently not used ");
gd.addNumericField("Outlier N-th from extreme", this.outliers_nth_fromextrem, 0,3,"",
"0 - use min/max, 1 - use second min/max, ... second from min/max - removes dual-tile clusters max/mins");
gd.addNumericField("Outliers tolerance absolute", this.outliers_tolerance_absolute, 5,7,"pix",
"Absolute difference from extreme neighbor");
gd.addNumericField("Outliers tolerance realtive", this.outliers_tolerance_relative, 5,7,"pix/pix",
"Add to tolerance as a fraction of absolute tile disparity");
gd.addNumericField("Maximal number of outlier iterations", this.outliers_max_iter, 0,3,"",
"Maximal number of iterations for removing outliers");
gd.addNumericField("Maximal outlier strength 2", this.outliers_max_strength2, 5,7,"",
"Maximal outlier strength for second pass filtering");
gd.addNumericField("Outlier N-th from extreme 2", this.outliers_nth_fromextrem2, 0,3,"",
"Second filter: 0 - use min/max, 1 - use second min/max, ... second from min/max - removes dual-tile clusters max/mins");
gd.addNumericField("Outliers tolerance absolute 2", this.outliers_tolerance_absolute2, 5,7,"",
"Absolute difference from extreme neighbor, second filter");
gd.addNumericField("Outliers tolerance realtive 2", this.outliers_tolerance_relative2, 5,7,"",
"Add to tolerance as a fraction of absolute tile disparity, second filter");
gd.addNumericField("Outliers LMA maximal strength", this.outliers_lma_max_strength, 5,7,"",
"Maximal LMA strength for an outlier");
gd.addNumericField("Outliers non-LMA maximal strength", this.outliers_max_strength, 5,7,"",
"Outliers non-LMA (centroid) maximal strength");
gd.addNumericField("Outliers from LMA max strength", this.outliers_from_lma_max_strength, 5,7,"",
"Non-LMA outliers from LMA neighbors maximal strength");
gd.addNumericField("Search for LMA radius", this.search_radius, 0,3,"tile",
"Search farther if no LMA tiles are found around this non-LMA tile");
gd.addCheckbox ("Remove non-LMA tile if no LMA near", this.remove_no_lma_neib,
"Remove non-LMA tile if no LMA one is found within specified radius");
gd.addNumericField("LMA difference positive", this.diff_from_lma_pos, 5,7,"",
"Maximal non-LMA tile positive difference from the LMA neighbor");
gd.addNumericField("LMA difference negative", this.diff_from_lma_neg, 5,7,"",
"Maximal non-LMA tile negative difference from the LMA neighbor");
gd.addNumericField("LMA outliers N-th from extreme", this.outliers_lma_nth_fromextrem, 0,3,"",
"0 - use min/max, 1 - use second min/max, ... ");
gd.addNumericField("Margin from the sensor FOV edge ", this.filter_margin, 0,3,"pix",
"Disregard tiles with centers closer to the sensor FoV in pixels");
gd.addMessage ("Show scene sequence");
gd.addCheckbox ("Generate mapped scene sequence", this.generate_mapped,
"Generate scene sequence mapped to the reference scene");
gd.addNumericField("Scene sequence horizontal extra", this.extra_hor_tile, 0,3,"tiles",
"Enlarge reference scene window horizontally in each direction to accommodate other scenes in a sequence");
gd.addNumericField("Scene sequence vertical extra", this.extra_vert_tile, 0,3,"tiles",
"Enlarge reference scene window vertically in each direction to accommodate other scenes in a sequence");
gd.addNumericField("Sensor mask (bitmask, -1 - all sensors)",this.sensor_mask, 0,3,"",
"Select which sensors to be included in each scene of the sequence");
gd.addNumericField("3D mode (-1 - RAW, 0 - infinity, 1 - FG, 2 BG)", this.mode3d, 0, 3, "",
"3D mode for rendering scenes in a sequence: -1 - raw images, 0 - no 3D, use infinity; 1 - Foreground; 2 - Background");
gd.addCheckbox ("Show scene sequences in (pseudo)colors", this.show_mapped_color,
"Show generated scene sequences in (pseudo)color mode");
gd.addCheckbox ("Show scene sequences in monochrome", this.show_mapped_mono,
"Show generated scene sequences in monochrome mode");
gd.addMessage ("Interscene match parameters");
gd.addNumericField("Image margin", this.margin, 0,5,"pix",
......@@ -247,6 +361,42 @@ public class IntersceneMatchParameters {
this.range_min_strength = gd.getNextNumber();
this.range_max = gd.getNextNumber();
this.num_bottom = (int) gd.getNextNumber();
this.num_passes = (int) gd.getNextNumber();
this.max_change = gd.getNextNumber();
this.min_disparity = gd.getNextNumber();
this.max_sym_disparity = gd.getNextNumber();
this.min_strength_replace = gd.getNextNumber();
this.min_strength_blur = gd.getNextNumber();
this.sigma = gd.getNextNumber();
this.num_blur = (int) gd.getNextNumber();
this.disparity_corr = gd.getNextNumber();
this.outliers_nth_fromextrem = (int) gd.getNextNumber();
this.outliers_tolerance_absolute = gd.getNextNumber();
this.outliers_tolerance_relative = gd.getNextNumber();
this.outliers_max_iter = (int) gd.getNextNumber();
this.outliers_max_strength2 = gd.getNextNumber();
this.outliers_nth_fromextrem2 = (int) gd.getNextNumber();
this.outliers_tolerance_absolute2 = gd.getNextNumber();
this.outliers_tolerance_relative2 = gd.getNextNumber();
this.outliers_lma_max_strength = gd.getNextNumber();
this.outliers_max_strength = gd.getNextNumber();
this.outliers_from_lma_max_strength = gd.getNextNumber();
this.search_radius = (int) gd.getNextNumber();
this.remove_no_lma_neib = gd.getNextBoolean();
this.diff_from_lma_pos = gd.getNextNumber();
this.diff_from_lma_neg = gd.getNextNumber();
this.outliers_lma_nth_fromextrem=(int)gd.getNextNumber();
this.filter_margin = (int) gd.getNextNumber();
this.generate_mapped = gd.getNextBoolean();
this.extra_hor_tile = (int) gd.getNextNumber();
this.extra_vert_tile = (int) gd.getNextNumber();
this.sensor_mask = (int) gd.getNextNumber();
this.mode3d = (int) gd.getNextNumber();
this.show_mapped_color = gd.getNextBoolean();
this.show_mapped_mono = gd.getNextBoolean();
this.margin = (int) gd.getNextNumber();
this.sensor_mask_inter= (int) gd.getNextNumber();
this.use_partial = gd.getNextBoolean();
......@@ -300,12 +450,49 @@ public class IntersceneMatchParameters {
properties.setProperty(prefix+"show_images", this.show_images + ""); // boolean
properties.setProperty(prefix+"show_images_bgfg", this.show_images_bgfg + ""); // boolean
properties.setProperty(prefix+"show_images_mono", this.show_images_mono + ""); // boolean
properties.setProperty(prefix+"show_color_nan", this.show_color_nan + ""); // boolean
properties.setProperty(prefix+"show_mono_nan", this.show_mono_nan + ""); // boolean
properties.setProperty(prefix+"show_color_nan", this.show_color_nan + ""); // boolean
properties.setProperty(prefix+"show_mono_nan", this.show_mono_nan + ""); // boolean
properties.setProperty(prefix+"show_ranges", this.show_ranges + ""); // boolean
properties.setProperty(prefix+"range_disparity_offset",this.range_disparity_offset+""); // double
properties.setProperty(prefix+"range_min_strength", this.range_min_strength+""); // double
properties.setProperty(prefix+"range_max", this.range_max+""); // double
properties.setProperty(prefix+"num_bottom", this.num_bottom+""); // int
properties.setProperty(prefix+"num_passes", this.num_passes+""); // int
properties.setProperty(prefix+"max_change", this.max_change+""); // double
properties.setProperty(prefix+"min_disparity", this.min_disparity+""); // double
properties.setProperty(prefix+"max_sym_disparity", this.max_sym_disparity+""); // double
properties.setProperty(prefix+"min_strength_replace", this.min_strength_replace+""); // double
properties.setProperty(prefix+"min_strength_blur", this.min_strength_blur+""); // double
properties.setProperty(prefix+"sigma", this.sigma+""); // double
properties.setProperty(prefix+"num_blur", this.num_blur+""); // int
properties.setProperty(prefix+"disparity_corr", this.disparity_corr+""); // double
properties.setProperty(prefix+"outliers_nth_fromextrem", this.outliers_nth_fromextrem+""); // int
properties.setProperty(prefix+"outliers_tolerance_absolute", this.outliers_tolerance_absolute+""); // double
properties.setProperty(prefix+"outliers_tolerance_relative", this.outliers_tolerance_relative+""); // double
properties.setProperty(prefix+"outliers_max_iter", this.outliers_max_iter+""); // int
properties.setProperty(prefix+"outliers_max_strength2", this.outliers_max_strength2+""); // double
properties.setProperty(prefix+"outliers_nth_fromextrem2", this.outliers_nth_fromextrem2+""); // int
properties.setProperty(prefix+"outliers_tolerance_absolute2", this.outliers_tolerance_absolute2+""); // double
properties.setProperty(prefix+"outliers_tolerance_relative2", this.outliers_tolerance_relative2+""); // double
properties.setProperty(prefix+"outliers_lma_max_strength", this.outliers_lma_max_strength+""); // double
properties.setProperty(prefix+"outliers_max_strength", this.outliers_max_strength+""); // double
properties.setProperty(prefix+"outliers_from_lma_max_strength",this.outliers_from_lma_max_strength+"");// double
properties.setProperty(prefix+"search_radius", this.search_radius+""); // int
properties.setProperty(prefix+"remove_no_lma_neib", this.remove_no_lma_neib+""); // boolean
properties.setProperty(prefix+"diff_from_lma_pos", this.diff_from_lma_pos+""); // double
properties.setProperty(prefix+"diff_from_lma_neg", this.diff_from_lma_neg+""); // double
properties.setProperty(prefix+"outliers_lma_nth_fromextrem", this.outliers_lma_nth_fromextrem+""); // int
properties.setProperty(prefix+"filter_margin", this.filter_margin+""); // int
properties.setProperty(prefix+"generate_mapped", this.generate_mapped+""); // boolean
properties.setProperty(prefix+"extra_hor_tile", this.extra_hor_tile+""); // int
properties.setProperty(prefix+"extra_vert_tile", this.extra_vert_tile+""); // int
properties.setProperty(prefix+"sensor_mask", this.sensor_mask+""); // int
properties.setProperty(prefix+"mode3d", this.mode3d+""); // int
properties.setProperty(prefix+"show_mapped_color", this.show_mapped_color+""); // boolean
properties.setProperty(prefix+"show_mapped_mono", this.show_mapped_mono+""); // boolean
properties.setProperty(prefix+"margin", this.margin+""); // int
properties.setProperty(prefix+"sensor_mask_inter", this.sensor_mask_inter+""); // int
properties.setProperty(prefix+"use_partial", this.use_partial+""); // boolean
......@@ -363,6 +550,42 @@ public class IntersceneMatchParameters {
if (properties.getProperty(prefix+"range_disparity_offset")!=null) this.range_disparity_offset=Double.parseDouble(properties.getProperty(prefix+"range_disparity_offset"));
if (properties.getProperty(prefix+"range_min_strength")!=null) this.range_min_strength=Double.parseDouble(properties.getProperty(prefix+"range_min_strength"));
if (properties.getProperty(prefix+"range_max")!=null) this.range_max=Double.parseDouble(properties.getProperty(prefix+"range_max"));
if (properties.getProperty(prefix+"num_bottom")!=null) this.num_bottom=Integer.parseInt(properties.getProperty(prefix+"num_bottom"));
if (properties.getProperty(prefix+"num_passes")!=null) this.num_passes=Integer.parseInt(properties.getProperty(prefix+"num_passes"));
if (properties.getProperty(prefix+"max_change")!=null) this.max_change=Double.parseDouble(properties.getProperty(prefix+"max_change"));
if (properties.getProperty(prefix+"min_disparity")!=null) this.min_disparity=Double.parseDouble(properties.getProperty(prefix+"min_disparity"));
if (properties.getProperty(prefix+"max_sym_disparity")!=null) this.max_sym_disparity=Double.parseDouble(properties.getProperty(prefix+"max_sym_disparity"));
if (properties.getProperty(prefix+"min_strength_replace")!=null) this.min_strength_replace=Double.parseDouble(properties.getProperty(prefix+"min_strength_replace"));
if (properties.getProperty(prefix+"min_strength_blur")!=null) this.min_strength_blur=Double.parseDouble(properties.getProperty(prefix+"min_strength_blur"));
if (properties.getProperty(prefix+"sigma")!=null) this.sigma=Double.parseDouble(properties.getProperty(prefix+"sigma"));
if (properties.getProperty(prefix+"num_blur")!=null) this.num_blur=Integer.parseInt(properties.getProperty(prefix+"num_blur"));
if (properties.getProperty(prefix+"disparity_corr")!=null) this.disparity_corr=Double.parseDouble(properties.getProperty(prefix+"disparity_corr"));
if (properties.getProperty(prefix+"outliers_nth_fromextrem")!=null) this.outliers_nth_fromextrem=Integer.parseInt(properties.getProperty(prefix+"outliers_nth_fromextrem"));
if (properties.getProperty(prefix+"outliers_tolerance_absolute")!=null) this.outliers_tolerance_absolute=Double.parseDouble(properties.getProperty(prefix+"outliers_tolerance_absolute"));
if (properties.getProperty(prefix+"outliers_tolerance_relative")!=null) this.outliers_tolerance_relative=Double.parseDouble(properties.getProperty(prefix+"outliers_tolerance_relative"));
if (properties.getProperty(prefix+"outliers_max_iter")!=null) this.outliers_max_iter=Integer.parseInt(properties.getProperty(prefix+"outliers_max_iter"));
if (properties.getProperty(prefix+"outliers_max_strength2")!=null) this.outliers_max_strength2=Double.parseDouble(properties.getProperty(prefix+"outliers_max_strength2"));
if (properties.getProperty(prefix+"outliers_nth_fromextrem2")!=null) this.outliers_nth_fromextrem2=Integer.parseInt(properties.getProperty(prefix+"outliers_nth_fromextrem2"));
if (properties.getProperty(prefix+"outliers_tolerance_absolute2")!=null) this.outliers_tolerance_absolute2=Double.parseDouble(properties.getProperty(prefix+"outliers_tolerance_absolute2"));
if (properties.getProperty(prefix+"outliers_tolerance_relative2")!=null) this.outliers_tolerance_relative2=Double.parseDouble(properties.getProperty(prefix+"outliers_tolerance_relative2"));
if (properties.getProperty(prefix+"outliers_lma_max_strength")!=null) this.outliers_lma_max_strength=Double.parseDouble(properties.getProperty(prefix+"outliers_lma_max_strength"));
if (properties.getProperty(prefix+"outliers_max_strength")!=null) this.outliers_max_strength=Double.parseDouble(properties.getProperty(prefix+"outliers_max_strength"));
if (properties.getProperty(prefix+"outliers_from_lma_max_strength")!=null)this.outliers_from_lma_max_strength=Double.parseDouble(properties.getProperty(prefix+"outliers_from_lma_max_strength"));
if (properties.getProperty(prefix+"search_radius")!=null) this.search_radius=Integer.parseInt(properties.getProperty(prefix+"search_radius"));
if (properties.getProperty(prefix+"remove_no_lma_neib")!=null) this.remove_no_lma_neib=Boolean.parseBoolean(properties.getProperty(prefix+"remove_no_lma_neib"));
if (properties.getProperty(prefix+"diff_from_lma_pos")!=null) this.diff_from_lma_pos=Double.parseDouble(properties.getProperty(prefix+"diff_from_lma_pos"));
if (properties.getProperty(prefix+"diff_from_lma_neg")!=null) this.diff_from_lma_neg=Double.parseDouble(properties.getProperty(prefix+"diff_from_lma_neg"));
if (properties.getProperty(prefix+"outliers_lma_nth_fromextrem")!=null) this.outliers_lma_nth_fromextrem=Integer.parseInt(properties.getProperty(prefix+"outliers_lma_nth_fromextrem"));
if (properties.getProperty(prefix+"filter_margin")!=null) this.filter_margin=Integer.parseInt(properties.getProperty(prefix+"filter_margin"));
if (properties.getProperty(prefix+"generate_mapped")!=null) this.generate_mapped=Boolean.parseBoolean(properties.getProperty(prefix+"generate_mapped"));
if (properties.getProperty(prefix+"extra_hor_tile")!=null) this.extra_hor_tile=Integer.parseInt(properties.getProperty(prefix+"extra_hor_tile"));
if (properties.getProperty(prefix+"extra_vert_tile")!=null) this.extra_vert_tile=Integer.parseInt(properties.getProperty(prefix+"extra_vert_tile"));
if (properties.getProperty(prefix+"sensor_mask")!=null) this.sensor_mask=Integer.parseInt(properties.getProperty(prefix+"sensor_mask"));
if (properties.getProperty(prefix+"mode3d")!=null) this.mode3d=Integer.parseInt(properties.getProperty(prefix+"mode3d"));
if (properties.getProperty(prefix+"show_mapped_color")!=null) this.show_mapped_color=Boolean.parseBoolean(properties.getProperty(prefix+"show_mapped_color"));
if (properties.getProperty(prefix+"show_mapped_mono")!=null) this.show_mapped_mono=Boolean.parseBoolean(properties.getProperty(prefix+"show_mapped_mono"));
if (properties.getProperty(prefix+"margin")!=null) this.margin=Integer.parseInt(properties.getProperty(prefix+"margin"));
if (properties.getProperty(prefix+"sensor_mask_inter")!=null) this.sensor_mask_inter=Integer.parseInt(properties.getProperty(prefix+"sensor_mask_inter"));
if (properties.getProperty(prefix+"use_partial")!=null) this.use_partial=Boolean.parseBoolean(properties.getProperty(prefix+"use_partial"));
......@@ -419,9 +642,46 @@ public class IntersceneMatchParameters {
imp.show_color_nan = this.show_color_nan;
imp.show_mono_nan = this.show_mono_nan;
imp.show_ranges = this.show_ranges;
imp.range_disparity_offset = this.range_disparity_offset;
imp.range_disparity_offset= this.range_disparity_offset;
imp.range_min_strength = this.range_min_strength;
imp.range_max = this.range_max;
imp.num_bottom = this.num_bottom;
imp.num_passes = this.num_passes;
imp.max_change = this.max_change;
imp.min_disparity = this.min_disparity;
imp.max_sym_disparity = this.max_sym_disparity;
imp.min_strength_replace = this.min_strength_replace;
imp.min_strength_blur = this.min_strength_blur;
imp.sigma = this.sigma;
imp.num_blur = this.num_blur;
imp.disparity_corr = this.disparity_corr;
imp.outliers_nth_fromextrem = this.outliers_nth_fromextrem;
imp.outliers_tolerance_absolute = this.outliers_tolerance_absolute;
imp.outliers_tolerance_relative = this.outliers_tolerance_relative;
imp.outliers_max_iter = this.outliers_max_iter;
imp.outliers_max_strength2 = this.outliers_max_strength2;
imp.outliers_nth_fromextrem2 = this.outliers_nth_fromextrem2;
imp.outliers_tolerance_absolute2 = this.outliers_tolerance_absolute2;
imp.outliers_tolerance_relative2 = this.outliers_tolerance_relative2;
imp.outliers_lma_max_strength = this.outliers_lma_max_strength;
imp.outliers_max_strength = this.outliers_max_strength;
imp.outliers_from_lma_max_strength= this.outliers_from_lma_max_strength;
imp.search_radius = this.search_radius;
imp.remove_no_lma_neib = this.remove_no_lma_neib;
imp.diff_from_lma_pos = this.diff_from_lma_pos;
imp.diff_from_lma_neg = this.diff_from_lma_neg;
imp.outliers_lma_nth_fromextrem = this.outliers_lma_nth_fromextrem;
imp.filter_margin = this.filter_margin;
imp.generate_mapped = this.generate_mapped;
imp.extra_hor_tile = this.extra_hor_tile;
imp.extra_vert_tile = this.extra_vert_tile;
imp.sensor_mask = this.sensor_mask;
imp.mode3d = this.mode3d;
imp.show_mapped_color = this.show_mapped_color;
imp.show_mapped_mono = this.show_mapped_mono;
imp.margin = this.margin;
imp.sensor_mask_inter = this.sensor_mask_inter;
imp.use_partial = this.use_partial;
......
......@@ -2493,6 +2493,7 @@ public class OpticalFlow {
scene_ers_atr_dt); // double [] ers_atr_dt)(ers_scene_original_xyz_dt);
//setupERS() will be inside transformToScenePxPyD()
double [][] scene_pXpYD = transformToScenePxPyD( // will be null for disparity == NaN
null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null)
disparity_ref, // final double [] disparity_ref, // invalid tiles - NaN in disparity (maybe it should not be masked by margins?)
scene_xyz, // final double [] scene_xyz, // camera center in world coordinates
scene_atr, // final double [] scene_atr, // camera orientation relative to world frame
......@@ -2710,20 +2711,19 @@ public class OpticalFlow {
ImageDtt.startAndJoin(threads);
return world_xyz;
}
public double [][] transformToScenePxPyD(
final Rectangle full_woi_in, // show larger than sensor WOI (or null) IN TILES
final double [] disparity_ref, // invalid tiles - NaN in disparity
final double [] scene_xyz, // camera center in world coordinates
final double [] scene_atr, // camera orientation relative to world frame
final QuadCLT scene_QuadClt,
final QuadCLT reference_QuadClt) {
return transformToScenePxPyD(
null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null)
full_woi_in, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null)
disparity_ref, // invalid tiles - NaN in disparity
scene_xyz, // camera center in world coordinates
scene_atr, // camera orientation relative to world frame
scene_xyz, // camera center in world coordinates
scene_atr, // camera orientation relative to world frame
scene_QuadClt,
reference_QuadClt,
this.threadsMax);
......@@ -3963,8 +3963,8 @@ public class OpticalFlow {
boolean export_images = clt_parameters.imp.export_images;
boolean export_dsi_image = clt_parameters.imp.show_ranges;
boolean show_images = clt_parameters.imp.show_images;
boolean show_color_nan = clt_parameters.imp.show_color_nan;
boolean show_mono_nan = clt_parameters.imp.show_mono_nan;
// boolean show_color_nan = clt_parameters.imp.show_color_nan;
// boolean show_mono_nan = clt_parameters.imp.show_mono_nan;
boolean show_images_bgfg = clt_parameters.imp.show_images_bgfg;
boolean show_images_mono = clt_parameters.imp.show_images_mono;
......@@ -3973,6 +3973,15 @@ public class OpticalFlow {
double range_min_strength = clt_parameters.imp.range_min_strength ; // 0.5;
double range_max = clt_parameters.imp.range_max ; // 5000.0;
boolean generate_mapped = clt_parameters.imp.generate_mapped;
int extra_hor_tile = clt_parameters.imp.extra_hor_tile;
int extra_vert_tile = clt_parameters.imp.extra_vert_tile;
int sensor_mask = clt_parameters.imp.sensor_mask; // -1 - all
int mode3d = clt_parameters.imp.mode3d; // 0 - infinity, 1 - FG, 2 - BG
boolean show_mapped_color = clt_parameters.imp.show_mapped_color;
boolean show_mapped_mono = clt_parameters.imp.show_mapped_mono;
final int debugLevelInner=clt_parameters.batch_run? -2: debugLevel; // copied from TQ
......@@ -4221,29 +4230,124 @@ public class OpticalFlow {
debugLevel); // int debug_level
}
if (generate_mapped) {
if (!build_orientations && !build_interscene) {
for (int scene_index = ref_index - 1; scene_index >= 0 ; scene_index--) {
quadCLTs[scene_index] = (QuadCLT) quadCLT_main.spawnNoModelQuadCLT( // restores image data
set_channels[scene_index].set_name,
clt_parameters,
colorProcParameters, //
threadsMax,
debugLevel-2);
}
}
double [] selected_disparity = null;
int tilesX = quadCLTs[ref_index].getTileProcessor().getTilesX();
int tilesY = quadCLTs[ref_index].getTileProcessor().getTilesY();
if (mode3d == 0) {
selected_disparity = new double [tilesX * tilesY];
Arrays.fill(selected_disparity,clt_parameters.disparity);
} else {
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 [][] dls = {
combo_dsn_final[COMBO_DSN_INDX_DISP],
combo_dsn_final[COMBO_DSN_INDX_LMA],
combo_dsn_final[COMBO_DSN_INDX_STRENGTH]
};
double [][] ds = conditionInitialDS(
true, // boolean use_conf, // use configuration parameters, false - use following
clt_parameters, // CLTParameters clt_parameters,
dls, // double [][] dls
quadCLTs[ref_index], // QuadCLT scene,
debugLevel);
selected_disparity = ds[0]; // combo_dsn_final[COMBO_DSN_INDX_DISP_FG];
if (mode3d > 1) { // BG mode
double [] bg_lma = combo_dsn_final[COMBO_DSN_INDX_DISP_BG_ALL].clone();
double [] bg_str = combo_dsn_final[COMBO_DSN_INDX_STRENGTH].clone();
for (int i = 0; i < bg_lma.length; i++) {
if (Double.isNaN(combo_dsn_final[COMBO_DSN_INDX_LMA][i])){
bg_lma[i] = Double.NaN;
}
if (!Double.isNaN(combo_dsn_final[COMBO_DSN_INDX_DISP_BG][i])){
bg_lma[i] = combo_dsn_final[COMBO_DSN_INDX_LMA_BG][i];
}
if (!Double.isNaN(combo_dsn_final[COMBO_DSN_INDX_STRENGTH_BG][i])){
bg_str[i] = combo_dsn_final[COMBO_DSN_INDX_STRENGTH_BG][i];
}
}
double [][] dls_bg = {
combo_dsn_final[COMBO_DSN_INDX_DISP_BG_ALL],
bg_lma,
bg_str
};
double [][] ds_bg = conditionInitialDS(
false, // boolean use_conf, // use configuration parameters, false - use following
clt_parameters, // CLTParameters clt_parameters,
dls_bg, // double [][] dls
quadCLTs[ref_index], // QuadCLT scene,
debugLevel);
selected_disparity = ds_bg[0]; // combo_dsn_final[COMBO_DSN_INDX_DISP_FG];
}
}
// for now using disparity for just standard size (90x64), later may use full size and at
// minimum fill peripheral areas with Laplassian?
Rectangle fov_tiles = new Rectangle(
extra_hor_tile,
extra_vert_tile,
tilesX + 2 * extra_hor_tile,
tilesY + 2 * extra_vert_tile);
boolean toRGB = !show_mapped_mono; // false; // true;// ** TEMPORARILY **
String scenes_suffix = quadCLTs[quadCLTs.length-1].getImageName()+
"-SEQ-"; // MOD3D"+mode3d + "-"+(toRGB?"COLOR":"MONO");
if (mode3d < 0) scenes_suffix+="RAW";
else if (mode3d == 0) scenes_suffix+="INF";
else if (mode3d == 1) scenes_suffix+="FG";
else if (mode3d == 2) scenes_suffix+="BG";
scenes_suffix += "-"+(toRGB?"COLOR":"MONO");
ImagePlus imp_scenes = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
fov_tiles, // Rectangle fov_tiles,
mode3d, // int mode3d,
toRGB, // boolean toRGB,
sensor_mask, // int sensor_mask,
scenes_suffix, // String suffix,
selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
debugLevel); // int debugLevel);
quadCLTs[ref_index].saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_scenes); // ImagePlus imp)
if (show_mapped_color) {
imp_scenes.show();
/*
if (show_images_mono) {
imp_scenes.show();
}
*/
}
}
if (export_images) {
final boolean toRGB = true;
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);
}
// re-load
/*
quadCLTs[ref_index] = (QuadCLT) quadCLT_main.spawnQuadCLT( // restores dsi from "DSI-MAIN"
set_channels[ref_index].set_name,
clt_parameters,
colorProcParameters, //
threadsMax,
debugLevel);
*/
double [][] dls = {
combo_dsn_final[COMBO_DSN_INDX_DISP],
combo_dsn_final[COMBO_DSN_INDX_LMA],
combo_dsn_final[COMBO_DSN_INDX_STRENGTH]
};
double [][] ds = conditionInitialDS(
false, // boolean use_conf, // use configuration parameters, false - use following
clt_parameters, // CLTParameters clt_parameters,
dls, // double [][] dls
quadCLTs[ref_index], // QuadCLT scene,
......@@ -4271,6 +4375,7 @@ public class OpticalFlow {
bg_str
};
double [][] ds_bg = conditionInitialDS(
false, // boolean use_conf, // use configuration parameters, false - use following
clt_parameters, // CLTParameters clt_parameters,
dls_bg, // double [][] dls
quadCLTs[ref_index], // QuadCLT scene,
......@@ -4399,23 +4504,13 @@ public class OpticalFlow {
null); // int [] wh);
}
// re-load , should create quadCLTs[ref_index].dsi
/*
quadCLTs[ref_index] = (QuadCLT) quadCLT_main.spawnQuadCLT( // restores dsi from "DSI-MAIN"
set_channels[ref_index].set_name,
clt_parameters,
colorProcParameters, //
threadsMax,
debugLevel);
*/
// TODO:********************
// double [] disparity = combo_dsn_final[COMBO_DSN_INDX_DISP].clone();
// double [] strength = combo_dsn_final[COMBO_DSN_INDX_STRENGTH];
double [][] dls = {
combo_dsn_final[COMBO_DSN_INDX_DISP],
combo_dsn_final[COMBO_DSN_INDX_LMA],
combo_dsn_final[COMBO_DSN_INDX_STRENGTH]
};
double [][] ds = conditionInitialDS(
false, // boolean use_conf, // use configuration parameters, false - use following
clt_parameters, // CLTParameters clt_parameters,
dls, // double [][] dls
quadCLTs[ref_index], // QuadCLT scene,
......@@ -4448,6 +4543,74 @@ public class OpticalFlow {
return true;
}
public ImagePlus renderSceneSequence(
CLTParameters clt_parameters,
Rectangle fov_tiles,
int mode3d,
boolean toRGB,
int sensor_mask,
String suffix,
double [] ref_disparity,
QuadCLT [] quadCLTs,
int debugLevel) {
// int mode3d=-1;
int ref_index = quadCLTs.length -1;
int num_sens = quadCLTs[ref_index].getNumSensors();
ErsCorrection ers_reference = quadCLTs[ref_index].getErsCorrection();
int num_used_sens = 0;
for (int i = 0; i < num_sens; i++) if (((sensor_mask >> i) & 1) != 0) num_used_sens++;
int [] channels = new int [num_used_sens];
int nch = 0;
for (int i = 0; i < num_sens; i++) if (((sensor_mask >> i) & 1) != 0) channels[nch++] = i;
ImageStack stack_scenes = null;
int dbg_scene = 95;
for (int nscene = 0; nscene < quadCLTs.length ; nscene++) if (quadCLTs[nscene] != null){
if (nscene== dbg_scene) {
System.out.println("renderSceneSequence(): nscene = "+nscene);
}
String ts = quadCLTs[nscene].getImageName();
double [] scene_xyz = ZERO3;
double [] scene_atr = ZERO3;
if ((nscene != ref_index) && (mode3d >= 0)) {
scene_xyz = ers_reference.getSceneXYZ(ts);
scene_atr = ers_reference.getSceneATR(ts);
double [] scene_ers_xyz_dt = ers_reference.getSceneErsXYZ_dt(ts);
double [] scene_ers_atr_dt = ers_reference.getSceneErsATR_dt(ts);
quadCLTs[nscene].getErsCorrection().setErsDt(
scene_ers_xyz_dt, // double [] ers_xyz_dt,
scene_ers_atr_dt); // double [] ers_atr_dt)(ers_scene_original_xyz_dt);
}
ImagePlus imp_scene = QuadCLT.renderGPUFromDSI(
sensor_mask, // final int sensor_mask,
fov_tiles, // testr, // null, // final Rectangle full_woi_in, // show larger than sensor WOI (or null)
clt_parameters, // CLTParameters clt_parameters,
ref_disparity, // double [] disparity_ref,
scene_xyz, // final double [] scene_xyz, // camera center in world coordinates
scene_atr, // final double [] scene_atr, // camera orientation relative to world frame
quadCLTs[nscene], // final QuadCLT scene,
toRGB, // final boolean toRGB,
// "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
"", // String suffix, no suffix here
threadsMax, // int threadsMax,
debugLevel); // int debugLevel)
if (stack_scenes == null) {
stack_scenes = new ImageStack(imp_scene.getWidth(),imp_scene.getHeight());
}
for (int i = 0; i < channels.length; i++) {
stack_scenes.addSlice(
ts+"-"+channels[i],
imp_scene.getStack().getPixels(i+1));
}
}
// ImagePlus imp_scenes = new ImagePlus(image_name+sAux()+suffix, stack_scenes);
ImagePlus imp_scenes = new ImagePlus(suffix, stack_scenes);
imp_scenes.getProcessor().resetMinAndMax();
return imp_scenes;
}
public double [][] getSceneSZXY(
QuadCLT scene,
double disparity_offset,
......@@ -7295,6 +7458,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
if (nscene == indx_ref) {
// transform to self - maybe use a method that sets central points
scene_pXpYD = transformToScenePxPyD(
null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null)
disparity_ref, // 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_atr, // camera orientation relative to world frame
......@@ -7311,6 +7475,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
scene_ers_atr_dt); // double [] ers_atr_dt)(ers_scene_original_xyz_dt);
//setupERS() will be inside transformToScenePxPyD()
scene_pXpYD = transformToScenePxPyD( // will be null for disparity == NaN
null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null)
disparity_ref, // final double [] disparity_ref, // invalid tiles - NaN in disparity (maybe it should not be masked by margins?)
scene_xyz, // final double [] scene_xyz, // camera center in world coordinates
scene_atr, // final double [] scene_atr, // camera orientation relative to world frame
......@@ -8215,6 +8380,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
if (nscene == indx_ref) {
// transform to self - maybe use a method that sets central points
scene_pXpYD = transformToScenePxPyD(
null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null)
disparity_ref, // 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_atr, // camera orientation relative to world frame
......@@ -8231,6 +8397,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
scene_ers_atr_dt); // double [] ers_atr_dt)(ers_scene_original_xyz_dt);
//setupERS() will be inside transformToScenePxPyD()
double [][] scene_pXpYD_prefilter = transformToScenePxPyD( // will be null for disparity == NaN, total size - tilesX*tilesY
null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null)
disparity_ref, // final double [] disparity_ref, // invalid tiles - NaN in disparity (maybe it should not be masked by margins?)
scene_xyz, // final double [] scene_xyz, // camera center in world coordinates
scene_atr, // final double [] scene_atr, // camera orientation relative to world frame
......@@ -8646,6 +8813,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
double [][] scene_pXpYD;
// transform to self - maybe use a method that sets central points
scene_pXpYD = transformToScenePxPyD(
null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null)
disparity_ref, // 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_atr, // camera orientation relative to world frame
......@@ -9530,6 +9698,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
return null;
}
return conditionInitialDS(
false, // boolean use_conf, // use configuration parameters, false - use following
clt_parameters,
dls,
scene,
......@@ -9537,64 +9706,154 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
}
private double [][] conditionInitialDS(
boolean use_conf, // use configuration parameters, false - use following
CLTParameters clt_parameters,
double [][] dls,
QuadCLT scene,
int debug_level)
{
int num_bottom = 6; // average this number of lowest disparity neighbors (of 8)
int num_passes = 100;
double max_change = 1.0e-3;
double min_disparity = -0.2;
double max_sym_disparity = 0.2;
double min_strength_replace = 0.05; /// 0.14; /// Before /// - LWIR, after - RGB
double min_strength_blur = 0.06; /// 0.2;
double sigma = 2; /// 5;
int num_blur = 1; // 3;
double disparity_corr = 0.0;
int outliers_nth_fromextrem = 1; // second from min/max - removes dual-tile max/mins
double outliers_tolerance_absolute = 0.2;
double outliers_tolerance_relative = 0.02;
int outliers_max_iter = 100;
double outliers_max_strength2 = 1.0; // 0.5; any
int outliers_nth_fromextrem2 = 0; // second from min/max - removes dual-tile max/mins
double outliers_tolerance_absolute2 = 0.5;
double outliers_tolerance_relative2 = 0.1;
double outliers_lma_max_strength = 0.5;
double outliers_max_strength = 0.1; /// 0.25;
double outliers_from_lma_max_strength = 0.8;
int search_radius = 1; // Search farther if no LMA neighbor is found closer. Original value - 1 (8 neighbors)
boolean remove_no_lma_neib = false;
double diff_from_lma_pos = 100.0;
double diff_from_lma_neg = 2.0;
int outliers_lma_nth_fromextrem = 1;
int margin = 8; // pixels
if (use_conf) {
num_bottom = clt_parameters.imp.num_bottom;
num_passes = clt_parameters.imp.num_passes;
max_change = clt_parameters.imp.max_change;
min_disparity = clt_parameters.imp.min_disparity;
max_sym_disparity = clt_parameters.imp.max_sym_disparity;
min_strength_replace = clt_parameters.imp.min_strength_replace;
min_strength_blur = clt_parameters.imp.min_strength_blur;
sigma = clt_parameters.imp.sigma;
num_blur = clt_parameters.imp.num_blur;
disparity_corr = clt_parameters.imp.disparity_corr;
outliers_nth_fromextrem = clt_parameters.imp.outliers_nth_fromextrem;
outliers_tolerance_absolute = clt_parameters.imp.outliers_tolerance_absolute;
outliers_tolerance_relative = clt_parameters.imp.outliers_tolerance_relative;
outliers_max_iter = clt_parameters.imp.outliers_max_iter;
outliers_max_strength2 = clt_parameters.imp.outliers_max_strength2;
outliers_nth_fromextrem2 = clt_parameters.imp.outliers_nth_fromextrem2;
outliers_tolerance_absolute2 = clt_parameters.imp.outliers_tolerance_absolute2;
outliers_tolerance_relative2 = clt_parameters.imp.outliers_tolerance_relative2;
outliers_lma_max_strength = clt_parameters.imp.outliers_lma_max_strength;
outliers_max_strength = clt_parameters.imp.outliers_max_strength;
outliers_from_lma_max_strength= clt_parameters.imp.outliers_from_lma_max_strength;
search_radius = clt_parameters.imp.search_radius;
remove_no_lma_neib = clt_parameters.imp.remove_no_lma_neib;
diff_from_lma_pos = clt_parameters.imp.diff_from_lma_pos;
diff_from_lma_neg = clt_parameters.imp.diff_from_lma_neg;
outliers_lma_nth_fromextrem = clt_parameters.imp.outliers_lma_nth_fromextrem;
margin = clt_parameters.imp.filter_margin;
}
return conditionInitialDS(
clt_parameters, // CLTParameters clt_parameters,
dls, // double [][] dls,
scene, // QuadCLT scene,
debug_level, // int debug_level,
num_bottom, // final int num_bottom,
num_passes, // final int num_passes,
max_change, // final double max_change,
min_disparity, // final double min_disparity,
max_sym_disparity, // final double max_sym_disparity,
min_strength_replace, // final double min_strength_replace,
min_strength_blur, // final double min_strength_blur,
sigma, // final double sigma,
num_blur, // final int num_blur,
disparity_corr, // final double disparity_corr,
outliers_nth_fromextrem, // final int outliers_nth_fromextrem,
outliers_tolerance_absolute, // final double outliers_tolerance_absolute,
outliers_tolerance_relative, // final double outliers_tolerance_relative,
outliers_max_iter, // final int outliers_max_iter,
outliers_max_strength2, // final double outliers_max_strength2,
outliers_nth_fromextrem2, // final int outliers_nth_fromextrem2,
outliers_tolerance_absolute2, // final double outliers_tolerance_absolute2,
outliers_tolerance_relative2, // final double outliers_tolerance_relative2,
outliers_lma_max_strength, // final double outliers_lma_max_strength,
outliers_max_strength, // final double outliers_max_strength,
outliers_from_lma_max_strength, // final double outliers_from_lma_max_strength,
search_radius, // final int search_radius, // Search farther if no LMA neighbor is found closer. Original value - 1 (8 neighbors)
remove_no_lma_neib, // final boolean remove_no_lma_neib, // remove without LMA neighbors
diff_from_lma_pos, // final double diff_from_lma_pos,
diff_from_lma_neg, // final double diff_from_lma_neg,
outliers_lma_nth_fromextrem, // final int outliers_lma_nth_fromextrem,
margin); // final int margin)
}
private double [][] conditionInitialDS(
CLTParameters clt_parameters,
double [][] dls,
QuadCLT scene,
int debug_level,
final int num_bottom,
final int num_passes,
final double max_change,
final double min_disparity,
final double max_sym_disparity,
final double min_strength_replace,
final double min_strength_blur,
final double sigma,
final int num_blur,
final double disparity_corr,
final int outliers_nth_fromextrem,
final double outliers_tolerance_absolute,
final double outliers_tolerance_relative,
final int outliers_max_iter,
final double outliers_max_strength2,
final int outliers_nth_fromextrem2,
final double outliers_tolerance_absolute2,
final double outliers_tolerance_relative2,
final double outliers_lma_max_strength,
final double outliers_max_strength,
final double outliers_from_lma_max_strength,
final int search_radius, // Search farther if no LMA neighbor is found closer. Original value - 1 (8 neighbors)
final boolean remove_no_lma_neib, // remove without LMA neighbors
final double diff_from_lma_pos,
final double diff_from_lma_neg,
final int outliers_lma_nth_fromextrem,
final int margin)
{
final int tilesX = scene.getTileProcessor().getTilesX();
final int tilesY = scene.getTileProcessor().getTilesY();
final int transform_size = scene.getTileProcessor().getTileSize();
final int tiles =tilesX * tilesY;
final int num_bottom = 6; // average this number of lowest disparity neighbors (of 8)
final int num_passes = 100;
final double max_change = 1e-3;
final double min_disparity = -.2;
final double max_sym_disparity = .2;
final double min_strength_replace = 0.05; /// 0.14; /// Before /// - LWIR, after - RGB
final double min_strength_blur = 0.06; /// 0.2;
final double sigma = 2; /// 5;
final int num_blur = 1; // 3;
final double disparity_corr = 0.00;
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_relative = .02;
final int outliers_max_iter = 100;
final double outliers_max_strength2 = 1.0; // 0.5; any
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_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.8;
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 = 8; // pixels
// double [][] dsrbg = scene.getDSRBG();
// if (dsrbg == null) {
// return null;
// }
/*
double [][] dls = scene.getDLS();
if (dls == 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(
double [] disp_outliers = QuadCLT.removeDisparityLMAOutliers( // nothing removed
false, // final boolean non_ma,
dls, //final double [][] dls,
outliers_lma_max_strength, // final double max_strength, // do not touch stronger
......@@ -9606,18 +9865,19 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
threadsMax, // final int threadsMax,
debug_level); // final int debug_level)
dbg_img[3] = disp_outliers.clone();
disp_outliers = QuadCLT.removeDisparityOutliersByLMA(
disp_outliers = QuadCLT.removeDisparityOutliersByLMA( // removed sky edge near strong objects
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
search_radius, // int search_radius, // Search farther if no LMA neighbor is found closer. Original value - 1 (8
remove_no_lma_neib, // 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
disp_outliers = QuadCLT.removeDisparityLMAOutliers( // filter non-lma tiles
disp_outliers = QuadCLT.removeDisparityLMAOutliers( // filter non-lma tiles // removed too few !!!
true, // final boolean non_ma,
new double[][] {disp_outliers, dls[1], dls[2]}, //final double [][] dls,
outliers_lma_max_strength, // final double max_strength, // do not touch stronger
......@@ -9869,6 +10129,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
// double [][] dsrbg_ref= ref_scene.getDSRBG();
double [][] dls= ref_scene.getDLS();
double [][] ref_pXpYD = transformToScenePxPyD( // full size - [tilesX*tilesY], some nulls
null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null)
dls[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_atr, // camera orientation relative to world frame
......@@ -9897,6 +10158,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
//setupERS() will be inside transformToScenePxPyD()
*/
double [][] scene_pXpYD = transformToScenePxPyD( // will be null for disparity == NaN, total size - tilesX*tilesY
null, // final Rectangle [] extra_woi, // show larger than sensor WOI (or null)
dls[0], // final double [] disparity_ref, // invalid tiles - NaN in disparity (maybe it should not be masked by margins?)
scene_xyz, // final double [] scene_xyz, // camera center in world coordinates
scene_atr, // final double [] scene_atr, // camera orientation relative to world frame
......
......@@ -221,9 +221,10 @@ public class QuadCLT extends QuadCLTCPU {
*/
public static double [] removeDisparityOutliersByLMA(
final double [][] dls,
final double max_strength, // do not touch stronger
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 int search_radius, // Search farther if no LMA neighbor is found closer. Original value - 1 (8 neighbors)
final boolean remove_no_lma_neib, // remove without LMA neighbors
final int width, //tilesX
final int threadsMax,
......@@ -238,7 +239,7 @@ public class QuadCLT extends QuadCLTCPU {
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger anum_updated = new AtomicInteger(0);
final int dbg_tile = 1235;
final int dbg_tile = 1944;
anum_updated.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
......@@ -250,22 +251,28 @@ public class QuadCLT extends QuadCLTCPU {
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;
for (int rad = 1; rad <= search_radius; rad++) {
int numdir = TileNeibs.getNumDirs(rad);
for (int dir = 0; dir < numdir; dir++) {
int ineib = tn.getNeibIndexRadius(nTile, dir, rad);
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 (!(Double.isNaN(best_fit_pos) && Double.isNaN(best_fit_neg))) {
break;
}
}
if ( (best_fit_neg > diff_from_lma_neg) ||
(best_fit_pos > diff_from_lma_pos) ||
......@@ -2064,7 +2071,7 @@ public class QuadCLT extends QuadCLTCPU {
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
-1, // 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
......
......@@ -140,6 +140,70 @@ public class TileNeibs{
default: return indx;
}
}
public static int getNumDirs(int radius) {
if (radius < 0) {
return 0;
} else if (radius == 0) {
return 1;
} else {
return 8 * radius;
}
}
/**
* Get 2d element index after step of variable radius:
* radius==1 - same as getNeibIndex(int indx, int dir), 8 directions
* radius==2 - 16 directions (5x5 square), 0 - still up, north
* radius==3 - 24 directions (7x7 square)
* ...
* @param indx start index
* @param dir step direction (CW from up)
* @param radius - "distance" from the start point
* @return new index or -1 if leaving array in any direction
*/
public int getNeibIndexRadius(int indx, int dir, int radius) {
if (radius < 2) {
return getNeibIndex(indx, dir);
}
int y = indx / sizeX;
int x = indx % sizeX;
if (dir > (8 * radius)) {
System.out.println("getNeibIndex(): indx="+indx+", dir="+dir+", radius="+radius);
}
int dr = (dir + radius) % (8 * radius);
int quad = dr / (2 * radius);
int side = dr % (2 * radius);
switch (quad) {
case 0:
x = x - radius + side;
y = y - radius;
break;
case 1:
x = x + radius;
y = y - radius + side;
break;
case 2:
x = x + radius - side;
y = y + radius;
break;
case 3:
x = x - radius;
y = y + radius - side;
break;
}
if ((x >= 0) && (y >= 0) && (x < sizeX) && (y < sizeY)) {
return x + sizeX*y;
} else {
return -1;
}
}
/**
* Get 2d element index after step N, NE, ... NW. Returns -1 if leaving array
* And 2 steps for dir = 8(N), 9(NNE),..23(NNW)
......
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