CLIJ2

Logo

GPU accelerated image processing for everyone

CLIJ2 home

Labelling

Authors: Robert Haase, Daniela Vorkel, April 2020

Source

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();

blobs.gif

Initialize GPU

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");

Create a mask using a fixed threshold

Ext.CLIJ2_automaticThreshold(input, mask, "Otsu");
Ext.CLIJ2_pull(mask);

CLIJ2_automaticThreshold_result37

Label connected components

Ext.CLIJ2_connectedComponentsLabelingBox(mask, labelmap);

Ext.CLIJ2_pull(labelmap);
run("glasbey on dark");

CLIJ2_connectedComponentsLabelingBox_result38

Remove labels touching image borders

Ext.CLIJ2_excludeLabelsOnEdges(labelmap, labels_not_touching_image_borders);
Ext.CLIJ2_pull(labels_not_touching_image_borders);
run("glasbey on dark");

CLIJ2_excludeLabelsOnEdges_result39

At the end of the macro, clean up:


Ext.CLIJ2_clear();