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.
- napari-afmreader - used to load a range of Atomic Force Microscopy images.
- napari-crop - used for cropping images (typically prior to filtering and slicing).
- napari-skimage - Napari interface to Scikit Image functions.
- napari-topostats - required as some of the functionality is reused.
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.
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

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




...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 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.

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.

Workflow¶
A typical workflow will involve...
- Filtering an image to flatten it, removing scars and apply Gaussian blurring.
- Optionally selecting and cropping regions of interest.
- 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".

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.

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.

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

Filtering¶
The parameters for filtering can be configured easily from the Filter widget.
- Select the Image to filter (you do not have to change Original image (uncropped)).
- Typically Row alignment quantile will not need modifying from
0.50. - 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.
- Gaussian mode works well with
nearestbut other options are available, for details seemodeparameter in scikit-image. - 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.

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

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).

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.

Select one or more region 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).

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.

Slicing¶
Under the Slicing widget you can now slice your image.
- 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
_filteredsuffix), or it may be one of the crops. - Choose the number of Slices to create and the Segmentation method (
labelis fine for the time being,watershedstill needs some work). - Enable the statistics to calculate by checking boxes next to Area, Centroid and Feret Maximum for those that are required.
- Set the Minimum size of objects, this may require experimentation.
- Output will by default go to the
outputdirectory 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).

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).
