Commit d87183b6 authored by Andrey Filippov's avatar Andrey Filippov

tested model generation (w/o field calibration with gpu tile processor)

parent e608c208
......@@ -6264,8 +6264,6 @@ private Panel panel1,
public boolean batchLwir() {
long startTime=System.nanoTime();
// load needed sensor and kernels files
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
......
......@@ -918,9 +918,15 @@ public class GPUTileProcessor {
* Copy array of CPU-prepared tasks to the GPU memory
* @param tile_tasks array of TpTask prepared by the CPU (before geometry correction is applied)
* @param use_aux Use second (aux) camera
* @param verify correct data
*/
public void setTasks(TpTask [] tile_tasks, boolean use_aux) // while is it in class member? - just to be able to free
public void setTasks(
TpTask [] tile_tasks,
boolean use_aux, // while is it in class member? - just to be able to free
boolean verify
)
{
if (verify) checkTasks(tile_tasks);
num_task_tiles = tile_tasks.length;
float [] ftasks = new float [TPTASK_SIZE * num_task_tiles];
for (int i = 0; i < num_task_tiles; i++) {
......@@ -929,6 +935,40 @@ public class GPUTileProcessor {
cuMemcpyHtoD(gpu_tasks, Pointer.to(ftasks), TPTASK_SIZE * num_task_tiles * Sizeof.FLOAT);
}
void checkTasks (TpTask [] tile_tasks) {
float min_disp = tile_tasks[0].target_disparity;
float max_disp = min_disp;
int min_ty = tile_tasks[0].ty;
int min_tx = tile_tasks[0].tx;
int max_ty = min_ty;
int max_tx = min_tx;
int max_task = 0;
for (int i = 0; i < tile_tasks.length; i++) {
if (Float.isNaN(tile_tasks[i].target_disparity)) {
System.out.println(String.format("Disparity=NaN for tY=%d, tX=%d, task = 0x%x", tile_tasks[i].ty, tile_tasks[i].tx, tile_tasks[i].task));
System.out.println("Setting disparity and tas to 0");
tile_tasks[i].target_disparity = 0f;
tile_tasks[i].task = 0;
}
if (tile_tasks[i].task != 0) {
if (tile_tasks[i].target_disparity < min_disp ) min_disp = tile_tasks[i].target_disparity;
if (tile_tasks[i].target_disparity > max_disp ) max_disp = tile_tasks[i].target_disparity;
if (tile_tasks[i].task > max_task ) max_task = tile_tasks[i].task;
if (tile_tasks[i].ty < min_ty ) min_ty = tile_tasks[i].ty;
if (tile_tasks[i].ty > max_ty ) max_ty = tile_tasks[i].ty;
if (tile_tasks[i].tx < min_tx ) min_tx = tile_tasks[i].tx;
if (tile_tasks[i].tx > max_tx ) max_tx = tile_tasks[i].tx;
}
}
System.out.println(String.format("---Disparity=[%f..%f] task=[0..0x%x] ty=[%d..%d] tx=[%d..%d] ---",
min_disp,max_disp, max_task, min_ty, max_ty, min_tx, max_tx));
}
public TpTask [] getTasks (boolean use_aux)
{
float [] ftasks = new float [TPTASK_SIZE * num_task_tiles];
......@@ -1926,6 +1966,7 @@ public class GPUTileProcessor {
boolean calc_textures,
boolean calc_extra)
{
execCalcReverseDistortions(); // will check if it is needed first
if (GPU_TEXTURES_kernel == null)
{
IJ.showMessage("Error", "No GPU kernel: GPU_TEXTURES_kernel");
......@@ -2204,8 +2245,9 @@ public class GPUTileProcessor {
return textures;
}
public double [][][][] doubleTextures(
Rectangle woi,
public double [][][][] doubleTextures( // may be accelerated with multithreading if needed.
Rectangle woi, // null or width and height match texture_tiles
double [][][][] texture_tiles, // null or [tilesY][tilesX]
int [] indices,
float [] ftextures,
int full_width,
......@@ -2214,22 +2256,34 @@ public class GPUTileProcessor {
){
int texture_slice_size = (2 * DTT_SIZE)* (2 * DTT_SIZE);
int texture_tile_size = texture_slice_size * num_src_slices ;
double [][][][] textures = new double [woi.height][woi.width][num_slices][texture_slice_size];
if ((woi == null) && (texture_tiles==null)) {
System.out.println("doubleTextures(): woi and texture_tiles can not be simultaneously null");
return null;
}
if (texture_tiles == null) {
texture_tiles = new double [woi.height][woi.width][][];
} else {
woi.height = texture_tiles.length;
woi.width = texture_tiles[0].length;
}
// double [][][][] textures = new double [woi.height][woi.width][num_slices][texture_slice_size];
for (int indx = 0; indx < indices.length; indx++) if ((indices[indx] & (1 << LIST_TEXTURE_BIT)) != 0){
int tile = indices[indx] >> CORR_NTILE_SHIFT;
int tileX = tile % full_width;
int tileY = tile / full_width;
int wtileX = tileX - woi.x;
int wtileY = tileY - woi.y;
if ((wtileX < woi.width) && (wtileY < woi.height)) {
texture_tiles[tileY][tileX] = new double [num_slices][texture_slice_size];
if ((wtileX >=0 ) && (wtileX < woi.width) && (wtileY >= 0) && (wtileY < woi.height)) {
for (int slice = 0; slice < num_slices; slice++) {
for (int i = 0; i < texture_slice_size; i++) {
textures[wtileY][wtileX][slice][i] = ftextures[indx * texture_tile_size + slice * texture_slice_size + i];
texture_tiles[wtileY][wtileX][slice][i] = ftextures[indx * texture_tile_size + slice * texture_slice_size + i];
}
}
}
}
return textures;
return texture_tiles;
}
public float [][] getRBG (int ncam){
......
......@@ -60,16 +60,17 @@ public class CLTPass3d{
public boolean [] border_tiles = null; // these are border tiles, zero out alpha
public boolean [] selected = null; // which tiles are selected for this layer
public double [][][][] texture_tiles;
public float [][] texture_img = null; // [3][] (RGB) or [4][] RGBA
public Rectangle texture_woi = null; // null or generated texture location/size
// texture_selection is only used for the GPU and if not null means it is for the GPU
public boolean [] texture_selection = null; // use by the GPU to set texture to generate
public double [][] max_tried_disparity = null; //[ty][tx] used for combined passes, shows maximal disparity for this tile, regardless of results
public boolean is_combo = false;
public boolean is_measured = false;
public String texture = null; // relative (to x3d) path
public Rectangle texture_bounds;
public Rectangle texture_bounds; // in tiles, not pixels !
public int dbg_index;
public int disparity_index = ImageDtt.DISPARITY_INDEX_CM; // may also be ImageDtt.DISPARITY_INDEX_POLY
public double [][] tiles_RBGA = null;
SuperTiles superTiles = null;
TileProcessor tileProcessor;
......@@ -99,7 +100,31 @@ public class CLTPass3d{
{
return texture_tiles;
}
// texture_selection is only used for the GPU and if not null means it is for the GPU
public boolean [] getTextureSelection()
{
return texture_selection;
}
public void setTextureSelection(boolean [] selection) {
texture_selection = selection;
}
public void setTextureSelection(int indx, boolean sel) {
texture_selection[indx] = sel;
}
public double [][] getTilesRBGA()
{
return tiles_RBGA;
}
public void setTilesRBGA(double [][] rgba)
{
tiles_RBGA = rgba;
}
/*
public float [][] getTextureImages()
{
return texture_img;
......@@ -109,17 +134,35 @@ public class CLTPass3d{
{
return texture_woi;
}
*/
public double [][] getMaxTriedDisparity()
{
return max_tried_disparity;
}
public double [][] getTileRBGA(
int num_layers) // 4 or 12
{
if (texture_img != null) {
System.out.println("FIXME: implement replacement for the GPU-generated textures (using macro mode?)");
// if (texture_img != null) {
// System.out.println("FIXME: implement replacement for the GPU-generated textures (using macro mode?)");
// }
double [][] tones = getTilesRBGA();
if (tones != null) {
int nl = tones.length;
if (nl > num_layers) {
double [][] tones1 = new double [num_layers][tones[0].length];
for (int n = 0; n < num_layers; n++) {
tones1[n] = tones[n];
}
return tones1;
} else {
return tones;
}
}
System.out.println("FIXME: should not get here, tones should be calculated earlier");
if (texture_tiles == null) return null;
int tilesY = texture_tiles.length;
int tilesX = 0;
......@@ -175,11 +218,12 @@ public class CLTPass3d{
// Will not work if texture is disabled
public void updateSelection(){ // add updating border tiles?
public void updateSelection(){ // add updating border tiles? -- only for CPU!
int tilesX = tileProcessor.getTilesX();
int tilesY = tileProcessor.getTilesY();
selected = new boolean[tilesY*tilesX];
int minX = tilesX, minY = tilesY, maxX = -1, maxY = -1;
/*
if (texture_img != null) { // using GPU output
//tileProcessor.getTileSize()
if (texture_woi != null) {
......@@ -195,6 +239,7 @@ public class CLTPass3d{
return;
}
}
*/
if (texture_tiles != null) {
for (int ty = 0; ty < tilesY; ty++) for (int tx = 0; tx < tilesX; tx++){
if (texture_tiles[ty][tx] != null) {
......@@ -214,7 +259,6 @@ public class CLTPass3d{
texture_bounds = new Rectangle(minX, minY, maxX - minX +1, maxY - minY +1 );
}
}
public Rectangle getTextureBounds(){
return texture_bounds;
}
......@@ -250,7 +294,7 @@ public class CLTPass3d{
// border_tiles = null; // these are border tiles, zero out alpha
// selected = null; // which tiles are selected for this layer
superTiles = null;
setTilesRBGA(null);
}
/**
......
......@@ -50,10 +50,6 @@ public class ImageDtt extends ImageDttCPU {
final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
//// Uses quadCLT from gpuQuad
//// final double [][][] image_data, // first index - number of image in a quad
//// final boolean [][] saturation_imp, // (near) saturated pixels or null
// correlation results - final and partial
final double [][][][] clt_corr_combo, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [type][tilesY][tilesX] should be set by caller
// types: 0 - selected correlation (product+offset), 1 - sum
......@@ -65,12 +61,10 @@ public class ImageDtt extends ImageDttCPU {
final double [][] disparity_map, // [8][tilesY][tilesX], only [6][] is needed on input or null - do not calculate
// last 2 - contrast, avg/ "geometric average)
final int disparity_modes, // bit mask of disparity_map slices to calculate/return
final double [][][][] texture_tiles, // compatible with the CPU ones
final float [][] texture_img, // null or [3][] (RGB) or [4][] RGBA
final Rectangle texture_woi, // null or generated texture location/size
//// final double [][][][] texture_tiles, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
final Rectangle texture_woi_pix, // null or generated texture location/size in pixels
final float [][][] iclt_fimg, // will return quad images or null to skip, use quadCLT.linearStackToColor
//// final int width,
// new parameters, will replace some other?
final double gpu_corr_scale, // 0.75; // reduce GPU-generated correlation values
final double gpu_fat_zero, // clt_parameters.getGpuFatZero(is_mono);absolute == 30.0
......@@ -81,17 +75,9 @@ public class ImageDtt extends ImageDttCPU {
final double gpu_sigma_rb_corr, // = 0.5; // apply LPF after accumulating R and B correlation before G, monochrome ? 1.0 : gpu_sigma_rb_corr;
final double gpu_sigma_corr, // = 0.9;gpu_sigma_corr_m
final int gpu_corr_rad, // = transform_size - 1 ?
//// final double corr_fat_zero, // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum (use for absolute)
//// final boolean corr_sym,
//// final double corr_offset,
final double corr_red, // +used
final double corr_blue,// +used
//// final double corr_sigma,
//// final boolean corr_normalize, // normalize correlation results by rms
//// final double min_corr, // 0.02; // minimal correlation value to consider valid
//// final double max_corr_sigma, // 1.2; // weights of points around global max to find fractional
final double max_corr_radius, // 3.9;
//// final boolean max_corr_double, //"Double pass when masking center of mass to reduce preference for integer values
final int corr_mode, // Correlation mode: 0 - integer max, 1 - center of mass, 2 - polynomial
final double min_shot, // +10.0; // Do not adjust for shot noise if lower than
......@@ -101,23 +87,12 @@ public class ImageDtt extends ImageDttCPU {
final boolean diff_gauss, // true; // when averaging images, use Gaussian around average as weight (false - sharp all/nothing)
final double min_agree, // +3.0; // minimal number of channels to agree on a point (real number to work with fuzzy averages)
final boolean dust_remove, // +Do not reduce average weight when only one image differs much from the average
//// final boolean keep_weights, // Add port weights to RGBA stack (debug feature)
final GeometryCorrection geometryCorrection, // for GPU TODO: combine geometry corrections if geometryCorrection_main is not null
final GeometryCorrection geometryCorrection_main, // if not null correct this camera (aux) to the coordinates of the main
//// using quadCLT instance
//// final double [][][][][][] clt_kernels, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
//// final int kernel_step,
final int window_type, // GPU: will not be used
//// final double [][] shiftXY, // [port]{shiftX,shiftY} // GPU: will not be used
final double disparity_corr, // disparity at infinity
//// final double [][][] fine_corr, // quadratic coefficients for fine correction (or null) // GPU: will not be used
//// final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
//// final double shiftX, // shift image horizontally (positive - right) - just for testing // GPU: will not be used
//// final double shiftY, // shift image vertically (positive - down) // GPU: will not be used
final int debug_tileX,
final int debug_tileY,
// final boolean no_fract_shift, // GPU: will not be used
// final boolean no_deconvolution, // GPU: will not be used
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
......@@ -137,7 +112,9 @@ public class ImageDtt extends ImageDttCPU {
final boolean macro_mode = macro_scale != 1; // correlate tile data instead of the pixel data
final int quad = 4; // number of subcameras
final int numcol = 3; // number of colors // keep the same, just do not use [0] and [1], [2] - green
// final int numcol = 3; // number of colors // keep the same, just do not use [0] and [1], [2] - green
final int numcol = isMonochrome()?1:3;
final int width = gpuQuad.getImageWidth();
final int height = gpuQuad.getImageHeight();
final int tilesX=gpuQuad.getTilesX(); // width/transform_size;
......@@ -251,8 +228,6 @@ public class ImageDtt extends ImageDttCPU {
}
if (globalDebugLevel > 0) {
System.out.println("clt_aberrations_quad_corr(): width="+width+" height="+height+" transform_size="+transform_size+
" debug_tileX="+debug_tileX+" debug_tileY="+debug_tileY+" globalDebugLevel="+globalDebugLevel);
......@@ -315,6 +290,12 @@ public class ImageDtt extends ImageDttCPU {
tile_op, // final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
all_pairs, // final int corr_mask, // <0 - use corr mask from the tile tile_op, >=0 - overwrite all with non-zero corr_mask_tp
threadsMax); // final int threadsMax, // maximal number of threads to launch
if (tp_tasks.length == 0) {
System.out.println("Empty tasks - nothing to do");
return;
}
//texture_tiles
final boolean fneed_macro = need_macro;
final boolean fneed_corr = need_corr && used_corrs[0];
......@@ -343,7 +324,8 @@ public class ImageDtt extends ImageDttCPU {
gpuQuad.setTasks( // copy tp_tasks to the GPU memory
tp_tasks, // TpTask [] tile_tasks,
use_main); // use_aux); // boolean use_aux)
use_main, // use_aux); // boolean use_aux)
imgdtt_params.gpu_verify); // boolean verify
gpuQuad.execSetTilesOffsets(); // prepare tiles offsets in GPU memory
gpuQuad.execConvertDirect();
......@@ -367,7 +349,7 @@ public class ImageDtt extends ImageDttCPU {
dust_remove); // boolean dust_remove,
float [][] rbga = gpuQuad.getRBGA(
(isMonochrome() ? 1 : 3), // int num_colors,
(texture_woi != null)? texture_woi : woi);
(texture_woi_pix != null)? texture_woi_pix : woi);
for (int ncol = 0; ncol < texture_img.length; ncol++) if (ncol < rbga.length) {
texture_img[ncol] = rbga[ncol];
}
......@@ -407,8 +389,45 @@ public class ImageDtt extends ImageDttCPU {
}
}
}
}
// does it need non-overlapping texture tiles
if (texture_tiles != null) { // compatible with the CPU ones
//Generate non-overlapping (16x16) texture tiles, prepare
gpuQuad.execTextures(
col_weights, // double [] color_weights,
isLwir(), // boolean is_lwir,
min_shot, // double min_shot, // 10.0
scale_shot, // double scale_shot, // 3.0
diff_sigma, // double diff_sigma, // pixel value/pixel change
diff_threshold, // double diff_threshold, // pixel value/pixel change - never used in GPU ?
min_agree, // double min_agree, // minimal number of channels to agree on a point (real number to work with fuzzy averages)
dust_remove, // boolean dust_remove, // Do not reduce average weight when only one image differs much from the average
true, // boolean calc_textures,
false); // boolean calc_extra)
// int numcol = quadCLT_main.isMonochrome()?1:3;
// int ports = imp_quad_main.length; // quad
int [] texture_indices = gpuQuad.getTextureIndices();
int num_src_slices = numcol + 1; // + (clt_parameters.keep_weights?(ports + numcol + 1):0); // 12 ; // calculate
float [] flat_textures = gpuQuad.getFlatTextures( // fatal error has been detected by the Java Runtime Environment:
texture_indices.length,
numcol, // int num_colors,
false); // clt_parameters.keep_weights); // boolean keep_weights);
// int texture_slice_size = (2 * gpuQuad.getDttSize())* (2 * gpuQuad.getDttSize());
// int texture_tile_size = texture_slice_size * num_src_slices ;
// double [][][][] texture_tiles = new double [tilesY][tilesX][][];
gpuQuad.doubleTextures(
new Rectangle(0, 0, tilesX, tilesY), // Rectangle woi,
texture_tiles, // double [][][][] texture_tiles, // null or [tilesY][tilesX]
texture_indices, // int [] indices,
flat_textures, // float [][][] ftextures,
tilesX, // int full_width,
4, // rbga only /int num_slices
num_src_slices // int num_src_slices
);
}
// does it need correlations?
if (fneed_corr) {
//Generate 2D phase correlations from the CLT representation
......@@ -918,7 +937,7 @@ public class ImageDtt extends ImageDttCPU {
for (int ii = 0; ii < dir_corr_strength.length; ii++) {
if (dir_corr_strength[ii] == null) dir_corr_strength[ii] = nan2;
}
System.out.println(String.format("corr4dirsLMA -> ↔: %7.4f (%7.4f) ↕:%7.4f (%7.4f) ⤡:%7.4f (%7.4f) ⤢:%7.4f (%7.4f)",
System.out.println(String.format("corr4dirsLMA -> ↔: %7.4f (%7.4f) ↕:%7.4f (%7.4f) ⇖:%7.4f (%7.4f) ⇗:%7.4f (%7.4f)",
dir_corr_strength[0][0],dir_corr_strength[0][1],dir_corr_strength[1][0],dir_corr_strength[1][1],
dir_corr_strength[2][0],dir_corr_strength[2][1],dir_corr_strength[3][0],dir_corr_strength[3][1]));
}
......
......@@ -1511,64 +1511,36 @@ public class ImageDttCPU {
// removing macro and FPGA modes
public double [][] cltMeasureLazyEye ( // returns d,s lazy eye parameters
final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
// final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
final double [][][] image_data, // first index - number of image in a quad
final boolean [][] saturation_imp, // (near) saturated pixels or null
// correlation results - final and partial
// final double [][][][] clt_corr_combo, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [type][tilesY][tilesX] should be set by caller
// types: 0 - selected correlation (product+offset), 1 - sum
// final double [][][][][] clt_corr_partial,// [tilesY][tilesX][quad]color][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [tilesY][tilesX] should be set by caller
// When clt_mismatch is non-zero, no far objects extraction will be attempted
final double [][] clt_mismatch, // [12][tilesY * tilesX] // ***** transpose unapplied ***** ?. null - do not calculate
// values in the "main" directions have disparity (*_CM) subtracted, in the perpendicular - as is
final double [][] disparity_map, // [8][tilesY][tilesX], only [6][] is needed on input or null - do not calculate
// last 2 - contrast, avg/ "geometric average)
// final double [][][][] texture_tiles, // [tilesY][tilesX]["RGBA".length()][]; null - will skip images combining
final int width,
final double corr_fat_zero, // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
// final boolean corr_sym,
// final double corr_offset,
final double corr_red,
final double corr_blue,
final double corr_sigma,
// final boolean corr_normalize, // normalize correlation results by rms
final double min_corr, // 0.02; // minimal correlation value to consider valid
// final double max_corr_sigma, // 1.2; // weights of points around global max to find fractional
// final double max_corr_radius, // 3.9;
// final boolean max_corr_double, //"Double pass when masking center of mass to reduce preference for integer values
// final int corr_mode, // Correlation mode: 0 - integer max, 1 - center of mass, 2 - polynomial
// final double min_shot, // 10.0; // Do not adjust for shot noise if lower than
// final double scale_shot, // 3.0; // scale when dividing by sqrt ( <0 - disable correction)
// final double diff_sigma, // 5.0;//RMS difference from average to reduce weights (~ 1.0 - 1/255 full scale image)
// final double diff_threshold, // 5.0; // RMS difference from average to discard channel (~ 1.0 - 1/255 full scale image)
// final boolean diff_gauss, // true; // when averaging images, use Gaussian around average as weight (false - sharp all/nothing)
// final double min_agree, // 3.0; // minimal number of channels to agree on a point (real number to work with fuzzy averages)
// final boolean dust_remove, // Do not reduce average weight when only one image differs much from the average
// final boolean keep_weights, // Add port weights to RGBA stack (debug feature)
final GeometryCorrection geometryCorrection,
final GeometryCorrection geometryCorrection_main, // if not null correct this camera (aux) to the coordinates of the main
final double [][][][][][] clt_kernels, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
final int kernel_step,
// final int transform_size,
final int window_type,
final double [][] shiftXY, // [port]{shiftX,shiftY}
final double disparity_corr, // disparity at infinity
// final double [][][] fine_corr, // quadratic coefficients for fine correction (or null)
// final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
final double shiftX, // shift image horizontally (positive - right) - just for testing
final double shiftY, // shift image vertically (positive - down)
final int tileStep, // process tileStep x tileStep cluster of tiles when adjusting lazy eye parameters
final int debug_tileX,
final int debug_tileY,
// final boolean no_fract_shift,
// final boolean no_deconvolution,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
......@@ -2390,7 +2362,7 @@ public class ImageDttCPU {
final double [][][] image_data, // first index - number of image in a quad
final boolean [][] saturation_imp, // (near) saturated pixels or null
// correlation results - final and partial
final double [][][][] clt_corr_combo, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
final double [][][][] clt_corr_combo_in, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [type][tilesY][tilesX] should be set by caller
// types: 0 - selected correlation (product+offset), 1 - sum
final double [][][][][] clt_corr_partial,// [tilesY][tilesX][quad]color][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
......@@ -2442,6 +2414,14 @@ public class ImageDttCPU {
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
// ****** FIXME tries to use color == 3, should be disabled!
if (clt_corr_combo_in != null) {
System.out.println("clt_corr_combo != null");
System.out.println("clt_corr_combo != null");
System.out.println("clt_corr_combo != null");
}
final double [][][][] clt_corr_combo = (globalDebugLevel >-10000)?null:clt_corr_combo_in;
final boolean debug_distort= globalDebugLevel > 0; ///false; // true;
final double [][] debug_offsets = new double[imgdtt_params.lma_dbg_offset.length][2];
......@@ -3072,8 +3052,8 @@ public class ImageDttCPU {
// if ((clt_corr_partial != null) && (imgdtt_params.corr_mode_debug || imgdtt_params.gpu_mode_debug)) {
if (debugTile0) {
System.out.println("Debugging tileY = "+tileY+" tileX = " + tileX);
System.out.println("Debugging tileY = "+tileY+" tileX = " + tileX);
System.out.println("Debugging tileY = "+tileY+" tileX = " + tileX);
// System.out.println("Debugging tileY = "+tileY+" tileX = " + tileX);
// System.out.println("Debugging tileY = "+tileY+" tileX = " + tileX);
}
double [][][] corr_pairs_td = corr2d.correlateCompositeTD(
......@@ -3577,6 +3557,7 @@ public class ImageDttCPU {
} // if (disparity_map != null){ // not null - calculate correlations
// only debug is left
// old (per-color correlation)
// ****** FIXME tries to use color == 3, should be disabled!
if ((clt_corr_combo != null) && !imgdtt_params.corr_mode_debug){ // not null - calculate correlations // not used in lwir
tcorr_tpartial= new double[corr_pairs.length][numcol+1][4][transform_len];
tcorr_partial = new double[quad][numcol+1][];
......@@ -3623,7 +3604,7 @@ public class ImageDttCPU {
for (int i = 0; i < transform_len; i++) {
for (int n = 0; n<4; n++) {
tcorr_tpartial[pair][numcol][n][i] = 0.0;
for (int ncol= 0; ncol < tcorr_tpartial[pair].length; ncol++) {
for (int ncol= 0; ncol < tcorr_tpartial[pair].length; ncol++) { // tcorr_tpartial[pair].length = 4 > colors
if (tcorr_tpartial[pair][ncol] != null) {
tcorr_tpartial[pair][numcol][n][i] += col_weights[ncol] * tcorr_tpartial[pair][0][n][i];
}
......@@ -5197,7 +5178,6 @@ public class ImageDttCPU {
// in monochrome mode only MONO_CHN == GREEN_CHN is used, R and B are null
public double [][] combineRBGATiles( // USED in lwir
final double [][][][] texture_tiles, // array [tilesY][tilesX][4][4*transform_size] or [tilesY][tilesX]{null}
// final int transform_size,
final boolean overlap, // when false - output each tile as 16x16, true - overlap to make 8x8
final boolean sharp_alpha, // combining mode for alpha channel: false - treat as RGB, true - apply center 8x8 only
final int threadsMax, // maximal number of threads to launch
......@@ -5227,7 +5207,6 @@ public class ImageDttCPU {
}
}
// final double [][] dpixels = new double["RGBA".length()+(has_weights? 4: 0)][width*height]; // assuming java initializes them to 0
final double [][] dpixels = new double["RGBA".length()+(has_weights? 8: 0)][width*height]; // assuming java initializes them to 0
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
......
......@@ -29,6 +29,7 @@ import com.elphel.imagej.common.GenericJTabbedDialog;
public class ImageDttParameters {
public boolean gpu_mode_debug = true;
public boolean gpu_verify = false; // verify tasks/ input data
public boolean corr_mode_debug = true;
public boolean mix_corr_poly = true;
public boolean corr_poly_only = false; // if LMA fails, discard tile
......@@ -212,6 +213,8 @@ public class ImageDttParameters {
gd.addCheckbox ("Debug CPU->GPU matching", this.gpu_mode_debug,
"output clt_corr_partial");
gd.addCheckbox ("Verify GPU input", this.gpu_verify,
"Check tp_tasks and fix NaN");
gd.addCheckbox ("Enable ImageDtt correlation debug layers", this.corr_mode_debug,
"false - return (old) per-coord correlations, true - replace them with more pairs correlation (new)");
gd.addCheckbox ("Replace CM layer with mixed/new poly one", this.mix_corr_poly);
......@@ -507,6 +510,7 @@ public class ImageDttParameters {
}
public void dialogAnswers(GenericJTabbedDialog gd) {
this.gpu_mode_debug = gd.getNextBoolean();
this.gpu_verify = gd.getNextBoolean();
this.corr_mode_debug= gd.getNextBoolean();
this.mix_corr_poly= gd.getNextBoolean();
this.corr_poly_only= gd.getNextBoolean();
......@@ -658,6 +662,7 @@ public class ImageDttParameters {
public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"gpu_mode_debug", this.gpu_mode_debug+"");
properties.setProperty(prefix+"gpu_verify", this.gpu_verify+"");
properties.setProperty(prefix+"corr_mode_debug", this.corr_mode_debug+"");
properties.setProperty(prefix+"mix_corr_poly", this.mix_corr_poly+"");
properties.setProperty(prefix+"corr_poly_only", this.corr_poly_only+"");
......@@ -809,6 +814,7 @@ public class ImageDttParameters {
public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"gpu_mode_debug")!=null) this.gpu_mode_debug=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_mode_debug"));
if (properties.getProperty(prefix+"gpu_verify")!=null) this.gpu_verify=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_verify"));
if (properties.getProperty(prefix+"corr_mode_debug")!=null) this.corr_mode_debug=Boolean.parseBoolean(properties.getProperty(prefix+"corr_mode_debug"));
if (properties.getProperty(prefix+"mix_corr_poly")!=null) this.mix_corr_poly=Boolean.parseBoolean(properties.getProperty(prefix+"mix_corr_poly"));
if (properties.getProperty(prefix+"corr_poly_only")!=null) this.corr_poly_only=Boolean.parseBoolean(properties.getProperty(prefix+"corr_poly_only"));
......@@ -960,6 +966,7 @@ public class ImageDttParameters {
public ImageDttParameters clone() throws CloneNotSupportedException {
ImageDttParameters idp = new ImageDttParameters();
idp.gpu_mode_debug = this.gpu_mode_debug;
idp.gpu_verify = this.gpu_verify;
idp.corr_mode_debug = this.corr_mode_debug;
idp.mix_corr_poly = this.mix_corr_poly;
idp.corr_poly_only = this.corr_poly_only;
......
......@@ -283,9 +283,10 @@ public class MacroCorrelation {
double [][] shiftXY = {{0.0,0.0},{0.0,0.0},{0.0,0.0},{0.0,0.0}};
double [][][][] clt_corr_combo = new double [ImageDtt.TCORR_TITLES.length][mTilesY][mTilesX][]; // needed always
double [][][][] clt_corr_combo = null; // new double [ImageDtt.TCORR_TITLES.length][mTilesY][mTilesX][]; // needed always
double [][][][][] clt_corr_partial = null; // [tp.tilesY][tp.tilesX][pair][color][(2*transform_size-1)*(2*transform_size-1)]
/*
if (show_corr_partial) {
clt_corr_partial = new double [mTilesY][mTilesX][][][];
for (int i = 0; i < mTilesY; i++){
......@@ -296,6 +297,7 @@ public class MacroCorrelation {
}
if (show_corr_combo) {
clt_corr_combo = new double [ImageDtt.TCORR_TITLES.length][mTilesY][mTilesX][]; // needed always
for (int i = 0; i < mTilesY; i++){
for (int j = 0; j < mTilesX; j++){
for (int k = 0; k<clt_corr_combo.length; k++){
......@@ -304,9 +306,8 @@ public class MacroCorrelation {
}
}
}
*/
// double [][][][] texture_tiles = save_textures ? new double [tilesY][tilesX][][] : null; // ["RGBA".length()][];
ImageDtt image_dtt = new ImageDtt(
clt_parameters.transform_size,
this.mtp.isMonochrome(),
......
......@@ -24,7 +24,7 @@ package com.elphel.imagej.tileprocessor;
**
*/
import static jcuda.driver.JCudaDriver.cuMemcpyDtoH;
//import static jcuda.driver.JCudaDriver.cuMemcpyDtoH;
import java.awt.Rectangle;
import java.io.DataOutputStream;
......@@ -44,12 +44,9 @@ import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.correction.CorrectionColorProc;
import com.elphel.imagej.correction.EyesisCorrections;
import com.elphel.imagej.gpu.GPUTileProcessor;
import com.elphel.imagej.gpu.GPUTileProcessor.TpTask;
import ij.ImagePlus;
import ij.ImageStack;
import jcuda.Pointer;
import jcuda.Sizeof;
public class QuadCLT extends QuadCLTCPU {
private GPUTileProcessor.GpuQuad gpuQuad = null;
......@@ -330,10 +327,15 @@ public class QuadCLT extends QuadCLTCPU {
0xf, // int out_image, // from which tiles to generate image (currently 0/1)
0x3f, // int corr_mask, // which correlation pairs to generate (maybe later - reduce size from 15x15)
debugLevel); // final int debugLevel) - not yet used
if (tp_tasks.length == 0) {
System.out.println("Empty tasks - nothing to do");
return;
}
gpuQuad.setTasks( // copy tp_tasks to the GPU memory
tp_tasks, // TpTask [] tile_tasks,
use_aux); // boolean use_aux)
use_aux, // boolean use_aux)
clt_parameters.img_dtt.gpu_verify); // boolean verify
gpuQuad.execSetTilesOffsets();
gpuQuad.execConvertDirect();
......@@ -596,10 +598,16 @@ public class QuadCLT extends QuadCLTCPU {
0xf, // int out_image, // from which tiles to generate image (currently 0/1)
0x3f, // int corr_mask, // which correlation pairs to generate (maybe later - reduce size from 15x15)
debugLevel); // final int debugLevel) - not yet used
if (tp_tasks.length == 0) {
System.out.println("--- Empty tasks - nothing to do ---");
return null;
}
quadCLT_main.getGPU().setTasks( // copy tp_tasks to the GPU memory
tp_tasks, // TpTask [] tile_tasks,
use_aux); // boolean use_aux)
use_aux, // boolean use_aux)
clt_parameters.img_dtt.gpu_verify); // boolean verify
/*
quadCLT_main.getGPU().setGeometryCorrection( // copy Geometry correction data to the GPU memory (once per camera group?), allocate GPU memory for the rotation/deriv. matrices
quadCLT_main.getGeometryCorrection(),
......@@ -1056,8 +1064,10 @@ public class QuadCLT extends QuadCLTCPU {
}
}
}
double [][][][] texture_tiles = quadCLT_main.getGPU().doubleTextures(
double [][][][] texture_tiles = new double [tilesY][tilesX][][];
quadCLT_main.getGPU().doubleTextures(
new Rectangle(0, 0, tilesX, tilesY), // Rectangle woi,
texture_tiles, // double [][][][] texture_tiles, // null or [tilesY][tilesX]
texture_indices, // int [] indices,
flat_textures, // float [][][] ftextures,
tilesX, // int full_width,
......@@ -1219,9 +1229,9 @@ public class QuadCLT extends QuadCLTCPU {
double [][][][] clt_corr_combo = new double [ImageDtt.TCORR_TITLES.length][tilesY][tilesX][]; // will only be used inside?
// double min_corr_selected = clt_parameters.min_corr; // 0.02 was not used !
// yes, needed (for macro)
double [][] disparity_map = new double [ImageDtt.DISPARITY_TITLES.length][]; //[0] -residual disparity, [1] - orthogonal (just for debugging)
//if ((i >= IMG_TONE_RGB) || ((i >= IMG_DIFF0_INDEX) && (i < (IMG_DIFF0_INDEX + 4)))) {
/*
double [][] shiftXY = new double [4][2];
// not used
......@@ -1264,8 +1274,8 @@ public class QuadCLT extends QuadCLTCPU {
}
}
float [][] texture_img = new float [isMonochrome()?2:4][];
Rectangle texture_woi = new Rectangle();
// float [][] texture_img = new float [isMonochrome()?2:4][];
// Rectangle texture_woi = new Rectangle();
image_dtt.clt_aberrations_quad_corr_GPU( // USED in LWIR
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
......@@ -1285,8 +1295,9 @@ public class QuadCLT extends QuadCLTCPU {
// last 2 - contrast, avg/ "geometric average)
disparity_modes, // disparity_modes, // bit mask of disparity_map slices to calculate/return
texture_img, // texture_img, // null or [3][] (RGB) or [4][] RGBA
texture_woi, // texture_woi, // null or generated texture location/size
null, // final double [][][][] texture_tiles, // compatible with the CPU ones
null, // texture_img, // texture_img, // null or [3][] (RGB) or [4][] RGBA
null, // texture_woi, // texture_woi, // null or generated texture location/size
null, // iclt_fimg, // will return quad images or null to skip, use quadCLT.linearStackToColor
// new parameters, will replace some other?
// clt_parameters.getFatZero(isMonochrome()), // final double gpu_fat_zero, // clt_parameters.getGpuFatZero(is_mono);absolute == 30.0\
......@@ -1323,8 +1334,8 @@ public class QuadCLT extends QuadCLTCPU {
scan_rslt.tile_op = tile_op;
scan_rslt.disparity_map = disparity_map;
scan_rslt.texture_tiles = null; // texture_tiles;
scan_rslt.texture_img = texture_img;
scan_rslt.texture_woi = texture_woi;
// scan_rslt.texture_img = texture_img;
// scan_rslt.texture_woi = texture_woi;
scan_rslt.is_measured = true;
scan_rslt.is_combo = false;
scan_rslt.resetProcessed();
......@@ -1357,8 +1368,674 @@ public class QuadCLT extends QuadCLTCPU {
return scan_rslt;
}
public ImagePlus getBackgroundImage(
boolean [] bgnd_tiles,
CLTParameters clt_parameters,
ColorProcParameters colorProcParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
String name,
int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
int threadsMax, // maximal number of threads to launch
boolean updateStatus,
int debugLevel
) {
if ((gpuQuad == null) || !(isAux()?clt_parameters.gpu_use_aux : clt_parameters.gpu_use_main)) {
return super.getBackgroundImage( // measure background // USED in lwir
bgnd_tiles,
clt_parameters,
colorProcParameters,
rgbParameters,
name,
disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
}
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
CLTPass3d bgnd_data = tp.clt_3d_passes.get(0);
boolean [] bgnd_tiles_grown2 = bgnd_data.selected.clone(); // only these have non 0 alpha
tp.growTiles(
2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
bgnd_tiles_grown2,
null); // prohibit
// bgnd_data.getTextureSelection()
bgnd_data.setTextureSelection(bgnd_tiles_grown2);
Rectangle texture_woi_pix = new Rectangle(); // in pixels
float [][] texture_img = GetTextureGPU( // returns texture
clt_parameters, // CLTParameters clt_parameters,
texture_woi_pix, // Rectangle texture_woi, // = new Rectangle();
bgnd_data.disparity, // double [][] disparity_array, // [tilesY][tilesX]
bgnd_tiles_grown2, // bgnd_tiles_grown2, // boolean [] selection,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
// for now - use just RGB. Later add option for RGBA
float [][] texture_rgb = {texture_img[0],texture_img[1],texture_img[2]};
float [][] texture_rgba = {texture_img[0],texture_img[1],texture_img[2],texture_img[3]};
int out_width = tilesX * clt_parameters.transform_size;
int out_height = tilesY * clt_parameters.transform_size;
ImagePlus imp_texture_bgnd = linearStackToColor(
clt_parameters,
colorProcParameters,
rgbParameters,
name+"-texture-bgnd", // String name,
"", //String suffix, // such as disparity=...
true, // toRGB,
!this.correctionsParameters.jpeg, // boolean bpp16, // 16-bit per channel color mode for result
true, // boolean saveShowIntermediate, // save/show if set globally
false, //true, // boolean saveShowFinal, // save/show result (color image?)
((clt_parameters.alpha1 > 0)? texture_rgba: texture_rgb),
texture_woi_pix.width, // tilesX * clt_parameters.transform_size,
texture_woi_pix.height, // tilesY * clt_parameters.transform_size,
1.0, // double scaleExposure, // is it needed?
debugLevel);
// imp_texture_bgnd.show();
// resize for backdrop here!
// public double getFOVPix(){ // get ratio of 1 pixel X/Y to Z (distance to object)
ImagePlus imp_texture_full = resizeToFull(
out_width, // int out_width,
out_height, // int out_height,
texture_woi_pix.x, // int x0, // image offset-x
texture_woi_pix.y, // int y0, // image offset-y
imp_texture_bgnd, // ImagePlus imp_texture_bgnd,
false, // boolean fillBlack,
false, // boolean noalpha, // only with fillBlack, otherwise ignored
debugLevel);
// imp_texture_full.show();
return imp_texture_full;
}
public CLTPass3d CLTMeasureCorr( // perform single pass according to prepared tiles operations and disparity // not used in lwir
CLTParameters clt_parameters,
final int scanIndex,
final boolean save_textures,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
if ((gpuQuad == null) || !(isAux()?clt_parameters.gpu_use_aux : clt_parameters.gpu_use_main)) {
return super.CLTMeasureCorr( // perform single pass according to prepared tiles operations and disparity
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
scanIndex, // final int scanIndex,
save_textures, // final boolean save_textures,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
}
// GPU will not use textures. Maybe set texture_selection instead?
// final int transform_size =clt_parameters.transform_size;
CLTPass3d scan = tp.clt_3d_passes.get(scanIndex);
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
int [][] tile_op = scan.tile_op;
double [][] disparity_array = scan.disparity;
boolean [] tex_sel = null;
if (save_textures) {
tex_sel = new boolean [tilesY*tilesX];
for (int ty = 0; ty < tilesY; ty++) {
for (int tx = 0; tx < tilesX; tx++) {
if (tile_op[ty][tx] != 0){
tex_sel[ty * tilesX + tx] = true;
}
}
}
}
double [][] disparity_map = new double [ImageDtt.DISPARITY_TITLES.length][];
/*
double [][] shiftXY = new double [4][2];
// not used
if (!clt_parameters.fine_corr_ignore) {
double [][] shiftXY0 = {
{clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0},
{clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1},
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}};
shiftXY = shiftXY0;
}
*/
ImageDtt image_dtt = new ImageDtt(
clt_parameters.transform_size,
isMonochrome(),
isLwir(),
clt_parameters.getScaleStrength(isAux()),
gpuQuad);
double z_correction = clt_parameters.z_correction;
if (clt_parameters.z_corr_map.containsKey(image_name)){ // not used in lwir
z_correction +=clt_parameters.z_corr_map.get(image_name);
}
final double disparity_corr = (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
// TODO: find where BITS_ALL_DIFFS is not needed and remove - it takes much longer than correlation in the GPU
int disparity_modes =
ImageDtt.BITS_ALL_DISPARITIES |
ImageDtt.BITS_ALL_DIFFS | // needs max_diff?
ImageDtt.BITS_OVEREXPOSED; // |
// ImageDtt.BITS_TONE_RGB;
image_dtt.clt_aberrations_quad_corr_GPU( // USED in LWIR
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
//// Uses quadCLT from gpuQuad
// correlation results - final and partial
null, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [type][tilesY][tilesX] should be set by caller
// types: 0 - selected correlation (product+offset), 1 - sum
null, // clt_corr_partial,// [tilesY][tilesX][quad]color][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [tilesY][tilesX] should be set by caller
// When clt_mismatch is non-zero, no far objects extraction will be attempted
null, // clt_mismatch, // [12][tilesY * tilesX] // ***** transpose unapplied ***** ?. null - do not calculate
// values in the "main" directions have disparity (*_CM) subtracted, in the perpendicular - as is
disparity_map, // disparity_map, // [8][tilesY][tilesX], only [6][] is needed on input or null - do not calculate
// last 2 - contrast, avg/ "geometric average)
disparity_modes, // disparity_modes, // bit mask of disparity_map slices to calculate/return
null, // final double [][][][] texture_tiles, // compatible with the CPU ones
null, // texture_img, // texture_img, // null or [3][] (RGB) or [4][] RGBA
null, // texture_woi, // texture_woi, // null or generated texture location/size
null, // iclt_fimg, // will return quad images or null to skip, use quadCLT.linearStackToColor
// new parameters, will replace some other?
// clt_parameters.getFatZero(isMonochrome()), // final double gpu_fat_zero, // clt_parameters.getGpuFatZero(is_mono);absolute == 30.0\
clt_parameters.gpu_corr_scale, // gpu_corr_scale, // 0.75; // reduce GPU-generated correlation values
clt_parameters.getGpuFatZero(isMonochrome()), // final double gpu_fat_zero, // clt_parameters.getGpuFatZero(is_mono);absolute == 30.0\
clt_parameters.gpu_sigma_r, // 0.9, 1.1
clt_parameters.gpu_sigma_b, // 0.9, 1.1
clt_parameters.gpu_sigma_g, // 0.6, 0.7
clt_parameters.gpu_sigma_m, // = 0.4; // 0.7;
(isMonochrome()? 1.0 : clt_parameters.gpu_sigma_rb_corr), // final double gpu_sigma_rb_corr, // = 0.5; // apply LPF after accumulating R and B correlation before G, monochrome ? 1.0 : gpu_sigma_rb_corr;
clt_parameters.gpu_sigma_corr, // = 0.9;gpu_sigma_corr_m
image_dtt.transform_size - 1, // clt_parameters.gpu_corr_rad, // = transform_size - 1 ?
clt_parameters.corr_red, // +used
clt_parameters.corr_blue, // +used
clt_parameters.max_corr_radius,// 3.9;
clt_parameters.corr_mode, // Correlation mode: 0 - integer max, 1 - center of mass, 2 - polynomial
clt_parameters.min_shot, // 10.0; // Do not adjust for shot noise if lower than
clt_parameters.scale_shot, // 3.0; // scale when dividing by sqrt ( <0 - disable correction)
clt_parameters.diff_sigma, // 5.0;//RMS difference from average to reduce weights (~ 1.0 - 1/255 full scale image)
clt_parameters.diff_threshold, // 5.0; // RMS difference from average to discard channel (~ 1.0 - 1/255 full scale image)
clt_parameters.diff_gauss, // true; // when averaging images, use gaussian around average as weight (false - sharp all/nothing)
clt_parameters.min_agree, // 3.0; // minimal number of channels to agree on a point (real number to work with fuzzy averages)
clt_parameters.dust_remove, // Do not reduce average weight when only one image differes much from the average
geometryCorrection, // final GeometryCorrection geometryCorrection,
null, // final GeometryCorrection geometryCorrection_main, // if not null correct this camera (aux) to the coordinates of the main
clt_parameters.clt_window,
disparity_corr, // final double disparity_corr, // disparity at infinity
clt_parameters.tileX, // final int debug_tileX,
clt_parameters.tileY, // final int debug_tileY,
threadsMax,
debugLevel);
scan.disparity_map = disparity_map;
scan.texture_tiles = null;
scan.setTextureSelection(tex_sel);
scan.is_measured = true; // but no disparity map/textures
scan.is_combo = false;
scan.resetProcessed();
return scan;
}
public String getPassImage( // get image from a single pass, return relative path for x3d // USED in lwir
CLTParameters clt_parameters,
ColorProcParameters colorProcParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
String name,
int scanIndex,
int threadsMax, // maximal number of threads to launch
boolean updateStatus,
int debugLevel)
{
if ((gpuQuad == null) || !(isAux()?clt_parameters.gpu_use_aux : clt_parameters.gpu_use_main)) {
return super.getPassImage( // get image from a single pass, return relative path for x3d // USED in lwir
clt_parameters,
colorProcParameters,
rgbParameters,
name,
scanIndex,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
}
// final int tilesX = tp.getTilesX();
// final int tilesY = tp.getTilesY();
final int transform_size =clt_parameters.transform_size;
CLTPass3d scan = tp.clt_3d_passes.get(scanIndex);
Rectangle texture_woi_pix = new Rectangle(); // in pixels
float [][] texture_img = GetTextureGPU( // returns texture
clt_parameters, // CLTParameters clt_parameters,
texture_woi_pix, // Rectangle texture_woi, // = new Rectangle();
scan.disparity, // double [][] disparity_array, // [tilesY][tilesX]
scan.getTextureSelection(), // bgnd_tiles_grown2, // boolean [] selection,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
// for now - use just RGB. Later add option for RGBA
float [][] texture_rgb = {texture_img[0],texture_img[1],texture_img[2]};
float [][] texture_rgba = {texture_img[0],texture_img[1],texture_img[2],texture_img[3]};
float [][] texture_rgbx = ((clt_parameters.alpha1 > 0)? texture_rgba: texture_rgb);
scan.texture_bounds = new Rectangle(
texture_woi_pix.x/transform_size,
texture_woi_pix.y/transform_size,
texture_woi_pix.width/transform_size,
texture_woi_pix.height/transform_size);
scan.selected = scan.getTextureSelection().clone(); // null
ImagePlus imp_texture_cluster = linearStackToColor(
clt_parameters,
colorProcParameters,
rgbParameters,
name+"-texture", // String name,
"", //String suffix, // such as disparity=...
true, // toRGB,
!this.correctionsParameters.jpeg, // boolean bpp16, // 16-bit per channel color mode for result
true, // boolean saveShowIntermediate, // save/show if set globally
false, //true, // boolean saveShowFinal, // save/show result (color image?)
texture_rgbx,
scan.texture_bounds.width * transform_size, // tilesX * clt_parameters.transform_size,
scan.texture_bounds.height * transform_size, // tilesY * clt_parameters.transform_size,
1.0, // double scaleExposure, // is it needed?
debugLevel);
String path= correctionsParameters.selectX3dDirectory(
//TODO: Which one to use - name or this.image_name ?
correctionsParameters.getModelName(this.image_name), // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.x3dModelVersion,
true, // smart,
true); //newAllowed, // save
// only show/save original size if debug or debug_filters)
eyesisCorrections.saveAndShow(
imp_texture_cluster,
path,
correctionsParameters.png,
clt_parameters.show_textures,
-1); // jpegQuality){// <0 - keep current, 0 - force Tiff, >0 use for JPEG
scan.is_measured = true; // should it be here?
scan.is_combo = false;
return imp_texture_cluster.getTitle()+".png"; // imp_texture_cluster;
}
public void setPassAvgRBGA( // get image from a single pass, return relative path for x3d // USED in lwir
CLTParameters clt_parameters,
int scanIndex,
int threadsMax, // maximal number of threads to launch
boolean updateStatus,
int debugLevel)
{
if ((gpuQuad != null) && (isAux()?clt_parameters.gpu_use_aux : clt_parameters.gpu_use_main)) {
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
CLTPass3d scan = tp.clt_3d_passes.get(scanIndex);
double [] disparity = scan.getDisparity();
double [] strength = scan.getStrength();
boolean [] selection = null; // scan.getSelected();
if (selection == null) {
selection = new boolean[tilesX*tilesY];
for (int nTile = 0; nTile < selection.length; nTile++) {
selection[nTile] = !Double.isNaN(disparity[nTile]) && (strength[nTile] > 0.0);
}
scan.setSelected(selection);
}
if ((scan.disparity == null) || (scan.tile_op == null)) {
int d = ImageDtt.setImgMask(0, 0xf); // no correlations
d = ImageDtt.setForcedDisparity(d,true);
scan.setTileOpDisparity(
d,
scan.getSelected(), // boolean [] selection,
scan.getDisparity()); // double [] disparity)
}
scan.texture_tiles = getTextureTilesGPU( // returns texture tiles, as with CPU
clt_parameters, // CLTParameters clt_parameters,
scan.tile_op, // int [][] tile_op,
scan.disparity, // double [][] disparity_array, // [tilesY][tilesX]
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
}
super.setPassAvgRBGA( // get image from a single pass, return relative path for x3d // USED in lwir
clt_parameters,
scanIndex,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
}
/*
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
final int transform_size =clt_parameters.transform_size;
CLTPass3d scan = tp.clt_3d_passes.get(scanIndex);
Rectangle texture_woi = new Rectangle();
// need to set tasks first!
float [][] texture_img = GetTextureGPU( // returns texture
clt_parameters, // CLTParameters clt_parameters,
texture_woi, // Rectangle texture_woi, // = new Rectangle();
scan.disparity, // double [][] disparity_array, // [tilesY][tilesX]
scan.getTextureSelection(), // bgnd_tiles_grown2, // boolean [] selection,
threadsMax, // final int threadsMax, // maximal number of threads to launch
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
// for now - use just RGB. Later add option for RGBA
float [][] texture_rgb = {texture_img[0],texture_img[1],texture_img[2]};
float [][] texture_rgba = {texture_img[0],texture_img[1],texture_img[2],texture_img[3]};
float [][] texture_rgbx = ((clt_parameters.alpha1 > 0)? texture_rgba: texture_rgb);
scan.texture_bounds = new Rectangle(
texture_woi.x * transform_size,
texture_woi.y * transform_size,
texture_woi.width * transform_size,
texture_woi.height * transform_size);
scan.selected = scan.getTextureSelection().clone();
int numTiles = tilesX * tilesY;
int num_layers = texture_rgbx.length; // here only 3/4
double [][] tileTones = new double [num_layers][numTiles];
double [] scales = new double [num_layers];
for (int n = 0; n < num_layers; n++){
if (n < 3) scales[n] = 1.0/255.0; // R,B,G
else if (n == 3) scales[n] = 1.0; //alpha
else if (n < 8) scales[n] = 1.0; // ports 0..3
else scales[n] = 1.0/255.0; // RBG rms, in 1/255 units, but small
}
int tx0 = scan.texture_bounds.x;
int ty0 = scan.texture_bounds.y;
int tw = scan.texture_bounds.width;
int th = scan.texture_bounds.height;
int text_step = transform_size * tw;
for (int ty = ty0; ty < (ty0 + th); ty++) {
for (int tx = tx0; tx < (tx0 + tw); tx++) {
int text_start = ((ty - ty0) * transform_size * tw + (tx-tx0)) * transform_size;
double s = 0.0;
for (int n = 0; n < num_layers; n++) {
for (int i = 0; i < transform_size; i++) {
for (int j = 0; j < transform_size; j++) {
s += texture_rgbx[n][text_start + i * text_step + j];
}
}
tileTones[n][ty * tilesX + tx] = s * scales[n] /(transform_size * transform_size);
}
}
}
scan.setTilesRBGA(tileTones);
(new ShowDoubleFloatArrays()).showArrays( // out of boundary 15
tileTones,
tilesX,
tilesY,
true,
image_name+sAux()+"-TileTones");
}
*/
public float [][] GetTextureGPU( // returns texture
CLTParameters clt_parameters,
Rectangle texture_woi_pix, // = new Rectangle(); in pixels!
double [][] disparity_array, // [tilesY][tilesX]
boolean [] selection,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
int d = ImageDtt.setImgMask(0, 0xf);
d = ImageDtt.setForcedDisparity(d,true);
int [][] tile_op = new int [tilesY][tilesX];
int indx = 0;
if (selection != null) {
for (int ty = 0; ty < tilesY; ty++) {
for (int tx = 0; tx < tilesX; tx++) {
if (selection[indx++]) {
tile_op[ty][tx] = d;
}
}
}
} else {
for (int ty = 0; ty < tilesY; ty++) {
for (int tx = 0; tx < tilesX; tx++) {
tile_op[ty][tx] = d;
}
}
}
/*
double [][] shiftXY = new double [4][2];
// not used
if (!clt_parameters.fine_corr_ignore) {
double [][] shiftXY0 = {
{clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0},
{clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1},
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}};
shiftXY = shiftXY0;
}
*/
ImageDtt image_dtt = new ImageDtt(
clt_parameters.transform_size,
isMonochrome(),
isLwir(),
clt_parameters.getScaleStrength(isAux()),
gpuQuad);
double z_correction = clt_parameters.z_correction;
if (clt_parameters.z_corr_map.containsKey(image_name)){ // not used in lwir
z_correction +=clt_parameters.z_corr_map.get(image_name);
}
final double disparity_corr = (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
float [][] texture_img = new float [isMonochrome()?2:4][];
image_dtt.clt_aberrations_quad_corr_GPU( // USED in LWIR
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
//// Uses quadCLT from gpuQuad
// correlation results - final and partial
null, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [type][tilesY][tilesX] should be set by caller
// types: 0 - selected correlation (product+offset), 1 - sum
null, // clt_corr_partial,// [tilesY][tilesX][quad]color][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [tilesY][tilesX] should be set by caller
// When clt_mismatch is non-zero, no far objects extraction will be attempted
null, // clt_mismatch, // [12][tilesY * tilesX] // ***** transpose unapplied ***** ?. null - do not calculate
// values in the "main" directions have disparity (*_CM) subtracted, in the perpendicular - as is
null, // disparity_map, // [8][tilesY][tilesX], only [6][] is needed on input or null - do not calculate
// last 2 - contrast, avg/ "geometric average)
0, // disparity_modes, // bit mask of disparity_map slices to calculate/return
null, // final double [][][][] texture_tiles, // compatible with the CPU ones
texture_img, // texture_img, // null or [3][] (RGB) or [4][] RGBA
texture_woi_pix, // texture_woi_pix, // null or generated texture location/size
null, // iclt_fimg, // will return quad images or null to skip, use quadCLT.linearStackToColor
// new parameters, will replace some other?
// clt_parameters.getFatZero(isMonochrome()), // final double gpu_fat_zero, // clt_parameters.getGpuFatZero(is_mono);absolute == 30.0\
clt_parameters.gpu_corr_scale, // gpu_corr_scale, // 0.75; // reduce GPU-generated correlation values
clt_parameters.getGpuFatZero(isMonochrome()), // final double gpu_fat_zero, // clt_parameters.getGpuFatZero(is_mono);absolute == 30.0\
clt_parameters.gpu_sigma_r, // 0.9, 1.1
clt_parameters.gpu_sigma_b, // 0.9, 1.1
clt_parameters.gpu_sigma_g, // 0.6, 0.7
clt_parameters.gpu_sigma_m, // = 0.4; // 0.7;
(isMonochrome()? 1.0 : clt_parameters.gpu_sigma_rb_corr), // final double gpu_sigma_rb_corr, // = 0.5; // apply LPF after accumulating R and B correlation before G, monochrome ? 1.0 : gpu_sigma_rb_corr;
clt_parameters.gpu_sigma_corr, // = 0.9;gpu_sigma_corr_m
image_dtt.transform_size - 1, // clt_parameters.gpu_corr_rad, // = transform_size - 1 ?
clt_parameters.corr_red, // +used
clt_parameters.corr_blue, // +used
clt_parameters.max_corr_radius,// 3.9;
clt_parameters.corr_mode, // Correlation mode: 0 - integer max, 1 - center of mass, 2 - polynomial
clt_parameters.min_shot, // 10.0; // Do not adjust for shot noise if lower than
clt_parameters.scale_shot, // 3.0; // scale when dividing by sqrt ( <0 - disable correction)
clt_parameters.diff_sigma, // 5.0;//RMS difference from average to reduce weights (~ 1.0 - 1/255 full scale image)
clt_parameters.diff_threshold, // 5.0; // RMS difference from average to discard channel (~ 1.0 - 1/255 full scale image)
clt_parameters.diff_gauss, // true; // when averaging images, use gaussian around average as weight (false - sharp all/nothing)
clt_parameters.min_agree, // 3.0; // minimal number of channels to agree on a point (real number to work with fuzzy averages)
clt_parameters.dust_remove, // Do not reduce average weight when only one image differes much from the average
geometryCorrection, // final GeometryCorrection geometryCorrection,
null, // final GeometryCorrection geometryCorrection_main, // if not null correct this camera (aux) to the coordinates of the main
clt_parameters.clt_window,
disparity_corr, // final double disparity_corr, // disparity at infinity
clt_parameters.tileX, // final int debug_tileX,
clt_parameters.tileY, // final int debug_tileY,
threadsMax,
debugLevel);
return texture_img;
}
public double [][][][] getTextureTilesGPU( // returns texture tiles, as with CPU
CLTParameters clt_parameters,
int [][] tile_op,
double [][] disparity_array, // [tilesY][tilesX]
// boolean [] selection, // null - all
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
/*
int d = ImageDtt.setImgMask(0, 0xf);
d = ImageDtt.setForcedDisparity(d,true);
int [][] tile_op = new int [tilesY][tilesX];
int indx = 0;
if (selection != null) {
for (int ty = 0; ty < tilesY; ty++) {
for (int tx = 0; tx < tilesX; tx++) {
if (selection[indx++]) {
tile_op[ty][tx] = d;
}
}
}
} else {
for (int ty = 0; ty < tilesY; ty++) {
for (int tx = 0; tx < tilesX; tx++) {
tile_op[ty][tx] = d;
}
}
}
*/
/*
double [][] shiftXY = new double [4][2];
// not used
if (!clt_parameters.fine_corr_ignore) {
double [][] shiftXY0 = {
{clt_parameters.fine_corr_x_0,clt_parameters.fine_corr_y_0},
{clt_parameters.fine_corr_x_1,clt_parameters.fine_corr_y_1},
{clt_parameters.fine_corr_x_2,clt_parameters.fine_corr_y_2},
{clt_parameters.fine_corr_x_3,clt_parameters.fine_corr_y_3}};
shiftXY = shiftXY0;
}
*/
ImageDtt image_dtt = new ImageDtt(
clt_parameters.transform_size,
isMonochrome(),
isLwir(),
clt_parameters.getScaleStrength(isAux()),
gpuQuad);
double z_correction = clt_parameters.z_correction;
if (clt_parameters.z_corr_map.containsKey(image_name)){ // not used in lwir
z_correction +=clt_parameters.z_corr_map.get(image_name);
}
final double disparity_corr = (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
double [][][][] texture_tiles = new double [tilesY][tilesX][][];
image_dtt.clt_aberrations_quad_corr_GPU( // USED in LWIR
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
//// Uses quadCLT from gpuQuad
// correlation results - final and partial
null, // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [type][tilesY][tilesX] should be set by caller
// types: 0 - selected correlation (product+offset), 1 - sum
null, // clt_corr_partial,// [tilesY][tilesX][quad]color][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// [tilesY][tilesX] should be set by caller
// When clt_mismatch is non-zero, no far objects extraction will be attempted
null, // clt_mismatch, // [12][tilesY * tilesX] // ***** transpose unapplied ***** ?. null - do not calculate
// values in the "main" directions have disparity (*_CM) subtracted, in the perpendicular - as is
null, // disparity_map, // [8][tilesY][tilesX], only [6][] is needed on input or null - do not calculate
// last 2 - contrast, avg/ "geometric average)
0, // disparity_modes, // bit mask of disparity_map slices to calculate/return
texture_tiles, // final double [][][][] texture_tiles, // compatible with the CPU ones
null, // texture_img, // null or [3][] (RGB) or [4][] RGBA
null, // texture_woi, // null or generated texture location/size
null, // iclt_fimg, // will return quad images or null to skip, use quadCLT.linearStackToColor
// new parameters, will replace some other?
// clt_parameters.getFatZero(isMonochrome()), // final double gpu_fat_zero, // clt_parameters.getGpuFatZero(is_mono);absolute == 30.0\
clt_parameters.gpu_corr_scale, // gpu_corr_scale, // 0.75; // reduce GPU-generated correlation values
clt_parameters.getGpuFatZero(isMonochrome()), // final double gpu_fat_zero, // clt_parameters.getGpuFatZero(is_mono);absolute == 30.0\
clt_parameters.gpu_sigma_r, // 0.9, 1.1
clt_parameters.gpu_sigma_b, // 0.9, 1.1
clt_parameters.gpu_sigma_g, // 0.6, 0.7
clt_parameters.gpu_sigma_m, // = 0.4; // 0.7;
(isMonochrome()? 1.0 : clt_parameters.gpu_sigma_rb_corr), // final double gpu_sigma_rb_corr, // = 0.5; // apply LPF after accumulating R and B correlation before G, monochrome ? 1.0 : gpu_sigma_rb_corr;
clt_parameters.gpu_sigma_corr, // = 0.9;gpu_sigma_corr_m
image_dtt.transform_size - 1, // clt_parameters.gpu_corr_rad, // = transform_size - 1 ?
clt_parameters.corr_red, // +used
clt_parameters.corr_blue, // +used
clt_parameters.max_corr_radius,// 3.9;
clt_parameters.corr_mode, // Correlation mode: 0 - integer max, 1 - center of mass, 2 - polynomial
clt_parameters.min_shot, // 10.0; // Do not adjust for shot noise if lower than
clt_parameters.scale_shot, // 3.0; // scale when dividing by sqrt ( <0 - disable correction)
clt_parameters.diff_sigma, // 5.0;//RMS difference from average to reduce weights (~ 1.0 - 1/255 full scale image)
clt_parameters.diff_threshold, // 5.0; // RMS difference from average to discard channel (~ 1.0 - 1/255 full scale image)
clt_parameters.diff_gauss, // true; // when averaging images, use gaussian around average as weight (false - sharp all/nothing)
clt_parameters.min_agree, // 3.0; // minimal number of channels to agree on a point (real number to work with fuzzy averages)
clt_parameters.dust_remove, // Do not reduce average weight when only one image differes much from the average
geometryCorrection, // final GeometryCorrection geometryCorrection,
null, // final GeometryCorrection geometryCorrection_main, // if not null correct this camera (aux) to the coordinates of the main
clt_parameters.clt_window,
disparity_corr, // final double disparity_corr, // disparity at infinity
clt_parameters.tileX, // final int debug_tileX,
clt_parameters.tileY, // final int debug_tileY,
threadsMax,
debugLevel);
return texture_tiles;
}
public CLTPass3d CLTMeasureTextures( // perform single pass according to prepared tiles operations and disparity // not used in lwir
CLTParameters clt_parameters,
final int scanIndex,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
if ((gpuQuad == null) || !(isAux()?clt_parameters.gpu_use_aux : clt_parameters.gpu_use_main)) {
return super.CLTMeasureTextures( // measure background // USED in lwir
clt_parameters,
scanIndex,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
}
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
CLTPass3d scan = tp.clt_3d_passes.get(scanIndex);
// maybe just rely on tile_op ?
boolean [] text_sel = new boolean [tilesX * tilesY];
for (int ty = 0; ty < tilesY; ty++) {
for (int tx = 0; tx < tilesX; tx++) {
text_sel[ty*tilesX + tx] = scan.tile_op[ty][tx] != 0;
}
}
// scan.setTextureSelection(scan.selected); // .clone(); GPU will measure when the texture will be requested
scan.setTextureSelection(text_sel); // .clone(); GPU will measure when the texture will be requested
// scan.is_measured = true; // but no disparity map/textures
scan.is_combo = false;
return scan; // what about processed and other attributes?
}
}
......@@ -1574,7 +1574,6 @@ public class QuadCLTCPU {
if (equirectangularParameters.clearAllMaps) eyesisCorrections.pixelMapping.deleteEquirectangularMapAll(srcChannel); // save memory? //removeUnusedSensorData - no, use equirectangular specific settings
}
//pixelMapping
// Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing image "+(iImage+1)+" (of "+fileIndices.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
......@@ -2262,7 +2261,6 @@ public class QuadCLTCPU {
if (equirectangularParameters.clearAllMaps) eyesisCorrections.pixelMapping.deleteEquirectangularMapAll(srcChannel); // save memory? //removeUnusedSensorData - no, use equirectangular specific settings
}
//pixelMapping
// Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing image "+(iImage+1)+" (of "+fileIndices.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
......@@ -2863,7 +2861,6 @@ public class QuadCLTCPU {
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
// Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+setNames.size()+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
......@@ -3688,7 +3685,6 @@ public class QuadCLTCPU {
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
//Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+set_channels.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
......@@ -3770,7 +3766,6 @@ public class QuadCLTCPU {
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
//Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+set_channels.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
......@@ -3851,7 +3846,6 @@ public class QuadCLTCPU {
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
//Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+set_channels.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
......@@ -4221,7 +4215,7 @@ public class QuadCLTCPU {
final int tilesY = tp.getTilesY();
if (clt_parameters.correlate){ // true
clt_corr_combo = new double [ImageDtt.TCORR_TITLES.length][tilesY][tilesX][];
clt_corr_combo = new double [ImageDtt.TCORR_TITLES.length][tilesY][tilesX][]; // will it work???
texture_tiles = new double [tilesY][tilesX][][]; // ["RGBA".length()][];
for (int i = 0; i < tilesY; i++){
for (int j = 0; j < tilesX; j++){
......@@ -6132,7 +6126,6 @@ public class QuadCLTCPU {
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
//Runtime.getRuntime().gc();
if (debugLevel >-1) System.out.println("Processing set "+(nSet+1)+" (of "+fileIndices.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
......@@ -6732,6 +6725,13 @@ public class QuadCLTCPU {
return null;
}
this.startStepTime=System.nanoTime();
setPassAvgRBGA( // get image from a single pass, return relative path for x3d // USED in lwir
clt_parameters, // CLTParameters clt_parameters,
tp.clt_3d_passes.size() - 1, // int scanIndex,
threadsMax, // int threadsMax, // maximal number of threads to launch
updateStatus, // boolean updateStatus,
debugLevel); // int debugLevel)
double [][] assign_dbg = tp.assignTilesToSurfaces(
clt_parameters,
geometryCorrection,
......@@ -7136,26 +7136,34 @@ public class QuadCLTCPU {
//max_expand
String name = (String) imp_quad[0].getProperty("name");
CLTPass3d bgnd_data = CLTBackgroundMeas( // measure background
// should create data for the macro! (diff, rgb)
CLTPass3d bgnd_data = CLTBackgroundMeas( // measure background - both CPU and GPU (remove textures from GPU)
clt_parameters,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
tp.clt_3d_passes.add(bgnd_data);
// if (show_init_refine)
// if ((debugLevel > -2) && clt_parameters.show_first_bg) {
if ((debugLevel > -3) && clt_parameters.show_first_bg) {
if ((debugLevel > -2) && clt_parameters.show_first_bg) {
// if ((debugLevel > -3) && clt_parameters.show_first_bg) {
tp.showScan(
tp.clt_3d_passes.get(0), // CLTPass3d scan,
"bgnd_data-"+tp.clt_3d_passes.size());
}
//TODO: Move away from here?
boolean no_image_save = true;
boolean no_image_save = false; // Restore? true;
boolean [] bgmask = getBackgroundImageMasks(
clt_parameters,
name, // .getTitle(), //String name=(String) imp_src.getProperty("name");
ImageDtt.DISPARITY_INDEX_CM, // index of disparity value in disparity_map == 2 (0,2 or 4)
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
ImagePlus imp_bgnd = getBackgroundImage(
no_image_save, // boolean no_image,
ImagePlus imp_bgnd_int = getBackgroundImage(
bgmask, // boolean [] bgnd_tiles,
clt_parameters,
colorProcParameters,
rgbParameters,
......@@ -7164,10 +7172,22 @@ public class QuadCLTCPU {
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
// imp_bgnd_int.show();
// if (debugLevel > -100) {
// return null;
// }
// resize for backdrop here!
ImagePlus imp_bgnd = finalizeBackgroundImage( // USED in lwir
imp_bgnd_int, // ImagePlus imp_texture_bgnd,
no_image_save, // boolean no_image_save,
clt_parameters, // CLTParameters clt_parameters,
name, // String name,
debugLevel); // int debugLevel)
// imp_bgnd.show();
bgnd_data.texture = (imp_bgnd == null)? null: ( imp_bgnd.getTitle()+ (clt_parameters.black_back? ".jpeg" : ".png"));
......@@ -7301,7 +7321,6 @@ public class QuadCLTCPU {
"macro_combo-"+mtp.clt_3d_passes.size());
}
// ArrayList <CLTPass3d>
new_meas = mc.prepareMeasurementsFromMacro(
mtp.clt_3d_passes, // final ArrayList <CLTPass3d> macro_passes, // macro correlation measurements
......@@ -7384,7 +7403,7 @@ public class QuadCLTCPU {
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_refinePassSetup-"+tp.clt_3d_passes.size());
CLTMeasure( // perform single pass according to prepared tiles operations and disparity
CLTMeasureCorr( // perform single pass according to prepared tiles operations and disparity
// image_data, // first index - number of image in a quad
// saturation_imp, //final boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
......@@ -7431,7 +7450,7 @@ public class QuadCLTCPU {
}
// add new scan from macro
tp.clt_3d_passes.add(from_macro_pass);
CLTMeasure( // perform single pass according to prepared tiles operations and disparity
CLTMeasureCorr( // perform single pass according to prepared tiles operations and disparity
// image_data, // first index - number of image in a quad
// saturation_imp, //final boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
......@@ -7502,7 +7521,7 @@ public class QuadCLTCPU {
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"after_refinePassSetup-"+tp.clt_3d_passes.size());
CLTMeasure( // perform single pass according to prepared tiles operations and disparity
CLTMeasureCorr( // perform single pass according to prepared tiles operations and disparity
// image_data, // first index - number of image in a quad
// saturation_imp, //final boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
......@@ -8927,7 +8946,7 @@ public class QuadCLTCPU {
// num_extended = numLeftRemoved[0];
CLTMeasure( // perform single pass according to prepared tiles operations and disparity BUG: gets with .disparity==null
CLTMeasureCorr( // perform single pass according to prepared tiles operations and disparity BUG: gets with .disparity==null
// image_data, // first index - number of image in a quad
// saturation_imp, //final boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
......@@ -9124,6 +9143,8 @@ public class QuadCLTCPU {
// for (int i = 0; i < bgnd_sel.length; i++) if (bgnd_sel[i]) num_bgnd++;
// if (num_bgnd >= clt_parameters.min_bgnd_tiles) { // TODO: same for the backdrop too
// double infinity_disparity = geometryCorrection.getDisparityFromZ(clt_parameters.infinityDistance);
//TODO make it w/o need for bgndScan.texture as GPU will calculate texture right before output
//use selection? or texture_selection instead?
if (bgndScan.texture != null) { // TODO: same for the backdrop too
if (clt_parameters.infinityDistance > 0.0){ // generate background as a billboard
// grow selection, then grow once more and create border_tiles
......@@ -9131,32 +9152,38 @@ public class QuadCLTCPU {
boolean [] bg_sel_backup = bgndScan.getSelected().clone();
boolean [] bg_border_backup = (bgndScan.getBorderTiles() == null) ? null: bgndScan.getBorderTiles().clone();
boolean [] bg_selected = bgndScan.getSelected();
// tp.growTiles(
// 2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
// bg_selected,
// null); // prohibit
boolean [] border_tiles = bg_selected.clone();
tp.growTiles(
2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
bg_selected,
null); // prohibit
// for (int)
for (int i = 0; i < border_tiles.length; i++){
border_tiles[i] = !border_tiles[i] && bg_selected[i];
}
// update texture_tiles (remove what is known not to be background
if (bgndScan.texture_tiles != null) { // for CPU
for (int ty = 0; ty < tilesY; ty++){
for (int tx = 0; tx < tilesX; tx++){
if (!bg_selected[tx + tilesX*ty]){
bgndScan.texture_tiles[ty][tx] = null;
bgndScan.texture_tiles[ty][tx] = null; //
}
}
}
} else {// for GPU
for (int i = 0; i < bg_selected.length; i++) {
if (!bg_selected[i]) {
bgndScan.setTextureSelection(i,false);
}
}
}
//TODO2020: set texture_selection
bgndScan.setBorderTiles(border_tiles);
// limit tile_op to selection?
// updates selection from non-null texture tiles
String texturePath = getPassImage( // get image from a single pass
String texturePath = getPassImage( // get image from a single pass - both CPU and GPU
clt_parameters,
colorProcParameters,
rgbParameters,
......@@ -9205,14 +9232,13 @@ public class QuadCLTCPU {
}
}
// With GPU - do nothing here or copy selected -> texture_selection?
for (int scanIndex = next_pass; scanIndex < tp.clt_3d_passes.size(); scanIndex++){
if (debugLevel > 0){
System.out.println("FPGA processing scan #"+scanIndex);
}
/// CLTPass3d scan =
/*
CLTMeasure( // perform single pass according to prepared tiles operations and disparity
// image_data, // first index - number of image in a quad
clt_parameters,
scanIndex,
true, // final boolean save_textures,
......@@ -9220,6 +9246,13 @@ public class QuadCLTCPU {
threadsMax, // maximal number of threads to launch
updateStatus,
batch_mode ? -5: debugLevel);
*/
CLTMeasureTextures( // has GPU version - will just copy selection
clt_parameters,
scanIndex,
threadsMax, // maximal number of threads to launch
updateStatus,
batch_mode ? -5: debugLevel);
}
......@@ -9398,20 +9431,20 @@ public class QuadCLTCPU {
}
public ImagePlus getBackgroundImage( // USED in lwir
boolean no_image_save,
// public ImagePlus getBackgroundImage( // USED in lwir
public boolean[] getBackgroundImageMasks( // USED in lwir
// boolean no_image_save,
CLTParameters clt_parameters,
ColorProcParameters colorProcParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
// ColorProcParameters colorProcParameters,
// EyesisCorrectionParameters.RGBParameters rgbParameters,
String name,
int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
// int strength_index, // index of strength data in disparity map ==6
int threadsMax, // maximal number of threads to launch
boolean updateStatus,
int debugLevel
)
{
final boolean new_mode = false;
// final boolean new_mode = false;
boolean dbg_gpu_transition = true;
......@@ -9420,11 +9453,11 @@ public class QuadCLTCPU {
ShowDoubleFloatArrays sdfa_instance = null;
if ((clt_parameters.debug_filters && (debugLevel > -1)) || dbg_gpu_transition)
// if ((debugLevel > -1))
if ((debugLevel > -1))
sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging?
CLTPass3d bgnd_data = tp.clt_3d_passes.get(0);
double [][][][] texture_tiles = bgnd_data.texture_tiles;
// double [][][][] texture_tiles = bgnd_data.texture_tiles;
boolean [] bgnd_tiles = tp.getBackgroundMask( // which tiles do belong to the background
clt_parameters.bgnd_range, // disparity range to be considered background
......@@ -9468,9 +9501,9 @@ public class QuadCLTCPU {
null); // prohibit
// hacking - grow bgnd texture even more, without changing selection
boolean [] bgnd_tiles_grown2 = bgnd_tiles_grown.clone(); // only these have non 0 alpha
bgnd_data.selected = bgnd_tiles_grown; // selected for background w/o extra transparent layer
boolean [] bgnd_tiles_grown2 = bgnd_tiles_grown.clone(); // only these have non 0 alpha
tp.growTiles(
2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
bgnd_tiles_grown2,
......@@ -9488,13 +9521,48 @@ public class QuadCLTCPU {
}
sdfa_instance.showArrays(dbg_img, tilesX, tilesY, true, "strict_grown",titles);
}
// not here - will be set/calculated for GPU only
/// bgnd_data.setTextureSelection(bgnd_tiles_grown2); // selected for background w/o extra transparent layer
return bgnd_tiles ;
}
public ImagePlus getBackgroundImage( // USED in lwir
boolean [] bgnd_tiles,
CLTParameters clt_parameters,
ColorProcParameters colorProcParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
String name,
int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
int threadsMax, // maximal number of threads to launch
boolean updateStatus,
int debugLevel
) {
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
final boolean new_mode = false;
int num_bgnd = 0;
CLTPass3d bgnd_data = tp.clt_3d_passes.get(0);
double [][][][] texture_tiles = bgnd_data.texture_tiles;
double [][][][] texture_tiles_bgnd = new double[tilesY][tilesX][][];
double [] alpha_zero = new double [4*clt_parameters.transform_size*clt_parameters.transform_size];
int alpha_index = 3;
boolean [] bgnd_tiles_grown = bgnd_tiles.clone(); // only these have non 0 alpha
tp.growTiles(
2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
bgnd_tiles,
null); // prohibit
boolean [] bgnd_tiles_grown2 = bgnd_tiles_grown.clone(); // only these have non 0 alpha
tp.growTiles(
2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
bgnd_tiles_grown2,
null); // prohibit
for (int i = 0; i < alpha_zero.length; i++) alpha_zero[i]=0.0;
if (new_mode) {
// Seems to be wrong for the second?
if (new_mode) { // not used
for (int tileY = 0; tileY < tilesY; tileY++){
for (int tileX = 0; tileX < tilesX; tileX++){
texture_tiles_bgnd[tileY][tileX]= null;
......@@ -9531,6 +9599,8 @@ public class QuadCLTCPU {
if (num_bgnd < clt_parameters.min_bgnd_tiles){
return null; // no background to generate // not used in lwir
}
ImageDtt image_dtt = new ImageDtt(
clt_parameters.transform_size,
isMonochrome(),
......@@ -9575,6 +9645,18 @@ public class QuadCLTCPU {
debugLevel);
// resize for backdrop here!
// public double getFOVPix(){ // get ratio of 1 pixel X/Y to Z (distance to object)
return imp_texture_bgnd;
}
public ImagePlus finalizeBackgroundImage( // USED in lwir
ImagePlus imp_texture_bgnd,
boolean no_image_save,
CLTParameters clt_parameters,
String name,
int debugLevel) {
ImagePlus imp_texture_bgnd_ext = resizeForBackdrop(
imp_texture_bgnd,
clt_parameters.black_back, // boolean fillBlack,
......@@ -9584,7 +9666,6 @@ public class QuadCLTCPU {
//TODO: Which one to use - name or this.image_name ?
correctionsParameters.getModelName(this.image_name), // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.x3dModelVersion,
// name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
true, // smart,
true); //newAllowed, // save
// only show/save original size if debug or debug_filters)
......@@ -9610,7 +9691,7 @@ public class QuadCLTCPU {
public String getPassImage( // get image form a single pass, return relative path for x3d // USED in lwir
public String getPassImage( // get image from a single pass, return relative path for x3d // USED in lwir
CLTParameters clt_parameters,
ColorProcParameters colorProcParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
......@@ -9813,6 +9894,68 @@ public class QuadCLTCPU {
return imp_ext;
}
public ImagePlus resizeToFull(
int out_width,
int out_height,
int x0, // image offset-x pixels
int y0, // image offset-y pixels
ImagePlus imp,
boolean fillBlack,
boolean noalpha, // only with fillBlack, otherwise ignored
int debugLevel)
{
int width = imp.getWidth();
int height = imp.getHeight();
// int h_margin = (int) Math.round((backdropPixels - width)/2);
// int v_margin = (int) Math.round((backdropPixels - height)/2);
// int width2 = width + 2 * h_margin;
// int height2 = height + 2 * v_margin;
int [] src_pixels = (int []) imp.getProcessor().getPixels();
int [] pixels = new int [out_width * out_height];
int black = noalpha ? 0 : 0xff000000;
int mask = noalpha ? 0xffffff : 0xffffffff;
if (fillBlack) {
for (int i = 0; i < pixels.length; i++){
pixels[i] = black;
}
}
int indx = 0;
int offset = y0 * out_width + x0; // v_margin * width2 + h_margin;
if (fillBlack) {
for (int i = 0; i < height; i++){
for (int j = 0; j < width; j++){
int a = (src_pixels[indx] >> 24) & 0xff;
if (a == 255) {
pixels[offset+ i * out_width + j] = src_pixels[indx] & mask;
} else if (a == 0) {
pixels[offset+ i * out_width + j] = black;
} else {
int r = (src_pixels[indx] >> 16) & 0xff; //' maybe - swap with b?
int g = (src_pixels[indx] >> 8) & 0xff;
int b = (src_pixels[indx] >> 0) & 0xff;
r = (r * a) / 255;
g = (g * a) / 255;
b = (b * a) / 255;
pixels[offset+ i * out_width + j] = black | (r << 16) | (g << 8) | b;
}
indx++;
}
}
} else { // not used in lwir
for (int i = 0; i < height; i++){
for (int j = 0; j < width; j++){
pixels[offset+ i * out_width + j] = src_pixels[indx++];
}
}
}
ColorProcessor cp=new ColorProcessor(out_width,out_height);
cp.setPixels(pixels);
ImagePlus imp_ext=new ImagePlus(imp.getTitle()+"-ext",cp);
return imp_ext;
}
//[tp.tilesY][tp.tilesX]["RGBA".length()][]
//linearStackToColor
......@@ -9869,7 +10012,7 @@ public class QuadCLTCPU {
}
}
}
clt_corr_combo = null; // Something is broke in old code, tries to use color==3 ==colors.weights.length
image_dtt.clt_aberrations_quad_corr(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
......@@ -9961,6 +10104,23 @@ public class QuadCLTCPU {
return scan_rslt;
}
public CLTPass3d CLTMeasureTextures( // perform single pass according to prepared tiles operations and disparity // not used in lwir
CLTParameters clt_parameters,
final int scanIndex,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
return CLTMeasure( // measure background // USED in lwir
clt_parameters,
scanIndex,
true, // save_textures,
false, // save_corr,
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
}
public CLTPass3d CLTMeasure( // perform single pass according to prepared tiles operations and disparity // not used in lwir
CLTParameters clt_parameters,
final int scanIndex,
......@@ -9980,7 +10140,7 @@ public class QuadCLTCPU {
updateStatus, // final boolean updateStatus,
debugLevel); // final int debugLevel);
}
public CLTPass3d CLTMeasure( // perform single pass according to prepared tiles operations and disparity // not used in lwir
public CLTPass3d CLTMeasureCorr( // perform single pass according to prepared tiles operations and disparity // not used in lwir
CLTParameters clt_parameters,
final int scanIndex,
final boolean save_textures,
......@@ -10040,7 +10200,8 @@ public class QuadCLTCPU {
}
// undecided, so 2 modes of combining alpha - same as rgb, or use center tile only
double [][][][] clt_corr_combo = new double [ImageDtt.TCORR_TITLES.length][tilesY][tilesX][]; // will only be used inside?
double [][][][] clt_corr_combo = null; // new double [ImageDtt.TCORR_TITLES.length][tilesY][tilesX][]; // will only be used inside?
// broken clt_aberrations_quad_corr_new
if (debugLevel > -1){
int numTiles = 0;
for (int ty = 0; ty < tile_op.length; ty ++) for (int tx = 0; tx < tile_op[ty].length; tx ++){
......@@ -10176,7 +10337,7 @@ public class QuadCLTCPU {
int [][] tile_op = scan.tile_op;
double [][] disparity_array = scan.disparity;
// undecided, so 2 modes of combining alpha - same as rgb, or use center tile only
double [][][][] clt_corr_combo = new double [ImageDtt.TCORR_TITLES.length][tilesY][tilesX][]; // will only be used inside?
double [][][][] clt_corr_combo = null; // new double [ImageDtt.TCORR_TITLES.length][tilesY][tilesX][]; // will only be used inside?
if (debugLevel > -1){
int numTiles = 0;
for (int ty = 0; ty < tile_op.length; ty ++) for (int tx = 0; tx < tile_op[ty].length; tx ++){
......@@ -10904,6 +11065,14 @@ public class QuadCLTCPU {
} else continue; // if (correctionsParameters.clt_batch_surf)
if (correctionsParameters.clt_batch_assign) {
// prepare average RGBA for the last scan
setPassAvgRBGA( // get image from a single pass, return relative path for x3d // USED in lwir
clt_parameters, // CLTParameters clt_parameters,
tp.clt_3d_passes.size() - 1, // int scanIndex,
threadsMax, // int threadsMax, // maximal number of threads to launch
updateStatus, // boolean updateStatus,
debugLevelInner); // int debugLevel)
double [][] assign_dbg = tp.assignTilesToSurfaces(
clt_parameters,
geometryCorrection,
......@@ -11096,4 +11265,56 @@ public class QuadCLTCPU {
}
return true;
}
public void setPassAvgRBGA( // get image from a single pass, return relative path for x3d // USED in lwir
CLTParameters clt_parameters,
int scanIndex,
int threadsMax, // maximal number of threads to launch
boolean updateStatus,
int debugLevel)
{
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
// final int transform_size =clt_parameters.transform_size;
CLTPass3d scan = tp.clt_3d_passes.get(scanIndex);
double [][][][] texture_tiles = scan.texture_tiles;
if (texture_tiles == null) return;
int num_layers = 0;
for (int ty = 0; ty < tilesY; ty++){
if (texture_tiles[ty] != null){
for (int tx = 0; tx < tilesX; tx++){
if (texture_tiles[ty][tx] != null){
num_layers = texture_tiles[ty][tx].length;
break;
}
}
if (num_layers > 0) break;
}
if (num_layers > 0) break;
}
int numTiles = tilesX * tilesY;
double [] scales = new double [num_layers];
for (int n = 0; n < num_layers; n++){
if (n < 3) scales[n] = 1.0/255.0; // R,B,G
else if (n == 3) scales[n] = 1.0; //alpha
else if (n < 8) scales[n] = 1.0; // ports 0..3
else scales[n] = 1.0/255.0; // RBG rms, in 1/255 units, but small
}
double [][] tileTones = new double [num_layers][numTiles];
for (int ty = 0; ty < tilesY; ty++ ) if (texture_tiles[ty] != null){
for (int tx = 0; tx < tilesX; tx++ ) if (texture_tiles[ty][tx] != null) {
int indx = ty * tilesX + tx;
for (int n = 0; n < num_layers; n++) if (texture_tiles[ty][tx][n] != null){
double s = 0.0;
for (int i = 0; i < texture_tiles[ty][tx][n].length; i++){
s += texture_tiles[ty][tx][n][i];
}
s /= (texture_tiles[ty][tx][n].length/4); // overlapping tiles
s *= scales[n];
tileTones[n][indx] = s;
}
}
}
scan.setTilesRBGA(tileTones);
}
}
......@@ -4215,7 +4215,7 @@ public class TilePlanes {
if (world_xyz != null) {
double l2 = world_xyz[0]*world_xyz[0] + world_xyz[1]*world_xyz[1]+world_xyz[2]*world_xyz[2];
if (l2 < 0.5) {
if (debugLevel > -1) {
if (debugLevel > 0) { // -1
System.out.println("getWorldXYZ(): l2="+l2); // +" this=\n"+this.toString());
}
world_xyz = null;
......@@ -4317,7 +4317,7 @@ public class TilePlanes {
world_xyz = norm_xyz.times((xyz.transpose().times(norm_xyz).get(0,0))).getColumnPackedCopy();
double l2 = world_xyz[0]*world_xyz[0] + world_xyz[1]*world_xyz[1]+world_xyz[2]*world_xyz[2];
if (l2 < 0.5) {
if (debugLevel > -1) {
if (debugLevel > 0) { // -1
System.out.println("getWorldXYZ(): l2="+l2); // +" this=\n"+this.toString());
}
}
......
......@@ -269,6 +269,7 @@ public class TileProcessor {
* @param debugLevel debug level
* @return combined pass, contains same data as after the measurement of the actual one
*/
/*
public CLTPass3d combinePasses_old(
final ArrayList <CLTPass3d> passes,
final int firstPass,
......@@ -415,6 +416,7 @@ public class TileProcessor {
}
return combo_pass;
}
*/
/**
* When expanding over previously identified background (may be in error) remove tiles from the
......@@ -1293,7 +1295,11 @@ public class TileProcessor {
combo_pass.calc_disparity[nt] = pass.disparity_map[disparity_index][nt]/corr_magic_scale + pass.disparity[ty][tx];
combo_pass.strength[nt] = pass.disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][nt];
// Only copy for full disparity
for (int i = 0; i< ImageDtt.QUAD; i++) combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt] = pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt];
for (int i = 0; i< ImageDtt.QUAD; i++) {
if (pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i]!= null) {// do not copy empty
combo_pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt] = pass.disparity_map[ImageDtt.IMG_DIFF0_INDEX + i][nt];
}
}
if (copyDebug){
combo_pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt] = pass.disparity_map[ImageDtt.DISPARITY_INDEX_CM][nt];
......@@ -3419,9 +3425,7 @@ public class TileProcessor {
if (debugLevel > -1)
sdfa_instance = new ShowDoubleFloatArrays(); // just for debugging?
// boolean [] new_tiles = new boolean [tilesY * tilesX]; // grow selection by 1 tile over non-background?
CLTPass3d bgnd_data = clt_3d_passes.get(0);
// double [][][][] texture_tiles = bgnd_data.texture_tiles;
double [][] disparity_map= bgnd_data.disparity_map;
for (int tileY = 0; tileY < tilesY; tileY++){
for (int tileX = 0; tileX < tilesX; tileX++){
......@@ -5809,7 +5813,7 @@ public class TileProcessor {
}
// show testure_tiles
double [][][][] texture_tiles = scan_prev.getTextureTiles();
double [][][][] texture_tiles = scan_prev.getTextureTiles(); // each is null, manually set texture_tiles - null
ImageDtt image_dtt = new ImageDtt(
clt_parameters.transform_size,
isMonochrome(),
......@@ -5831,9 +5835,9 @@ public class TileProcessor {
String [] rgba_weights_titles = {"red","blue","green","alpha","port0","port1","port2","port3","r-rms","b-rms","g-rms","w-rms"};
String name = scan_prev.getTextureName();
boolean show_nonoverlap = false; // true; // clt_parameters.show_nonoverlap
boolean show_overlap = false; //true; // clt_parameters.show_overlap
boolean show_rgba_color = false; //true; // clt_parameters.show_rgba_color
boolean show_nonoverlap = true; //false; // true; // clt_parameters.show_nonoverlap
boolean show_overlap = true; //false; //true; // clt_parameters.show_overlap
boolean show_rgba_color = true; //false; //true; // clt_parameters.show_rgba_color
if (!batch_mode && show_nonoverlap){
texture_nonoverlap = image_dtt.combineRBGATiles(
......@@ -5883,7 +5887,7 @@ public class TileProcessor {
(clt_parameters.keep_weights?rgba_weights_titles:rgba_titles));
}
}
if (!batch_mode && (debugLevel > -1)) {
if (!batch_mode && (debugLevel > -3)) {
double [][] tiles_tone = scan_prev.getTileRBGA(
12); // int num_layers);
sdfa_instance.showArrays(
......@@ -7581,7 +7585,7 @@ public class TileProcessor {
int num_surf = tileSurface.getSurfaceDataLength();
if (num_surf_proc > num_surf) num_surf_proc = num_surf;
int op = ImageDtt.setImgMask(0, 0xf);
op = ImageDtt.setPairMask(op,0xf);
/// op = ImageDtt.setPairMask(op,0xf); // 2020 no need for correlations, just textures?
op = ImageDtt.setForcedDisparity(op,true);
int numClusters = 0; // needed?
for (int ns = 0 ; ns < num_surf_proc; ns ++){
......
......@@ -3054,7 +3054,7 @@ if (debugLevel > -100) return true; // temporarily !
return occl_sel;
}
public double [][][][][] getRigTextures(
public double [][][][][] getRigTextures( // never used
boolean need_master,
boolean need_aux,
double [] disparity, // non-nan - measure
......@@ -8101,6 +8101,13 @@ if (debugLevel > -100) return true; // temporarily !
if (quadCLT_main.correctionsParameters.clt_batch_assign) {
if (updateStatus) IJ.showStatus("Assigning tiles to candidate surfaces "+quadCLT_main.image_name);
// prepare average RGBA for the last scan
quadCLT_main.setPassAvgRBGA( // get image from a single pass, return relative path for x3d // USED in lwir
clt_parameters, // CLTParameters clt_parameters,
quadCLT_main.tp.clt_3d_passes.size() - 1, // int scanIndex,
threadsMax, // int threadsMax, // maximal number of threads to launch
updateStatus, // boolean updateStatus,
debugLevelInner); // int debugLevel)
double [][] assignments_dbg = quadCLT_main.tp.assignTilesToSurfaces(
clt_parameters,
quadCLT_main.geometryCorrection,
......@@ -8392,6 +8399,13 @@ if (debugLevel > -100) return true; // temporarily !
if (quadCLT_main.correctionsParameters.clt_batch_assign) {
if (updateStatus) IJ.showStatus("Assigning tiles to candidate surfaces "+quadCLT_main.image_name);
// prepare average RGBA for the last scan
quadCLT_main.setPassAvgRBGA( // get image from a single pass, return relative path for x3d // USED in lwir
clt_parameters, // CLTParameters clt_parameters,
quadCLT_main.tp.clt_3d_passes.size() - 1, // int scanIndex,
threadsMax, // int threadsMax, // maximal number of threads to launch
updateStatus, // boolean updateStatus,
debugLevelInner); // int debugLevel)
double [][] assignments_dbg = quadCLT_main.tp.assignTilesToSurfaces(
clt_parameters,
quadCLT_main.geometryCorrection,
......
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