Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F110902605
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Apr 28, 17:20
Size
52 KB
Mime Type
application/octet-stream
Expires
Wed, Apr 30, 17:20 (2 d)
Engine
blob
Format
Raw Data
Handle
25830701
Attached To
R2075 deconvolution
View Options
diff --git a/DeconvolutionLab2/build.xml b/DeconvolutionLab2/build.xml
index f2d1dd2..e0d0384 100644
--- a/DeconvolutionLab2/build.xml
+++ b/DeconvolutionLab2/build.xml
@@ -1,26 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="DeconvolutionLab2" default="build" basedir=".">
<property name="imagej" location="../../ImageJ/plugins"/>
<property name="fiji" location="../../Fiji-deconv.app/plugins"/>
+ <property name="matlab" location="/Applications/MATLAB_R2014b.app/java/"/>
<target name="build">
<mkdir dir="bin"/>
<copy todir="bin"><fileset dir="ij"></fileset></copy>
<copy file="plugins.config" toDir="bin" />
<zip destfile="../DeconvolutionLab2-src.zip" basedir="src" />
<zip destfile="../DeconvolutionLab2-cls.zip" basedir="bin" />
<jar destfile="../DeconvolutionLab_2.jar" basedir="bin">
<manifest>
<attribute name="Main-Class" value="DeconvolutionLab2"/>
<attribute name="Class-Path" value="ij.jar jtransforms.jar"/>
</manifest>
</jar>
<copy toDir="${fiji}" file="../DeconvolutionLab_2.jar" />
+ <copy toDir="${matlab}" file="../DeconvolutionLab_2.jar" />
<copy toDir="${imagej}" file="../DeconvolutionLab_2.jar" />
</target>
</project>
\ No newline at end of file
diff --git a/DeconvolutionLab2/src/DL2.java b/DeconvolutionLab2/src/DL2.java
new file mode 100644
index 0000000..8e0ee74
--- /dev/null
+++ b/DeconvolutionLab2/src/DL2.java
@@ -0,0 +1,84 @@
+import ij.ImagePlus;
+import ij.WindowManager;
+
+import java.io.File;
+
+import matlab.Converter;
+import deconvolution.Deconvolution;
+import deconvolutionlab.Config;
+import deconvolutionlab.Lab;
+import deconvolutionlab.dialog.LabDialog;
+
+/*
+ * DeconvolutionLab2
+ *
+ * Conditions of use: You are free to use this software for research or
+ * educational purposes. In addition, we expect you to include adequate
+ * citations and acknowledgments whenever you present or publish results that
+ * are based on it.
+ *
+ * Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
+ * Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
+ * R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
+ */
+
+/*
+ * Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
+ *
+ * This file is part of DeconvolutionLab2 (DL2).
+ *
+ * DL2 is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * DL2. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * This class is dedicated to the Matlab interface for DeconvolutionLab2
+ * @author sage
+ *
+ */
+public class DL2 {
+
+ public static void lab() {
+ String config = System.getProperty("user.dir") + File.separator + "DeconvolutionLab2.config";
+ Config.getInstance(config);
+ LabDialog dialog = new LabDialog();
+ dialog.setVisible(true);
+ }
+
+ public static void run(String command) {
+ return;
+ }
+
+ public static void launch(String command) {
+ return;
+ }
+
+ public static Object get(String image) {
+ ImagePlus imp = WindowManager.getCurrentImage();
+ if (imp != null)
+ return Converter.get(imp);
+ return null;
+ }
+
+ public static void run(Object image, Object psf, String algo) {
+ Converter.createImage("input", image, true);
+ Converter.createImage("psf", psf, true);
+ String cmd = " -image platform input -psf platform psf -algorithm " + algo;
+ Deconvolution d = new Deconvolution(cmd);
+ d.deconvolve(false);
+ }
+
+ public static void help() {
+ Lab.help();
+ }
+
+}
diff --git a/DeconvolutionLab2/src/DeconvolutionLab2.java b/DeconvolutionLab2/src/DeconvolutionLab2.java
index 2efede5..e51c8f2 100644
--- a/DeconvolutionLab2/src/DeconvolutionLab2.java
+++ b/DeconvolutionLab2/src/DeconvolutionLab2.java
@@ -1,93 +1,127 @@
+/*
+ * DeconvolutionLab2
+ *
+ * Conditions of use: You are free to use this software for research or
+ * educational purposes. In addition, we expect you to include adequate
+ * citations and acknowledgments whenever you present or publish results that
+ * are based on it.
+ *
+ * Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
+ * Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
+ * R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
+ */
+
+/*
+ * Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
+ *
+ * This file is part of DeconvolutionLab2 (DL2).
+ *
+ * DL2 is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * DL2. If not, see <http://www.gnu.org/licenses/>.
+ */
+
import java.io.File;
+import matlab.Converter;
import deconvolution.Command;
import deconvolution.Deconvolution;
import deconvolutionlab.Config;
import deconvolutionlab.Constants;
import deconvolutionlab.Lab;
import deconvolutionlab.Platform;
import deconvolutionlab.dialog.LabDialog;
import deconvolutionlab.monitor.Monitors;
public class DeconvolutionLab2 {
public static String ack = Constants.name + " " + Constants.version + " " + Constants.copyright;
public static void main(String arg[]) {
System.out.println(ack);
Lab.getInstance(Platform.STANDALONE);
if (arg.length == 0) {
lab(arg);
return;
}
String flag = arg[0].trim().toLowerCase();
if (flag.equalsIgnoreCase("help")) {
help();
return;
}
if (flag.equalsIgnoreCase("lab")) {
lab(arg);
}
if (flag.equalsIgnoreCase("fft")) {
Lab.checkFFT(Monitors.createDefaultMonitor());
}
if (flag.equalsIgnoreCase("run")) {
String cmd = "";
for (int i = 1; i < arg.length; i++)
cmd += arg[i] + " ";
new Deconvolution(cmd).deconvolve(true);
}
if (flag.equalsIgnoreCase("launch")) {
String cmd = "";
for (int i = 1; i < arg.length; i++)
cmd += arg[i] + " ";
new Deconvolution(cmd).launch("", true);
}
}
private static void lab(String arg[]) {
String config = System.getProperty("user.dir") + File.separator + "DeconvolutionLab2.config";
if (arg.length >= 2) {
String filename = arg[1].trim();
File file = new File(filename);
if (file.exists())
if (file.isFile())
if (file.canRead())
config = filename;
}
Config.getInstance(config);
LabDialog dialog = new LabDialog();
dialog.setVisible(true);
}
- private static void help() {
+ public static void help() {
System.out.println("More info:" + Constants.url);
System.out.println("Syntax:");
System.out.println("java -jar DeconvolutionLab_2.jar lab");
System.out.println("java -jar DeconvolutionLab_2.jar run {command} ...");
System.out.println("java -jar DeconvolutionLab_2.jar launch {command} ...");
System.out.println("java -jar DeconvolutionLab_2.jar fft");
System.out.println("java -jar DeconvolutionLab_2.jar info");
System.out.println("java -jar DeconvolutionLab_2.jar help");
System.out.println("{command} is the full command line for running a deconvolution");
System.out.print("Keywords of {command}: ");
for (String keyword : Command.keywords)
System.out.print(keyword + " ");
}
public DeconvolutionLab2(String cmd) {
System.out.println("cmd: " + cmd);
deconvolutionlab.Lab.getInstance(Platform.STANDALONE);
String config = System.getProperty("user.dir") + File.separator + "DeconvolutionLab2.config";
Config.getInstance(config);
new Deconvolution(cmd).deconvolve(false);
}
+
+
}
diff --git a/DeconvolutionLab2/src/DeconvolutionLab2_FFT.java b/DeconvolutionLab2/src/DeconvolutionLab2_FFT.java
index 1a86876..943f976 100644
--- a/DeconvolutionLab2/src/DeconvolutionLab2_FFT.java
+++ b/DeconvolutionLab2/src/DeconvolutionLab2_FFT.java
@@ -1,13 +1,44 @@
+/*
+ * 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.Lab;
import deconvolutionlab.Platform;
import deconvolutionlab.monitor.Monitors;
import ij.plugin.PlugIn;
public class DeconvolutionLab2_FFT implements PlugIn {
@Override
public void run(String arg) {
Lab.getInstance(Platform.IMAGEJ);
Lab.checkFFT(Monitors.createDefaultMonitor());
}
}
diff --git a/DeconvolutionLab2/src/DeconvolutionLab2_Help.java b/DeconvolutionLab2/src/DeconvolutionLab2_Help.java
index 33cfb52..1b08f49 100644
--- a/DeconvolutionLab2/src/DeconvolutionLab2_Help.java
+++ b/DeconvolutionLab2/src/DeconvolutionLab2_Help.java
@@ -1,12 +1,43 @@
+/*
+ * 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.plugin.PlugIn;
import deconvolutionlab.Lab;
import deconvolutionlab.Platform;
public class DeconvolutionLab2_Help implements PlugIn {
@Override
public void run(String arg) {
Lab.getInstance(Platform.IMAGEJ);
Lab.help();
}
}
diff --git a/DeconvolutionLab2/src/DeconvolutionLab2_Lab.java b/DeconvolutionLab2/src/DeconvolutionLab2_Lab.java
index e7ba40f..d99963b 100644
--- a/DeconvolutionLab2/src/DeconvolutionLab2_Lab.java
+++ b/DeconvolutionLab2/src/DeconvolutionLab2_Lab.java
@@ -1,19 +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 java.io.File;
import deconvolutionlab.Config;
import deconvolutionlab.Lab;
import deconvolutionlab.Platform;
import deconvolutionlab.dialog.LabDialog;
import ij.IJ;
import ij.plugin.PlugIn;
public class DeconvolutionLab2_Lab implements PlugIn {
@Override
public void run(String arg) {
Lab.getInstance(Platform.IMAGEJ);
String config = IJ.getDirectory("plugins") + File.separator + "DeconvolutionLab2.config";
Config.getInstance(config);
new LabDialog().setVisible(true);
}
}
diff --git a/DeconvolutionLab2/src/DeconvolutionLab2_Launch.java b/DeconvolutionLab2/src/DeconvolutionLab2_Launch.java
index 33a8d1c..8a3d331 100644
--- a/DeconvolutionLab2/src/DeconvolutionLab2_Launch.java
+++ b/DeconvolutionLab2/src/DeconvolutionLab2_Launch.java
@@ -1,24 +1,55 @@
+/*
+ * 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.Config;
import deconvolutionlab.Lab;
import deconvolutionlab.Platform;
import deconvolutionlab.dialog.LabDialog;
import ij.IJ;
import ij.Macro;
import ij.plugin.PlugIn;
public class DeconvolutionLab2_Launch implements PlugIn {
@Override
public void run(String arg) {
Lab.getInstance(Platform.IMAGEJ);
String config = IJ.getDirectory("plugins") + File.separator + "DeconvolutionLab2.config";
Config.getInstance(config);
if (Macro.getOptions() == null)
new LabDialog().setVisible(true);
else
new Deconvolution(Macro.getOptions()).launch("", false);
}
}
diff --git a/DeconvolutionLab2/src/DeconvolutionLab2_Run.java b/DeconvolutionLab2/src/DeconvolutionLab2_Run.java
index 0462b41..ce534b5 100644
--- a/DeconvolutionLab2/src/DeconvolutionLab2_Run.java
+++ b/DeconvolutionLab2/src/DeconvolutionLab2_Run.java
@@ -1,24 +1,55 @@
+/*
+ * 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.Config;
import deconvolutionlab.Lab;
import deconvolutionlab.Platform;
import deconvolutionlab.dialog.LabDialog;
import ij.IJ;
import ij.Macro;
import ij.plugin.PlugIn;
public class DeconvolutionLab2_Run implements PlugIn {
@Override
public void run(String arg) {
Lab.getInstance(Platform.IMAGEJ);
String config = IJ.getDirectory("plugins") + File.separator + "DeconvolutionLab2.config";
Config.getInstance(config);
if (Macro.getOptions() == null)
new LabDialog().setVisible(true);
else
new Deconvolution(Macro.getOptions()).deconvolve(false);
}
}
diff --git a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Celegans.java b/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Celegans.java
index 2f51a44..9343fed 100644
--- a/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Celegans.java
+++ b/DeconvolutionLab2/src/course/DeconvolutionLab2_Course_Celegans.java
@@ -1,81 +1,91 @@
package course;
// Course Version 2
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 deconvolution.Deconvolution;
public class DeconvolutionLab2_Course_Celegans implements PlugIn {
private String desktop = FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath() + File.separator + "Desktop";
private String root = desktop + File.separator + "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 I ", "IN_");
- run(" -algorithm RIF 0.001 ", "RIF_");
+ 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(img + psf + algo + param).deconvolve(false);
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/deconvolution/Deconvolution.java b/DeconvolutionLab2/src/deconvolution/Deconvolution.java
index 16de499..ccbd1bf 100644
--- a/DeconvolutionLab2/src/deconvolution/Deconvolution.java
+++ b/DeconvolutionLab2/src/deconvolution/Deconvolution.java
@@ -1,663 +1,660 @@
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolution;
import java.io.File;
import java.util.ArrayList;
import javax.swing.JFrame;
import deconvolution.algorithm.AbstractAlgorithm;
import deconvolution.algorithm.Controller;
import deconvolutionlab.Lab;
import deconvolutionlab.Output;
import deconvolutionlab.OutputCollection;
-import deconvolutionlab.monitor.AbstractMonitor;
import deconvolutionlab.monitor.ConsoleMonitor;
import deconvolutionlab.monitor.Monitors;
import deconvolutionlab.monitor.StatusMonitor;
import deconvolutionlab.monitor.TableMonitor;
import deconvolutionlab.monitor.Verbose;
import fft.AbstractFFT;
import fft.AbstractFFTLibrary;
import fft.FFT;
import lab.tools.NumFormat;
import signal.RealSignal;
import signal.apodization.AbstractApodization;
import signal.apodization.Apodization;
import signal.apodization.UniformApodization;
import signal.factory.SignalFactory;
import signal.padding.Padding;
public class Deconvolution implements Runnable {
private AbstractAlgorithm algo = null;
private String path;
private Monitors monitors = Monitors.createDefaultMonitor();
private Verbose verbose = Verbose.Log;
private Controller controller;
private OutputCollection outs;
private Padding padding = new Padding();
private Apodization apodization = new Apodization();
private double factorNormalization = 1.0;
private AbstractFFTLibrary fftlib;
private String command = "";
private boolean live = false;
private ArrayList<String> report = new ArrayList<String>();
private String name = "";
private boolean exit = false;
private boolean watcherMonitor = true;
private boolean watcherConsole = true;
private boolean watcherDisplay = true;
private boolean watcherMultithreading = true;
private ArrayList<DeconvolutionListener> listeners = new ArrayList<DeconvolutionListener>();
public Deconvolution(String command) {
super();
monitors = Monitors.createDefaultMonitor();
this.command = command;
decode();
}
public void setCommand(String command) {
this.command = command;
decode();
}
public String getCommand() {
return command;
}
public Monitors getMonitors() {
if (monitors == null)
return Monitors.createDefaultMonitor();
return monitors;
}
/**
* This method runs the deconvolution without graphical user interface.
*
* @param exit
* System.exit call is true
*/
public void deconvolve(boolean exit) {
this.exit = exit;
monitors = new Monitors();
if (watcherConsole)
monitors.add(new ConsoleMonitor());
if (watcherMonitor) {
TableMonitor m = new TableMonitor(440, 440);
monitors.add(m);
String t = algo == null ? "Monitor " + name : name + " " + algo.getName();
JFrame frame = new JFrame(t);
frame.add(m.getPanel());
frame.pack();
frame.setVisible(true);
}
if (fftlib == null) {
run();
return;
}
if (!fftlib.isMultithreadable()) {
run();
return;
}
if (watcherMultithreading) {
Thread thread = new Thread(this);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
else {
run();
}
}
/**
* This method runs the deconvolution with a graphical user interface.
*
* @param job
* Name of the job of deconvolution
* @param exit
* System.exit call is true
*/
public void launch(String job, boolean exit) {
this.name = job;
this.exit = exit;
DeconvolutionDialog d = new DeconvolutionDialog(this);
monitors = new Monitors();
monitors.add(new StatusMonitor(d.getProgressBar()));
if (watcherConsole)
monitors.add(new ConsoleMonitor());
if (watcherMonitor) {
TableMonitor m = new TableMonitor(440, 440);
monitors.add(m);
d.addTableMonitor("Monitor", m);
}
}
public void decode() {
algo = null;
path = System.getProperty("user.dir");
if (monitors==null)
monitors = Monitors.createDefaultMonitor();
verbose = Verbose.Log;
controller = new Controller();
outs = new OutputCollection();
padding = new Padding();
apodization = new Apodization();
factorNormalization = 1.0;
fftlib = FFT.getLibraryByName("Academic");
live = false;
ArrayList<Token> tokens = Command.parse(command);
for (Token token : tokens) {
if (token.keyword.equalsIgnoreCase("-algorithm"))
algo = Command.decodeAlgorithm(token, controller);
if (token.keyword.equalsIgnoreCase("-disable")) {
watcherMonitor = Command.decodeDisable(token, "monitor");
watcherConsole = Command.decodeDisable(token, "console");
watcherDisplay = Command.decodeDisable(token, "display");
watcherMultithreading = Command.decodeDisable(token, "multithreading");
}
if (token.keyword.equalsIgnoreCase("-verbose"))
verbose = Verbose.getByName(token.parameters);
if (token.keyword.equalsIgnoreCase("-path") && !token.parameters.equalsIgnoreCase("current")) {
path = token.parameters;
}
if (token.keyword.equalsIgnoreCase("-fft"))
fftlib = FFT.getLibraryByName(token.parameters);
if (token.keyword.equalsIgnoreCase("-pad"))
padding = Command.decodePadding(token);
if (token.keyword.equalsIgnoreCase("-apo"))
apodization = Command.decodeApodization(token);
if (token.keyword.equalsIgnoreCase("-norm"))
factorNormalization = Command.decodeNormalization(token);
if (token.keyword.equalsIgnoreCase("-constraint"))
Command.decodeController(token, controller);
if (token.keyword.equalsIgnoreCase("-time"))
Command.decodeController(token, controller);
if (token.keyword.equalsIgnoreCase("-residu"))
Command.decodeController(token, controller);
if (token.keyword.equalsIgnoreCase("-reference"))
Command.decodeController(token, controller);
if (token.keyword.equalsIgnoreCase("-savestats"))
Command.decodeController(token, controller);
if (token.keyword.equalsIgnoreCase("-showstats"))
Command.decodeController(token, controller);
if (token.keyword.equals("-out")) {
Output out = Command.decodeOut(token);
if (out != null)
outs.add(out);
}
}
if (name.equals("") && algo != null)
name = algo.getShortname();
}
public void setApodization(ArrayList<AbstractApodization> apos) {
AbstractApodization apoXY = new UniformApodization();
AbstractApodization apoZ = new UniformApodization();
if (apos.size() >= 1)
apoXY = apos.get(0);
if (apos.size() >= 2)
apoZ = apos.get(1);
this.apodization = new Apodization(apoXY, apoXY, apoZ);
}
@Override
public void run() {
double chrono = System.nanoTime();
for(DeconvolutionListener listener : listeners)
listener.started();
live = true;
if (monitors != null)
monitors.setVerbose(verbose);
report.add("Path: " + checkPath(path));
monitors.log("Path: " + checkPath(path));
RealSignal image = openImage();
-
if (image == null) {
monitors.error("Image: Not valid " + command);
report.add("Image: Not valid");
if (exit)
System.exit(-101);
return;
}
- report.add("Image: " + image.dimAsString());
-
- monitors.log("Image: " + image.nx + " x " + image.ny + " x " + image.nz);
+ report.add( "Image: " + image.dimAsString());
+ monitors.log("Image: " + image.dimAsString());
+
RealSignal y = padding.pad(monitors, getApodization().apodize(monitors, image));
RealSignal psf = openPSF();
if (psf == null) {
monitors.error("PSF: not valid");
report.add("PSF: Not valid");
if (exit)
System.exit(-102);
return;
}
- report.add("PSF: " + psf.dimAsString());
-
- monitors.log("PSF: " + psf.nx + " x " + psf.ny + " x " + psf.nz);
+ report.add( "PSF: " + psf.dimAsString());
+ monitors.log("PSF: " + psf.dimAsString());
+
monitors.log("PSF: normalization " + (factorNormalization <= 0 ? "no" : factorNormalization));
RealSignal h = psf.changeSizeAs(y).normalize(factorNormalization);
if (algo == null) {
monitors.error("Algorithm: not valid");
if (exit)
System.exit(-103);
return;
}
if (controller == null) {
monitors.error("Controller: not valid");
if (exit)
System.exit(-104);
return;
}
AbstractFFT fft;
if (fftlib != null)
fft = FFT.createFFT(monitors, fftlib, image.nx, image.ny, image.nz);
else
fft = FFT.createDefaultFFT(monitors, image.nx, image.ny, image.nz);
report.add("FFT: " + fft.getName());
algo.setFFT(fft);
controller.setFFT(fft);
algo.setController(controller);
if (outs != null) {
outs.setPath(path);
controller.setOutputs(outs);
}
monitors.log("Algorithm: " + algo.getName());
report.add("Algorithm: " + algo.getName());
RealSignal x = algo.run(monitors, y, h, true);
RealSignal result = padding.crop(monitors, x);
if (outs != null)
outs.executeFinal(monitors, result, controller);
live = false;
for(DeconvolutionListener listener : listeners)
listener.finish();
report.add("End " + algo.getName() + " in " + NumFormat.time(System.nanoTime()-chrono));
if (watcherDisplay)
Lab.show(monitors, result, "Result of " + algo.getShortname());
if (exit) {
System.out.println("End");
System.exit(0);
}
-
}
/**
* This methods make a recap of the deconvolution. Useful before starting the processing.
*
* @return list of messages to print
*/
public ArrayList<String> recap() {
ArrayList<String> lines = new ArrayList<String>();
Token image = Command.extract(command, "-image");
if (image == null)
lines.add("<b>Image</b>: <span color=\"red\">keyword -image not found</span>");
else
lines.add("<b>Image</b>: " + image.parameters);
String norm = (factorNormalization < 0 ? " (no normalization)" : " (normalization to " + factorNormalization + ")");
Token psf = Command.extract(command, "-psf");
if (psf == null)
lines.add("<b>PSF</b>: <span color=\"red\">keyword -psf not found</span>");
else
lines.add("<b>PSF</b>: " + psf.parameters + norm);
if (algo == null) {
lines.add("<b>Algorithm</b>: <span color=\"red\">not valid</span>");
}
else {
Controller controller = algo.getController();
String con = ", " + controller.getConstraintAsString() + " constraint";
lines.add("<b>Algorithm</b>: " + algo.toString() + con);
lines.add("<b>Stopping Criteria</b>: " + controller.getStoppingCriteria(algo));
lines.add("<b>Reference</b>: " + controller.getReference());
lines.add("<b>Stats</b>: " + controller.getShowStats() + " " + controller.getSaveStats());
lines.add("<b>Padding</b>: " + padding.toString());
lines.add("<b>Apodization</b>: " + apodization.toString());
if (algo.getFFT() != null)
lines.add("<b>FFT</b>: " + algo.getFFT().getName());
}
lines.add("<b>Path</b>: " + path);
lines.add("<b>Verbose</b>: " + verbose.name().toLowerCase());
lines.add("<b>Monitor</b>: " + (watcherMonitor ? "on" : "off"));
lines.add("<b>Console</b>: " + (watcherConsole ? "on" : "off"));
lines.add("<b>Final Display</b>: " + (watcherDisplay ? "on" : "off"));
lines.add("<b>Multithreading</b>: " + (watcherMultithreading ? "on" : "off"));
if (outs == null)
lines.add("<b>Outputs</b>: not valid");
else
lines.addAll(outs.getInformation());
return lines;
}
public ArrayList<String> checkAlgo() {
ArrayList<String> lines = new ArrayList<String>();
RealSignal image = openImage();
if (image == null) {
lines.add("No valid input image");
return lines;
}
if (padding == null) {
lines.add("No valid padding");
return lines;
}
if (apodization == null) {
lines.add("No valid apodization");
return lines;
}
RealSignal psf = openPSF();
if (psf == null) {
lines.add("No valid PSF");
return lines;
}
if (algo == null) {
lines.add("No valid algorithm");
return lines;
}
Controller controller = algo.getController();
RealSignal y = padding.pad(monitors, getApodization().apodize(monitors, image));
RealSignal h = psf.changeSizeAs(y).normalize(factorNormalization);
int iter = controller.getIterationMax();
algo.getController().setIterationMax(1);
RealSignal x = algo.run(monitors, y, h, true);
Lab.show(monitors, x, "Estimate after 1 iteration");
lines.add("Time: " + NumFormat.seconds(controller.getTimeNano()));
lines.add("Peak Memory: " + controller.getMemoryAsString());
controller.setIterationMax(iter);
return lines;
}
public ArrayList<String> checkImage() {
ArrayList<String> lines = new ArrayList<String>();
RealSignal image = openImage();
if (image == null) {
lines.add("No valid input image");
return lines;
}
if (padding == null) {
lines.add("No valid padding");
return lines;
}
if (apodization == null) {
lines.add("No valid apodization");
return lines;
}
RealSignal signal = padding.pad(monitors, getApodization().apodize(monitors, image));
lines.add("<b>Image</b>");
lines.add("Original size " + image.dimAsString() + " padded to " + signal.dimAsString());
lines.add("Original: " + formatStats(image));
lines.add("Preprocessing: " + formatStats(signal));
Lab.show(monitors, signal, "Image");
return lines;
}
public ArrayList<String> checkPSF() {
ArrayList<String> lines = new ArrayList<String>();
RealSignal image = openImage();
if (image == null) {
lines.add("No valid input image");
return lines;
}
if (padding == null) {
lines.add("No valid padding");
return lines;
}
if (apodization == null) {
lines.add("No valid apodization");
return lines;
}
RealSignal psf = openPSF();
if (psf == null) {
lines.add("No valid PSF");
return lines;
}
RealSignal signal = padding.pad(monitors, getApodization().apodize(monitors, image));
RealSignal h = psf.changeSizeAs(signal);
lines.add("<b>PSF</b>");
lines.add("Original size " + psf.dimAsString() + " padded to " + h.dimAsString());
String e = NumFormat.nice(h.getEnergy());
h.normalize(factorNormalization);
lines.add("Original: " + formatStats(psf));
lines.add("Preprocessing: " + formatStats(h));
lines.add("Energy = " + e + " and after normalization=" + NumFormat.nice(h.getEnergy()));
Lab.show(monitors, h, "Padded and Normalized PSF");
return lines;
}
public ArrayList<String> getDeconvolutionReports() {
return report;
}
public String getName() {
return name;
}
public boolean isLive() {
return live;
}
public void abort() {
live = false;
algo.getController().abort();
}
public Padding getPadding1() {
return padding;
}
public Apodization getApodization() {
return apodization;
}
public OutputCollection getOuts() {
return outs;
}
public AbstractAlgorithm getAlgo() {
return algo;
}
public String getPath() {
return path;
}
public String checkPath(String path) {
File dir = new File(path);
if (dir.exists()) {
if (dir.isDirectory()) {
if (dir.canWrite())
return path + " (writable)";
else
return path + " (non-writable)";
}
else {
return path + " (non-directory)";
}
}
else {
return path + " (not-valid)";
}
}
public RealSignal openImage() {
Token token = Command.extract(command, "-image");
if (token == null)
return null;
if (token.parameters.startsWith(">>>"))
return null;
return getImage(monitors, token);
}
public RealSignal openPSF() {
Token token = Command.extract(command, "-psf");
if (token == null)
return null;
if (token.parameters.startsWith(">>>"))
return null;
return getImage(monitors, token);
}
private RealSignal getImage(Monitors monitors, Token token) {
String arg = token.option.trim();
String cmd = token.parameters.substring(arg.length(), token.parameters.length()).trim();
if (arg.equalsIgnoreCase("synthetic")) {
String parts[] = cmd.split(" ");
if (parts.length <= 0)
return null;
String shape = parts[0];
for (String name : SignalFactory.getAllName()) {
if (shape.equalsIgnoreCase(name.toLowerCase())) {
double params[] = Command.parseNumeric(cmd);
SignalFactory factory = SignalFactory.getFactoryByName(shape);
if (factory == null)
return null;
double amplitude = params.length > 0 ? params[0] : 1;
double background = params.length > 1 ? params[1] : 0;
factory.intensity(background, amplitude);
int np = factory.getParameters().length;
double[] features = new double[np];
for (int i = 0; i < Math.min(np, params.length); i++)
features[i] = params[i + 2];
factory.setParameters(features);
int nx = params.length > np + 2 ? (int) Math.round(params[np + 2]) : 128;
int ny = params.length > np + 3 ? (int) Math.round(params[np + 3]) : 128;
int nz = params.length > np + 4 ? (int) Math.round(params[np + 4]) : 128;
double cx = params.length > np + 5 ? params[np + 5] : 0.5;
double cy = params.length > np + 6 ? params[np + 6] : 0.5;
double cz = params.length > np + 7 ? params[np + 7] : 0.5;
factory = factory.center(cx, cy, cz);
RealSignal x = factory.generate(nx, ny, nz);
return x;
}
}
}
if (arg.equalsIgnoreCase("file") || arg.equalsIgnoreCase("dir") || arg.equalsIgnoreCase("directory")) {
RealSignal signal = null;
File file = new File(path + File.separator + cmd);
if (file != null) {
if (file.isFile())
signal = Lab.open(monitors, path + File.separator + cmd);
if (file.isDirectory())
signal = Lab.openDir(monitors, path + File.separator + cmd);
}
if (signal == null) {
File local = new File(cmd);
if (local != null) {
if (local.isFile())
signal = Lab.open(monitors, cmd);
if (local.isDirectory())
signal = Lab.openDir(monitors, cmd);
}
}
return signal;
}
if (arg.equalsIgnoreCase("platform")) {
return Lab.getImager().create(cmd);
}
return null;
}
private static String formatStats(RealSignal x) {
float stats[] = x.getStats();
String s = " mean=" + NumFormat.nice(stats[0]);
s += " stdev=" + NumFormat.nice(stats[1]);
s += " min=" + NumFormat.nice(stats[3]);
s += " max=" + NumFormat.nice(stats[2]);
return s;
}
public void addDeconvolutionListener(DeconvolutionListener listener) {
listeners.add(listener);
}
}
diff --git a/DeconvolutionLab2/src/matlab/Converter.java b/DeconvolutionLab2/src/matlab/Converter.java
new file mode 100644
index 0000000..86001e3
--- /dev/null
+++ b/DeconvolutionLab2/src/matlab/Converter.java
@@ -0,0 +1,409 @@
+package matlab;
+
+import ij.ImagePlus;
+import ij.ImageStack;
+import ij.process.ByteProcessor;
+import ij.process.ColorProcessor;
+import ij.process.FloatProcessor;
+import ij.process.ShortProcessor;
+
+public class Converter {
+
+ public static boolean verbose;
+
+ /**
+ * Get an image.
+ *
+ * @param imageplus image
+ * @return an N x M array representing the input image
+ */
+ public static Object get(ImagePlus imageplus) {
+ if (imageplus == null)
+ return null;
+ int width = imageplus.getWidth();
+ int height = imageplus.getHeight();
+ int stackSize = imageplus.getStackSize();
+ int counter = 0;
+ ImageStack imagestack = imageplus.getStack();
+ switch (imageplus.getType()) {
+
+ case ImagePlus.COLOR_256: {
+ ;
+ }
+ case ImagePlus.GRAY8: {
+ short[][][] is = new short[height][width][stackSize];
+ for (int sz = 0; sz < stackSize; sz++) {
+ ByteProcessor byteprocessor = (ByteProcessor) imagestack.getProcessor(sz + 1);
+ byte[] pixels = (byte[]) byteprocessor.getPixels();
+ counter = 0;
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ is[h][w][sz] = (short)(pixels[counter]&0xff);
+ w++;
+ counter++;
+ }
+ counter = ++h * width;
+ }
+ }
+ return is;
+ }
+ case ImagePlus.GRAY16: {
+ int[][][] is = new int[height][width][stackSize];
+ for (int sz = 0; sz < stackSize; sz++) {
+ counter = 0;
+ ShortProcessor shortprocessor = (ShortProcessor) imagestack.getProcessor(sz + 1);
+ short[] spixels = (short[]) shortprocessor.getPixels();
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ is[h][w][sz] = (int)(spixels[counter]&0xffff);
+ w++;
+ counter++;
+ }
+ counter = ++h * width;
+ }
+ }
+ return is;
+ }
+ case ImagePlus.GRAY32: {
+ double[][][] fs = new double[height][width][stackSize];
+ for (int sz = 0; sz < stackSize; sz++) {
+ FloatProcessor floatprocessor = (FloatProcessor) imagestack.getProcessor(sz + 1);
+ float[] fpixels = (float[]) floatprocessor.getPixels();
+ counter = 0;
+ int i = 0;
+ while (i < height) {
+ int j = 0;
+ while (j < width) {
+ fs[i][j][sz] = (double) fpixels[counter];
+ j++;
+ counter++;
+ }
+ counter = ++i * width;
+ }
+ }
+ return fs;
+ }
+ case ImagePlus.COLOR_RGB: {
+ if (stackSize == 1) {
+ short[][][] is = new short[height][width][3];
+ ColorProcessor colorprocessor = (ColorProcessor) imagestack.getProcessor(1);
+ byte[] red = new byte[width * height];
+ byte[] green = new byte[width * height];
+ byte[] blue = new byte[width * height];
+ colorprocessor.getRGB(red, green, blue);
+ counter = 0;
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ is[h][w][0] = (short)(red[counter]&0xff);
+ is[h][w][1] = (short)(green[counter]&0xff);
+ is[h][w][2] = (short)(blue[counter]&0xff);
+ w++;
+ counter++;
+ }
+ counter = ++h * width;
+ }
+ return is;
+ }
+ short[][][][] is = new short[height][width][stackSize][3];
+ for (int sz = 0; sz < stackSize; sz++) {
+ ColorProcessor colorprocessor = (ColorProcessor) imagestack.getProcessor(sz + 1);
+ byte[] red = new byte[width * height];
+ byte[] green = new byte[width * height];
+ byte[] blue = new byte[width * height];
+ colorprocessor.getRGB(red, green, blue);
+ counter = 0;
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ is[h][w][sz][0] = (short)red[counter];
+ is[h][w][sz][1] = (short)green[counter];
+ is[h][w][sz][2] = (short)blue[counter];
+ w++;
+ counter++;
+ }
+ counter = ++h * width;
+ }
+ }
+ return is;
+ }
+ default:
+ System.out.println("MIJ Error message: Unknow type of volumes.");
+ return null;
+ }
+ }
+ /**
+ * Create a new image in ImageJ from a Matlab variable with a specified
+ * title.
+ *
+ * This method try to create a image (ImagePlus of ImageJ) from a Matlab's
+ * variable which should be an 2D or 3D array The recognize type are byte,
+ * short, int, float and double. The dimensionality of the 2 (image) or 3
+ * (stack of images)
+ *
+ * @param title
+ * title of the new image
+ * @param object
+ * Matlab variable
+ * @param showImage
+ * Whether to display the newly created image or not
+ * @return the resulting ImagePlus instance
+ */
+ public static ImagePlus createImage(String title, Object object, boolean showImage) {
+ ImagePlus imp = null;
+ int i = 0;
+ if (object instanceof byte[][]) {
+ byte[][] is = (byte[][]) object;
+ int height = is.length;
+ int width = is[0].length;
+ ByteProcessor byteprocessor = new ByteProcessor(width, height);
+ byte[] bp = (byte[]) byteprocessor.getPixels();
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ bp[i] = is[h][w];
+ w++;
+ i++;
+ }
+ i = ++h * width;
+ }
+ imp = new ImagePlus(title, byteprocessor);
+
+ }
+ else if (object instanceof short[][]) {
+ short[][] is = (short[][]) object;
+ int height = is.length;
+ int width = is[0].length;
+ ShortProcessor shortprocessor = new ShortProcessor(width, height);
+ short[] sp = (short[]) shortprocessor.getPixels();
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ sp[i] = is[h][w];
+ w++;
+ i++;
+ }
+ i = ++h * width;
+ }
+ imp = new ImagePlus(title, shortprocessor);
+
+ }
+ else if (object instanceof int[][]) {
+ if (verbose)
+ System.out.println("MIJ warning message: Loss of precision: convert int 32-bit to short 16-bit");
+ int[][] is = (int[][]) object;
+ int height = is.length;
+ int width = is[0].length;
+ ShortProcessor shortprocessor = new ShortProcessor(width, height);
+ short[] sp = (short[]) shortprocessor.getPixels();
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ sp[i] = (short) is[h][w];
+ w++;
+ i++;
+ }
+ i = ++h * width;
+ }
+ imp = new ImagePlus(title, shortprocessor);
+ }
+ else if (object instanceof float[][]) {
+ float[][] fs = (float[][]) object;
+ int height = fs.length;
+ int width = fs[0].length;
+ FloatProcessor floatprocessor = new FloatProcessor(width, height);
+ float[] fp = (float[]) floatprocessor.getPixels();
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ fp[i] = fs[h][w];
+ w++;
+ i++;
+ }
+ i = ++h * width;
+ }
+ floatprocessor.resetMinAndMax();
+ imp = new ImagePlus(title, floatprocessor);
+
+ }
+ else if (object instanceof double[][]) {
+ if (verbose)
+ System.out.println("MIJ warning message: Loss of precision: convert double 32-bit to float 32-bit");
+ double[][] ds = (double[][]) object;
+ int height = ds.length;
+ int width = ds[0].length;
+ FloatProcessor floatprocessor = new FloatProcessor(width, height);
+ float[] fp = (float[]) floatprocessor.getPixels();
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ fp[i] = (float) ds[h][w];
+ w++;
+ i++;
+ }
+ i = ++h * width;
+ }
+ floatprocessor.resetMinAndMax();
+ imp = new ImagePlus(title, floatprocessor);
+
+ }
+ else if (object instanceof byte[][][]) {
+ byte[][][] is = (byte[][][]) object;
+ int height = is.length;
+ int width = is[0].length;
+ int stackSize = is[0][0].length;
+ ImageStack imagestack = new ImageStack(width, height);
+ for (int sz = 0; sz < stackSize; sz++) {
+ ByteProcessor byteprocessor = new ByteProcessor(width, height);
+ byte[] bp = (byte[]) byteprocessor.getPixels();
+ i = 0;
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ bp[i] = is[h][w][sz];
+ w++;
+ i++;
+ }
+ i = ++h * width;
+ }
+ imagestack.addSlice("", byteprocessor);
+ }
+ imp = new ImagePlus(title, imagestack);
+
+ }
+ else if (object instanceof short[][][]) {
+ short[][][] is = (short[][][]) object;
+ int height = is.length;
+ int width = is[0].length;
+ int stackSize = is[0][0].length;
+ ImageStack imagestack = new ImageStack(width, height);
+ for (int sz = 0; sz < stackSize; sz++) {
+ ShortProcessor shortprocessor = new ShortProcessor(width, height);
+ short[] sp = (short[]) shortprocessor.getPixels();
+ i = 0;
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ sp[i] = is[h][w][sz];
+ w++;
+ i++;
+ }
+ i = ++h * width;
+ }
+ imagestack.addSlice("", shortprocessor);
+ }
+ imp = new ImagePlus(title, imagestack);
+
+ }
+ else if (object instanceof int[][][]) {
+ if (verbose)
+ System.out.println("MIJ warning message: Loss of precision: convert int 32 bits to short 16 bits");
+ int[][][] is = (int[][][]) object;
+ int height = is.length;
+ int width = is[0].length;
+ int stackSize = is[0][0].length;
+ ImageStack imagestack = new ImageStack(width, height);
+ for (int sz = 0; sz < stackSize; sz++) {
+ ShortProcessor shortprocessor = new ShortProcessor(width, height);
+ short[] sp = (short[]) shortprocessor.getPixels();
+ i = 0;
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ sp[i] = (short) is[h][w][sz];
+ w++;
+ i++;
+ }
+ i = ++h * width;
+ }
+ if (sz == 0)
+ shortprocessor.resetMinAndMax();
+ imagestack.addSlice("", shortprocessor);
+
+ }
+ imp = new ImagePlus(title, imagestack);
+
+ }
+ else if (object instanceof float[][][]) {
+ float[][][] fs = (float[][][]) object;
+ int height = fs.length;
+ int width = fs[0].length;
+ int stackSize = fs[0][0].length;
+ ImageStack imagestack = new ImageStack(width, height);
+ for (int sz = 0; sz < stackSize; sz++) {
+ FloatProcessor floatprocessor = new FloatProcessor(width, height);
+ float[] fp = (float[]) floatprocessor.getPixels();
+ i = 0;
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ fp[i] = fs[h][w][sz];
+ w++;
+ i++;
+ }
+ i = ++h * width;
+ }
+ if (sz == 0)
+ floatprocessor.resetMinAndMax();
+ imagestack.addSlice("", floatprocessor);
+ }
+ imp = new ImagePlus(title, imagestack);
+
+ }
+ else if (object instanceof double[][][]) {
+ if (verbose)
+ System.out.println("MIJ warning message: Loss of precision: convert double 32-bit to float 32-bit");
+ double[][][] ds = (double[][][]) object;
+ int height = ds.length;
+ int width = ds[0].length;
+ int stackSize = ds[0][0].length;
+ ImageStack imagestack = new ImageStack(width, height);
+ for (int sz = 0; sz < stackSize; sz++) {
+ FloatProcessor floatprocessor = new FloatProcessor(width, height);
+ float[] fp = (float[]) floatprocessor.getPixels();
+ i = 0;
+ int h = 0;
+ while (h < height) {
+ int w = 0;
+ while (w < width) {
+ fp[i] = (float) ds[h][w][sz];
+ w++;
+ i++;
+ }
+ i = ++h * width;
+ }
+ if (sz == 0)
+ floatprocessor.resetMinAndMax();
+ imagestack.addSlice("", floatprocessor);
+ }
+ imp = new ImagePlus(title, imagestack);
+
+ }
+ else {
+ System.out.println("MIJ Error message: Unknow type of images or volumes.");
+ return null;
+ }
+
+ if (showImage) {
+ imp.show();
+ imp.updateAndDraw();
+ }
+ return imp;
+ }
+
+}
Event Timeline
Log In to Comment