|
1 | 1 | #@ OpService ops |
2 | 2 | #@ UIService ui |
3 | | -#@ ImgPlus img |
4 | | -#@ Integer numIterations(value=30) |
5 | | -#@ Float numericalAperture(value=1.4) |
6 | | -#@ Float wavelength(value=550) |
7 | | -#@ Float riImmersion(value=1.5) |
8 | | -#@ Float riSample(value=1.4) |
9 | | -#@ Float xySpacing(value=62.9) |
10 | | -#@ Float zSpacing(value=160) |
11 | | -#@OUTPUT ImgPlus psf |
12 | | -#@OUTPUT ImgPlus deconvolved |
| 3 | +#@ Img (label = "Input image:", autofill = false) img |
| 4 | +#@ Integer (label="Iterations", value=15) iterations |
| 5 | +#@ Float (label="Numerical Aperture", style="format:0.00", min=0.00, value=1.45) numerical_aperture |
| 6 | +#@ Integer (label="Emission Wavelength (nm)", value=457) wavelength |
| 7 | +#@ Float (label="Refractive Index (immersion)", style="format:0.00", min=0.00, value=1.5) ri_immersion |
| 8 | +#@ Float (label="Refractive Index (sample)", style="format:0.00", min=0.00, value=1.4) ri_sample |
| 9 | +#@ Float (label="Lateral spacing (μm/pixel)", style="format:0.0000", min=0.0000, value=0.065) lateral_spacing |
| 10 | +#@ Float (label="Axial spacing (μm/pixel)", style="format:0.0000", min=0.0000, value=0.1) axial_spacing |
| 11 | +#@ Float (label="Particle/sample Position (μm)", style="format:0.0000", min=0.0000, value=0) p_z |
| 12 | +#@ Float (label="Regularization factor", style="format:0.00000", min=0.00000, value=0.002) reg_factor |
| 13 | +#@ Boolean (label = "Show PSF:", value = false) show_psf |
| 14 | +#@output Img result |
13 | 15 |
|
14 | | -from net.imglib2 import FinalDimensions |
15 | | -from net.imglib2.type.numeric.real import FloatType; |
16 | | - |
17 | | -# convert to float (TODO: make sure deconvolution op works on other types) |
18 | | -imgF=ops.convert().float32(img) |
| 16 | +# Richardson-Lucy Total Variation deconvolution with a simulated point spread function. |
| 17 | +# |
| 18 | +# This script utilizes an ImageJ Ops implementation of Richardson-Lucy Total Variation (RLTV) |
| 19 | +# deconvolution as described by Dey et al. 2006 and a simulated point spread function (PSF) |
| 20 | +# using the Gibson-Lanni model. |
| 21 | +# |
| 22 | +# Arguments |
| 23 | +# * `img`: A 3-dimensional image with known lateral (x and y) and axial (z) spacing. |
| 24 | +# * `iterations`: The number of iterations to perform (default = 15). |
| 25 | +# * `numerical_aperture`: The numerical aperature (NA) of the objective used. |
| 26 | +# * `wavelength`: The emission wavelength in nanometers (nm) of the image. |
| 27 | +# * `ri_immersion`: The refractive index of immersion medium (air, oil, etc...). |
| 28 | +# * `ri_sample`: The refractive index of the sample, a measured value (default = 1.4) |
| 29 | +# * `lateral_spacing`: The X and Y pixel spacing in μm/pixel of the image. |
| 30 | +# * `axial_spacing`: The Z spacing in μm/pixel of the image. |
| 31 | +# * `p_z`: The position of the sample from the coverslip. |
| 32 | +# * `reg_factor`: The regularization factor. |
| 33 | +# * `show_psf`: Optionally display the simulated PSF. |
| 34 | +# |
| 35 | +# Returns |
| 36 | +# * `result`: The deconvolved data. |
| 37 | +# * `PSF`: The simulated PSF (optional). |
| 38 | +# |
| 39 | +# Reference |
| 40 | +# |
| 41 | +# https://doi.org/10.1002/jemt.20294 |
19 | 42 |
|
20 | | -# make psf same size as image |
21 | | -psfSize=FinalDimensions([img.dimension(0), img.dimension(1), img.dimension(2)]); |
| 43 | +from net.imglib2 import FinalDimensions |
| 44 | +from net.imglib2.type.numeric.real import FloatType |
22 | 45 |
|
23 | | -# add border in z direction |
24 | | -borderSize=[0,0,psfSize.dimension(2)/2]; |
| 46 | +# convert input image to float |
| 47 | +img = ops.convert().float32(img) |
25 | 48 |
|
26 | | -wavelength=wavelength*1E-9 |
27 | | -xySpacing=xySpacing*1E-9 |
28 | | -zSpacing=zSpacing*1E-9 |
| 49 | +# use image dimensions for PSF size |
| 50 | +psf_size = FinalDimensions(img.dimensionsAsLongArray()) |
29 | 51 |
|
30 | | -# currently there is a bug when generating a PSF with wavelength < 545 nm |
31 | | -# (this has been fixed, but the fix has not yet been distributed) |
32 | | -if wavelength<545E-09: |
33 | | - wavelength = 545E-09; |
| 52 | +# convert the input parameters to meters (m) |
| 53 | +wavelength = float(wavelength) * 1E-9 |
| 54 | +lateral_spacing *= 1E-6 |
| 55 | +axial_spacing *= 1E-6 |
| 56 | +p_z *= 1E-6 |
34 | 57 |
|
35 | | -riImmersion = 1.5; |
36 | | -riSample = 1.4; |
37 | | -xySpacing = 62.9E-9; |
38 | | -zSpacing = 160E-9; |
39 | | -depth = 0; |
| 58 | +# create the synthetic PSF |
| 59 | +psf = ops.create().kernelDiffraction( |
| 60 | + psf_size, |
| 61 | + numerical_aperture, |
| 62 | + wavelength, |
| 63 | + ri_sample, |
| 64 | + ri_immersion, |
| 65 | + lateral_spacing, |
| 66 | + axial_spacing, |
| 67 | + p_z, |
| 68 | + FloatType() |
| 69 | + ) |
40 | 70 |
|
41 | | -psf = ops.create().kernelDiffraction(psfSize, numericalAperture, wavelength, |
42 | | - riSample, riImmersion, xySpacing, zSpacing, depth, FloatType()); |
| 71 | +# deconvolve image |
| 72 | +result = ops.deconvolve().richardsonLucyTV(img, psf, iterations, reg_factor) |
43 | 73 |
|
44 | | -deconvolved = ops.deconvolve().richardsonLucy(imgF, psf, borderSize, None, |
45 | | - None, None, None, numIterations, True, True); |
| 74 | +# optionally show the PSF |
| 75 | +if show_psf: |
| 76 | + ui.show("PSF", psf) |
0 commit comments