Clij results as black images

Hello,
I am starting to use some functions of Clij2 in Fiji and got several times as a result images that are only black (value of Pixel NaN). To test it more I ran the macro example from Robert Haase on Tribolium morphometry, and there, all of the result windows after the distance mesh image window also appeared black. Is there some setting somewhere that I should change?
Thank you!
Prisca

Hey @prisca,

that’s unfortunate :pensive: Would you mind sharing some details about your computer? What graphics card are you using and on which operating system?

Furthermore, please execute these two scripts and tell me what the output:

Thanks for your patience :slightly_smiling_face:

Cheers,
Robert

Hello Robert,
These are the specifications of the graphic card and processor I am using here:
NVDIA GeForce RTX2080 Ti,
AMD Ryzen 72700X Eight-core processor, 3.70 GHz,
RAM 128GB

And the Results obtained when running both macros:
CPU mean filter no 1 took 957 msec
CPU mean filter no 2 took 968 msec
CPU mean filter no 3 took 1007 msec
CPU mean filter no 4 took 955 msec
CPU mean filter no 5 took 961 msec
CPU mean filter no 6 took 973 msec
CPU mean filter no 7 took 967 msec
CPU mean filter no 8 took 1002 msec
CPU mean filter no 9 took 957 msec
CPU mean filter no 10 took 967 msec
Pushing one image to the GPU took 27 msec
CLIJ2 GPU mean filter no 1 took 7 msec
CLIJ2 GPU mean filter no 2 took 6 msec
CLIJ2 GPU mean filter no 3 took 5 msec
CLIJ2 GPU mean filter no 4 took 7 msec
CLIJ2 GPU mean filter no 5 took 6 msec
CLIJ2 GPU mean filter no 6 took 6 msec
CLIJ2 GPU mean filter no 7 took 7 msec
CLIJ2 GPU mean filter no 8 took 7 msec
CLIJ2 GPU mean filter no 9 took 7 msec
CLIJ2 GPU mean filter no 10 took 6 msec
CLIJ GPU mean filter no 1 took 8 msec
CLIJ GPU mean filter no 2 took 7 msec
CLIJ GPU mean filter no 3 took 7 msec
CLIJ GPU mean filter no 4 took 7 msec
CLIJ GPU mean filter no 5 took 8 msec
CLIJ GPU mean filter no 6 took 8 msec
CLIJ GPU mean filter no 7 took 8 msec
CLIJ GPU mean filter no 8 took 7 msec
CLIJ GPU mean filter no 9 took 8 msec
CLIJ GPU mean filter no 10 took 7 msec
Pulling one image from the GPU took 59 msec
GPU: GeForce RTX 2080 Ti
Memory in GB: 11
OpenCL version: 1.2

    LocalMemorySizeInBytes: 49152
    MaxMemoryAllocationSizeInBytes: 2952790016
    MaxWorkGroupSize: 1024
    Compatible image types: [SignedNormalizedInt8, SignedNormalizedInt16, UnsignedNormalizedInt8, UnsignedNormalizedInt16, SignedInt8, SignedInt16, SignedInt32, UnsignedInt8, UnsignedInt16, UnsignedInt32, HalfFloat, Float]

Best GPU device for images: GeForce RTX 2080 Ti
Best largest GPU device: GeForce RTX 2080 Ti
Best CPU device: GeForce RTX 2080 Ti

Thanks!

Hey @prisca,

cool, I’m working with the same GPU over here so I’m prettty sure we can make it work on your side.

Step by step. If I execute this code

close("*");

run("Blobs (25K)");
run("CLIJ2 Macro Extensions", "cl_device=[GeForce RTX 2080 Ti]");

// gaussian blur
image1 = "blobs.gif";
Ext.CLIJ2_push(image1);
image2 = "gaussian_blur1915207998";
sigma_x = 2.0;
sigma_y = 2.0;
Ext.CLIJ2_gaussianBlur2D(image1, image2, sigma_x, sigma_y);
Ext.CLIJ2_pull(image2);

It shows that:

Does it work on your computer as well?

I forgot to write: the result of the filtering of the brain images appeared as visible images in that case.
thank you,
Prisca

Ok, can you provide a detailed description or executable code snippet that does not work?

Ah ok. I can reproduce that. It appears to be a bug. Stay tuned :slight_smile:

OK, yes, I tried again and the problem starts from line 139.
I got such black images when trying i.e “draw distance mesh between touching labels” with an image containing 3D labels (touching).
Thank you.

There is a division by zero in the determination of distances toward background. Thus, the stack distance_map is ok, but the maximum projection afterwards fails, because some pixels are NaNs.

That’s new obviously. I’m about to figure out when this “bug” was introduced.

You mentioned other scenarios where this happens. Are they also related to neighbor distance analysis?

Thanks for the support!

Ok, I checked the math inside clij carefully and conclude that this was a bug in the example code. What I did here, I eliminated “touches” with the background. I usually do such things to prevent further analysis to be harmed by the existence of the background label. Typically, one is not interested of the distance of any cell centroid with the background centroid position. However, this resulted in image stacks with NaN pixels. The maximum projection decides to show NaN as the maximum intensity along Z. That’s different in ImageJ, but I’d rather say correct. To make a long story short. I adapted the example code to treat the distances to background a bit differently.

Are you also using the maximum projection to visualise the labels? Try setting the measurement in column 0 (corresponding to background) to 0 to ignore NaN distances to background.
Ext.CLIJ2_setColumn(distances_vector, 0, 0);

Let me know if you have any further issues. I’m happy to assist. And thanks again for the feedback :slight_smile: