|
| 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 |
0 commit comments