Skip to content

Instantly share code, notes, and snippets.

@haesleinhuepf
Created September 6, 2020 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haesleinhuepf/734c58c944bdde703cdd47d03a0435d6 to your computer and use it in GitHub Desktop.
Save haesleinhuepf/734c58c944bdde703cdd47d03a0435d6 to your computer and use it in GitHub Desktop.
run("Close All");
run("Image Sequence...", "open=[C:/Users/rober/Downloads/FIB-SEM images-20200906T073825Z-001/FIB-SEM images/pores_in _calcite_022.tif] sort");
// invert image and LUT to make a binary image with (true=255, false=0)
run("Invert", "stack");
run("Invert LUT");
// init GPU
run("CLIJ2 Macro Extensions", "cl_device=RTX");
Ext.CLIJ2_clear();
// push image to GPU memory
binary = getTitle();
Ext.CLIJ2_push(binary);
// connected components labeling
Ext.CLIJ2_connectedComponentsLabelingBox(binary, labels);
Ext.CLIJ2_pull(labels);
// extend the labels with a given radius
radius = 100;
larger_labels = "larger_labels";
Ext.CLIJx_extendLabelsWithMaximumRadius(labels, larger_labels, radius);
Ext.CLIJ2_pull(larger_labels);
// determine which labels are touching
Ext.CLIJ2_generateTouchMatrix(larger_labels, touch_matrix);
// determine how many touching neighbors each label has
Ext.CLIJ2_countTouchingNeighbors(touch_matrix, touching_neighbors_count);
// set number of neighbors for background = 0
Ext.CLIJ2_setColumn(touching_neighbors_count, 0, 0);
// visualize touch count in colours
parametric_image = "parametric_image";
Ext.CLIJ2_replaceIntensities(labels, touching_neighbors_count, parametric_image);
Ext.CLIJ2_pull(parametric_image);
setMinAndMax(0, 16);
run("16_colors");
// read out positions from labels
Ext.CLIJ2_centroidsOfBackgroundAndLabels(labels, coordinate_list);
// put positions and neighbor count in one table/image
Ext.CLIJ2_getDimensions(coordinate_list, number_of_points, dimensionality, _);
Ext.CLIJ2_create2D(vertical_table, number_of_points, dimensionality + 1, 32);
Ext.CLIJ2_paste2D(coordinate_list, vertical_table, 0, 0);
Ext.CLIJ2_paste2D(touching_neighbors_count, vertical_table, 0, dimensionality);
// rotate vector so that touch-count sits in lines, not in rows:
Ext.CLIJ2_transposeXY(vertical_table, smal_table);
// show table
run("Clear Results");
Ext.CLIJ2_pullToResultsTable(smal_table);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment