Count proximal labels in an other label image

Count proximal labels in an other label image#

import numpy as np
import pyclesperanto_prototype as cle

cle.get_device()
<gfx90c on Platform: AMD Accelerated Parallel Processing (2 refs)>

Our starting point is a label image and another label image, where some of the labels in the first image are selected from.

label_image = cle.artificial_tissue_2d()
cle.imshow(label_image, labels=True)
../_images/5aab384f2d6305ca2a62b8fbc42a1b9a9bba3b039774c6c64b34e02a0325804a.png
random_vector = np.random.random((1, int(label_image.max() + 1)))
sparse_labels = cle.exclude_labels_with_values_out_of_range(random_vector, label_image, minimum_value_range=0, maximum_value_range=0.3)
cle.imshow(sparse_labels, labels=True)
../_images/133c9aff8a4170f89b7f852e8faaa036925dfc855cd867817d7f3173c400bd6a.png

We now count for every label in label_image, how many labels are proximal to it in the sparse_labels image. For measuring the distance, we use the centroid distance.

count_map = cle.proximal_other_labels_count_map(label_image, sparse_labels, maximum_distance=25)
cle.imshow(count_map)
../_images/0542f63c53ee6ea451437919108f808454db88ae44aa046c04bd5a981d0c8f9c.png