Many of CLIJ’s Kernels are integrated into ImageJ Ops. Examples in Jython are provided.
The Ops are available in ImageJ’s script editor after installing the CLIJ update site.
When calling an Op, a
CLIJService will automatically initialize CLIJ if this did not already happen. In case you want to initialize CLIJ with a custom GPU, this is the way to go:
#@CLIJService clijService clijService.get("Intel(R) HD Graphics Kabylake Desktop GT1.5");
Afterwards, you can convert images to
ClearCLBuffer objects which makes them accessible on the OpenCL device:
#@IOService io #@OpService ops input = io.open("PATH_TO_IMAGE") inputGPU = ops.run("CLIJ_push", input)
Furthermore, you can create images, for example with the same size as a given one:
targetGPU = ops.run("CLIJ_create", inputGPU)
Alternatively, create an image with a given size and a given type:
targetGPU = ops.run("CLIJ_create", [input.dimension(0), input.dimension(1), 5], inputGPU.getNativeType())
Most CLIJ Ops are hybrid, meaning they can act both as a computer and a function (see the SpecialOps JavaDoc for further details). There are no inplace operations in CLIJ.
In this example the output object will be automatically generated and returned by the Op (function):
imageOutput = ops.run("CLIJ_maximumZProjection", imageInput)
In the next example both the input and the output are created beforehand and handed to the Op (computer):
ops.run("CLIJ_maximumZProjection", imageOutput, imageInput)
CAUTION Be aware that in this case the output is the first and the input is the second parameter, in contrast to other CLIJ APIs where the order is the other way around. The next ImageJ Op generation will revert this order, meaning that the order might change in a future version of CLIJ as well.
To get the image back into
imglib2 format, call the
#@UIService ui target = ops.run("CLIJ_pull", targetGPU) ui.show(target)
After finishing imag processing, memory on GPU needs to be released explicitly:
imageInput.close(); imageOutput.close(); targetGPU.close();
More examples can be found here.