Identifying labels which touch the background

Identifying labels which touch the background#

In developmental biology it is a common task to differentiate layers of cells, for example in epithelial tissue. Therefore it might be useful to know if a cell is part of an outer layer, if it touches the background. In this notebook we measure and visualize this.

For demonstrating it we simulate a clumb of cells.

import pyclesperanto_prototype as cle

# import a function from a file in the same folder
from simulated_cell_clumb import simulate_data
cells = simulate_data()
cells
cle._ image
shape(200, 200)
dtypeuint32
size156.2 kB
min0.0
max41.0

Determining which cells touch the background#

To determine which cells touch the background, we need to produce a touch matrix which tells us which objects touch which others.

touch_matrix = cle.generate_touch_matrix(cells)
touch_matrix
cle._ image
shape(42, 42)
dtypefloat32
size6.9 kB
min0.0
max1.0

The first row and column in this image represent objects touching the background. We can read out this first row or column like this:

touching_background = touch_matrix[0]
touching_background
cle.array([0. 1. 1. 1. 0. 1. 1. 1. 0. 1. 0. 0. 1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1. 1.
 0. 0. 1. 0. 0. 1. 0. 1. 1. 0. 0. 1. 1. 0. 0. 1. 1. 1.], dtype=float32)

And we can visualized it in the original image coordinates.

cle.replace_intensities(cells, touching_background)
cle._ image
shape(200, 200)
dtypefloat32
size156.2 kB
min0.0
max1.0

Or we can get a label image representing those objects.

cle.exclude_labels(cle.binary_not([touching_background]), cells)
cle._ image
shape(200, 200)
dtypeuint32
size156.2 kB
min0.0
max20.0