Commit a74958ee authored by Andrey Filippov's avatar Andrey Filippov

more experimenting and visualizations of the inter-scene

parent 61e720a6
......@@ -800,19 +800,21 @@ public class CLTParameters {
public boolean taEnMismatch = false; // Enable cost of a measurement layer not having same layer in the same location or near
// gpu processing parameters
public double gpu_corr_scale = 0.75; // reduce GPU-generated correlation values
public int gpu_corr_rad = 7; // size of the correlation to save - initially only 15x15
public double gpu_weight_r = 0.5; // 25;
public double gpu_weight_b = 0.2; // 0.25; // weight g = 1.0 - gpu_weight_r - gpu_weight_b
public double gpu_sigma_r = 0.9; // 1.1;
public double gpu_sigma_b = 0.9; // 1.1;
public double gpu_sigma_g = 0.6; // 0.7;
public double gpu_sigma_m = 0.4; // 0.7;
public double gpu_sigma_rb_corr = 0.3; // apply LPF after accumulating R and B correlation before G,
public double gpu_sigma_corr = 0.8;
public double gpu_sigma_corr_m = 0.15;
public double gpu_fatz = 500.0; // was 30
public double gpu_fatz_m = 500.0; // was 30
public double gpu_corr_scale = 0.75; // reduce GPU-generated correlation values
public int gpu_corr_rad = 7; // size of the correlation to save - initially only 15x15
public double gpu_weight_r = 0.5; // 25;
public double gpu_weight_b = 0.2; // 0.25; // weight g = 1.0 - gpu_weight_r - gpu_weight_b
public double gpu_sigma_r = 0.9; // 1.1;
public double gpu_sigma_b = 0.9; // 1.1;
public double gpu_sigma_g = 0.6; // 0.7;
public double gpu_sigma_m = 0.4; // 0.7;
public double gpu_sigma_rb_corr = 0.3; // apply LPF after accumulating R and B correlation before G,
public double gpu_sigma_corr = 0.8;
public double gpu_sigma_corr_m = 0.15;
public double gpu_sigma_log_corr = 3.0; // fill in after testing
public double gpu_sigma_log_corr_m = 3.0; // fill in after testing
public double gpu_fatz = 500.0; // was 30
public double gpu_fatz_m = 500.0; // was 30
public boolean gpu_woi = false; // if true - use gpu_woi_tx, ...
public int gpu_woi_tx = 0;
......@@ -908,6 +910,10 @@ public class CLTParameters {
return monochrome ? gpu_sigma_corr_m : gpu_sigma_corr;
}
public double getGpuCorrLoGSigma(boolean monochrome) {
return monochrome ? gpu_sigma_log_corr_m : gpu_sigma_log_corr;
}
public double getGpuCorrRBSigma(boolean monochrome) {
return monochrome ? 1.0 : gpu_sigma_rb_corr;
}
......@@ -1648,6 +1654,8 @@ public class CLTParameters {
properties.setProperty(prefix+"gpu_sigma_rb_corr", this.gpu_sigma_rb_corr +"");
properties.setProperty(prefix+"gpu_sigma_corr", this.gpu_sigma_corr +"");
properties.setProperty(prefix+"gpu_sigma_corr_m", this.gpu_sigma_corr_m +"");
properties.setProperty(prefix+"gpu_sigma_log_corr", this.gpu_sigma_log_corr +"");
properties.setProperty(prefix+"gpu_sigma_log_corr_m", this.gpu_sigma_log_corr_m +"");
properties.setProperty(prefix+"gpu_fatz", this.gpu_fatz +"");
properties.setProperty(prefix+"gpu_fatz_m", this.gpu_fatz_m +"");
......@@ -2468,6 +2476,8 @@ public class CLTParameters {
if (properties.getProperty(prefix+"gpu_sigma_rb_corr")!=null) this.gpu_sigma_rb_corr=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_rb_corr"));
if (properties.getProperty(prefix+"gpu_sigma_corr")!=null) this.gpu_sigma_corr=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_corr"));
if (properties.getProperty(prefix+"gpu_sigma_corr_m")!=null) this.gpu_sigma_corr_m=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_corr_m"));
if (properties.getProperty(prefix+"gpu_sigma_log_corr")!=null) this.gpu_sigma_log_corr=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_log_corr"));
if (properties.getProperty(prefix+"gpu_sigma_log_corr_m")!=null) this.gpu_sigma_log_corr_m=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_log_corr_m"));
if (properties.getProperty(prefix+"gpu_fatz")!=null) this.gpu_fatz=Double.parseDouble(properties.getProperty(prefix+"gpu_fatz"));
if (properties.getProperty(prefix+"gpu_fatz_m")!=null) this.gpu_fatz_m=Double.parseDouble(properties.getProperty(prefix+"gpu_fatz_m"));
......@@ -3475,6 +3485,12 @@ public class CLTParameters {
"LPF sigma to apply to the composite 2D correlation for RGB images");
gd.addNumericField("LPF sigma for correlation, mono", this.gpu_sigma_corr_m, 4, 6,"pix",
"LPF sigma to apply to the composite 2D correlation for monochrome images");
gd.addNumericField("LoG sigma for correlation, color", this.gpu_sigma_log_corr, 4, 6,"pix",
"Use LoG filter to reduce dynamic range of the correlation input to fit into float range");
gd.addNumericField("LoG sigma for correlation, mono", this.gpu_sigma_log_corr_m, 4, 6,"pix",
"Use LoG filter to reduce dynamic range of the correlation input to fit into float range");
gd.addNumericField("Fat zero (absolute) for phase correlation of color images", this.gpu_fatz, 4, 6,"",
"Add squared fat zero to the sum of squared amplitudes, color images");
gd.addNumericField("Fat zero (absolute) for phase correlation of monochrome images", this.gpu_fatz_m, 4, 6,"",
......@@ -4287,6 +4303,8 @@ public class CLTParameters {
this.gpu_sigma_rb_corr = gd.getNextNumber();
this.gpu_sigma_corr = gd.getNextNumber();
this.gpu_sigma_corr_m = gd.getNextNumber();
this.gpu_sigma_log_corr = gd.getNextNumber();
this.gpu_sigma_log_corr_m = gd.getNextNumber();
this.gpu_fatz = gd.getNextNumber();
this.gpu_fatz_m = gd.getNextNumber();
......
......@@ -669,8 +669,9 @@ public class ImageDtt extends ImageDttCPU {
final double gpu_sigma_b, // 0.9, 1.1
final double gpu_sigma_g, // 0.6, 0.7
final double gpu_sigma_m, // = 0.4; // 0.7;
final double gpu_sigma_rb_corr, // = 0.5; // apply LPF after accumulating R and B correlation before G, monochrome ? 1.0 :
final double gpu_sigma_corr, // = 0.9;gpu_sigma_corr_m
final double gpu_sigma_rb_corr, // = 0.5; // apply LPF after accumulating R and B correlation before G, monochrome ? 1.0 :
final double gpu_sigma_corr, // = 0.9;gpu_sigma_corr_m
final double gpu_sigma_log_corr, // hpf to reduce dynamic range for correlations
final double corr_red, // +used
final double corr_blue,// +used
final int threadsMax, // maximal number of threads to launch
......@@ -722,6 +723,42 @@ public class ImageDtt extends ImageDttCPU {
"lpf_rb_corr", // String const_name, // "lpf_corr"
lpf_rb_flat,
globalDebugLevel > -1);
final float [] log_flat = floatGetCltHpfFd(gpu_sigma_log_corr);
if (globalDebugLevel < -100) {
double dbg_sum = 0.0;
for (int i = 0; i < log_flat.length; i++) dbg_sum +=log_flat[i];
System.out.println("dbg_sum("+gpu_sigma_log_corr+")="+dbg_sum);
(new ShowDoubleFloatArrays()).showArrays(
log_flat,
8,
8,
"hpf_"+gpu_sigma_log_corr);
final float [] log_flat0 = floatGetCltHpfFd(4.0);
dbg_sum = 0.0;
for (int i = 0; i < log_flat.length; i++) dbg_sum +=log_flat0[i];
System.out.println("dbg_sum("+4.0+")="+dbg_sum);
(new ShowDoubleFloatArrays()).showArrays(
log_flat0,
8,
8,
"hpf_"+4.0);
final float [] log_flat1 = floatGetCltHpfFd(1.0);
dbg_sum = 0.0;
for (int i = 0; i < log_flat.length; i++) dbg_sum +=log_flat1[i];
System.out.println("dbg_sum("+1.0+")="+dbg_sum);
(new ShowDoubleFloatArrays()).showArrays(
log_flat1,
8,
8,
"hpf_"+1.0);
System.out.println("dbg_sum("+1.0+")="+dbg_sum);
}
gpuQuad.setLpfCorr(// constants memory - same for all cameras
"LoG_corr", // String const_name, // "lpf_corr"
log_flat,
globalDebugLevel > -1);
gpuQuad.setTasks( // copy tp_tasks to the GPU memory
tp_tasks, // TpTask [] tile_tasks,
......@@ -1419,7 +1456,8 @@ public class ImageDtt extends ImageDttCPU {
// each of the top elements may be null to skip particular combo type
final double [][][][] corr_tiles, // [tilesY][tilesX][pair][] ([(2*gpu_corr_rad+1)*(2*gpu_corr_rad+1)]) or null
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
// [tilesY][tilesX] should be set by caller
final float [][][] fcorr_tiles, // [tile][index][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
// 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
......@@ -1436,6 +1474,7 @@ public class ImageDtt extends ImageDttCPU {
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final float gpu_fcorr_scale = (float) gpu_corr_scale;
if (this.gpuQuad == null) {
System.out.println("clt_aberrations_quad_corr_GPU(): this.gpuQuad is null, bailing out");
return;
......@@ -1642,14 +1681,12 @@ public class ImageDtt extends ImageDttCPU {
// double [][] corrs = new double [GPUTileProcessor.NUM_PAIRS][corr_length]; // 225-long (15x15)
// added quad and cross combos
double [][] corrs = new double [GPUTileProcessor.NUM_PAIRS + num_combo][corr_length]; // 225-long (15x15)
float [][] fcorrs = (fcorr_tiles == null) ? null : new float [GPUTileProcessor.NUM_PAIRS + num_combo][corr_length]; // 225-long (15x15)
int indx_corr = indx_tile * num_tile_corr;
int nt = (corr_indices[indx_corr] >> GPUTileProcessor.CORR_NTILE_SHIFT);
int tileX = nt % tilesX;
int tileY = nt / tilesX;
int tIndex = tileY * tilesX + tileX;
// if (tileY >= 122) {
// System.out.println("tileY="+tileY+" tileX="+tileX);
// }
// Prepare the same (currently 10-layer) corrs as double [][], as in CPU version
int pair_mask = 0;
......@@ -1661,6 +1698,9 @@ public class ImageDtt extends ImageDttCPU {
for (int i = 0; i < corr_length; i++) {
corrs[pair][i] = gpu_corr_scale * fcorr2D[indx_corr][i]; // from float to double
}
if (fcorrs != null) for (int i = 0; i < corr_length; i++) {
fcorrs[pair][i] = gpu_fcorr_scale * fcorr2D[indx_corr][i];
}
indx_corr++;
}
}
......@@ -1672,18 +1712,25 @@ public class ImageDtt extends ImageDttCPU {
for (int i = 0; i < corr_length; i++) {
corrs[pair][i] = gpu_corr_scale * fcorr2D_combo[ncm][indx_tile][i]; // from float to double
}
if (fcorrs != null) for (int i = 0; i < corr_length; i++) {
fcorrs[pair][i] = gpu_fcorr_scale * fcorr2D_combo[ncm][indx_tile][i];
}
}
}
if (corr_tiles != null) {
corr_tiles[tileY][tileX] = corrs;
}
if (fcorr_tiles != null) {
fcorr_tiles[tileY * tilesX + tileX] = fcorrs; // does not require corr_common_GPU()
}
if ((disparity_map != null) || (clt_corr_partial != null) || (clt_mismatch != null)) {
int used_pairs = pair_mask; // imgdtt_params.dbg_pair_mask; //TODO: use tile tasks
int tile_lma_debug_level = ((tileX == debug_tileX) && (tileY == debug_tileY))? (imgdtt_params.lma_debug_level-1) : -2;
boolean debugTile =(tileX == debug_tileX) && (tileY == debug_tileY) && (globalDebugLevel > -1);
corr_common_GPU(
imgdtt_params, // final ImageDttParameters imgdtt_params,
clt_corr_partial, // final double [][][][][] clt_corr_partial,
clt_corr_partial, // final double [][][][][] clt_corr_partial,
used_pairs, // final int used_pairs,
disparity_map, // final double [][] disparity_map,
clt_mismatch, // final double [][] clt_mismatch,
......@@ -1743,7 +1790,7 @@ public class ImageDtt extends ImageDttCPU {
public void corr_common_GPU(
final ImageDttParameters imgdtt_params,
final double [][][][][] clt_corr_partial,
final double [][][][][] clt_corr_partial,
final int used_pairs,
final double [][] disparity_map,
final double [][] clt_mismatch,
......@@ -2041,7 +2088,7 @@ public class ImageDtt extends ImageDttCPU {
// create LMA instance, calculate LMA composite argmax
// Create 2 groups: ortho & diag
Correlations2dLMA lma;
if (imgdtt_params.pcorr_use) {
if (imgdtt_params.pcorr_use) { // new group phase correlation
double [][] fake_corrs = {corrs[6],null,null,null,corrs[7],null};
lma = corr2d.corrLMA(
imgdtt_params, // ImageDttParameters imgdtt_params,
......
......@@ -24,6 +24,7 @@ package com.elphel.imagej.tileprocessor;
*/
// ← → ↑ ↓ ⇖ ⇗ ⇘ ⇙ ↔ ↕
import java.awt.Rectangle;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -5525,13 +5526,13 @@ public class ImageDttCPU {
}
/**
* Get frequency-domain representation of the LPF (version for the GPU, in floats)
* @param sigma blurring in pixels
* @param sigma2 squared Gaussian sigma in pixels
* @return float array of the filter, 64 long for 8-pixel DTT
*/
public float [] floatGetCltLpfFd(
double sigma) {
double sigma2) {
DttRad2 dtt = new DttRad2(transform_size);
double [] clt_fd = dtt.dttt_iiie(getLpf(sigma));
double [] clt_fd = dtt.dttt_iiie(getLpf(sigma2));
int l = clt_fd.length;
float [] lpf_flat = new float [l];
for (int j = 0; j < l; j++) {
......@@ -5540,18 +5541,36 @@ public class ImageDttCPU {
return lpf_flat;
}
/**
* Get frequency-domain representation of the LPF (version for the GPU, in floats)
* @param sigma Gaussian sigma in pixels
* @return float array of the filter, 64 long for 8-pixel DTT
*/
public float [] floatGetCltHpfFd(
double sigma) {
DttRad2 dtt = new DttRad2(transform_size);
double [] clt_fd = (sigma == 0.0)? (new double[transform_size*transform_size]) : dtt.dttt_iiie(getLpf(sigma * sigma));
int l = clt_fd.length;
float [] hpf_flat = new float [l];
for (int j = 0; j < l; j++) {
hpf_flat[j] = (float) (1.0 - clt_fd[j]*2*transform_size);
}
return hpf_flat;
}
/**
* Get pixel-domain representation of the LPF
* @param sigma blurring in pixels
* @param sigma2 squared Gaussian sigma in pixels
* @return double array of the filter, 64 long for 8-pixel DTT
*/
public double [] getLpf(
double sigma)
double sigma2) // sigma squared
{
int transform_len = transform_size * transform_size;
final double [] filter_direct= new double[transform_len];
if (sigma == 0) {
if (sigma2 == 0) {
filter_direct[0] = 1.0;
for (int i= 1; i<filter_direct.length;i++) {
filter_direct[i] =0;
......@@ -5559,7 +5578,7 @@ public class ImageDttCPU {
} else {
for (int i = 0; i < transform_size; i++){
for (int j = 0; j < transform_size; j++){
filter_direct[i*transform_size+j] = Math.exp(-(i*i+j*j)/(2*sigma)); // FIXME: should be sigma*sigma !
filter_direct[i*transform_size+j] = Math.exp(-(i*i+j*j)/(2*sigma2));
}
}
}
......@@ -5580,6 +5599,95 @@ public class ImageDttCPU {
return filter_direct;
}
/**
* Get frequency-domain representation of the LoG (version for the GPU, in floats)
* @param sigma Gaussian sigma in pixels
* @return float array of the filter, 64 long for 8-pixel DTT
*/
public float [] floatGetCltLoGFd(
double sigma) {
DttRad2 dtt = new DttRad2(transform_size);
double [] clt_fd = dtt.dttt_iiie(getLoG(sigma));
int l = clt_fd.length;
float [] log_flat = new float [l];
for (int j = 0; j < l; j++) {
log_flat[j] = (float) (clt_fd[j]*2*transform_size);
}
return log_flat;
}
/**
* Get pixel-domain representation of the LoG
* @param sigma Gaussian sigma in pixels
* @return double array of the filter, 64 long for 8-pixel DTT
*/
public double [] getLoG(
double sigma)
{
int transform_len = transform_size * transform_size;
final double sigma2 = sigma*sigma;
final double sigma4 = sigma2*sigma2;
final double [] filter_direct= new double[transform_len];
if (sigma == 0) {
filter_direct[0] = 1.0;
for (int i= 1; i<filter_direct.length;i++) {
filter_direct[i] =0;
}
} else {
for (int i = 0; i < transform_size; i++){
for (int j = 0; j < transform_size; j++){
//https://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm
filter_direct[i*transform_size+j] =
-1.0/(Math.PI * sigma4)*(1.0 - (i*i+j*j)/(2*sigma2))*
Math.exp(-(i*i+j*j)/(2*sigma2));
}
}
}
(new ShowDoubleFloatArrays()).showArrays(
filter_direct,
8,
8,
"log_direct-"+sigma);
// normalize
double sum2 = 0;
for (int i = 0; i < transform_size; i++){
for (int j = 0; j < transform_size; j++){
double d = filter_direct[i*transform_size+j];
d*=d;
d*=Math.cos(Math.PI*i/(2*transform_size))*Math.cos(Math.PI*j/(2*transform_size));
if (i > 0) d*= 2.0;
if (j > 0) d*= 2.0;
sum2 +=d;
}
}
double sum = Math.sqrt(sum2);
for (int i = 0; i<filter_direct.length; i++){
filter_direct[i] /= sum;
}
System.out.println("getLoG("+sigma+") sum="+sum);
/*
sum2 = 0;
for (int i = 0; i < transform_size; i++){
for (int j = 0; j < transform_size; j++){
double d = filter_direct[i*transform_size+j];
d*=d;
d*=Math.cos(Math.PI*i/(2*transform_size))*Math.cos(Math.PI*j/(2*transform_size));
if (i > 0) d*= 2.0;
if (j > 0) d*= 2.0;
sum2 +=d;
}
}
*/
(new ShowDoubleFloatArrays()).showArrays(
filter_direct,
8,
8,
"log_direct_norm-"+sigma);
return filter_direct;
}
public void clt_lpf( // USED in lwir
......@@ -5838,7 +5946,7 @@ public class ImageDttCPU {
}
// extract correlation result in linescan order (for visualization)
public double [] corr_dbg( // not used in lwir
public double [] corr_dbg(
final double [][][] corr_data,
final int corr_size,
final double border_contrast,
......@@ -5884,10 +5992,6 @@ public class ImageDttCPU {
return corr_data_out;
}
// final float [][][][] fcorr_td = new float[tilesY][tilesX][][];
// final float [][][][] fcorr_combo_td = new float[4][tilesY][tilesX][];
public static float [][] corr_td_dbg(
final float [][][][] fcorr_td,
// if 0 - fcorr_combo_td = new float[4][tilesY][tilesX][];
......@@ -5957,6 +6061,60 @@ public class ImageDttCPU {
}
// final float [][][][] fcorr_td = new float[tilesY][tilesX][][];
// final float [][][][] fcorr_combo_td = new float[4][tilesY][tilesX][];
public static void corr_td_normalize(
final float [][][][] fcorr_td, // will be updated
// if 0 - fcorr_combo_td = new float[4][tilesY][tilesX][];
// if > 0 - fcorr_td = new float[tilesY][tilesX][num_slices][];
final int num_slices,
final int transform_size,
final double fat_zero_abs,
final double output_amplitude,
final int threadsMax) // maximal number of threads to launch
{
final double fat_zero_abs2 = fat_zero_abs * fat_zero_abs;
final int tilesY = (num_slices == 0) ? fcorr_td[0].length : fcorr_td.length;
final int tilesX = (num_slices == 0) ? fcorr_td[0][0].length : fcorr_td[0].length;
final int nTiles = tilesX*tilesY;
final int fnum_slices = (num_slices == 0) ? fcorr_td.length : num_slices;
final int transform_len = transform_size*transform_size; // 64
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
int tileY = nTile/tilesX;
int tileX = nTile - tileY * tilesX;
if ((num_slices == 0) || (fcorr_td[tileY][tileX] != null)) {
for (int slice = 0; slice < fnum_slices; slice ++) {
float [] ftile = (num_slices > 0) ? fcorr_td[tileY][tileX][slice] : fcorr_td[slice][tileY][tileX];
if (ftile != null) {
for (int i = 0; i < transform_len; i++) {
double s2 = fat_zero_abs2;
for (int q = 0; q < 4; q++) {
double d = ftile[q * transform_len + i];
s2 += d*d;
}
double k = output_amplitude/Math.sqrt(s2);
for (int q = 0; q < 4; q++) {
ftile[q * transform_len + i] *= k;
}
}
}
}
}
}
}
};
}
startAndJoin(threads);
}
// extract correlation result in linescan order (for visualization)
public static double [][] corr_partial_dbg( // not used in lwir
......@@ -5972,19 +6130,14 @@ public class ImageDttCPU {
final int tilesX=corr_data[0].length;
final int nTiles=tilesX*tilesY;
final int tile_size = corr_size+1;
final int corr_len = corr_size*corr_size;
System.out.println("corr_partial_dbg(): tilesY="+tilesY+", tilesX="+tilesX+", corr_size="+corr_size+", corr_len="+corr_len+
" pairs="+pairs +" colors = "+colors+" tile_size="+tile_size);
final double [][] corr_data_out = new double[pairs*colors][tilesY*tilesX*tile_size*tile_size];
// final String [] colorNames = {"red","blue","green","composite"};
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int pair = 0; pair< pairs; pair++) {
for (int nColor = 0; nColor < colors; nColor++) {
for (int i=0; i<corr_data_out.length;i++) corr_data_out[pair*colors+nColor][i]= 0;
Arrays.fill(corr_data_out[pair*colors+nColor], Double.NaN);
}
}
......@@ -6007,10 +6160,10 @@ public class ImageDttCPU {
corr_data_out[indx],
((tileY*tile_size + i) *tilesX + tileX)*tile_size ,
corr_size);
corr_data_out[indx][((tileY*tile_size + i) *tilesX + tileX)*tile_size+corr_size] = border_contrast*((i & 1) - 0.5);
// corr_data_out[indx][((tileY*tile_size + i) *tilesX + tileX)*tile_size+corr_size] = border_contrast*((i & 1) - 0.5);
}
for (int i = 0; i < tile_size; i++){
corr_data_out[indx][((tileY*tile_size + corr_size) *tilesX + tileX)*tile_size+i] = border_contrast*((i & 1) - 0.5);
// corr_data_out[indx][((tileY*tile_size + corr_size) *tilesX + tileX)*tile_size+i] = border_contrast*((i & 1) - 0.5);
}
}
}
......@@ -6022,8 +6175,528 @@ public class ImageDttCPU {
startAndJoin(threads);
return corr_data_out;
}
public static float [][][] extract_corr_woi(
final boolean copy, // copy tiles stack, not reference
final float [][][] fcorr,
final Rectangle woi,
final int tilesX,
final int threadsMax) // maximal number of threads to launch
{
final int tilesY = fcorr.length/tilesX;
if ((woi.width + woi.x) >= tilesX) {
int ww = woi.width;
woi.width = tilesX - woi.x;
if (woi.width <= 0) {
if (ww > tilesX) ww = tilesX;
woi.width = ww;
woi.x = tilesX - woi.width;
}
}
if ((woi.height + woi.y) >= tilesY) {
int wndh = woi.height;
woi.height = tilesY - woi.y;
if (woi.height <= 0) {
if (wndh > tilesY) wndh = tilesY;
woi.height = wndh;
woi.y = tilesY - woi.height;
}
}
final int nTiles=woi.width * woi.height;
final float [][][] fcorr_out = new float [fcorr.length][][];
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
int tileY = nTile / woi.width + woi.y;
int tileX = nTile % woi.width + woi.x;
int tile = tileY * tilesX + tileX;
if (copy && (fcorr[tile] != null)) {
fcorr_out[tile] = fcorr[tile].clone();
} else {
fcorr_out[tile] = fcorr[tile];
}
}
}
};
}
startAndJoin(threads);
return fcorr_out;
}
public static float [][] corr_partial_dbg( // not used in lwir
final float [][][] fcorr_data, // [tile][index][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
final int tilesX,
final int corr_size,
final int layers,
final double border_contrast,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final int tilesY=fcorr_data.length/tilesX;
final int nTiles=tilesX*tilesY;
final int tile_size = corr_size+1;
// final int corr_len = corr_size*corr_size;
final float [][] fcorr_data_out = new float[layers][tilesY*tilesX*tile_size*tile_size];
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int layer = 0; layer < layers; layer++) {
Arrays.fill(fcorr_data_out[layer], Float.NaN);
}
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
int tileY,tileX;
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
if (fcorr_data[nTile] != null) {
for (int layer = 0; layer < layers; layer++) {
for (int i = 0; i < corr_size;i++){
System.arraycopy(
fcorr_data[nTile][layer],
corr_size* i,
fcorr_data_out[layer],
((tileY*tile_size + i) *tilesX + tileX)*tile_size ,
corr_size);
}
}
}
}
}
};
}
startAndJoin(threads);
return fcorr_data_out;
}
// extract correlation result in linescan order (for visualization)
// extracts 10 correlation tiles
public static float [] corr_partial_wnd( // not used in lwir
final double [][][][][] corr_data,
final int corr_size,
final Rectangle woi,
final int gap,
final int [] wh,
final int threadsMax) // maximal number of threads to launch
{
final int tile_size = corr_size+1;
final int [][] layout = {{0,0,0},{1,1,0},{2,0,1},{3,1,1},{4,0,2},{5,1,2},{6,0,3},{7,1,3},{8,0,4},{9,1,4}}; // {source_index, row, col};
if ((woi.width + woi.x) >= corr_data[0].length) {
int ww = woi.width;
woi.width = corr_data[0].length - woi.x;
if (woi.width <= 0) {
if (ww > corr_data[0].length) ww = corr_data[0].length;
woi.width = ww;
woi.x = corr_data[0].length - woi.width;
}
}
if ((woi.height + woi.y) >= corr_data.length) {
int wndh = woi.height;
woi.height = corr_data.length - woi.y;
if (woi.height <= 0) {
if (wndh > corr_data.length) wndh = corr_data.length;
woi.height = wndh;
woi.y = corr_data.length - woi.height;
}
}
final int nTiles=woi.width * woi.height;
final int clust_width = 5 * tile_size + gap;
final int clust_height = 2 * tile_size + gap;
final int width = woi.width* clust_width - gap;
final int height = woi.height*clust_height - gap;
if (wh != null) {
wh[0] = width;
wh[1] = height;
}
final float [] corr_data_out = new float[width * height];
Arrays.fill(corr_data_out, Float.NaN);
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
int tileY = nTile / woi.width; // relative to woi
int tileX = nTile % woi.width;
int stileY = tileY + woi.y; // absolute in the corr_data
int stileX = tileX + woi.x;
if (corr_data[stileY][stileX] != null) {
for (int n = 0; n < layout.length; n++) {
int src_layer = layout[n][0];
int v_tile = layout[n][1];