Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92612230
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 22, 00:50
Size
135 KB
Mime Type
application/octet-stream
Expires
Sun, Nov 24, 00:50 (2 d)
Engine
blob
Format
Raw Data
Handle
22475562
Attached To
R2075 deconvolution
View Options
diff --git a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Resolution.java b/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Resolution.java
deleted file mode 100644
index 2399e6e..0000000
--- a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Resolution.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * DeconvolutionLab2
- *
- * Conditions of use: You are free to use this software for research or
- * educational purposes. In addition, we expect you to include adequate
- * citations and acknowledgments whenever you present or publish results that
- * are based on it.
- *
- * Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
- * Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
- * R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
- */
-
-/*
- * Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
- *
- * This file is part of DeconvolutionLab2 (DL2).
- *
- * DL2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * DL2. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package course;
-import java.io.File;
-
-import javax.swing.filechooser.FileSystemView;
-
-import bilib.tools.Files;
-import deconvolution.algorithm.Convolution;
-import deconvolution.algorithm.NaiveInverseFilter;
-import deconvolution.algorithm.Simulation;
-import deconvolution.algorithm.TikhonovRegularizedInverseFilter;
-import deconvolutionlab.Lab;
-import deconvolutionlab.monitor.Monitors;
-import deconvolutionlab.output.ShowOrtho;
-import ij.gui.Plot;
-import ij.plugin.PlugIn;
-import signal.Assessment;
-import signal.RealSignal;
-import signal.factory.BesselJ0;
-import signal.factory.CubeSphericalBeads;
-
-public class DeconvolutionLab2_Course_Resolution implements PlugIn {
-
- private String root = Files.getDesktopDirectory() + "Deconvolution" + File.separator;
- private String path = root + "results" + File.separator + "resolution" + File.separator;
-
- public DeconvolutionLab2_Course_Resolution() {
-
- Monitors monitors = Monitors.createDefaultMonitor();
- new File(path).mkdir();
- System.setProperty("user.dir", path);
-
- new File(path + "RIF").mkdir();
- new File(path + "LW").mkdir();
- new File(path + "LW+").mkdir();
- new File(path + "RL").mkdir();
-
- int nx = 160;
- int ny = 160;
- int nz = 160;
- int spacing = 8;
- int b = 8;
-
- RealSignal x = new CubeSphericalBeads(2, 0.5, spacing, b).intensity(100).generate(nx, ny, nz);
- x.plus(10);
- Lab.save(monitors, x.createOrthoview(b, b, b), path + "ref.tif");
-System.out.println("mean x " + x.getStats()[0]);
- RealSignal h = new BesselJ0(1, 10, 0.001, 0.00000001).generate(nx, ny, nz);
- Lab.save(monitors, h, path + "psf.tif");
- Lab.show(monitors, h, "psf");
- Lab.showOrthoview(h);
- Lab.showMIP(h);
-
- Convolution convolution = new Convolution();
- convolution.disableDisplayFinal().disableSystem();
- convolution.addOutput(new ShowOrtho("convolution"));
- RealSignal y = convolution.run(x, h);
- Lab.save(monitors, y.createOrthoview(b, b, b), path + "conv.tif");
- Lab.showPlanar(y);
-System.out.println("mean y " + y.getStats()[0]);
-
- Simulation simulation = new Simulation(0, 0.25, 0.25);
- simulation.disableDisplayFinal().disableSystem();
- simulation.addOutput(new ShowOrtho("simualtion").origin(b, b, b));
- RealSignal ys = simulation.run(x, h);
- Lab.save(monitors, ys.createOrthoview(b, b, b), path + "simu.tif");
- Lab.showPlanar(ys);
- Lab.showMIP(ys);
-System.out.println("mean ys " + ys.getStats()[0]);
-
-
- plotProfile(x, "refY", b, 0, b, b, ny-1, b);
- plotProfile(x, "refX", 0, b, b, nx-1, b, b);
- plotProfile(x, "refZ", b, b, 0, b, b, nz-1);
-
- plotProfile(y, "convY", b, 0, b, b, ny-1, b);
- plotProfile(y, "convX", 0, b, b, nx-1, b, b);
- plotProfile(y, "convZ", b, b, 0, b, b, nz-1);
- plotProfile(ys, "simuY", b, 0, b, b, ny-1, b);
- plotProfile(ys, "simuX", 0, b, b, nx-1, b, b);
- plotProfile(ys, "simuZ", b, b, 0, b, b, nz-1);
-
- NaiveInverseFilter nif = new NaiveInverseFilter();
- nif.addOutput(new ShowOrtho("nif").origin(b, b, b));
- nif.disableDisplayFinal().disableSystem().setReference(path + "ref.tif").setStats();
- RealSignal nic = nif.run(y, h);
- Lab.save(monitors, nic.createOrthoview(b, b, b), path + "nif_conv.tif");
- Lab.showPlanar(monitors, nic, nic + "NIF_CONV //"+Assessment.rmse(nic, x));
- RealSignal nis = nif.run(ys, h);
- Lab.save(monitors, nis.createOrthoview(b, b, b), path + "nif_simu.tif");
- Lab.showPlanar(monitors, nis, nis + "NIF_SIMU //"+Assessment.rmse(nis, x));
-
- plotProfile(nic, "nicY", b, 0, b, b, ny-1, b);
- plotProfile(nic, "nicX", 0, b, b, nx-1, b, b);
- plotProfile(nic, "nicZ", b, b, 0, b, b, nz-1);
-
- plotProfile(nis, "nisY", b, 0, b, b, ny-1, b);
- plotProfile(nis, "nisX", 0, b, b, nx-1, b, b);
- plotProfile(nis, "nisZ", b, b, 0, b, b, nz-1);
-
- TikhonovRegularizedInverseFilter trif = new TikhonovRegularizedInverseFilter(1e-3);
- trif.disableDisplayFinal().disableSystem().setReference(path + "ref.tif");
- for(int i=-5; i<-1; i++) {
- trif.setParameters(new double[] {Math.pow(10, i)});
- RealSignal t = trif.run(ys, h);
- Lab.save(monitors, t.createOrthoview(b, b, b), path + "trif" + i + ".tif");
- Lab.showPlanar(monitors, t, "TRIF" + i + " //"+Assessment.rmse(t, x));
- Lab.showOrthoview(monitors, t, "TRIF"+ i + " //"+Assessment.rmse(t, x), b, b, b);
- plotProfile(t, "tirfY" + i, b, 0, b, b, ny-1, b);
- plotProfile(t, "tirfX" + i, 0, b, b, nx-1, b, b);
- plotProfile(t, "tirfZ" + i, b, b, 0, b, b, nz-1);
- System.out.println("mean trif " + i + " " + t.getStats()[0]);
- }
- //plotProfile(t, "trifY", b, 0, b, b, ny-1, b);
- //plotProfile(t, "trifX", 0, b, b, nx-1, b, b);
- //plotProfile(t, "trifZ", b, b, 0, b, b, nz-1);
- /*
- RichardsonLucyTV rl = new RichardsonLucyTV(100, 0.00001);
- rl.disableDisplayFinal().disableSystem().setReference(res + "ref.tif").setStats();
- rl.addOutput(new ShowOrtho("rltv").frequency(1).origin(b, b, b));
- RealSignal fli = rl.run(ys, h);
-
-//RLTV 0.0001 100 Signals: 167.2 Mb 14.6724 0.9261 n/a
-//RL 100 Signals: 138.6 Mb 14.6688 0.9224 n/a
-//RLTV 0.001 100 Signals: 167.2 Mb 14.6979 0.9515 n/a
-//LW+ 5000 Signals: 311.6 Mb 15.4276 1.6812 n/a
-/*
- LandweberPositivity lw = new LandweberPositivity(100, 1.95);
- lw.disableDisplayFinal().disableSystem().setReference(res + "ref.tif").setStats();
- lw.addOutput(new ShowOrtho("lw").frequency(20).origin(border, border, border));
- RealSignal lwi = lw.run(ys, h);
-
- Lab.show(lwi);
- */
- }
-
- private static void plotProfile(RealSignal signal, String name, int x1, int y1, int z1, int x2, int y2, int z2) {
- double dx = x2 - x1;
- double dy = y2 - y1;
- double dz = z2 - z1;
- double len = Math.sqrt(dx*dx + dy*dy + dz*dz);
- int n = (int)Math.round(len * 2);
- double ds = len / n;
- dx = (double)(x2 - x1) / n;
- dy = (double)(y2 - y1) / n;
- dz = (double)(z2 - z1) / n;
- double value[] = new double[n];
- double dist[] = new double[n];
- for(int s=0; s<n; s++) {
- double x = x1 + s*dx;
- double y = y1 + s*dy;
- double z = z1 + s*dz;
- dist[s] = s*ds;
- value[s] = signal.getInterpolatedPixel(x, y, z);
- }
- Plot plot = new Plot(name, "distance", "intensity", dist, value);
- plot.show();
- }
-
- public static void main(String arg[]) {
- new DeconvolutionLab2_Course_Resolution();
- }
-
- @Override
- public void run(String arg) {
- new DeconvolutionLab2_Course_Resolution();
- }
-
-
-}
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/course/DeconvolutionLab2_JavaCoding.java b/DeconvolutionLab2/src/course/DeconvolutionLab2_JavaCoding.java
deleted file mode 100644
index 91bb4ca..0000000
--- a/DeconvolutionLab2/src/course/DeconvolutionLab2_JavaCoding.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * DeconvolutionLab2
- *
- * Conditions of use: You are free to use this software for research or
- * educational purposes. In addition, we expect you to include adequate
- * citations and acknowledgments whenever you present or publish results that
- * are based on it.
- *
- * Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
- * Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
- * R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
- */
-
-/*
- * Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
- *
- * This file is part of DeconvolutionLab2 (DL2).
- *
- * DL2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * DL2. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package course;
-
-import java.io.File;
-
-import javax.swing.filechooser.FileSystemView;
-
-import deconvolution.algorithm.Simulation;
-import deconvolutionlab.Lab;
-import deconvolutionlab.monitor.Monitors;
-import ij.plugin.PlugIn;
-import signal.RealSignal;
-
-public class DeconvolutionLab2_JavaCoding implements PlugIn {
-
- private String desktop = FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath() + File.separator + "Desktop" + File.separator;
-
- public DeconvolutionLab2_JavaCoding() {
- String path = desktop + "Deconvolution" + File.separator + "data" + File.separator + "bars" + File.separator;
- Monitors monitors = Monitors.createDefaultMonitor();
- RealSignal image = Lab.openFile(monitors, path + "bars.tif");
- RealSignal psf = Lab.openFile(monitors, path + "psf.tif");
- Simulation convolution = new Simulation(100, 100, 10);
- RealSignal a = convolution.run(image, psf);
- Lab.showMIP(monitors, a, "a");
- }
-
- public static void main(String arg[]) {
- new DeconvolutionLab2_JavaCoding();
- }
-
- @Override
- public void run(String arg) {
- new DeconvolutionLab2_JavaCoding();
- }
-
-}
diff --git a/DeconvolutionLab2/src/deconvolution/Stats.java b/DeconvolutionLab2/src/deconvolution/Stats.java
index c1ca4c1..7d65cb7 100644
--- a/DeconvolutionLab2/src/deconvolution/Stats.java
+++ b/DeconvolutionLab2/src/deconvolution/Stats.java
@@ -1,170 +1,174 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolution;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.File;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import bilib.table.CustomizedColumn;
import bilib.table.CustomizedTable;
import bilib.tools.NumFormat;
import deconvolutionlab.Constants;
import deconvolutionlab.Lab;
import deconvolutionlab.monitor.Monitors;
import deconvolutionlab.system.SystemUsage;
import signal.RealSignal;
import signal.SignalCollector;
public class Stats {
public enum Mode {NO, SHOW, SAVE, SHOWSAVE};
private CustomizedTable table;
private float[] statsInput;
private Mode mode;
private boolean embedded = false;
public Stats(Mode mode) {
this.mode = mode;
ArrayList<CustomizedColumn> columns = new ArrayList<CustomizedColumn>();
columns.add(new CustomizedColumn("Iterations", String.class, 100, false));
columns.add(new CustomizedColumn("Mean", String.class, 100, false));
columns.add(new CustomizedColumn("Minimum", String.class, 100, false));
columns.add(new CustomizedColumn("Maximum", String.class, 100, false));
columns.add(new CustomizedColumn("Stdev", String.class, 100, false));
columns.add(new CustomizedColumn("Energy", String.class, 100, false));
columns.add(new CustomizedColumn("Time", String.class, 100, false));
columns.add(new CustomizedColumn("Memory", String.class, 100, false));
columns.add(new CustomizedColumn("Signal", String.class, 100, false));
columns.add(new CustomizedColumn("PSNR", String.class, 100, false));
columns.add(new CustomizedColumn("SNR", String.class, 100, false));
columns.add(new CustomizedColumn("Residu", String.class, 100, false));
table = new CustomizedTable(columns, true);
}
public void setEmbeddedInFrame(boolean embedded) {
this.embedded = embedded;
}
/**
* Show the stats table in a frame if it is not yet embedded in another frame.
*/
public void show() {
if (embedded)
return;
if (mode == Mode.SHOW || mode == Mode.SHOWSAVE) {
JFrame frame = new JFrame("Stats");
frame.getContentPane().add(getPanel());
frame.pack();
Lab.setVisible(frame);
}
}
public void save(Monitors monitors, String path) {
if (mode == Mode.SAVE || mode == Mode.SHOWSAVE) {
String filename = path + File.separator + "stats.csv";
monitors.log("Stats save " + filename);
table.saveCSV(filename);
}
}
public void addInput(RealSignal x) {
statsInput = x.getStats();
- table.append(compute(x, 0, "", "", "", ""));
+ table.append(compute(x, "In: " + x.name, "", "", "", ""));
}
public void add(RealSignal x, int iterations) {
- table.append(compute(x, iterations, "", "", "", ""));
+ table.append(compute(x, ""+iterations, "", "", "", ""));
}
public void add(RealSignal x, int iterations, String time, String psnr, String snr, String residu) {
- table.append(compute(x, iterations, time, psnr, snr, residu));
+ table.append(compute(x, ""+iterations, time, psnr, snr, residu));
+ }
+
+ public void addOutput(RealSignal x, String algo, String time, String psnr, String snr, String residu) {
+ table.append(compute(x, "Out: " + algo, time, psnr, snr, residu));
}
- public String[] compute(RealSignal x, int iterations, String time, String psnr, String snr, String residu) {
+ public String[] compute(RealSignal x, String iterations, String time, String psnr, String snr, String residu) {
float params[] = null;
if (x != null)
params = x.getStats();
String[] row = new String[12];
- row[0] = "" + iterations;
+ row[0] = iterations;
row[1] = (params == null ? "-" : "" + params[0]);
row[2] = (params == null ? "-" : "" + params[1]);
row[3] = (params == null ? "-" : "" + params[2]);
row[4] = (params == null ? "-" : "" + params[3]);
row[5] = (params == null ? "-" : "" + params[5]);
row[6] = time;
row[7] = NumFormat.bytes(SystemUsage.getHeapUsed());
row[8] = SignalCollector.sumarize();
row[9] = psnr;
row[10] = snr;
row[11] = residu;
return row;
}
public JPanel getPanel() {
JScrollPane scroll = new JScrollPane(table);
scroll.setPreferredSize(new Dimension(Constants.widthGUI, 400));
JPanel panel = new JPanel(new BorderLayout());
panel = new JPanel(new BorderLayout());
panel.add(scroll);
panel.setBorder(BorderFactory.createEtchedBorder());
return panel;
}
public String toStringStats() {
if (mode == Mode.SHOW)
return "show";
if (mode == Mode.SAVE)
return "save";
if (mode == Mode.SHOWSAVE)
return "show and save";
return "no";
}
public Mode getMode() {
return mode;
}
public float[] getStatsInput() {
return statsInput;
}
}
diff --git a/DeconvolutionLab2/src/deconvolution/algorithm/AbstractAlgorithm.java b/DeconvolutionLab2/src/deconvolution/algorithm/AbstractAlgorithm.java
index e6c15e7..1566acd 100644
--- a/DeconvolutionLab2/src/deconvolution/algorithm/AbstractAlgorithm.java
+++ b/DeconvolutionLab2/src/deconvolution/algorithm/AbstractAlgorithm.java
@@ -1,477 +1,479 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolution.algorithm;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import signal.Constraint;
import signal.RealSignal;
import signal.SignalCollector;
import signal.apodization.Apodization;
import signal.padding.Padding;
import bilib.tools.NumFormat;
import deconvolution.Stats;
import deconvolutionlab.Lab;
import deconvolutionlab.monitor.Monitors;
import deconvolutionlab.monitor.Verbose;
import deconvolutionlab.output.Output;
import deconvolutionlab.system.SystemInfo;
import fft.AbstractFFT;
import fft.FFT;
/**
* This class is the common part of every algorithm of deconvolution.
*
* @author Daniel Sage
*
*/
public abstract class AbstractAlgorithm implements Callable<RealSignal> {
/** y is the input signal of the deconvolution. */
protected RealSignal y;
/** h is the PSF signal for the deconvolution. */
protected RealSignal h;
protected boolean threaded;
/** Optimized implementation in term of memory footprint */
protected boolean optimizedMemoryFootprint;
protected int iterMax = 0;
protected AbstractFFT fft;
protected Controller controller;
public AbstractAlgorithm() {
setController(new Controller());
optimizedMemoryFootprint = true;
threaded = true;
fft = FFT.getFastestFFT().getDefaultFFT();
}
public AbstractAlgorithm(Controller controller) {
this.controller = controller;
optimizedMemoryFootprint = true;
threaded = true;
fft = FFT.getFastestFFT().getDefaultFFT();
}
public void setOptimizedMemoryFootprint(boolean optimizedMemoryFootprint) {
this.optimizedMemoryFootprint = optimizedMemoryFootprint;
}
public abstract String getName();
public abstract String[] getShortnames();
public abstract double getMemoryFootprintRatio();
public abstract int getComplexityNumberofFFT();
public abstract boolean isRegularized();
public abstract boolean isStepControllable();
public abstract boolean isIterative();
public abstract boolean isWaveletsBased();
public abstract AbstractAlgorithm setParameters(double... params);
public abstract double getRegularizationFactor();
public abstract double getStepFactor();
public abstract double[] getParameters();
public abstract double[] getDefaultParameters();
public RealSignal run(RealSignal image, RealSignal psf) {
String sn = getShortnames()[0];
+ String algoParam = sn + "(" + getParametersAsString() + ")";
if (controller.isSystem())
SystemInfo.activate();
Padding pad = controller.getPadding();
Apodization apo = controller.getApodization();
double norm = controller.getNormalizationPSF();
+ controller.setAlgoName(algoParam);
fft = controller.getFFT();
controller.setIterationsMax(iterMax);
if (image == null)
return null;
if (psf == null)
return null;
// Prepare the controller and the outputs
Monitors monitors = controller.getMonitors();
monitors.setVerbose(controller.getVerbose());
monitors.log("Path: " + controller.toStringPath());
monitors.log("Algorithm: " + getName());
// Prepare the signal and the PSF
y = pad.pad(monitors, image);
y.setName("y");
apo.apodize(monitors, y);
monitors.log("Input: " + y.dimAsString());
h = psf.changeSizeAs(y);
h.setName("h");
h.normalize(norm);
monitors.log("PSF: " + h.dimAsString() + " normalized " + (norm <= 0 ? "no" : norm));
String iterations = (isIterative() ? iterMax + " iterations" : "direct");
controller.setIterationsMax(iterMax);
- monitors.log(getShortnames()[0] + " is starting (" + iterations + ")");
+ monitors.log(sn + " is starting (" + iterations + ")");
controller.setMonitors(monitors);
controller.start(y);
h.circular();
// FFT
fft.init(monitors, y.nx, y.ny, y.nz);
controller.setFFT(fft);
- monitors.log(getShortnames()[0] + " data ready");
- monitors.log(getShortnames()[0] + "" + getParametersToString());
+ monitors.log(sn + " data ready");
+ monitors.log(algoParam);
RealSignal x = null;
try {
if (threaded == true) {
ExecutorService pool = Executors.newSingleThreadExecutor();
Future<RealSignal> future = pool.submit(this);
x = future.get();
}
else {
x = call();
}
}
catch (InterruptedException ex) {
ex.printStackTrace();
x = y.duplicate();
}
catch (ExecutionException ex) {
ex.printStackTrace();
x = y.duplicate();
}
catch (Exception e) {
e.printStackTrace();
x = y.duplicate();
}
SignalCollector.free(y);
SignalCollector.free(h);
x.setName("x");
RealSignal result = pad.crop(monitors, x);
controller.finish(result);
monitors.log(getName() + " is finished");
SignalCollector.free(x);
if (controller.isDisplayFinal())
Lab.show(monitors, result, "Final Display of " + sn);
- result.setName("Output of " + sn);
+ result.setName("Out of " + algoParam);
monitors.log("End of " + sn + " in " + NumFormat.seconds(controller.getTimeNano()) + " and " + controller.getMemoryAsString());
return result;
}
public AbstractAlgorithm noPopup() {
return this.disableDisplayFinal().disableSystem();
}
public AbstractAlgorithm setController(Controller controller) {
this.controller = controller;
return this;
}
public Controller getController() {
return controller;
}
public int getIterationsMax() {
return iterMax;
}
public int getIterations() {
return controller.getIterations();
}
public double getTime() {
return controller.getTimeNano();
}
public double getMemory() {
return controller.getMemory();
}
public double getResidu() {
return controller.getResidu();
}
public double getSNR() {
return controller.getSNR();
}
public double getPSNR() {
return controller.getPSNR();
}
public void setWavelets(String waveletsName) {
}
@Override
public String toString() {
String s = "";
s += getName();
s += (isIterative() ? ", " + iterMax + " iterations" : " (direct)");
s += (isRegularized() ? ", &lambda=" + NumFormat.nice(getRegularizationFactor()) : "");
s += (isStepControllable() ? ", &gamma=" + NumFormat.nice(getStepFactor()) : "");
return s;
}
public String getParametersAsString() {
double p[] = getParameters();
String param = "";
for (int i = 0; i < p.length; i++)
if (i == p.length - 1)
- param += p[i];
+ param += NumFormat.nice(p[i]);
else
- param += p[i] + ", ";
+ param += NumFormat.nice(p[i]) + ", ";
return param;
}
public AbstractFFT getFFT() {
return controller.getFFT();
}
public AbstractAlgorithm setFFT(AbstractFFT fft) {
this.fft = fft;
controller.setFFT(fft);
return this;
}
public String getPath() {
return controller.getPath();
}
public AbstractAlgorithm setPath(String path) {
controller.setPath(path);
return this;
}
public boolean isSystem() {
return controller.isSystem();
}
public AbstractAlgorithm enableSystem() {
controller.setSystem(true);
return this;
}
public AbstractAlgorithm disableSystem() {
controller.setSystem(false);
return this;
}
public boolean isMultithreading() {
return controller.isMultithreading();
}
public AbstractAlgorithm enableMultithreading() {
controller.setMultithreading(true);
return this;
}
public AbstractAlgorithm disableMultithreading() {
controller.setMultithreading(false);
return this;
}
public boolean isDisplayFinal() {
return controller.isDisplayFinal();
}
public AbstractAlgorithm enableDisplayFinal() {
controller.setDisplayFinal(true);
return this;
}
public AbstractAlgorithm disableDisplayFinal() {
controller.setDisplayFinal(false);
return this;
}
public double getNormalizationPSF() {
return controller.getNormalizationPSF();
}
public AbstractAlgorithm setNormalizationPSF(double normalizationPSF) {
controller.setNormalizationPSF(normalizationPSF);
return this;
}
public double getEpsilon() {
return controller.getEpsilon();
}
public AbstractAlgorithm setEpsilon(double epsilon) {
controller.setEpsilon(epsilon);
return this;
}
public Padding getPadding() {
return controller.getPadding();
}
public AbstractAlgorithm setPadding(Padding padding) {
controller.setPadding(padding);
return this;
}
public Apodization getApodization() {
return controller.getApodization();
}
public AbstractAlgorithm setApodization(Apodization apodization) {
controller.setApodization(apodization);
return this;
}
public Monitors getMonitors() {
return controller.getMonitors();
}
public AbstractAlgorithm setMonitors(Monitors monitors) {
controller.setMonitors(monitors);
return this;
}
public Verbose getVerbose() {
return controller.getVerbose();
}
public AbstractAlgorithm setVerbose(Verbose verbose) {
controller.setVerbose(verbose);
return this;
}
public Constraint.Mode getConstraint() {
return controller.getConstraint();
}
public AbstractAlgorithm setConstraint(Constraint.Mode constraint) {
controller.setConstraint(constraint);
return this;
}
public Stats getStats() {
return controller.getStats();
}
public AbstractAlgorithm setStats(Stats stats) {
controller.setStats(stats);
return this;
}
public AbstractAlgorithm showStats() {
controller.setStats(new Stats(Stats.Mode.SHOW));
return this;
}
public AbstractAlgorithm saveStats(Stats stats) {
controller.setStats(new Stats(Stats.Mode.SAVE));
return this;
}
public AbstractAlgorithm setStats() {
controller.setStats(new Stats(Stats.Mode.SHOWSAVE));
return this;
}
public double getResiduMin() {
return controller.getResiduMin();
}
public AbstractAlgorithm setResiduMin(double residuMin) {
controller.setResiduMin(residuMin);
return this;
}
public double getTimeLimit() {
return controller.getTimeLimit();
}
public AbstractAlgorithm setTimeLimit(double timeLimit) {
controller.setTimeLimit(timeLimit);
return this;
}
public String getReference() {
return controller.getReference();
}
public AbstractAlgorithm setReference(String reference) {
controller.setReference(reference);
return this;
}
public ArrayList<Output> getOuts() {
return controller.getOuts();
}
public AbstractAlgorithm setOuts(ArrayList<Output> outs) {
controller.setOuts(outs);
return this;
}
public AbstractAlgorithm addOutput(Output out) {
controller.addOutput(out);
return this;
}
public String getParametersToString() {
double params[] = getParameters();
if (params != null) {
if (params.length > 0) {
String s = " ";
for (double param : params)
s += NumFormat.nice(param) + " ";
return s;
}
}
return "parameter-free";
}
}
diff --git a/DeconvolutionLab2/src/deconvolution/algorithm/Controller.java b/DeconvolutionLab2/src/deconvolution/algorithm/Controller.java
index 7d29903..78b75ff 100644
--- a/DeconvolutionLab2/src/deconvolution/algorithm/Controller.java
+++ b/DeconvolutionLab2/src/deconvolution/algorithm/Controller.java
@@ -1,645 +1,654 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolution.algorithm;
import java.io.File;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import signal.Assessment;
import signal.ComplexSignal;
import signal.Constraint;
import signal.RealSignal;
import signal.apodization.Apodization;
import signal.padding.Padding;
import bilib.tools.Files;
import bilib.tools.NumFormat;
import deconvolution.Deconvolution;
import deconvolution.Stats;
import deconvolutionlab.Constants;
import deconvolutionlab.monitor.AbstractMonitor;
import deconvolutionlab.monitor.ConsoleMonitor;
import deconvolutionlab.monitor.Monitors;
import deconvolutionlab.monitor.TableMonitor;
import deconvolutionlab.monitor.Verbose;
import deconvolutionlab.output.Output;
import deconvolutionlab.system.SystemUsage;
import fft.AbstractFFT;
import fft.FFT;
/**
* This is an important class to manage all the common task of the algorithm.
* The method start() is called before at the starting of the algorithm. The
* method ends() is called at the end of every iterations for the iterative
* algorithm. It returns true if one the stopping criteria is true. The method
* finish() is called when the algorithm is completely terminated.
*
* @author Daniel Sage
*
*/
public class Controller {
private String path;
private boolean system;
private boolean multithreading;
private boolean displayFinal;
private double normalizationPSF;
private double epsilon;
private Padding padding;
private Apodization apodization;
private ArrayList<Output> outs;
private Stats stats;
private Constraint.Mode constraintMode;
private double residuMin;
private double timeLimit;
private String reference;
private Monitors monitors;
private Verbose verbose;
private AbstractFFT fft;
private int iterationsMax = 100;
private boolean doResidu = false;
private boolean doTime = false;
private boolean doReference = false;
private boolean doConstraint = false;
private boolean abort = false;
private double timeStarting = 0;
private double memoryStarting = 0;
private double residu = Double.MAX_VALUE;
private int iterations = 0;
private double memoryPeak = 0;
private double snr = 0;
private double psnr = 0;
private RealSignal refImage;
private RealSignal prevImage;
private RealSignal x;
private Timer timer;
+
+ private String algoName = "";
public Controller() {
doResidu = false;
doTime = false;
doReference = false;
doConstraint = false;
timeStarting = System.nanoTime();
setPath(Files.getWorkingDirectory());
setSystem(true);
setMultithreading(true);
setDisplayFinal(true);
setFFT(FFT.getFastestFFT().getDefaultFFT());
setNormalizationPSF(1);
setEpsilon(1e-6);
setPadding(new Padding());
setApodization(new Apodization());
monitors = new Monitors();
monitors.add(new ConsoleMonitor());
monitors.add(new TableMonitor(Constants.widthGUI, 240));
setVerbose(Verbose.Log);
setStats(new Stats(Stats.Mode.NO));
setConstraint(Constraint.Mode.NO);
setResiduMin(-1);
setTimeLimit(-1);
setReference("");
setOuts(new ArrayList<Output>());
}
+ public void setAlgoName(String algoName) {
+ this.algoName = algoName;
+ }
+
public void setFFT(AbstractFFT fft) {
this.fft = fft;
}
public void abort() {
this.abort = true;
}
public void setIterationsMax(int iterationsMax) {
this.iterationsMax = iterationsMax;
}
public boolean needSpatialComputation() {
return doConstraint || doResidu || doReference;
}
/**
* Call one time at the beginning of the algorithms
*
* @param x
* the input signal
*/
public void start(RealSignal x) {
this.x = x;
stats.show();
stats.addInput(x);
iterations = 0;
timer = new Timer();
timer.schedule(new Updater(), 0, 100);
timeStarting = System.nanoTime();
memoryStarting = SystemUsage.getHeapUsed();
if (doConstraint && x != null)
Constraint.setModel(x);
if (doReference) {
refImage = new Deconvolution("Reference", "-image file " + reference).openImage();
if (refImage == null)
monitors.error("Impossible to load the reference image " + reference);
else
monitors.log("Reference image loaded");
}
for (Output out : outs)
out.executeStarting(monitors, x, this);
this.prevImage = x;
}
public boolean ends(ComplexSignal X) {
boolean out = false;
for (Output output : outs)
out = out | output.is(iterations);
if (doConstraint || doResidu || doReference || out) {
if (fft == null)
fft = FFT.createDefaultFFT(monitors, X.nx, X.ny, X.nz);
x = fft.inverse(X, x);
return ends(x);
}
return ends((RealSignal) null);
}
public boolean ends(RealSignal x) {
this.x = x;
if (doConstraint || doResidu || doReference)
compute(iterations, x, doConstraint, doResidu, doReference);
for (Output out : outs)
out.executeIterative(monitors, x, this, iterations);
iterations++;
double p = iterations * 100.0 / iterationsMax;
monitors.progress("Iterative " + iterations + "/" + iterationsMax, p);
double timeElapsed = getTimeSecond();
boolean stopIter = (iterations >= iterationsMax);
boolean stopTime = doTime && (timeElapsed >= timeLimit);
boolean stopResd = doResidu && (residu <= residuMin);
monitors.log("@" + iterations + " Time: " + NumFormat.seconds(timeElapsed*1e9));
addStats();
String prefix = "Stopped>> by ";
if (abort)
monitors.log(prefix + "abort");
if (stopIter)
monitors.log(prefix + "iteration " + iterations + " > " + iterationsMax);
if (stopTime)
monitors.log(prefix + "time " + timeElapsed + " > " + timeLimit);
if (stopResd)
monitors.log(prefix + "residu " + NumFormat.nice(residu) + " < " + NumFormat.nice(residuMin));
return abort | stopIter | stopTime | stopResd;
}
public void finish(RealSignal x) {
this.x = x;
boolean ref = doReference;
boolean con = doConstraint;
boolean res = doResidu;
if (con || res || ref)
compute(iterations, x, con, res, ref);
- addStats();
+ String pnsrText = doReference ? NumFormat.nice(psnr) : "n/a";
+ String snrText = doReference ? NumFormat.nice(snr) : "n/a";
+ String residuText = doResidu ? NumFormat.nice(residu) : "n/a";
+ stats.addOutput(x, algoName, NumFormat.seconds(getTimeNano()), pnsrText, snrText, residuText);
+
stats.save(monitors, path);
for (Output out : outs)
out.executeFinal(monitors, x, this);
monitors.log("Time: " + NumFormat.seconds(getTimeNano()) + " Peak:" + getMemoryAsString());
if (timer != null)
timer.cancel();
}
private void compute(int iterations, RealSignal x, boolean con, boolean res, boolean ref) {
if (x == null)
return;
if (con && constraintMode != null)
new Constraint(monitors).apply(x, constraintMode);
if (ref && refImage != null) {
String s = "";
psnr = Assessment.psnr(x, refImage);
snr = Assessment.snr(x, refImage);
s += " PSNR: " + NumFormat.nice(psnr);
s += " SNR: " + NumFormat.nice(snr);
monitors.log("@" + iterations + " " + s);
}
residu = Double.MAX_VALUE;
if (res && prevImage != null) {
residu = Assessment.relativeResidu(x, prevImage);
prevImage = x.duplicate();
monitors.log("@" + iterations + " Residu: " + NumFormat.nice(residu));
}
}
private void addStats() {
String pnsrText = doReference ? NumFormat.nice(psnr) : "n/a";
String snrText = doReference ? NumFormat.nice(snr) : "n/a";
String residuText = doResidu ? NumFormat.nice(residu) : "n/a";
-
stats.add(x, iterations, NumFormat.seconds(getTimeNano()), pnsrText, snrText, residuText);
}
public double getTimeNano() {
return (System.nanoTime() - timeStarting);
}
public double getTimeSecond() {
return (System.nanoTime() - timeStarting) * 1e-9;
}
public String getConstraintAsString() {
if (!doConstraint)
return "no";
if (constraintMode == null)
return "null";
return constraintMode.name().toLowerCase();
}
public String getStoppingCriteriaAsString(AbstractAlgorithm algo) {
String stop = algo.isIterative() ? "iterations limit=" + algo.getIterationsMax() + ", " : "direct, ";
stop += doTime ? ", time limit=" + NumFormat.nice(timeLimit * 1e-9) : " no time limit" + ", ";
stop += doResidu ? ", residu limit=" + NumFormat.nice(residuMin) : " no residu limit";
return stop;
}
public double getMemory() {
return memoryPeak - memoryStarting;
}
public String getMemoryAsString() {
return NumFormat.bytes(getMemory());
}
public int getIterations() {
return iterations;
}
public double getSNR() {
return snr;
}
public double getPSNR() {
return psnr;
}
public double getResidu() {
return residu;
}
private void update() {
memoryPeak = Math.max(memoryPeak, SystemUsage.getHeapUsed());
}
public AbstractFFT getFFT() {
return fft;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path
* the path to set
*/
public void setPath(String path) {
this.path = path;
}
/**
* @return the system
*/
public boolean isSystem() {
return system;
}
/**
* @param system
* the system to set
*/
public void setSystem(boolean system) {
this.system = system;
}
/**
* @return the multithreading
*/
public boolean isMultithreading() {
return multithreading;
}
/**
* @param multithreading
* the multithreading to set
*/
public void setMultithreading(boolean multithreading) {
this.multithreading = multithreading;
}
/**
* @return the displayFinal
*/
public boolean isDisplayFinal() {
return displayFinal;
}
/**
* @param displayFinal
* the displayFinal to set
*/
public void setDisplayFinal(boolean displayFinal) {
this.displayFinal = displayFinal;
}
/**
* @return the normalizationPSF
*/
public double getNormalizationPSF() {
return normalizationPSF;
}
/**
* @param normalizationPSF
* the normalizationPSF to set
*/
public void setNormalizationPSF(double normalizationPSF) {
this.normalizationPSF = normalizationPSF;
}
/**
* @return the epsilon
*/
public double getEpsilon() {
return epsilon;
}
/**
* @param epsilon
* the epsilon to set
*/
public void setEpsilon(double epsilon) {
this.epsilon = epsilon;
}
/**
* @return the padding
*/
public Padding getPadding() {
return padding;
}
/**
* @param padding
* the padding to set
*/
public void setPadding(Padding padding) {
this.padding = padding;
}
/**
* @return the apodization
*/
public Apodization getApodization() {
return apodization;
}
/**
* @param apodization
* the apodization to set
*/
public void setApodization(Apodization apodization) {
this.apodization = apodization;
}
/**
* @return the monitors
*/
public Monitors getMonitors() {
if (monitors == null)
return Monitors.createDefaultMonitor();
return monitors;
}
/**
* @param monitors
* the monitors to set
*/
public void setMonitors(Monitors monitors) {
this.monitors = monitors;
}
/**
* @return the verbose
*/
public Verbose getVerbose() {
return verbose;
}
/**
* @param verbose
* the verbose to set
*/
public void setVerbose(Verbose verbose) {
this.verbose = verbose;
}
public Constraint.Mode getConstraint() {
return constraintMode;
}
public void setConstraint(Constraint.Mode constraintMode) {
doConstraint = constraintMode != Constraint.Mode.NO;
this.constraintMode = constraintMode;
}
/**
* @return the stats
*/
public Stats getStats() {
return stats;
}
/**
* @param stats
* the stats to set
*/
public void setStats(Stats stats) {
this.stats = stats;
}
/**
* @return the residuMin
*/
public double getResiduMin() {
return residuMin;
}
/**
* @param residuMin
* the residuMin to set
*/
public void setResiduMin(double residuMin) {
doResidu = residuMin > 0;
this.residuMin = residuMin;
}
/**
* @return the timeLimit
*/
public double getTimeLimit() {
return timeLimit;
}
/**
* @param timeLimit
* the timeLimit to set
*/
public void setTimeLimit(double timeLimit) {
doTime = timeLimit > 0;
this.timeLimit = timeLimit;
}
/**
* @return the reference
*/
public String getReference() {
return reference;
}
/**
* @param reference
* the reference to set
*/
public void setReference(String reference) {
doReference = false;
if (reference == null)
return;
if (reference.equals(""))
return;
doReference = true;
this.reference = reference;
}
/**
* @return the outs
*/
public ArrayList<Output> getOuts() {
return outs;
}
/**
* @param outs
* the outs to set
*/
public void setOuts(ArrayList<Output> outs) {
this.outs = outs;
}
public void addOutput(Output out) {
this.outs.add(out);
}
public String toStringMonitor() {
String s = "[" + verbose.name().toLowerCase() + "] ";
for (AbstractMonitor monitor : monitors) {
s += "" + monitor.getName() + " ";
}
return s;
}
public Stats.Mode getStatsMode() {
return stats.getMode();
}
public void setStatsMode(Stats.Mode mode) {
this.stats = new Stats(mode);
}
public String toStringRunning() {
String s = "";
s += "system " + (system ? "shown" : "hidden ");
s += ", multithreading " + (multithreading ? "on" : "off ");
s += ", display final " + (displayFinal ? "on " : "off ");
return s;
}
public String toStringPath() {
File dir = new File(path);
if (dir.exists()) {
if (dir.isDirectory()) {
if (dir.canWrite())
return path + " (writable)";
else
return path + " (non-writable)";
}
else {
return path + " (non-directory)";
}
}
else {
return path + " (not-valid)";
}
}
private class Updater extends TimerTask {
@Override
public void run() {
update();
}
}
}
diff --git a/DeconvolutionLab2/src/deconvolution/algorithm/RegularizedInverseFilter.java b/DeconvolutionLab2/src/deconvolution/algorithm/RegularizedInverseFilter.java
index 309f51e..4d0909d 100644
--- a/DeconvolutionLab2/src/deconvolution/algorithm/RegularizedInverseFilter.java
+++ b/DeconvolutionLab2/src/deconvolution/algorithm/RegularizedInverseFilter.java
@@ -1,190 +1,186 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolution.algorithm;
import java.util.concurrent.Callable;
-import deconvolutionlab.Lab;
import signal.ComplexSignal;
import signal.Operations;
import signal.RealSignal;
import signal.SignalCollector;
import signal.factory.complex.ComplexSignalFactory;
public class RegularizedInverseFilter extends AbstractAlgorithm implements Callable<RealSignal> {
private double lambda = 0.001;
public RegularizedInverseFilter(double lambda) {
super();
this.lambda = lambda;
}
@Override
public RealSignal call() {
if (optimizedMemoryFootprint)
return runOptimizedMemoryFootprint();
else
return runTextBook();
}
public RealSignal runTextBook() {
ComplexSignal Y = fft.transform(y);
ComplexSignal H = fft.transform(h);
ComplexSignal H2 = Operations.multiply(H, H);
ComplexSignal L = ComplexSignalFactory.laplacian(Y.nx, Y.ny, Y.nz);
ComplexSignal L2 = Operations.multiply(lambda, L, L);
ComplexSignal FA = Operations.add(H2, L2);
ComplexSignal FT = Operations.divideStabilized(H, FA);
ComplexSignal X = Operations.multiply(Y, FT);
RealSignal x = fft.inverse(X);
SignalCollector.free(FT);
SignalCollector.free(Y);
SignalCollector.free(H);
SignalCollector.free(FA);
SignalCollector.free(L);
SignalCollector.free(H2);
SignalCollector.free(L2);
SignalCollector.free(X);
return x;
}
public RealSignal runOptimizedMemoryFootprint() {
ComplexSignal Y = fft.transform(y);
ComplexSignal H = fft.transform(h);
ComplexSignal X = filter(Y, H);
SignalCollector.free(Y);
SignalCollector.free(H);
RealSignal x = fft.inverse(X);
SignalCollector.free(X);
return x;
}
public ComplexSignal filter(ComplexSignal Y, ComplexSignal H) {
ComplexSignal L = ComplexSignalFactory.laplacian(Y.nx, Y.ny, Y.nz);
L.setName("Laplacian");
-System.out.println(" >>>>>>>>>>>>>>>>>> " + L.getEnergy());
-Lab.show(controller.getMonitors(), L, "L");
float la, lb, ha, hb, fa, fb, ta, tb, ya, yb;
int nxy = Y.nx * Y.ny * 2;
float w = (float) lambda;
float epsilon = (float) Operations.epsilon;
for (int k = 0; k < Y.nz; k++)
for (int i = 0; i < nxy; i += 2) {
la = L.data[k][i];
lb = L.data[k][i + 1];
ha = H.data[k][i];
hb = H.data[k][i + 1];
fa = w * (la * la - lb * lb) + (ha * ha - hb * hb);
fb = w * (2f * la * lb) + (2f * ha * hb);
float mag = Math.max(epsilon, fa * fa + fb * fb);
ta = (ha * fa + hb * fb) / mag;
tb = (hb * fa - ha * fb) / mag;
ya = Y.data[k][i];
yb = Y.data[k][i + 1];
L.data[k][i] = ya * ta - yb * tb;
L.data[k][i + 1] = ya * tb + ta * yb;
}
- // SignalCollector.free(L);
return L;
}
@Override
public String getName() {
return "Regularized Inverse Filter";
}
@Override
public String[] getShortnames() {
return new String[] {"RIF", "LRIF"};
}
@Override
public int getComplexityNumberofFFT() {
return 3;
}
@Override
public double getMemoryFootprintRatio() {
return 8.0;
}
@Override
public boolean isRegularized() {
return true;
}
@Override
public boolean isStepControllable() {
return false;
}
@Override
public boolean isIterative() {
return false;
}
@Override
public boolean isWaveletsBased() {
return false;
}
@Override
public AbstractAlgorithm setParameters(double... params) {
if (params == null)
return this;
if (params.length > 0)
lambda = (float) params[0];
return this;
}
@Override
public double[] getDefaultParameters() {
return new double[] { 0.1 };
}
@Override
public double[] getParameters() {
return new double[] { lambda };
}
@Override
public double getRegularizationFactor() {
return lambda;
}
@Override
public double getStepFactor() {
return 0;
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/Lab.java b/DeconvolutionLab2/src/deconvolutionlab/Lab.java
index b6694a7..3f47a3f 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/Lab.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/Lab.java
@@ -1,534 +1,576 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolutionlab;
import java.io.File;
import java.util.ArrayList;
import java.util.regex.Pattern;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import bilib.tools.Files;
import bilib.tools.NumFormat;
import bilib.tools.WebBrowser;
import deconvolutionlab.Imager.ContainerImage;
import deconvolutionlab.monitor.Monitors;
import fft.AbstractFFT;
import fft.AbstractFFTLibrary;
import fft.FFT;
import ij.IJ;
+import ij.gui.Plot;
import imagej.IJImager;
import plugins.sage.deconvolutionlab.IcyImager;
import signal.ComplexComponent;
import signal.ComplexSignal;
import signal.RealSignal;
import signal.factory.SignalFactory;
import signal.factory.Sphere;
/**
* This class contains a collection of useful static methods to manage all the
* peripherical aspects of the deconvolution, such as load, display, or save an
* image.
* <p>
* At the construction of the class, the config is loaded. In practice, any
* deconvolution program has to start with Lab.init(Platform).
*
* @author Daniel Sage
*
*/
public class Lab {
private static Imager imaging;
private static ArrayList<JFrame> frames;
private static ArrayList<JDialog> dialogs;
static {
frames = new ArrayList<JFrame>();
dialogs = new ArrayList<JDialog>();
imaging = new IJImager();
Config.init(Files.getWorkingDirectory() + "DeconvolutionLab2.config");
}
/**
* Initializes the Lab with a give platform.
*
* @param platform
* The platform is ImageJ, ICY, or Matlab.
*/
public static void init(Imager.Platform platform) {
init(platform, Files.getWorkingDirectory() + "DeconvolutionLab2.config");
}
/**
* Initializes the Lab with a give platform and a given configuration file
*
* @param platform
* @param configFilename
*/
public static void init(Imager.Platform platform, String configFilename) {
switch (platform) {
case IMAGEJ:
imaging = new IJImager();
break;
case ICY:
imaging = new IcyImager();
break;
default:
imaging = new IJImager();
break;
}
Config.init(configFilename);
}
/**
* Returns the platform.
*
* @return
*/
public static Imager.Platform getPlatform() {
return imaging.getPlatform();
}
/**
* Open a web page on the DeconvolutionLab2.
*/
public static void help() {
WebBrowser.open(Constants.url);
}
/**
* Checks the installed FFT libraries on a small (40, 30, 20) signal.
*
* @param monitors
*/
public static void checkFFT(Monitors monitors) {
ArrayList<AbstractFFTLibrary> libraries = FFT.getInstalledLibraries();
for (AbstractFFTLibrary library : libraries) {
RealSignal y = new Sphere(3, 1).generate(40, 30, 20);
double chrono = System.nanoTime();
AbstractFFT fft = library.getDefaultFFT();
fft.init(monitors, y.nx, y.ny, y.nz);
RealSignal x = fft.inverse(fft.transform(y));
chrono = System.nanoTime() - chrono;
double residu = y.getEnergy() - x.getEnergy();
monitors.log("\t residu of reconstruction: " + residu);
monitors.log("\t computation time (" + x.nx + "x" + x.ny + "x" + x.nz + ") " + NumFormat.time(chrono));
}
}
public static ContainerImage createContainer(Monitors monitors, String title) {
monitors.log("Create Live Real Signal " + title);
return imaging.createContainer(title);
}
public static void append(Monitors monitors, ContainerImage container, RealSignal signal, String title) {
imaging.append(container, signal, title, Imager.Type.FLOAT);
monitors.log("Add Live Real Signal " + title);
}
public static void append(Monitors monitors, ContainerImage container, RealSignal signal, String title, Imager.Type type) {
imaging.append(container, signal, title, type);
monitors.log("Add Live Real Signal " + title);
}
/**
* Displays a the module of complex signal.
*
* @param monitors
* @param signal
* @param title
*/
public static void show(Monitors monitors, ComplexSignal signal, String title) {
if (signal == null) {
monitors.error("Show " + title + " this image does not exist.");
return;
}
monitors.log("Show Real Signal " + title);
imaging.show(signal, title, ComplexComponent.MODULE);
}
/**
* Displays a real 3D signal a z-stack of images.
*
* @param signal
*/
public static void show(RealSignal signal) {
if (signal == null) {
return;
}
imaging.show(signal, signal.name, Imager.Type.FLOAT, signal.nz / 2);
}
/**
* Displays a real 3D signal a z-stack of images.
*
* @param monitors
* @param signal
*/
public static void show(Monitors monitors, RealSignal signal) {
if (signal == null) {
monitors.error("This image does not exist.");
return;
}
monitors.log("Show Real Signal " + signal.name);
imaging.show(signal, signal.name, Imager.Type.FLOAT, signal.nz / 2);
}
/**
* Displays a real 3D signal a z-stack of images.
*
* @param monitors
* @param signal
* @param title
*/
public static void show(Monitors monitors, RealSignal signal, String title) {
if (signal == null) {
monitors.error("Show " + title + " this image does not exist.");
return;
}
monitors.log("Show Real Signal " + title);
imaging.show(signal, title, Imager.Type.FLOAT, signal.nz / 2);
}
/**
* Displays a real 3D signal a z-stack of images using a given type.
*
* @param monitors
* @param signal
* @param title
* @param type
*/
public static void show(Monitors monitors, RealSignal signal, String title, Imager.Type type) {
if (signal == null) {
monitors.error("Show " + title + " this image does not exist.");
return;
}
monitors.log("Show Real Signal " + title);
imaging.show(signal, title, type, signal.nz / 2);
}
/**
* Displays a real 3D signal a z-stack of images using a given type and
* shows the slice number z.
*
* @param monitors
* @param signal
* @param title
* @param type
* @param z
*/
public static void show(Monitors monitors, RealSignal signal, String title, Imager.Type type, int z) {
if (signal == null) {
monitors.error("Show " + title + " this image does not exist.");
return;
}
monitors.log("Show Real Signal " + title);
imaging.show(signal, title, type, z);
}
public static void save(Monitors monitors, RealSignal signal, String path, String name) {
save(monitors, signal, path + File.separator + name + ".tif", Imager.Type.FLOAT);
}
public static void save(Monitors monitors, RealSignal signal, String path, String name, Imager.Type type) {
save(monitors, signal, path + File.separator + name + ".tif", type);
}
+
+ public static void save(Monitors monitors, RealSignal signal, String filename, Imager.Type type) {
+ imaging.save(signal, filename, type);
+ monitors.log("Save Real Signal " + filename);
+ }
public static void save(Monitors monitors, RealSignal signal, String filename) {
imaging.save(signal, filename, Imager.Type.FLOAT);
monitors.log("Save Real Signal " + filename);
}
- public static void save(Monitors monitors, RealSignal signal, String filename, Imager.Type type) {
+ public static void save(RealSignal signal, String path, String name) {
+ save(signal, path + File.separator + name + ".tif", Imager.Type.FLOAT);
+ }
+
+ public static void save(RealSignal signal, String path, String name, Imager.Type type) {
+ save(signal, path + File.separator + name + ".tif", type);
+ }
+
+ public static void save(RealSignal signal, String filename) {
+ imaging.save(signal, filename, Imager.Type.FLOAT);
+ }
+
+ public static void save(RealSignal signal, String filename, Imager.Type type) {
imaging.save(signal, filename, type);
- monitors.log("Save Real Signal " + filename);
}
public static RealSignal createSynthetic(Monitors monitors, String cmd) {
RealSignal signal = SignalFactory.createFromCommand(cmd);
if (signal == null)
monitors.error("Unable to create " + cmd);
else
monitors.log("Create " + cmd);
return signal;
}
/**
* Return the active image.
*
* @return
*/
public static RealSignal getImage() {
return getImager().getActiveImage();
}
/**
* Return an image from the platform with a specified name.
*
* @param name
* @return
*/
public static RealSignal getImage(String name) {
return getImager().getImageByName(name);
}
/**
* Return an image from the platform with a specified name.
*
* @param monitors
* @param name
* @return
*/
public static RealSignal getImage(Monitors monitors, String name) {
RealSignal signal = getImager().getImageByName(name);
if (signal == null)
monitors.error("Unable to get " + name);
else
monitors.log("Load " + name);
return signal;
}
/**
* Open an image from the disk.
*
* @param filename
* @return
*/
public static RealSignal openFile(String filename) {
return imaging.open(filename);
}
/**
* Open an image from the disk.
*
* @param monitors
* @param filename
* @return
*/
public static RealSignal openFile(Monitors monitors, String filename) {
RealSignal signal = imaging.open(filename);
if (signal == null)
monitors.error("Unable to open " + filename);
else
monitors.log("Load " + filename);
return signal;
}
/**
* Open a series of image from a directory.
*
* @param path
* @return
*/
public static RealSignal openDir(String path) {
return openDir(Monitors.createDefaultMonitor(), path);
}
/**
* Open a series of image from a directory.
*
* @param monitors
* @param path
* @return
*/
public static RealSignal openDir(Monitors monitors, String path) {
String parts[] = path.split(" pattern ");
String dirname = path;
String regex = "";
if (parts.length == 2) {
dirname = parts[0].trim();
regex = parts[1].trim();
}
File file = new File(dirname + File.separator);
if (!file.isDirectory()) {
monitors.error("Dir " + dirname + " is not a directory.");
return null;
}
String[] list = file.list();
ArrayList<RealSignal> slices = new ArrayList<RealSignal>();
int nx = 0;
int ny = 0;
Pattern pattern = Pattern.compile(regex);
for (String filename : list) {
if (pattern.matcher(filename).find()) {
RealSignal slice = imaging.open(dirname + File.separator + filename);
if (slice != null) {
slices.add(slice);
nx = Math.max(nx, slice.nx);
ny = Math.max(ny, slice.ny);
monitors.log("Image " + path + File.separator + filename + " is loaded.");
}
}
else {
monitors.error("Error in loading image " + path + File.separator + filename);
}
}
int nz = slices.size();
if (nz <= 0) {
monitors.error("Dir " + path + " do no contain valid images.");
return null;
}
RealSignal signal = new RealSignal(file.getName(), nx, ny, nz);
for (int z = 0; z < slices.size(); z++)
signal.setSlice(z, slices.get(z));
return signal;
}
+ public static void showOrthoview(RealSignal signal, int hx, int hy, int hz) {
+ showOrthoview(signal, signal.name, hx, hy, hz);
+ }
+
public static void showOrthoview(RealSignal signal, String title, int hx, int hy, int hz) {
if (signal == null) {
return;
}
imaging.show(signal.createOrthoview(hx, hy, hz), title, Imager.Type.FLOAT, 0);
}
public static void showOrthoview(Monitors monitors, RealSignal signal, String title, int hx, int hy, int hz) {
if (signal == null) {
monitors.error("Show Orthoview " + title + " this image does not exist.");
return;
}
imaging.show(signal.createOrthoview(hx, hy, hz), title, Imager.Type.FLOAT, 0);
}
public static void showOrthoview(RealSignal signal) {
+ showOrthoview(signal, signal.name);
+ }
+
+ public static void showOrthoview(RealSignal signal, String title) {
if (signal == null) {
return;
}
int hx = signal.nx / 2;
int hy = signal.ny / 2;
int hz = signal.nz / 2;
- imaging.show(signal.createOrthoview(hx, hy, hz), signal.name, Imager.Type.FLOAT, 0);
+ imaging.show(signal.createOrthoview(hx, hy, hz), title, Imager.Type.FLOAT, 0);
}
-
+
public static void showOrthoview(Monitors monitors, RealSignal signal, String title) {
if (signal == null) {
monitors.error("Show Orthoview " + title + " this image does not exist.");
return;
}
int hx = signal.nx / 2;
int hy = signal.ny / 2;
int hz = signal.nz / 2;
imaging.show(signal.createOrthoview(hx, hy, hz), title, Imager.Type.FLOAT, 0);
}
public static void showMIP(RealSignal signal) {
+ showMIP(signal, signal.name);
+ }
+
+ public static void showMIP(RealSignal signal, String title) {
if (signal == null) {
return;
}
- imaging.show(signal.createMIP(), signal.name, Imager.Type.FLOAT, 0);
+ imaging.show(signal.createMIP(), title, Imager.Type.FLOAT, 0);
}
-
+
public static void showMIP(Monitors monitors, RealSignal signal, String title) {
if (signal == null) {
monitors.error("Show MIP " + title + " this image does not exist.");
return;
}
imaging.show(signal.createMIP(), title, Imager.Type.FLOAT, 0);
}
public static void showPlanar(RealSignal signal) {
+ showPlanar(signal, signal.name);
+ }
+
+ public static void showPlanar(RealSignal signal, String title) {
if (signal == null) {
return;
}
- imaging.show(signal.createPlanar(), signal.name, Imager.Type.FLOAT, 0);
+ imaging.show(signal.createPlanar(), title, Imager.Type.FLOAT, 0);
}
-
+
public static void showPlanar(Monitors monitors, RealSignal signal, String title) {
if (signal == null) {
monitors.error("Show Planar " + title + " this image does not exist.");
return;
}
imaging.show(signal.createPlanar(), title, Imager.Type.FLOAT, 0);
}
-/*
- public static RealSignal create(Monitors monitors, String name) {
- RealSignal signal = imaging.create(name);
- if (signal != null)
- monitors.log("Created the real signal " + name + " " + signal.toString());
- else
- monitors.error("Impossible to create the real signal " + name);
- return signal;
+
+
+ public static void plotProfile(RealSignal signal, String name, int x1, int y1, int z1, int x2, int y2, int z2) {
+ if (signal == null) {
+ return;
+ }
+ double dx = x2 - x1;
+ double dy = y2 - y1;
+ double dz = z2 - z1;
+ double len = Math.sqrt(dx*dx + dy*dy + dz*dz);
+ int n = (int)Math.round(len * 2);
+ double ds = len / n;
+ dx = (double)(x2 - x1) / n;
+ dy = (double)(y2 - y1) / n;
+ dz = (double)(z2 - z1) / n;
+ double value[] = new double[n];
+ double dist[] = new double[n];
+ for(int s=0; s<n; s++) {
+ double x = x1 + s*dx;
+ double y = y1 + s*dy;
+ double z = z1 + s*dz;
+ dist[s] = s*ds;
+ value[s] = signal.getInterpolatedPixel(x, y, z);
+ }
+ Plot plot = new Plot(name, "distance", "intensity", dist, value);
+ plot.show();
}
- public static RealSignal create(Monitors monitors) {
- RealSignal signal = imaging.create();
- if (signal != null)
- monitors.log("Created the real signal from the active window " + signal.toString());
- else
- monitors.error("Impossible to create the real signal from the active window");
- return signal;
- }
-*/
public static Imager getImager() {
return imaging;
}
public static String getActiveImage() {
if (imaging.isSelectable())
return imaging.getSelectedImage();
return "";
}
public static void setVisible(JDialog dialog, boolean modal) {
if (dialog == null)
return;
dialogs.add(dialog);
imaging.setVisible(dialog, modal);
}
public static void setVisible(JPanel panel, String name, int x, int y) {
JFrame frame = new JFrame(name);
frame.getContentPane().add(panel);
frame.pack();
frame.setLocation(x, y);
frame.setVisible(true);
frames.add(frame);
}
public static void setVisible(JFrame frame) {
frames.add(frame);
frame.setVisible(true);
}
public static void close() {
for (JFrame frame : frames)
if (frame != null)
frame.dispose();
for (JDialog dialog : dialogs)
if (dialog != null)
dialog.dispose();
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/LabPanel.java b/DeconvolutionLab2/src/deconvolutionlab/LabPanel.java
index 2b7255e..c35d600 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/LabPanel.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/LabPanel.java
@@ -1,303 +1,298 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolutionlab;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import bilib.component.PanelImage;
import deconvolution.Command;
import deconvolution.Deconvolution;
import deconvolutionlab.dialog.BatchDialog;
import deconvolutionlab.module.AboutModule;
import deconvolutionlab.module.AbstractModule;
import deconvolutionlab.module.AlgorithmModule;
import deconvolutionlab.module.BatchModule;
import deconvolutionlab.module.CommandModule;
import deconvolutionlab.module.ConfigModule;
import deconvolutionlab.module.ControllerModule;
import deconvolutionlab.module.DirectoryModule;
-import deconvolutionlab.module.FFTModule;
+import deconvolutionlab.module.ResourcesModule;
import deconvolutionlab.module.GroupedModulePanel;
import deconvolutionlab.module.ImageModule;
import deconvolutionlab.module.LanguageModule;
import deconvolutionlab.module.LicenceModule;
import deconvolutionlab.module.OutputModule;
import deconvolutionlab.module.PSFModule;
import deconvolutionlab.module.PreprocessingModule;
import deconvolutionlab.system.SystemInfo;
/**
* This class build the main panel for DeconvolutionLab2. It consists to a
* series of collapse/expanded modules that are placed in different tabs. The size
* of the panel is dynamically computed,
*
* @author Daniel Sage
*
*/
public class LabPanel extends JPanel implements ActionListener, ChangeListener {
private JTabbedPane tab = new JTabbedPane();
private JButton bnHelp = new JButton("Help");
private JButton bnQuit = new JButton("Quit");
- private JButton bnSystem = new JButton("System");
private JButton bnBatch = new JButton("Batch");
private JButton bnRun = new JButton("Run");
private JButton bnLaunch = new JButton("Launch");
private JButton bnClose;
private ImageModule image;
private PSFModule psf;
private AlgorithmModule algo;
private AboutModule about;
private LicenceModule licence;
private OutputModule output;
private PreprocessingModule preprocessing;
private ConfigModule config;
private BatchModule batch;
private LanguageModule language;
private CommandModule command;
private DirectoryModule directory;
- private FFTModule fft;
+ private ResourcesModule resources;
private ControllerModule controller;
private GroupedModulePanel panelDeconv;
private GroupedModulePanel panelAdvanc;
private GroupedModulePanel panelScript;
private GroupedModulePanel panelAbout;
private AbstractModule modules[];
public LabPanel(JButton bnClose) {
this.bnClose = bnClose;
image = new ImageModule();
psf = new PSFModule();
algo = new AlgorithmModule();
output = new OutputModule();
preprocessing = new PreprocessingModule();
controller = new ControllerModule();
batch = new BatchModule();
language = new LanguageModule();
about = new AboutModule();
licence = new LicenceModule();
config = new ConfigModule();
command = new CommandModule();
directory = new DirectoryModule();
- fft = new FFTModule();
+ resources = new ResourcesModule();
- modules = new AbstractModule[] { image, psf, algo, output, controller, preprocessing, batch, directory, fft };
+ modules = new AbstractModule[] { image, psf, algo, output, controller, preprocessing, batch, directory, resources };
Command.active(modules, command);
Command.command();
panelDeconv = new GroupedModulePanel(buildDeconvolutionPanel(), this);
panelAdvanc = new GroupedModulePanel(buildAdvancedPanel(), this);
panelScript = new GroupedModulePanel(buildProgrammingPanel(), this);
panelAbout = new GroupedModulePanel(buildAboutPanel(), this);
Border border = BorderFactory.createEmptyBorder(5, 5, 5, 5);
PanelImage bottom = new PanelImage("celegans.jpg");
bottom.setBorder(border);
bottom.setLayout(new GridLayout(1, 6));
bottom.setBorder(border);
bottom.add(bnHelp);
- bottom.add(bnSystem);
bottom.add(bnClose);
bottom.add(bnBatch);
bottom.add(bnRun);
bottom.add(bnLaunch);
tab.add("Deconvolution", panelDeconv);
tab.add("Advanced", panelAdvanc);
tab.add("Scripting", panelScript);
tab.add("About", panelAbout);
tab.addChangeListener(this);
setLayout(new BorderLayout());
add(tab, BorderLayout.CENTER);
add(bottom, BorderLayout.SOUTH);
bnBatch.addActionListener(this);
bnRun.addActionListener(this);
bnLaunch.addActionListener(this);
bnClose.addActionListener(this);
bnQuit.addActionListener(this);
bnHelp.addActionListener(this);
- bnSystem.addActionListener(this);
((GroupedModulePanel) tab.getSelectedComponent()).organize();
setMinimumSize(new Dimension(500, 500));
Config.load();
algo.open();
controller.open();
about.open();
command.open();
// sizeModule();
Command.command();
image.update();
psf.update();
output.update();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bnHelp)
Lab.help();
else if (e.getSource() == bnClose)
Config.store();
- else if (e.getSource() == bnSystem)
- SystemInfo.activate();
else if (e.getSource() == bnBatch) {
tab.setSelectedIndex(2);
batch.expand();
sizeModule();
BatchDialog dlg = new BatchDialog(batch);
Lab.setVisible(dlg, true);
}
else if (e.getSource() == bnLaunch) {
String job = language.getJobName() + " " + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date());
Deconvolution d = new Deconvolution(job, Command.command(), Deconvolution.Finish.ALIVE);
d.launch();
}
else if (e.getSource() == bnRun) {
String job = language.getJobName() + " " + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date());
Deconvolution d = new Deconvolution(job, Command.command());
d.deconvolve();
}
}
@Override
public void stateChanged(ChangeEvent e) {
((GroupedModulePanel) tab.getSelectedComponent()).organize();
Command.command();
}
private ArrayList<AbstractModule> buildDeconvolutionPanel() {
ArrayList<AbstractModule> list = new ArrayList<AbstractModule>();
list.add(image);
list.add(psf);
list.add(algo);
list.add(directory);
return list;
}
private ArrayList<AbstractModule> buildAdvancedPanel() {
ArrayList<AbstractModule> list = new ArrayList<AbstractModule>();
list.add(output);
list.add(controller);
list.add(preprocessing);
- list.add(fft);
+ list.add(resources);
return list;
}
private ArrayList<AbstractModule> buildProgrammingPanel() {
ArrayList<AbstractModule> list = new ArrayList<AbstractModule>();
list.add(batch);
list.add(command);
list.add(language);
return list;
}
private ArrayList<AbstractModule> buildAboutPanel() {
ArrayList<AbstractModule> list = new ArrayList<AbstractModule>();
list.add(about);
list.add(licence);
list.add(config);
return list;
}
public void close() {
for (AbstractModule module : modules)
module.close();
bnLaunch.removeActionListener(this);
bnRun.removeActionListener(this);
bnBatch.removeActionListener(this);
bnClose.removeActionListener(this);
bnHelp.removeActionListener(this);
Lab.close();
}
public void sizeModule() {
if (tab.getSelectedIndex() == 0)
sizePanel(panelDeconv);
if (tab.getSelectedIndex() == 1)
sizePanel(panelAdvanc);
if (tab.getSelectedIndex() == 2)
sizePanel(panelScript);
if (tab.getSelectedIndex() == 3)
sizePanel(panelAbout);
}
private void sizePanel(GroupedModulePanel panel) {
Dimension dim = getSize();
int hpc = 70;
int npc = hpc * panel.getModules().size();
Dimension small = new Dimension(dim.width, hpc);
Dimension large = new Dimension(dim.width, dim.height - npc);
setMinimumSize(new Dimension(Constants.widthGUI, 4 * hpc));
for (AbstractModule module : panel.getModules()) {
if (module.isExpanded()) {
module.setPreferredSize(large);
module.setMaximumSize(large);
module.setMinimumSize(small);
module.getExpandedPanel().setPreferredSize(large);
module.getExpandedPanel().setMaximumSize(large);
module.getExpandedPanel().setMinimumSize(small);
}
else {
module.setPreferredSize(small);
module.setMaximumSize(small);
module.setMinimumSize(small);
module.getCollapsedPanel().setPreferredSize(small);
module.getCollapsedPanel().setMaximumSize(small);
module.getCollapsedPanel().setMinimumSize(small);
}
}
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/module/DirectoryModule.java b/DeconvolutionLab2/src/deconvolutionlab/module/DirectoryModule.java
index 427a986..d6afddb 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/module/DirectoryModule.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/module/DirectoryModule.java
@@ -1,248 +1,225 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolutionlab.module;
-import ij.IJ;
-
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JTextField;
import bilib.component.GridPanel;
import bilib.tools.Files;
import deconvolution.Command;
import deconvolutionlab.Config;
+import deconvolutionlab.system.SystemInfo;
public class DirectoryModule extends AbstractModule implements ActionListener, KeyListener {
private JComboBox<String> cmbPath;
private JTextField txtPath;
- private JButton bnBrowse;
-
- private JCheckBox chkSystem;
- private JCheckBox chkDisplayFinal;
+ private JButton bnBrowse;
public DirectoryModule() {
super("Path", "", "Default", "");
}
@Override
public String getCommand() {
String cmd = "";
if (cmbPath.getSelectedIndex() == 1)
cmd += "-path home ";
if (cmbPath.getSelectedIndex() == 2)
cmd += "-path desktop ";
if (cmbPath.getSelectedIndex() == 3)
cmd += " -path " + txtPath.getText();
- if (!chkSystem.isSelected())
- cmd += " -system no";
- if (!chkDisplayFinal.isSelected())
- cmd += " -display no";
return cmd;
}
@Override
public JPanel buildExpandedPanel() {
cmbPath = new JComboBox<String>(new String[] { "current", "home", "desktop", "specify ..."});
txtPath = new JTextField("", 35);
- bnBrowse = new JButton("Browse");
- chkSystem = new JCheckBox("Show the system panel");
- chkDisplayFinal = new JCheckBox("Display the final output");
+ bnBrowse = new JButton("Browse or drag anf drop a directory");
GridPanel pn1 = new GridPanel(true, 3);
pn1.place(0, 0, 3, 1, "Working directory");
pn1.place(1, 0, cmbPath);
pn1.place(1, 1, bnBrowse);
pn1.place(2, 0, 3, 1, txtPath);
pn1.place(5, 0, 3, 1, " ");
- pn1.place(6, 0, 3, 1, chkSystem);
- pn1.place(7, 0, 3, 1, chkDisplayFinal);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.add(pn1);
String dir = Files.getWorkingDirectory();
Config.register(getName(), "current", cmbPath, cmbPath.getItemAt(0));
Config.register(getName(), "path", txtPath, dir);
- Config.register(getName(), "system", chkSystem, true);
- Config.register(getName(), "display", chkDisplayFinal, true);
// Add drop area
pn1.setDropTarget(new LocalDropTarget());
txtPath.setDropTarget(new LocalDropTarget());
+ bnBrowse.setDropTarget(new LocalDropTarget());
+
getCollapsedPanel().setDropTarget(new LocalDropTarget());
bnTitle.setDropTarget(new LocalDropTarget());
bnSynopsis.setDropTarget(new LocalDropTarget());
bnExpand.setDropTarget(new LocalDropTarget());
- chkSystem.addActionListener(this);
- chkDisplayFinal.addActionListener(this);
cmbPath.addActionListener(this);
txtPath.addKeyListener(this);
bnBrowse.addActionListener(this);
getAction1Button().addActionListener(this);
return panel;
}
private void update() {
setCommand(getCommand());
if (cmbPath.getSelectedIndex() == 0) {
txtPath.setText(Files.getWorkingDirectory());
txtPath.setEnabled(false);
- bnBrowse.setEnabled(false);
}
if (cmbPath.getSelectedIndex() == 1) {
txtPath.setText(Files.getHomeDirectory());
txtPath.setEnabled(false);
- bnBrowse.setEnabled(false);
}
if (cmbPath.getSelectedIndex() == 2) {
txtPath.setText(Files.getDesktopDirectory());
txtPath.setEnabled(false);
- bnBrowse.setEnabled(false);
}
if (cmbPath.getSelectedIndex() == 3) {
txtPath.setEnabled(true);
- bnBrowse.setEnabled(true);
}
setSynopsis(new File(txtPath.getText()).getName());
Command.command();
}
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
if (e.getSource() == bnBrowse) {
File f = Files.browseDirectory(txtPath.getText());
if (f != null) {
txtPath.setText(f.getAbsolutePath());
+ cmbPath.setSelectedIndex(3);
}
}
else if (e.getSource() == cmbPath) {
if (cmbPath.getSelectedIndex() == 1) {
File f = new File(Files.getWorkingDirectory());
txtPath.setText(f.getAbsolutePath());
}
if (cmbPath.getSelectedIndex() == 2) {
File f = new File(Files.getHomeDirectory());
txtPath.setText(f.getAbsolutePath());
}
if (cmbPath.getSelectedIndex() == 3) {
File f = new File(Files.getDesktopDirectory());
txtPath.setText(f.getAbsolutePath());
}
}
else if (e.getSource() == getAction1Button()) {
cmbPath.setSelectedIndex(0);
txtPath.setText(Files.getWorkingDirectory());
txtPath.setEnabled(false);
- bnBrowse.setEnabled(false);
- chkDisplayFinal.setSelected(true);
- chkSystem.setSelected(true);
}
update();
}
@Override
public void close() {
- chkDisplayFinal.removeActionListener(this);
- chkSystem.removeActionListener(this);
cmbPath.removeActionListener(this);
txtPath.removeKeyListener(this);
bnBrowse.removeActionListener(this);
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
update();
}
public class LocalDropTarget extends DropTarget {
@Override
public void drop(DropTargetDropEvent e) {
e.acceptDrop(DnDConstants.ACTION_COPY);
e.getTransferable().getTransferDataFlavors();
Transferable transferable = e.getTransferable();
DataFlavor[] flavors = transferable.getTransferDataFlavors();
for (DataFlavor flavor : flavors) {
if (flavor.isFlavorJavaFileListType()) {
try {
List<File> files = (List<File>) transferable.getTransferData(flavor);
for (File file : files) {
- cmbPath.setSelectedIndex(1);
- bnBrowse.setEnabled(true);
+ cmbPath.setSelectedIndex(3);
txtPath.setEnabled(true);
if (file.isDirectory())
txtPath.setText(file.getAbsolutePath());
else
txtPath.setText(file.getParent());
update();
}
}
catch (UnsupportedFlavorException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}
e.dropComplete(true);
super.drop(e);
}
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/module/ImageModule.java b/DeconvolutionLab2/src/deconvolutionlab/module/ImageModule.java
index 02e47a2..9223479 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/module/ImageModule.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/module/ImageModule.java
@@ -1,360 +1,364 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolutionlab.module;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import signal.RealSignal;
import signal.factory.SignalFactory;
import bilib.table.CustomizedColumn;
import bilib.table.CustomizedTable;
import bilib.tools.Files;
import deconvolution.Command;
import deconvolution.Deconvolution;
import deconvolution.DeconvolutionDialog;
import deconvolutionlab.Config;
import deconvolutionlab.Constants;
import deconvolutionlab.Imager;
import deconvolutionlab.Lab;
import deconvolutionlab.dialog.PatternDialog;
import deconvolutionlab.dialog.SyntheticDialog;
import deconvolutionlab.monitor.Monitors;
public class ImageModule extends AbstractModule implements ActionListener, MouseListener {
private CustomizedTable table;
private JButton bnFile;
private JButton bnDirectory;
private JButton bnSynthetic;
private JButton bnPlatform;
public ImageModule() {
super("Image", "-image", (Lab.getPlatform() == Imager.Platform.IMAGEJ ? "Active" : ""), "Check");
}
@Override
public String getCommand() {
int row = table.getSelectedRow();
if (row < 0)
return "";
return "-image " + table.getCell(row, 1) + " " + table.getCell(row, 2);
}
@Override
public JPanel buildExpandedPanel() {
ArrayList<CustomizedColumn> columns = new ArrayList<CustomizedColumn>();
columns.add(new CustomizedColumn("Name", String.class, 100, false));
columns.add(new CustomizedColumn("Source", String.class, 100, false));
columns.add(new CustomizedColumn("Command", String.class, Constants.widthGUI - 200, true));
columns.add(new CustomizedColumn("", String.class, 30, "\u232B", "Delete this image source"));
table = new CustomizedTable(columns, true);
table.getColumnModel().getColumn(3).setMaxWidth(30);
table.getColumnModel().getColumn(3).setMinWidth(30);
table.addMouseListener(this);
bnFile = new JButton("\u2295 file");
bnDirectory = new JButton("\u2295 directory");
bnSynthetic = new JButton("\u2295 synthetic");
bnPlatform = new JButton("\u2295 platform");
JToolBar pn = new JToolBar("Controls Image");
pn.setBorder(BorderFactory.createEmptyBorder());
pn.setLayout(new GridLayout(1, 4));
pn.setFloatable(false);
pn.add(bnFile);
pn.add(bnDirectory);
pn.add(bnSynthetic);
if (Lab.getPlatform() == Imager.Platform.IMAGEJ)
pn.add(bnPlatform);
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEtchedBorder());
panel.setLayout(new BorderLayout());
panel.add(pn, BorderLayout.SOUTH);
panel.add(table.getMinimumPane(100, 100), BorderLayout.CENTER);
// Add drop area
table.setDropTarget(new LocalDropTarget());
getCollapsedPanel().setDropTarget(new LocalDropTarget());
bnTitle.setDropTarget(new LocalDropTarget());
bnSynopsis.setDropTarget(new LocalDropTarget());
bnExpand.setDropTarget(new LocalDropTarget());
bnFile.addActionListener(this);
bnDirectory.addActionListener(this);
bnSynthetic.addActionListener(this);
bnPlatform.addActionListener(this);
getAction1Button().addActionListener(this);
getAction2Button().addActionListener(this);
bnFile.setToolTipText("Add a new source read from a single file (3D z-stack)");
bnDirectory.setToolTipText("Add a new source read from the 2D images from a directory");
bnSynthetic.setToolTipText("Add a new source artificially created");
bnPlatform.setToolTipText("Add a new source from a list of images of the platform");
getAction2Button().setToolTipText("Click to have a preview, Shift-click or Ctrl-click to show the complete stack");
getAction1Button().setToolTipText("Select the active window from the running platform");
Config.registerTable(getName(), "image", table);
return panel;
}
public void update() {
int row = table.getSelectedRow();
if (row >= 0) {
setCommand(getCommand());
setSynopsis(table.getCell(row, 0));
Command.command();
}
else {
setSynopsis("");
setCommand("Drag your image file, here");
}
getAction2Button().setEnabled(table.getRowCount() > 0);
}
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
if (e.getSource() == bnFile)
file(Command.getPath());
else if (e.getSource() == bnDirectory)
dir(Command.getPath());
else if (e.getSource() == bnSynthetic)
synthetic(false);
else if (e.getSource() == bnPlatform)
platform();
else if (e.getSource() == getAction1Button()) {
int row = -1;
for(int i=0; i<table.getRowCount(); i++) {
if (table.getCell(i, 0).equalsIgnoreCase("active"))
if (table.getCell(i, 1).equalsIgnoreCase("platform"))
if (table.getCell(i, 2).equalsIgnoreCase("active"))
row = i;
}
if (row < 0)
table.insert(new String[] { "active", "platform", "active", "\u232B" });
else
table.setRowSelectionInterval(row, row);
}
else if (e.getSource() == getAction2Button()) {
boolean s = (e.getModifiers() & ActionEvent.SHIFT_MASK) == ActionEvent.SHIFT_MASK;
boolean c = (e.getModifiers() & ActionEvent.CTRL_MASK) == ActionEvent.CTRL_MASK;
display(s | c);
}
update();
}
public void platform() {
String name = Lab.getActiveImage();
if (name != "")
table.insert(new String[] { name, "platform", name, "\u232B" });
}
private void file(String path) {
File file = Files.browseFile(path);
if (file == null)
return;
table.insert(new String[] { file.getName(), "file", file.getAbsolutePath(), "\u232B" });
}
private void dir(String path) {
File file = Files.browseDirectory(path);
if (file == null)
return;
PatternDialog dlg = new PatternDialog(file);
Lab.setVisible(dlg, true);
if (dlg.wasCancel())
return;
table.insert(new String[] { dlg.getDirName(), "directory", dlg.getCommand(), "\u232B" });
}
private void synthetic(boolean edit) {
ArrayList<SignalFactory> list = SignalFactory.getImages();
SyntheticDialog dlg = new SyntheticDialog(list);
if (edit) {
int row = table.getSelectedRow();
if (row >= 0) {
dlg.setParameters(table.getCell(row, 0), table.getCell(row, 2));
}
}
Lab.setVisible(dlg, true);
if (dlg.wasCancel())
return;
if (edit) {
int row = table.getSelectedRow();
if (row <= 0)
table.removeRow(row);
}
table.insert(new String[] { dlg.getShapeName(), "synthetic", dlg.getCommand(), "\u232B" });
}
private void edit() {
- int row = table.getSelectedRow();
+ int row = table.getSelectedRow();
if (row < 0)
return;
- String name = table.getCell(row, 0).trim();
- for (SignalFactory factory : SignalFactory.getAll()) {
- if (name.equals(factory.getName().trim())) {
- synthetic(true);
- return;
+ String source = table.getCell(row, 1).trim().toLowerCase();
+ if (source.equals("synthetic")) {
+ String name = table.getCell(row, 0).trim();
+ for(SignalFactory factory : SignalFactory.getAll()) {
+ if (name.equals(factory.getName().trim())) {
+ synthetic(true);
+ return;
+ }
}
}
- String filename = table.getCell(row, 1).trim();
- File file = new File(filename);
- if (!file.exists())
- return;
- if (file.isFile())
- file(table.getCell(row, 21));
- else
- dir(table.getCell(row, 1));
+ else if (source.equals("directory")) {
+ dir(table.getCell(row, 2));
+ }
+ else if (source.equals("file")) {
+ file(table.getCell(row, 2));
+ }
+ else if (source.equals("platform")) {
+ platform();
+ }
}
private void display(boolean stack) {
int row = table.getSelectedRow();
if (row < 0)
return;
Deconvolution deconvolution = new Deconvolution("Check Image", Command.command());
deconvolution.openImage();
if (stack) {
RealSignal x = deconvolution.getImage();
if (x != null)
Lab.show(Monitors.createDefaultMonitor(), x, table.getCell(row, 0));
}
else {
DeconvolutionDialog d = new DeconvolutionDialog(DeconvolutionDialog.Module.IMAGE, deconvolution);
Lab.setVisible(d, false);
}
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getSource() == table) {
int row = table.getSelectedRow();
if (row < 0)
return;
if (table.getSelectedColumn() == 3) {
table.removeRow(row);
if (table.getRowCount() > 0)
table.setRowSelectionInterval(0, 0);
}
update();
if (e.getClickCount() == 2) {
edit();
}
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void close() {
bnFile.removeActionListener(this);
bnDirectory.removeActionListener(this);
bnSynthetic.removeActionListener(this);
bnPlatform.removeActionListener(this);
}
public class LocalDropTarget extends DropTarget {
@Override
public void drop(DropTargetDropEvent e) {
e.acceptDrop(DnDConstants.ACTION_COPY);
e.getTransferable().getTransferDataFlavors();
Transferable transferable = e.getTransferable();
DataFlavor[] flavors = transferable.getTransferDataFlavors();
for (DataFlavor flavor : flavors) {
if (flavor.isFlavorJavaFileListType()) {
try {
List<File> files = (List<File>) transferable.getTransferData(flavor);
for (File file : files) {
if (file.isDirectory()) {
table.insert(new String[] { file.getName(), "directory", file.getAbsolutePath(), "\u232B" });
table.setRowSelectionInterval(0, 0);
update();
}
if (file.isFile()) {
table.insert(new String[] { file.getName(), "file", file.getAbsolutePath(), "\u232B" });
update();
}
}
}
catch (UnsupportedFlavorException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}
e.dropComplete(true);
super.drop(e);
}
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/module/OutputModule.java b/DeconvolutionLab2/src/deconvolutionlab/module/OutputModule.java
index f76c4e5..cc64663 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/module/OutputModule.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/module/OutputModule.java
@@ -1,231 +1,243 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolutionlab.module;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JButton;
+import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import bilib.table.CustomizedColumn;
import bilib.table.CustomizedTable;
import deconvolution.Command;
import deconvolutionlab.Config;
import deconvolutionlab.Constants;
import deconvolutionlab.Lab;
import deconvolutionlab.dialog.OutputDialog;
import deconvolutionlab.output.Output;
import deconvolutionlab.output.Output.View;
public class OutputModule extends AbstractModule implements ActionListener, MouseListener {
private CustomizedTable table;
private JButton bnStack;
private JButton bnSeries;
private JButton bnMIP;
private JButton bnOrtho;
private JButton bnPlanar;
private JButton bnFigure;
+ private JCheckBox chkDisplayFinal;
public OutputModule() {
super("Output", "", "Clear", "");
}
@Override
public String getCommand() {
String cmd = " ";
if (table == null)
return cmd;
for (int i = 0; i < table.getRowCount(); i++) {
String[] values = new String[table.getColumnCount()];
for(int c=0; c<table.getColumnCount(); c++)
values[c] = table.getCell(i, c) == null ? "" : table.getCell(i, c).trim();
cmd += " -out " + values[0] + " " + values[1] + " " + values[2] + " " + values[3] + " " + values[4];
if (values[5].equals(""))
cmd += " noshow";
if (values[6].equals(""))
cmd += " nosave";
}
+ if (!chkDisplayFinal.isSelected())
+ cmd += " -display no";
return cmd;
}
public void update() {
setCommand(getCommand());
- setSynopsis(table.getRowCount() + " output" + (table.getRowCount() > 1 ? "s" : ""));
+ int count = table.getRowCount() + (chkDisplayFinal.isSelected() ? 1 : 0);
+ setSynopsis(count + " output" + (count > 1 ? "s" : ""));
Command.command();
- getAction1Button().setEnabled(table.getRowCount() > 0);
}
@Override
public JPanel buildExpandedPanel() {
+ chkDisplayFinal = new JCheckBox("Display the final output as 32-bit stack (default)");
+ chkDisplayFinal.setSelected(true);
String[] dynamics = { "intact", "rescaled", "normalized", "clipped" };
String[] types = { "float", "short", "byte" };
ArrayList<CustomizedColumn> columns = new ArrayList<CustomizedColumn>();
columns.add(new CustomizedColumn("Mode", String.class, 80, false));
columns.add(new CustomizedColumn("Name", String.class, Constants.widthGUI, true));
columns.add(new CustomizedColumn("Dynamic", String.class, 100, dynamics, "Select the dynamic range"));
columns.add(new CustomizedColumn("Type", String.class, 100, types, "Select the type"));
columns.add(new CustomizedColumn("Origin", String.class, 120, false));
columns.add(new CustomizedColumn("Show", String.class, 50, false));
columns.add(new CustomizedColumn("Save", String.class, 50, false));
columns.add(new CustomizedColumn("Del", String.class, 30, "\u232B", "Delete this image source"));
table = new CustomizedTable(columns, true);
table.getColumnModel().getColumn(5).setMaxWidth(50);
table.getColumnModel().getColumn(6).setMaxWidth(50);
table.getColumnModel().getColumn(7).setMaxWidth(30);
table.getColumnModel().getColumn(0).setMaxWidth(100);
table.getColumnModel().getColumn(2).setMaxWidth(100);
table.getColumnModel().getColumn(3).setMaxWidth(100);
table.addMouseListener(this);
bnStack = new JButton("\u2295 stack");
bnSeries = new JButton("\u2295 series");
bnMIP = new JButton("\u2295 mip");
bnOrtho = new JButton("\u2295 ortho");
bnPlanar = new JButton("\u2295 planar");
bnFigure = new JButton("\u2295 figure");
JToolBar pn = new JToolBar("Controls Image");
pn.setBorder(BorderFactory.createEmptyBorder());
pn.setLayout(new GridLayout(1, 6));
pn.setFloatable(false);
pn.add(bnStack);
pn.add(bnSeries);
pn.add(bnMIP);
pn.add(bnOrtho);
pn.add(bnPlanar);
pn.add(bnFigure);
-
+
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEtchedBorder());
panel.setLayout(new BorderLayout());
+ panel.add(chkDisplayFinal, BorderLayout.NORTH);
panel.add(pn, BorderLayout.SOUTH);
panel.add(table.getMinimumPane(100, 100), BorderLayout.CENTER);
bnStack.addActionListener(this);
bnSeries.addActionListener(this);
bnMIP.addActionListener(this);
bnOrtho.addActionListener(this);
bnPlanar.addActionListener(this);
- bnFigure.addActionListener(this);
+ bnFigure.addActionListener(this);
+ chkDisplayFinal.addActionListener(this);
getAction1Button().addActionListener(this);
Config.registerTable(getName(), "output", table);
+ Config.register(getName(), "display", chkDisplayFinal, true);
return panel;
}
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
View view = null;
if (e.getSource() == bnStack)
view = View.STACK;
else if (e.getSource() == bnSeries)
view = View.SERIES;
else if (e.getSource() == bnMIP)
view = View.MIP;
else if (e.getSource() == bnOrtho)
view = View.ORTHO;
else if (e.getSource() == bnPlanar)
view = View.PLANAR;
else if (e.getSource() == bnFigure)
view = View.FIGURE;
if (view != null) {
OutputDialog dlg = new OutputDialog(view);
Lab.setVisible(dlg, true);
if (dlg.wasCancel())
return;
Output out = dlg.getOut();
if (out != null)
table.insert(out.getAsString());
-
- //Lab.setVisible(new OutputPanel(view), "panel", 30, 30);
update();
}
if (e.getSource() == getAction1Button()) {
table.removeRows();
+ chkDisplayFinal.setSelected(true);
+ }
+ if (e.getSource() == chkDisplayFinal) {
+ update();
}
}
@Override
public void mouseClicked(MouseEvent e) {
int row = table.getSelectedRow();
if (table.getSelectedColumn() == 7) {
table.removeRow(row);
if (table.getRowCount() > 0)
table.setRowSelectionInterval(0, 0);
}
update();
Command.command();
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void close() {
+ chkDisplayFinal.removeActionListener(this);
bnStack.removeActionListener(this);
bnSeries.removeActionListener(this);
bnMIP.removeActionListener(this);
bnOrtho.removeActionListener(this);
bnPlanar.removeActionListener(this);
bnFigure.removeActionListener(this);
getAction1Button().removeActionListener(this);
getAction2Button().removeActionListener(this);
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/module/PSFModule.java b/DeconvolutionLab2/src/deconvolutionlab/module/PSFModule.java
index e92dbd0..e619091 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/module/PSFModule.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/module/PSFModule.java
@@ -1,350 +1,350 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolutionlab.module;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import bilib.table.CustomizedColumn;
import bilib.table.CustomizedTable;
import bilib.tools.Files;
import deconvolution.Command;
import deconvolution.Deconvolution;
import deconvolution.DeconvolutionDialog;
import deconvolutionlab.Config;
import deconvolutionlab.Constants;
import deconvolutionlab.Imager;
import deconvolutionlab.Lab;
import deconvolutionlab.dialog.PatternDialog;
import deconvolutionlab.dialog.SyntheticDialog;
import deconvolutionlab.monitor.Monitors;
import signal.RealSignal;
import signal.factory.SignalFactory;
public class PSFModule extends AbstractModule implements ActionListener, MouseListener {
private CustomizedTable table;
private JButton bnFile;
private JButton bnDirectory;
private JButton bnSynthetic;
private JButton bnPlatform;
public PSFModule() {
super("PSF", "-psf", "", "Check");
}
@Override
public String getCommand() {
int row = table.getSelectedRow();
if (row < 0)
return "";
return "-psf " + table.getCell(row, 1) + " " + table.getCell(row, 2);
}
@Override
public JPanel buildExpandedPanel() {
ArrayList<CustomizedColumn> columns = new ArrayList<CustomizedColumn>();
columns.add(new CustomizedColumn("Name", String.class, 100, false));
columns.add(new CustomizedColumn("Source", String.class, 100, false));
columns.add(new CustomizedColumn("Command", String.class, Constants.widthGUI - 200, true));
columns.add(new CustomizedColumn("", String.class, 30, "\u232B", "Delete this PSF source"));
table = new CustomizedTable(columns, true);
table.getColumnModel().getColumn(3).setMaxWidth(30);
table.getColumnModel().getColumn(3).setMinWidth(30);
table.addMouseListener(this);
bnFile = new JButton("\u2295 file");
bnDirectory = new JButton("\u2295 directory");
bnSynthetic = new JButton("\u2295 synthetic");
bnPlatform = new JButton("\u2295 platform");
JToolBar pn = new JToolBar("Controls PSF");
pn.setBorder(BorderFactory.createEmptyBorder());
pn.setLayout(new GridLayout(1, 5));
pn.setFloatable(false);
pn.add(bnFile);
pn.add(bnDirectory);
pn.add(bnSynthetic);
if (Lab.getPlatform() == Imager.Platform.IMAGEJ)
pn.add(bnPlatform);
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEtchedBorder());
panel.setLayout(new BorderLayout());
panel.add(pn, BorderLayout.SOUTH);
panel.add(table.getMinimumPane(100, 100), BorderLayout.CENTER);
// Add drop area
table.setDropTarget(new LocalDropTarget());
getCollapsedPanel().setDropTarget(new LocalDropTarget());
bnTitle.setDropTarget(new LocalDropTarget());
bnSynopsis.setDropTarget(new LocalDropTarget());
bnExpand.setDropTarget(new LocalDropTarget());
bnFile.addActionListener(this);
bnDirectory.addActionListener(this);
bnSynthetic.addActionListener(this);
bnPlatform.addActionListener(this);
getAction1Button().addActionListener(this);
getAction2Button().addActionListener(this);
bnFile.setToolTipText("Add a new source read from a single file (3D z-stack)");
bnDirectory.setToolTipText("Add a new source read from the 2D images from a directory");
bnSynthetic.setToolTipText("Add a new source artificially created");
bnPlatform.setToolTipText("Add a new source from a list of images of the platform");
-getAction2Button().setToolTipText("Click to have a preview, Shift-click or Ctrl-click to show the complete stack");
- getAction1Button().setToolTipText("Select the active window");
+ getAction2Button().setToolTipText("Click to have a preview, Shift-click or Ctrl-click to show the complete stack");
Config.registerTable(getName(), "psf", table);
return panel;
}
public void update() {
int row = table.getSelectedRow();
if (row >= 0) {
setCommand(getCommand());
setSynopsis(table.getCell(row, 0));
Command.command();
}
else {
setSynopsis("");
setCommand("Drag your image file, here");
}
getAction2Button().setEnabled(table.getRowCount() > 0);
}
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
if (e.getSource() == bnFile)
file(Command.getPath());
else if (e.getSource() == bnDirectory)
dir(Command.getPath());
else if (e.getSource() == bnSynthetic)
synthetic(false);
else if (e.getSource() == bnPlatform)
platform();
- else if (e.getSource() == getAction1Button())
- platform();
else if (e.getSource() == getAction2Button()) {
boolean s = (e.getModifiers() & ActionEvent.SHIFT_MASK) == ActionEvent.SHIFT_MASK;
boolean c = (e.getModifiers() & ActionEvent.CTRL_MASK) == ActionEvent.CTRL_MASK;
display(s | c);
}
update();
}
public void platform() {
String name = Lab.getActiveImage();
if (name != "")
table.insert(new String[] {name, "platform", name, "\u232B" });
}
private void file(String path) {
File file = Files.browseFile(path);
if (file == null)
return;
table.insert(new String[] { file.getName(), "file", file.getAbsolutePath(), "\u232B" });
}
private void dir(String path) {
File file = Files.browseDirectory(path);
if (file == null)
return;
PatternDialog dlg = new PatternDialog(file);
Lab.setVisible(dlg, true);
if (dlg.wasCancel())
return;
table.insert(new String[] { dlg.getDirName(), "directory", dlg.getCommand(), "\u232B" });
}
private void synthetic(boolean edit) {
ArrayList<SignalFactory> list = SignalFactory.getPSF();
SyntheticDialog dlg = new SyntheticDialog(list);
if (edit) {
int row = table.getSelectedRow();
if (row >= 0) {
dlg.setParameters(table.getCell(row, 0), table.getCell(row, 2));
}
}
Lab.setVisible(dlg, true);
if (dlg.wasCancel())
return;
if (edit) {
int row = table.getSelectedRow();
if (row <= 0)
table.removeRow(row);
}
- table.insert(new String[] { dlg.getShapeName(), "synthetic", dlg.getCommand(), "" });
+ table.insert(new String[] { dlg.getShapeName(), "synthetic", dlg.getCommand(), "\u232B" });
}
private void edit() {
- int row = table.getSelectedRow();
-
+ int row = table.getSelectedRow();
if (row < 0)
return;
- String name = table.getCell(row, 0).trim();
- for(SignalFactory factory : SignalFactory.getAll()) {
- if (name.equals(factory.getName().trim())) {
- synthetic(true);
- return;
+ String source = table.getCell(row, 1).trim().toLowerCase();
+ if (source.equals("synthetic")) {
+ String name = table.getCell(row, 0).trim();
+ for(SignalFactory factory : SignalFactory.getAll()) {
+ if (name.equals(factory.getName().trim())) {
+ synthetic(true);
+ return;
+ }
}
}
- String filename = table.getCell(row, 1).trim();
- File file = new File(filename);
- if (!file.exists())
- return;
- if (file.isFile())
- file(table.getCell(row, 21));
- else
- dir(table.getCell(row, 1));
+ else if (source.equals("directory")) {
+ dir(table.getCell(row, 2));
+ }
+ else if (source.equals("file")) {
+ file(table.getCell(row, 2));
+ }
+ else if (source.equals("platform")) {
+ platform();
+ }
}
private void display(boolean stack) {
int row = table.getSelectedRow();
if (row < 0)
return;
Deconvolution deconvolution = new Deconvolution("Check PSF", Command.command());
deconvolution.openPSF();
if (stack) {
RealSignal x = deconvolution.getPSF();
if (x != null)
Lab.show(Monitors.createDefaultMonitor(), x, table.getCell(row, 0));
}
else {
DeconvolutionDialog d = new DeconvolutionDialog(DeconvolutionDialog.Module.PSF, deconvolution);
Lab.setVisible(d, false);
}
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getSource() == table) {
int row = table.getSelectedRow();
if (row < 0)
return;
if (table.getSelectedColumn() == 3) {
table.removeRow(row);
if (table.getRowCount() > 0)
table.setRowSelectionInterval(0, 0);
}
update();
if (e.getClickCount() == 2) {
edit();
}
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void close() {
bnFile.removeActionListener(this);
bnDirectory.removeActionListener(this);
bnSynthetic.removeActionListener(this);
bnPlatform.removeActionListener(this);
}
public class LocalDropTarget extends DropTarget {
@Override
public void drop(DropTargetDropEvent e) {
e.acceptDrop(DnDConstants.ACTION_COPY);
e.getTransferable().getTransferDataFlavors();
Transferable transferable = e.getTransferable();
DataFlavor[] flavors = transferable.getTransferDataFlavors();
for (DataFlavor flavor : flavors) {
if (flavor.isFlavorJavaFileListType()) {
try {
List<File> files = (List<File>) transferable.getTransferData(flavor);
for (File file : files) {
if (file.isDirectory()) {
table.insert(new String[] { file.getName(), "directory", file.getAbsolutePath(), "\u232B" });
table.setRowSelectionInterval(0, 0);
update();
}
if (file.isFile()) {
table.insert(new String[] { file.getName(), "file", file.getAbsolutePath(), "\u232B" });
update();
}
}
}
catch (UnsupportedFlavorException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}
e.dropComplete(true);
super.drop(e);
}
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/module/FFTModule.java b/DeconvolutionLab2/src/deconvolutionlab/module/ResourcesModule.java
similarity index 73%
rename from DeconvolutionLab2/src/deconvolutionlab/module/FFTModule.java
rename to DeconvolutionLab2/src/deconvolutionlab/module/ResourcesModule.java
index 4020e17..f200bac 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/module/FFTModule.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/module/ResourcesModule.java
@@ -1,171 +1,163 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolutionlab.module;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.BorderFactory;
+import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToolBar;
-import bilib.component.HTMLPane;
+import bilib.component.GridPanel;
import bilib.table.CustomizedColumn;
-import bilib.table.CustomizedTable;
import deconvolution.algorithm.Algorithm;
import deconvolutionlab.Config;
import deconvolutionlab.Constants;
+import deconvolutionlab.system.SystemInfo;
import fft.AbstractFFTLibrary;
import fft.FFT;
-public class FFTModule extends AbstractModule implements ActionListener {
+public class ResourcesModule extends AbstractModule implements ActionListener {
- private CustomizedTable table;
private JComboBox<String> cmbFFT;
private JComboBox<String> cmbEpsilon;
- private HTMLPane doc;
private JComboBox<String> cmbMultithreading;
+ private JComboBox<String> cmbSystem;
- public FFTModule() {
- super("FFT", "", "Default", "");
+ public ResourcesModule() {
+ super("Resources", "", "System", "Default");
}
@Override
public String getCommand() {
String cmd = " ";
if (cmbFFT.getSelectedIndex() != 0)
cmd += " -fft " + FFT.getLibraryByName((String) cmbFFT.getSelectedItem()).getLibraryName();
if (cmbEpsilon.getSelectedIndex() != 6)
cmd += " -epsilon " + (String) cmbEpsilon.getSelectedItem();
if (cmbMultithreading.getSelectedIndex() != 0)
cmd += " -multithreading no";
+ if (cmbSystem.getSelectedIndex() != 0)
+ cmd += " -system no";
return cmd;
}
public void update() {
AbstractFFTLibrary library = FFT.getLibraryByName((String) cmbFFT.getSelectedItem());
setCommand(getCommand());
setSynopsis(library.getLibraryName());
- doc.clear();
- doc.append(library.getCredit());
- doc.append("<hr>");
- doc.append(library.getLicence());
}
@Override
public JPanel buildExpandedPanel() {
- doc = new HTMLPane(100, 1000);
cmbFFT = new JComboBox<String>(FFT.getLibrariesAsArray());
cmbEpsilon = new JComboBox<String>(new String[] { "1E-0", "1E-1", "1E-2", "1E-3", "1E-4", "1E-5", "1E-6", "1E-7", "1E-8", "1E-9", "1E-10", "1E-11", "1E-12" });
cmbEpsilon.setSelectedItem("1E-6");
cmbMultithreading = new JComboBox<String>(new String[] { "yes", "no" });
-
+ cmbSystem = new JComboBox<String>(new String[] { "yes", "no" });
+
ArrayList<CustomizedColumn> columns = new ArrayList<CustomizedColumn>();
columns.add(new CustomizedColumn("FFT Library", String.class, 100, false));
columns.add(new CustomizedColumn("Installed", String.class, 40, false));
columns.add(new CustomizedColumn("Installation", String.class, Constants.widthGUI, false));
- table = new CustomizedTable(columns, true);
- table.setRowSelectionAllowed(false);
- JToolBar tool = new JToolBar("Path");
- tool.setBorder(BorderFactory.createEmptyBorder());
- tool.setLayout(new GridLayout(3, 3));
- tool.setFloatable(false);
- tool.add(new JLabel("fft"));
- tool.add(cmbFFT);
- tool.add(new JLabel("FFT Library"));
+ GridPanel pn = new GridPanel(false, 2);
+ pn.place(0, 0, new JLabel("fft"));
+ pn.place(0, 1, cmbFFT);
+ pn.place(0, 2, new JLabel("FFT Library"));
- tool.add(new JLabel("espilon"));
- tool.add(cmbEpsilon);
- tool.add(new JLabel("Machine epsilon"));
+ pn.place(1, 0, new JLabel("espilon"));
+ pn.place(1, 1, cmbEpsilon);
+ pn.place(1, 2, new JLabel("Machine epsilon"));
- tool.add(new JLabel("multithreading"));
- tool.add(cmbMultithreading);
- tool.add(new JLabel("Activate multithreading"));
+ pn.place(2, 0, new JLabel("multithreading"));
+ pn.place(2, 1, cmbMultithreading);
+ pn.place(2, 2, new JLabel("Activate multithreading"));
+ pn.place(3, 0, new JLabel("system"));
+ pn.place(3, 1, cmbSystem);
+ pn.place(3, 2, new JLabel("Open system panel at each run"));
- JPanel pn = new JPanel();
- pn.setLayout(new BorderLayout());
- pn.add(tool, BorderLayout.NORTH);
- pn.add(table.getMinimumPane(100, 100), BorderLayout.CENTER);
-
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEtchedBorder());
panel.setLayout(new BorderLayout());
- panel.add(pn, BorderLayout.NORTH);
- panel.add(doc.getPane(), BorderLayout.CENTER);
- getAction1Button().addActionListener(this);
+ panel.add(pn, BorderLayout.CENTER);
Config.register(getName(), "fft", cmbFFT, Algorithm.getDefaultAlgorithm());
Config.register(getName(), "epsilon", cmbEpsilon, "1E-6");
Config.register(getName(), "multithreading", cmbMultithreading, cmbMultithreading.getItemAt(0));
+ Config.register(getName(), "system", cmbSystem, cmbSystem.getItemAt(0));
cmbMultithreading.addActionListener(this);
cmbFFT.addActionListener(this);
cmbEpsilon.addActionListener(this);
-
- for(AbstractFFTLibrary lib : FFT.getInstalledLibraries()) {
- String name = lib.getLibraryName();
- String i = lib.isInstalled() ? "yes" : "no";
- String loc = lib.getLocation();
- table.append(new String[]{name, i, loc});
- }
-
+ cmbSystem.addActionListener(this);
+ getAction1Button().addActionListener(this);
+ getAction2Button().addActionListener(this);
update();
return panel;
}
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
- if (e.getSource() == getAction1Button()) {
+ if (e.getSource() == getAction2Button()) {
cmbFFT.setSelectedIndex(0);;
cmbEpsilon.setSelectedItem("1E-6");
cmbMultithreading.setSelectedIndex(0);
+ cmbSystem.setSelectedIndex(0);
}
+ else if (e.getSource() == getAction1Button()) {
+ SystemInfo.activate();
+ }
+
update();
}
@Override
public void close() {
+ cmbSystem.removeActionListener(this);
cmbFFT.removeActionListener(this);
cmbEpsilon.removeActionListener(this);
cmbMultithreading.removeActionListener(this);
getAction1Button().removeActionListener(this);
+ getAction2Button().removeActionListener(this);
}
}
diff --git a/DeconvolutionLab2/src/signal/factory/complex/ComplexSignalFactory.java b/DeconvolutionLab2/src/signal/factory/complex/ComplexSignalFactory.java
index a17d6c1..7489292 100644
--- a/DeconvolutionLab2/src/signal/factory/complex/ComplexSignalFactory.java
+++ b/DeconvolutionLab2/src/signal/factory/complex/ComplexSignalFactory.java
@@ -1,222 +1,222 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package signal.factory.complex;
import signal.ComplexSignal;
public class ComplexSignalFactory {
public static ComplexSignal gaussian(int nx, int ny, int nz, double sigma) {
double K = sigma * sigma / 2.0;
int xsize = nx / 2;
int ysize = ny / 2;
int zsize = nz / 2;
float[][][] function = new float[xsize + 1][ysize + 1][zsize + 1];
double wx, wy, wz, wr;
for (int z = 0; z <= zsize; z++)
for (int y = 0; y <= ysize; y++)
for (int x = 0; x <= xsize; x++) {
- wx = Math.PI * x / xsize;
- wy = Math.PI * y / ysize;
- wz = Math.PI * z / ysize;
+ wx = (xsize > 0 ? Math.PI * x / xsize : 0);
+ wy = (ysize > 0 ? Math.PI * y / ysize : 0);
+ wz = (zsize > 0 ? Math.PI * z / zsize : 0);
wr = Math.sqrt(wx * wx + wy * wy + wz * wz);
function[x][y][z] = (float) Math.exp(-wr * wr * K);
}
return createHermitian("Gaussian", nx, ny, nz, function);
}
public static ComplexSignal identity(int nx, int ny, int nz) {
int xsize = nx / 2;
int ysize = ny / 2;
int zsize = nz / 2;
float[][][] function = new float[xsize + 1][ysize + 1][zsize + 1];
for (int z = 0; z <= zsize; z++)
for (int y = 0; y <= ysize; y++)
for (int x = 0; x <= xsize; x++)
function[x][y][z] = 1.0f;
return createHermitian("Identity", nx, ny, nz, function);
}
public static ComplexSignal laplacian(int nx, int ny, int nz) {
int xsize = nx / 2;
int ysize = ny / 2;
int zsize = nz / 2;
float[][][] function = new float[xsize + 1][ysize + 1][zsize + 1];
double wx, wy, wz;
for (int z = 0; z <= zsize; z++)
for (int y = 0; y <= ysize; y++)
for (int x = 0; x <= xsize; x++) {
- wx = Math.PI * x / xsize;
- wy = Math.PI * y / ysize;
- wz = Math.PI * z / zsize;
+ wx = (xsize > 0 ? Math.PI * x / xsize : 0);
+ wy = (ysize > 0 ? Math.PI * y / ysize : 0);
+ wz = (zsize > 0 ? Math.PI * z / zsize : 0);
function[x][y][z] = (float) ((wx * wx + wy * wy + wz * wz));
}
return createHermitian("Laplacian", nx, ny, nz, function);
}
public static ComplexSignal directionalDerivative(int nx, int ny, int nz, double vx, double vy, double vz) {
int xsize = nx / 2;
int ysize = ny / 2;
int zsize = nz / 2;
float[][][] function = new float[xsize + 1][ysize + 1][zsize + 1];
double wx, wy, wz;
for (int z = 0; z <= zsize; z++)
for (int y = 0; y <= ysize; y++)
for (int x = 0; x <= xsize; x++) {
- wx = Math.PI * x / xsize;
- wy = Math.PI * y / ysize;
- wz = Math.PI * z / zsize;
+ wx = (xsize > 0 ? Math.PI * x / xsize : 0);
+ wy = (ysize > 0 ? Math.PI * y / ysize : 0);
+ wz = (zsize > 0 ? Math.PI * z / zsize : 0);
function[x][y][z] = (float) ((wx * vx + vy * wy + vz * wz));
}
return createHermitian("Directional Derivative", nx, ny, nz, function);
}
public static ComplexSignal rings(int nx, int ny, int nz, double mu) {
int xsize = nx / 2;
int ysize = ny / 2;
int zsize = nz / 2;
double K = ysize/2;
float[][][] function = new float[xsize + 1][ysize + 1][zsize + 1];
double wx, wy, wz, wr;
for (int z = 0; z <= zsize; z++)
for (int y = 0; y <= ysize; y++)
for (int x = 0; x <= xsize; x++) {
- wx = Math.PI * x / xsize;
- wy = Math.PI * y / ysize;
- wz = Math.PI * z / ysize;
+ wx = (xsize > 0 ? Math.PI * x / xsize : 0);
+ wy = (ysize > 0 ? Math.PI * y / ysize : 0);
+ wz = (zsize > 0 ? Math.PI * z / zsize : 0);
wr = Math.sqrt(wx * wx + wy * wy + wz*wz);
function[x][y][z] =
(float) (1.0 - 1.0 / (1.0 + Math.exp(-K * (wr - mu)))
+ 1.0 / (1.0 + Math.exp(-K * (wr - 0.6 * mu)))
- 1.0 / (1.0 + Math.exp(-K * (wr - 0.4 * mu))));
}
return createHermitian("Airy", nx, ny, nz, function);
}
public static ComplexSignal createHermitian(String name, int nx, int ny, int nz, float[][][] firstQuadrantReal, float[][][] firstQuadrantImag) {
ComplexSignal signal = new ComplexSignal(name, nx, ny, nz);
int xsize = firstQuadrantReal.length - 1;
int ysize = firstQuadrantReal[0].length - 1;
int zsize = firstQuadrantReal[0][0].length - 1;
if (xsize >= 1 && ysize >= 1 && zsize >= 1) {
for (int z = 0; z <= zsize; z++)
for (int y = 0; y <= ysize; y++)
for (int x = 0; x <= xsize; x++) {
signal.data[z][2 * (x + nx * y)] = firstQuadrantReal[x][y][z];
signal.data[z][2 * (x + nx * y)+1] = firstQuadrantImag[x][y][z];
}
for (int z = 0; z < zsize; z++)
for (int y = 0; y < ysize; y++)
for (int x = 0; x < xsize; x++) {
int a = nx - 1 - x;
int b = nx * (ny - 1 - y);
signal.data[z][2 * (a + nx * y)] = firstQuadrantReal[x + 1][y][z];
signal.data[z][2 * (a + b)] = firstQuadrantReal[x + 1][y + 1][z];
signal.data[z][2 * (x + b)] = firstQuadrantReal[x][y + 1][z];
signal.data[z][1 + 2 * (a + nx * y)] = firstQuadrantImag[x + 1][y][z];
signal.data[z][1 + 2 * (a + b)] = firstQuadrantImag[x + 1][y + 1][z];
signal.data[z][1 + 2 * (x + b)] = firstQuadrantImag[x][y + 1][z];
int c = nz - 1 - z;
signal.data[c][2 * (x + nx * y)] = firstQuadrantReal[x][y][z + 1];
signal.data[c][2 * (a + nx * y)] = firstQuadrantReal[x + 1][y][z + 1];
signal.data[c][2 * (a + b)] = firstQuadrantReal[x + 1][y + 1][z + 1];
signal.data[c][2 * (x + b)] = firstQuadrantReal[x][y + 1][z + 1];
signal.data[c][1 + 2 * (x + nx * y)] = firstQuadrantImag[x][y][z + 1];
signal.data[c][1 + 2 * (a + nx * y)] = firstQuadrantImag[x + 1][y][z + 1];
signal.data[c][1 + 2 * (a + b)] = firstQuadrantImag[x + 1][y + 1][z + 1];
signal.data[c][1 + 2 * (x + b)] = firstQuadrantImag[x][y + 1][z + 1];
}
}
if (zsize == 0) {
for (int y = 0; y <= ysize; y++)
for (int x = 0; x <= xsize; x++) {
signal.data[0][2 * (x + nx * y)] = firstQuadrantReal[x][y][0];
signal.data[0][1 + 2 * (x + nx * y)] = firstQuadrantImag[x][y][0];
}
for (int y = 0; y < ysize; y++)
for (int x = 0; x < xsize; x++) {
int a = nx - 1 - x;
int b = nx * (ny - 1 - y);
signal.data[0][2 * (a + nx * y)] = firstQuadrantReal[x + 1][y][0];
signal.data[0][2 * (a + b)] = firstQuadrantReal[x + 1][y + 1][0];
signal.data[0][2 * (x + b)] = firstQuadrantReal[x][y + 1][0];
signal.data[0][1 + 2 * (a + nx * y)] = firstQuadrantImag[x + 1][y][0];
signal.data[0][1 + 2 * (a + b)] = firstQuadrantImag[x + 1][y + 1][0];
signal.data[0][1 + 2 * (x + b)] = firstQuadrantImag[x][y + 1][0];
}
}
return signal;
}
public static ComplexSignal createHermitian(String name, int nx, int ny, int nz, float[][][] firstQuadrant) {
ComplexSignal signal = new ComplexSignal(name, nx, ny, nz);
int xsize = firstQuadrant.length - 1;
int ysize = firstQuadrant[0].length - 1;
int zsize = firstQuadrant[0][0].length - 1;
if (xsize >= 1 && ysize >= 1 && zsize >= 1) {
for (int z = 0; z <= zsize; z++)
for (int y = 0; y <= ysize; y++)
for (int x = 0; x <= xsize; x++) {
signal.data[z][2 * (x + nx * y)] = firstQuadrant[x][y][z];
}
for (int z = 0; z < zsize; z++)
for (int y = 0; y < ysize; y++)
for (int x = 0; x < xsize; x++) {
int a = nx - 1 - x;
int b = nx * (ny - 1 - y);
signal.data[z][2 * (a + nx * y)] = firstQuadrant[x + 1][y][z];
signal.data[z][2 * (a + b)] = firstQuadrant[x + 1][y + 1][z];
signal.data[z][2 * (x + b)] = firstQuadrant[x][y + 1][z];
int c = nz - 1 - z;
signal.data[c][2 * (x + nx * y)] = firstQuadrant[x][y][z + 1];
signal.data[c][2 * (a + nx * y)] = firstQuadrant[x + 1][y][z + 1];
signal.data[c][2 * (a + b)] = firstQuadrant[x + 1][y + 1][z + 1];
signal.data[c][2 * (x + b)] = firstQuadrant[x][y + 1][z + 1];
}
}
if (zsize == 0) {
for (int y = 0; y <= ysize; y++)
for (int x = 0; x <= xsize; x++) {
signal.data[0][2 * (x + nx * y)] = firstQuadrant[x][y][0];
}
for (int y = 0; y < ysize; y++)
for (int x = 0; x < xsize; x++) {
int a = nx - 1 - x;
int b = nx * (ny - 1 - y);
signal.data[0][2 * (a + nx * y)] = firstQuadrant[x + 1][y][0];
signal.data[0][2 * (a + b)] = firstQuadrant[x + 1][y + 1][0];
signal.data[0][2 * (x + b)] = firstQuadrant[x][y + 1][0];
}
}
return signal;
}
}
Event Timeline
Log In to Comment