GPU-accelerated image processing in ImageJ using CLIJ

View the Project on GitHub clij/clij-docs

CLIJ and Imagej Ops in the Script Editor

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.

Initializing CLIJ

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");

Using Ops

Afterwards, you can convert images to ClearCLBuffer objects which makes them accessible on the OpenCL device:

#@IOService io
#@OpService ops

input ="PATH_TO_IMAGE")
inputGPU ="CLIJ_push", input)

Furthermore, you can create images, for example with the same size as a given one:

targetGPU ="CLIJ_create", inputGPU)

Alternatively, create an image with a given size and a given type:

targetGPU ="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 ="CLIJ_maximumZProjection", imageInput)

In the next example both the input and the output are created beforehand and handed to the Op (computer):"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 CLIJ_pull op:

#@UIService ui

target ="CLIJ_pull", targetGPU)

After finishing imag processing, memory on GPU needs to be released explicitly:


More examples can be found here.

Back to CLIJ documentation