• Stars
    star
    238
  • Rank 169,306 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Extension for 3D Slicer that allows the application to be used from Jupyter notebook

SlicerJupyter

Extension for 3D Slicer that allows the application to be used from Jupyter notebook

Demo video: https://youtu.be/oZ3_cRXX2QM

Usage

Option 1. Run using Binder

You can use this option for a quick start. No installation or setup is needed, just click the link below and start using Slicer via Jupyter notebook in your web browser.

Binder

When you click on the link, Binder launches 3D Slicer with SlicerJupyter extension on their cloud servers. Binder is a free service and server resources are quite limited. Also, there is no interactive access to the graphical user interface. Therefore, this option is only recommended for testing, demos, or simple computations or visualizations.

Option 2. Run on your own computer

  • Install 3D Slicer and launch it
  • Install SlicerJupyter extension in Extension Manager (in the application menu choose View/Extension Manager, click Install button of SlicerJupyter, wait for the installation to complete, and click Restart)
  • Switch to JupyterKernel module (open the module finder by click the "Search" icon on the toolbar, or hitting Ctrl/Cmd-F, then type its name)
  • Click Start Jupyter server button

Run classic notebook interface

Follow all the installation steps above (start Jupyter server once with the default JupyterLab user interface), then restart Slicer. After this, a classic notebook server can be started by typing this into the Python console in Slicer:

slicer.util._executePythonModule('notebook',['--notebook-dir', 'some/path/to/workspace'])

Using external Jupyter server

Slicer's Python kernel can be used in Jupyter servers in external Python environments. Kernel specification installation command is displayed in Jupyter server in external Python environment section in JupyterKernel module.

You need to install and set up these Python packages: jupyter jupyterlab ipywidgets pandas ipyevents ipycanvas.

Option 3. Run using docker on your computer

  • Install docker
  • Run the docker image as described here

Using Slicer from a notebook

  • Create a new notebook, selecting Slicer 4.x kernel (for example, Slicer 4.13). Jupyter will open a new Slicer instance automatically when kernel start is requested. This Slicer instance will be automatically closed when kernel is shut down. If you manually close the Slicer application (e.g., File/Exit menu is used in Slicer) then Jupyter will automaticall restart the application in a few seconds.

Select Slicer kernel

  • While the kernel is starting, "Kernel starting, please wait.." message is displayed. After maximum few ten seconds Slicer kernel should start.
  • Do a quick test - show views content in the notebook:
import JupyterNotebooksLib as slicernb
slicernb.ViewDisplay()
  • Try the interactive view widget:
slicernb.ViewInteractiveWidget()
  • Hit Tab key for auto-complete
  • Hit Shift+Tab for showing documentation for a method (hit multiple times to show more details). Note: method name must be complete (you can use Tab key to complete the name) and the cursor must be inside the name or right after it (not in the parentheses). For example, type slicer.util.getNode and hit Shift+Tab.

Hit Tab key to auto-complete

Hit Shift-Tab key to inspect

Notes

Upgrading pip

You may see warning messages about upgrading pip, such as this:

WARNING: You are using pip version 20.1.1; however, version 20.3.3 is available.
You should consider upgrading via the '/Applications/Slicer.app/Contents/bin/./python-real -m pip install --upgrade pip' command.

In general, it is not necessary to upgrade pip, so you can ignore this warning. If you do want to upgrade it then you need to use the Slicer's "Python launcher" (instead of python-real). Slicer's Python launcher is called PythonSlicer and it sets up Slicer's virtual Python environment so that the real Python executable (python-real) can run correctly.

Script not on PATH

You may get warning about installing scripts in folder that is not on PATH:

WARNING: The script pyjson5 is installed in ‘/Applications/Slicer.app/Contents/lib/Python/bin’ which is not on PATH.

This warning is displayed to warn you that the installed script will not run by simply typing its name anywhere in a terminal. This can be safely ignored.

Shutdown all Slicer Jupyter kernels

If a Jupyter server is kept running then it will automatically restart all kernel instances (Slicer applications) that it manages. If the browser window is accidentally closed before shutting down the server, then you can get the address of all running servers by typing the following into any Slicer Python console:

slicer.util._executePythonModule('jupyter', ['notebook', 'list'])

Open the address in a web browser and click "Quit" button to shutdown the server.

Examples

You can get started by looking at example Slicer notebooks here.

For developers

Build instructions

  • Build 3D Slicer
  • Configure this project using CMake, set Slicer_DIR CMake variable to the .../Slicer-build
  • Install prerequisites

Install kernel manually

Example:

jupyter-kernelspec install /tmp/SlicerJupyter-build/inner-build/share/Slicer-4.13/qt-loadable-modules/JupyterKernel/Slicer-4.13/ --replace --user

Launch a kernel manually

Type this into Slicer's Python console to manually start a kernel that a notebook can connect to:

connection_file=r'C:\Users\andra\AppData\Roaming\jupyter\runtime\kernel-3100f53f-3433-40f9-8978-c72ed8f88515.json'
print('Jupyter connection file: ['+connection_file+']')
slicer.modules.jupyterkernel.startKernel(connection_file)

Path of connection_file is printed on jupyter notebook's terminal window.

Special commands

These commands must be the last commands in a cell.

  • __kernel_debug_enable(): enable detailed logging of all incoming Jupyter requests
  • __kernel_debug_disable(): enable detailed logging of all incoming Jupyter requests

More Repositories

1

Slicer

Multi-platform, free open source software for visualization and image computing.
C++
1,637
star
2

SlicerGitSVNArchive

⚠️ OBSOLETE | Multi-platform, free open source software for visualization and image computing.
C++
871
star
3

SlicerNotebooks

Examples that illustrate how to use 3D Slicer via Jupyter notebooks in Python
Jupyter Notebook
71
star
4

ExtensionsIndex

Slicer extensions index
Python
65
star
5

SlicerDocker

Build, package, test, and run 3D Slicer and Slicer Extensions in Docker.
Dockerfile
55
star
6

SlicerExecutionModel

An open-source CMake-based project that provides macros and associated tools for the easy building of 3D Slicer command line interface (CLI) modules.
C++
32
star
7

vtkAddon

General-purpose features that may be integrated into VTK library in the future.
C++
14
star
8

SlicerOpenCV

Slicer Extension wrapping OpenCV
CMake
12
star
9

SlicerLanguagePacks

3D Slicer extension for creating, editing, and storing translations for Slicer core and extensions
Python
8
star
10

SlicerBuildEnvironment

A repository of scripts to set up a Slicer build environment.
Dockerfile
8
star
11

SlicerDeveloperToolsForExtensions

Set of tools to help developers when creating new Slicer extensions
Python
7
star
12

SkullStripper

Skull stripping for structural MR images of the brain, tested on T1 and T2 contrast.
C++
7
star
13

LandmarkRegistration

An interactive registration tool that manages viewing and manipulating of sets of fiducials
Python
6
star
14

Slicer-MeshContourSegmentation

⚠️ OBSOLETE | Slicer Command Line Module. Given some initial points in polydata will construct a contour and evolve it to high mean-curvature areas, returning the interior region indices.
C++
6
star
15

SlicerSurfaceToolbox

Supports various cleanup and optimization processes on surface models
C++
5
star
16

DashboardScripts

Collection of scripts used to configure/build/test/package 3D Slicer and associated extensions
CMake
4
star
17

github-circleci-trigger

A simple GitHub post-receive web hook handler able to trigger a CircleCI build.
Python
4
star
18

SlicerSOFA

3D Slicer extension to enable simulations using the SOFA framework
Python
4
star
19

Slicer-MultiResolutionAffineRegistration

⚠️ OBSOLETE | Legacy Slicer module - Provides affine registration using multiple resolution levels and decomposed affine transforms
C++
3
star
20

SlicerTestingData

Slicer Testing Data Mirror
Python
3
star
21

Slicer-BSplineDeformableRegistration

⚠️ OBSOLETE | Legacy Slicer module - Registers two images together using BSpline transform and mutual information
C++
3
star
22

ParameterSerializer

An open-source library for serialization and deserialization of Insight Segmentation and Registration Toolkit (ITK) classes.
C++
2
star
23

teem

Slicer fork of teem library - Official repository is hosted on SVN: https://svn.code.sf.net/p/teem/code/teem/trunk
C
2
star
24

SlicerProgrammingTutorial

Introduction to Python scripting and module development for 3D Slicer
2
star
25

SlicerNeuro

Extension for 3D Slicer than installs tools commonly needed for neuroimaging.
C++
2
star
26

Slicer-AffineRegistration

⚠️ OBSOLETE | Legacy Slicer module - Registers two images together using an affine transform and mutual information.
C++
2
star
27

sliceri18n

Python package that contains tools for internationalization of applications that use Python and Qt
Python
2
star
28

slicer.kitware.com-midas3-archive

This project is a snapshot of the data historically served from slicer.kitware.com/midas3
2
star
29

preview.apidocs.slicer.org

This project hosts and serves a preview version of Slicer API documentation
Shell
1
star
30

CurveMaker

Simple 3D Slicer module to generate a spline curve from a list of fiducials
Python
1
star
31

Slicer-RigidRegistration

⚠️ OBSOLETE | Legacy Slicer module - Registers two images together using a rigid transform and mutual information
C++
1
star
32

qMidasAPI

DISCONTINUED - Use http://github.com/commontk/qRestAPI
C++
1
star
33

Slicer-i18n

Repository to track tasks and store resources related to internationalization (i18n) of 3D Slicer.
1
star
34

leapmotion-python-distributions

CMake project for building LeapMotion Python 3 modules
CMake
1
star
35

Slicer-RobustStatisticsSegmenter

⚠️ OBSOLETE | Editor extension for using the 'RobustStatSegmenter' CLI module.
Python
1
star
36

SlicerBinaryDependencies

Binary dependencies required to build Slicer
1
star
37

apidocs.slicer.org

This project hosts and serves the Slicer API documentation
Shell
1
star
38

jqplot

⚠️ OBSOLETE | Fork of jqplot from https://bitbucket.org/cleonello/jqplot to support patches for Slicer4
JavaScript
1
star
39

SlicerRegistrationLibrary

Library of registration cases including step-by-step instructions and discussions
1
star
40

Attic

⚠️ OBSOLETE | This is where abandoned classes and deprecated code related to Slicer may be archived
C++
1
star
41

SlicerDataStore

This project organizes Slicer sample data, atlases and registration case library images.
Python
1
star
42

SlicerLanguageTranslations

Repository to store source and localized language translation files for 3D Slicer and its extensions
1
star
43

Slicer-OpenSSL

OpenSSL sources and builds used in Slicer-based projects.
CMake
1
star
44

OpenIGTLinkIF

DISCONTINUED - See https://github.com/openigtlink/OpenIGTLinkIF - OpenIGTLink IF module manages communications between 3D Slicer and other OpenIGTLink-compliant software through the network.
C++
1
star
45

Slicer-OtsuThresholdImageFilter

Legacy Slicer module - This filter creates a binary thresholded image that separates an image into foreground and background components
C++
1
star