Page MenuHomec4science

No OneTemporary

File Metadata

Created
Mon, Nov 25, 17:16
diff --git a/DeconvolutionLab2/build.xml b/DeconvolutionLab2/build.xml
index 0cfdb6a..1f5e7ea 100644
--- a/DeconvolutionLab2/build.xml
+++ b/DeconvolutionLab2/build.xml
@@ -1,48 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="DeconvolutionLab2" default="build" basedir=".">
<property name="imagej" location="${user.home}/Desktop/ImageJ/plugins" />
- <property name="fiji" location="${user.home}/Desktop/Fiji-deconv.app/plugins" />
+ <property name="fiji" location="${user.home}/Desktop/Fiji.app/plugins" />
<property name="matlab" location="/Applications/MATLAB_R2014b.app/java/" />
<property name="doc" location="${user.home}/Desktop/doc/" />
<property name="javadoc.header" value="&lt;h3&gt;DeconvolutionLab2&lt;/h3&gt;&#09;v1.0" />
<property name="javadoc.footer" value="&lt;h4&gt;DeconvolutionLab2&lt;/h4&gt;&#09;&lt;script&gt; var tStamp=new Date(); document.write(tStamp.toUTCString()); &lt;/script&gt;" />
<property name="javadoc.bottom" value='Copyright &amp;copy; &lt;script&gt; var currYear=new Date(); document.write(currYear.getFullYear()); &lt;/script&gt;, Biomedical Imaging Group, EPFL, Lausanne, Switzerland. All rights reserved.' />
<target name="build">
<mkdir dir="${doc}" />
<mkdir dir="bin" />
<copy todir="bin"><fileset dir="ij"></fileset></copy>
<copy file="plugins.config" toDir="bin" />
<zip destfile="../DeconvolutionLab2-src.zip" basedir="src" />
<zip destfile="../DeconvolutionLab2-cls.zip" basedir="bin" />
<jar destfile="../DeconvolutionLab_2.jar" basedir="bin">
<manifest>
<attribute name="Main-Class" value="DeconvolutionLab2" />
<attribute name="Class-Path" value="ij.jar jtransforms.jar" />
</manifest>
</jar>
<copy toDir="${fiji}" file="../DeconvolutionLab_2.jar" />
<copy toDir="${matlab}" file="../DeconvolutionLab_2.jar" />
<copy toDir="${imagej}" file="../DeconvolutionLab_2.jar" />
<javadoc destdir="${doc}" author="true" version="true" overview="${basedir}/overview.html" windowtitle="DeconvolutionLab2">
<fileset dir="src">
<include name="**/*.java" />
<exclude name="**/fft/**" />
<exclude name="**/jfftw/**" />
</fileset>
<header>
<![CDATA[${javadoc.header}]]>
</header>
<footer>
<![CDATA[${javadoc.footer}]]>
</footer>
<bottom>
<![CDATA[${javadoc.bottom}]]>
</bottom>
</javadoc>
</target>
</project>
diff --git a/DeconvolutionLab2/plugins.config b/DeconvolutionLab2/plugins.config
index d92448e..2831334 100644
--- a/DeconvolutionLab2/plugins.config
+++ b/DeconvolutionLab2/plugins.config
@@ -1,14 +1,15 @@
# Name: DeconvolutionLab 2
# Daniel Sage
# Biomedical Imaging Group
# Ecole Polytechnique Federale de Lausanne (EPFL), Lausanne, Switzerland
# Date: 11 July 2016
Plugins>DeconvolutionLab2, "DeconvolutionLab2 Lab", DeconvolutionLab2_Lab
Plugins>DeconvolutionLab2, "DeconvolutionLab2 Launch", DeconvolutionLab2_Launch
Plugins>DeconvolutionLab2, "DeconvolutionLab2 Run", DeconvolutionLab2_Run
Plugins>DeconvolutionLab2, "DeconvolutionLab2 FFT", DeconvolutionLab2_FFT
Plugins>DeconvolutionLab2, "DeconvolutionLab2 Help", DeconvolutionLab2_Help
-Plugins>DeconvolutionLab2, "Test_Airy", Test_Airy
\ No newline at end of file
+
+
diff --git a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Resolution.java b/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Resolution.java
index 6ad69c2..38380e4 100644
--- a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Resolution.java
+++ b/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Resolution.java
@@ -1,143 +1,198 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package course;
import java.io.File;
import javax.swing.filechooser.FileSystemView;
import deconvolution.algorithm.Convolution;
-import deconvolution.algorithm.LandweberPositivity;
import deconvolution.algorithm.NaiveInverseFilter;
-import deconvolution.algorithm.RichardsonLucyTV;
import deconvolution.algorithm.Simulation;
+import deconvolution.algorithm.TikhonovRegularizedInverseFilter;
import deconvolutionlab.Lab;
import deconvolutionlab.monitor.Monitors;
import deconvolutionlab.output.ShowOrtho;
+import ij.gui.Plot;
import ij.plugin.PlugIn;
+import signal.Assessment;
import signal.RealSignal;
-import signal.factory.Airy;
+import signal.factory.BesselJ0;
import signal.factory.CubeSphericalBeads;
public class DeconvolutionLab2_Course_Resolution implements PlugIn {
private String desktop = FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath() + File.separator + "Desktop";
private String root = desktop + File.separator + "Deconvolution" + File.separator;
- private String res = root + "results" + File.separator + "resolution" + File.separator;
+ private String path = root + "results" + File.separator + "resolution" + File.separator;
public DeconvolutionLab2_Course_Resolution() {
Monitors monitors = Monitors.createDefaultMonitor();
- new File(res).mkdir();
- System.setProperty("user.dir", res);
+ new File(path).mkdir();
+ System.setProperty("user.dir", path);
- new File(res + "RIF").mkdir();
- new File(res + "LW").mkdir();
- new File(res + "LW+").mkdir();
- new File(res + "RL").mkdir();
+ new File(path + "RIF").mkdir();
+ new File(path + "LW").mkdir();
+ new File(path + "LW+").mkdir();
+ new File(path + "RL").mkdir();
int nx = 128;
- int ny = 120;
- int nz = 122;
- int spacing = 12;
- int border = 6;
+ int ny = 128;
+ int nz = 128;
+ int spacing = 11;
+ int b = 11;
- RealSignal x = new CubeSphericalBeads(4, 0.1, spacing, border).intensity(100).generate(nx, ny, nz);
- //RealSignal x = new Sphere(30, 1).generate(nx, ny, nz);
- //RealSignal x = new Constant().intensity(0, 255).generate(nx, ny, nz);
- //Lab.show(monitors, x, "reference");
- //Lab.showOrthoview(x);
- //Lab.showMIP(x);
- Lab.showOrthoview(monitors, x, "Ref", border, border, border);
+ RealSignal x = new CubeSphericalBeads(4, 0.1, spacing, b).intensity(100).generate(nx, ny, nz);
+ Lab.save(monitors, x.createOrthoview(b, b, b), path + "ref.tif");
- //RealSignal h = new Gaussian(3, 3, 1).generate(nx, ny, nz);
- RealSignal h = new Airy(100, 50, 0.5, 0.1).generate(nx, ny, nz);
+ RealSignal h = new BesselJ0(3, 6, 0.01, 0.01).generate(nx, ny, nz);
+ Lab.save(monitors, h, path + "psf.tif");
Lab.show(monitors, h, "psf");
- //Lab.showOrthoview(h);
- //Lab.showMIP(h);
+ Lab.showOrthoview(h);
+ Lab.showMIP(h);
+ Lab.showPlanar(h);
Convolution convolution = new Convolution();
convolution.disableDisplayFinal().disableSystem();
convolution.addOutput(new ShowOrtho("convolution"));
RealSignal y = convolution.run(x, h);
-
- Simulation simulation = new Simulation(0, 0.25, 0);
+ Lab.save(monitors, y.createOrthoview(b, b, b), path + "conv.tif");
+ Lab.showPlanar(y);
+
+ Simulation simulation = new Simulation(0, 1, 1);
simulation.disableDisplayFinal().disableSystem();
- simulation.addOutput(new ShowOrtho("simualtion").origin(border, border, border));
+ simulation.addOutput(new ShowOrtho("simualtion").origin(b, b, b));
RealSignal ys = simulation.run(x, h);
- Lab.showOrthoview(monitors, ys, "Simulation", border, border, border);
- //Lab.show(y);
+ Lab.save(monitors, ys.createOrthoview(b, b, b), path + "simu.tif");
+ Lab.showPlanar(ys);
+ Lab.showMIP(ys);
+ Lab.showPlanar(ys);
+
+
+ plotProfile(x, "refY", b, 0, b, b, ny-1, b);
+ plotProfile(x, "refX", 0, b, b, nx-1, b, b);
+ plotProfile(x, "refZ", b, b, 0, b, b, nz-1);
+ plotProfile(y, "convY", b, 0, b, b, ny-1, b);
+ plotProfile(y, "convX", 0, b, b, nx-1, b, b);
+ plotProfile(y, "convZ", b, b, 0, b, b, nz-1);
+ plotProfile(ys, "simuY", b, 0, b, b, ny-1, b);
+ plotProfile(ys, "simuX", 0, b, b, nx-1, b, b);
+ plotProfile(ys, "simuZ", b, b, 0, b, b, nz-1);
+
NaiveInverseFilter nif = new NaiveInverseFilter();
- nif.addOutput(new ShowOrtho("nif").origin(border, border, border));
- nif.disableDisplayFinal().disableSystem().setReference(res + "ref.tif").setStats();
- nif.run(ys, h);
- //Lab.show(nifo);
-/*
- TikhonovRegularizedInverseFilter rif = new TikhonovRegularizedInverseFilter(1e-8);
- rif.disableDisplayFinal().disableSystem().setReference(res + "ref.tif");
- rif.addOutput(new ShowOrtho("trif").origin(border, border, border));
- for(int i=-8; i<=0; i+=1) {
- rif.setParameters(new double[] {Math.pow(10, i)});
- RealSignal t = rif.run(ys, h);
- System.out.println("" + i + " " +Assessment.rmse(t, x));
- }
-*/
+ nif.addOutput(new ShowOrtho("nif").origin(b, b, b));
+ nif.disableDisplayFinal().disableSystem().setReference(path + "ref.tif").setStats();
+ RealSignal nic = nif.run(y, h);
+ Lab.save(monitors, nic.createOrthoview(b, b, b), path + "nif_conv.tif");
+ Lab.showPlanar(monitors, nic, nic + "NIF_CONV //"+Assessment.rmse(nic, x));
+ RealSignal nis = nif.run(ys, h);
+ Lab.save(monitors, nis.createOrthoview(b, b, b), path + "nif_simu.tif");
+ Lab.showPlanar(monitors, nis, nis + "NIF_SIMU //"+Assessment.rmse(nis, x));
+ plotProfile(nic, "nicY", b, 0, b, b, ny-1, b);
+ plotProfile(nic, "nicX", 0, b, b, nx-1, b, b);
+ plotProfile(nic, "nicZ", b, b, 0, b, b, nz-1);
+
+ plotProfile(nis, "nisY", b, 0, b, b, ny-1, b);
+ plotProfile(nis, "nisX", 0, b, b, nx-1, b, b);
+ plotProfile(nis, "nisZ", b, b, 0, b, b, nz-1);
+
+ TikhonovRegularizedInverseFilter trif = new TikhonovRegularizedInverseFilter(1e-3);
+ trif.disableDisplayFinal().disableSystem().setReference(path + "ref.tif");
+ for(int i=-5; i<-1; i++) {
+ trif.setParameters(new double[] {Math.pow(10, i)});
+ RealSignal t = trif.run(ys, h);
+ Lab.save(monitors, t.createOrthoview(b, b, b), path + "trif" + i + ".tif");
+ Lab.showPlanar(monitors, t, "TRIF" + i + " //"+Assessment.rmse(t, x));
+ Lab.showOrthoview(monitors, t, "TRIF"+ i + " //"+Assessment.rmse(t, x), b, b, b);
+ plotProfile(t, "tirfY" + i, b, 0, b, b, ny-1, b);
+ plotProfile(t, "tirfX" + i, 0, b, b, nx-1, b, b);
+ plotProfile(t, "tirfZ" + i, b, b, 0, b, b, nz-1);
+ }
+ //plotProfile(t, "trifY", b, 0, b, b, ny-1, b);
+ //plotProfile(t, "trifX", 0, b, b, nx-1, b, b);
+ //plotProfile(t, "trifZ", b, b, 0, b, b, nz-1);
+ /*
RichardsonLucyTV rl = new RichardsonLucyTV(100, 0.00001);
rl.disableDisplayFinal().disableSystem().setReference(res + "ref.tif").setStats();
- rl.addOutput(new ShowOrtho("rltv").frequency(1).origin(border, border, border));
+ rl.addOutput(new ShowOrtho("rltv").frequency(1).origin(b, b, b));
RealSignal fli = rl.run(ys, h);
//RLTV 0.0001 100 Signals: 167.2 Mb 14.6724 0.9261 n/a
//RL 100 Signals: 138.6 Mb 14.6688 0.9224 n/a
//RLTV 0.001 100 Signals: 167.2 Mb 14.6979 0.9515 n/a
//LW+ 5000 Signals: 311.6 Mb 15.4276 1.6812 n/a
-
+/*
LandweberPositivity lw = new LandweberPositivity(100, 1.95);
lw.disableDisplayFinal().disableSystem().setReference(res + "ref.tif").setStats();
lw.addOutput(new ShowOrtho("lw").frequency(20).origin(border, border, border));
RealSignal lwi = lw.run(ys, h);
Lab.show(lwi);
+ */
+ }
+
+ private static void plotProfile(RealSignal signal, String name, int x1, int y1, int z1, int x2, int y2, int z2) {
+ double dx = x2 - x1;
+ double dy = y2 - y1;
+ double dz = z2 - z1;
+ double len = Math.sqrt(dx*dx + dy*dy + dz*dz);
+ int n = (int)Math.round(len * 2);
+ double ds = len / n;
+ dx = (double)(x2 - x1) / n;
+ dy = (double)(y2 - y1) / n;
+ dz = (double)(z2 - z1) / n;
+ double value[] = new double[n];
+ double dist[] = new double[n];
+ for(int s=0; s<n; s++) {
+ double x = x1 + s*dx;
+ double y = y1 + s*dy;
+ double z = z1 + s*dz;
+ dist[s] = s*ds;
+ value[s] = signal.getInterpolatedPixel(x, y, z);
+ }
+ Plot plot = new Plot(name, "distance", "intensity", dist, value);
+ plot.show();
}
public static void main(String arg[]) {
new DeconvolutionLab2_Course_Resolution();
}
@Override
public void run(String arg) {
new DeconvolutionLab2_Course_Resolution();
}
}
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/signal/RealSignal.java b/DeconvolutionLab2/src/signal/RealSignal.java
index 84b444a..64657a1 100644
--- a/DeconvolutionLab2/src/signal/RealSignal.java
+++ b/DeconvolutionLab2/src/signal/RealSignal.java
@@ -1,732 +1,790 @@
/*
* 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.awt.image.BufferedImage;
import deconvolutionlab.monitor.Monitors;
public class RealSignal extends Signal implements SignalListener {
private BufferedImage preview;
public RealSignal(String name, int nx, int ny, int nz) {
super(name, nx, ny, nz);
this.data = new float[nz][];
int step = Math.max(1, nz / SignalCollector.NOTIFICATION_RATE);
notify(name, 0);
for (int k = 0; k < nz; k++) {
data[k] = new float[nx * ny];
if (k % step == 0)
notify(name, k * 100.0 / nz);
}
notify(name, 100);
SignalCollector.alloc(this);//name, nx, ny, ny, false);
}
@Override
public void notify(String name, double progress) {
SignalCollector.setProgress(progress);
}
public void copy(RealSignal source) {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] = source.data[k][i];
}
}
public void setSignal(RealSignal signal) {
int sx = signal.nx;
int mx = Math.min(nx, signal.nx);
int my = Math.min(ny, signal.ny);
int mz = Math.min(nz, signal.nz);
for (int i = 0; i < mx; i++)
for (int j = 0; j < my; j++)
for (int k = 0; k < mz; k++)
data[k][i + nx * j] = signal.data[k][i + sx * j];
}
public void getSignal(RealSignal signal) {
int sx = signal.nx;
int mx = Math.min(nx, signal.nx);
int my = Math.min(ny, signal.ny);
int mz = Math.min(nz, signal.nz);
for (int i = 0; i < mx; i++)
for (int j = 0; j < my; j++)
for (int k = 0; k < mz; k++)
signal.data[k][i + sx * j] = data[k][i + nx * j];
}
/**
* Applies a soft threshold (in-place processing)
*
* @param inferiorLimit
* @param superiorLimit
* @return the instance of the calling object
*/
public RealSignal thresholdSoft(float inferiorLimit, float superiorLimit) {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
if (data[k][i] <= inferiorLimit)
data[k][i] += inferiorLimit;
else if (data[k][i] >= superiorLimit)
data[k][i] -= superiorLimit;
else
data[k][i] = 0f;
}
return this;
}
/**
* Multiplies by a signal pixelwise (in-place processing)
*
* @param factor
* @return the instance of the calling object
*/
public RealSignal times(RealSignal factor) {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] *= factor.data[k][i];
}
return this;
}
/**
* Multiplies by a scalar factor (in-place processing)
*
* @param factor
* @return the instance of the calling object
*/
public RealSignal times(float factor) {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] *= factor;
}
return this;
}
/**
* Adds a signal pixelwise (in-place processing)
*
* @param factor
* @return the instance of the calling object
*/
public RealSignal plus(RealSignal factor) {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] += factor.data[k][i];
}
return this;
}
/**
* Subtracts by a signal pixelwise (in-place processing)
*
* @param factor
* @return the instance of the calling object
*/
public RealSignal minus(RealSignal factor) {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] -= factor.data[k][i];
}
return this;
}
/**
* Adds a scalar term (in-place processing)
*
* @param term
* @return the instance of the calling object
*/
public RealSignal plus(float term) {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] += term;
}
return this;
}
/**
* Subtracts a scalar term (in-place processing)
*
* @param term
* @return the instance of the calling object
*/
public RealSignal minus(float term) {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] -= term;
}
return this;
}
/**
* Takes the maximum (in-place processing)
*
* @param factor
* @return the instance of the calling object
*/
public RealSignal max(RealSignal factor) {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] = Math.max(data[k][i], factor.data[k][i]);
}
return this;
}
/**
* Takes the minimum (in-place processing)
*
* @param factor
* @return the instance of the calling object
*/
public RealSignal min(RealSignal factor) {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] = Math.min(data[k][i], factor.data[k][i]);
}
return this;
}
public double[][][] get3DArrayAsDouble() {
double[][][] ar = new double[nx][ny][nz];
for (int k = 0; k < nz; k++) {
float[] s = data[k];
for (int i = 0; i < nx; i++)
for (int j = 0; j < ny; j++) {
ar[i][j][k] = s[i + j * nx];
}
}
return ar;
}
public void set3DArrayAsDouble(double[][][] real) {
for (int k = 0; k < nz; k++) {
float[] s = data[k];
for (int i = 0; i < nx; i++)
for (int j = 0; j < ny; j++) {
s[i + j * nx] = (float) real[i][j][k];
}
}
}
public RealSignal duplicate() {
RealSignal out = new RealSignal("copy(" + name + ")", nx, ny, nz);
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
System.arraycopy(data[k], 0, out.data[k], 0, nxy);
return out;
}
public float getEnergy() {
int nxy = nx * ny;
float energy = 0.f;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++)
energy += data[k][i];
return energy;
}
public float[] getStats() {
int nxy = nx * ny;
float min = Float.MAX_VALUE;
float max = -Float.MAX_VALUE;
double norm1 = 0.0;
double norm2 = 0.0;
double mean = 0.0;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
float v = data[k][i];
max = Math.max(max, v);
min = Math.min(min, v);
mean += v;
norm1 += (v > 0 ? v : -v);
norm2 += v * v;
}
mean = mean / (nz * nxy);
norm1 = norm1 / (nz * nxy);
norm2 = Math.sqrt(norm2 / (nz * nxy));
double stdev = 0.0;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
stdev += (data[k][i] - mean) * (data[k][i] - mean);
}
stdev = Math.sqrt(stdev / (nz * nxy));
return new float[] { (float) mean, min, max, (float) stdev, (float) norm1, (float) norm2 };
}
public float[] getExtrema() {
int nxy = nx * ny;
float min = Float.MAX_VALUE;
float max = -Float.MAX_VALUE;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
float v = data[k][i];
max = Math.max(max, v);
min = Math.min(min, v);
}
return new float[] { min, max };
}
public RealSignal normalize(double to) {
if (to == 0)
return this;
int nxy = nx * ny;
float sum = 0f;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++)
sum += data[k][i];
if (sum != 0f) {
double r = to / sum;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++)
data[k][i] *= r;
}
return this;
}
public void setSlice(int z, RealSignal slice) {
int mx = slice.nx;
int my = slice.ny;
for (int j = 0; j < Math.min(ny, my); j++)
for (int i = 0; i < Math.min(nx, mx); i++)
data[z][i + nx * j] = slice.data[0][i + mx * j];
}
public RealSignal getSlice(int z) {
RealSignal slice = new RealSignal(name + "_z=" + z, nx, ny, 1);
for (int j = 0; j < nx * ny; j++)
slice.data[0][j] = data[z][j];
return slice;
}
public void multiply(double factor) {
for (int k = 0; k < nz; k++)
for (int i = 0; i < nx * ny; i++)
data[k][i] *= factor;
}
public float[] getInterleaveXYZAtReal() {
float[] interleave = new float[2 * nz * nx * ny];
for (int k = 0; k < nz; k++)
for (int j = 0; j < ny; j++)
for (int i = 0; i < nx; i++)
interleave[2 * (k * nx * ny + j * nx + i)] = data[k][i + j * nx];
return interleave;
}
public void setInterleaveXYZAtReal(float[] interleave) {
for (int k = 0; k < nz; k++)
for (int j = 0; j < ny; j++)
for (int i = 0; i < nx; i++)
data[k][i + nx * j] = interleave[(k * nx * ny + j * nx + i) * 2];
}
public float[] getInterleaveXYAtReal(int k) {
float real[] = new float[nx * ny * 2];
for (int i = 0; i < nx; i++)
for (int j = 0; j < ny; j++) {
int index = i + j * nx;
real[2 * index] = data[k][index];
}
return real;
}
public void setInterleaveXYAtReal(int k, float real[]) {
for (int i = 0; i < nx; i++)
for (int j = 0; j < ny; j++) {
int index = i + j * nx;
data[k][index] = real[2 * index];
}
}
public float[] getXYZ() {
int nxy = nx * ny;
float[] d = new float[nz * nx * ny];
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++)
d[k * nxy + i] = data[k][i];
return d;
}
public void setXYZ(float[] data) {
if (nx * ny * nz != data.length)
return;
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++)
this.data[k][i] = data[k * nxy + i];
}
public float[] getXY(int k) {
return data[k];
}
public void setXY(int k, float slice[]) {
data[k] = slice;
}
public float[] getX(int j, int k) {
float line[] = new float[nx];
for (int i = 0; i < nx; i++)
line[i] = data[k][i + j * nx];
return line;
}
public float[] getZ(int i, int j) {
float line[] = new float[nz];
int index = i + j * nx;
for (int k = 0; k < nz; k++)
line[k] = data[k][index];
return line;
}
public float[] getY(int i, int k) {
float line[] = new float[ny];
for (int j = 0; j < ny; j++)
line[j] = data[k][i + j * nx];
return line;
}
public void setX(int j, int k, float line[]) {
for (int i = 0; i < nx; i++)
data[k][i + j * nx] = line[i];
}
public void setY(int i, int k, float line[]) {
for (int j = 0; j < ny; j++)
data[k][i + j * nx] = line[j];
}
public void setZ(int i, int j, float line[]) {
int index = i + j * nx;
for (int k = 0; k < nz; k++)
data[k][index] = line[k];
}
public void clip(float min, float max) {
for (int k = 0; k < nz; k++)
for (int j = 0; j < ny * nx; j++)
if (data[k][j] < min)
data[k][j] = min;
else if (data[k][j] > max)
data[k][j] = max;
}
public void fill(float constant) {
for (int k = 0; k < nz; k++)
for (int j = 0; j < ny * nx; j++)
data[k][j] = constant;
}
+ /**
+ * Get a interpolated pixel value at specific position without specific
+ * boundary conditions.
+ *
+ * If the positions is not on the pixel grid, the method return a
+ * interpolated value of the pixel (linear interpolation). If the positions
+ * is outside of this signal, the method return 0.0.
+ *
+ * @param x
+ * position in the X axis
+ * @param y
+ * position in the Y axis
+ * @param z
+ * position in the Z axis
+ * @return an interpolated value
+ */
+ public float getInterpolatedPixel(double x, double y, double z) {
+ if (x > nx - 1)
+ return 0.0f;
+ if (y > ny - 1)
+ return 0.0f;
+ if (z > nz - 1)
+ return 0.0f;
+ if (x < 0)
+ return 0.0f;
+ if (y < 0)
+ return 0.0f;
+ if (z < 0)
+ return 0.0f;
+ int i = (x >= 0.0 ? ((int) x) : ((int) x - 1));
+ int j = (y >= 0.0 ? ((int) y) : ((int) y - 1));
+ int k = (z >= 0.0 ? ((int) z) : ((int) z - 1));
+ boolean fi = (i == nx - 1);
+ boolean fj = (j == ny - 1);
+ boolean fk = (k == nz - 1);
+ int index = i + j * nx;
+ try {
+ double v3_000 = data[k][index];
+ double v3_100 = fi ? v3_000 : data[k][index + 1];
+ double v3_010 = fj ? v3_000 : data[k][index + nx];
+ double v3_110 = fi ? (fj ? v3_000 : v3_010) : data[k][index + 1 + nx];
+ double v3_001 = fk ? v3_000 : data[k + 1][index];
+ double v3_011 = fk ? (fj ? v3_000 : v3_010) : data[k + 1][index + 1];
+ double v3_101 = fk ? (fi ? v3_000 : v3_100) : data[k + 1][index + nx];
+ double v3_111 = fk ? (fj ? (fi ? v3_000 : v3_100) : v3_110) : data[k + 1][index + 1 + nx];
+ double dx3 = x - (double) i;
+ double dy3 = y - (double) j;
+ double dz3 = z - (double) k;
+ double z1 = (dx3 * (v3_110 * dy3 - v3_100 * (dy3 - 1.0)) - (dx3 - 1.0) * (v3_010 * dy3 - v3_000 * (dy3 - 1.0)));
+ double z2 = (dx3 * (v3_111 * dy3 - v3_101 * (dy3 - 1.0)) - (dx3 - 1.0) * (v3_011 * dy3 - v3_001 * (dy3 - 1.0)));
+ return (float)(z2 * dz3 - z1 * (dz3 - 1.0));
+ }
+ catch(Exception ex) {
+ return 0f;
+ }
+ }
+
public RealSignal changeSizeAs(RealSignal model) {
return size(model.nx, model.ny, model.nz);
}
public RealSignal size(int mx, int my, int mz) {
String n = "resize(" + name + ")";
int ox = (mx - nx) / 2;
int oy = (my - ny) / 2;
int oz = (mz - nz) / 2;
RealSignal signal = new RealSignal(n, mx, my, mz);
int vx = Math.min(nx, mx);
int vy = Math.min(ny, my);
int vz = Math.min(nz, mz);
for (int k = 0; k < vz; k++)
for (int j = 0; j < vy; j++)
for (int i = 0; i < vx; i++) {
int pi = ox >= 0 ? i + ox : i;
int qi = ox >= 0 ? i : i - ox;
int pj = oy >= 0 ? j + oy : j;
int qj = oy >= 0 ? j : j - oy;
int pk = oz >= 0 ? k + oz : k;
int qk = oz >= 0 ? k : k - oz;
signal.data[pk][pi + pj * mx] = data[qk][qi + qj * nx];
}
return signal;
}
public RealSignal createOrthoview() {
return createOrthoview(nx / 2, ny / 2, nz / 2);
}
public RealSignal createOrthoview(int hx, int hy, int hz) {
String n = "ortho(" + name + ")";
int vx = nx + nz;
int vy = ny + nz;
RealSignal view = new RealSignal(n, vx, vy, 1);
hx = Math.min(nx - 1, Math.max(0, hx));
hy = Math.min(ny - 1, Math.max(0, hy));
hz = Math.min(nz - 1, Math.max(0, hz));
for (int x = 0; x < nx; x++)
for (int y = 0; y < ny; y++)
view.data[0][x + vx * y] = data[hz][x + nx * y];
for (int z = 0; z < nz; z++)
for (int y = 0; y < ny; y++)
view.data[0][nx + z + vx * y] = data[z][hx + nx * y];
for (int z = 0; z < nz; z++)
for (int x = 0; x < nx; x++)
view.data[0][x + vx * (ny + z)] = data[z][x + nx * hy];
return view;
}
public RealSignal createFigure(int hx, int hy, int hz) {
String n = "figure(" + name + ")";
int vx = nx + nz + 4;
int vy = ny + 2;
float max = this.getExtrema()[1];
RealSignal view = new RealSignal(n, vx, vy, 1);
for (int i = 0; i < vx * vy; i++)
view.data[0][i] = max;
hx = Math.min(nx - 1, Math.max(0, hx));
hy = Math.min(ny - 1, Math.max(0, hy));
hz = Math.min(nz - 1, Math.max(0, hz));
for (int x = 0; x < nx; x++)
for (int y = 0; y < ny; y++)
view.data[0][x + 1 + vx * (y + 1)] = data[hz][x + nx * y];
for (int z = 0; z < nz; z++)
for (int y = 0; y < ny; y++)
view.data[0][nx + 3 + z + vx * (y + 1)] = data[z][hx + nx * y];
return view;
}
public RealSignal createMIP() {
String n = "mip(" + name + ")";
int vx = nx + nz;
int vy = ny + nz;
RealSignal view = new RealSignal(n, vx, vy, 1);
for (int x = 0; x < nx; x++)
for (int y = 0; y < ny; y++)
for (int k = 0; k < nz; k++) {
int index = x + vx * y;
view.data[0][index] = Math.max(view.data[0][index], data[k][x + nx * y]);
}
for (int z = 0; z < nz; z++)
for (int y = 0; y < ny; y++)
for (int x = 0; x < nx; x++) {
int index = nx + z + vx * y;
view.data[0][index] = Math.max(view.data[0][index], data[z][x + nx * y]);
}
for (int z = 0; z < nz; z++)
for (int x = 0; x < nx; x++)
for (int y = 0; y < ny; y++) {
int index = x + vx * (ny + z);
view.data[0][index] = Math.max(view.data[0][index], data[z][x + nx * y]);
}
return view;
}
public RealSignal createPlanar() {
String n = "planar(" + name + ")";
int nr = (int) Math.sqrt(nz);
int nc = (int) Math.ceil(nz / nr) + 1;
int w = nx * nr;
int h = ny * nc;
RealSignal view = new RealSignal(n, w, h, 1);
for (int k = 0; k < nz; k++) {
int col = k % nr;
int row = k / nr;
int offx = col * nx;
int offy = row * ny;
for (int x = 0; x < nx; x++)
for (int y = 0; y < ny; y++)
view.data[0][x + offx + w * (y + offy)] = data[k][x + nx * y];
}
return view;
}
+
public RealSignal circular() {
for (int i = 0; i < nx; i++)
for (int j = 0; j < ny; j++)
setZ(i, j, rotate(getZ(i, j)));
for (int i = 0; i < nx; i++)
for (int k = 0; k < nz; k++)
setY(i, k, rotate(getY(i, k)));
for (int j = 0; j < ny; j++)
for (int k = 0; k < nz; k++)
setX(j, k, rotate(getX(j, k)));
return this;
}
public RealSignal rescale(Monitors monitors) {
new Constraint(monitors).rescaled(this, 0, 255);
return this;
}
public float[] rotate(float[] buffer) {
int len = buffer.length;
if (len <= 1)
return buffer;
int count = 0;
int offset = 0;
int start = len / 2;
while (count < len) {
int index = offset;
float tmp = buffer[index];
int index2 = (start + index) % len;
while (index2 != offset) {
buffer[index] = buffer[index2];
count++;
index = index2;
index2 = (start + index) % len;
}
buffer[index] = tmp;
count++;
offset++;
}
return buffer;
}
@Override
public String toString() {
return "Real Signal [" + nx + ", " + ny + ", " + nz + "]";
}
public BufferedImage preview() {
if (preview != null)
return preview;
int nxy = nx*ny;
float[] pixels = new float[nx*ny];
for (int i = 0; i < nxy; i++)
for (int k = 0; k < nz; k++) {
pixels[i] = Math.max(pixels[i], data[k][i]);
}
float max = -Float.MAX_VALUE;
float min = Float.MAX_VALUE;
for (int i = 0; i < nxy; i++) {
if (pixels[i] > max)
max = pixels[i];
if (pixels[i] < min)
min = pixels[i];
}
float a = 255f / Math.max(max-min, (float)Operations.epsilon);
preview = new BufferedImage(nx, ny, BufferedImage.TYPE_INT_ARGB);
int alpha = (255 << 24);
for (int i = 0; i < nx; i++)
for (int j = 0; j < ny; j++) {
int v = (int)(a*(pixels[i+j*nx] - min));
preview.setRGB(i, j, alpha | (v << 16) | (v << 8) | v);
}
return preview;
}
public RealSignal log10() {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] = (float)Math.log10(data[k][i]);
}
return this;
}
public RealSignal log() {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] = (float)Math.log(data[k][i]);
}
return this;
}
public RealSignal exp() {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] = (float)Math.exp(data[k][i]);
}
return this;
}
public RealSignal abs() {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] = (float)Math.abs(data[k][i]);
}
return this;
}
public RealSignal sqrt() {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] = (float)Math.sqrt(data[k][i]);
}
return this;
}
public RealSignal sqr() {
int nxy = nx * ny;
for (int k = 0; k < nz; k++)
for (int i = 0; i < nxy; i++) {
data[k][i] = (float)(data[k][i]*data[k][i]);
}
return this;
}
public RealSignal rescale(double min, double max) {
int nxy = nx * ny;
float minf = (float)min;
float stats[] = getStats();
float a = ((float)max-minf) / (stats[2] - stats[1]);
for(int k=0; k<nz; k++)
for(int i=0; i<nxy; i++) {
data[k][i] = a*(data[k][i] - stats[1]) + minf;
}
return this;
}
}
diff --git a/DeconvolutionLab2/src/signal/factory/Airy.java b/DeconvolutionLab2/src/signal/factory/Airy.java
index 4eef21a..cc8b54e 100644
--- a/DeconvolutionLab2/src/signal/factory/Airy.java
+++ b/DeconvolutionLab2/src/signal/factory/Airy.java
@@ -1,96 +1,96 @@
/*
* 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 bilib.tools.Bessel;
import signal.RealSignal;
public class Airy extends SignalFactory {
private double pupil = 5;
private double lambda = 1;
private double distanceAxial = 0.5;
private double attenuationFactor = 3;
public Airy(double pupil, double lambda, double distanceAxial, double attenuationFactor) {
super(new double[] {pupil, lambda, distanceAxial, attenuationFactor});
setParameters(new double[] {pupil, lambda, distanceAxial, attenuationFactor});
}
@Override
public String getName() {
return "Airy";
}
@Override
public String[] getParametersName() {
return new String[] { "Pupil (normalized unit)", "Wavelength (normalized unit)", "Axial distance (normalized unit)", "Attenuation Factor" };
}
@Override
public void setParameters(double[] parameters) {
if (parameters.length >= 1)
this.pupil = parameters[0];
if (parameters.length >= 2)
this.lambda = parameters[1];
if (parameters.length >= 3)
this.distanceAxial = parameters[2];
if (parameters.length >= 4)
this.attenuationFactor = parameters[3];
}
@Override
public double[] getParameters() {
return new double[] {pupil, lambda, distanceAxial, attenuationFactor};
}
@Override
public void fill(RealSignal signal) {
int xsize = nx / 2;
int ysize = ny / 2;
double d = Math.max(0.01, distanceAxial);
double diag = Math.sqrt(xsize*xsize + ysize*ysize);
double b = 2.0 * Math.PI * pupil / lambda;
double epsilon = 0.01 / diag;
for(int i=0; i<nx; i++)
for(int j=0; j<ny; j++) {
double r = Math.max(epsilon, Math.sqrt((i-xc)*(i-xc)+(j-yc)*(j-yc)) / diag);
for(int k=0; k<nz; k++) {
- double dz = Math.abs(k-zc)/nz;
+ double dz = 1 - Math.abs(k-zc)/nz;
double z1 = d + dz;
double jc = Bessel.J1(r * b / z1) / r;
- signal.data[k][i+j*nx] = (float)(jc*jc* Math.exp(-dz*attenuationFactor));
+ signal.data[k][i+j*nx] = (float)(jc*jc*Math.exp(-dz*attenuationFactor));
}
}
}
}
diff --git a/DeconvolutionLab2/src/signal/factory/DoubleConeWave.java b/DeconvolutionLab2/src/signal/factory/BesselJ0.java
similarity index 56%
rename from DeconvolutionLab2/src/signal/factory/DoubleConeWave.java
rename to DeconvolutionLab2/src/signal/factory/BesselJ0.java
index 013ae97..7c963d6 100644
--- a/DeconvolutionLab2/src/signal/factory/DoubleConeWave.java
+++ b/DeconvolutionLab2/src/signal/factory/BesselJ0.java
@@ -1,95 +1,99 @@
/*
* 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 bilib.tools.Bessel;
import signal.RealSignal;
-public class DoubleConeWave extends SignalFactory {
+public class BesselJ0 extends SignalFactory {
- private double aperture = 60;
- private double periodTopZ = 5;
- private double periodCenterZ = 15;
- private double attenuation = 10;
+ private double sizeCenter = 2;
+ private double sizeTop = 5;
+ private double attenuationAxial = 0.2;
+ private double attenuationLateral = 0.2;
- public DoubleConeWave(double aperture, double periodTopZ, double periodCenterZ, double attenuation) {
- super(new double[] {aperture, periodTopZ, periodCenterZ, attenuation});
- setParameters(new double[] {aperture, periodTopZ, periodCenterZ, attenuation});
+ public BesselJ0(double sizeCenter, double sizeTop, double attenuationLateral, double attenuationAxial) {
+ super(new double[] {sizeCenter, sizeTop, attenuationLateral, attenuationAxial});
+ setParameters(new double[] {sizeCenter, sizeTop, attenuationLateral, attenuationAxial});
}
@Override
public String getName() {
- return "DoubleConeWave";
+ return "BesselJ0";
}
@Override
public String[] getParametersName() {
- return new String[] { "Aperture", "Period TopZ", "Period CenterZ", "Attenuation" };
+ return new String[] { "Size Center", "Size Top/Bottom", "Attenuation Lateral (<1)", "Attenuation Axial (<1)" };
}
@Override
public void setParameters(double[] parameters) {
if (parameters.length >= 1)
- this.aperture = parameters[0];
+ this.sizeCenter = parameters[0];
if (parameters.length >= 2)
- this.periodTopZ = parameters[1];
+ this.sizeTop = parameters[1];
if (parameters.length >= 3)
- this.periodCenterZ = parameters[2];
+ this.attenuationLateral = parameters[2];
if (parameters.length >= 4)
- this.attenuation = parameters[3];
+ this.attenuationAxial = parameters[3];
}
@Override
public double[] getParameters() {
- return new double[] {aperture, periodTopZ, periodCenterZ, attenuation};
+ return new double[] {sizeCenter, sizeTop, attenuationLateral, attenuationAxial};
}
@Override
public void fill(RealSignal signal) {
- double apernorm = (2.0*aperture)/(nx+ny);
- double diag = Math.sqrt(nx*nx+ny*ny+nz*nz);
- double step = (periodCenterZ-periodTopZ)/nz;
+ double axial[] = new double[nz];
+ double s[] = new double[nz];
+ double tauAxial = - Math.log(attenuationAxial);
+ double tauLateral = - Math.log(attenuationLateral);
+ double diag = Math.sqrt(nx*nx+ny*ny) * 0.5;
+ double A = amplitude;
+ for(int k=0; k<nz; k++) {
+ double dz = Math.abs(k-zc)/(0.5*nz);
+ s[k] = 1.0 / (sizeCenter + dz*(sizeTop-sizeCenter));
+ axial[k] = A*Math.exp(-tauAxial*dz);
+ }
for(int i=0; i<nx; i++)
for(int j=0; j<ny; j++) {
double r = Math.sqrt((i-xc)*(i-xc)+(j-yc)*(j-yc));
+ double att = A*Math.exp(-tauLateral*r/diag);
for(int k=0; k<nz; k++) {
- double z = Math.abs(k-zc);
- double p = Math.sqrt(r*r + z*z)/diag;
- double period = Math.max(1, periodCenterZ-step*z);
- double sz = apernorm*z + period*0.25;
- double s = 1.0 / (1.0+Math.exp(-(r+sz))) - 1.0 / (1.0+Math.exp(-(r-sz)));
- double q = Math.cos(2.0*Math.PI*(r-apernorm*z)/period);
- double g = (attenuation*p+1);
- signal.data[k][i+j*nx] = (float)(amplitude * s * q * q / g);
+ double jc = Bessel.J0(r * s[k]);
+ signal.data[k][i+j*nx] = (float)(jc*jc*axial[k]*att);
}
}
}
}
diff --git a/DeconvolutionLab2/src/signal/factory/SignalFactory.java b/DeconvolutionLab2/src/signal/factory/SignalFactory.java
index 31981a0..1ceffc0 100644
--- a/DeconvolutionLab2/src/signal/factory/SignalFactory.java
+++ b/DeconvolutionLab2/src/signal/factory/SignalFactory.java
@@ -1,275 +1,275 @@
/*
* 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 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 DoubleConeWave(60, 5, 15, 10));
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 DoubleConeWave(60, 5, 15, 10));
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;
}
protected RealSignal doInBackground() throws Exception {
fill(signal);
done = true;
return signal;
}
protected void done() {
done = true;
}
}
}

Event Timeline