Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92974096
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
Mon, Nov 25, 07:03
Size
76 KB
Mime Type
application/octet-stream
Expires
Wed, Nov 27, 07:03 (2 d)
Engine
blob
Format
Raw Data
Handle
22550518
Attached To
R2075 deconvolution
View Options
diff --git a/DeconvolutionLab2/DeconvolutionLab2.config b/DeconvolutionLab2/DeconvolutionLab2.config
index 48b59a1..728fdc7 100644
--- a/DeconvolutionLab2/DeconvolutionLab2.config
+++ b/DeconvolutionLab2/DeconvolutionLab2.config
@@ -1,82 +1,82 @@
#DeconvolutionLab2 [Beta 1]
#DeconvolutionLab2 [Beta 1]
-#Fri Feb 03 08:33:07 CET 2017
+#Fri Feb 03 09:17:03 CET 2017
Algorithm.FISTA.iterations=10
Algorithm.FISTA.reg=0.1
Algorithm.FISTA.scale=3
Algorithm.FISTA.step=1.0
Algorithm.FISTA.wavelets=Haar
Algorithm.ICTM.iterations=10
Algorithm.ICTM.reg=0.1
Algorithm.ICTM.step=1.0
Algorithm.ISTA.iterations=10
Algorithm.ISTA.reg=0.1
Algorithm.ISTA.scale=3
Algorithm.ISTA.step=1.0
Algorithm.ISTA.wavelets=Haar
Algorithm.LW+.iterations=10
Algorithm.LW+.step=1.0
Algorithm.LW.iterations=10
Algorithm.LW.step=1.0
Algorithm.RIF.reg=0.1
Algorithm.RL.iterations=10
Algorithm.RLTV.reg=0.1
Algorithm.SIM.gaussian.mean=0.0
Algorithm.SIM.gaussian.stdev=1.0
Algorithm.SIM.poisson=0.0
Algorithm.TM.iterations=10
Algorithm.TM.reg=0.1
Algorithm.TM.step=1.0
Algorithm.TRIF.reg=0.1
Algorithm.VC.iterations=10
Algorithm.VC.step=1.0
Algorithm.algorithm=Landweber
Border.apoxy=Uniform
Border.apoz=Uniform
Border.extxy=0
Border.extz=0
Border.normalization=1
Border.padxy=None
Border.padz=None
Controller.constraint.enable=false
Controller.constraint.snapshot=1
Controller.constraint.value=No
Controller.reference.enable=false
Controller.reference.snapshot=1
Controller.reference.value=
Controller.residu.enable=false
Controller.residu.snapshot=1
Controller.residu.value=0.01
Controller.savestats.enable=false
Controller.savestats.snapshot=1
Controller.savestats.value=Stats
Controller.showstats.enable=false
Controller.showstats.snapshot=1
Controller.showstats.value=Stats
DeconvolutionLab.MainDialog.location.h=579
DeconvolutionLab.MainDialog.location.w=573
DeconvolutionLab.MainDialog.location.x=124
DeconvolutionLab.MainDialog.location.y=52
Fourier.dim=XYZ
Fourier.epsilon=1E-6
Fourier.fft=Academic
Image.image.row0=Cube;synthetic;Cube 100.0 0.0 10.0 1.0 size 128 128 32 ;null
Image.image.row1=resolution;directory;/Users/dsage/Desktop/DeconvolutionLab2-Course/resolution;null
Image.image.selected=Cube;synthetic;Cube 100.0 0.0 10.0 1.0 size 128 128 32 ;null
Language.headless=Run (Headless)
Language.job=Job
Language.language=ImageJ Macro
Output.output.row0=mip @1;MI1;;;;\u2713;null;null
Output.output.selected=mip @1;MI1;;;;\u2713;null;null
-PSF.psf.row0=MotionBlur;synthetic;MotionBlur 100.0 0.0 3.0 30.0 3.0 size 128 128 32 ;
+PSF.psf.row0=MotionBlur2D;synthetic;MotionBlur2D 100.0 0.0 3.0 3.0 3.0 size 128 128 32 ;
PSF.psf.row1=Airy;synthetic;Airy 100.0 0.0 1.0 size 128 128 32 ;null
PSF.psf.row2=Defocus;synthetic;Defocus 100.0 0.0 3.0 10.0 10.0 size 3 3 100 ;null
-PSF.psf.selected=MotionBlur;synthetic;MotionBlur 100.0 0.0 3.0 30.0 3.0 size 128 128 32 ;
+PSF.psf.selected=MotionBlur2D;synthetic;MotionBlur2D 100.0 0.0 3.0 3.0 3.0 size 128 128 32 ;
Watcher.disable.console=false
Watcher.disable.display=false
Watcher.disable.multithreading=false
Watcher.disable.table=false
Watcher.path=/Users/dsage/git/deconvolution/DeconvolutionLab2
Watcher.time.value=3600
Watcher.time=No time limitation
Watcher.verbose=Verbose\: log
diff --git a/DeconvolutionLab2/src/DeconvolutionLab2_FFT.java b/DeconvolutionLab2/src/DeconvolutionLab2_FFT.java
index ccf0775..1a86876 100644
--- a/DeconvolutionLab2/src/DeconvolutionLab2_FFT.java
+++ b/DeconvolutionLab2/src/DeconvolutionLab2_FFT.java
@@ -1,17 +1,13 @@
-import java.io.File;
-
-import deconvolutionlab.Config;
import deconvolutionlab.Lab;
import deconvolutionlab.Platform;
import deconvolutionlab.monitor.Monitors;
-import ij.IJ;
import ij.plugin.PlugIn;
public class DeconvolutionLab2_FFT implements PlugIn {
@Override
public void run(String arg) {
Lab.getInstance(Platform.IMAGEJ);
Lab.checkFFT(Monitors.createDefaultMonitor());
}
}
diff --git a/DeconvolutionLab2/src/DeconvolutionLab2_Lab.java b/DeconvolutionLab2/src/DeconvolutionLab2_Lab.java
new file mode 100644
index 0000000..e7ba40f
--- /dev/null
+++ b/DeconvolutionLab2/src/DeconvolutionLab2_Lab.java
@@ -0,0 +1,19 @@
+import java.io.File;
+
+import deconvolutionlab.Config;
+import deconvolutionlab.Lab;
+import deconvolutionlab.Platform;
+import deconvolutionlab.dialog.LabDialog;
+import ij.IJ;
+import ij.plugin.PlugIn;
+
+public class DeconvolutionLab2_Lab implements PlugIn {
+
+ @Override
+ public void run(String arg) {
+ Lab.getInstance(Platform.IMAGEJ);
+ String config = IJ.getDirectory("plugins") + File.separator + "DeconvolutionLab2.config";
+ Config.getInstance(config);
+ new LabDialog().setVisible(true);
+ }
+}
diff --git a/DeconvolutionLab2/src/deconvolution/Deconvolution.java b/DeconvolutionLab2/src/deconvolution/Deconvolution.java
index bf4cf98..7ebf639 100644
--- a/DeconvolutionLab2/src/deconvolution/Deconvolution.java
+++ b/DeconvolutionLab2/src/deconvolution/Deconvolution.java
@@ -1,667 +1,662 @@
/*
* 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.io.File;
import java.util.ArrayList;
import javax.swing.JFrame;
import deconvolution.algorithm.AbstractAlgorithm;
import deconvolution.algorithm.Controller;
import deconvolutionlab.Lab;
import deconvolutionlab.Output;
import deconvolutionlab.OutputCollection;
import deconvolutionlab.monitor.AbstractMonitor;
import deconvolutionlab.monitor.ConsoleMonitor;
import deconvolutionlab.monitor.Monitors;
import deconvolutionlab.monitor.TableMonitor;
import deconvolutionlab.monitor.Verbose;
import fft.AbstractFFT;
import fft.AbstractFFTLibrary;
import fft.FFT;
import lab.tools.NumFormat;
import signal.RealSignal;
import signal.apodization.AbstractApodization;
import signal.apodization.Apodization;
import signal.apodization.UniformApodization;
import signal.factory.SignalFactory;
import signal.padding.Padding;
public class Deconvolution implements Runnable {
private AbstractAlgorithm algo = null;
private String path;
private Monitors monitors = Monitors.createDefaultMonitor();
private Verbose verbose = Verbose.Log;
private Controller controller;
private OutputCollection outs;
private Padding padding = new Padding();
private Apodization apodization = new Apodization();
private double factorNormalization = 1.0;
private AbstractFFTLibrary fftlib;
private String command = "";
private boolean live = false;
private ArrayList<String> report = new ArrayList<String>();
private String name = "";
private boolean exit = false;
private boolean watcherMonitor = true;
private boolean watcherConsole = true;
private boolean watcherDisplay = true;
private boolean watcherMultithreading = true;
private ArrayList<DeconvolutionListener> listeners = new ArrayList<DeconvolutionListener>();
public Deconvolution(String command) {
super();
monitors = Monitors.createDefaultMonitor();
this.command = command;
decode();
}
public void setCommand(String command) {
this.command = command;
decode();
}
public String getCommand() {
return command;
}
public Monitors getMonitors() {
if (monitors == null)
return Monitors.createDefaultMonitor();
return monitors;
}
/**
* This method runs the deconvolution without graphical user interface.
*
* @param exit
* System.exit call is true
*/
public void deconvolve(boolean exit) {
this.exit = exit;
monitors = new Monitors();
if (watcherConsole)
monitors.add(new ConsoleMonitor());
if (watcherMonitor) {
TableMonitor m = new TableMonitor(440, 440);
monitors.add(m);
String t = algo == null ? "Monitor " + name : name + " " + algo.getName();
JFrame frame = new JFrame(t);
frame.add(m.getPanel());
frame.pack();
frame.setVisible(true);
}
if (fftlib == null) {
run();
return;
}
if (!fftlib.isMultithreadable()) {
run();
return;
}
if (watcherMultithreading) {
Thread thread = new Thread(this);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
else {
run();
}
}
/**
* This method runs the deconvolution with a graphical user interface.
*
* @param job
* Name of the job of deconvolution
* @param exit
* System.exit call is true
*/
public void launch(String job, boolean exit) {
this.name = job;
this.exit = exit;
DeconvolutionDialog d = new DeconvolutionDialog(this);
monitors = new Monitors();
if (watcherConsole)
monitors.add(new ConsoleMonitor());
if (watcherMonitor) {
TableMonitor m = new TableMonitor(440, 440);
monitors.add(m);
d.addTableMonitor("Monitor", m);
}
}
public void decode() {
algo = null;
path = System.getProperty("user.dir");
if (monitors==null)
monitors = Monitors.createDefaultMonitor();
verbose = Verbose.Log;
controller = new Controller();
outs = new OutputCollection();
padding = new Padding();
apodization = new Apodization();
factorNormalization = 1.0;
fftlib = FFT.getLibraryByName("Academic");
live = false;
ArrayList<Token> tokens = Command.parse(command);
for (Token token : tokens) {
if (token.keyword.equalsIgnoreCase("-algorithm"))
algo = Command.decodeAlgorithm(token, controller);
if (token.keyword.equalsIgnoreCase("-disable")) {
watcherMonitor = Command.decodeDisable(token, "monitor");
watcherConsole = Command.decodeDisable(token, "console");
watcherDisplay = Command.decodeDisable(token, "display");
watcherMultithreading = Command.decodeDisable(token, "multithreading");
}
if (token.keyword.equalsIgnoreCase("-verbose"))
verbose = Verbose.getByName(token.parameters);
if (token.keyword.equalsIgnoreCase("-path") && !token.parameters.equalsIgnoreCase("current")) {
path = token.parameters;
}
if (token.keyword.equalsIgnoreCase("-fft"))
fftlib = FFT.getLibraryByName(token.parameters);
if (token.keyword.equalsIgnoreCase("-pad"))
padding = Command.decodePadding(token);
if (token.keyword.equalsIgnoreCase("-apo"))
apodization = Command.decodeApodization(token);
if (token.keyword.equalsIgnoreCase("-norm"))
factorNormalization = Command.decodeNormalization(token);
if (token.keyword.equalsIgnoreCase("-constraint"))
Command.decodeController(token, controller);
if (token.keyword.equalsIgnoreCase("-time"))
Command.decodeController(token, controller);
if (token.keyword.equalsIgnoreCase("-residu"))
Command.decodeController(token, controller);
if (token.keyword.equalsIgnoreCase("-reference"))
Command.decodeController(token, controller);
if (token.keyword.equalsIgnoreCase("-savestats"))
Command.decodeController(token, controller);
if (token.keyword.equalsIgnoreCase("-showstats"))
Command.decodeController(token, controller);
if (token.keyword.equals("-out")) {
Output out = Command.decodeOut(token);
if (out != null)
outs.add(out);
}
}
if (name.equals("") && algo != null)
name = algo.getShortname();
}
public void setApodization(ArrayList<AbstractApodization> apos) {
AbstractApodization apoXY = new UniformApodization();
AbstractApodization apoZ = new UniformApodization();
if (apos.size() >= 1)
apoXY = apos.get(0);
if (apos.size() >= 2)
apoZ = apos.get(1);
this.apodization = new Apodization(apoXY, apoXY, apoZ);
}
@Override
public void run() {
double chrono = System.nanoTime();
for(DeconvolutionListener listener : listeners)
listener.started();
live = true;
if (monitors != null)
monitors.setVerbose(verbose);
report.add("Path: " + checkPath(path));
monitors.log("Path: " + checkPath(path));
RealSignal image = openImage();
if (image == null) {
monitors.error("Image: Not valid " + command);
report.add("Image: Not valid");
if (exit)
System.exit(-101);
return;
}
report.add("Image: " + image.dimAsString());
monitors.log("Image: " + image.nx + " x " + image.ny + " x " + image.nz);
RealSignal y = padding.pad(monitors, getApodization().apodize(monitors, image));
RealSignal psf = openPSF();
if (psf == null) {
monitors.error("PSF: not valid");
report.add("PSF: Not valid");
if (exit)
System.exit(-102);
return;
}
report.add("PSF: " + psf.dimAsString());
monitors.log("PSF: " + psf.nx + " x " + psf.ny + " x " + psf.nz);
monitors.log("PSF: normalization " + (factorNormalization <= 0 ? "no" : factorNormalization));
RealSignal h = psf.changeSizeAs(y).normalize(factorNormalization);
if (algo == null) {
monitors.error("Algorithm: not valid");
if (exit)
System.exit(-103);
return;
}
if (controller == null) {
monitors.error("Controller: not valid");
if (exit)
System.exit(-104);
return;
}
AbstractFFT fft;
if (fftlib != null)
fft = FFT.createFFT(monitors, fftlib, image.nx, image.ny, image.nz);
else
fft = FFT.createDefaultFFT(monitors, image.nx, image.ny, image.nz);
report.add("FFT: " + fft.getName());
algo.setFFT(fft);
controller.setFFT(fft);
algo.setController(controller);
if (outs != null) {
outs.setPath(path);
controller.setOutputs(outs);
}
monitors.log("Algorithm: " + algo.getName());
report.add("Algorithm: " + algo.getName());
RealSignal x = algo.run(monitors, y, h, true);
RealSignal result = padding.crop(monitors, x);
if (outs != null)
outs.executeFinal(monitors, result, controller);
live = false;
for(DeconvolutionListener listener : listeners)
listener.finish();
report.add("End " + algo.getName() + " in " + NumFormat.time(System.nanoTime()-chrono));
if (watcherDisplay)
Lab.show(monitors, result, "Result of " + algo.getShortname());
if (exit) {
System.out.println("End");
System.exit(0);
}
}
/**
* This methods make a recap of the deconvolution. Useful before starting the processing.
*
* @return list of messages to print
*/
public ArrayList<String> recap() {
ArrayList<String> lines = new ArrayList<String>();
Token image = Command.extract(command, "-image");
if (image == null)
lines.add("<b>Image</b>: <span color=\"red\">keyword -image not found</span>");
else
lines.add("<b>Image</b>: " + image.parameters);
String norm = (factorNormalization < 0 ? " (no normalization)" : " (normalization to " + factorNormalization + ")");
Token psf = Command.extract(command, "-psf");
if (psf == null)
lines.add("<b>PSF</b>: <span color=\"red\">keyword -psf not found</span>");
else
lines.add("<b>PSF</b>: " + psf.parameters + norm);
if (algo == null) {
lines.add("<b>Algorithm</b>: <span color=\"red\">not valid</span>");
}
else {
Controller controller = algo.getController();
String con = ", " + controller.getConstraintAsString() + " constraint";
lines.add("<b>Algorithm</b>: " + algo.toString() + con);
lines.add("<b>Stopping Criteria</b>: " + controller.getStoppingCriteria(algo));
lines.add("<b>Reference</b>: " + controller.getReference());
lines.add("<b>Stats</b>: " + controller.getShowStats() + " " + controller.getSaveStats());
lines.add("<b>Padding</b>: " + padding.toString());
lines.add("<b>Apodization</b>: " + apodization.toString());
if (algo.getFFT() != null)
lines.add("<b>FFT</b>: " + algo.getFFT().getName());
}
lines.add("<b>Path</b>: " + path);
- String m = "";
- if (monitors != null) {
- for (AbstractMonitor monitor : monitors)
- m += monitor.getName() + " ";
- }
lines.add("<b>Verbose</b>: " + verbose.name().toLowerCase());
lines.add("<b>Monitor</b>: " + (watcherMonitor ? "on" : "off"));
lines.add("<b>Console</b>: " + (watcherConsole ? "on" : "off"));
lines.add("<b>Final Display</b>: " + (watcherDisplay ? "on" : "off"));
lines.add("<b>Multithreading</b>: " + (watcherMultithreading ? "on" : "off"));
if (outs == null)
lines.add("<b>Outputs</b>: not valid");
else
lines.addAll(outs.getInformation());
return lines;
}
public ArrayList<String> checkAlgo() {
ArrayList<String> lines = new ArrayList<String>();
RealSignal image = openImage();
if (image == null) {
lines.add("No valid input image");
return lines;
}
if (padding == null) {
lines.add("No valid padding");
return lines;
}
if (apodization == null) {
lines.add("No valid apodization");
return lines;
}
RealSignal psf = openPSF();
if (psf == null) {
lines.add("No valid PSF");
return lines;
}
if (algo == null) {
lines.add("No valid algorithm");
return lines;
}
Controller controller = algo.getController();
RealSignal y = padding.pad(monitors, getApodization().apodize(monitors, image));
RealSignal h = psf.changeSizeAs(y).normalize(factorNormalization);
int iter = controller.getIterationMax();
algo.getController().setIterationMax(1);
RealSignal x = algo.run(monitors, y, h, true);
Lab.show(monitors, x, "Estimate after 1 iteration");
lines.add("Time: " + NumFormat.seconds(controller.getTimeNano()));
lines.add("Peak Memory: " + controller.getMemoryAsString());
controller.setIterationMax(iter);
return lines;
}
public ArrayList<String> checkImage() {
ArrayList<String> lines = new ArrayList<String>();
RealSignal image = openImage();
if (image == null) {
lines.add("No valid input image");
return lines;
}
if (padding == null) {
lines.add("No valid padding");
return lines;
}
if (apodization == null) {
lines.add("No valid apodization");
return lines;
}
RealSignal signal = padding.pad(monitors, getApodization().apodize(monitors, image));
lines.add("<b>Image</b>");
lines.add("Original size " + image.dimAsString() + " padded to " + signal.dimAsString());
lines.add("Original: " + formatStats(image));
lines.add("Preprocessing: " + formatStats(signal));
Lab.show(monitors, signal, "Image");
return lines;
}
public ArrayList<String> checkPSF() {
ArrayList<String> lines = new ArrayList<String>();
RealSignal image = openImage();
if (image == null) {
lines.add("No valid input image");
return lines;
}
if (padding == null) {
lines.add("No valid padding");
return lines;
}
if (apodization == null) {
lines.add("No valid apodization");
return lines;
}
RealSignal psf = openPSF();
if (psf == null) {
lines.add("No valid PSF");
return lines;
}
RealSignal signal = padding.pad(monitors, getApodization().apodize(monitors, image));
RealSignal h = psf.changeSizeAs(signal);
lines.add("<b>PSF</b>");
lines.add("Original size " + psf.dimAsString() + " padded to " + h.dimAsString());
String e = NumFormat.nice(h.getEnergy());
h.normalize(factorNormalization);
lines.add("Original: " + formatStats(psf));
lines.add("Preprocessing: " + formatStats(h));
lines.add("Energy = " + e + " and after normalization=" + NumFormat.nice(h.getEnergy()));
Lab.show(monitors, h, "Padded and Normalized PSF");
return lines;
}
public ArrayList<String> getDeconvolutionReports() {
return report;
}
public String getName() {
return name;
}
public boolean isLive() {
return live;
}
public void abort() {
live = false;
algo.getController().abort();
}
public Padding getPadding1() {
return padding;
}
public Apodization getApodization() {
return apodization;
}
public OutputCollection getOuts() {
return outs;
}
public AbstractAlgorithm getAlgo() {
return algo;
}
public String getPath() {
return path;
}
public String checkPath(String path) {
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)";
}
}
public RealSignal openImage() {
Token token = Command.extract(command, "-image");
if (token == null)
return null;
if (token.parameters.startsWith(">>>"))
return null;
return getImage(monitors, token);
}
public RealSignal openPSF() {
Token token = Command.extract(command, "-psf");
if (token == null)
return null;
if (token.parameters.startsWith(">>>"))
return null;
return getImage(monitors, token);
}
private RealSignal getImage(Monitors monitors, Token token) {
String arg = token.option.trim();
String cmd = token.parameters.substring(arg.length(), token.parameters.length()).trim();
if (arg.equalsIgnoreCase("synthetic")) {
String parts[] = cmd.split(" ");
if (parts.length <= 0)
return null;
String shape = parts[0];
for (String name : SignalFactory.getAllName()) {
if (shape.equalsIgnoreCase(name.toLowerCase())) {
double params[] = Command.parseNumeric(cmd);
SignalFactory factory = SignalFactory.getFactoryByName(shape);
if (factory == null)
return null;
double amplitude = params.length > 0 ? params[0] : 1;
double background = params.length > 1 ? params[1] : 0;
factory.intensity(background, amplitude);
int np = factory.getParameters().length;
double[] features = new double[np];
for (int i = 0; i < Math.min(np, params.length); i++)
features[i] = params[i + 2];
factory.setParameters(features);
int nx = params.length > np + 2 ? (int) Math.round(params[np + 2]) : 128;
int ny = params.length > np + 3 ? (int) Math.round(params[np + 3]) : 128;
int nz = params.length > np + 4 ? (int) Math.round(params[np + 4]) : 128;
double cx = params.length > np + 5 ? params[np + 5] : 0.5;
double cy = params.length > np + 6 ? params[np + 6] : 0.5;
double cz = params.length > np + 7 ? params[np + 7] : 0.5;
factory = factory.center(cx, cy, cz);
RealSignal x = factory.generate(nx, ny, nz);
return x;
}
}
}
if (arg.equalsIgnoreCase("file") || arg.equalsIgnoreCase("dir") || arg.equalsIgnoreCase("directory")) {
RealSignal signal = null;
File file = new File(path + File.separator + cmd);
if (file != null) {
if (file.isFile())
signal = Lab.open(monitors, path + File.separator + cmd);
if (file.isDirectory())
signal = Lab.openDir(monitors, path + File.separator + cmd);
}
if (signal == null) {
File local = new File(cmd);
if (local != null) {
if (local.isFile())
signal = Lab.open(monitors, cmd);
if (local.isDirectory())
signal = Lab.openDir(monitors, cmd);
}
}
return signal;
}
if (arg.equalsIgnoreCase("platform")) {
return Lab.getImager().create(cmd);
}
return null;
}
private static String formatStats(RealSignal x) {
float stats[] = x.getStats();
String s = " mean=" + NumFormat.nice(stats[0]);
s += " stdev=" + NumFormat.nice(stats[1]);
s += " min=" + NumFormat.nice(stats[3]);
s += " max=" + NumFormat.nice(stats[2]);
return s;
}
public void addDeconvolutionListener(DeconvolutionListener listener) {
listeners.add(listener);
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/LabImager.java b/DeconvolutionLab2/src/deconvolutionlab/LabImager.java
index 2667f60..4d6702a 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/LabImager.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/LabImager.java
@@ -1,214 +1,218 @@
/*
* 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 ij.ImagePlus;
import ij.ImageStack;
import ij.WindowManager;
import ij.io.FileSaver;
import ij.io.Opener;
import ij.process.FloatProcessor;
import ij.process.ImageProcessor;
import signal.ComplexComponent;
import signal.ComplexSignal;
import signal.RealSignal;
public class LabImager extends PlatformImager {
public static RealSignal create(ImagePlus imp) {
int nx = imp.getWidth();
int ny = imp.getHeight();
int nz = imp.getStackSize();
RealSignal signal = new RealSignal(nx, ny, nz);
for (int k = 0; k < nz; k++) {
ImageProcessor ip = imp.getStack().getProcessor(k + 1).convertToFloat();
signal.setXY(k, (float[]) ip.getPixels());
}
return signal;
}
@Override
public RealSignal create() {
return build(WindowManager.getCurrentImage());
}
@Override
public RealSignal create(String name) {
- ImagePlus imp = WindowManager.getImage(name);
+ ImagePlus imp = null;
+ if (name.equalsIgnoreCase("active"))
+ imp = WindowManager.getCurrentImage();
+ else
+ imp = WindowManager.getImage(name);
if (imp == null)
imp = WindowManager.getCurrentImage();
return build(imp);
}
@Override
public RealSignal open(String filename) {
Opener opener = new Opener();
ImagePlus imp = opener.openImage(filename);
return build(imp);
}
@Override
public void show(RealSignal signal, String title) {
show(signal, title, PlatformImager.Type.FLOAT);
}
@Override
public void show(RealSignal signal, String title, PlatformImager.Type type) {
show(signal, title, type, signal.nz / 2);
}
@Override
public void show(RealSignal signal, String title, PlatformImager.Type type, int z) {
ImagePlus imp = build(signal, type);
if (imp != null) {
imp.setTitle(title);
int nz = imp.getStackSize();
imp.show();
imp.setSlice(Math.max(1, Math.min(nz, z)));
imp.getProcessor().resetMinAndMax();
}
}
public ContainerImage createContainer(String title) {
return new ContainerImage();
}
@Override
public void append(ContainerImage container, RealSignal signal, String title) {
append(container, signal, title, PlatformImager.Type.FLOAT);
}
@Override
public void append(ContainerImage container, RealSignal signal, String title, PlatformImager.Type type) { ImagePlus cont = (ImagePlus) container.object;
if (container.object == null) {
ImageStack stack = new ImageStack(signal.nx, signal.ny);
stack.addSlice(build(signal, type).getProcessor());
stack.addSlice(build(signal, type).getProcessor());
container.object = new ImagePlus(title, stack);
((ImagePlus)container.object).show();
}
else {
cont.getStack().addSlice(build(signal, type).getProcessor());
cont.setSlice(cont.getStack().getSize());
cont.updateAndDraw();
cont.getProcessor().resetMinAndMax();
}
}
@Override
public void save(RealSignal signal, String filename) {
save(signal, filename, PlatformImager.Type.FLOAT);
}
@Override
public void save(RealSignal signal, String filename, PlatformImager.Type type) {
ImagePlus imp = build(signal, type);
if (imp != null) {
if (imp.getStackSize() == 1) {
new FileSaver(imp).saveAsTiff(filename);
}
else {
new FileSaver(imp).saveAsTiffStack(filename);
}
}
}
@Override
public void show(ComplexSignal signal, String title) {
show(signal, title, ComplexComponent.MODULE);
}
@Override
public void show(ComplexSignal signal, String title, ComplexComponent complex) {
ImageStack stack = new ImageStack(signal.nx, signal.ny);
for (int k = 0; k < signal.nz; k++) {
float[] plane = null;
switch (complex) {
case REAL:
plane = signal.getRealXY(k);
break;
case IMAGINARY:
plane = signal.getImagXY(k);
break;
case MODULE:
plane = signal.getModuleXY(k);
break;
default:
plane = signal.getModuleXY_dB(k);
}
stack.addSlice(new FloatProcessor(signal.nx, signal.ny, plane));
}
new ImagePlus(title, stack).show();
}
private RealSignal build(ImagePlus imp) {
if (imp == null)
return null;
int nx = imp.getWidth();
int ny = imp.getHeight();
int nz = imp.getStackSize();
RealSignal signal = new RealSignal(nx, ny, nz);
for (int k = 0; k < nz; k++) {
ImageProcessor ip = imp.getStack().getProcessor(k + 1).convertToFloat();
signal.setXY(k, (float[]) ip.getPixels());
}
return signal;
}
private ImagePlus build(RealSignal signal, PlatformImager.Type type) {
if (signal == null)
return null;
ImageStack stack = new ImageStack(signal.nx, signal.ny);
for (int k = 0; k < signal.nz; k++) {
ImageProcessor ip = new FloatProcessor(signal.nx, signal.ny, signal.getXY(k));
switch (type) {
case BYTE:
stack.addSlice(ip.convertToByteProcessor(false));
break;
case SHORT:
stack.addSlice(ip.convertToShortProcessor(false));
break;
case FLOAT:
stack.addSlice(ip);
default:
break;
}
}
return new ImagePlus("", stack);
}
@Override
public String getName() {
return "ImageJ";
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/modules/FFTModule.java b/DeconvolutionLab2/src/deconvolutionlab/modules/FFTModule.java
index cc97a88..c8d4d57 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/modules/FFTModule.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/modules/FFTModule.java
@@ -1,199 +1,199 @@
/*
* 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.modules;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import lab.component.CustomizedColumn;
import lab.component.CustomizedTable;
import lab.component.GridPanel;
import lab.component.HTMLPane;
import lab.tools.NumFormat;
import signal.Signal;
import deconvolution.Command;
import deconvolution.Deconvolution;
import deconvolution.algorithm.Algorithm;
import deconvolutionlab.Config;
import deconvolutionlab.Constants;
import fft.AbstractFFTLibrary;
import fft.FFT;
public class FFTModule extends AbstractModule implements ActionListener, ChangeListener {
private HTMLPane info;
private JComboBox<String> cmbFFT;
private JComboBox<String> cmbType;
private JComboBox<String> cmbSep;
private JComboBox<String> cmbEpsilon;
private CustomizedTable table;
public FFTModule(boolean expanded) {
super("Fourier", "", "", "Default", expanded);
}
@Override
public String getCommand() {
String cmd = "";
if (cmbFFT.getSelectedIndex() != 0)
cmd += " -fft " + (String) cmbFFT.getSelectedItem();
return cmd;
}
@Override
public JPanel buildExpandedPanel() {
ArrayList<CustomizedColumn> columns = new ArrayList<CustomizedColumn>();
columns.add(new CustomizedColumn("Name", String.class, 120, false));
columns.add(new CustomizedColumn("Installed", String.class, 120, false));
+ columns.add(new CustomizedColumn("Multithreadable", String.class, 120, false));
columns.add(new CustomizedColumn("Location", String.class, Constants.widthGUI, false));
table = new CustomizedTable(columns, true);
table.setRowSelectionAllowed(false);
info = new HTMLPane(100, 100);
cmbFFT = new JComboBox<String>(FFT.getLibrariesAsArray());
cmbType = new JComboBox<String>(new String[] { "float" });
cmbSep = new JComboBox<String>(new String[] { "XYZ" });
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");
GridPanel pnNumeric = new GridPanel(false, 3);
pnNumeric.place(3, 0, new JLabel("FFT Fourier Library"));
pnNumeric.place(3, 1, cmbFFT);
pnNumeric.place(6, 0, new JLabel("FFT Dimension"));
pnNumeric.place(6, 1, cmbSep);
pnNumeric.place(7, 0, new JLabel("<html>Machine Epsilon ε</html>"));
pnNumeric.place(7, 1, cmbEpsilon);
- pnNumeric.place(8, 0, new JLabel("Data Type"));
- pnNumeric.place(8, 1, cmbType);
JScrollPane scroll2 = new JScrollPane(pnNumeric);
scroll2.setBorder(BorderFactory.createEmptyBorder());
scroll2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scroll2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
JPanel control = new JPanel(new BorderLayout());
Border b1 = BorderFactory.createEtchedBorder();
Border b2 = BorderFactory.createEmptyBorder(10, 10, 10, 10);
control.setBorder(BorderFactory.createCompoundBorder(b1, b2));
control.add(scroll2, BorderLayout.NORTH);
control.add(info.getPane(), BorderLayout.CENTER);
control.add(table.getPane(80, 80), BorderLayout.SOUTH);
JPanel panel = new JPanel(new BorderLayout());
panel.add(control, BorderLayout.CENTER);
Config.register(getName(), "epsilon", cmbEpsilon, "1E-6");
Config.register(getName(), "fft", cmbFFT, Algorithm.getDefaultAlgorithm());
Config.register(getName(), "dim", cmbSep, "XYZ");
cmbFFT.addActionListener(this);
cmbType.addActionListener(this);
cmbEpsilon.addActionListener(this);
getAction1Button().addActionListener(this);
getAction2Button().addActionListener(this);
fillInstallation();
return panel;
}
private void fillInstallation() {
ArrayList<AbstractFFTLibrary> libs = FFT.getRegisteredLibraries();
for (AbstractFFTLibrary lib : libs) {
String name = lib.getLibraryName();
String installed = lib.isInstalled() ? " Yes" : "No";
+ String multit = lib.isMultithreadable() ? " Yes" : "No";
String location = lib.getLocation();
- table.append(new String[] { name, installed, location });
+ table.append(new String[] { name, installed, multit, location });
}
AbstractFFTLibrary fftlib = FFT.getLibraryByName((String) cmbFFT.getSelectedItem());
info.clear();
info.append("p", fftlib.getLicence());
}
private void update() {
setCommand(getCommand());
Signal.epsilon = NumFormat.parseNumber((String) cmbEpsilon.getSelectedItem(), 1e-6);
Command.command();
}
@Override
public void stateChanged(ChangeEvent e) {
update();
}
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
if (e.getSource() == cmbFFT || e.getSource() == cmbSep) {
AbstractFFTLibrary fftlib = FFT.getLibraryByName((String) cmbFFT.getSelectedItem());
info.clear();
info.append("p", fftlib.getLicence());
}
if (e.getSource() == getAction1Button()) {
cmbFFT.removeActionListener(this);
cmbType.removeActionListener(this);
cmbEpsilon.removeActionListener(this);
cmbFFT.setSelectedIndex(0);
cmbType.setSelectedIndex(0);
cmbEpsilon.setSelectedIndex(0);
cmbFFT.addActionListener(this);
cmbType.addActionListener(this);
cmbEpsilon.addActionListener(this);
}
update();
}
@Override
public void close() {
getAction1Button().removeActionListener(this);
getAction2Button().removeActionListener(this);
cmbFFT.removeActionListener(this);
cmbType.removeActionListener(this);
cmbEpsilon.removeActionListener(this);
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/modules/ImageModule.java b/DeconvolutionLab2/src/deconvolutionlab/modules/ImageModule.java
index d65ba6c..705ea4c 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/modules/ImageModule.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/modules/ImageModule.java
@@ -1,341 +1,352 @@
/*
* 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.modules;
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 deconvolution.Command;
import deconvolution.Deconvolution;
import deconvolutionlab.Config;
import deconvolutionlab.Constants;
import deconvolutionlab.ImageSelector;
import deconvolutionlab.Lab;
import deconvolutionlab.PlatformImageSelector;
import deconvolutionlab.dialog.PatternDialog;
import deconvolutionlab.dialog.SyntheticDialog;
import deconvolutionlab.monitor.Monitors;
import lab.component.CustomizedColumn;
import lab.component.CustomizedTable;
import lab.tools.Files;
import signal.RealSignal;
import signal.factory.SignalFactory;
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(boolean expanded) {
- super("Image", "-image", "Select", "Show", expanded);
+ super("Image", "-image", "Active", "Show", expanded);
}
@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, 5));
pn.setFloatable(false);
pn.add(bnFile);
pn.add(bnDirectory);
pn.add(bnSynthetic);
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);
table.setDropTarget(new LocalDropTarget());
getCollapsedPanel().setDropTarget(new LocalDropTarget());
bnFile.addActionListener(this);
bnDirectory.addActionListener(this);
bnSynthetic.addActionListener(this);
bnPlatform.addActionListener(this);
getAction1Button().addActionListener(this);
getAction2Button().addActionListener(this);
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) {
Deconvolution deconvolution = new Deconvolution(Command.command());
file(deconvolution.getPath());
}
else if (e.getSource() == bnDirectory) {
Deconvolution deconvolution = new Deconvolution(Command.command());
dir(deconvolution.getPath());
}
else if (e.getSource() == bnSynthetic)
synthetic(false);
else if (e.getSource() == bnPlatform)
platform();
- else if (e.getSource() == getAction1Button())
- 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", "" });
+ else
+ table.setRowSelectionInterval(row, row);
+ }
else if (e.getSource() == getAction2Button())
display();
update();
}
public void platform() {
PlatformImageSelector selector = new ImageSelector(Lab.getPlatform()).getImageSelector();
String name = selector.getSelectedImage();
if (name != null)
if (name != "")
table.insert(new String[] { name, "platform", name, "" });
}
private void file(String path) {
File file = Files.browseFile(path);
if (file == null)
return;
table.insert(new String[] { file.getName(), "file", file.getAbsolutePath(), "" });
}
private void dir(String path) {
File file = Files.browseDirectory(path);
if (file == null)
return;
PatternDialog dlg = new PatternDialog(file);
dlg.setVisible(true);
if (dlg.wasCancel())
return;
table.insert(new String[] { dlg.getDirName(), "directory", dlg.getCommand(), "" });
}
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, 1));
}
}
dlg.setVisible(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(), "" });
}
private void edit() {
int row = table.getSelectedRow();
if (row < 0)
return;
String name = table.getCell(row, 0).trim();
System.out.println("edit " + row + " " + name);
for (SignalFactory factory : SignalFactory.getAll()) {
if (name.equals(factory.getName().trim()))
synthetic(true);
return;
}
String filename = table.getCell(row, 1).trim();
System.out.println("edit " + row + " " + filename + " " + new File(filename).exists() + " " + new File(filename).isDirectory());
File file = new File(filename);
if (!file.exists())
return;
if (file.isFile())
file(table.getCell(row, 21));
else
dir(table.getCell(row, 1));
}
private void display() {
int row = table.getSelectedRow();
if (row < 0)
return;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
int row = table.getSelectedRow();
RealSignal x = new Deconvolution(getCommand()).openImage();
if (x != null)
Lab.show(Monitors.createDefaultMonitor(), x, table.getCell(row, 0));
}
});
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
@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(), "" });
table.setRowSelectionInterval(0, 0);
update();
}
if (file.isFile()) {
table.insert(new String[] { file.getName(), "file", file.getAbsolutePath(), "" });
update();
}
}
}
catch (UnsupportedFlavorException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}
e.dropComplete(true);
super.drop(e);
}
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/modules/PSFModule.java b/DeconvolutionLab2/src/deconvolutionlab/modules/PSFModule.java
index e79c845..2eeabc5 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/modules/PSFModule.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/modules/PSFModule.java
@@ -1,343 +1,343 @@
/*
* 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.modules;
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 lab.component.CustomizedColumn;
import lab.component.CustomizedTable;
import lab.tools.Files;
import signal.RealSignal;
import signal.factory.SignalFactory;
import deconvolution.Command;
import deconvolution.Deconvolution;
import deconvolutionlab.Config;
import deconvolutionlab.Constants;
import deconvolutionlab.ImageSelector;
import deconvolutionlab.Lab;
import deconvolutionlab.PlatformImageSelector;
import deconvolutionlab.dialog.PatternDialog;
import deconvolutionlab.dialog.SyntheticDialog;
import deconvolutionlab.monitor.Monitors;
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(boolean expanded) {
- super("PSF", "-psf", "Select", "Show", expanded);
+ super("PSF", "-psf", "", "Show", expanded);
}
@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);
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);
table.setDropTarget(new LocalDropTarget());
getCollapsedPanel().setDropTarget(new LocalDropTarget());
bnFile.addActionListener(this);
bnDirectory.addActionListener(this);
bnSynthetic.addActionListener(this);
bnPlatform.addActionListener(this);
getAction1Button().addActionListener(this);
getAction2Button().addActionListener(this);
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) {
Deconvolution deconvolution = new Deconvolution(Command.command());
file(deconvolution.getPath());
}
else if (e.getSource() == bnDirectory) {
Deconvolution deconvolution = new Deconvolution(Command.command());
dir(deconvolution.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())
display();
update();
}
public void platform() {
PlatformImageSelector selector = new ImageSelector(Lab.getPlatform()).getImageSelector();
String name = selector.getSelectedImage();
if (name != null)
if (name != "")
table.insert(new String[] {name, "platform", name, "" });
}
private void file(String path) {
File file = Files.browseFile(path);
if (file == null)
return;
table.insert(new String[] { file.getName(), "file", file.getAbsolutePath(), "" });
}
private void dir(String path) {
File file = Files.browseDirectory(path);
if (file == null)
return;
PatternDialog dlg = new PatternDialog(file);
dlg.setVisible(true);
if (dlg.wasCancel())
return;
table.insert(new String[] { dlg.getDirName(), "directory", dlg.getCommand(), "" });
}
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, 1));
}
}
dlg.setVisible(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(), "" });
}
private void edit() {
int row = table.getSelectedRow();
if (row < 0)
return;
String name = table.getCell(row, 0).trim();
System.out.println("edit " + row + " " + name);
for(SignalFactory factory : SignalFactory.getAll()) {
if (name.equals(factory.getName().trim()))
synthetic(true);
return;
}
String filename = table.getCell(row, 1).trim();
System.out.println("edit " + row + " " + filename + " " + new File(filename).exists() + " " +new File(filename).isDirectory());
File file = new File(filename);
if (!file.exists())
return;
if (file.isFile())
file(table.getCell(row, 21));
else
dir(table.getCell(row, 1));
}
private void display() {
int row = table.getSelectedRow();
if (row < 0)
return;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
int row = table.getSelectedRow();
RealSignal x = new Deconvolution(getCommand()).openPSF();
if (x != null)
Lab.show(Monitors.createDefaultMonitor(), x, table.getCell(row, 0));
}
});
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
@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(), "" });
table.setRowSelectionInterval(0, 0);
update();
}
if (file.isFile()) {
table.insert(new String[] { file.getName(), "file", file.getAbsolutePath(), "" });
update();
}
}
}
catch (UnsupportedFlavorException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}
e.dropComplete(true);
super.drop(e);
}
}
}
diff --git a/DeconvolutionLab2/src/imagej/IJImager.java b/DeconvolutionLab2/src/imagej/IJImager.java
index f60c2eb..ac47161 100644
--- a/DeconvolutionLab2/src/imagej/IJImager.java
+++ b/DeconvolutionLab2/src/imagej/IJImager.java
@@ -1,218 +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 imagej;
import java.util.HashMap;
import deconvolutionlab.PlatformImager;
import deconvolutionlab.PlatformImager.ContainerImage;
import ij.ImagePlus;
import ij.ImageStack;
import ij.WindowManager;
import ij.io.FileSaver;
import ij.io.Opener;
import ij.process.FloatProcessor;
import ij.process.ImageProcessor;
import signal.ComplexComponent;
import signal.ComplexSignal;
import signal.RealSignal;
public class IJImager extends PlatformImager {
public static RealSignal create(ImagePlus imp) {
int nx = imp.getWidth();
int ny = imp.getHeight();
int nz = imp.getStackSize();
RealSignal signal = new RealSignal(nx, ny, nz);
for (int k = 0; k < nz; k++) {
ImageProcessor ip = imp.getStack().getProcessor(k + 1).convertToFloat();
signal.setXY(k, (float[]) ip.getPixels());
}
return signal;
}
@Override
public RealSignal create() {
return build(WindowManager.getCurrentImage());
}
@Override
public RealSignal create(String name) {
- ImagePlus imp = WindowManager.getImage(name);
+ ImagePlus imp = null;
+ if (name.equalsIgnoreCase("active"))
+ imp = WindowManager.getCurrentImage();
+ else
+ imp = WindowManager.getImage(name);
if (imp == null)
imp = WindowManager.getCurrentImage();
return build(imp);
}
@Override
public RealSignal open(String filename) {
Opener opener = new Opener();
ImagePlus imp = opener.openImage(filename);
return build(imp);
}
@Override
public void show(RealSignal signal, String title) {
show(signal, title, PlatformImager.Type.FLOAT);
}
@Override
public void show(RealSignal signal, String title, PlatformImager.Type type) {
show(signal, title, type, signal.nz / 2);
}
@Override
public void show(RealSignal signal, String title, PlatformImager.Type type, int z) {
ImagePlus imp = build(signal, type);
if (imp != null) {
imp.setTitle(title);
int nz = imp.getStackSize();
imp.show();
imp.setSlice(Math.max(1, Math.min(nz, z)));
imp.getProcessor().resetMinAndMax();
}
}
public ContainerImage createContainer(String title) {
return new ContainerImage();
}
@Override
public void append(ContainerImage container, RealSignal signal, String title) {
append(container, signal, title, PlatformImager.Type.FLOAT);
}
@Override
public void append(ContainerImage container, RealSignal signal, String title, PlatformImager.Type type) { ImagePlus cont = (ImagePlus) container.object;
if (container.object == null) {
ImageStack stack = new ImageStack(signal.nx, signal.ny);
stack.addSlice(build(signal, type).getProcessor());
stack.addSlice(build(signal, type).getProcessor());
container.object = new ImagePlus(title, stack);
((ImagePlus)container.object).show();
}
else {
cont.getStack().addSlice(build(signal, type).getProcessor());
cont.setSlice(cont.getStack().getSize());
cont.updateAndDraw();
cont.getProcessor().resetMinAndMax();
}
}
@Override
public void save(RealSignal signal, String filename) {
save(signal, filename, PlatformImager.Type.FLOAT);
}
@Override
public void save(RealSignal signal, String filename, PlatformImager.Type type) {
ImagePlus imp = build(signal, type);
if (imp != null) {
if (imp.getStackSize() == 1) {
new FileSaver(imp).saveAsTiff(filename);
}
else {
new FileSaver(imp).saveAsTiffStack(filename);
}
}
}
@Override
public void show(ComplexSignal signal, String title) {
show(signal, title, ComplexComponent.MODULE);
}
@Override
public void show(ComplexSignal signal, String title, ComplexComponent complex) {
ImageStack stack = new ImageStack(signal.nx, signal.ny);
for (int k = 0; k < signal.nz; k++) {
float[] plane = null;
switch (complex) {
case REAL:
plane = signal.getRealXY(k);
break;
case IMAGINARY:
plane = signal.getImagXY(k);
break;
case MODULE:
plane = signal.getModuleXY(k);
break;
default:
plane = signal.getModuleXY_dB(k);
}
stack.addSlice(new FloatProcessor(signal.nx, signal.ny, plane));
}
new ImagePlus(title, stack).show();
}
private RealSignal build(ImagePlus imp) {
if (imp == null)
return null;
int nx = imp.getWidth();
int ny = imp.getHeight();
int nz = imp.getStackSize();
RealSignal signal = new RealSignal(nx, ny, nz);
for (int k = 0; k < nz; k++) {
ImageProcessor ip = imp.getStack().getProcessor(k + 1).convertToFloat();
signal.setXY(k, (float[]) ip.getPixels());
}
return signal;
}
private ImagePlus build(RealSignal signal, PlatformImager.Type type) {
if (signal == null)
return null;
ImageStack stack = new ImageStack(signal.nx, signal.ny);
for (int k = 0; k < signal.nz; k++) {
ImageProcessor ip = new FloatProcessor(signal.nx, signal.ny, signal.getXY(k));
switch (type) {
case BYTE:
stack.addSlice(ip.convertToByteProcessor(false));
break;
case SHORT:
stack.addSlice(ip.convertToShortProcessor(false));
break;
case FLOAT:
stack.addSlice(ip);
default:
break;
}
}
return new ImagePlus("", stack);
}
@Override
public String getName() {
return "ImageJ";
}
}
diff --git a/DeconvolutionLab2/src/signal/factory/MotionBlur.java b/DeconvolutionLab2/src/signal/factory/MotionBlur.java
index 59a0bbf..0bb21bc 100644
--- a/DeconvolutionLab2/src/signal/factory/MotionBlur.java
+++ b/DeconvolutionLab2/src/signal/factory/MotionBlur.java
@@ -1,89 +1,92 @@
/*
* 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;
import signal.RealSignal;
+import signal.Signal;
public class MotionBlur extends SignalFactory {
- private double sigma = 3.0;
- private double direction = 30.0;
- private double elongation = 3.0;
+ private double sigma = 3.0;
+ private double direction = 30.0;
+ private double elongation = 3.0;
public MotionBlur(double sigma, double direction, double elongation) {
- super(new double[] {sigma, direction, elongation});
+ super(new double[] { sigma, direction, elongation });
}
@Override
public String getName() {
return "MotionBlur";
}
-
+
@Override
public String[] getParametersName() {
- return new String[] {"Sigma", "Direction", "Elongation"};
- }
+ return new String[] { "Sigma", "Direction", "Elongation" };
+ }
@Override
public void setParameters(double[] parameters) {
if (parameters.length >= 1)
this.sigma = parameters[0];
if (parameters.length >= 2)
this.direction = parameters[1];
if (parameters.length >= 3)
this.elongation = parameters[2];
}
@Override
public double[] getParameters() {
- return new double[] {sigma, direction, elongation};
+ return new double[] { sigma, direction, elongation };
}
@Override
public void fill(RealSignal signal) {
- double K1 = 0.5 / (sigma*sigma);
- double K2 = 0.5 / (sigma*sigma*elongation*elongation);
+ double K1 = 0.5 / (sigma * sigma);
+ double K2 = 0.5 / (sigma * sigma * elongation * elongation);
double cosa = Math.cos(Math.toRadians(direction));
double sina = Math.sin(Math.toRadians(direction));
- for(int x=0; x<nx; x++)
- for(int y=0; y<ny; y++) {
- double dx = (x-xc);
- double dy = (y-yc);
- //double ps = (1.0 + (dx*cosa + dy*sina)/(dx*dx + dy*dy)) * 0.5;
- double K = K1 + dx * K2 /(dx*dx + dy*dy);
- double r2 = (x-xc)*(x-xc) + (y-yc)*(y-yc);
- for(int z=0; z<nz; z++) {
- signal.data[z][x+nx*y] = (float)((amplitude-background) * Math.exp(-r2*K) + background);
+ for (int x = 0; x < nx; x++)
+ for (int y = 0; y < ny; y++) {
+ double dx = (x - xc);
+ double dy = (y - yc);
+
+ double M = (dx * cosa + dy * sina) / Math.max(dx * dx + dy * dy, Signal.epsilon);
+ M = (1.0 - 1.0 / (1.0 + Math.exp(-M / elongation)));
+
+ double r2 = (x - xc) * (x - xc) + (y - yc) * (y - yc);
+ for (int z = 0; z < nz; z++) {
+ signal.data[z][x + nx * y] = (float) ((amplitude - background) * M * Math.exp(0) + background);
+ }
}
- }
}
}
diff --git a/DeconvolutionLab2/src/signal/factory/SignalFactory.java b/DeconvolutionLab2/src/signal/factory/SignalFactory.java
index b9aee46..32776a0 100644
--- a/DeconvolutionLab2/src/signal/factory/SignalFactory.java
+++ b/DeconvolutionLab2/src/signal/factory/SignalFactory.java
@@ -1,213 +1,213 @@
/*
* 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;
import java.util.ArrayList;
import javax.swing.SwingWorker;
import deconvolutionlab.monitor.Monitors;
import signal.RealSignal;
public abstract class SignalFactory {
protected double fractXC = 0.5;
protected double fractYC = 0.5;
protected double fractZC = 0.5;
protected double background = 0.0;
protected double amplitude = 1.0;
protected double xc;
protected double yc;
protected double zc;
protected int nx;
protected int ny;
protected int nz;
public SignalFactory() {
}
public SignalFactory(double[] parameters) {
setParameters(parameters);
}
public static SignalFactory get(String name) {
ArrayList<SignalFactory> list = getAll();
for (SignalFactory factory : list) {
if (factory.getName().equals(name))
return factory;
}
return null;
}
public static ArrayList<String> getAllName() {
ArrayList<String> list = new ArrayList<String>();
for (SignalFactory factory : getAll()) {
list.add(factory.getName());
}
return list;
}
public static ArrayList<SignalFactory> getAll() {
ArrayList<SignalFactory> list = new ArrayList<SignalFactory>();
list.add(new Airy(1));
list.add(new Astigmatism(3, 0.2));
list.add(new Constant());
list.add(new Cross(1, 1, 30));
list.add(new Cube(10 ,1));
list.add(new Defocus(3, 10, 10));
list.add(new DoG(3, 4));
list.add(new DoubleHelix(3, 10, 10));
list.add(new Gaussian(3, 3, 3));
list.add(new GridSpots(3, 1, 10));
list.add(new Impulse());
- list.add(new MotionBlur(3, 30, 3));
+ //list.add(new MotionBlur(3, 30, 3));
list.add(new Ramp(1, 0, 0));
list.add(new RandomLines(3));
list.add(new Sinc(3, 3, 3));
list.add(new Sphere(10, 1));
list.add(new Torus(10));
return list;
}
public static ArrayList<SignalFactory> getImages() {
ArrayList<SignalFactory> list = new ArrayList<SignalFactory>();
list.add(new Cube(10, 1));
list.add(new Sphere(10, 1));
list.add(new GridSpots(3, 1, 10));
list.add(new Constant());
list.add(new Cross(1, 1, 30));
list.add(new DoG(3, 4));
list.add(new Gaussian(3, 3, 3));
list.add(new Impulse());
list.add(new Ramp(1, 0, 0));
list.add(new RandomLines(3));
list.add(new Torus(10));
return list;
}
public static ArrayList<SignalFactory> getPSF() {
ArrayList<SignalFactory> list = new ArrayList<SignalFactory>();
list.add(new Airy(1));
list.add(new Astigmatism(3, 0.2));
list.add(new Cross(3, 1, 10));
list.add(new Cube(10, 1));
list.add(new Defocus(3, 10, 10));
list.add(new DoG(3, 4));
list.add(new DoubleHelix(3, 10, 10));
list.add(new Gaussian(3, 3, 3));
- list.add(new MotionBlur(3, 30, 3));
+ //list.add(new MotionBlur(3, 30, 3));
list.add(new Impulse());
list.add(new Sinc(3, 3, 3));
list.add(new Sphere(10, 1));
list.add(new RandomLines(3));
list.add(new Torus(10));
return list;
}
public static SignalFactory getFactoryByName(String name) {
ArrayList<SignalFactory> list = getAll();
for (SignalFactory factory : list)
if (name.toLowerCase().equals(factory.getName().toLowerCase())) {
return factory;
}
return null;
}
public SignalFactory center(double fractXC, double fractYC, double fractZC) {
this.fractXC = fractXC;
this.fractYC = fractYC;
this.fractZC = fractZC;
return this;
}
public SignalFactory intensity(double background, double amplitude) {
this.background = background;
this.amplitude = amplitude;
return this;
}
public String params() {
String name[] = getParametersName();
double params[] = getParameters();
if (params.length == 1)
return name[0] + "=" + params[0];
else if (params.length == 2)
return name[0] + "=" + params[0] + " " + name[1] + "=" + params[1];
else
return name[0] + "=" + params[0] + " " + name[1] + "=" + params[2] + " " + name[2] + "=" + params[2];
}
public RealSignal generate(int nx, int ny, int nz) {
this.nx = nx;
this.ny = ny;
this.nz = nz;
xc = fractXC * nx;
yc = fractYC * ny;
zc = fractZC * nz;
RealSignal signal = new RealSignal(nx, ny, nz);
fill(signal);
return signal;
}
public abstract String getName();
public abstract void setParameters(double[] parameters);
public abstract double[] getParameters();
public abstract String[] getParametersName();
public abstract void fill(RealSignal signal);
public class Worker extends SwingWorker<RealSignal, String> {
private RealSignal signal;
public boolean done=false;
public Worker(RealSignal signal) {
this.signal = signal;
done = false;
}
protected RealSignal doInBackground() throws Exception {
fill(signal);
done = true;
return signal;
}
protected void done() {
System.out.println("Done");
done = true;
}
}
}
Event Timeline
Log In to Comment