Quick start#

About napari#

napari is a fast, interactive, multi-dimensional image viewer, with a vibrant plugin ecosystem that expands its capability to tackle various domain-specific visualization and analysis needs. It is built on Qt (for the GUI), vispy (for performant GPU-based rendering), and the scientific Python stack (numpy, scipy, and scikit-image).

napari is an open source project on GitHub to facilitate transparency, reuse, and extensibility.

At its core, it provides critical viewer features out-of-the-box, such as support for large multi-dimensional data; “layers” to simultaneously visualize images, models, and analysis results; and easy manual, interactive annotation in 3D.

What’s covered here#

This tutorial is for napari first-timers to give them a quick glance of what napari does, and give it a try right away. We will cover:

  • Installation

  • Open napari

  • Open an image

  • Image display adjustment

  • Manually label the cell

  • Get the cell area measurement

  • Next steps

Along the way, you will see how to access napari functions from Python code and from GUI - though for different purposes, one method might be easier than another. This quick start guide will not cover ALL possible methods but only some ways to perform basic tasks. For the more complete guide, please visit our usage guide.

You will also see some examples of plugins. The core napari viewer focuses on domain-agnostic functions such as layer controls. Analyses and domain specific functions, such as reading a special file format and image segmentation, live in the realm of plugins.

Installation#

If you run into any issues, please visit the more detailed installation guide, or report an issue on GitHub!

Open napari#

napari can be opened in one of multiple ways, depending on how it’s used in your image analysis workflow.

Here we will be mainly focused on the GUI application.

  • From command line:

    Once installed, run

napari
  • If you installed the bundled app:

    Click on the app icon to open it.

    Note: macOS users might need to right click on the app icon and select “Open” to bypass the security check. You can also go to System Settings > Privacy & Security and click on “Open Anyway”.

Open an image#

napari natively supports tiff and many other formats supported by skimage.io.imread as input image file format.

Try with your own images or download this ome tiff file.

Additional input file formats may be supported by plugins. Try napari-aicsimageio if you have czi, lif, or nd2 files.

Once you have the proper plugin installed, use File > Open Files(s) and select the image file, or simply drag and drop the image into napari.

For demo purpose, we will use a sample image that comes with napari.

  1. Open napari IPython console

IPython console

  1. Type

from skimage import data
viewer.add_image(data.cell(), name='cell')
MESA: error: ZINK: vkCreateInstance failed (VK_ERROR_INCOMPATIBLE_DRIVER)
glx: failed to create drisw screen
image of a single cell opened in napari viewer

Note

Once you have a napari viewer open, you can also make a new Image layer from an image (or URL to an image) copied to your Clipboard using File -> New Image from Clipboard menu item (keybinding Command/Ctrl+N).

Image display adjustment#

The layer controls panel at the upper left of the viewer allows you to adjust contrast, colormap, and other layer properties. These settings affect the visualization, but do not affect the underlying data.

To change the image display through the API, in IPython console, type

viewer.layers['cell'].colormap = "yellow"
image of singular cell with yellow tint

Manually label the cell#

To measure the area of the cell, we can use a labels layer and manually “paint” the cell. The labels layer allows you to record the segmentation result by assigning background = 0, and assigning each object with an integer.

  1. Add a new labels layer

  2. Click on “paint”

  3. Circle the cell

  4. Use “fill” bucket to fill it.

Tip

To switch to a new, unique label – one larger than the current largest label – press the default keybinding m.

Several plugins can perform automatic segmentation that takes image layers as input and generates labels layers as output.

Try cellpose-napari if you have cell images.

Get the cell area measurement#

To analyze labels our layer, we can use scikit-image, a popular Python library that comes with your napari installation. skimage.measure.regionprops provides a good set of features that can be extracted from labels, including area measurement.

In IPython console, type

from skimage.measure import regionprops
props = regionprops(viewer.layers['Labels'].data)
print("the cell area is: ", props[0].area)

Alternatively, try this plugin to have the result in a table form.

Note: the area reported by regionprops is the number of pixels. Check pixel size and convert the reported number to physical units.

Next steps#

  • napari provides the flexibility to handle multi-dimensional data. Try opening 3D or higher dimensional images, and switch to 3D view.

ndisplay