Interactive image visualization with napari#

napari is a python-based image viewer. Today, we will use it by remote-controlling it from a jupyter notebook.

See also

For opening an image, we still use scikit-image:

import napari

from import imread

image = imread('../../data/Haase_MRT_tfl3d1.tif')

# print out the spatial dimensions of the image
(192, 256, 256)
# Create an empty viewer
viewer = napari.Viewer()
# Add a new layer containing an image
<Image layer 'image' at 0x1d5a7bb9af0>

With this command, we can make a screenshot of napari and save it in our notebook.



We can programmatically move the Z-slice slider like this.

dims = viewer.dims.current_step
(96, 128, 128)
# modify Z-slice position
dims = list(dims)
dims[0] = 60
viewer.dims.current_step = dims

# take another screenshot

3D rendering#

We can also activate the 3D view programmatically.

viewer.dims.ndisplay = 3


Camera orientation#

For changing the camera position it is recommended to print out the camera, e.g. after a modification was done manually. This allows you to understand what center, zoom, angles etc mean. You can then modify these parameters using Python.
Camera(center=(95.5, 127.5, 127.5), zoom=2.2191406249999996, angles=(0.0, 0.0, 90.00000000000001), perspective=0.0, interactive=True) = (15, -15, 90)