In this notebook we visualize which cells in a tissue are neighbord by drawing a mesh. Furthermore, we can change the intensity of the mesh so that it corresponds to the distance between the centroids of the cells.
import pyclesperanto_prototype as cle
import numpy as np
from skimage.io import imshow
import matplotlib
Let's generate some tissue-like structure consisting of cells which typicall have 6 neighbors
# define centroids of cells
pointlist = cle.push_zyx(np.asarray(
[
[0, 100, 200, 300, 400, 50, 150, 250, 350, 0, 100, 200, 300, 400, 50, 150, 250, 350, 0, 100, 200, 300, 400],
[0, 0, 0, 0, 0, 40, 40, 40, 40, 80, 80, 80, 80, 80, 120, 120, 120, 120, 160, 160, 160, 160, 160]
]))
print(pointlist)
[[ 0. 100. 200. 300. 400. 50. 150. 250. 350. 0. 100. 200. 300. 400. 50. 150. 250. 350. 0. 100. 200. 300. 400.] [ 0. 0. 0. 0. 0. 40. 40. 40. 40. 80. 80. 80. 80. 80. 120. 120. 120. 120. 160. 160. 160. 160. 160.]]
# generate an image where the centroid are labelled (labelled spots image)
labelled_spots = cle.pointlist_to_labelled_spots(pointlist)
imshow(cle.pull_zyx(labelled_spots))
c:\users\rober\miniconda3\lib\site-packages\pyopencl\__init__.py:252: CompilerWarning: Non-empty compiler output encountered. Set the environment variable PYOPENCL_COMPILER_OUTPUT=1 to see more. warn("Non-empty compiler output encountered. Set the " c:\users\rober\miniconda3\lib\site-packages\skimage\io\_plugins\matplotlib_plugin.py:150: UserWarning: Low image data range; displaying image with stretched contrast. lo, hi, cmap = _get_display_range(image) c:\users\rober\miniconda3\lib\site-packages\skimage\io\_plugins\matplotlib_plugin.py:150: UserWarning: Float image out of standard range; displaying image with stretched contrast. lo, hi, cmap = _get_display_range(image)
<matplotlib.image.AxesImage at 0x267e4368be0>
# extend the spots to make some artificial tissue image (label image)
cells = cle.extend_labeling_via_voronoi(labelled_spots)
cmap = matplotlib.colors.ListedColormap ( np.random.rand ( 256,3))
imshow(cle.pull_zyx(cells), cmap=cmap)
c:\users\rober\miniconda3\lib\site-packages\pyopencl\__init__.py:252: CompilerWarning: Non-empty compiler output encountered. Set the environment variable PYOPENCL_COMPILER_OUTPUT=1 to see more. warn("Non-empty compiler output encountered. Set the "
<matplotlib.image.AxesImage at 0x267e44bd580>
pointlist = cle.label_centroids_to_pointlist(cells)
print(pointlist)
[[ 13.554028 100. 200. 300. 386.44598 50. 150. 250. 350. 13.57647 100. 200. 300. 386.42352 50. 150. 250. 350. 13.845719 100. 200. 300. 386.15427 ] [ 15.785854 15.711423 15.711423 15.711423 15.785854 39.46 39.46 39.46 39.46 79.460785 79.46 79.46 79.46 79.460785 119.65166 119.65166 119.65166 119.65166 143.8476 143.92326 143.92326 143.92326 143.8476 ]]
touch_matrix = cle.generate_touch_matrix(cells)
imshow(cle.pull_zyx(touch_matrix))
<matplotlib.image.AxesImage at 0x267e4565b50>
mesh = cle.touch_matrix_to_mesh(pointlist, touch_matrix)
imshow(cle.pull_zyx(mesh))
<matplotlib.image.AxesImage at 0x267e45bbaf0>
number_of_touching_neighbors_vector = cle.count_touching_neighbors(touch_matrix)
print(number_of_touching_neighbors_vector)
[[0. 2. 3. 3. 3. 2. 5. 5. 5. 5. 4. 6. 6. 6. 4. 5. 5. 5. 5. 2. 3. 3. 3. 2.]]
# visualize in a parametric image
parametric_image = cle.replace_intensities(cells, number_of_touching_neighbors_vector)
imshow(cle.pull_zyx(parametric_image))
<matplotlib.image.AxesImage at 0x267e4622190>
# Alternatively, in very short:
parametric_image = cle.touching_neighbor_count_map(cells)
imshow(cle.pull_zyx(parametric_image))
<matplotlib.image.AxesImage at 0x267e46c0ca0>