Inspecting 3D image data with pyclesperanto#
This notebook demonstrates how to navigate through 3D images.
import pyclesperanto_prototype as cle
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from skimage.io import imread
# Laod example data
input_image = imread('../../data/Haase_MRT_tfl3d1.tif')
Copy Slice#
In order to visualize crop specific slices; without the image leaving GPU memory, use the copy_slice
method.
# Copy Slice
image_slice = cle.create([256, 256]);
slice_z_position = 40.0;
cle.copy_slice(input_image, image_slice, slice_z_position)
# show result
cle.imshow(image_slice)
![../_images/c60c6141e977151383e4e4988e95e2b2a8a313b44d0ead1d5e0cbcf484394c62.png](../_images/c60c6141e977151383e4e4988e95e2b2a8a313b44d0ead1d5e0cbcf484394c62.png)
# Alternatively, don't hand over the output image and retrieve it
another_slice = cle.create_2d_xy(input_image)
cle.copy_slice(input_image, another_slice, slice_index = 80)
# show result
cle.imshow(another_slice)
![../_images/94d2e1e1937c5fe79debe6f4cc905a8a4f9415fbce9ee61f1b66bdc05012264b.png](../_images/94d2e1e1937c5fe79debe6f4cc905a8a4f9415fbce9ee61f1b66bdc05012264b.png)
Projection#
pyclesperanto offers min/mean/max and sum projections in x, y and z.
# Maximum Z Projection
projection = cle.maximum_z_projection(input_image)
# show result
cle.imshow(projection)
![../_images/d8f11fbbae3f5e1e60dde436a78650ecc23e15279f1765bc78de1dc6c6bfe485.png](../_images/d8f11fbbae3f5e1e60dde436a78650ecc23e15279f1765bc78de1dc6c6bfe485.png)
If you pass an image stack to cle.imshow
it will make the maximum intensity projection along Z for you:
cle.imshow(input_image)
![../_images/d8f11fbbae3f5e1e60dde436a78650ecc23e15279f1765bc78de1dc6c6bfe485.png](../_images/d8f11fbbae3f5e1e60dde436a78650ecc23e15279f1765bc78de1dc6c6bfe485.png)
# Sum Z Projection
projection = cle.sum_z_projection(input_image)
# show result
cle.imshow(projection)
![../_images/0816d14fa0c366e9c64d3556f28333dfbe6128ee76e5347ec2a7b9fe6ce35309.png](../_images/0816d14fa0c366e9c64d3556f28333dfbe6128ee76e5347ec2a7b9fe6ce35309.png)
# Mean Y Projection
projection = cle.mean_y_projection(input_image)
# show result
cle.imshow(projection)
![../_images/651b6c99f2ac893b51f41872b1e6fbb4d58e1b34b378fd3f483faadd2f67d2ae.png](../_images/651b6c99f2ac893b51f41872b1e6fbb4d58e1b34b378fd3f483faadd2f67d2ae.png)
Transpose XZ#
In order to transpose axes of images in the GPU, use the transpose methods
# Transpose X against Z
transposed_image = cle.create([256, 256, 129]);
cle.transpose_xz(input_image, transposed_image)
# show result
cle.imshow(transposed_image[126])
cle.imshow(transposed_image[98])
![../_images/e97110ffe1a16f851b0206a58dcb1a6d09d3dcc80b6d9f2dc5319d6b87e9d93b.png](../_images/e97110ffe1a16f851b0206a58dcb1a6d09d3dcc80b6d9f2dc5319d6b87e9d93b.png)
![../_images/44ea47c8299b20c9c33cd7067d72806bcaeeae466cc49f3fdda93c67a9abfaa8.png](../_images/44ea47c8299b20c9c33cd7067d72806bcaeeae466cc49f3fdda93c67a9abfaa8.png)
Use subplots to but them side by side
fig, axs = plt.subplots(1, 4, figsize=(15, 7))
cle.imshow(transposed_image[75], plot=axs[0])
cle.imshow(transposed_image[100], plot=axs[1])
cle.imshow(transposed_image[125], plot=axs[2])
cle.imshow(transposed_image[150], plot=axs[3])
![../_images/c7f6aa8ebe01402e92cd9a40e380bf9cf1b1febdd7a6e15069da4e5756ff6e04.png](../_images/c7f6aa8ebe01402e92cd9a40e380bf9cf1b1febdd7a6e15069da4e5756ff6e04.png)