CLIJ2

Logo

GPU accelerated image processing for everyone

CLIJ2 home

Classic Watershed (MorphoLibJ extension)

Author: Robert Haase, May 2021

Source

This tutorial demonstrates the use of the Classic Watershed plugin as CLIJx extension.

See also

To make this script run, please activate the update sites clij, clij2 and install the clijx-assistant-extensions in your Fiji.

We cleanup first and load the blobs image as example.

close("*");

// Init GPU
run("CLIJ2 Macro Extensions", "cl_device=");
Ext.CLIJ2_clear();

// Load image from disc 
run("Blobs (25K)");
blobs_image = getTitle();
Ext.CLIJ2_pushCurrentZStack(blobs_image);

blobs.gif

The algorithm expects a grey value image representing hills (high values, white) and valleys (low values, dark). Thus, we need to invert the input image.

// invert
Ext.CLIJ2_subtractImageFromScalar(blobs_image, inverted_image, 255);

Ext.CLIJ2_pull(inverted_image);

CLIJ2_subtractImageFromScalar_result231

Furthermore, the authors suggest to use a blurred version of the image and optionally a binary image as mask. The clijx-assistant-extension for that algorithm has the binary image as mandatory input. Thus, we need to provide it.

sigma = 4;
Ext.CLIJ2_gaussianBlur2D(inverted_image, blurred_image, sigma, sigma);
Ext.CLIJ2_pull(blurred_image);

// threshold
Ext.CLIJ2_thresholdOtsu(blobs_image, binary_image);
Ext.CLIJ2_pullBinary(binary_image);

CLIJ2_gaussianBlur2D_result232 CLIJ2_thresholdOtsu_result233

The result will be a label image.

// Classic Watershed
h_min = 1.0;
h_max = 3.4028235E38;
Ext.CLIJx_morphoLibJClassicWatershed(blurred_image, binary_image, watershed_label_image, h_min, h_max);

Ext.CLIJ2_pull(watershed_label_image);
run("glasbey_on_dark");
>   Extracting pixel values (h_min = 1.0, h_max = 255.0)...
>   Extraction took 1 ms.
>   Sorting pixels by value...
>   Sorting took 5 ms.
>   Flooding...
>   Flooding took: 4 ms
> Watershed 3d took 13 ms.

CLIJx_morphoLibJClassicWatershed_result234

Clean up by the end

Ext.CLIJ2_clear();