Commit 379f3835 authored by Andrey Filippov's avatar Andrey Filippov

Saving center CLT and weights

parent c216c7e4
......@@ -5915,11 +5915,12 @@ public class OpticalFlow {
cuas_atr = new double [] { center_ATR[0][0], center_ATR[0][1], center_ATR[0][2]};
}
boolean combine_clt = true;
boolean combine_clt = (cuas_atr[0] != 0) || (cuas_atr[1] != 0) || (cuas_atr[2] != 0);
if (combine_clt) {
boolean apply_clt = true; // set GPU with data
boolean show_clt = true;
boolean merge_clt = true;
boolean save_clt = true;
QuadCLT ref_clt = quadCLTs[ref_index];
int sensor_mask_clt = -1; // all
......@@ -5937,9 +5938,10 @@ public class OpticalFlow {
dls, // double [][] dls
quadCLTs[ref_index], // QuadCLT scene,
debugLevel);
float [][] combo_seq_clt = getTDComboSceneSequence(
boolean save_weights = true;
float [][] combo_seq_clt_w = getTDComboSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
save_weights, // boolean save_weights, // output corresponding weights for each data
merge_clt, // boolean merge_all,
sensor_mask_clt, // int sensor_mask,
null, // Rectangle fov_tiles,
......@@ -5949,6 +5951,36 @@ public class OpticalFlow {
quadCLTs, // QuadCLT [] quadCLTs,
ref_clt, // QuadCLT refCLT, // should be the same instance if one of quadCLTs
debugLevel); // int debugLevel)
float [][] combo_seq_clt = save_weights? new float [combo_seq_clt_w.length/2][]: combo_seq_clt_w;
if (save_weights) { // remove second half (weights as integer numbers)
for (int i = 0; i< combo_seq_clt.length; i++) {
combo_seq_clt[i] = combo_seq_clt_w[i];
}
}
if (save_clt) {
int [] wh_c = ref_clt.getWHC(false);
//final int tile_size_td = 4 * GPUTileProcessor.DTT_SIZE * GPUTileProcessor.DTT_SIZE;
final int width_clt = wh_c[0] * 2; // to make image dimensions similar
final int height_clt = combo_seq_clt[0].length/width_clt;
String [] clt_titles = new String [combo_seq_clt_w.length];
for (int i = 0; i < combo_seq_clt.length; i++) {
clt_titles[i] = "chn-"+i;
if (save_weights) {
clt_titles[i+combo_seq_clt.length] = "weight-"+i;
}
}
String suffix_clt = "-clt_combo";
if (save_weights) {
suffix_clt+="_weights";
}
ref_clt.saveFloatArrayInModelDirectory( // error
suffix_clt, // String suffix,
clt_titles, // combo_dsn_titles_full, // null, // String [] labels, // or null
combo_seq_clt_w, // dbg_data, // float [][] data,
width_clt, // int width,
height_clt); // int height)
}
int [] whc = new int[3];
if (apply_clt) { // set GPU with data
quadCLTs[ref_index].setComboToTD(
......@@ -8169,8 +8201,9 @@ public class OpticalFlow {
public static float [][] getTDComboSceneSequence(
CLTParameters clt_parameters,
boolean merge_all,
int sensor_mask,
final boolean save_weights, // output corresponding weights for each data
final boolean merge_all,
final int sensor_mask,
Rectangle fov_tiles,
double [] stereo_xyz, // offset reference camera {x,y,z}
double [] stereo_atr_in, // offset reference orientation (cuas)
......@@ -8222,12 +8255,14 @@ public class OpticalFlow {
sc0 = nscene;
break;
}
final float [][] sumFclt = new float [merge_all? 1 : quadCLTs[sc0].getNumSensors()][quadCLTs[sc0].getCltSize(false)];
final int [][] numAcc = new int [sumFclt.length][sumFclt[0].length];
final int num_slices = merge_all? 1 : quadCLTs[sc0].getNumSensors();
final float [][] sumFclt = new float [num_slices * (save_weights? 2:1)][quadCLTs[sc0].getCltSize(false)];
final int [][] numAcc = new int [num_slices][sumFclt[0].length];
// next two to improve multithreading performance
final int tile_size_td = 4 * GPUTileProcessor.DTT_SIZE * GPUTileProcessor.DTT_SIZE;
final int tiles_td = sumFclt[0].length/tile_size_td;
final int tiles_td_all = tiles_td * sumFclt.length; // usually sumFclt.length==1
final int tiles_td_all = tiles_td * num_slices; // usually sumFclt.length==1
final Thread[] threads = ImageDtt.newThreadArray(THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
......@@ -8363,6 +8398,9 @@ public class OpticalFlow {
} else {
sumFclt[nsens][indx] = Float.NaN;
}
if (save_weights) {
sumFclt[nsens + num_slices][indx] = numAcc[nsens][indx];
}
}
}
}
......
......@@ -2616,6 +2616,7 @@ public class QuadCLT extends QuadCLTCPU {
public int getCltSize(boolean use_ref) {// per sensor, in floats
return gpuQuad.getCltSize(use_ref);
}
public int getNumSensors() { // Use QCC - this one may be null
if (gpuQuad != null) {
return gpuQuad.getNumSensors();
......@@ -2623,6 +2624,12 @@ public class QuadCLT extends QuadCLTCPU {
return super.getNumSensors();
}
public int [] getWHC(boolean use_reference) {
final int [] width_height = gpuQuad.getWH(use_reference);
final int num_colors = gpuQuad.getNumColors();
return new int [] {width_height[0],width_height[1],num_colors};
}
/**
* Get individual or combined transform domain data from the GPU
* @param sensor_mask bitmask of the sensors to use
......
......@@ -5117,6 +5117,26 @@ public class QuadCLTCPU {
return imp;
}
public ImagePlus saveFloatArrayInModelDirectory(
String suffix,
String [] labels, // or null
float [][] data,
int width,
int height)
{
String x3d_path = getX3dDirectory();
String file_name = image_name + suffix;
String file_path = x3d_path + Prefs.getFileSeparator() + file_name + ".tiff";
ImageStack imageStack = ShowDoubleFloatArrays.makeStack(data, width, height, labels, false);
ImagePlus imp = new ImagePlus( file_name, imageStack);
FileSaver fs=new FileSaver(imp);
fs.saveAsTiff(file_path);
System.out.println("saveFloatArrayInModelDirectory(): saved "+file_path);
return imp;
}
public ImagePlus saveDoubleArrayInTopModelDirectory(
String suffix,
String [] labels, // or null
......
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