Jni & Java for Plugin Imagej

Hi !

I am Working with 3D data and I want to increase the speed of my Plugin so I decided to use JNI.

Im Searching for Help for how to create a 3D tab in C, modify the values and send it to my plugIn java.

I search also how to pick my tab in my java Plugin.

Have a great day !

Hi @Cpl-042,

may I ask how large is your 3D data? If it’s small enough to process it in the GPU, you might want to consider using clij to speed up your processing. Under the hood it uses OpenCL which is a C-dialect. Furthermore, I’d be happy to introduce you to how to program OpenCL and use your own OpenCL code from ImageJ.

Let me know if you want to know more.

Cheers,
Robert

Hi !

My images are very heavy : 120 Go for a 4000x4000x4000 image obtained per tomography !

Your tools are still usefull my type of images ?

Thansk a lot !

1 Like

If you can proccess it tile-by-tile or slice-by-slice, yes. What kind of operations are you planning to use? Do you by chance have a workflow in ImageJ which is “just slow” but does the right thing?

That’s what I will do !

I want to compute Some gaussian filter, applying several functions on my image, compute tensors and eigen / vector values.

For now, Nothing works because Im in the begining of my algorithm

I Think it may be a good thing to look at what your proposing !

1 Like

Cool! So Gaussian blur is available. Regarding Eigenvectors, I started implementing that on the GPU. Try out clij and if you’re interested, I’ll dig out the code I worked on. Would be happy to collaborate on that with someone who has a realistic use case for this. :slightly_smiling_face:

Cheers,
Robert

Im computing a different gaussian filter : a derivative one on the principal axis and simple gaussians on the others.

I Go read the documentation !

1 Like

Hi Romain ? @Cpl-042,

As mentioned by @haesleinhuepf openCL and CLIJ is the way to go, if you want to have a look to quite older JNI stuff, check the JNI version of 3D filters.

Pixels values in ImageJ are stored as 1D arrays so it is quite straightforward to use them for C processing, check ij.process.ImageProcessot.getPixels in ImageJ API.

Best,

Thomas

Hello !

So I read the doc and it seem to be easier to use than JNI but there is Some questions that I didn’t found :

  • how to install on an offline computer
  • how to manipulate my pixels in C file to be faster and bring them to my plugin
  • how managing and compiling files in C and Java Into my éclipse project

I am also very interrested to know the faster way to convert an Image under the ImagePlus type to a 1D array !

I am sorry if the answer is obvious or if I didn’t really understood how Clij works.

Have a great day.

Romain

Hey @Cpl-042,

glad to hear you’re doing a deep dive into clij. I’m here to support you.

clij and clij2 are primarily build as Fiji plugins. Thus, I’d recommend installing it to a Fiji and then shipping the Fiji installation to an offline computer. Alternatively, you can pack your clij dependent project together with clij and all its dependencies in an uber-jar and ship it to offline computers. I did this trick in the clicy and clatlab projects. It’s basically just an entry in their pom.xml files.

There is a template-plugin available for clij2, where you can input your code. Reminder: It’s OpenCL, not C :wink:
Furthermore, CLIJ brings some convenience functions (actually defines) to make OpenCL easier to use. You find a full list online.

Basically, you can build everything with maven. Just import the pom.xml in your Eclipse as project.
The OpenCL-compilation happens at runtime, because it depends on available OpenCL devices (GPUs) in the target computer. Side note: OpenCL also runs on CPUs, but one may have to install special drivers.

Not sure if this is very easy. The problem is that Java is pretty limited in array length. You can call imageplus.getProcesser().getPixels() and you will get a 1D array of the pixels of the current 2D plane. This is under the hood also used by CLIJ to push an image to GPU memory. If you want to process an image as Java 1D array slice-by-slice, you can take a look here. I can just discourage you from doing this as it results in array type specific code and likely slower than on the GPU using CLIJ.

The target audience for CLIJ was initially people who don’t want to learn OpenCL. But there is some more detailed documentation targeting people like you who want to dive into this. There is an intro for Java developers and some examples. Furthermore, you might want to read about OpenCL to get started and to get the best performance out of it.

If you have any questions, please let me know. I’d be happy to answer and take them to improve documentation.

Cheers,
Robert

1 Like