CLIJ2

Logo

GPU accelerated image processing for everyone

CLIJ2 home

Working with spots, pointlists, matrixes and tables

Authors: Robert Haase, Daniela Vorkel, April 2020

Source

This macro demonstrates how to operate on spot images, pointlists, distance matrices and touch matrices in the GPU.

</pre>

Initialize GPU

// init GPU
run("CLIJ2 Macro Extensions", "cl_device=[GeForce RTX 2060 SUPER]");
Ext.CLIJ2_clear();

run("Close All");

Define a small array representing a spot detection result and push it to the GPU

array = newArray(
	0, 0, 0, 0, 0,
	0, 0, 1, 0, 1,
	0, 1, 0, 0, 0,
	0, 0, 0, 1, 0,
	1, 0, 0, 0, 0);

width = 5;
height = 5;
depth = 1;

Ext.CLIJ2_pushArray(spots_image, array, width, height, depth);
Ext.CLIJ2_pull(spots_image);
zoom(100);

CLIJ2_pushArray_result119-1

Convert the spot image into a point list

Ext.CLIJ2_spotsToPointList(spots_image, pointlist);
Ext.CLIJ2_pull(pointlist);
zoom(100);

CLIJ2_spotsToPointList_result120-1

Determine the distance between all spots and write the result as distance matrix.

Ext.CLIJ2_generateDistanceMatrix(pointlist, pointlist, distance_matrix);
Ext.CLIJ2_pull(distance_matrix);
zoom(100);

CLIJ2_generateDistanceMatrix_result121-1

Label all spots

Ext.CLIJ2_labelSpots(spots_image, labelled_spots);
Ext.CLIJ2_pull(labelled_spots);
zoom(100);
run("glasbey_on_dark");

CLIJ2_labelSpots_result122-1

Blow labels up, until they touch (similar to Voronoi diagram)

Ext.CLIJ2_labelVoronoiOctagon(labelled_spots, label_voronoi);
Ext.CLIJ2_pull(label_voronoi);
zoom(100);

CLIJ2_labelVoronoiOctagon_result123-1

Analyze touching labels and save it as a touch matrix

Ext.CLIJ2_generateTouchMatrix(label_voronoi, touch_matrix);
Ext.CLIJ2_pull(touch_matrix);
zoom(100);

CLIJ2_generateTouchMatrix_result124-1

Count neighbors for every touching node

Ext.CLIJ2_countTouchingNeighbors(touch_matrix, count_vector);
Ext.CLIJ2_pull(count_vector);
zoom(100);

CLIJ2_countTouchingNeighbors_result125-1

Get pixel statistics from the labelled image

run("Clear Results");
Ext.CLIJ2_statisticsOfLabelledPixels(spots_image, label_voronoi);

IDENTIFIERBOUNDING_BOX_XBOUNDING_BOX_YBOUNDING_BOX_ZBOUNDING_BOX_END_XBOUNDING_BOX_END_YBOUNDING_BOX_END_ZBOUNDING_BOX_WIDTHBOUNDING_BOX_HEIGHTBOUNDING_BOX_DEPTHMINIMUM_INTENSITYMAXIMUM_INTENSITYMEAN_INTENSITYSUM_INTENSITYSTANDARD_DEVIATION_INTENSITYPIXEL_COUNTSUM_INTENSITY_TIMES_XSUM_INTENSITY_TIMES_YSUM_INTENSITY_TIMES_ZMASS_CENTER_XMASS_CENTER_YMASS_CENTER_ZSUM_XSUM_YSUM_ZCENTROID_XCENTROID_YCENTROID_ZSUM_DISTANCE_TO_MASS_CENTERMEAN_DISTANCE_TO_MASS_CENTERMAX_DISTANCE_TO_MASS_CENTERMAX_MEAN_DISTANCE_TO_MASS_CENTER_RATIOSUM_DISTANCE_TO_CENTROIDMEAN_DISTANCE_TO_CENTROIDMAX_DISTANCE_TO_CENTROIDMAX_MEAN_DISTANCE_TO_CENTROID_RATIO
1100210221010.33310.47132102105101.6670.33302.4140.8051.4141.7571.9620.6540.7451.140
2300410221010.25010.433441041014203.5000.50003.4140.8541.4141.6572.8280.7070.7071.000
3000120231010.20010.40051201202600.4001.20005.6501.1302.2361.9794.2390.8481.2651.492
4220440331010.11110.3149330330272703.0003.00009.6571.0731.4141.3189.6571.0731.4141.318
5030140221010.25010.433404004021400.5003.50003.4140.8541.4141.6572.8280.7070.7071.000

Push the results table as an image to the GPU

Ext.CLIJ2_pushResultsTable(table_image);
Ext.CLIJ2_pull(table_image);
zoom(100);

CLIJ2_pushResultsTable_result126-1

Push a single column of the results table to the GPU

Ext.CLIJ2_pushResultsTableColumn(mean_intensity_vector, "MEAN_INTENSITY");
Ext.CLIJ2_pull(mean_intensity_vector);
zoom(100);

CLIJ2_pushResultsTableColumn_result127-1

Multiply the pointlist with a scalar to get points virtually more distant

zoom_factor = 100;
Ext.CLIJ2_multiplyImageAndScalar(pointlist, pointlist_multiplied, zoom_factor);
Ext.CLIJ2_pull(pointlist_multiplied);
zoom(100);

CLIJ2_multiplyImageAndScalar_result128-1

Draw a mesh of touching neighbors and corresponding spots

Ext.CLIJ2_create2D(mesh, width * zoom_factor, height * zoom_factor, 32);
Ext.CLIJ2_touchMatrixToMesh(pointlist_multiplied, touch_matrix, mesh);
Ext.CLIJ2_pull(mesh);

CLIJ2_create2D_result129

Draw a mesh showing shorter edges than from given value

Ext.CLIJ2_create2D(mesh2, width * zoom_factor, height * zoom_factor, 32);
Ext.CLIJ2_distanceMatrixToMesh(pointlist_multiplied, distance_matrix, mesh2, 2.5);
Ext.CLIJ2_pull(mesh2);

CLIJ2_create2D_result130

At the end of the macro, clean up:

Ext.CLIJ2_clear();

This is just a useful function to get a nice visualization in the notebook:

function zoom(factor) {
	getDimensions(width, height, channels, slices, frames);
	before = getTitle();	
	run("Scale...", "x=" + factor + " y=" + factor + " width=" + (width * factor) + " height=" + (height* factor) + " interpolation=None average create");
	selectWindow(before);
	close();
}