/
YacuDecuRichardsonLucyTheoreticalPSFCommand.java
92 lines (67 loc) · 2.47 KB
/
YacuDecuRichardsonLucyTheoreticalPSFCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package net.imagej.ops.experiments.filter.deconvolve;
import net.imagej.ImgPlus;
import net.imagej.ops.OpService;
import net.imagej.ops.special.computer.Computers;
import net.imagej.ops.special.computer.UnaryComputerOp;
import net.imglib2.FinalDimensions;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.Img;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.real.FloatType;
import org.scijava.ItemIO;
import org.scijava.command.Command;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
@Plugin(type = Command.class, headless = true, menuPath = "Plugins>OpsExperiments>YacuDecu Theoretical PSF")
public class YacuDecuRichardsonLucyTheoreticalPSFCommand<T extends RealType<T> & NativeType<T>> implements Command {
@Parameter
OpService ops;
@Parameter
ImgPlus<T> img;
@Parameter(type = ItemIO.INPUT)
Integer iterations = 100;
@Parameter(type = ItemIO.INPUT)
Float numericalAperture = 1.4f;
@Parameter(type = ItemIO.INPUT)
Float wavelength = 550f;
@Parameter(type = ItemIO.INPUT)
Float riImmersion = 1.5f;
@Parameter(type = ItemIO.INPUT)
Float riSample = 1.4f;
@Parameter(type = ItemIO.INPUT)
Float xySpacing = 62.9f;
@Parameter(type = ItemIO.INPUT)
Float zSpacing = 160f;
@Parameter(type = ItemIO.INPUT)
Float depth = 0f;
@Parameter(type = ItemIO.OUTPUT)
Img<FloatType> psf;
@Parameter(type = ItemIO.OUTPUT)
Img<FloatType> deconvolved;
@Override
public void run() {
Img<FloatType> imgF = ops.convert().float32(img);
wavelength = wavelength * 1E-9f;
xySpacing = xySpacing * 1E-9f;
zSpacing = zSpacing * 1E-9F;
if (wavelength < 545E-9) {
wavelength = 545E-9f;
}
FinalDimensions psfDims=new FinalDimensions(64,64,50);
// create the diffraction based psf
psf = ops.create().kernelDiffraction(psfDims, numericalAperture, wavelength, riSample, riImmersion, xySpacing,
zSpacing, depth, new FloatType());
// normalize PSF energy to 1
float sumPSF = ops.stats().sum(psf).getRealFloat();
FloatType val = new FloatType();
val.set(sumPSF);
psf = (Img<FloatType>) ops.math().divide(psf, val);
@SuppressWarnings("unchecked")
final UnaryComputerOp<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>> deconvolver =
(UnaryComputerOp) Computers.unary(ops, UnaryComputerYacuDecu.class,
RandomAccessibleInterval.class, imgF, psf, iterations);
deconvolved = ops.create().img(imgF);
deconvolver.compute(imgF, deconvolved);
}
}