Skip to content

Napari

Napari is an extensible framework for viewing, processing and manipulating images and we have developed a plugin to use AFMslicer in Napari, napari-afmslicer.

Installation

If you have followed the installation instructions to install napari-afmslicer from PyPI or from a clone repository you will, obviously, already have napari-afmslicer and its dependencies installed.

However, it is possible that you may have followed the Napari installation guide which installs Napari without any plugins. Because the napari-afmslicer has been released to PyPI it is also available in the Napari Hub which means you can then install napari-afmslicer from within Napari via the Plugins > Install/Uninstall Plugins menu item. Search for afmslicer

Dependencies

napari-afmslicer includes a small selection of plugins as dependencies and these are pulled in automatically when you install napari-afmslicer.

The napari-crop and napari-skimage plugins in particular may be of use to further pre-process images prior to slicing but they are not developed or maintained by the developers of napari-afmslicer. If you encounter problems with either of these plugins please contact the developers of those packages.

Usage

Info

In the following the term "widget" refers to a panel for processing an image with various settings. These typically include a menu at the top for selecting which image to apply the processing to. Most of the options have tool-tips which when you move the mouse over will appear and describe information about the parameter and what changing its setting impacts.

Launching

You can launch Napari from the command line within your Virtual Environment.

napari

Widgets can be launched from the menu under Plugins > AFMSlicer > from which you can enable each components of the plugin. Currently there are three components, each of which can be enabled independently.

  • 3D Viewer
  • Filter
  • Slicing

Loading widgets from the Plugin menu.

Each of the widgets appears on the right-hand side of Napari.

Screenshot of napari with the filter widget loaded.

Screenshot of napari with the slicing widget loaded.

Screenshot of napari with the 3D-viewing widget loaded.

Screenshot of napari with the filter, slicing and 3D-viewing widgets loaded from the menu. Note they are not tabbed.

...with AFMSlicer Widgets

You can automatically load the Napari AFMSlicer plugin with the -w napari-afmslicer flag and load all widgets too with the __all__ option (see napari --help for more details)...

napari -w napari-afmslicer __all__

Napari will start and the AFMSlicer widgets will be on the right-hand side. Unlike launching the widgets from the Plugins menu they are tabbed and the tabs appear at the bottom with the active tab highlighted, allowing you to switch between the Filtering, Slicing and 3D Viewer AFMSlicer widgets.

Screenshot of napari with the filter, slicing and 3D viewer plugins loaded as tabs.

Tool Tips

Hovering over a parameter with the mouse will show the associated tool tip for the option which describes what the setting does and possible options.

Showing the tool-tip for the Slices parameter

Workflow

A typical workflow will involve...

  1. Filtering an image to flatten it, removing scars and apply Gaussian blurring.
  2. Optionally selecting and cropping regions of interest.
  3. Running slicing on the whole image or each of the selected regions.

Opening Files

Open files using the menu item File > Open File(s) (accessible via the shortcut Ctrl + O). You can select more than one image a time to be loaded, each will be listed on the left as its own "Layer".

Selecting files to open in napari

For each image you have opened you are prompted to select the channel for which you wish to load data. This defaults to Height Sensor so unless you want a different channel just hit return and the dialogue box will disappear and the image will open.

Selecting files to open in napari

Once opened each image is listed as its own "Layer" in the bottom left of Napari in the Layer List. You can toggle whether a given layer is shown by clicking on the "eye" icon next to it in the Layer List.

Hide and show layers by clicking on the box with an "eye" in it.

Showing the sample1 layer with sample2 hidden

Hide and show layers by clicking on the box with an "eye" in it.

Showing the sample2 layer with sample2 hidden

Filtering

The parameters for filtering can be configured easily from the Filter widget.

  1. Select the Image to filter (you do not have to change Original image (uncropped)).
  2. Typically Row alignment quantile will not need modifying from 0.50.
  3. Gaussian Size will depend on how much "noise" there is in your image, higher values cause more blurring which can mask noise but also blurs boundaries in regions. You may need to experiment with this parameter.
  4. Gaussian mode works well with nearest but other options are available, for details see mode parameter in scikit-image.
  5. Whether to run scar removals depends on the scan and whether, in your judgement, there are any scars that need to be removed. Unchecking Remove scars will prevent scar removal from running completely. Otherwise leave enabled, the defaults are generally good but may need adjusting.

Once you are happy with these parameters click on the Filter button, after a short while a new layer will appear listed as <image_name>_filtered

Hide and show layers by clicking on the box with an "eye" in it.

Showing the sample1 post filtering

Hide and show layers by clicking on the box with an "eye" in it.

Showing the sample2 post filtering

By filtering before cropping a region you will have a clearer view of the features to select.

Cropping

Plugins > napari_crop has three options for cropping, by Crop Regions is the one you are most likely to want to use which allows free hand selection of a region to crop.

Select the filtered layer, in this example sample2_filtered, in the Layer list on the bottom left of the image and click on the Shapes button at the top of the Layer List region (its a box with a trapezoid in).

Creating a Shapes layer

This creates a new layer, sample3_filtered - Shapes and the Layer controls box on the left above the Layer List will change and have a number of buttons for selecting and drawing shapes in the image. Select the Add rectangles (R) tool and you can select regions to crop.

Select the rectangle select tool from the layer controls widget.

Selecting the Add rectangles tool

Select one or more region to crop.

Selecting rectangles to crop

Here we have enabled the Crop Region(s) widget from the Plugin > napari-crop > Crop Regions in the menus and are selecting the layer to crop which should be the "filtered" layer (sample2_filtered) and the shapes layer should be the corresponding "Shapes" layer (sample2_filtered - Shapes).

Selecting rectangles to crop

Now click the Run button under the Crop Regions widget.

You now have a separate layer for each crop and can toggle which cropped regions to display via the "eye" button on each layer. Here regions 0, 2 and 5 are shown whilst 1, 3, and 4 are hidden. Note that the _filtered layer has been hidden from display as well as the Shape layer which just shows transparent boxes for each of the cropped regions.

Cropped regions 0, 2 and 5

Slicing

Under the Slicing widget you can now slice your image.

  1. Select the image you wish to filter from from the pull-down list to the right of Image. This may be the whole, filtered image (with the _filtered suffix), or it may be one of the crops.
  2. Choose the number of Slices to create and the Segmentation method (label is fine for the time being, watershed still needs some work).
  3. Enable the statistics to calculate by checking boxes next to Area, Centroid and Feret Maximum for those that are required.
  4. Set the Minimum size of objects, this may require experimentation.
  5. Output will by default go to the output directory but this can be changed if required.

When ready click on the Slice Image and Summarise button. Once complete a dialog box will pop up at the bottom of the image area (it may need expanding to show).

Screenshot of napari after slicing an image.

If slicing was successful the message will read 🔪 Slicing complete results are in : output 🔪.

3D Viewer

The 3D viewer can be used to view the images in three dimensions. Select the _filtered layer for the Image to be viewed and a number of slices to create this image with (it can be different to those the slicing was performed with).

Screenshot of napari showing a 3D view of an image.