clij / clij/clijpy

Multiple issues with demo

Open
#2 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
10
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Hi,

first of all, thanks for the effort of making Clij available in Python. I tried it in Fiji and was amazed at the speed increase and thus wanted to see if I could use it in Python as well. Installation worked without problem on OSX (10.13.6) but it took me a while then to get code to run properly. All this is based on the demo examples provided. I had a series of issues but I think they all come from the fact that probably I'm not importing the right libraries. Anyway, I'll just describe my issues and explain how I solved them.

1. The examples all import the CLIJx class. But it does not seem to exist. The only thing that works for me is CLIJPY. I also tried CLIJ2 which exists but doesn't seem to have the same methods.
2. When attempting to copy data into an array I get that ```'net.haesleinhuepf.clijpy.CLIJPY' object has no attribute 'copy'``` so I just used the push method instead.
3. ```clijx.blur``` doesn't exist, so I used ```clijx.op.blur```
4. When calling the blur method like this ```clijx.op.blur(input, blurred, 5, 5, 0);``` it says no method matching your arguments. I somehow found out that I could replace the numbers by ```clijx.op.blur(input, blurred, Float(5), Float(5), Float(0));```

With all these changes I get the following working code that does work and produce a blurred image:

```python
# init pyimage to get access to jar files
import imagej
ij = imagej.init('/Applications/Fiji.app/')
ij.getVersion()

# load some image data
from skimage import io
sk_img = io.imread('https://samples.fiji.sc/blobs.png')

# init clijpy to get access to the GPU
from jnius import autoclass

CLIJpy = autoclass('net.haesleinhuepf.clijpy.CLIJPY')
clijx = CLIJpy.getInstance();

Float = autoclass('java.lang.Float')
Int = autoclass('java.lang.Integer')

# convert and array to an ImageJ2 img:
import numpy as np
np_arr = np.array(sk_img)
ij_img = ij.py.to_java(np_arr)

# push the image to the GPU
input8 = clijx.push(ij_img)

# reserve memory for output, same size and type as input
blurred = clijx.create(input8.getDimensions());

# blur, threshold and label the image
clijx.op.blur(input8, blurred, Float(10), Float(10), Float(0));

# pull image back from GPU
ij_img_result = clijx.pull(blurred);
# convert to numpy/python
np_arr_result = ij.py.rai_to_numpy(ij_img_result);
```
I'm just curious where I went completely wrong. When doing a few tests I noticed that while the blurring is indeed much faster with clijpy than the classic skimage, what takes a lot of time is the conversion done by ```rai_to_numpy```. Is that expected? Unfortunately this last step is so slow that it seems to make the effective gain in time of the GPU processing vanish.

I hope there's a simple explanation for these issues and maybe there's a way to make the numpy conversion faster!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.