Page MenuHomec4science

No OneTemporary

File Metadata

Created
Sat, Aug 3, 23:16
diff --git a/DeconvolutionLab2/build.xml b/DeconvolutionLab2/build.xml
index e0d0384..dbfacae 100644
--- a/DeconvolutionLab2/build.xml
+++ b/DeconvolutionLab2/build.xml
@@ -1,28 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="DeconvolutionLab2" default="build" basedir=".">
<property name="imagej" location="../../ImageJ/plugins"/>
<property name="fiji" location="../../Fiji-deconv.app/plugins"/>
<property name="matlab" location="/Applications/MATLAB_R2014b.app/java/"/>
<target name="build">
<mkdir dir="bin"/>
<copy todir="bin"><fileset dir="ij"></fileset></copy>
<copy file="plugins.config" toDir="bin" />
<zip destfile="../DeconvolutionLab2-src.zip" basedir="src" />
<zip destfile="../DeconvolutionLab2-cls.zip" basedir="bin" />
<jar destfile="../DeconvolutionLab_2.jar" basedir="bin">
<manifest>
<attribute name="Main-Class" value="DeconvolutionLab2"/>
- <attribute name="Class-Path" value="ij.jar jtransforms.jar"/>
+ <attribute name="Class-Path" value="."/>
</manifest>
</jar>
<copy toDir="${fiji}" file="../DeconvolutionLab_2.jar" />
<copy toDir="${matlab}" file="../DeconvolutionLab_2.jar" />
-
<copy toDir="${imagej}" file="../DeconvolutionLab_2.jar" />
</target>
</project>
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/DL2.java b/DeconvolutionLab2/src/DL2.java
index 8e0ee74..0323a0e 100644
--- a/DeconvolutionLab2/src/DL2.java
+++ b/DeconvolutionLab2/src/DL2.java
@@ -1,84 +1,94 @@
import ij.ImagePlus;
+import ij.Macro;
import ij.WindowManager;
import java.io.File;
import matlab.Converter;
import deconvolution.Deconvolution;
import deconvolutionlab.Config;
import deconvolutionlab.Lab;
import deconvolutionlab.dialog.LabDialog;
/*
* 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/>.
*/
/**
* This class is dedicated to the Matlab interface for DeconvolutionLab2
* @author sage
*
*/
public class DL2 {
public static void lab() {
String config = System.getProperty("user.dir") + File.separator + "DeconvolutionLab2.config";
Config.getInstance(config);
LabDialog dialog = new LabDialog();
dialog.setVisible(true);
}
public static void run(String command) {
- return;
+ new Deconvolution(Macro.getOptions()).deconvolve(false);
}
public static void launch(String command) {
- return;
+ new Deconvolution(Macro.getOptions()).launch("matlab", false);
}
public static Object get(String image) {
ImagePlus imp = WindowManager.getCurrentImage();
if (imp != null)
return Converter.get(imp);
return null;
}
public static void run(Object image, Object psf, String algo) {
Converter.createImage("input", image, true);
Converter.createImage("psf", psf, true);
String cmd = " -image platform input -psf platform psf -algorithm " + algo;
Deconvolution d = new Deconvolution(cmd);
d.deconvolve(false);
}
public static void help() {
Lab.help();
}
+
+ public static void clear() {
+ int ids[] = WindowManager.getIDList();
+ for(int id : ids) {
+ ImagePlus imp = WindowManager.getImage(id);
+ if (imp != null)
+ imp.close();
+ }
+ }
}
diff --git a/DeconvolutionLab2/src/DeconvolutionLab2.java b/DeconvolutionLab2/src/DeconvolutionLab2.java
index e51c8f2..91bc5d3 100644
--- a/DeconvolutionLab2/src/DeconvolutionLab2.java
+++ b/DeconvolutionLab2/src/DeconvolutionLab2.java
@@ -1,127 +1,135 @@
/*
* 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/>.
*/
import java.io.File;
-import matlab.Converter;
import deconvolution.Command;
import deconvolution.Deconvolution;
import deconvolutionlab.Config;
import deconvolutionlab.Constants;
import deconvolutionlab.Lab;
import deconvolutionlab.Platform;
import deconvolutionlab.dialog.LabDialog;
import deconvolutionlab.monitor.Monitors;
public class DeconvolutionLab2 {
public static String ack = Constants.name + " " + Constants.version + " " + Constants.copyright;
public static void main(String arg[]) {
System.out.println(ack);
Lab.getInstance(Platform.STANDALONE);
if (arg.length == 0) {
+ System.out.println("Starting lab");
lab(arg);
return;
}
String flag = arg[0].trim().toLowerCase();
if (flag.equalsIgnoreCase("help")) {
+ System.out.println("Starting help");
help();
return;
}
- if (flag.equalsIgnoreCase("lab")) {
+ else if (flag.equalsIgnoreCase("lab")) {
+ System.out.println("Starting lab");
lab(arg);
}
- if (flag.equalsIgnoreCase("fft")) {
+ else if (flag.equalsIgnoreCase("fft")) {
+ System.out.println("Starting fft");
Lab.checkFFT(Monitors.createDefaultMonitor());
}
- if (flag.equalsIgnoreCase("run")) {
+ else if (flag.equalsIgnoreCase("run")) {
+ System.out.println("Starting run");
String cmd = "";
for (int i = 1; i < arg.length; i++)
cmd += arg[i] + " ";
new Deconvolution(cmd).deconvolve(true);
}
- if (flag.equalsIgnoreCase("launch")) {
+ else if (flag.equalsIgnoreCase("launch")) {
+ System.out.println("Starting launch");
String cmd = "";
for (int i = 1; i < arg.length; i++)
cmd += arg[i] + " ";
new Deconvolution(cmd).launch("", true);
}
+ else
+ System.out.println("" + flag + " command not found");
+
}
private static void lab(String arg[]) {
String config = System.getProperty("user.dir") + File.separator + "DeconvolutionLab2.config";
if (arg.length >= 2) {
String filename = arg[1].trim();
File file = new File(filename);
if (file.exists())
if (file.isFile())
if (file.canRead())
config = filename;
}
Config.getInstance(config);
LabDialog dialog = new LabDialog();
dialog.setVisible(true);
}
public static void help() {
System.out.println("More info:" + Constants.url);
System.out.println("Syntax:");
System.out.println("java -jar DeconvolutionLab_2.jar lab");
System.out.println("java -jar DeconvolutionLab_2.jar run {command} ...");
System.out.println("java -jar DeconvolutionLab_2.jar launch {command} ...");
System.out.println("java -jar DeconvolutionLab_2.jar fft");
System.out.println("java -jar DeconvolutionLab_2.jar info");
System.out.println("java -jar DeconvolutionLab_2.jar help");
System.out.println("{command} is the full command line for running a deconvolution");
System.out.print("Keywords of {command}: ");
for (String keyword : Command.keywords)
System.out.print(keyword + " ");
}
public DeconvolutionLab2(String cmd) {
System.out.println("cmd: " + cmd);
deconvolutionlab.Lab.getInstance(Platform.STANDALONE);
String config = System.getProperty("user.dir") + File.separator + "DeconvolutionLab2.config";
Config.getInstance(config);
new Deconvolution(cmd).deconvolve(false);
}
}
diff --git a/DeconvolutionLab2/src/deconvolution/Command.java b/DeconvolutionLab2/src/deconvolution/Command.java
index 7c82eed..b681ba2 100644
--- a/DeconvolutionLab2/src/deconvolution/Command.java
+++ b/DeconvolutionLab2/src/deconvolution/Command.java
@@ -1,299 +1,290 @@
/*
* 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.util.ArrayList;
import java.util.Collections;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lab.tools.NumFormat;
import signal.Constraint;
import signal.apodization.AbstractApodization;
import signal.apodization.Apodization;
import signal.apodization.UniformApodization;
import signal.padding.AbstractPadding;
import signal.padding.NoPadding;
import signal.padding.Padding;
import wavelets.Wavelets;
import deconvolution.algorithm.AbstractAlgorithm;
import deconvolution.algorithm.Algorithm;
import deconvolution.algorithm.Controller;
import deconvolutionlab.Output;
import deconvolutionlab.Output.View;
import deconvolutionlab.modules.AbstractModule;
import deconvolutionlab.modules.CommandModule;
import deconvolutionlab.modules.LanguageModule;
import deconvolutionlab.monitor.ConsoleMonitor;
import deconvolutionlab.monitor.Monitors;
import deconvolutionlab.monitor.TableMonitor;
public class Command {
public static String keywords[] = { "-image", "-psf", "-algorithm", "-path", "-disable", "-verbose", "-time", "-constraint", "-residu", "-reference", "-savestats", "-showstats", "-out", "-pad", "-apo", "-norm", "-fft" };
private static AbstractModule modules[];
private static CommandModule command;
public static void active(AbstractModule[] m, CommandModule c) {
modules = m;
command = c;
}
public static String command() {
if (modules == null)
return "";
String cmd = "";
for (AbstractModule m : modules)
cmd += m.getCommand() + " ";
if (command != null)
command.setCommand(cmd);
return cmd;
}
/**
* This methods first segments the command line, then create all the tokens
* of the command line
*
* @param command
* Command line
* @return the list of tokens extracted from the command line
*/
public static ArrayList<Token> parse(String command) {
ArrayList<CommandSegment> segments = new ArrayList<CommandSegment>();
for (String keyword : keywords)
segments.addAll(findSegment(command, keyword));
+ Collections.sort(segments);
ArrayList<Token> tokens = new ArrayList<Token>();
for(int i=0; i<segments.size(); i++) {
String keyword = segments.get(i).keyword;
int begin = segments.get(i).index+keyword.length()+1;
int end = (i<segments.size()-1 ? segments.get(i+1).index : command.length());
Token token = new Token(keyword, command, begin, end);
tokens.add(token);
}
-
/*
for (int i = 0; i < segments.size(); i++) {
CommandSegment segment = segments.get(i);
String next = (i + 1 < segments.size() ? segments.get(i + 1).keyword : "");
int end = (i + 1 < segments.size() ? segments.get(i + 1).index - next.length() : command.length());
tokens.add(new Token(segment.keyword, command, segment.index, end));
}
*/
return tokens;
}
public static Token extract(String command, String keyword) {
ArrayList<Token> tokens = parse(command);
for (Token token : tokens)
if (token.keyword.equalsIgnoreCase(keyword))
return token;
return (Token) null;
}
public static double[] parseNumeric(String line) {
ArrayList<String> num = new ArrayList<String>();
Pattern p = Pattern.compile("[-+]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?");
Matcher m = p.matcher(line);
while (m.find()) {
num.add(m.group());
}
double number[] = new double[num.size()];
for (int i = 0; i < num.size(); i++)
number[i] = Double.parseDouble(num.get(i));
return number;
}
public static ArrayList<CommandSegment> findSegment(String command, String keyword) {
ArrayList<CommandSegment> segments = new ArrayList<CommandSegment>();
String regex = "(?<!\\w)" + keyword + "(?!\\w)";
Matcher matcher = Pattern.compile(regex).matcher(command);
while (matcher.find()) {
segments.add(new CommandSegment(keyword, matcher.start()));
- System.out.println(" " + "," + matcher.end() + " " + matcher.group());
}
- Collections.sort(segments);
return segments;
}
- /*
- * public static ArrayList<CommandSegment> findSegment(String command,
- * String key) { int index = -1; ArrayList<CommandSegment> segments = new
- * ArrayList<CommandSegment>(); do { index = command.indexOf(key, index +
- * 1); if (index >= 0) { segments.add(new CommandSegment(key, index +
- * key.length())); } } while (index >= 0); return segments; }
- */
public static AbstractAlgorithm decodeAlgorithm(Token token, Controller controller) {
String option = token.option;
AbstractAlgorithm algo = Algorithm.createAlgorithm(option);
double params[] = parseNumeric(token.parameters);
if (params != null) {
algo.setParameters(params);
if (algo.isIterative())
controller.setIterationMax(algo.getController().getIterationMax());
}
if (algo.isWaveletsBased()) {
for (String wavelet : Wavelets.getWaveletsAsArray()) {
int pos = token.parameters.toLowerCase().indexOf(wavelet.toLowerCase());
if (pos >= 0)
algo.setWavelets(wavelet);
}
}
return algo;
}
public static Output decodeOut(Token token) {
int freq = 0;
String line = token.parameters;
String parts[] = token.parameters.split(" ");
for (int i = 0; i < Math.min(2, parts.length); i++) {
if (parts[i].startsWith("@"))
freq = (int) NumFormat.parseNumber(parts[i], 0);
}
String p = token.parameters.toLowerCase();
Output out = null;
if (p.startsWith("stack"))
out = new Output(View.STACK, freq, line.substring("stack".length(), line.length()));
if (p.startsWith("series"))
out = new Output(View.SERIES, freq, line.substring("series".length(), line.length()));
if (p.startsWith("mip"))
out = new Output(View.MIP, freq, line.substring("mip".length(), line.length()));
if (p.startsWith("ortho"))
out = new Output(View.ORTHO, freq, line.substring("ortho".length(), line.length()));
if (p.startsWith("figure"))
out = new Output(View.FIGURE, freq, line.substring("figure".length(), line.length()));
if (p.startsWith("planar"))
out = new Output(View.PLANAR, freq, line.substring("planar".length(), line.length()));
return out;
}
public static void decodeController(Token token, Controller controller) {
int freq = 1;
String line = token.parameters;
if (token.parameters.startsWith("@")) {
String parts[] = token.parameters.split(" ");
if (parts.length >= 1) {
freq = (int) NumFormat.parseNumber(parts[0], 1);
line = token.parameters.substring(parts[0].length(), token.parameters.length()).trim();
}
}
if (token.keyword.equals("-constraint")) {
controller.setConstraint(freq, Constraint.getByName(line.trim()));
}
else if (token.keyword.equals("-residu")) {
double stop = NumFormat.parseNumber(line, -1);
controller.setResiduStop(freq, stop);
}
else if (token.keyword.equals("-reference")) {
controller.setReference(freq, line);
}
else if (token.keyword.equals("-savestats")) {
controller.setSaveStats(freq, line);
}
else if (token.keyword.equals("-showstats")) {
controller.setShowStats(freq, line);
}
else if (token.keyword.equals("-time")) {
double stop = NumFormat.parseNumber(line, Double.MAX_VALUE);
controller.setTimeStop(stop);
}
}
public static double decodeNormalization(Token token) {
if (token.parameters.toLowerCase().endsWith("no"))
return 0;
else
return NumFormat.parseNumber(token.parameters, 1);
}
public static boolean decodeDisable(Token token, String word) {
String p = token.parameters.toLowerCase();
String parts[] = p.split(" ");
for (String part : parts) {
if (part.trim().equals(word))
return false;
}
return true;
}
public static Padding decodePadding(Token token) {
AbstractPadding padXY = new NoPadding();
AbstractPadding padZ = new NoPadding();
int extXY = 0;
int extZ = 0;
String param = token.parameters.trim();
String[] parts = param.split(" ");
if (parts.length > 0)
padXY = Padding.getByShortname(parts[0].trim());
if (parts.length > 1)
padZ = Padding.getByShortname(parts[1].trim());
double[] ext = NumFormat.parseNumbers(param);
if (ext.length > 0)
extXY = (int) Math.round(ext[0]);
if (ext.length > 1)
extZ = (int) Math.round(ext[1]);
return new Padding(padXY, padXY, padZ, extXY, extXY, extZ);
}
public static Apodization decodeApodization(Token token) {
AbstractApodization apoXY = new UniformApodization();
AbstractApodization apoZ = new UniformApodization();
String[] parts = token.parameters.trim().split(" ");
if (parts.length >= 1)
apoXY = Apodization.getByShortname(parts[0].trim());
if (parts.length >= 2)
apoZ = Apodization.getByShortname(parts[1].trim());
return new Apodization(apoXY, apoXY, apoZ);
}
}
diff --git a/DeconvolutionLab2/src/deconvolution/Deconvolution.java b/DeconvolutionLab2/src/deconvolution/Deconvolution.java
index ccbd1bf..f5174bd 100644
--- a/DeconvolutionLab2/src/deconvolution/Deconvolution.java
+++ b/DeconvolutionLab2/src/deconvolution/Deconvolution.java
@@ -1,660 +1,642 @@
/*
* 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.ConsoleMonitor;
import deconvolutionlab.monitor.Monitors;
import deconvolutionlab.monitor.StatusMonitor;
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 Padding pad = new Padding();
+ private Apodization apo = new Apodization();
+ private double norm = 1.0;
+ private AbstractFFTLibrary fft;
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) {
+ if (fft == null) {
run();
return;
}
- if (!fftlib.isMultithreadable()) {
+ if (!fft.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();
monitors.add(new StatusMonitor(d.getProgressBar()));
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");
+ pad = new Padding();
+ apo = new Apodization();
+ norm = 1.0;
+ fft = 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);
+ fft = FFT.getLibraryByName(token.parameters);
if (token.keyword.equalsIgnoreCase("-pad"))
- padding = Command.decodePadding(token);
+ pad = Command.decodePadding(token);
if (token.keyword.equalsIgnoreCase("-apo"))
- apodization = Command.decodeApodization(token);
+ apo = Command.decodeApodization(token);
if (token.keyword.equalsIgnoreCase("-norm"))
- factorNormalization = Command.decodeNormalization(token);
+ norm = 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);
+ this.apo = 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.dimAsString());
- 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.dimAsString());
- 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);
+ report.add("FFT: " + fft.getLibraryName());
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);
+ RealSignal result = algo.run(monitors, image, psf, fft, pad, apo, norm, true);
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 + ")");
+ String normf = (norm < 0 ? " (no normalization)" : " (normalization to " + norm + ")");
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);
+ lines.add("<b>PSF</b>: " + psf.parameters + normf);
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());
+ lines.add("<b>Padding</b>: " + pad.toString());
+ lines.add("<b>Apodization</b>: " + apo.toString());
if (algo.getFFT() != null)
lines.add("<b>FFT</b>: " + algo.getFFT().getName());
}
lines.add("<b>Path</b>: " + path);
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) {
+ if (pad == null) {
lines.add("No valid padding");
return lines;
}
- if (apodization == null) {
+ if (apo == 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);
+ RealSignal x = algo.run(monitors, image, psf, fft, pad, apo, norm, 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) {
+ if (pad == null) {
lines.add("No valid padding");
return lines;
}
- if (apodization == null) {
+ if (apo == null) {
lines.add("No valid apodization");
return lines;
}
- RealSignal signal = padding.pad(monitors, getApodization().apodize(monitors, image));
+ RealSignal signal = pad.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) {
+ if (pad == null) {
lines.add("No valid padding");
return lines;
}
- if (apodization == null) {
+ if (apo == 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 signal = pad.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);
+ h.normalize(norm);
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 Padding getPadding() {
+ return pad;
}
public Apodization getApodization() {
- return apodization;
+ return apo;
}
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/deconvolution/algorithm/AbstractAlgorithm.java b/DeconvolutionLab2/src/deconvolution/algorithm/AbstractAlgorithm.java
index 7e88e00..bcb8f27 100644
--- a/DeconvolutionLab2/src/deconvolution/algorithm/AbstractAlgorithm.java
+++ b/DeconvolutionLab2/src/deconvolution/algorithm/AbstractAlgorithm.java
@@ -1,182 +1,206 @@
/*
* 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 java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
-import lab.tools.NumFormat;
import deconvolutionlab.monitor.Monitors;
import fft.AbstractFFT;
+import fft.AbstractFFTLibrary;
import fft.FFT;
+import lab.tools.NumFormat;
import signal.Operations;
import signal.RealSignal;
+import signal.apodization.Apodization;
+import signal.padding.Padding;
/**
* This class is the common part of every algorithm of deconvolution.
*
* @author Daniel Sage
*
*/
public abstract class AbstractAlgorithm implements Callable<RealSignal> {
protected RealSignal y = null;
protected RealSignal h = null;
- protected RealSignal reference = null;
-
protected Controller controller = null;
protected AbstractFFT fft = null;
public AbstractAlgorithm() {
this.controller = new Controller();
}
public abstract String getName();
public abstract String getShortname();
public abstract boolean isRegularized();
public abstract boolean isStepControllable();
public abstract boolean isIterative();
public abstract boolean isWaveletsBased();
public abstract void setParameters(double[] params);
public abstract double getRegularizationFactor();
public abstract double getStepFactor();
public abstract double[] getParameters();
public abstract double[] getDefaultParameters();
- public RealSignal run(Monitors monitors, RealSignal image, RealSignal psf, boolean threaded) {
+ public RealSignal run(Monitors monitors,
+ RealSignal image, RealSignal psf,
+ AbstractFFTLibrary fftlib, Padding pad, Apodization apo, double norm, boolean threaded) {
+
+ if (image == null)
+ return null;
+ if (psf == null)
+ return null;
+
+ 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);
+
+ controller.setFFT(fft);
+
+ y = (pad == null ? image.duplicate() : pad.pad(monitors, apo.apodize(monitors, image)));
+ monitors.log("Input: " + y.dimAsString());
+
+ h = psf.changeSizeAs(y).normalize(norm);
+ monitors.log("PSF: " + h.dimAsString());
+
+ monitors.log("PSF: normalization " + (norm <= 0 ? "no" : norm));
String iterations = (isIterative() ? controller.getIterationMax() + " iterations" : "direct");
monitors.log(getShortname() + " is starting (" + iterations + ")");
- y = image.duplicate();
- h = psf.duplicate();
controller.setMonitors(monitors);
controller.start(y);
h = Operations.circularShift(h);
if (fft == null)
fft = FFT.createDefaultFFT(monitors, y.nx, y.ny, y.nz);
else
fft.init(monitors, y.nx, y.ny, y.nz);
monitors.log(getShortname() + " data ready");
double params[] = getParameters();
if (params != null) {
if (params.length > 0) {
String s = " ";
for (double param : params)
s += "" + param + " ";
monitors.log(getShortname() + s);
}
}
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();
}
controller.finish(x);
monitors.log(getName() + " is finished");
- return x;
+
+ RealSignal result = pad.crop(monitors, x);
+
+ return result;
}
public AbstractFFT getFFT() {
return fft;
}
public void setFFT(AbstractFFT fft) {
this.fft = fft;
}
public Controller getController() {
return controller;
}
public void setController(Controller controller) {
this.controller = controller;
controller.setAlgorithm(getName());
}
public int getIterations() {
return controller.getIterations();
}
public double getTime() {
return controller.getTimeNano();
}
public double getMemory() {
return controller.getMemory();
}
public void setWavelets(String waveletsName) {
}
@Override
public String toString() {
String s = "";
s += getName();
s += (isIterative() ? ", " + controller.getIterationMax() + " iterations" : " (direct)");
s += (isRegularized() ? ", &lambda=" + NumFormat.nice(getRegularizationFactor()) : "");
s += (isStepControllable() ? ", &gamma=" + NumFormat.nice(getStepFactor()) : "");
return s;
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/Constants.java b/DeconvolutionLab2/src/deconvolutionlab/Constants.java
index 97dc944..cabd770 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/Constants.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/Constants.java
@@ -1,65 +1,65 @@
/*
* 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.Dimension;
public class Constants {
public static String name = "DeconvolutionLab2 [Beta 1]";
public static String copyright = "\u00A9 2010-2017. Biomedical Imaging Group, EPFL.";
public static String url = "http://bigwww.epfl.ch/deconvolution/";
public static String reference =
"D. Sage, L. Donati, F. Soulez, D. Fortun, A. Seitz, R. Guiet, C. Vonesch, M Unser " +
"DeconvolutionLab2 : An open-source software for deconvolution microscopy " +
"Methods, 2017.";
- public static String version = "(Beta 24.01.2017)";
+ public static String version = "(Beta 11.02.2017)";
public static String authors =
"Daniel Sage, " +
"Cédric Vonesch, " +
"Guillaume Schmit, " +
"Pierre Besson, " +
"Raquel Terrés Cristofani, " +
"Alessandra Griffa";
public static String help =
"<h1>" + name + "</h1>" +
"<h2>" + version + "</h2>";
public static int widthGUI = 500;
public static Dimension dimParameters = new Dimension(88, 25);
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/Lab.java b/DeconvolutionLab2/src/deconvolutionlab/Lab.java
index 2d2504b..5b81719 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/Lab.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/Lab.java
@@ -1,363 +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;
import java.io.File;
import java.util.ArrayList;
import java.util.regex.Pattern;
import javax.swing.JFrame;
import deconvolution.algorithm.Controller;
import deconvolutionlab.PlatformImager.ContainerImage;
import deconvolutionlab.monitor.Monitors;
import fft.AbstractFFT;
import fft.AbstractFFTLibrary;
import fft.FFT;
import imagej.IJImager;
import lab.component.CustomizedColumn;
import lab.component.CustomizedTable;
import lab.tools.NumFormat;
import lab.tools.WebBrowser;
import plugins.sage.deconvolutionlab.IcyImager;
import signal.ComplexComponent;
import signal.ComplexSignal;
import signal.RealSignal;
import signal.factory.Sphere;
public class Lab {
private static PlatformImager imager;
private static Lab instance = null;
private static Platform platform = Platform.IMAGEJ;
private static CustomizedTable tableStats = null;
private static JFrame frameStats = null;
static {
imager = new IJImager();
createStats();
}
private static void createStats() {
ArrayList<CustomizedColumn> columns = new ArrayList<CustomizedColumn>();
columns.add(new CustomizedColumn("Name", String.class, 100, false));
columns.add(new CustomizedColumn("Algorithm", String.class, 100, false));
columns.add(new CustomizedColumn("Iterations", String.class, 100, false));
columns.add(new CustomizedColumn("Image Mean", String.class, 100, false));
columns.add(new CustomizedColumn("Image Minimum", String.class, 100, false));
columns.add(new CustomizedColumn("Image Maximum", String.class, 100, false));
columns.add(new CustomizedColumn("Image Stdev", String.class, 100, false));
columns.add(new CustomizedColumn("Image norm1", String.class, 100, false));
columns.add(new CustomizedColumn("Image norm2", 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("Peak", 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));
tableStats = new CustomizedTable(columns, true);
}
public static Platform getPlatform() {
return platform;
}
public static void getInstance(Platform p) {
platform = p;
if (instance == null) {
instance = new Lab();
switch (p) {
case STANDALONE:
imager = new LabImager();
break;
case IMAGEJ:
imager = new IJImager();
break;
case ICY:
imager = new IcyImager();
break;
default:
imager = new LabImager();
break;
}
}
}
public static void help() {
WebBrowser.open(Constants.url);
}
public static void checkFFT(Monitors monitors) {
ArrayList<AbstractFFTLibrary> libraries = FFT.getInstalledLibraries();
for (int k = 1; k <= 3; k++)
for (AbstractFFTLibrary library : libraries) {
RealSignal y = new Sphere(3, 1).generate(40, 30, 20);
double chrono = System.nanoTime();
- AbstractFFT fft = FFT.createDefaultFFT(monitors, y.nx, y.ny, y.nz);
+ 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(fft.getName() + " Test " + k);
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 imager.createContainer(title);
}
public static void append(Monitors monitors, ContainerImage container, RealSignal signal, String title) {
imager.append(container, signal, title);
monitors.log("Add Live Real Signal " + title);
}
public static void append(Monitors monitors, ContainerImage container, RealSignal signal, String title, PlatformImager.Type type) {
imager.append(container, signal, title, type);
monitors.log("Add Live Real Signal " + 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);
imager.show(signal, title);
}
public static void show(Monitors monitors, ComplexSignal signal, String title, ComplexComponent complex) {
if (signal == null) {
monitors.error("Show " + title + " this image does not exist.");
return;
}
monitors.log("Show Real Signal " + title);
imager.show(signal, title, complex);
}
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);
imager.show(signal, title);
}
public static void show(Monitors monitors, RealSignal signal, String title, PlatformImager.Type type) {
if (signal == null) {
monitors.error("Show " + title + " this image does not exist.");
return;
}
monitors.log("Show Real Signal " + title);
imager.show(signal, title, type);
}
public static void show(Monitors monitors, RealSignal signal, String title, PlatformImager.Type type, int z) {
if (signal == null) {
monitors.error("Show " + title + " this image does not exist.");
return;
}
monitors.log("Show Real Signal " + title);
imager.show(signal, title, type);
}
public static void save(Monitors monitors, RealSignal signal, String filename) {
imager.save(signal, filename);
monitors.log("Save Real Signal " + filename);
}
public static void save(Monitors monitors, RealSignal signal, String filename, PlatformImager.Type type) {
imager.save(signal, filename, type);
monitors.log("Save Real Signal " + filename);
}
public static void firstStats(Monitors monitors, String name, Controller controller, boolean show, boolean save) {
if (controller == null)
return;
Lab.createStats();
if (show) {
frameStats = new JFrame(name);
frameStats.getContentPane().add(tableStats.getPane(600, 200));
frameStats.pack();
frameStats.setVisible(true);
}
nextStats(monitors, "Start", controller, show, save);
}
public static void nextStats(Monitors monitors, String name, Controller controller, boolean show, boolean save) {
if (tableStats == null)
return;
if (controller == null)
return;
tableStats.append(controller.stats(name));
monitors.log("Stats " + name);
if (show && frameStats != null) {
if (!frameStats.isVisible())
frameStats.setVisible(true);
frameStats.requestFocus();
}
}
public static void lastStats(Monitors monitors, String filename, Controller controller, boolean show, boolean save) {
if (controller == null)
return;
if (tableStats == null)
return;
nextStats(monitors, "End", controller, show, save);
if (save) {
monitors.log("Stats " + filename);
tableStats.saveCSV(filename + ".csv");
}
}
public static RealSignal open(Monitors monitors, String filename) {
RealSignal signal = imager.open(filename);
if (signal == null)
monitors.error("Unable to open " + filename);
else
monitors.log("Load " + filename);
return signal;
}
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 = imager.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(nx, ny, nz);
for (int z = 0; z < slices.size(); z++)
signal.setSlice(z, slices.get(z));
return signal;
}
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;
}
imager.show(signal.createOrthoview(hx, hy, hz), title);
}
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;
imager.show(signal.createOrthoview(hx, hy, hz), title);
}
public static void showMIP(Monitors monitors, RealSignal signal, String title) {
if (signal == null) {
monitors.error("Show MIP " + title + " this image does not exist.");
return;
}
imager.show(signal.createMIP(), title);
}
public static void showMontage(Monitors monitors, RealSignal signal, String title) {
if (signal == null) {
monitors.error("Show Montage " + title + " this image does not exist.");
return;
}
imager.show(signal.createMontage(), title);
}
public static RealSignal create(Monitors monitors, String name) {
RealSignal signal = imager.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 RealSignal create(Monitors monitors) {
RealSignal signal = imager.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 PlatformImager getImager() {
return imager;
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/modules/LanguageModule.java b/DeconvolutionLab2/src/deconvolutionlab/modules/LanguageModule.java
index f3e67fd..d846d99 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/modules/LanguageModule.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/modules/LanguageModule.java
@@ -1,213 +1,211 @@
/*
* 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.FlowLayout;
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.JComboBox;
import javax.swing.JPanel;
import javax.swing.JTextField;
import deconvolution.Command;
import deconvolution.Token;
import deconvolutionlab.Config;
import lab.component.HTMLPane;
public class LanguageModule extends AbstractModule implements ActionListener {
private HTMLPane language;
private JComboBox<String> cmb;
private JComboBox<String> gui;
private JTextField txt;
public LanguageModule(boolean expanded) {
super("Language", "", "", "", expanded);
}
@Override
public JPanel buildExpandedPanel() {
language = new HTMLPane("Monaco", 100, 100);
cmb = new JComboBox<String>(new String[] { "Command line", "ImageJ Macro", "Java", "Matlab" });
gui = new JComboBox<String>(new String[] { "Run (Headless)", "Launch (with control panel)" });
txt = new JTextField("Job", 8);
JPanel pn = new JPanel(new FlowLayout());
pn.add(txt);
pn.add(cmb);
pn.add(gui);
JPanel panel = new JPanel(new BorderLayout());
panel.add(pn, BorderLayout.NORTH);
panel.add(language.getPane(), BorderLayout.CENTER);
cmb.addActionListener(this);
gui.addActionListener(this);
Config.register(getName(), "language", cmb, cmb.getItemAt(0));
Config.register(getName(), "headless", gui, gui.getItemAt(0));
Config.register(getName(), "job", txt, "Job");
language.clear();
return panel;
}
@Override
public void expand() {
super.expand();
update();
}
public void update() {
if (cmb.getSelectedIndex() == 0) {
language.clear();
- String mode = "java -jar DeconvolutionLab_2.jar ";
- if (gui.getSelectedIndex() == 0)
- mode += " Run ";
- else
- mode += " Launch ";
- language.append("p", mode + Command.command());
+ String run = gui.getSelectedIndex() == 0 ? " Run " : " Launch ";
+ language.append("p", "java -jar DeconvolutionLab_2.jar " + run + Command.command());
+ language.append("p", "");
+ language.append("p", "java -cp JTransforms.jar:DeconvolutionLab_2.jar DeconvolutionLab2 "+ run + Command.command());
}
else if (cmb.getSelectedIndex() == 1) {
language.clear();
language.append("p", imagej(gui.getSelectedIndex() == 0));
}
else if (cmb.getSelectedIndex() == 2) {
language.clear();
language.append("p", java(gui.getSelectedIndex() == 0));
}
else if (cmb.getSelectedIndex() == 3) {
language.clear();
String text = "Matlab code, not yet implemented";
language.append("p", text);
}
}
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
if (e.getSource() == cmb)
update();
if (e.getSource() == gui)
update();
}
@Override
public void close() {
}
@Override
public void setCommand(String command) {
update();
}
@Override
public String getCommand() {
return "";
}
private String imagej(boolean headless) {
String job = txt.getText();
String macro = "<p>// Job: " + job + " </p>";
macro += "<p>// Macro generated by DeconvolutionLab2 </p>";
macro += "<p>// " + new SimpleDateFormat("dd/MM/yy HH:m:s").format(new Date()) + " </p>";
String param = "<p>parameters = \"\"</p>";
ArrayList<Token> tokens = Command.parse(Command.command());
String image = "image = \" NOT DEFINED \" ";
String psf = "psf = \" NOT DEFINED \" ";
String algo = "algo = \" NOT DEFINED \" ";
for (Token token : tokens) {
if (token.keyword.equals("-image"))
image = "<p>image = \" -image " + token.parameters.trim() + "\" </p>";
else if (token.keyword.equals("-psf"))
psf = "<p>psf = \" -psf " + token.parameters.trim() + "\" </p>";
else if (token.keyword.equals("-algorithm"))
algo = "<p>algorithm = \" -algorithm " + token.parameters.trim() + "\" </p>";
else
param += "<p>parameters += \" " + token.keyword + " " + token.parameters.trim() + "\" </p>";
}
String option = macro + image + psf + algo + param;
String cmd = "";
if (headless)
cmd = "<p>run(\"DeconvolutionLab2 Run\", image + psf + algorithm + parameters)</p>";
else
cmd = "<p>run(\"DeconvolutionLab2 Launch\", image + psf + algorithm + parameters)</p>";
return option + cmd;
}
private String java(boolean headless) {
String job = txt.getText();
String p = headless ? ".deconvolve(false);" : ".launch(\"" + job + "\", false);";
String tab1 = "<p style=\"padding-left:10px\">";
String tab2 = "<p style=\"padding-left:20px\">";
String code = "";
code += "<p>import deconvolution.Deconvolution;</p>";
code += "<p>import ij.plugin.PlugIn;</p>";
code += "<p></p>";
code += "<p>public class DeconvolutionLab2_" + job + " implements PlugIn {</p>";
code += tab1 + "public DeconvolutionLab2_" + job + "() {</p>";
String param = tab2 + "String parameters = \"\";</p>";
ArrayList<Token> tokens = Command.parse(Command.command());
String image = tab2 + "String image = \" NOT DEFINED \";";
String psf = tab2 + "String psf = \" NOT DEFINED \";";
String algo = tab2 + "String algo = \" NOT DEFINED \";";
for (Token token : tokens) {
if (token.keyword.equals("-image"))
image = tab2 + "String image = \" -image " + token.parameters.trim() + "\";</p>";
else if (token.keyword.equals("-psf"))
psf = tab2 + "String psf = \" -psf " + token.parameters.trim() + "\";</p>";
else if (token.keyword.equals("-algorithm"))
algo = tab2 + "String algorithm = \" -algorithm " + token.parameters.trim() + "\";</p>";
else
param += tab2 + "parameters += \" " + token.keyword + " " + token.parameters.trim() + "\";</p>";
}
code += image + psf + algo + param;
code += tab2 + "new Deconvolution(image + psf + algorithm + parameters)" + p;
code += tab1 + "}</p>";
code += tab1 + "<p></p>";
code += tab1 + "@Override</p>";
code += tab1 + "public void run(String arg0) {</p>";
code += tab2 + " new DeconvolutionLab2_" + job + "();</p>";
code += tab1 + "}</p>";
code += "<p>}</p>";
return code;
}
}
diff --git a/DeconvolutionLab2/src/fft/AbstractFFTLibrary.java b/DeconvolutionLab2/src/fft/AbstractFFTLibrary.java
index b319369..60355ba 100644
--- a/DeconvolutionLab2/src/fft/AbstractFFTLibrary.java
+++ b/DeconvolutionLab2/src/fft/AbstractFFTLibrary.java
@@ -1,55 +1,57 @@
/*
* 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 fft;
import java.util.ArrayList;
public abstract class AbstractFFTLibrary {
protected boolean installed = false;
protected ArrayList<AbstractFFT> ffts = new ArrayList<AbstractFFT>();
-
+
+ public abstract AbstractFFT getDefaultFFT();
+
public abstract String getLibraryName();
public abstract String getCredit();
public abstract String getLicence();
public abstract boolean isMultithreadable();
public abstract String getLocation();
public boolean isInstalled() {
return installed;
}
public ArrayList<AbstractFFT> getFFTs() {
return ffts;
}
}
diff --git a/DeconvolutionLab2/src/fft/academic/AcademicLibrary.java b/DeconvolutionLab2/src/fft/academic/AcademicLibrary.java
index 05c3b9c..7134c58 100644
--- a/DeconvolutionLab2/src/fft/academic/AcademicLibrary.java
+++ b/DeconvolutionLab2/src/fft/academic/AcademicLibrary.java
@@ -1,76 +1,82 @@
/*
* 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 fft.academic;
+import fft.AbstractFFT;
import fft.AbstractFFTLibrary;
public class AcademicLibrary extends AbstractFFTLibrary {
public AcademicLibrary() {
installed = true;
if (installed) {
ffts.add(new Academic());
ffts.add(new AcademicFFT_XYZ());
ffts.add(new AcademicFFT_XY_Z());
}
}
@Override
public String getLocation() {
return AcademicLibrary.class.getCanonicalName();
}
@Override
public boolean isMultithreadable() {
return false;
}
@Override
public String getCredit() {
return "http://bigwww.epfl.ch/thevenaz/academicFFT/ (P. Thévenaz)";
}
@Override
public String getLicence() {
String licence = "<h1>AcademicFFT of Philippe Thévenaz, EPFL.</h1>";
licence += "<p>EPFL makes no warranties of any kind on this software and ";
licence += "shall in no event be liable for damages of any kind in ";
licence += "connection with the use and exploitation of this technology.</p>";
return licence;
}
@Override
public String getLibraryName() {
return "Academic";
}
+
+ @Override
+ public AbstractFFT getDefaultFFT() {
+ return new Academic();
+ }
}
diff --git a/DeconvolutionLab2/src/fft/fftw/FFTWLibrary.java b/DeconvolutionLab2/src/fft/fftw/FFTWLibrary.java
index 2691b8d..2810e2b 100644
--- a/DeconvolutionLab2/src/fft/fftw/FFTWLibrary.java
+++ b/DeconvolutionLab2/src/fft/fftw/FFTWLibrary.java
@@ -1,201 +1,207 @@
/*
* 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 fft.fftw;
import java.io.File;
import java.security.CodeSource;
import deconvolutionlab.monitor.Monitors;
+import fft.AbstractFFT;
import fft.AbstractFFTLibrary;
import jfftw.complex.nd.Plan;
public class FFTWLibrary extends AbstractFFTLibrary {
private String location;
public FFTWLibrary(Monitors monitors) {
String path = "";
boolean found = false;
if (!found) {
try {
CodeSource code = FFTWLibrary.class.getProtectionDomain().getCodeSource();
File file = new File(code.getLocation().toURI().getPath());
path = file.getParentFile().getPath() + File.separator + "FFTW" + File.separator;
found = existsWidsom(monitors, path);
location = path;
}
catch (Exception ex) {
monitors.log("FFTW Widsom not found in : " + path);
location = "Not found in " + path;
found = false;
}
}
if (!found) {
try {
CodeSource code = FFTWLibrary.class.getProtectionDomain().getCodeSource();
File file = new File(code.getLocation().toURI().getPath());
path = file.getParentFile().getPath() + File.separator;
found = existsWidsom(monitors, path);
location = path;
}
catch (Exception ex) {
monitors.log("FFTW Widsom not found in : " + path);
location = "Not found in " + path;
found = false;
}
}
if (!found) {
try {
path = System.getProperty("user.home") + File.separator + "FFTW" + File.separator;
found = existsWidsom(monitors, path);
location = path;
}
catch (Exception ex) {
monitors.log("FFTW Widsom not found in : " + path);
location = "Not found in " + path;
found = false;
}
}
if (!found) {
try {
path = System.getProperty("user.home") + File.separator;
found = existsWidsom(monitors, path);
location = path;
}
catch (Exception ex) {
monitors.log("FFTW Widsom not found in : " + path);
location = "Not found in " + path;
found = false;
}
}
if (!found)
return;
loadLibraries(monitors, path);
try {
new Plan(new int[] { 20, 20, 20 }, Plan.FORWARD, Plan.ESTIMATE | Plan.IN_PLACE | Plan.USE_WISDOM);
ffts.add(new FFTW3D());
installed = true;
}
catch (UnsatisfiedLinkError ex) {
ex.printStackTrace();
installed = false;
}
}
@Override
public String getLocation() {
return location;
}
@Override
public boolean isMultithreadable() {
return true;
}
@Override
public String getCredit() {
return "http://www.fftw.org (FFTW Version 2)";
}
@Override
public String getLibraryName() {
return "FFTW2";
}
@Override
public String getLicence() {
return "<h1>FFTW Version 2, " + "<p>http://www.fftw.org" + "<p>FFTW 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 2 of the License, or " + "(at your option) any later version.";
}
private static void loadLibraries(Monitors monitors, String path) {
try {
String osname = System.getProperty("os.name");
if (osname.startsWith("Linux")) {
String osarch = System.getProperty("os.arch");
if (osarch.contains("64")) {
System.load(path + "libFFTWJNI64.so");
monitors.log("Loading library FFTW for " + osarch + " " + osname + " " + path + "libFFTWJNI64.so");
}
else {
System.load(path + "libFFTWJNI32.so");
monitors.log("Loading library FFTW for " + osarch + " " + osname + " " + path + "libFFTWJNI32.so");
}
}
else if (osname.startsWith("Windows")) {
String osarch = System.getProperty("os.arch");
if (osarch.contains("64")) {
System.load(path + "FFTWJNIWin64.dll");
monitors.log("Loading library FFTW for " + osarch + " " + osname + " " + path + "FFTWJNIWin64.dll");
}
else {
System.load(path + "FFTWJNIWin32.dll");
monitors.log("Loading library FFTW for " + osarch + " " + osname + " " + path + "FFTWJNIWin32.dll");
}
}
else if (osname.startsWith("Mac")) {
System.load(path + "libFFTWJNIMac.jnilib");
monitors.log("Loading library FFTW for " + osname + " " + path + "libFFTWJNIMac.jnilib");
}
else {
monitors.log("FFTW is not provided for the architecture : " + osname);
}
}
catch (Exception ex) {
monitors.log("FFTW not found in : " + path);
System.out.println(">>" + ex.toString());
}
}
private static boolean existsWidsom(Monitors monitors, String path) {
boolean found = false;
if (new File(path + "Wisdom").exists()) {
monitors.log("FFTW found in : " + path);
found = true;
}
else {
monitors.log("FFTW Widsom not found in : " + path);
found = false;
}
return found;
}
+
+ @Override
+ public AbstractFFT getDefaultFFT() {
+ return new FFTW3D();
+ }
}
diff --git a/DeconvolutionLab2/src/fft/jtransforms/JTransforms.java b/DeconvolutionLab2/src/fft/jtransforms/JTransforms.java
index b4c217b..98f47b4 100644
--- a/DeconvolutionLab2/src/fft/jtransforms/JTransforms.java
+++ b/DeconvolutionLab2/src/fft/jtransforms/JTransforms.java
@@ -1,89 +1,89 @@
/*
* 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 fft.jtransforms;
import deconvolutionlab.monitor.Monitors;
-import edu.emory.mathcs.jtransforms.fft.FloatFFT_2D;
-import edu.emory.mathcs.jtransforms.fft.FloatFFT_3D;
+import org.jtransforms.fft.FloatFFT_2D;
+import org.jtransforms.fft.FloatFFT_3D;
import fft.AbstractFFT;
import fft.Separability;
import signal.ComplexSignal;
import signal.RealSignal;
public class JTransforms extends AbstractFFT {
private FloatFFT_3D fftXYZ = null;
private FloatFFT_2D fftXY = null;
public JTransforms() {
super(Separability.XYZ);
}
@Override
public void init(Monitors monitors, int nx, int ny, int nz) {
super.init(monitors, nx, ny, nz);
try {
if (nz > 1)
fftXYZ = new FloatFFT_3D(nz, ny, nx);
else
fftXY = new FloatFFT_2D(ny, nx);
}
catch (Exception ex) {
System.out.println("check " + ex + ". " + nx + " " + ny + " " + nz);
}
}
@Override
public void transformInternal(RealSignal x, ComplexSignal X) {
float[] interleave = x.getInterleaveXYZAtReal();
if (fftXYZ != null)
fftXYZ.complexForward(interleave);
if (fftXY != null)
fftXY.complexForward(interleave);
X.setInterleaveXYZ(interleave);
}
@Override
public void inverseInternal(ComplexSignal X, RealSignal x) {
float[] interleave = X.getInterleaveXYZ();
if (fftXYZ != null)
fftXYZ.complexInverse(interleave, true);
if (fftXY != null)
fftXY.complexInverse(interleave, true);
x.setInterleaveXYZAtReal(interleave);
}
@Override
public String getName() {
return "JTransforms";
}
}
diff --git a/DeconvolutionLab2/src/fft/jtransforms/JTransformsFFT_XYZ.java b/DeconvolutionLab2/src/fft/jtransforms/JTransformsFFT_XYZ.java
index 7a4d126..5982742 100644
--- a/DeconvolutionLab2/src/fft/jtransforms/JTransformsFFT_XYZ.java
+++ b/DeconvolutionLab2/src/fft/jtransforms/JTransformsFFT_XYZ.java
@@ -1,89 +1,89 @@
/*
* 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 fft.jtransforms;
import deconvolutionlab.monitor.Monitors;
-import edu.emory.mathcs.jtransforms.fft.FloatFFT_2D;
-import edu.emory.mathcs.jtransforms.fft.FloatFFT_3D;
+import org.jtransforms.fft.FloatFFT_2D;
+import org.jtransforms.fft.FloatFFT_3D;
import fft.AbstractFFT;
import fft.Separability;
import signal.ComplexSignal;
import signal.RealSignal;
public class JTransformsFFT_XYZ extends AbstractFFT {
private FloatFFT_3D fftXYZ = null;
private FloatFFT_2D fftXY = null;
public JTransformsFFT_XYZ() {
super(Separability.XYZ);
}
@Override
public void init(Monitors monitors, int nx, int ny, int nz) {
super.init(monitors, nx, ny, nz);
try {
if (nz > 1)
fftXYZ = new FloatFFT_3D(nz, ny, nx);
else
fftXY = new FloatFFT_2D(ny, nx);
}
catch (Exception ex) {
System.out.println("check " + ex + ". " + nx + " " + ny + " " + nz);
}
}
@Override
public void transformInternal(RealSignal x, ComplexSignal X) {
float[] interleave = x.getInterleaveXYZAtReal();
if (fftXYZ != null)
fftXYZ.complexForward(interleave);
if (fftXY != null)
fftXY.complexForward(interleave);
X.setInterleaveXYZ(interleave);
}
@Override
public void inverseInternal(ComplexSignal X, RealSignal x) {
float[] interleave = X.getInterleaveXYZ();
if (fftXYZ != null)
fftXYZ.complexInverse(interleave, true);
if (fftXY != null)
fftXY.complexInverse(interleave, true);
x.setInterleaveXYZAtReal(interleave);
}
@Override
public String getName() {
return "JTransforms XYZ";
}
}
diff --git a/DeconvolutionLab2/src/fft/jtransforms/JTransformsFFT_XY_Z.java b/DeconvolutionLab2/src/fft/jtransforms/JTransformsFFT_XY_Z.java
index 2ba6295..8403988 100644
--- a/DeconvolutionLab2/src/fft/jtransforms/JTransformsFFT_XY_Z.java
+++ b/DeconvolutionLab2/src/fft/jtransforms/JTransformsFFT_XY_Z.java
@@ -1,102 +1,103 @@
/*
* 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 fft.jtransforms;
+import org.jtransforms.fft.FloatFFT_1D;
+import org.jtransforms.fft.FloatFFT_2D;
+
import deconvolutionlab.monitor.Monitors;
-import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D;
-import edu.emory.mathcs.jtransforms.fft.FloatFFT_2D;
import fft.AbstractFFT;
import fft.Separability;
import signal.ComplexSignal;
import signal.RealSignal;
public class JTransformsFFT_XY_Z extends AbstractFFT {
private FloatFFT_2D fftXY = null;
private FloatFFT_1D fftZ = null;
public JTransformsFFT_XY_Z() {
super(Separability.XY_Z);
}
@Override
public void init(Monitors monitors, int nx, int ny, int nz) {
super.init(monitors, nx, ny, nz);
try {
fftXY = new FloatFFT_2D(ny, nx);
if (nz > 1)
fftZ = new FloatFFT_1D(nz);
}
catch (Exception ex) {
}
}
@Override
public void transformInternal(RealSignal x, ComplexSignal X) {
for (int k = 0; k < nz; k++) {
float interleave[] = x.getInterleaveXYAtReal(k);
fftXY.complexForward(interleave);
X.setInterleaveXY(k, interleave);
}
if (fftZ == null)
return;
for (int i = 0; i < nx; i++)
for (int j = 0; j < ny; j++) {
float interleave[] = X.getInterleaveZ(i, j);
fftZ.complexForward(interleave);
X.setInterleaveZ(i, j, interleave);
}
}
@Override
public void inverseInternal(ComplexSignal X, RealSignal x) {
for (int k = 0; k < nz; k++) {
float interleave[] = X.getInterleaveXY(k);
fftXY.complexInverse(interleave, true);
X.setInterleaveXY(k, interleave);
}
if (fftZ != null) {
for (int i = 0; i < nx; i++)
for (int j = 0; j < ny; j++) {
float interleave[] = X.getInterleaveZ(i, j);
fftZ.complexInverse(interleave, true);
X.setInterleaveZ(i, j, interleave);
}
}
x = X.getRealSignal();
}
@Override
public String getName() {
return "JTransforms XY_Z";
}
}
diff --git a/DeconvolutionLab2/src/fft/jtransforms/JTransformsLibrary.java b/DeconvolutionLab2/src/fft/jtransforms/JTransformsLibrary.java
index 51829bb..33ec577 100644
--- a/DeconvolutionLab2/src/fft/jtransforms/JTransformsLibrary.java
+++ b/DeconvolutionLab2/src/fft/jtransforms/JTransformsLibrary.java
@@ -1,79 +1,87 @@
/*
* 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 fft.jtransforms;
+import fft.AbstractFFT;
import fft.AbstractFFTLibrary;
public class JTransformsLibrary extends AbstractFFTLibrary {
public JTransformsLibrary() {
+ System.out.println("JTransformsLibrary");
try {
- Class.forName("edu.emory.mathcs.jtransforms.fft.FloatFFT_3D");
- Class.forName("edu.emory.mathcs.jtransforms.fft.FloatFFT_1D");
- Class.forName("edu.emory.mathcs.jtransforms.fft.FloatFFT_2D");
+ Class.forName("org.jtransforms.fft.FloatFFT_3D");
+ Class.forName("org.jtransforms.fft.FloatFFT_1D");
+ Class.forName("org.jtransforms.fft.FloatFFT_2D");
installed = true;
}
catch (ClassNotFoundException ex) {
+ System.out.println("" + ex);
installed = false;
}
if (installed) {
ffts.add(new JTransforms());
ffts.add(new JTransformsFFT_XYZ());
ffts.add(new JTransformsFFT_XY_Z());
}
}
@Override
public String getLocation() {
return JTransformsLibrary.class.getCanonicalName();
}
@Override
public boolean isMultithreadable() {
return true;
}
@Override
public String getCredit() {
return "JTransforms of Piotr Wendykier";
}
@Override
public String getLibraryName() {
return "JTransforms";
}
@Override
public String getLicence() {
return "<h1>JTransforms of Piotr Wendykier</h1>" + "<p>https://sites.google.com/site/piotrwendykier/software/jtransforms" + "<p>JTransforms is distributed under the terms of the BSD-2-Clause license." + "<p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " + "AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT " + "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS" + "FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT " + "HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, " + "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED " + "TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; " + "OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, " + "WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR " + "OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED " + "OF THE POSSIBILITY OF SUCH DAMAGE.";
}
+
+ @Override
+ public AbstractFFT getDefaultFFT() {
+ return new JTransforms();
+ }
}
diff --git a/DeconvolutionLab2/src/signal/padding/Padding.java b/DeconvolutionLab2/src/signal/padding/Padding.java
index 414c636..413f447 100644
--- a/DeconvolutionLab2/src/signal/padding/Padding.java
+++ b/DeconvolutionLab2/src/signal/padding/Padding.java
@@ -1,250 +1,250 @@
/*
* 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.padding;
import java.util.ArrayList;
import deconvolutionlab.monitor.Monitors;
import signal.RealSignal;
public class Padding {
private AbstractPadding padX = getDefault();
private AbstractPadding padY = getDefault();
private AbstractPadding padZ = getDefault();
private int minExtensionX = 0;
private int minExtensionY = 0;
private int minExtensionZ = 0;
private int nx = -1;
private int ny = -1;
private int nz = -1;
public Padding() {
padX = new NoPadding();
padY = new NoPadding();
padZ = new NoPadding();
this.minExtensionX = 0;
this.minExtensionY = 0;
this.minExtensionZ = 0;
}
public Padding(int minExtensionX, int minExtensionY, int minExtensionZ) {
padX = new NoPadding();
padY = new NoPadding();
padZ = new NoPadding();
this.minExtensionX = minExtensionX;
this.minExtensionY = minExtensionY;
this.minExtensionZ = minExtensionZ;
}
public Padding(AbstractPadding padX, AbstractPadding padY, AbstractPadding padZ, int minExtensionX, int minExtensionY, int minExtensionZ) {
this.padX = padX;
this.padY = padY;
this.padZ = padZ;
this.minExtensionX = minExtensionX;
this.minExtensionY = minExtensionY;
this.minExtensionZ = minExtensionZ;
}
public Padding(AbstractPadding pad, int extension) {
this.padX = pad;
this.padY = pad;
this.padZ = pad;
this.minExtensionX = extension;
this.minExtensionY = extension;
this.minExtensionZ = extension;
}
public Padding(String nameX, String nameY, String nameZ, int minExtensionX, int minExtensionY, int minExtensionZ) {
for(AbstractPadding pad : getPaddings()) {
if (pad.getName().equals(nameX))
padX = pad;
if (pad.getName().equals(nameY))
padY = pad;
if (pad.getName().equals(nameZ))
padZ = pad;
if (pad.getShortname().equals(nameX))
padX = pad;
if (pad.getShortname().equals(nameY))
padY = pad;
if (pad.getShortname().equals(nameZ))
padZ = pad;
this.minExtensionX = minExtensionX;
this.minExtensionY = minExtensionY;
this.minExtensionZ = minExtensionZ;
}
}
public static ArrayList<AbstractPadding> getPaddings() {
ArrayList<AbstractPadding> pads = new ArrayList<AbstractPadding>();
pads.add(new NoPadding());
pads.add(new Multiple2Padding());
pads.add(new Power2Padding());
pads.add(new Multiple23Padding());
pads.add(new Multiple235Padding());
return pads;
}
public static ArrayList<String> getPaddingsName() {
ArrayList<AbstractPadding> pads = getPaddings();
ArrayList<String> names = new ArrayList<String>();
for(AbstractPadding pad : pads)
names.add(pad.getName());
return names;
}
public static String[] getPaddingsAsArray() {
ArrayList<AbstractPadding> pads = getPaddings();
String names[] = new String[pads.size()];
for(int i=0; i<pads.size(); i++)
names[i] = pads.get(i).getName();
return names;
}
public static AbstractPadding getByName(String name) {
ArrayList<AbstractPadding> pads = getPaddings();
for(AbstractPadding pad : pads)
if (name.equals(pad.getName()))
return pad;
return getDefault();
}
public static AbstractPadding getByShortname(String name) {
ArrayList<AbstractPadding> pads = getPaddings();
for(AbstractPadding pad : pads)
if (name.equals(pad.getShortname()))
return pad;
return getDefault();
}
public static AbstractPadding getDefault() {
return new NoPadding();
}
public int[] pad(int nx, int ny, int nz) {
return new int[] { padX.padding(nx+minExtensionX), padY.padding(ny+minExtensionY), padZ.padding(nz+minExtensionZ)};
}
public RealSignal pad(Monitors monitors, RealSignal input) {
if (padX instanceof NoPadding && padY instanceof NoPadding &&
padZ instanceof NoPadding && (minExtensionX + minExtensionY + minExtensionZ == 0)) {
nx = ny = nz = -1;
- return input;
+ return input.duplicate();
}
nx = input.nx;
ny = input.ny;
nz = input.nz;
int lx = padX.padding(nx+minExtensionX);
int ly = padY.padding(ny+minExtensionY);
int lz = padZ.padding(nz+minExtensionZ);
monitors.log("Padding to (" + lx + ", " + ly + ", " + lz + ")");
if (lx == nx)
if (ly == ny)
if (lz == nz)
- return input;
+ return input.duplicate();
int ox = (lx - nx) / 2;
int oy = (ly - ny) / 2;
int oz = (lz - nz) / 2;
RealSignal large = new RealSignal(lx, ly, lz);
for(int k=0; k<nz; k++) {
float in[] = input.data[k];
float lpix[] = large.data[k+oz];
for(int i=0; i<nx; i++)
for(int j=0; j<ny; j++)
lpix[(i+ox) + lx*(j+oy)] = in[i + nx*j];
}
return large;
}
public RealSignal crop(Monitors monitors, RealSignal large) {
if (nx == -1 || ny == -1 || nz == -1) {
return large;
}
int lx = large.nx;
int ly = large.ny;
int lz = large.nz;
int ox = (lx - nx) / 2;
int oy = (ly - ny) / 2;
int oz = (lz - nz) / 2;
if (lx == nx)
if (ly == ny)
if (lz == nz)
return large;
RealSignal output = new RealSignal(nx, ny, nz);
monitors.log("Cropping to (" + nx + ", " + ny + ", " + nz + ")");
for(int k=0; k<nz; k++) {
float lpix[] = large.data[k+oz];
float out[] = output.data[k];
for(int i=0; i<nx; i++)
for(int j=0; j<ny; j++)
out[i + nx*j] = lpix[(i+ox) + lx*(j+oy)];
}
return output;
}
@Override
public String toString() {
String s = "";
s += "lateral (XY)";
if (padX instanceof NoPadding) {
if (minExtensionX == 0)
s += " no padding";
else
s += " extension of " + minExtensionX;
}
else {
s += " enforced to " + padX.getName();
}
s += ", axial (Z)";
if (padZ instanceof NoPadding) {
if (minExtensionZ == 0)
s += " no padding";
else
s += " extension of " + minExtensionZ;
}
else {
s += " enforced to " + padZ.getName();
}
return s;
}
}

Event Timeline