Commit 200f2455 authored by Andrey Filippov's avatar Andrey Filippov

Mixing noise - random and FPN for performance evaluation

parent 3ca96c86
...@@ -28,64 +28,95 @@ package com.elphel.imagej.cameras; ...@@ -28,64 +28,95 @@ package com.elphel.imagej.cameras;
import java.util.Properties; import java.util.Properties;
import com.elphel.imagej.common.GenericJTabbedDialog; import com.elphel.imagej.common.GenericJTabbedDialog;
import com.elphel.imagej.tileprocessor.NoiseParameters;
public class InterNoiseParameters { public class InterNoiseParameters {
public double noise_sigma = 1.5; public NoiseParameters noise = new NoiseParameters (0.1, 0.0, 1.5, 1.0, 16);
public double noise_scale = 0.01; // public double noise_sigma = 1.5;
public double initial_offset = 1.0; // public double noise_scale = 0.01;
// public double initial_offset = 1.0;
public boolean ref_only = false; // also see imgdtt_params.dbg_pair_mask to switch between all pairs (63) and binocular only (1) public boolean ref_only = false; // also see imgdtt_params.dbg_pair_mask to switch between all pairs (63) and binocular only (1)
public boolean show_final_2d = true; // show 2d correlations during last interation step
public int noise_debug_level = -1; // Noise testing debug level public int noise_debug_level = -1; // Noise testing debug level
public void dialogQuestions(GenericJTabbedDialog gd) { public void dialogQuestions(GenericJTabbedDialog gd) {
gd.addMessage("Additive noise parameters"); gd.addMessage("Additive noise parameters");
gd.addMessage("LMA other parameters"); gd.addMessage("LMA other parameters");
gd.addNumericField("Noise Gaussian sigma", this.noise_sigma, 3,5,"pix", gd.addNumericField("Noise Gaussian sigma", this.noise.sigma, 3,5,"pix",
"Blur noise with 2D Gaussian"); "Blur noise with 2D Gaussian");
gd.addNumericField("Scale noise", this.noise_scale, 6,8,"", gd.addNumericField("Scale noise random (each scene indepemdent)", this.noise.scale_random, 6,8,"",
"Scale noise relative to the average value of the color component");
gd.addNumericField("Scale noise FPN (same for each scene)", this.noise.scale_fpn, 6,8,"",
"Scale noise relative to the average value of the color component."); "Scale noise relative to the average value of the color component.");
gd.addNumericField("Offset target disparity", this.initial_offset, 3,5,"pix", gd.addNumericField("Offset target disparity", this.noise.initial_offset, 3,5,"pix",
"Offset target disparity before attempting to correlate and refine."); "Offset target disparity before attempting to correlate and refine.");
gd.addNumericField("Subset number of sensors (2/4/8/16)", this.noise.used_sensors, 0,3,"",
"Performance comparison - use only some of 16 sensors");
gd.addCheckbox ("Reference scene only", this.ref_only, gd.addCheckbox ("Reference scene only", this.ref_only,
"Process only reference scene (intra-scene, no inter-scene accumulation)."); "Process only reference scene (intra-scene, no inter-scene accumulation).");
gd.addNumericField("Debug level", this.noise_debug_level, 0,3,"", gd.addCheckbox ("Show 2d correlations for the last iteration", this.show_final_2d,
"Show single-scene and interframe 2d correlations for the last iteration");
gd.addNumericField("Debug level", this.noise_debug_level, 0,3,"",
"Debug level of interscene noise testing."); "Debug level of interscene noise testing.");
} }
public void dialogAnswers(GenericJTabbedDialog gd) { public void dialogAnswers(GenericJTabbedDialog gd) {
this.noise_sigma = gd.getNextNumber(); this.noise.sigma = gd.getNextNumber();
this.noise_scale = gd.getNextNumber(); this.noise.scale_random = gd.getNextNumber();
this.initial_offset = gd.getNextNumber(); this.noise.scale_fpn = gd.getNextNumber();
this.noise.initial_offset = gd.getNextNumber();
this.noise.used_sensors = (int) gd.getNextNumber();
this.ref_only = gd.getNextBoolean(); this.ref_only = gd.getNextBoolean();
this.show_final_2d = gd.getNextBoolean();
this.noise_debug_level = (int) gd.getNextNumber(); this.noise_debug_level = (int) gd.getNextNumber();
} }
public void setProperties(String prefix,Properties properties){ public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"noise_sigma", this.noise_sigma+""); properties.setProperty(prefix+"noise.sigma", this.noise.sigma+"");
properties.setProperty(prefix+"noise_scale", this.noise_scale+""); properties.setProperty(prefix+"noise.scale_random", this.noise.scale_random+"");
properties.setProperty(prefix+"initial_offset", this.initial_offset+""); properties.setProperty(prefix+"noise.scale_fpn", this.noise.scale_fpn+"");
properties.setProperty(prefix+"ref_only", this.ref_only+""); properties.setProperty(prefix+"noise.initial_offset", this.noise.initial_offset+"");
properties.setProperty(prefix+"noise_debug_level", this.noise_debug_level+""); properties.setProperty(prefix+"noise.used_sensors", this.noise.used_sensors+"");
properties.setProperty(prefix+"ref_only", this.ref_only+"");
properties.setProperty(prefix+"show_final_2d", this.show_final_2d+"");
properties.setProperty(prefix+"noise_debug_level", this.noise_debug_level+"");
} }
public void getProperties(String prefix,Properties properties){ public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"noise_sigma")!=null) this.noise_sigma=Double.parseDouble(properties.getProperty(prefix+"noise_sigma")); if (properties.getProperty(prefix+"noise.sigma")!=null) {
if (properties.getProperty(prefix+"noise_scale")!=null) this.noise_scale=Double.parseDouble(properties.getProperty(prefix+"noise_scale")); this.noise.sigma=Double.parseDouble(properties.getProperty(prefix+"noise.sigma"));
if (properties.getProperty(prefix+"initial_offset")!=null) this.initial_offset=Double.parseDouble(properties.getProperty(prefix+"initial_offset")); } else if (properties.getProperty(prefix+"noise_sigma")!=null) { // old format
this.noise.sigma=Double.parseDouble(properties.getProperty(prefix+"noise_sigma"));
}
if (properties.getProperty(prefix+"noise.scale_random")!=null) {
this.noise.scale_random=Double.parseDouble(properties.getProperty(prefix+"noise.scale_random"));
} else if (properties.getProperty(prefix+"noise_scale")!=null) {
this.noise.scale_random=Double.parseDouble(properties.getProperty(prefix+"noise_scale"));
}
if (properties.getProperty(prefix+"noise.scale_fpn")!=null) this.noise.scale_fpn=Double.parseDouble(properties.getProperty(prefix+"noise.scale_fpn"));
if (properties.getProperty(prefix+"noise.initial_offset")!=null) {
this.noise.initial_offset=Double.parseDouble(properties.getProperty(prefix+"noise.initial_offset"));
} else if (properties.getProperty(prefix+"initial_offset")!=null) {
this.noise.initial_offset=Double.parseDouble(properties.getProperty(prefix+"initial_offset"));
}
if (properties.getProperty(prefix+"noise.used_sensors")!=null) this.noise.used_sensors=Integer.parseInt(properties.getProperty(prefix+"noise.used_sensors"));
if (properties.getProperty(prefix+"ref_only")!=null) this.ref_only=Boolean.parseBoolean(properties.getProperty(prefix+"ref_only")); if (properties.getProperty(prefix+"ref_only")!=null) this.ref_only=Boolean.parseBoolean(properties.getProperty(prefix+"ref_only"));
if (properties.getProperty(prefix+"show_final_2d")!=null) this.show_final_2d=Boolean.parseBoolean(properties.getProperty(prefix+"show_final_2d"));
if (properties.getProperty(prefix+"noise_debug_level")!=null) this.noise_debug_level=Integer.parseInt(properties.getProperty(prefix+"noise_debug_level")); if (properties.getProperty(prefix+"noise_debug_level")!=null) this.noise_debug_level=Integer.parseInt(properties.getProperty(prefix+"noise_debug_level"));
} }
@Override @Override
public InterNoiseParameters clone() throws CloneNotSupportedException { public InterNoiseParameters clone() throws CloneNotSupportedException {
InterNoiseParameters inp = new InterNoiseParameters(); InterNoiseParameters inp = new InterNoiseParameters();
inp.noise_sigma = this.noise_sigma; inp.noise = this.noise.clone();
inp.noise_scale = this.noise_scale;
inp.initial_offset = this.initial_offset;
inp.ref_only = this.ref_only; inp.ref_only = this.ref_only;
inp.show_final_2d = this.show_final_2d;
inp.noise_debug_level = this.noise_debug_level; inp.noise_debug_level = this.noise_debug_level;
return inp; return inp;
} }
} }
package com.elphel.imagej.tileprocessor;
import com.elphel.imagej.cameras.InterNoiseParameters;
public class NoiseParameters {
public double scale_random = 0.1;
public double scale_fpn = 0.0;
public double sigma = 1.5;
public double initial_offset = 1.0;
public int used_sensors = 16; // 2/4/8/16
public NoiseParameters (
double scale_random,
double scale_fpn,
double sigma,
double initial_offset,
int used_sensors) {
this.scale_random = scale_random;
this.scale_fpn = scale_fpn;
this.sigma = sigma;
this.initial_offset= initial_offset;
this.used_sensors = used_sensors;
}
@Override
public NoiseParameters clone() throws CloneNotSupportedException {
return new NoiseParameters(
scale_random,
scale_fpn,
sigma,
initial_offset,
used_sensors);
}
}
...@@ -3163,7 +3163,8 @@ public class OpticalFlow { ...@@ -3163,7 +3163,8 @@ public class OpticalFlow {
ColorProcParameters colorProcParameters, ColorProcParameters colorProcParameters,
QuadCLT.SetChannels [] set_channels, QuadCLT.SetChannels [] set_channels,
QuadCLT ref_scene, // ordered by increasing timestamps QuadCLT ref_scene, // ordered by increasing timestamps
double [] noise_sigma_level, // double []
NoiseParameters noise_sigma_level,
int debug_level int debug_level
) )
{ {
...@@ -3192,6 +3193,7 @@ public class OpticalFlow { ...@@ -3192,6 +3193,7 @@ public class OpticalFlow {
clt_parameters, clt_parameters,
colorProcParameters, // colorProcParameters, //
noise_sigma_level, // double [] noise_sigma_level, noise_sigma_level, // double [] noise_sigma_level,
ref_scene, // QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
threadsMax, threadsMax,
-1); // debug_level); -1); // debug_level);
scenes[i].setDSRBG( scenes[i].setDSRBG(
...@@ -3276,6 +3278,7 @@ public class OpticalFlow { ...@@ -3276,6 +3278,7 @@ public class OpticalFlow {
combo_dsn_change[0], // final double [] disparity_ref, // disparity in the reference view tiles (Double.NaN - invalid) combo_dsn_change[0], // final double [] disparity_ref, // disparity in the reference view tiles (Double.NaN - invalid)
margin, // final int margin, margin, // final int margin,
nrefine, // final int nrefine, // just for debug title nrefine, // final int nrefine, // just for debug title
clt_parameters.inp.show_final_2d, // final boolean show_2d_corr,
debug_level-5); // final int debug_level) debug_level-5); // final int debug_level)
Runtime.getRuntime().gc(); Runtime.getRuntime().gc();
...@@ -3386,7 +3389,8 @@ public class OpticalFlow { ...@@ -3386,7 +3389,8 @@ public class OpticalFlow {
boolean ref_only, // process only reference frame (false - inter-scene) boolean ref_only, // process only reference frame (false - inter-scene)
ColorProcParameters colorProcParameters, ColorProcParameters colorProcParameters,
QuadCLT ref_scene, // ordered by increasing timestamps QuadCLT ref_scene, // ordered by increasing timestamps
double [] noise_sigma_level, // double []
NoiseParameters noise_sigma_level,
int debug_level int debug_level
) )
{ {
...@@ -3405,6 +3409,7 @@ public class OpticalFlow { ...@@ -3405,6 +3409,7 @@ public class OpticalFlow {
clt_parameters, clt_parameters,
colorProcParameters, // colorProcParameters, //
noise_sigma_level, // double [] noise_sigma_level, noise_sigma_level, // double [] noise_sigma_level,
ref_scene, // QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
threadsMax, threadsMax,
-1); // debug_level); -1); // debug_level);
scenes[i].setDSRBG( scenes[i].setDSRBG(
...@@ -3475,7 +3480,7 @@ public class OpticalFlow { ...@@ -3475,7 +3480,7 @@ public class OpticalFlow {
} }
if (noise_sigma_level != null) { // add initial offset to the expected disparity if (noise_sigma_level != null) { // add initial offset to the expected disparity
for (int i = 0; i < combo_dsn_change[0].length; i++) { for (int i = 0; i < combo_dsn_change[0].length; i++) {
combo_dsn_change[0][i] += noise_sigma_level[2]; combo_dsn_change[0][i] += noise_sigma_level.initial_offset; // [2];
} }
} }
for (int nrefine = 0; nrefine < max_refines; nrefine++) { for (int nrefine = 0; nrefine < max_refines; nrefine++) {
...@@ -3543,13 +3548,20 @@ public class OpticalFlow { ...@@ -3543,13 +3548,20 @@ public class OpticalFlow {
//noise_sigma_level //noise_sigma_level
String rslt_suffix = "-results-nonoise"; String rslt_suffix = "-results-nonoise";
if (noise_sigma_level != null) { if (noise_sigma_level != null) {
rslt_suffix = "-results-lev_"+noise_sigma_level[0]+"-sigma_"+noise_sigma_level[1]+"-offset"+noise_sigma_level[2]; // rslt_suffix = "-results-lev_"+noise_sigma_level[0]+"-sigma_"+noise_sigma_level[1]+"-offset"+noise_sigma_level[2];
rslt_suffix =
"-results-rnd_"+noise_sigma_level.scale_random+
"-fpn_"+ noise_sigma_level.scale_fpn+
"-sigma_"+ noise_sigma_level.sigma+ // [1]+
"-offset"+ noise_sigma_level.initial_offset+ // [2];
"-sensors"+ noise_sigma_level.used_sensors;
if (ref_only) { if (ref_only) {
rslt_suffix +="-nointer"; rslt_suffix +="-nointer";
} else { } else {
rslt_suffix +="-inter"; rslt_suffix +="-inter";
} }
rslt_suffix +="-mask"+clt_parameters.img_dtt.dbg_pair_mask; // rslt_suffix +="-mask"+clt_parameters.img_dtt.dbg_pair_mask;
} }
ref_scene.saveDoubleArrayInModelDirectory( ref_scene.saveDoubleArrayInModelDirectory(
rslt_suffix, // String suffix, rslt_suffix, // String suffix,
...@@ -3597,7 +3609,8 @@ public class OpticalFlow { ...@@ -3597,7 +3609,8 @@ public class OpticalFlow {
boolean ref_only, // process only reference frame (false - inter-scene) boolean ref_only, // process only reference frame (false - inter-scene)
ColorProcParameters colorProcParameters, ColorProcParameters colorProcParameters,
QuadCLT ref_scene, // ordered by increasing timestamps QuadCLT ref_scene, // ordered by increasing timestamps
double [] noise_sigma_level, // double []
NoiseParameters noise_sigma_level,
int debug_level int debug_level
) )
{ {
...@@ -3616,6 +3629,7 @@ public class OpticalFlow { ...@@ -3616,6 +3629,7 @@ public class OpticalFlow {
clt_parameters, clt_parameters,
colorProcParameters, // colorProcParameters, //
noise_sigma_level, // double [] noise_sigma_level, noise_sigma_level, // double [] noise_sigma_level,
ref_scene, // QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
threadsMax, threadsMax,
-1); // debug_level); -1); // debug_level);
scenes[i].setDSRBG( scenes[i].setDSRBG(
...@@ -3624,31 +3638,44 @@ public class OpticalFlow { ...@@ -3624,31 +3638,44 @@ public class OpticalFlow {
updateStatus, // boolean updateStatus, updateStatus, // boolean updateStatus,
-1); // debug_level); // int debugLevel) -1); // debug_level); // int debugLevel)
} }
// String [] combo_dsn_titles = {"disp", "strength", "num_valid","change"};
String [] combo_dsn_titles = {"disp", "strength","disp_lma","num_valid","change"};
// final String [] iter_titles = {"disp", "diff", "strength","disp_lma"};
final int [] iter_indices = {0,1,2,4}; // which to save for each iteration: {"disp", "strength","disp_lma","change"};
final int [] initial_indices = {0,1,3}; // initial: "disp", "strength","num_valid"
double [][] combo_dsn = null; double [][] combo_dsn = null;
if (noise_sigma_level == null) { if (noise_sigma_level == null) {
combo_dsn = prepareInitialComboDS( double[][] combo_dsn0 = prepareInitialComboDS( // 3
clt_parameters, // final CLTParameters clt_parameters, clt_parameters, // final CLTParameters clt_parameters,
scenes, // final QuadCLT [] scenes, scenes, // final QuadCLT [] scenes,
indx_ref, // final int indx_ref, indx_ref, // final int indx_ref,
debug_level-2); // final int debug_level); debug_level-2); // final int debug_level);
combo_dsn = new double[combo_dsn_titles.length - 1][];
for (int i = 0; i < combo_dsn0.length; i++) {
combo_dsn[initial_indices[i]] = combo_dsn0[i]; // "disp", "strength", <null>, "num_valid"
}
} else { } else {
combo_dsn = ref_scene. readDoubleArrayFromModelDirectory( combo_dsn = ref_scene. readDoubleArrayFromModelDirectory( //"disp", "strength","disp_lma","num_valid"
"-results-nonoise", // String suffix, "-results-nonoise", // String suffix,
3, // int num_slices, // (0 - all) combo_dsn_titles.length - 1, // 4
null); // int [] wh); null); // int [] wh);
} }
final double [][] combo_dsn_change = new double [combo_dsn.length+1][]; // final double [][] combo_dsn_change = new double [combo_dsn.length+1][];
for (int i = 0; i < combo_dsn.length; i++) {
combo_dsn_change[i] = combo_dsn[i];
}
final int margin = 8; final int margin = 8;
final int tilesX = ref_scene.getTileProcessor().getTilesX(); final int tilesX = ref_scene.getTileProcessor().getTilesX();
final int tilesY = ref_scene.getTileProcessor().getTilesY(); final int tilesY = ref_scene.getTileProcessor().getTilesY();
final double [][] combo_dsn_change = new double [combo_dsn_titles.length] [tilesX*tilesY];
String [] combo_dsn_titles = {"disp", "strength", "num_valid","change"}; for (int i = 0; i < combo_dsn.length; i++) { // 4 elements: "disp", "strength","disp_lma","num_valid"
if (combo_dsn[i] != null) combo_dsn_change[i] = combo_dsn[i]; // all but change
}
if (noise_sigma_level != null) { // add initial offset to the expected disparity
for (int i = 0; i < combo_dsn_change[0].length; i++) {
combo_dsn_change[0][i] += noise_sigma_level.initial_offset; // [2];
}
}
// combo_dsn_change[combo_dsn_change.length - 1] = new double [tilesX*tilesY];
if (debug_level > 0) { if (debug_level > 0) {
(new ShowDoubleFloatArrays()).showArrays( (new ShowDoubleFloatArrays()).showArrays(
combo_dsn_change, combo_dsn_change,
...@@ -3660,35 +3687,30 @@ public class OpticalFlow { ...@@ -3660,35 +3687,30 @@ public class OpticalFlow {
} }
final int max_refines = 10; final int max_refines = 10;
final String [] iter_titles = {"disp", "diff", "strength"}; // final String [] iter_titles = {"disp", "diff", "strength"};
final int [] iter_indices = {0,1,3};
final int last_slices = combo_dsn_titles.length; final int last_slices = combo_dsn_titles.length;
final int last_initial_slices = last_slices + iter_titles.length; final int last_initial_slices = last_slices + initial_indices.length;
final double [][] refine_results = new double [last_slices + 3 * (max_refines + 1)][]; // final double [][] refine_results = new double [last_slices + 3 * (max_refines + 1)][];
final double [][] refine_results = new double [last_slices + 4 * (max_refines + 1)][];
String [] refine_titles = new String [refine_results.length]; String [] refine_titles = new String [refine_results.length];
for (int i = 0; i < combo_dsn_titles.length; i++) { for (int i = 0; i < combo_dsn_titles.length; i++) {
refine_results[i] = combo_dsn_change[i]; refine_results[i] = combo_dsn_change[i]; // first 5 - references to 5-element combo_dsn_change
refine_titles[i] = combo_dsn_titles[i]+"-last"; refine_titles[i] = combo_dsn_titles[i]+"-last"; // "disp", "strength","disp_lma","num_valid","change"
} }
for (int i = 0; i < iter_titles.length; i++) { for (int i = 0; i < initial_indices.length; i++) {
refine_titles[last_slices + i] = iter_titles[i]+"-initial"; refine_titles[last_slices + i] = combo_dsn_titles[initial_indices[i]]+"-initial"; // "disp", "strength","num_valid"
if (combo_dsn_change[iter_indices[i]] != null) { if (combo_dsn_change[initial_indices[i]] != null) {
refine_results[last_slices + i] = combo_dsn_change[iter_indices[i]].clone(); refine_results[last_slices + i] = combo_dsn_change[initial_indices[i]].clone();
} else { } else {
refine_results[last_slices + i] = new double [tilesX * tilesY]; refine_results[last_slices + i] = new double [tilesX * tilesY];
} }
} }
for (int nrefine = 0; nrefine < max_refines; nrefine++) { for (int nrefine = 0; nrefine < max_refines; nrefine++) {
for (int i = 0; i < iter_titles.length; i++) { for (int i = 0; i < iter_indices.length; i++) {
refine_titles[last_initial_slices + i * max_refines + nrefine ] = combo_dsn_titles[iter_indices[i]]+"-"+nrefine; refine_titles[last_initial_slices + i * max_refines + nrefine ] = combo_dsn_titles[iter_indices[i]]+"-"+nrefine;
} }
} }
if (noise_sigma_level != null) { // add initial offset to the expected disparity
for (int i = 0; i < combo_dsn_change[0].length; i++) {
combo_dsn_change[0][i] += noise_sigma_level[2];
}
}
for (int nrefine = 0; nrefine < max_refines; nrefine++) { for (int nrefine = 0; nrefine < max_refines; nrefine++) {
Runtime.getRuntime().gc(); Runtime.getRuntime().gc();
System.out.println("--- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")"); System.out.println("--- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
...@@ -3702,10 +3724,12 @@ public class OpticalFlow { ...@@ -3702,10 +3724,12 @@ public class OpticalFlow {
combo_dsn_change[0], // final double [] disparity_ref, // disparity in the reference view tiles (Double.NaN - invalid) combo_dsn_change[0], // final double [] disparity_ref, // disparity in the reference view tiles (Double.NaN - invalid)
margin, // final int margin, margin, // final int margin,
nrefine, // final int nrefine, // just for debug title nrefine, // final int nrefine, // just for debug title
( nrefine == (max_refines - 1)) && clt_parameters.inp.show_final_2d, // final boolean show_2d_corr,
debug_level-5); // final int debug_level) debug_level-5); // final int debug_level)
Runtime.getRuntime().gc(); Runtime.getRuntime().gc();
System.out.println("--- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")"); System.out.println("--- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (debug_level > 0) { if (debug_level > 0) {
(new ShowDoubleFloatArrays()).showArrays( (new ShowDoubleFloatArrays()).showArrays(
disparity_map, disparity_map,
...@@ -3725,12 +3749,24 @@ public class OpticalFlow { ...@@ -3725,12 +3749,24 @@ public class OpticalFlow {
combo_dsn_change[1][nTile] = disparity_map[strength_index][nTile]; combo_dsn_change[1][nTile] = disparity_map[strength_index][nTile];
} }
} }
combo_dsn_change[combo_dsn_change.length -1] = disparity_map[disparity_index]; System.arraycopy(combo_dsn_change[0], 0, combo_dsn_change[2], 0, combo_dsn_change[0].length); // lma
// combo_dsn_change[2] = combo_dsn_change[0].clone(); // lma
double [] disp_lma = disparity_map[ImageDtt.DISPARITY_INDEX_POLY];
if (disp_lma != null) {
for (int i = 0; i < disp_lma.length; i++) {
if (Double.isNaN(disp_lma[i])) {
combo_dsn_change[2][i] = Double.NaN;
}
}
}
for (int i = 0; i < iter_titles.length; i++) { // combo_dsn_change[combo_dsn_change.length -1] = disparity_map[disparity_index];
System.arraycopy(disparity_map[disparity_index], 0, combo_dsn_change[combo_dsn_change.length -1], 0, combo_dsn_change[0].length); // lma
for (int i = 0; i < iter_indices.length; i++) {
refine_results[last_initial_slices + (i * max_refines) + nrefine] = combo_dsn_change[iter_indices[i]].clone(); refine_results[last_initial_slices + (i * max_refines) + nrefine] = combo_dsn_change[iter_indices[i]].clone();
} }
// clt_parameters.inp.show_final_2d, // final boolean show_2d_corr,
if (debug_level >0) { if (debug_level >0) {
(new ShowDoubleFloatArrays()).showArrays( (new ShowDoubleFloatArrays()).showArrays(
combo_dsn_change, combo_dsn_change,
...@@ -3754,13 +3790,19 @@ public class OpticalFlow { ...@@ -3754,13 +3790,19 @@ public class OpticalFlow {
//noise_sigma_level //noise_sigma_level
String rslt_suffix = "-results-nonoise"; String rslt_suffix = "-results-nonoise";
if (noise_sigma_level != null) { if (noise_sigma_level != null) {
rslt_suffix = "-results-lev_"+noise_sigma_level[0]+"-sigma_"+noise_sigma_level[1]+"-offset"+noise_sigma_level[2]; rslt_suffix =
// "-results-lev_"+noise_sigma_level[0]+
"-results-rnd_"+noise_sigma_level.scale_random+
"-fpn_"+ noise_sigma_level.scale_fpn+
"-sigma_"+ noise_sigma_level.sigma+ // [1]+
"-offset"+ noise_sigma_level.initial_offset+ // [2];
"-sensors"+ noise_sigma_level.used_sensors;
if (ref_only) { if (ref_only) {
rslt_suffix +="-nointer"; rslt_suffix +="-nointer";
} else { } else {
rslt_suffix +="-inter"; rslt_suffix +="-inter";
} }
rslt_suffix +="-mask"+clt_parameters.img_dtt.dbg_pair_mask; //rslt_suffix +="-mask"+clt_parameters.img_dtt.dbg_pair_mask;
} }
ref_scene.saveDoubleArrayInModelDirectory( ref_scene.saveDoubleArrayInModelDirectory(
rslt_suffix, // String suffix, rslt_suffix, // String suffix,
...@@ -4002,9 +4044,9 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -4002,9 +4044,9 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
final double disparity_corr = debug_disparity_bias; // 0.0; // (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction); final double disparity_corr = debug_disparity_bias; // 0.0; // (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
for (int nscene = 0; nscene < num_scenes; nscene++) { for (int nscene = 0; nscene < num_scenes; nscene++) {
if (nscene == indx_ref) { if (nscene == indx_ref) {
System.out.println("\nCorrelating reference scene\n"); System.out.println("\nCorrelating reference scene, nrefine = "+nrefine+"\n");
} else { } else {
System.out.println("\nCorrelating scene "+nscene+"\n"); System.out.println("\nCorrelating scene "+nrefine+":"+nscene+"\n");
} }
String ts = scenes[nscene].getImageName(); String ts = scenes[nscene].getImageName();
double [][] scene_pXpYD; double [][] scene_pXpYD;
...@@ -4936,9 +4978,9 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -4936,9 +4978,9 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
TpTask[] tp_tasks_ref = null; TpTask[] tp_tasks_ref = null;
for (int nscene = 0; nscene < num_scenes; nscene++) { for (int nscene = 0; nscene < num_scenes; nscene++) {
if (nscene == indx_ref) { if (nscene == indx_ref) {
System.out.println("\nCorrelating reference scene\n"); System.out.println("\nCorrelating reference scene, nrefine = "+nrefine+"\n");
} else { } else {
System.out.println("\nCorrelating scene "+nscene+"\n"); System.out.println("\nCorrelating scene "+nrefine+":"+nscene+"\n");
} }
String ts = scenes[nscene].getImageName(); String ts = scenes[nscene].getImageName();
double [][] scene_pXpYD; double [][] scene_pXpYD;
...@@ -5479,6 +5521,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -5479,6 +5521,7 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
final double [] disparity_ref, // disparity in the reference view tiles (Double.NaN - invalid) final double [] disparity_ref, // disparity in the reference view tiles (Double.NaN - invalid)
final int margin, final int margin,
final int nrefine, // just for debug title final int nrefine, // just for debug title
final boolean show_2d_corr,
final int debug_level final int debug_level
) )
{ {
...@@ -5494,12 +5537,9 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -5494,12 +5537,9 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
double fat_zero_single = clt_parameters.getGpuFatZero(ref_scene.isMonochrome()); // for single scene double fat_zero_single = clt_parameters.getGpuFatZero(ref_scene.isMonochrome()); // for single scene
// TODO: make per-tile variable // TODO: make per-tile variable
double scaled_fat_zero = fat_zero_single / (scenes.length); double scaled_fat_zero = fat_zero_single / (scenes.length);
boolean show_accumulated_correlations =debug_level > -5; boolean show_accumulated_correlations = show_2d_corr || debug_level > -5;
boolean show_reference_correlations =debug_level > -5; boolean show_reference_correlations = show_2d_corr || debug_level > -5;
final float [][][] fclt_corr = (show_accumulated_correlations || show_reference_correlations) ? (new float [tilesX * tilesY][][]) : null; // not all used
final float [][][] fclt_corr = (show_accumulated_correlations || show_reference_correlations) ? (new float [tilesX * tilesY][][]) : null; // not all used
ImageDtt image_dtt; ImageDtt image_dtt;
image_dtt = new ImageDtt( image_dtt = new ImageDtt(
numSens, numSens,
...@@ -5523,9 +5563,9 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad ...@@ -5523,9 +5563,9 @@ public double[][] correlateIntersceneDebug( // only uses GPU and quad
TpTask[] tp_tasks_ref = null; TpTask[] tp_tasks_ref = null;
for (int nscene = 0; nscene < num_scenes; nscene++) { for (int nscene = 0; nscene < num_scenes; nscene++) {
if (nscene == indx_ref) { if (nscene == indx_ref) {
System.out.println("\nCorrelating reference scene\n"); System.out.println("\nCorrelating reference scene, nrefine = "+nrefine+"\n");
} else { } else {
System.out.println("\nCorrelating scene "+nscene+"\n"); System.out.println("\nCorrelating scene "+nrefine+":"+nscene+"\n");
} }
String ts = scenes[nscene].getImageName(); String ts = scenes[nscene].getImageName();
double [][] scene_pXpYD; double [][] scene_pXpYD;
......
...@@ -228,7 +228,8 @@ public class QuadCLTCPU { ...@@ -228,7 +228,8 @@ public class QuadCLTCPU {
String set_name, String set_name,
CLTParameters clt_parameters, CLTParameters clt_parameters,
ColorProcParameters colorProcParameters, ColorProcParameters colorProcParameters,
double [] noise_sigma_level, NoiseParameters noise_sigma_level,
QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
int threadsMax, int threadsMax,
int debugLevel) int debugLevel)
{ {
...@@ -238,6 +239,7 @@ public class QuadCLTCPU { ...@@ -238,6 +239,7 @@ public class QuadCLTCPU {
clt_parameters, clt_parameters,
colorProcParameters, colorProcParameters,
noise_sigma_level, // double [] noise_sigma_level, noise_sigma_level, // double [] noise_sigma_level,
ref_scene, // QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
threadsMax, threadsMax,
debugLevel); debugLevel);
...@@ -282,7 +284,8 @@ public class QuadCLTCPU { ...@@ -282,7 +284,8 @@ public class QuadCLTCPU {
quadCLT.restoreFromModel( quadCLT.restoreFromModel(
clt_parameters, clt_parameters,
colorProcParameters, colorProcParameters,
null, // double [] noise_sigma_level, null, // double [] noise_sigma_level,
null, // final QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
threadsMax, threadsMax,
debugLevel); debugLevel);
...@@ -614,7 +617,9 @@ public class QuadCLTCPU { ...@@ -614,7 +617,9 @@ public class QuadCLTCPU {
public QuadCLTCPU restoreFromModel( public QuadCLTCPU restoreFromModel(
CLTParameters clt_parameters, CLTParameters clt_parameters,
ColorProcParameters colorProcParameters, ColorProcParameters colorProcParameters,
double [] noise_sigma_level, // double []
NoiseParameters noise_sigma_level,
QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
int threadsMax, int threadsMax,
int debugLevel) int debugLevel)
...@@ -654,6 +659,7 @@ public class QuadCLTCPU { ...@@ -654,6 +659,7 @@ public class QuadCLTCPU {
if (noise_sigma_level != null) { if (noise_sigma_level != null) {
generateAddNoise( generateAddNoise(
"-NOISE", "-NOISE",
ref_scene, // final QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
noise_sigma_level, noise_sigma_level,
threadsMax, threadsMax,
1); // debugLevel); // final int debug_level) 1); // debugLevel); // final int debug_level)
...@@ -686,12 +692,110 @@ public class QuadCLTCPU { ...@@ -686,12 +692,110 @@ public class QuadCLTCPU {
public void generateAddNoise( public void generateAddNoise(
final String suffix, final String suffix,
final double [] noise_sigma_level, final QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
// final double []
final NoiseParameters noise_sigma_level,
final int threadsMax,
final int debug_level)
{
final double scale_random = noise_sigma_level.scale_random; // _sigma_level[0];
final double scale_fpn = noise_sigma_level.scale_fpn; // noise_sigma_level[0];
final double sigma = noise_sigma_level.sigma; // [1];
ImagePlus imp = generateAddNoise(
suffix, // final String suffix,
sigma, // final double sigma,
threadsMax, // final int threadsMax,
debug_level); // final int debug_level) : null;
ImagePlus imp_ref = null;
if (scale_fpn >0){
if (ref_scene !=null) {
imp_ref= ref_scene.generateAddNoise(
suffix, // final String suffix,
sigma, // final double sigma,
threadsMax, // final int threadsMax,
debug_level); // final int debug_level) : null;
} else {
imp_ref= imp; // when calculating ref_scene itself it is provided as null
}
}
final int num_cams = this.image_data.length;
final int num_cols = image_data[0].length;
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
ImageStack imageStack = imp.getStack();
final float [][] fpixels = new float [num_cams][];
for (int q = 0; q < num_cams; q++) {
fpixels[q] = (float[]) imageStack.getPixels(q+1);
}
final float [][] fpixels_ref = (imp_ref != null) ? (new float [num_cams][]): null;
if (imp_ref != null) {
ImageStack imageStack_ref = imp_ref.getStack();
for (int q = 0; q < num_cams; q++) {
fpixels_ref[q] = (float[]) imageStack_ref.getPixels(q+1);
}
}
for (int q = 0; q < num_cams; q++) {
final int fq = q;
for (int c =0; c < num_cols; c++) {
final int fc = c;
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int i = ai.getAndIncrement(); i < image_data[fq][fc].length; i = ai.getAndIncrement()) {
if (image_data[fq][fc][i] != 0.0) {
image_data[fq][fc][i] += scale_random * fpixels[fq][i];
if (fpixels_ref != null) {
image_data[fq][fc][i] += scale_fpn * fpixels_ref[fq][i];
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
}
if (debug_level > 100) {
double [][] dbg_data = new double [num_cams*num_cols][];
for (int q = 0; q < num_cams;q++) {
for (int c = 0; c < num_cols; c++) {
dbg_data[q*num_cols+c] = image_data[q][c];
}
}
int [] image_wh = geometryCorrection.getSensorWH();
String noise_suffix = suffix + sigma;
saveDoubleArrayInModelDirectory(
noise_suffix + "-MIXED-RND"+scale_random+"-FPN"+scale_fpn, // noise_sigma_level[0], // String suffix,
null, // String [] labels, // or null
dbg_data, // double [][] data,
image_wh[0], // int width,
image_wh[1]); // int height)
}
}
// May need to run twice - for both refscene and this one if fpn >=0
/**
* Load existing noise image, generate if it did no exist
* @param suffix file name suffix (sigma will be added)
* @param sigma blur sigma (in pixels), the amount of added noise will be used by caller, noise image only depends on sigma
* @param threadsMax
* @param debug_level
* @return Noise image, one slice per sensor (Bayer mosaic still use 1 slice per sensor)
*/
public ImagePlus generateAddNoise(
final String suffix,
final double sigma,
final int threadsMax, final int threadsMax,
final int debug_level) final int debug_level)
{ {
final double scale =noise_sigma_level[0];
final double sigma =noise_sigma_level[1];
final int num_cams = this.image_data.length; final int num_cams = this.image_data.length;
final int num_cols = image_data[0].length; final int num_cols = image_data[0].length;
final int [] image_wh = geometryCorrection.getSensorWH(); final int [] image_wh = geometryCorrection.getSensorWH();
...@@ -815,45 +919,12 @@ public class QuadCLTCPU { ...@@ -815,45 +919,12 @@ public class QuadCLTCPU {
image_wh[0], // int width, image_wh[0], // int width,
image_wh[1]); // int height) image_wh[1]); // int height)
} }
ImageStack imageStack = imp.getStack(); return imp;
float [][] fpixels = new float [num_cams][]; }
for (int q = 0; q < num_cams; q++) {
fpixels[q] = (float[]) imageStack.getPixels(q+1);
}
for (int q = 0; q < num_cams; q++) {
final int fq = q;
for (int c =0; c < num_cols; c++) {
final int fc = c;
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int i = ai.getAndIncrement(); i < image_data[fq][fc].length; i = ai.getAndIncrement()) {
if (image_data[fq][fc][i] != 0.0) {
image_data[fq][fc][i] += scale * fpixels[fq][i];
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
}
if (debug_level > 100) {
double [][] dbg_data = new double [num_cams*num_cols][];
for (int q = 0; q < num_cams;q++) {
for (int c = 0; c < num_cols; c++) {
dbg_data[q*num_cols+c] = image_data[q][c];
}
}
saveDoubleArrayInModelDirectory(
noise_suffix + "-MIXED"+noise_sigma_level[0], // String suffix,
null, // String [] labels, // or null
dbg_data, // double [][] data,
image_wh[0], // int width,
image_wh[1]); // int height)
}
}
public ImagePlus saveDoubleArrayInModelDirectory( public ImagePlus saveDoubleArrayInModelDirectory(
...@@ -874,6 +945,7 @@ public class QuadCLTCPU { ...@@ -874,6 +945,7 @@ public class QuadCLTCPU {
ImagePlus imp = new ImagePlus( file_name, imageStack); ImagePlus imp = new ImagePlus( file_name, imageStack);
FileSaver fs=new FileSaver(imp); FileSaver fs=new FileSaver(imp);
fs.saveAsTiff(file_path); fs.saveAsTiff(file_path);
System.out.println("saveDoubleArrayInModelDirectory(): saved "+file_path);
return imp; return imp;
} }
......
...@@ -8619,6 +8619,7 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8619,6 +8619,7 @@ if (debugLevel > -100) return true; // temporarily !
clt_parameters, clt_parameters,
colorProcParameters, // colorProcParameters, //
null, // noise_sigma_level, // double [] noise_sigma_level, null, // noise_sigma_level, // double [] noise_sigma_level,
null, // final QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
threadsMax, threadsMax,
debugLevel); debugLevel);
// temporarily fix wrong sign: // temporarily fix wrong sign:
...@@ -8664,12 +8665,16 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8664,12 +8665,16 @@ if (debugLevel > -100) return true; // temporarily !
// double [] noise_sigma_level = {1.0, 1.5, 1.0}; // amount, sigma, offset // double [] noise_sigma_level = {1.0, 1.5, 1.0}; // amount, sigma, offset
// double [] noise_sigma_level = {3.0, 1.5, 1.0}; // amount, sigma, offset // double [] noise_sigma_level = {3.0, 1.5, 1.0}; // amount, sigma, offset
// double [] noise_sigma_level = {5.0, 1.5, 1.0}; // amount, sigma, offset // double [] noise_sigma_level = {5.0, 1.5, 1.0}; // amount, sigma, offset
double [] noise_sigma_level = null; // double [] noise_sigma_level = null;
if (clt_parameters.inp.noise_scale > 0.0) { NoiseParameters noise_sigma_level = null;
noise_sigma_level = new double[] { if ((clt_parameters.inp.noise.scale_random > 0.0) || (clt_parameters.inp.noise.scale_fpn > 0.0)){
noise_sigma_level = clt_parameters.inp.noise.clone();
/*
new double[] {
clt_parameters.inp.noise_scale, clt_parameters.inp.noise_scale,
clt_parameters.inp.noise_sigma, clt_parameters.inp.noise_sigma,
clt_parameters.inp.initial_offset}; // amount, sigma, offset clt_parameters.inp.initial_offset}; // amount, sigma, offset
*/
} }
boolean ref_only = clt_parameters.inp.ref_only; // true; // process only reference frame (false - inter-scene) boolean ref_only = clt_parameters.inp.ref_only; // true; // process only reference frame (false - inter-scene)
...@@ -8692,6 +8697,7 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8692,6 +8697,7 @@ if (debugLevel > -100) return true; // temporarily !
clt_parameters, clt_parameters,
colorProcParameters, // colorProcParameters, //
noise_sigma_level, // double [] noise_sigma_level, noise_sigma_level, // double [] noise_sigma_level,
null, // QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
threadsMax, threadsMax,
clt_parameters.inp.noise_debug_level); // debugLevel); clt_parameters.inp.noise_debug_level); // debugLevel);
/**/ /**/
...@@ -8722,12 +8728,16 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8722,12 +8728,16 @@ if (debugLevel > -100) return true; // temporarily !
// double [] noise_sigma_level = {1.0, 1.5, 1.0}; // amount, sigma, offset // double [] noise_sigma_level = {1.0, 1.5, 1.0}; // amount, sigma, offset
// double [] noise_sigma_level = {3.0, 1.5, 1.0}; // amount, sigma, offset // double [] noise_sigma_level = {3.0, 1.5, 1.0}; // amount, sigma, offset
// double [] noise_sigma_level = {5.0, 1.5, 1.0}; // amount, sigma, offset // double [] noise_sigma_level = {5.0, 1.5, 1.0}; // amount, sigma, offset
double [] noise_sigma_level = null; // double [] noise_sigma_level = null;
if (clt_parameters.inp.noise_scale >= 0.0) {// <0 - will generate no-noise data NoiseParameters noise_sigma_level = null;
noise_sigma_level = new double[] { if ((clt_parameters.inp.noise.scale_random >= 0.0) || (clt_parameters.inp.noise.scale_fpn >= 0.0)) {// <0 - will generate no-noise data
noise_sigma_level = clt_parameters.inp.noise.clone();
/*
noise_sigma_level = new double[] {
clt_parameters.inp.noise_scale, clt_parameters.inp.noise_scale,
clt_parameters.inp.noise_sigma, clt_parameters.inp.noise_sigma,
clt_parameters.inp.initial_offset}; // amount, sigma, offset clt_parameters.inp.initial_offset}; // amount, sigma, offset\
*/
} }
boolean ref_only = clt_parameters.inp.ref_only; // true; // process only reference frame (false - inter-scene) boolean ref_only = clt_parameters.inp.ref_only; // true; // process only reference frame (false - inter-scene)
...@@ -8750,6 +8760,7 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8750,6 +8760,7 @@ if (debugLevel > -100) return true; // temporarily !
clt_parameters, clt_parameters,
colorProcParameters, // colorProcParameters, //
noise_sigma_level, // double [] noise_sigma_level, noise_sigma_level, // double [] noise_sigma_level,
null, // final QuadCLTCPU ref_scene, // may be null if scale_fpn <= 0
threadsMax, threadsMax,
clt_parameters.inp.noise_debug_level); // debugLevel); clt_parameters.inp.noise_debug_level); // debugLevel);
/* /*
...@@ -8760,7 +8771,10 @@ if (debugLevel > -100) return true; // temporarily ! ...@@ -8760,7 +8771,10 @@ if (debugLevel > -100) return true; // temporarily !
*/ */
// Create 4-slice image with noise from the current data // Create 4-slice image with noise from the current data
if (noise_sigma_level != null) { if (noise_sigma_level != null) {
String noisy_4slice_suffix = "-noise-level_"+ noise_sigma_level[0]+"-sigma_"+noise_sigma_level[1]; String noisy_4slice_suffix =
"-noise-random_"+ noise_sigma_level.scale_random+
"-noise-fpn_"+ noise_sigma_level.scale_fpn+
"-sigma_"+noise_sigma_level.sigma;
ref_quadCLT.genSave4sliceImage( ref_quadCLT.genSave4sliceImage(
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
noisy_4slice_suffix, // String suffix, noisy_4slice_suffix, // String suffix,
......
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