Skip to content

Commit 4a90c30

Browse files
committed
Add gaussian subtraction scijava ops example
1 parent 1dade99 commit 4a90c30

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
=========================
2+
Gaussian blur subtraction
3+
=========================
4+
5+
In this example we will use SciJava Ops to open an image, apply a guassian blur and subract the blurred image from the input image.
6+
This technique can be used to extract features, such as puncta, from a noisy background.
7+
8+
SciJava Ops via Fiji's sripting engine with `script parameters`_:
9+
10+
.. tabs::
11+
12+
.. code-tab:: groovy
13+
14+
#@ ImgPlus img
15+
#@ Double (label="Sigma:", value=5.0) sigma
16+
#@output ImgPlus result
17+
18+
import org.scijava.ops.api.OpEnvironment
19+
import net.imglib2.type.numeric.real.FloatType
20+
21+
// build the Ops environment
22+
ops = OpEnvironment.build();
23+
24+
// convert input ImgPlus image to float32
25+
img = ops.op("convert.float32").arity1().input(img).apply();
26+
27+
// create gaussian blurred image
28+
img_gauss = ops.op("filter.gauss").arity2().input(img, sigma).apply();
29+
30+
// subtract the input and blurred images
31+
result = ops.op("create.img").arity2().input(img, new FloatType()).apply();
32+
ops.op("math.sub").arity2().input(img, img_gauss).output(result).compute();
33+
34+
.. code-tab:: python
35+
36+
#@ ImgPlus img
37+
#@ Double (label="Sigma:", value=5.0) sigma
38+
#@output ImgPlus result
39+
40+
from org.scijava.ops.api import OpEnvironment
41+
from net.imglib2.type.numeric.real import FloatType
42+
43+
# build the Ops environment
44+
ops = OpEnvironment.build()
45+
46+
# convert input ImgPlus image to float32
47+
img = ops.op("convert.float32").arity1().input(img).apply()
48+
49+
# create gaussian blurred image
50+
img_gauss = ops.op("filter.gauss").arity2().input(img, sigma).apply()
51+
52+
# subtract the input and blurred images
53+
result = ops.op("create.img").arity2().input(img, FloatType()).apply()
54+
ops.op("math.sub").arity2().input(img, img_gauss).output(result).compute()
55+
56+
.. _`script parameters`: https://imagej.net/scripting/parameters

docs/ops/doc/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ The combination of these libraries allows declarative image analysis workflows,
2525
ScriptingInImageJ2
2626
Benchmarks
2727

28+
.. toctree::
29+
:maxdepth: 2
30+
:caption: ⚙️ Examples
31+
32+
examples/example_gaussian_subtraction
33+
2834
.. toctree::
2935
:maxdepth: 2
3036
:caption: 🛠️ Development

0 commit comments

Comments
 (0)