Page MenuHomec4science

No OneTemporary

File Metadata

Created
Thu, Nov 21, 23:24
diff --git a/DeconvolutionLab2/src/DL2.java b/DeconvolutionLab2/src/DL2.java
index ec123d7..6df7b4d 100644
--- a/DeconvolutionLab2/src/DL2.java
+++ b/DeconvolutionLab2/src/DL2.java
@@ -1,252 +1,252 @@
/*
* 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 deconvolution.Deconvolution;
import deconvolutionlab.Imager;
import deconvolutionlab.Lab;
import deconvolutionlab.LabDialog;
import ij.ImagePlus;
import ij.WindowManager;
import matlab.Converter;
import signal.RealSignal;
/**
* This class allows Matlab interface for DeconvolutionLab2
*
* A Matlab 3D variable in converted to a RealSignal and vice-versa.
*
- * @author sage
+ * @author Daniel Sage
*
*/
public class DL2 {
public static void lab() {
Lab.init(Imager.Platform.MATLAB, System.getProperty("user.dir") + File.separator + "DeconvolutionLab2.config");
LabDialog dlg = new LabDialog();
Lab.setVisible(dlg, false);
}
public static void run(String command) {
new Deconvolution("Matlab", command).deconvolve();
}
public static void launch(String command) {
new Deconvolution("Matlab", command).launch();
}
public static Object get(String image) {
ImagePlus imp = WindowManager.getCurrentImage();
if (imp != null)
return Converter.get(imp);
return null;
}
public static Object run(Object arrayImage, Object arrayPSF, String algo) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -image platform input -psf platform psf -algorithm " + algo;
Deconvolution d = new Deconvolution("Matlab", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
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();
}
}
public static Object DIV(Object arrayImage, Object arrayPSF) {
return DIV(arrayImage, arrayPSF, "");
}
public static Object DIV(Object arrayImage, Object arrayPSF, String options) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -algorithm DIV " + options;
Deconvolution d = new Deconvolution("Matlab DIV", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
public static Object CONV(Object arrayImage, Object arrayPSF) {
return CONV(arrayImage, arrayPSF, "");
}
public static Object CONV(Object arrayImage, Object arrayPSF, String options) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -algorithm CONV " + options;
Deconvolution d = new Deconvolution("Matlab CONV", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
public static Object NIF(Object arrayImage, Object arrayPSF) {
return NIF(arrayImage, arrayPSF, "");
}
public static Object NIF(Object arrayImage, Object arrayPSF, String options) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -algorithm NIF " + options;
Deconvolution d = new Deconvolution("Matlab NIF", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
public static Object TRIF(Object arrayImage, Object arrayPSF, double regularizationFactor) {
return TRIF(arrayImage, arrayPSF, regularizationFactor, "");
}
public static Object TRIF(Object arrayImage, Object arrayPSF, double regularizationFactor, String options) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -algorithm TRIF " + regularizationFactor + " " + options;
Deconvolution d = new Deconvolution("Matlab TRIF", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
public static Object RIF(Object arrayImage, Object arrayPSF, double regularizationFactor) {
return RIF(arrayImage, arrayPSF, regularizationFactor, "");
}
public static Object RIF(Object arrayImage, Object arrayPSF, double regularizationFactor, String options) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -algorithm RIF " + regularizationFactor + " " + options;
Deconvolution d = new Deconvolution("Matlab RIF", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
public static Object RL(Object arrayImage, Object arrayPSF, double itmax) {
return RL(arrayImage, arrayPSF, itmax, "");
}
public static Object RL(Object arrayImage, Object arrayPSF, double itmax, String options) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -algorithm RL " + itmax + " " + options;
Deconvolution d = new Deconvolution("Matlab RL", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
public static Object RLTV(Object arrayImage, Object arrayPSF, double itmax, double regularizationFactor) {
return RLTV(arrayImage, arrayPSF, itmax, regularizationFactor, "");
}
public static Object RLTV(Object arrayImage, Object arrayPSF, double itmax, double regularizationFactor, String options) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -algorithm RLTV " + itmax + " " + regularizationFactor + " " + options;
Deconvolution d = new Deconvolution("Matlab RLTV", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
public static Object LW(Object arrayImage, Object arrayPSF, double itmax, double gamma) {
return LW(arrayImage, arrayPSF, itmax, gamma, "");
}
public static Object LW(Object arrayImage, Object arrayPSF, double itmax, double gamma, String options) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -algorithm LW " + itmax + " " + gamma + " " + options;
Deconvolution d = new Deconvolution("Matlab LW", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
public static Object NNLS(Object arrayImage, Object arrayPSF, double itmax, double gamma) {
return NNLS(arrayImage, arrayPSF, itmax, gamma, "");
}
public static Object NNLS(Object arrayImage, Object arrayPSF, double itmax, double gamma, String options) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -algorithm NNLS " + itmax + " " + options;
Deconvolution d = new Deconvolution("Matlab NNLS", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
public static Object BVLS(Object arrayImage, Object arrayPSF, double itmax, double gamma) {
return BVLS(arrayImage, arrayPSF, itmax, gamma, "");
}
public static Object BVLS(Object arrayImage, Object arrayPSF, double itmax, double gamma, String options) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -algorithm BVLS " + itmax + " " + options;
Deconvolution d = new Deconvolution("Matlab BVLS", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
public static Object TM(Object arrayImage, Object arrayPSF, double itmax, double gamma, double lambda) {
return TM(arrayImage, arrayPSF, itmax, gamma, lambda, "");
}
public static Object TM(Object arrayImage, Object arrayPSF, double itmax, double gamma, double lambda, String options) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -algorithm TM " + itmax + " " + gamma + " " + lambda + " " + options;
Deconvolution d = new Deconvolution("Matlab TM", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
public static Object ICTM(Object arrayImage, Object arrayPSF, double itmax, double gamma, double lambda) {
return ICTM(arrayImage, arrayPSF, itmax, gamma, lambda, "");
}
public static Object ICTM(Object arrayImage, Object arrayPSF, double itmax, double gamma, double lambda, String options) {
RealSignal image = Converter.createRealSignal(arrayImage);
RealSignal psf = Converter.createRealSignal(arrayPSF);
String command = " -algorithm ICTM " + itmax + " " + gamma + " " + lambda + " " + options;
Deconvolution d = new Deconvolution("Matlab ICTM", command);
RealSignal result = d.deconvolve(image, psf);
return Converter.createObject(result);
}
}
diff --git a/DeconvolutionLab2/src/DeconvolutionLab2_FFT.java b/DeconvolutionLab2/src/DeconvolutionLab2_FFT.java
deleted file mode 100644
index 141022c..0000000
--- a/DeconvolutionLab2/src/DeconvolutionLab2_FFT.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * DeconvolutionLab2
- *
- * Conditions of use: You are free to use this software for research or
- * educational purposes. In addition, we expect you to include adequate
- * citations and acknowledgments whenever you present or publish results that
- * are based on it.
- *
- * Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
- * Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
- * R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
- */
-
-/*
- * Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
- *
- * This file is part of DeconvolutionLab2 (DL2).
- *
- * DL2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * DL2. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import deconvolutionlab.Imager;
-import deconvolutionlab.Lab;
-import deconvolutionlab.monitor.Monitors;
-import ij.plugin.PlugIn;
-
-public class DeconvolutionLab2_FFT implements PlugIn {
-
- @Override
- public void run(String arg) {
- Lab.init(Imager.Platform.IMAGEJ);
- Lab.checkFFT(Monitors.createDefaultMonitor());
- }
-}
diff --git a/DeconvolutionLab2/src/DeconvolutionLab2_Help.java b/DeconvolutionLab2/src/DeconvolutionLab2_Help.java
index 22ff1ab..4da0bc6 100644
--- a/DeconvolutionLab2/src/DeconvolutionLab2_Help.java
+++ b/DeconvolutionLab2/src/DeconvolutionLab2_Help.java
@@ -1,43 +1,50 @@
/*
* 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 deconvolutionlab.Imager;
import deconvolutionlab.Lab;
import ij.plugin.PlugIn;
+/**
+ * This class only opens the current browser on the webpage of the Deconvoltuinlab2
+ * documentation.
+ *
+ * @author Daniel Sage
+ *
+ */
public class DeconvolutionLab2_Help implements PlugIn {
@Override
public void run(String arg) {
Lab.init(Imager.Platform.IMAGEJ);
Lab.help();
}
}
diff --git a/DeconvolutionLab2/src/DeconvolutionLab2_Lab.java b/DeconvolutionLab2/src/DeconvolutionLab2_Lab.java
index b23c3f6..046c9be 100644
--- a/DeconvolutionLab2/src/DeconvolutionLab2_Lab.java
+++ b/DeconvolutionLab2/src/DeconvolutionLab2_Lab.java
@@ -1,49 +1,49 @@
/*
* 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 ij.IJ;
+import ij.plugin.PlugIn;
+
import java.io.File;
-import bilib.tools.Files;
import deconvolutionlab.Imager;
import deconvolutionlab.Lab;
import deconvolutionlab.LabDialog;
-import ij.IJ;
-import ij.plugin.PlugIn;
public class DeconvolutionLab2_Lab implements PlugIn {
@Override
public void run(String arg) {
Lab.init(Imager.Platform.IMAGEJ, IJ.getDirectory("plugins") + File.separator + "DeconvolutionLab2.config");
LabDialog dlg = new LabDialog();
Lab.setVisible(dlg, false);
}
}
diff --git a/DeconvolutionLab2/src/Display_FactorySignals.java b/DeconvolutionLab2/src/Display_FactorySignals.java
deleted file mode 100644
index 3924a9a..0000000
--- a/DeconvolutionLab2/src/Display_FactorySignals.java
+++ /dev/null
@@ -1,254 +0,0 @@
-import java.io.File;
-import java.util.ArrayList;
-
-import bilib.table.CustomizedTable;
-import bilib.tools.Files;
-import deconvolution.algorithm.Convolution;
-import deconvolutionlab.Lab;
-import deconvolutionlab.monitor.Monitors;
-import fft.AbstractFFT;
-import fft.FFT;
-import ij.plugin.PlugIn;
-import signal.ComplexSignal;
-import signal.RealSignal;
-import signal.factory.SignalFactory;
-import signal.factory.Sphere;
-import signal.factory.complex.ComplexSignalFactory;
-
-public class Display_FactorySignals implements PlugIn {
-
- private String path = Files.getDesktopDirectory() + File.separator + "Deconvolution" + File.separator + "Signals" + File.separator;
-
- @Override
- public void run(String arg0) {
- }
-
- public static void main(String arg[]) {
- new Display_FactorySignals();
- }
-
- public Display_FactorySignals() {
- new File(path).mkdir();
- int nx = 128;
- int ny = 96;
- int nz = 100;
-
- ArrayList<SignalFactory> factories = SignalFactory.getAll();
- RealSignal image = new Sphere(20, 0.5).generate(nx, ny, nz);
- Monitors monitors = Monitors.createDefaultMonitor();
- CustomizedTable table = new CustomizedTable(new String[] {"Name", "mean", "min", "max"}, true);
- table.show("Stats", 500, 500);
- for(SignalFactory factory : factories) {
- RealSignal psf = factory.intensity(133).generate(nx, ny, nz);
- Lab.show(psf);
- float s[] = psf.getStats();
- table.append(new String[] {factory.getName(), ""+s[0], ""+s[1], ""+s[2]});
- Lab.showOrthoview(psf);
- Lab.save(monitors, psf, path + psf.name + ".tif");
- Lab.save(monitors, psf.createMIP(), path + "mip-" + psf.name + ".tif");
- Lab.save(monitors, psf.createOrthoview(), path + "ortho-" + psf.name + ".tif");
- Convolution convolution = new Convolution();
- RealSignal a = convolution.run(image, psf);
- Lab.showMIP(monitors, a, "conv " + factory.getName());
- Lab.save(monitors, a, path + "conv-"+psf.name + ".tif");
- Lab.save(monitors, a.createMIP(), path + "conv-mip-" + psf.name + ".tif");
- Lab.save(monitors, a.createOrthoview(), path + "conv-ortho-" + psf.name + ".tif");
- }
- }
-
- public void d() {
- int nx = 150;
- int ny = 128;
- int nz = 100;
- int xsize = nx / 2;
- int ysize = ny / 2;
- int zsize = nz / 2;
- double wx, wy, wz;
- RealSignal psf = new RealSignal("psf", nx, ny, nz);
- AbstractFFT fft = FFT.getFastestFFT().getDefaultFFT();
- fft.init(Monitors.createDefaultMonitor(), nx, ny, 1);
- double pupil = 10;
- double defocus = 10;
- double wave = 2;
-
- double defocusTop = 2.0*Math.PI / (defocus*defocus*pupil);
- double defocusCen = 2.0*Math.PI / pupil;
-
- for (int z = 0; z <= zsize; z++) {
- float[][][] real = new float[xsize + 1][ysize + 1][1];
- float[][][] imag = new float[xsize + 1][ysize + 1][1];
- wz = wave*(z-zsize)*2.0*Math.PI / zsize;
- double cosz = Math.cos(wz);
- double sinz = Math.sin(wz);
- double fcz = z * Math.abs(defocusTop-defocusCen) / zsize+ defocusTop;
- for (int y = 0; y <= ysize; y++)
- for (int x = 0; x <= xsize; x++) {
- wx = Math.PI * x / xsize;
- wy = Math.PI * y / ysize;
- double g = wy*wy+wx*wx >= fcz*fcz ? 0 : 1;
- real[x][y][0] = (float) (g * cosz);
- imag[x][y][0] = (float) (g * sinz);
- }
- ComplexSignal c = ComplexSignalFactory.createHermitian(""+z, nx, ny, 1, real, imag);
- RealSignal pz = fft.inverse(c).circular();
-
- //pz.plus(1);
- //pz.normalize(1);
- psf.setXY(z, pz.getXY(0));
- psf.setXY(nz-1-z, pz.duplicate().getXY(0));
- }
- //psf = new Gaussian(3,4,4).generate(nx, ny, nz);
- float min = psf.getExtrema()[0];
- psf.minus(min);
- float max = psf.getExtrema()[1];
- psf.times(1/max);
- float aft[] = psf.getExtrema();
- System.out.println(" // " + aft[0] + " // " + aft[1]);
- psf.normalize(1);
- Lab.show(psf);
- Lab.showOrthoview(psf);
- Lab.save(Monitors.createDefaultMonitor(), psf, "psfdiffraction.tif");
- /*
- fft.init(Monitors.createDefaultMonitor(), nx, ny, nz);
- ComplexSignal otf = fft.transform(psf);
- Lab.show(otf.getModule().circular().log());
- Lab.showOrthoview(otf.getModule().circular().log());
-
-
- RealSignal r = new Cube(30, 1).generate(nx, ny, nz);
- RealSignal a = new Convolution().run(r, psf);
- Lab.showOrthoview(a);
- */
- }
- public void c() {
- int nx = 128;
- int ny = 128;
- int nz = 128;
- RealSignal otf = new RealSignal("psf", nx, ny, nz);
-
- int cx = nx/2;
- int cy = ny/2;
- int cz = nz/2;
- double pi = Math.PI;
- double periodTop = 5;
- double periodCenter = 15;
- double attenuation = 10;
- double aperture = 60;
- double apernorm = (2.0*aperture)/(nx+ny);
- double diag = Math.sqrt(nx*nx+ny*ny+nz*nz);
- double step = (periodCenter-periodTop)/nz;
- for(int i=0; i<nx; i++)
- for(int j=0; j<ny; j++) {
- double r = Math.sqrt((i-cx)*(i-cx)+(j-cy)*(j-cy));
- for(int k=0; k<nx; k++) {
- double z = Math.abs(k-cz);
- double p = Math.sqrt(r*r + z*z)/diag;
- double period = Math.max(1, periodCenter-step*z);
- double sz = apernorm*z + period*0.25;
- double s1 = 1.0 / (1.0+Math.exp(-(r+sz)));
- double s2 = 1.0 / (1.0+Math.exp(-(r-sz)));
- double s = Math.cos(2*pi*(r-apernorm*z)/period);
- double g = (attenuation*p+1);
- otf.data[k][i+j*nx] = (float)((s1-s2)*s*s/g);
- }
- }
- Lab.show(otf);
- Lab.showOrthoview(otf, "out", cx, cy, cz);
- float[] stats = otf.getStats();
- for(float s : stats)
- System.out.println("" + s);
-
- AbstractFFT fft = FFT.getFastestFFT().getDefaultFFT();
- fft.init(Monitors.createDefaultMonitor(), nx, ny, nz);
- ComplexSignal psf = fft.transform(otf);
- float[] stats1 = psf.getModule().getStats();
- for(float s : stats1)
- System.out.println("PSF " + s);
- Lab.show(psf.getModule().circular().log());
- Lab.showOrthoview(psf.getModule().circular().log(), "out", cx, cy, cz);
- }
-
- public void b() {
- int nx = 128;
- int ny = 128;
- int nz = 128;
- RealSignal otf = new RealSignal("psf", nx, ny, nz);
-
- int cx = nx/2;
- int cy = ny/2;
- int cz = nz/2;
-
- for(int i=0; i<nx; i++)
- for(int j=0; j<ny; j++) {
- double r = Math.sqrt((i-cx)*(i-cx)+(j-cy)*(j-cy));
- for(int k=0; k<nx; k++) {
- double df = Math.abs(k-cz);
- double dd = df - 6;
- double sig = 3 + df * 0.2;
- double sigd = 0.1 + dd * 0.2;
- double norm = 1.0 / (Math.PI*sig*sig);
- double g = norm * Math.exp(-r*r/(2.0*sig*sig));
- double gd = (dd < 0 ? 0 : norm * Math.exp(-r*r/(2*sigd*sigd)));
- otf.data[k][i+j*nx] = (float)(g-gd); //(Math.exp(-r*0.1));
- }
- }
- Lab.show(otf);
- Lab.showOrthoview(otf, "out", cx, cy, cz);
-
- float[] stats = otf.getStats();
- for(float s : stats)
- System.out.println("" + s);
-
- AbstractFFT fft = FFT.getFastestFFT().getDefaultFFT();
- fft.init(Monitors.createDefaultMonitor(), nx, ny, nz);
- ComplexSignal psf = fft.transform(otf);
- float[] stats1 = psf.getModule().getStats();
- for(float s : stats1)
- System.out.println("PSF " + s);
- Lab.show(Monitors.createDefaultMonitor(), psf.getModule().circular(), "psf");
- }
-
- public void va() {
- int nx = 128;
- int ny = 128;
- int nz = 128;
- RealSignal otf = new RealSignal("psf", nx, ny, nz);
-
- int cx = nx/2;
- int cy = ny/2;
- int cz = nz/2;
- double p = 1.3;
- for(int i=0; i<nx; i++)
- for(int j=0; j<ny; j++) {
- double d = Math.sqrt((i-cx)*(i-cx) + (j-cy)*(j-cy));
- double v = (p-Math.exp(-d*0.1));
- for(int k=0; k<nx; k++) {
- double dz = ((double)Math.abs(k-cz))/nz;
- double g = Math.exp(-dz*dz*2*nx);
- double vz = g*v*Math.cos(d*Math.PI*2/nx);
- if (vz > 0) {
- double r = Math.sqrt((i-cx)*(i-cx) + (j-cy)*(j-cy) + (k-cz)*(k-cz));
- if (r < cx)
- otf.data[k][i+j*nx] = (float)vz; //(Math.exp(-r*0.1));
-
- }
- }
- }
- Lab.show(otf);
- Lab.showOrthoview(otf, "out", cx, cy, cz);
-
- float[] stats = otf.getStats();
- for(float s : stats)
- System.out.println("" + s);
-
- AbstractFFT fft = FFT.getFastestFFT().getDefaultFFT();
- fft.init(Monitors.createDefaultMonitor(), nx, ny, nz);
- ComplexSignal psf = fft.transform(otf);
- float[] stats1 = psf.getModule().getStats();
- for(float s : stats1)
- System.out.println("PSF " + s);
- Lab.show(Monitors.createDefaultMonitor(), psf.getModule().circular(), "psf");
-
- }
-
-}
diff --git a/DeconvolutionLab2/src/bilib/component/BorderToggledButton.java b/DeconvolutionLab2/src/bilib/component/BorderToggledButton.java
index 18997b6..b444038 100644
--- a/DeconvolutionLab2/src/bilib/component/BorderToggledButton.java
+++ b/DeconvolutionLab2/src/bilib/component/BorderToggledButton.java
@@ -1,51 +1,52 @@
/*
* bilib --- Java Bioimaging Library ---
*
* Author: Daniel Sage, Biomedical Imaging Group, EPFL, Lausanne, Switzerland
*
* 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.
*/
/*
* 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 bilib.component;
import java.awt.Insets;
import javax.swing.JButton;
public class BorderToggledButton extends JButton {
private String text = "";
public BorderToggledButton(String text) {
super(text);
this.text = text;
setMargin(new Insets(1, 1, 1, 1));
}
+ @Override
public void setSelected(boolean selected) {
if (selected)
setText("<html><b>" + text + "</b></html>");
else
setText(text);
}
}
diff --git a/DeconvolutionLab2/src/bilib/table/CustomizedColumn.java b/DeconvolutionLab2/src/bilib/table/CustomizedColumn.java
index df3c3fd..eb12602 100644
--- a/DeconvolutionLab2/src/bilib/table/CustomizedColumn.java
+++ b/DeconvolutionLab2/src/bilib/table/CustomizedColumn.java
@@ -1,65 +1,100 @@
/*
* bilib --- Java Bioimaging Library ---
*
* Author: Daniel Sage, Biomedical Imaging Group, EPFL, Lausanne, Switzerland
*
* 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.
*/
/*
* 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 bilib.table;
+/**
+ * This class allows to customized the columns of the CustomizedTable tables.
+ *
+ * @author Daniel Sage
+ *
+ */
public class CustomizedColumn {
- public Class<?> classe;
- public String header;
- public int width;
- public boolean editable;
- public String[] choices; // Combobox
- public String button; // Button
- public String tooltip;
- public CustomizedColumn(String header, Class<?> classe, int width, boolean editable) {
- this.classe = classe;
+ private Class<?> columnClasse; // usually it is a String
+ private String header;
+ private boolean editable;
+ private int width;
+ private String[] choices; // ComboBox
+ private String button; // Button
+ private String tooltip;
+
+ public CustomizedColumn(String header, Class<?> columnClasse, int width, boolean editable) {
+ this.columnClasse = columnClasse;
this.header = header;
this.width = width;
this.editable = editable;
}
public CustomizedColumn(String header, Class<?> classe, int width, String[] choices, String tooltip) {
- this.classe = classe;
+ this.columnClasse = classe;
this.header = header;
this.width = width;
this.editable = true;
this.choices = choices;
this.tooltip = tooltip;
}
- public CustomizedColumn(String header, Class<?> classe, int width, String button, String tooltip) {
- this.classe = classe;
+ public CustomizedColumn(String header, Class<?> columnClasse, int width, String button, String tooltip) {
+ this.columnClasse = columnClasse;
this.header = header;
this.width = width;
this.editable = false;
this.button = button;
this.tooltip = tooltip;
}
+
+ public Class<?> getColumnClass() {
+ return columnClasse;
+ }
+
+ public String getHeader() {
+ return header;
+ }
+
+ public boolean isEditable() {
+ return editable;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public String[] getChoices() {
+ return choices;
+ }
+
+ public String getButton() {
+ return button;
+ }
+
+ public String getTooltip() {
+ return tooltip;
+ }
}
diff --git a/DeconvolutionLab2/src/bilib/table/CustomizedTable.java b/DeconvolutionLab2/src/bilib/table/CustomizedTable.java
index c1a2859..bd8d681 100644
--- a/DeconvolutionLab2/src/bilib/table/CustomizedTable.java
+++ b/DeconvolutionLab2/src/bilib/table/CustomizedTable.java
@@ -1,296 +1,334 @@
/*
* bilib --- Java Bioimaging Library ---
*
* Author: Daniel Sage, Biomedical Imaging Group, EPFL, Lausanne, Switzerland
*
* 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.
*/
/*
* 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 bilib.table;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Rectangle;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
+/**
+ * This class build a table by extending JTable. Usually the contructor expects
+ * a list of CustomizedColumn objects that defines the columns of the table.
+ *
+ * @author Daniel Sage
+ *
+ */
+
public class CustomizedTable extends JTable {
- private JScrollPane pane = null;
+ private JScrollPane pane = null;
private ArrayList<CustomizedColumn> columns;
+ public CustomizedTable(ArrayList<CustomizedColumn> columns, boolean sortable) {
+ create(columns);
+ setAutoCreateRowSorter(sortable);
+ setRowHeight(20);
+ }
+
+
public CustomizedTable(String headers[], boolean sortable) {
ArrayList<CustomizedColumn> colums = new ArrayList<CustomizedColumn>();
for (int i = 0; i < headers.length; i++)
colums.add(new CustomizedColumn(headers[i], String.class, 150, false));
create(colums);
setAutoCreateRowSorter(sortable);
setRowHeight(20);
}
- public CustomizedTable(ArrayList<CustomizedColumn> columns, boolean sortable) {
- create(columns);
- setAutoCreateRowSorter(sortable);
- setRowHeight(20);
- }
-
private void create(ArrayList<CustomizedColumn> column) {
columns = column;
DefaultTableModel model = new DefaultTableModel() {
@Override
public boolean isCellEditable(int row, int col) {
- return columns.get(col).editable;
+ return columns.get(col).isEditable();
}
@Override
public Class<?> getColumnClass(int col) {
- return columns.get(col).classe;
+ return columns.get(col).getColumnClass();
}
};
setModel(model);
int n = columns.size();
String headers[] = new String[n];
for (int col = 0; col < n; col++)
- headers[col] = columns.get(col).header;
+ headers[col] = columns.get(col).getHeader();
model.setColumnIdentifiers(headers);
setFillsViewportHeight(true);
for (int col = 0; col < n; col++) {
TableColumn tc = getColumnModel().getColumn(col);
- tc.setPreferredWidth(columns.get(col).width);
+ tc.setPreferredWidth(columns.get(col).getWidth());
- if (columns.get(col).choices != null) {
+ if (columns.get(col).getChoices() != null) {
JComboBox<String> cmb = new JComboBox<String>();
- for (String p : columns.get(col).choices) {
+ for (String p : columns.get(col).getChoices()) {
cmb.addItem(p);
- cmb.setToolTipText(columns.get(col).tooltip);
+ cmb.setToolTipText(columns.get(col).getTooltip());
tc.setCellEditor(new DefaultCellEditor(cmb));
}
}
- if (columns.get(col).button != null) {
+ if (columns.get(col).getButton() != null) {
ButtonRenderer bn = new ButtonRenderer();
- bn.setToolTipText(columns.get(col).tooltip);
+ bn.setToolTipText(columns.get(col).getTooltip());
tc.setCellRenderer(bn);
}
}
getTableHeader().setReorderingAllowed(false);
}
public void setPreferredSize(int width, int height) {
if (pane != null)
pane.setPreferredSize(new Dimension(width, height));
}
+ /**
+ * Removes one specify row from the table.
+ *
+ * @param row Row to remove
+ */
public void removeRow(int row) {
if (row >= 0 && row < getRowCount())
((DefaultTableModel) getModel()).removeRow(row);
}
+ /**
+ * Removes all rows of the table.
+ */
public void removeRows() {
- while(getRowCount() > 0)
+ while (getRowCount() > 0)
((DefaultTableModel) getModel()).removeRow(0);
}
public String[] getRow(int row) {
if (row >= 0) {
int ncol = getColumnCount();
String items[] = new String[ncol];
for (int col = 0; col < ncol; col++)
items[col] = (String) getModel().getValueAt(row, col);
return items;
}
return new String[1];
}
public String getCell(int row, int col) {
if (row >= 0 && col >= 0) {
return (String) getModel().getValueAt(row, col);
}
return "";
}
-
+
public void setCell(int row, int col, String value) {
if (row >= 0 && col >= 0) {
getModel().setValueAt(value, row, col);
}
}
public String getRowCSV(int row, String seperator) {
if (row >= 0) {
int ncol = getColumnCount();
String items = "";
for (int col = 0; col < ncol - 1; col++) {
if ((String) getModel().getValueAt(row, col) == null)
items += "" + seperator;
- else
+ else
items += (String) getModel().getValueAt(row, col) + seperator;
}
if (ncol >= 1)
items += (String) getModel().getValueAt(row, ncol - 1);
return items;
}
return "";
}
+ /**
+ * Saves the table in a CSV file
+ *
+ * @param filename Complete path and filename
+ */
public void saveCSV(String filename) {
File file = new File(filename);
try {
BufferedWriter buffer = new BufferedWriter(new FileWriter(file));
int nrows = getRowCount();
int ncols = getColumnCount();
String row = "";
for (int c = 0; c < columns.size(); c++)
- row += columns.get(c).header + (c == columns.size() - 1 ? "" : ", ");
+ row += columns.get(c).getHeader() + (c == columns.size() - 1 ? "" : ", ");
buffer.write(row + "\n");
for (int r = 0; r < nrows; r++) {
row = "";
for (int c = 0; c < ncols; c++)
row += this.getCell(r, c) + (c == ncols - 1 ? "" : ", ");
buffer.write(row + "\n");
}
buffer.close();
}
catch (IOException ex) {
}
}
public String getSelectedAtColumn(int col) {
int row = getSelectedRow();
if (row >= 0)
return (String) getModel().getValueAt(row, col);
else
return "";
}
public void setSelectedAtColumn(int col, String selection) {
int nrows = this.getRowCount();
for (int i = 0; i < nrows; i++) {
String name = (String) getModel().getValueAt(i, col);
if (name.equals(selection))
this.setRowSelectionInterval(i, i + 1);
}
}
+ /**
+ * Add a row at the end of the table.
+ *
+ * @param row
+ */
public void append(Object[] row) {
DefaultTableModel model = (DefaultTableModel) getModel();
int i = 0;
try {
model.addRow(row);
i = getRowCount() - 1;
if (i >= 0) {
getSelectionModel().setSelectionInterval(i, i);
scrollRectToVisible(new Rectangle(getCellRect(i, 0, true)));
}
}
catch (Exception e) {
}
repaint();
}
+ /**
+ * Add a row at the top of the table.
+ *
+ * @param row
+ */
public void insert(Object[] row) {
DefaultTableModel model = (DefaultTableModel) getModel();
int i = 0;
try {
model.insertRow(0, row);
getSelectionModel().setSelectionInterval(i, i);
scrollRectToVisible(new Rectangle(getCellRect(i, 0, true)));
}
catch (Exception e) {
}
repaint();
}
@Override
public int getSelectedRow() {
int row = super.getSelectedRow();
if (row < 0) {
if (getRowCount() > 0) {
setRowSelectionInterval(0, 0);
row = super.getSelectedRow();
}
return row;
}
return row;
}
+ /**
+ * Replaces all the content of the table by a content private as list of String[].
+ *
+ * @param data
+ */
public void update(ArrayList<String[]> data) {
DefaultTableModel model = (DefaultTableModel) getModel();
model.getDataVector().removeAllElements();
for (String[] row : data)
model.addRow(row);
repaint();
}
public JScrollPane getPane(int width, int height) {
setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
setPreferredScrollableViewportSize(new Dimension(width, height));
setFillsViewportHeight(true);
pane = new JScrollPane(this);
return pane;
}
public JScrollPane getMinimumPane(int width, int height) {
setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
setMinimumSize(new Dimension(width, height));
setShowVerticalLines(true);
setPreferredScrollableViewportSize(new Dimension(width, height));
setFillsViewportHeight(true);
return new JScrollPane(this);
}
public JFrame show(String title, int w, int h) {
JFrame frame = new JFrame(title);
frame.add(getPane(w, h));
frame.pack();
frame.setVisible(true);
return frame;
}
+
public class ButtonRenderer extends JButton implements TableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
- setText((String)value);
+ setText((String) value);
setMargin(new Insets(1, 1, 1, 1));
return this;
}
}
}
diff --git a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Bigradient.java b/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Bigradient.java
deleted file mode 100644
index 3d91c35..0000000
--- a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Bigradient.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * DeconvolutionLab2
- *
- * Conditions of use: You are free to use this software for research or
- * educational purposes. In addition, we expect you to include adequate
- * citations and acknowledgments whenever you present or publish results that
- * are based on it.
- *
- * Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
- * Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
- * R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
- */
-
-/*
- * Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
- *
- * This file is part of DeconvolutionLab2 (DL2).
- *
- * DL2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * DL2. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package course;
-
-import java.io.File;
-
-import bilib.tools.Files;
-import deconvolution.Deconvolution;
-import ij.plugin.PlugIn;
-
-public class DeconvolutionLab2_Course_Bigradient implements PlugIn {
-
- private String root = Files.getDesktopDirectory() + "Deconvolution" + File.separator;
- private String res = root + "results" + File.separator + "bigradient" + File.separator;
- private String data = root + "data" + File.separator + "bigradient" + File.separator;
-
- public DeconvolutionLab2_Course_Bigradient() {
-
- new File(res).mkdir();
- System.setProperty("user.dir", res);
-
- new File(res + "TRIF").mkdir();
- new File(res + "RIF").mkdir();
- new File(res + "LW").mkdir();
- new File(res + "LW-ITER").mkdir();
- new File(res + "LW+").mkdir();
- new File(res + "LW+-ITER").mkdir();
- new File(res + "RL").mkdir();
- new File(res + "RL-ITER").mkdir();
- new File(res + "RLTV").mkdir();
- new File(res + "RLTV-ITER").mkdir();
- new File(res + "FISTA").mkdir();
- new File(res + "FISTA-ITER").mkdir();
-
- String psf = " -psf file " + data + "psf.tif -reference " + data + "ref.tif ";
- String noisy = " -image file convnoise.tif";
-
- new Deconvolution("run", "-image file " + data + "ref.tif" + psf + " -algorithm SIM 0 1 1 -out stack convnoise -out stack conbnoise_8 rescaled byte noshow").deconvolve();
-
- new Deconvolution("run", noisy + psf + " -algorithm NIF -out stack NIF").deconvolve();
- new Deconvolution("run", noisy + psf + " -algorithm DIV -out stack DIV").deconvolve();
-
- for(int i=0; i<=3; i++) {
- double p = Math.pow(5, i-10);
- String name = "RIF" + String.format("%02d", i);
- new Deconvolution("run", noisy + psf + " -algorithm RIF " + p + out("RIF" + File.separator, name)).deconvolve();
- }
- for(int i=0; i<=3; i++) {
- double p = Math.pow(5, i-10);
- String name = "TRIF" + String.format("%02d", i);
- new Deconvolution("run", noisy + psf + " -algorithm TRIF " + p + out("TRIF" + File.separator, name)).deconvolve();
- }
-
- String lw = " -algorithm LW 20 1 -out mip @2 LW-ITER/I -out stats @1 LW nosave";
- new Deconvolution("run", noisy + psf + lw).deconvolve();
- new File(res + "LW-ITER/I.tif").delete();
-
-
- String lwp = " -algorithm LW+ 20 1 -out mip @2 LW+-ITER/I -out stats @1 LW+ nosave";
- new Deconvolution("run", noisy + psf + lwp).deconvolve();
- new File(res + "LW+-ITER/I.tif").delete();
-
-
- String rl = " -algorithm RL 20 -out mip @2 RL-ITER/I -out stats @1 RL nosave";
- new Deconvolution("run", noisy + psf + rl).deconvolve();
- new File(res + "RL-ITER/I.tif").delete();
-
- String rltv = " -algorithm RLTV 20 10 -out mip @2 RLTV-ITER/I -out stats @1 RLTV nosave";
- new Deconvolution("run", noisy + psf + rltv).deconvolve();
- new File(res + "RLTV-ITER/I.tif").delete();
-
- String fista = " -algorithm FISTA 20 1 1 Spline3 3 -mip @2 FISTA-ITER/I -out stats @1 FISTA nosave";
- new Deconvolution("run", noisy + psf + fista).deconvolve();
- new File(res + "FISTA-ITER/I.tif").delete();
-
- }
-
- private static String out(String root, String name) {
- return "out stats " + root + name +
- " -out stack " + root + name + "_32 -out stack " + root + name + "_8 rescaled byte noshow";
- }
-
- public static void main(String arg[]) {
- new DeconvolutionLab2_Course_Bigradient();
- }
-
- @Override
- public void run(String arg) {
- new DeconvolutionLab2_Course_Bigradient();
- }
-
-}
diff --git a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Border.java b/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Border.java
deleted file mode 100644
index 620eb15..0000000
--- a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Border.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * DeconvolutionLab2
- *
- * Conditions of use: You are free to use this software for research or
- * educational purposes. In addition, we expect you to include adequate
- * citations and acknowledgments whenever you present or publish results that
- * are based on it.
- *
- * Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
- * Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
- * R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
- */
-
-/*
- * Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
- *
- * This file is part of DeconvolutionLab2 (DL2).
- *
- * DL2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * DL2. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package course;
-
-import ij.plugin.PlugIn;
-
-import java.io.File;
-
-import signal.RealSignal;
-import signal.factory.Cube;
-import signal.factory.Gaussian;
-import bilib.tools.Files;
-import deconvolution.Deconvolution;
-import deconvolutionlab.Lab;
-import deconvolutionlab.monitor.Monitors;
-
-public class DeconvolutionLab2_Course_Border implements PlugIn {
-
- private String root = Files.getDesktopDirectory() + "Deconvolution" + File.separator;
- private String res = root + "results" + File.separator + "border" + File.separator;
-
- public DeconvolutionLab2_Course_Border() {
-
- Monitors monitors = Monitors.createDefaultMonitor();
- new File(res).mkdir();
- System.setProperty("user.dir", res);
-
- int nx = 200;
- int ny = 200;
- int nz = 40;
-
- RealSignal im = new Cube(22, .1).intensity(100).center(0.25, 0.00, 0.05).generate(nx, ny, nz);
- RealSignal i0 = new Cube(22, .1).intensity(100).center(0.25, 0.05, 0.05).generate(nx, ny, nz);
- RealSignal i1 = new Cube(22, .1).intensity(100).center(0.25, 0.10, 0.05).generate(nx, ny, nz);
- RealSignal i2 = new Cube(22, .1).intensity(100).center(0.25, 0.15, 0.05).generate(nx, ny, nz);
- im.max(i1.max(i2).max(i0));
-
- RealSignal g = new Gaussian(10, 10, 10).intensity(101).generate(nx, ny, nz);
-
- Lab.save(monitors, im, res + "ref.tif");
- Lab.save(monitors, g, res + "psf.tif");
-
- String psf = " -psf file " + "psf.tif";
- String ref = " -image file " + "ref.tif";
- String cst = " -image synthetic constant 250 0 size 200 200 40";
-
- String algo = " -algorithm CONV -out ortho REFo (64,32,16)";
- new Deconvolution("run", ref + " -psf synthetic impulse " + algo).deconvolve();
-
- algo = " -algorithm CONV -stack CONV -out ortho CONVo rescaled byte (64,32,16) -out mip CONVp rescaled byte";
- new Deconvolution("run", ref + psf + algo).deconvolve();
-
- algo = " -algorithm CONV -pad NO NO 200 200 -out ortho PADo200 rescaled byte (64,32,16) -out mip PADp200 rescaled byte";
- new Deconvolution("run", ref + psf + algo).deconvolve();
-
- algo = " -algorithm CONV -pad NO NO 100 100 -out ortho PADo100 rescaled byte (64,32,16) -out mip PADp100 rescaled byte";
- new Deconvolution("run", ref + psf + algo).deconvolve();
-
- algo = " -algorithm CONV -pad NO NO 40 40 -out ortho PADo40 rescaled byte (64,32,16) -out mip PADp40 rescaled byte";
- new Deconvolution("run", ref + psf + algo).deconvolve();
-
- algo = " -algorithm CONV -pad NO NO 20 20 -out ortho PADo20 rescaled byte (64,32,16) -out mip PADp20 rescaled byte";
- new Deconvolution("run", ref + psf + algo).deconvolve();
-
- algo = " -algorithm CONV -pad NO NO 10 10 -out ortho PADo10 rescaled byte (64,32,16) -out mip PADp10 rescaled byte";
- new Deconvolution("run", ref + psf + algo).deconvolve();
-
- algo = " -algorithm CONV -pad NO NO 5 5 -out ortho PADo2 rescaled byte (64,32,16) -out mip PADp2 rescaled byte";
- new Deconvolution("run", ref + psf + algo).deconvolve();
-
- algo = " -algorithm CONV -apo HANN HANN -out ortho HANNo rescaled byte (64,32,16) -out mip HANNp rescaled byte";
- new Deconvolution("run", ref + psf + algo).deconvolve();
-
- algo = " -algorithm CONV -apo TUKEY TUKEY -out ortho TUKEYo rescaled byte (64,32,16) -out mip TUKEYp rescaled byte";
- new Deconvolution("run", ref + psf + algo).deconvolve();
-
- algo = " -algorithm CONV --pad NO NO 8 8 apo HANN HANN -out ortho PAD8_HANNo rescaled byte (64,32,16) -out mip PAD8_HANNp rescaled byte";
- new Deconvolution("run", ref + psf + algo).deconvolve();
-
-
- algo = " -algorithm CONV -apo HANN HANN -out ortho HANN_CSTo rescaled byte -out mip HANN_CSTp rescaled byte";
- new Deconvolution("run", cst + psf + algo).deconvolve();
-
- algo = " -algorithm CONV -apo TUKEY TUKEY -out ortho TUKEY_CSTo rescaled byte -out mip TUKEY_CSTp rescaled byte";
- new Deconvolution("run", cst + psf + algo).deconvolve();
-
-
- algo = " -algorithm CONV -pad E2 E2 -out ortho PADpPower2FFTW rescaled byte (64,32,16) -out mip PADpPower2FFTW rescaled byte";
-
-
- new Deconvolution("run", cst + psf + algo + " -fft FFTW2 ").deconvolve();
- new Deconvolution("run", cst + psf + algo + " -fft Academic ").deconvolve();
- new Deconvolution("run", cst + psf + algo + " -fft JTransforms ").deconvolve();
-
- }
-
- public static void main(String arg[]) {
- new DeconvolutionLab2_Course_Border();
- }
-
- @Override
- public void run(String arg) {
- new DeconvolutionLab2_Course_Border();
- }
-
-
-}
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Celegans.java b/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Celegans.java
deleted file mode 100644
index cc5fc72..0000000
--- a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Celegans.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * DeconvolutionLab2
- *
- * Conditions of use: You are free to use this software for research or
- * educational purposes. In addition, we expect you to include adequate
- * citations and acknowledgments whenever you present or publish results that
- * are based on it.
- *
- * Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
- * Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
- * R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
- */
-
-/*
- * Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
- *
- * This file is part of DeconvolutionLab2 (DL2).
- *
- * DL2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * DL2. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package course;
-
-import ij.ImagePlus;
-import ij.io.FileSaver;
-import ij.io.Opener;
-import ij.plugin.PlugIn;
-import ij.process.ColorProcessor;
-
-import java.io.File;
-
-import javax.swing.filechooser.FileSystemView;
-
-import bilib.tools.Files;
-import deconvolution.Deconvolution;
-
-public class DeconvolutionLab2_Course_Celegans implements PlugIn {
-
- private String root = Files.getDesktopDirectory() + "DeconvolutionLab2-Course" + File.separator;
- private String res = root + "Results" + File.separator + "c-elegans" + File.separator;
- private String data = root + "Data" + File.separator + "c-elegans" + File.separator;
-
- public DeconvolutionLab2_Course_Celegans() {
-
- new File(res).mkdir();
- System.setProperty("user.dir", res);
-
- run(" -algorithm RIF 0.000001 ", "RIF6_");
- run(" -algorithm RIF 0.0000001 ", "RIF7_");
- //run(" -algorithm RL 100 ", "RL_");
- run(" -algorithm LW+ 200 1 ", "LW+_");
- //run(" -algorithm I ", "IN_");
- //run(" -algorithm RIF 0.001 ", "RIF3_");
- //run(" -algorithm RIF 0.0001 ", "RIF4_");
- //run(" -algorithm RIF 0.00001 ", "RIF5_");
- //run(" -algorithm VC 100 ", "VC");
- //run(" -algorithm RLTV 10 0.1 ", "RLTV");
- //run(" -algorithm FISTA 50 1 0.1 ", "FISTA");
- //run(" -algorithm ISTA 50 1 0.1 ", "ISTA");
- }
-
- private void run(String a, String name) {
- String channels[] = new String[] { "CY3", "FITC", "DAPI"};
-
- ImagePlus[] ort = new ImagePlus[3];
- ImagePlus[] fig = new ImagePlus[3];
- for (int i=0; i<3; i++) {
- String channel = channels[i];
- String psf = " -psf file " + data + "psf-CElegans-" + channel + ".tif";
- String img = " -image file " + data + "CElegans-" + channel +".tif";
- String param = " -fft JTransforms -disable display multithreading";
- String algo = a + out(name + channel);
- new Deconvolution("deconvolve", img + psf + algo + param).deconvolve();
- ort[i] = new Opener().openImage( res + name + channel + "_ortho_8.tif");
- fig[i] = new Opener().openImage( res + name + channel + "_figure_8.tif");
- }
- new FileSaver(color(ort)).saveAsTiff(res + name + "-ortho-rgb.tif");
- new FileSaver(color(fig)).saveAsTiff(res + name + "-figure-rgb.tif");
- }
-
- private static String out(String name) {
- return
- " -out ortho " + name + "_ortho_8 rescaled byte (160,180,50) noshow" +
- " -out mip " + name + "_mip_8 rescaled byte noshow" +
- " -out figure " + name + "_figure_8 rescaled byte (160,180,50) ";
-
- }
-
- private static ImagePlus color(ImagePlus imp[]) {
- int nx = imp[0].getWidth();
- int ny = imp[0].getHeight();
- ColorProcessor cp = new ColorProcessor(nx, ny);
- byte r[] = (byte[])imp[0].getProcessor().getPixels();
- byte g[] = (byte[])imp[1].getProcessor().getPixels();
- byte b[] = (byte[])imp[2].getProcessor().getPixels();
- cp.setRGB(r, g, b);
- ImagePlus out = new ImagePlus( "rgb", cp);
- out.show();
- return out;
- }
- public static void main(String arg[]) {
- new DeconvolutionLab2_Course_Celegans();
- }
-
- @Override
- public void run(String arg) {
- new DeconvolutionLab2_Course_Celegans();
- }
-
-}
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Noise.java b/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Noise.java
deleted file mode 100644
index 129cae6..0000000
--- a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Noise.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * DeconvolutionLab2
- *
- * Conditions of use: You are free to use this software for research or
- * educational purposes. In addition, we expect you to include adequate
- * citations and acknowledgments whenever you present or publish results that
- * are based on it.
- *
- * Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
- * Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
- * R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
- */
-
-/*
- * Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
- *
- * This file is part of DeconvolutionLab2 (DL2).
- *
- * DL2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * DL2. If not, see <http://www.gnu.org/licenses/>.
- */
-package course;
-
-import java.io.File;
-
-import javax.swing.filechooser.FileSystemView;
-
-import bilib.tools.Files;
-import deconvolution.Deconvolution;
-import deconvolutionlab.Lab;
-import deconvolutionlab.monitor.Monitors;
-import ij.plugin.PlugIn;
-import signal.RealSignal;
-import signal.factory.Cube;
-
-public class DeconvolutionLab2_Course_Noise implements PlugIn {
-
- private String root = Files.getDesktopDirectory() + "Deconvolution" + File.separator;
- private String res = root + "results" + File.separator + "noise" + File.separator;
-
- public DeconvolutionLab2_Course_Noise() {
-
- Monitors monitors = Monitors.createDefaultMonitor();
- new File(res).mkdir();
- System.setProperty("user.dir", res);
-
- int nx = 560;
- int ny = 120;
- int nz = 1;
- String size = " size " + nx + " " + ny + " " + nz;
-
- RealSignal im = new Cube(50, 0.25).intensity(100).center(0.2, 0.5, 0).generate(nx, ny, nz);
- RealSignal i1 = new Cube(50, 0.25).intensity(70).center(0.4, 0.5, 0).generate(nx, ny, nz);
- RealSignal i2 = new Cube(50, 0.25).intensity(40).center(0.6, 0.5, 0).generate(nx, ny, nz);
- RealSignal i3 = new Cube(50, 0.25).intensity(10).center(0.8, 0.5, 0).generate(nx, ny, nz);
- im.plus(i1);
- im.plus(i2);
- im.plus(i3);
- Lab.show(monitors, im, "im.tif");
- Lab.save(monitors, im, res + "im.tif");
-
- String psf = " -psf synthetic impulse 1 0 " + size;
- String image = " -image file im.tif";
-
- // Simulation
- String name = "SIM m 0 s 50 p 0";
- String out = " -stack " + name + " -out stack " + name + "-BYTE rescaled byte noshow";
- new Deconvolution("noise", psf + image + " -algorithm " + name + out).run();
-
- name = "SIM m 0 s 00 p 150";
- out = " -stack " + name + " -out stack " + name + "-BYTE rescaled byte noshow";
- new Deconvolution("noise", psf + image + " -algorithm " + name + out).run();
-
- name = "SIM m 0 s 15 p 30";
- out = " -stack " + name + " -out stack " + name + "-BYTE rescaled byte noshow";
- new Deconvolution("noise", psf + image + " -algorithm " + name + out).run();
- }
-
-
- public static void main(String arg[]) {
- new DeconvolutionLab2_Course_Noise();
- }
-
- @Override
- public void run(String arg) {
- new DeconvolutionLab2_Course_Noise();
- }
-
-}
diff --git a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Piecewise.java b/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Piecewise.java
deleted file mode 100644
index 29cb717..0000000
--- a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Piecewise.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * DeconvolutionLab2
- *
- * Conditions of use: You are free to use this software for research or
- * educational purposes. In addition, we expect you to include adequate
- * citations and acknowledgments whenever you present or publish results that
- * are based on it.
- *
- * Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
- * Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
- * R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
- */
-
-/*
- * Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
- *
- * This file is part of DeconvolutionLab2 (DL2).
- *
- * DL2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * DL2. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package course;
-
-import java.io.File;
-import java.util.Random;
-
-import javax.swing.filechooser.FileSystemView;
-
-import bilib.tools.Files;
-import deconvolution.Deconvolution;
-import deconvolutionlab.Lab;
-import deconvolutionlab.monitor.Monitors;
-import ij.plugin.PlugIn;
-import signal.RealSignal;
-import signal.factory.Constant;
-import signal.factory.Cube;
-
-public class DeconvolutionLab2_Course_Piecewise implements PlugIn {
-
- private String root = Files.getDesktopDirectory() + "Deconvolution" + File.separator;
- private String res = root + "results" + File.separator + "piecewise" + File.separator;
-
- public DeconvolutionLab2_Course_Piecewise() {
-
- Monitors monitors = Monitors.createDefaultMonitor();
- new File(res).mkdir();
- System.setProperty("user.dir", res);
-
- new File(res + "RIF").mkdir();
- new File(res + "LW").mkdir();
- new File(res + "LW+").mkdir();
- new File(res + "RL").mkdir();
- new File(res + "RLTV").mkdir();
- new File(res + "ISTA").mkdir();
- new File(res + "FISTA").mkdir();
-
- int nx = 128;
- int ny = 128;
- int nz = 128;
- int spacing = 16;
-
- Random rand = new Random(1234);
- RealSignal x = new Constant().intensity(10).generate(nx, ny, nz);
- for(int i = 0; i< 12; i++) {
- double xc = (rand.nextDouble()*0.6 + 0.2);
- double yc = (rand.nextDouble()*0.6 + 0.2);
- double zc = (rand.nextDouble()*0.6 + 0.2);
- double size = 15 + (rand.nextDouble()*30);
- double ampl = (rand.nextDouble()+0.5)*10;
- x.plus(new Cube(size, 0.1).intensity(ampl).center(xc, yc, zc).generate(nx, ny, nz));
- }
- Lab.show(monitors, x, "reference");
- Lab.save(monitors, x, res + "ref.tif");
-
- String algo = " ";
- String ground = " -image file " + res + "ref.tif ";
- //String psf = " -psf file ../../Data/resolution/psfgl.tif";
- String psf = " -psf synthetic gaussian 100.0 0.0 1.2 1.2 3.6 size ";
- // nx + " " + ny + " " + nz;
- String signal = " -image file signal.tif -reference " + res + "ref.tif -disable monitor";
-
- String paramout = " intact float (" + spacing + "," + spacing + "," + spacing + ")";
-
- algo = " -algorithm CONV -out stats @3 PR nosave -out stack PR -out ortho PRo ";
- new Deconvolution("run", ground + "-reference reference.tif -psf synthetic impulse 100 0 size 128 128 128 " + algo).deconvolve();
-
- algo = " -algorithm SIM 0 1 1 -out stats @3 SIM nosave -out stack signal -out ortho SIGNALo ";
- new Deconvolution("run", ground + psf + algo).deconvolve();
-
- algo = " -algorithm NIF -out ortho NIF " + paramout;
- new Deconvolution("run", signal + psf + algo).deconvolve();
-
- algo = " -algorithm RLTV 15 0.01 -out stats @1 RLTV nosave -out ortho @1 RLTV/RLTV" + paramout;
- new Deconvolution("run", signal + psf + algo).deconvolve();
- }
-
- public static void main(String arg[]) {
- new DeconvolutionLab2_Course_Piecewise();
- }
-
- @Override
- public void run(String arg) {
- new DeconvolutionLab2_Course_Piecewise();
- }
-
-}
diff --git a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_SpectralAnaylsis.java b/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_SpectralAnaylsis.java
deleted file mode 100644
index c42cfa2..0000000
--- a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_SpectralAnaylsis.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * DeconvolutionLab2
- *
- * Conditions of use: You are free to use this software for research or
- * educational purposes. In addition, we expect you to include adequate
- * citations and acknowledgments whenever you present or publish results that
- * are based on it.
- *
- * Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
- * Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
- * R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
- */
-
-/*
- * Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
- *
- * This file is part of DeconvolutionLab2 (DL2).
- *
- * DL2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * DL2. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package course;
-import java.io.File;
-
-import javax.swing.filechooser.FileSystemView;
-
-import bilib.tools.Files;
-import deconvolution.Deconvolution;
-import deconvolutionlab.Imager;
-import deconvolutionlab.Lab;
-import deconvolutionlab.monitor.Monitors;
-import fft.AbstractFFT;
-import fft.FFT;
-import ij.plugin.PlugIn;
-import signal.ComplexSignal;
-import signal.Operations;
-import signal.RealSignal;
-import signal.factory.DoG;
-import signal.factory.Gaussian;
-import signal.factory.complex.ComplexSignalFactory;
-
-public class DeconvolutionLab2_Course_SpectralAnaylsis implements PlugIn {
-
- private String root = Files.getDesktopDirectory() + "Deconvolution" + File.separator;
- private String res = root + "results" + File.separator + "star" + File.separator;
- private String data = root + "data" + File.separator + "star" + File.separator;
-
- public DeconvolutionLab2_Course_SpectralAnaylsis() {
-
- new File(res).mkdir();
- System.setProperty("user.dir", res);
-
- new File(res + "TRIF").mkdir();
- new File(res + "TRIF-FILTER").mkdir();
- new File(res + "RIF").mkdir();
- new File(res + "RIF-FILTER").mkdir();
- new File(res + "LW").mkdir();
- new File(res + "LW-ITER").mkdir();
- new File(res + "LW+").mkdir();
- new File(res + "LW+-ITER").mkdir();
- new File(res + "RL").mkdir();
- new File(res + "RL-ITER").mkdir();
- new File(res + "NOISELESS").mkdir();
- new File(res + "PERTURBATION").mkdir();
- new File(res + "SIMULATION").mkdir();
- new File(res + "ICTM").mkdir();
- new File(res + "ICTM-ITER").mkdir();
-
- Monitors monitors = Monitors.createDefaultMonitor();
- int nx = 256;
- int ny = 256;
- int nz = 1;
- String size = " size " + nx + " " + ny + " " + nz;
- double noise = 0.04;
- double poisson = 0.01;
- double wiener = Math.sqrt(noise * 2.0 / Math.PI);
- System.out.println("Wiener value " + wiener);
- AbstractFFT fft = FFT.createDefaultFFT(monitors, nx, ny, nz);
- ComplexSignal L = ComplexSignalFactory.laplacian(nx, ny, nz);
- RealSignal laplacian = fft.inverse(L).circular().rescale(monitors);
- Lab.save(monitors, laplacian, res + "laplacian.tif", Imager.Type.BYTE);
-
- RealSignal h = new DoG(2, 3.6).generate(nx, ny, nz);
- h.times(0.7f);
- h.plus(new Gaussian(1.5, 1.5, 1.5).generate(nx, ny, nz));
- Lab.save(monitors, h, res + "psf.tif");
-
- h.plus(new Gaussian(0.5, 0.5, 0.5).generate(nx, ny, nz));
- Lab.save(monitors, h, res + "psfPerturbated.tif");
-
- String psf = " -psf file psf.tif -fft FFTW2";
- String impulse = " -psf synthetic impulse 100.0 0.0 " + size;
- String image = " -image file " + data + "ref.tif";
- String constant = " -image constant 0 0 " + size;
-
- // Simulation
- String algo = " -algorithm CONV " + out("CONV");
- new Deconvolution("run", psf + image + algo).deconvolve();
-
- algo = " -algorithm CONV " + out("CONV-PERTURBATED");
- new Deconvolution("run", psf + image + algo).deconvolve();
- ComplexSignal H = fft.transform(h);
- ComplexSignal H2 = Operations.multiply(H, H);
- ComplexSignal LP = ComplexSignalFactory.laplacian(nx, ny, nz);
-
- algo = " -algorithm SIM " + (6*noise) + " " + noise + " " + poisson + " " + out("SIM");
- new Deconvolution("run", psf + image + algo).deconvolve();
-
- algo = " -algorithm SIM " + (6*noise) + " " + noise + " " + poisson + " " + out("NOISE");
- new Deconvolution("run", impulse + constant + algo).deconvolve();
-
- // No Noise
- String nonoise = " -image file CONV.tif -psf file psfPerturbated.tif";
- new Deconvolution("run", nonoise + " -algorithm TRIF " + wiener + out("NOISELESS/WIF")).deconvolve();
- new Deconvolution("run", nonoise + " -algorithm NIF -epsilon 1E0 " + out("NOISELESS/NIF0")).deconvolve();
- new Deconvolution("run", nonoise + " -algorithm NIF -epsilon 1E-3 " + out("NOISELESS/NIF-1")).deconvolve();
- new Deconvolution("run", nonoise + " -algorithm NIF -epsilon 1E-6 " + out("NOISELESS/NIF-6")).deconvolve();
- new Deconvolution("run", nonoise + " -algorithm NIF -epsilon 1E-9 " + out("NOISELESS/NIF-9")).deconvolve();
- new Deconvolution("run", nonoise + " -algorithm NIF -epsilon 1E-12 " + out("NOISELESS/NIF-12")).deconvolve();
- new Deconvolution("run", nonoise + " -algorithm DIV " + out("NOISELESS/DIV")).deconvolve();
-
- // Pertubatation
- String pertubation = " -image file CONV.tif -psf file psfPerturbated.tif";
- new Deconvolution("run", pertubation + " -algorithm TRIF " + wiener + out("PERTURBATION/WIF")).deconvolve();
- new Deconvolution("run", pertubation + " -algorithm NIF " + out("PERTURBATION/NIF")).deconvolve();
- new Deconvolution("run", pertubation + " -algorithm DIV " + out("PERTURBATION/DIV")).deconvolve();
-
- // Noisy
- String simulation = " -image file SIM.tif " + psf;
-
- new Deconvolution("run", simulation + " -algorithm TRIF " + wiener + out("SIMULATION/WIF")).deconvolve();
- new Deconvolution("run", simulation + " -algorithm NIF "+ out("SIMULATION/NIF")).deconvolve();
- new Deconvolution("run", simulation + " -algorithm DIV" + out("SIMULATION/DIV")).deconvolve();
-
- algo = " -algorithm LW+ 100 0.5 -out mip @1 LW+-ITER/I ";
- new Deconvolution("run", simulation + algo + out("LW+/LW+")).deconvolve();
- new File(res + "LW+-ITER/I.tif").delete();
-
- for(int i=0; i<=20; i++) {
- double p = Math.pow(5, i-12);
- String name = "RIF/RIF" + String.format("%02d", i);
- new Deconvolution("run", simulation + " -algorithm RIF " + p + out(name)).deconvolve();
- RealSignal fa = fft.inverse(Operations.add(H2, Operations.multiply(p, LP, LP))).circular();
- Lab.save(monitors, fa, res + "RIF-FILTER/RIF" + String.format("%02d", i) + ".tif");
- }
-
- for(int i=0; i<=20; i++) {
- double p = Math.pow(5, i-12);
- String name = "TRIF/TRIF" + String.format("%02d", i);
- new Deconvolution("run", simulation + " -algorithm TRIF " + p + out(name)).deconvolve();
- RealSignal fa = fft.inverse(Operations.add(H2, Operations.multiply(p, LP, LP))).circular();
- Lab.save(monitors, fa, res + "TRIF-FILTER/RIF" + String.format("%02d", i) + ".tif");
- }
-
-
- algo = " -algorithm RL 100 -out mip @1 RL-ITER/I ";
- new Deconvolution("run", simulation + algo + out("RL/RL")).deconvolve();
- new File(res + "RL-ITER/I.tif").delete();
-
- algo = " -algorithm ICTM 100 1.5 0.001 -out mip @1 ICTM-ITER/I ";
- new Deconvolution("run", simulation + algo + out("ICTM/ICTM")).deconvolve();
- new File(res + "ICTM-ITER/I.tif").delete();
-
- }
-
- private static String out(String name) {
- return " -out stats " + name +
- " -out stack " + name + " noshow -out ortho " + name + "-BYTE rescaled byte noshow";
- }
-
- public static void main(String arg[]) {
- new DeconvolutionLab2_Course_SpectralAnaylsis();
- }
-
- @Override
- public void run(String arg) {
- new DeconvolutionLab2_Course_SpectralAnaylsis();
- }
-
-}
diff --git a/DeconvolutionLab2/src/course/DeconvolutionLab2_MemoryFootprint.java b/DeconvolutionLab2/src/course/DeconvolutionLab2_MemoryFootprint.java
deleted file mode 100644
index aa43077..0000000
--- a/DeconvolutionLab2/src/course/DeconvolutionLab2_MemoryFootprint.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * DeconvolutionLab2
- *
- * Conditions of use: You are free to use this software for research or
- * educational purposes. In addition, we expect you to include adequate
- * citations and acknowledgments whenever you present or publish results that
- * are based on it.
- *
- * Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
- * Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
- * R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
- */
-
-/*
- * Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
- *
- * This file is part of DeconvolutionLab2 (DL2).
- *
- * DL2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * DL2. If not, see <http://www.gnu.org/licenses/>.
- */
-package course;
-
-import bilib.table.CustomizedTable;
-import bilib.tools.NumFormat;
-import deconvolution.Deconvolution;
-import ij.plugin.PlugIn;
-import signal.SignalCollector;
-
-public class DeconvolutionLab2_MemoryFootprint implements PlugIn {
-
- public DeconvolutionLab2_MemoryFootprint() {
-
- CustomizedTable table = new CustomizedTable(new String[] { "Name", "Algo", "Optimized", "Time", "Energy", "Peak Count", "Peak Bytes", "End Count", "End Byte", "Ratio" }, true);
- table.show("Memory Footprint", 1100, 300);
-
- run(table, "CONV");
- run(table, "FISTA 10 1 1");
- run(table, "ICTM 10 1 0.1");
- run(table, "I");
- run(table, "ISTA 10 1 1");
- run(table, "LW 10 1");
- run(table, "LLS 10 1");
- run(table, "NLLS 10 1");
- run(table, "NIF");
- run(table, "DIV");
- run(table, "RIF 1");
- run(table, "RL 10");
- run(table, "RLTV 10 1");
- run(table, "SIM 1 1 1");
- run(table, "BVLS 10 1");
- run(table, "TM 10 1 0.1");
- run(table, "TRIF 1");
- run(table, "VC 10 1");
- }
-
- private void run(CustomizedTable table, String cmd) {
- int nx = 64;
- int ny = 32;
- int nz = 12;
- String size = " size " + nx + " " + ny + " " + nz;
- String image = " -image synthetic Cross 110 0 1 1 80.0 " + size;
- String psf = " -psf synthetic Double-Helix 100 0 3 10 10 " + size;
-
- for (int i = 0; i <= 1; i++) {
- SignalCollector.resetSignals();
- SignalCollector.clear();
- Deconvolution d = new Deconvolution("noise", " -algorithm " + cmd + psf + image + " -display no");
- boolean optimized = i == 1;
- d.getAlgorithm().setOptimizedMemoryFootprint(optimized);
- String n = d.getAlgorithm().getName();
- double chrono = System.nanoTime();
- d.run();
- String energy = "" + d.getOutput().getEnergy();
- String time = NumFormat.time(System.nanoTime() - chrono);
- int cp = SignalCollector.getCountPeakSignals();
- int cs = SignalCollector.getCountSignals();
- long bp = SignalCollector.getBytesPeakSignals();
- long bs = SignalCollector.getBytesSignals();
- double ratio = (bp + bs) / (nx * ny * nz * 4);
- table.append(new String[] { n, cmd, "" + optimized, time, energy, "" + cp, NumFormat.bytes(bp), "" + cs, NumFormat.bytes(bs), NumFormat.nice(ratio) });
- }
- }
-
- public static void main(String arg[]) {
- new DeconvolutionLab2_MemoryFootprint();
- }
-
- @Override
- public void run(String arg) {
- new DeconvolutionLab2_MemoryFootprint();
- }
-
-}
diff --git a/DeconvolutionLab2/src/deconvolution/Command.java b/DeconvolutionLab2/src/deconvolution/Command.java
index 44aa624..edb6e67 100644
--- a/DeconvolutionLab2/src/deconvolution/Command.java
+++ b/DeconvolutionLab2/src/deconvolution/Command.java
@@ -1,432 +1,430 @@
/*
* 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 ij.IJ;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import signal.Constraint;
+import signal.Operations;
+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 bilib.tools.Files;
import bilib.tools.NumFormat;
import deconvolution.algorithm.Algorithm;
import deconvolution.algorithm.AlgorithmList;
import deconvolution.algorithm.Controller;
import deconvolutionlab.Constants;
import deconvolutionlab.module.AbstractModule;
import deconvolutionlab.module.CommandModule;
import deconvolutionlab.monitor.ConsoleMonitor;
import deconvolutionlab.monitor.Monitors;
import deconvolutionlab.monitor.TableMonitor;
import deconvolutionlab.monitor.Verbose;
import deconvolutionlab.output.Output;
import deconvolutionlab.output.Output.View;
import fft.FFT;
-import signal.Constraint;
-import signal.Operations;
-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;
public class Command {
public static String keywords[] = { "-image", "-psf", "-algorithm", "-path", "-disable", "-verbose", "-monitor", "-display", "-multithreading", "-system", "-stats", "-constraint", "-time", "-residu", "-reference", "-out", "-pad", "-apo", "-norm", "-fft", "-epsilon" };
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;
}
public static Controller decodeController(String command) {
Controller controller = new Controller();
- ArrayList<Token> tokens = parse(command);
- for (Token token : tokens) {
+ ArrayList<CommandToken> tokens = parse(command);
+ for (CommandToken token : tokens) {
if (token.keyword.equalsIgnoreCase("-path")) {
if (token.parameters.trim().equals("current"))
controller.setPath(Files.getWorkingDirectory());
else if (token.parameters.trim().equals("home"))
controller.setPath(Files.getHomeDirectory());
else if (token.parameters.trim().equals("desktop"))
controller.setPath(Files.getDesktopDirectory());
else
controller.setPath(token.parameters);
}
if (token.keyword.equalsIgnoreCase("-monitor"))
controller.setMonitors(decodeMonitors(token.parameters));
if (token.keyword.equalsIgnoreCase("-verbose"))
controller.setVerbose(Verbose.getByName(token.parameters));
if (token.keyword.equalsIgnoreCase("-system"))
controller.setSystem(decodeBoolean(token.parameters));
if (token.keyword.equalsIgnoreCase("-multithreading"))
controller.setMultithreading(decodeBoolean(token.parameters));
if (token.keyword.equalsIgnoreCase("-display"))
controller.setDisplayFinal(decodeBoolean(token.parameters));
if (token.keyword.equalsIgnoreCase("-stats"))
controller.setStats(decodeStats(token));
if (token.keyword.equalsIgnoreCase("-constraint"))
controller.setConstraint(decodeConstraint(token));
if (token.keyword.equalsIgnoreCase("-time"))
controller.setTimeLimit(decodeTimeLimit(token));
if (token.keyword.equalsIgnoreCase("-residu"))
controller.setResiduMin(decodeResidu(token));
if (token.keyword.equalsIgnoreCase("-reference"))
controller.setReferenceName(token.parameters);
if (token.keyword.equalsIgnoreCase("-pad"))
controller.setPadding(decodePadding(token));
if (token.keyword.equalsIgnoreCase("-apo"))
controller.setApodization(decodeApodization(token));
if (token.keyword.equalsIgnoreCase("-norm"))
controller.setNormalizationPSF(decodeNormalization(token));
if (token.keyword.equalsIgnoreCase("-epsilon"))
Operations.epsilon = NumFormat.parseNumber(token.parameters, 1e-6);
if (token.keyword.equalsIgnoreCase("-fft"))
controller.setFFT(FFT.getLibraryByName(token.parameters).getDefaultFFT());
if (token.keyword.equalsIgnoreCase("-epsilon"))
Operations.epsilon = NumFormat.parseNumber(token.parameters, 1e-6);
if (token.keyword.equals("-out")) {
Output out = decodeOut(token);
if (out != null)
controller.addOutput(out);
}
}
return controller;
}
public static Algorithm decodeAlgorithm(String command) {
Algorithm algo = AlgorithmList.getDefaultAlgorithm();
- ArrayList<Token> tokens = parse(command);
- for (Token token : tokens) {
+ ArrayList<CommandToken> tokens = parse(command);
+ for (CommandToken token : tokens) {
if (token.keyword.equalsIgnoreCase("-algorithm"))
algo = Command.decodeAlgorithm(token);
}
return algo;
}
/**
* 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) {
+ public static ArrayList<CommandToken> 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>();
+ ArrayList<CommandToken> tokens = new ArrayList<CommandToken>();
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);
+ CommandToken token = new CommandToken(keyword, command, begin, end);
tokens.add(token);
}
return tokens;
}
- public static Token extract(String command, String keyword) {
- ArrayList<Token> tokens = parse(command);
- for (Token token : tokens)
+ public static CommandToken extract(String command, String keyword) {
+ ArrayList<CommandToken> tokens = parse(command);
+ for (CommandToken token : tokens)
if (token.keyword.equalsIgnoreCase(keyword))
return token;
- return (Token) null;
+ return (CommandToken) 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)";
if (command == null)
return segments;
Matcher matcher = Pattern.compile(regex).matcher(command);
while (matcher.find()) {
segments.add(new CommandSegment(keyword, matcher.start()));
}
return segments;
}
public static String extractOptions(String command) {
ArrayList<CommandSegment> segments = new ArrayList<CommandSegment>();
for (String keyword : keywords)
segments.addAll(findSegment(command, keyword));
Collections.sort(segments);
String options = "";
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());
if (keyword != "-image" && keyword != "-psf" && keyword != "-algorithm")
options += keyword + " " + command.substring(begin, end);
}
return options;
}
- public static Algorithm decodeAlgorithm(Token token) {
+ public static Algorithm decodeAlgorithm(CommandToken token) {
String option = token.option;
Algorithm algo = AlgorithmList.createAlgorithm(option);
double params[] = parseNumeric(token.parameters);
if (params != null) {
algo.setParameters(params);
}
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) {
+ public static Output decodeOut(CommandToken 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 double decodeNormalization(Token token) {
+ public static double decodeNormalization(CommandToken token) {
if (token.parameters.toLowerCase().endsWith("no"))
return 0;
else
return NumFormat.parseNumber(token.parameters, 1);
}
- public static Stats decodeStats(Token token) {
+ public static Stats decodeStats(CommandToken token) {
String parts[] = token.parameters.toLowerCase().split(" ");
int m = 0;
for (String p : parts) {
if (p.startsWith("no") || p.equals("false") || p.equals("0"))
return new Stats(Stats.Mode.NO);
if (p.equals("1"))
return new Stats(Stats.Mode.SHOW);
if (p.equals("2"))
return new Stats(Stats.Mode.SAVE);
if (p.equals("3"))
return new Stats(Stats.Mode.SHOWSAVE);
if (p.equals("show"))
m += 1;
if (p.equals("save"))
m += 2;
}
if (m==1)
return new Stats(Stats.Mode.SHOW);
if (m==2)
return new Stats(Stats.Mode.SAVE);
if (m==3)
return new Stats(Stats.Mode.SHOWSAVE);
return new Stats(Stats.Mode.NO);
}
- public static Constraint.Mode decodeConstraint(Token token) {
+ public static Constraint.Mode decodeConstraint(CommandToken token) {
String p = token.parameters.toLowerCase();
if (p.startsWith("non"))
return Constraint.Mode.NONNEGATIVE;
if (p.startsWith("no"))
return Constraint.Mode.NO;
if (p.startsWith("clip"))
return Constraint.Mode.CLIPPED;
if (p.equals("0"))
return Constraint.Mode.NO;
return Constraint.Mode.NO;
}
- public static double decodeResidu(Token token) {
+ public static double decodeResidu(CommandToken token) {
if (token.parameters.toLowerCase().endsWith("no"))
return -1;
else
return NumFormat.parseNumber(token.parameters, 1);
}
- public static double decodeTimeLimit(Token token) {
+ public static double decodeTimeLimit(CommandToken token) {
if (token.parameters.toLowerCase().endsWith("no"))
return -1;
else
return NumFormat.parseNumber(token.parameters, 1);
}
- public static Padding decodePadding(Token token) {
+ public static Padding decodePadding(CommandToken token) {
AbstractPadding padXY = new NoPadding();
AbstractPadding padZ = new NoPadding();
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);
int extXY = 0;
if (ext.length > 0)
extXY = (int) Math.round(ext[0]);
int extZ = 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) {
+ public static Apodization decodeApodization(CommandToken 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);
}
public static String getPath() {
command();
- ArrayList<Token> tokens = parse(command.getCommand());
+ ArrayList<CommandToken> tokens = parse(command.getCommand());
String path = System.getProperty("user.dir");
- for (Token token : tokens)
+ for (CommandToken token : tokens)
if (token.keyword.equalsIgnoreCase("-path") && !token.parameters.equalsIgnoreCase("current"))
path = token.parameters;
return path;
}
public static Monitors decodeMonitors(String cmd) {
String parts[] = cmd.toLowerCase().split(" ");
Monitors monitors = new Monitors();
for (String p : parts) {
if (p.equals("0") || p.startsWith("no"))
monitors.clear();
if (p.equals("1") || p.startsWith("console"))
monitors.add(new ConsoleMonitor());
if (p.equals("2"))
monitors.add(new TableMonitor(Constants.widthGUI, 240));
if (p.equals("3")) {
monitors.add(new ConsoleMonitor());
monitors.add(new TableMonitor(Constants.widthGUI, 240));
}
if (p.equals("console"))
monitors.add(new ConsoleMonitor());
if (p.equals("table"))
monitors.add(new TableMonitor(Constants.widthGUI, 240));
}
return monitors;
}
public static boolean decodeBoolean(String cmd) {
String p = cmd.toLowerCase();
if (p.startsWith("no"))
return false;
if (p.equals("0"))
return false;
if (p.equals("false"))
return false;
if (p.startsWith("dis"))
return false;
return true;
}
}
diff --git a/DeconvolutionLab2/src/deconvolution/Token.java b/DeconvolutionLab2/src/deconvolution/CommandToken.java
similarity index 92%
rename from DeconvolutionLab2/src/deconvolution/Token.java
rename to DeconvolutionLab2/src/deconvolution/CommandToken.java
index 3b1cc05..d0ec9b1 100644
--- a/DeconvolutionLab2/src/deconvolution/Token.java
+++ b/DeconvolutionLab2/src/deconvolution/CommandToken.java
@@ -1,86 +1,93 @@
/*
* 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/>.
*/
/*
* 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;
+ */
+package deconvolution;
-public class Token {
+/**
+ * This class is the basic component of the command.
+ *
+ * @author Daniel Sage
+ *
+ */
+public class CommandToken {
public String keyword;
public String parameters = "?";
public String option = "?";
- public Token(String keyword, String command, int begin, int end) {
+ public CommandToken(String keyword, String command, int begin, int end) {
this.keyword = keyword;
try {
this.parameters = command.substring(begin, end).trim();
String arg[] = parameters.split(" ");
option = arg.length >= 1 ? arg[0].trim() : "";
}
catch(Exception ex) {
option = "";
}
}
@Override
public String toString() {
return keyword + " [" + option + "]" + parameters;
}
}
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/deconvolution/Deconvolution.java b/DeconvolutionLab2/src/deconvolution/Deconvolution.java
index d885c03..c27a2e8 100644
--- a/DeconvolutionLab2/src/deconvolution/Deconvolution.java
+++ b/DeconvolutionLab2/src/deconvolution/Deconvolution.java
@@ -1,410 +1,406 @@
/*
* 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 ij.IJ;
-
import java.io.File;
+import signal.RealSignal;
+import signal.SignalCollector;
import bilib.tools.NumFormat;
import deconvolution.algorithm.Algorithm;
import deconvolution.algorithm.Controller;
import deconvolutionlab.Lab;
import deconvolutionlab.monitor.AbstractMonitor;
import deconvolutionlab.monitor.Monitors;
-import deconvolutionlab.monitor.StatusMonitor;
import deconvolutionlab.monitor.TableMonitor;
import deconvolutionlab.output.Output;
-import signal.RealSignal;
-import signal.SignalCollector;
/**
* This class is the main class to run deconvolution with or without user interface.
*
* All the parameters are given in the command line (String variable command).
*
* @author Daniel Sage
*
*/
public class Deconvolution implements Runnable {
public enum Finish {
DIE, ALIVE, KILL
};
private Algorithm algo = null;
- private Controller controller = new Controller();
- private String command = "";
- private Features report = new Features();
- private String name = "";
- public RealSignal image;
- public RealSignal psf;
- private RealSignal deconvolvedImage;
- private Finish finish = Finish.DIE;
- private DeconvolutionDialog dialog;
-
- private boolean embeddedStats = false;
+ private Controller controller = new Controller();
+ private String command = "";
+ private Features report = new Features();
+ private String name = "";
+ public RealSignal image;
+ public RealSignal psf;
+ private RealSignal deconvolvedImage;
+ private Finish finish = Finish.DIE;
+ private DeconvolutionDialog dialog;
+ private boolean embeddedStats = false;
public Deconvolution(String name, String command) {
this.name = name;
this.finish = Finish.DIE;
setCommand(command);
}
public Deconvolution(String name, String command, Finish finish) {
this.name = name;
this.finish = finish;
setCommand(command);
}
public void setCommand(String command) {
this.command = command;
controller = Command.decodeController(command);
algo = Command.decodeAlgorithm(command);
algo.setController(controller);
this.command = command;
if (name.equals("") && algo != null)
name = algo.getShortnames()[0];
}
public RealSignal deconvolve() {
return deconvolve(image, psf);
}
public RealSignal deconvolve(RealSignal image, RealSignal psf) {
this.image = image;
this.psf = psf;
for(AbstractMonitor monitor : controller.getMonitors())
if (monitor instanceof TableMonitor)
Lab.setVisible(((TableMonitor)monitor).getPanel(), "Monitor of " + name, 10, 10);
if (controller.getFFT() == null) {
run();
return deconvolvedImage;
}
if (!controller.getFFT().isMultithreadable()) {
run();
return deconvolvedImage;
}
if (controller.isMultithreading()) {
Thread thread = new Thread(this);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
else {
run();
}
return deconvolvedImage;
}
/**
* This method runs the deconvolution with a graphical user interface.
*/
public void launch() {
embeddedStats = true;
dialog = new DeconvolutionDialog(DeconvolutionDialog.Module.ALL, this);
Lab.setVisible(dialog, false);
}
@Override
public void run() {
double chrono = System.nanoTime();
Monitors monitors = controller.getMonitors();
report.add("Path", controller.toStringPath());
if (image == null)
image = openImage();
if (image == null) {
monitors.error("Image: Not valid " + command);
report.add("Image", "Not valid");
if (finish == Finish.KILL)
System.exit(-101);
return;
}
report.add("Image", image.dimAsString());
monitors.log("Image: " + image.dimAsString());
psf = openPSF();
if (psf == null) {
monitors.error("PSF: not valid");
report.add("PSF", "Not valid");
if (finish == Finish.KILL)
System.exit(-102);
return;
}
report.add("PSF", psf.dimAsString());
if (algo == null) {
monitors.error("Algorithm: not valid");
if (finish == Finish.KILL)
System.exit(-103);
return;
}
report.add("FFT", controller.getFFT().getName());
report.add("Algorithm", algo.getName());
if (embeddedStats) {
TableMonitor tableMonitor = null;
for(AbstractMonitor monitor : controller.getMonitors())
if (monitor instanceof TableMonitor)
tableMonitor = (TableMonitor)monitor;
if (controller.getStats().getMode() == Stats.Mode.SHOW || controller.getStats().getMode() == Stats.Mode.SHOWSAVE) {
controller.getStats().setEmbeddedInFrame(embeddedStats);
dialog.addStats(controller.getStats());
}
if (tableMonitor != null) {
dialog.addMonitor(tableMonitor);
}
}
algo.setController(controller);
deconvolvedImage = algo.run(image, psf);
report.add("End", NumFormat.time(System.nanoTime() - chrono));
if (finish == Finish.KILL) {
System.out.println("End");
System.exit(0);
}
if (finish == Finish.DIE)
die();
}
public void close() {
if (dialog != null)
dialog.dispose();
SignalCollector.free(image);
SignalCollector.free(psf);
SignalCollector.free(deconvolvedImage);
algo = null;
image = null;
psf = null;
deconvolvedImage = null;
System.gc();
}
public void die() {
SignalCollector.free(image);
SignalCollector.free(psf);
}
/**
* This methods make a recap of the deconvolution. Useful before starting
* the processing.
*
* @return list of messages to print
*/
public Features recap() {
Features features = new Features();
- Token image = Command.extract(command, "-image");
+ CommandToken image = Command.extract(command, "-image");
features.add("Image", image == null ? "keyword -image not found" : image.parameters);
double norm = controller.getNormalizationPSF();
String normf = (norm < 0 ? " (no normalization)" : " (normalization to " + norm + ")");
- Token psf = Command.extract(command, "-psf");
+ CommandToken psf = Command.extract(command, "-psf");
features.add("PSF", psf == null ? "keyword -psf not found" : psf.parameters + " norm:" + normf);
if (algo == null) {
features.add("Algorithm", "not valid>");
}
else {
Controller controller = algo.getController();
features.add("Algorithm", algo.toString());
features.add("Stopping Criteria", controller.getStoppingCriteriaAsString(algo));
features.add("Reference", controller.getReferenceName());
features.add("Constraint", controller.getConstraintAsString());
features.add("Padding", controller.getPadding().toString());
features.add("Apodization", controller.getApodization().toString());
features.add("FFT", controller.getFFT() == null ? "null" : controller.getFFT().getName());
}
features.add("Path", controller.getPath());
String s = "[" + controller.getVerbose().name() + "] ";
for(AbstractMonitor monitor : controller.getMonitors())
s+= monitor.getName() + " ";
features.add("Monitor", s);
if (controller.getStats() != null)
features.add("Stats", controller.getStats().toStringStats());
features.add("Running", controller.toStringRunning());
for (Output out : controller.getOuts())
features.add("Output " + out.getName(), out.toString());
controller.getMonitors().log("Recap deconvolution parameters");
return features;
}
public Features checkOutput() {
Features features = new Features();
if (deconvolvedImage == null) {
features.add("Image", "No valid output image");
return features;
}
float stati[] = deconvolvedImage.getStats();
int sizi = deconvolvedImage.nx * deconvolvedImage.ny * deconvolvedImage.nz;
float totali = stati[0] * sizi;
features.add("<html><b>Deconvolved Image</b></html>", "");
features.add("Size", deconvolvedImage.dimAsString() + " " + NumFormat.bytes(sizi * 4));
features.add("Mean (stdev)", NumFormat.nice(stati[0]) + " (" + NumFormat.nice(stati[3]) + ")");
features.add("Min ... Max", NumFormat.nice(stati[1]) + " ... " + NumFormat.nice(stati[2]));
features.add("Energy (int)", NumFormat.nice(stati[5]) + " (" + NumFormat.nice(totali) + ")");
return features;
}
public void abort() {
algo.getController().abort();
}
public RealSignal openImage() {
- Token token = Command.extract(command, "-image");
+ CommandToken token = Command.extract(command, "-image");
if (token == null)
return null;
if (token.parameters.startsWith(">>>"))
return null;
String arg = token.option.trim();
String cmd = token.parameters.substring(arg.length(), token.parameters.length()).trim();
image = createRealSignal(controller.getMonitors(), arg, cmd, controller.getPath());
controller.getMonitors().log("Open image " + arg + " " + cmd);
return image;
}
public RealSignal openPSF() {
- Token token = Command.extract(command, "-psf");
+ CommandToken token = Command.extract(command, "-psf");
if (token == null)
return null;
if (token.parameters.startsWith(">>>"))
return null;
String arg = token.option.trim();
String cmd = token.parameters.substring(arg.length(), token.parameters.length()).trim();
psf = createRealSignal(controller.getMonitors(), arg, cmd, controller.getPath());
controller.getMonitors().log("Open PSF " + arg + " " + cmd);
return psf;
}
private static RealSignal createRealSignal(Monitors monitors, String arg, String cmd, String path) {
RealSignal signal = null;
if (arg.equalsIgnoreCase("synthetic")) {
signal = Lab.createSynthetic(monitors, cmd);
}
if (arg.equalsIgnoreCase("platform")) {
signal = Lab.getImage(monitors, cmd);
}
if (arg.equalsIgnoreCase("file")) {
File file = new File(path + File.separator + cmd);
if (file != null) {
if (file.isFile())
signal = Lab.openFile(monitors, path + File.separator + cmd);
}
if (signal == null) {
File local = new File(cmd);
if (local != null) {
if (local.isFile())
signal = Lab.openFile(monitors, cmd);
}
}
}
if (arg.equalsIgnoreCase("dir") || arg.equalsIgnoreCase("directory")) {
File file = new File(path + File.separator + cmd);
if (file != null) {
if (file.isDirectory())
signal = Lab.openDir(monitors, path + File.separator + cmd);
}
if (signal == null) {
File local = new File(cmd);
if (local != null) {
if (local.isDirectory())
signal = Lab.openDir(monitors, cmd);
}
}
}
return signal;
}
public void setAlgorithm(Algorithm algo) {
this.algo = algo;
}
public Algorithm getAlgorithm() {
return algo;
}
public void setController(Controller controller) {
this.controller = controller;
}
public Controller getController() {
return controller;
}
public RealSignal getOutput() {
return deconvolvedImage;
}
public RealSignal getImage() {
return image;
}
public RealSignal getPSF() {
return psf;
}
public Features getDeconvolutionReports() {
return report;
}
public String getName() {
return name;
}
public Monitors getMonitors() {
return controller.getMonitors();
}
public String getCommand() {
return command;
}
}
diff --git a/DeconvolutionLab2/src/deconvolution/algorithm/Controller.java b/DeconvolutionLab2/src/deconvolution/algorithm/Controller.java
index 6709698..fec111d 100644
--- a/DeconvolutionLab2/src/deconvolution/algorithm/Controller.java
+++ b/DeconvolutionLab2/src/deconvolution/algorithm/Controller.java
@@ -1,676 +1,676 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolution.algorithm;
import java.io.File;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import signal.Assessment;
import signal.ComplexSignal;
import signal.Constraint;
import signal.RealSignal;
import signal.apodization.Apodization;
import signal.padding.Padding;
import bilib.tools.Files;
import bilib.tools.NumFormat;
import deconvolution.Deconvolution;
import deconvolution.Stats;
import deconvolutionlab.Constants;
import deconvolutionlab.monitor.AbstractMonitor;
import deconvolutionlab.monitor.ConsoleMonitor;
import deconvolutionlab.monitor.Monitors;
import deconvolutionlab.monitor.TableMonitor;
import deconvolutionlab.monitor.Verbose;
import deconvolutionlab.output.Output;
import deconvolutionlab.system.SystemUsage;
import fft.AbstractFFT;
import fft.FFT;
/**
* This is an important class to manage all the common task of the algorithm.
* The method start() is called before at the starting of the algorithm. The
* method ends() is called at the end of every iterations for the iterative
* algorithm. It returns true if one the stopping criteria is true. The method
* finish() is called when the algorithm is completely terminated.
*
* A timer is started to get the peak memory.
*
* @author Daniel Sage
*
*/
public class Controller {
private String path;
private boolean system;
private boolean multithreading;
private boolean displayFinal;
private double normalizationPSF;
private double epsilon;
private Padding padding;
private Apodization apodization;
private ArrayList<Output> outs;
private Stats stats;
private Constraint.Mode constraintMode;
private double residuMin;
private double timeLimit;
private String referenceName;
private Monitors monitors;
private Verbose verbose;
private AbstractFFT fft;
private int iterationsMax = 100;
private boolean doResidu = false;
private boolean doTime = false;
private boolean doReference = false;
private boolean doConstraint = false;
private boolean abort = false;
private double timeStarting = 0;
private double memoryStarting = 0;
private double residu = Double.MAX_VALUE;
private int iterations = 0;
private double memoryPeak = 0;
private double snr = 0;
private double psnr = 0;
private RealSignal refImage;
private RealSignal prevImage;
private RealSignal x;
private Timer timer;
private String algoName = "";
/**
* Constructor.
*
* One controller is always instantiated for every run of a algorithm.
*/
public Controller() {
doResidu = false;
doTime = false;
doReference = false;
doConstraint = false;
timeStarting = System.nanoTime();
setPath(Files.getWorkingDirectory());
setSystem(true);
setMultithreading(true);
setDisplayFinal(true);
setFFT(FFT.getFastestFFT().getDefaultFFT());
setNormalizationPSF(1);
setEpsilon(1e-6);
setPadding(new Padding());
setApodization(new Apodization());
monitors = new Monitors();
monitors.add(new ConsoleMonitor());
monitors.add(new TableMonitor(Constants.widthGUI, 240));
setVerbose(Verbose.Log);
setStats(new Stats(Stats.Mode.NO));
setConstraint(Constraint.Mode.NO);
setResiduMin(-1);
setTimeLimit(-1);
setReference(null);
setOuts(new ArrayList<Output>());
}
public void setAlgoName(String algoName) {
this.algoName = algoName;
}
public void setFFT(AbstractFFT fft) {
this.fft = fft;
}
public void abort() {
this.abort = true;
}
public void setIterationsMax(int iterationsMax) {
this.iterationsMax = iterationsMax;
}
public boolean needSpatialComputation() {
return doConstraint || doResidu || doReference;
}
/**
* Call one time at the beginning of the algorithms
*
* @param x
* the input signal
*/
public void start(RealSignal x) {
this.x = x;
stats.show();
stats.addInput(x);
iterations = 0;
timer = new Timer();
timer.schedule(new Updater(), 0, 100);
timeStarting = System.nanoTime();
memoryStarting = SystemUsage.getHeapUsed();
if (doConstraint && x != null)
Constraint.setModel(x);
- if (doReference) {
+ if (doReference && refImage == null) {
refImage = new Deconvolution("Reference", "-image file " + referenceName).openImage();
if (refImage == null)
monitors.error("Impossible to load the reference image " + referenceName);
else
monitors.log("Reference image loaded");
}
for (Output out : outs)
out.executeStarting(monitors, x, this);
this.prevImage = x;
}
public boolean ends(ComplexSignal X) {
boolean out = false;
for (Output output : outs)
out = out | output.is(iterations);
if (doConstraint || doResidu || doReference || out) {
if (fft == null)
fft = FFT.createDefaultFFT(monitors, X.nx, X.ny, X.nz);
x = fft.inverse(X, x);
return ends(x);
}
return ends((RealSignal) null);
}
public boolean ends(RealSignal x) {
this.x = x;
if (doConstraint || doResidu || doReference)
compute(iterations, x, doConstraint, doResidu, doReference);
for (Output out : outs)
out.executeIterative(monitors, x, this, iterations);
iterations++;
double p = iterations * 100.0 / iterationsMax;
monitors.progress("Iterative " + iterations + "/" + iterationsMax, p);
double timeElapsed = getTimeSecond();
boolean stopIter = (iterations >= iterationsMax);
boolean stopTime = doTime && (timeElapsed >= timeLimit);
boolean stopResd = doResidu && (residu <= residuMin);
monitors.log("@" + iterations + " Time: " + NumFormat.seconds(timeElapsed*1e9));
String pnsrText = doReference ? "" + psnr : "n/a";
String snrText = doReference ? "" + snr : "n/a";
String residuText = doResidu ? "" + residu : "n/a";
stats.add(x, iterations, NumFormat.seconds(getTimeNano()), pnsrText, snrText, residuText);
String prefix = "Stopped>> by ";
if (abort)
monitors.log(prefix + "abort");
if (stopIter)
monitors.log(prefix + "iteration " + iterations + " > " + iterationsMax);
if (stopTime)
monitors.log(prefix + "time " + timeElapsed + " > " + timeLimit);
if (stopResd)
monitors.log(prefix + "residu " + NumFormat.nice(residu) + " < " + NumFormat.nice(residuMin));
return abort | stopIter | stopTime | stopResd;
}
public void finish(RealSignal x) {
this.x = x;
boolean ref = doReference;
boolean con = doConstraint;
boolean res = doResidu;
if (con || res || ref)
compute(iterations, x, con, res, ref);
String pnsrText = doReference ? ""+psnr : "n/a";
String snrText = doReference ? ""+snr : "n/a";
String residuText = doResidu ? "" + residu : "n/a";
stats.addOutput(x, algoName, NumFormat.seconds(getTimeNano()), pnsrText, snrText, residuText);
stats.save(monitors, path);
for (Output out : outs)
out.executeFinal(monitors, x, this);
monitors.log("Time: " + NumFormat.seconds(getTimeNano()) + " Peak:" + getMemoryAsString());
if (timer != null)
timer.cancel();
}
private void compute(int iterations, RealSignal x, boolean con, boolean res, boolean ref) {
if (x == null)
return;
if (con && constraintMode != null)
new Constraint(monitors).apply(x, constraintMode);
if (ref && refImage != null) {
String s = "";
psnr = Assessment.psnr(x, refImage);
snr = Assessment.snr(x, refImage);
s += " PSNR: " + NumFormat.nice(psnr);
s += " SNR: " + NumFormat.nice(snr);
monitors.log("@" + iterations + " " + s);
}
residu = Double.MAX_VALUE;
if (res && prevImage != null) {
residu = Assessment.relativeResidu(x, prevImage);
prevImage = x.duplicate();
monitors.log("@" + iterations + " Residu: " + NumFormat.nice(residu));
}
}
public double getTimeNano() {
return (System.nanoTime() - timeStarting);
}
public double getTimeSecond() {
return (System.nanoTime() - timeStarting) * 1e-9;
}
public String getConstraintAsString() {
if (!doConstraint)
return "no";
if (constraintMode == null)
return "null";
return constraintMode.name().toLowerCase();
}
public String getStoppingCriteriaAsString(Algorithm algo) {
String stop = algo.isIterative() ? "iterations limit=" + algo.getIterationsMax() + ", " : "direct, ";
stop += doTime ? ", time limit=" + NumFormat.nice(timeLimit * 1e-9) : " no time limit" + ", ";
stop += doResidu ? ", residu limit=" + NumFormat.nice(residuMin) : " no residu limit";
return stop;
}
public double getMemory() {
return memoryPeak - memoryStarting;
}
public String getMemoryAsString() {
return NumFormat.bytes(getMemory());
}
public int getIterations() {
return iterations;
}
public double getSNR() {
return snr;
}
public double getPSNR() {
return psnr;
}
public double getResidu() {
return residu;
}
private void update() {
memoryPeak = Math.max(memoryPeak, SystemUsage.getHeapUsed());
}
public AbstractFFT getFFT() {
return fft;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path
* the path to set
*/
public void setPath(String path) {
this.path = path;
}
/**
* @return the system
*/
public boolean isSystem() {
return system;
}
/**
* @param system
* the system to set
*/
public void setSystem(boolean system) {
this.system = system;
}
/**
* @return the multithreading
*/
public boolean isMultithreading() {
return multithreading;
}
/**
* @param multithreading
* the multithreading to set
*/
public void setMultithreading(boolean multithreading) {
this.multithreading = multithreading;
}
/**
* @return the displayFinal
*/
public boolean isDisplayFinal() {
return displayFinal;
}
/**
* @param displayFinal
* the displayFinal to set
*/
public void setDisplayFinal(boolean displayFinal) {
this.displayFinal = displayFinal;
}
/**
* @return the normalizationPSF
*/
public double getNormalizationPSF() {
return normalizationPSF;
}
/**
* @param normalizationPSF
* the normalizationPSF to set
*/
public void setNormalizationPSF(double normalizationPSF) {
this.normalizationPSF = normalizationPSF;
}
/**
* @return the epsilon
*/
public double getEpsilon() {
return epsilon;
}
/**
* @param epsilon
* the epsilon to set
*/
public void setEpsilon(double epsilon) {
this.epsilon = epsilon;
}
/**
* @return the padding
*/
public Padding getPadding() {
return padding;
}
/**
* @param padding
* the padding to set
*/
public void setPadding(Padding padding) {
this.padding = padding;
}
/**
* @return the apodization
*/
public Apodization getApodization() {
return apodization;
}
/**
* @param apodization
* the apodization to set
*/
public void setApodization(Apodization apodization) {
this.apodization = apodization;
}
/**
* @return the monitors
*/
public Monitors getMonitors() {
if (monitors == null)
return Monitors.createDefaultMonitor();
return monitors;
}
/**
* @param monitors
* the monitors to set
*/
public void setMonitors(Monitors monitors) {
this.monitors = monitors;
}
/**
* @return the verbose
*/
public Verbose getVerbose() {
return verbose;
}
/**
* @param verbose
* the verbose to set
*/
public void setVerbose(Verbose verbose) {
this.verbose = verbose;
}
public Constraint.Mode getConstraint() {
return constraintMode;
}
public void setConstraint(Constraint.Mode constraintMode) {
doConstraint = constraintMode != Constraint.Mode.NO;
this.constraintMode = constraintMode;
}
/**
* @return the stats
*/
public Stats getStats() {
return stats;
}
/**
* @param stats
* the stats to set
*/
public void setStats(Stats stats) {
this.stats = stats;
}
/**
* @return the residuMin
*/
public double getResiduMin() {
return residuMin;
}
/**
* @param residuMin
* the residuMin to set
*/
public void setResiduMin(double residuMin) {
doResidu = residuMin > 0;
this.residuMin = residuMin;
}
/**
* @return the timeLimit
*/
public double getTimeLimit() {
return timeLimit;
}
/**
* @param timeLimit
* the timeLimit to set
*/
public void setTimeLimit(double timeLimit) {
doTime = timeLimit > 0;
this.timeLimit = timeLimit;
}
/**
* @return the reference
*/
public String getReferenceName() {
return referenceName;
}
/**
* @param reference
* the reference to set
*/
public void setReferenceName(String referenceName) {
doReference = false;
if (referenceName == null)
return;
if (referenceName.equals(""))
return;
doReference = true;
this.referenceName = referenceName;
}
/**
* @return the reference
*/
public RealSignal getReference() {
return refImage;
}
/**
* @param reference
* the reference to set
*/
public void setReference(RealSignal refImage) {
doReference = false;
if (refImage == null)
return;
doReference = true;
this.refImage = refImage;
}
/**
* @return the outs
*/
public ArrayList<Output> getOuts() {
return outs;
}
/**
* @param outs
* the outs to set
*/
public void setOuts(ArrayList<Output> outs) {
this.outs = outs;
}
public void addOutput(Output out) {
this.outs.add(out);
}
public String toStringMonitor() {
String s = "[" + verbose.name().toLowerCase() + "] ";
for (AbstractMonitor monitor : monitors) {
s += "" + monitor.getName() + " ";
}
return s;
}
public Stats.Mode getStatsMode() {
return stats.getMode();
}
public void setStatsMode(Stats.Mode mode) {
this.stats = new Stats(mode);
}
public String toStringRunning() {
String s = "";
s += "system " + (system ? "shown" : "hidden ");
s += ", multithreading " + (multithreading ? "on" : "off ");
s += ", display final " + (displayFinal ? "on " : "off ");
return s;
}
public String toStringPath() {
File dir = new File(path);
if (dir.exists()) {
if (dir.isDirectory()) {
if (dir.canWrite())
return path + " (writable)";
else
return path + " (non-writable)";
}
else {
return path + " (non-directory)";
}
}
else {
return path + " (not-valid)";
}
}
private class Updater extends TimerTask {
@Override
public void run() {
update();
}
}
}
diff --git a/DeconvolutionLab2/src/deconvolution/algorithm/Simulation.java b/DeconvolutionLab2/src/deconvolution/algorithm/Simulation.java
index d0bb0c1..cabbb61 100644
--- a/DeconvolutionLab2/src/deconvolution/algorithm/Simulation.java
+++ b/DeconvolutionLab2/src/deconvolution/algorithm/Simulation.java
@@ -1,169 +1,168 @@
/*
* 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 bilib.tools.PsRandom;
import signal.ComplexSignal;
import signal.Operations;
import signal.RealSignal;
import signal.SignalCollector;
+import bilib.tools.PsRandom;
public class Simulation extends Algorithm implements Callable<RealSignal> {
private static PsRandom rand = new PsRandom(1234);
private double mean = 0.0;
private double stdev = 10.0;
private double poisson = 0.0;
public Simulation(double mean, double stdev, double poisson) {
super();
this.mean = mean;
this.stdev = stdev;
this.poisson = poisson;
}
@Override
public RealSignal call() {
ComplexSignal Y = fft.transform(y);
ComplexSignal H = fft.transform(h);
ComplexSignal X = Operations.multiply(H, Y);
SignalCollector.free(Y);
SignalCollector.free(H);
RealSignal x = fft.inverse(X);
SignalCollector.free(X);
gaussian(x, mean, stdev);
poisson(x, poisson);
return x;
}
public void gaussian(RealSignal x, double mean, double sd) {
for (int k = 0; k < x.nz; k++) {
float[] slice = x.getXY(k);
for (int j = 0; j < x.ny * x.nx; j++) {
- double a = slice[j];
slice[j] += (float) rand.nextGaussian(mean, sd);
}
}
}
public void poisson(RealSignal x, double factor) {
if (factor < Operations.epsilon)
return;
double f = 1.0/(factor);
for (int k = 0; k < x.nz; k++) {
float[] slice = x.getXY(k);
for (int j = 0; j < x.ny * x.nx; j++)
if (slice[j] > Operations.epsilon) {
slice[j] = (float)(rand.nextPoissonian(f*(slice[j])) * factor);
}
}
}
@Override
public String getName() {
return "Simulation with noise";
}
@Override
public String[] getShortnames() {
return new String[] {"SIM", "SIMU"};
}
@Override
public int getComplexityNumberofFFT() {
return 3;
}
@Override
public double getMemoryFootprintRatio() {
return 8.0;
}
@Override
public boolean isRegularized() {
return false;
}
@Override
public boolean isStepControllable() {
return false;
}
@Override
public boolean isIterative() {
return false;
}
@Override
public boolean isWaveletsBased() {
return false;
}
@Override
public Algorithm setParameters(double... params) {
if (params == null)
return this;
if (params.length > 0)
mean = params[0];
if (params.length > 1)
stdev = params[1];
if (params.length > 2)
poisson = params[2];
return this;
}
@Override
public double[] getDefaultParameters() {
return new double[] {0, 1, 0};
}
@Override
public double[] getParameters() {
return new double[] {mean, stdev, poisson};
}
@Override
public double getRegularizationFactor() {
return 0.0;
}
@Override
public double getStepFactor() {
return 0;
}
}
diff --git a/DeconvolutionLab2/src/deconvolution/capsule/AlgorithmCapsule.java b/DeconvolutionLab2/src/deconvolution/capsule/AlgorithmCapsule.java
index 84f0267..fc58d92 100644
--- a/DeconvolutionLab2/src/deconvolution/capsule/AlgorithmCapsule.java
+++ b/DeconvolutionLab2/src/deconvolution/capsule/AlgorithmCapsule.java
@@ -1,185 +1,183 @@
/*
* 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.capsule;
import javax.swing.JSplitPane;
-import com.esotericsoftware.minlog.Log;
-
+import signal.ComplexSignal;
+import signal.RealSignal;
+import signal.SignalCollector;
import bilib.component.HTMLPane;
import bilib.table.CustomizedTable;
import bilib.tools.NumFormat;
import deconvolution.Deconvolution;
import deconvolution.Features;
import deconvolution.algorithm.Algorithm;
-import deconvolution.algorithm.AlgorithmPanel;
import deconvolution.algorithm.AlgorithmList;
+import deconvolution.algorithm.AlgorithmPanel;
import deconvolutionlab.monitor.Monitors;
import fft.AbstractFFT;
import fft.FFT;
-import signal.ComplexSignal;
-import signal.RealSignal;
-import signal.SignalCollector;
/**
* This class is a information module for the algorithm.
*
* @author Daniel Sage
*
*/
public class AlgorithmCapsule extends AbstractCapsule implements Runnable {
private CustomizedTable table;
private HTMLPane doc;
public AlgorithmCapsule(Deconvolution deconvolution) {
super(deconvolution);
doc = new HTMLPane(100, 1000);
table = new CustomizedTable(new String[] { "Features", "Values" }, false);
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, table.getPane(200, 200), doc.getPane());
}
@Override
public void update() {
if (doc == null)
return;
if (table == null)
return;
table.removeRows();
table.append(new String[] { "PSF", "Waiting for loading ..." });
Thread thread = new Thread(this);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
split.setDividerLocation(300);
}
@Override
public String getName() {
return "Algorithm";
}
@Override
public void run() {
Features features = new Features();
if (deconvolution.getAlgorithm() == null) {
features.add("Algorithm", "No valid algorithm");
return;
}
Algorithm algo = deconvolution.getAlgorithm();
doc.clear();
String name = algo.getShortnames()[0];
AlgorithmPanel algoPanel = AlgorithmList.getPanel(name);
if (algoPanel != null)
doc.append(algoPanel.getDocumentation());
if (deconvolution.image == null) {
startAsynchronousTimer("Open image", 200);
deconvolution.image = deconvolution.openImage();
stopAsynchronousTimer();
}
if (deconvolution.image == null) {
features.add("Image", "No valid input image");
return;
}
if (deconvolution.getController().getPadding() == null) {
features.add("Padding", "No valid padding");
return;
}
if (deconvolution.getController().getApodization() == null) {
features.add("Apodization", "No valid apodization");
return;
}
if (deconvolution.psf == null) {
startAsynchronousTimer("Open PSF", 200);
deconvolution.psf = deconvolution.openPSF();
stopAsynchronousTimer();
}
if (deconvolution.psf == null) {
features.add("Image", "No valid PSF");
return;
}
startAsynchronousTimer("Check Algorithm", 200);
AbstractFFT f = FFT.getFastestFFT().getDefaultFFT();
double Q = Math.sqrt(2);
if (deconvolution.image != null) {
int mx = deconvolution.image.nx;
int my = deconvolution.image.ny;
int mz = deconvolution.image.nz;
while (mx * my * mz > Math.pow(2, 15)) {
mx = (int)(mx / Q);
my = (int)(my / Q);
mz = (int)(mz / Q);
}
double N = deconvolution.image.nx * deconvolution.image.ny * deconvolution.image.nz;
double M = mx * my * mz;
double ratio = 1;
if (M != 0)
ratio = (N * Math.log(N)) / (M * Math.log(M));
double chrono = System.nanoTime();
RealSignal x = new RealSignal("test", mx, my, mz);
ComplexSignal c = new ComplexSignal("test", mx, my, mz);
f.init(Monitors.createDefaultMonitor(), mx, my, mz);
f.transform(x, c);
SignalCollector.free(x);
SignalCollector.free(c);
chrono = (System.nanoTime() - chrono);
features.add("Small dataset", mx + "x" + my + "x" + mz);
features.add("Elapsed time on small dataset", NumFormat.time(chrono) );
chrono = chrono * ratio * algo.getComplexityNumberofFFT();
features.add("Estimated time for input dataset", NumFormat.time(chrono) );
features.add("Estimated number of FFTs", "" + algo.getComplexityNumberofFFT());
}
else
features.add("Estimated time", "Error" );
double mem = (algo.getMemoryFootprintRatio() * deconvolution.image.nx * deconvolution.image.ny * deconvolution.image.nz * 4);
features.add("Estimated required memory", NumFormat.bytes(mem));
features.add("Iterative", algo.isIterative() ? "" + algo.getIterationsMax() : "Direct");
table.removeRows();
for (String[] feature : features)
table.append(feature);
stopAsynchronousTimer();
}
}
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/deconvolutionlab/Constants.java b/DeconvolutionLab2/src/deconvolutionlab/Constants.java
index 1394f51..131cb5c 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";
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 = "(20.04.2017)";
+ public static String version = "(08.05.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 = 600;
public static Dimension dimParameters = new Dimension(88, 25);
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/Lab.java b/DeconvolutionLab2/src/deconvolutionlab/Lab.java
index 3f47a3f..cd9b448 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/Lab.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/Lab.java
@@ -1,576 +1,588 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolutionlab;
+import ij.gui.Plot;
+import imagej.IJImager;
+
import java.io.File;
import java.util.ArrayList;
import java.util.regex.Pattern;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
+import plugins.sage.deconvolutionlab.IcyImager;
+import signal.ComplexComponent;
+import signal.ComplexSignal;
+import signal.RealSignal;
+import signal.factory.SignalFactory;
+import signal.factory.Sphere;
import bilib.tools.Files;
import bilib.tools.NumFormat;
import bilib.tools.WebBrowser;
import deconvolutionlab.Imager.ContainerImage;
import deconvolutionlab.monitor.Monitors;
import fft.AbstractFFT;
import fft.AbstractFFTLibrary;
import fft.FFT;
-import ij.IJ;
-import ij.gui.Plot;
-import imagej.IJImager;
-import plugins.sage.deconvolutionlab.IcyImager;
-import signal.ComplexComponent;
-import signal.ComplexSignal;
-import signal.RealSignal;
-import signal.factory.SignalFactory;
-import signal.factory.Sphere;
/**
* This class contains a collection of useful static methods to manage all the
* peripherical aspects of the deconvolution, such as load, display, or save an
* image.
* <p>
* At the construction of the class, the config is loaded. In practice, any
* deconvolution program has to start with Lab.init(Platform).
*
* @author Daniel Sage
*
*/
public class Lab {
private static Imager imaging;
private static ArrayList<JFrame> frames;
private static ArrayList<JDialog> dialogs;
static {
frames = new ArrayList<JFrame>();
dialogs = new ArrayList<JDialog>();
imaging = new IJImager();
Config.init(Files.getWorkingDirectory() + "DeconvolutionLab2.config");
}
/**
* Initializes the Lab with a give platform.
*
* @param platform
* The platform is ImageJ, ICY, or Matlab.
*/
public static void init(Imager.Platform platform) {
init(platform, Files.getWorkingDirectory() + "DeconvolutionLab2.config");
}
/**
* Initializes the Lab with a give platform and a given configuration file
*
* @param platform
* @param configFilename
*/
public static void init(Imager.Platform platform, String configFilename) {
switch (platform) {
case IMAGEJ:
imaging = new IJImager();
break;
case ICY:
imaging = new IcyImager();
break;
default:
imaging = new IJImager();
break;
}
Config.init(configFilename);
}
/**
* Returns the platform.
*
* @return
*/
public static Imager.Platform getPlatform() {
return imaging.getPlatform();
}
/**
* Open a web page on the DeconvolutionLab2.
*/
public static void help() {
WebBrowser.open(Constants.url);
}
/**
* Checks the installed FFT libraries on a small (40, 30, 20) signal.
*
* @param monitors
*/
public static void checkFFT(Monitors monitors) {
ArrayList<AbstractFFTLibrary> libraries = FFT.getInstalledLibraries();
for (AbstractFFTLibrary library : libraries) {
RealSignal y = new Sphere(3, 1).generate(40, 30, 20);
double chrono = System.nanoTime();
AbstractFFT fft = library.getDefaultFFT();
fft.init(monitors, y.nx, y.ny, y.nz);
RealSignal x = fft.inverse(fft.transform(y));
chrono = System.nanoTime() - chrono;
double residu = y.getEnergy() - x.getEnergy();
monitors.log("\t residu of reconstruction: " + residu);
monitors.log("\t computation time (" + x.nx + "x" + x.ny + "x" + x.nz + ") " + NumFormat.time(chrono));
}
}
public static ContainerImage createContainer(Monitors monitors, String title) {
monitors.log("Create Live Real Signal " + title);
return imaging.createContainer(title);
}
public static void append(Monitors monitors, ContainerImage container, RealSignal signal, String title) {
imaging.append(container, signal, title, Imager.Type.FLOAT);
monitors.log("Add Live Real Signal " + title);
}
public static void append(Monitors monitors, ContainerImage container, RealSignal signal, String title, Imager.Type type) {
imaging.append(container, signal, title, type);
monitors.log("Add Live Real Signal " + title);
}
/**
* Displays a the module of complex signal.
*
* @param monitors
* @param signal
* @param title
*/
public static void show(Monitors monitors, ComplexSignal signal, String title) {
if (signal == null) {
monitors.error("Show " + title + " this image does not exist.");
return;
}
monitors.log("Show Real Signal " + title);
imaging.show(signal, title, ComplexComponent.MODULE);
}
/**
* Displays a real 3D signal a z-stack of images.
*
* @param signal
*/
public static void show(RealSignal signal) {
if (signal == null) {
return;
}
imaging.show(signal, signal.name, Imager.Type.FLOAT, signal.nz / 2);
}
+ /**
+ * Displays a real 3D signal a z-stack of images.
+ *
+ * @param signal
+ */
+ public static void show(RealSignal signal, String title) {
+ if (signal == null) {
+ return;
+ }
+ imaging.show(signal, title, Imager.Type.FLOAT, signal.nz / 2);
+ }
+
/**
* Displays a real 3D signal a z-stack of images.
*
* @param monitors
* @param signal
*/
public static void show(Monitors monitors, RealSignal signal) {
if (signal == null) {
monitors.error("This image does not exist.");
return;
}
monitors.log("Show Real Signal " + signal.name);
imaging.show(signal, signal.name, Imager.Type.FLOAT, signal.nz / 2);
}
/**
* Displays a real 3D signal a z-stack of images.
*
* @param monitors
* @param signal
* @param title
*/
public static void show(Monitors monitors, RealSignal signal, String title) {
if (signal == null) {
monitors.error("Show " + title + " this image does not exist.");
return;
}
monitors.log("Show Real Signal " + title);
imaging.show(signal, title, Imager.Type.FLOAT, signal.nz / 2);
}
/**
* Displays a real 3D signal a z-stack of images using a given type.
*
* @param monitors
* @param signal
* @param title
* @param type
*/
public static void show(Monitors monitors, RealSignal signal, String title, Imager.Type type) {
if (signal == null) {
monitors.error("Show " + title + " this image does not exist.");
return;
}
monitors.log("Show Real Signal " + title);
imaging.show(signal, title, type, signal.nz / 2);
}
/**
* Displays a real 3D signal a z-stack of images using a given type and
* shows the slice number z.
*
* @param monitors
* @param signal
* @param title
* @param type
* @param z
*/
public static void show(Monitors monitors, RealSignal signal, String title, Imager.Type type, int z) {
if (signal == null) {
monitors.error("Show " + title + " this image does not exist.");
return;
}
monitors.log("Show Real Signal " + title);
imaging.show(signal, title, type, z);
}
public static void save(Monitors monitors, RealSignal signal, String path, String name) {
save(monitors, signal, path + File.separator + name + ".tif", Imager.Type.FLOAT);
}
public static void save(Monitors monitors, RealSignal signal, String path, String name, Imager.Type type) {
save(monitors, signal, path + File.separator + name + ".tif", type);
}
public static void save(Monitors monitors, RealSignal signal, String filename, Imager.Type type) {
imaging.save(signal, filename, type);
monitors.log("Save Real Signal " + filename);
}
public static void save(Monitors monitors, RealSignal signal, String filename) {
imaging.save(signal, filename, Imager.Type.FLOAT);
monitors.log("Save Real Signal " + filename);
}
public static void save(RealSignal signal, String path, String name) {
save(signal, path + File.separator + name + ".tif", Imager.Type.FLOAT);
}
public static void save(RealSignal signal, String path, String name, Imager.Type type) {
save(signal, path + File.separator + name + ".tif", type);
}
public static void save(RealSignal signal, String filename) {
imaging.save(signal, filename, Imager.Type.FLOAT);
}
public static void save(RealSignal signal, String filename, Imager.Type type) {
imaging.save(signal, filename, type);
}
public static RealSignal createSynthetic(Monitors monitors, String cmd) {
RealSignal signal = SignalFactory.createFromCommand(cmd);
if (signal == null)
monitors.error("Unable to create " + cmd);
else
monitors.log("Create " + cmd);
return signal;
}
/**
* Return the active image.
*
* @return
*/
public static RealSignal getImage() {
return getImager().getActiveImage();
}
/**
* Return an image from the platform with a specified name.
*
* @param name
* @return
*/
public static RealSignal getImage(String name) {
return getImager().getImageByName(name);
}
/**
* Return an image from the platform with a specified name.
*
* @param monitors
* @param name
* @return
*/
public static RealSignal getImage(Monitors monitors, String name) {
RealSignal signal = getImager().getImageByName(name);
if (signal == null)
monitors.error("Unable to get " + name);
else
monitors.log("Load " + name);
return signal;
}
/**
* Open an image from the disk.
*
* @param filename
* @return
*/
public static RealSignal openFile(String filename) {
return imaging.open(filename);
}
/**
* Open an image from the disk.
*
* @param monitors
* @param filename
* @return
*/
public static RealSignal openFile(Monitors monitors, String filename) {
RealSignal signal = imaging.open(filename);
if (signal == null)
monitors.error("Unable to open " + filename);
else
monitors.log("Load " + filename);
return signal;
}
/**
* Open a series of image from a directory.
*
* @param path
* @return
*/
public static RealSignal openDir(String path) {
return openDir(Monitors.createDefaultMonitor(), path);
}
/**
* Open a series of image from a directory.
*
* @param monitors
* @param path
* @return
*/
public static RealSignal openDir(Monitors monitors, String path) {
String parts[] = path.split(" pattern ");
String dirname = path;
String regex = "";
if (parts.length == 2) {
dirname = parts[0].trim();
regex = parts[1].trim();
}
File file = new File(dirname + File.separator);
if (!file.isDirectory()) {
monitors.error("Dir " + dirname + " is not a directory.");
return null;
}
String[] list = file.list();
ArrayList<RealSignal> slices = new ArrayList<RealSignal>();
int nx = 0;
int ny = 0;
Pattern pattern = Pattern.compile(regex);
for (String filename : list) {
if (pattern.matcher(filename).find()) {
RealSignal slice = imaging.open(dirname + File.separator + filename);
if (slice != null) {
slices.add(slice);
nx = Math.max(nx, slice.nx);
ny = Math.max(ny, slice.ny);
monitors.log("Image " + path + File.separator + filename + " is loaded.");
}
}
else {
monitors.error("Error in loading image " + path + File.separator + filename);
}
}
int nz = slices.size();
if (nz <= 0) {
monitors.error("Dir " + path + " do no contain valid images.");
return null;
}
RealSignal signal = new RealSignal(file.getName(), nx, ny, nz);
for (int z = 0; z < slices.size(); z++)
signal.setSlice(z, slices.get(z));
return signal;
}
public static void showOrthoview(RealSignal signal, int hx, int hy, int hz) {
showOrthoview(signal, signal.name, hx, hy, hz);
}
public static void showOrthoview(RealSignal signal, String title, int hx, int hy, int hz) {
if (signal == null) {
return;
}
imaging.show(signal.createOrthoview(hx, hy, hz), title, Imager.Type.FLOAT, 0);
}
public static void showOrthoview(Monitors monitors, RealSignal signal, String title, int hx, int hy, int hz) {
if (signal == null) {
monitors.error("Show Orthoview " + title + " this image does not exist.");
return;
}
imaging.show(signal.createOrthoview(hx, hy, hz), title, Imager.Type.FLOAT, 0);
}
public static void showOrthoview(RealSignal signal) {
showOrthoview(signal, signal.name);
}
public static void showOrthoview(RealSignal signal, String title) {
if (signal == null) {
return;
}
int hx = signal.nx / 2;
int hy = signal.ny / 2;
int hz = signal.nz / 2;
imaging.show(signal.createOrthoview(hx, hy, hz), title, Imager.Type.FLOAT, 0);
}
public static void showOrthoview(Monitors monitors, RealSignal signal, String title) {
if (signal == null) {
monitors.error("Show Orthoview " + title + " this image does not exist.");
return;
}
int hx = signal.nx / 2;
int hy = signal.ny / 2;
int hz = signal.nz / 2;
imaging.show(signal.createOrthoview(hx, hy, hz), title, Imager.Type.FLOAT, 0);
}
public static void showMIP(RealSignal signal) {
showMIP(signal, signal.name);
}
public static void showMIP(RealSignal signal, String title) {
if (signal == null) {
return;
}
imaging.show(signal.createMIP(), title, Imager.Type.FLOAT, 0);
}
public static void showMIP(Monitors monitors, RealSignal signal, String title) {
if (signal == null) {
monitors.error("Show MIP " + title + " this image does not exist.");
return;
}
imaging.show(signal.createMIP(), title, Imager.Type.FLOAT, 0);
}
public static void showPlanar(RealSignal signal) {
showPlanar(signal, signal.name);
}
public static void showPlanar(RealSignal signal, String title) {
if (signal == null) {
return;
}
imaging.show(signal.createPlanar(), title, Imager.Type.FLOAT, 0);
}
public static void showPlanar(Monitors monitors, RealSignal signal, String title) {
if (signal == null) {
monitors.error("Show Planar " + title + " this image does not exist.");
return;
}
imaging.show(signal.createPlanar(), title, Imager.Type.FLOAT, 0);
}
public static void plotProfile(RealSignal signal, String name, int x1, int y1, int z1, int x2, int y2, int z2) {
if (signal == null) {
return;
}
double dx = x2 - x1;
double dy = y2 - y1;
double dz = z2 - z1;
double len = Math.sqrt(dx*dx + dy*dy + dz*dz);
int n = (int)Math.round(len * 2);
double ds = len / n;
dx = (double)(x2 - x1) / n;
dy = (double)(y2 - y1) / n;
dz = (double)(z2 - z1) / n;
double value[] = new double[n];
double dist[] = new double[n];
for(int s=0; s<n; s++) {
double x = x1 + s*dx;
double y = y1 + s*dy;
double z = z1 + s*dz;
dist[s] = s*ds;
value[s] = signal.getInterpolatedPixel(x, y, z);
}
Plot plot = new Plot(name, "distance", "intensity", dist, value);
plot.show();
}
public static Imager getImager() {
return imaging;
}
public static String getActiveImage() {
if (imaging.isSelectable())
return imaging.getSelectedImage();
return "";
}
public static void setVisible(JDialog dialog, boolean modal) {
if (dialog == null)
return;
dialogs.add(dialog);
imaging.setVisible(dialog, modal);
}
public static void setVisible(JPanel panel, String name, int x, int y) {
JFrame frame = new JFrame(name);
frame.getContentPane().add(panel);
frame.pack();
frame.setLocation(x, y);
frame.setVisible(true);
frames.add(frame);
}
public static void setVisible(JFrame frame) {
frames.add(frame);
frame.setVisible(true);
}
public static void close() {
for (JFrame frame : frames)
if (frame != null)
frame.dispose();
for (JDialog dialog : dialogs)
if (dialog != null)
dialog.dispose();
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/dialog/SyntheticDialog.java b/DeconvolutionLab2/src/deconvolutionlab/dialog/SyntheticDialog.java
index e420828..5a0e032 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/dialog/SyntheticDialog.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/dialog/SyntheticDialog.java
@@ -1,336 +1,346 @@
/*
* 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.dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import bilib.component.GridPanel;
import bilib.component.SpinnerRangeDouble;
import bilib.component.SpinnerRangeInteger;
import bilib.tools.NumFormat;
import deconvolutionlab.Lab;
import deconvolutionlab.monitor.Monitors;
import ij.gui.GUI;
import signal.RealSignal;
import signal.factory.SignalFactory;
public class SyntheticDialog extends JDialog implements ActionListener, WindowListener {
private SpinnerRangeDouble spnIntensity = new SpinnerRangeDouble(255, -999999, 999999, 1);
private SpinnerRangeInteger spnWidth = new SpinnerRangeInteger(200, 1, 9999, 1);
private SpinnerRangeInteger spnHeight = new SpinnerRangeInteger(100, 1, 9999, 1);
private SpinnerRangeInteger spnSlices = new SpinnerRangeInteger(100, 1, 9999, 1);
private SpinnerRangeDouble spnCenterX = new SpinnerRangeDouble(0.5, -10, 10, 0.05);
private SpinnerRangeDouble spnCenterY = new SpinnerRangeDouble(0.5, -10, 10, 0.05);
private SpinnerRangeDouble spnCenterZ = new SpinnerRangeDouble(0.5, -10, 10, 0.05);
private SpinnerRangeDouble spnParameter1 = new SpinnerRangeDouble(10, -9999, 9999, 1);
private SpinnerRangeDouble spnParameter2 = new SpinnerRangeDouble(10, -9999, 9999, 1);
private SpinnerRangeDouble spnParameter3 = new SpinnerRangeDouble(10, -9999, 9999, 1);
private SpinnerRangeDouble spnParameter4 = new SpinnerRangeDouble(10, -9999, 9999, 1);
private JLabel lbl1 = new JLabel("Parameters 1 of the shape");
private JLabel lbl2 = new JLabel("Parameters 2 of the shape");
private JLabel lbl3 = new JLabel("Parameters 3 of the shape");
private JLabel lbl4 = new JLabel("Parameters 4 of the shape");
private JComboBox<String> cmbShapes;
private JButton bnShow = new JButton("Show");
private JButton bnOK = new JButton("OK");
private JButton bnCancel = new JButton("Cancel");
private boolean cancel = false;
private String shape;
private String command;
public SyntheticDialog(ArrayList<SignalFactory> list) {
super(new JFrame(), "Synthetic");
String[] cmb = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
cmb[i] = list.get(i).getName();
}
cmbShapes = new JComboBox<String>(cmb);
GridPanel pnParams = new GridPanel("parameters", 3);
pnParams.place(8, 0, lbl1);
pnParams.place(8, 1, spnParameter1);
pnParams.place(9, 0, lbl2);
pnParams.place(9, 1, spnParameter2);
pnParams.place(10, 0, lbl3);
pnParams.place(10, 1, spnParameter3);
pnParams.place(11, 0, lbl4);
pnParams.place(11, 1, spnParameter4);
GridPanel pnSize = new GridPanel("size", 3);
pnSize.place(1, 0, "Width [pixels] (nx)");
pnSize.place(1, 1, spnWidth);
pnSize.place(2, 0, "Height [pixels] (ny)");
pnSize.place(2, 1, spnHeight);
pnSize.place(3, 0, "Number of Slices (nz)");
pnSize.place(3, 1, spnSlices);
GridPanel pnIntensity = new GridPanel("intensity", 3);
pnIntensity.place(1, 0, "Signal Intensity");
pnIntensity.place(1, 1, spnIntensity);
GridPanel pnCenter = new GridPanel("center", 3);
pnCenter.place(4, 0, "Center [% of nx] (cx)");
pnCenter.place(4, 1, spnCenterX);
pnCenter.place(5, 0, "Center [% of ny] (cy)");
pnCenter.place(5, 1, spnCenterY);
pnCenter.place(7, 0, "Center [% of nz] (cz)");
pnCenter.place(7, 1, spnCenterZ);
GridPanel pn = new GridPanel(false);
pn.place(0, 0, 3, 1, cmbShapes);
pn.place(1, 0, 3, 1, pnParams);
pn.place(2, 0, 3, 1, pnSize);
pn.place(3, 0, 3, 1, pnIntensity);
pn.place(4, 0, 3, 1, pnCenter);
pn.place(11, 0, bnCancel);
pn.place(11, 1, bnShow);
pn.place(11, 2, bnOK);
pn.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
bnShow.addActionListener(this);
bnOK.addActionListener(this);
bnCancel.addActionListener(this);
cmbShapes.addActionListener(this);
add(pn);
pack();
updateInterface();
addWindowListener(this);
GUI.center(this);
setModal(true);
}
private void updateInterface() {
SignalFactory factory = SignalFactory.get((String) cmbShapes.getSelectedItem());
String labels[] = factory.getParametersName();
lbl1.setVisible(false);
lbl2.setVisible(false);
lbl3.setVisible(false);
if (labels.length >= 1) {
lbl1.setVisible(true);
lbl1.setText(labels[0]);
}
if (labels.length >= 2) {
lbl2.setVisible(true);
lbl2.setText(labels[1]);
}
if (labels.length >= 3) {
lbl3.setVisible(true);
lbl3.setText(labels[2]);
}
if (labels.length >= 4) {
lbl4.setVisible(true);
lbl4.setText(labels[3]);
}
double params[] = factory.getParameters();
spnParameter1.setVisible(false);
spnParameter2.setVisible(false);
spnParameter3.setVisible(false);
spnParameter4.setVisible(false);
if (params.length >= 1) {
spnParameter1.setVisible(true);
spnParameter1.set(params[0]);
}
if (params.length >= 2) {
spnParameter2.setVisible(true);
spnParameter2.set(params[1]);
}
if (params.length >= 3) {
spnParameter3.setVisible(true);
spnParameter3.set(params[2]);
}
if (params.length >= 4) {
spnParameter4.setVisible(true);
spnParameter4.set(params[3]);
}
pack();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bnShow) {
SignalFactory factory = SignalFactory.get((String) cmbShapes.getSelectedItem());
- double params[] = factory.getParameters();
+ int np = factory.getParameters().length;
+ double params[] = new double[np];
+ if (np >= 1)
+ params[0] = spnParameter1.get();
+ if (np >= 2)
+ params[1] = spnParameter2.get();
+ if (np >= 3)
+ params[2] = spnParameter3.get();
+ if (np >= 4)
+ params[3] = spnParameter4.get();
+
factory.setParameters(params);
factory.intensity(spnIntensity.get());
factory.center(spnCenterX.get(), spnCenterY.get(), spnCenterZ.get());
RealSignal signal = factory.generate(spnWidth.get(), spnHeight.get(), spnSlices.get());
Lab.show(Monitors.createDefaultMonitor(), signal, factory.getName());
}
if (e.getSource() == cmbShapes) {
updateInterface();
}
if (e.getSource() == bnCancel) {
dispose();
cancel = true;
shape = "";
command = "";
return;
}
if (e.getSource() == bnOK) {
int nx = spnWidth.get();
int ny = spnHeight.get();
int nz = spnSlices.get();
shape = (String) cmbShapes.getSelectedItem();
command = shape + " ";
SignalFactory factory = SignalFactory.get(shape);
int n = factory.getParameters().length;
if (n >= 1) {
command += "" + spnParameter1.get();
if (n >= 2)
command += " " + spnParameter2.get();
if (n >= 3)
command += " " + spnParameter3.get();
if (n >= 4)
command += " " + spnParameter4.get();
command += " ";
}
command += " size " + nx + " " + ny + " " + nz + " intensity " + + spnIntensity.get() + " ";
if (spnCenterX.get() != 0.5 || spnCenterY.get() != 0.5 || spnCenterZ.get() != 0.5) {
double cx = Math.round(spnCenterX.get() * 1000000) / 1000000.0;
double cy = Math.round(spnCenterY.get() * 1000000) / 1000000.0;
double cz = Math.round(spnCenterZ.get() * 1000000) / 1000000.0;
command += " center " + cx + " " + cy + " " + cz + " ";
}
dispose();
cancel = false;
}
}
/**
* Set the command line parameters to the components of the user interface
*
* @param name String containing the name of shape
* @param parameters String containing all the parameters plus the optional keywords: size, intensity, center
*/
public void setParameters(String name, String parameters) {
cmbShapes.setSelectedItem(name);
SignalFactory factory = SignalFactory.getFactoryByName(name);
if (factory == null)
return;
int np = factory.getParameters().length;
double params[] = NumFormat.parseNumbers(parameters);
if (np >= 1 && params.length >= 1)
spnParameter1.set(params[0]);
if (np >= 2 && params.length >= 2)
spnParameter2.set(params[1]);
if (np >= 3 && params.length >= 3)
spnParameter3.set(params[2]);
if (np >= 4 && params.length >= 4)
spnParameter4.set(params[3]);
double size[] = NumFormat.parseNumbersAfter("size", parameters);
if (size.length > 0)
spnWidth.set((int) size[0]);
if (size.length > 1)
spnHeight.set((int) size[1]);
if (size.length > 2)
spnSlices.set((int) size[2]);
double intensity[] = NumFormat.parseNumbersAfter("intensity", parameters);
if (intensity.length > 0)
spnIntensity.set(intensity[0]);
double center[] = NumFormat.parseNumbersAfter("center", parameters);
if (center.length > 0)
spnCenterX.set(center[0]);
if (center.length > 1)
spnCenterY.set(center[1]);
if (center.length > 2)
spnCenterZ.set(center[2]);
}
public String getShapeName() {
return shape;
}
public String getCommand() {
return command;
}
public boolean wasCancel() {
return cancel;
}
@Override
public void windowOpened(WindowEvent e) {
}
@Override
public void windowClosing(WindowEvent e) {
dispose();
cancel = true;
shape = "";
command = "";
return;
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowDeactivated(WindowEvent e) {
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/module/LanguageModule.java b/DeconvolutionLab2/src/deconvolutionlab/module/LanguageModule.java
index 86115c1..be094dd 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/module/LanguageModule.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/module/LanguageModule.java
@@ -1,251 +1,251 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolutionlab.module;
import java.awt.BorderLayout;
import java.awt.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 bilib.component.HTMLPane;
import deconvolution.Command;
import deconvolution.Deconvolution;
-import deconvolution.Token;
+import deconvolution.CommandToken;
import deconvolution.algorithm.Algorithm;
import deconvolutionlab.Config;
public class LanguageModule extends AbstractModule implements ActionListener {
private HTMLPane language;
private JComboBox<String> cmb;
private JComboBox<String> gui;
private JTextField txt;
public LanguageModule() {
super("Language", "", "", "");
}
public String getJobName() {
if (txt != null)
return txt.getText();
return "";
}
@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 BorderLayout());
pn.add(cmb, BorderLayout.WEST);
pn.add(txt, BorderLayout.CENTER);
pn.add(gui, BorderLayout.EAST);
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 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();
language.append("p", matlab());
}
}
@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 matlab() {
String job = txt.getText();
String script = "";
String cmd = Command.command();
Deconvolution d = new Deconvolution("Matlab", cmd);
String options = Command.extractOptions(cmd);
Algorithm algo = d.getAlgorithm();
if (algo == null)
return "ERROR";
String s = algo.getShortnames()[0];
String param = algo.getParametersAsString();
script += p("% this function returns the deconvolved image as an 3D matrix");
script += p("% image is a 3D matrix containing the image");
script += p("% psf is a 3D matrix containing the PSF");
script += p("function result = " + job + "(image, psf)");
script += p1("% Install first DeconvolutionLab_2.jar into the java directory of Matlab");
script += p1("javaaddpath([matlabroot filesep 'java' filesep 'DeconvolutionLab_2.jar'])");
script += p1("% Run the deconvolution\n");
script += p1("result = DL2." + s + "(image, psf, " + param +" , '" + options +"');");
script += p("end");
return script;
}
private String imagej(boolean headless) {
String job = txt.getText();
String macro = p("// Job: " + job + " ");
macro += p("// Macro generated by DeconvolutionLab2 ");
macro += p("// " + new SimpleDateFormat("dd/MM/yy HH:m:s").format(new Date()) + " ");
String param = p("parameters = \"\" ");
- ArrayList<Token> tokens = Command.parse(Command.command());
+ ArrayList<CommandToken> tokens = Command.parse(Command.command());
String image = "image = \" NOT DEFINED \" ";
String psf = "psf = \" NOT DEFINED \" ";
String algo = "algo = \" NOT DEFINED \" ";
- for (Token token : tokens) {
+ for (CommandToken token : tokens) {
if (token.keyword.equals("-image"))
image = p("image = \" -image " + token.parameters.trim() + "\" ");
else if (token.keyword.equals("-psf"))
psf = p("psf = \" -psf " + token.parameters.trim() + "\" ");
else if (token.keyword.equals("-algorithm"))
algo = p("algorithm = \" -algorithm " + token.parameters.trim() + "\" ");
else
param += p("parameters += \" " + token.keyword + " " + token.parameters.trim() + "\"");
}
String option = macro + image + psf + algo + param;
String cmd = "";
if (headless)
cmd = p("run(\"DeconvolutionLab2 Run\", image + psf + algorithm + parameters)");
else
cmd = p("run(\"DeconvolutionLab2 Launch\", image + psf + algorithm + parameters)");
return option + cmd;
}
private String java(boolean headless) {
String job = txt.getText();
String code = "";
code += p("import deconvolution.Deconvolution;");
code += p("import ij.plugin.PlugIn;");
code += p("");
code += p("public class DeconvolutionLab2_" + job + " implements PlugIn {");
code += p1("public DeconvolutionLab2_" + job + "() {");
String param = p2("String parameters = \"\";");
- ArrayList<Token> tokens = Command.parse(Command.command());
+ ArrayList<CommandToken> tokens = Command.parse(Command.command());
String image = p2("String image = \" NOT DEFINED \";");
String psf = p2("String psf = \" NOT DEFINED \";");
String algo = p2("String algo = \" NOT DEFINED \";");
- for (Token token : tokens) {
+ for (CommandToken token : tokens) {
if (token.keyword.equals("-image"))
image = p2("String image = \" -image " + token.parameters.trim() + "\";");
else if (token.keyword.equals("-psf"))
psf = p2("String psf = \" -psf " + token.parameters.trim() + "\";");
else if (token.keyword.equals("-algorithm"))
algo = p2("String algorithm = \" -algorithm " + token.parameters.trim() + "\";");
else
param += p2("parameters += \" " + token.keyword + " " + token.parameters.trim() + "\";");
}
code += image + psf + algo + param;
code += p2("new Deconvolution(image + psf + algorithm + parameters)");
code += p1("}");
code += p1("");
code += p1("@Override");
code += p1("public void run(String arg0) {");
code += p2(" new DeconvolutionLab2_" + job + "();");
code += p1("}");
code += p("}");
return code;
}
private String p(String content) {
return "<p>" + content + "</p>";
}
private String p1(String content) {
return "<p style=\"padding-left:10px\">" + content + "</p>";
}
private String p2(String content) {
return "<p style=\"padding-left:20px\">" + content + "</p>";
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/system/AbstractMeter.java b/DeconvolutionLab2/src/deconvolutionlab/system/AbstractMeter.java
index b783253..29f1912 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/system/AbstractMeter.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/system/AbstractMeter.java
@@ -1,119 +1,119 @@
/*
* 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.system;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.util.HashMap;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import bilib.table.CustomizedTable;
import deconvolutionlab.Constants;
public abstract class AbstractMeter extends JButton {
protected Color colorBackground = new Color(10, 10, 10, 30);
protected Color colorText = new Color(10, 10, 10);
protected Color colorHot = new Color(10, 10, 160, 30);
protected CustomizedTable table;
protected HashMap<String, Integer> features = new HashMap<String, Integer>();
protected boolean initialized = false;
protected String prefix = "\u25BA ";
protected boolean collapse = true;
public AbstractMeter() {
super("");
int w = (int)(Constants.widthGUI/3.2);
int h = 25;
setBorder(BorderFactory.createEtchedBorder());
setPreferredSize(new Dimension(w, h));
setMinimumSize(new Dimension(w, h));
table = new CustomizedTable(new String[] {"Tool", "Feature", "Value"}, false);
}
public boolean isExpanded() {
return !collapse;
}
public void collapse() {
collapse = true;
prefix = " \u25BA ";
}
public void expand() {
collapse = false;
prefix = " \u25BC ";
}
public JPanel getPanel(int width, int height) {
JPanel panel = new JPanel(new BorderLayout());
panel.add(table.getPane(width, height), BorderLayout.CENTER);
setDetail();
initialized = true;
return panel;
}
- public abstract String getName();
+ public abstract String getMeterName();
public abstract void setDetail();
public void update() {
if (table == null)
return;
setDetail();
}
protected void add(int i, String row[]) {
if (initialized) {
int r = features.get(row[0]);
if (i>=0 && i<table.getRowCount())
table.setCell(r, 1, row[1]);
}
else {
table.append(row);
features.put(row[0], i);
}
}
protected String split(String name) {
String func = name.substring(3);
return func.replaceAll("(\\p{Ll})(\\p{Lu})", "$1 $2");
}
}
diff --git a/DeconvolutionLab2/src/deconvolutionlab/system/FFTMeter.java b/DeconvolutionLab2/src/deconvolutionlab/system/FFTMeter.java
index a057252..cb07214 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/system/FFTMeter.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/system/FFTMeter.java
@@ -1,59 +1,59 @@
/*
* 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.system;
import java.awt.Graphics;
import fft.FFT;
public class FFTMeter extends AbstractMeter {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(colorText);
g.drawString(prefix + FFT.getFastestFFT().getLibraryName(), 10, 17);
}
@Override
public void update() {
repaint();
}
@Override
- public String getName() {
+ public String getMeterName() {
return "FFT";
}
@Override
public void setDetail() {
}
}
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/deconvolutionlab/system/FileMeter.java b/DeconvolutionLab2/src/deconvolutionlab/system/FileMeter.java
index c0c099d..7b058f6 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/system/FileMeter.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/system/FileMeter.java
@@ -1,91 +1,91 @@
/*
* 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.system;
import java.awt.Graphics;
import java.io.File;
import java.lang.management.ClassLoadingMXBean;
import java.lang.management.ManagementFactory;
import bilib.tools.NumFormat;
public class FileMeter extends AbstractMeter {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
double maxi = SystemUsage.getTotalSpace();
double used = maxi - SystemUsage.getAvailableSpace();
String space = NumFormat.bytes(used);
int w = getWidth();
g.setColor(colorBackground);
for(int i=0; i<w; i+=w/10)
g.drawLine(i, 0, i, 30);
int posu = (int)Math.round(w*used/maxi);
g.setColor(colorHot);
g.fillRect(0, 0, posu, 30);
g.setColor(colorText);
g.drawString(prefix + space, 10, 17);
}
@Override
public void update() {
repaint();
}
@Override
- public String getName() {
+ public String getMeterName() {
return "File";
}
@Override
public void setDetail() {
File[] roots = File.listRoots();
int i=0;
add(i++, new String[] { "Properties", "java.class.path", System.getProperty("java.class.path") });
add(i++, new String[] { "Properties", "java.home", System.getProperty("java.home") });
add(i++, new String[] { "Properties", "user.dir", System.getProperty("user.dir") });
add(i++, new String[] { "Properties", "user.home", System.getProperty("user.home") });
add(i++, new String[] { "Properties", "user.name", System.getProperty("user.name") });
for (File root : roots) {
add(i++, new String[] { "FileSystem", "Root Path", root.getAbsolutePath() });
add(i++, new String[] { "FileSystem", "Total Space", NumFormat.bytes(root.getTotalSpace()) });
add(i++, new String[] { "FileSystem", "Usable Space", NumFormat.bytes(root.getUsableSpace()) });
}
ClassLoadingMXBean loader = ManagementFactory.getClassLoadingMXBean();
add(i++, new String[] { "ClassLoading", "Loaded Class", "" + loader.getLoadedClassCount() });
}
}
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/deconvolutionlab/system/JavaMeter.java b/DeconvolutionLab2/src/deconvolutionlab/system/JavaMeter.java
index 3b3f3be..9820067 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/system/JavaMeter.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/system/JavaMeter.java
@@ -1,79 +1,79 @@
/*
* 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.system;
import java.awt.Graphics;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import bilib.tools.NumFormat;
public class JavaMeter extends AbstractMeter {
@Override
public void paintComponent(Graphics g) {
g.setColor(colorText);
g.drawString(prefix + "Java "+ System.getProperty("java.version") , 10, 17);
}
@Override
public void update() {
repaint();
}
@Override
- public String getName() {
+ public String getMeterName() {
return "Java";
}
@Override
public void setDetail() {
int i = 0;
add(i++, new String[] { "Properties", "OS", System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch") });
add(i++, new String[] { "Properties", "Java Version", System.getProperty("java.version") });
RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
add(i++, new String[] { "Runtime", "LibraryPath", rt.getLibraryPath() });
add(i++, new String[] { "Runtime", "Name", rt.getName() });
add(i++, new String[] { "Runtime", "VmVersion", rt.getVmVersion() });
for (int k = 0; k<rt.getInputArguments().size(); k++) {
String input = rt.getInputArguments().get(k);
add(i++, new String[] { "Runtime", "Input Arguments " + (k+1), input });
}
Runtime runt = Runtime.getRuntime();
add(i++, new String[] { "JVM", "Available processors", "" + runt.availableProcessors() });
add(i++, new String[] { "JVM", "Initial Memory (-Xms)", NumFormat.bytes(runt.freeMemory()) });
add(i++, new String[] { "JVM", "Maximum Memory (-Xmx)", NumFormat.bytes(runt.maxMemory()) });
add(i++, new String[] { "JVM", "Total Used Memory", NumFormat.bytes(runt.totalMemory()) });
}
}
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/deconvolutionlab/system/MemoryMeter.java b/DeconvolutionLab2/src/deconvolutionlab/system/MemoryMeter.java
index 287943e..86c79c2 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/system/MemoryMeter.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/system/MemoryMeter.java
@@ -1,101 +1,101 @@
/*
* 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.system;
import java.awt.Graphics;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
import bilib.tools.NumFormat;
public class MemoryMeter extends AbstractMeter {
private double peak;
public void reset() {
peak = 0;
}
@Override
public void update() {
repaint();
}
@Override
public void paintComponent(Graphics g) {
MemoryUsage mem = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
double used = mem.getUsed();
double maxi = mem.getMax();
peak = Math.max(used, peak);
super.paintComponent(g);
int w = getWidth();
g.setColor(colorBackground);
for(int i=0; i<w; i+=w/10)
g.drawLine(i, 0, i, 30);
int posu = (int)Math.round(w*used/maxi);
int posp = (int)Math.round(w*peak/maxi);
String u = NumFormat.bytes(used);
g.setColor(colorHot);
g.fillRect(0, 0, posu, 30);
g.fillRect(0, 0, posp, 30);
g.setColor(colorText);
g.drawString(prefix + u, 10, 17);
}
@Override
- public String getName() {
+ public String getMeterName() {
return "Memory";
}
@Override
public void setDetail() {
MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
MemoryUsage heapU = mem.getHeapMemoryUsage();
MemoryUsage nonhU = mem.getNonHeapMemoryUsage();
Runtime runt = Runtime.getRuntime();
int i = 0;
add(i++, new String[] { "JVM", "Initial Memory (-Xms)", NumFormat.bytes(runt.freeMemory()) });
add(i++, new String[] { "JVM", "Maximum Memory (-Xmx)", NumFormat.bytes(runt.maxMemory()) });
add(i++, new String[] { "JVM", "Total Used Memory", NumFormat.bytes(runt.totalMemory()) });
add(i++, new String[] { "Memory", "Heap Used", NumFormat.bytes(heapU.getUsed()) });
add(i++, new String[] { "Memory", "Heap Init", NumFormat.bytes(heapU.getInit()) });
add(i++, new String[] { "Memory", "Heap Max ", NumFormat.bytes(heapU.getMax()) });
add(i++, new String[] { "Memory", "NonHeap Used", NumFormat.bytes(nonhU.getUsed()) });
add(i++, new String[] { "Memory", "NonHeap Init", NumFormat.bytes(nonhU.getInit()) });
}
}
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/deconvolutionlab/system/ProcessorMeter.java b/DeconvolutionLab2/src/deconvolutionlab/system/ProcessorMeter.java
index d50f35d..ac1f84d 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/system/ProcessorMeter.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/system/ProcessorMeter.java
@@ -1,104 +1,104 @@
/*
* 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.system;
import java.awt.Color;
import java.awt.Graphics;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import bilib.tools.NumFormat;
public class ProcessorMeter extends AbstractMeter {
@Override
public void update() {
repaint();
}
@Override
public void paintComponent(Graphics g) {
double used = SystemUsage.getLoad();
double maxi = 100;
super.paintComponent(g);
int w = getWidth();
g.setColor(new Color(10, 10, 10, 30));
for(int i=0; i<w; i+=w/10)
g.drawLine(i, 0, i, 30);
int posu = (int)Math.round(w*used/maxi);
String u = String.format("%3.3f", used);
g.setColor(colorHot);
g.fillRect(0, 0, posu, 30);
g.setColor(colorText);
g.drawString(prefix + u + "%", 10, 17);
}
@Override
- public String getName() {
+ public String getMeterName() {
return "Processor";
}
@Override
public void setDetail() {
Runtime runt = Runtime.getRuntime();
int i = 0;
RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
add(i++, new String[] { "JVM", "Available processors", "" + runt.availableProcessors() });
add(i++, new String[] { "Runtime", "Uptime", "" + NumFormat.time(rt.getUptime()*1e6) });
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
for (Method method : os.getClass().getDeclaredMethods()) {
method.setAccessible(true);
if (method.getName().startsWith("get") && Modifier.isPublic(method.getModifiers())) {
try {
String name = split(method.getName());
if (name.contains("Size"))
add(i++, new String[] { "OS", name, NumFormat.bytes(Double.parseDouble(method.invoke(os).toString())) });
else if (name.contains("Time"))
add(i++, new String[] { "OS", name, NumFormat.time(Double.parseDouble(method.invoke(os).toString())) });
else if (name.contains("Load"))
add(i++, new String[] { "OS", name, NumFormat.nice(100 * Double.parseDouble(method.invoke(os).toString()))+"%" });
else
add(i++, new String[] { "OS", name, "" + method.invoke(os).toString() });
}
catch (Exception e) {
}
}
}
}
}
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/deconvolutionlab/system/SignalMeter.java b/DeconvolutionLab2/src/deconvolutionlab/system/SignalMeter.java
index f09eabf..229ff4c 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/system/SignalMeter.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/system/SignalMeter.java
@@ -1,60 +1,60 @@
/*
* 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.system;
import java.awt.Graphics;
import signal.SignalCollector;
public class SignalMeter extends AbstractMeter {
@Override
public void paintComponent(Graphics g) {
g.setColor(colorText);
g.drawString(prefix + SignalCollector.sumarize(), 10, 17);
}
@Override
public void update() {
repaint();
}
@Override
- public String getName() {
+ public String getMeterName() {
return "Signals";
}
@Override
public void setDetail() {
}
}
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/deconvolutionlab/system/SystemPanel.java b/DeconvolutionLab2/src/deconvolutionlab/system/SystemPanel.java
index f801207..3871fad 100644
--- a/DeconvolutionLab2/src/deconvolutionlab/system/SystemPanel.java
+++ b/DeconvolutionLab2/src/deconvolutionlab/system/SystemPanel.java
@@ -1,242 +1,239 @@
/*
* 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.system;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
+import signal.SignalCollector;
import bilib.component.PanelImage;
import bilib.tools.NumFormat;
import deconvolutionlab.Config;
import deconvolutionlab.Constants;
import fft.FFTPanel;
-import signal.SignalCollector;
public class SystemPanel extends JPanel implements ActionListener, MouseListener {
private JPanel cards;
private String[] rates = new String[] { "1 s.", "0.5 s.", "0.2 s.", "0.1 s.", "10 s.", "5 s.", "2 s." };
private JButton bnRate = new JButton("1 s.");
private JButton bnClear = new JButton("Clear");
private Timer timer = new Timer();
private TimerTask updater = new Updater();
private MemoryMeter memory;
private ProcessorMeter processor;
private SignalMeter signal;
private FFTMeter fft;
private JavaMeter java;
private FileMeter file;
private int width = Constants.widthGUI;
private static SystemPanel instance;
private int rate = 0;
- private static JFrame frame;
private ArrayList<AbstractMeter> meters = new ArrayList<AbstractMeter>();
public static SystemPanel getInstance(JFrame parent) {
if (instance == null) {
instance = new SystemPanel();
}
- frame = parent;
-
return instance;
}
private SystemPanel() {
memory = new MemoryMeter();
processor = new ProcessorMeter();
signal = new SignalMeter();
fft = new FFTMeter();
java = new JavaMeter();
file = new FileMeter();
meters.add(memory);
meters.add(processor);
meters.add(signal);
meters.add(fft);
meters.add(java);
meters.add(file);
// Panel meters on top
JPanel meters = new JPanel(new GridLayout(2, 3));
meters.add(file);
meters.add(memory);
meters.add(processor);
meters.add(java);
meters.add(signal);
meters.add(fft);
bnClear.setToolTipText("Clear all the entries");
bnRate.setToolTipText("Choose the rate of refreshing the information");
JPanel pan = new JPanel(new GridLayout(2, 1));
pan.add(bnRate);
pan.add(bnClear);
restart();
// Panel Compact
PanelImage pnCompact = new PanelImage("celegans.jpg");
pnCompact.setPreferredSize(new Dimension(width, 20));
// Panel cards, compact is visible
cards = new JPanel(new CardLayout());
cards.add("collapse", pnCompact);
cards.add(signal.getName(), SignalCollector.getPanel(width, 200));
cards.add(memory.getName(), memory.getPanel(width, 200));
cards.add(processor.getName(), processor.getPanel(width, 200));
cards.add(fft.getName(), new FFTPanel(width, 200));
cards.add(java.getName(), java.getPanel(width, 200));
cards.add(file.getName(), file.getPanel(width, 200));
cards.setVisible(false);
JPanel top = new JPanel(new BorderLayout());
top.add(meters, BorderLayout.CENTER);
top.add(pan, BorderLayout.EAST);
setLayout(new BorderLayout());
add(top, BorderLayout.NORTH);
add(cards, BorderLayout.CENTER);
bnClear.addActionListener(this);
signal.addMouseListener(this);
memory.addMouseListener(this);
processor.addMouseListener(this);
java.addMouseListener(this);
file.addMouseListener(this);
fft.addMouseListener(this);
bnRate.addActionListener(this);
setMinimumSize(new Dimension(width, 70));
bnClear.setEnabled(signal.isExpanded());
Rectangle rect = Config.getDialog("System.Frame");
if (rect.x > 0 && rect.y > 0)
setLocation(rect.x, rect.y);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bnRate) {
rate++;
if (rate >= rates.length)
rate = 0;
bnRate.setText(rates[rate]);
restart();
}
if (e.getSource() == bnClear) {
SignalCollector.clear();
}
}
public void update() {
for(AbstractMeter meter : meters)
meter.update();
}
public void restart() {
long refreshTime = (long) (NumFormat.parseNumber(bnRate.getText(), 1) * 1000);
if (updater != null) {
updater.cancel();
updater = null;
}
updater = new Updater();
timer.schedule(updater, 0, refreshTime);
}
private class Updater extends TimerTask {
@Override
public void run() {
update();
}
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getSource() instanceof AbstractMeter) {
AbstractMeter meter = (AbstractMeter) e.getSource();
if (meter.isExpanded()) {
meter.collapse();
cards.setVisible(false);
}
else for(AbstractMeter m : meters) {
if (m.isExpanded())
m.collapse();
meter.expand();
cards.setVisible(true);
}
((CardLayout) (cards.getLayout())).show(cards, meter.getName());
}
bnClear.setEnabled(signal.isExpanded());
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
}
diff --git a/DeconvolutionLab2/src/signal/Signal.java b/DeconvolutionLab2/src/signal/Signal.java
index 05a70b5..b78b7f0 100644
--- a/DeconvolutionLab2/src/signal/Signal.java
+++ b/DeconvolutionLab2/src/signal/Signal.java
@@ -1,60 +1,69 @@
/*
* 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;
-import java.util.ArrayList;
-
+/**
+ * This class is an abstract class to store a 3D signal in a float array 'data'.
+ * The data are store in a 2D array, the first index represents the z direction
+ * and the second store a 2D plane in row-major representation.
+ *
+ * There are two implementations of this class: RealSignal to store a real volume
+ * and ComplexSignal to store a complex signal in interleaving mode.
+ *
+ * @author Daniel Sage
+ *
+ */
public class Signal {
- public int nx = 0;
- public int ny;
- public int nz;
+ final public int nx;
+ final public int ny;
+ final public int nz;
public float data[][];
public String name = "untitled";
public Signal(String name, int nx, int ny, int nz) {
this.name = name;
this.nx = nx;
this.ny = ny;
this.nz = nz;
}
public Signal setName(String name) {
this.name = name;
return this;
}
public String dimAsString() {
return nx + "x" + ny + "x" + nz + " ";
}
}
diff --git a/DeconvolutionLab2/src/signal/apodization/Apodization.java b/DeconvolutionLab2/src/signal/apodization/Apodization.java
index 20c0cd9..1420220 100644
--- a/DeconvolutionLab2/src/signal/apodization/Apodization.java
+++ b/DeconvolutionLab2/src/signal/apodization/Apodization.java
@@ -1,161 +1,159 @@
/*
* 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.apodization;
import java.util.ArrayList;
-import deconvolutionlab.Lab;
-import deconvolutionlab.monitor.Monitors;
-import signal.Operations;
import signal.RealSignal;
+import deconvolutionlab.monitor.Monitors;
public class Apodization {
private AbstractApodization apoX = getDefault();
private AbstractApodization apoY = getDefault();
private AbstractApodization apoZ = getDefault();
public Apodization() {
apoX = new UniformApodization();
apoY = new UniformApodization();
apoZ = new UniformApodization();
}
public Apodization(AbstractApodization apoX, AbstractApodization apoY, AbstractApodization apoZ) {
this.apoX = apoX;
this.apoY = apoY;
this.apoZ = apoZ;
}
public Apodization(String nameX, String nameY, String nameZ) {
for(AbstractApodization apo : getApodizations()) {
if (apo.getName().equals(nameX))
apoX = apo;
if (apo.getName().equals(nameY))
apoY = apo;
if (apo.getName().equals(nameZ))
apoZ = apo;
if (apo.getShortname().equals(nameX))
apoX = apo;
if (apo.getShortname().equals(nameY))
apoY = apo;
if (apo.getShortname().equals(nameZ))
apoZ = apo;
}
}
public static ArrayList<AbstractApodization> getApodizations() {
ArrayList<AbstractApodization> apos = new ArrayList<AbstractApodization>();
apos.add(new UniformApodization());
apos.add(new HammingApodization());
apos.add(new HannApodization());
apos.add(new RaisedCosineApodization(1));
apos.add(new TukeyApodization(0.5));
apos.add(new WelchApodization());
return apos;
}
public static ArrayList<String> getApodizationsName() {
ArrayList<AbstractApodization> apos = getApodizations();
ArrayList<String> names = new ArrayList<String>();
for(AbstractApodization apo : apos)
names.add(apo.getName());
return names;
}
public static String[] getApodizationsAsArray() {
ArrayList<AbstractApodization> apos = getApodizations();
String names[] = new String[apos.size()];
for(int i=0; i<apos.size(); i++)
names[i] = apos.get(i).getName();
return names;
}
public static AbstractApodization getByName(String name) {
ArrayList<AbstractApodization> apos = getApodizations();
for(AbstractApodization apo : apos)
if (name.equals(apo.getName()))
return apo;
return getDefault();
}
public static AbstractApodization getByShortname(String name) {
ArrayList<AbstractApodization> apos = getApodizations();
for(AbstractApodization apo : apos)
if (name.equals(apo.getShortname()))
return apo;
return getDefault();
}
public static AbstractApodization getDefault() {
return new UniformApodization();
}
public void apodize(Monitors monitors, RealSignal signal) {
if (apoX instanceof UniformApodization &&
apoY instanceof UniformApodization &&
apoZ instanceof UniformApodization) {
return;
}
if (monitors != null)
monitors.log("Apodization (" + apoX.getName() + ", " + apoY.getName() + ", " + apoZ.getName() + ")");
signal.setName("apo(" + signal.name + ")");
for(int i=0; i<signal.nx; i++) {
double cx = apoX.apodize(i, signal.nx);
for(int j=0; j<signal.ny; j++) {
double cy = apoY.apodize(j, signal.ny);
int index = i + signal.nx*j;
for(int k=0; k<signal.nz; k++) {
double cz = apoZ.apodize(k, signal.nz);
signal.data[k][index] = (float)(cx * cy * cz * signal.data[k][index]);
}
}
}
}
@Override
public String toString() {
String s = "";
s += "lateral (XY)";
if (apoX instanceof UniformApodization)
s += " keep unchanged";
else
s+= " " + apoX.getName();
s += ", axial (Z)";
if (apoZ instanceof UniformApodization)
s += " keep unchanged";
else
s+= " " + apoZ.getName();
return s;
}
}
diff --git a/DeconvolutionLab2/src/signal/factory/Defocus.java b/DeconvolutionLab2/src/signal/factory/Defocus.java
index c3ba9d8..a200a06 100644
--- a/DeconvolutionLab2/src/signal/factory/Defocus.java
+++ b/DeconvolutionLab2/src/signal/factory/Defocus.java
@@ -1,98 +1,97 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package signal.factory;
import signal.RealSignal;
public class Defocus extends SignalFactory {
private double fwhm = 3.0;
private double low2fwhm = 10;
private double up2fwhm = 10;
public Defocus(double fwhm, double low2fwhm, double up2fwhm) {
super(new double[] {fwhm, low2fwhm, up2fwhm});
setParameters(new double[] { fwhm, low2fwhm, up2fwhm });
}
@Override
public String getName() {
return "Defocus";
}
@Override
public String[] getParametersName() {
return new String[] {"FWHM at focus plane", "-Delta Z (2xFWHM)", "+Delta Z (2xFWHM)"};
}
@Override
public void setParameters(double[] parameters) {
if (parameters.length >= 1)
this.fwhm = parameters[0];
if (parameters.length >= 2)
this.low2fwhm = parameters[1];
if (parameters.length >= 3)
this.up2fwhm = parameters[2];
}
@Override
public double[] getParameters() {
return new double[] {fwhm, low2fwhm, up2fwhm};
}
@Override
public void fill(RealSignal signal) {
double sigma = fwhm;
double zup = zc - low2fwhm;
double zlw = zc + up2fwhm;
double Q = 2.0*Math.PI;
double A0 = (sigma * sigma * Q);
double aup = 2.0 / ((zup-zc)*(zup-zc));
double alw = 2.0 / ((zlw-zc)*(zlw-zc));
for(int z=0; z<nz; z++) {
double sigmaZ = sigma;
if (z > zc)
sigmaZ += sigma * aup * (z-zc)*(z-zc);
else
sigmaZ += sigma * alw * (z-zc)*(z-zc);
double K = 1.0 / (2.0*sigmaZ*sigmaZ);
- double A = A0 / (sigmaZ * sigmaZ * 2);
for(int x=0; x<nx; x++)
for(int y=0; y<ny; y++) {
double r2 = (x-xc)*(x-xc) + (y-yc)*(y-yc);
signal.data[z][x+nx*y] = (float)(amplitude * Math.exp(-K*r2));
}
}
}
}
diff --git a/DeconvolutionLab2/src/signal/factory/Laplacian.java b/DeconvolutionLab2/src/signal/factory/Laplacian.java
index 1b326e3..806cfc2 100644
--- a/DeconvolutionLab2/src/signal/factory/Laplacian.java
+++ b/DeconvolutionLab2/src/signal/factory/Laplacian.java
@@ -1,74 +1,73 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package signal.factory;
-import deconvolutionlab.Lab;
-import deconvolutionlab.monitor.Monitors;
-import fft.AbstractFFT;
-import fft.FFT;
import signal.ComplexSignal;
import signal.RealSignal;
import signal.factory.complex.ComplexSignalFactory;
+import deconvolutionlab.monitor.Monitors;
+import fft.AbstractFFT;
+import fft.FFT;
public class Laplacian extends SignalFactory {
public Laplacian() {
super(new double[] {});
}
@Override
public String getName() {
return "Laplacian";
}
@Override
public String[] getParametersName() {
return new String[] {};
}
@Override
public void setParameters(double[] parameters) {
}
@Override
public double[] getParameters() {
return new double[] {};
}
@Override
public void fill(RealSignal signal) {
AbstractFFT fft = FFT.createDefaultFFT(Monitors.createDefaultMonitor(), nx, ny, nz);
ComplexSignal C = ComplexSignalFactory.laplacian(nx, ny, nz);
RealSignal s = fft.inverse(C).circular().times((float)amplitude);
signal.copy(s);
}
}
diff --git a/DeconvolutionLab2/src/signal/factory/SignalFactory.java b/DeconvolutionLab2/src/signal/factory/SignalFactory.java
index 1ceffc0..6340870 100644
--- a/DeconvolutionLab2/src/signal/factory/SignalFactory.java
+++ b/DeconvolutionLab2/src/signal/factory/SignalFactory.java
@@ -1,275 +1,277 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package signal.factory;
import java.util.ArrayList;
import javax.swing.SwingWorker;
+import signal.RealSignal;
import bilib.tools.NumFormat;
import deconvolution.Command;
-import signal.RealSignal;
public abstract class SignalFactory {
protected double fractXC = 0.5;
protected double fractYC = 0.5;
protected double fractZC = 0.5;
protected double amplitude = 1.0;
protected double xc;
protected double yc;
protected double zc;
protected int nx;
protected int ny;
protected int nz;
public SignalFactory() {
}
public SignalFactory(double[] parameters) {
setParameters(parameters);
}
public static SignalFactory get(String name) {
ArrayList<SignalFactory> list = getAll();
for (SignalFactory factory : list) {
if (factory.getName().equals(name))
return factory;
}
return null;
}
public static RealSignal createFromCommand(String cmd) {
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;
int np = factory.getParameters().length;
double parameters[] = new double[np];
if (np >= 1 && params.length >= 1)
parameters[0] = params[0];
if (np >= 2 && params.length >= 2)
parameters[1] = params[1];
if (np >= 3 && params.length >= 3)
parameters[2] = params[2];
if (np >= 4 && params.length >= 4)
parameters[3] = params[3];
double size[] = NumFormat.parseNumbersAfter("size", cmd);
int nx = 128;
int ny = 128;
int nz = 32;
if (size.length > 0)
nx = (int) size[0];
if (size.length > 1)
ny = (int) size[1];
if (size.length > 2)
nz = (int) size[2];
double intensity[] = NumFormat.parseNumbersAfter("intensity", cmd);
double amplitude = 255;
if (intensity.length > 0)
amplitude = intensity[0];
double center[] = NumFormat.parseNumbersAfter("center", cmd);
double cx = 0.5;
double cy = 0.5;
double cz = 0.5;
if (center.length > 0)
cx = center[0];
if (center.length > 1)
cy = center[1];
if (center.length > 2)
cz = center[2];
factory.intensity(amplitude);
factory.setParameters(parameters);
factory = factory.center(cx, cy, cz);
return factory.generate(nx, ny, nz);
}
}
return null;
}
public static ArrayList<String> getAllName() {
ArrayList<String> list = new ArrayList<String>();
for (SignalFactory factory : getAll()) {
list.add(factory.getName());
}
return list;
}
public static ArrayList<SignalFactory> getAll() {
ArrayList<SignalFactory> list = new ArrayList<SignalFactory>();
list.add(new Airy(5, 1, 0.5, 3));
list.add(new Astigmatism(5, 1));
list.add(new AxialDiffractionSimulation(10, 10, 2));
list.add(new BesselJ0(2, 5, 0.2, 0.2));
list.add(new Constant());
list.add(new Cross(1, 1, 30));
list.add(new Cube(10 ,1));
list.add(new CubeSphericalBeads(3, 0.5, 8, 16));
list.add(new Defocus(3, 10, 10));
list.add(new DirectionalDerivative(1, 1, 0));
list.add(new DirectionalMotionBlur(3, 30, 3));
list.add(new DoG(3, 4));
list.add(new DoubleHelix(3, 30, 10));
list.add(new Gaussian(3, 3, 3));
list.add(new Impulse());
list.add(new Laplacian());
list.add(new Ramp(1, 1, 1));
list.add(new RandomLines(100));
list.add(new Sinc(3, 3, 3));
list.add(new Sphere(10, 1));
list.add(new Torus(30));
return list;
}
public static ArrayList<SignalFactory> getImages() {
ArrayList<SignalFactory> list = new ArrayList<SignalFactory>();
list.add(new Cube(10, 1));
list.add(new CubeSphericalBeads(3, 0.5, 8, 16));
list.add(new Sphere(10, 1));
list.add(new Constant());
list.add(new Cross(1, 1, 30));
list.add(new Gaussian(3, 3, 3));
list.add(new Impulse());
list.add(new Ramp(1, 0, 0));
list.add(new RandomLines(3));
list.add(new Torus(10));
return list;
}
public static ArrayList<SignalFactory> getPSF() {
ArrayList<SignalFactory> list = new ArrayList<SignalFactory>();
list.add(new Airy(5, 1, 0.5, 3));
list.add(new Astigmatism(5, 1));
list.add(new AxialDiffractionSimulation(10, 10, 2));
list.add(new BesselJ0(2, 5, 0.2, 0.2));
list.add(new Cross(1, 1, 30));
list.add(new CubeSphericalBeads(3, 0.5, 8, 16));
list.add(new Defocus(3, 10, 10));
list.add(new DirectionalDerivative(1, 1, 0));
list.add(new DirectionalMotionBlur(3, 30, 3));
list.add(new DoG(3, 4));
list.add(new DoubleHelix(3, 30, 10));
list.add(new Gaussian(3, 3, 3));
list.add(new Impulse());
list.add(new Laplacian());
list.add(new Sinc(3, 3, 3));
list.add(new Sphere(10, 1));
return list;
}
public static SignalFactory getFactoryByName(String name) {
ArrayList<SignalFactory> list = getAll();
for (SignalFactory factory : list)
if (name.toLowerCase().equals(factory.getName().toLowerCase())) {
return factory;
}
return null;
}
public SignalFactory center(double fractXC, double fractYC, double fractZC) {
this.fractXC = fractXC;
this.fractYC = fractYC;
this.fractZC = fractZC;
return this;
}
public SignalFactory intensity(double amplitude) {
this.amplitude = amplitude;
return this;
}
public String params() {
String name[] = getParametersName();
double params[] = getParameters();
if (params.length == 1)
return name[0] + "=" + params[0];
else if (params.length == 2)
return name[0] + "=" + params[0] + " " + name[1] + "=" + params[1];
else
return name[0] + "=" + params[0] + " " + name[1] + "=" + params[2] + " " + name[2] + "=" + params[2];
}
public RealSignal generate(int nx, int ny, int nz) {
this.nx = nx;
this.ny = ny;
this.nz = nz;
xc = fractXC * nx;
yc = fractYC * ny;
zc = fractZC * nz;
RealSignal signal = new RealSignal(getName(), nx, ny, nz);
fill(signal);
return signal;
}
public abstract String getName();
public abstract void setParameters(double[] parameters);
public abstract double[] getParameters();
public abstract String[] getParametersName();
public abstract void fill(RealSignal signal);
public class Worker extends SwingWorker<RealSignal, String> {
private RealSignal signal;
public boolean done=false;
public Worker(RealSignal signal) {
this.signal = signal;
done = false;
}
+ @Override
protected RealSignal doInBackground() throws Exception {
fill(signal);
done = true;
return signal;
}
+ @Override
protected void done() {
done = true;
}
}
}
diff --git a/DeconvolutionLab2/src/wavelets/spline/SplineWaveletsTool.java b/DeconvolutionLab2/src/wavelets/spline/SplineWaveletsTool.java
index 8929bbd..cf797e9 100644
--- a/DeconvolutionLab2/src/wavelets/spline/SplineWaveletsTool.java
+++ b/DeconvolutionLab2/src/wavelets/spline/SplineWaveletsTool.java
@@ -1,255 +1,255 @@
/*
* 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 wavelets.spline;
import signal.RealSignal;
public class SplineWaveletsTool {
private SplineFilter filters;
public SplineWaveletsTool(int scale, int order) {
this.filters = new SplineFilter(order);
}
public void analysis1(RealSignal in, RealSignal out) {
int nx = in.nx;
int ny = in.ny;
int nz = in.nz;
float ux[] = new float[nx];
float vx[] = new float[nx];
for (int z = 0; z < nz; z++)
for (int y = 0; y < ny; y++) {
ux = in.getX(y, z);
splitMirror(ux, vx, filters.h, filters.g);
out.setX(y, z, vx);
}
float uy[] = new float[ny];
float vy[] = new float[ny];
for (int z = 0; z < nz; z++)
for (int x = 0; x < nx; x++) {
uy = out.getY(x, z);
splitMirror(uy, vy, filters.h, filters.g);
out.setY(x, z, vy);
}
if (nz > 1) {
float uz[] = new float[nz];
float vz[] = new float[nz];
for (int x = 0; x < nx; x++)
for (int y = 0; y < ny; y++) {
uz = out.getZ(x, y);
splitMirror(uz, vz, filters.h, filters.g);
out.setZ(x, y, vz);
}
}
}
public void synthesis1(RealSignal in, RealSignal out) {
int nx = in.nx;
int ny = in.ny;
int nz = in.nz;
float ux[] = new float[nx];
float vx[] = new float[nx];
for (int z = 0; z < nz; z++)
for (int y = 0; y < ny; y++) {
ux = in.getX(y, z);
mergeMirror(ux, vx, filters.h, filters.g);
out.setX(y, z, vx);
}
float uy[] = new float[ny];
float vy[] = new float[ny];
for (int z = 0; z < nz; z++)
for (int x = 0; x < nx; x++) {
uy = out.getY(x, z);
mergeMirror(uy, vy, filters.h, filters.g);
out.setY(x, z, vy);
}
if (nz > 1) {
float uz[] = new float[nz];
float vz[] = new float[nz];
for (int x = 0; x < nx; x++)
for (int y = 0; y < ny; y++) {
uz = out.getZ(x, y);
mergeMirror(uz, vz, filters.h, filters.g);
out.setZ(x, y, vz);
}
}
}
- private void splitMirror(float vin[], float vout[], double h[], double g[]) {
+ static private void splitMirror(float vin[], float vout[], double h[], double g[]) {
int n = vin.length;
int n2 = n / 2;
int nh = h.length;
int ng = g.length;
double pix;
int j, k, j1, j2;
int period = 2 * n - 2; // period for mirror boundary conditions
for (int i = 0; i < n2; i++) {
j = i * 2;
pix = vin[j] * h[0];
for (k = 1; k < nh; k++) { // Low pass part
j1 = j - k;
if (j1 < 0) { // Mirror conditions
while (j1 < 0)
j1 += period; // Periodize
if (j1 >= n)
j1 = period - j1; // Symmetrize
}
j2 = j + k;
if (j2 >= n) { // Mirror conditions
while (j2 >= n)
j2 -= period; // Periodize
if (j2 < 0)
j2 = -j2; // Symmetrize
}
pix = pix + h[k] * (vin[j1] + vin[j2]);
}
vout[i] = (float) pix;
j = j + 1;
pix = vin[j] * g[0]; // High pass part
for (k = 1; k < ng; k++) {
j1 = j - k;
if (j1 < 0) { // Mirror conditions
while (j1 < 0)
j1 += period; // Periodize
if (j1 >= n)
j1 = period - j1; // Symmetrize
}
j2 = j + k;
if (j2 >= n) { // Mirror conditions
while (j2 >= n)
j2 -= period; // Periodize
if (j2 < 0)
j2 = -j2; // Symmetrize
}
pix = pix + g[k] * (vin[j1] + vin[j2]);
}
vout[i + n2] = (float) pix;
}
}
static private void mergeMirror(float vin[], float vout[], double h[], double g[]) {
int n = vin.length;
int n2 = n / 2;
int nh = h.length;
int ng = g.length;
double pix1, pix2;
int j, k, kk, i1, i2;
int k01 = (nh / 2) * 2 - 1;
int k02 = (ng / 2) * 2 - 1;
int period = 2 * n2 - 1; // period for mirror boundary conditions
for (int i = 0; i < n2; i++) {
j = 2 * i;
pix1 = h[0] * vin[i];
for (k = 2; k < nh; k += 2) {
i1 = i - (k / 2);
if (i1 < 0) {
i1 = (-i1) % period;
if (i1 >= n2)
i1 = period - i1;
}
i2 = i + (k / 2);
if (i2 > n2 - 1) {
i2 = i2 % period;
if (i2 >= n2)
i2 = period - i2;
}
pix1 = pix1 + h[k] * (vin[i1] + vin[i2]);
}
pix2 = 0.;
for (k = -k02; k < ng; k += 2) {
kk = Math.abs(k);
i1 = i + (k - 1) / 2;
if (i1 < 0) {
i1 = (-i1 - 1) % period;
if (i1 >= n2)
i1 = period - 1 - i1;
}
if (i1 >= n2) {
i1 = i1 % period;
if (i1 >= n2)
i1 = period - 1 - i1;
}
pix2 = pix2 + g[kk] * vin[i1 + n2];
}
vout[j] = (float) (pix1 + pix2);
j = j + 1;
pix1 = 0.;
for (k = -k01; k < nh; k += 2) {
kk = Math.abs(k);
i1 = i + (k + 1) / 2;
if (i1 < 0) {
i1 = (-i1) % period;
if (i1 >= n2)
i1 = period - i1;
}
if (i1 >= n2) {
i1 = (i1) % period;
if (i1 >= n2)
i1 = period - i1;
}
pix1 = pix1 + h[kk] * vin[i1];
}
pix2 = g[0] * vin[i + n2];
for (k = 2; k < ng; k += 2) {
i1 = i - (k / 2);
if (i1 < 0) {
i1 = (-i1 - 1) % period;
if (i1 >= n2)
i1 = period - 1 - i1;
}
i2 = i + (k / 2);
if (i2 > n2 - 1) {
i2 = i2 % period;
if (i2 >= n2)
i2 = period - 1 - i2;
}
pix2 = pix2 + g[k] * (vin[i1 + n2] + vin[i2 + n2]);
}
vout[j] = (float) (pix1 + pix2);
}
}
}

Event Timeline