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:

from import imread

image = imread('blobs.tif')

# print out the spatial dimensions of the image
(254, 256)

This little “magic” command is necessary before starting napari from notebooks.

%gui qt
import napari

# Create an empty viewer
viewer = napari.Viewer()
# Add a new layer containing an image
<Image layer 'image' at 0x24299698b80>

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

# Remove all layers to start from scratch
for l in viewer.layers:
# add the image again with a different lookup table
<Image layer 'image' at 0x2429b6598e0>

We now blur the image and put it in the viewer

from skimage.filters import gaussian
blurred_image = gaussian(image, sigma=5)

# Add to napari
<Image layer 'blurred_image' at 0x2429b7056a0>

We now apply background subtraction to the image and add it to the viewer

from skimage.morphology import white_tophat, disk
background_subtracted_image = white_tophat(image, disk(25))

# Add a new layer containing an image
<Image layer 'background_subtracted_image' at 0x2429b6c31f0>

By clicking the galery button (buttom left), we can view the different images side by side



Start a new notebook, import napari, load the image ../data/hela-cells.tif and add its three channels independently to napari as three layers. Afterwards, play with colormap and blending in the user interface. Can you make it look similar to ImageJ? Also check out the napari image layer tutorial. Can you also code this?