Interactive image visualization with napari

Interactive image visualization with napari#

napari is a python-based image viewer. This notebook demonstrates how to remote control it from python.

See also

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

import napari
from skimage.io import imread
import napari_segment_blobs_and_things_with_membranes as nsbatm
import napari_skimage_regionprops as nsr
# Create an empty viewer
viewer = napari.Viewer()

First we load an image and show it in the viewer.

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

viewer.add_image(image)
<Image layer 'image' at 0x1e423868df0>

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

napari.utils.nbscreenshot(viewer)

Cell segmentation#

We can also segment the nuclei and show them on top of the image.

label_image = nsbatm.voronoi_otsu_labeling(image, spot_sigma=9)

# add labels to viewer
label_layer = viewer.add_labels(label_image)

You can visualize labelled objects as overlay (per default)

napari.utils.nbscreenshot(viewer)

… or as opaque contours

label_layer.contour = 2
label_layer.opacity = 1

napari.utils.nbscreenshot(viewer)

Quantitative measurements#

We can also derive quantitative measurements and attach them to the napari viewer.

nsr.regionprops_table(image, label_image, napari_viewer=viewer)

napari.utils.nbscreenshot(viewer)
Napari status bar display of label properties disabled because https://github.com/napari/napari/issues/5417 and https://github.com/napari/napari/issues/4342