Commit da48d22b authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

fixing headless run

parent 1b78d16a
...@@ -573,7 +573,7 @@ public class EyesisCorrectionParameters { ...@@ -573,7 +573,7 @@ public class EyesisCorrectionParameters {
String [] sensorFiles=null; String [] sensorFiles=null;
// try reading all matching files // try reading all matching files
File dir= new File (this.sensorDirectory); File dir= new File (this.sensorDirectory);
// if (debugLevel>1) System.out.println("selectSensorFiles, dir="+this.sensorDirectory); if (debugLevel>1) System.out.println("selectSensorFiles, dir="+this.sensorDirectory);
File [] fileList=null; File [] fileList=null;
if (dir.exists()) { if (dir.exists()) {
fileList=dir.listFiles(sensorFilter); fileList=dir.listFiles(sensorFilter);
......
...@@ -25,17 +25,16 @@ ...@@ -25,17 +25,16 @@
** **
*/ */
import ij.*; import java.awt.Button;
import ij.process.*; import java.awt.Color;
import ij.gui.*; import java.awt.Frame;
import ij.io.FileInfo; import java.awt.GraphicsEnvironment;
import ij.io.FileSaver; import java.awt.GridLayout;
import ij.io.OpenDialog; import java.awt.Panel;
import ij.io.Opener; import java.awt.Rectangle;
import ij.plugin.frame.*; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*; import java.awt.event.WindowEvent;
import java.awt.event.*;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
...@@ -53,6 +52,28 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -53,6 +52,28 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
import ij.CompositeImage;
import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.Macro;
import ij.Prefs;
import ij.WindowManager;
import ij.gui.GUI;
import ij.gui.GenericDialog;
import ij.gui.Plot;
import ij.gui.PlotWindow;
import ij.gui.Roi;
import ij.io.FileInfo;
import ij.io.FileSaver;
import ij.io.OpenDialog;
import ij.io.Opener;
import ij.plugin.PlugIn;
import ij.plugin.frame.PlugInFrame;
import ij.process.ColorProcessor;
import ij.process.FloatProcessor;
import ij.process.ImageProcessor;
import loci.common.services.DependencyException; import loci.common.services.DependencyException;
import loci.common.services.ServiceException; import loci.common.services.ServiceException;
import loci.formats.FormatException; import loci.formats.FormatException;
...@@ -60,10 +81,14 @@ import loci.formats.FormatException; ...@@ -60,10 +81,14 @@ import loci.formats.FormatException;
//import javax.swing.SwingUtilities; //import javax.swing.SwingUtilities;
//import javax.swing.UIManager; //import javax.swing.UIManager;
public class Eyesis_Correction extends PlugInFrame implements ActionListener { public class Eyesis_Correction implements PlugIn, ActionListener {
/** /**
* *
*/ */
private Boolean headless=GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance();
private PlugInFrame plugInFrame;
String prefsPath;
private static final long serialVersionUID = -1507307664341265263L; private static final long serialVersionUID = -1507307664341265263L;
private Panel panel1, private Panel panel1,
panel2, panel2,
...@@ -341,9 +366,14 @@ private Panel panel1, ...@@ -341,9 +366,14 @@ private Panel panel1,
public String buttonLabel=""; public String buttonLabel="";
} }
@Override
public Eyesis_Correction() { public void run(String arg) {
super("Eyesis_Correction"); String options=Macro.getOptions();
try {
prefsPath=Macro.getValue(options, "prefs", Prefs.getPrefsDir()+Prefs.getFileSeparator()+"Eyesis_Correction.xml");
} catch(Exception e) {
prefsPath=Prefs.getPrefsDir()+Prefs.getFileSeparator()+"Eyesis_Correction.xml";
}
if (IJ.versionLessThan("1.43q")) return; if (IJ.versionLessThan("1.43q")) return;
if (instance!=null) { if (instance!=null) {
instance.toFront(); instance.toFront();
...@@ -353,14 +383,38 @@ private Panel panel1, ...@@ -353,14 +383,38 @@ private Panel panel1,
loadPrefs(); loadPrefs();
} catch (IOException e1) { } catch (IOException e1) {
System.out.println("failed to load preferences"); System.out.println("failed to load preferences");
// e1.printStackTrace(); e1.printStackTrace();
} }
EYESIS_CORRECTIONS = new EyesisCorrections(SYNC_COMMAND.stopRequested,CORRECTION_PARAMETERS); EYESIS_CORRECTIONS = new EyesisCorrections(SYNC_COMMAND.stopRequested,CORRECTION_PARAMETERS);
if (options!=null || headless) {
processFiles();
} else {
initGui();
}
}
public void initGui() {
Color color_configure= new Color(200, 200,160); Color color_configure= new Color(200, 200,160);
Color color_process= new Color(180, 180, 240); Color color_process= new Color(180, 180, 240);
Color color_conf_process= new Color(180, 240, 240); Color color_conf_process= new Color(180, 240, 240);
Color color_restore= new Color(180, 240, 180); Color color_restore= new Color(180, 240, 180);
Color color_stop= new Color(255, 160, 160); Color color_stop= new Color(255, 160, 160);
//<<<<<<< HEAD
plugInFrame=new PlugInFrame("Eyesis_Correction") {
private static final long serialVersionUID = -4138832568507690332L;
@Override
public void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID()==WindowEvent.WINDOW_CLOSING) {
instance = null;
}
}
};
instance=plugInFrame;
plugInFrame.addKeyListener(IJ.getInstance());
int menuRows=4 + (ADVANCED_MODE?4:0) + (MODE_3D?3:0);
plugInFrame.setLayout(new GridLayout(menuRows, 1));
/*=======
instance = this; instance = this;
...@@ -368,6 +422,8 @@ private Panel panel1, ...@@ -368,6 +422,8 @@ private Panel panel1,
int menuRows=4 + (ADVANCED_MODE?4:0) + (MODE_3D?3:0) + (DCT_MODE?2:0); int menuRows=4 + (ADVANCED_MODE?4:0) + (MODE_3D?3:0) + (DCT_MODE?2:0);
setLayout(new GridLayout(menuRows, 1)); setLayout(new GridLayout(menuRows, 1));
>>>>>>> origin/dct
*/
panel6 = new Panel(); panel6 = new Panel();
panel6.setLayout(new GridLayout(1, 0, 5, 5)); panel6.setLayout(new GridLayout(1, 0, 5, 5));
addButton("Save",panel6); addButton("Save",panel6);
...@@ -375,13 +431,13 @@ private Panel panel1, ...@@ -375,13 +431,13 @@ private Panel panel1,
addButton("Stop",panel6,color_stop); addButton("Stop",panel6,color_stop);
addButton("Abort",panel6,color_stop); addButton("Abort",panel6,color_stop);
add(panel6); plugInFrame.add(panel6);
panel5 = new Panel(); panel5 = new Panel();
panel5.setLayout(new GridLayout(1, 0, 5, 5)); panel5.setLayout(new GridLayout(1, 0, 5, 5));
addButton("Configure spilt", panel5, color_configure); addButton("Configure spilt", panel5, color_configure);
addButton("Configure demosaic", panel5, color_configure); addButton("Configure demosaic", panel5, color_configure);
add(panel5); plugInFrame.add(panel5);
panel5a = new Panel(); panel5a = new Panel();
panel5a.setLayout(new GridLayout(1, 0, 5, 5)); panel5a.setLayout(new GridLayout(1, 0, 5, 5));
addButton("Configure convolution", panel5a, color_configure); addButton("Configure convolution", panel5a, color_configure);
...@@ -389,7 +445,7 @@ private Panel panel1, ...@@ -389,7 +445,7 @@ private Panel panel1,
addButton("Configure color", panel5a, color_configure); addButton("Configure color", panel5a, color_configure);
addButton("Channel gains", panel5a, color_configure); addButton("Channel gains", panel5a, color_configure);
addButton("Configure RGB", panel5a, color_configure); addButton("Configure RGB", panel5a, color_configure);
add(panel5a); plugInFrame.add(panel5a);
// Debug/development options // Debug/development options
...@@ -399,13 +455,13 @@ private Panel panel1, ...@@ -399,13 +455,13 @@ private Panel panel1,
panel1.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap panel1.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap
addButton("Split Image",panel1); addButton("Split Image",panel1);
addButton("Debayer Image",panel1); addButton("Debayer Image",panel1);
add(panel1); plugInFrame.add(panel1);
panel2 = new Panel(); panel2 = new Panel();
panel2.setLayout(new GridLayout(1, 0, 5, 5)); panel2.setLayout(new GridLayout(1, 0, 5, 5));
addButton("Select kernel stack",panel2); addButton("Select kernel stack",panel2);
addButton("Convolve with stack",panel2); addButton("Convolve with stack",panel2);
add(panel2); plugInFrame.add(panel2);
panel3 = new Panel(); panel3 = new Panel();
panel3.setLayout(new GridLayout(1, 0, 5, 5)); panel3.setLayout(new GridLayout(1, 0, 5, 5));
...@@ -413,14 +469,14 @@ private Panel panel1, ...@@ -413,14 +469,14 @@ private Panel panel1,
addButton("Combine pair",panel3); addButton("Combine pair",panel3);
addButton("Colors",panel3); addButton("Colors",panel3);
addButton("RGB",panel3); addButton("RGB",panel3);
add(panel3); plugInFrame.add(panel3);
panel4 = new Panel(); panel4 = new Panel();
panel4.setLayout(new GridLayout(1, 0, 5, 5)); panel4.setLayout(new GridLayout(1, 0, 5, 5));
addButton("Test",panel4); addButton("Test",panel4);
addButton("Test Debayer",panel4); addButton("Test Debayer",panel4);
add(panel4); plugInFrame.add(panel4);
} }
panel7 = new Panel(); panel7 = new Panel();
panel7.setLayout(new GridLayout(1, 0, 5, 5)); panel7.setLayout(new GridLayout(1, 0, 5, 5));
...@@ -433,7 +489,7 @@ private Panel panel1, ...@@ -433,7 +489,7 @@ private Panel panel1,
addButton("Tiff Writer", panel7); addButton("Tiff Writer", panel7);
addButton("Tiff Properties", panel7); addButton("Tiff Properties", panel7);
} }
add(panel7); plugInFrame.add(panel7);
if (MODE_3D){ if (MODE_3D){
panelPostProcessing1 = new Panel(); panelPostProcessing1 = new Panel();
...@@ -443,7 +499,7 @@ private Panel panel1, ...@@ -443,7 +499,7 @@ private Panel panel1,
addButton("ConvertPP", panelPostProcessing1,color_process); addButton("ConvertPP", panelPostProcessing1,color_process);
addButton("Linear Features", panelPostProcessing1); addButton("Linear Features", panelPostProcessing1);
addButton("Intercam correlations", panelPostProcessing1); addButton("Intercam correlations", panelPostProcessing1);
add(panelPostProcessing1); plugInFrame.add(panelPostProcessing1);
panelPostProcessing2 = new Panel(); panelPostProcessing2 = new Panel();
panelPostProcessing2.setLayout(new GridLayout(1, 0, 5, 5)); panelPostProcessing2.setLayout(new GridLayout(1, 0, 5, 5));
...@@ -454,15 +510,18 @@ private Panel panel1, ...@@ -454,15 +510,18 @@ private Panel panel1,
addButton("Fill FG gaps", panelPostProcessing2); addButton("Fill FG gaps", panelPostProcessing2);
addButton("Filter Z-map", panelPostProcessing2); addButton("Filter Z-map", panelPostProcessing2);
addButton("Occluding FG", panelPostProcessing2); addButton("Occluding FG", panelPostProcessing2);
add(panelPostProcessing2); plugInFrame.add(panelPostProcessing2);
panelPostProcessing3 = new Panel(); panelPostProcessing3 = new Panel();
panelPostProcessing3.setLayout(new GridLayout(1, 0, 5, 5)); panelPostProcessing3.setLayout(new GridLayout(1, 0, 5, 5));
addButton("Refine Disparities", panelPostProcessing3); addButton("Refine Disparities", panelPostProcessing3);
addButton("Init Photometry", panelPostProcessing3); addButton("Init Photometry", panelPostProcessing3);
addButton("Plane Likely", panelPostProcessing3); addButton("Plane Likely", panelPostProcessing3);
add(panelPostProcessing3); plugInFrame.add(panelPostProcessing3);
} }
// <<<<<<< HEAD
plugInFrame.pack();
/* =======
if (DCT_MODE) { if (DCT_MODE) {
panelDct1 = new Panel(); panelDct1 = new Panel();
panelDct1.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap panelDct1.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap
...@@ -490,16 +549,16 @@ private Panel panel1, ...@@ -490,16 +549,16 @@ private Panel panel1,
addButton("CLT stack", panelClt1, color_process); addButton("CLT stack", panelClt1, color_process);
addButton("Select second CLT image", panelClt1, color_configure); addButton("Select second CLT image", panelClt1, color_configure);
addButton("CLT correlate", panelClt1, color_process); addButton("CLT correlate", panelClt1, color_process);
addButton("Create CLT kernels", panelClt1, color_process); addButton("CLT test 2", panelClt1, color_process);
addButton("Read CLT kernels", panelClt1, color_process); addButton("CLT test 3", panelClt1, color_process);
addButton("Reset CLT kernels", panelClt1, color_stop); addButton("CLT test 4", panelClt1, color_process);
addButton("CLT process files", panelClt1, color_process);
add(panelClt1); add(panelClt1);
} }
pack(); pack();
>>>>>>> origin/dct
GUI.center(this); */
setVisible(true); GUI.center(plugInFrame);
plugInFrame.setVisible(true);
FHT_INSTANCE= new DoubleFHT(); FHT_INSTANCE= new DoubleFHT();
SDFA_INSTANCE= new showDoubleFloatArrays(); SDFA_INSTANCE= new showDoubleFloatArrays();
// main loop // main loop
...@@ -528,7 +587,6 @@ private Panel panel1, ...@@ -528,7 +587,6 @@ private Panel panel1,
} }
} }
private String prefsPath=Prefs.getPrefsDir()+Prefs.getFileSeparator()+"Eyesis_Correction.xml";
private Properties prefsProperties=new Properties(); private Properties prefsProperties=new Properties();
public void loadPrefs() throws IOException{ public void loadPrefs() throws IOException{
...@@ -543,6 +601,13 @@ private Panel panel1, ...@@ -543,6 +601,13 @@ private Panel panel1,
try { try {
prefsProperties.loadFromXML(is); prefsProperties.loadFromXML(is);
if (!headless){
System.out.println("Skipping getAllProperties(prefsProperties)");
}else{
getAllProperties(prefsProperties);
if (DEBUG_LEVEL>0) System.out.println("Configuration parameters are restored from "+this.prefsPath);
}
} catch (IOException e) { } catch (IOException e) {
String msg="Failed to read XML configuration file: "+this.prefsPath; String msg="Failed to read XML configuration file: "+this.prefsPath;
IJ.showMessage("Error",msg); IJ.showMessage("Error",msg);
...@@ -554,7 +619,7 @@ private Panel panel1, ...@@ -554,7 +619,7 @@ private Panel panel1,
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
String sValue= this.prefsProperties.getProperty("ADVANCED_MODE"); String sValue = this.prefsProperties.getProperty("ADVANCED_MODE");
if (sValue!=null) { if (sValue!=null) {
ADVANCED_MODE=Boolean.parseBoolean(sValue); ADVANCED_MODE=Boolean.parseBoolean(sValue);
System.out.println("Read ADVANCED_MODE="+ADVANCED_MODE); System.out.println("Read ADVANCED_MODE="+ADVANCED_MODE);
...@@ -609,13 +674,7 @@ private Panel panel1, ...@@ -609,13 +674,7 @@ private Panel panel1,
b.addKeyListener(IJ.getInstance()); b.addKeyListener(IJ.getInstance());
panel.add(b); panel.add(b);
} }
public void processWindowEvent(WindowEvent e) { @Override
super.processWindowEvent(e);
if (e.getID()==WindowEvent.WINDOW_CLOSING) {
instance = null;
}
}
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String label = e.getActionCommand(); String label = e.getActionCommand();
if (label.equals("Abort")) { if (label.equals("Abort")) {
...@@ -642,6 +701,70 @@ private Panel panel1, ...@@ -642,6 +701,70 @@ private Panel panel1,
} }
// matchSimulatedPattern.FFT_SIZE=FFT_SIZE; // matchSimulatedPattern.FFT_SIZE=FFT_SIZE;
} }
public void processFiles() {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
String configPath=null;
if (!headless && EYESIS_CORRECTIONS.correctionsParameters.saveSettings) {
configPath=EYESIS_CORRECTIONS.correctionsParameters.selectResultsDirectory(
true,
true);
if (configPath==null){
String msg="No results directory selected, command aborted";
System.out.println("Warning: "+msg);
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
} catch (Exception e){
String msg="Failed to save configuration to "+configPath+", command aborted";
System.out.println("Error: "+msg);
IJ.showMessage("Error",msg);
return;
}
}
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL);
int numChannels=EYESIS_CORRECTIONS.getNumChannels();
NONLIN_PARAMETERS.modifyNumChannels(numChannels);
CHANNEL_GAINS_PARAMETERS.modifyNumChannels(numChannels);
if (CORRECTION_PARAMETERS.deconvolve && (NONLIN_PARAMETERS.noiseGainPower!=0)) {
EYESIS_CORRECTIONS.updateImageNoiseGains(
NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters,
CONVOLVE_FFT_SIZE, //int fftSize, // 128 - fft size, kernel size should be size/2
THREADS_MAX, // int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, // boolean updateStatus,
DEBUG_LEVEL); //int globalDebugLevel){
}
EYESIS_CORRECTIONS.processChannelImages(
SPLIT_PARAMETERS, // EyesisCorrectionParameters.SplitParameters splitParameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters,
COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
CONVOLVE_FFT_SIZE, //int convolveFFTSize, // 128 - fft size, kernel size should be size/2
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
DEBUG_LEVEL); //final int debugLevel);
if (configPath!=null) {
saveTimestampedProperties( // save config again
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
}
}
public void runMenuCommand(String label){ public void runMenuCommand(String label){
int i, j; //,l,iq; int i, j; //,l,iq;
// String label = e.getActionCommand(); // String label = e.getActionCommand();
...@@ -1055,69 +1178,7 @@ private Panel panel1, ...@@ -1055,69 +1178,7 @@ private Panel panel1,
return; return;
/* ======================================================================== */ /* ======================================================================== */
} else if (label.equals("Process files")) { } else if (label.equals("Process files")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL; processFiles();
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
String configPath=null;
if (EYESIS_CORRECTIONS.correctionsParameters.saveSettings) {
configPath=EYESIS_CORRECTIONS.correctionsParameters.selectResultsDirectory(
true,
true);
if (configPath==null){
String msg="No results directory selected, command aborted";
System.out.println("Warning: "+msg);
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
} catch (Exception e){
String msg="Failed to save configuration to "+configPath+", command aborted";
System.out.println("Error: "+msg);
IJ.showMessage("Error",msg);
return;
}
}
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL);
int numChannels=EYESIS_CORRECTIONS.getNumChannels();
NONLIN_PARAMETERS.modifyNumChannels(numChannels);
CHANNEL_GAINS_PARAMETERS.modifyNumChannels(numChannels);
if (CORRECTION_PARAMETERS.deconvolve && (NONLIN_PARAMETERS.noiseGainPower!=0)) {
EYESIS_CORRECTIONS.updateImageNoiseGains(
NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters,
CONVOLVE_FFT_SIZE, //int fftSize, // 128 - fft size, kernel size should be size/2
THREADS_MAX, // int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, // boolean updateStatus,
DEBUG_LEVEL); //int globalDebugLevel){
}
EYESIS_CORRECTIONS.processChannelImages(
SPLIT_PARAMETERS, // EyesisCorrectionParameters.SplitParameters splitParameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters,
COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
CONVOLVE_FFT_SIZE, //int convolveFFTSize, // 128 - fft size, kernel size should be size/2
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
DEBUG_LEVEL); //final int debugLevel);
if (configPath!=null) {
saveTimestampedProperties( // save config again
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
}
return; return;
/* ======================================================================== */ /* ======================================================================== */
} else if (label.equals("Tiff Writer")) { } else if (label.equals("Tiff Writer")) {
...@@ -2579,7 +2640,7 @@ private Panel panel1, ...@@ -2579,7 +2640,7 @@ private Panel panel1,
for (int ii = 0; ii<n; ii++) { for (int ii = 0; ii<n; ii++) {
dindex[ii] = (double) ii; dindex[ii] = ii;
x[ii] = 0.0; x[ii] = 0.0;
} }
// x[1] = 1.0; // x[1] = 1.0;
...@@ -2890,7 +2951,16 @@ private Panel panel1, ...@@ -2890,7 +2951,16 @@ private Panel panel1,
int numChannels=EYESIS_CORRECTIONS.getNumChannels(); int numChannels=EYESIS_CORRECTIONS.getNumChannels();
NONLIN_PARAMETERS.modifyNumChannels(numChannels); NONLIN_PARAMETERS.modifyNumChannels(numChannels);
CHANNEL_GAINS_PARAMETERS.modifyNumChannels(numChannels); CHANNEL_GAINS_PARAMETERS.modifyNumChannels(numChannels);
/*
if (CORRECTION_PARAMETERS.deconvolve && (NONLIN_PARAMETERS.noiseGainPower!=0)) {
EYESIS_CORRECTIONS.updateImageNoiseGains(
NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters,
CONVOLVE_FFT_SIZE, //int fftSize, // 128 - fft size, kernel size should be size/2
THREADS_MAX, // int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, // boolean updateStatus,
DEBUG_LEVEL); //int globalDebugLevel){
}
*/
if (!EYESIS_DCT.DCTKernelsAvailable()){ if (!EYESIS_DCT.DCTKernelsAvailable()){
if (DEBUG_LEVEL > 0){ if (DEBUG_LEVEL > 0){
System.out.println("Reading/converting DCT kernels"); System.out.println("Reading/converting DCT kernels");
...@@ -2905,7 +2975,11 @@ private Panel panel1, ...@@ -2905,7 +2975,11 @@ private Panel panel1,
EYESIS_DCT.showKernels(); // show restored kernels EYESIS_DCT.showKernels(); // show restored kernels
} }
} }
// EYESIS_CORRECTIONS.processChannelImages(
EYESIS_DCT.processDCTChannelImages( EYESIS_DCT.processDCTChannelImages(
// SPLIT_PARAMETERS, // EyesisCorrectionParameters.SplitParameters splitParameters,
DCT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters, DCT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters, DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters, NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters,
...@@ -3780,9 +3854,6 @@ private Panel panel1, ...@@ -3780,9 +3854,6 @@ private Panel panel1,
/* ======================================================================== */ /* ======================================================================== */
} else if (label.equals("CLT correlate")) { } else if (label.equals("CLT correlate")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL; DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
runtime.gc();
System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
// IJ.showMessage("DCT test 1"); // IJ.showMessage("DCT test 1");
if (!CLT_PARAMETERS.showDialog()) return; if (!CLT_PARAMETERS.showDialog()) return;
// process selected image stack // process selected image stack
...@@ -3988,7 +4059,6 @@ private Panel panel1, ...@@ -3988,7 +4059,6 @@ private Panel panel1,
for (int chn = 0; chn < clt_corr.length; chn++) { for (int chn = 0; chn < clt_corr.length; chn++) {
image_dtt.clt_dtt2( // DCCT2, DSCT2, DCST2, DSST2 - in-place image_dtt.clt_dtt2( // DCCT2, DSCT2, DCST2, DSST2 - in-place
clt_corr[chn], // final double [][][][] clt_data, clt_corr[chn], // final double [][][][] clt_data,
true, // final boolean transpose, // when doing inverse transform, the data comes in transposed form, so CS <->SC
THREADS_MAX, // maximal number of threads to launch THREADS_MAX, // maximal number of threads to launch
DEBUG_LEVEL); // globalDebugLevel) DEBUG_LEVEL); // globalDebugLevel)
} }
...@@ -4032,193 +4102,28 @@ private Panel panel1, ...@@ -4032,193 +4102,28 @@ private Panel panel1,
DBG_IMP.getTitle()+"-C"+suffix, titles_rbg); DBG_IMP.getTitle()+"-C"+suffix, titles_rbg);
} }
//==============================================================================
} else if (label.equals("Create CLT kernels")) {
if (!CLT_PARAMETERS.showDialog()) return;
if (EYESIS_DCT == null){
EYESIS_DCT = new EyesisDCT (
EYESIS_CORRECTIONS,
CORRECTION_PARAMETERS,
DCT_PARAMETERS);
}
String configPath=null;
if (EYESIS_CORRECTIONS.correctionsParameters.saveSettings) {
configPath=EYESIS_CORRECTIONS.correctionsParameters.selectResultsDirectory(
true,
true);
if (configPath==null){
String msg="No results directory selected, command aborted";
System.out.println("Warning: "+msg);
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
} catch (Exception e){
String msg="Failed to save configuration to "+configPath+", command aborted";
System.out.println("Error: "+msg);
IJ.showMessage("Error",msg);
return;
}
}
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL);
EYESIS_DCT.createCLTKernels(
CLT_PARAMETERS,
CONVOLVE_FFT_SIZE/2,
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
//"Reset DCT kernels"
} else if (label.equals("Reset CLT kernels")) {
if (EYESIS_DCT != null){
EYESIS_DCT.resetCLTKernels();
}
} else if (label.equals("Read CLT kernels")) {
if (!CLT_PARAMETERS.showDialog()) return;
if (EYESIS_DCT == null){
EYESIS_DCT = new EyesisDCT (
EYESIS_CORRECTIONS,
CORRECTION_PARAMETERS,
DCT_PARAMETERS);
}
String configPath=null;
if (EYESIS_CORRECTIONS.correctionsParameters.saveSettings) {
configPath=EYESIS_CORRECTIONS.correctionsParameters.selectResultsDirectory(
true,
true);
if (configPath==null){
String msg="No results directory selected, command aborted";
System.out.println("Warning: "+msg);
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
} catch (Exception e){
String msg="Failed to save configuration to "+configPath+", command aborted";
System.out.println("Error: "+msg);
IJ.showMessage("Error",msg);
return;
}
}
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL);
EYESIS_DCT.readCLTKernels(
CLT_PARAMETERS,
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
if (DEBUG_LEVEL > -1){
EYESIS_DCT.showCLTKernels(
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
}
return; /*
} else if (label.equals("CLT process files")) { double [][] iclt_data = new double [clt_data.length][];
DEBUG_LEVEL=MASTER_DEBUG_LEVEL; for (int chn=0; chn<iclt_data.length;chn++){
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL); iclt_data[chn] = image_dtt.iclt_2d(
if (EYESIS_DCT == null){ clt_data[chn], // scanline representation of dcd data, organized as dct_size x dct_size tiles
EYESIS_DCT = new EyesisDCT ( CLT_PARAMETERS.transform_size, // final int
EYESIS_CORRECTIONS, CLT_PARAMETERS.clt_window, //window_type
CORRECTION_PARAMETERS, CLT_PARAMETERS.iclt_mask, //which of 4 to transform back
DCT_PARAMETERS); CLT_PARAMETERS.dbg_mode, //which of 4 to transform back
if (DEBUG_LEVEL > 0){ THREADS_MAX, // maximal number of threads to launch
System.out.println("Created new EyesisDCT instance, will need to read CLT kernels"); DEBUG_LEVEL); // globalDebugLevel)
}
}
String configPath=null;
if (EYESIS_CORRECTIONS.correctionsParameters.saveSettings) {
configPath=EYESIS_CORRECTIONS.correctionsParameters.selectResultsDirectory(
true,
true);
if (configPath==null){
String msg="No results directory selected, command aborted";
System.out.println("Warning: "+msg);
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
} catch (Exception e){
String msg="Failed to save configuration to "+configPath+", command aborted";
System.out.println("Error: "+msg);
IJ.showMessage("Error",msg);
return;
}
}
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL);
int numChannels=EYESIS_CORRECTIONS.getNumChannels();
NONLIN_PARAMETERS.modifyNumChannels(numChannels);
CHANNEL_GAINS_PARAMETERS.modifyNumChannels(numChannels);
if (!EYESIS_DCT.CLTKernelsAvailable()){
if (DEBUG_LEVEL > 0){
System.out.println("Reading CLT kernels");
}
EYESIS_DCT.readCLTKernels(
CLT_PARAMETERS,
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
if (DEBUG_LEVEL > 1){
EYESIS_DCT.showCLTKernels(
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
}
} }
SDFA_INSTANCE.showArrays(
///======================================== iclt_data,
(tilesX + 1) * CLT_PARAMETERS.transform_size,
EYESIS_DCT.processCLTChannelImages( (tilesY + 1) * CLT_PARAMETERS.transform_size,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters,
COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
CONVOLVE_FFT_SIZE, //int convolveFFTSize, // 128 - fft size, kernel size should be size/2
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
DEBUG_LEVEL); //final int debugLevel);
if (configPath!=null) {
saveTimestampedProperties( // save config again
configPath, // full path or null
null, // use as default directory if path==null
true, true,
PROPERTIES); DBG_IMP.getTitle()+"-ICLT-"+CLT_PARAMETERS.iclt_mask);
} */
return; return;
// End of buttons code // End of buttons code
...@@ -4429,6 +4334,7 @@ private Panel panel1, ...@@ -4429,6 +4334,7 @@ private Panel panel1,
public MultipleExtensionsFileFilter (String [] patterns) { public MultipleExtensionsFileFilter (String [] patterns) {
this.patterns=patterns.clone(); this.patterns=patterns.clone();
} }
@Override
public boolean accept (File file) { public boolean accept (File file) {
int i; int i;
String name=file.getName(); String name=file.getName();
...@@ -4438,6 +4344,7 @@ private Panel panel1, ...@@ -4438,6 +4344,7 @@ private Panel panel1,
} }
return false; return false;
} }
@Override
public String getDescription() { public String getDescription() {
return description; return description;
} }
...@@ -5736,6 +5643,7 @@ private Panel panel1, ...@@ -5736,6 +5643,7 @@ private Panel panel1,
final long startTime = System.nanoTime(); final long startTime = System.nanoTime();
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
@Override
public void run() { public void run() {
float [] pixels=null; // will be initialized at first use float [] pixels=null; // will be initialized at first use
float [] kernelPixels=null; // will be initialized at first use float [] kernelPixels=null; // will be initialized at first use
...@@ -5878,6 +5786,7 @@ private Panel panel1, ...@@ -5878,6 +5786,7 @@ private Panel panel1,
final long startTime = System.nanoTime(); final long startTime = System.nanoTime();
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
@Override
public void run() { public void run() {
double [][] tile= new double[nChn][debayerParameters.size * debayerParameters.size ]; double [][] tile= new double[nChn][debayerParameters.size * debayerParameters.size ];
double [][] both_masks; double [][] both_masks;
...@@ -6125,6 +6034,7 @@ private Panel panel1, ...@@ -6125,6 +6034,7 @@ private Panel panel1,
final long startTime = System.nanoTime(); final long startTime = System.nanoTime();
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
@Override
public void run() { public void run() {
double [] tile= new double[size * size ]; double [] tile= new double[size * size ];
int tileY,tileX; int tileY,tileX;
...@@ -7449,4 +7359,3 @@ G= Y +Pr*(- 2*Kr*(1-Kr))/Kg + Pb*(-2*Kb*(1-Kb))/Kg ...@@ -7449,4 +7359,3 @@ G= Y +Pr*(- 2*Kr*(1-Kr))/Kg + Pb*(-2*Kb*(1-Kb))/Kg
} }
} }
...@@ -30,6 +30,7 @@ import ij.process.*; ...@@ -30,6 +30,7 @@ import ij.process.*;
import ij.gui.*; import ij.gui.*;
import ij.plugin.frame.*; import ij.plugin.frame.*;
import ij.text.*; import ij.text.*;
import ij.plugin.PlugIn;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
...@@ -50,9 +51,8 @@ import org.xml.sax.InputSource; ...@@ -50,9 +51,8 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/* This plugin opens images in Elphel JP4/JP46 format (opens as JPEG, reads MakerNote and converts). */ /* This plugin opens images in Elphel JP4/JP46 format (opens as JPEG, reads MakerNote and converts). */
public class JP46_Reader_camera extends PlugInFrame implements ActionListener { public class JP46_Reader_camera implements PlugIn,ActionListener {
/** /**
* *
...@@ -61,6 +61,7 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener { ...@@ -61,6 +61,7 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener {
Panel panel1; Panel panel1;
Panel confpanel; Panel confpanel;
Frame instance; Frame instance;
PlugInFrame plugInFrame;
String arg; String arg;
...@@ -75,44 +76,33 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener { ...@@ -75,44 +76,33 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener {
public boolean demux=true; public boolean demux=true;
public String imageTitle="cameraImage"; public String imageTitle="cameraImage";
private int ExifOffset=0x0c; private int ExifOffset=0x0c;
private Boolean headless=GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance();
public JP46_Reader_camera() { public void run(String arg) {
super("JP46 Reader Camera");
if (IJ.versionLessThan("1.39t")) return;
if (instance!=null) {
instance.toFront();
return;
} }
instance = this;
addKeyListener(IJ.getInstance());
panel1 = new Panel(); public JP46_Reader_camera(Boolean showGui) {
if (showGui) initGui();
panel1.setLayout(new GridLayout(6, 1, 50, 5)); }
addButton("Open JP4/JP46...",panel1);
addButton("Open JP4/JP46 from camera",panel1);
addButton("Configure...",panel1);
addButton("Show image properties",panel1);
addButton("Decode image info to properties",panel1);
addButton("Split Bayer",panel1);
public JP46_Reader_camera() {
initGui();
}
add(panel1); public void initGui() {
//super("JP46 Reader Camera");
if (headless) return;
pack();
GUI.center(this);
setVisible(true);
}
public JP46_Reader_camera(boolean showGUI) {
super("JP46 Reader Camera");
if (IJ.versionLessThan("1.39t")) return; if (IJ.versionLessThan("1.39t")) return;
if (instance!=null) { if (instance!=null) {
instance.toFront(); instance.toFront();
return; return;
} }
instance = this;
addKeyListener(IJ.getInstance()); plugInFrame=new PlugInFrame("JP46 Reader Camera");
instance = (Frame)plugInFrame;
plugInFrame.addKeyListener(IJ.getInstance());
panel1 = new Panel(); panel1 = new Panel();
...@@ -124,10 +114,10 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener { ...@@ -124,10 +114,10 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener {
addButton("Show image properties",panel1); addButton("Show image properties",panel1);
addButton("Decode image info to properties",panel1); addButton("Decode image info to properties",panel1);
addButton("Split Bayer",panel1); addButton("Split Bayer",panel1);
add(panel1); plugInFrame.add(panel1);
pack(); plugInFrame.pack();
GUI.center(this); GUI.center(plugInFrame);
setVisible(showGUI); plugInFrame.setVisible(true);
} }
void addButton(String label, Panel panel) { void addButton(String label, Panel panel) {
......
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