Skip to content

Commit f39542b

Browse files
committed
Update script with adjustable grid size and show options
This commit updates the DeconWithGrid.groovy script with a detailed description of the script and its purpose, as well as new adjustable grid dimensions and optional show results. I also added more comments and refactored the script to fit my style.
1 parent 9700ee3 commit f39542b

File tree

1 file changed

+100
-28
lines changed

1 file changed

+100
-28
lines changed
Lines changed: 100 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,111 @@
11
#@ OpService ops
22
#@ UIService ui
3+
#@ String (visibility = MESSAGE, value ="<b>[ Deconvolution settings ]</b>", required = false) decon_msg
4+
#@ Integer (label = "Grid image X dimension size:", min = 0, value = 150) x_dim
5+
#@ Integer (label = "Grid image Y dimension size:", min = 0, value = 100) y_dim
6+
#@ Integer (label = "Number of iterations", min = 0, value = 15) iterations
7+
#@ String (visibility = MESSAGE, value ="<b>[ Show results settings ]</b>", required = false) show_msg
8+
#@ Boolean (label = "Show input image:", value = true) show_grid
9+
#@ Boolean (label = "Show gradient kernel", value = true) show_kernel
10+
#@ Boolean (label = "Show convolved grid:", value = true) show_conv
11+
#@ Boolean (label = "Show RL result:", value = true) show_rl
12+
#@ Boolean (label = "Show RLTV result:", value = true) show_rltv
13+
#@ Boolean (label = "Show RL non-circulant reuslt:", value = true) show_rl_nc
14+
#@ Boolean (label = "Show RL accelerated non-circulant result:", value = true) show_rl_acc_nc
315

4-
import net.imglib2.type.numeric.real.FloatType;
5-
import net.imglib2.outofbounds.OutOfBoundsConstantValueFactory
6-
import net.imglib2.util.Util
16+
import net.imglib2.type.numeric.real.FloatType
717

8-
// create the sample image
9-
base = ops.run("create.img", [150, 100], new FloatType())
10-
formula = "p[0]^2 * p[1]"
11-
ops.image().equation(base, formula)
12-
13-
ui.show("input image", base);
18+
// Richardson-Lucy deconvolution with a simulated grid image.
19+
//
20+
// This script utilizes the ImageJ Ops implementation of Richardson-Lucy (RL) and
21+
// Richardson-Lucy Total Variation (RLTV) deconvolution. Specifically this script
22+
// template creates a simulated grid image with sharp edges, convolves the grid
23+
// image with a simple gradient kernel and performs the various RL deconvolution
24+
// strategies such as accelerated processing and non-circulant deconvolution.
25+
//
26+
// See https://imagej.net/libs/imagej-ops/deconvolution for more information on
27+
// RL/RLTV deconvolution with ImageJ Ops.
28+
//
29+
// Arguments
30+
// * `x_dim`: The grid image X dimension size.
31+
// * `y_dim`: The grid image Y dimension size.
32+
// * `iterations`: The number of deconvolution iterations to perform (default = 10).
33+
//
34+
// Returns
35+
// * `grid_img`: The simulated grid image.
36+
// * `kernel`: The gradient kernel used to convolve the grid image.
37+
// * `conv_img`: The convolved grid image.
38+
// * `rl_decon_img`: The Richardson-Lucy deconvolution result.
39+
// * `rltv_decon_img`: The Richardson-Lucy Total Variation deconvolution result.
40+
// * `rl_nc_decon_img`: The Richardson-Lucy non-circulant deconvolution result.
41+
// * `rl_acc_nc_decon_img`: The Richardson-Lucy accelerated non-circulant deconvolution
42+
// result.
1443

15-
// create kernel
16-
kernel_big = ops.run("create.img", [20,20], new FloatType())
17-
18-
ops.image().equation(kernel_big, "p[0]")
44+
// create a sample grid image with the given X and Y dimensions
45+
// where each pixel is assigned the value (x² * y)
46+
grid_img = ops.run("create.img", [x_dim, y_dim], new FloatType())
47+
formula = "p[0]^2 * p[1]"
48+
ops.image().equation(grid_img, formula)
49+
if (show_grid) {
50+
ui.show("input grid image", grid_img)
51+
}
1952

20-
// convolve with large kernel
21-
convolved_big = ops.filter().convolve(base, kernel_big)
53+
// create a gradient kernel and convolve the grid image
54+
kernel = ops.run("create.img", [20,20], new FloatType())
55+
ops.image().equation(kernel, "p[0]")
56+
if (show_kernel) {
57+
ui.show("gradient kernel", kernel)
58+
}
2259

23-
ui.show("convolved", convolved_big);
60+
// convolve the grid image with the gradient kernel
61+
conv_img= ops.filter().convolve(grid_img, kernel)
62+
if (show_conv) {
63+
ui.show("convolved grid image", conv_img)
64+
}
2465

25-
// deconvolve with Richardson Lucy
26-
base_deconvolved_big=ops.create().img(convolved_big, new FloatType())
27-
base_deconvolved_big = ops.deconvolve().richardsonLucy(base_deconvolved_big, convolved_big, kernel_big, null, new OutOfBoundsConstantValueFactory<>(Util.getTypeFromInterval(kernel_big).createVariable()), 10)
66+
// deconvolve with Richardson-Lucy (RL)
67+
if (show_rl) {
68+
rl_decon_img = ops.deconvolve().richardsonLucy(conv_img, kernel, iterations)
69+
ui.show("Richardson-Lucy", rl_decon_img)
70+
}
2871

29-
// deconvolve with non-circulant Richardson Lucy
30-
base_deconvolved_big_noncirc=ops.create().img(convolved_big, new FloatType())
31-
base_deconvolved_big_noncirc = ops.deconvolve().richardsonLucy(base_deconvolved_big_noncirc, convolved_big, kernel_big, null, null, null, null, null, 50, true, false)
72+
// deconvolve with Richardson-Lucy Total Variation (RLTV)
73+
if (show_rltv) {
74+
rltv_decon_img = ops.deconvolve().richardsonLucyTV(conv_img, kernel, iterations, 0.002)
75+
ui.show("Richardson-Lucy TV", rltv_decon_img)
76+
}
3277

33-
// deconvolve with accelerated non-circulalant Richardson LUcy
34-
base_deconvolved_big_acc_noncirc=ops.create().img(convolved_big, new FloatType())
35-
base_deconvolved_big_acc_noncirc = ops.deconvolve().richardsonLucy(base_deconvolved_big_acc_noncirc, convolved_big, kernel_big, null, null, null, null, null, 50, true, true)
78+
// deconvolve with non-circulant Richardson-Lucy
79+
if (show_rl_nc) {
80+
// create the output image (empty) for the deconvlution Op
81+
rl_nc_decon_img = ops.create().img(conv_img, new FloatType())
82+
ops.deconvolve().richardsonLucy(rl_nc_decon_img,
83+
conv_img,
84+
kernel,
85+
null,
86+
null,
87+
null,
88+
null,
89+
null,
90+
iterations,
91+
true,
92+
false)
93+
ui.show("Ricahrdson-Lucy non-circulant", rl_nc_decon_img)
94+
}
3695

37-
ui.show("RL",base_deconvolved_big)
38-
ui.show("RLNon-Circ",base_deconvolved_big_noncirc)
39-
ui.show("RL Acc/Non-Circ",base_deconvolved_big_acc_noncirc)
96+
// deconvolve with accelerated non-circulalant Richardson Lucyi
97+
if (show_rl_acc_nc) {
98+
rl_acc_nc_decon_img = ops.create().img(conv_img, new FloatType())
99+
ops.deconvolve().richardsonLucy(rl_acc_nc_decon_img,
100+
conv_img,
101+
kernel,
102+
null,
103+
null,
104+
null,
105+
null,
106+
null,
107+
iterations,
108+
true,
109+
true)
110+
ui.show("Richardson-Lucy accelerated non-circulant", rl_acc_nc_decon_img)
111+
}

0 commit comments

Comments
 (0)