Run Slicer in your web browser - as a Jupyter notebook or as a full application

It has been possible to use Slicer from Jupyter notebooks but the most recent Slicer Preview Release takes this to a whole new level.

Click here to try a few example interactive notebooks now - or see a short video demonstrating the new features:

Highlights:

  1. Improved interactive use

You can now use IPython widgets (sliders, buttons, etc.) to control Slicer or adjust processing and visualization parameters. For example, CLI module parameters can be adjusted using slider widgets and results are computed and displayed autoamtically in the notebook:

3D Slicer views are in notebooks are now interactive. You can zoom/rotate 3D views, browse slices, place points, or edit segmentations - right in the notebook:

You can display and control selected viewers, all viewers, or the entire application in notebook cells. This allows users to implement complete data processing workflows in a notebook, even if certain steps require manual user inputs (3D regions, seed points, etc.).

  1. Data node visualization directly in the notebook

Slicer takes advantage of rich data visualization capabilities of Jupyter notebooks. For example, markup fiducial list node is displayed as a nicely formatted table, model node is rendered as a 3D object, etc. New visualizers can be added for all MRML node types, if this proves to be useful.

  1. Available on the web

Since now the full application user interface is available interactively in Jupyter, it is possible to use Slicer remotely, in a web browser, without installing any software locally. For example, click here to launch Slicer in your web browser using binder - a free Jupyter web hosting service. They allocate quite limited computational resources to each instance, but it still sufficient to run Slicer.

[


Many thanks to Jupyter/xeus team, and especially to Sylvain Corlay and Martin Renou for their excellent work of creating a robust and flexible Jupyter kernel for C++ applications with embedded Python; and to @jcfr for setting up the new Slicer docker container.

More information, instructions for local installation: GitHub - Slicer/SlicerJupyter: Extension for 3D Slicer that allows the application to be used from Jupyter notebook

Any comments and suggestions are welcome.

18 Likes

@lassoan this is great. COngrats to everyone who helped to develop.

I don’t know much about binder, would the backend benefit from GPU and GPU accelerated rendering for large volumes (that typically our users work with)?

1 Like

Yes, you can configure your docker container to use GPU.

great to know !!! Thanks a lot for the efforts!

1 Like

I want to 1) emphasize how cool this is and 2) ask: is there a way to open Slicer in a new tab using the whole extent of the screen? I have forked the repo to give access to users to a demo of our module:
Binder

At the moment, it looks like this:

As you can see, a lot of space is wasted around each side of the window.

I tried slicer.util.mainWindow().setFixedWidth(width) but the window just went “behind” the gray margins.

It is great that you like it! (it is not obvious that it just how powerful this infrastructure is)

You can open a new browser tab automatically like this:

display(Javascript('window.open("../desktop", "_blank");'))

You have a couple of options for controlling window size, resolution, and scaling. One option is to display noVNC manual controls (we decided to remove it for sake of simplicity). The other is to configure noVNC and the window manager to automatically resize (it is not so trivial, because you may not want to have very high resolution because rendering may slow down, so above a certain size you would rather scale; and you probably also want to support certain range of screen aspect ratio). noVNC is used very widely and all kinds of automatic resizing/rescaling solutions are already available if you search on the web.

I see. That’s slightly different to the line I’m using to open the tab automatically:

But I see in the JavaScript docs (are they?) that "_blank" is the default anyway. In the binder I shared above, with a single cell and a line at the end that opens the new tab, my Chrome blocked the new tab and asked if I wanted to allow pop-ups. But that’s not very important.

I’ll look into noVNC to improve the window size issues. Thanks, @lassoan!

This is great!

Is there some kind of documentation page I can find somewhere?

Is there a way to make use of a part of slicer’s function in a program? I’m trying to use my own method of segmentation and I want to use slicer’s 3d model generation/volume creation from a segmented arrays of image, to then export it as an stl file. Is there a way I could achieve this?

You can use the Slicer application headless to run scripts in the Slicer environment. This can run natively alongside your app or from a docker container (for example if you wish to make it a part of a web app.
In addition to this there is a web server for slicer in the works. This will allow you to get access to functionality of Slicer using web requests.

Although if your segmentation method is python based and you are working with a desktop app I would suggest you consider using Slicer as a host platform and integrate the segmentation into it.

Is there a way to make use of a part of slicer’s function in a program? I’m trying to use my own method of segmentation and I want to use slicer’s 3d model generation/volume creation from a segmented arrays of image, to then export it as an stl file. Is there a way I could achieve this?

Maybe you can create a python script for Slicer to execute on the console like this:
Slicer.exe --python-script "/full/path/to/myscript.py" --no-splash --no-main-window

Inside the script you need to read your segment data (e.g. from a numpy array, maybe like this), then you need to create a closed surface representation of the segment (like this), you need change the storage of 3D models to stl (like this), then you need to export segments as models (like this), then you can save your model as .stl maybe like this:
slicer.util.saveNode(modelNode, filepath)

I haven’t tested this workflow, but I think it should work

1 Like