Inspecting 3D image data with pyclesperanto#

This notebook demonstrates how to navigate through 3D images.

import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from skimage.io import imread
import stackview
# Laod example data
input_image = imread('data/Haase_MRT_tfl3d1.tif')

This image is an image stack which can be quickly visualized like this:

stackview.animate(input_image[::5,::2,::2])

Using the stackview.insight method we can quickly read image shape and intensity range. It also gives us a view of the entire dataset, an intensity projection actually.

stackview.insight(input_image)
shape(192, 256, 256)
dtypeuint8
size12.0 MB
min0
max255

Selecting slices#

In order to visualize specific slices, we can select them.

image_slice = input_image[100]

# show result
stackview.imshow(image_slice)
_images/a0193fc6d7198615470da43081ff3e5f998cffe6a114326f3977d9de5897f0c3.png

We can also do this interactively.

stackview.slice(input_image)

Intensity projections#

In order to take a look at the entire stack, we can do projections.

projection_max = input_image.max(axis=0)

stackview.imshow(projection_max)
_images/a1f1fc88705c76f88871bb70dc9b6fb00f3139ca6e5e6b245d90060404885521.png
projection_mean = input_image.mean(axis=0)

stackview.imshow(projection_mean)
_images/39006f7f7aa19fe8f7a7417c717092a4df438b56ffb587250d228f10b107ce7d.png

We can also do this in different directions

projection_mean = input_image.mean(axis=1)

stackview.imshow(projection_mean)
_images/a7f86bfef8a1c2e09cd61717dc46f2fa1793dcfa28d2eeadc1270577bd32781d.png
projection_mean = input_image.mean(axis=2)

stackview.imshow(projection_mean)
_images/ee2a885230c9c3902fe4c290e48d2c726015513352abe705d4ab09170bc09c3e.png

And we can transpose the image axes in case that’s necessary.

projection_mean = input_image.mean(axis=2).T

stackview.imshow(projection_mean)
_images/c62db3683cfc32de658e8e87c017918a9d3916be1273c2a6273b78334806fc08.png

Subplots can help us to get an overview of the dataset

fig, axs = plt.subplots(1, 3, figsize=(15, 7))
stackview.imshow(input_image[75], plot=axs[0])
stackview.imshow(input_image[100], plot=axs[1])
stackview.imshow(input_image[125], plot=axs[2])
_images/41414a32c6b0fa071e9fb5c47d46a55ac9d7642db150d695c0bee4a034a7ebb8.png

Exercise#

Crop out Robert’s nose programmatically. Hint: Use stackview.crop to navigate the dataset.

stackview.crop(input_image)