GPU accelerated image processing for everyone
Authors: Robert Haase, Daniela Vorkel, April 2020
This macro shows how to apply an automated threshold method and how to label connected components on an image using GPU.
// get test data run("Blobs (25K)"); input = getTitle();
First we initialize the GPU and push image data to the GPU memory:
run("CLIJ2 Macro Extensions", "cl_device="); Ext.CLIJ2_clear(); // push data to GPU Ext.CLIJ2_push(input); // clean up ImageJ run("Close All");
Ext.CLIJ2_automaticThreshold(input, mask, "Otsu"); Ext.CLIJ2_pull(mask);
Ext.CLIJ2_connectedComponentsLabelingBox(mask, labelmap); Ext.CLIJ2_pull(labelmap); run("glasbey on dark");
Ext.CLIJ2_excludeLabelsOnEdges(labelmap, labels_not_touching_image_borders); Ext.CLIJ2_pull(labels_not_touching_image_borders); run("glasbey on dark");
At the end of the macro, clean up:
Ext.CLIJ2_clear();