To create and/or run Napari script, open a Jupyter notebook or Jupyter Lab from napari-env environment in Anaconda. Or, in case you have an open Napari viewer, you can use the script-editor:
To get intellisense tips when writing the script one can write the code inside Napari (need to install the napari_script_editor plugin and then accessing it via the user interface Tools > Scripts > Script editor).
A simple way to get the syntax of running various commands from a script is to use the Script-Editor together with the Assistant (Plugins > Assistant, need to install the Napari-assistant plugin):
In the Script-Editor check the Record checkbox
In the Assistant navigate to the operation you want to perform
run the operation > the underlying scripting is added to the Script-Editor
import napari # napari package viewer = napari.Viewer() # cretae a new napari viewer |
there is more than one way to open a file. The simplest way, when no plugin is needed is by using napari.open command with parameter:
file_path = 'C:/Users/ehuds/Downloads/cropped napari 3d segmentation.tif' # change to your path viewer.open(file_path, name='my_first_image') |
When the file opening requires a specific plugin one can provide it using the plugin parameter. Imaris file, for example can be opened using the ‘bioformats’ plugin
file_path = 'C:/Users/ehuds/Downloads/yw1_2022-06-21_11.03.29_F02.ims' # change to your path viewer.open(file_path, plugin='bioformats', name='my_first_imaris_image') |
skimage.io
imread
commandinstead of a plugin one can try skimage.io
to read the file
from skimage.io import imread # skimage package to read files from disk file_path = 'C:/Users/ehuds/Downloads/cropped napari 3d segmentation.tif' # change to your path img1 = imread(file_path) # read file from disk new_layer = viewer.add_image(img1, name='my_first_skimage_image') # view image in napari viewer |
3D images can be viewed in a 2D viewer as video (recommended when 3rd channel is time) or in 3D viewer (recommended when 3rd channel is Z-stack/slices). By default the viewer opens the image in 2D viewer. To switch to 3D
viewer.dims.ndisplay = 3 # set to 2 for 2D video mode |
There are many plugins that can be used for segmentation.
This napari-plugin is based on scikit-image and allows segmenting nuclei and cells based on fluorescence microscopy images with high intensity in nuclei and/or membranes. It populates image processing operations to the Tools
menu in napari. You can recognize them with their suffix (nsbatwm)
in brackets. Furthermore, it can be used from the napari-assistant graphical user interface. Therefore, just click the menu Tools > Utilities > Assistant (na)
or run naparia
from the command line.
Here we show an example how to run this plugin from a script
segment the