Neighbor meshes in three dimensions#

The neighbor meshes we worked with in this chapter in general also work in three dimensions. It is just more challenging to visualize those.

from skimage.io import imread
import pyclesperanto_prototype as cle
import matplotlib.pyplot as plt

The image data we use here shows a crop of a developing Tribolium castaneum embryo imaged using light sheet microscopy by Daniela Vorkel, Myers lab, MPI-CBG / CSBD Dresden.

raw_image = imread("../../data/Lund_000500_resampled-cropped.tif")

raw_image.shape
(100, 256, 256)

For the ease-of-use we write a short function for visualizing our image stack in three maximum projections from different persepctives.

def orthogonal_show(image, labels=False):

    fig, axs = plt.subplots(1, 3, figsize=(15, 7))

    cle.imshow(cle.maximum_x_projection(image), plot=axs[0], labels=labels)
    cle.imshow(cle.maximum_y_projection(image), plot=axs[1], labels=labels)
    cle.imshow(cle.maximum_z_projection(image), plot=axs[2], labels=labels)
    
    axs[0].set_title("Maximum intensity along X")
    axs[1].set_title("Maximum intensity along Y")
    axs[2].set_title("Maximum intensity along Z")

orthogonal_show(raw_image)
../_images/b30c38082371b1233ce76cfbb27dee1cf2952fc27e8cdae0742bed8a47ec95eb.png

We can now segment nuclei in our our dataset.

background_subtracted = cle.top_hat_box(raw_image, radius_x=5, radius_y=5, radius_z=5)

nuclei = cle.voronoi_otsu_labeling(background_subtracted)

orthogonal_show(nuclei, labels=True)
../_images/09b7fd4ce227c904cd560e13ba06cd1f7c85ea01da6189764f7f270307ba4d26.png

After segmentation, we expand the labels a bit so they touch.

expanded_nuclei = cle.dilate_labels(nuclei, radius=4)

orthogonal_show(expanded_nuclei, labels=True)
../_images/bb02d3d920d14cc47faf7b78f172a7a46dac5f741ab9f3c0c10aa5ddecbc609d.png

And then, we can visualize a (centroid) distance mesh between touching neighbors.

mesh = cle.draw_distance_mesh_between_touching_labels(expanded_nuclei)

orthogonal_show(mesh)
../_images/a068cfcf93ddeb33777aa30622c4d19788275a8fb685cb27dbd6c40cf5088d0f.png