Commit 632eb62e authored by Andrey Filippov's avatar Andrey Filippov

Set default directory, averaging to multithreaded

parent 50de1233
...@@ -1102,24 +1102,25 @@ if (MORE_BUTTONS) { ...@@ -1102,24 +1102,25 @@ if (MORE_BUTTONS) {
Runtime runtime = Runtime.getRuntime(); Runtime runtime = Runtime.getRuntime();
runtime.gc(); runtime.gc();
if (DEBUG_LEVEL>0) System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")"); if (DEBUG_LEVEL>0) System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
if (label==null) return; if (label==null) return;
String LOG_LEVEL; if (LWIR_PARAMETERS !=null) {
switch (MASTER_DEBUG_LEVEL) { String LOG_LEVEL;
case -2: LOG_LEVEL = "FATAL"; break; switch (LWIR_PARAMETERS.getDebugLevel()) {
case -1: LOG_LEVEL = "ERROR"; break; case -2: LOG_LEVEL = "FATAL"; break;
case 0: LOG_LEVEL = "WARN"; break; case -1: LOG_LEVEL = "ERROR"; break;
case 1: LOG_LEVEL = "INFO"; break; case 0: LOG_LEVEL = "WARN"; break;
case 2: LOG_LEVEL = "DEBUG"; break; case 1: LOG_LEVEL = "INFO"; break;
default: LOG_LEVEL = "OFF"; case 2: LOG_LEVEL = "DEBUG"; break;
} default: LOG_LEVEL = "OFF";
}
boolean LOG_LEVEL_SET = loci.common.DebugTools.enableLogging(LOG_LEVEL); boolean LOG_LEVEL_SET = loci.common.DebugTools.enableLogging(LOG_LEVEL);
if (!LOG_LEVEL_SET) { // only first time true if (!LOG_LEVEL_SET) { // only first time true
loci.common.DebugTools.setRootLevel(LOG_LEVEL); loci.common.DebugTools.setRootLevel(LOG_LEVEL);
} }
System.out.println("DEBUG_LEVEL = "+DEBUG_LEVEL+", MASTER_DEBUG_LEVEL = "+MASTER_DEBUG_LEVEL+ System.out.println("DEBUG_LEVEL = "+DEBUG_LEVEL+", LWIR_PARAMETERS.getDebugLevel() = "+LWIR_PARAMETERS.getDebugLevel()+
" LOG_LEVEL="+LOG_LEVEL+"LOG_LEVEL_SET="+LOG_LEVEL_SET); " LOG_LEVEL="+LOG_LEVEL+"LOG_LEVEL_SET="+LOG_LEVEL_SET);
}
if (FOCUSING_FIELD!=null) FOCUSING_FIELD.setThreads(THREADS_MAX); if (FOCUSING_FIELD!=null) FOCUSING_FIELD.setThreads(THREADS_MAX);
/* ======================================================================== */ /* ======================================================================== */
...@@ -9441,7 +9442,8 @@ if (MORE_BUTTONS) { ...@@ -9441,7 +9442,8 @@ if (MORE_BUTTONS) {
if (LWIR_READER == null) { if (LWIR_READER == null) {
LWIR_READER = new LwirReader(LWIR_PARAMETERS); LWIR_READER = new LwirReader(LWIR_PARAMETERS);
} }
ImagePlus [] imps = LWIR_READER.acquire("/data_ssd/imagej-elphel/attic/camera_img/test-calib"); // directory to save // ImagePlus [] imps = LWIR_READER.acquire(DISTORTION_PROCESS_CONFIGURATION.sourceDirectory); // directory to save
ImagePlus [] imps = LWIR_READER.acquire("attic/lwir_test_images"); // directory to save
if (imps != null) { if (imps != null) {
// for (ImagePlus imp: imps) { // for (ImagePlus imp: imps) {
// imp.show(); // imp.show();
...@@ -897,22 +897,24 @@ private Panel panel1, ...@@ -897,22 +897,24 @@ private Panel panel1,
if (DEBUG_LEVEL>0) System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")"); if (DEBUG_LEVEL>0) System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
CLT_PARAMETERS.batch_run = false; CLT_PARAMETERS.batch_run = false;
if (label==null) return; if (label==null) return;
String LOG_LEVEL; if ((CLT_PARAMETERS !=null) && (CLT_PARAMETERS.lwir !=null)) {
switch (MASTER_DEBUG_LEVEL) { String LOG_LEVEL;
case -2: LOG_LEVEL = "FATAL"; break; switch (CLT_PARAMETERS.lwir.getDebugLevel()) {
case -1: LOG_LEVEL = "ERROR"; break; case -2: LOG_LEVEL = "FATAL"; break;
case 0: LOG_LEVEL = "WARN"; break; case -1: LOG_LEVEL = "ERROR"; break;
case 1: LOG_LEVEL = "INFO"; break; case 0: LOG_LEVEL = "WARN"; break;
case 2: LOG_LEVEL = "DEBUG"; break; case 1: LOG_LEVEL = "INFO"; break;
default: LOG_LEVEL = "OFF"; case 2: LOG_LEVEL = "DEBUG"; break;
} default: LOG_LEVEL = "OFF";
}
boolean LOG_LEVEL_SET = loci.common.DebugTools.enableLogging(LOG_LEVEL); boolean LOG_LEVEL_SET = loci.common.DebugTools.enableLogging(LOG_LEVEL);
if (!LOG_LEVEL_SET) { // only first time true if (!LOG_LEVEL_SET) { // only first time true
loci.common.DebugTools.setRootLevel(LOG_LEVEL); loci.common.DebugTools.setRootLevel(LOG_LEVEL);
} }
System.out.println("DEBUG_LEVEL = "+DEBUG_LEVEL+", MASTER_DEBUG_LEVEL = "+MASTER_DEBUG_LEVEL+ System.out.println("DEBUG_LEVEL = "+DEBUG_LEVEL+", CLT_PARAMETERS.lwir.getDebugLevel() = "+CLT_PARAMETERS.lwir.getDebugLevel()+
" LOG_LEVEL="+LOG_LEVEL+"LOG_LEVEL_SET="+LOG_LEVEL_SET); " LOG_LEVEL="+LOG_LEVEL+"LOG_LEVEL_SET="+LOG_LEVEL_SET);
}
/* ======================================================================== */ /* ======================================================================== */
if (label.equals("Configure spilt")) { if (label.equals("Configure spilt")) {
...@@ -4873,7 +4875,7 @@ private Panel panel1, ...@@ -4873,7 +4875,7 @@ private Panel panel1,
if (LWIR_READER == null) { if (LWIR_READER == null) {
LWIR_READER = new LwirReader(CLT_PARAMETERS.lwir); LWIR_READER = new LwirReader(CLT_PARAMETERS.lwir);
} }
ImagePlus [] imps = LWIR_READER.acquire("/data_ssd/imagej-elphel/attic/camera_img/test"); // directory to save ImagePlus [] imps = LWIR_READER.acquire("attic/lwir_test_images"); // directory to save
if (imps != null) { if (imps != null) {
for (ImagePlus imp: imps) { for (ImagePlus imp: imps) {
// imp.show(); // imp.show();
......
...@@ -208,12 +208,54 @@ public class LwirReader { ...@@ -208,12 +208,54 @@ public class LwirReader {
return imps; return imps;
} }
public ImagePlus [] averageMultiFrames(ImagePlus [][] sets) { public ImagePlus [] averageMultiFrames(
//TODO: convert to multithreaded ! final ImagePlus [][] sets) {
int num_frames = sets.length; final int num_frames = sets.length;
int num_channels = sets[0].length; final int num_channels = sets[0].length;
ImagePlus [] imps_avg = new ImagePlus [num_channels]; final ImagePlus [] imps_avg = new ImagePlus [num_channels];
final Thread[] threads = newThreadArray(MAX_THREADS);
final AtomicInteger indxAtomic = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int chn = indxAtomic.getAndIncrement(); chn < num_channels; chn = indxAtomic.getAndIncrement())
{
int width = sets[0][chn].getWidth();
int height = sets[0][chn].getHeight();
String title = sets[0][chn].getTitle()+"_average"+num_frames;
float [] pixels_avg = (float []) sets[0][chn].getProcessor().getPixels(); //null pointer
for (int n = 1; n < num_frames; n++) {
float [] pixels = (float []) sets[n][chn].getProcessor().getPixels();
for (int i = 0; i < pixels_avg.length; i++) {
pixels_avg[i] += pixels[i];
}
}
double scale = 1.0/num_frames;
for (int i = 0; i < pixels_avg.length; i++) {
pixels_avg[i] *= scale;
}
ImageProcessor ip=new FloatProcessor(width,height);
ip.setPixels(pixels_avg);
ip.resetMinAndMax();
imps_avg[chn]= new ImagePlus(title, ip);
Properties properties0 = sets[0][chn].getProperties();
for (String key:properties0.stringPropertyNames()) {
imps_avg[chn].setProperty(key, properties0.getProperty(key));
}
imps_avg[chn].setProperty("average", ""+num_frames);
if (motorsPosition!=null) for (int m=0;m<motorsPosition.length;m++ ) {
imps_avg[chn].setProperty("MOTOR"+(m+1), ""+motorsPosition[m]);
}
ImagejJp4Tiff.encodeProperiesToInfo(imps_avg[chn]);
}
}
};
}
startAndJoin(threads);
/*
for (int chn = 0; chn < num_channels; chn++) { for (int chn = 0; chn < num_channels; chn++) {
int width = sets[0][chn].getWidth(); int width = sets[0][chn].getWidth();
int height = sets[0][chn].getHeight(); int height = sets[0][chn].getHeight();
...@@ -244,7 +286,7 @@ public class LwirReader { ...@@ -244,7 +286,7 @@ public class LwirReader {
ImagejJp4Tiff.encodeProperiesToInfo(imps_avg[chn]); ImagejJp4Tiff.encodeProperiesToInfo(imps_avg[chn]);
// TODO: Overwrite some properties? // TODO: Overwrite some properties?
} }
*/
return imps_avg; return imps_avg;
} }
...@@ -513,13 +555,14 @@ public class LwirReader { ...@@ -513,13 +555,14 @@ public class LwirReader {
String set_path = dirpath+Prefs.getFileSeparator()+set_name; String set_path = dirpath+Prefs.getFileSeparator()+set_name;
File set_dir = new File(set_path); File set_dir = new File(set_path);
set_dir.mkdirs(); // including parent set_dir.mkdirs(); // including parent
LOGGER.warn("Saving image set to: "+set_dir.getAbsolutePath());
for (ImagePlus imp:imps_avg) { for (ImagePlus imp:imps_avg) {
String fname = imp.getTitle(); String fname = imp.getTitle();
fname = fname.substring(0, fname.lastIndexOf('_')) + ".tiff"; // remove _average fname = fname.substring(0, fname.lastIndexOf('_')) + ".tiff"; // remove _average
FileSaver fs=new FileSaver(imp); FileSaver fs=new FileSaver(imp);
String path=set_path+Prefs.getFileSeparator()+fname; String path=set_path+Prefs.getFileSeparator()+fname;
IJ.showStatus("Saving "+path); IJ.showStatus("Saving "+path);
LOGGER.debug("LWIR_ACQUIRE: 'Saving "+path+ " (and other with the same timestamp)" ); LOGGER.info("LWIR_ACQUIRE: 'Saving "+path );
fs.saveAsTiff(path); fs.saveAsTiff(path);
} }
} }
......
...@@ -49,6 +49,7 @@ public class LwirReaderParameters { ...@@ -49,6 +49,7 @@ public class LwirReaderParameters {
protected double vnir_gain_g = 2.0; protected double vnir_gain_g = 2.0;
protected double vnir_gain_rg = 0.7705; // 1.116; halogen/fluorescent protected double vnir_gain_rg = 0.7705; // 1.116; halogen/fluorescent
protected double vnir_gain_bg = 2.401; // 1.476; protected double vnir_gain_bg = 2.401; // 1.476;
/* /*
protected double [] vnir_exp_corr = {1.0, 1.0, 1.0, 1.0}; protected double [] vnir_exp_corr = {1.0, 1.0, 1.0, 1.0};
protected double [] vnir_gcorr_rbgb = { protected double [] vnir_gcorr_rbgb = {
...@@ -69,9 +70,17 @@ public class LwirReaderParameters { ...@@ -69,9 +70,17 @@ public class LwirReaderParameters {
protected int vnir_lag = 1; // frames protected int vnir_lag = 1; // frames
protected double max_mismatch_ms = 0.05; protected double max_mismatch_ms = 0.05;
protected int max_frame_diff = 1; // 2; protected int max_frame_diff = 1; // 2;
protected int debug_level = 0;//-3: OFF, -2:Fatal, -1:ERROR, 0:WARN, 1:INFO,2:DEBUG
// --- interface methods // --- interface methods
public int getDebugLevel() {
return this.debug_level;
}
public void setDebugLevel(int level) {
this.debug_level = level;
}
public void setProperties(String prefix,Properties properties){ public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"avg_number", this.avg_number+""); properties.setProperty(prefix+"avg_number", this.avg_number+"");
properties.setProperty(prefix+"lwir_ffc", this.lwir_ffc+""); properties.setProperty(prefix+"lwir_ffc", this.lwir_ffc+"");
...@@ -96,6 +105,8 @@ public class LwirReaderParameters { ...@@ -96,6 +105,8 @@ public class LwirReaderParameters {
properties.setProperty(prefix+"vnir_lag", this.vnir_lag+""); properties.setProperty(prefix+"vnir_lag", this.vnir_lag+"");
properties.setProperty(prefix+"max_mismatch_ms", this.max_mismatch_ms+""); properties.setProperty(prefix+"max_mismatch_ms", this.max_mismatch_ms+"");
properties.setProperty(prefix+"max_frame_diff", this.max_frame_diff+""); properties.setProperty(prefix+"max_frame_diff", this.max_frame_diff+"");
properties.setProperty(prefix+"debug_level", this.debug_level+"");
} }
public void getProperties(String prefix,Properties properties){ public void getProperties(String prefix,Properties properties){
...@@ -122,6 +133,7 @@ public class LwirReaderParameters { ...@@ -122,6 +133,7 @@ public class LwirReaderParameters {
if (properties.getProperty(prefix+"vnir_lag")!=null) this.vnir_lag=Integer.parseInt(properties.getProperty(prefix+"vnir_lag")); if (properties.getProperty(prefix+"vnir_lag")!=null) this.vnir_lag=Integer.parseInt(properties.getProperty(prefix+"vnir_lag"));
if (properties.getProperty(prefix+"max_mismatch_ms")!=null) this.max_mismatch_ms=Double.parseDouble(properties.getProperty(prefix+"max_mismatch_ms")); if (properties.getProperty(prefix+"max_mismatch_ms")!=null) this.max_mismatch_ms=Double.parseDouble(properties.getProperty(prefix+"max_mismatch_ms"));
if (properties.getProperty(prefix+"max_frame_diff")!=null) this.max_frame_diff=Integer.parseInt(properties.getProperty(prefix+"max_frame_diff")); if (properties.getProperty(prefix+"max_frame_diff")!=null) this.max_frame_diff=Integer.parseInt(properties.getProperty(prefix+"max_frame_diff"));
if (properties.getProperty(prefix+"debug_level")!=null) this.debug_level=Integer.parseInt(properties.getProperty(prefix+"debug_level"));
parameters_updated = true; parameters_updated = true;
} }
@Override @Override
...@@ -150,6 +162,7 @@ public class LwirReaderParameters { ...@@ -150,6 +162,7 @@ public class LwirReaderParameters {
lrp.vnir_lag= this.vnir_lag; lrp.vnir_lag= this.vnir_lag;
lrp.max_mismatch_ms= this.max_mismatch_ms; lrp.max_mismatch_ms= this.max_mismatch_ms;
lrp.max_frame_diff= this.max_frame_diff; lrp.max_frame_diff= this.max_frame_diff;
lrp.debug_level= this.debug_level;
return lrp; return lrp;
} }
...@@ -184,7 +197,8 @@ public class LwirReaderParameters { ...@@ -184,7 +197,8 @@ public class LwirReaderParameters {
(lrp.lwir_trig_dly == this.lwir_trig_dly) && (lrp.lwir_trig_dly == this.lwir_trig_dly) &&
(lrp.vnir_lag == this.vnir_lag) && (lrp.vnir_lag == this.vnir_lag) &&
(lrp.max_mismatch_ms == this.max_mismatch_ms) && (lrp.max_mismatch_ms == this.max_mismatch_ms) &&
(lrp.max_frame_diff == this.max_frame_diff); (lrp.max_frame_diff == this.max_frame_diff) &&
(lrp.debug_level == this.debug_level);
} }
@Override @Override
...@@ -242,6 +256,7 @@ public class LwirReaderParameters { ...@@ -242,6 +256,7 @@ public class LwirReaderParameters {
gd.addNumericField("VNIR lag", this.vnir_lag, 0,3,"","Visible camera lag (in frames) relative to LWIR one"); gd.addNumericField("VNIR lag", this.vnir_lag, 0,3,"","Visible camera lag (in frames) relative to LWIR one");
gd.addNumericField("Max mismatch", this.max_mismatch_ms, 3,6,"ms","Maximal mismatch between image timestamps. Larger mismatch requires LWIR sinsor reinitialization"); gd.addNumericField("Max mismatch", this.max_mismatch_ms, 3,6,"ms","Maximal mismatch between image timestamps. Larger mismatch requires LWIR sinsor reinitialization");
gd.addNumericField("Max frame diff",this.max_frame_diff, 0,3,"","Maximal difference in frames between simultaneously acquired channels as calculated from the timestamps"); gd.addNumericField("Max frame diff",this.max_frame_diff, 0,3,"","Maximal difference in frames between simultaneously acquired channels as calculated from the timestamps");
gd.addNumericField("Debug level", this.debug_level, 0,3,"","Image acquisition log level: -3: OFF, -2:FATAL, -1:ERROR, 0:WARN, 1:INFO, 2:DEBUG");
} }
public void dialogAnswers(GenericJTabbedDialog gd) { public void dialogAnswers(GenericJTabbedDialog gd) {
...@@ -268,6 +283,7 @@ public class LwirReaderParameters { ...@@ -268,6 +283,7 @@ public class LwirReaderParameters {
this.vnir_lag = (int) gd.getNextNumber(); this.vnir_lag = (int) gd.getNextNumber();
this.max_mismatch_ms = gd.getNextNumber(); this.max_mismatch_ms = gd.getNextNumber();
this.max_frame_diff = (int) gd.getNextNumber(); this.max_frame_diff = (int) gd.getNextNumber();
this.debug_level = (int) gd.getNextNumber();
parameters_updated = true; parameters_updated = true;
} }
......
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