How to set -ve value pixels to 0 in CLIJ2

Hi @haesleinhuepf
I need to set all negative valued pixels in my image to 0.
Whats a good way to do it in CLIJ2.

In imageJ i used the threshold tool, and the min image pixel value to set a threshold on the image that includes all pixels with values from minvalue to 0, then use that to make a “selection”
then i use the Set command to fill in that selection with zeros. in javascript i looks like this:

var minTempClipZero = tempClipZero.getStatistics().min;
IJ.setThreshold(tempClipZero, minTempClipZero, 0.0);
//messageContinue(“below zeros:”, “below zeros thresholded?, Continue?”);, “Create Selection”, “”);
//messageContinue(“below zeros selected:”, “below zeros selected?, Continue?”);
// carefull: if no pixels below 0 then nothing selected and all image is set to zero!
if (minTempClipZero < -0.000000000001) {, “Set…”, “value=0.0”);

Is there an analogous way in CLIJ2?
I can’t see how to do the things that
Threshold-> Create Selection → set

Are -ve value pixels even allowed on the GPU? is it using signed integers under the hood? or floats?



1 Like

Hey Dan @chalkie666 ,

I think you’re looking for the function maximumImageAndScalar:

run("CLIJ2 Macro Extensions", "cl_device=");
Ext.CLIJ2_pushArray(source, newArray(0, -1, 5), 3, 1, 1); // width=3, height=1, depth=1
Ext.CLIJ2_maximumImageAndScalar(source, destination, 0);


Sure! You just need to make sure that the image is of the right type. Images are of the type as you push them to the GPU. Most operations produce images of the same type as given input images. If you call an operation such a the sumZProjection the result will be a 32-bit float image to avoid value clipping. Technically CLIJ supports many types ((u)int8/16/32, half-float and float). From ImageJ Macro only unsigned 8- and 16-bit integer images and 32-bit float images are supported.

Have a great weekend and let me know if this works!


1 Like