Image viewer for python notebooks

Hi All,

@ctrueden @thewtex @jni @szymon.stoma

We are currently running a python image analysis course in Juypter notebooks.
Could you recommend good image viewers for this scenario?

Best wishes,
Christian

Hi Christian,

Have you explored Napari yet? https://napari.org/

We’ve only recently discovered it but I think we’re all moving to it for research in Jupyter and I will be using it next time I do a image analysis course for sure.

Chas

4 Likes

I have heard good things about Napari… There is also the option of using VTK in a notebook as described in this thread.

3 Likes

Thank you for the suggestion! I have in fact tried it. It is great but I think it would be nice if it would be rendered within a notebook cell. For me it pops up another window, using below code:

from skimage import data
import napari

with napari.gui_qt():
    myviewer=napari.Viewer()
    myviewer.add_image(data.binary_blobs())

Thanks a lot! I in fact tried it and I find it really good! Imho, it has the advantage of rendering within the notebook.

Scikit-image also has a viewer, it does not seem to render in the notebook but apparently it allows to easily make GUI for parameters.

https://scikit-image.org/docs/dev/user_guide/viewer.html

napari is nice, but not in notebooks. I think he need a interactive web canvas.

if you want a web interactive canvas, try bokeh?

Have you had a look at neuroglancer? It has a notebook extension.

Disclaimer: It is very much focused on 3D visualization of connectomics data and I do not know if it supports 2D data or time series. I have never used the Jupyter notebook extension but it may be worth a try.

1 Like

If your students are running notebooks locally, napari has quite quickly become the best solution. Unfortunately it doesn’t yet work (to my knowledge) in remote cases e.g. when running a JupyterHub. For a solution fully integrated into notebooks I use a combination of Matplotlib+ipywidgets for 2D and ipyvolume for 3D. The latter is a bit complicated to customise in details but easy to use for a quick 3D rendering.

2 Likes

This is pretty much what I have traditionally used (mpl+ipy / ipyvol).

I was not aware napari doesn’t work with Hub. I might have to investigate that as we’re moving to a centralised Hub on a computer server soon.

It’s hopefully coming in a future release (see https://github.com/napari/napari/issues/495) but unfortunately I don’t think it’s a super-high priority for the napari developers right now. I think a lot of people are moving to centralised JupyterHubs and it would be a very useful feature.

1 Like

Here are a few recently updated examples of itkwidgets with

3 Likes

Hi everyone!

It’s so great to see people I’ve never met, even virtually (:wave: @ChasNelson!) recommend napari!

I have little to add to this thread, just to confirm that everyone’s impressions are accurate: napari is a native app so does not render on a notebook, and it does not support remote kernels, and it might do one or both of those things one day, but not imminently. In addition to the issue pointed to by @guiwitz, there is a fresh meta-issue created by @sofroniewn about this here: https://github.com/napari/napari/issues/881

I do also want to say that for tutorials using local kernels, napari works great. I recently ran a workshop at my university using napari as the viewer. The empty notebook can be found here and the completed one here. (There are also other completed notebooks in those branches, index here.) Two things I really like are the layers, which allows students to see the different steps of a workflow overlaid on one another, and mixing interactions such as point picking with other parts of the pipeline, which makes it very nice to quickly segment data with watershed, for example.

Also, the scikit-image viewer is deprecated, please don’t build on it! No one has touched that code in a long time. :sweat_smile:

Final side note, @Christian_Tischer, regarding your code snippet: on a notebook or IPython kernel, it is better to use %gui qt in your first cell and then not use with napari.gui_qt():. This allows your kernel to remain interactive while you view your data in napari. Otherwise, you will not be able to enter more commands into IPython until you close the napari window.

I hope this helps!

5 Likes

@ChasNelson I forgot to mention that for the remote case, there actually is a workaround using a remote Linux desktop that you can find here https://github.com/manics/jupyter-omeroanalysis-desktop/tree/napari-binder. It’s pretty straightforward to integrate with a project running on mybinder (you can e.g. try a demo I made here https://github.com/guiwitz/napari_demo). However it’s quite complex in the background, and I have never tried to use that solution with a “private” JupyterHub. I hope I’ll get to explore this soon, as it would solve the local installation problem, which I always try to avoid typically when teaching to beginners.

4 Likes

:+1:

Thanks @guiwitz for this great demo! I stumbled upon it earlier and bookmarked it, but didn’t find the time yet to try out myself, except clicking the launch binder button… It seems like a great solution for teaching indeed if you want to avoid locally installing software.


For what it’s worth, the solution implemented by #apeer/@sebi06 using #ipywidgets seems to be worth a look as well:

Read_CZI_and_OMETIFF_and_display_widgets_and_napari/using_apeer-ometiff-library.ipynb

4 Likes