GPU accelerated image processing for everyone
This notebook demonstrates how measurements from CLIJ2 methods can be combined in ImageJs results tables.
Author: Robert Haase January 2021
// clean up first run("Close All"); run("Clear Results"); // Get test data //run("Blobs (25K)"); open("C:/structure/data/blobs.tif"); getDimensions(width, height, channels, slices, frames); input = getTitle(); makeRectangle(74, 44, 100, 100); run("Crop");
run("CLIJ2 Macro Extensions", "cl_device="); Ext.CLIJ2_clear(); Ext.CLIJ2_push(input); Ext.CLIJ2_thresholdOtsu(input, binary); Ext.CLIJ2_connectedComponentsLabeling(binary, labels); Ext.CLIJ2_pull(labels); run("glasbey_on_dark");
We perform a measurement which results in a table. To keep the resulting example table simple, we delete all columns but IDENTIFIER and MEAN_INTENSITY. Note, the first row corresponds to measurement resulting from label 0, corresponding to background.
// put many columns in Ext.CLIJ2_statisticsOfBackgroundAndLabelledPixels(input, labels); // remove all columns but one headings = split(Table.headings(), " "); for (i = 0; i < lengthOf(headings); i++) { column_name = headings[i]; if (column_name != "MEAN_INTENSITY" && column_name != "IDENTIFIER" && column_name != " ") { Table.deleteColumn(column_name); } }
IDENTIFIER | MEAN_INTENSITY |
---|---|
0 | 54.885 |
1 | 167.857 |
2 | 210.679 |
3 | 160.000 |
4 | 195.953 |
5 | 184.619 |
6 | 201.840 |
7 | 137.143 |
8 | 196.889 |
9 | 197.208 |
10 | 189.802 |
11 | 138.857 |
12 | 195.151 |
13 | 180.417 |
14 | 136.000 |
We will now measure the centroid distance of every label to the nearest neighbor and put it in the table as a new column:
// determine nearest neighbor distance Ext.CLIJ2_centroidsOfLabels(labels, centroids); Ext.CLIJ2_generateDistanceMatrix(centroids, centroids, distance_matrix); Ext.CLIJ2_averageDistanceOfNClosestPoints(distance_matrix, distance_list, 1); // save measurements to table in new column append_new_rows = false; Ext.CLIJx_pullToResultsTableColumn(distance_list, "nearest_neighbor_distance", append_new_rows);
IDENTIFIER | MEAN_INTENSITY | nearest_neighbor_distance |
---|---|---|
0 | 54.885 | 0.000 |
1 | 167.857 | 32.002 |
2 | 210.679 | 29.744 |
3 | 160.000 | 28.212 |
4 | 195.953 | 26.458 |
5 | 184.619 | 24.928 |
6 | 201.840 | 29.744 |
7 | 137.143 | 26.458 |
8 | 196.889 | 24.928 |
9 | 197.208 | 19.415 |
10 | 189.802 | 29.255 |
11 | 138.857 | 19.415 |
12 | 195.151 | 31.551 |
13 | 180.417 | 18.719 |
14 | 136.000 | 18.719 |
We will now determine if labels are on the edge of the image and add a column with 1 if the label touches an edge and 0 if not.
Ext.CLIJx_flagLabelsOnEdges(labels, flag_vector); append_new_rows = false; Ext.CLIJx_pullToResultsTableColumn(flag_vector, "is_on_image_edge", append_new_rows);
IDENTIFIER | MEAN_INTENSITY | nearest_neighbor_distance | is_on_image_edge |
---|---|---|---|
0 | 54.885 | 0.000 | 1 |
1 | 167.857 | 32.002 | 1 |
2 | 210.679 | 29.744 | 1 |
3 | 160.000 | 28.212 | 1 |
4 | 195.953 | 26.458 | 0 |
5 | 184.619 | 24.928 | 1 |
6 | 201.840 | 29.744 | 0 |
7 | 137.143 | 26.458 | 1 |
8 | 196.889 | 24.928 | 1 |
9 | 197.208 | 19.415 | 0 |
10 | 189.802 | 29.255 | 1 |
11 | 138.857 | 19.415 | 0 |
12 | 195.151 | 31.551 | 1 |
13 | 180.417 | 18.719 | 1 |
14 | 136.000 | 18.719 | 1 |
Last but not least, we clean up GPU memory :-)
Ext.CLIJ2_clear();