Sectioning, Exporting, etc

I have a few questions about Napari that I haven’t found answers for in the tutorials or on this forum (though I may have missed it). By way of background, I installed Napari in anaconda, but I am running it as a stand alone viewer, not in a notebook.

There are a few functionalities that I imagine Napari has, but which I haven’t figured out yet.
1 - When viewing a 3D object, is there a way to optically section through the object?

2 - Once I have a particular image that I would like to save, is there a standard export function?

3 - Related to the above, is there a way to list the various command line options that are implemented in Napari?
Thanks for the assistance and I am enthusiastic about the Napari project!

1 Like

Hi Michael, that’s great that you are excited about napari and giving a try! I’ll try and answer your questions below

Not yet, but this is definitely something we want to support soon. Do you want cropping functionality? So say you have a [100, 512, 512] volume you could have 3 sliders that would “crop” the rendered volumes, say to do something like render only the first 50 slices making a [50, 512, 512] volume. We definitely have plans to support this. Or are you more interested in mixed 2D and 3D rendering - see issue 639? I’d like to get working on both these features fairly soon and will update this thread when we have something. Also if you can provide more detail around functionality that you want here feel free to open a new issue directly on the repo or respond here to this message. Example use cases / screenshots from other tools are always appreciated too.

Not yet either. We will also provide this eventually, but havn’t gotten around to it yet. Right now you’re probably best grabbing the image array data directly from the property and then using imageio.imwrite or directly. You can do this from the napari console where you have access to the viewer object. In the future this sort of functionality will be accessible via drop down menus / dialog boxes, but we aren’t there yet.

napari -h or napari --help on the command line should list the current command line options.

Hope this helps, and feel free to ask more questions as they come up!!

Do you want cropping functionality? So say you have a [100, 512, 512] volume you could have 3 sliders that would “crop” the rendered volumes, say to do something like render only the first 50 slices making a [50, 512, 512] volume.

The feature request was for the ability to generate a cross section at an arbitrary plane in a 3D dataset. In ImageJ, this is referred to as orthogonal views, in UCSF Chimera, it is referred to as Clipping. But unlike in imageJ, one would have the ability to get an orthogonal view from any angle.

Concerning export, I am not able to follow your instructions, I don’t know how to grab the data from the property, is there a code snippet available that I could modify for my own uses? ( I am new to these tools).


Ah, I get it. Right now we’ve got plans for linked orthoviews so you could see all three views at the same time if you wanted, and we’ve also had a feature request for non-orthogonal (arbitrary angle) slicing but we havn’t start working on it. I hope in the next couple months we’ll make good progress on these issues though.

Unfortunately we don’t have a tutorial yet for saving image data, but we should definitely make one, especially as we don’t have any GUI support for saving yet. Maybe @talley or @jni have something we can put up on our tutorials page relatively quickly, but in the mean time our napari viewer tutorial will tell you about the concept of layers in the viewer and how to access the console. Then, say you have a layer named astronaut inside the viewer, inside the console you could do

from import imsave
#get the numpy array of the data from the layer called 'astronaut'
image = viewer.layers['astronaut'].data
imsave('astro.png', image)

and that would save the image as a png file. Your screen would look something like this:

Thanks Nicholas for the very prompt and helpful replies. The non-orthogonal slicing is exactly what I was requesting, it would be very useful, though likely will require significant effort.

In terms of saving, the code you provided worked (after I renamed the layer, the default ‘image’ threw an error). However, it saved a copy of the image as it was prior to import (ie a stack), not a file with the current view in the Napari viewer. Effectively, I would like to be able to make the equivalent of a screenshot of the viewer window, but perhaps without compression (ie a tif file). I was looking at the Naparimovie plugin which appears to do this for a sequence of frames, so it seems possible.

Thanks again!

1 Like

You should be able to use the viewer.screenshot method as follows

from import imsave
image = viewer.screenshot()
imsave('screenshot.png', image)
1 Like