Skip to main content

Interactive Jupyter widgets to visualize images, point sets, and meshes in 2D and 3D

Project description

PyPI version npm Build status Interactive example on MyBinder License Software citation DOI

Interactive Jupyter widgets to visualize images, point sets, and meshes on the web.

itkwidgets chest CT in JupyterLab

Key Features:

itkwidgets demo

These widgets are designed to support spatial analysis with the Insight Toolkit (ITK), but they work equally well with other spatial analysis tools in the scientific Python ecosystem.

These widgets are built on itk.js and vtk.js.

Examples on Binder

Data types:

Recipes:

Installation

To install the widgets for the Jupyter Notebook with pip:

pip install itkwidgets

For Jupyter Lab, additionally, run:

jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib jupyterlab-datawidgets itkwidgets

Usage

In Jupyter, import the view function:

from itkwidgets import view

Then, call the view function at the end of a cell, passing in the image to examine:

view(image)

For information on additional options, see the view function docstring:

view?

Other available widgets:

  • itkwidgets.line_profile: Plot an intensity line profile.

  • itkwidgets.checkerboard: Compare two images in a checkerboard pattern.

  • itkwidgets.compare: Compare two images side-by-side.

Using within a Docker Container

You can use itkwidgets from within a docker container with jupyterlab. To create a local docker image:

Install docker and build the docker image with:

git clone https://github.com/InsightSoftwareConsortium/itkwidgets
cd itkwidgets/docker
IMAGE=itkwidgets:0.1.0
docker build -t $IMAGE .

Then run the docker container with:

EXAMPLESDIR=`pwd`/../examples
docker run -it --rm -v $EXAMPLESDIR:/home/jovyan -p 8888:8888 itkwidgets:0.1.0

Finally, connect to your notebook at http://127.0.0.1:8888/lab

Advanced Usage

The itkwidgets are based on ipywidgets. As a consequence, widgets traits can be queried, assigned, or observed with the viewer object returned by the view function. itkwidgets can be combined with other ipywidgets to quickly explore algorithm parameters, create graphical interfaces, or create data visualization dashboards.

Mouse Controls

Left click + drag

Rotate

Right click + drag or shift + left click + drag

Pan

Mouse wheel or control + left click + drag or pinch

Zoom

Alt + left click + drag left-right

Change color transfer function window

Shift + left click + drag top-bottom

Change color transfer function level

Shift + alt + left click + drag top-bottom

Change primary Gaussian volume opacity transfer function magnitude

Keyboard Shortcuts

Keyboard shortcuts take effect when the mouse is positioned inside the viewer. All shortcuts are prefixed with Alt+. Corresponding keys for the Dvorak keyboard layout have the same effect.

Alt + 1

X-plane mode

Alt + 2

Y-plane mode

Alt + 3

Z-plane mode

Alt + 4

Volume rendering mode

Alt + q

Toggle user interface

Alt + w

Toggle region of interest (ROI) selection widget

Alt + e

Reset ROI

Alt + r

Reset camera

Alt + s

Toggle slicing planes in volume rendering mode

Alt + f

Toggle fullscreen

Examples

After installation, try the following examples that demonstrate how to visualize:

or how to:

Troubleshooting

IOPub data rate exceeded.

If you experience the notebook warning:

IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

Set the notebook configuration value:

jupyter notebook --NotebookApp.iopub_data_rate_limit=1e12

Scrolling in JupyterLab

Cell output scrolls by default in JupyterLab. To disable scrolling, right click in the region to the left of the output and select Disable Scrolling for Outputs.

‘Permission denied’ during installation

If Permission denied errors occur during installation, install the Python package with user permission via:

pip install –user itkwidgets

For JupyterLab extension installation, configure JupyterLab to use your user application directory by setting the environmental variable, JUPYTERLAB_DIR:

export JUPYTERLAB_DIR=$HOME/.local/share/jupyter/lab

Check that this is picked up in the value of the Application directory reported by:

jupyter lab path

Then, install the extension as usual:

jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib jupyterlab-datawidgets itkwidgets

Hacking

Participation is welcome! For a development installation (requires Node.js):

git clone https://github.com/InsightSoftwareConsortium/itkwidgets.git
cd itkwidgets
python -m pip install -r requirements-dev.txt -r requirements.txt
python -m pip install -e .
jupyter nbextension install --py --symlink --sys-prefix itkwidgets
jupyter nbextension enable --py --sys-prefix itkwidgets
jupyter nbextension enable --py --sys-prefix widgetsnbextension
python -m pytest
python -m pytest --nbmake examples/*.ipynb

The above commands will setup your system for development with the Jupyter Notebook. In one terminal, start Jupyter:

cd itkwidgets
jupyter notebook

In another terminal, put Webpack in watch mode to rebuild any Javascript changes when you save a Javascript file:

cd itkwidgets
npm run watch

If Python code is changed, restart the kernel to see the changes. If Javascript code is changed, reload the page after to Webpack has finished building.

To develop for Jupyter Lab, additionally run:

jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib jupyterlab-datawidgets jupyter-webrtc
jupyter labextension install ./js
jupyter lab --watch

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

itkwidgets-0.32.5.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

itkwidgets-0.32.5-py2.py3-none-any.whl (3.4 MB view details)

Uploaded Python 2 Python 3

File details

Details for the file itkwidgets-0.32.5.tar.gz.

File metadata

  • Download URL: itkwidgets-0.32.5.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for itkwidgets-0.32.5.tar.gz
Algorithm Hash digest
SHA256 2a3429e3d05649b14d666b17482280fe0370d6fd2efaafacfcb8eb0e86162b8b
MD5 978f6e17eeb5d2ba59586ade07c4d775
BLAKE2b-256 ec6f0743248c9e6f5929282c13fc42c14fdaa5800eb57bb9ea706f7ab2633cd5

See more details on using hashes here.

File details

Details for the file itkwidgets-0.32.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for itkwidgets-0.32.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 25af47151fa30b61dd58fabffd1af9accc5749480ff918ce7855f3e266f19948
MD5 2135a1d1874f585f9b992324f9e9f42d
BLAKE2b-256 5c377c8679d008aedebb3eef821da21be414578af1bb1aac581d2cf601a81a32

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page